SimpleNetConfigurator Class Reference

#include <SimpleNetConfigurator.h>

Inheritance diagram for SimpleNetConfigurator:

UnderlayConfigurator List of all members.

Protected Member Functions

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

Protected Attributes

GlobalRoutingHashMaproutingHashMap
uint32 nextFreeAddress
cModuleType * moduleType
uint sendQueueLength
 send queue length of overlay terminals
int numCreated
int numKilled

Private Member Functions

int createRandomNode (bool initialize)
 creates an overlay node
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.

Member Function Documentation

int SimpleNetConfigurator::createRandomNode ( bool  initialize  )  [private, virtual]

creates an overlay node

Implements UnderlayConfigurator.

00080 {
00081     // derive overlay node from ned
00082     cModule* node = moduleType->create("overlayTerminal", parentModule());
00083 
00084     node->par("overlayType").setStringValue(parentModule()->par("overlayType"));
00085     node->par("tier1Type").setStringValue(parentModule()->
00086                                                par("tier1Type"));
00087     node->par("tier2Type").setStringValue(parentModule()->
00088                                                par("tier2Type"));
00089     node->par("tier3Type").setStringValue(parentModule()->
00090                                                par("tier3Type"));
00091 
00092     node->setDisplayString("i=device/wifilaptop_l;i2=block/circle_s");
00093     node->buildInside();
00094     node->scheduleStart(simulation.simTime());
00095 
00096     for (int i = 0; i < MAX_STAGE_UNDERLAY + 1; i++) {
00097         node->callInitialize(i);
00098     }
00099 
00100     // FIXME use only IPv4?
00101     IPvXAddress addr = IPAddress(nextFreeAddress++);
00102 
00103     SimpleNodeEntry entry(node, findChannelType(channelTypes[
00104                             intuniform(0, channelTypes.size() - 1)].c_str()));
00105 
00106     routingHashMap->insertNode(addr, entry);
00107     SimpleUDP* simple = check_and_cast<SimpleUDP*>(node->submodule("udp"));
00108     simple->setNodeEntry(entry);
00109 
00110     // Add pseudo-Interface to node's interfaceTable
00111     IPv4InterfaceData* ifdata = new IPv4InterfaceData;
00112     ifdata->setInetAddress(addr.get4());
00113     ifdata->setNetmask(IPAddress("255.255.255.255"));
00114     InterfaceEntry* e = new InterfaceEntry;
00115     e->setName("dummy interface");
00116     e->setIPv4Data(ifdata);
00117 
00118     IPAddressResolver().interfaceTableOf(node)->addInterface(e, NULL);
00119 
00120     // append index to module name
00121     char buf[80];
00122     sprintf(buf, "overlayTerminal[%i]", numCreated);
00123     node->setName(buf);
00124 
00125     // if the node was not created during startup we have to
00126     // finish the initialization process manually
00127     if ( !initialize) {
00128         for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) {
00129             node->callInitialize(i);
00130         }
00131     }
00132 
00133     //show ip... todo: migrate
00134     /*
00135     if (ev.isGUI()) {
00136     node->displayString().insertTag("t", 0);
00137     node->displayString().setTagArg("t", 0, addr.str().c_str());
00138     node->displayString().setTagArg("t", 1, "l");
00139     }
00140     */
00141 
00142     overlayTerminalCount++;
00143     numCreated++;
00144 
00145     return node->id();
00146 }

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

Cleans up configurator.

Implements UnderlayConfigurator.

00230 {
00231     // statistics
00232     recordScalar("Terminals added", numCreated);
00233     recordScalar("Terminals removed", numKilled);
00234 
00235     struct timeval now, diff;
00236     gettimeofday(&now, NULL);
00237     timersub(&now, &initFinishedTime, &diff);
00238     printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
00239 }

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

Init method for derived underlay configurators.

Implements UnderlayConfigurator.

00039 {
00040     if(stage != MAX_STAGE_UNDERLAY)
00041         return;
00042 
00043     // fetch some parameters
00044     routingHashMap = GlobalRoutingHashMapAccess().get();
00045     moduleType = findModuleType(par("overlayTerminalType"));
00046 
00047     // set maximum coordinates and send queue length
00048     SimpleNodeEntry::setFieldSize(par("fieldSize"));
00049     SimpleNodeEntry::setSendQueueLength(par("sendQueueLength"));
00050 
00051     // FIXME get address from parameter
00052     nextFreeAddress = 0x1000001;
00053 
00054     // flag indicating simulation initialization phase (true)
00055     // vs. normal mode (false)
00056     init = true;
00057 
00058     // count the overlay clients
00059     overlayTerminalCount = 0;
00060     numCreated = 0;
00061     numKilled = 0;
00062 
00063     // add the overlay nodes
00064     firstNodeId = createRandomNode(true);
00065     for (int i = 1; i < initialOverlayTerminalNum; i++) {
00066         createRandomNode(true);
00067     }
00068 
00069     // update display
00070     setDisplayString();
00071 
00072     // initialize simulation
00073     if (par("simulateMobility")) {
00074         cMessage* msg = new cMessage();
00075         scheduleAt(simulation.simTime(), msg);
00076     }
00077 }

void SimpleNetConfigurator::killRandomNode (  )  [private, virtual]

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

Implements UnderlayConfigurator.

00150 {
00151     // FIXME: better way to do this?
00152     // getEntry is inefficient!
00153     const GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry(
00154                 intuniform( 0, routingHashMap->size() -1 ));
00155     cGate* gate = e.second.getGate();
00156 
00157     cModule* node = gate->ownerModule()->parentModule();
00158 
00159     if(keepFirstNode && (node->id() == firstNodeId))
00160       return;
00161 
00162     InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)->
00163                          interfaceByName("dummy interface");
00164 
00165     delete ie->ipv4();
00166 
00167     node->callFinish();
00168     node->deleteModule();
00169     routingHashMap->removeNode( e.first );
00170 
00171     overlayTerminalCount--;
00172     numKilled++;
00173 }

void SimpleNetConfigurator::migrateRandomNode (  )  [private, virtual]

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

Implements UnderlayConfigurator.

00176 {
00177     GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry(
00178                                              intuniform(0, routingHashMap->size() -1));
00179 
00180     cGate* gate = e.second.getGate();
00181     cModule* node = gate->ownerModule()->parentModule();
00182 
00183     if(keepFirstNode && (node->id() == firstNodeId))
00184       return;
00185 
00186     routingHashMap->removeNode(e.first);
00187 
00188     node->bubble("I am migrating!");
00189 
00190     // FIXME use only IPv4?
00191     IPvXAddress addr = IPAddress(nextFreeAddress++);
00192 
00193     SimpleNodeEntry entry(node, findChannelType(channelTypes[intuniform(
00194                                    0, channelTypes.size() - 1)].c_str()));
00195 
00196     routingHashMap->insertNode(addr, entry);
00197     SimpleUDP* simple = check_and_cast<SimpleUDP*>(gate->ownerModule());
00198     simple->setNodeEntry(entry);
00199 
00200     InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)->
00201                          interfaceByName("dummy interface");
00202 
00203     delete ie->ipv4();
00204 
00205     // Add pseudo-Interface to node's interfaceTable
00206     IPv4InterfaceData* ifdata = new IPv4InterfaceData;
00207     ifdata->setInetAddress(addr.get4());
00208     ifdata->setNetmask(IPAddress("255.255.255.255"));
00209     ie->setIPv4Data(ifdata);
00210 
00211     // inform the notofication board about the migration
00212     NotificationBoard* nb = check_and_cast<NotificationBoard*>
00213                             (node->submodule("notificationBoard"));
00214     nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED);
00215 }

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

Sets display string.

Implements UnderlayConfigurator.

00219 {
00220     //
00221     // Updates the statistics display string.
00222     //
00223 
00224     char buf[80];
00225     sprintf(buf, "%i overlay clients", overlayTerminalCount);
00226     displayString().setTagArg("t", 0, buf);
00227 }


Member Data Documentation

cModuleType* SimpleNetConfigurator::moduleType [protected]

uint32 SimpleNetConfigurator::nextFreeAddress [protected]

int SimpleNetConfigurator::numCreated [protected]

int SimpleNetConfigurator::numKilled [protected]

GlobalRoutingHashMap* SimpleNetConfigurator::routingHashMap [protected]

uint SimpleNetConfigurator::sendQueueLength [protected]

send queue length of overlay terminals


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7