OverSim
SimpleNcs Class Reference

#include <SimpleNcs.h>

Inheritance diagram for SimpleNcs:
AbstractNcs

Public Member Functions

 SimpleNcs ()
virtual ~SimpleNcs ()
virtual void init (NeighborCache *neighborCache)
Prox getCoordinateBasedProx (const AbstractNcsNodeInfo &info) const
virtual AbstractNcsNodeInfogetUnvalidNcsInfo () const
virtual AbstractNcsNodeInfocreateNcsInfo (const std::vector< double > &coords) const
const AbstractNcsNodeInfogetOwnNcsInfo () const
const std::vector< double > & getOwnCoordinates () const
- Public Member Functions inherited from AbstractNcs
virtual ~AbstractNcs ()
virtual bool isReady ()
virtual void processCoordinates (const simtime_t &rtt, const AbstractNcsNodeInfo &nodeInfo)
virtual void handleTimerEvent (cMessage *msg)
virtual bool handleRpcCall (BaseCallMessage *msg)

Protected Attributes

NeighborCacheneighborCache

Private Types

enum  delayFaultTypeNum { delayFaultUndefined, delayFaultLiveAll, delayFaultLivePlanetlab, delayFaultSimulation }

Private Member Functions

simtime_t falsifyDelay (simtime_t oldDelay) const

Private Attributes

SimpleCoordsInfoownCoords
uint32_t dimension

Static Private Attributes

static std::map< std::string,
delayFaultTypeNum
delayFaultTypeMap
static std::string delayFaultTypeString
static bool faultyDelay

Detailed Description

Definition at line 35 of file SimpleNcs.h.

Member Enumeration Documentation

Enumerator:
delayFaultUndefined 
delayFaultLiveAll 
delayFaultLivePlanetlab 
delayFaultSimulation 

Definition at line 46 of file SimpleNcs.h.

Constructor & Destructor Documentation

SimpleNcs::SimpleNcs ( )
inline

Definition at line 60 of file SimpleNcs.h.

{ ownCoords = NULL; };
virtual SimpleNcs::~SimpleNcs ( )
inlinevirtual

Definition at line 61 of file SimpleNcs.h.

{ delete ownCoords; };

Member Function Documentation

AbstractNcsNodeInfo * SimpleNcs::createNcsInfo ( const std::vector< double > &  coords) const
virtual

Implements AbstractNcs.

Definition at line 79 of file SimpleNcs.cc.

{
assert(coords.size() > 1);
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;
// 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;
// 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;
// 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.

{ return ownCoords->getCoords(); };
const AbstractNcsNodeInfo& SimpleNcs::getOwnNcsInfo ( ) const
inlinevirtual

Implements AbstractNcs.

Definition at line 70 of file SimpleNcs.h.

{ return *ownCoords; };
virtual AbstractNcsNodeInfo* SimpleNcs::getUnvalidNcsInfo ( ) const
inlinevirtual

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.

{
this->neighborCache = neighborCache;
neighborCache->par("simpleNcsDelayFaultType").stdstringValue();
faultyDelay = true;
break;
default:
faultyDelay = false;
}
PeerInfo* peerInfo =
->getPeerInfo(this->neighborCache->getOverlayThisNode().getIp());
if(peerInfo == NULL) {
throw cRuntimeError("No PeerInfo Found");
}
SimpleNodeEntry* entry = dynamic_cast<SimpleInfo*>(peerInfo)->getEntry();
for (uint8_t i = 0; i < entry->getDim(); i++) {
ownCoords->setCoords(i, entry->getCoords(i));
}
ownCoords->setAccessDelay((entry->getRxAccessDelay() +
800 / entry->getRxBandwidth() +
entry->getTxAccessDelay() +
800 / entry->getTxBandwidth()) / 2.0);
}

Member Data Documentation

std::map< std::string, SimpleNcs::delayFaultTypeNum > SimpleNcs::delayFaultTypeMap
staticprivate

Definition at line 52 of file SimpleNcs.h.

Referenced by falsifyDelay(), and init().

std::string SimpleNcs::delayFaultTypeString
staticprivate

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
staticprivate

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.

Referenced by init().

SimpleCoordsInfo* SimpleNcs::ownCoords
private

The documentation for this class was generated from the following files: