Nps Class Reference

#include <Nps.h>

Inheritance diagram for Nps:
RpcListener AbstractNcs

List of all members.

Public Member Functions

 Nps ()
void init (NeighborCache *neighborCache)
virtual bool isAdapting ()
void handleTimerEvent (cMessage *msg)
virtual bool handleRpcCall (BaseCallMessage *msg)
Prox getCoordinateBasedProx (const AbstractNcsNodeInfo &info) const
AbstractNcsNodeInfogetUnvalidNcsInfo () const
AbstractNcsNodeInfocreateNcsInfo (const std::vector< double > &coords) const
virtual const AbstractNcsNodeInfogetOwnNcsInfo () const
const std::vector< double > & getOwnCoordinates () const
double getOwnCoordinates (uint8_t i) const
uint8_t getOwnLayer () const

Protected Member Functions

void computeOwnLayer (const std::vector< LandmarkDataEntry > &landmarks)
 computes this node's NPS layer (max of reference points' layers + 1)
void computeOwnCoordinates (const std::vector< LandmarkDataEntry > &landmarks)
 methods for computing own coordinates with the received data
void setOwnLayer (int8_t layer)
 announces node's NPS layer to Bootstrap Oracle and Neighbor Cache
void setOwnCoordinates (const std::vector< double > &coords)
void sendCoordRequests ()
 Get a random set of landmarks / NPS reference node and send coordinate requests to them.
void sendCoordRequests (const std::vector< TransportAddress > &landmarks)
void sendCoordsReqCall (const TransportAddress &dest, simtime_t timeout)
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
void coordsReqRpcResponse (CoordsReqResponse *response, cPolymorphic *context, int rpcId, simtime_t rtt)
void coordsReqRpc (CoordsReqCall *msg)
std::vector< LandmarkDataEntrygetLandmarkData () const
std::vector< TransportAddressgetLandmarks (uint8_t howmany)
 Askes GlobalNodeList for appropriate landmark nodes.
const std::vector
< TransportAddress > & 
getLandmarkSet () const
uint16_t getLandmarkSetSize () const
bool setLandmarkSet (uint8_t howManyLM, uint8_t maxLayer, std::vector< TransportAddress > *landmarkSet)
bool enoughLandmarks ()
void updateNodeMeasurement (const TransportAddress &node, uint8_t pending=0, uint8_t sent=0, uint8_t passed=0)
void deleteNodeMeasurement (const TransportAddress &node)
uint16_t getReceivedCalls () const

Protected Attributes

std::vector< RttMeasurementnodeMeasurements

Private Attributes

NeighborCacheneighborCache
BaseOverlayoverlay
GlobalNodeListglobalNodeList
CoordBasedRoutingcoordBasedRouting
uint8_t npsMaxLayer
uint8_t npsDimensions
simtime_t landmarkTimeout
GnpNpsCoordsInfoownCoords
int16_t pendingRequests
uint8_t coordCalcRuns
std::vector< TransportAddresslandmarkSet
uint16_t receivedCalls
cMessage * landmarkTimer

Friends

class Landmark

Detailed Description

Definition at line 76 of file Nps.h.


Constructor & Destructor Documentation

Nps::Nps (  )  [inline]

Definition at line 102 of file Nps.h.

00102 {};


Member Function Documentation

void Nps::computeOwnCoordinates ( const std::vector< LandmarkDataEntry > &  landmarks  )  [protected]

methods for computing own coordinates with the received data

Definition at line 495 of file Nps.cc.

Referenced by coordsReqRpcResponse().

00496 {
00497     CoordCalcFunction coordcalcf(landmarks);
00498 
00499     Vec_DP initCoordinates(npsDimensions);
00500     Vec_DP bestCoordinates(npsDimensions);
00501     std::vector<double> computedCoordinatesStdVector(npsDimensions);
00502 
00503     double bestval;
00504     double resval;
00505 
00506     for (uint runs = 0; runs < coordCalcRuns; runs++) {
00507         // start with random coordinates (-100..100 in each dim)
00508         for (uint i = 0; i < npsDimensions; i++) {
00509             initCoordinates[i] = uniform(-100, 100);
00510         }
00511         // compute minimum coordinates via Simplex-Downhill minimum
00512         // function value is returned, coords are written into initCoordinates
00513         // (call by reference)
00514         resval = CoordCalcFunction::simplex_min(&coordcalcf, initCoordinates);
00515         if (runs == 0 || (runs > 0 && resval < bestval) ) {
00516             bestval = resval;
00517             bestCoordinates = initCoordinates;
00518         }
00519     }
00520 
00521     for (uint i = 0; i < npsDimensions; i++) {
00522         computedCoordinatesStdVector[i] = bestCoordinates[i];
00523     }
00524 
00525     setOwnCoordinates(computedCoordinatesStdVector);
00526 }

void Nps::computeOwnLayer ( const std::vector< LandmarkDataEntry > &  landmarks  )  [protected]

computes this node's NPS layer (max of reference points' layers + 1)

Definition at line 449 of file Nps.cc.

Referenced by coordsReqRpcResponse().

00450 {
00451     int8_t computedLayer = getOwnLayer();
00452     for (uint i = 0; i < landmarks.size(); i++) {
00453         if (computedLayer <= landmarks[i].layer) {
00454             computedLayer = landmarks[i].layer + 1;
00455         }
00456     }
00457     setOwnLayer(computedLayer);
00458 }

void Nps::coordsReqRpc ( CoordsReqCall *  msg  )  [protected]

Definition at line 160 of file Nps.cc.

Referenced by handleRpcCall().

00161 {
00162     receivedCalls++;
00163     CoordsReqResponse* coordResp = new CoordsReqResponse("CoordsReqResp");
00164     coordResp->setLayer(getOwnLayer()); //TODO
00165     coordResp->setNcsInfoArraySize(npsDimensions + 1);
00166 
00167     //if (getOwnLayer() != 0) {
00168     // ordinary node
00169 
00170     const std::vector<double>& ownCoordinates = getOwnCoordinates();
00171 
00172     uint8_t i;
00173     for (i = 0; i < ownCoordinates.size(); ++i) {
00174         coordResp->setNcsInfo(i, ownCoordinates[i]);
00175     }
00176     coordResp->setNcsInfo(i, getOwnLayer());
00177 
00178     /*} else {
00179         // landmark node
00180         Landmark* landmark = check_and_cast<Landmark*>(neighborCache->getParentModule()
00181             ->getModuleByRelativePath("tier1.landmark"));
00182         assert(landmark);
00183         const std::vector<double>& ownCoordinates = landmark->getOwnNpsCoords();
00184 
00185         uint8_t i;
00186         for (i = 0; i < ownCoordinates.size(); ++i) {
00187             coordResp->setNcsInfo(i, ownCoordinates[i]);
00188         }
00189         coordResp->setNcsInfo(i, getOwnLayer());
00190     }*/
00191 
00192     coordResp->setBitLength(COORDSREQRESPONSE_L(coordResp));
00193     neighborCache->sendRpcResponse(msg, coordResp);
00194 }

void Nps::coordsReqRpcResponse ( CoordsReqResponse *  response,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected]

Definition at line 207 of file Nps.cc.

Referenced by handleRpcResponse().

00209 {
00210     pendingRequests--;
00211     NodeHandle& srcNode = response->getSrcNode();
00212 
00213     std::vector<double> tempCoords;
00214     for (uint8_t i = 0; i < response->getNcsInfoArraySize(); i++) {
00215         tempCoords.push_back(response->getNcsInfo(i));
00216     }
00217     GnpNpsCoordsInfo* coordsInfo =
00218         static_cast<GnpNpsCoordsInfo*>(createNcsInfo(tempCoords));
00219 
00220     EV << "[Nps::coordsReqRpcResponse() @ " << neighborCache->thisNode.getAddress()
00221        << " (" << neighborCache->thisNode.getKey().toString(16) << ")]\n    received landmark coords: "
00222        << tempCoords[0];
00223 
00224     for (uint8_t i = 1; i < npsDimensions; i++) {
00225         EV << ", " << tempCoords[i];
00226     }
00227     EV  << " (rtt = " << rtt << ")" << endl;
00228 
00229 #ifdef EXTJOIN_DISCOVERY
00230     if (doingDiscovery()) {
00231         //if in Discovery insert RTT only if lower then already set RTT
00232         if ((isEntry(srcNode) && rtt < getNodeRtt(srcNode))
00233             || (isEntry(srcNode) && getNodeRtt(srcNode) < 0) ) {
00234             updateNode(srcNode, rtt, tempCoords, 0);
00235         } else if (!(isEntry(srcNode))) {
00236             updateNode(srcNode, rtt, tempCoords, 0);
00237         } else {
00238             updateNode(srcNode, getNodeRtt(srcNode), tempCoords, 0);
00239         }
00240         setNodeLayer(srcNode, tempLayer);
00241     }
00242     else if (doingNodeMeasurement()) {
00243         if (getPendingRttsReq(srcNode) == -1) {
00244             updateNode(srcNode, rtt, tempCoords, 0);
00245             setNodeLayer(srcNode, tempLayer);
00246             RttToNodeCall* prevCall = getNodeMessage(srcNode);
00247 
00248             RttToNodeResponse* rttRes = new RttToNodeResponse("RttToNodeXRes");
00249             rttRes->setPingedNode(srcNode);
00250             rttRes->setRttToNode(rtt);
00251             std::vector<double> tempOwnCoords;
00252             tempOwnCoords = getOwnCoordinates();
00253             rttRes->setOwnCoordinatesArraySize(tempOwnCoords.size());
00254             for (uint i = 0; i < tempOwnCoords.size(); i++) {
00255                 rttRes->setOwnCoordinates(i, tempOwnCoords[i]);
00256             }
00257 
00258             sendRpcResponse(prevCall, rttRes);
00259             deleteNodeMeasurement(srcNode);
00260         } else {
00261             updateNode(srcNode, rtt, tempCoords, 0);
00262             setNodeLayer(srcNode, tempLayer);
00263             if (checkCoordinates(getOwnCoordinates(), tempCoords, rtt)) {
00264                 updateNodeMeasurement(srcNode, -1, 0, 1);
00265             } else {
00266                 updateNodeMeasurement(srcNode, -1, 0, 0);
00267             }
00268         }
00269     }
00270     else
00271 #endif
00272     if (pendingRequests == 0) {
00273         // got all responses, now compute own coordinates and join overlay
00274         neighborCache->updateNode(srcNode, rtt, NodeHandle::UNSPECIFIED_NODE,
00275                                   coordsInfo);
00276 
00277         std::vector<LandmarkDataEntry> probedLandmarks;
00278         if (getLandmarkSetSize() < npsDimensions + 1) {
00279             setLandmarkSet(npsDimensions + 1, npsMaxLayer, &landmarkSet);
00280         }
00281 
00282         for (std::vector<TransportAddress>::iterator it = landmarkSet.begin();
00283              it != landmarkSet.end(); ++it) {
00284             const GnpNpsCoordsInfo* tempInfo =
00285                 dynamic_cast<const GnpNpsCoordsInfo*>(neighborCache->getNodeCoordsInfo(*it));
00286 
00287             assert(tempInfo);
00288 
00289             LandmarkDataEntry temp;
00290             temp.coordinates.resize(tempInfo->getDimension());
00291             temp.rtt = neighborCache->getNodeRtt(*it).first;
00292             temp.layer = tempInfo->getLayer();
00293             for (uint8_t i = 0; i < tempInfo->getDimension(); ++i) {
00294                 temp.coordinates[i] = tempInfo->getCoords(i);
00295             }
00296             temp.ip = NULL;
00297 
00298             probedLandmarks.push_back(temp);
00299         }
00300         assert(probedLandmarks.size() > 0);
00301 
00302         computeOwnCoordinates(probedLandmarks);
00303         computeOwnLayer(probedLandmarks);
00304 
00305         std::vector<double> coords = getOwnCoordinates();
00306         EV << "[Nps::coordsReqRpcResponse() @ " << neighborCache->thisNode.getAddress()
00307            << " (" << neighborCache->thisNode.getKey().toString(16) << ")]\n    setting own coords: "
00308            << coords[0];
00309         for (uint8_t i = 1; i < npsDimensions; i++) {
00310             EV << ", " << coords[i];
00311         }
00312         EV << endl;
00313 
00314         //test
00315         /*
00316         ChurnGenerator* lmChurnGen = NULL;
00317         for (uint8_t i = 0; i < neighborCache->underlayConfigurator->getChurnGeneratorNum(); i++) {
00318             ChurnGenerator* searchedGen;
00319             searchedGen = neighborCache->underlayConfigurator->getChurnGenerator(i);
00320             if (searchedGen->getNodeType().overlayType != "oversim.common.cbr.LandmarkModules") {
00321                 lmChurnGen = searchedGen;
00322             }
00323         }
00324         */
00325 
00326         SimpleNodeEntry* entry =
00327                 dynamic_cast<SimpleInfo*>(globalNodeList->
00328                                           getPeerInfo(neighborCache->thisNode.getAddress()))->getEntry();
00329 
00330         double error = 0;
00331         for (uint8_t i = 1; i < entry->getDim(); i++) {
00332             error += pow(coords[i] - entry->getCoords(i), 2);
00333         }
00334         error = sqrt(error);
00335 
00336         neighborCache->globalStatistics
00337           ->addStdDev("NPS: Coordinate difference", error);
00338 
00339         neighborCache->neighborCache.clear(); //TODO
00340         neighborCache->neighborCacheExpireMap.clear(); //TODO
00341 
00342         neighborCache->getParentModule()
00343             ->bubble("GNP/NPS coordinates calculated -> JOIN overlay!");
00344 
00345         if (coordBasedRouting) {
00346             int bitsPerDigit = neighborCache->overlay->getBitsPerDigit();
00347             neighborCache->thisNode.setKey(
00348                 coordBasedRouting->getNodeId(coords, bitsPerDigit,
00349                                              OverlayKey::getLength()));
00350 
00351             EV << "[Nps::coordsReqRpcResponse() @ "
00352                << neighborCache->thisNode.getAddress()
00353                << " (" << neighborCache->thisNode.getKey().toString(16) << ")]"
00354                << "\n    -> nodeID ( 2): "
00355                << neighborCache->thisNode.getKey().toString(2)
00356                << "\n    -> nodeID (16): "
00357                << neighborCache->thisNode.getKey().toString(16) << endl;
00358 
00359             // returning to BaseOverlay
00360             neighborCache->overlay->join(neighborCache->thisNode.getKey());
00361         } else {
00362             // returning to BaseOverlay
00363             neighborCache->overlay->join();
00364         }
00365     } else {
00366         neighborCache->updateNode(srcNode, rtt, NodeHandle::UNSPECIFIED_NODE,
00367                                   coordsInfo);
00368     }
00369 }

AbstractNcsNodeInfo * Nps::createNcsInfo ( const std::vector< double > &  coords  )  const [virtual]

Implements AbstractNcs.

Definition at line 633 of file Nps.cc.

Referenced by coordsReqRpcResponse().

00634 {
00635     assert(coords.size() > 1);
00636     GnpNpsCoordsInfo* info = new GnpNpsCoordsInfo();
00637 
00638     uint8_t i;
00639     for (i = 0; i < coords.size() - 1; ++i) {
00640         info->setCoords(i, coords[i]);
00641     }
00642     info->setLayer(coords[i]);
00643 
00644     return info;
00645 }

void Nps::deleteNodeMeasurement ( const TransportAddress node  )  [protected]

Definition at line 616 of file Nps.cc.

Referenced by coordsReqRpcResponse(), and handleRpcTimeout().

00617 {
00618     for(uint i = 0; i < nodeMeasurements.size(); i++) {
00619         if (nodeMeasurements[i].measuredNode == node) {
00620 #ifdef EXTJOIN_DISCOVERY
00621             delete nodeMeasurements[i].message;
00622 #endif
00623             nodeMeasurements.erase(nodeMeasurements.begin()+i);
00624             i--;
00625         }
00626     }
00627     if (nodeMeasurements.size() == 0) {
00628         //stopNodeMeasurement();
00629     }
00630 }

bool Nps::enoughLandmarks (  )  [protected]

Definition at line 555 of file Nps.cc.

Referenced by handleTimerEvent().

00556 {
00557     return (globalNodeList->getLandmarkPeerSize() > npsDimensions);
00558 }

Prox Nps::getCoordinateBasedProx ( const AbstractNcsNodeInfo info  )  const [virtual]

Implements AbstractNcs.

Definition at line 561 of file Nps.cc.

00562 {
00563     return ownCoords->getDistance(abstractInfo);
00564 
00565     /*
00566     if (!dynamic_cast<const GnpNpsCoordsInfo*>(&abstractInfo)) {
00567             throw cRuntimeError("GNP/NPS coords needed!");
00568     }
00569 
00570     const GnpNpsCoordsInfo& info =
00571         *(static_cast<const GnpNpsCoordsInfo*>(&abstractInfo));
00572 
00573     double dist = 0.0;
00574     uint32_t size = info.getDimension();
00575 
00576     for (uint32_t i = 0; i < size; i++) {
00577         dist += pow(ownCoords->getCoords(i) - info.getCoords(i), 2);
00578     }
00579     dist = sqrt(dist);
00580 
00581     return Prox(dist, 0.0); //TODO accuracy
00582     */
00583 }

std::vector<LandmarkDataEntry> Nps::getLandmarkData (  )  const [protected]
std::vector< TransportAddress > Nps::getLandmarks ( uint8_t  howmany  )  [protected]

Askes GlobalNodeList for appropriate landmark nodes.

Parameters:
howmany number of needed landmark nodes
Returns:
vector of landmark addresses

Definition at line 528 of file Nps.cc.

Referenced by sendCoordRequests().

00529 {
00530     std::vector<TransportAddress> returnPool;
00531 
00532     if (howmany > globalNodeList->getLandmarkPeerSize()) {
00533         throw cRuntimeError("Not enough landmarks available in network!");
00534     }
00535 
00536     while (returnPool.size() < howmany) {
00537         TransportAddress* lm = globalNodeList->getRandomAliveNode();
00538         PeerInfo* lmInfo = globalNodeList->getPeerInfo(lm->getAddress());
00539         if (lmInfo->getNpsLayer() >= 0 &&
00540             lmInfo->getNpsLayer() < npsMaxLayer) {
00541             // already in returnPool?
00542             bool alreadyin = false;
00543             for (uint8_t i = 0; i < returnPool.size(); i++) {
00544                 if (returnPool[i] == *lm)
00545                     alreadyin = true;
00546             }
00547             if (alreadyin == false) {
00548                 returnPool.push_back(*lm);
00549             }
00550         }
00551     }
00552     return returnPool;
00553 }

const std::vector<TransportAddress>& Nps::getLandmarkSet (  )  const [inline, protected]

Definition at line 172 of file Nps.h.

00172 { return landmarkSet; };

uint16_t Nps::getLandmarkSetSize (  )  const [inline, protected]

Definition at line 173 of file Nps.h.

Referenced by coordsReqRpcResponse().

00173 { return landmarkSet.size(); };

double Nps::getOwnCoordinates ( uint8_t  i  )  const [inline]

Definition at line 115 of file Nps.h.

00115 { return ownCoords->getCoords(i); };

const std::vector<double>& Nps::getOwnCoordinates (  )  const [inline]

Definition at line 114 of file Nps.h.

Referenced by coordsReqRpc(), coordsReqRpcResponse(), and handleRpcTimeout().

00114 { return ownCoords->getCoords(); };

uint8_t Nps::getOwnLayer (  )  const [inline]

Definition at line 116 of file Nps.h.

Referenced by computeOwnLayer(), and coordsReqRpc().

00116 { return ownCoords->getLayer(); };

virtual const AbstractNcsNodeInfo& Nps::getOwnNcsInfo (  )  const [inline, virtual]

Implements AbstractNcs.

Definition at line 112 of file Nps.h.

00112 { return *ownCoords; };

uint16_t Nps::getReceivedCalls (  )  const [inline, protected]

Definition at line 188 of file Nps.h.

00188 { return receivedCalls; };

AbstractNcsNodeInfo* Nps::getUnvalidNcsInfo (  )  const [inline, virtual]

Implements AbstractNcs.

Definition at line 110 of file Nps.h.

00110 {return new GnpNpsCoordsInfo; };

bool Nps::handleRpcCall ( BaseCallMessage *  msg  )  [virtual]

Reimplemented from AbstractNcs.

Definition at line 150 of file Nps.cc.

00151 {
00152     RPC_SWITCH_START( msg );
00153         RPC_DELEGATE( CoordsReq, coordsReqRpc );
00154         //if (discovery)
00155     RPC_SWITCH_END( );
00156 
00157     return RPC_HANDLED;
00158 }

