9#include <click/pair.hh>
10#include <click/standard/threadsched.hh>
12# include <click/simclick.h>
22class HashMap_ArenaFactory;
33 inline Master*
master()
const;
39 inline bool dying()
const;
42 enum { STOP_RUNCOUNT = -2147483647 - 1 };
69 return visit(e, isoutput, port, visitor,
true);
78 void set_flow_code_override(
int eindex,
const String &flow_code);
85 static void set_handler(
const Element *e,
const String &hname, uint32_t flags, HandlerCallback callback,
void *read_user_data = 0,
void *write_user_data = 0);
89 enum { FIRST_GLOBAL_HANDLER = 0x40000000 };
95 void* attachment(
const String& aname)
const;
96 void*& force_attachment(
const String& aname);
97 void* set_attachment(
const String& aname,
void* value);
100 HashMap_ArenaFactory* arena_factory()
const;
102 inline ThreadSched* thread_sched()
const;
103 inline void set_thread_sched(ThreadSched* scheduler);
104 inline int home_thread_id(
const Element* e)
const;
105 inline void set_home_thread_id(
const Element* e,
int home_thread);
107 inline void non_fullpush();
131 static void static_initialize();
132 static void static_cleanup();
137 void add_requirement(
const String &type,
const String &value);
139 int add_connection(
int from_idx,
int from_port,
int to_idx,
int to_port,
bool is_context,
String context);
141 int add_module_ref(
struct module* module);
145 void set_hotswap_router(
Router* router);
164 virtual void notifyParent(
InitFuture* future);
174 class ChildrenFuture :
public InitFuture {
public:
175 ChildrenFuture(
Element* owner = 0);
181 void post(std::function<
int(
void)>,
Element* owner = 0);
187 class FctFuture :
public InitFuture {
public:
188 FctFuture(std::function<
int(
void)> f,
Element* owner = 0);
192 virtual int solve_initialize(
ErrorHandler* errh)
override;
196 class FctChildFuture :
public FctFuture {
public:
200 virtual int solve_initialize(
ErrorHandler* errh)
override;
205 ChildrenFuture* get_root_init_future() {
206 return &_root_init_future;
213 inline void set_foreground(
bool foreground);
231 bool operator==(
const Port &x)
const {
232 return idx == x.idx && port == x.port;
234 bool operator!=(
const Port &x)
const {
235 return idx != x.idx || port != x.port;
237 bool operator<(
const Port &x)
const {
238 return idx < x.idx || (idx == x.idx && port < x.port);
240 bool operator<=(
const Port &x)
const {
241 return idx < x.idx || (idx == x.idx && port <= x.port);
251 Connection() : _is_context(false), _context(
"") {
253 Connection(
int from_idx,
int from_port,
int to_idx,
int to_port) : _is_context(false), _context(
"") {
254 p[0] = Port(to_idx, to_port);
255 p[1] = Port(from_idx, from_port);
257 Connection(
int from_idx,
int from_port,
int to_idx,
int to_port,
bool is_context,
String context) {
258 p[0] = Port(to_idx, to_port);
259 p[1] = Port(from_idx, from_port);
260 _is_context = is_context;
264 const Port &operator[](
int i)
const {
265 assert(i >= 0 && i < 2);
268 Port &operator[](
int i) {
269 assert(i >= 0 && i < 2);
273 bool operator==(
const Connection &x)
const {
274 return p[0] == x.p[0] && p[1] == x.p[1];
276 bool operator<(
const Connection &x)
const {
277 return p[0] < x.p[0] || (p[0] == x.p[0] && p[1] < x.p[1]);
283 simclick_node_t *simnode()
const;
284 int sim_get_ifid(
const char* ifname);
285 int sim_listen(
int ifid,
int element);
286 int sim_if_ready(
int ifid);
287 int sim_write(
int ifid,
int ptype,
const unsigned char *,
int len,
288 simclick_simpacketinfo *pinfo);
289 int sim_incoming_packet(
int ifid,
int ptype,
const unsigned char *,
290 int len, simclick_simpacketinfo* pinfo);
291 void sim_trace(
const char* event);
292 int sim_get_node_id();
293 int sim_get_next_pkt_id();
294 int sim_if_promisc(
int ifid);
303 class RouterContextErrh;
306 ROUTER_NEW, ROUTER_PRECONFIGURE, ROUTER_PREINITIALIZE,
307 ROUTER_LIVE, ROUTER_DEAD
310 RUNNING_DEAD = -2, RUNNING_INACTIVE = -1, RUNNING_PREPARING = 0,
311 RUNNING_BACKGROUND = 1, RUNNING_ACTIVE = 2
315 ChildrenFuture _root_init_future;
320 bool _have_connections : 1;
321 mutable bool _conn_sorted : 1;
322 bool _have_configuration : 1;
323 volatile int _running;
333 struct element_landmark_t {
334 uint32_t first_landmarkid;
338 uint32_t _last_landmarkid;
355 enum { HANDLER_BUFSIZ = 256 };
366 struct notifier_signals_t {
367 enum { capacity = 4096 };
371 notifier_signals_t *next;
372 notifier_signals_t(
const String &n, notifier_signals_t *nx)
373 : name(n), nsig(0), next(nx) {
374 memset(&sig[0], 0,
sizeof(sig));
377 notifier_signals_t *_notifier_signals;
378 HashMap_ArenaFactory* _arena_factory;
380 ThreadSched* _thread_sched;
395 Connection *remove_connection(Connection *cp);
396 void hookup_error(
const Port &p,
bool isoutput,
const char *message,
402 const char *hard_flow_code_override(
int e)
const;
403 int processing_error(
const Connection &conn,
bool,
int,
ErrorHandler*);
406 void set_connections();
407 void sort_connections()
const;
408 int connindex_lower_bound(
bool isoutput,
const Port &port)
const;
411 inline int ngports(
bool isout)
const {
412 return _element_gport_offset[isout].
back();
414 inline int gport(
bool isoutput,
const Port &port)
const;
416 int hard_home_thread_id(
const Element *e)
const;
421 void initialize_handlers(
bool,
bool);
422 inline Handler* xhandler(
int)
const;
423 int find_ehandler(
int,
const String&,
bool allow_star)
const;
425 void store_local_handler(
int eindex,
Handler &h);
426 static void store_global_handler(
Handler &h);
430 static String router_read_handler(
Element *e,
void *user_data);
437 friend int Element::set_nports(
int,
int);
469 return _running == RUNNING_DEAD;
476 return _state == ROUTER_LIVE;
487 return _state > ROUTER_PRECONFIGURE;
502 return _elements.
size();
528 return _root_element;
532Router::thread_sched()
const
534 return _thread_sched;
538Router::set_thread_sched(ThreadSched* ts)
544Router::home_thread_id(
const Element* e)
const
547 return _element_home_thread_ids[e->
eindex() + 1];
549 return hard_home_thread_id(e);
553Router::set_home_thread_id(
const Element* e,
int home_thread_id)
555 _element_home_thread_ids[e->
eindex() + 1] = home_thread_id;
574Router::non_fullpush() {
575 _is_fullpush =
false;
583Router::name_info()
const
608 return _runcount.
value();
625 if (_flow_code_override.
size())
626 return hard_flow_code_override(eindex);
634 activate(
true, errh);
638Router::set_foreground(
bool foreground)
640 assert(_running >= RUNNING_BACKGROUND);
641 _running = foreground ? RUNNING_ACTIVE : RUNNING_BACKGROUND;
658 return find(name,
"", errh);
678 return visit(e,
true, port, visitor);
698 return visit(e,
false, port, visitor);
701inline HashMap_ArenaFactory*
702Router::arena_factory()
const
704 return _arena_factory;
719 return _hotswap_router;
723Handler::Handler(
const String &name)
724 : _name(name), _read_user_data(0), _write_user_data(0), _flags(0),
725 _use_count(0), _next_by_name(-1)
Base class for filter predicates for elements and ports.
Definition elemfilter.hh:7
Base class for Click elements.
Definition element.hh:42
int eindex() const
Return the element's index within its router.
Definition element.hh:524
Error reporting class.
Definition error.hh:90
Represents a router's handlers.
Definition handler.hh:19
Manages Click name databases.
Definition nameinfo.hh:11
An activity signal.
Definition notifier.hh:12
A router configuration.
Definition router.hh:28
bool handlers_ready() const
Return true iff the router's handlers have been initialized.
Definition router.hh:485
static const Handler * handler(const Element *e, const String &hname)
Return element e's handler named hname.
Definition router.cc:1982
String elandmark(int i) const
Returns element index eindex's landmark.
Definition router.cc:353
~Router()
Destroy the router.
Definition router.cc:110
int nelements() const
Returns the number of elements in the router.
Definition router.hh:500
int visit_upstream(Element *e, int port, RouterVisitor *visitor) const
Traverse the router configuration upstream of [port]e.
Definition router.hh:696
int32_t runcount() const
Return the router's runcount.
Definition router.hh:606
void adjust_runcount(int32_t delta)
Adjust the runcount by delta.
Definition router.cc:844
const String & ename(int i) const
Returns element index eindex's name.
Definition router.cc:292
void set_runcount(int32_t rc)
Set the runcount.
Definition router.cc:822
void set_econfiguration(int i, const String &conf)
Sets element index eindex's configuration string.
Definition router.cc:339
void unuse()
Decrement the router's reference count.
Definition router.cc:174
String configuration_string() const
Returns the router's initial configuration string.
Definition router.cc:2537
void please_stop_driver()
Request a driver stop by adjusting the runcount by -1.
Definition router.hh:614
static int hindex(const Element *e, const String &hname)
Return the handler index for element e's handler named hname.
Definition router.cc:2011
bool is_fullpush() const
Tell if the whole router is in full push mode.
Definition router.hh:569
void unparse_declarations(StringAccum &sa, const String &indent=String()) const
Unparse declarations of the router's elements into sa.
Definition router.cc:2350
const Vector< Element * > & elements() const
Returns a vector containing all the router's elements.
Definition router.hh:493
const char * flow_code_override(int eindex) const
Returns the overriding flow code for element e, if any.
Definition router.hh:623
static void add_read_handler(const Element *e, const String &hname, ReadHandlerCallback callback, void *user_data, uint32_t flags=0)
Add an e.hname read handler.
Definition router.cc:2079
Master * master() const
Return the Master object for this router.
Definition router.hh:591
String element_ports_string(const Element *e) const
Return a string representing e's ports.
Definition router.cc:2459
int visit_ports(Element *e, bool isoutput, int port, RouterVisitor *visitor) const
Traverse the router configuration from one of e's ports, passing per each ports.
Definition router.cc:1016
void unparse_requirements(StringAccum &sa, const String &indent=String()) const
Unparse the router's requirements into sa.
Definition router.cc:2329
bool running() const
Return true iff the router is currently running.
Definition router.hh:460
static int set_handler_flags(const Element *e, const String &hname, uint32_t set_flags, uint32_t clear_flags=0)
Change the e.hname handler's flags.
Definition router.cc:2190
void unparse(StringAccum &sa, const String &indent=String()) const
Unparse this router into sa.
Definition router.cc:2433
Router * hotswap_router() const
Returns the currently-installed router this router will eventually replace.
Definition router.hh:717
static void add_write_handler(const Element *e, const String &hname, WriteHandlerCallback callback, void *user_data, uint32_t flags=0)
Add an e.hname write handler.
Definition router.cc:2112
int visit_downstream(Element *e, int port, RouterVisitor *visitor) const
Traverse the router configuration downstream of e[port].
Definition router.hh:676
const String & econfiguration(int i) const
Returns element index eindex's configuration string.
Definition router.cc:325
void use()
Increment the router's reference count.
Definition router.hh:450
static void set_handler(const Element *e, const String &hname, uint32_t flags, HandlerCallback callback, void *read_user_data=0, void *write_user_data=0)
Add a comprehensive e.hname handler.
Definition router.cc:2153
int visit(Element *e, bool isoutput, int port, RouterVisitor *visitor, bool all_paths=false) const
Traverse the router configuration from one of e's ports, maximum once per port.
Definition router.cc:907
void unparse_connections(StringAccum &sa, const String &indent=String()) const
Unparse the router's connections into sa.
Definition router.cc:2370
String ename_context(int i) const
Returns element index eindex's name context.
Definition router.cc:307
static void element_hindexes(const Element *e, Vector< int > &result)
Return the handler indexes for element e's handlers.
Definition router.cc:2038
Element * find(const String &name, ErrorHandler *errh=0) const
Finds an element named name.
Definition router.hh:656
int new_notifier_signal(const char *name, NotifierSignal &signal)
Create a new basic signal.
Definition router.cc:2266
int upstream_elements(Element *e, int port, ElementFilter *filter, Vector< Element * > &result)
Search for elements upstream from e.
Definition router.cc:1143
bool initialized() const
Return true iff the router has been successfully initialized.
Definition router.hh:474
bool dying() const
Return true iff the router is in the process of being killed.
Definition router.hh:467
int downstream_elements(Element *e, int port, ElementFilter *filter, Vector< Element * > &result)
Search for elements downstream from e.
Definition router.cc:1114
Element * root_element() const
Returns this router's root element.
Definition router.hh:526
Element * element(int i) const
Returns the element with index i.
Definition router.hh:513
A set of Tasks scheduled on the same CPU.
Definition routerthread.hh:32
Base class for router configuration visitors.
Definition routervisitor.hh:17
Efficiently build up Strings from pieces.
Definition straccum.hh:28
A string of characters.
Definition string.hh:22
Represents a frequently-scheduled computational task.
Definition task.hh:49
Vector template.
Definition vector.hh:111
T & back()
Return a reference to the last element (number size()-1).
Definition vector.hh:334
size_type size() const
Return the number of elements.
Definition vector.hh:231
A 32-bit integer with support for atomic operations.
Definition atomic.hh:71
uint32_t value() const
Return the value.
Definition atomic.hh:179
Classes for synchronizing among multiple CPUs, particularly in the Linux kernel.
Support for Task, which triggers execution frequently.
Support for Timer, which triggers execution at a given time.
Click's vector container template.