[Xorp-hackers] Events and sockets in XORP

Victor Faion vfaion at gmail.com
Tue Feb 3 10:46:10 PST 2009


On Tue, Feb 3, 2009 at 17:45, Pavlin Radoslavov
<pavlin at icsi.berkeley.edu> wrote:
> 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
>

Hmm, when I changed the first parameter to be "fea" I get pretty much
the same error, even though xorp_fea seems to startup:

[ 2009/02/03 18:29:02  INFO xorp_rtrmgr:8229 RTRMGR +249
master_conf_tree.cc execute ] Changed modules: bpsf, interfaces,
firewall, fea
[ 2009/02/03 18:29:02  INFO xorp_rtrmgr:8229 RTRMGR +101
module_manager.cc execute ] Executing module: bpsf (bpsf/xorp_bpsf)
[ 2009/02/03 18:29:02 INFO xorp_bpsf XrlBpsfTarget ] creating XrlBpsfNode
[ 2009/02/03 18:29:02 INFO xorp_bpsf XrlBpsfTarget ] Starting up XrlBpsfNode
[ 2009/02/03 18:29:02  WARNING xorp_rtrmgr:8229 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 "fea" does not exist or is not enabled.
[ 2009/02/03 18:29:02  ERROR xorp_bpsf:8230 XrlBpsfTarget +277
xrl_bpsf_node.cc bind_cb ] Xrl Error: 201 Resolve failed
[ 2009/02/03 18:29:04  INFO xorp_rtrmgr:8229 RTRMGR +101
module_manager.cc execute ] Executing module: interfaces
(fea/xorp_fea)
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] MFEA enabled
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] CLI enabled
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] CLI started
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] MFEA enabled
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] CLI enabled
[ 2009/02/03 18:29:05 INFO xorp_fea MFEA ] CLI started
[ 2009/02/03 18:29:06  INFO xorp_rtrmgr:8229 RTRMGR +101
module_manager.cc execute ] Executing module: firewall (fea/xorp_fea)
[ 2009/02/03 18:29:10  INFO xorp_rtrmgr:8229 RTRMGR +101
module_manager.cc execute ] Executing module: fea (fea/xorp_fea)
[ 2009/02/03 18:29:16  INFO xorp_rtrmgr:8229 RTRMGR +2233 task.cc
run_task ] No more tasks to run

Not sure how to control the order of the process startups, seems the
fea is starting after my process.

I changed bind_cb to call listen directly. Does it matter that I call
send_tcp_open_and_bind and send_tcp_listen on two different instances
of XrlSocket4V0p1Client? I tried to declare XrlSocket4V0p1Client in
the header and initialize it in the constructor but I got an error:
"XrlSocket4V0p1Client does not name a type"

Also, I was passing in the instance of the eventloop to the
constructor, but I guess I don't need to do this. Do I need to do
anything directly with it besides call its run function in my main
function?

Victor



More information about the Xorp-hackers mailing list