29 #include <platdep/sockets.h>
33 #include <sys/ioctl.h>
34 #include <arpa/inet.h>
35 #include <netinet/in.h>
40 #include "IInterfaceTable.h"
41 #include "InterfaceEntry.h"
42 #include "IPv4InterfaceData.h"
43 #include "IPAddressResolver.h"
46 #include <IRoutingTable.h>
64 cModule* node = getParentModule()->getSubmodule(
"overlayTerminal", 0);
66 std::string nodeInterface = std::string(par(
"nodeInterface").stringValue());
67 std::string stunServer = std::string(par(
"stunServer").stringValue());
68 std::string nodeIP = std::string(par(
"nodeIP").stringValue());
70 if (!nodeInterface.size() && !stunServer.size() && !nodeIP.size()) {
71 throw cRuntimeError(
"SingleHostConfigurator::initializeUnderlay(): "
72 "Please specify at least one of "
73 "**.nodeInterface, **.nodeIP, or **.stunServer");
76 if (nodeInterface.size()) {
80 if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) !=
83 snprintf(req.ifr_name,
sizeof(req.ifr_name),
"%s", nodeInterface.c_str());
85 if (!ioctl(sock_fd, SIOCGIFADDR, &req)) {
86 addr = IPAddress(inet_ntoa(((
struct sockaddr_in *)
87 (&req.ifr_addr))->sin_addr));
89 throw cRuntimeError(
"SingleHostConfigurator::"
90 "initializeUnderlay(): "
91 "Invalid interface!");
96 throw cRuntimeError(
"SingleHostConfigurator::"
97 "initializeUnderlay(): "
98 "**.nodeInterface parameter not supported on WIN32 yet!");
100 }
else if (nodeIP.size()) {
101 addr = IPAddress(nodeIP.c_str());
104 IPvXAddress gw = addr;
105 InterfaceEntry* ifEntry = IPAddressResolver().interfaceTableOf(node)->
106 getInterfaceByName(
"outDev");
107 IRoutingTable* rTable = check_and_cast<IRoutingTable*>(node->getSubmodule(
"routingTable", 0));
109 ifEntry->ipv4Data()->setIPAddress(addr.get4());
110 ifEntry->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);
112 IPRoute* te =
new IPRoute();
113 te->setHost(IPAddress::UNSPECIFIED_ADDRESS);
114 te->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
115 te->setGateway(gw.get4());
116 te->setInterface(ifEntry);
117 te->setType(IPRoute::REMOTE);
118 te->setSource(IPRoute::MANUAL);
119 rTable->addRoute(te);
125 if (strlen(par(
"bootstrapIP")) > 0) {
131 IPAddress(par(
"bootstrapIP").stringValue()), par(
"bootstrapPort")));
137 scheduleAt(simTime(),
new cMessage(
"init phase finished"));
141 if (std::string(msg->getName()) !=
"init phase finished") {
142 throw cRuntimeError(
"unknown self-message received");
154 getDisplayString().setTagArg(
"t", 0, buf);
160 struct timeval now, diff;
161 gettimeofday(&now, NULL);
163 printf(
"Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);