Page MenuHomec4science

controlmsgsprioritydecap.cc
No OneTemporary

File Metadata

Created
Sun, Jul 6, 00:17

controlmsgsprioritydecap.cc

#include <click/config.h>
#include "util.hh"
#include "controlmsgsprioritydecap.hh"
#define DEBUG_CHATTER(arg, ...) do { if (_debug) { click_chatter(arg, ## __VA_ARGS__);} } while (0)
CLICK_DECLS
ControlMsgsPriorityDecap::ControlMsgsPriorityDecap()
{
}
ControlMsgsPriorityDecap::~ControlMsgsPriorityDecap()
{
}
int ControlMsgsPriorityDecap::configure(Vector<String> &conf, ErrorHandler *errh){
_active = true;
_debug = false;
if(Args(this, errh).bind(conf)
.read("ACTIVE", _active)
.read("DEBUG", _debug)
.complete() < 0)
return -1;
return 0;
}
int
ControlMsgsPriorityDecap::initialize(ErrorHandler *errh) {
return 0;
}
void
ControlMsgsPriorityDecap::push(int, Packet *p_in) {
if(!_active) {
output(0).push(p_in);
return;
}
int length = p_in->length();
Timestamp now;
if(_debug) {
now.assign_now();
click_chatter("[ControlMsgsPriorityDecap %s] Decapsulating packet of length %d", now.unparse().c_str(), length);
}
// check management messages
click_ether *init_hdr = (click_ether *) p_in->data();
if(init_hdr->ether_type == htons(ETHERTYPE_HP_AV)) {
output(0).push(p_in);
return;
}
// assume ethernet header, store it
WritablePacket *eth_hdr = Packet::make(sizeof(click_ether));
memcpy(eth_hdr->data(), p_in->data(), sizeof(click_ether));
p_in->pull(sizeof(click_ether));
click_ip *ip_hdr = (click_ip *) (p_in->data());
if(ip_hdr->ip_p == IP_PROTO_IPIP) {
// remove IP header between ethernet header and acne, reset ethertype to acne ethertype
p_in->pull(sizeof(click_ip));
WritablePacket *out = p_in->push_mac_header(sizeof(click_ether));
click_ether *new_eth_hdr = (click_ether *) out->data();
memcpy(new_eth_hdr, eth_hdr->data(), sizeof(click_ether));
new_eth_hdr->ether_type = htons(ETHERTYPE_ACNE);
output(0).push(out);
}
else {
click_chatter("[ControlMsgsPriorityDecap] WARNING: trying to decap packet (eth_type %04X) that has wrong IP protocol (is %d, should be 4).",
ntohs(((click_ether *)eth_hdr->data())->ether_type), ntohs(ip_hdr->ip_p));
output(0).push(p_in);
}
eth_hdr->kill();
}
int
ControlMsgsPriorityDecap::active_handler(const String &s, Element *e, void *,
ErrorHandler *errh) {
ControlMsgsPriorityDecap *elmt = (ControlMsgsPriorityDecap *)e;
int active;
if(!cp_integer(s, &active))
return errh->error("Active must be 0 or 1");
if (!(active == 0 || active == 1))
return errh->error("Active must be 0 or 1");
elmt->set_active(active==1);
return 0;
}
void ControlMsgsPriorityDecap::add_handlers() {
add_write_handler("active", active_handler, 0);
}
EXPORT_ELEMENT(ControlMsgsPriorityDecap)
CLICK_ENDDECLS

Event Timeline