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

📄 rxstats.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * rxstats.{cc,hh} -- sets wifi txrate annotation on a packet * John Bicket * * Copyright (c) 2003 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 <click/error.hh>#include <click/glue.hh>#include <click/packet_anno.hh>#include <click/straccum.hh>#include <clicknet/ether.h>#include <clicknet/wifi.h>#include "rxstats.hh"CLICK_DECLSRXStats::RXStats()  : Element(1, 1){  static unsigned char bcast_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };  _bcast = EtherAddress(bcast_addr);}RXStats::~RXStats(){}intRXStats::configure(Vector<String> &conf, ErrorHandler *errh){  if (cp_va_parse(conf, this, errh,		  cpKeywords, 		  cpEnd) < 0) {    return -1;  }  return 0;}Packet *RXStats::simple_action(Packet *p_in){  click_ether *eh = (click_ether *) p_in->data();  EtherAddress src = EtherAddress(eh->ether_shost);  struct click_wifi_extra *ceh = (struct click_wifi_extra *) p_in->all_user_anno();      DstInfo *nfo = _neighbors.findp(src);  if (!nfo) {    DstInfo foo = DstInfo(src);    _neighbors.insert(src, foo);    nfo = _neighbors.findp(src);  }  nfo->_rate = ceh->rate;  nfo->_signal = ceh->rssi;  nfo->_noise = ceh->silence;  nfo->_packets++;  nfo->_sum_signal += ceh->rssi;  nfo->_sum_noise += ceh->silence;  click_gettimeofday(&nfo->_last_received);  return p_in;}enum {H_STATS, H_RESET};static StringRXStats_read_param(Element *e, void *thunk){  RXStats *td = (RXStats *)e;  switch ((uintptr_t) thunk) {  case H_STATS: {    struct timeval now;    click_gettimeofday(&now);        StringAccum sa;    for (RXStats::NIter iter = td->_neighbors.begin(); iter; iter++) {      RXStats::DstInfo n = iter.value();      struct timeval age = now - n._last_received;      sa << n._eth.s().cc();      sa << " rate " << n._rate;      sa << " signal " << n._signal;      sa << " noise " << n._noise;      sa << " avg_signal " << (n._packets ? (n._sum_signal / n._packets) : 0);      sa << " avg_noise " << (n._packets ? (n._sum_noise / n._packets) : 0);      sa << " total_signal " << n._sum_signal;      sa << " total_noise " << n._sum_noise;      sa << " packets " << n._packets;      sa << " last_received " << age << "\n";    }    return sa.take_string();  }  default:    return String();  }  }  static int RXStats_write_param(const String &in_s, Element *e, void *vparam,		      ErrorHandler *){  RXStats *f = (RXStats *)e;  String s = cp_uncomment(in_s);  switch((int)vparam) {  case H_RESET: f->_neighbors.clear(); return 0;  }  return 0;}	  voidRXStats::add_handlers(){  add_default_handlers(true);  add_read_handler("stats", RXStats_read_param, (void *) H_STATS);  add_write_handler("reset", RXStats_write_param, (void *) H_RESET);}// generate Vector template instance#include <click/bighashmap.cc>#if EXPLICIT_TEMPLATE_INSTANCEStemplate class HashMap<EtherAddress, RXStats::DstInfo>;#endifCLICK_ENDDECLSEXPORT_ELEMENT(RXStats)

⌨️ 快捷键说明

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