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

📄 filtertxrahulc

📁 COPE the first practical network coding scheme which is developped on click
💻
字号:
#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 "filtertx.hh"#include "netcoding/xorheader_general.hh"#include "netcoding/ackheader.hh"#include "netcoding/recpheader.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();/*    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) {          struct click_enc_ack *ackh = (struct click_enc_ack *)next;          uint16_t nentries = ackh->nentries();          for (int i = 0; i < nentries; i++) {            uint16_t nb = ackh->get_entry_nb(i);            uint16_t seq = ackh->get_entry_seq(i);            uint16_t bmap = ackh->get_entry_bmap(i);            click_chatter("%s: sending ack with srcea = %s, dstea = %s, nbralias = %u, seq = %u, bmap = %u at %u, mac max_tries = %u, mac retries = %u", id().cc(), src.s().c_str(), dst.s().c_str(), nb, seq, bmap, Timestamp::now().msec1(), ceha->max_tries, (uint32_t)ceha->retries);          }          next = next + ackh->get_hlen(nentries);          et = ntohs(ackh->_et_next);        }        // click_chatter("%s: et_next is %x", id().cc(), et);        if (et == 0x0981) {          struct click_enc_recp *recph = (struct click_enc_recp *)next;          next = next + recph->get_hlen(recph->nentries());          et = ntohs(recph->_et_next);        }        // click_chatter("%s: et_next is %x", id().cc(), et);        if (et == 0x0977) {          // encoded packet          struct click_xorn_header *xorh = (struct click_xorn_header *)next;          uint32_t nentries = xorh->nentries();          // click_chatter("%s: nentries is %u, xorh is %x", id().cc(), nentries, xorh);           for (unsigned int i = 0; i < nentries; i++) {            click_chatter("%s: sending encoded packet with ipsrc = %s, ipid = %u, nbr = %u, at %u, mac max_tries = %u, mac retries = %u", id().cc(), IPAddress(xorh->get_entry_src(i)).s().c_str(), xorh->get_entry_ipid(i), (uint16_t)xorh->get_entry_alias(i), Timestamp::now().msec1(), (uint32_t)ceha->max_tries, (uint32_t)ceha->retries);          }        } else 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, nseq = %u at %u, max max_tries = %u, mac retries = %u", id().cc(), IPAddress(iph->ip_src).s().c_str(), ntohs(iph->ip_id), EtherAddress(dst).s().c_str(), srh->nseq(), Timestamp::now().msec1(), (uint32_t)ceha->max_tries, (uint32_t)ceha->retries);        }      }    }    if (noutputs() == 2) {      output(1).push(p);    } else {      p->kill();    }    return 0;  }  else {    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) {          struct click_enc_ack *ackh = (struct click_enc_ack *)next;          uint16_t nentries = ackh->nentries();          for (int i = 0; i < nentries; i++) {            uint16_t nb = ackh->get_entry_nb(i);            uint16_t seq = ackh->get_entry_seq(i);            uint16_t bmap = ackh->get_entry_bmap(i);            click_chatter("%s: receiving ack with srcea = %s, dstea = %s, nbralias = %u, seq = %u, bmap = %u at %u, mac max_tries = %u, mac retries = %u", id().cc(), src.s().c_str(), dst.s().c_str(), nb, seq, bmap, Timestamp::now().msec1(), ceha->max_tries, (uint32_t)ceha->retries);          }          next = next + ackh->get_hlen(nentries);          et = ntohs(ackh->_et_next);        }        // click_chatter("%s: et_next is %x", id().cc(), et);        if (et == 0x0981) {          struct click_enc_recp *recph = (struct click_enc_recp *)next;          next = next + recph->get_hlen(recph->nentries());          et = ntohs(recph->_et_next);        }        // click_chatter("%s: et_next is %x", id().cc(), et);        if (et == 0x0977) {          // encoded packet          struct click_xorn_header *xorh = (struct click_xorn_header *)next;          uint32_t nentries = xorh->nentries();          // click_chatter("%s: nentries is %u, xorh is %x", id().cc(), nentries, xorh);           for (unsigned int i = 0; i < nentries; i++) {            click_chatter("%s: receiving encoded packet with ipsrc = %s, ipid = %u, nbr = %u", id().cc(), IPAddress(xorh->get_entry_src(i)).s().c_str(), xorh->get_entry_ipid(i), (uint16_t)xorh->get_entry_alias(i));          }        } else if (et == 0x0943) {          struct srpacket *srh = (struct srpacket *)next;          const click_ip *iph = (const click_ip *)(next + srh->hlen_wo_data());          click_chatter("%s: receiving unencoded packet with ipsrc = %s, ipid = %u, dstea = %s, nseq = %u at %u, max max_tries = %u, mac retries = %u", id().cc(), IPAddress(iph->ip_src).s().c_str(), ntohs(iph->ip_id), EtherAddress(dst).s().c_str(), srh->nseq(), Timestamp::now().msec1(), (uint32_t)ceha->max_tries, (uint32_t)ceha->retries);        }      }    }  }    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 + -