46 maxLayer = neighborCache->par(
"npsMaxLayer");
47 dimensions = neighborCache->par(
"gnpDimensions");
65 if (neighborCache->getParentModule()->getModuleByRelativePath(
"tier1")
66 ->getModuleByRelativePath(
"landmark") == NULL) {
90 cPolymorphic* context,
91 int rpcId, simtime_t rtt)
98 #ifdef EXTJOIN_DISCOVERY
100 rttToNodeRpcResponse(_RttToNodeResponse, context, rpcId, rtt);
110 cPolymorphic* context,
int rpcId,
117 #ifdef EXTJOIN_DISCOVERY
118 if (getPendingRttsReq(dest) == -1) {
127 for (uint i = 0; i < tempOwnCoords.size(); i++) {
130 sendRpcResponse(call, rttRes);
135 #ifdef EXTJOIN_DISCOVERY
143 #ifdef EXTJOIN_DISCOVERY
175 for (i = 0; i < ownCoordinates.size(); ++i) {
198 #ifdef EXTJOIN_DISCOVERY
204 setNodeMessage(dest, msg);
210 cPolymorphic* context,
int rpcId, simtime_t rtt)
217 tempCoords.push_back(response->
getNcsInfo(i));
227 EV <<
", " << tempCoords[i];
229 EV <<
" (rtt = " << rtt <<
")" << endl;
231 #ifdef EXTJOIN_DISCOVERY
232 if (doingDiscovery()) {
234 if ((isEntry(srcNode) && rtt < getNodeRtt(srcNode))
235 || (isEntry(srcNode) && getNodeRtt(srcNode) < 0) ) {
236 updateNode(srcNode, rtt, tempCoords, 0);
237 }
else if (!(isEntry(srcNode))) {
238 updateNode(srcNode, rtt, tempCoords, 0);
240 updateNode(srcNode, getNodeRtt(srcNode), tempCoords, 0);
242 setNodeLayer(srcNode, tempLayer);
244 else if (doingNodeMeasurement()) {
245 if (getPendingRttsReq(srcNode) == -1) {
246 updateNode(srcNode, rtt, tempCoords, 0);
247 setNodeLayer(srcNode, tempLayer);
256 for (uint i = 0; i < tempOwnCoords.size(); i++) {
260 sendRpcResponse(prevCall, rttRes);
263 updateNode(srcNode, rtt, tempCoords, 0);
264 setNodeLayer(srcNode, tempLayer);
279 std::vector<LandmarkDataEntry> probedLandmarks;
284 for (std::vector<TransportAddress>::iterator it =
landmarkSet.begin();
295 for (uint8_t i = 0; i < tempInfo->
getDimension(); ++i) {
300 probedLandmarks.push_back(temp);
302 assert(probedLandmarks.size() > 0);
312 EV <<
", " << coords[i];
335 for (uint8_t i = 1; i < entry->
getDim(); i++) {
336 error += pow(coords[i] - entry->
getCoords(i), 2);
342 ->
addStdDev(
"NPS: Coordinate difference", error);
348 ->bubble(
"GNP/NPS coordinates calculated -> JOIN overlay!");
357 #ifdef EXTJOIN_DISCOVERY
359 cPolymorphic* context,
int rpcId, simtime_t rtt)
364 tempCoords.resize(dim);
365 for (uint i = 0; i < dim; i++) {
368 if (checkCoordinates(tempCoords, getNodeCoords(nodeToCheck), response->
getRttToNode())) {
379 std::vector<TransportAddress>* landmarkSet)
381 landmarkSet->clear();
383 uint availableLM = 0;
386 if (dynamic_cast<GnpNpsCoordsInfo*>(it->second.coordsInfo) &&
389 landmark.
setIp(it->first.getIp());
390 landmark.
setPort(it->second.nodeRef.getPort());
391 landmarkSet->push_back(landmark);
395 if (availableLM < howManyLM) {
398 uint i = availableLM;
399 while (i > howManyLM) {
400 uint randomNumber = (intuniform(0, landmarkSet->size()));
401 landmarkSet->erase(landmarkSet->begin() + randomNumber);
410 std::vector <TransportAddress> landmarks;
413 simtime_t timeout = -1;
415 if (landmarks.size() > 0) {
416 for (
size_t i = 0; i < landmarks.size(); i++) {
431 timeout, 0, -1,
this);
438 for (uint i = 0; i < landmarks.size(); i++) {
439 if (computedLayer <= landmarks[i].layer) {
440 computedLayer = landmarks[i].layer + 1;
444 return computedLayer;
463 #ifdef EXTJOIN_DISCOVERY
464 bool Nps::checkCoordinates(
Coords coordsOK,
Coords coordsToCheck, simtime_t dist)
466 simtime_t predDist = 0.0;
468 for (uint i = 0; i < coordsOK.size(); i++) {
469 predDist += pow(coordsOK[i] - coordsToCheck[i], 2);
471 simtime_t predDistLow = sqrt(SIMTIME_DBL(predDist)) * 2 * (1 - 0.3) / 1000;
472 simtime_t predDistHigh = sqrt(SIMTIME_DBL(predDist)) * 2 * (1 + 0.3) / 1000;
473 if (dist > predDistLow && dist < predDistHigh) {
496 initCoordinates[i] = uniform(-300, 300);
502 if (runs == 0 || (runs > 0 && resval < bestval) ) {
504 bestCoordinates = initCoordinates;
509 computedCoordinatesStdVector[i] = bestCoordinates[i];
513 return computedCoordinatesStdVector;
518 std::vector<TransportAddress> returnPool;
521 throw cRuntimeError(
"Not enough landmarks available in network!");
524 while (returnPool.size() < howmany) {
530 bool alreadyin =
false;
531 for (uint8_t i = 0; i < returnPool.size(); i++) {
532 if (returnPool[i] == *lm)
535 if (alreadyin ==
false) {
536 returnPool.push_back(*lm);
562 bool alreadySet =
false;
592 #ifdef EXTJOIN_DISCOVERY
607 assert(coords.size() > 1);
611 for (i = 0; i < coords.size() - 1; ++i) {
612 info->setCoords(i, coords[i]);
614 info->setLayer(coords[i]);
623 double accf = 0.0000001;
624 double accx = 0.0000001;
625 uint32_t nmax = 30001;
626 uint8_t dim = init.
size();
640 for (uint8_t i = 0; i < dim; i++) {
642 spx[i+1] = init + tmp;
648 for (count = 1; count <= nmax; count++) {
659 ihi = spx.
high(&vhi);
662 vre = functionObject->
f(spx[ihi]);
663 if (vre < functionObject->
f(spx[spx.
low()])) {
666 vre = functionObject->
f(spx[ihi]);
667 if (vre > functionObject->
f(spx[spx.
low()])) {
671 }
else if (vre >= vhi) {
674 if (functionObject->
f(spx[ihi]) > vhi) {
684 if (spx.
size() < accx)
687 init = spx[spx.
low()];
696 for (uint i = 0; i <
landmarks.size(); i++) {
698 double diff = SIMTIME_DBL(
landmarks[i].rtt) / 2 * 1000 -
701 if (SIMTIME_DBL(
landmarks[i].rtt) != 0) {
702 rel_diff = diff / (SIMTIME_DBL(
landmarks[i].rtt) / 2 * 1000);
704 opp_error(
"[CBR] RTT == 0. Node is landmark? This shouldn't happen.");
706 sum += rel_diff * rel_diff;
714 double sum_of_squares = 0.0;
715 for (
int i = 0; i < nodeCoordinates.
size(); i++) {
716 sum_of_squares += pow(landmark.
coordinates[i] - nodeCoordinates[i], 2);
718 double result = sqrt(sum_of_squares);