UnderlayConfigurator Class Reference

#include <UnderlayConfigurator.h>

Inheritance diagram for UnderlayConfigurator:

IPv4UnderlayConfigurator SimpleNetConfigurator SingleHostConfigurator

List of all members.


Detailed Description

Base class for configurators of different underlay models.

Author:
Stephan Krause, Bernhard Heep

Public Member Functions

 UnderlayConfigurator ()
virtual ~UnderlayConfigurator ()
bool isInInitPhase ()
 still in initialization phase?
bool isSimulationEndingSoon ()
 Is the simulation ending soon?
bool 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)

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
double gracefulLeaveDelay
 delay until scheduled node is removed from overlay
double gracefulLeaveProbability
 probability that node is notified befor removal
BootstrapOraclebootstrapOracle
 pointer to BootstrapOracle
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
double transitionTime
 time to wait before measuring after init phase is finished
double measurementTime
 duration of the simulation after init and transition phase

Static Protected Attributes

static const uint 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 (  ) 

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

UnderlayConfigurator::~UnderlayConfigurator (  )  [virtual]

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


Member Function Documentation

bool UnderlayConfigurator::isInInitPhase (  )  [inline]

bool UnderlayConfigurator::isSimulationEndingSoon (  )  [inline]

Is the simulation ending soon?

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

00056 { return simulationEndingSoon; };

bool UnderlayConfigurator::getGracefulLeaveDelay (  )  [inline]

Return the gracefulLeaveDelay.

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

00061 { return gracefulLeaveDelay; };

bool UnderlayConfigurator::isTransitionTimeFinished (  )  [inline]

00064 { 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 IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

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 IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

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 IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

Referenced by RandomChurn::handleMessage().

void UnderlayConfigurator::initFinished (  ) 

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

00136 {
00137     Enter_Method_Silent();
00138 
00139     if (++initCounter == churnGenerator.size()) {
00140         init = false;
00141         gettimeofday(&initFinishedTime, NULL);
00142 
00143         scheduleAt(simulation.simTime() + transitionTime,
00144                 endTransitionTimer);
00145 
00146         if (measurementTime >= 0) {
00147             scheduleAt(simulation.simTime() + transitionTime + measurementTime,
00148                        endSimulationTimer);
00149 
00150             if ((transitionTime + measurementTime) < gracefulLeaveDelay) {
00151                 throw new cRuntimeError("UnderlayConfigurator::initFinished():"
00152                                         " gracefulLeaveDelay must be bigger "
00153                                         "than transitionTime + measurementTime!");
00154             }
00155 
00156             scheduleAt(simulation.simTime() + transitionTime + measurementTime
00157                     - gracefulLeaveDelay,
00158                     endSimulationNotificationTimer);
00159         }
00160         consoleOut("INIT phase finished");
00161     }
00162 }

ChurnGenerator * UnderlayConfigurator::getChurnGenerator ( int  typeID  ) 

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

00226 {
00227     Enter_Method_Silent();
00228 
00229     return churnGenerator[typeID];
00230 }

int UnderlayConfigurator::numInitStages (  )  const [protected]

OMNeT number of init stages.

00052 {
00053     return MAX_STAGE_UNDERLAY + 1;
00054 }

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

OMNeT init methods.

00057 {
00058     if (stage == MIN_STAGE_UNDERLAY) {
00059         gracefulLeaveDelay = par("gracefulLeaveDelay");
00060         gracefulLeaveProbability = par("gracefulLeaveProbability");
00061         channelTypes = cStringTokenizer(par("channelTypes"), " ").asVector();
00062 
00063         transitionTime = par("transitionTime");
00064         measurementTime = par("measurementTime");
00065 
00066         bootstrapOracle = BootstrapOracleAccess().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 = findModuleType(it->c_str());
00107 
00108             if (genType == NULL) {
00109                 throw new cRuntimeError((std::string("UnderlayConfigurator::"
00110                    "initialize(): invalid churn generator: ") + *it).c_str());
00111             }
00112 
00113             ChurnGenerator* gen = check_and_cast<ChurnGenerator*>
00114                                 (genType->create(it->c_str(),parentModule()));
00115 
00116             // Name the generator
00117             char buf[80];
00118             sprintf(buf, "churnGenerator[%i]", t.typeID);
00119             gen->setName(buf);
00120 
00121             // Add it to the list of generators and initialize it
00122             churnGenerator.push_back(gen);
00123             t.typeID++;
00124             t.terminalType = (terminalTypes.size() == 1) ?
00125                 terminalTypes[0] :
00126                 terminalTypes[it - churnGeneratorTypes.begin()];
00127 
00128             gen->setNodeType(t);
00129             gen->buildInside();
00130             gen->setDisplayString("i=block/cogwheel");
00131         }
00132     }
00133 }

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

