OverSim
ConnectReaSE Class Reference

#include <ConnectReaSE.h>

Public Member Functions

virtual int addOverlayNode (AccessInfo *overlayNode, bool migrate=false)
 Gathers some information about the terminal and appends it to the overlay terminal vector.
virtual AccessInfo getAccessNode ()
 Getter for router module.
virtual cModule * removeOverlayNode (int ID)
 Removes a node from the network.
virtual cModule * getOverlayNode (int ID)
 searches overlayTerminal[] for a given node
virtual AccessInfo migrateNode (int ID)

Protected Member Functions

virtual int numInitStages () const
 OMNeT number of init stages.
virtual void initialize (int stage)
 Gather some information about the router node.
virtual void handleMessage (cMessage *msg)
 OMNeT handleMessage method.
virtual void updateDisplayString ()
 Displays the current number of terminals connected to the network.

Protected Attributes

std::vector< std::string > channelTypesRx
 vector of possible access channels (rx)
std::vector< std::string > channelTypesTx
 vector of possible access channels (tx)
std::vector< terminalInfooverlayTerminal
 the terminals at this access router
cOutVector lifetimeVector
 vector of node lifetimes
std::vector< autoSystemAS_Pool
std::vector< edgePoolglobalEdgePool
uint32 totalCountOfAS
uint32 nextPow
uint32 ASShift
double channelDiversity

Private Member Functions

cGate * firstUnusedGate (cModule *owner, const char *name, cGate::Type type=cGate::NONE)
 Returns a module's fist unconnected gate.
void setUpAS (cModule *currAS)
 Gathers all needed edge router information of a specified autonomous system.

Static Private Member Functions

static bool extractFromParentModule (cModule *currModule, void *properties)
 Finds submodules with special properties.

Detailed Description

Definition at line 106 of file ConnectReaSE.h.

Member Function Documentation

int ConnectReaSE::addOverlayNode ( AccessInfo overlayNode,
bool  migrate = false 
)
virtual

Gathers some information about the terminal and appends it to the overlay terminal vector.

Definition at line 194 of file ConnectReaSE.cc.

Referenced by ReaSEUnderlayConfigurator::createNode(), and ReaSEUnderlayConfigurator::migrateNode().

{
Enter_Method("addOverlayNode()");
cModule* node = overlayNode->terminal;
terminalInfo terminal;
terminal.module = node;
terminal.interfaceTable = IPAddressResolver().interfaceTableOf(node);
terminal.remoteInterfaceTable = overlayNode->edge->interfaceTable;
terminal.routingTable = IPAddressResolver().routingTableOf(node);
terminal.PPPInterface = node->getSubmodule("ppp", 0);
terminal.createdAt = simTime();
terminal.IPAddress = overlayNode->IPAddress;
terminal.edgeRouter = overlayNode->edge;
terminal.ASindex = overlayNode->ASindex;
// update display
if (ev.isGUI()) {
const char* ip_disp = const_cast<char*>
(IPAddress(terminal.IPAddress).str().c_str());
terminal.module->getDisplayString().insertTag("t", 0);
terminal.module->getDisplayString().setTagArg("t", 0, ip_disp);
terminal.module->getDisplayString().setTagArg("t", 1, "l");
}
//find first unused interface
int k = 1;
while ( overlayNode->edge->Router->findSubmodule("ppp", k) != -1 )
k++;
cModuleType* pppInterfaceModuleType = cModuleType::get("inet.linklayer.ppp.PPPInterface");
terminal.remotePPPInterface = pppInterfaceModuleType->
create("ppp", overlayNode->edge->Router, 0, k);
overlayNode->edge->countPPPInterfaces++;
// connect terminal to access router and vice versa
cGate* routerInGate = firstUnusedGate(overlayNode->edge->Router, "pppg", cGate::INPUT);
cGate* routerOutGate = firstUnusedGate(overlayNode->edge->Router, "pppg", cGate::OUTPUT);
cChannelType* channelTypeRx = cChannelType::find( overlayNode->edge->channelTypeRxStr.c_str() );
cChannelType* channelTypeTx = cChannelType::find( overlayNode->edge->channelTypeTxStr.c_str() );
if (!channelTypeRx || !channelTypeTx)
opp_error("Could not find Channel or ChannelRx Type. Most likely "
"parameter channelTypes does not match the channels defined "
"in channels.ned");
//create channels
cDatarateChannel* channelRx = check_and_cast<cDatarateChannel*>(channelTypeRx->create(overlayNode->edge->channelTypeRxStr.c_str()));
cDatarateChannel* channelTx = check_and_cast<cDatarateChannel*>(channelTypeTx->create(overlayNode->edge->channelTypeTxStr.c_str()));
//connect terminal
terminal.module->gate("pppg$o", 0)->connectTo(routerInGate,channelRx);
routerOutGate->connectTo(terminal.module->gate("pppg$i", 0),channelTx);
// connect ppp interface module to router module and vice versa
routerInGate->connectTo(terminal.remotePPPInterface->gate("phys$i"));
terminal.remotePPPInterface->gate("phys$o")->connectTo(routerOutGate);
// connect ppp interface module to network layer module and vice versa
cModule* netwModule = overlayNode->edge->Router->getSubmodule("networkLayer");
cGate* netwInGate = firstUnusedGate(netwModule, "ifIn");
cGate* netwOutGate = firstUnusedGate(netwModule, "ifOut");
netwOutGate->connectTo(terminal.remotePPPInterface->gate("netwIn"));
terminal.remotePPPInterface->gate("netwOut")->connectTo(netwInGate);
// connect network layer module to ip and arp modules
cModule* ipModule = overlayNode->edge->Router->getSubmodule("networkLayer")->
getSubmodule("ip");
cGate* ipIn = firstUnusedGate(ipModule, "queueIn");
netwInGate->connectTo(ipIn);
//
// Start ppp interface modules
//
terminal.remotePPPInterface->finalizeParameters();
terminal.remotePPPInterface->setDisplayString("i=block/ifcard");
terminal.remotePPPInterface->buildInside();
terminal.remotePPPInterface->scheduleStart(simTime());
terminal.remotePPPInterface->callInitialize();
if ( !migrate) {
// we are already in stage 4 and need to call initialize
// for all previous stages manually
for (int i=0; i < MAX_STAGE_UNDERLAY + 1; i++) {
terminal.module->callInitialize(i);
}
}
//calculate diversity factor for both channels (+/- diversity)
double diversityFactor = (uniform(0 , 2*channelDiversity) + (100-channelDiversity))/100;
//customize channel delays
channelRx->setDelay(SIMTIME_DBL(channelRx->getDelay()*diversityFactor));
channelTx->setDelay(SIMTIME_DBL(channelTx->getDelay()*diversityFactor));
terminal.remoteInterfaceEntry = overlayNode->edge->interfaceTable->getInterface(
overlayNode->edge->interfaceTable->getNumInterfaces() - 1);
terminal.interfaceEntry = terminal.interfaceTable->getInterfaceByName("ppp0");
//
// Fill in interface table.
//
// router
IPv4InterfaceData* interfaceData = new IPv4InterfaceData;
interfaceData->setIPAddress(overlayNode->edge->IPAddress);
interfaceData->setNetmask(IPAddress::ALLONES_ADDRESS);
terminal.remoteInterfaceEntry->setIPv4Data(interfaceData);
// terminal
terminal.interfaceEntry->ipv4Data()->setIPAddress(IPAddress(terminal.IPAddress));
terminal.interfaceEntry->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);
//
// Fill in routing table.
//
// add edge routing entry
IPRoute* re = new IPRoute();
re->setHost(IPAddress(terminal.IPAddress));
re->setNetmask(IPAddress::ALLONES_ADDRESS);
re->setInterface(terminal.remoteInterfaceEntry);
re->setType(IPRoute::DIRECT);
re->setSource(IPRoute::MANUAL);
overlayNode->edge->routingTable->addRoute(re);
terminal.remoteRoutingEntry = re;
// add terminal routing entry
IPRoute* te = new IPRoute();
te->setHost(IPAddress::UNSPECIFIED_ADDRESS);
te->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
te->setGateway(overlayNode->edge->IPAddress);
te->setInterface(terminal.interfaceEntry);
te->setType(IPRoute::REMOTE);
te->setSource(IPRoute::MANUAL);
terminal.routingTable->addRoute(te);
terminal.routingEntry = te;
// append module to overlay terminal vector
overlayTerminal.push_back(terminal);
int ID = node->getId();
return ID;
}
bool ConnectReaSE::extractFromParentModule ( cModule *  currModule,
void *  properties 
)
staticprivate

Finds submodules with special properties.

Parameters
currModulecurrently tested module
propertiespointer to topologyProperty (parent module and special property)

Definition at line 497 of file ConnectReaSE.cc.

Referenced by setUpAS().

{
topologyProperty* currProp = (topologyProperty*)properties;
if (currModule->getParentModule() == currProp->pModule) {
if (currModule->getProperties()->get(currProp->property)) {
return true;
}
}
return false;
}
cGate * ConnectReaSE::firstUnusedGate ( cModule *  owner,
const char *  name,
cGate::Type  type = cGate::NONE 
)
private

Returns a module's fist unconnected gate.

Parameters
ownergate owner module
namename of the gate vector
typegate type (input or output)

Definition at line 483 of file ConnectReaSE.cc.

Referenced by addOverlayNode().

{
int index;
for (index = 0; index < owner->gateSize(name); index++) {
cGate *gate = type == cGate::NONE ? owner->gate(name, index) : owner->gateHalf(name, type, index);
if (!gate->isConnectedOutside()) {
return gate;
}
}
owner->setGateSize(name, index + 2);
return type == cGate::NONE ? owner->gate(name, index + 1) : owner->gateHalf(name, type, index + 1);
}
AccessInfo ConnectReaSE::getAccessNode ( )
virtual

Getter for router module.

Returns
pointer to router module

Definition at line 137 of file ConnectReaSE.cc.

Referenced by ReaSEUnderlayConfigurator::createNode(), and migrateNode().

{
Enter_Method("getAccessNode()");
bool candidateOK = false;
int numTries = 10;
uint32 test_IP = 0;
AccessInfo node;
edgeRoutes* connectionCandidate;
uint32 tempIndex, tempASindex;
while ((numTries > 0)&&(!candidateOK)) {
numTries--;
tempIndex = intuniform(0, globalEdgePool.size()-1);
connectionCandidate = globalEdgePool[tempIndex].edge;
tempASindex = globalEdgePool[tempIndex].indexAS;
//limit terminals per edge router
if (connectionCandidate->IPAddresses.size() >= ((uint32_t) 1 << AS_Pool[tempASindex].edgeShift)) // maximum reached?
continue;
// test_IP = connectionCandidate->IPAddress + 1; // begin with first IP after the edge router
// for (int i = 0; i < (1 << AS_Pool[tempASindex].edgeShift); i++ ) {
// test_IP += i;
// candidateOK = true;
// for (uint32 j = 0; j < connectionCandidate->IPAddresses.size(); j++) {
// if (connectionCandidate->IPAddresses[j] == test_IP) {
// candidateOK =false;
// break;
// }
// }
// if (candidateOK) {
// connectionCandidate->IPAddresses.push_back(test_IP);
// break;
// }
// }
// FIXME: check overlays for side effects of reused IP addresses
test_IP = ++connectionCandidate->lastIP;
connectionCandidate->IPAddresses.push_back(test_IP);
break;
}
// no free IP address after 10 tries
if (numTries == 0) {
opp_error("Error creating node: No available IP found after four tries!");
}
EV << "Found available IP: " << test_IP;
node.ASindex = tempASindex;
node.IPAddress = test_IP;
node.edge = connectionCandidate;
return node;
}
cModule * ConnectReaSE::getOverlayNode ( int  ID)
virtual

searches overlayTerminal[] for a given node

Parameters
IDposition of the node in overlayTerminal
Returns
the nodeId if found, -1 else

Definition at line 419 of file ConnectReaSE.cc.

Referenced by ReaSEUnderlayConfigurator::preKillNode().

{
Enter_Method("getOverlayNode()");
cModule* node = NULL;
for (unsigned int i=0; i<overlayTerminal.size(); i++) {
if (overlayTerminal[i].module->getId() == ID) {
node = overlayTerminal[i].module;
return node;
}
}
opp_error("Node was not found in global list of overlay terminals");
return node;
}
void ConnectReaSE::handleMessage ( cMessage *  msg)
protectedvirtual

OMNeT handleMessage method.

Parameters
msgthe message to handle

Definition at line 460 of file ConnectReaSE.cc.

{
error("this module doesn't handle messages, it runs only in initialize()");
}
void ConnectReaSE::initialize ( int  stage)
protectedvirtual

Gather some information about the router node.

Definition at line 47 of file ConnectReaSE.cc.

{
//EV << "Connector Stage" << stage;
if (stage != MAX_STAGE_UNDERLAY)
return;
//get parameters
channelTypesTx = cStringTokenizer(par("channelTypes"), " ").asVector();
channelTypesRx = cStringTokenizer(par("channelTypesRx"), " ").asVector();
channelDiversity = par("channelDiversity");
if (channelTypesTx.size() < channelTypesRx.size()) {
}
else if (channelTypesTx.size() > channelTypesRx.size()) {
}
// make sure that delay cannot be zero and diversity cannot be below zero
if (channelDiversity>=100)
channelDiversity = 99.99f;
else if (channelDiversity<0)
// statistics
lifetimeVector.setName("Terminal Lifetime");
// set up network
cModule* tempModule;
cTopology tempTopology("tempTopo");
edgePool tempEdgePool;
tempTopology.extractByProperty("AS");
totalCountOfAS = tempTopology.getNumNodes();
nextPow = 0;
while (((uint32_t) 1 << nextPow) < totalCountOfAS + 1) {
}
ASShift = 32 - nextPow;
if (tempTopology.getNumNodes() == 0) {
//no AS topology
tempTopology.extractByProperty("RL");
if (tempTopology.getNumNodes() == 0)
//no router topology
opp_error("ConnectReaSE: Neither an AS topology nor a router topology was detected.");
setUpAS(getParentModule());
}
else {
// set up all autonomous systems (AS)
int index = 0;
std::vector<cModule*> Modules;
for (int i=0; i<tempTopology.getNumNodes(); i++) {
tempModule = tempTopology.getNode(i)->getModule();
Modules.push_back(tempModule);
index++;
}
for (uint32 i=0; i< Modules.size(); i++) {
setUpAS(Modules[i]);
}
}
// put all edge router in one data structure to get a equal probability of selection
for (uint32 i=0; i<AS_Pool.size(); i++) {
for (uint32 j=0; j< AS_Pool[i].edgeRouter.size(); j++) {
tempEdgePool.edge = &AS_Pool[i].edgeRouter[j];
tempEdgePool.indexAS = i;
globalEdgePool.push_back(tempEdgePool);
}
}
//cout << "Number of Edges in Network: " << globalEdgePool.size() << endl;
for (uint32 i=0; i<globalEdgePool.size(); i++) {
//select channel
globalEdgePool[i].edge->channelTypeTxStr = channelTypesTx[intuniform(0,channelTypesTx.size()-1)];
globalEdgePool[i].edge->channelTypeRxStr = channelTypesRx[intuniform(0,channelTypesRx.size()-1)];
}
}
AccessInfo ConnectReaSE::migrateNode ( int  ID)
virtual

Definition at line 435 of file ConnectReaSE.cc.

Referenced by ReaSEUnderlayConfigurator::migrateNode().

{
Enter_Method("migrateNode()");
AccessInfo newEdgeRouter;
terminalInfo terminal;
for (unsigned int i=0; i<overlayTerminal.size(); i++) {
if (overlayTerminal[i].module->getId() == ID) {
terminal = overlayTerminal[i];
break;
}
}
if (terminal.module == NULL) opp_error("ConnectReaSE: Cannot find migrating node");
do {
newEdgeRouter = getAccessNode();
}
while ((newEdgeRouter.edge->Router->getId() == terminal.edgeRouter->Router->getId()) && (AS_Pool[terminal.ASindex].edgeRouter.size()!= 1));
return newEdgeRouter;
}
virtual int ConnectReaSE::numInitStages ( void  ) const
inlineprotectedvirtual

OMNeT number of init stages.

Returns
needed number of init stages

Definition at line 144 of file ConnectReaSE.h.

{
return MAX_STAGE_UNDERLAY + 1;
}
cModule * ConnectReaSE::removeOverlayNode ( int  ID)
virtual

Removes a node from the network.

Definition at line 350 of file ConnectReaSE.cc.

Referenced by ReaSEUnderlayConfigurator::handleTimerEvent(), and ReaSEUnderlayConfigurator::migrateNode().

{
Enter_Method("removeOverlayNode()");
cModule* node = NULL;
terminalInfo terminal;
int index = 0;
uint32 releasedIP;
// find module
for (unsigned int i=0; i<overlayTerminal.size(); i++) {
if (overlayTerminal[i].module->getId() == ID) {
terminal = overlayTerminal[i];
node = terminal.module;
index = i;
break;
}
}
if (node == NULL) return NULL;
releasedIP = IPAddressResolver().addressOf(terminal.module).get4().getInt();;
// free IP address
for (unsigned int i=0; i < terminal.edgeRouter->IPAddresses.size(); i++) {
if (terminal.edgeRouter->IPAddresses[i] == releasedIP) {
terminal.edgeRouter->IPAddresses.erase(terminal.edgeRouter->IPAddresses.begin() + i);
break;
}
}
cModule* ppp = terminal.remotePPPInterface;
// disconnect terminal
node->gate("pppg$o", 0)->disconnect();
node->gate("pppg$i", 0)->getPreviousGate()->disconnect();
// disconnect ip and arp modules
ppp->gate("netwIn")->getPathStartGate()->disconnect();
ppp->gate("netwOut")->getNextGate()->disconnect();
// remove associated ppp interface module
ppp->callFinish();
ppp->deleteModule();
// remove associated interface table entry
terminal.edgeRouter->interfaceTable->deleteInterface(terminal.remoteInterfaceEntry);
// remove routing entries
terminal.routingTable->deleteRoute(terminal.routingEntry);
terminal.edgeRouter->routingTable ->deleteRoute(terminal.remoteRoutingEntry);
//TODO: implement life vector statistics
lifetimeVector.record(simTime() - overlayTerminal[index].createdAt);
// remove terminal from overlay terminal vector
overlayTerminal.erase(overlayTerminal.begin() + index);
return node;
}
void ConnectReaSE::setUpAS ( cModule *  currAS)
private

Gathers all needed edge router information of a specified autonomous system.

This method gathers all edge routers, their IPs and the IPs of all connected hosts.

Parameters
currASAS module

Definition at line 509 of file ConnectReaSE.cc.

Referenced by initialize().

