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

ReaSEUnderlayConfigurator Class Reference

Configurator module for the ReaSEUnderlay. More...

#include <ReaSEUnderlayConfigurator.h>

Inheritance diagram for ReaSEUnderlayConfigurator:
UnderlayConfigurator

List of all members.

Public Member Functions

TransportAddresscreateNode (NodeType type, bool initialize=false)
 Creates an overlay node.
void preKillNode (NodeType type, TransportAddress *addr=NULL)
 Notifies and schedules overlay nodes for removal.
void migrateNode (NodeType type, TransportAddress *addr=NULL)
 Migrates overlay nodes from one access net to another.

Protected Member Functions

void initializeUnderlay (int stage)
 Sets up backbone, assigns ip addresses, calculates routing tables, sets some parameters and adds the initial number of nodes to the network.
void handleTimerEvent (cMessage *msg)
 process timer messages
void finishUnderlay ()
 Saves statistics, prints simulation time.
void setDisplayString ()
 Updates the statistics display string.

Protected Attributes

std::vector< cModule * > accessNode
 stores accessRouter
std::deque< IPvXAddress > killList
 stores nodes scheduled to be killed
std::set< int > scheduledID
 stores nodeIds to prevent migration of prekilled nodes
int numCreated
 number of overall created overlay terminals
int numKilled
 number of overall killed overlay terminals

Private Attributes

int accessRouterNum
 number of access router
int overlayAccessRouterNum
 number of overlayAccessRouter
int overlayTerminalNum
 number of terminal in the overlay
ConnectReaSETerminalConnector

Detailed Description

Configurator module for the ReaSEUnderlay.

Author:
Markus Mauch
Todo:
possibility to disable tier1-3 in overlay(access)routers

Definition at line 47 of file ReaSEUnderlayConfigurator.h.


Member Function Documentation

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

Creates an overlay node.

Parameters:
type the NodeType of the node to create
initialize creation during init phase?

Implements UnderlayConfigurator.

Definition at line 65 of file ReaSEUnderlayConfigurator.cc.

{
    Enter_Method_Silent();
    // derive overlay node from ned
    std::string nameStr = "overlayTerminal";
    if (churnGenerator.size() > 1) {
        nameStr += "-" + convertToString<int32_t>(type.typeID);
    }
    AccessInfo accessNet= TerminalConnector->getAccessNode();
    cModuleType* moduleType = cModuleType::get(type.terminalType.c_str());
    cModule* node = moduleType->create(nameStr.c_str(), accessNet.edge->Router->getParentModule(), //TODO: insert node in submodule
                                       numCreated + 1, numCreated);

    if (type.channelTypesTx.size() > 0) {
        throw cRuntimeError("ReaSEUnderlayConfigurator::createNode(): Setting "
                    "channel types via the churn generator is not allowed "
                    "with the ReaSEUnderlay. Use **.accessNet.channelTypes instead!");
    }

    node->setGateSize("pppg", 1);

    std::string displayString;

    if ((type.typeID > 0) && (type.typeID <= NUM_COLORS)) {
        ((displayString += "i=device/wifilaptop_l,")
                        += colorNames[type.typeID - 1])
                        += ",40;i2=block/circle_s";
    } else {
        displayString = "i=device/wifilaptop_l;i2=block/circle_s";
    }

    node->finalizeParameters();
    node->setDisplayString(displayString.c_str());

    node->buildInside();
    node->scheduleStart(simTime());

    // create meta information
    ReaSEInfo* info = new ReaSEInfo(type.typeID, node->getId(), type.context);

    accessNet.terminal = node;
    // add node to a randomly chosen access net
    info->setNodeID(TerminalConnector->addOverlayNode(&accessNet));


    // add node to bootstrap oracle
    globalNodeList->addPeer(IPAddressResolver().addressOf(node), info);

    // if the node was not created during startup we have to
    // finish the initialization process manually
    if (!initialize) {
        for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) {
            node->callInitialize(i);
        }
    }

    overlayTerminalCount++;
    numCreated++;

    churnGenerator[type.typeID]->terminalCount++;

    TransportAddress *address = new TransportAddress(
                                       IPAddressResolver().addressOf(node));

    // update display
    setDisplayString();

    return address;
}

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

Saves statistics, prints simulation time.

Reimplemented from UnderlayConfigurator.

