[Click] Calling "Handlers"

Eddie Kohler kohler at icir.org
Fri Dec 5 17:33:27 EST 2003


Hi Bow-Nan,

I don't blame you for getting confused by ControlSocket and PokeHandlers;
they are pretty difficult.  Particularly ControlSocket, my god.

> But, how do I Add and remove routes? There doesn't seem to be variables 
								^ "methods"?
> within LinearIPLookup that allow me to "add" the route or "remove" the 
> route. I guess what I mean is, I was expecting was something like:
> 
> LinearIPLookup(element IPRoutingTable, String Whattodo, Entry entry)
> 
> where IPRoutingTable is a routing table (maybe with entries stored in some 
> kind of array). and "Whattodo" is whether to "add", "remove" etc. and 
> entry is the entry to add,remove or left blank if just printing routing 
> table.
> 
> Is the concept of what I'm thinking about even correct? Because I just 
> don' tunderstand handlers at all. Any help would be great. Thanks

You are close to the right concept.  The thing you're missing is that
handlers are registered *with the Router object*, not with the element
itself.  This is so that the handlers can be called from external programs.
For example, when Click is installed in the kernel, each handler shows up
in the /click filesystem as a file -- a lot like a proc-file in Linux's
/proc filesystem. Read the click.o(8) manual page for more information.

Now, what about calling handlers from within a different Click element?
The easiest way is to use one of the static call_* methods on the
HandlerCall class.  And lucky for you, unlike many Click header files, the
handlercall.hh header file has some documentation :)

Quick summary: Say you wanted to call element "route_table"'s "add"
handler, passing it the value "128.0.0.0/8 1".  Then:

	#include <click/handlercall.hh>
	...
	Element *route_table = ...whatever...;
	ErrorHandler *errh = ...whatever... (or pass 0 for no error reporting);
	int success = HandlerCall::call_write(route_table, "add", "128.0.0.0/8 1", errh);
	/* success >= 0 if no error */

or if you have an element name, but not an element pointer:

	int success = HandlerCall::call_write("route_table.add", "128.0.0.0/8 1", errh);

Eddie


More information about the click mailing list