OverSim
SimpleUDP Class Reference

Implements the UDP protocol: encapsulates/decapsulates user data into/from UDP. More...

#include <SimpleUDP.h>

Public Types

enum  delayFaultTypeNum { delayFaultUndefined, delayFaultLiveAll, delayFaultLivePlanetlab, delayFaultSimulation }

Public Member Functions

void setNodeEntry (SimpleNodeEntry *entry)
 set or change the nodeEntry of this module
 SimpleUDP ()
virtual ~SimpleUDP ()
 destructor

Static Public Attributes

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

Protected Member Functions

void updateDisplayString ()
 utility: show current statistics above the icon
virtual void processMsgFromApp (cPacket *appData)
 process packets from application
virtual void processUDPPacket (cPacket *udpPacket)
virtual void processUndeliverablePacket (cPacket *udpPacket, cPolymorphic *ctrl)
virtual void sendUp (cPacket *payload, UDPControlInfo *ctrl, SockDesc *sd)
virtual void initialize (int stage)
 initialise the SimpleUDP module
virtual void handleMessage (cMessage *msg)
virtual int numInitStages () const
 returns the number of init stages
void finish ()

Protected Attributes

int numQueueLost
 number of lost packets due to queue full
int numPartitionLost
 number of lost packets due to network partitions
int numDestUnavailableLost
 number of lost packets due to unavailable destination
simtime_t delay
 simulated delay between sending and receiving udp module
simtime_t constantDelay
 constant delay between two peers
bool useCoordinateBasedDelay
 delay should be calculated from euklidean distance between two peers
double jitter
 amount of jitter in % of total delay
bool enableAccessRouterTxQueue
bool faultyDelay
GlobalNodeListglobalNodeList
 violate the triangle inequality?
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics
SimpleNodeEntrynodeEntry
 nodeEntry of the overlay node this module belongs to

Detailed Description

Implements the UDP protocol: encapsulates/decapsulates user data into/from UDP.

More info in the NED file.

Definition at line 59 of file SimpleUDP.h.

Member Enumeration Documentation

Enumerator:
delayFaultUndefined 
delayFaultLiveAll 
delayFaultLivePlanetlab 
delayFaultSimulation 

Definition at line 65 of file SimpleUDP.h.

Constructor & Destructor Documentation

SimpleUDP::SimpleUDP ( )

Definition at line 93 of file SimpleUDP.cc.

{
}
SimpleUDP::~SimpleUDP ( )
virtual

destructor

Definition at line 98 of file SimpleUDP.cc.

{
}

Member Function Documentation

void SimpleUDP::finish ( )
protected

Definition at line 156 of file SimpleUDP.cc.

