INET Framework for OMNeT++/OMNEST
inet::FlatNetworkConfigurator6 Class Reference

Configures IPv6 addresses and routing tables for a "flat" network, "flat" meaning that all hosts and routers will have the same network address. More...

#include <FlatNetworkConfigurator6.h>

Inheritance diagram for inet::FlatNetworkConfigurator6:

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void configureAdvPrefixes (cTopology &topo)
 
virtual void addOwnAdvPrefixRoutes (cTopology &topo)
 
virtual void addStaticRoutes (cTopology &topo)
 
virtual void setDisplayString (int numIPNodes, int numNonIPNodes)
 
virtual bool isIPNode (cTopology::Node *node)
 

Detailed Description

Configures IPv6 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.

Member Function Documentation

void inet::FlatNetworkConfigurator6::addOwnAdvPrefixRoutes ( cTopology &  topo)
protectedvirtual

Referenced by initialize().

133 {
134  // add globally routable prefixes to routing table
135  for (int i = 0; i < topo.getNumNodes(); i++) {
136  cTopology::Node *node = topo.getNode(i);
137 
138  // skip bus types
139  if (!isIPNode(node))
140  continue;
141 
142  IPv6RoutingTable *rt = L3AddressResolver().findIPv6RoutingTableOf(node->getModule());
143  IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(node->getModule());
144 
145  // skip non-IPv6 nodes
146  if (!rt)
147  continue;
148 
149  // skip hosts
150  if (!rt->par("isRouter").boolValue())
151  continue;
152 
153  // add globally routable prefixes to routing table
154  for (int x = 0; x < ift->getNumInterfaces(); x++) {
155  InterfaceEntry *ie = ift->getInterface(x);
156 
157  if (ie->isLoopback())
158  continue;
159 
160  for (int y = 0; y < ie->ipv6Data()->getNumAdvPrefixes(); y++)
161  if (ie->ipv6Data()->getAdvPrefix(y).prefix.isGlobal())
162  rt->addOrUpdateOwnAdvPrefix(ie->ipv6Data()->getAdvPrefix(y).prefix,
163  ie->ipv6Data()->getAdvPrefix(y).prefixLength,
164  ie->getInterfaceId(), SIMTIME_ZERO);
165 
166  }
167  }
168 }
virtual bool isIPNode(cTopology::Node *node)
Definition: FlatNetworkConfigurator6.cc:65
void inet::FlatNetworkConfigurator6::addStaticRoutes ( cTopology &  topo)
protectedvirtual

Referenced by initialize().

