#include <SimpleNcs.h>
Public Member Functions | |
SimpleNcs () | |
virtual | ~SimpleNcs () |
virtual void | init (NeighborCache *neighborCache) |
Prox | getCoordinateBasedProx (const AbstractNcsNodeInfo &info) const |
virtual AbstractNcsNodeInfo * | getUnvalidNcsInfo () const |
virtual AbstractNcsNodeInfo * | createNcsInfo (const std::vector< double > &coords) const |
const AbstractNcsNodeInfo & | getOwnNcsInfo () const |
const std::vector< double > & | getOwnCoordinates () const |
Protected Attributes | |
NeighborCache * | neighborCache |
Private Types | |
enum | delayFaultTypeNum { delayFaultUndefined, delayFaultLiveAll, delayFaultLivePlanetlab, delayFaultSimulation } |
Private Member Functions | |
simtime_t | falsifyDelay (simtime_t oldDelay) const |
Private Attributes | |
SimpleCoordsInfo * | ownCoords |
uint32_t | dimension |
Static Private Attributes | |
static std::map< std::string, delayFaultTypeNum > | delayFaultTypeMap |
static std::string | delayFaultTypeString |
static bool | faultyDelay |
Definition at line 35 of file SimpleNcs.h.
enum SimpleNcs::delayFaultTypeNum [private] |
Definition at line 46 of file SimpleNcs.h.
{ delayFaultUndefined, delayFaultLiveAll, delayFaultLivePlanetlab, delayFaultSimulation };
SimpleNcs::SimpleNcs | ( | ) | [inline] |
Definition at line 60 of file SimpleNcs.h.
{ ownCoords = NULL; };
virtual SimpleNcs::~SimpleNcs | ( | ) | [inline, virtual] |
Definition at line 61 of file SimpleNcs.h.
{ delete ownCoords; };
AbstractNcsNodeInfo * SimpleNcs::createNcsInfo | ( | const std::vector< double > & | coords | ) | const [virtual] |
Implements AbstractNcs.
Definition at line 79 of file SimpleNcs.cc.
{ assert(coords.size() > 1); SimpleCoordsInfo* info = new SimpleCoordsInfo(); uint8_t i; for (i = 0; i < coords.size() - 1; ++i) { info->setCoords(i, coords[i]); } info->setAccessDelay(coords[i]); return info; }
simtime_t SimpleNcs::falsifyDelay | ( | simtime_t | oldDelay | ) | const [private] |
Definition at line 102 of file SimpleNcs.cc.
Referenced by getCoordinateBasedProx().
{ // hash over string of oldDelay char delaystring[35]; sprintf(delaystring, "%.30f", SIMTIME_DBL(oldDelay)); CSHA1 sha1; uint8_t hashOverDelays[20]; sha1.Reset(); sha1.Update((uint8_t*)delaystring, 32); sha1.Final(); sha1.GetHash(hashOverDelays); // get the hash's first 4 bytes == 32 bits as one unsigned integer uint32_t decimalhash = 0; for (int i = 0; i < 4; i++) { decimalhash += (unsigned int) hashOverDelays[i] * (2 << (8 * (3 - i) - 1)); } // normalize decimal hash value onto 0..1 (decimal number / 2^32-1) double fraction = (double) decimalhash / (uint32_t) ((2 << 31) - 1); // flip a coin if faulty rtt is larger or smaller char sign = (decimalhash % 2 == 0) ? 1 : -1; // get the error ratio according to the distributions in // "Network Coordinates in the Wild", Figure 7 double errorRatio = 0; switch (delayFaultTypeMap[delayFaultTypeString]) { case delayFaultLiveAll: // Kumaraswamy, a=2.03, b=14, moved by 0.04 to the right errorRatio = pow((1.0 - pow(fraction, 1.0 / 14.0)), 1.0 / 2.03) + 0.04; break; case delayFaultLivePlanetlab: // Kumaraswamy, a=1.95, b=50, moved by 0.105 to the right errorRatio = pow((1.0 - pow(fraction, 1.0 / 50.0)), 1.0 / 1.95) + 0.105; break; case delayFaultSimulation: // Kumaraswamy, a=1.96, b=23, moved by 0.02 to the right errorRatio = pow((1.0 - pow(fraction, 1.0 / 23.0)), 1.0 / 1.96) + 0.02; //std::cout << "ErrorRatio: " << errorRatio << std::endl; break; default: break; } // If faulty rtt is smaller, set errorRatio to max 0.6 errorRatio = (sign == -1 && errorRatio > 0.6) ? 0.6 : errorRatio; return oldDelay + sign * errorRatio * oldDelay; }
Prox SimpleNcs::getCoordinateBasedProx | ( | const AbstractNcsNodeInfo & | info | ) | const [virtual] |
Implements AbstractNcs.
Definition at line 94 of file SimpleNcs.cc.
{ if (faultyDelay) { return falsifyDelay(ownCoords->getDistance(abstractInfo) /* + Rx */); } return ownCoords->getDistance(abstractInfo) /* + Rx */; }
const std::vector<double>& SimpleNcs::getOwnCoordinates | ( | ) | const [inline] |
Definition at line 71 of file SimpleNcs.h.
const AbstractNcsNodeInfo& SimpleNcs::getOwnNcsInfo | ( | ) | const [inline, virtual] |
virtual AbstractNcsNodeInfo* SimpleNcs::getUnvalidNcsInfo | ( | ) | const [inline, virtual] |
Implements AbstractNcs.
Definition at line 67 of file SimpleNcs.h.
{ return new SimpleCoordsInfo(); };
void SimpleNcs::init | ( | NeighborCache * | neighborCache | ) | [virtual] |
Implements AbstractNcs.
Definition at line 36 of file SimpleNcs.cc.
{ delayFaultTypeMap["live_all"] = delayFaultLiveAll; delayFaultTypeMap["live_planetlab"] = delayFaultLivePlanetlab; delayFaultTypeMap["simulation"] = delayFaultSimulation; this->neighborCache = neighborCache; delayFaultTypeString = neighborCache->par("simpleNcsDelayFaultType").stdstringValue(); switch (delayFaultTypeMap[delayFaultTypeString]) { case SimpleNcs::delayFaultLiveAll: case SimpleNcs::delayFaultLivePlanetlab: case SimpleNcs::delayFaultSimulation: faultyDelay = true; break; default: faultyDelay = false; } PeerInfo* peerInfo = GlobalNodeListAccess().get() ->getPeerInfo(this->neighborCache->getOverlayThisNode().getIp()); if(peerInfo == NULL) { throw cRuntimeError("No PeerInfo Found"); } SimpleNodeEntry* entry = dynamic_cast<SimpleInfo*>(peerInfo)->getEntry(); SimpleCoordsInfo::setDimension(entry->getDim()); ownCoords = new SimpleCoordsInfo(); for (uint8_t i = 0; i < entry->getDim(); i++) { ownCoords->setCoords(i, entry->getCoords(i) * 0.001); } ownCoords->setAccessDelay((entry->getRxAccessDelay() + 800 / entry->getRxBandwidth() + entry->getTxAccessDelay() + 800 / entry->getTxBandwidth()) / 2.0); }
std::map< std::string, SimpleNcs::delayFaultTypeNum > SimpleNcs::delayFaultTypeMap [static, private] |
Definition at line 52 of file SimpleNcs.h.
Referenced by falsifyDelay(), and init().
std::string SimpleNcs::delayFaultTypeString [static, private] |
Definition at line 53 of file SimpleNcs.h.
Referenced by falsifyDelay(), and init().
uint32_t SimpleNcs::dimension [private] |
Definition at line 42 of file SimpleNcs.h.
bool SimpleNcs::faultyDelay [static, private] |
Definition at line 54 of file SimpleNcs.h.
Referenced by getCoordinateBasedProx(), and init().
NeighborCache* SimpleNcs::neighborCache [protected] |
Definition at line 57 of file SimpleNcs.h.
SimpleCoordsInfo* SimpleNcs::ownCoords [private] |
Definition at line 39 of file SimpleNcs.h.
Referenced by getCoordinateBasedProx(), getOwnCoordinates(), getOwnNcsInfo(), init(), SimpleNcs(), and ~SimpleNcs().