📄 ovhdpkts.cc
字号:
#include <click/config.h>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/timestamp.hh>#include <clicknet/ether.h>#include <elements/wifi/sr/srpacket.hh>#include "ovhdpkts.hh"#include "xorheader_general.hh"CLICK_DECLSOverheardPackets::OverheardPackets() : Element(1, 1), _enc_ethtype(0){ click_chatter("init overheard packets");}OverheardPackets::~OverheardPackets(){}void *OverheardPackets::cast(const char *n){ if (strcmp(n, "OverheardPackets") == 0) return (OverheardPackets *) this; else return 0;}intOverheardPackets::configure(Vector<String> &conf, ErrorHandler *errh){ click_chatter("starting overheard packets"); int res; res = cp_va_parse(conf, this, errh, cpKeywords, "ETH", cpEtherAddress, "Ethernet address", &_myea, "ENCETHTYPE", cpUnsigned, "Ethtype for encoded packets", &_enc_ethtype, "LISTENMGR", cpElement, "Listen Manager for opp listening", &_listenmgr, "SCRAMBLEQ", cpElement, "Scramble Queue for timers", &_scrambleq, "GUESSMGR", cpElement, "Guess Manager", &_guessmgr, cpEnd); if (!_myea) return errh->error("ETH not specified"); if (!_enc_ethtype) { return errh->error("ENCETHTYPE not specified"); } if (!_listenmgr) { return errh->error("LISTENMGR not specified"); } if (_listenmgr->cast("ListenManager") == 0) { return errh->error("LISTENMGR element is not a ListenManager"); } if (!_scrambleq) { return errh->error("SCRAMBLEQUEUE not specified"); } if (_scrambleq->cast("ScrambleQueue") == 0) { return errh->error("SCRAMBLEQUEUE element is not a ScrambleQueue"); } if (!_guessmgr) { return errh->error("GUESSMGR not specified"); } if (_guessmgr->cast("GuessManager") == 0) { return errh->error("GUESSMGR element is not a GuessManager"); } click_chatter("overheard packets done"); return res;} void OverheardPackets::fwd_packet(Packet *p){ if (p->packet_type_anno()!=Packet::OTHERHOST) { output(0).push(p); return; // packets are always new } else { struct click_ether *eth_p = (click_ether *)p->data(); EtherAddress src = EtherAddress(eth_p->ether_shost); EtherAddress dst = EtherAddress(eth_p->ether_dhost); uint16_t et = ntohs(eth_p->ether_type); if (et == _enc_ethtype) { click_chatter("encoded and dropped"); } StringAccum sa; sa << src << " " << dst << " " << et; click_chatter("%s: dropping a packet %s", id().cc(), sa.c_str()); p->kill(); return; }} //downstream element pushes packets to listenmanagervoidOverheardPackets::push(int, Packet *p){ // there seem to be 4 bytes at the end, we will take them out now p->take(4); click_chatter("%s packet of length %d", id().cc(), p->length()); int now = Timestamp::now().msec1(); // Check if encoded packet struct click_ether *eth_p = (click_ether *)p->data(); EtherAddress src = EtherAddress(eth_p->ether_shost); EtherAddress dst = EtherAddress(eth_p->ether_dhost); uint16_t et = ntohs(eth_p->ether_type); if (et == _enc_ethtype) { struct click_xorn_header *xorh = (struct click_xorn_header *)(eth_p + 1); int nentries = xorh->nentries(); for (int i = 0; i < nentries; i++) { IPAddress ip_t = IPAddress(xorh->get_entry_src(i)); uint16_t ipid_t = xorh->get_entry_ipid(i); _guessmgr->register_guess_single(src, ip_t, ipid_t); StringAccum sa_t; sa_t << "Encoded " << ip_t << " " << ipid_t; click_chatter("%s %s", id().cc(), sa_t.c_str()); } StringAccum sa; sa << et; click_chatter("%s got an encoded packet %s", id().cc(), sa.c_str()); fwd_packet(p); return; } const click_ip *iph = p->ip_header(); IPAddress ipsrc = IPAddress(iph->ip_src); uint16_t ipid = ntohs(iph->ip_id); if (src != _myea) { _guessmgr->register_guess(src, ipsrc, ipid); } if (dst == _myea) { click_chatter("%s packet addressed to me. just forward it", id().cc()); fwd_packet(p); return; } bool isnew = _listenmgr->register_packet_to_recp(p, now); if (isnew) { _scrambleq->wakeup_if_needed(); } fwd_packet(p);} CLICK_ENDDECLSEXPORT_ELEMENT(OverheardPackets)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -