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

📄 settxrate.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * settxrate.{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 "settxrate.hh"#include <clicknet/ether.h>#include <click/etheraddress.hh>#include <clicknet/wifi.h>CLICK_DECLSSetTXRate::SetTXRate()  : Element(1, 1){}SetTXRate::~SetTXRate(){}intSetTXRate::configure(Vector<String> &conf, ErrorHandler *errh){  _rate = 0;  _et = 0;  _offset = 0;  _max_retries = 0;  if (cp_va_parse(conf, this, errh,		  cpOptional,		  cpUnsigned, "rate", &_rate, 		  cpKeywords, 		  "RATE", cpUnsigned, "rate", &_rate, 		  "ETHTYPE", cpUnsigned, "Ethernet encapsulation type", &_et,		  "OFFSET", cpUnsigned, "offset", &_offset,		  "MAX_RETRIES", cpUnsigned, "max retries", &_max_retries,		  cpEnd) < 0) {    return -1;  }  if (_rate < 0) {    return errh->error("RATE must be >= 0");  }  if (_max_retries < 0) {    return errh->error("MAX_RETRIES must be >= 0");  }    return 0;}Packet *SetTXRate::simple_action(Packet *p_in){  uint8_t *dst_ptr = (uint8_t *) p_in->data() + _offset;  click_ether *eh = (click_ether *) dst_ptr;  if (_et && eh->ether_type != htons(_et)) {    return p_in;  }  struct click_wifi_extra *ceh = (struct click_wifi_extra *) p_in->all_user_anno();  ceh->magic = WIFI_EXTRA_MAGIC;  ceh->rate = _rate ? _rate : 2;  if (_max_retries) {    ceh->max_tries = _max_retries + 1;  } else {    ceh->max_tries = WIFI_MAX_RETRIES+1;  }  return p_in;}enum {H_RATE};StringSetTXRate::read_handler(Element *e, void *thunk){  SetTXRate *foo = (SetTXRate *)e;  switch((uintptr_t) thunk) {  case H_RATE: return String(foo->_rate) + "\n";  default:   return "\n";  }  }intSetTXRate::write_handler(const String &arg, Element *e,			 void *vparam, ErrorHandler *errh) {  SetTXRate *f = (SetTXRate *) e;  String s = cp_uncomment(arg);  switch((int)vparam) {  case H_RATE: {    unsigned m;    if (!cp_unsigned(s, &m))       return errh->error("rate parameter must be unsigned");    f->_rate = m;    break;  }  }  return 0;}voidSetTXRate::add_handlers(){  add_default_handlers(true);  add_read_handler("rate", read_handler, (void *) H_RATE);  add_write_handler("rate", write_handler, (void *) H_RATE);}CLICK_ENDDECLSEXPORT_ELEMENT(SetTXRate)

⌨️ 快捷键说明

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