#include <SimpleNetConfigurator.h>
Inheritance diagram for SimpleNetConfigurator:
Adds overlay nodes to the network in init phase and adds/removes/migrates overlay nodes after init phase.
Public Member Functions | |
virtual TransportAddress * | createNode (NodeType type, bool initialize=false) |
Creates an overlay node. | |
virtual void | preKillNode (NodeType type, TransportAddress *addr=NULL) |
Notifies and schedules overlay nodes for removal. | |
virtual void | migrateNode (NodeType type, TransportAddress *addr=NULL) |
Migrates overlay nodes from one access net to another. | |
Protected Member Functions | |
void | initializeUnderlay (int stage) |
Enables access to the globalHashMap, sets some parameters and adds the initial number of nodes to the network. | |
void | handleTimerEvent (cMessage *msg) |
void | finishUnderlay () |
Saves statistics, prints simulation time. | |
void | setDisplayString () |
Prints statistics. | |
Protected Attributes | |
uint32 | nextFreeAddress |
adress of the node that will be created next | |
cModuleType * | moduleType |
type of overlay terminals | |
std::deque< IPvXAddress > | killList |
stores nodes scheduled to be killed | |
std::set< int > | scheduledID |
stores nodeIds to prevent migration of prekilled nodes | |
uint | sendQueueLength |
send queue length of overlay terminals | |
int | numCreated |
number of overall created overlay terminals | |
int | numKilled |
number of overall killed overlay terminals |
TransportAddress * SimpleNetConfigurator::createNode | ( | NodeType | type, | |
bool | initialize = false | |||
) | [virtual] |
Creates an overlay node.
initialize |
Implements UnderlayConfigurator.
00063 { 00064 Enter_Method_Silent(); 00065 // derive overlay node from ned 00066 cModule* node = moduleType->create("overlayTerminal", parentModule()); 00067 00068 node->par("overlayType").setStringValue(type.overlayType.c_str()); 00069 node->par("tier1Type").setStringValue(type.tier1Type.c_str()); 00070 node->par("tier2Type").setStringValue(type.tier2Type.c_str()); 00071 node->par("tier3Type").setStringValue(type.tier3Type.c_str()); 00072 00073 node->setDisplayString("i=device/wifilaptop_l;i2=block/circle_s"); 00074 node->buildInside(); 00075 node->scheduleStart(simulation.simTime()); 00076 00077 for (int i = 0; i < MAX_STAGE_UNDERLAY + 1; i++) { 00078 node->callInitialize(i); 00079 } 00080 00081 // FIXME use only IPv4? 00082 IPvXAddress addr = IPAddress(nextFreeAddress++); 00083 00084 cChannelType* chan = findChannelType(type.channelTypes[ 00085 intuniform(0, type.channelTypes.size() - 1)].c_str()); 00086 if (!chan) opp_error("Could not find Channel Type. Most likely parameter " 00087 "channelTypes does not match the channels defined in " 00088 "channels.ned"); 00089 SimpleNodeEntry* entry = new SimpleNodeEntry(node, chan); 00090 node->gate("out",0)->setChannel(chan->create("outChan")); 00091 00092 SimpleUDP* simple = check_and_cast<SimpleUDP*>(node->submodule("udp")); 00093 simple->setNodeEntry(*entry); 00094 00095 // Add pseudo-Interface to node's interfaceTable 00096 IPv4InterfaceData* ifdata = new IPv4InterfaceData; 00097 ifdata->setInetAddress(addr.get4()); 00098 ifdata->setNetmask(IPAddress("255.255.255.255")); 00099 InterfaceEntry* e = new InterfaceEntry; 00100 e->setName("dummy interface"); 00101 e->setIPv4Data(ifdata); 00102 00103 IPAddressResolver().interfaceTableOf(node)->addInterface(e, NULL); 00104 00105 // create meta information 00106 SimpleInfo* info = new SimpleInfo(type.typeID, node->submodule("overlay")->id()); 00107 info->setEntry(entry); 00108 00109 // append index to module name 00110 char buf[80]; 00111 sprintf(buf, "overlayTerminal[%i]", numCreated); 00112 node->setName(buf); 00113 00114 //add node to bootstrap oracle 00115 bootstrapOracle->addPeer(addr, info); 00116 00117 // if the node was not created during startup we have to 00118 // finish the initialization process manually 00119 if ( !initialize) { 00120 for (int i = MAX_STAGE_UNDERLAY + 1; i < NUM_STAGES_ALL; i++) { 00121 node->callInitialize(i); 00122 } 00123 } 00124 00125 //show ip... todo: migrate 00126 /* 00127 if (ev.isGUI()) { 00128 node->displayString().insertTag("t", 0); 00129 node->displayString().setTagArg("t", 0, addr.str().c_str()); 00130 node->displayString().setTagArg("t", 1, "l"); 00131 } 00132 */ 00133 00134 overlayTerminalCount++; 00135 numCreated++; 00136 00137 churnGenerator[type.typeID - 1]->terminalCount++; 00138 00139 TransportAddress *address = new TransportAddress(addr); 00140 00141 // update display 00142 setDisplayString(); 00143 00144 return address; 00145 }
void SimpleNetConfigurator::preKillNode | ( | NodeType | type, | |
TransportAddress * | addr = NULL | |||
) | [virtual] |
Notifies and schedules overlay nodes for removal.
addr | NULL for random node |
Implements UnderlayConfigurator.
00148 { 00149 Enter_Method_Silent(); 00150 00151 SimpleNodeEntry* entry; 00152 SimpleInfo* info; 00153 00154 if(addr != NULL) { 00155 info = dynamic_cast<SimpleInfo*>(bootstrapOracle->getPeerInfo(*addr)); 00156 if(info != NULL) { 00157 entry = info->getEntry(); 00158 } 00159 else 00160 opp_error("SimpleNetConfigurator: Trying to pre kill node with nonexistant TransportAddress!"); 00161 } 00162 else { 00163 info = dynamic_cast<SimpleInfo*>(bootstrapOracle->getRandomPeerInfo(type.typeID)); 00164 entry = info->getEntry(); 00165 } 00166 00167 uint32_t effectiveType = info->getTypeID(); 00168 cGate* gate = entry->getGate(); 00169 00170 cModule* node = gate->ownerModule()->parentModule(); 00171 00172 if(keepFirstNode && (node->id() == firstNodeId)) 00173 return; 00174 00175 if(scheduledID.count(node->id())) 00176 return; 00177 00178 //remove node from bootstrap oracle 00179 bootstrapOracle->removePeer(IPAddressResolver().addressOf(node)); 00180 00181 //put node into the kill list and schedule a message for final removal of the node 00182 killList.push_front(IPAddressResolver().addressOf(node)); 00183 scheduledID.insert(node->id()); 00184 00185 overlayTerminalCount--; 00186 numKilled++; 00187 00188 churnGenerator[effectiveType - 1]->terminalCount--; 00189 00190 // update display 00191 setDisplayString(); 00192 00193 // inform the notofication board about the removal 00194 double random = uniform(0, 1); 00195 if(random < gracefullLeavePropability) { 00196 NotificationBoard* nb = check_and_cast<NotificationBoard*>(node->submodule("notificationBoard")); 00197 nb->fireChangeNotification(NF_OVERLAY_NODE_LEAVE); 00198 cMessage* msg = new cMessage(); 00199 scheduleAt(simulation.simTime() + gracefullLeaveDelay, msg); 00200 } 00201 else { 00202 cMessage* msg = new cMessage(); 00203 scheduleAt(simulation.simTime(), msg); 00204 } 00205 }
void SimpleNetConfigurator::migrateNode | ( | NodeType | type, | |
TransportAddress * | addr = NULL | |||
) | [virtual] |
Migrates overlay nodes from one access net to another.
addr | NULL for random node |
Implements UnderlayConfigurator.
00208 { 00209 Enter_Method_Silent(); 00210 00211 SimpleNodeEntry* entry; 00212 00213 if(addr != NULL) { 00214 SimpleInfo* info = dynamic_cast<SimpleInfo*>(bootstrapOracle->getPeerInfo(*addr)); 00215 if(info != NULL) { 00216 entry = info->getEntry(); 00217 } 00218 else 00219 opp_error("SimpleNetConfigurator: Trying to migrate node with nonexistant TransportAddress!"); 00220 } 00221 else { 00222 SimpleInfo* info = dynamic_cast<SimpleInfo*>(bootstrapOracle->getRandomPeerInfo(type.typeID)); 00223 entry = info->getEntry(); 00224 } 00225 00226 cGate* gate = entry->getGate(); 00227 cModule* node = gate->ownerModule()->parentModule(); 00228 00229 if(keepFirstNode && (node->id() == firstNodeId)) 00230 return; 00231 00232 // do not migrate node that is already scheduled 00233 if(scheduledID.count(node->id())) 00234 return; 00235 00236 //remove node from bootstrap oracle 00237 bootstrapOracle->killPeer(IPAddressResolver().addressOf(node)); 00238 00239 node->bubble("I am migrating!"); 00240 00241 // FIXME use only IPv4? 00242 IPvXAddress address = IPAddress(nextFreeAddress++); 00243 00244 SimpleNodeEntry* newentry = new SimpleNodeEntry(node, findChannelType(channelTypes[intuniform( 00245 0, channelTypes.size() - 1)].c_str())); 00246 00247 SimpleUDP* simple = check_and_cast<SimpleUDP*>(gate->ownerModule()); 00248 simple->setNodeEntry(*newentry); 00249 00250 InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)-> 00251 interfaceByName("dummy interface"); 00252 00253 delete ie->ipv4(); 00254 00255 // Add pseudo-Interface to node's interfaceTable 00256 IPv4InterfaceData* ifdata = new IPv4InterfaceData; 00257 ifdata->setInetAddress(address.get4()); 00258 ifdata->setNetmask(IPAddress("255.255.255.255")); 00259 ie->setIPv4Data(ifdata); 00260 00261 // create meta information 00262 SimpleInfo* newinfo = new SimpleInfo(type.typeID, node->submodule("overlay")->id()); 00263 newinfo->setEntry(newentry); 00264 00265 //add node to bootstrap oracle 00266 bootstrapOracle->addPeer(address, newinfo); 00267 00268 // inform the notofication board about the migration 00269 NotificationBoard* nb = check_and_cast<NotificationBoard*> 00270 (node->submodule("notificationBoard")); 00271 nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED); 00272 }
void SimpleNetConfigurator::initializeUnderlay | ( | int | stage | ) | [protected, virtual] |
Enables access to the globalHashMap, sets some parameters and adds the initial number of nodes to the network.
stage | the phase of the initialisation |
Implements UnderlayConfigurator.
00038 { 00039 if(stage != MAX_STAGE_UNDERLAY) 00040 return; 00041 00042 // fetch some parameters 00043 moduleType = findModuleType(par("overlayTerminalType")); 00044 00045 // set maximum coordinates and send queue length 00046 SimpleNodeEntry::setFieldSize(par("fieldSize")); 00047 SimpleNodeEntry::setSendQueueLength(par("sendQueueLength")); 00048 00049 // FIXME get address from parameter 00050 nextFreeAddress = 0x1000001; 00051 00052 // count the overlay clients 00053 overlayTerminalCount = 0; 00054 // Now done in base class churnGenerator->setOverlayTerminalCount(overlayTerminalCount); 00055 00056 numCreated = 0; 00057 numKilled = 0; 00058 00059 //Now done in base class churnGenerator->initializeChurn(); 00060 }
void SimpleNetConfigurator::handleTimerEvent | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from UnderlayConfigurator.
00275 { 00276 Enter_Method_Silent(); 00277 00278 // get next scheduled node and remove it from the kill list 00279 IPvXAddress addr = killList.back(); 00280 killList.pop_back(); 00281 00282 SimpleNodeEntry* entry = NULL; 00283 00284 SimpleInfo* info = dynamic_cast<SimpleInfo*>(bootstrapOracle->getPeerInfo(addr)); 00285 if(info != NULL) { 00286 entry = info->getEntry(); 00287 } 00288 else 00289 opp_error("SimpleNetConfigurator: Trying to kill node with nonexistant TransportAddress!"); 00290 00291 cGate* gate = entry->getGate(); 00292 cModule* node = gate->ownerModule()->parentModule(); 00293 00294 scheduledID.erase(node->id()); 00295 bootstrapOracle->killPeer(addr); 00296 00297 InterfaceEntry* ie = IPAddressResolver().interfaceTableOf(node)-> 00298 interfaceByName("dummy interface"); 00299 delete ie->ipv4(); 00300 00301 node->callFinish(); 00302 node->deleteModule(); 00303 00304 delete msg; 00305 }
void SimpleNetConfigurator::finishUnderlay | ( | ) | [protected, virtual] |
Saves statistics, prints simulation time.
Reimplemented from UnderlayConfigurator.
00318 { 00319 // statistics 00320 recordScalar("Terminals added", numCreated); 00321 recordScalar("Terminals removed", numKilled); 00322 00323 struct timeval now, diff; 00324 gettimeofday(&now, NULL); 00325 timersub(&now, &initFinishedTime, &diff); 00326 printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec); 00327 }
void SimpleNetConfigurator::setDisplayString | ( | ) | [protected, virtual] |
Prints statistics.
Implements UnderlayConfigurator.
00308 { 00309 // 00310 // Updates the statistics display string. 00311 // 00312 char buf[80]; 00313 sprintf(buf, "%i overlay clients", overlayTerminalCount); 00314 displayString().setTagArg("t", 0, buf); 00315 }
uint32 SimpleNetConfigurator::nextFreeAddress [protected] |
adress of the node that will be created next
cModuleType* SimpleNetConfigurator::moduleType [protected] |
type of overlay terminals
std::deque<IPvXAddress> SimpleNetConfigurator::killList [protected] |
stores nodes scheduled to be killed
std::set<int> SimpleNetConfigurator::scheduledID [protected] |
stores nodeIds to prevent migration of prekilled nodes
uint SimpleNetConfigurator::sendQueueLength [protected] |
send queue length of overlay terminals
int SimpleNetConfigurator::numCreated [protected] |
number of overall created overlay terminals
int SimpleNetConfigurator::numKilled [protected] |
number of overall killed overlay terminals