IPv4UnderlayConfigurator Class Reference

#include <IPv4UnderlayConfigurator.h>

Inheritance diagram for IPv4UnderlayConfigurator:

UnderlayConfigurator List of all members.

Detailed Description

Configurator module for the IPv4Underlay.


Public Member Functions

void createRandomNode (bool initialize)
 Creates an overlay node and adds it to a randomly chosen access net.
void killRandomNode ()
 Removes randomly chosen overlay nodes from a randomly chosen access net.
void migrateRandomNode ()
 Migrates randomly chosen overlay nodes from on access net to another.

Protected Member Functions

void initializeUnderlay (int stage)
 Init method for derived underlay configurators.
void finish ()
 Cleans up configurator.
void setDisplayString ()
 Updates the statistics display string.

Protected Attributes

std::vector< cModule * > accessNode
int numCreated
int numKilled

Private Attributes

int accessRouterNum
int overlayAccessRouterNum
int overlayTerminalNum


Member Function Documentation

void IPv4UnderlayConfigurator::createRandomNode ( bool  initialize  )  [virtual]

Creates an overlay node and adds it to a randomly chosen access net.

Parameters:
initialize creation during init phase?

Implements UnderlayConfigurator.

00202 {
00203     // derive overlay node from ned
00204     cModuleType* moduleType = findModuleType("OverlayHost");//parentModule()->par("overlayTerminalType"));
00205     cModule* node = moduleType->create("overlayTerminal", parentModule());
00206 
00207     node->par("overlayType").setStringValue(parentModule()->par("overlayType"));
00208     node->par("overlayAppType").setStringValue(parentModule()->par("overlayAppType"));
00209 
00210     node->setGateSize("in", 1);
00211     node->setGateSize("out", 1);
00212     node->setDisplayString("i=device/wifilaptop_l;i2=block/circle_s");
00213     node->buildInside();
00214     node->scheduleStart(simulation.simTime());
00215 
00216     // add node to a randomly chosen access net
00217     AccessNet* accessNet = check_and_cast<AccessNet*>
00218                            (accessNode[intuniform(0, accessNode.size() - 1)]->submodule("accessNet"));
00219     accessNet->addOverlayNode(node);
00220 
00221     // append index to module name
00222     char buf[80];
00223     sprintf(buf, "overlayTerminal[%i]", numCreated);
00224     node->setName(buf);
00225 
00226     // if the node was not created during startup we have to
00227     // finish the initialization process manually
00228     if ( !initialize) {
00229         for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) {
00230             node->callInitialize(i);
00231         }
00232     }
00233 
00234     overlayTerminalCount++;
00235     numCreated++;
00236 }

void IPv4UnderlayConfigurator::finish (  )  [protected, virtual]

Cleans up configurator.

Implements UnderlayConfigurator.

00292 {
00293     // statistics
00294     recordScalar("Terminals added", numCreated);
00295     recordScalar("Terminals removed", numKilled);
00296 
00297     struct timeval now, diff;
00298     gettimeofday(&now, NULL);
00299     timersub(&now, &initFinishedTime, &diff);
00300     printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
00301 }

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

Init method for derived underlay configurators.

Implements UnderlayConfigurator.

