⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filtertx.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
#include <click/config.h>#include <click/error.hh>#include <click/confparse.hh>#include <click/standard/scheduleinfo.hh>#include <clicknet/wifi.h>#include <clicknet/llc.h>#include <click/straccum.hh>#include <click/timestamp.hh>#include <clicknet/ether.h>#include <clicknet/ip.h>#include <click/ipaddress.hh>#include <click/etheraddress.hh>#include "filtertx.hh"#include "netcoding/xorheader_general.hh"#include "sr/srpacket.hh"CLICK_DECLSFilterTX::FilterTX()  : Element(1, 1),    _drops(0){}FilterTX::~FilterTX(){}voidFilterTX::notify_noutputs(int n) {  set_noutputs((n > 2 || n < 1) ? 1 : n);}intFilterTX::configure(Vector<String> &conf, ErrorHandler *errh){    if (cp_va_parse(conf, this, errh, 		    cpKeywords,		    cpEnd) < 0) {      return -1;    }  return 0;}Packet *FilterTX::simple_action(Packet *p){  struct click_wifi_extra *ceha = (struct click_wifi_extra *) p->all_user_anno();    struct click_wifi_extra *cehp = (struct click_wifi_extra *) p->data();  click_chatter("%s packet length %d", id().cc(), p->length());  /*     if (ceha->magic == WIFI_EXTRA_MAGIC) {     click_chatter("%s: ceha is set", id().cc());     } else if (cehp->magic == WIFI_EXTRA_MAGIC) {     click_chatter("%s: cehp is set", id().cc());     } else {     click_chatter("%s: neither is set", id().cc());     }     */  if ((ceha->magic == WIFI_EXTRA_MAGIC && ceha->flags & WIFI_EXTRA_TX) ||      (cehp->magic == WIFI_EXTRA_MAGIC && cehp->flags & WIFI_EXTRA_TX)) {    // now we will log stuff from this packet    click_wifi* w = (click_wifi *)p->data();    if (p->length() >= sizeof(struct click_wifi) + sizeof(struct click_llc)) {      if (!(w->i_fc[1] & WIFI_FC1_WEP)) {        uint8_t dir = w->i_fc[1] & WIFI_FC1_DIR_MASK;        EtherAddress bssid;        EtherAddress src;        EtherAddress dst;        switch (dir) {          case WIFI_FC1_DIR_NODS:            dst = EtherAddress(w->i_addr1);            src = EtherAddress(w->i_addr2);            bssid = EtherAddress(w->i_addr3);            break;          case WIFI_FC1_DIR_TODS:            bssid = EtherAddress(w->i_addr1);            src = EtherAddress(w->i_addr2);            dst = EtherAddress(w->i_addr3);            break;          case WIFI_FC1_DIR_FROMDS:            dst = EtherAddress(w->i_addr1);            bssid = EtherAddress(w->i_addr2);            src = EtherAddress(w->i_addr3);            break;          case WIFI_FC1_DIR_DSTODS:            dst = EtherAddress(w->i_addr1);            src = EtherAddress(w->i_addr2);            bssid = EtherAddress(w->i_addr3);            break;          default:            dst = EtherAddress(w->i_addr1);            src = EtherAddress(w->i_addr2);            bssid = EtherAddress(w->i_addr3);        }        struct click_llc *llc = (struct click_llc *)(w+1);        uint16_t et = ntohs(llc->llc_un.type_snap.ether_type);      	uint8_t *next = (uint8_t *)(llc+1);        if ((et == 0x0980) || (et == 0x0981) || (et == 0x0977) || (et == 0x0943)) {          click_chatter("%s: time %u, ethdst %s, length %u, mac_retries %u, mac_fail %d", id().cc(), Timestamp::now().msec1(), dst.s().c_str(), p->length(), (uint32_t)ceha->retries, (uint32_t)((ceha->flags) & WIFI_EXTRA_TX_FAIL));        }        if (et == 0x0977) {          struct click_xorn_header *xorh = (struct click_xorn_header *)(next);          int nentries = xorh->nentries();          for (unsigned int i = 0; i < xorh->nentries(); i++) {            StringAccum sa_t;            sa_t << "Ethtype " << xorh->get_entry_ethtype(i) << " IPID " << xorh->get_entry_ipid(i) << " Source " << IPAddress(xorh->get_entry_src(i)) << " Alias " << xorh->get_entry_alias(i) << " Length " << xorh->get_entry_len(i);            click_chatter("%s Coded packet %s", id().cc(), sa_t.c_str());          }        }        if (et == 0x0943) {      	  struct srpacket *srh = (struct srpacket *)next;      	  const click_ip *iph = (const click_ip *)(next + srh->hlen_wo_data());      	  click_chatter("%s: sending unencoded packet with ipsrc = %s, ipid = %u, dstea = %s", id().cc(), IPAddress(iph->ip_src).s().c_str(), ntohs(iph->ip_id), EtherAddress(dst).s().c_str());        }      }    }    if (noutputs() == 2) {      output(1).push(p);    } else {      p->kill();    }    return 0;  }    return p;}enum {H_DROPS };static StringFilterTX_read_param(Element *e, void *thunk){  FilterTX *td = (FilterTX *)e;  switch ((uintptr_t) thunk) {  case H_DROPS:     return String(td->_drops) + "\n";  default:    return String();  }}voidFilterTX::add_handlers(){  add_read_handler("drops", FilterTX_read_param, (void *) H_DROPS);}CLICK_ENDDECLSEXPORT_ELEMENT(FilterTX)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -