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     cChannelType* chan = findChannelType(channelTypes[
00104                             intuniform(0, channelTypes.size() - 1)].c_str());
00105     if (!chan) opp_error("Could not find Channel Type. Most likely parameter "
00106                     "channelTypes does not match the channels defined in "
00107                     "channels.ned");
00108     SimpleNodeEntry entry(node, chan);
00109 
00110     routingHashMap->insertNode(addr, entry);
00111     SimpleUDP* simple = check_and_cast<SimpleUDP*>(node->submodule("udp"));
00112     simple->setNodeEntry(entry);
00113 
00114     // Add pseudo-Interface to node's interfaceTable
00115     IPv4InterfaceData* ifdata = new IPv4InterfaceData;
00116     ifdata->setInetAddress(addr.get4());
00117     ifdata->setNetmask(IPAddress("255.255.255.255"));
00118     InterfaceEntry* e = new InterfaceEntry;
00119     e->setName("dummy interface");
00120     e->setIPv4Data(ifdata);
00121 
00122     IPAddressResolver().interfaceTableOf(node)->addInterface(e, NULL);
00123 
00124     // append index to module name
00125     char buf[80];
00126     sprintf(buf, "overlayTerminal[%i]", numCreated);
00127     node->setName(buf);
00128 
00129     //add node to bootstrap oracle
00130     //TransportAddress* peer = new TransportAddress(addr);
00131     PeerInfo* info = new PeerInfo(node->submodule("overlay")->id());
00132     //bootstrapOracle->addPeer(peer, info);
00133     bootstrapOracle->addPeer(addr, info);
00134 
00135     // if the node was not created during startup we have to
00136     // finish the initialization process manually
00137     if ( !initialize) {
00138         for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) {
00139             node->callInitialize(i);
00140         }
00141     }
00142 
00143     //show ip... todo: migrate
00144     /*
00145     if (ev.isGUI()) {
00146     node->displayString().insertTag("t", 0);
00147     node->displayString().setTagArg("t", 0, addr.str().c_str());
00148     node->displayString().setTagArg("t", 1, "l");
00149     }
00150     */
00151 
00152     overlayTerminalCount++;
00153     numCreated++;
00154 
00155     return node->id();
00156 }

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

Cleans up configurator.

Implements UnderlayConfigurator.

00252 {
00253     // statistics
00254     recordScalar("Terminals added", numCreated);
00255     recordScalar("Terminals removed", numKilled);
00256 
00257     struct timeval now, diff;
00258     gettimeofday(&now, NULL);
00259     timersub(&now, &initFinishedTime, &diff);
00260     printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
00261 }

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.

00160 {
00161     // FIXME: better way to do this?
00162     // getEntry is inefficient!
00163     const GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry(
00164                 intuniform( 0, routingHashMap->size() -1 ));
00165     cGate* gate = e.second.getGate();
00166 
00167     cModule* node = gate->ownerModule()->parentModule();
00168 
00169     if(keepFirstNode && (node->id() == firstNodeId))
00170       return;
00171 
00172     //remove node from bootstrap oracle
00173     bootstrapOracle->killPeer(IPAddressResolver().addressOf(node).get4());
00174 
00175     InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)->
00176                          interfaceByName("dummy interface");
00177 
00178     delete ie->ipv4();
00179 
00180     node->callFinish();
00181     node->deleteModule();
00182     routingHashMap->removeNode( e.first );
00183 
00184     overlayTerminalCount--;
00185     numKilled++;
00186 }

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

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

Implements UnderlayConfigurator.

00189 {
00190     GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry(
00191                                              intuniform(0, routingHashMap->size() -1));
00192 
00193     cGate* gate = e.second.getGate();
00194     cModule* node = gate->ownerModule()->parentModule();
00195 
00196     if(keepFirstNode && (node->id() == firstNodeId))
00197       return;
00198 
00199     //remove node from bootstrap oracle
00200     bootstrapOracle->killPeer(IPAddressResolver().addressOf(node).get4());
00201 
00202     routingHashMap->removeNode(e.first);
00203 
00204     node->bubble("I am migrating!");
00205 
00206     // FIXME use only IPv4?
00207     IPvXAddress addr = IPAddress(nextFreeAddress++);
00208 
00209     SimpleNodeEntry entry(node, findChannelType(channelTypes[intuniform(
00210                                    0, channelTypes.size() - 1)].c_str()));
00211 
00212     routingHashMap->insertNode(addr, entry);
00213     SimpleUDP* simple = check_and_cast<SimpleUDP*>(gate->ownerModule());
00214     simple->setNodeEntry(entry);
00215 
00216     InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)->
00217                          interfaceByName("dummy interface");
00218 
00219     delete ie->ipv4();
00220 
00221     // Add pseudo-Interface to node's interfaceTable
00222     IPv4InterfaceData* ifdata = new IPv4InterfaceData;
00223     ifdata->setInetAddress(addr.get4());
00224     ifdata->setNetmask(IPAddress("255.255.255.255"));
00225     ie->setIPv4Data(ifdata);
00226 
00227     //add new node to bootstrap oracle
00228     //TransportAddress* peer = new TransportAddress(addr);
00229     PeerInfo* info = new PeerInfo(node->submodule("overlay")->id());
00230     //bootstrapOracle->addPeer(peer, info);
00231     bootstrapOracle->addPeer(addr, info);
00232 
00233     // inform the notofication board about the migration
00234     NotificationBoard* nb = check_and_cast<NotificationBoard*>
00235                             (node->submodule("notificationBoard"));
00236     nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED);
00237 }

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

Sets display string.

Implements UnderlayConfigurator.

00241 {
00242     //
00243     // Updates the statistics display string.
00244     //
00245 
00246     char buf[80];
00247     sprintf(buf, "%i overlay clients", overlayTerminalCount);
00248     displayString().setTagArg("t", 0, buf);
00249 }


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 Fri May 11 14:52:40 2007 for ITM OverSim by  doxygen 1.4.7