174 {
175  int numIPNodes = 0;
176 
177  // fill in routing tables
178  for (int i = 0; i < topo.getNumNodes(); i++) {
179  cTopology::Node *destNode = topo.getNode(i);
180 
181  // skip bus types
182  if (!isIPNode(destNode))
183  continue;
184 /*
185  void addOrUpdateOwnAdvPrefix(const IPv6Address& destPrefix, int prefixLength,
186  int interfaceId, simtime_t expiryTime);
187  */
188 
189  numIPNodes++; // FIXME split into num hosts, num routers
190  IPv6RoutingTable *destRt = L3AddressResolver().findIPv6RoutingTableOf(destNode->getModule());
191  IInterfaceTable *destIft = L3AddressResolver().interfaceTableOf(destNode->getModule());
192 
193  // skip non-IPv6 nodes
194  if (!destRt)
195  continue;
196 
197  // don't add routes towards hosts
198  if (!destRt->par("isRouter").boolValue())
199  continue;
200 
201  // get a list of globally routable prefixes from the dest node
202  std::vector<const IPv6InterfaceData::AdvPrefix *> destPrefixes;
203  for (int x = 0; x < destIft->getNumInterfaces(); x++) {
204  InterfaceEntry *destIf = destIft->getInterface(x);
205 
206  if (destIf->isLoopback())
207  continue;
208 
209  for (int y = 0; y < destIf->ipv6Data()->getNumAdvPrefixes(); y++)
210  if (destIf->ipv6Data()->getAdvPrefix(y).prefix.isGlobal())
211  destPrefixes.push_back(&destIf->ipv6Data()->getAdvPrefix(y));
212 
213  }
214 
215  std::string destModName = destNode->getModule()->getFullName();
216 
217  // calculate shortest paths from everywhere towards destNode
218  topo.calculateUnweightedSingleShortestPathsTo(destNode);
219 
220  // add route (with dest=destPrefixes) to every router routing table in the network
221  for (int j = 0; j < topo.getNumNodes(); j++) {
222  if (i == j)
223  continue;
224  if (!isIPNode(topo.getNode(j)))
225  continue;
226 
227  cTopology::Node *atNode = topo.getNode(j);
228  if (atNode->getNumPaths() == 0)
229  continue; // not connected
230 
231  IPv6RoutingTable *rt = L3AddressResolver().findIPv6RoutingTableOf(atNode->getModule());
232  IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(atNode->getModule());
233 
234  // skip non-IPv6 nodes
235  if (!rt)
236  continue;
237 
238  // skip hosts' routing tables
239  if (!rt->par("isRouter").boolValue())
240  continue;
241 
242  // determine the local interface id
243  cGate *localGate = atNode->getPath(0)->getLocalGate();
244  InterfaceEntry *localIf = ift->getInterfaceByNodeOutputGateId(localGate->getId());
245 
246  // determine next hop link address. That's a bit tricky because
247  // the directly adjacent cTopo node might be a non-IP getNode(ethernet switch etc)
248  // so we have to "seek through" them.
249  cTopology::Node *prevNode = atNode;
250  // if there's no ethernet switch between atNode and it's next hop
251  // neighbour, we don't go into the following while() loop
252  while (!isIPNode(prevNode->getPath(0)->getRemoteNode()))
253  prevNode = prevNode->getPath(0)->getRemoteNode();
254 
255  // ok, the next hop is now just one step away from prevNode
256  cGate *remoteGate = prevNode->getPath(0)->getRemoteGate();
257  cModule *nextHop = remoteGate->getOwnerModule();
258  IInterfaceTable *nextHopIft = L3AddressResolver().interfaceTableOf(nextHop);
259  InterfaceEntry *nextHopOnlinkIf = nextHopIft->getInterfaceByNodeInputGateId(remoteGate->getId());
260 
261  // find link-local address for next hop
262  IPv6Address nextHopLinkLocalAddr = nextHopOnlinkIf->ipv6Data()->getLinkLocalAddress();
263 
264  // traverse through address of each node
265  // add to route table
266  for (auto & destPrefixe : destPrefixes) {
267  rt->addStaticRoute(destPrefixe->prefix, destPrefixe->prefixLength,
268  localIf->getInterfaceId(), nextHopLinkLocalAddr);
269  }
270  }
271  }
272 
273  // update display string
274  setDisplayString(numIPNodes, topo.getNumNodes() - numIPNodes);
275 }
virtual void setDisplayString(int numIPNodes, int numNonIPNodes)
Definition: FlatNetworkConfigurator6.cc:57
virtual bool isIPNode(cTopology::Node *node)
Definition: FlatNetworkConfigurator6.cc:65
void inet::FlatNetworkConfigurator6::configureAdvPrefixes ( cTopology &  topo)
protectedvirtual

Referenced by initialize().

72 {
73  // assign advertised prefixes to all router interfaces
74  for (int i = 0; i < topo.getNumNodes(); i++) {
75  // skip bus types
76  if (!isIPNode(topo.getNode(i)))
77  continue;
78 
79  int nodeIndex = i;
80 
81  // find interface table and assign address to all (non-loopback) interfaces
82  cModule *mod = topo.getNode(i)->getModule();
83  IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(mod);
84  IPv6RoutingTable *rt = L3AddressResolver().findIPv6RoutingTableOf(mod);
85 
86  // skip non-IPv6 nodes
87  if (!rt)
88  continue;
89 
90  // skip hosts
91  if (!rt->par("isRouter").boolValue())
92  continue;
93 
94  // assign prefix to interfaces
95  for (int k = 0; k < ift->getNumInterfaces(); k++) {
96  InterfaceEntry *ie = ift->getInterface(k);
97  if (!ie->ipv6Data() || ie->isLoopback())
98  continue;
99  if (ie->ipv6Data()->getNumAdvPrefixes() > 0)
100  continue; // already has one
101 
102  // add a prefix
103  IPv6Address prefix(0xaaaa0000 + nodeIndex, ie->getNetworkLayerGateIndex() << 16, 0, 0);
104  ASSERT(prefix.isGlobal());
105 
106  IPv6InterfaceData::AdvPrefix p;
107  p.prefix = prefix;
108  p.prefixLength = 64;
109  // RFC 2461:6.2.1. Only default values are used in FlatNetworkConfigurator6
110  // Default: 2592000 seconds (30 days), fixed (i.e., stays the same in
111  // consecutive advertisements).
112  p.advValidLifetime = 2592000;
113  // Default: TRUE
114  p.advOnLinkFlag = true;
115  // Default: 604800 seconds (7 days), fixed (i.e., stays the same in consecutive
116  // advertisements).
117  p.advPreferredLifetime = 604800;
118  // Default: TRUE
119  p.advAutonomousFlag = true;
120 #ifdef WITH_xMIPv6
121  p.advRtrAddr = false;
122 #endif
123  ie->ipv6Data()->addAdvPrefix(p);
124 
125  // add a link-local address (tentative) if it doesn't have one
126  if (ie->ipv6Data()->getLinkLocalAddress().isUnspecified())
127  ie->ipv6Data()->assignAddress(IPv6Address::formLinkLocalAddress(ie->getInterfaceToken()), true, SIMTIME_ZERO, SIMTIME_ZERO);
128  }
129  }
130 }
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
virtual bool isIPNode(cTopology::Node *node)
Definition: FlatNetworkConfigurator6.cc:65
static IPv6Address formLinkLocalAddress(const InterfaceToken &ident)
Forms a link-local address using the given interface identifier.
Definition: IPv6Address.cc:357
const double k
Definition: QAM16Modulation.cc:24
void inet::FlatNetworkConfigurator6::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
53 {
54  throw cRuntimeError("this module doesn't handle messages, it runs only in initialize()");
55 }
void inet::FlatNetworkConfigurator6::initialize ( int  stage)
overrideprotectedvirtual
35 {
36  cSimpleModule::initialize(stage);
37 
38  if (stage == INITSTAGE_NETWORK_LAYER_2) {
39  cTopology topo("topo");
40 
41  // extract topology
42  topo.extractByProperty("networkNode");
43  EV_DEBUG << "cTopology found " << topo.getNumNodes() << " nodes\n";
44 
46 
48  addStaticRoutes(topo);
49  }
50 }
virtual void configureAdvPrefixes(cTopology &topo)
Definition: FlatNetworkConfigurator6.cc:71
virtual void addOwnAdvPrefixRoutes(cTopology &topo)
Definition: FlatNetworkConfigurator6.cc:132
Initialization of network-layer protocols, stage 2.
Definition: InitStages.h:78
virtual void addStaticRoutes(cTopology &topo)
Definition: FlatNetworkConfigurator6.cc:173
bool inet::FlatNetworkConfigurator6::isIPNode ( cTopology::Node *  node)
protectedvirtual

Referenced by addOwnAdvPrefixRoutes(), addStaticRoutes(), and configureAdvPrefixes().

66 {
67  return L3AddressResolver().findIPv6RoutingTableOf(node->getModule()) != nullptr
68  && L3AddressResolver().findInterfaceTableOf(node->getModule()) != nullptr;
69 }
virtual int inet::FlatNetworkConfigurator6::numInitStages ( ) const
inlineoverrideprotectedvirtual
36 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::FlatNetworkConfigurator6::setDisplayString ( int  numIPNodes,
int  numNonIPNodes 
)
protectedvirtual

Referenced by addStaticRoutes().

58 {
59  // update display string
60  char buf[80];
61  sprintf(buf, "%d IPv6 nodes\n%d non-IP nodes", numIPNodes, numNonIPNodes);
62  getDisplayString().setTagArg("t", 0, buf);
63 }

The documentation for this class was generated from the following files: