OverSim
SimpleNodeEntry Class Reference

representation of a single node in the GlobalNodeList More...

#include <SimpleNodeEntry.h>

Classes

struct  Channel

Public Types

typedef std::pair< simtime_t,
bool > 
SimpleDelay
 type for return value of calcDelay()

Public Member Functions

 ~SimpleNodeEntry ()
 SimpleNodeEntry (cModule *node, cChannelType *typeRx, cChannelType *typeTx, uint32_t sendQueueLength, uint32_t fieldSize)
 Constructor for node entries with 2D random coordinates.
 SimpleNodeEntry (cModule *node, cChannelType *typeRx, cChannelType *typeTx, uint32_t sendQueueLength, NodeRecord *nodeRecord, int index)
 Constructor for node entries with given n-dim coordinates.
cGate * getUdpIPv4Gate () const
 Getter for SimpleUDP ingate.
cGate * getUdpIPv6Gate () const
 Getter for SimpleUDP IPv6 ingate.
cGate * getTcpIPv4Gate () const
 Getter for SimpleUDP ingate.
cGate * getTcpIPv6Gate () const
 Getter for SimpleUDP IPv6 ingate.
SimpleDelay calcDelay (cPacket *msg, const SimpleNodeEntry &dest, bool faultyDelay=false)
 Calculates delay between two nodes.
SimpleDelay calcAccessRouterDelay (cPacket *msg)
 Calculates delay introduced by send queue at the access router of the destination node.
std::string info () const
 OMNeT++ info method.
simtime_t getAccessDelay () const
simtime_t getTxAccessDelay () const
simtime_t getRxAccessDelay () const
float getBandwidth () const
float getTxBandwidth () const
float getRxBandwidth () const
float getErrorRate () const
void setX (float x)
void setY (float y)
float getX () const
float getY () const
float getCoords (int dim) const
uint8_t getDim () const
int getRecordIndex () const
NodeRecordgetNodeRecord () const

Static Public Member Functions

static simtime_t getFaultyDelay (simtime_t oldDelay)
 Calculates SHA1 hash over errorfree delay (always the same uniform distributed value), uses this to generate a realistic error distribution and returns the real RTT augmented with this error.

Protected Member Functions

float operator- (const SimpleNodeEntry &entry) const
 Calculates euclidean distance between two terminals.

Protected Attributes

cGate * UdpIPv4ingate
 IPv4 ingate of the SimpleUDP module of this terminal.
cGate * UdpIPv6ingate
 IPv6 ingate of the SimpleUDP module of this terminal.
cGate * TcpIPv4ingate
 IPv4 ingate of the SimpleTCP module of this terminal.
cGate * TcpIPv6ingate
 IPv6 ingate of the SimpleTCP module of this terminal.
struct SimpleNodeEntry::Channel rx
struct SimpleNodeEntry::Channel tx
NodeRecordnodeRecord
int index

Friends

std::ostream & operator<< (std::ostream &out, const SimpleNodeEntry &entry)
 Stream output.

Detailed Description

representation of a single node in the GlobalNodeList

Author
Bernhard Heep

Definition at line 62 of file SimpleNodeEntry.h.

Member Typedef Documentation

typedef std::pair<simtime_t, bool> SimpleNodeEntry::SimpleDelay

type for return value of calcDelay()

Definition at line 135 of file SimpleNodeEntry.h.

Constructor & Destructor Documentation

SimpleNodeEntry::~SimpleNodeEntry ( )
inline

Definition at line 66 of file SimpleNodeEntry.h.

{
if (index == -1) delete nodeRecord;
}
SimpleNodeEntry::SimpleNodeEntry ( cModule *  node,
cChannelType *  typeRx,
cChannelType *  typeTx,
uint32_t  sendQueueLength,
uint32_t  fieldSize 
)

Constructor for node entries with 2D random coordinates.

Parameters
nodepointer to new terminal
typeRxreceive access channel of new terminal
typeTxtransmit access channel of new terminal
sendQueueLengthinitial send queue size
fieldSizelength of one side of the coordinate space

Definition at line 87 of file SimpleNodeEntry.cc.

{
assert(NodeRecord::dim == 2);
index = -1;
// use random values as coordinates
nodeRecord->coords[0] = uniform(0, fieldSize) - fieldSize / 2;
nodeRecord->coords[1] = uniform(0, fieldSize) - fieldSize / 2;
SimpleNodeEntry(node, typeRx, typeTx, sendQueueLength, nodeRecord, index);
}
SimpleNodeEntry::SimpleNodeEntry ( cModule *  node,
cChannelType *  typeRx,
cChannelType *  typeTx,
uint32_t  sendQueueLength,
NodeRecord nodeRecord,
int  index 
)

Constructor for node entries with given n-dim coordinates.

Parameters
nodepointer to new terminal
typeRxreceive access channel of new terminal
typeTxtransmit access channel of new terminal
sendQueueLengthlength of the send queue in bytes
nodeRecordthe node's coordinates
indexthe position in unusedNodeRecords

Definition at line 105 of file SimpleNodeEntry.cc.

{
cModule* udpModule = node->getSubmodule("udp");
UdpIPv4ingate = udpModule->gate("ipIn");
UdpIPv6ingate = udpModule->gate("ipv6In");
cModule* tcpModule = node->getSubmodule("tcp", 0);
if (tcpModule) {
TcpIPv4ingate = tcpModule->gate("ipIn");
TcpIPv6ingate = tcpModule->gate("ipv6In");
}
this->nodeRecord = nodeRecord;
this->index = index;
cDatarateChannel* tempRx = dynamic_cast<cDatarateChannel*>(typeRx->create("temp"));
cDatarateChannel* tempTx = dynamic_cast<cDatarateChannel*>(typeTx->create("temp"));
rx.bandwidth = tempRx->par("datarate");
rx.errorRate = tempRx->par("ber");
rx.accessDelay = tempRx->par("delay");
rx.maxQueueTime = (sendQueueLength * 8.0) / rx.bandwidth;
rx.finished = 0;
tx.bandwidth = tempTx->par("datarate");
tx.errorRate = tempTx->par("ber");
tx.accessDelay = tempTx->par("delay");
tx.maxQueueTime = (sendQueueLength * 8.0) / tx.bandwidth;
tx.finished = 0;
delete tempRx;
delete tempTx;
}

Member Function Documentation

SimpleNodeEntry::SimpleDelay SimpleNodeEntry::calcAccessRouterDelay ( cPacket *  msg)

Calculates delay introduced by send queue at the access router of the destination node.

Parameters
msgpointer to message to get its length for delay calculation and set bit error flag
Returns
delay in s and boolean value that is false if message should be deleted

Definition at line 194 of file SimpleNodeEntry.cc.

Referenced by SimpleUDP::handleMessage().

{
simtime_t now = simTime();
simtime_t bandwidthDelay = ((msg->getByteLength() * 8) / rx.bandwidth);
simtime_t newRxFinished = std::max(rx.finished + rx.accessDelay +
bandwidthDelay, now);
// access router send queue
if ((newRxFinished > (now + rx.maxQueueTime)) && (rx.maxQueueTime != 0)) {
EV << "[SimpleNodeEntry::calcAccessRouterDelay()]\n"
<< " Access router send queue overrun"
<< "\n newRxFinished = fmax(rxFinished + accessDelay + bandwidthDelay, now)"
<< "\n newRxFinished = " << newRxFinished
<< "\n rx.finished = " << rx.finished
<< "\n now = " << now
<< "\n bandwidthDelay = " << bandwidthDelay
<< "\n (newRxFinished > now + rxMaxQueueTime) == true"
<< "\n rx.maxQueueTime = " << rx.maxQueueTime
<< endl;
return SimpleDelay(0, false);
}
rx.finished = newRxFinished;
std::cout << "RouterDelay: " << rx.finished - now << std::endl;
return SimpleDelay(rx.finished - now, true);
}
SimpleNodeEntry::SimpleDelay SimpleNodeEntry::calcDelay ( cPacket *  msg,
const SimpleNodeEntry dest,
bool  faultyDelay = false 
)

Calculates delay between two nodes.

Parameters
msgpointer to message to get its length for delay calculation and set bit error flag
destdestination terminal
faultyDelayviolate triangle inequality?
Returns
delay in s and boolean value that is false if message should be deleted

Definition at line 152 of file SimpleNodeEntry.cc.

Referenced by SimpleUDP::processMsgFromApp(), and SimpleTCPConnection::sendToIP().

