#include <SimpleNetConfigurator.h>
Inheritance diagram for SimpleNetConfigurator:
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 | |
GlobalRoutingHashMap * | routingHashMap |
uint32 | nextFreeAddress |
cModuleType * | moduleType |
uint | sendQueueLength |
send queue length of overlay terminals | |
int | numCreated |
int | numKilled |
Private Member Functions | |
void | 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. |
void SimpleNetConfigurator::createRandomNode | ( | bool | initialize | ) | [private, virtual] |
creates an overlay node
Implements UnderlayConfigurator.
00079 { 00080 // derive overlay node from ned 00081 cModule* node = moduleType->create("overlayTerminal", parentModule()); 00082 00083 node->par("overlayType").setStringValue(parentModule()->par("overlayType")); 00084 node->par("overlayAppType").setStringValue(parentModule()-> 00085 par("overlayAppType")); 00086 00087 node->setDisplayString("i=device/wifilaptop_l;i2=block/circle_s"); 00088 node->buildInside(); 00089 node->scheduleStart(simulation.simTime()); 00090 00091 for (int i = 0; i < MAX_STAGE_UNDERLAY + 1; i++) { 00092 node->callInitialize(i); 00093 } 00094 00095 // FIXME use only IPv4? 00096 IPvXAddress addr = IPAddress(nextFreeAddress++); 00097 00098 SimpleNodeEntry entry(node, findChannelType(channelTypes[ 00099 intuniform(0, channelTypes.size() - 1)].c_str())); 00100 00101 routingHashMap->insertNode(addr, entry); 00102 SimpleUDP* simple = check_and_cast<SimpleUDP*>(node->submodule("udp")); 00103 simple->setNodeEntry(entry); 00104 00105 // Add pseudo-Interface to node's interfaceTable 00106 IPv4InterfaceData* ifdata = new IPv4InterfaceData; 00107 ifdata->setInetAddress(addr.get4()); 00108 ifdata->setNetmask(IPAddress("255.255.255.255")); 00109 InterfaceEntry* e = new InterfaceEntry; 00110 e->setName("dummy interface"); 00111 e->setIPv4Data(ifdata); 00112 00113 IPAddressResolver().interfaceTableOf(node)->addInterface(e, NULL); 00114 00115 // append index to module name 00116 char buf[80]; 00117 sprintf(buf, "overlayTerminal[%i]", numCreated); 00118 node->setName(buf); 00119 00120 // if the node was not created during startup we have to 00121 // finish the initialization process manually 00122 if ( !initialize) { 00123 for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) { 00124 node->callInitialize(i); 00125 } 00126 } 00127 00128 //show ip... todo: migrate 00129 /* 00130 if (ev.isGUI()) { 00131 node->displayString().insertTag("t", 0); 00132 node->displayString().setTagArg("t", 0, addr.str().c_str()); 00133 node->displayString().setTagArg("t", 1, "l"); 00134 } 00135 */ 00136 00137 overlayTerminalCount++; 00138 numCreated++; 00139 }
void SimpleNetConfigurator::finish | ( | ) | [protected, virtual] |
Cleans up configurator.
Implements UnderlayConfigurator.
00215 { 00216 // statistics 00217 recordScalar("Terminals added", numCreated); 00218 recordScalar("Terminals removed", numKilled); 00219 00220 struct timeval now, diff; 00221 gettimeofday(&now, NULL); 00222 timersub(&now, &initFinishedTime, &diff); 00223 printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec); 00224 }
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 for (int i = 0; i < initialOverlayTerminalNum; i++) { 00065 createRandomNode(true); 00066 } 00067 00068 // update display 00069 setDisplayString(); 00070 00071 // initialize simulation 00072 if (par("simulateMobility")) { 00073 cMessage* msg = new cMessage(); 00074 scheduleAt(simulation.simTime(), msg); 00075 } 00076 }
void SimpleNetConfigurator::killRandomNode | ( | ) | [private, virtual] |
Removes randomly chosen overlay nodes from a randomly chosen access net.
Implements UnderlayConfigurator.
00142 { 00143 // FIXME: better way to do this? 00144 // getEntry is inefficient! 00145 const GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry( 00146 intuniform( 0, routingHashMap->size() -1 )); 00147 cGate* gate = e.second.getGate(); 00148 00149 cModule* node = gate->ownerModule()->parentModule(); 00150 00151 InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)-> 00152 interfaceByName("dummy interface"); 00153 00154 delete ie->ipv4(); 00155 00156 node->callFinish(); 00157 node->deleteModule(); 00158 routingHashMap->removeNode( e.first ); 00159 00160 overlayTerminalCount--; 00161 numKilled++; 00162 }
void SimpleNetConfigurator::migrateRandomNode | ( | ) | [private, virtual] |
Migrates randomly chosen overlay nodes from on access net to another.
Implements UnderlayConfigurator.
00165 { 00166 GlobalRoutingHashMap::RouteEntry e = routingHashMap->getEntry( 00167 intuniform(0, routingHashMap->size() -1)); 00168 00169 cGate* gate = e.second.getGate(); 00170 cModule* node = gate->ownerModule()->parentModule(); 00171 routingHashMap->removeNode(e.first); 00172 00173 node->bubble("I am migrating!"); 00174 00175 // FIXME use only IPv4? 00176 IPvXAddress addr = IPAddress(nextFreeAddress++); 00177 00178 SimpleNodeEntry entry(node, findChannelType(channelTypes[intuniform( 00179 0, channelTypes.size() - 1)].c_str())); 00180 00181 routingHashMap->insertNode(addr, entry); 00182 SimpleUDP* simple = check_and_cast<SimpleUDP*>(gate->ownerModule()); 00183 simple->setNodeEntry(entry); 00184 00185 InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)-> 00186 interfaceByName("dummy interface"); 00187 00188 delete ie->ipv4(); 00189 00190 // Add pseudo-Interface to node's interfaceTable 00191 IPv4InterfaceData* ifdata = new IPv4InterfaceData; 00192 ifdata->setInetAddress(addr.get4()); 00193 ifdata->setNetmask(IPAddress("255.255.255.255")); 00194 ie->setIPv4Data(ifdata); 00195 00196 // inform the notofication board about the migration 00197 NotificationBoard* nb = check_and_cast<NotificationBoard*> 00198 (node->submodule("notificationBoard")); 00199 nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED); 00200 }
void SimpleNetConfigurator::setDisplayString | ( | ) | [protected, virtual] |
Sets display string.
Implements UnderlayConfigurator.
00204 { 00205 // 00206 // Updates the statistics display string. 00207 // 00208 00209 char buf[80]; 00210 sprintf(buf, "%i overlay clients", overlayTerminalCount); 00211 displayString().setTagArg("t", 0, buf); 00212 }
cModuleType* SimpleNetConfigurator::moduleType [protected] |
uint32 SimpleNetConfigurator::nextFreeAddress [protected] |
int SimpleNetConfigurator::numCreated [protected] |
int SimpleNetConfigurator::numKilled [protected] |
uint SimpleNetConfigurator::sendQueueLength [protected] |
send queue length of overlay terminals