00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _TCP_CONVERGENCE_LAYER_H_
00018 #define _TCP_CONVERGENCE_LAYER_H_
00019
00020 #include <oasys/io/TCPClient.h>
00021 #include <oasys/io/TCPServer.h>
00022 #include <oasys/serialize/Serialize.h>
00023
00024 #include "StreamConvergenceLayer.h"
00025
00026 namespace dtn {
00027
00028 class IPAnnounce;
00029
00033 class TCPConvergenceLayer : public StreamConvergenceLayer {
00034 public:
00038 static const u_int8_t TCPCL_VERSION = 0x03;
00039
00043 static const u_int16_t TCPCL_DEFAULT_PORT = 4556;
00044
00048 TCPConvergenceLayer();
00049
00051 bool interface_up(Interface* iface, int argc, const char* argv[]);
00052 bool interface_down(Interface* iface);
00053 void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00055
00059 class TCPLinkParams : public StreamLinkParams {
00060 public:
00061 bool hexdump_;
00062 in_addr_t local_addr_;
00063 in_addr_t remote_addr_;
00064 u_int16_t remote_port_;
00065
00066 protected:
00067
00068 TCPLinkParams(bool init_defaults);
00069 friend class TCPConvergenceLayer;
00070 };
00071
00075 static TCPLinkParams default_link_params_;
00076
00077 protected:
00078 friend class IPAnnounce;
00079
00081 bool set_link_defaults(int argc, const char* argv[],
00082 const char** invalidp);
00083 void dump_link(const LinkRef& link, oasys::StringBuffer* buf);
00085
00087 virtual LinkParams* new_link_params();
00088 virtual bool parse_link_params(LinkParams* params,
00089 int argc, const char** argv,
00090 const char** invalidp);
00091 virtual bool parse_nexthop(const LinkRef& link, LinkParams* params);
00092 virtual CLConnection* new_connection(const LinkRef& link,
00093 LinkParams* params);
00095
00100 class Listener : public CLInfo, public oasys::TCPServerThread {
00101 public:
00102 Listener(TCPConvergenceLayer* cl);
00103 void accepted(int fd, in_addr_t addr, u_int16_t port);
00104
00106 TCPConvergenceLayer* cl_;
00107 };
00108
00118 class Connection : public StreamConvergenceLayer::Connection {
00119 public:
00123 Connection(TCPConvergenceLayer* cl, TCPLinkParams* params);
00124
00128 Connection(TCPConvergenceLayer* cl, TCPLinkParams* params,
00129 int fd, in_addr_t addr, u_int16_t port);
00130
00134 virtual ~Connection();
00135
00139 virtual void serialize(oasys::SerializeAction *a);
00140
00141 protected:
00142 friend class TCPConvergenceLayer;
00143
00145 virtual void connect();
00146 virtual void accept();
00147 virtual void disconnect();
00148 virtual void initialize_pollfds();
00149 virtual void handle_poll_activity();
00151
00153 void send_data();
00155
00157 void recv_data();
00158
00163 TCPLinkParams* tcp_lparams()
00164 {
00165 TCPLinkParams* ret = dynamic_cast<TCPLinkParams*>(params_);
00166 ASSERT(ret != NULL);
00167 return ret;
00168 }
00169
00170 oasys::TCPClient* sock_;
00171 struct pollfd* sock_pollfd_;
00172 };
00173 };
00174
00175 }
00176
00177 #endif