Init method for derived underlay configurators.

Implemented in IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

Referenced by initialize().

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

Reimplemented in IPv4UnderlayConfigurator, and SimpleNetConfigurator.

Referenced by handleMessage().

00180 {
00181     delete msg;
00182 }

void UnderlayConfigurator::finish (  )  [protected]

Cleans up configurator.

00185 {
00186     finishUnderlay();
00187 }

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

Cleans up concrete underlay configurator.

Reimplemented in IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

Referenced by finish().

00190 {
00191     //...
00192 }

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

Sets display string.

Implemented in IPv4UnderlayConfigurator, SimpleNetConfigurator, and SingleHostConfigurator.

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

Node mobility simulation.

Parameters:
msg timer-message

Reimplemented in SingleHostConfigurator.

00165 {
00166     if (msg == endSimulationNotificationTimer) {
00167         simulationEndingSoon = true;
00168         //      bootstrapOracle->sendNotificationToAllPeers(NF_OVERLAY_NODE_LEAVE);
00169     } else if (msg == endSimulationTimer) {
00170         endSimulation();
00171     } else if (msg == endTransitionTimer) {
00172         consoleOut("transition time finished");
00173         globalStatistics->startMeasuring();
00174     } else {
00175         handleTimerEvent(msg);
00176     }
00177 }

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

Referenced by handleMessage(), and initFinished().

00195 {
00196     if (!ev.isGUI()) {
00197         struct timeval now, diff;
00198         gettimeofday(&now, NULL);
00199         timersub(&now, &initStartTime, &diff);
00200 
00201         std::stringstream ss;
00202         std::string line1(71, '*');
00203         std::string line2(71, '*');
00204 
00205         ss << "   " << text << "   ";
00206         line1.replace(35 - ss.str().size() / 2,
00207                       ss.str().size(),
00208                       ss.str());
00209         ss.str("");
00210 
00211         ss << "   (sim time: " << simTime()
00212            << ", real time: " << diff.tv_sec
00213            << "." << diff.tv_usec << ")   ";
00214         line2.replace(35 - ss.str().size() / 2,
00215                       ss.str().size(),
00216                       ss.str());
00217 
00218         std::cout << "\n" << line1 << "\n"
00219                   << line2 << "\n" << std::endl;
00220     } else {
00221         EV << "[UnderlayConfigurator::consoleOut()] " << text;
00222     }
00223 }


Member Data Documentation

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

the Id of the overlayTerminal created first in the overlay

Referenced by initialize().

probability that node is notified befor removal

Referenced by initialize(), SimpleNetConfigurator::preKillNode(), and IPv4UnderlayConfigurator::preKillNode().

pointer to GlobalStatistics

Referenced by handleMessage(), and initialize().

timer to signal end of simulation

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

timer to notify nodes that simulation ends soon

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

timer to signal end of transition time

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

Referenced by consoleOut(), and initialize().

time to wait before measuring after init phase is finished

Referenced by initFinished(), and initialize().

duration of the simulation after init and transition phase

Referenced by initFinished(), and initialize().

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

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

Initial value:

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

Referenced by SimpleNetConfigurator::createNode(), and IPv4UnderlayConfigurator::createNode().

unsigned int UnderlayConfigurator::initCounter [private]

Referenced by initFinished(), and initialize().


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

Generated on Fri Sep 19 13:05:08 2008 for ITM OverSim by  doxygen 1.5.5