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 <FlatNetworkConfigurator.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.
void inet::FlatNetworkConfigurator::addDefaultRoutes |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
Referenced by initialize().
112 for (
int i = 0; i < topo.getNumNodes(); i++) {
113 cTopology::Node *node = topo.getNode(i);
116 if (!nodeInfo[i].isIPNode)
119 IInterfaceTable *ift = nodeInfo[i].ift;
120 IIPv4RoutingTable *rt = nodeInfo[i].rt;
124 InterfaceEntry *ie =
nullptr;
125 for (
int k = 0;
k < ift->getNumInterfaces();
k++)
126 if (!ift->getInterface(
k)->isLoopback()) {
127 ie = ift->getInterface(
k);
131 nodeInfo[i].usesDefaultRoute = (numIntf == 1);
135 EV_INFO <<
" " << node->getModule()->getFullName() <<
"=" << nodeInfo[i].address
136 <<
" has only one (non-loopback) interface, adding default route\n";
139 IPv4Route *
e =
new IPv4Route();
140 e->setDestination(IPv4Address());
141 e->setNetmask(IPv4Address());
const value< double, units::C > e(1.602176487e-19)
manually added static route
Definition: IRoute.h:40
const double k
Definition: QAM16Modulation.cc:24
void inet::FlatNetworkConfigurator::assignAddresses |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
Referenced by initialize().
82 uint32 networkAddress = IPv4Address(par(
"networkAddress").
stringValue()).getInt();
84 int maxNodes = (~netmask) - 1;
85 if (topo.getNumNodes() > maxNodes)
86 throw cRuntimeError(
"netmask too large, not enough addresses for all %d nodes", topo.getNumNodes());
89 for (
int i = 0; i < topo.getNumNodes(); i++) {
91 if (!nodeInfo[i].isIPNode)
95 nodeInfo[i].address.set(addr);
98 IInterfaceTable *ift = nodeInfo[i].ift;
99 for (
int k = 0;
k < ift->getNumInterfaces();
k++) {
100 InterfaceEntry *ie = ift->getInterface(
k);
101 if (!ie->isLoopback()) {
102 ie->ipv4Data()->setIPAddress(IPv4Address(addr));
uint32_t uint32
Definition: Compat.h:30
#define stringValue()
Definition: NedFunctions.cc:24
static const IPv4Address ALLONES_ADDRESS
255.255.255.255
Definition: IPv4Address.h:105
const double k
Definition: QAM16Modulation.cc:24
void inet::FlatNetworkConfigurator::extractTopology |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
Referenced by initialize().
62 topo.extractByProperty(
"networkNode");
63 EV_DEBUG <<
"cTopology found " << topo.getNumNodes() <<
" nodes\n";
66 nodeInfo.resize(topo.getNumNodes());
67 for (
int i = 0; i < topo.getNumNodes(); i++) {
68 cModule *
mod = topo.getNode(i)->getModule();
69 nodeInfo[i].isIPNode = L3AddressResolver().findIPv4RoutingTableOf(mod) !=
nullptr && L3AddressResolver().findInterfaceTableOf(mod) !=
nullptr;
70 if (nodeInfo[i].isIPNode) {
71 nodeInfo[i].ift = L3AddressResolver().interfaceTableOf(mod);
72 nodeInfo[i].rt = L3AddressResolver().routingTableOf(mod);
73 nodeInfo[i].ipForwardEnabled = mod->hasPar(
"forwarding") ? mod->par(
"forwarding").boolValue() :
false;
74 topo.getNode(i)->setWeight(nodeInfo[i].ipForwardEnabled ? 0.0 :
INFINITY);
#define INFINITY
Definition: Topology.h:29
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
void inet::FlatNetworkConfigurator::fillRoutingTables |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
Referenced by initialize().
152 for (
int i = 0; i < topo.getNumNodes(); i++) {
153 cTopology::Node *destNode = topo.getNode(i);
156 if (!nodeInfo[i].isIPNode)
159 IPv4Address destAddr = nodeInfo[i].address;
160 std::string destModName = destNode->getModule()->getFullName();
163 topo.calculateWeightedSingleShortestPathsTo(destNode);
167 for (
int j = 0; j < topo.getNumNodes(); j++) {
170 if (!nodeInfo[j].isIPNode)
173 cTopology::Node *atNode = topo.getNode(j);
174 if (atNode->getNumPaths() == 0)
176 if (nodeInfo[j].usesDefaultRoute)
179 IPv4Address atAddr = nodeInfo[j].address;
181 IInterfaceTable *ift = nodeInfo[j].ift;
183 int outputGateId = atNode->getPath(0)->getLocalGate()->getId();
184 InterfaceEntry *ie = ift->getInterfaceByNodeOutputGateId(outputGateId);
186 throw cRuntimeError(
"%s has no interface for output gate id %d", ift->getFullPath().c_str(), outputGateId);
188 EV_INFO <<
" from " << atNode->getModule()->getFullName() <<
"=" << IPv4Address(atAddr);
189 EV_INFO <<
" towards " << destModName <<
"=" << IPv4Address(destAddr) <<
" interface " << ie->getName() << endl;
192 IIPv4RoutingTable *rt = nodeInfo[j].rt;
193 IPv4Route *
e =
new IPv4Route();
194 e->setDestination(destAddr);
195 e->setNetmask(IPv4Address(255, 255, 255, 255));
const value< double, units::C > e(1.602176487e-19)
manually added static route
Definition: IRoute.h:40
void inet::FlatNetworkConfigurator::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
206 throw cRuntimeError(
"this module doesn't handle messages, it runs only in initialize()");
void inet::FlatNetworkConfigurator::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
34 cSimpleModule::initialize(stage);
37 cTopology topo(
"topo");
virtual void assignAddresses(cTopology &topo, NodeInfoVector &nodeInfo)
Definition: FlatNetworkConfigurator.cc:79
std::vector< NodeInfo > NodeInfoVector
Definition: FlatNetworkConfigurator.h:50
virtual void addDefaultRoutes(cTopology &topo, NodeInfoVector &nodeInfo)
Definition: FlatNetworkConfigurator.cc:109
virtual void extractTopology(cTopology &topo, NodeInfoVector &nodeInfo)
Definition: FlatNetworkConfigurator.cc:59
virtual void fillRoutingTables(cTopology &topo, NodeInfoVector &nodeInfo)
Definition: FlatNetworkConfigurator.cc:149
Initialization of network-layer protocols, stage 2.
Definition: InitStages.h:78
virtual void setDisplayString(cTopology &topo, NodeInfoVector &nodeInfo)
Definition: FlatNetworkConfigurator.cc:209
virtual int inet::FlatNetworkConfigurator::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
The number of initialization stages.
Definition: InitStages.h:116
void inet::FlatNetworkConfigurator::setDisplayString |
( |
cTopology & |
topo, |
|
|
NodeInfoVector & |
nodeInfo |
|
) |
| |
|
protectedvirtual |
Referenced by initialize().
212 for (
int i = 0; i < topo.getNumNodes(); i++)
213 if (nodeInfo[i].isIPNode)
219 sprintf(buf,
"%d IPv4 nodes\n%d non-IPv4 nodes", numIPNodes, topo.getNumNodes() - numIPNodes);
220 getDisplayString().setTagArg(
"t", 0, buf);
The documentation for this class was generated from the following files: