📄 txstat.cc
字号:
/* * txstat.{cc,hh} -- extract per-packet link tx counts * John Bicket * * Copyright (c) 1999-2002 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include <click/confparse.hh>#include <clicknet/ether.h>#include <click/error.hh>#include <click/glue.hh>#include <click/timer.hh>#include <click/straccum.hh>#include <clicknet/wifi.h>#include <elements/wifi/txstat.hh>CLICK_DECLSTXStat::TXStat(){ add_input(); static unsigned char bcast_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; _bcast = EtherAddress(bcast_addr);}TXStat::~TXStat(){}voidTXStat::notify_noutputs(int n) { set_noutputs(n > 0 ? 1 : 0); }intTXStat::configure(Vector<String> &conf, ErrorHandler *errh){ int res = cp_va_parse(conf, this, errh, cpEtherAddress, "Source Ethernet address", &_eth, cpKeywords, cpEnd); return res; }intTXStat::initialize(ErrorHandler *errh){ if (noutputs() > 0) { if (!_eth) return errh->error("Source IP and Ethernet address must be specified to send probes"); } return 0;}Packet *TXStat::simple_action(Packet *p_in){ click_ether *eh = (click_ether *) p_in->data(); //click_chatter("SRCR %s: got sr packet", _ip.s().cc()); EtherAddress dst = EtherAddress(eh->ether_dhost); if (dst == _bcast) { //click_chatter("TXStat %s: broadcast packet", _eth.s().cc()); p_in->kill(); return 0; } struct click_wifi_extra *ceh = (struct click_wifi_extra *) p_in->all_user_anno(); //int long_retries = p_in->user_anno_c (TX_ANNO_LONG_RETRIES); bool success = !(ceh->flags & WIFI_EXTRA_TX_FAIL); int rate = ceh->rate; TXNeighborInfo *nfo = _neighbors.findp(dst); if (!nfo) { TXNeighborInfo foo = TXNeighborInfo(dst); _neighbors.insert(dst, foo); nfo = _neighbors.findp(dst); } nfo->_packets_sent++; //nfo->_long_retries += long_retries; //nfo->_short_retries += short_retries; nfo->_rate = rate; //click_chatter("TXStat %s: long=%d, short=%d, fail=%s", //_eth.s().cc(), long_retries, short_retries, failure ? "true" : "false"); if (!success) { nfo->_failures++; } p_in->kill(); return 0;}StringTXStat::static_print_tx_stats(Element *e, void *){ TXStat *n = (TXStat *) e; return n->print_tx_stats();}String TXStat::print_tx_stats() { StringAccum sa; for (TXNIter iter = _neighbors.begin(); iter; iter++) { TXNeighborInfo nfo = iter.value(); sa << nfo._eth.s().cc() << "\n"; sa << " packets sent :" << nfo._packets_sent << "\n"; sa << " failures :" << nfo._failures << "\n"; sa << " long_retries :" << nfo._long_retries << "\n"; sa << " short_retries:" << nfo._short_retries << "\n"; sa << " rate :" << nfo._rate << "\n"; sa << "\n"; } return sa.take_string();}voidTXStat::add_handlers(){ add_read_handler("tx_stats", static_print_tx_stats, 0);}EXPORT_ELEMENT(TXStat)#include <click/bighashmap.cc>#include <click/vector.cc>CLICK_ENDDECLS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -