xorp

IoTcpUdp Class Reference

A base class for I/O TCP/UDP communication. More...

#include <io_tcpudp.hh>

Inheritance diagram for IoTcpUdp:
IoTcpUdpDummy IoTcpUdpSocket

List of all members.

Public Member Functions

 IoTcpUdp (FeaDataPlaneManager &fea_data_plane_manager, const IfTree &iftree, int family, bool is_tcp)
 Constructor for a given address family.
virtual ~IoTcpUdp ()
 Virtual destructor.
IoTcpUdpManagerio_tcpudp_manager ()
 Get the IoTcpUdpManager instance.
FeaDataPlaneManagerfea_data_plane_manager ()
 Get the FeaDataPlaneManager instance.
virtual bool is_running () const
 Test whether this instance is running.
EventLoopeventloop ()
 Get the event loop.
const IfTreeiftree () const
 Get the interface tree.
virtual int family () const
 Get the address family.
virtual bool is_tcp () const
 Test whether this is TCP entry.
IoTcpUdpReceiverio_tcpudp_receiver ()
 Get the registered receiver.
virtual void register_io_tcpudp_receiver (IoTcpUdpReceiver *io_tcpudp_receiver)
 Register the I/O TCP/UDP data receiver.
virtual void unregister_io_tcpudp_receiver ()
 Unregister the I/O TCP/UDP data receiver.
virtual int start (string &error_msg)=0
 Start operation.
virtual int stop (string &error_msg)=0
 Stop operation.
virtual int tcp_open (string &error_msg)=0
 Open a TCP socket.
virtual int udp_open (string &error_msg)=0
 Open an UDP socket.
virtual int tcp_open_and_bind (const IPvX &local_addr, uint16_t local_port, string &error_msg)=0
 Create a bound TCP socket.
virtual int udp_open_and_bind (const IPvX &local_addr, uint16_t local_port, const string &local_dev, int reuse, string &error_msg)=0
 Create a bound UDP socket.
virtual int udp_open_bind_join (const IPvX &local_addr, uint16_t local_port, const IPvX &mcast_addr, uint8_t ttl, bool reuse, string &error_msg)=0
 Create a bound UDP multicast socket.
virtual int tcp_open_bind_connect (const IPvX &local_addr, uint16_t local_port, const IPvX &remote_addr, uint16_t remote_port, string &error_msg)=0
 Create a bound and connected TCP socket.
virtual int udp_open_bind_connect (const IPvX &local_addr, uint16_t local_port, const IPvX &remote_addr, uint16_t remote_port, string &error_msg)=0
 Create a bound and connected UDP socket.
virtual int udp_open_bind_broadcast (const string &ifname, const string &vifname, uint16_t local_port, uint16_t remote_port, bool reuse, bool limited, bool connected, string &error_msg)=0
 Create a bound, and optionally connected, UDP broadcast socket.
virtual int bind (const IPvX &local_addr, uint16_t local_port, string &error_msg)=0
 Bind a socket.
virtual int udp_join_group (const IPvX &mcast_addr, const IPvX &join_if_addr, string &error_msg)=0
 Join multicast group on already bound socket.
virtual int udp_leave_group (const IPvX &mcast_addr, const IPvX &leave_if_addr, string &error_msg)=0
 Leave multicast group on already bound socket.
virtual int close (string &error_msg)=0
 Close socket.
virtual int tcp_listen (uint32_t backlog, string &error_msg)=0
 Listen for inbound connections on socket.
virtual int udp_enable_recv (string &error_msg)=0
 Enable a UDP socket for datagram reception.
virtual int send (const vector< uint8_t > &data, string &error_msg)=0
 Send data on socket.
virtual int send_to (const IPvX &remote_addr, uint16_t remote_port, const vector< uint8_t > &data, string &error_msg)=0
 Send data on socket to a given destination.
virtual int send_from_multicast_if (const IPvX &group_addr, uint16_t group_port, const IPvX &ifaddr, const vector< uint8_t > &data, string &error_msg)=0
 Send data on socket to a given multicast group from a given interface.
virtual int set_socket_option (const string &optname, uint32_t optval, string &error_msg)=0
 Set a named socket option with an integer value.
virtual int set_socket_option (const string &optname, const string &optval, string &error_msg)=0
 Set a named socket option with a string value.
virtual int accept_connection (bool is_accepted, string &error_msg)=0
 Accept or reject a pending connection.

Protected Member Functions

virtual void recv_event (const string &if_name, const string &vif_name, const IPvX &src_host, uint16_t src_port, const vector< uint8_t > &data)
 Data received event.
virtual void inbound_connect_event (const IPvX &src_host, uint16_t src_port, IoTcpUdp *new_io_tcpudp)
 Inbound connection request received event.
