|
IBR-DTNSuite 0.6
|
00001 00002 #ifndef IBRDTN_DAEMON_NODE_H_ 00003 #define IBRDTN_DAEMON_NODE_H_ 00004 00005 #include <string> 00006 #include <ibrdtn/data/EID.h> 00007 #include <map> 00008 #include <set> 00009 #include <list> 00010 00011 namespace dtn 00012 { 00013 namespace net 00014 { 00015 class ConvergenceLayer; 00016 } 00017 00018 namespace core 00019 { 00023 class Node 00024 { 00025 public: 00031 enum Type 00032 { 00033 NODE_FLOATING = 0, 00034 NODE_PERMANENT = 1, 00035 NODE_CONNECTED = 2 00036 }; 00037 00038 enum Protocol 00039 { 00040 CONN_UNSUPPORTED = -1, 00041 CONN_UNDEFINED = 0, 00042 CONN_UDPIP = 1, 00043 CONN_TCPIP = 2, 00044 CONN_ZIGBEE = 3, 00045 CONN_BLUETOOTH = 4, 00046 CONN_HTTP = 5 00047 }; 00048 00049 class URI 00050 { 00051 public: 00052 URI(const std::string &uri, const Protocol p); 00053 ~URI(); 00054 00055 const Protocol protocol; 00056 const std::string value; 00057 00058 void decode(std::string &address, unsigned int &port) const; 00059 00060 bool operator<(const URI &other) const; 00061 bool operator==(const URI &other) const; 00062 00063 bool operator==(const Node::Protocol &p) const; 00064 }; 00065 00066 class Attribute 00067 { 00068 public: 00069 Attribute(const std::string &name, const std::string &value); 00070 ~Attribute(); 00071 00072 const std::string name; 00073 const std::string value; 00074 00075 bool operator<(const Attribute &other) const; 00076 bool operator==(const Attribute &other) const; 00077 00078 bool operator==(const std::string &name) const; 00079 }; 00080 00081 static std::string getTypeName(Node::Type type); 00082 static std::string getProtocolName(Node::Protocol proto); 00083 00089 Node(Node::Type type = NODE_PERMANENT, unsigned int rtt = 2700); 00090 00091 Node(const dtn::data::EID &id, Node::Type type = NODE_PERMANENT, unsigned int rtt = 2700); 00092 00096 virtual ~Node(); 00097 00103 Node::Type getType() const; 00104 void setType(Node::Type type); 00105 00111 bool has(Node::Protocol proto) const; 00112 bool has(const std::string &name) const; 00113 00118 void add(const URI &u); 00119 void add(const Attribute &attr); 00120 00125 void remove(const URI &u); 00126 void remove(const Attribute &attr); 00127 00131 void clear(); 00132 00138 std::list<URI> get(Node::Protocol proto) const; 00139 00145 std::list<Attribute> get(const std::string &name) const; 00146 00147 /* 00148 * Set a description for the node. 00149 * @param description a description 00150 */ 00151 void setDescription(std::string description); 00152 00157 std::string getDescription() const; 00158 00163 void setEID(const dtn::data::EID &id); 00164 00169 const dtn::data::EID& getEID() const; 00170 00176 void setTimeout(int timeout); 00177 00182 int getTimeout() const; 00183 00187 unsigned int getRoundTripTime() const; 00188 00194 bool decrementTimeout(int step); 00195 00202 bool operator==(const Node &other) const; 00203 bool operator<(const Node &other) const; 00204 00205 std::string toString() const; 00206 00207 bool doConnectImmediately() const; 00208 void setConnectImmediately(bool val); 00209 00210 private: 00211 bool _connect_immediately; 00212 std::string _description; 00213 dtn::data::EID _id; 00214 int _timeout; 00215 unsigned int _rtt; 00216 Node::Type _type; 00217 00218 std::set<URI> _uri_list; 00219 std::set<Attribute> _attr_list; 00220 std::map<std::string, std::string> _attributes; 00221 }; 00222 } 00223 } 00224 00225 #endif /*IBRDTN_DAEMON_NODE_H_*/