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

📄 compblock.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * compblock.{cc,hh} -- element blocks packets based on ratio of rate * annotations set by IPRateMonitor. * Benjie Chen * * Copyright (c) 1999-2000 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 "compblock.hh"#include <click/error.hh>#include <click/confparse.hh>#include <click/packet_anno.hh>CLICK_DECLSCompareBlock::CompareBlock()  : Element(1, 2), _fwd_weight(0), _rev_weight(1){}CompareBlock::~CompareBlock(){}intCompareBlock::configure(Vector<String> &conf, ErrorHandler *errh){  _bad = 0;  return cp_va_parse(conf, this, errh,		     cpInteger, "forward weight", &_fwd_weight,		     cpInteger, "reverse weight", &_rev_weight,		     cpInteger, "threshold", &_thresh,		     cpEnd);}voidCompareBlock::push(int, Packet *p){  // int network = *((unsigned char *)&p->ip_header()->ip_src);  int fwd = FWD_RATE_ANNO(p);  if (fwd < 1) fwd = 1;  int rev = REV_RATE_ANNO(p);  if (rev < 1) rev = 1;  if ((fwd > _thresh || rev > _thresh) &&      _fwd_weight * fwd > _rev_weight * rev) {    output(1).push(p);  } else    output(0).push(p);}// HANDLERSintCompareBlock::fwd_weight_write_handler(const String &conf, Element *e,     				       void *, ErrorHandler *errh){  Vector<String> args;  cp_argvec(conf, args);  CompareBlock* me = (CompareBlock *) e;  if(args.size() != 1) {    return errh->error("expecting one integer");  }  int weight;  if(!cp_integer(args[0], &weight)) {    return errh->error("not an integer");  }  me->_fwd_weight = weight;  return 0;}intCompareBlock::rev_weight_write_handler(const String &conf, Element *e,     				       void *, ErrorHandler *errh){  Vector<String> args;  cp_argvec(conf, args);  CompareBlock* me = (CompareBlock *) e;  if(args.size() != 1) {    return errh->error("expecting one integer");  }  int weight;  if(!cp_integer(args[0], &weight)) {    return errh->error("not an integer");  }  me->_rev_weight = weight;  return 0;}intCompareBlock::thresh_write_handler(const String &conf, Element *e,     				   void *, ErrorHandler *errh){  Vector<String> args;  cp_argvec(conf, args);  CompareBlock* me = (CompareBlock *) e;  if(args.size() != 1) {    return errh->error("expecting one integer");  }  int thresh;  if(!cp_integer(args[0], &thresh)) {    return errh->error("not an integer");  }  me->_thresh = thresh;  return 0;}StringCompareBlock::fwd_weight_read_handler(Element *e, void *){  CompareBlock *me = (CompareBlock *) e;  return String(me->_fwd_weight) + "\n";}StringCompareBlock::rev_weight_read_handler(Element *e, void *){  CompareBlock *me = (CompareBlock *) e;  return String(me->_rev_weight) + "\n";}StringCompareBlock::thresh_read_handler(Element *e, void *){  CompareBlock *me = (CompareBlock *) e;  return String(me->_thresh) + "\n";}voidCompareBlock::add_handlers(){  add_read_handler("fwd_weight", fwd_weight_read_handler, 0);  add_write_handler("fwd_weight", fwd_weight_write_handler, 0);  add_read_handler("rev_weight", rev_weight_read_handler, 0);  add_write_handler("rev_weight", rev_weight_write_handler, 0);}CLICK_ENDDECLSEXPORT_ELEMENT(CompareBlock)ELEMENT_MT_SAFE(CompareBlock)

⌨️ 快捷键说明

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