virtual void outgoing_connect_event ()
 Outgoing connection request completed event.
virtual void error_event (const string &error, bool fatal)
 Error occured event.
virtual void disconnect_event ()
 Connection closed by peer event.

Protected Attributes

bool _is_running

Private Attributes

IoTcpUdpManager_io_tcpudp_manager
FeaDataPlaneManager_fea_data_plane_manager
EventLoop_eventloop
const IfTree_iftree
const int _family
const bool _is_tcp
IoTcpUdpReceiver_io_tcpudp_receiver

Detailed Description

A base class for I/O TCP/UDP communication.


Constructor & Destructor Documentation

IoTcpUdp::IoTcpUdp ( FeaDataPlaneManager fea_data_plane_manager,
const IfTree iftree,
int  family,
bool  is_tcp 
)

Constructor for a given address family.

Parameters:
fea_data_plane_managerthe corresponding data plane manager (FeaDataPlaneManager).
iftreethe interface tree to use.
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
is_tcpif true this is TCP entry, otherwise UDP.

Member Function Documentation

virtual int IoTcpUdp::accept_connection ( bool  is_accepted,
string &  error_msg 
) [pure virtual]

Accept or reject a pending connection.

Parameters:
is_acceptedif true, the connection is accepted, otherwise is rejected.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::bind ( const IPvX local_addr,
uint16_t  local_port,
string &  error_msg 
) [pure virtual]

Bind a socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::close ( string &  error_msg) [pure virtual]

Close socket.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

void IoTcpUdp::disconnect_event ( ) [protected, virtual]

Connection closed by peer event.

It applies only to TCP sockets. This method is not called if the socket is gracefully closed through close().

void IoTcpUdp::error_event ( const string &  error,
bool  fatal 
) [protected, virtual]

Error occured event.

Parameters:
errora textual description of the error.
fatalindication of whether socket is shutdown because of error.
EventLoop& IoTcpUdp::eventloop ( ) [inline]

Get the event loop.

Returns:
the event loop.
virtual int IoTcpUdp::family ( ) const [inline, virtual]

Get the address family.

Returns:
the address family.
FeaDataPlaneManager& IoTcpUdp::fea_data_plane_manager ( ) [inline]

Get the FeaDataPlaneManager instance.

Returns:
the FeaDataPlaneManager instance.
const IfTree& IoTcpUdp::iftree ( ) const [inline]

Get the interface tree.

Returns:
the interface tree.
void IoTcpUdp::inbound_connect_event ( const IPvX src_host,
uint16_t  src_port,
IoTcpUdp new_io_tcpudp 
) [protected, virtual]

Inbound connection request received event.

It applies only to TCP sockets.

Parameters:
src_hostthe originating host IP address.
src_portthe originating host port number.
new_io_tcpudpthe handler for the new connection.
IoTcpUdpManager& IoTcpUdp::io_tcpudp_manager ( ) [inline]

Get the IoTcpUdpManager instance.

Returns:
the IoTcpUdpManager instance.
IoTcpUdpReceiver* IoTcpUdp::io_tcpudp_receiver ( ) [inline]

Get the registered receiver.

Returns:
the registered receiver.
virtual bool IoTcpUdp::is_running ( ) const [inline, virtual]

Test whether this instance is running.

Returns:
true if the instance is running, otherwise false.
virtual bool IoTcpUdp::is_tcp ( ) const [inline, virtual]

Test whether this is TCP entry.

Returns:
true if this is TCP entry, otherwise false (i.e., UDP).
void IoTcpUdp::outgoing_connect_event ( ) [protected, virtual]

Outgoing connection request completed event.

It applies only to TCP sockets.

void IoTcpUdp::recv_event ( const string &  if_name,
const string &  vif_name,
const IPvX src_host,
uint16_t  src_port,
const vector< uint8_t > &  data 
) [protected, virtual]

Data received event.

Parameters:
if_namethe interface name the packet arrived on, if known. If unknown, then it is an empty string.
vif_namethe vif name the packet arrived on, if known. If unknown, then it is an empty string.
src_hostthe originating host IP address.
src_portthe originating host port number.
datathe data received.
void IoTcpUdp::register_io_tcpudp_receiver ( IoTcpUdpReceiver io_tcpudp_receiver) [virtual]

Register the I/O TCP/UDP data receiver.

Parameters:
io_tcpudp_receiverthe receiver to register.
virtual int IoTcpUdp::send ( const vector< uint8_t > &  data,
string &  error_msg 
) [pure virtual]

Send data on socket.

Parameters:
datablock of data to be sent.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::send_from_multicast_if ( const IPvX group_addr,
uint16_t  group_port,
const IPvX ifaddr,
const vector< uint8_t > &  data,
string &  error_msg 
) [pure virtual]

