TCPConvergenceLayer.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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         in_addr_t local_addr_;          
00062         in_addr_t remote_addr_;         
00063         u_int16_t remote_port_;         
00064 
00065     protected:
00066         // See comment in LinkParams for why this is protected
00067         TCPLinkParams(bool init_defaults);
00068         friend class TCPConvergenceLayer;
00069     };
00070 
00074     static TCPLinkParams default_link_params_;
00075 
00076 protected:
00077     friend class IPAnnounce;
00078 
00080     bool set_link_defaults(int argc, const char* argv[],
00081                            const char** invalidp);
00082     void dump_link(Link* link, oasys::StringBuffer* buf);
00084     
00086     virtual LinkParams* new_link_params();
00087     virtual bool parse_link_params(LinkParams* params,
00088                                    int argc, const char** argv,
00089                                    const char** invalidp);
00090     virtual bool parse_nexthop(Link* link, LinkParams* params);
00091     virtual CLConnection* new_connection(LinkParams* params);
00093 
00098     class Listener : public CLInfo, public oasys::TCPServerThread {
00099     public:
00100         Listener(TCPConvergenceLayer* cl);
00101         void accepted(int fd, in_addr_t addr, u_int16_t port);
00102 
00104         TCPConvergenceLayer* cl_;
00105     };
00106 
00116     class Connection : public StreamConvergenceLayer::Connection {
00117     public:
00121         Connection(TCPConvergenceLayer* cl, TCPLinkParams* params);
00122 
00126         Connection(TCPConvergenceLayer* cl, TCPLinkParams* params,
00127                    int fd, in_addr_t addr, u_int16_t port);
00128 
00132         virtual ~Connection();
00133 
00137         virtual void serialize(oasys::SerializeAction *a);
00138 
00139     protected:
00140         friend class TCPConvergenceLayer;
00141 
00143         virtual void connect();
00144         virtual void accept();
00145         virtual void disconnect();
00146         virtual void initialize_pollfds();
00147         virtual void handle_poll_activity();
00149 
00151         void send_data();
00153         
00154         void recv_data();
00155         bool recv_contact_header(int timeout);
00156         bool send_bundle(Bundle* bundle);
00157         bool recv_bundle();
00158         bool handle_reply();
00159         int handle_ack();
00160         bool send_ack(u_int32_t bundle_id, size_t acked_len);
00161         bool send_keepalive();
00162 
00167         TCPLinkParams* tcp_lparams()
00168         {
00169             TCPLinkParams* ret = dynamic_cast<TCPLinkParams*>(params_);
00170             ASSERT(ret != NULL);
00171             return ret;
00172         }
00173         
00174         oasys::TCPClient* sock_;        
00175         struct pollfd*    sock_pollfd_; 
00176     };
00177 };
00178 
00179 } // namespace dtn
00180 
00181 #endif /* _TCP_CONVERGENCE_LAYER_H_ */

Generated on Thu Jun 7 12:54:30 2007 for DTN Reference Implementation by  doxygen 1.5.1