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/Singleton.h>
00029
00030 namespace dtntunnel {
00031
00032 class TCPTunnel;
00033 class UDPTunnel;
00034
00038 class DTNTunnel : public oasys::Logger,
00039 public oasys::Singleton<DTNTunnel>
00040 {
00041 public:
00043 DTNTunnel();
00044
00051 struct BundleHeader {
00052 BundleHeader()
00053 {
00054 memset(this, 0, sizeof(BundleHeader));
00055 }
00056
00057 BundleHeader(u_int8_t protocol,
00058 u_int8_t eof,
00059 u_int32_t seqno,
00060 u_int32_t client_addr,
00061 u_int32_t remote_addr,
00062 u_int16_t client_port,
00063 u_int16_t remote_port)
00064 : protocol_(protocol),
00065 eof_(eof),
00066 seqno_(seqno),
00067 client_addr_(client_addr),
00068 remote_addr_(remote_addr),
00069 client_port_(client_port),
00070 remote_port_(remote_port)
00071 {
00072 }
00073
00074 u_int8_t protocol_;
00075 u_int8_t eof_;
00076 u_int32_t seqno_;
00077 u_int32_t client_addr_;
00078 u_int32_t remote_addr_;
00079 u_int16_t client_port_;
00080 u_int16_t remote_port_;
00081
00082 } __attribute__((packed));
00083
00088 int send_bundle(dtn::APIBundle* bundle, dtn_endpoint_id_t* dest_eid);
00089
00091 int handle_bundle(dtn_bundle_spec_t* spec,
00092 dtn_bundle_payload_t* payload);
00093
00095 int main(int argc, char* argv[]);
00096
00098 u_int max_size() { return max_size_; }
00099 u_int delay() { return delay_; }
00100 dtn_endpoint_id_t* dest_eid() { return &dest_eid_; }
00101
00102 protected:
00103 std::string loglevelstr_;
00104 oasys::log_level_t loglevel_;
00105 std::string logfile_;
00106
00107 UDPTunnel* udptunnel_;
00108 TCPTunnel* tcptunnel_;
00109
00110 dtn_handle_t recv_handle_;
00111 dtn_handle_t send_handle_;
00112 oasys::Mutex send_lock_;
00113 bool listen_;
00114 dtn_endpoint_id_t local_eid_;
00115 dtn_endpoint_id_t dest_eid_;
00116 bool custody_;
00117 u_int expiration_;
00118 bool tcp_;
00119 bool udp_;
00120 in_addr_t local_addr_;
00121 u_int16_t local_port_;
00122 in_addr_t remote_addr_;
00123 u_int16_t remote_port_;
00124 u_int delay_;
00125 u_int max_size_;
00126
00127 void init_log();
00128 void init_tunnel();
00129 void init_registration();
00130 void get_options(int argc, char* argv[]);
00131 };
00132
00133 }
00134
00135 #endif