Configures Ipv4 addresses and routing tables for a "flat" network, "flat" meaning that all hosts and routers will have the same network address.
More...
#include <Ipv4FlatNetworkConfigurator.h>
Configures Ipv4 addresses and routing tables for a "flat" network, "flat" meaning that all hosts and routers will have the same network address.
For more info please see the NED file.
◆ NodeInfoVector
◆ addDefaultRoutes()
| void inet::Ipv4FlatNetworkConfigurator::addDefaultRoutes |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
105 for (
int i = 0; i < topo.getNumNodes(); i++) {
106 cTopology::Node *node = topo.getNode(i);
109 if (!nodeInfo[i].isIPNode)
112 IInterfaceTable *ift = nodeInfo[i].ift;
113 IIpv4RoutingTable *rt = nodeInfo[i].rt;
117 NetworkInterface *ie =
nullptr;
118 for (
int k = 0;
k < ift->getNumInterfaces();
k++)
119 if (!ift->getInterface(
k)->isLoopback()) {
120 ie = ift->getInterface(
k);
124 nodeInfo[i].usesDefaultRoute = (numIntf == 1);
128 EV_INFO <<
" " << node->getModule()->getFullName() <<
"=" << nodeInfo[i].address
129 <<
" has only one (non-loopback) interface, adding default route\n";
132 Ipv4Route *
e =
new Ipv4Route();
133 e->setDestination(Ipv4Address());
134 e->setNetmask(Ipv4Address());
Referenced by initialize().
◆ assignAddresses()
| void inet::Ipv4FlatNetworkConfigurator::assignAddresses |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
74 uint32_t networkAddress = Ipv4Address(par(
"networkAddress").stringValue()).getInt();
75 uint32_t netmask = Ipv4Address(par(
"netmask").stringValue()).getInt();
76 int maxNodes = (~netmask) - 1;
77 if (topo.getNumNodes() > maxNodes)
78 throw cRuntimeError(
"netmask too large, not enough addresses for all %d nodes", topo.getNumNodes());
81 for (
int i = 0; i < topo.getNumNodes(); i++) {
83 if (!nodeInfo[i].isIPNode)
86 uint32_t addr = networkAddress | uint32_t(++numIPNodes);
87 nodeInfo[i].address.set(addr);
90 IInterfaceTable *ift = nodeInfo[i].ift;
91 for (
int k = 0;
k < ift->getNumInterfaces();
k++) {
92 NetworkInterface *ie = ift->getInterface(
k);
93 if (!ie->isLoopback()) {
94 auto ipv4Data = ie->getProtocolDataForUpdate<Ipv4InterfaceData>();
95 ipv4Data->setIPAddress(Ipv4Address(addr));
Referenced by initialize().
◆ extractTopology()
| void inet::Ipv4FlatNetworkConfigurator::extractTopology |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
54 topo.extractByProperty(
"networkNode");
55 EV_DEBUG <<
"cTopology found " << topo.getNumNodes() <<
" nodes\n";
58 nodeInfo.resize(topo.getNumNodes());
59 for (
int i = 0; i < topo.getNumNodes(); i++) {
60 cModule *
mod = topo.getNode(i)->getModule();
61 nodeInfo[i].isIPNode = L3AddressResolver().findIpv4RoutingTableOf(
mod) !=
nullptr && L3AddressResolver().findInterfaceTableOf(
mod) !=
nullptr;
62 if (nodeInfo[i].isIPNode) {
63 nodeInfo[i].ift = L3AddressResolver().interfaceTableOf(
mod);
64 nodeInfo[i].rt = L3AddressResolver().getIpv4RoutingTableOf(
mod);
65 nodeInfo[i].ipForwardEnabled =
mod->hasPar(
"forwarding") ?
mod->par(
"forwarding") :
false;
66 topo.getNode(i)->setWeight(nodeInfo[i].ipForwardEnabled ? 0.0 :
INFINITY);
Referenced by initialize().
◆ fillRoutingTables()
| void inet::Ipv4FlatNetworkConfigurator::fillRoutingTables |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
145 for (
int i = 0; i < topo.getNumNodes(); i++) {
146 cTopology::Node *destNode = topo.getNode(i);
149 if (!nodeInfo[i].isIPNode)
152 Ipv4Address destAddr = nodeInfo[i].address;
153 std::string destModName = destNode->getModule()->getFullName();
156 topo.calculateWeightedSingleShortestPathsTo(destNode);
160 for (
int j = 0; j < topo.getNumNodes(); j++) {
163 if (!nodeInfo[j].isIPNode)
166 cTopology::Node *atNode = topo.getNode(j);
167 if (atNode->getNumPaths() == 0)
169 if (nodeInfo[j].usesDefaultRoute)
172 Ipv4Address atAddr = nodeInfo[j].address;
174 IInterfaceTable *ift = nodeInfo[j].ift;
176 int outputGateId = atNode->getPath(0)->getLocalGate()->getId();
177 NetworkInterface *ie = ift->findInterfaceByNodeOutputGateId(outputGateId);
179 throw cRuntimeError(
"%s has no interface for output gate id %d", ift->getFullPath().c_str(), outputGateId);
181 EV_INFO <<
" from " << atNode->getModule()->getFullName() <<
"=" << Ipv4Address(atAddr);
182 EV_INFO <<
" towards " << destModName <<
"=" << Ipv4Address(destAddr) <<
" interface " << ie->getInterfaceName() << endl;
185 IIpv4RoutingTable *rt = nodeInfo[j].rt;
186 Ipv4Route *
e =
new Ipv4Route();
187 e->setDestination(destAddr);
188 e->setNetmask(Ipv4Address(255, 255, 255, 255));
Referenced by initialize().
◆ handleMessage()
| void inet::Ipv4FlatNetworkConfigurator::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
199 throw cRuntimeError(
"this module doesn't handle messages, it runs only in initialize()");
◆ initialize()
| void inet::Ipv4FlatNetworkConfigurator::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
26 cSimpleModule::initialize(stage);
29 cTopology topo(
"topo");
◆ numInitStages()
| virtual int inet::Ipv4FlatNetworkConfigurator::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ setDisplayString()
| void inet::Ipv4FlatNetworkConfigurator::setDisplayString |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
205 for (
int i = 0; i < topo.getNumNodes(); i++)
206 if (nodeInfo[i].isIPNode)
211 sprintf(buf,
"%d Ipv4 nodes\n%d non-Ipv4 nodes", numIPNodes, topo.getNumNodes() - numIPNodes);
212 getDisplayString().setTagArg(
"t", 0, buf);
Referenced by initialize().
The documentation for this class was generated from the following files: