Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes

UnderlayConfigurator Class Reference

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

#include <UnderlayConfigurator.h>

Inheritance diagram for UnderlayConfigurator:
InetUnderlayConfigurator ReaSEUnderlayConfigurator 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 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(endSimulationNotificationTimer);
    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]
void UnderlayConfigurator::finish (  )  [protected]

Cleans up configurator.

Definition at line 205 of file UnderlayConfigurator.cc.

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

Cleans up concrete underlay configurator.

Reimplemented in InetUnderlayConfigurator, ReaSEUnderlayConfigurator, 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 ParetoChurn::createNode(), and LifetimeChurn::createNode().

{ return gracefulLeaveDelay; };

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

Node mobility simulation.

Parameters:
msg timer-message

Definition at line 185 of file UnderlayConfigurator.cc.

{
    if (msg == endSimulationNotificationTimer) {
        simulationEndingSoon = true;
        // globalNodeList->sendNotificationToAllPeers(NF_OVERLAY_NODE_LEAVE);
    } else if (msg == endSimulationTimer) {
        endSimulation();
    } else if (msg == endTransitionTimer) {
        consoleOut("transition time finished");
        globalStatistics->startMeasuring();
    } else {
        handleTimerEvent(msg);
    }
}

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

Definition at line 156 of file UnderlayConfigurator.cc.

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

{
    Enter_Method_Silent();

    if (++initCounter == churnGenerator.size() || !churnGenerator.size()) {
        init = false;
        gettimeofday(&initFinishedTime, NULL);

        scheduleAt(simTime() + transitionTime,
                endTransitionTimer);

        if (measurementTime >= 0) {
            scheduleAt(simTime() + transitionTime + measurementTime,
                       endSimulationTimer);

            if ((transitionTime + measurementTime) < gracefulLeaveDelay) {
                throw cRuntimeError("UnderlayConfigurator::initFinished():"
                                        " gracefulLeaveDelay must be bigger "
                                        "than transitionTime + measurementTime!");
            }

            scheduleAt(simTime() + transitionTime + measurementTime
                    - gracefulLeaveDelay,
                    endSimulationNotificationTimer);
        }
        consoleOut("INIT phase finished");
    }
}

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

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");

        globalNodeList = GlobalNodeListAccess().get();
        globalStatistics = GlobalStatisticsAccess().get();

        endSimulationNotificationTimer =
            new cMessage("endSimulationNotificationTimer");
        endSimulationTimer = new cMessage("endSimulationTimer");
        endTransitionTimer = new cMessage("endTransitionTimer");

        gettimeofday(&initStartTime, NULL);
        init = true;
        simulationEndingSoon = false;
        initCounter = 0;

        firstNodeId = -1;
        WATCH(firstNodeId);
        WATCH(overlayTerminalCount);
    }

    if (stage >= MIN_STAGE_UNDERLAY && stage <= MAX_STAGE_UNDERLAY) {
        initializeUnderlay(stage);
    }

    if (stage == MAX_STAGE_UNDERLAY) {
        // Create churn generators
        NodeType t;
        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  )  [protected, pure virtual]

Init method for derived underlay configurators.

Implemented in InetUnderlayConfigurator, ReaSEUnderlayConfigurator, SimpleUnderlayConfigurator, 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(), and DHTTestApp::handleTimerEvent().

{ return simulationEndingSoon; };

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:
type NodeType of the node to migrate
addr NULL for random node

Implemented in InetUnderlayConfigurator, ReaSEUnderlayConfigurator, 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.

{
    return MAX_STAGE_UNDERLAY + 1;
}

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, ReaSEUnderlayConfigurator, 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(), ReaSEUnderlayConfigurator::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().

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

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


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