Go to the documentation of this file.00001 #include "core/Node.h"
00002 #include "net/ConvergenceLayer.h"
00003 #include <ibrcommon/Logger.h>
00004
00005 #include <iostream>
00006
00007 using namespace std;
00008
00009 namespace dtn
00010 {
00011 namespace core
00012 {
00013 Node::Node(Node::Type type, unsigned int rtt)
00014 : _connect_immediately(false), _address(), _description(), _id("dtn:none"), _timeout(5), _rtt(rtt), _type(type), _port(4556), _protocol(CONN_UNDEFINED)
00015 {
00016 }
00017
00018 Node::Node(dtn::data::EID id, Node::Protocol proto, Node::Type type, unsigned int rtt)
00019 : _connect_immediately(false), _address(), _description(), _id(id), _timeout(5), _rtt(rtt), _type(type), _port(4556), _protocol(proto)
00020 {
00021
00022 }
00023
00024 Node::~Node()
00025 {
00026 }
00027
00028 std::string Node::getTypeName(Node::Type type)
00029 {
00030 switch (type)
00031 {
00032 case Node::NODE_FLOATING:
00033 return "floating";
00034
00035 case Node::NODE_PERMANENT:
00036 return "permanent";
00037
00038 case Node::NODE_CONNECTED:
00039 return "connected";
00040 }
00041
00042 return "unknown";
00043 }
00044
00045 std::string Node::getProtocolName(Node::Protocol proto)
00046 {
00047 switch (proto)
00048 {
00049 case Node::CONN_UNSUPPORTED:
00050 return "unsupported";
00051
00052 case Node::CONN_UNDEFINED:
00053 return "undefined";
00054
00055 case Node::CONN_UDPIP:
00056 return "UDP";
00057
00058 case Node::CONN_TCPIP:
00059 return "TCP";
00060
00061 case Node::CONN_ZIGBEE:
00062 return "ZigBee";
00063
00064 case Node::CONN_BLUETOOTH:
00065 return "Bluetooth";
00066
00067 case Node::CONN_HTTP:
00068 return "HTTP";
00069 }
00070
00071 return "unknown";
00072 }
00073
00074 Node::Type Node::getType() const
00075 {
00076 return _type;
00077 }
00078
00079 void Node::setType(Node::Type type)
00080 {
00081 _type = type;
00082 }
00083
00084 void Node::setProtocol(Node::Protocol protocol)
00085 {
00086 _protocol = protocol;
00087 }
00088
00089 Node::Protocol Node::getProtocol() const
00090 {
00091 return _protocol;
00092 }
00093
00094 void Node::setAddress(string address)
00095 {
00096 _address = address;
00097 }
00098
00099 string Node::getAddress() const
00100 {
00101 return _address;
00102 }
00103
00104 void Node::setPort(unsigned int port)
00105 {
00106 _port = port;
00107 }
00108
00109 unsigned int Node::getPort() const
00110 {
00111 return _port;
00112 }
00113
00114 void Node::setDescription(string description)
00115 {
00116 _description = description;
00117 }
00118
00119 string Node::getDescription() const
00120 {
00121 return _description;
00122 }
00123
00124
00125 void Node::setURI(string uri)
00126 {
00127 _id = dtn::data::EID(uri);
00128 }
00129
00130 string Node::getURI() const
00131 {
00132 return _id.getString();
00133 }
00134
00135 void Node::setEID(const dtn::data::EID &id)
00136 {
00137 _id = id;
00138 }
00139
00140 const dtn::data::EID& Node::getEID() const
00141 {
00142 return _id;
00143 }
00144
00145 void Node::setTimeout(int timeout)
00146 {
00147 _timeout = timeout;
00148 }
00149
00150 int Node::getTimeout() const
00151 {
00152 return _timeout;
00153 }
00154
00155 unsigned int Node::getRoundTripTime() const
00156 {
00157 return _rtt;
00158 }
00159
00160 bool Node::decrementTimeout(int step)
00161 {
00162 if (_type == NODE_PERMANENT) return true;
00163
00164 if (_timeout <= 0) return false;
00165 _timeout -= step;
00166 return true;
00167 }
00168
00169 bool Node::operator==(const Node &other) const
00170 {
00171 return (other._id == _id) && (other._protocol == _protocol);
00172 }
00173
00174 bool Node::operator<(const Node &other) const
00175 {
00176
00177
00178
00179
00180
00181 if (_protocol < other._protocol) return true;
00182 if (_protocol != other._protocol) return false;
00183 if (_id < other._id ) return true;
00184
00185 return false;
00186 }
00187
00188 std::string Node::toString() const
00189 {
00190 std::stringstream ss; ss << getURI() << " (" << Node::getTypeName(getType()) << ", " << Node::getProtocolName(getProtocol()) << ", " << getAddress() << ", " << getPort() << ")";
00191 return ss.str();
00192 }
00193
00194 bool Node::doConnectImmediately() const
00195 {
00196 return _connect_immediately;
00197 }
00198
00199 void Node::setConnectImmediately(bool val)
00200 {
00201 _connect_immediately = val;
00202 }
00203 }
00204 }