{
if ((pow(1 - tx.errorRate, msg->getByteLength() * 8) <= uniform(0, 1)) ||
(pow(1 - dest.rx.errorRate, msg->getByteLength() * 8) <= uniform(0, 1))) {
msg->setBitError(true);
}
simtime_t now = simTime();
simtime_t bandwidthDelay = ((msg->getByteLength() * 8) / tx.bandwidth);
simtime_t newTxFinished = std::max(tx.finished, now) + bandwidthDelay;
// send queue
if ((newTxFinished > now + tx.maxQueueTime) && (tx.maxQueueTime != 0)) {
EV << "[SimpleNodeEntry::calcDelay()]\n"
<< " Send queue overrun"
<< "\n newTxFinished = fmax(txFinished, now) + bandwidthDelay"
<< "\n newTxFinished = " << newTxFinished
<< "\n tx.finished = " << tx.finished
<< "\n now = " << now
<< "\n bandwidthDelay = " << bandwidthDelay
<< "\n (newTxFinished > now + txMaxQueueTime) == true"
<< "\n tx.maxQueueTime = " << tx.maxQueueTime
<< endl;
return SimpleDelay(0, false);
}
tx.finished = newTxFinished;
simtime_t destBandwidthDelay = (msg->getByteLength() * 8) / dest.rx.bandwidth;
simtime_t coordDelay = 0.001 * (*this - dest);
if (faultyDelay)
coordDelay = getFaultyDelay(coordDelay);
return SimpleDelay(tx.finished - now
+ coordDelay
+ destBandwidthDelay + dest.rx.accessDelay, true);
}
simtime_t SimpleNodeEntry::getAccessDelay ( ) const
inline

Definition at line 175 of file SimpleNodeEntry.h.

{ return tx.accessDelay; };
float SimpleNodeEntry::getBandwidth ( ) const
inline

Definition at line 181 of file SimpleNodeEntry.h.

{ return tx.bandwidth; };
float SimpleNodeEntry::getCoords ( int  dim) const
inline
uint8_t SimpleNodeEntry::getDim ( ) const
inline
float SimpleNodeEntry::getErrorRate ( ) const
inline

Definition at line 186 of file SimpleNodeEntry.h.

{ return tx.errorRate; };
simtime_t SimpleNodeEntry::getFaultyDelay ( simtime_t  oldDelay)
static

Calculates SHA1 hash over errorfree delay (always the same uniform distributed value), uses this to generate a realistic error distribution and returns the real RTT augmented with this error.

Definition at line 224 of file SimpleNodeEntry.cc.

Referenced by calcDelay().

{
// 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
unsigned int 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 / (unsigned int) ((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;
}
/*
std::cout << "decimalhash: " << decimalhash << " -- fraction: " << fraction << " -- errorRatio: " << errorRatio << std::endl;
std::cout << SimpleUDP::delayFaultTypeString << " -- " << "old: " << oldDelay << " -- new: " << oldDelay + sign * errorRatio * oldDelay << std::endl;
*/
// If faulty rtt is smaller, set errorRatio to max 0.6
//errorRatio = (sign == -1 && errorRatio > 0.6) ? 0.6 : errorRatio;
errorRatio = (errorRatio > 0.6) ? 0.6 : errorRatio;
return (oldDelay + sign * errorRatio * oldDelay); // * 0.789; //TODO
}
NodeRecord* SimpleNodeEntry::getNodeRecord ( ) const
inline
int SimpleNodeEntry::getRecordIndex ( ) const
inline
simtime_t SimpleNodeEntry::getRxAccessDelay ( ) const
inline

Definition at line 178 of file SimpleNodeEntry.h.

Referenced by SimpleNcs::init().

{ return rx.accessDelay; };
float SimpleNodeEntry::getRxBandwidth ( ) const
inline

Definition at line 184 of file SimpleNodeEntry.h.

Referenced by SimpleNcs::init().

{ return rx.bandwidth; };
cGate* SimpleNodeEntry::getTcpIPv4Gate ( ) const
inline

Getter for SimpleUDP ingate.

Returns
the ingate

Definition at line 122 of file SimpleNodeEntry.h.

Referenced by SimpleTCPConnection::sendToIP().

{
return TcpIPv4ingate;
};
cGate* SimpleNodeEntry::getTcpIPv6Gate ( ) const
inline

Getter for SimpleUDP IPv6 ingate.

Returns
the ingate

Definition at line 132 of file SimpleNodeEntry.h.

Referenced by SimpleTCPConnection::sendToIP().

{
return TcpIPv6ingate;
};
simtime_t SimpleNodeEntry::getTxAccessDelay ( ) const
inline

Definition at line 177 of file SimpleNodeEntry.h.

Referenced by SimpleNcs::init().

{ return tx.accessDelay; };
float SimpleNodeEntry::getTxBandwidth ( ) const
inline

Definition at line 183 of file SimpleNodeEntry.h.

Referenced by SimpleNcs::init().

{ return tx.bandwidth; };
cGate* SimpleNodeEntry::getUdpIPv4Gate ( ) const
inline
cGate* SimpleNodeEntry::getUdpIPv6Gate ( ) const
inline

Getter for SimpleUDP IPv6 ingate.

Returns
the ingate

Definition at line 112 of file SimpleNodeEntry.h.

Referenced by SimpleUDP::processMsgFromApp().

{
return UdpIPv6ingate;
};
float SimpleNodeEntry::getX ( ) const
inline

Definition at line 190 of file SimpleNodeEntry.h.

Referenced by SimpleUnderlayConfigurator::createNode().

{ return nodeRecord->coords[0]; };
float SimpleNodeEntry::getY ( ) const
inline

Definition at line 191 of file SimpleNodeEntry.h.

Referenced by SimpleUnderlayConfigurator::createNode().

{ return nodeRecord->coords[1]; };
std::string SimpleNodeEntry::info ( ) const

OMNeT++ info method.

Returns
infostring

Definition at line 285 of file SimpleNodeEntry.cc.

{
std::ostringstream str;
str << *this;
return str.str();
}
float SimpleNodeEntry::operator- ( const SimpleNodeEntry entry) const
protected

Calculates euclidean distance between two terminals.

Parameters
entrydestination entry
Returns
the euclidean distance

Definition at line 142 of file SimpleNodeEntry.cc.

{
double sum_of_squares = 0;
for (uint32_t i = 0; i < nodeRecord->dim; i++) {
sum_of_squares += pow(nodeRecord->coords[i] -
entry.nodeRecord->coords[i], 2);
}
return sqrt(sum_of_squares);
}
void SimpleNodeEntry::setX ( float  x)
inline

Definition at line 188 of file SimpleNodeEntry.h.

Referenced by SimpleUnderlayConfigurator::migrateNode().

{ nodeRecord->coords[0] = x; };
void SimpleNodeEntry::setY ( float  y)
inline

Definition at line 189 of file SimpleNodeEntry.h.

Referenced by SimpleUnderlayConfigurator::migrateNode().

{ nodeRecord->coords[1] = y; };

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const SimpleNodeEntry entry 
)
friend

Stream output.

Parameters
outoutput stream
entrythe terminal
Returns
reference to stream out

Definition at line 292 of file SimpleNodeEntry.cc.

{
out << "(";
for (uint8_t i = 0; i < NodeRecord::dim; i++) {
out << "dim" << i <<": " << entry.nodeRecord->coords[i];
out << ", ";
}
// out << ", y:" << entry.nodeRecord->coords[1]
out << ")\n[rx]"
<< "\nbandwidth = " << entry.rx.bandwidth
<< ",\ndelay = " << entry.rx.accessDelay
<< ",\nerrorRate = " << entry.rx.errorRate
<< ",\ntxMaxQueueTime = " << entry.rx.maxQueueTime
<< ",\ntxFinished = " << entry.rx.finished;
out << "\n[tx]"
<< "\nbandwidth = " << entry.tx.bandwidth
<< ",\ndelay = " << entry.tx.accessDelay
<< ",\nerrorRate = " << entry.tx.errorRate
<< ",\ntxMaxQueueTime = " << entry.tx.maxQueueTime
<< ",\ntxFinished = " << entry.tx.finished;
return out;
}

Member Data Documentation

int SimpleNodeEntry::index
protected

Definition at line 230 of file SimpleNodeEntry.h.

Referenced by getRecordIndex(), SimpleNodeEntry(), and ~SimpleNodeEntry().

NodeRecord* SimpleNodeEntry::nodeRecord
protected
cGate* SimpleNodeEntry::TcpIPv4ingate
protected

IPv4 ingate of the SimpleTCP module of this terminal.

Definition at line 218 of file SimpleNodeEntry.h.

Referenced by getTcpIPv4Gate(), and SimpleNodeEntry().

cGate* SimpleNodeEntry::TcpIPv6ingate
protected

IPv6 ingate of the SimpleTCP module of this terminal.

Definition at line 219 of file SimpleNodeEntry.h.

Referenced by getTcpIPv6Gate(), and SimpleNodeEntry().

cGate* SimpleNodeEntry::UdpIPv4ingate
protected

IPv4 ingate of the SimpleUDP module of this terminal.

Definition at line 216 of file SimpleNodeEntry.h.

Referenced by getUdpIPv4Gate(), and SimpleNodeEntry().

cGate* SimpleNodeEntry::UdpIPv6ingate
protected

IPv6 ingate of the SimpleUDP module of this terminal.

Definition at line 217 of file SimpleNodeEntry.h.

Referenced by getUdpIPv6Gate(), and SimpleNodeEntry().


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