OverSim
UnderlayConfigurator Class Reference

Base class for configurators of different underlay models. More...

#include <UnderlayConfigurator.h>

Inheritance diagram for UnderlayConfigurator:
InetUnderlayConfigurator ReaSEUnderlayConfigurator SimpleUnderlayConfigurator SingleHostUnderlayConfigurator

Public Member Functions

 UnderlayConfigurator ()
virtual ~UnderlayConfigurator ()
bool isInInitPhase ()
 still in initialization phase?
bool isSimulationEndingSoon ()
 Is the simulation ending soon?
simtime_t getGracefulLeaveDelay ()
 Return the gracefulLeaveDelay.
bool isTransitionTimeFinished ()
virtual TransportAddresscreateNode (NodeType type, bool initialize=false)=0
 Creates an overlay node.
virtual void preKillNode (NodeType type, TransportAddress *addr=NULL)=0
 Notifies and schedules overlay nodes for removal.
virtual void migrateNode (NodeType type, TransportAddress *addr=NULL)=0
 Migrates overlay nodes from one access net to another.
void initFinished ()
ChurnGeneratorgetChurnGenerator (int typeID)
uint8_t getChurnGeneratorNum ()
int getOverlayTerminalCount ()

Protected Member Functions

int numInitStages () const
 OMNeT number of init stages.
virtual void initialize (int stage)
 OMNeT init methods.
virtual void initializeUnderlay (int stage)=0
 Init method for derived underlay configurators.
virtual void handleTimerEvent (cMessage *msg)
void finish ()
 Cleans up configurator.
virtual void finishUnderlay ()
 Cleans up concrete underlay configurator.
virtual void setDisplayString ()=0
 Sets display string.
void handleMessage (cMessage *msg)
 Node mobility simulation.

Protected Attributes

int overlayTerminalCount
 current number of overlay terminals
int firstNodeId
 the Id of the overlayTerminal created first in the overlay
simtime_t gracefulLeaveDelay
 delay until scheduled node is removed from overlay
double gracefulLeaveProbability
 probability that node is notified befor removal
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics
std::vector< ChurnGenerator * > churnGenerator
 pointer to the ChurnGenerators
cMessage * endSimulationTimer
 timer to signal end of simulation
cMessage * endSimulationNotificationTimer
 timer to notify nodes that simulation ends soon
cMessage * endTransitionTimer
 timer to signal end of transition time
struct timeval initFinishedTime
 timestamp at end of init phase
struct timeval initStartTime
 timestamp at begin of init phase
simtime_t transitionTime
 time to wait before measuring after init phase is finished
simtime_t measurementTime
 duration of the simulation after init and transition phase

Static Protected Attributes

static const int NUM_COLORS = 8
static const char * colorNames []

Private Member Functions

void consoleOut (const std::string &text)

Private Attributes

bool init
bool simulationEndingSoon
bool transitionTimeFinished
unsigned int initCounter

Detailed Description

Base class for configurators of different underlay models.

Author
Stephan Krause, Bernhard Heep

Definition at line 53 of file UnderlayConfigurator.h.

Constructor & Destructor Documentation

UnderlayConfigurator::UnderlayConfigurator ( )

Definition at line 36 of file UnderlayConfigurator.cc.

UnderlayConfigurator::~UnderlayConfigurator ( )
virtual

Definition at line 45 of file UnderlayConfigurator.cc.

{
cancelAndDelete(endSimulationTimer);
cancelAndDelete(endTransitionTimer);
}

Member Function Documentation

void UnderlayConfigurator::consoleOut ( const std::string &  text)
private

Definition at line 215 of file UnderlayConfigurator.cc.

Referenced by handleMessage(), and initFinished().

{
if (!ev.isGUI()) {
struct timeval now, diff;
gettimeofday(&now, NULL);
diff = timeval_substract(now, initStartTime);
std::stringstream ss;
std::string line1(71, '*');
std::string line2(71, '*');
ss << " " << text << " ";
line1.replace(35 - ss.str().size() / 2,
ss.str().size(),
ss.str());
ss.str("");
ss << " (sim time: " << simTime()
<< ", real time: " << diff.tv_sec
<< "." << diff.tv_usec << ") ";
line2.replace(35 - ss.str().size() / 2,
ss.str().size(),
ss.str());
std::cout << "\n" << line1 << "\n"
<< line2 << "\n" << std::endl;
} else {
EV << "[UnderlayConfigurator::consoleOut()] " << text;
}
}
virtual TransportAddress* UnderlayConfigurator::createNode ( NodeType  type,
bool  initialize = false 
)
pure virtual

Creates an overlay node.

Parameters
typeNodeType of the node to create
initializeare we in init phase?

Implemented in ReaSEUnderlayConfigurator, SimpleUnderlayConfigurator, InetUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by LifetimeChurn::createNode(), ParetoChurn::createNode(), RandomChurn::handleMessage(), and NoChurn::handleMessage().

void UnderlayConfigurator::finish ( )
protected

Cleans up configurator.

Definition at line 205 of file UnderlayConfigurator.cc.

void UnderlayConfigurator::finishUnderlay ( )
protectedvirtual

Cleans up concrete underlay configurator.

Reimplemented in ReaSEUnderlayConfigurator, InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Definition at line 210 of file UnderlayConfigurator.cc.

Referenced by finish().

{
//...
}
ChurnGenerator * UnderlayConfigurator::getChurnGenerator ( int  typeID)

Definition at line 246 of file UnderlayConfigurator.cc.

Referenced by GlobalTraceManager::createNode(), GlobalTraceManager::deleteNode(), and GlobalTraceManager::getAppGateById().

{
Enter_Method_Silent();
return churnGenerator[typeID];
}
uint8_t UnderlayConfigurator::getChurnGeneratorNum ( )

Definition at line 253 of file UnderlayConfigurator.cc.

{
Enter_Method_Silent();
return churnGenerator.size();
}
simtime_t UnderlayConfigurator::getGracefulLeaveDelay ( )
inline

Return the gracefulLeaveDelay.

Definition at line 73 of file UnderlayConfigurator.h.

Referenced by LifetimeChurn::createNode(), and ParetoChurn::createNode().

{ return gracefulLeaveDelay; };
int UnderlayConfigurator::getOverlayTerminalCount ( )
inline

Definition at line 108 of file UnderlayConfigurator.h.

Referenced by GlobalViewBuilder::spreadGlobalView().

void UnderlayConfigurator::handleMessage ( cMessage *  msg)
protected

Node mobility simulation.

Parameters
msgtimer-message

Definition at line 185 of file UnderlayConfigurator.cc.

{
// globalNodeList->sendNotificationToAllPeers(NF_OVERLAY_NODE_LEAVE);
} else if (msg == endSimulationTimer) {
endSimulation();
} else if (msg == endTransitionTimer) {
consoleOut("transition time finished");
} else {
}
}
void UnderlayConfigurator::handleTimerEvent ( cMessage *  msg)
protectedvirtual
void UnderlayConfigurator::initFinished ( )

Definition at line 156 of file UnderlayConfigurator.cc.

Referenced by RandomChurn::handleMessage(), LifetimeChurn::handleMessage(), NoChurn::handleMessage(), ParetoChurn::handleMessage(), and SingleHostUnderlayConfigurator::handleTimerEvent().