void Nps::handleRpcResponse ( BaseResponseMessage *  msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected, virtual]

This method is called if an RPC response has been received.

Parameters:
msg The response message.
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
rtt The Round-Trip-Time of this RPC

Reimplemented from RpcListener.

Definition at line 87 of file Nps.cc.

00090 {
00091     // call rpc stubs
00092     RPC_SWITCH_START( msg );
00093         RPC_ON_RESPONSE( CoordsReq ) {
00094             coordsReqRpcResponse(_CoordsReqResponse, context, rpcId, rtt);
00095         }
00096 #ifdef EXTJOIN_DISCOVERY
00097         RPC_ON_RESPONSE( RttToNode ) {
00098             rttToNodeRpcResponse(_RttToNodeResponse, context, rpcId, rtt);
00099         }
00100 #endif
00101     RPC_SWITCH_END( );
00102 
00103     return;
00104 }

void Nps::handleRpcTimeout ( BaseCallMessage *  msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey 
) [protected, virtual]

This method is called if an RPC timeout has been reached.

Parameters:
msg The original RPC message.
dest The destination node
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
destKey the destination OverlayKey

Reimplemented from RpcListener.

Definition at line 106 of file Nps.cc.

00110 {
00111     RPC_SWITCH_START( msg ) {
00112 
00113         RPC_ON_CALL( CoordsReq ) {
00114             if (true/*doingNodeMeasurement()*/) {//TODO
00115 #ifdef EXTJOIN_DISCOVERY
00116                 if (getPendingRttsReq(dest) == -1) {
00117                     RttToNodeCall* call = getNodeMessage(dest);
00118 
00119                     RttToNodeResponse* rttRes = new RttToNodeResponse("RttToNodeXRes");
00120                     rttRes->setPingedNode(dest);
00121                     rttRes->setRttToNode(0);
00122                     std::vector<double> tempOwnCoords;
00123                     tempOwnCoords = getOwnCoordinates();
00124                     rttRes->setOwnCoordinatesArraySize(tempOwnCoords.size());
00125                     for (uint i = 0; i < tempOwnCoords.size(); i++) {
00126                         rttRes->setOwnCoordinates(i, tempOwnCoords[i]);
00127                     }
00128                     sendRpcResponse(call, rttRes);
00129                     deleteNodeMeasurement(dest);
00130                 } else {
00131 #endif
00132                     updateNodeMeasurement(dest, -1);
00133 #ifdef EXTJOIN_DISCOVERY
00134                 }
00135 #endif
00136 
00137             } else {
00138                 pendingRequests--;
00139             }
00140         }
00141 #ifdef EXTJOIN_DISCOVERY
00142         RPC_ON_CALL( RttToNode ) {
00143             updateNodeMeasurement(dest, -1);
00144         }
00145 #endif
00146     }
00147     RPC_SWITCH_END( )
00148 }

void Nps::handleTimerEvent ( cMessage *  msg  )  [virtual]

Reimplemented from AbstractNcs.

Definition at line 73 of file Nps.cc.

00074 {
00075     // process landmark timer message
00076     if (msg == landmarkTimer) {
00077         if (enoughLandmarks()) {
00078             delete msg;
00079             //std::cout << "[" << getThisNode().getAddress() << "] (Re-)Trying to contact landmarks" << std::endl;
00080             sendCoordRequests();
00081         } else {
00082             neighborCache->scheduleAt(simTime() + landmarkTimeout, msg);
00083         }
00084     }
00085 }

void Nps::init ( NeighborCache neighborCache  )  [virtual]

Implements AbstractNcs.

Definition at line 41 of file Nps.cc.

