00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _DTNTUNNEL_H_
00018 #define _DTNTUNNEL_H_
00019
00020 #include <sys/types.h>
00021 #include <netinet/in.h>
00022 #include <netdb.h>
00023
00024 #include <dtn_api.h>
00025 #include <APIBundleQueue.h>
00026 #include <oasys/debug/Log.h>
00027 #include <oasys/thread/Mutex.h>
00028 #include <oasys/util/App.h>
00029 #include <oasys/util/Singleton.h>
00030
00031 namespace dtntunnel {
00032
00033 class TCPTunnel;
00034 class UDPTunnel;
00035
00039 class DTNTunnel : public oasys::App,
00040 public oasys::Singleton<DTNTunnel>
00041 {
00042 public:
00044 DTNTunnel();
00045
00052 struct BundleHeader {
00053 BundleHeader()
00054 {
00055 memset(this, 0, sizeof(BundleHeader));
00056 }
00057
00058 BundleHeader(u_int8_t protocol,
00059 u_int8_t eof,
00060 u_int32_t connection_id,
00061 u_int32_t seqno,
00062 u_int32_t client_addr,
00063 u_int32_t remote_addr,
00064 u_int16_t client_port,
00065 u_int16_t remote_port)
00066 : protocol_(protocol),
00067 eof_(eof),
00068 connection_id_(connection_id),
00069 seqno_(seqno),
00070 client_addr_(client_addr),
00071 remote_addr_(remote_addr),
00072 client_port_(client_port),
00073 remote_port_(remote_port)
00074 {
00075 }
00076
00077 u_int8_t protocol_;
00078 u_int8_t eof_;
00079 u_int32_t connection_id_;
00080 u_int32_t seqno_;
00081 u_int32_t client_addr_;
00082 u_int32_t remote_addr_;
00083 u_int16_t client_port_;
00084 u_int16_t remote_port_;
00085
00086 } __attribute__((packed));
00087
00092 int send_bundle(dtn::APIBundle* bundle, dtn_endpoint_id_t* dest_eid);
00093
00095 int handle_bundle(dtn_bundle_spec_t* spec,
00096 dtn_bundle_payload_t* payload);
00097
00099 int main(int argc, char* argv[]);
00100
00102 void fill_options();
00103 void validate_options(int argc, char* const argv[], int remainder);
00104
00106 u_int max_size() { return max_size_; }
00107 u_int delay() { return delay_; }
00108 dtn_endpoint_id_t* dest_eid() { return &dest_eid_; }
00109
00110 protected:
00111 UDPTunnel* udptunnel_;
00112 TCPTunnel* tcptunnel_;
00113
00114 dtn_handle_t recv_handle_;
00115 dtn_handle_t send_handle_;
00116 oasys::Mutex send_lock_;
00117 bool listen_;
00118 dtn_endpoint_id_t local_eid_;
00119 dtn_endpoint_id_t dest_eid_;
00120 bool custody_;
00121 u_int expiration_;
00122 bool tcp_;
00123 bool udp_;
00124 in_addr_t local_addr_;
00125 u_int16_t local_port_;
00126 in_addr_t remote_addr_;
00127 u_int16_t remote_port_;
00128 u_int delay_;
00129 u_int max_size_;
00130 std::string tunnel_spec_;
00131 bool tunnel_spec_set_;
00132
00133 void init_tunnel();
00134 void init_registration();
00135 };
00136
00137 }
00138
00139 #endif