All convergence layers that maintain a connection (i.e. More...
#include <ConnectionConvergenceLayer.h>
Classes | |
class | LinkParams |
Tunable parameter structure stored in each Link's CLInfo slot. More... | |
Public Member Functions | |
ConnectionConvergenceLayer (const char *logpath, const char *cl_name) | |
Constructor. | |
virtual bool | parse_nexthop (const LinkRef &link, LinkParams *params)=0 |
Parse and validate the nexthop address for the given link. | |
bool | init_link (const LinkRef &link, int argc, const char *argv[]) |
Virtual from ConvergenceLayer. | |
void | delete_link (const LinkRef &link) |
Virtual from ConvergenceLayer. | |
void | dump_link (const LinkRef &link, oasys::StringBuffer *buf) |
Virtual from ConvergenceLayer. | |
bool | reconfigure_link (const LinkRef &link, int argc, const char *argv[]) |
Virtual from ConvergenceLayer. | |
bool | open_contact (const ContactRef &contact) |
Virtual from ConvergenceLayer. | |
bool | close_contact (const ContactRef &contact) |
Virtual from ConvergenceLayer. | |
void | bundle_queued (const LinkRef &link, const BundleRef &bundle) |
Virtual from ConvergenceLayer. | |
void | cancel_bundle (const LinkRef &link, const BundleRef &bundle) |
Virtual from ConvergenceLayer. | |
Protected Member Functions | |
virtual LinkParams * | new_link_params ()=0 |
Create a new LinkParams structure. | |
virtual bool | parse_link_params (LinkParams *params, int argc, const char **argv, const char **invalidp) |
Parse the link parameters, returning true iff the args are valid for the given nexthop address. | |
virtual bool | finish_init_link (const LinkRef &link, LinkParams *params) |
After the link parameters are parsed, do any initialization of the link that's necessary before starting up a connection. | |
virtual CLConnection * | new_connection (const LinkRef &link, LinkParams *params)=0 |
Create a new CL-specific connection object. |
All convergence layers that maintain a connection (i.e.
a TCP socket) to next hop peers derive from this base class. As such, it manages all communication to/from the main bundle daemon thread, handles the main thread of control for each connection, and dispatches to the specific CL implementation to handle the actual wire protocol.
The design is as follows:
Open links contain a Connection class stored in the Contact's cl_info slot. The lifetime of this object is one-to-one with the duration of the Contact object. The Connection class is a thread that contains a MsgQueue for commands to be sent from the bundle daemon. The commands are SEND_BUNDLE, CANCEL_BUNDLE, and BREAK_CONTACT. When in an idle state, the thread blocks on this queue as well as the socket or other connection object so it can be notified of events coming from either the daemon or the peer node.
To enable backpressure, each connection has a maximum queue depth for bundles that have been pushed onto the queue but have not yet been sent or registered as in-flight by the CL. The state of the link is set to BUSY when this limit is reached, but is re-set to AVAILABLE if By default, there is no hard limit on the number of bundles that can be in-flight, instead the limit is determined by the capacity of the underlying link.
The hardest case to handle is how to close a contact, as there is a race condition between the underlying connection breaking and the higher layers determining that the link should be closed. If the underlying link breaks due to a timeout or goes idle for an on demand link, a ContactDownEvent is posted and the thread terminates, setting the is_stopped() bit in the thread class. In response to this event, the daemon will call the close_contact method. In this case, the connection thread has already terminated so it is cleaned up when the Contact object goes away.
If the link is closed by the daemon thread due to user configuration or a scheduled link's open time elapsing, then close_contact will be called while the connection is still open. The connection thread is informed by sending it a BREAK_CONTACT command. Reception of this command closes the connection and terminates, setting the is_stopped() bit when it is done. All this logic is handled by the break_contact method in the Connection class.
Finally, for bidirectional protocols, opportunistic links can be created in response to new connections arriving from a peer node.
Definition at line 75 of file ConnectionConvergenceLayer.h.
dtn::ConnectionConvergenceLayer::ConnectionConvergenceLayer | ( | const char * | logpath, | |
const char * | cl_name | |||
) |
Constructor.
Definition at line 45 of file ConnectionConvergenceLayer.cc.
void dtn::ConnectionConvergenceLayer::bundle_queued | ( | const LinkRef & | link, | |
const BundleRef & | bundle | |||
) | [virtual] |
Virtual from ConvergenceLayer.
Implements dtn::ConvergenceLayer.
Definition at line 383 of file ConnectionConvergenceLayer.cc.
References ASSERT, dtn::CLConnection::CLMSG_BUNDLES_QUEUED, and dtn::CLConnection::cmdqueue_.
void dtn::ConnectionConvergenceLayer::cancel_bundle | ( | const LinkRef & | link, | |
const BundleRef & | bundle | |||
) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Definition at line 414 of file ConnectionConvergenceLayer.cc.
References ASSERT, dtn::CLConnection::CLMSG_CANCEL_BUNDLE, dtn::CLConnection::cmdqueue_, and dtn::BundleDaemon::post().
bool dtn::ConnectionConvergenceLayer::close_contact | ( | const ContactRef & | contact | ) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Definition at line 262 of file ConnectionConvergenceLayer.cc.
References dtn::CLConnection::InFlightBundle::ack_data_, ASSERT, dtn::CLConnection::IncomingBundle::bundle_, dtn::CLConnection::InFlightBundle::bundle_, dtn::CLConnection::CLMSG_BREAK_CONTACT, dtn::CLConnection::cmdqueue_, dtn::CLConnection::contact_broken_, dtn::EVENTSRC_PEER, dtn::CLConnection::incoming_, dtn::CLConnection::inflight_, dtn::BundleProtocol::payload_offset(), dtn::BundleDaemon::post(), dtn::CLConnection::IncomingBundle::rcvd_data_, dtn::ConnectionConvergenceLayer::LinkParams::reactive_frag_enabled_, dtn::CLConnection::InFlightBundle::sent_data_, dtn::CLConnection::IncomingBundle::total_length_, dtn::CLConnection::InFlightBundle::total_length_, and dtn::CLConnection::InFlightBundle::transmit_event_posted_.
void dtn::ConnectionConvergenceLayer::delete_link | ( | const LinkRef & | link | ) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Definition at line 156 of file ConnectionConvergenceLayer.cc.
References ASSERT.
void dtn::ConnectionConvergenceLayer::dump_link | ( | const LinkRef & | link, | |
oasys::StringBuffer * | buf | |||
) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Reimplemented in dtn::SerialConvergenceLayer, dtn::StreamConvergenceLayer, and dtn::TCPConvergenceLayer.
Definition at line 96 of file ConnectionConvergenceLayer.cc.
References ASSERT.
bool dtn::ConnectionConvergenceLayer::finish_init_link | ( | const LinkRef & | link, | |
LinkParams * | params | |||
) | [protected, virtual] |
After the link parameters are parsed, do any initialization of the link that's necessary before starting up a connection.
Reimplemented in dtn::StreamConvergenceLayer.
Definition at line 180 of file ConnectionConvergenceLayer.cc.
Referenced by init_link().
bool dtn::ConnectionConvergenceLayer::init_link | ( | const LinkRef & | link, | |
int | argc, | |||
const char * | argv[] | |||
) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Definition at line 117 of file ConnectionConvergenceLayer.cc.
References ASSERT, finish_init_link(), new_link_params(), parse_link_params(), and parse_nexthop().
virtual CLConnection* dtn::ConnectionConvergenceLayer::new_connection | ( | const LinkRef & | link, | |
LinkParams * | params | |||
) | [protected, pure virtual] |
Create a new CL-specific connection object.
Implemented in dtn::SerialConvergenceLayer, and dtn::TCPConvergenceLayer.
Referenced by open_contact().
virtual LinkParams* dtn::ConnectionConvergenceLayer::new_link_params | ( | ) | [protected, pure virtual] |
Create a new LinkParams structure.
Implemented in dtn::SerialConvergenceLayer, and dtn::TCPConvergenceLayer.
Referenced by init_link().
bool dtn::ConnectionConvergenceLayer::open_contact | ( | const ContactRef & | contact | ) | [virtual] |
Virtual from ConvergenceLayer.
Implements dtn::ConvergenceLayer.
Definition at line 237 of file ConnectionConvergenceLayer.cc.
References ASSERT, new_connection(), and dtn::CLConnection::set_contact().
bool dtn::ConnectionConvergenceLayer::parse_link_params | ( | LinkParams * | params, | |
int | argc, | |||
const char ** | argv, | |||
const char ** | invalidp | |||
) | [protected, virtual] |
Parse the link parameters, returning true iff the args are valid for the given nexthop address.
Reimplemented in dtn::SerialConvergenceLayer, dtn::StreamConvergenceLayer, and dtn::TCPConvergenceLayer.
Definition at line 53 of file ConnectionConvergenceLayer.cc.
References dtn::ConnectionConvergenceLayer::LinkParams::data_timeout_, dtn::ConnectionConvergenceLayer::LinkParams::reactive_frag_enabled_, dtn::ConnectionConvergenceLayer::LinkParams::recvbuf_len_, dtn::ConnectionConvergenceLayer::LinkParams::sendbuf_len_, dtn::ConnectionConvergenceLayer::LinkParams::test_read_delay_, dtn::ConnectionConvergenceLayer::LinkParams::test_read_limit_, dtn::ConnectionConvergenceLayer::LinkParams::test_recv_delay_, dtn::ConnectionConvergenceLayer::LinkParams::test_write_delay_, and dtn::ConnectionConvergenceLayer::LinkParams::test_write_limit_.
Referenced by init_link(), and reconfigure_link().
virtual bool dtn::ConnectionConvergenceLayer::parse_nexthop | ( | const LinkRef & | link, | |
LinkParams * | params | |||
) | [pure virtual] |
Parse and validate the nexthop address for the given link.
Implemented in dtn::SerialConvergenceLayer, and dtn::TCPConvergenceLayer.
Referenced by dtn::TCPConvergenceLayer::Connection::connect(), init_link(), and dtn::SerialConvergenceLayer::Connection::initialize_pollfds().
bool dtn::ConnectionConvergenceLayer::reconfigure_link | ( | const LinkRef & | link, | |
int | argc, | |||
const char * | argv[] | |||
) | [virtual] |
Virtual from ConvergenceLayer.
Reimplemented from dtn::ConvergenceLayer.
Definition at line 190 of file ConnectionConvergenceLayer.cc.
References ASSERT, parse_link_params(), dtn::CLConnection::recvbuf_, dtn::ConnectionConvergenceLayer::LinkParams::recvbuf_len_, dtn::CLConnection::sendbuf_, and dtn::ConnectionConvergenceLayer::LinkParams::sendbuf_len_.