[Xorp-hackers] Events and sockets in XORP
Victor Faion
vfaion at gmail.com
Tue Feb 3 09:06:52 PST 2009
On Mon, Feb 2, 2009 at 19:48, Pavlin Radoslavov
<pavlin at icsi.berkeley.edu> wrote:
>> > First you need to open the TCP socket by using one of the tcp_open*
>> > XRLs, which will give you the sockid. Then you can use sockid for
>> > additional operations on the socket.
>> >
>> > You might also have a look at fea/test_xrl_sockets4_tcp.cc for usage
>> > of some of the TCP-related XRLs.
>> >
>> > Pavlin
>> >
>>
>>
>> I was trying to do something like this:
>>
>> int XrlBpsfNode::startup() {
>> const IPv4 localIP("146.169.3.2");
>> const uint32_t localPort(1337);
>> printf("%s\n", "Starting up XrlBpsfNode");
>> XrlSocket4V0p1Client cl(this);
>> if(!cl.send_tcp_open_and_bind("socket4/0.1/tcp_open_and_bind",
>> "bpsf/0.1", localIP, localPort,
>> callback(this, &XrlBpsfNode::bind_cb))) {
>> printf("%s\n", "Error opening and binding socket");
>> return(XORP_ERROR);
>> }
>> return cl.send_tcp_listen("socket4/0.1/tcp_listen", server_sockid, 100,
>> callback(this, &XrlBpsfNode::listen_cb));
>> }
>
> In the above code you cannot call send_tcp_open_and_bind() and
> send_tcp_listen() back-to-back. You must return to the eventloop
> after you call the first XRL, because only when the bind_cb is
> called you will get the sockid for the new socket.
>
> In other words, only after bind_cb is called you can call the rest
> of the XRL(s) that require sockid.
>
>> but when I run make I keep getting errors like this:
>>
>> g++ -g -Werror -W -Wall -Wwrite-strings -Wcast-qual -Wpointer-arith
>> -Wcast-align -Woverloaded-virtual -ftemplate-depth-25 -pipe -o
>> xorp_bpsf xorp_bpsf.o ./.libs/libbpsf.a
>> ../xrl/targets/.libs/libbpsfbase.a ../libxipc/.libs/libxipc.a
>> ../libcomm/.libs/libcomm.a ../libxorp/.libs/libxorp.a -lpcap -lcrypto
>> -lrt
>> ./.libs/libbpsf.a(xrl_bpsf_node.o): In function `XrlBpsfNode::startup()':
>> /root/project/xorp1.6/xorp-1.6/bpsf/xrl_bpsf_node.cc:37: undefined
>> reference to `XrlSocket4V0p1Client::send_tcp_open_and_bind(char
>> const*, std::basic_string<char, std::char_traits<char>,
>> std::allocator<char> > const&, IPv4 const&, unsigned int const&,
>> ref_ptr<XorpCallback2<void, XrlError const&, std::basic_string<char,
>> std::char_traits<char>, std::allocator<char> > const*> > const&)'
>> /root/project/xorp1.6/xorp-1.6/bpsf/xrl_bpsf_node.cc:44: undefined
>> reference to `XrlSocket4V0p1Client::send_tcp_listen(char const*,
>> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> const&, unsigned int const&, ref_ptr<XorpCallback1<void, XrlError
>> const&> > const&)'
>> collect2: ld returned 1 exit status
>> make: *** [xorp_bpsf] Error 1
>>
>>
>> even though I have included "xrl/interfaces/socket4_xif.hh" where
>> those functions are defined. I'm not sure if the target destination
>> I'm passing ("bpsf/0.1") is correct. This is the process I wrote which
>> implements socket4_user/0.1, but for some reason the compiler doesn't
>> like it.
>
> I think the issue is that you need to link your program with the
> particular XRL interface library as well:
>
> (top_builddir)/xrl/interfaces/libsocket4xif.la
>
> For reference, see the test_xrl_sockets4_tcp entry in
> fea/Makefile.am .
>
> Pavlin
>
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
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);
}
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));
}
void XrlBpsfNode::listen() {
XrlSocket4V0p1Client cl(this);
cl.send_tcp_listen("socket4/0.1/tcp_listen", server_sockid, 100,
callback(this, &XrlBpsfNode::listen_cb));
}
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.
[ 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!
Victor
More information about the Xorp-hackers
mailing list