[Xorp-hackers] Events and sockets in XORP

Pavlin Radoslavov pavlin at ICSI.Berkeley.EDU
Tue Feb 3 09:45:59 PST 2009


Victor Faion <vfaion at gmail.com> wrote:

> I think I understand the way the eventloop is supposed to be used a
> little better, basically every function needs to be scheduled on the
                           ~~~~~~~~~~~~~~

Small wording clarification: the above should read "every event
processing".
The functions/methods in the rest of your code are basically called
directly or indirectly by the callbacks.

The XRL related callbacks are are also event handling, except that
you don't deal directly with the eventloop (the underlying XRL
library does that for you).

> eventloop and have a callback. Am I allowed to chain events using
> callbacks (i.e., have a callback schedule an event)?
> 
> I changed the open/bind/listening to go like this:
> 
> int XrlBpsfNode::startup() {
>   const IPv4 localIP("146.169.3.2");
>   const uint32_t localPort(1337);
>   XLOG_INFO("%s\n", "Starting up XrlBpsfNode");
>   XrlSocket4V0p1Client cl(this);
>   if(!cl.send_tcp_open_and_bind("socket4/0.1/tcp_open_and_bind",
>         xrl_router().instance_name(),
>         localIP, localPort,
>         callback(this, &XrlBpsfNode::bind_cb))) {
>     XLOG_ERROR("%s\n", "Error opening and binding socket");
>     return(XORP_ERROR);
>   }
>   return (XORP_OK);
> }

The first argument to send_tcp_open_and_bind() must be the recepient
target name of that XRL, which typically is the FEA with targetname
of "fea".

> and then the bind_cb function schedules the function that calls
> send_tcp_listen, but I'm not sure if this is how I'm supposed to
> schedule things:
> 
> void XrlBpsfNode::bind_cb(const XrlError& e, const string* psockid) {
>   if (e != XrlError::OKAY()) {
>     XLOG_ERROR("Xrl Error: %s\n", e.str().c_str());
>     return;
>   }
>   server_sockid = *psockid;
>   const TimeVal b(1, 0);
>   bind_timer = event_loop.new_oneoff_after(
>       b, callback(this, &XrlBpsfNode::listen));
> }

You don't need to schedule a timer to call XrlBpsfNode::listen();
you can call XrlBpsfNode::listen() directly from within the bind_cb
callback.

Also, the TimeVal b() timer is allocated on the stack and will be
destroyed when bind_cb() returns; i.e., the scheduled callback for
that timer will never be called.

> 
> void XrlBpsfNode::listen() {
>   XrlSocket4V0p1Client cl(this);
>   cl.send_tcp_listen("socket4/0.1/tcp_listen", server_sockid, 100,
>       callback(this, &XrlBpsfNode::listen_cb));
> }

Here again the first argument of send_tcp_listen() must be "fea".

> void XrlBpsfNode::listen_cb(const XrlError& e) {
>   if (e != XrlError::OKAY())
>     XLOG_INFO("%s\n", "Error when listening on socket");
> }

> When I run xorp_rtrmgr I get an error regarding socket4:
> 
> 
> [ 2009/02/03 16:51:18  INFO xorp_rtrmgr:4034 RTRMGR +249
> master_conf_tree.cc execute ] Changed modules: bpsf, interfaces,
> firewall, fea
> [ 2009/02/03 16:51:18  INFO xorp_rtrmgr:4034 RTRMGR +101
> module_manager.cc execute ] Executing module: bpsf (bpsf/xorp_bpsf)
> [ 2009/02/03 16:51:18 INFO xorp_bpsf XrlBpsfTarget ] creating XrlBpsfNode
> [ 2009/02/03 16:51:18 INFO xorp_bpsf XrlBpsfTarget ] Starting up XrlBpsfNode
> [ 2009/02/03 16:51:18  WARNING xorp_rtrmgr:4034 XrlFinderTarget +407
> ../xrl/targets/finder_base.cc handle_finder_0_2_resolve_xrl ] Handling
> method for finder/0.2/resolve_xrl failed: XrlCmdError 102 Command
> failed Target "socket4" does not exist or is not enabled.

After you use target name of "fea" this error should go away.

> [ 2009/02/03 16:51:18  ERROR xorp_bpsf:4035 XrlBpsfTarget +275
> xrl_bpsf_node.cc bind_cb ] Xrl Error: 201 Resolve failed
> [ 2009/02/03 16:51:20  INFO xorp_rtrmgr:4034 RTRMGR +101
> module_manager.cc execute ] Executing module: interfaces
> (fea/xorp_fea)
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] MFEA enabled
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] CLI enabled
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] CLI started
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] MFEA enabled
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] CLI enabled
> [ 2009/02/03 16:51:21 INFO xorp_fea MFEA ] CLI started
> [ 2009/02/03 16:51:22  INFO xorp_rtrmgr:4034 RTRMGR +101
> module_manager.cc execute ] Executing module: firewall (fea/xorp_fea)
> [ 2009/02/03 16:51:26  INFO xorp_rtrmgr:4034 RTRMGR +101
> module_manager.cc execute ] Executing module: fea (fea/xorp_fea)
> [ 2009/02/03 16:51:32  INFO xorp_rtrmgr:4034 RTRMGR +2233 task.cc
> run_task ] No more tasks to run
> 
> 
> I'm not sure what you meant before when you said that I should
> register with the FEA to send/receive TCP. Does this mean calling
> something like send_register_class_event_interest? Many thanks for the
> help!

The registration is done when you send XRLs like tcp_open_and_bind.

Pavlin



More information about the Xorp-hackers mailing list