{
globalStatistics->addStdDev("SimpleUDP: Packets sent",
numSent);
globalStatistics->addStdDev("SimpleUDP: Packets dropped with bad checksum",
numDroppedBadChecksum);
globalStatistics->addStdDev("SimpleUDP: Packets dropped due to queue overflows",
globalStatistics->addStdDev("SimpleUDP: Packets dropped due to network partitions",
globalStatistics->addStdDev("SimpleUDP: Packets dropped due to unavailable destination",
}
void SimpleUDP::handleMessage ( cMessage *  msg)
protectedvirtual

Definition at line 405 of file SimpleUDP.cc.

{
// received from IP layer
if (msg->arrivedOn("ipIn") || msg->arrivedOn("ipv6In"))
{
SimpleNodeEntry::SimpleDelay temp = std::make_pair(0, true);
}
if (temp.second == false) {
delete msg;
return;
}
if (temp.first > 0) {
scheduleAt(simTime() + temp.first, msg);
} else if (dynamic_cast<ICMPMessage *>(msg) || dynamic_cast<ICMPv6Message *>(msg))
processICMPError(PK(msg));
else
processUDPPacket(PK(msg));
}
else if (msg->isSelfMessage())
{
if (dynamic_cast<ICMPMessage *>(msg) || dynamic_cast<ICMPv6Message *>(msg))
processICMPError(PK(msg));
else
processUDPPacket(PK(msg));
}
else // received from application layer
{
if (msg->getKind()==UDP_C_DATA)
else
processCommandFromApp(msg);
}
if (ev.isGUI())
}
void SimpleUDP::initialize ( int  stage)
protectedvirtual

initialise the SimpleUDP module

Parameters
stagestage of initialisation phase

Definition at line 103 of file SimpleUDP.cc.

{
if(stage == MIN_STAGE_UNDERLAY) {
WATCH_PTRMAP(socketsByIdMap);
WATCH_MAP(socketsByPortMap);
lastEphemeralPort = EPHEMERAL_PORTRANGE_START;
icmp = NULL;
icmpv6 = NULL;
numSent = 0;
numPassedUp = 0;
numDroppedWrongPort = 0;
numDroppedBadChecksum = 0;
WATCH(numSent);
WATCH(numPassedUp);
WATCH(numDroppedWrongPort);
WATCH(numDroppedBadChecksum);
WATCH(numQueueLost);
constantDelay = par("constantDelay");
useCoordinateBasedDelay = par("useCoordinateBasedDelay");
delayFaultTypeString = par("delayFaultType").stdstringValue();
faultyDelay = true;
break;
default:
faultyDelay = false;
break;
}
jitter = par("jitter");
enableAccessRouterTxQueue = par("enableAccessRouterTxQueue");
nodeEntry = NULL;
WATCH_PTR(nodeEntry);
}
}
virtual int SimpleUDP::numInitStages ( void  ) const
inlineprotectedvirtual

returns the number of init stages

Returns
the number of init stages

Definition at line 138 of file SimpleUDP.h.

{
return MAX_STAGE_UNDERLAY + 1;
}
void SimpleUDP::processMsgFromApp ( cPacket *  appData)
protectedvirtual

process packets from application

Parameters
appDatathe data that has to be sent

Definition at line 276 of file SimpleUDP.cc.

Referenced by handleMessage().

{
cModule *node = getParentModule();
IPvXAddress srcAddr, destAddr;
UDPControlInfo *udpCtrl = check_and_cast<UDPControlInfo *>(appData->getControlInfo());
srcAddr = udpCtrl->getSrcAddr();
destAddr = udpCtrl->getDestAddr();
// add header byte length for the skipped IP and UDP headers (decreased in processUDPPacket)
if (destAddr.isIPv6()) {
appData->setByteLength(appData->getByteLength() + UDP_HEADER_BYTES + IPv6_HEADER_BYTES);
} else {
appData->setByteLength(appData->getByteLength() + UDP_HEADER_BYTES + IP_HEADER_BYTES);
}
/* main modifications for SimpleUDP start here */
SimpleInfo* info = dynamic_cast<SimpleInfo*>(globalNodeList->getPeerInfo(destAddr));
numSent++;
if (info == NULL) {
EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n"
<< " No route to host " << destAddr
<< endl;
delete appData;
return;
}
SimpleNodeEntry* destEntry = info->getEntry();
// calculate delay
simtime_t totalDelay = 0;
if (srcAddr != destAddr) {
if (faultyDelay) {
SimpleInfo* thisInfo = static_cast<SimpleInfo*>(globalNodeList->getPeerInfo(srcAddr));
temp = nodeEntry->calcDelay(appData, *destEntry,
!(thisInfo->getNpsLayer() == 0 ||
info->getNpsLayer() == 0)); //TODO
} else {
temp = nodeEntry->calcDelay(appData, *destEntry);
}
if (useCoordinateBasedDelay == false) {
totalDelay = constantDelay;
} else if (temp.second == false) {
EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n"
<< " Send queue full: packet " << appData << " dropped"
<< endl;
delete appData;
return;
} else {
totalDelay = temp.first;
}
}
SimpleInfo* thisInfo = dynamic_cast<SimpleInfo*>(globalNodeList->getPeerInfo(srcAddr));
EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n"
<< " Partition " << thisInfo->getTypeID() << "->" << info->getTypeID()
<< " is not connected"
<< endl;
delete appData;
return;
}
if (jitter) {
// jitter
//totalDelay += truncnormal(0, SIMTIME_DBL(totalDelay) * jitter);
//workaround (bug in truncnormal(): sometimes returns inf)
double temp = truncnormal(0, SIMTIME_DBL(totalDelay) * jitter);
while (temp == INFINITY || temp != temp) { // reroll if temp is INF or NaN
std::cerr << "\n******* SimpleUDP: truncnormal() -> inf !!\n"
<< std::endl;
temp = truncnormal(0, SIMTIME_DBL(totalDelay) * jitter);
}
totalDelay += temp;
}
BaseOverlayMessage* temp = NULL;
if (ev.isGUI() && appData) {
if ((temp = dynamic_cast<BaseOverlayMessage*>(appData))) {
switch (temp->getStatType()) {
appData->setKind(1);
break;
appData->setKind(2);
break;
default:
appData->setKind(3);
break;
}
} else {
appData->setKind(1);
}
}
EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n"
<< " Packet " << appData << " sent with delay = " << SIMTIME_DBL(totalDelay)
<< endl;
//RECORD_STATS(globalStatistics->addStdDev("SimpleUDP: delay", totalDelay));
/* main modifications for SimpleUDP end here */
if (!destAddr.isIPv6()) {
// send directly to IPv4 gate of the destination node
sendDirect(appData, totalDelay, 0, destEntry->getUdpIPv4Gate());
} else {
sendDirect(appData, totalDelay, 0, destEntry->getUdpIPv6Gate());
}
}
void SimpleUDP::processUDPPacket ( cPacket *  udpPacket)
protectedvirtual

