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 : _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 : _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
00136 void Node::setTimeout(int timeout)
00137 {
00138 _timeout = timeout;
00139 }
00140
00141 int Node::getTimeout() const
00142 {
00143 return _timeout;
00144 }
00145
00146 unsigned int Node::getRoundTripTime() const
00147 {
00148 return _rtt;
00149 }
00150
00151 bool Node::decrementTimeout(int step)
00152 {
00153 if (_type == NODE_PERMANENT) return true;
00154
00155 if (_timeout <= 0) return false;
00156 _timeout -= step;
00157 return true;
00158 }
00159
00160 bool Node::operator==(const Node &other) const
00161 {
00162 return (other._id == _id) && (other._protocol == _protocol);
00163 }
00164
00165 bool Node::operator<(const Node &other) const
00166 {
00167
00168
00169
00170
00171
00172 if (_protocol < other._protocol) return true;
00173 if (_protocol != other._protocol) return false;
00174 if (_id < other._id ) return true;
00175
00176 return false;
00177 }
00178
00179 std::string Node::toString() const
00180 {
00181 std::stringstream ss; ss << getURI() << " (" << Node::getTypeName(getType()) << ", " << Node::getProtocolName(getProtocol()) << ", " << getAddress() << ", " << getPort() << ")";
00182 return ss.str();
00183 }
00184 }
00185 }