xorp

IoTcpUdpManager Class Reference

A class that manages I/O TCP/UDP communications. More...

#include <io_tcpudp_manager.hh>

Inheritance diagram for IoTcpUdpManager:
IoTcpUdpManagerReceiver InstanceWatcher

List of all members.

Public Member Functions

 IoTcpUdpManager (FeaNode &fea_node, const IfTree &iftree)
 Constructor for IoTcpUdpManager.
virtual ~IoTcpUdpManager ()
 Virtual destructor.
int tcp_open (int family, const string &creator, string &sockid, string &error_msg)
 Open a TCP socket.
int udp_open (int family, const string &creator, string &sockid, string &error_msg)
 Open an UDP socket.
int tcp_open_and_bind (int family, const string &creator, const IPvX &local_addr, uint16_t local_port, string &sockid, string &error_msg)
 Create a bound TCP socket.
int udp_open_and_bind (int family, const string &creator, 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 (int family, const string &creator, 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 (int family, const string &creator, 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 (int family, const string &creator, 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 (int family, const string &creator, 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 connected UDP broadcast socket.
int bind (int family, const string &sockid, const IPvX &local_addr, uint16_t local_port, string &error_msg)
 Bind a socket.
int udp_join_group (int family, const string &sockid, const IPvX &mcast_addr, const IPvX &join_if_addr, string &error_msg)
 Join multicast group on already bound socket.
int udp_leave_group (int family, const string &sockid, const IPvX &mcast_addr, const IPvX &leave_if_addr, string &error_msg)
 Leave multicast group on already bound socket.
int close (int family, const string &sockid, string &error_msg)
 Close socket.
int tcp_listen (int family, const string &sockid, uint32_t backlog, string &error_msg)
 Listen for inbound connections on socket.
int udp_enable_recv (int family, const string &sockid, string &error_msg)
 Enable a UDP socket for datagram reception.
int send (int family, const string &sockid, const vector< uint8_t > &data, string &error_msg)
 Send data on socket.
int send_to (int family, const string &sockid, 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 (int family, const string &sockid, 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 (int family, const string &sockid, const string &optname, uint32_t optval, string &error_msg)
 Set a named socket option with an integer value.
int set_socket_option (int family, const string &sockid, const string &optname, const string &optval, string &error_msg)
 Set a named socket option with a string value.
int accept_connection (int family, const string &sockid, bool is_accepted, string &error_msg)
 Accept or reject a pending connection.
void recv_event (const string &receiver_name, const string &sockid, 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 string &receiver_name, const string &sockid, const IPvX &src_host, uint16_t src_port, const string &new_sockid)
 Inbound connection request received event.
void outgoing_connect_event (int family, const string &receiver_name, const string &sockid)
 Outgoing connection request completed event.
void error_event (int family, const string &receiver_name, const string &sockid, const string &error, bool fatal)
 Error occured event.
void disconnect_event (int family, const string &receiver_name, const string &sockid)
 Connection closed by peer event.
void instance_birth (const string &instance_name)
 Inform the watcher that a component instance is alive.
void instance_death (const string &instance_name)
 Inform the watcher that a component instance is dead.
void set_io_tcpudp_manager_receiver (IoTcpUdpManagerReceiver *v)
 Set the instance that is responsible for sending IP packets to a receiver.
const IfTreeiftree () const
 Get a reference to the interface tree.
int register_data_plane_manager (FeaDataPlaneManager *fea_data_plane_manager, bool is_exclusive)
 Register FeaDataPlaneManager data plane manager.
int unregister_data_plane_manager (FeaDataPlaneManager *fea_data_plane_manager)
 Unregister FeaDataPlaneManager data plane manager.
list< FeaDataPlaneManager * > & fea_data_plane_managers ()
 Get the list of registered data plane managers.
IoTcpUdpCommconnect_io_tcpudp_comm (int family, bool is_tcp, const string &creator, const string &listener_sockid, const IPvX &peer_host, uint16_t peer_port, IoTcpUdp *new_io_tcpudp)
 Connect IoTcpUdpComm entry to a new plugin.

Private Types

typedef map< string,
IoTcpUdpComm * > 
CommTable

Private Member Functions

IoTcpUdpCommfind_io_tcpudp_comm (int family, const string &sockid, string &error_msg)
 Find an IoTcpUdpComm entry.
IoTcpUdpCommopen_io_tcpudp_comm (int family, bool is_tcp, const string &creator, bool allocate_plugins=true)
 Create and open IoTcpUdpComm entry.
void delete_io_tcpudp_comm (int family, const string &sockid)
 Delete an existing IoTcpUdoComm entry.
CommTable & comm_table_by_family (int family)
 Get the CommTable for an address family.
void erase_comm_handlers_by_creator (int family, const string &creator)
 Erase CommTable handlers for a given creator name.
bool has_comm_handler_by_creator (const string &creator) const
 Test whether there is a CommTable handler for a given creator name.
bool is_my_address (const IPvX &local_addr) const
 Test whether an address belongs to this host.

Private Attributes

FeaNode_fea_node
EventLoop_eventloop
const IfTree_iftree
CommTable _comm_table4
CommTable _comm_table6
IoTcpUdpManagerReceiver_io_tcpudp_manager_receiver
list< FeaDataPlaneManager * > _fea_data_plane_managers

Detailed Description

A class that manages I/O TCP/UDP communications.


Member Function Documentation

int IoTcpUdpManager::accept_connection ( int  family,
const string &  sockid,
bool  is_accepted,
string &  error_msg 
)

Accept or reject a pending connection.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
is_acceptedif true, the connection is accepted, otherwise is rejected.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpManager::bind ( int  family,
const string &  sockid,
const IPvX local_addr,
uint16_t  local_port,
string &  error_msg 
)

Bind a socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidthe socket ID of the socket to bind.
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 IoTcpUdpManager::close ( int  family,
const string &  sockid,
string &  error_msg 
)

Close socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID of socket to be closed.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
IoTcpUdpManager::CommTable & IoTcpUdpManager::comm_table_by_family ( int  family) [private]

Get the CommTable for an address family.

Parameters:
familythe address family.
Returns:
a reference to the CommTable for the address family.
IoTcpUdpComm * IoTcpUdpManager::connect_io_tcpudp_comm ( int  family,
bool  is_tcp,
const string &  creator,
const string &  listener_sockid,
const IPvX peer_host,
uint16_t  peer_port,
IoTcpUdp new_io_tcpudp 
)

Connect IoTcpUdpComm entry to a new plugin.

Parameters:
familythe address family.
is_tcpif true this is TCP entry, otherwise UDP.
creatorthe name of the creator.
listener_sockidthe socket ID of the listener socket.
peer_hostthe peer host IP address.
peer_portthe peer host port number.
new_io_tcpudpthe handler for the new connection.
Returns:
an entry (IoTcpUdpComm) to handle the connection from the new plugin.
void IoTcpUdpManager::delete_io_tcpudp_comm ( int  family,
const string &  sockid 
) [private]

Delete an existing IoTcpUdoComm entry.

Parameters:
familythe address family.
sockidthe socket ID of the entry to delete.
void IoTcpUdpManager::disconnect_event ( int  family,
const string &  receiver_name,
const string &  sockid 
) [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().

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
receiver_namethe name of the receiver to send the event to.
sockidunique socket ID.

Implements IoTcpUdpManagerReceiver.

void IoTcpUdpManager::erase_comm_handlers_by_creator ( int  family,
const string &  creator 
) [private]

Erase CommTable handlers for a given creator name.

Parameters:
familythe address family.
creatorthe name of the creator.
void IoTcpUdpManager::error_event ( int  family,
const string &  receiver_name,
const string &  sockid,
const string &  error,
bool  fatal 
) [virtual]

Error occured event.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
receiver_namethe name of the receiver to send the event to.
sockidunique socket ID.
errora textual description of the error.
fatalindication of whether socket is shutdown because of error.

Implements IoTcpUdpManagerReceiver.

list<FeaDataPlaneManager*>& IoTcpUdpManager::fea_data_plane_managers ( ) [inline]

Get the list of registered data plane managers.

Returns:
the list of registered data plane managers.
IoTcpUdpComm * IoTcpUdpManager::find_io_tcpudp_comm ( int  family,
const string &  sockid,
string &  error_msg 
) [private]

Find an IoTcpUdpComm entry.

Parameters:
familythe address family.
sockidthe socket ID to search for. the IoTcpUdpComm entry if found, otherwise NULL.
bool IoTcpUdpManager::has_comm_handler_by_creator ( const string &  creator) const [private]

Test whether there is a CommTable handler for a given creator name.

Parameters:
creatorthe name of the creator.
Returns:
true if there is a CommTable handler for the given creator name, otherwise false.
const IfTree& IoTcpUdpManager::iftree ( ) const [inline]

Get a reference to the interface tree.

Returns:
a reference to the interface tree (IfTree).
void IoTcpUdpManager::inbound_connect_event ( const string &  receiver_name,
const string &  sockid,
const IPvX src_host,
uint16_t  src_port,
const string &  new_sockid 
) [virtual]

Inbound connection request received event.

It applies only to TCP sockets.

Parameters:
receiver_namethe name of the receiver to send the event to.
sockidunique socket ID.
src_hostthe originating host IP address.
src_portthe originating host port number.
new_sockidthe new socket ID.

Implements IoTcpUdpManagerReceiver.

void IoTcpUdpManager::instance_birth ( const string &  instance_name) [virtual]

Inform the watcher that a component instance is alive.

Parameters:
instance_namethe name of the instance that is alive.

Implements InstanceWatcher.

void IoTcpUdpManager::instance_death ( const string &  instance_name) [virtual]

Inform the watcher that a component instance is dead.

Parameters:
instance_namethe name of the instance that is dead.

Implements InstanceWatcher.

bool IoTcpUdpManager::is_my_address ( const IPvX local_addr) const [private]

Test whether an address belongs to this host.

Parameters:
local_addrthe address to test.
Returns:
true if the address belongs to this host, otherwise false.
IoTcpUdpComm * IoTcpUdpManager::open_io_tcpudp_comm ( int  family,
bool  is_tcp,
const string &  creator,
bool  allocate_plugins = true 
) [private]

Create and open IoTcpUdpComm entry.

Parameters:
familythe address family.
is_tcpif true this is TCP entry, otherwise UDP.
creatorthe name of the creator.
allocate_pluginsif true, then allocate the plugin handler(s) internally, otherwise they will be explicitly added externally.
void IoTcpUdpManager::outgoing_connect_event ( int  family,
const string &  receiver_name,
const string &  sockid 
) [virtual]

Outgoing connection request completed event.

It applies only to TCP sockets.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
receiver_namethe name of the receiver to send the event to.
sockidunique socket ID.

Implements IoTcpUdpManagerReceiver.

void IoTcpUdpManager::recv_event ( const string &  receiver_name,
const string &  sockid,
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:
receiver_namethe name of the receiver to send the data to.
sockidunique socket ID.
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 IoTcpUdpManagerReceiver.

int IoTcpUdpManager::register_data_plane_manager ( FeaDataPlaneManager fea_data_plane_manager,
bool  is_exclusive 
)

Register FeaDataPlaneManager data plane manager.

Parameters:
fea_data_plane_managerthe data plane manager to register.
is_exclusiveif true, the manager is registered as the exclusive manager, otherwise is added to the list of managers.
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpManager::send ( int  family,
const string &  sockid,
const vector< uint8_t > &  data,
string &  error_msg 
)

Send data on socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
datablock of data to be sent.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpManager::send_from_multicast_if ( int  family,
const string &  sockid,
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 IoTcpUdpManager::send_to ( int  family,
const string &  sockid,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
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 IoTcpUdpManager::set_socket_option ( int  family,
const string &  sockid,
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.
int IoTcpUdpManager::set_socket_option ( int  family,
const string &  sockid,
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" "receive_broadcast" "reuseport" "send_broadcast" "tos" "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 IoTcpUdpManager::tcp_listen ( int  family,
const string &  sockid,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidthe unique socket ID of the socket to perform listen.
backlogthe maximum number of pending connections.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpManager::tcp_open ( int  family,
const string &  creator,
string &  sockid,
string &  error_msg 
)

Open a TCP socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::tcp_open_and_bind ( int  family,
const string &  creator,
const IPvX local_addr,
uint16_t  local_port,
string &  sockid,
string &  error_msg 
)

Create a bound TCP socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::tcp_open_bind_connect ( int  family,
const string &  creator,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::udp_enable_recv ( int  family,
const string &  sockid,
string &  error_msg 
)

Enable a UDP socket for datagram reception.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidthe unique socket ID of the socket to enable datagram reception for.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoTcpUdpManager::udp_join_group ( int  family,
const string &  sockid,
const IPvX mcast_addr,
const IPvX join_if_addr,
string &  error_msg 
)

Join multicast group on already bound socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
sockidunique socket ID.
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 IoTcpUdpManager::udp_leave_group ( int  family,
const string &  sockid,
const IPvX mcast_addr,
const IPvX leave_if_addr,
string &  error_msg 
)

Leave multicast group on already bound socket.

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

Open an UDP socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::udp_open_and_bind ( int  family,
const string &  creator,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::udp_open_bind_broadcast ( int  family,
const string &  creator,
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 connected UDP broadcast socket.

Parameters:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::udp_open_bind_connect ( int  family,
const string &  creator,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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 IoTcpUdpManager::udp_open_bind_join ( int  family,
const string &  creator,
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:
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
creatorthe name of the socket creator.
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.
int IoTcpUdpManager::unregister_data_plane_manager ( FeaDataPlaneManager fea_data_plane_manager)

Unregister FeaDataPlaneManager data plane manager.

Parameters:
fea_data_plane_managerthe data plane manager to unregister.
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