📄 suppressor.cc
字号:
/* * suppressor.{cc,hh} -- element for Ethernet switch * John Jannotti * * 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 "suppressor.hh"#include <click/bitvector.hh>#include <click/confparse.hh>#include <click/error.hh>CLICK_DECLSSuppressor::Suppressor(){}Suppressor::~Suppressor(){}voidSuppressor::notify_ninputs(int i){ set_ninputs(i); set_noutputs(i);}boolSuppressor::set(int output, bool sup){ // Need to change anything? if (sup == suppressed(output)) return false; if (sup) suppress(output); else allow(output); return true;}intSuppressor::initialize(ErrorHandler *){ allow_all(); return 0;}voidSuppressor::push(int source, Packet *p){ if (suppressed(source)) { p->kill(); } else { // forward output(source).push(p); }}Packet *Suppressor::pull(int source){ if (suppressed(source)) { return 0; } else { return input(source).pull(); }}static Stringread_active(Element *e, void *thunk){ Suppressor *sup = static_cast<Suppressor *>(e); int port = (int) reinterpret_cast<long>(thunk); return (sup->suppressed(port) ? "false\n" : "true\n");}static intwrite_active(const String &in_s, Element *e, void *thunk, ErrorHandler *errh){ Suppressor *sup = static_cast<Suppressor *>(e); int port = (int) reinterpret_cast<long>(thunk); bool active; if (!cp_bool(cp_uncomment(in_s), &active)) return errh->error("active value must be boolean"); else { sup->set(port, active); return 0; }}static intwrite_reset(const String &, Element *e, void *, ErrorHandler *){ Suppressor *sup = static_cast<Suppressor *>(e); sup->allow_all(); return 0;}voidSuppressor::add_handlers(){ for (int i = 0; i < ninputs(); i++) { String s = "active" + String(i); add_read_handler(s, read_active, (void *)i); add_write_handler(s, write_active, (void *)i); } add_write_handler("reset", write_reset, 0);}CLICK_ENDDECLSEXPORT_ELEMENT(Suppressor)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -