INET Framework for OMNeT++/OMNEST
inet::Ipv6FlatNetworkConfigurator 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 <Ipv6FlatNetworkConfigurator.h>

Inheritance diagram for inet::Ipv6FlatNetworkConfigurator:

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

◆ addOwnAdvPrefixRoutes()

void inet::Ipv6FlatNetworkConfigurator::addOwnAdvPrefixRoutes ( cTopology &  topo)
protectedvirtual
123 {
124  // add globally routable prefixes to routing table
125  for (int i = 0; i < topo.getNumNodes(); i++) {
126  cTopology::Node *node = topo.getNode(i);
127 
128  // skip bus types
129  if (!isIPNode(node))
130  continue;
131 
132  Ipv6RoutingTable *rt = L3AddressResolver().findIpv6RoutingTableOf(node->getModule());
133  IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(node->getModule());
134 
135  // skip non-Ipv6 nodes
136  if (!rt)
137  continue;
138 
139  // skip hosts
140  if (!rt->par("isRouter"))
141  continue;
142 
143  // add globally routable prefixes to routing table
144  for (int x = 0; x < ift->getNumInterfaces(); x++) {
145  NetworkInterface *ie = ift->getInterface(x);
146 
147  if (ie->isLoopback())
148  continue;
149  auto ipv6Data = ie->getProtocolData<Ipv6InterfaceData>();
150  for (int y = 0; y < ipv6Data->getNumAdvPrefixes(); y++)
151  if (ipv6Data->getAdvPrefix(y).prefix.isGlobal())
152  rt->addOrUpdateOwnAdvPrefix(ipv6Data->getAdvPrefix(y).prefix,
153  ipv6Data->getAdvPrefix(y).prefixLength,
154  ie->getInterfaceId(), SIMTIME_ZERO);
155 
156  }
157  }
158 }

Referenced by initialize().

◆ addStaticRoutes()

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

Referenced by initialize().

◆ configureAdvPrefixes()

void inet::Ipv6FlatNetworkConfigurator::configureAdvPrefixes ( cTopology &  topo)
protectedvirtual
61 {
62  // assign advertised prefixes to all router interfaces
63  for (int i = 0; i < topo.getNumNodes(); i++) {
64  // skip bus types
65  if (!isIPNode(topo.getNode(i)))
66  continue;
67 
68  int nodeIndex = i;
69 
70  // find interface table and assign address to all (non-loopback) interfaces
71  cModule *mod = topo.getNode(i)->getModule();
72  IInterfaceTable *ift = L3AddressResolver().interfaceTableOf(mod);
73  Ipv6RoutingTable *rt = L3AddressResolver().findIpv6RoutingTableOf(mod);
74 
75  // skip non-Ipv6 nodes
76  if (!rt)
77  continue;
78 
79  // skip hosts
80  if (!rt->par("isRouter"))
81  continue;
82 
83  // assign prefix to interfaces
84  for (int k = 0; k < ift->getNumInterfaces(); k++) {
85  NetworkInterface *ie = ift->getInterface(k);
86  auto ipv6Data = ie->findProtocolDataForUpdate<Ipv6InterfaceData>();
87  if (!ipv6Data || ie->isLoopback())
88  continue;
89  if (ipv6Data->getNumAdvPrefixes() > 0)
90  continue; // already has one
91 
92  // add a prefix
93  Ipv6Address prefix(0xaaaa0000 + nodeIndex, ie->getInterfaceId() << 16, 0, 0);
94  ASSERT(prefix.isGlobal());
95 
96  Ipv6InterfaceData::AdvPrefix p;
97  p.prefix = prefix;
98  p.prefixLength = 64;
99  // RFC 2461:6.2.1. Only default values are used in Ipv6FlatNetworkConfigurator
100  // Default: 2592000 seconds (30 days), fixed (i.e., stays the same in
101  // consecutive advertisements).
102  p.advValidLifetime = 2592000;
103  // Default: TRUE
104  p.advOnLinkFlag = true;
105  // Default: 604800 seconds (7 days), fixed (i.e., stays the same in consecutive
106  // advertisements).
107  p.advPreferredLifetime = 604800;
108  // Default: TRUE
109  p.advAutonomousFlag = true;
110 #ifdef INET_WITH_xMIPv6
111  p.advRtrAddr = false;
112 #endif
113  ipv6Data->addAdvPrefix(p);
114 
115  // add a link-local address (tentative) if it doesn't have one
116  if (ipv6Data->getLinkLocalAddress().isUnspecified())
117  ipv6Data->assignAddress(Ipv6Address::formLinkLocalAddress(ie->getInterfaceToken()), true, SIMTIME_ZERO, SIMTIME_ZERO);
118  }
119  }
120 }

Referenced by initialize().

◆ handleMessage()

void inet::Ipv6FlatNetworkConfigurator::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
42 {
43  throw cRuntimeError("this module doesn't handle messages, it runs only in initialize()");
44 }

◆ initialize()

void inet::Ipv6FlatNetworkConfigurator::initialize ( int  stage)
overrideprotectedvirtual
24 {
25  cSimpleModule::initialize(stage);
26 
27  if (stage == INITSTAGE_NETWORK_CONFIGURATION) {
28  cTopology topo("topo");
29 
30  // extract topology
31  topo.extractByProperty("networkNode");
32  EV_DEBUG << "cTopology found " << topo.getNumNodes() << " nodes\n";
33 
35 
37  addStaticRoutes(topo);
38  }
39 }

◆ isIPNode()

bool inet::Ipv6FlatNetworkConfigurator::isIPNode ( cTopology::Node *  node)
protectedvirtual
55 {
56  return L3AddressResolver().findIpv6RoutingTableOf(node->getModule()) != nullptr
57  && L3AddressResolver().findInterfaceTableOf(node->getModule()) != nullptr;
58 }

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

◆ numInitStages()

virtual int inet::Ipv6FlatNetworkConfigurator::numInitStages ( ) const
inlineoverrideprotectedvirtual
25 { return NUM_INIT_STAGES; }

◆ setDisplayString()

void inet::Ipv6FlatNetworkConfigurator::setDisplayString ( int  numIPNodes,
int  numNonIPNodes 
)
protectedvirtual
47 {
48  // update display string
49  char buf[80];
50  sprintf(buf, "%d Ipv6 nodes\n%d non-IP nodes", numIPNodes, numNonIPNodes);
51  getDisplayString().setTagArg("t", 0, buf);
52 }

Referenced by addStaticRoutes().


The documentation for this class was generated from the following files:
inet::math::mod
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:96
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::INITSTAGE_NETWORK_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_CONFIGURATION
Initialization of network configuration (e.g.
inet::Ipv6FlatNetworkConfigurator::isIPNode
virtual bool isIPNode(cTopology::Node *node)
Definition: Ipv6FlatNetworkConfigurator.cc:54
inet::Ipv6FlatNetworkConfigurator::addOwnAdvPrefixRoutes
virtual void addOwnAdvPrefixRoutes(cTopology &topo)
Definition: Ipv6FlatNetworkConfigurator.cc:122
inet::Ipv6FlatNetworkConfigurator::configureAdvPrefixes
virtual void configureAdvPrefixes(cTopology &topo)
Definition: Ipv6FlatNetworkConfigurator.cc:60
inet::Ipv6Address::formLinkLocalAddress
static Ipv6Address formLinkLocalAddress(const InterfaceToken &ident)
Forms a link-local address using the given interface identifier.
Definition: Ipv6Address.cc:348
inet::Ipv6FlatNetworkConfigurator::addStaticRoutes
virtual void addStaticRoutes(cTopology &topo)
Definition: Ipv6FlatNetworkConfigurator.cc:163
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::Ipv6FlatNetworkConfigurator::setDisplayString
virtual void setDisplayString(int numIPNodes, int numNonIPNodes)
Definition: Ipv6FlatNetworkConfigurator.cc:46