00042 {
00043     this->neighborCache = neighborCache;
00044     overlay = neighborCache->overlay;
00045 
00046     npsMaxLayer = neighborCache->par("npsMaxLayer");
00047     npsDimensions = neighborCache->par("npsDimensions");
00048     landmarkTimeout = neighborCache->par("landmarkTimeout");
00049 
00050     GnpNpsCoordsInfo::setDimension(npsDimensions);
00051     ownCoords = new GnpNpsCoordsInfo();
00052 
00053     receivedCalls = 0;
00054     pendingRequests = 0;
00055     coordCalcRuns = neighborCache->par("npsCoordCalcRuns");
00056 
00057     WATCH(*ownCoords);
00058     WATCH_VECTOR(landmarkSet);
00059 
00060     coordBasedRouting = CoordBasedRoutingAccess().get();
00061     globalNodeList = GlobalNodeListAccess().get();
00062 
00063     if (neighborCache->getParentModule()->getModuleByRelativePath("tier1")
00064         ->getModuleByRelativePath("landmark") == NULL) {
00065         landmarkTimer = new cMessage("landmarkTimer");
00066         neighborCache->scheduleAt(simTime() + landmarkTimeout, landmarkTimer);
00067     } else {
00068         // GNP-landmark or NPS-Layer-0-landmark
00069         ownCoords->setLayer(0); //TODO double, see Landmark.cc
00070     }
00071 }

virtual bool Nps::isAdapting (  )  [inline, virtual]

Implements AbstractNcs.

Definition at line 105 of file Nps.h.

00105 { return false; }

void Nps::sendCoordRequests ( const std::vector< TransportAddress > &  landmarks  )  [protected]
void Nps::sendCoordRequests (  )  [protected]

Get a random set of landmarks / NPS reference node and send coordinate requests to them.

Definition at line 422 of file Nps.cc.

Referenced by handleTimerEvent().

00423 {
00424     std::vector <TransportAddress> landmarks;
00425     landmarks = getLandmarks(npsDimensions + 1);
00426 
00427     simtime_t timeout = -1;
00428 
00429     if (landmarks.size() > 0) {
00430         for (size_t i = 0; i < landmarks.size(); i++) {
00431             const TransportAddress& tolm = landmarks[i];
00432             sendCoordsReqCall(tolm, timeout);
00433         }
00434         setLandmarkSet(npsDimensions + 1, npsMaxLayer, &landmarkSet);
00435     }
00436 }

void Nps::sendCoordsReqCall ( const TransportAddress dest,
simtime_t  timeout 
) [protected]

Definition at line 438 of file Nps.cc.

Referenced by sendCoordRequests().

00440 {
00441     CoordsReqCall* coordReq = new CoordsReqCall("CoordsReq");
00442     coordReq->setBitLength(COORDSREQCALL_L(coordReq));
00443     neighborCache->sendRouteRpcCall(neighborCache->getThisCompType(), dest,
00444                                     coordReq, NULL, NO_OVERLAY_ROUTING,
00445                                     timeout, 0, -1, this);
00446     pendingRequests++;
00447 }

bool Nps::setLandmarkSet ( uint8_t  howManyLM,
uint8_t  maxLayer,
std::vector< TransportAddress > *  landmarkSet 
) [protected]

Definition at line 392 of file Nps.cc.

Referenced by coordsReqRpcResponse(), and sendCoordRequests().

00394 {
00395     landmarkSet->clear();
00396     NeighborCache::NeighborCacheIterator it;
00397     uint availableLM = 0;
00398     TransportAddress landmark;
00399     for(it = neighborCache->neighborCache.begin(); it != neighborCache->neighborCache.end(); it++ ) {
00400         if (dynamic_cast<GnpNpsCoordsInfo*>(it->second.coordsInfo) &&
00401             static_cast<GnpNpsCoordsInfo*>(it->second.coordsInfo)->getLayer()
00402                 < maxLayer) {
00403             landmark.setAddress(it->first.getAddress());
00404             landmark.setPort(it->second.nodeRef.getPort());
00405             landmarkSet->push_back(landmark);
00406             availableLM++;
00407         }
00408     }
00409     if (availableLM < howManyLM) {
00410         return false;
00411     } else {
00412         uint i = availableLM;
00413         while (i > howManyLM) {
00414             uint randomNumber = (intuniform(0, landmarkSet->size()));
00415             landmarkSet->erase(landmarkSet->begin() + randomNumber);
00416             i--;
00417         }
00418         return true;
00419     }
00420 }

void Nps::setOwnCoordinates ( const std::vector< double > &  coords  )  [inline, protected]

Definition at line 133 of file Nps.h.

Referenced by computeOwnCoordinates(), and Landmark::initializeApp().

00133                                                             {
00134         for (uint8_t i = 0; i < coords.size(); ++i) {
00135             ownCoords->setCoords(i, coords[i]);
00136         }
00137     };

void Nps::setOwnLayer ( int8_t  layer  )  [protected]

announces node's NPS layer to Bootstrap Oracle and Neighbor Cache

Definition at line 460 of file Nps.cc.

Referenced by computeOwnLayer(), and Landmark::initializeApp().

00461 {
00462     ownCoords->setLayer(layer);
00463 
00464     // Update in BootstrapOracle
00465     PeerInfo* thisInfo = globalNodeList->getPeerInfo(neighborCache->getThisNode());
00466     thisInfo->setNpsLayer(layer);
00467 
00468     // Workaround against -1 ports in BS oracle
00469     if (layer > 0) globalNodeList->refreshEntry(neighborCache->overlay->getThisNode());
00470     if (layer < npsMaxLayer) {
00471         globalNodeList->incLandmarkPeerSize();
00472         globalNodeList->incLandmarkPeerSizePerType(thisInfo->getTypeID());
00473     }
00474 }

void Nps::updateNodeMeasurement ( const TransportAddress node,
uint8_t  pending = 0,
uint8_t  sent = 0,
uint8_t  passed = 0 
) [protected]

Definition at line 585 of file Nps.cc.

Referenced by coordsReqRpcResponse(), and handleRpcTimeout().

00589 {
00590     bool alreadySet = false;
00591     for(uint i = 0; i < nodeMeasurements.size(); i++) {
00592         if (nodeMeasurements[i].measuredNode == node && sent == 0) {
00593             nodeMeasurements[i].rttsPending += pending;
00594             nodeMeasurements[i].rttsSent += sent;
00595             nodeMeasurements[i].coordsPassed += passed;
00596             alreadySet = true;
00597             i = nodeMeasurements.size();
00598         } else if (nodeMeasurements[i].measuredNode == node) {
00599             nodeMeasurements[i].rttsPending = pending;
00600             nodeMeasurements[i].rttsSent = sent;
00601             nodeMeasurements[i].coordsPassed = passed;
00602             alreadySet = true;
00603             i = nodeMeasurements.size();
00604         }
00605     }
00606     if (!alreadySet) {
00607         RttMeasurement newNode;
00608         newNode.measuredNode = node;
00609         newNode.rttsPending = pending;
00610         newNode.rttsSent = sent;
00611         newNode.coordsPassed = passed;
00612         nodeMeasurements.push_back(newNode);
00613     }
00614 }


Friends And Related Function Documentation

friend class Landmark [friend]

Definition at line 78 of file Nps.h.


Member Data Documentation

Definition at line 84 of file Nps.h.

Referenced by coordsReqRpcResponse(), and init().

uint8_t Nps::coordCalcRuns [private]

Definition at line 93 of file Nps.h.

Referenced by computeOwnCoordinates(), and init().

Definition at line 83 of file Nps.h.

Referenced by coordsReqRpcResponse(), enoughLandmarks(), getLandmarks(), init(), and setOwnLayer().

std::vector<TransportAddress> Nps::landmarkSet [private]
simtime_t Nps::landmarkTimeout [private]

Definition at line 88 of file Nps.h.

Referenced by handleTimerEvent(), and init().

cMessage* Nps::landmarkTimer [private]

Definition at line 99 of file Nps.h.

Referenced by handleTimerEvent(), and init().

std::vector<RttMeasurement> Nps::nodeMeasurements [protected]

Definition at line 179 of file Nps.h.

Referenced by deleteNodeMeasurement(), and updateNodeMeasurement().

uint8_t Nps::npsDimensions [private]
uint8_t Nps::npsMaxLayer [private]

Definition at line 86 of file Nps.h.

Referenced by coordsReqRpcResponse(), getLandmarks(), init(), sendCoordRequests(), and setOwnLayer().

Definition at line 82 of file Nps.h.

Referenced by init().

int16_t Nps::pendingRequests [private]

Definition at line 92 of file Nps.h.

Referenced by coordsReqRpcResponse(), handleRpcTimeout(), init(), and sendCoordsReqCall().

uint16_t Nps::receivedCalls [private]

Definition at line 97 of file Nps.h.

Referenced by coordsReqRpc(), getReceivedCalls(), and init().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:18 2010 for OverSim by  doxygen 1.6.3