00035 {
00036     //backbone configuration
00037     if(stage == MIN_STAGE_UNDERLAY) {
00038         // Find all router module types.
00039         cTopology topo("topo");
00040         const char* typeNames[5];
00041         typeNames[0] = "Router";
00042         typeNames[1] = "OverlayRouter";
00043         typeNames[2] = "AccessRouter";
00044         typeNames[3] = "OverlayAccessRouter";
00045         typeNames[4] = NULL;
00046         topo.extractByModuleType(typeNames);
00047 
00048         // Assign IP addresses to all router modules.
00049         std::vector<uint32> nodeAddresses;
00050         nodeAddresses.resize(topo.nodes());
00051 
00052         uint32 lowIPBoundary = uint32((1 << 24) + 1);   // IP addresses for backbone
00053         int numIPNodes = 0;                             // nodes shall beginn with 1.1.0.1
00054         for (int i = 0; i < topo.nodes(); i++) {
00055             ++numIPNodes;
00056 
00057             uint32 addr = lowIPBoundary + uint32(numIPNodes << 16);
00058             nodeAddresses[i] = addr;
00059 
00060             // update ip display string
00061             if (ev.isGUI()) {
00062                 const char* ip_disp = const_cast<char*>(IPAddress(addr).str().c_str());
00063                 topo.node(i)->module()->displayString().insertTag("t", 0);
00064                 topo.node(i)->module()->displayString().setTagArg("t", 0, ip_disp);
00065                 topo.node(i)->module()->displayString().setTagArg("t", 1, "l");
00066                 topo.node(i)->module()->displayString().setTagArg("t", 2, "red");
00067             }
00068 
00069             // find interface table and assign address to all (non-loopback) interfaces
00070             InterfaceTable* ift = IPAddressResolver().interfaceTableOf(topo.node(i)->module());
00071 
00072             for ( int k = 0; k < ift->numInterfaces(); k++ ) {
00073                 InterfaceEntry* ie = ift->interfaceAt(k);
00074                 if (!ie->isLoopback()) {
00075                     ie->ipv4()->setInetAddress(IPAddress(addr));
00076                     // full address must match for local delivery
00077                     ie->ipv4()->setNetmask(IPAddress::ALLONES_ADDRESS);
00078                 }
00079             }
00080         }
00081 
00082         // Fill in routing tables.
00083         for ( int i = 0; i < topo.nodes(); i++ ) {
00084             cTopology::Node* destNode = topo.node(i);
00085             uint32 destAddr = nodeAddresses[i];
00086 
00087             // calculate shortest paths from everywhere towards destNode
00088             topo.unweightedSingleShortestPathsTo(destNode);
00089 
00090             // add route (with host=destNode) to every routing table in the network
00091             for ( int j = 0; j < topo.nodes(); j++ ) {
00092                 // continue if same node
00093                 if ( i == j )
00094                     continue;
00095 
00096                 // cancel simulation if node is not conencted with destination
00097                 cTopology::Node* atNode = topo.node(j);
00098                 if(atNode->paths() == 0)
00099                     error((std::string(atNode->module()->name()) +
00100                            ": Network is not entirely connected. Please increase your value for the connectivity parameter").c_str());
00101 
00102                 //
00103                 // Add routes at the atNode.
00104                 //
00105 
00106                 // find atNode's interface and routing table
00107                 InterfaceTable* ift = IPAddressResolver().interfaceTableOf(atNode->module());
00108                 RoutingTable* rt = IPAddressResolver().routingTableOf(atNode->module());
00109 
00110                 // find atNode's interface entry for the next hop node
00111                 int outputGateId = atNode->path(0)->localGate()->id();
00112                 InterfaceEntry *ie = ift->interfaceByNodeOutputGateId(outputGateId);
00113 
00114                 // find the next hop node on the path towards destNode
00115                 cModule* next_hop = atNode->path(0)->remoteNode()->module();
00116                 IPAddress next_hop_ip = IPAddressResolver().addressOf(next_hop).get4();
00117 
00118 
00119                 // Requirement 1: Each router has exactly one routing entry
00120                 // (netmask 255.255.0.0) to each other router
00121                 RoutingEntry* re = new RoutingEntry();
00122 
00123                 re->host = IPAddress(destAddr);
00124                 re->interfaceName = ie->name();
00125                 re->interfacePtr = ie;
00126                 re->source = RoutingEntry::MANUAL;
00127                 re->netmask = IPAddress(255, 255, 0, 0);
00128                 re->gateway = IPAddress(next_hop_ip);
00129                 re->type = RoutingEntry::REMOTE;
00130 
00131                 rt->addRoutingEntry(re);
00132 
00133                 // Requirement 2: Each router has a point-to-point routing
00134                 // entry (netmask 255.255.255.255) for each immediate neighbour
00135                 if ( atNode->distanceToTarget() == 1 ) {
00136                     RoutingEntry* re2 = new RoutingEntry();
00137 
00138                     re2->host = IPAddress(destAddr);
00139                     re2->interfaceName = ie->name();
00140                     re2->interfacePtr = ie;
00141                     re2->source = RoutingEntry::MANUAL;
00142                     re2->netmask = IPAddress(255, 255, 255, 255);
00143                     re2->type = RoutingEntry::DIRECT;
00144 
00145                     rt->addRoutingEntry(re2);
00146                 }
00147             }
00148         }
00149     }
00150     //accessnet configuration
00151     else if(stage == MAX_STAGE_UNDERLAY) {
00152         // fetch some parameters
00153         accessRouterNum = parentModule()->par("accessRouterNum");
00154         overlayAccessRouterNum = parentModule()->par("overlayAccessRouterNum");
00155 
00156         // flag indicating simulation initialization phase (true) vs. normal mode (false)
00157         init = true;
00158 
00159         // count the overlay clients
00160         overlayTerminalCount = 0;
00161         numCreated = 0;
00162         numKilled = 0;
00163 
00164         // add access node modules to access node vector
00165         // and assing the channel tpye to be used by the access node
00166         cModule* node;
00167         AccessNet* nodeAccess;
00168         for ( int i = 0; i < accessRouterNum; i++ ) {
00169             node = parentModule()->submodule("accessRouter", i);
00170             accessNode.push_back( node );
00171             nodeAccess = check_and_cast<AccessNet*>( node->submodule("accessNet") );
00172             nodeAccess->selectChannel( channelTypes[intuniform(0, channelTypes.size()-1)] );
00173         }
00174 
00175         for ( int i = 0; i < overlayAccessRouterNum; i++ ) {
00176             node = parentModule()->submodule("overlayAccessRouter", i);
00177             accessNode.push_back( node );
00178             nodeAccess = check_and_cast<AccessNet*>( node->submodule("accessNet") );
00179             nodeAccess->selectChannel( channelTypes[intuniform(0, channelTypes.size()-1)] );
00180         }
00181 
00182         // add the overlay nodes
00183         for ( int i = 0; i < initialOverlayTerminalNum; i++ ) {
00184             createRandomNode(true);
00185         }
00186 
00187         // debug stuff
00188         WATCH_PTRVECTOR(accessNode);
00189 
00190         // update display
00191         setDisplayString();
00192 
00193         // initialize simulation
00194         if ( par("simulateMobility") ) {
00195             cMessage* msg = new cMessage();
00196             scheduleAt(simulation.simTime(), msg);
00197         }
00198     }
00199 }

