xorp

IoTcpUdpComm Class Reference

A class that handles I/O TCP/UDP communication. More...

#include <io_tcpudp_manager.hh>

Inheritance diagram for IoTcpUdpComm:
NONCOPYABLE IoTcpUdpReceiver

List of all members.

Classes

class  JoinedMulticastGroup
 Joined multicast group class. More...

Public Member Functions

 IoTcpUdpComm (IoTcpUdpManager &io_tcpudp_manager, const IfTree &iftree, int family, bool is_tcp, const string &creator)
 Constructor for IoTcpUdpComm.
 IoTcpUdpComm (IoTcpUdpManager &io_tcpudp_manager, const IfTree &iftree, int family, bool is_tcp, const string &creator, const string &listener_sockid, const IPvX &peer_host, uint16_t peer_port)
 Constructor for connected IoTcpUdpComm.
virtual ~IoTcpUdpComm ()
 Virtual destructor.
void allocate_io_tcpudp_plugins ()
 Allocate the I/O TCP/UDP plugins (one per data plane manager).
void deallocate_io_tcpudp_plugins ()
 Deallocate the I/O TCP/UDP plugins (one per data plane manager).
void allocate_io_tcpudp_plugin (FeaDataPlaneManager *fea_data_plane_manager)
 Allocate an I/O TCP/UDP plugin for a given data plane manager.
void deallocate_io_tcpudp_plugin (FeaDataPlaneManager *fea_data_plane_manager)
 Deallocate the I/O TCP/UDP plugin for a given data plane manager.
void add_plugin (IoTcpUdp *new_io_tcpudp)
 Add a pre-allocated I/O TCP/UDP plugin.
void start_io_tcpudp_plugins ()
 Start all I/O TCP/UDP plugins.
void stop_io_tcpudp_plugins ()
 Stop all I/O TCP/UDP plugins.
int tcp_open (string &sockid, string &error_msg)
 Open a TCP socket.
int udp_open (string &sockid, string &error_msg)
 Open an UDP socket.
int tcp_open_and_bind (const IPvX &local_addr, uint16_t local_port, string &sockid, string &error_msg)
 Create a bound TCP socket.
int udp_open_and_bind (const IPvX &local_addr, uint16_t local_port, const string &local_dev, int reuse, string &sockid, string &error_msg)
 Create a bound UDP socket.
int udp_open_bind_join (const IPvX &local_addr, uint16_t local_port, const IPvX &mcast_addr, uint8_t ttl, bool reuse, string &sockid, string &error_msg)
 Create a bound UDP multicast socket.
int tcp_open_bind_connect (const IPvX &local_addr, uint16_t local_port, const IPvX &remote_addr, uint16_t remote_port, string &sockid, string &error_msg)
 Create a bound and connected TCP socket.
int udp_open_bind_connect (const IPvX &local_addr, uint16_t local_port, const IPvX &remote_addr, uint16_t remote_port, string &sockid, string &error_msg)
 Create a bound and connected UDP socket.
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 &sockid, string &error_msg)
 Create a bound, and optionally connected, UDP broadcast socket.
int bind (const IPvX &local_addr, uint16_t local_port, string &error_msg)
 Bind a socket.
int udp_join_group (const IPvX &mcast_addr, const IPvX &join_if_addr, string &error_msg)
 Join multicast group on already bound socket.
int udp_leave_group (const IPvX &mcast_addr, const IPvX &leave_if_addr, string &error_msg)
 Leave multicast group on already bound socket.
int close (string &error_msg)
 Close socket.
int tcp_listen (uint32_t backlog, string &error_msg)
 Listen for inbound connections on socket.
int udp_enable_recv (string &error_msg)
 Enable a UDP socket for datagram reception.
int send (const vector< uint8_t > &data, string &error_msg)
 Send data on socket.
int send_to (const IPvX &remote_addr, uint16_t remote_port, const vector< uint8_t > &data, string &error_msg)
 Send data on socket to a given destination.
int send_from_multicast_if (const IPvX &group_addr, uint16_t group_port, const IPvX &ifaddr, const vector< uint8_t > &data, string &error_msg)
 Send data on socket to a given multicast group from a given interface.
