[Xorp-hackers] Events and sockets in XORP

Victor Faion vfaion at gmail.com
Mon Feb 2 10:37:04 PST 2009


On Mon, Feb 2, 2009 at 09:51, Pavlin Radoslavov
<pavlin at icsi.berkeley.edu> wrote:
> Victor Faion <vfaion at gmail.com> wrote:
>
>> > To send/receive TCP you can do it via the FEA so you don't have to
>> > deal with sockets, etc.
>> > Basically, you need to use the xrl/interfaces/socket4.xif XRL API to
>> > register with the FEA to send/receive TCP.
>> > Then in your protocol you need to implement the receiving (target)
>> > side of socket4_user.xif .
>> > The XRL library itself will take care of the rest: on reception it
>> > will call the appropriate socket4_user.xif method.
>> > Once you process the event, just return back to the eventloop.
>> >
>>
>> I implemented these functions (basically just printing out their parameters):
>>
>> socket4_user_0_1_recv_event
>> socket4_user_0_1_inbound_connect_event
>> socket4_user_0_1_outgoing_connect_event
>> socket4_user_0_1_disconnect_event
>> socket4_user_0_1_error_event
>>
>> I'm not sure how to register with the FEA, I was trying to call
>> send_tcp_listen in my startup function, but I didn't know what
>> parameters to use (especially the sockid).
>>
>> The documentation on that function says:
>> Listen for inbound connections on socket. When a connection request
>> received the socket creator will receive notification through
>> socket4_user/0.1/inbound_connect_event.
>>
>> Does this mean the callback parameter should be my implementation of
>> inbound_connect_event, or is the callback passed just supposed to
>> generate some error if listening on a socket didn't succeed?
>>
>> For the destination target name I was passing
>> "socket4/0.1/tcp_listen", but I'm not sure if this is the right thing
>> to use.
>
> 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));
}

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.

Victor



More information about the Xorp-hackers mailing list