void IPv4UnderlayConfigurator::killRandomNode (  )  [virtual]

Removes randomly chosen overlay nodes from a randomly chosen access net.

Implements UnderlayConfigurator.

00239 {
00240     // find an access net with one or more overlay nodes
00241     AccessNet* accessNetModule;
00242     do {
00243         int z = intuniform(0, accessNode.size()-1);
00244         accessNetModule = check_and_cast<AccessNet*>(accessNode[z]->submodule("accessNet"));
00245     } while ( accessNetModule->size() == 0 );
00246 
00247     // remove a random node from the access net and delete it
00248     cModule* node = accessNetModule->removeOverlayNode(intuniform(0, accessNetModule->size() - 1));
00249     node->callFinish();
00250     node->deleteModule();
00251 
00252     overlayTerminalCount--;
00253     numKilled++;
00254 }

void IPv4UnderlayConfigurator::migrateRandomNode (  )  [virtual]

Migrates randomly chosen overlay nodes from on access net to another.

Implements UnderlayConfigurator.

00257 {
00258     // find an access net with one or more overlay nodes
00259     AccessNet* accessNetModule;
00260     do {
00261         int z = intuniform(0, accessNode.size()-1);
00262         accessNetModule = check_and_cast<AccessNet*>(accessNode[z]->submodule("accessNet"));
00263     } while ( accessNetModule->size() == 0 );
00264 
00265     // disconnect a random overlay node
00266     cModule* node = accessNetModule->removeOverlayNode(intuniform(0, accessNetModule->size() - 1));
00267 
00268     node->bubble("I am migrating!");
00269 
00270     // connect the node to another access net
00271     AccessNet* newAccessNetModule;
00272     do {
00273         newAccessNetModule = check_and_cast<AccessNet*>(accessNode[intuniform(0, accessNode.size() - 1)]->submodule("accessNet"));
00274 
00275     } while((newAccessNetModule == accessNetModule) && (accessNode.size() != 1));
00276 
00277     newAccessNetModule->addOverlayNode(node, true);
00278 
00279     // inform the notofication board about the migration
00280     NotificationBoard* nb = check_and_cast<NotificationBoard*>(node->submodule("notificationBoard"));
00281     nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED);
00282 }

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

Updates the statistics display string.

Implements UnderlayConfigurator.

00285 {
00286     char buf[80];
00287     sprintf(buf, "%i overlay clients\n%i access router\n%i overlay access router", overlayTerminalCount, accessRouterNum, overlayAccessRouterNum);
00288     displayString().setTagArg("t", 0, buf);
00289 }


Member Data Documentation

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

int IPv4UnderlayConfigurator::accessRouterNum [private]

int IPv4UnderlayConfigurator::numCreated [protected]

int IPv4UnderlayConfigurator::numKilled [protected]

int IPv4UnderlayConfigurator::overlayAccessRouterNum [private]

int IPv4UnderlayConfigurator::overlayTerminalNum [private]


The documentation for this class was generated from the following files:
Generated on Fri Dec 15 17:50:30 2006 for ITM OverSim by  doxygen 1.4.7