|
Click
|
A router configuration. More...
Classes | |
| class | InitFuture |
Public Member Functions | |
| enum | { STOP_RUNCOUNT = -2147483647 - 1 } |
| enum | { FIRST_GLOBAL_HANDLER = 0x40000000 } |
| Master * | master () const |
| Return the Master object for this router. | |
| bool | initialized () const |
| Return true iff the router has been successfully initialized. | |
| bool | handlers_ready () const |
| Return true iff the router's handlers have been initialized. | |
| bool | running () const |
| Return true iff the router is currently running. | |
| bool | dying () const |
| Return true iff the router is in the process of being killed. | |
| int32_t | runcount () const |
| Return the router's runcount. | |
| void | adjust_runcount (int32_t delta) |
| Adjust the runcount by delta. | |
| void | set_runcount (int32_t rc) |
| Set the runcount. | |
| void | please_stop_driver () |
| Request a driver stop by adjusting the runcount by -1. | |
| const Vector< Element * > & | elements () const |
| Returns a vector containing all the router's elements. | |
| int | nelements () const |
| Returns the number of elements in the router. | |
| Element * | element (int i) const |
| Returns the element with index i. | |
| Element * | root_element () const |
| Returns this router's root element. | |
| const String & | ename (int i) const |
| Returns element index eindex's name. | |
| String | ename_context (int i) const |
| Returns element index eindex's name context. | |
| String | elandmark (int i) const |
| Returns element index eindex's landmark. | |
| const String & | econfiguration (int i) const |
| Returns element index eindex's configuration string. | |
| void | set_econfiguration (int i, const String &conf) |
| Sets element index eindex's configuration string. | |
| Element * | find (const String &name, ErrorHandler *errh=0) const |
| Finds an element named name. | |
| Element * | find (const String &name, String context, ErrorHandler *errh=0) const |
| Finds an element named name. | |
| Element * | find (const String &name, const Element *context, ErrorHandler *errh=0) const |
| Finds an element named name. | |
| bool | element_can_reach (Element *a, Element *b) |
| 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. | |
| 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. | |
| int | visit_paths (Element *e, bool isoutput, int port, RouterVisitor *visitor) const |
| int | visit_downstream (Element *e, int port, RouterVisitor *visitor) const |
| Traverse the router configuration downstream of e[port]. | |
| int | visit_upstream (Element *e, int port, RouterVisitor *visitor) const |
| Traverse the router configuration upstream of [port]e. | |
| int | downstream_elements (Element *e, int port, ElementFilter *filter, Vector< Element * > &result) |
| Search for elements downstream from e. | |
| int | upstream_elements (Element *e, int port, ElementFilter *filter, Vector< Element * > &result) |
| Search for elements upstream from e. | |
| const char * | flow_code_override (int eindex) const |
| Returns the overriding flow code for element e, if any. | |
| void | set_flow_code_override (int eindex, const String &flow_code) |
| void * | attachment (const String &aname) const |
| void *& | force_attachment (const String &aname) |
| void * | set_attachment (const String &aname, void *value) |
| ErrorHandler * | chatter_channel (const String &channel_name) const |
| HashMap_ArenaFactory * | arena_factory () const |
| ThreadSched * | thread_sched () const |
| void | set_thread_sched (ThreadSched *scheduler) |
| int | home_thread_id (const Element *e) const |
| void | set_home_thread_id (const Element *e, int home_thread) |
| bool | is_fullpush () const |
| Tell if the whole router is in full push mode. | |
| void | non_fullpush () |
| String | configuration_string () const |
| Returns the router's initial configuration string. | |
| void | unparse (StringAccum &sa, const String &indent=String()) const |
| Unparse this router into sa. | |
| void | unparse_requirements (StringAccum &sa, const String &indent=String()) const |
| Unparse the router's requirements into sa. | |
| void | unparse_declarations (StringAccum &sa, const String &indent=String()) const |
| Unparse declarations of the router's elements into sa. | |
| void | unparse_connections (StringAccum &sa, const String &indent=String()) const |
| Unparse the router's connections into sa. | |
| String | element_ports_string (const Element *e) const |
| Return a string representing e's ports. | |
| static Element * | element (const Router *router, int i) |
| Return router's element with index eindex. | |
| static const Handler * | handler (const Element *e, const String &hname) |
| Return element e's handler named hname. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| static int | router_handler (int operation, String &data, Element *e, const Handler *handler, ErrorHandler *errh) |
| static int | hindex (const Element *e, const String &hname) |
| Return the handler index for element e's handler named hname. | |
| static const Handler * | handler (const Router *router, int hindex) |
| Return router's handler with index hindex. | |
| static void | element_hindexes (const Element *e, Vector< int > &result) |
| Return the handler indexes for element e's handlers. | |
Internal Functions | |
| Router (const String &configuration, Master *master) | |
| Create a router. | |
| ~Router () | |
| Destroy the router. | |
| void | use () |
| Increment the router's reference count. | |
| void | unuse () |
| Decrement the router's reference count. | |
| void | add_requirement (const String &type, const String &value) |
| int | add_element (Element *e, const String &name, const String &conf, const String &filename, unsigned lineno) |
| int | add_connection (int from_idx, int from_port, int to_idx, int to_port, bool is_context, String context) |
| int | add_module_ref (struct module *module) |
| Router * | hotswap_router () const |
| Returns the currently-installed router this router will eventually replace. | |
| void | set_hotswap_router (Router *router) |
| ChildrenFuture * | get_root_init_future () |
| int | initialize (ErrorHandler *errh) |
| void | activate (bool foreground, ErrorHandler *errh) |
| void | activate (ErrorHandler *errh) |
| void | set_foreground (bool foreground) |
| int | new_notifier_signal (const char *name, NotifierSignal &signal) |
| Create a new basic signal. | |
| String | notifier_signal_name (const atomic_uint32_t *signal) const |
| static void | static_initialize () |
| static void | static_cleanup () |
A router configuration.
| Router::Router | ( | const String & | configuration, |
| Master * | master | ||
| ) |
Create a router.
| configuration | router configuration |
| master | Master object |
Users generally do not call this function directly, instead creating a router object by calling Lexer functions (this function doesn't actually parse the configuration string). The router is registered with the Master object, but not initialized or activated.
| Router::~Router | ( | ) |
Destroy the router.
Users generally do not destroy Router objects directly, instead calling Router::unuse().
|
inline |
Return the Master object for this router.
never
|
inline |
Return true iff the router has been successfully initialized.
|
inline |
Return true iff the router's handlers have been initialized.
handlers_ready() returns false until each element's Element::add_handlers() method has been called. This happens after Element::configure(), but before Element::initialize().
|
inline |
Return true iff the router is currently running.
A running router has been successfully initialized (so running() implies initialized()), and has not stopped yet.
|
inline |
Return true iff the router is in the process of being killed.
|
inline |
Return the router's runcount.
The runcount is an integer that determines whether the router is running. A running router has positive runcount. Decrementing the router's runcount to zero or below will cause the router to stop, although elements like DriverManager can intercept the stop request and continue processing.
Elements request that the router stop its processing by calling adjust_runcount() or please_stop_driver().
| void Router::adjust_runcount | ( | int32_t | delta | ) |
Adjust the runcount by delta.
| delta | runcount adjustment |
Essentially performs the assignment "runcount += delta" with compensation for integer overflow. (For instance, if runcount is INT_MAX and delta is INT_MAX, the resulting runcount will be INT_MAX, not -2.) Uses atomic operations to ensure that runcount adjustments are not lost.
If the adjusted runcount is zero or negative, the router is asked to stop its normal processing. This will happen soon, although not necessarily immediately. Once it stops, the router will search for an element to manage the stop event (see the Script and DriverManager elements). If no such element exists, or the script completes without raising the runcount, the router stops permanently.
| void Router::set_runcount | ( | int32_t | rc | ) |
Set the runcount.
| rc | new runcount |
Sets the runcount to a specific value. If the new runcount is zero or negative, stops the router; see adjust_runcount().
|
inline |
Request a driver stop by adjusting the runcount by -1.
Returns a vector containing all the router's elements.
|
inline |
Returns the number of elements in the router.
|
inline |
Returns the element with index i.
| i | element index, or -1 for root_element() |
This function returns the element with index i. If i == -1, returns root_element(). If i is otherwise out of range, returns null.
|
inline |
Returns this router's root element.
Every router has a root Element. This element has Element::eindex() -1 and name "". It is not configured or initialized, and doesn't appear in the configuration; it exists only for convenience, when other Click code needs to refer to some arbitrary element at the top level of the compound element hierarchy.
Return router's element with index eindex.
| router | the router (may be null) |
| eindex | element index, or -1 for router->root_element() |
This function returns router's element with index eindex. If router is null or eindex is out of range, returns null.
| const String & Router::ename | ( | int | eindex | ) | const |
Returns element index eindex's name.
| eindex | element index |
Returns the empty string if eindex is out of range.
| String Router::ename_context | ( | int | eindex | ) | const |
Returns element index eindex's name context.
| eindex | element index |
The result is the context prefix for the element's name. This is the string up to, and including, the last slash in the element's name. Returns the empty string if eindex is out of range.
| String Router::elandmark | ( | int | eindex | ) | const |
Returns element index eindex's landmark.
| eindex | element index |
A landmark is a short string specifying where the element was defined. A typical landmark has the form "file:linenumber", as in "file.click:30". Returns the empty string if eindex is out of range.
| const String & Router::econfiguration | ( | int | eindex | ) | const |
Returns element index eindex's configuration string.
| eindex | element index |
Returns the empty string if eindex is out of range.
| void Router::set_econfiguration | ( | int | eindex, |
| const String & | conf | ||
| ) |
Sets element index eindex's configuration string.
| eindex | element index |
| conf | configuration string |
Does nothing if eindex is out of range.
|
inline |
Finds an element named name.
| name | element name |
| errh | optional error handler |
Returns the unique element named name, if any. If no element named name is found, reports an error to errh and returns null. The error is "<tt>no element named 'name'</tt>". If errh is null, no error is reported.
This function is equivalent to find(const String&, String, ErrorHandler*) with a context argument of the empty string.
| Element * Router::find | ( | const String & | name, |
| String | context, | ||
| ErrorHandler * | errh = 0 |
||
| ) | const |
Finds an element named name.
| name | element name |
| context | compound element context |
| errh | optional error handler |
Searches for an element named name in the compound element context specified by context, returning the first element found. For example, if context was "aaa/bbb/ccc/", then find() would search for elements named aaa/bbb/ccc/name, aaa/bbb/name, aaa/name, and finally name, returning the first element found. If nonempty, context should end with a slash.
If no element named name is found, reports an error to errh and returns null. The error is "<tt>no element named 'name'</tt>". If errh is null, no error is reported.
| Element * Router::find | ( | const String & | name, |
| const Element * | context, | ||
| ErrorHandler * | errh = 0 |
||
| ) | const |
Finds an element named name.
| name | element name |
| context | compound element context |
| errh | optional error handler |
Searches for an element named name in the compound element context specified by context, returning the first element found. For example, if ename(context) was "aaa/bbb/element", then find(name, context, errh) is equivalent to find(name, "aaa/bbb/", errh), and will search for elements named aaa/bbb/name, aaa/name, and finally name.
If no element named name is found, reports an error to errh and returns null. The error is "<tt>no element named 'name'</tt>". If errh is null, no error is reported.
| int Router::visit | ( | Element * | first_element, |
| bool | forward, | ||
| int | first_port, | ||
| RouterVisitor * | visitor, | ||
| bool | all_paths = false |
||
| ) | const |
Traverse the router configuration from one of e's ports, maximum once per port.
| e | element to start search |
| forward | true to search down from outputs, false to search up from inputs |
| port | port (or -1 to search all ports) |
| visitor | RouterVisitor traversal object |
Calls visitor ->visit() on each reachable port starting from a port on e. Follows connections and traverses inside elements from port to port by Element::flow_code(). The visitor can stop a traversal path by returning false from visit().
| int Router::visit_ports | ( | Element * | first_element, |
| bool | forward, | ||
| int | first_port, | ||
| RouterVisitor * | visitor | ||
| ) | const |
Traverse the router configuration from one of e's ports, passing per each ports.
| e | element to start search |
| forward | true to search down from outputs, false to search up from inputs |
| port | port (or -1 to search all ports) |
| visitor | RouterVisitor traversal object |
Calls visitor ->visit() on each reachable port starting from a port on e. Follows connections and traverses inside elements from port to port by Element::flow_code(). The visitor can stop a traversal path by returning false from visit().
|
inline |
Traverse the router configuration downstream of e[port].
| e | element to start search |
| port | output port (or -1 to search all output ports) |
| visitor | RouterVisitor traversal object |
Calls visitor ->visit() on each reachable input port starting from the output port e[port]. Follows connections and traverses inside elements from port to port by Element::flow_code(). The visitor can stop a traversal path by returning false from visit().
|
inline |
Traverse the router configuration upstream of [port]e.
| e | element to start search |
| port | input port (or -1 to search all input ports) |
| visitor | RouterVisitor traversal object |
Calls visitor ->visit() on each reachable output port starting from the input port [port]e. Follows connections and traverses inside elements from port to port by Element::flow_code(). The visitor can stop a traversal path by returning false from visit().
| int Router::downstream_elements | ( | Element * | e, |
| int | port, | ||
| ElementFilter * | filter, | ||
| Vector< Element * > & | result | ||
| ) |
Search for elements downstream from e.
| e | element to start search |
| port | output port (or -1 to search all output ports) |
| filter | ElementFilter naming elements that stop the search |
| result | stores results |
This function searches the router configuration graph, starting from e's output port port and proceeding downstream along element connections, and inside elements from port to port by Element::flow_code(). All found elements are stored in result.
If filter != NULL, then each found port is passed to filter's ElementFilter::check_match() function to check whether to stop the search. For example, if filter is CastElementFilter("Storage"), then the search will stop after any Storage element. The result will then include the Storage elements and any elements in between e and the Storage elements.
| int Router::upstream_elements | ( | Element * | e, |
| int | port, | ||
| ElementFilter * | filter, | ||
| Vector< Element * > & | result | ||
| ) |
Search for elements upstream from e.
| e | element to start search |
| port | input port (or -1 to search all ports) |
| filter | ElementFilter naming elements that stop the search |
| result | stores results |
This function searches the router configuration graph, starting from e's input port port and proceeding upstream along element connections, and inside elements from port to port by Element::flow_code(). All found elements are stored in result.
If filter != NULL, then each found port is passed to filter's ElementFilter::check_match() function to check whether to stop the search. For example, if filter is CastElementFilter("Storage"), then the search will stop after any Storage element. The result will then include the Storage elements and any elements in between e and the Storage elements.
|
inline |
Returns the overriding flow code for element e, if any.
| eindex | element index |
Return element e's handler named hname.
| e | element, if any |
| hname | handler name |
Searches for element e's handler named hname. Returns NULL if no such handler exists. If e is NULL or equal to some root_element(), then this function searches for a global handler named hname.
The return Handler pointer remains valid until the named handler is changed in some way (add_read_handler(), add_write_handler(), set_handler(), or set_handler_flags()).
|
static |
Add an e.hname read handler.
| e | element, if any |
| hname | handler name |
| callback | read callback |
| user_data | user data for read callback |
| flags | additional flags to set (Handler::flags()) |
Adds a read handler named hname for element e. If e is NULL or equal to some root_element(), then adds a global read handler. The handler's callback function is callback. When the read handler is triggered, Click will call callback(e, user_data).
Any previous read handler with the same name and element is replaced. Any comprehensive handler function (see set_handler()) is replaced. Any write-only handler (add_write_handler()) remains.
The new handler's flags equal the old flags or'ed with flags. Any special flags in flags are ignored.
To create a read handler with parameters, you must use set_handler().
|
static |
Add an e.hname write handler.
| e | element, if any |
| hname | handler name |
| callback | read callback |
| user_data | user data for write callback |
| flags | additional flags to set (Handler::flags()) |
Adds a write handler named hname for element e. If e is NULL or equal to some root_element(), then adds a global write handler. The handler's callback function is callback. When the write handler is triggered, Click will call callback(data, e, user_data, errh).
Any previous write handler with the same name and element is replaced. Any comprehensive handler function (see set_handler()) is replaced. Any read-only handler (add_read_handler()) remains.
The new handler's flags equal the old flags or'ed with flags. Any special flags in flags are ignored.
|
static |
Add a comprehensive e.hname handler.
| e | element, if any |
| hname | handler name |
| flags | flags to set (Handler::flags()) |
| callback | comprehensive handler callback |
| read_user_data | read user data for callback |
| write_user_data | write user data for callback |
Sets a handler named hname for element e. If e is NULL or equal to some root_element(), then sets a global handler. The handler's callback function is callback. The resulting handler is a read handler if flags contains Handler::f_read, and a write handler if flags contains Handler::f_write. If the flags contain Handler::f_read_param, then any read handler will accept parameters.
When the handler is triggered, Click will call callback(operation, data, e, h, errh), where:
Any previous handlers with the same name and element are replaced.
|
static |
Change the e.hname handler's flags.
| e | element, if any |
| hname | handler name |
| set_flags | flags to set (Handler::flags()) |
| clear_flags | flags to clear (Handler::flags()) |
Changes the handler flags for the handler named hname on element e. If e is NULL or equal to some root_element(), then changes a global handler. The handler's flags are changed by clearing the clear_flags and then setting the set_flags, except that the special flags (Handler::f_special) are unchanged.
Return the handler index for element e's handler named hname.
| e | element, if any |
| hname | handler name |
Searches for element e's handler named hname. Returns -1 if no such handler exists. If e is NULL or equal to some root_element(), then this function searches for a global handler named hname.
The returned integer is a handler index, which is a number that identifies the handler. An integer >= FIRST_GLOBAL_HANDLER corresponds to a global handler.
Return router's handler with index hindex.
| router | the router |
| hindex | handler index (Router::hindex()) |
Returns the Handler object on router with handler index hindex. If hindex >= FIRST_GLOBAL_HANDLER, then returns a global handler. If hindex is < 0 or corresponds to no existing handler, returns null.
The return Handler pointer remains valid until the named handler is changed in some way (add_read_handler(), add_write_handler(), set_handler(), or set_handler_flags()).
Return the handler indexes for element e's handlers.
| e | element, if any |
| result | collector for handler indexes |
Iterates over all element e's handlers, and appends their handler indexes to result. If e is NULL or equal to some root_element(), then iterates over the global handlers.
|
inline |
Tell if the whole router is in full push mode.
If true, all packets of this router are always handled by the same thread (but mutltiple threads can handle different packets). This means that sharing can be disabled.
| String Router::configuration_string | ( | ) | const |
Returns the router's initial configuration string.
never
| void Router::unparse | ( | StringAccum & | sa, |
| const String & | indent = String() |
||
| ) | const |
Unparse this router into sa.
Calls unparse_requirements(), unparse_declarations(), and unparse_connections(), in that order. Each line is prefixed by indent.
| void Router::unparse_requirements | ( | StringAccum & | sa, |
| const String & | indent = String() |
||
| ) | const |
Unparse the router's requirements into sa.
never
Appends at most one require() statement to sa.
| void Router::unparse_declarations | ( | StringAccum & | sa, |
| const String & | indent = String() |
||
| ) | const |
Unparse declarations of the router's elements into sa.
Appends this router's elements' declarations to sa. If the router is initialized, then each element's configuration string is found by Element::configuration(), which might include post-initialization changes.
| void Router::unparse_connections | ( | StringAccum & | sa, |
| const String & | indent = String() |
||
| ) | const |
Unparse the router's connections into sa.
Appends this router's connections to sa in parseable format.
Return a string representing e's ports.
| e | element |
The returned string is suitable for an element's ports handler. It lists the input ports, then the output ports. For example:
1 input push~ - InfiniteSource@1 [0], InfiniteSource@4 [0] 1 output push~ - [0] Align@3
In the port lines, the first column describes the processing type (a tilde suffix represents an agnostic port); the second column lists any packet statistics available; and the third column lists other ports that are connected to this port.
|
inline |
Increment the router's reference count.
Routers are reference counted objects. A Router is created with one reference, which is held by its Master object. Normally the Router and all its elements will be deleted when the Master drops this reference, but you can preserve the Router for longer by adding a reference yourself.
| void Router::unuse | ( | ) |
Decrement the router's reference count.
Destroys the router if the reference count decrements to zero.
|
inline |
Returns the currently-installed router this router will eventually replace.
This function is only meaningful during a router's initialization. If this router was installed with the hotswap option, then hotswap_router() will return the currently-installed router that this router will eventually replace (assuming error-free initialization). Otherwise, hotswap_router() will return 0.
| int Router::new_notifier_signal | ( | const char * | name, |
| NotifierSignal & | signal | ||
| ) |
Create a new basic signal.
| name | signal name | |
| [out] | signal | set to new signal |
Creates a new basic NotifierSignal and stores it in signal. The signal is initially active.