88 std::string temp = par(
"defaultQueryType").stdstringValue();
91 else if (temp ==
"exact_timeout")
93 else if (temp ==
"available")
95 else if (temp ==
"estimated")
97 else throw cRuntimeError((std::string(
"Wrong query type: ")
100 temp = par(
"defaultQueryTypeI").stdstringValue();
101 if (temp ==
"available")
103 else if (temp ==
"estimated")
105 else throw cRuntimeError((std::string(
"Wrong query type (I): ")
108 temp = par(
"defaultQueryTypeQ").stdstringValue();
111 else if (temp ==
"exact_timeout")
113 else if (temp ==
"query")
115 else throw cRuntimeError((std::string(
"Wrong query type (Q): ")
118 temp = par(
"ncsType").stdstringValue();
119 if (temp ==
"none")
ncs = NULL;
120 else if (temp ==
"vivaldi")
ncs =
new Vivaldi();
122 else if (temp ==
"gnp")
ncs =
new Nps();
123 else if (temp ==
"nps")
ncs =
new Nps();
126 else throw cRuntimeError((std::string(
"Wrong NCS type: ")
129 if (par(
"doDiscovery")) {
131 throw cRuntimeError(
"Discovery Mode with collectClosestNodes = 0");
154 if(par(
"treeMgmtEnableTreeManagement")) {
158 if(par(
"gvbEnableGlobalViewBuilder")) {
171 cbrTimer =
new cMessage(
"cbrTimer");
198 ->
addStdDev(
"NeighborCache: Ping hit rate",
234 cPolymorphic* context,
263 throw cRuntimeError(
"not waiting for response,"
264 " but additional contexts found!");
281 throw cRuntimeError(
"NeighborCache error!");
312 for (uint32_t i = 0; i < waitingContexts.size(); ++i) {
313 assert(waitingContexts[i].proxListener || !waitingContexts[i].proxContext);
314 if (waitingContexts[i].proxListener) {
315 waitingContexts[i].proxListener->proxCallback(handle,
316 waitingContexts[i].
id,
317 waitingContexts[i].proxContext,
330 Enter_Method_Silent();
336 <<
" inserting rtt(" << SIMTIME_DBL(rtt) <<
") of node " << add.
getIp()
344 bool deleteInfo =
false;
399 for (uint32_t i = 0; i < waitingContexts.size(); ++i) {
400 if (waitingContexts[i].proxListener) {
401 waitingContexts[i].proxListener
403 waitingContexts[i].
id,
404 waitingContexts[i].proxContext,
417 if (deleteInfo)
delete ncsInfo;
424 Enter_Method_Silent();
426 EV <<
"[NeighborCache::updateNcsInfo() @ " <<
thisNode.
getIp()
428 <<
" inserting new NcsInfo of node " << node.
getIp()
486 throw cRuntimeError(
"NeighborCache.cc: getNodeHandle was asked for "
487 "a non-existent node reference.");
495 throw cRuntimeError(
"NeighborCache.cc: getNodeAge was asked for "
496 "a non-existent address.");
508 for (uint32_t i = 0; i < (size - (
maxSize / 2)); ++i) {
525 simtime_t insertTime)
529 while (it->second != address) ++it;
540 simtime_t nearestNodeRtt = MAXTIME;
544 if (it->second.rtt < nearestNodeRtt &&
548 nearestNode.
setIp(it->first.getIp());
549 nearestNodeRtt = it->second.rtt;
550 nearestNode.
setPort(it->second.nodeRef.getPort());
560 std::vector<TransportAddress>* nodes =
561 new std::vector<TransportAddress>();
563 for (uint8_t i = 0; (i < number && i <
closestNodes->size()); ++i) {
572 std::vector<TransportAddress>* nodes =
573 new std::vector<TransportAddress>;
576 for (uint8_t i = 0; (i < number && i <
neighborCache.size()); ++i) {
577 nodes->push_back((it++)->first);
622 double absoluteDiff = 0;
623 uint32_t numNeighbors = 0;
624 uint32_t sampleSize = 10;
626 for (std::map<simtime_t, TransportAddress>::reverse_iterator it =
629 numNeighbors < sampleSize; ++it) {
636 double predictionError = fabs(dist - SIMTIME_DBL(cacheEntry.
rtt));
648 absoluteDiff += predictionError;
651 assert(numNeighbors != 0);
652 absoluteDiff /= numNeighbors;
654 return (absoluteDiff > 1.0) ? 1.0 : absoluteDiff;
713 ((dynamic_cast<Nps*>(
ncs) || dynamic_cast<SimpleNcs*>(
ncs) ||
714 (dynamic_cast<SVivaldi*>(
ncs) &&
715 static_cast<SVivaldi*>(
ncs)->getLoss() > 0.95)))) {
762 EV <<
"[NeighborCache::setCbrNodeId() @ "
765 <<
"\n -> nodeID ( 2): "
767 <<
"\n -> nodeID (16): "
787 static_cast<SVivaldi*
>(
ncs)->getOwnError() < 0.2))) {
816 bool messageHandled =
false;
818 if (
ncs && !messageHandled) {
833 return messageHandled;
837 int rpcId, simtime_t rtt) {
845 cPolymorphic* context,
int rpcId) {
857 cPolymorphic *contextPointer)
859 Enter_Method(
"getProx()");
862 queryProx(node, rpcId, listener, contextPointer);
867 delete contextPointer;
872 throw cRuntimeError(
"Prox queried for undefined TransportAddress!");
873 delete contextPointer;
877 bool sendQuery =
false;
963 throw cRuntimeError(
"Unknown query type!");
969 queryProx(node, rpcId, listener, contextPointer);
971 }
else delete contextPointer;
978 Enter_Method(
"estimateProx()");
994 cPolymorphic *contextPointer)
996 Enter_Method(
"queryProx()");
1013 pingNode(node, -1, 0, NULL,
"PING");
1029 throw cRuntimeError(
"NeighborCache.cc: getNodeCoords was asked for "
1030 "a non-existent node reference.");
1048 double tempRttError = prox.
proximity - SIMTIME_DBL(rtt);
1058 if (tempRttError < 0){
1072 (tempRttError / SIMTIME_DBL(rtt)));
1080 throw cRuntimeError(
"NeighborCache.cc: getMeanVarRtt was asked for"
1081 "a non-existent node reference.");
1085 if (size == 0)
return std::make_pair(-1.0,-1.0);
1087 simtime_t rttSum = 0;
1088 for (
int i = 0; i < size; i++){
1091 simtime_t meanRtt = rttSum / size;
1093 return std::make_pair(meanRtt, -1.0);
1096 return std::make_pair(meanRtt, 0.0);
1100 for (
int i = 0; i < size; i++){
1101 simtime_t tempRtt =
neighborCache[node].lastRtts.at(i) - meanRtt;
1102 sum += (SIMTIME_DBL(tempRtt) * SIMTIME_DBL(tempRtt));
1105 return std::make_pair(meanRtt, (sum / size));
1120 simtime_t timeout = -1;
1124 std::pair<simtime_t, simtime_t> temp =
getMeanVarRtt(node,
true);
1125 simtime_t meanRtt = temp.first;
1126 simtime_t varRtt = temp.second;
1129 if (meanRtt == -1)
return -1;
1132 timeout = meanRtt + 4 * varRtt;
1135 timeout = meanRtt * 1.2;
1147 double timeout = -1;