{
cTopology edgeTopo("Edges");
cTopology Topo("All nodes");
cModule* tempNode;
uint32 tempIP;
edgeRoutes tempEdge;
autoSystem tempAS;
int k;
tempProp->pModule = currAS;
tempProp->property = "EdgeRouter";
edgeTopo.extractFromNetwork(extractFromParentModule, (void*) tempProp);
tempProp->property = "RL";
Topo.extractFromNetwork(extractFromParentModule, (void*) tempProp);
//get net shift for IP address
nextPow = 1;
while ((1 << nextPow) < edgeTopo.getNumNodes() + 2) {
}
// add information about edge router
for (int i=0; i< edgeTopo.getNumNodes(); i++) {
tempEdge.Router = edgeTopo.getNode(i)->getModule();
tempEdge.IPAddress = IPAddressResolver().addressOf(tempEdge.Router).get4().getInt();
tempEdge.IPAddresses.push_back(IPAddressResolver().addressOf(tempEdge.Router).get4().getInt());
tempEdge.interfaceTable = IPAddressResolver().interfaceTableOf(tempEdge.Router);
tempEdge.routingTable = IPAddressResolver().routingTableOf(tempEdge.Router);
k = 0;
while ( tempEdge.Router->findSubmodule("ppp", k) != -1 )
k++;
tempEdge.countPPPInterfaces = k;
// the last allocated IP is the router address plus the (k - 1) connected ReaSE hosts
tempEdge.lastIP = tempEdge.IPAddress + k - 1; // FIXME: check overlays for side effects of reused IP addresses
// find hosts
Topo.calculateUnweightedSingleShortestPathsTo(Topo.getNodeFor(edgeTopo.getNode(i)->getModule()));
for (int j=0; j< Topo.getNumNodes(); j++) {
tempNode = Topo.getNode(j)->getModule();
if (tempNode->getProperties()->get("CoreRouter"))
continue;
if (tempNode->getProperties()->get("GatewayRouter"))
continue;
if (tempNode->getProperties()->get("EdgeRouter"))
continue;
if (Topo.getNode(j)->getPath(0)->getRemoteNode()->getModule() != edgeTopo.getNode(i)->getModule())
continue;
//fill IP table
tempIP = IPAddressResolver().addressOf(Topo.getNode(j)->getModule()).get4().getInt();
tempEdge.IPAddresses.push_back(tempIP);
}
tempAS.edgeRouter.push_back(tempEdge);
}
delete tempProp;
AS_Pool.push_back(tempAS);
}
void ConnectReaSE::updateDisplayString ( )
protectedvirtual

Displays the current number of terminals connected to the network.

Definition at line 465 of file ConnectReaSE.cc.

Referenced by addOverlayNode(), and removeOverlayNode().

{
if (ev.isGUI()) {
char buf[80];
if ( overlayTerminal.size() == 1 ) {
sprintf(buf, "1 terminal connected");
} else {
sprintf(buf, "%zi terminals connected", overlayTerminal.size());
}
getDisplayString().setTagArg("t", 0, buf);
getDisplayString().setTagArg("t", 2, "blue");
if ((overlayTerminal.size() % 100) == 0) {
cerr << "ConnectReaSE: " << overlayTerminal.size() << " Terminals connected in network." <<endl;
}
}
}

Member Data Documentation

std::vector<autoSystem> ConnectReaSE::AS_Pool
protected

Definition at line 176 of file ConnectReaSE.h.

Referenced by getAccessNode(), initialize(), migrateNode(), and setUpAS().

uint32 ConnectReaSE::ASShift
protected

Definition at line 178 of file ConnectReaSE.h.

Referenced by initialize(), and setUpAS().

double ConnectReaSE::channelDiversity
protected

Definition at line 179 of file ConnectReaSE.h.

Referenced by addOverlayNode(), and initialize().

std::vector<std::string> ConnectReaSE::channelTypesRx
protected

vector of possible access channels (rx)

Definition at line 166 of file ConnectReaSE.h.

Referenced by initialize().

std::vector<std::string> ConnectReaSE::channelTypesTx
protected

vector of possible access channels (tx)

Definition at line 168 of file ConnectReaSE.h.

Referenced by initialize().

std::vector<edgePool> ConnectReaSE::globalEdgePool
protected

Definition at line 177 of file ConnectReaSE.h.

Referenced by getAccessNode(), and initialize().

cOutVector ConnectReaSE::lifetimeVector
protected

vector of node lifetimes

Definition at line 174 of file ConnectReaSE.h.

Referenced by initialize(), and removeOverlayNode().

uint32 ConnectReaSE::nextPow
protected

Definition at line 178 of file ConnectReaSE.h.

Referenced by initialize(), and setUpAS().

std::vector<terminalInfo> ConnectReaSE::overlayTerminal
protected

the terminals at this access router

Definition at line 171 of file ConnectReaSE.h.

Referenced by addOverlayNode(), getOverlayNode(), migrateNode(), removeOverlayNode(), and updateDisplayString().

uint32 ConnectReaSE::totalCountOfAS
protected

Definition at line 178 of file ConnectReaSE.h.

Referenced by initialize().


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