int set_socket_option (const string &optname, uint32_t optval, string &error_msg)
 Set a named socket option with an integer value.
int set_socket_option (const string &optname, const string &optval, string &error_msg)
 Set a named socket option with a string value.
int accept_connection (bool is_accepted, string &error_msg)
 Accept or reject a pending connection.
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.
void inbound_connect_event (const IPvX &src_host, uint16_t src_port, IoTcpUdp *new_io_tcpudp)
 Inbound connection request received event.
void outgoing_connect_event ()
 Outgoing connection request completed event.
void error_event (const string &error, bool fatal)
 Error occured event.
void disconnect_event ()
 Connection closed by peer event.
const string & creator () const
 Get the creator name.
const string & sockid () const
 Get the socket ID.
const string & listener_sockid () const
 Get the listener socket ID.
const IPvXpeer_host () const
 Get the peer host IP address.
uint16_t peer_port () const
 Get the peer host port number.

Private Types

typedef list< pair
< FeaDataPlaneManager
*, IoTcpUdp * > > 
IoTcpUdpPlugins
typedef map
< JoinedMulticastGroup,
JoinedMulticastGroup
JoinedGroupsTable

Private Member Functions

 IoTcpUdpComm (const IoTcpUdpComm &)
IoTcpUdpCommoperator= (const IoTcpUdpComm &)

Private Attributes

IoTcpUdpManager_io_tcpudp_manager
const IfTree_iftree
const int _family
const bool _is_tcp
const string _creator
const string _sockid
const string _listener_sockid
const IPvX _peer_host
const uint16_t _peer_port
IoTcpUdpPlugins _io_tcpudp_plugins
JoinedGroupsTable _joined_groups_table

Detailed Description

A class that handles I/O TCP/UDP communication.


Constructor & Destructor Documentation

IoTcpUdpComm::IoTcpUdpComm ( IoTcpUdpManager io_tcpudp_manager,
const IfTree iftree,
int  family,
bool  is_tcp,
const string &  creator 
)

Constructor for IoTcpUdpComm.

Parameters:
io_tcpudp_managerthe corresponding I/O TCP/UDP manager (IoTcpUdpManager).
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.
creatorthe name of the socket creator.
IoTcpUdpComm::IoTcpUdpComm ( IoTcpUdpManager io_tcpudp_manager,
const IfTree iftree,
int  family,
bool  is_tcp,
const string &  creator,
const string &  listener_sockid,
const IPvX peer_host,
uint16_t  peer_port 
)

Constructor for connected IoTcpUdpComm.

Parameters:
io_tcpudp_managerthe corresponding I/O TCP/UDP manager (IoTcpUdpManager).
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.
creatorthe name of the socket creator.
listener_sockidthe socket ID of the listener socket.
peer_hostthe peer host IP address.
peer_portthe peer host port number.

Member Function Documentation

int IoTcpUdpComm::accept_connection ( bool  is_accepted,
string &  error_msg 
)

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.
void IoTcpUdpComm::add_plugin ( IoTcpUdp new_io_tcpudp)

Add a pre-allocated I/O TCP/UDP plugin.

Parameters:
new_io_tcpudpthe plugin to add.
void IoTcpUdpComm::allocate_io_tcpudp_plugin ( FeaDataPlaneManager fea_data_plane_manager)

Allocate an I/O TCP/UDP plugin for a given data plane manager.

Parameters:
fea_data_plane_managerthe data plane manager.
int IoTcpUdpComm::bind ( const IPvX local_addr,
uint16_t  local_port,
string &  error_msg 
)

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.
int IoTcpUdpComm::close ( string &  error_msg)

Close socket.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
const string& IoTcpUdpComm::creator ( ) const [inline]

Get the creator name.

Returns:
the creator name.
void IoTcpUdpComm::deallocate_io_tcpudp_plugin ( FeaDataPlaneManager fea_data_plane_manager)

Deallocate the I/O TCP/UDP plugin for a given data plane manager.