Definition at line 207 of file SimpleUDP.cc.

Referenced by handleMessage().

{
int srcPort, destPort;
IPvXAddress srcAddr, destAddr;
UDPControlInfo *ctrl = check_and_cast<UDPControlInfo *>(udpPacket->removeControlInfo());
srcPort = ctrl->getSrcPort();
destPort = ctrl->getDestPort();
srcAddr = ctrl->getSrcAddr();
destAddr = ctrl->getDestAddr();
// simulate checksum: discard packet if it has bit error
EV << "Packet " << udpPacket->getName() << " received from network, dest port " << destPort << "\n";
if (udpPacket->hasBitError())
{
EV << "Packet has bit error, discarding\n";
delete udpPacket;
numDroppedBadChecksum++;
return;
}
// send back ICMP error if no socket is bound to that port
SocketsByPortMap::iterator it = socketsByPortMap.find(destPort);
if (it==socketsByPortMap.end())
{
EV << "No socket registered on port " << destPort << "\n";
processUndeliverablePacket(udpPacket, ctrl);
return;
}
SockDescList& list = it->second;
int matches = 0;
// deliver a copy of the packet to each matching socket
if (destAddr.isIPv6())
{
// packet size is increased in processMsgFromApp
udpPacket->setByteLength(udpPacket->getByteLength() - UDP_HEADER_BYTES - IPv6_HEADER_BYTES);
}
else
{
udpPacket->setByteLength(udpPacket->getByteLength() - UDP_HEADER_BYTES - IP_HEADER_BYTES);
}
for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it)
{
SockDesc *sd = *it;
if (sd->onlyLocalPortIsSet || matchesSocket(sd, destAddr, srcAddr, srcPort))
{
if (matches == 0) {
sendUp(udpPacket, ctrl, sd);
} else {
opp_error("Edit SimpleUDP.cc to support multibinding.");
}
matches++;
}
}
// send back ICMP error if there is no matching socket
if (matches==0)
{
EV << "None of the sockets on port " << destPort << " matches the packet\n";
processUndeliverablePacket(udpPacket, ctrl);
return;
}
}
void SimpleUDP::processUndeliverablePacket ( cPacket *  udpPacket,
cPolymorphic *  ctrl 
)
protectedvirtual

Definition at line 196 of file SimpleUDP.cc.

Referenced by processUDPPacket().

{
numDroppedWrongPort++;
EV << "[SimpleUDP::processUndeliverablePacket()]\n"
<< " Dropped packet bound to unreserved port, ignoring ICMP error"
<< endl;
delete udpPacket;
delete ctrl;
}
void SimpleUDP::sendUp ( cPacket *  payload,
UDPControlInfo *  ctrl,
SockDesc *  sd 
)
protectedvirtual

Definition at line 185 of file SimpleUDP.cc.

Referenced by processUDPPacket().

{
// send payload with UDPControlInfo up to the application
udpCtrl->setSockId(sd->sockId);
udpCtrl->setUserId(sd->userId);
payload->setControlInfo(udpCtrl);
send(payload, "appOut", sd->appGateIndex);
numPassedUp++;
}
void SimpleUDP::setNodeEntry ( SimpleNodeEntry entry)

set or change the nodeEntry of this module

Parameters
entrythe new nodeEntry

Definition at line 449 of file SimpleUDP.cc.

Referenced by SimpleUnderlayConfigurator::createNode(), and SimpleUnderlayConfigurator::migrateNode().

{
nodeEntry = entry;
}
void SimpleUDP::updateDisplayString ( )
protected

utility: show current statistics above the icon

Definition at line 170 of file SimpleUDP.cc.

Referenced by handleMessage().

{
char buf[80];
sprintf(buf, "passed up: %d pks\nsent: %d pks", numPassedUp, numSent);
if (numDroppedWrongPort>0) {
sprintf(buf+strlen(buf), "\ndropped (no app): %d pks", numDroppedWrongPort);
getDisplayString().setTagArg("i",1,"red");
}
if (numQueueLost>0) {
sprintf(buf+strlen(buf), "\nlost (queue overflow): %d pks", numQueueLost);
getDisplayString().setTagArg("i",1,"red");
}
getDisplayString().setTagArg("t",0,buf);
}

Member Data Documentation

simtime_t SimpleUDP::constantDelay
protected

constant delay between two peers

Definition at line 81 of file SimpleUDP.h.

Referenced by initialize(), and processMsgFromApp().

simtime_t SimpleUDP::delay
protected

simulated delay between sending and receiving udp module

Definition at line 79 of file SimpleUDP.h.

std::map< std::string, SimpleUDP::delayFaultTypeNum > SimpleUDP::delayFaultTypeMap
static

Definition at line 71 of file SimpleUDP.h.

Referenced by SimpleNodeEntry::getFaultyDelay(), and initialize().

std::string SimpleUDP::delayFaultTypeString
static

Definition at line 64 of file SimpleUDP.h.

Referenced by SimpleNodeEntry::getFaultyDelay(), and initialize().

bool SimpleUDP::enableAccessRouterTxQueue
protected

Definition at line 84 of file SimpleUDP.h.

Referenced by handleMessage(), and initialize().

bool SimpleUDP::faultyDelay
protected

Definition at line 85 of file SimpleUDP.h.

Referenced by initialize(), and processMsgFromApp().

GlobalNodeList* SimpleUDP::globalNodeList
protected

violate the triangle inequality?

pointer to GlobalNodeList

Definition at line 86 of file SimpleUDP.h.

Referenced by initialize(), and processMsgFromApp().

GlobalStatistics* SimpleUDP::globalStatistics
protected

pointer to GlobalStatistics

Definition at line 87 of file SimpleUDP.h.

Referenced by finish(), initialize(), and SimpleUDP().

double SimpleUDP::jitter
protected

amount of jitter in % of total delay

Definition at line 83 of file SimpleUDP.h.

Referenced by initialize(), and processMsgFromApp().

SimpleNodeEntry* SimpleUDP::nodeEntry
protected

nodeEntry of the overlay node this module belongs to

Definition at line 88 of file SimpleUDP.h.

Referenced by handleMessage(), initialize(), processMsgFromApp(), and setNodeEntry().

int SimpleUDP::numDestUnavailableLost
protected

number of lost packets due to unavailable destination

Definition at line 78 of file SimpleUDP.h.

Referenced by finish(), initialize(), and processMsgFromApp().

int SimpleUDP::numPartitionLost
protected

number of lost packets due to network partitions

Definition at line 77 of file SimpleUDP.h.

Referenced by finish(), initialize(), and processMsgFromApp().

int SimpleUDP::numQueueLost
protected

number of lost packets due to queue full

Definition at line 76 of file SimpleUDP.h.

Referenced by finish(), initialize(), processMsgFromApp(), and updateDisplayString().

bool SimpleUDP::useCoordinateBasedDelay
protected

delay should be calculated from euklidean distance between two peers

Definition at line 82 of file SimpleUDP.h.

Referenced by initialize(), and processMsgFromApp().


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