UDPConvergenceLayer.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 _UDP_CONVERGENCE_LAYER_H_
00018 #define _UDP_CONVERGENCE_LAYER_H_
00019 
00020 #include <oasys/io/UDPClient.h>
00021 #include <oasys/thread/Thread.h>
00022 #include <oasys/io/RateLimitedSocket.h>
00023 
00024 #include "IPConvergenceLayer.h"
00025 
00026 namespace dtn {
00027 
00028 class UDPConvergenceLayer : public IPConvergenceLayer {
00029 public:
00033     static const u_int MAX_BUNDLE_LEN = 65507;
00034 
00038     static const u_int16_t UDPCL_DEFAULT_PORT = 4556;
00039     
00043     UDPConvergenceLayer();
00044         
00048     bool interface_up(Interface* iface, int argc, const char* argv[]);
00049 
00053     bool interface_down(Interface* iface);
00054     
00058     void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00059 
00063     bool init_link(Link* link, int argc, const char* argv[]);
00064     
00068     void dump_link(Link* link, oasys::StringBuffer* buf);
00069     
00074     bool open_contact(const ContactRef& contact);
00075     
00079     bool close_contact(const ContactRef& contact);
00080 
00084     void send_bundle(const ContactRef& contact, Bundle* bundle);
00085 
00095     class Params : public CLInfo {
00096     public:
00100         virtual void serialize( oasys::SerializeAction *a );
00101 
00102         in_addr_t local_addr_;          
00103         u_int16_t local_port_;          
00104         in_addr_t remote_addr_;         
00105         u_int16_t remote_port_;         
00106 
00107         u_int32_t rate_;                
00108         u_int32_t bucket_depth_;        
00109     };
00110     
00114     static Params defaults_;
00115 
00116 protected:
00117     bool parse_params(Params* params, int argc, const char** argv,
00118                       const char** invalidp);
00123     class Receiver : public CLInfo,
00124                      public oasys::UDPClient,
00125                      public oasys::Thread
00126     {
00127     public:
00131         Receiver(UDPConvergenceLayer::Params* params);
00132 
00136         virtual ~Receiver() {}
00137         
00147         void run();
00148 
00149         UDPConvergenceLayer::Params params_;
00150         
00151     protected:
00155         void process_data(u_char* bp, size_t len);
00156     };
00157 
00158     /*
00159      * Helper class that wraps the sender-side per-contact state.
00160      */
00161     class Sender : public CLInfo, public Logger {
00162     public:
00166         virtual ~Sender() {}
00167 
00171         bool init(Params* params, in_addr_t addr, u_int16_t port);
00172         
00173     private:
00174         friend class UDPConvergenceLayer;
00175         
00179         Sender(const ContactRef& contact);
00180         
00185         int send_bundle(Bundle* bundle);
00186 
00190         Params* params_;
00191 
00195         oasys::UDPClient socket_;
00196 
00200         oasys::RateLimitedSocket rate_socket_;
00201         
00205         ContactRef contact_;
00206 
00212         u_char buf_[UDPConvergenceLayer::MAX_BUNDLE_LEN];
00213     };   
00214 };
00215 
00216 } // namespace dtn
00217 
00218 #endif /* _UDP_CONVERGENCE_LAYER_H_ */

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3