Send data on socket to a given multicast group from a given interface.

Parameters:
group_addrdestination address for data.
group_portdestination port for data.
ifaddrinterface address.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::send_to ( const IPvX remote_addr,
uint16_t  remote_port,
const vector< uint8_t > &  data,
string &  error_msg 
) [pure virtual]

Send data on socket to a given destination.

The packet is not routed as the forwarding engine sending the packet may not have access to the full routing table.

Parameters:
remote_addrdestination address for data.
remote_portdestination port for data.
datablock of data to be sent.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::set_socket_option ( const string &  optname,
const string &  optval,
string &  error_msg 
) [pure virtual]

Set a named socket option with a string value.

Parameters:
optnamename of option to be set. Valid values are: "bindtodevice"
optvalvalue of option to be set.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::set_socket_option ( const string &  optname,
uint32_t  optval,
string &  error_msg 
) [pure virtual]

Set a named socket option with an integer value.

Parameters:
optnamename of option to be set. Valid values are: "onesbcast" (IPv4 only) "receive_broadcast" (IPv4 only) "reuseport" "send_broadcast" (IPv4 only) "tos" (IPv4 only) "ttl" "multicast_loopback" "multicast_ttl"
optvalvalue of option to be set. If value is logically boolean then zero represents false and any non-zero value true.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::start ( string &  error_msg) [pure virtual]

Start operation.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::stop ( string &  error_msg) [pure virtual]

Stop operation.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::tcp_listen ( uint32_t  backlog,
string &  error_msg 
) [pure virtual]

Listen for inbound connections on socket.

When a connection request is received the socket creator will receive notification.

Parameters:
backlogthe maximum number of pending connections.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::tcp_open ( string &  error_msg) [pure virtual]

Open a TCP socket.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::tcp_open_and_bind ( const IPvX local_addr,
uint16_t  local_port,
string &  error_msg 
) [pure virtual]

Create a bound TCP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::tcp_open_bind_connect ( const IPvX local_addr,
uint16_t  local_port,
const IPvX remote_addr,
uint16_t  remote_port,
string &  error_msg 
) [pure virtual]

Create a bound and connected TCP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
remote_addrthe address to connect to.
remote_portthe remote port to connect to.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_enable_recv ( string &  error_msg) [pure virtual]

Enable a UDP socket for datagram reception.

When a connection request is received the socket creator will receive notification.

Parameters:
backlogthe maximum number of pending connections.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_join_group ( const IPvX mcast_addr,
const IPvX join_if_addr,
string &  error_msg 
) [pure virtual]

Join multicast group on already bound socket.

Parameters:
mcast_addrgroup to join.
join_if_addrinterface address to perform join on.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_leave_group ( const IPvX mcast_addr,
const IPvX leave_if_addr,
string &  error_msg 
) [pure virtual]

Leave multicast group on already bound socket.

Parameters:
mcast_addrgroup to leave.
leave_if_addrinterface address to perform leave on.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_open ( string &  error_msg) [pure virtual]

Open an UDP socket.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_open_and_bind ( const IPvX local_addr,
uint16_t  local_port,
const string &  local_dev,
int  reuse,
string &  error_msg 
) [pure virtual]

Create a bound UDP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_open_bind_broadcast ( const string &  ifname,
const string &  vifname,
uint16_t  local_port,
uint16_t  remote_port,
bool  reuse,
bool  limited,
bool  connected,
string &  error_msg 
) [pure virtual]

Create a bound, and optionally connected, UDP broadcast socket.

Parameters:
ifnamethe interface name to bind socket to.
vifnamethe vif to bind socket to.
local_portthe port to bind socket to.
remote_portthe remote port to connect to.
reuseallow other sockets to bind to same port.
limitedset the socket up for transmission to the limited broadcast address 255.255.255.255.
connectedconnect the socket for use with send() not sendto().
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_open_bind_connect ( const IPvX local_addr,
uint16_t  local_port,
const IPvX remote_addr,
uint16_t  remote_port,
string &  error_msg 
) [pure virtual]

Create a bound and connected UDP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
remote_addrthe address to connect to.
remote_portthe remote port to connect to.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.

virtual int IoTcpUdp::udp_open_bind_join ( const IPvX local_addr,
uint16_t  local_port,
const IPvX mcast_addr,
uint8_t  ttl,
bool  reuse,
string &  error_msg 
) [pure virtual]

Create a bound UDP multicast socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
mcast_addrthe multicast group address to join.
ttlthe TTL to use for this multicast socket.
reuseallow other sockets to bind to same multicast group.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implemented in IoTcpUdpDummy, and IoTcpUdpSocket.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations