TCPConvergenceLayer.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  *
00007  * Intel Open Source License
00008  *
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  *
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  *
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  *
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _TCP_CONVERGENCE_LAYER_H_
00039 #define _TCP_CONVERGENCE_LAYER_H_
00040 
00041 #include <oasys/io/TCPClient.h>
00042 #include <oasys/io/TCPServer.h>
00043 
00044 #include "StreamConvergenceLayer.h"
00045 
00046 namespace dtn {
00047 
00051 class TCPConvergenceLayer : public StreamConvergenceLayer {
00052 public:
00056     static const u_int8_t TCPCL_VERSION = 0x03;
00057 
00061     static const u_int16_t TCPCL_DEFAULT_PORT = 5000;
00062     
00066     TCPConvergenceLayer();
00067 
00069     bool interface_up(Interface* iface, int argc, const char* argv[]);
00070     bool interface_down(Interface* iface);
00071     void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00073 
00077     class TCPLinkParams : public StreamLinkParams {
00078     public:
00079         in_addr_t local_addr_;          
00080         in_addr_t remote_addr_;         
00081         u_int16_t remote_port_;         
00082 
00083     protected:
00084         // See comment in LinkParams for why this is protected
00085         TCPLinkParams(bool init_defaults);
00086         friend class TCPConvergenceLayer;
00087     };
00088 
00092     static TCPLinkParams default_link_params_;
00093 
00094 protected:
00096     bool set_link_defaults(int argc, const char* argv[],
00097                            const char** invalidp);
00098     void dump_link(Link* link, oasys::StringBuffer* buf);
00100     
00102     virtual LinkParams* new_link_params();
00103     virtual bool parse_link_params(LinkParams* params,
00104                                    int argc, const char** argv,
00105                                    const char** invalidp);
00106     virtual bool parse_nexthop(Link* link, LinkParams* params);
00107     virtual CLConnection* new_connection(LinkParams* params);
00109 
00114     class Listener : public CLInfo, public oasys::TCPServerThread {
00115     public:
00116         Listener(TCPConvergenceLayer* cl);
00117         void accepted(int fd, in_addr_t addr, u_int16_t port);
00118 
00120         TCPConvergenceLayer* cl_;
00121     };
00122 
00132     class Connection : public StreamConvergenceLayer::Connection {
00133     public:
00137         Connection(TCPConvergenceLayer* cl, TCPLinkParams* params);
00138 
00142         Connection(TCPConvergenceLayer* cl, TCPLinkParams* params,
00143                    int fd, in_addr_t addr, u_int16_t port);
00144 
00148         virtual ~Connection();
00149 
00150     protected:
00151         friend class TCPConvergenceLayer;
00152 
00154         virtual void connect();
00155         virtual void accept();
00156         virtual void disconnect();
00157         virtual void initialize_pollfds();
00158         virtual void handle_poll_activity();
00160 
00162         void send_data();
00164         
00165         void recv_data();
00166         bool recv_contact_header(int timeout);
00167         bool send_bundle(Bundle* bundle);
00168         bool recv_bundle();
00169         bool handle_reply();
00170         int handle_ack();
00171         bool send_ack(u_int32_t bundle_id, size_t acked_len);
00172         bool send_keepalive();
00173 
00178         TCPLinkParams* tcp_lparams()
00179         {
00180             TCPLinkParams* ret = dynamic_cast<TCPLinkParams*>(params_);
00181             ASSERT(ret != NULL);
00182             return ret;
00183         }
00184         
00185         oasys::TCPClient* sock_;        
00186         struct pollfd*    sock_pollfd_; 
00187     };
00188 };
00189 
00190 } // namespace dtn
00191 
00192 #endif /* _TCP_CONVERGENCE_LAYER_H_ */

Generated on Fri Dec 22 14:48:01 2006 for DTN Reference Implementation by  doxygen 1.5.1