54 EV_INFO <<
"host auto configuration started" << std::endl;
56 std::string interfaces = par(
"interfaces").stringValue();
57 IPv4Address addressBase = IPv4Address(par(
"addressBase").
stringValue());
58 IPv4Address netmask = IPv4Address(par(
"netmask").
stringValue());
59 std::string mcastGroups = par(
"mcastGroups").stringValue();
64 IPv4Address myAddress = IPv4Address(addressBase.getInt() +
uint32(host->getId()));
68 throw cRuntimeError(
"Generated IP address is out of specified address range");
71 IIPv4RoutingTable *routingTable = L3AddressResolver().routingTableOf(host);
73 throw cRuntimeError(
"No routing table found");
76 IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(host);
78 throw cRuntimeError(
"No interface table found");
81 cStringTokenizer interfaceTokenizer(interfaces.c_str());
83 while ((ifname = interfaceTokenizer.nextToken()) !=
nullptr) {
84 InterfaceEntry *ie = ift->getInterfaceByName(ifname);
86 throw cRuntimeError(
"No such interface '%s'", ifname);
89 if (ie->isLoopback()) {
90 EV_INFO <<
"interface " << ifname <<
" skipped (is loopback)" << std::endl;
94 EV_INFO <<
"interface " << ifname <<
" gets " << myAddress.str() <<
"/" << netmask.str() << std::endl;
96 ie->ipv4Data()->setIPAddress(myAddress);
97 ie->ipv4Data()->setNetmask(netmask);
98 ie->setBroadcast(
true);
105 cStringTokenizer interfaceTokenizer(mcastGroups.c_str());
106 const char *mcastGroup_s;
107 while ((mcastGroup_s = interfaceTokenizer.nextToken()) !=
nullptr) {
108 IPv4Address mcastGroup(mcastGroup_s);
109 ie->ipv4Data()->joinMulticastGroup(mcastGroup);
static bool maskedAddrAreEqual(const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: IPv4Address.cc:260
static const IPv4Address ALL_HOSTS_MCAST
224.0.0.1 All hosts on a subnet
Definition: IPv4Address.h:107
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
uint32_t uint32
Definition: Compat.h:30
#define stringValue()
Definition: NedFunctions.cc:24
static const IPv4Address ALL_ROUTERS_MCAST
224.0.0.2 All routers on a subnet
Definition: IPv4Address.h:108