{
Enter_Method_Silent();
if (++initCounter == churnGenerator.size() || !churnGenerator.size()) {
init = false;
gettimeofday(&initFinishedTime, NULL);
scheduleAt(simTime() + transitionTime,
if (measurementTime >= 0) {
scheduleAt(simTime() + transitionTime + measurementTime,
throw cRuntimeError("UnderlayConfigurator::initFinished():"
" gracefulLeaveDelay must be bigger "
"than transitionTime + measurementTime!");
}
scheduleAt(simTime() + transitionTime + measurementTime
}
consoleOut("INIT phase finished");
}
}
void UnderlayConfigurator::initialize ( int  stage)
protectedvirtual

OMNeT init methods.

Definition at line 57 of file UnderlayConfigurator.cc.

{
if (stage == MIN_STAGE_UNDERLAY) {
gracefulLeaveDelay = par("gracefulLeaveDelay");
gracefulLeaveProbability = par("gracefulLeaveProbability");
transitionTime = par("transitionTime");
measurementTime = par("measurementTime");
new cMessage("endSimulationNotificationTimer");
endSimulationTimer = new cMessage("endSimulationTimer");
endTransitionTimer = new cMessage("endTransitionTimer");
gettimeofday(&initStartTime, NULL);
init = true;
WATCH(firstNodeId);
}
if (stage >= MIN_STAGE_UNDERLAY && stage <= MAX_STAGE_UNDERLAY) {
}
if (stage == MAX_STAGE_UNDERLAY) {
// Create churn generators
t.typeID = 0;
std::vector<std::string> churnGeneratorTypes =
cStringTokenizer(par("churnGeneratorTypes"), " ").asVector();
std::vector<std::string> terminalTypes =
cStringTokenizer(par("terminalTypes"), " ").asVector();
if (terminalTypes.size() != 1
&& churnGeneratorTypes.size() != terminalTypes.size())
{
opp_error("UnderlayConfigurator.initialize(): "
"terminalTypes size does not match churnGenerator size");
}
for (std::vector<std::string>::iterator it =
churnGeneratorTypes.begin(); it != churnGeneratorTypes.end(); ++it) {
cModuleType* genType = cModuleType::get(it->c_str());
if (genType == NULL) {
throw cRuntimeError((std::string("UnderlayConfigurator::"
"initialize(): invalid churn generator: ") + *it).c_str());
}
ChurnGenerator* gen = check_and_cast<ChurnGenerator*>
(genType->create("churnGenerator",
getParentModule(),
t.typeID + 1, t.typeID));
// check threshold for noChurnThreshold hack
gen->finalizeParameters();
if ((*it == "oversim.common.LifetimeChurn" ||
*it == "oversim.common.ParetoChurn") &&
((double)gen->par("noChurnThreshold") > 0) &&
((double)gen->par("lifetimeMean") >=
(double)gen->par("noChurnThreshold"))) {
gen->callFinish();
gen->deleteModule();
cModuleType* genType =
cModuleType::get("oversim.common.NoChurn");
gen = check_and_cast<ChurnGenerator*>
(genType->create("churnGenerator", getParentModule(),
t.typeID + 1, t.typeID));
gen->finalizeParameters();
EV << "[UnderlayConfigurator::initialize()]\n"
<< " churnGenerator[" << t.typeID
<< "]: \"oversim.common.NoChurn\" is used instead of \""
<< *it << "\"!\n (lifetimeMean exceeds noChurnThreshold)"
<< endl;
}
// Add it to the list of generators and initialize it
churnGenerator.push_back(gen);
t.terminalType = (terminalTypes.size() == 1) ?
terminalTypes[0] :
terminalTypes[it - churnGeneratorTypes.begin()];
gen->setNodeType(t);
gen->buildInside();
t.typeID++;
}
}
}
virtual void UnderlayConfigurator::initializeUnderlay ( int  stage)
protectedpure virtual

Init method for derived underlay configurators.

Implemented in ReaSEUnderlayConfigurator, SimpleUnderlayConfigurator, InetUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by initialize().

bool UnderlayConfigurator::isSimulationEndingSoon ( )
inline

Is the simulation ending soon?

Definition at line 68 of file UnderlayConfigurator.h.

Referenced by KBRTestApp::handleTimerEvent().

bool UnderlayConfigurator::isTransitionTimeFinished ( )
inline

Definition at line 76 of file UnderlayConfigurator.h.

virtual void UnderlayConfigurator::migrateNode ( NodeType  type,
TransportAddress addr = NULL 
)
pure virtual

Migrates overlay nodes from one access net to another.

Parameters
typeNodeType of the node to migrate
addrNULL for random node

Implemented in ReaSEUnderlayConfigurator, SimpleUnderlayConfigurator, InetUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by RandomChurn::handleMessage().

int UnderlayConfigurator::numInitStages ( ) const
protected

OMNeT number of init stages.

Definition at line 52 of file UnderlayConfigurator.cc.

{
return MAX_STAGE_UNDERLAY + 1;
}
virtual void UnderlayConfigurator::preKillNode ( NodeType  type,
TransportAddress addr = NULL 
)
pure virtual

Notifies and schedules overlay nodes for removal.

Parameters
typeNodeType of the node to remove
addrNULL for random node

Implemented in ReaSEUnderlayConfigurator, SimpleUnderlayConfigurator, InetUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by LifetimeChurn::deleteNode(), ParetoChurn::deleteNode(), and RandomChurn::handleMessage().

virtual void UnderlayConfigurator::setDisplayString ( )
protectedpure virtual

Member Data Documentation

const char * UnderlayConfigurator::colorNames
staticprotected
Initial value:
{
"red", "green", "yellow", "brown", "grey", "violet", "pink", "orange"}

Definition at line 171 of file UnderlayConfigurator.h.

Referenced by InetUnderlayConfigurator::createNode(), and ReaSEUnderlayConfigurator::createNode().

cMessage* UnderlayConfigurator::endSimulationNotificationTimer
protected

timer to notify nodes that simulation ends soon

Definition at line 161 of file UnderlayConfigurator.h.

Referenced by handleMessage(), initFinished(), initialize(), UnderlayConfigurator(), and ~UnderlayConfigurator().

cMessage* UnderlayConfigurator::endSimulationTimer
protected

timer to signal end of simulation

Definition at line 160 of file UnderlayConfigurator.h.

Referenced by handleMessage(), initFinished(), initialize(), UnderlayConfigurator(), and ~UnderlayConfigurator().

cMessage* UnderlayConfigurator::endTransitionTimer
protected

timer to signal end of transition time

Definition at line 162 of file UnderlayConfigurator.h.

Referenced by handleMessage(), initFinished(), initialize(), UnderlayConfigurator(), and ~UnderlayConfigurator().

int UnderlayConfigurator::firstNodeId
protected

the Id of the overlayTerminal created first in the overlay

Definition at line 152 of file UnderlayConfigurator.h.

Referenced by initialize().

GlobalStatistics* UnderlayConfigurator::globalStatistics
protected

pointer to GlobalStatistics

Definition at line 157 of file UnderlayConfigurator.h.

Referenced by handleMessage(), and initialize().

simtime_t UnderlayConfigurator::gracefulLeaveDelay
protected

delay until scheduled node is removed from overlay

Definition at line 153 of file UnderlayConfigurator.h.

Referenced by getGracefulLeaveDelay(), initFinished(), initialize(), InetUnderlayConfigurator::preKillNode(), and ReaSEUnderlayConfigurator::preKillNode().

double UnderlayConfigurator::gracefulLeaveProbability
protected

probability that node is notified befor removal

Definition at line 154 of file UnderlayConfigurator.h.

Referenced by initialize(), InetUnderlayConfigurator::preKillNode(), and ReaSEUnderlayConfigurator::preKillNode().

bool UnderlayConfigurator::init
private

Definition at line 174 of file UnderlayConfigurator.h.

Referenced by initFinished(), initialize(), and isInInitPhase().

unsigned int UnderlayConfigurator::initCounter
private

Definition at line 177 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

struct timeval UnderlayConfigurator::initFinishedTime
protected
struct timeval UnderlayConfigurator::initStartTime
protected

timestamp at begin of init phase

Definition at line 165 of file UnderlayConfigurator.h.

Referenced by consoleOut(), and initialize().

simtime_t UnderlayConfigurator::measurementTime
protected

duration of the simulation after init and transition phase

Definition at line 168 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

const int32_t UnderlayConfigurator::NUM_COLORS = 8
staticprotected
bool UnderlayConfigurator::simulationEndingSoon
private

Definition at line 175 of file UnderlayConfigurator.h.

Referenced by handleMessage(), initialize(), and isSimulationEndingSoon().

simtime_t UnderlayConfigurator::transitionTime
protected

time to wait before measuring after init phase is finished

Definition at line 167 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

bool UnderlayConfigurator::transitionTimeFinished
private

Definition at line 176 of file UnderlayConfigurator.h.

Referenced by isTransitionTimeFinished().


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