UnderlayConfigurator Class Reference

#include <UnderlayConfigurator.h>

Inheritance diagram for UnderlayConfigurator:

InetUnderlayConfigurator SimpleUnderlayConfigurator SingleHostUnderlayConfigurator

List of all members.


Detailed Description

Base class for configurators of different underlay models.

Author:
Stephan Krause, Bernhard Heep

Definition at line 53 of file UnderlayConfigurator.h.


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 TransportAddress * createNode (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 ()
ChurnGenerator * getChurnGenerator (int typeID)

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

std::vector< std::string > channelTypes
 possible access types
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
GlobalNodeList * globalNodeList
 pointer to GlobalNodeList
GlobalStatistics * globalStatistics
 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 unsigned 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

Constructor & Destructor Documentation

UnderlayConfigurator::UnderlayConfigurator (  ) 

Definition at line 36 of file UnderlayConfigurator.cc.

00037 {
00038     endSimulationTimer = NULL;
00039     endSimulationNotificationTimer = NULL;
00040     endTransitionTimer = NULL;
00041     initFinishedTime.tv_sec = 0;
00042     initFinishedTime.tv_usec = 0;
00043 }

UnderlayConfigurator::~UnderlayConfigurator (  )  [virtual]

Definition at line 45 of file UnderlayConfigurator.cc.

00046 {
00047     cancelAndDelete(endSimulationNotificationTimer);
00048     cancelAndDelete(endSimulationTimer);
00049     cancelAndDelete(endTransitionTimer);
00050 }


Member Function Documentation

bool UnderlayConfigurator::isInInitPhase (  )  [inline]

bool UnderlayConfigurator::isSimulationEndingSoon (  )  [inline]

Is the simulation ending soon?

Definition at line 68 of file UnderlayConfigurator.h.

Referenced by KBRTestApp::handleTimerEvent(), and DHTTestApp::handleTimerEvent().

00068 { return simulationEndingSoon; };

simtime_t UnderlayConfigurator::getGracefulLeaveDelay (  )  [inline]

Return the gracefulLeaveDelay.

Definition at line 73 of file UnderlayConfigurator.h.

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

00073 { return gracefulLeaveDelay; };

bool UnderlayConfigurator::isTransitionTimeFinished (  )  [inline]

Definition at line 76 of file UnderlayConfigurator.h.

00076 { return transitionTimeFinished; };

virtual TransportAddress* UnderlayConfigurator::createNode ( NodeType  type,
bool  initialize = false 
) [pure virtual]

Creates an overlay node.

Parameters:
type NodeType of the node to create
initialize are we in init phase?

Implemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

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

virtual void UnderlayConfigurator::preKillNode ( NodeType  type,
TransportAddress *  addr = NULL 
) [pure virtual]

Notifies and schedules overlay nodes for removal.

Parameters:
type NodeType of the node to remove
addr NULL for random node

Implemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

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

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

Migrates overlay nodes from one access net to another.

Parameters:
type NodeType of the node to migrate
addr NULL for random node

Implemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by RandomChurn::handleMessage().

void UnderlayConfigurator::initFinished (  ) 

Definition at line 155 of file UnderlayConfigurator.cc.

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

00156 {
00157     Enter_Method_Silent();
00158 
00159     if (++initCounter == churnGenerator.size()) {
00160         init = false;
00161         gettimeofday(&initFinishedTime, NULL);
00162 
00163         scheduleAt(simTime() + transitionTime,
00164                 endTransitionTimer);
00165 
00166         if (measurementTime >= 0) {
00167             scheduleAt(simTime() + transitionTime + measurementTime,
00168                        endSimulationTimer);
00169 
00170             if ((transitionTime + measurementTime) < gracefulLeaveDelay) {
00171                 throw cRuntimeError("UnderlayConfigurator::initFinished():"
00172                                         " gracefulLeaveDelay must be bigger "
00173                                         "than transitionTime + measurementTime!");
00174             }
00175 
00176             scheduleAt(simTime() + transitionTime + measurementTime
00177                     - gracefulLeaveDelay,
00178                     endSimulationNotificationTimer);
00179         }
00180         consoleOut("INIT phase finished");
00181     }
00182 }

ChurnGenerator * UnderlayConfigurator::getChurnGenerator ( int  typeID  ) 

Definition at line 245 of file UnderlayConfigurator.cc.

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

00246 {
00247     Enter_Method_Silent();
00248 
00249     return churnGenerator[typeID];
00250 }

int UnderlayConfigurator::numInitStages (  )  const [protected]

OMNeT number of init stages.

Definition at line 52 of file UnderlayConfigurator.cc.

00053 {
00054     return MAX_STAGE_UNDERLAY + 1;
00055 }

void UnderlayConfigurator::initialize ( int  stage  )  [protected, virtual]

OMNeT init methods.

Definition at line 57 of file UnderlayConfigurator.cc.

00058 {
00059     if (stage == MIN_STAGE_UNDERLAY) {
00060         gracefulLeaveDelay = par("gracefulLeaveDelay");
00061         gracefulLeaveProbability = par("gracefulLeaveProbability");
00062         channelTypes = cStringTokenizer(par("channelTypes"), " ").asVector();
00063 
00064         transitionTime = par("transitionTime");
00065         measurementTime = par("measurementTime");
00066 
00067         globalNodeList = GlobalNodeListAccess().get();
00068         globalStatistics =GlobalStatisticsAccess().get();
00069 
00070         endSimulationNotificationTimer =
00071             new cMessage("endSimulationNotificationTimer");
00072         endSimulationTimer = new cMessage("endSimulationTimer");
00073         endTransitionTimer = new cMessage("endTransitionTimer");
00074 
00075         gettimeofday(&initStartTime, NULL);
00076         init = true;
00077         simulationEndingSoon = false;
00078         initCounter = 0;
00079 
00080         firstNodeId = -1;
00081         WATCH(firstNodeId);
00082         WATCH(overlayTerminalCount);
00083     }
00084 
00085     if (stage >= MIN_STAGE_UNDERLAY && stage <= MAX_STAGE_UNDERLAY) {
00086         initializeUnderlay(stage);
00087     }
00088 
00089     if (stage == MAX_STAGE_UNDERLAY) {
00090         // Create churn generators
00091         NodeType t;
00092         std::vector<std::string> churnGeneratorTypes =
00093             cStringTokenizer(par("churnGeneratorTypes"), " ").asVector();
00094         std::vector<std::string> terminalTypes =
00095             cStringTokenizer(par("terminalTypes"), " ").asVector();
00096 
00097         if (terminalTypes.size() != 1
00098                 && churnGeneratorTypes.size() != terminalTypes.size())
00099         {
00100             opp_error("UnderlayConfigurator.initialize(): "
00101                       "terminalTypes size does not match churnGenerator size");
00102         }
00103 
00104         for (std::vector<std::string>::iterator it =
00105                 churnGeneratorTypes.begin(); it != churnGeneratorTypes.end(); ++it) {
00106 
00107             cModuleType* genType = cModuleType::get(it->c_str());
00108 
00109             if (genType == NULL) {
00110                 throw cRuntimeError((std::string("UnderlayConfigurator::"
00111                    "initialize(): invalid churn generator: ") + *it).c_str());
00112             }
00113 
00114             ChurnGenerator* gen = check_and_cast<ChurnGenerator*>
00115                                 (genType->create("churnGenerator",
00116                                                  getParentModule(),
00117                                                  t.typeID + 1, t.typeID));
00118 
00119             // check threshold for noChurnThreshold hack
00120             gen->finalizeParameters();
00121 
00122             if ((*it == "oversim.common.LifetimeChurn" ||
00123                  *it == "oversim.common.ParetoChurn") &&
00124                 ((double)gen->par("noChurnThreshold") > 0) &&
00125                 ((double)gen->par("lifetimeMean") >=
00126                  (double)gen->par("noChurnThreshold"))) {
00127                 gen->callFinish();
00128                 gen->deleteModule();
00129                 cModuleType* genType =
00130                     cModuleType::get("oversim.common.NoChurn");
00131                 gen = check_and_cast<ChurnGenerator*>
00132                         (genType->create("churnGenerator", getParentModule(),
00133                                          t.typeID + 1, t.typeID));
00134                 gen->finalizeParameters();
00135                 EV << "[UnderlayConfigurator::initialize()]\n"
00136                    << "    churnGenerator[" << t.typeID
00137                    << "]: \"oversim.common.NoChurn\" is used instead of \""
00138                    << *it << "\"!\n    (lifetimeMean exceeds noChurnThreshold)"
00139                    << endl;
00140             }
00141 
00142             // Add it to the list of generators and initialize it
00143             churnGenerator.push_back(gen);
00144             t.typeID++;
00145             t.terminalType = (terminalTypes.size() == 1) ?
00146                 terminalTypes[0] :
00147                 terminalTypes[it - churnGeneratorTypes.begin()];
00148 
00149             gen->setNodeType(t);
00150             gen->buildInside();
00151         }
00152     }
00153 }

virtual void UnderlayConfigurator::initializeUnderlay ( int  stage  )  [protected, pure virtual]

Init method for derived underlay configurators.

Implemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by initialize().

void UnderlayConfigurator::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

Reimplemented in InetUnderlayConfigurator, and SimpleUnderlayConfigurator.

Definition at line 199 of file UnderlayConfigurator.cc.

Referenced by handleMessage().

00200 {
00201     delete msg;
00202 }

void UnderlayConfigurator::finish (  )  [protected]

Cleans up configurator.

Definition at line 204 of file UnderlayConfigurator.cc.

00205 {
00206     finishUnderlay();
00207 }

void UnderlayConfigurator::finishUnderlay (  )  [protected, virtual]

Cleans up concrete underlay configurator.

Reimplemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Definition at line 209 of file UnderlayConfigurator.cc.

Referenced by finish().

00210 {
00211     //...
00212 }

virtual void UnderlayConfigurator::setDisplayString (  )  [protected, pure virtual]

void UnderlayConfigurator::handleMessage ( cMessage *  msg  )  [protected]

Node mobility simulation.

Parameters:
msg timer-message

Reimplemented in SingleHostUnderlayConfigurator.

Definition at line 184 of file UnderlayConfigurator.cc.

00185 {
00186     if (msg == endSimulationNotificationTimer) {
00187         simulationEndingSoon = true;
00188         //      globalNodeList->sendNotificationToAllPeers(NF_OVERLAY_NODE_LEAVE);
00189     } else if (msg == endSimulationTimer) {
00190         endSimulation();
00191     } else if (msg == endTransitionTimer) {
00192         consoleOut("transition time finished");
00193         globalStatistics->startMeasuring();
00194     } else {
00195         handleTimerEvent(msg);
00196     }
00197 }

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

Definition at line 214 of file UnderlayConfigurator.cc.

Referenced by handleMessage(), and initFinished().

00215 {
00216     if (!ev.isGUI()) {
00217         struct timeval now, diff;
00218         gettimeofday(&now, NULL);
00219         diff = timeval_substract(now, initStartTime);
00220 
00221         std::stringstream ss;
00222         std::string line1(71, '*');
00223         std::string line2(71, '*');
00224 
00225         ss << "   " << text << "   ";
00226         line1.replace(35 - ss.str().size() / 2,
00227                       ss.str().size(),
00228                       ss.str());
00229         ss.str("");
00230 
00231         ss << "   (sim time: " << simTime()
00232            << ", real time: " << diff.tv_sec
00233            << "." << diff.tv_usec << ")   ";
00234         line2.replace(35 - ss.str().size() / 2,
00235                       ss.str().size(),
00236                       ss.str());
00237 
00238         std::cout << "\n" << line1 << "\n"
00239                   << line2 << "\n" << std::endl;
00240     } else {
00241         EV << "[UnderlayConfigurator::consoleOut()] " << text;
00242     }
00243 }


Member Data Documentation

std::vector<std::string> UnderlayConfigurator::channelTypes [protected]

the Id of the overlayTerminal created first in the overlay

Definition at line 150 of file UnderlayConfigurator.h.

Referenced by initialize().

delay until scheduled node is removed from overlay

Definition at line 151 of file UnderlayConfigurator.h.

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

probability that node is notified befor removal

Definition at line 152 of file UnderlayConfigurator.h.

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

pointer to GlobalStatistics

Definition at line 155 of file UnderlayConfigurator.h.

Referenced by handleMessage(), and initialize().

timer to signal end of simulation

Definition at line 158 of file UnderlayConfigurator.h.

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

timer to notify nodes that simulation ends soon

Definition at line 159 of file UnderlayConfigurator.h.

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

timer to signal end of transition time

Definition at line 160 of file UnderlayConfigurator.h.

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

struct timeval UnderlayConfigurator::initFinishedTime [read, protected]

struct timeval UnderlayConfigurator::initStartTime [read, protected]

timestamp at begin of init phase

Definition at line 163 of file UnderlayConfigurator.h.

Referenced by consoleOut(), and initialize().

simtime_t UnderlayConfigurator::transitionTime [protected]

time to wait before measuring after init phase is finished

Definition at line 165 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

duration of the simulation after init and transition phase

Definition at line 166 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

const uint32_t UnderlayConfigurator::NUM_COLORS = 8 [static, protected]

const char * UnderlayConfigurator::colorNames [static, protected]

Initial value:

 {
     "red", "green", "yellow", "brown", "grey", "violet", "pink", "orange"}

Definition at line 169 of file UnderlayConfigurator.h.

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

Definition at line 172 of file UnderlayConfigurator.h.

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

Definition at line 173 of file UnderlayConfigurator.h.

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

Definition at line 174 of file UnderlayConfigurator.h.

Referenced by isTransitionTimeFinished().

unsigned int UnderlayConfigurator::initCounter [private]

Definition at line 175 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().


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

Generated on Wed Mar 25 16:32:54 2009 for OverSim by  doxygen 1.5.5