30 #include <IRoutingTable.h>
31 #include <RoutingTable6.h>
32 #include <IInterfaceTable.h>
33 #include <IPAddressResolver.h>
34 #include <IPv4InterfaceData.h>
35 #include <IPv6InterfaceData.h>
36 #include <NotificationBoard.h>
48 cTopology topo(
"topo");
49 topo.extractByProperty(
"node");
51 if (par(
"useIPv6Addresses").boolValue()) {
73 node = getParentModule()->getSubmodule(
"accessRouter", i);
78 node = getParentModule()->getSubmodule(
"overlayAccessRouter", i);
89 Enter_Method_Silent();
91 std::string nameStr =
"overlayTerminal";
93 nameStr +=
"-" + convertToString<uint32_t>(type.
typeID);
95 cModuleType* moduleType = cModuleType::get(type.
terminalType.c_str());
96 cModule* node = moduleType->create(nameStr.c_str(), getParentModule(),
100 throw cRuntimeError(
"InetUnderlayConfigurator::createNode(): Setting "
101 "channel types via the churn generator is not allowed "
102 "with the InetUnderlay. Use **.accessNet.channelTypes instead!");
105 node->setGateSize(
"pppg", 1);
107 std::string displayString;
110 ((displayString +=
"i=device/wifilaptop_l,")
112 +=
",40;i2=block/circle_s";
114 displayString =
"i=device/wifilaptop_l;i2=block/circle_s";
117 node->finalizeParameters();
118 node->setDisplayString(displayString.c_str());
121 node->scheduleStart(simTime());
127 ->getSubmodule(
"accessNet"));
139 node->callInitialize(i);
149 IPAddressResolver().addressOf(node));
160 Enter_Method_Silent();
172 std::cout <<
"all nodes are already prekilled" << std::endl;
184 opp_error(
"IPv4UnderlayConfigurator: Trying to pre kill node "
185 "with nonexistant TransportAddress!");
188 uint32_t effectiveType = info->
getTypeID();
198 killList.push_front(IPAddressResolver().addressOf(node));
210 NotificationBoard* nb = check_and_cast<NotificationBoard*>(
211 node->getSubmodule(
"notificationBoard"));
212 nb->fireChangeNotification(NF_OVERLAY_NODE_LEAVE);
214 double random = uniform(0, 1);
217 nb->fireChangeNotification(NF_OVERLAY_NODE_GRACEFUL_LEAVE);
220 cMessage* msg =
new cMessage();
227 Enter_Method_Silent();
245 opp_error(
"IPv4UnderlayConfigurator: Trying to pre kill node with nonexistant TransportAddress!");
255 opp_error(
"IPv4UnderlayConfigurator: Trying to remove node which is nonexistant in AccessNet!");
260 node->bubble(
"I am migrating!");
267 }
while((newAccessNetModule == accessNetModule) && (
accessNode.size() != 1));
279 NotificationBoard* nb = check_and_cast<NotificationBoard*>(node->getSubmodule(
"notificationBoard"));
280 nb->fireChangeNotification(NF_OVERLAY_TRANSPORTADDRESS_CHANGED);
285 Enter_Method_Silent();
299 opp_error(
"IPv4UnderlayConfigurator: Trying to kill node with nonexistant TransportAddress!");
308 opp_error(
"IPv4UnderlayConfigurator: Trying to remove node which is nonexistant in AccessNet!");
311 node->deleteModule();
319 sprintf(buf,
"%i overlay terminals\n%i access router\n%i overlay access router",
321 getDisplayString().setTagArg(
"t", 0, buf);
328 recordScalar(
"Terminals removed",
numKilled);
331 struct timeval now, diff;
332 gettimeofday(&now, NULL);
334 printf(
"Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
341 std::vector<uint32> nodeAddresses;
342 nodeAddresses.resize(topo.getNumNodes());
347 uint32 lowIPBoundary = IPAddress(par(
"startIPv4").stringValue()).getInt();
352 for (
int i = 0; i < topo.getNumNodes(); i++) {
355 uint32 addr = lowIPBoundary + uint32(numIPNodes << 16);
356 nodeAddresses[i] = addr;
360 topo.getNode(i)->getModule()->getDisplayString().insertTag(
"t", 0);
361 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 0,
362 const_cast<char*>(IPAddress(addr).str().c_str()));
363 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 1,
"l");
364 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 2,
"red");
368 IInterfaceTable* ift = IPAddressResolver().interfaceTableOf(topo.getNode(i)->getModule());
370 for (
int k = 0; k < ift->getNumInterfaces(); k++ ) {
371 InterfaceEntry* ie = ift->getInterface(k);
372 if (!ie->isLoopback()) {
373 ie->ipv4Data()->setIPAddress(IPAddress(addr));
375 ie->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);
381 for (
int i = 0; i < topo.getNumNodes(); i++) {
382 cTopology::Node* destNode = topo.getNode(i);
383 uint32 destAddr = nodeAddresses[i];
386 topo.calculateUnweightedSingleShortestPathsTo(destNode);
390 if ((strcmp(destNode->getModule()->getName(),
"overlayBackboneRouter") == 0) ||
391 (strcmp(destNode->getModule()->getName(),
"overlayAccessRouter") == 0)) {
401 if ( strcmp(destNode->getModule()->getName(),
"outRouter" ) == 0 ) {
402 IPRoute* defRoute =
new IPRoute();
403 defRoute->setHost(IPAddress::UNSPECIFIED_ADDRESS);
404 defRoute->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
405 defRoute->setGateway(IPAddress(par(
"gatewayIP").stringValue()));
406 defRoute->setInterface(IPAddressResolver().interfaceTableOf(destNode->getModule())->getInterfaceByName(
"tunDev"));
407 defRoute->setType(IPRoute::REMOTE);
408 defRoute->setSource(IPRoute::MANUAL);
409 IPAddressResolver().routingTableOf(destNode->getModule())->addRoute(defRoute);
411 IPRoute* gwRoute =
new IPRoute();
412 gwRoute->setHost(IPAddress(par(
"gatewayIP").stringValue()));
413 gwRoute->setNetmask(IPAddress(255, 255, 255, 255));
414 gwRoute->setInterface(IPAddressResolver().interfaceTableOf(destNode->getModule())->getInterfaceByName(
"tunDev"));
415 gwRoute->setType(IPRoute::DIRECT);
416 gwRoute->setSource(IPRoute::MANUAL);
417 IPAddressResolver().routingTableOf(destNode->getModule())->addRoute(gwRoute);
421 for (
int j = 0; j < topo.getNumNodes(); j++) {
427 cTopology::Node* atNode = topo.getNode(j);
429 if (atNode->getNumPaths() == 0) {
430 error((std::string(atNode->getModule()->getName()) +
": Network is not entirely connected."
431 "Please increase your value for the "
432 "connectivity parameter").c_str());
440 IInterfaceTable* ift = IPAddressResolver().interfaceTableOf(atNode->getModule());
441 IRoutingTable* rt = IPAddressResolver().routingTableOf(atNode->getModule());
444 int outputGateId = atNode->getPath(0)->getLocalGate()->getId();
445 InterfaceEntry *ie = ift->getInterfaceByNodeOutputGateId(outputGateId);
448 cModule* next_hop = atNode->getPath(0)->getRemoteNode()->getModule();
449 IPAddress next_hop_ip = IPAddressResolver().addressOf(next_hop).get4();
454 IPRoute*
re =
new IPRoute();
456 re->setHost(IPAddress(destAddr));
457 re->setInterface(ie);
458 re->setSource(IPRoute::MANUAL);
459 re->setNetmask(IPAddress(255, 255, 0, 0));
460 re->setGateway(IPAddress(next_hop_ip));
461 re->setType(IPRoute::REMOTE);
467 if (atNode->getDistanceToTarget() == 1) {
468 IPRoute* re2 =
new IPRoute();
470 re2->setHost(IPAddress(destAddr));
471 re2->setInterface(ie);
472 re2->setSource(IPRoute::MANUAL);
473 re2->setNetmask(IPAddress(255, 255, 255, 255));
474 re2->setType(IPRoute::DIRECT);
481 if (strcmp(destNode->getModule()->getName(),
"outRouter" ) == 0) {
482 IPRoute* defRoute =
new IPRoute();
483 defRoute->setHost(IPAddress::UNSPECIFIED_ADDRESS);
484 defRoute->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
485 defRoute->setGateway(IPAddress(next_hop_ip));
486 defRoute->setInterface(ie);
487 defRoute->setType(IPRoute::REMOTE);
488 defRoute->setSource(IPRoute::MANUAL);
490 rt->addRoute(defRoute);
499 std::vector<IPv6Words> nodeAddresses;
500 nodeAddresses.resize(topo.getNumNodes());
505 IPv6Words lowIPBoundary(IPv6Address(par(
"startIPv6").stringValue()));
510 for (
int i = 0; i < topo.getNumNodes(); i++) {
514 addr.
d0 += numIPNodes;
515 nodeAddresses[i] = addr;
519 topo.getNode(i)->getModule()->getDisplayString().insertTag(
"t", 0);
520 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 0,
521 const_cast<char*>(IPv6Address(addr.
d0, addr.
d1, addr.
d2, addr.
d3).str().c_str()));
522 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 1,
"l");
523 topo.getNode(i)->getModule()->getDisplayString().setTagArg(
"t", 2,
"red");
527 IInterfaceTable* ift = IPAddressResolver().interfaceTableOf(topo.getNode(i)->getModule());
529 for (
int k = 0; k < ift->getNumInterfaces(); k++ ) {
530 InterfaceEntry* ie = ift->getInterface(k);
531 if (!ie->isLoopback() && ie->ipv6Data()) {
534 IPv6Address prefix(addr.
d0, addr.
d1, addr.
d2, addr.
d3);
535 IPv6InterfaceData::AdvPrefix p;
538 p.advAutonomousFlag =
true;
539 p.advPreferredLifetime = 0;
540 p.advValidLifetime = 0;
541 p.advOnLinkFlag =
true;
542 ie->ipv6Data()->addAdvPrefix(p);
543 ie->setMACAddress(MACAddress::generateAutoAddress());
545 ie->ipv6Data()->assignAddress(prefix,
false, 0, 0);
547 if (ie->ipv6Data()->getLinkLocalAddress().isUnspecified()) {
548 ie->ipv6Data()->assignAddress(IPv6Address::formLinkLocalAddress(ie->getInterfaceToken()),
false, 0, 0);
555 for (
int i = 0; i < topo.getNumNodes(); i++) {
556 cTopology::Node* destNode = topo.getNode(i);
559 topo.calculateUnweightedSingleShortestPathsTo(destNode);
563 if ((strcmp(destNode->getModule()->getName(),
"overlayBackboneRouter") == 0) ||
564 (strcmp(destNode->getModule()->getName(),
"overlayAccessRouter") == 0)) {
567 globalNodeList->
addPeer(IPvXAddress(IPv6Address(nodeAddresses[i].d0, nodeAddresses[i].d1, nodeAddresses[i].d2, nodeAddresses[i].d3)), info);
571 for (
int j = 0; j < topo.getNumNodes(); j++) {
577 cTopology::Node* atNode = topo.getNode(j);
579 if (atNode->getNumPaths() == 0) {
580 error((std::string(atNode->getModule()->getName()) +
": Network is not entirely connected."
581 "Please increase your value for the "
582 "connectivity parameter").c_str());
590 IInterfaceTable* ift = IPAddressResolver().interfaceTableOf(atNode->getModule());
591 RoutingTable6* rt = IPAddressResolver().routingTable6Of(atNode->getModule());
594 int outputGateId = atNode->getPath(0)->getLocalGate()->getId();
595 InterfaceEntry *ie = ift->getInterfaceByNodeOutputGateId(outputGateId);
598 cModule* next_hop = atNode->getPath(0)->getRemoteNode()->getModule();
599 int destGateId = destNode->getLinkIn(0)->getLocalGateId();
600 IInterfaceTable* destIft = IPAddressResolver().interfaceTableOf(destNode->getModule());
601 int remoteGateId = atNode->getPath(0)->getRemoteGateId();
602 IInterfaceTable* remoteIft = IPAddressResolver().interfaceTableOf(next_hop);
603 IPv6Address next_hop_ip = remoteIft->getInterfaceByNodeInputGateId(remoteGateId)->ipv6Data()->getLinkLocalAddress();
604 IPv6InterfaceData::AdvPrefix destPrefix = destIft->getInterfaceByNodeInputGateId(destGateId)->ipv6Data()->getAdvPrefix(0);
607 rt->addStaticRoute(destPrefix.prefix, destPrefix.prefixLength, ie->getInterfaceId(), next_hop_ip);
623 double uniform2(
double start,
double end,
double index,
double new_calc)
625 static std::vector<double> value;
626 if ( (
unsigned int)index >= value.size() )
627 value.resize((
int)index + 1);
629 value[(int)index] = uniform(start, end);
630 return value[(int)index];
642 double intuniform2(
double start,
double end,
double index,
double new_calc)
644 static std::vector<double> value;
645 if ( (
unsigned int)index >= value.size() )
646 value.resize((
int)index + 1);
648 value[(int)index] = (
double)intuniform((
int)start, (
int)end);
649 return value[(int)index];