UnderlayConfigurator Class Reference

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

#include <UnderlayConfigurator.h>

Inheritance diagram for UnderlayConfigurator:
InetUnderlayConfigurator SimpleUnderlayConfigurator SingleHostUnderlayConfigurator

List of all members.

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 ()

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 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

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.

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

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

Definition at line 213 of file UnderlayConfigurator.cc.

Referenced by handleMessage(), and initFinished().

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

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().

void UnderlayConfigurator::finish (  )  [protected]

Cleans up configurator.

Definition at line 203 of file UnderlayConfigurator.cc.

00204 {
00205     finishUnderlay();
00206 }

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

Cleans up concrete underlay configurator.

Reimplemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Definition at line 208 of file UnderlayConfigurator.cc.

Referenced by finish().

00209 {
00210     //...
00211 }

ChurnGenerator * UnderlayConfigurator::getChurnGenerator ( int  typeID  ) 

Definition at line 244 of file UnderlayConfigurator.cc.

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

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

uint8_t UnderlayConfigurator::getChurnGeneratorNum (  ) 

Definition at line 251 of file UnderlayConfigurator.cc.

00252 {
00253     Enter_Method_Silent();
00254 
00255     return churnGenerator.size();
00256 }

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; };

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

Node mobility simulation.

Parameters:
msg timer-message

Definition at line 183 of file UnderlayConfigurator.cc.

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

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

Reimplemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Definition at line 198 of file UnderlayConfigurator.cc.

Referenced by handleMessage().

00199 {
00200     delete msg;
00201 }

void UnderlayConfigurator::initFinished (  ) 

Definition at line 154 of file UnderlayConfigurator.cc.

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

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

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

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

Init method for derived underlay configurators.

Implemented in InetUnderlayConfigurator, SimpleUnderlayConfigurator, and SingleHostUnderlayConfigurator.

Referenced by initialize().

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; };

bool UnderlayConfigurator::isTransitionTimeFinished (  )  [inline]

Definition at line 76 of file UnderlayConfigurator.h.

00076 { return transitionTimeFinished; };

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().

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 }

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::setDisplayString (  )  [protected, pure virtual]

Member Data Documentation

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().

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 simulation

Definition at line 158 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().

the Id of the overlayTerminal created first in the overlay

Definition at line 150 of file UnderlayConfigurator.h.

Referenced by initialize().

pointer to GlobalStatistics

Definition at line 155 of file UnderlayConfigurator.h.

Referenced by handleMessage(), and 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().

Definition at line 172 of file UnderlayConfigurator.h.

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

unsigned int UnderlayConfigurator::initCounter [private]

Definition at line 175 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 163 of file UnderlayConfigurator.h.

Referenced by consoleOut(), 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]

Definition at line 173 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 165 of file UnderlayConfigurator.h.

Referenced by initFinished(), and initialize().

Definition at line 174 of file UnderlayConfigurator.h.

Referenced by isTransitionTimeFinished().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3