Definition at line 298 of file ReaSEUnderlayConfigurator.cc.

{
    // statistics
    recordScalar("Terminals added", numCreated);
    recordScalar("Terminals removed", numKilled);

    if (!isInInitPhase()) {
        struct timeval now, diff;
        gettimeofday(&now, NULL);
        timersub(&now, &initFinishedTime, &diff);
        printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
    }
}

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

process timer messages

Parameters:
msg the received message

Reimplemented from UnderlayConfigurator.

Definition at line 257 of file ReaSEUnderlayConfigurator.cc.

{
    Enter_Method_Silent();

    // get next scheduled node from the kill list
    IPvXAddress addr = killList.back();
    killList.pop_back();

    //AccessNet* accessNetModule = NULL;
    int nodeID = -1;

    ReaSEInfo* info = dynamic_cast<ReaSEInfo*>(globalNodeList->getPeerInfo(addr));
    if (info != NULL) {
        //accessNetModule = info->getAccessNetModule();
        nodeID = info->getNodeID();
    } else {
        opp_error("IPv4UnderlayConfigurator: Trying to kill node with nonexistant TransportAddress!");
    }

    scheduledID.erase(nodeID);
    globalNodeList->killPeer(addr);

    cModule* node = TerminalConnector->removeOverlayNode(nodeID);

    if (node == NULL)
        opp_error("IPv4UnderlayConfigurator: Trying to remove node which is nonexistant in AccessNet!");

    node->callFinish();
    node->deleteModule();

    delete msg;
}

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

Sets up backbone, assigns ip addresses, calculates routing tables, sets some parameters and adds the initial number of nodes to the network.

Parameters:
stage the phase of the initialisation

Implements UnderlayConfigurator.

Definition at line 43 of file ReaSEUnderlayConfigurator.cc.

{
    //backbone configuration
    if (stage == MIN_STAGE_UNDERLAY) {

    }
    //access net configuration
    else if (stage == MAX_STAGE_UNDERLAY) {
        // fetch some parameters


        // count the overlay clients
        overlayTerminalCount = 0;

        numCreated = 0;
        numKilled = 0;

        // add access node modules to access node vector
        TerminalConnector = (ConnectReaSE*)getParentModule()->getSubmodule("TerminalConnector");
    }
}

void ReaSEUnderlayConfigurator::migrateNode ( NodeType  type,
TransportAddress addr = NULL 
) [virtual]

Migrates overlay nodes from one access net to another.

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

Implements UnderlayConfigurator.

Definition at line 203 of file ReaSEUnderlayConfigurator.cc.

{
    Enter_Method_Silent();

    // AccessNet* accessNetModule = NULL;
    int nodeID = -1;
    ReaSEInfo* info;

    // If no address given, get random node
    if (addr == NULL) {
        info = dynamic_cast<ReaSEInfo*>(globalNodeList->getRandomPeerInfo(type.typeID));
    } else {
        // get node information
        info = dynamic_cast<ReaSEInfo*>(globalNodeList->getPeerInfo(*addr));
    }

    if (info != NULL) {
        //accessNetModule = info->getAccessNetModule();
        nodeID = info->getNodeID();
    } else {
        opp_error("ReaSEUnderlayConfigurator: Trying to pre kill node with nonexistant TransportAddress!");
    }

    // do not migrate node that is already scheduled
    if (scheduledID.count(nodeID))
        return;

    cModule* node = TerminalConnector->removeOverlayNode(nodeID);//intuniform(0, accessNetModule->size() - 1));

    if (node == NULL)
        opp_error("ReaSEUnderlayConfigurator: Trying to remove node which is not an overlay node in network!");

    //remove node from bootstrap oracle
    globalNodeList->killPeer(IPAddressResolver().addressOf(node));

    node->bubble("I am migrating!");
    // connect the node to another access net
    AccessInfo newAccessModule;

    // create meta information
    ReaSEInfo* newinfo = new ReaSEInfo(type.typeID, node->getId(), type.context);
        newAccessModule = TerminalConnector->migrateNode(node->getId());
        newAccessModule.terminal = node;
        // add node to a randomly chosen access net
        info->setNodeID(TerminalConnector->addOverlayNode(&newAccessModule));

    //add node to bootstrap oracle
    globalNodeList->addPeer(IPAddressResolver().addressOf(node), newinfo);

    // inform the notification board about the migration
    NotificationBoard* nb = check_and_cast<NotificationBoard*>(node->getSubmodule("notificationBoard"));
    nb->fireChangeNotification(NF_OVERLAY_TRANSPORTADDRESS_CHANGED);
}

void ReaSEUnderlayConfigurator::preKillNode ( NodeType  type,
TransportAddress addr = NULL 
) [virtual]

Notifies and schedules overlay nodes for removal.

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

Implements UnderlayConfigurator.

Definition at line 136 of file ReaSEUnderlayConfigurator.cc.

{
    Enter_Method_Silent();

    // AccessNet* accessNetModule = NULL;
    int nodeID;
    ReaSEInfo* info;

    // If no address given, get random node
    if (addr == NULL) {
        addr = globalNodeList->getRandomAliveNode(type.typeID);

        if (addr == NULL) {
            // all nodes are already prekilled
            std::cout << "all nodes are already prekilled" << std::endl;
            return;
        }
    }

    // get node information
    info = dynamic_cast<ReaSEInfo*>(globalNodeList->getPeerInfo(*addr));

    if (info != NULL) {
        //accessNetModule = info->getAccessNetModule();
        nodeID = info->getNodeID();
    } else {
        opp_error("IPv4UnderlayConfigurator: Trying to pre kill node "
                  "with nonexistant TransportAddress!");
    }

    uint32_t effectiveType = info->getTypeID();

    // do not kill node that is already scheduled
    if (scheduledID.count(nodeID))
        return;
    //TODO: get overlay node
    cModule* node = TerminalConnector->getOverlayNode(nodeID);
    globalNodeList->removePeer(IPAddressResolver().addressOf(node));

    //put node into the kill list and schedule a message for final removal of the node
    killList.push_front(IPAddressResolver().addressOf(node));
    scheduledID.insert(nodeID);

    overlayTerminalCount--;
    numKilled++;

    churnGenerator[effectiveType]->terminalCount--;

    // update display
    setDisplayString();

    // inform the notification board about the removal
    NotificationBoard* nb = check_and_cast<NotificationBoard*>(
            node->getSubmodule("notificationBoard"));
    nb->fireChangeNotification(NF_OVERLAY_NODE_LEAVE);

    double random = uniform(0, 1);

    if (random < gracefulLeaveProbability) {
        nb->fireChangeNotification(NF_OVERLAY_NODE_GRACEFUL_LEAVE);
    }

    cMessage* msg = new cMessage();
    scheduleAt(simTime() + gracefulLeaveDelay, msg);

}

void ReaSEUnderlayConfigurator::setDisplayString (  )  [protected, virtual]

Updates the statistics display string.

Implements UnderlayConfigurator.

Definition at line 290 of file ReaSEUnderlayConfigurator.cc.

Referenced by createNode(), and preKillNode().

{
    char buf[80];
    sprintf(buf, "%i overlay terminals",
            overlayTerminalCount);
    getDisplayString().setTagArg("t", 0, buf);
}


Member Data Documentation

std::vector<cModule*> ReaSEUnderlayConfigurator::accessNode [protected]

stores accessRouter

Definition at line 108 of file ReaSEUnderlayConfigurator.h.

number of access router

Definition at line 76 of file ReaSEUnderlayConfigurator.h.

std::deque<IPvXAddress> ReaSEUnderlayConfigurator::killList [protected]

stores nodes scheduled to be killed

Definition at line 109 of file ReaSEUnderlayConfigurator.h.

Referenced by handleTimerEvent(), and preKillNode().

number of overall created overlay terminals

Definition at line 113 of file ReaSEUnderlayConfigurator.h.

Referenced by createNode(), finishUnderlay(), and initializeUnderlay().

number of overall killed overlay terminals

Definition at line 114 of file ReaSEUnderlayConfigurator.h.

Referenced by finishUnderlay(), initializeUnderlay(), and preKillNode().

number of overlayAccessRouter

Definition at line 77 of file ReaSEUnderlayConfigurator.h.

number of terminal in the overlay

Definition at line 78 of file ReaSEUnderlayConfigurator.h.

std::set<int> ReaSEUnderlayConfigurator::scheduledID [protected]

stores nodeIds to prevent migration of prekilled nodes

Definition at line 110 of file ReaSEUnderlayConfigurator.h.

Referenced by handleTimerEvent(), migrateNode(), and preKillNode().


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