Parameters:
fea_data_plane_managerthe data plane manager.
void IoTcpUdpComm::disconnect_event ( ) [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().

Implements IoTcpUdpReceiver.

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

Error occured event.

Parameters:
errora textual description of the error.
fatalindication of whether socket is shutdown because of error.

Implements IoTcpUdpReceiver.

void IoTcpUdpComm::inbound_connect_event ( const IPvX src_host,
uint16_t  src_port,
IoTcpUdp new_io_tcpudp 
) [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.

Implements IoTcpUdpReceiver.

const string& IoTcpUdpComm::listener_sockid ( ) const [inline]

Get the listener socket ID.

Returns:
the listener socket ID.
void IoTcpUdpComm::outgoing_connect_event ( ) [virtual]

Outgoing connection request completed event.

It applies only to TCP sockets.

Implements IoTcpUdpReceiver.

const IPvX& IoTcpUdpComm::peer_host ( ) const [inline]

Get the peer host IP address.

Returns:
the peer host IP address.
uint16_t IoTcpUdpComm::peer_port ( ) const [inline]

Get the peer host port number.

Returns:
the peer host port number.
void IoTcpUdpComm::recv_event ( const string &  if_name,
const string &  vif_name,
const IPvX src_host,
uint16_t  src_port,
const vector< uint8_t > &  data 
) [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.

Implements IoTcpUdpReceiver.

int IoTcpUdpComm::send ( const vector< uint8_t > &  data,
string &  error_msg 
)

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.
int IoTcpUdpComm::send_from_multicast_if ( const IPvX group_addr,
uint16_t  group_port,
const IPvX ifaddr,
const vector< uint8_t > &  data,
string &  error_msg 
)

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

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
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.
int IoTcpUdpComm::send_to ( const IPvX remote_addr,
uint16_t  remote_port,
const vector< uint8_t > &  data,
string &  error_msg 
)

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.
int IoTcpUdpComm::set_socket_option ( const string &  optname,
uint32_t  optval,
string &  error_msg 
)

Set a named socket option with an integer value.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
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.
int IoTcpUdpComm::set_socket_option ( const string &  optname,
const string &  optval,
string &  error_msg 
)

Set a named socket option with a string value.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
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.
const string& IoTcpUdpComm::sockid ( ) const [inline]

Get the socket ID.

Returns:
the socket ID.
int IoTcpUdpComm::tcp_listen ( uint32_t  backlog,
string &  error_msg 
)

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.
int IoTcpUdpComm::tcp_open ( string &  sockid,
string &  error_msg 
)

Open a TCP socket.

Parameters:
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::tcp_open_and_bind ( const IPvX local_addr,
uint16_t  local_port,
string &  sockid,
string &  error_msg 
)

Create a bound TCP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::tcp_open_bind_connect ( const IPvX local_addr,
uint16_t  local_port,
const IPvX remote_addr,
uint16_t  remote_port,
string &  sockid,
string &  error_msg 
)

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.
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::udp_enable_recv ( string &  error_msg)

Enable a UDP socket for datagram reception.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::udp_join_group ( const IPvX mcast_addr,
const IPvX join_if_addr,
string &  error_msg 
)

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.
int IoTcpUdpComm::udp_leave_group ( const IPvX mcast_addr,
const IPvX leave_if_addr,
string &  error_msg 
)

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.
int IoTcpUdpComm::udp_open ( string &  sockid,
string &  error_msg 
)

Open an UDP socket.

Parameters:
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::udp_open_and_bind ( const IPvX local_addr,
uint16_t  local_port,
const string &  local_dev,
int  reuse,
string &  sockid,
string &  error_msg 
)

Create a bound UDP socket.

Parameters:
local_addrthe interface address to bind socket to.
local_portthe port to bind socket to.
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::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 &  sockid,
string &  error_msg 
)

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().
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::udp_open_bind_connect ( const IPvX local_addr,
uint16_t  local_port,
const IPvX remote_addr,
uint16_t  remote_port,
string &  sockid,
string &  error_msg 
)

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.
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpComm::udp_open_bind_join ( const IPvX local_addr,
uint16_t  local_port,
const IPvX mcast_addr,
uint8_t  ttl,
bool  reuse,
string &  sockid,
string &  error_msg 
)

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.
sockidreturn parameter that contains unique socket ID when socket instantiation is successful.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

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