📄 filterbyhops.cc
字号:
/* * filterbyhops.{cc,hh} -- Grid packet filtering element * Douglas S. J. De Couto * * Copyright (c) 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 <stddef.h>#include "filterbyhops.hh"#include <click/confparse.hh>#include <click/error.hh>#include <click/router.hh>#include <clicknet/ether.h>#include <click/glue.hh>#include "grid.hh"#include <math.h>CLICK_DECLSFilterByGridHops::FilterByGridHops() : Element(1, 2){}FilterByGridHops::~FilterByGridHops(){}intFilterByGridHops::configure(Vector<String> &conf, ErrorHandler *errh){ int mh; int res = cp_va_parse(conf, this, errh, cpInteger, "max hops", &mh, cpEnd); if (res < 0) return res; if (mh < 0) return errh->error("max_hops must be positive"); _max_hops = mh; return res;}intFilterByGridHops::initialize(ErrorHandler *){ return 0;}voidFilterByGridHops::push(int, Packet *p){ assert(p); grid_nbr_encap *nb = (grid_nbr_encap *) (p->data() + sizeof(click_ether) + sizeof(grid_hdr)); if (ntohl(nb->hops_travelled) < _max_hops) output(0).push(p); else // ``too many hops'' output(1).push(p);}CLICK_ENDDECLSEXPORT_ELEMENT(FilterByGridHops)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -