Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120898028
dstcheck.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 7, 17:52
Size
2 KB
Mime Type
text/x-c
Expires
Wed, Jul 9, 17:52 (2 d)
Engine
blob
Format
Raw Data
Handle
27233238
Attached To
R1252 EMPoWER
dstcheck.cc
View Options
#include <click/config.h>
#include "util.hh"
#include "dstcheck.hh"
CLICK_DECLS
Dstcheck::Dstcheck() : _notifier(ActiveNotifier::SEARCH_CONTINUE_WAKE) {}
Dstcheck::~Dstcheck(){}
void * Dstcheck::cast(const char *n)
{
if (strcmp(n, ActiveNotifier::EMPTY_NOTIFIER) == 0){
return &_notifier;
}
else
return Element::cast(n);
}
int Dstcheck::configure(Vector<String> &conf, ErrorHandler *errh){
click_chatter("[Dstcheck] enters configure.\n");
_notifier.initialize(ActiveNotifier::EMPTY_NOTIFIER, router());
_debug = false;
_node_index = -1;
if (Args(conf, this, errh)
.read("INT1_ADDR", _addr_int1)
.read("INT2_ADDR", _addr_int2)
.read("DEBUG", _debug)
.read("NODE_INDEX", _node_index)
.complete() < 0)
return -1;
EtherAddress empty_addr = EtherAddress();
if(_addr_int1 == empty_addr && _addr_int2 == empty_addr){
click_chatter("[Dstcheck]: !!! ERROR: Have 0 interface, should have at least 1 !!!\n");
return 1;
}
//Store last bytes of both addresses for quick dst checks!
if(_addr_int1 != empty_addr){
_lb_int1 = LastAddrBytes(_addr_int1);
_lb_int1.set_hash();
}
if(_addr_int2 != empty_addr){
_lb_int2 = LastAddrBytes(_addr_int2);
_lb_int2.set_hash();
}
if(_debug)
click_chatter("[Dstcheck] configure done.\n");
return 0;
}
int Dstcheck::initialize(ErrorHandler *errh){
if(_debug)
click_chatter("[Dstcheck] Initializing...\n");
Element::initialize(errh);
return 0;
}
void Dstcheck::push(int port, Packet* p){
//assert(port == 0);
//Expects a layer 2.5 frame.
//check size:
if(p->length() < sizeof(empower_header)){
if(_debug)
click_chatter("[Dstcheck] dropping non-empower packet.\n");
p->kill();
return;
}
//check dst MAC
empower_header *header = (empower_header *)p->data();
//get last bytes of the route
//unsigned char *dst = &(header->_route._route[(header->_route._route_length-1)*NB_BYTES_HOP]);
unsigned char *dst = header->_route._dst;
LastAddrBytes lb = LastAddrBytes(dst);
if(lb == _lb_int1 || lb == _lb_int2){
//if(are_last_bytes_in_addr(dst, _addr_int1) || are_last_bytes_in_addr(dst, _addr_int2)){
if(_debug) click_chatter("[Dstcheck:%d] I am the final destination of this packet.\n",_node_index);
output(1).push(p);
} else {
if(_debug) click_chatter("[Dstcheck:%d] This packet is not for me.\n",_node_index);
output(0).push(p);
}
}
CLICK_ENDDECLS
EXPORT_ELEMENT(Dstcheck)
ELEMENT_PROVIDES(Dstcheck)
Event Timeline
Log In to Comment