00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _IP_DISCOVERY_H_
00018 #define _IP_DISCOVERY_H_
00019
00020 #include <oasys/thread/Thread.h>
00021 #include <oasys/thread/Notifier.h>
00022 #include <oasys/io/NetUtils.h>
00023 #include <oasys/io/UDPClient.h>
00024
00025 #include "discovery/Discovery.h"
00026
00027 namespace dtn {
00028
00035 class IPDiscovery : public Discovery,
00036 public oasys::Thread
00037 {
00038 public:
00039
00044 static const u_int32_t DEFAULT_DST_ADDR;
00045
00050 static const u_int32_t DEFAULT_SRC_ADDR;
00051
00055 static const u_int DEFAULT_MCAST_TTL;
00056
00061 struct DiscoveryHeader
00062 {
00063 u_int8_t cl_type;
00064 u_int8_t interval;
00065 u_int16_t length;
00066 u_int32_t inet_addr;
00067 u_int16_t inet_port;
00068 u_int16_t name_len;
00069 char sender_name[0];
00070 }
00071 __attribute__((packed));
00072
00076 typedef enum
00077 {
00078 UNDEFINED = 0,
00079 TCPCL = 1,
00080 UDPCL = 2,
00081 }
00082 cl_type_t;
00083
00084 static const char* type_to_str(cl_type_t t)
00085 {
00086 switch(t) {
00087 case TCPCL: return "tcp";
00088 case UDPCL: return "udp";
00089 case UNDEFINED:
00090 default: PANIC("Undefined cl_type_t %d",t);
00091 }
00092 NOTREACHED;
00093 }
00094
00095 static cl_type_t str_to_type(const char* cltype)
00096 {
00097 if (strncmp(cltype,"tcp",3) == 0)
00098 return TCPCL;
00099 else
00100 if (strncmp(cltype,"udp",3) == 0)
00101 return UDPCL;
00102 else
00103 PANIC("Unsupported CL type %s",cltype);
00104 NOTREACHED;
00105 }
00106
00110 void shutdown() { shutdown_ = true; socket_.get_notifier()->notify(); }
00111
00112 virtual ~IPDiscovery() {}
00113
00114 protected:
00115 friend class Discovery;
00116
00117 IPDiscovery(const std::string& name);
00118
00123 bool configure(int argc, const char* argv[]);
00124
00128 void run();
00129
00134 bool parse_advertisement(u_char* buf, size_t len,
00135 in_addr_t remote_addr,
00136 u_int8_t& cl_type,
00137 std::string& nexthop,
00138 EndpointID& remote_eid);
00139
00143 void handle_announce()
00144 {
00145 socket_.get_notifier()->notify();
00146 }
00147
00148 volatile bool shutdown_;
00149 in_addr_t local_addr_;
00150 u_int16_t port_;
00151 in_addr_t remote_addr_;
00152 u_int mcast_ttl_;
00153 oasys::UDPClient socket_;
00154 bool persist_;
00155 };
00156
00157 }
00158
00159 #endif