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

A C++ interface to abstract the functionality of a routing table, regardless of address type. More...

#include <GenericRoutingTable.h>

Inheritance diagram for inet::GenericRoutingTable:
inet::IRoutingTable

Public Member Functions

 GenericRoutingTable ()
 
virtual ~GenericRoutingTable ()
 
virtual IRoutecreateRoute () override
 
virtual void printRoutingTable () const override
 Prints routing table. More...
 
Miscellaneous functions
virtual bool isForwardingEnabled () const override
 Forwarding on/off. More...
 
virtual bool isMulticastForwardingEnabled () const override
 Multicast forwarding on/off. More...
 
virtual L3Address getRouterIdAsGeneric () const override
 Returns routerId. More...
 
virtual bool isLocalAddress (const L3Address &dest) const override
 Checks if the address is a local one, i.e. More...
 
virtual InterfaceEntrygetInterfaceByAddress (const L3Address &address) const override
 Returns an interface given by its address. More...
 
virtual void routeChanged (GenericRoute *entry, int fieldCode)
 To be called from route objects whenever a field changes. More...
 
Routing functions (query the route table)
virtual GenericRoutefindBestMatchingRoute (const L3Address &dest) const override
 The routing function. More...
 
virtual InterfaceEntrygetOutputInterfaceForDestination (const L3Address &dest) const override
 Convenience function based on findBestMatchingRoute(). More...
 
virtual L3Address getNextHopForDestination (const L3Address &dest) const override
 Convenience function based on findBestMatchingRoute(). More...
 
Multicast routing functions
virtual bool isLocalMulticastAddress (const L3Address &dest) const override
 Checks if the address is in one of the local multicast group address list. More...
 
virtual IMulticastRoutefindBestMatchingMulticastRoute (const L3Address &origin, const L3Address &group) const override
 Returns route for a multicast origin and group. More...
 
Route table manipulation
virtual int getNumRoutes () const override
 Returns the total number of unicast routes. More...
 
virtual IRoutegetRoute (int k) const override
 Returns the kth route. More...
 
virtual IRoutegetDefaultRoute () const override
 Finds and returns the default route, or nullptr if it doesn't exist. More...
 
virtual void addRoute (IRoute *entry) override
 Adds a route to the routing table. More...
 
virtual IRouteremoveRoute (IRoute *entry) override
 Removes the given route from the routing table, and returns it. More...
 
virtual bool deleteRoute (IRoute *entry) override
 Deletes the given route from the routing table. More...
 
virtual int getNumMulticastRoutes () const override
 Returns the total number of multicast routes. More...
 
virtual IMulticastRoutegetMulticastRoute (int k) const override
 Returns the kth multicast route. More...
 
virtual void addMulticastRoute (IMulticastRoute *entry) override
 Adds a multicast route to the routing table. More...
 
virtual IMulticastRouteremoveMulticastRoute (IMulticastRoute *entry) override
 Removes the given route from the routing table, and returns it. More...
 
virtual bool deleteMulticastRoute (IMulticastRoute *entry) override
 Deletes the given multicast route from the routing table. More...
 
- Public Member Functions inherited from inet::IRoutingTable
virtual ~IRoutingTable ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *) override
 Raises an error. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 Called by the signal handler whenever a change of a category occurs to which this client has subscribed. More...
 
virtual void configureRouterId ()
 
virtual void refreshDisplay () const override
 
virtual void configureInterface (InterfaceEntry *ie)
 
virtual void configureLoopback ()
 
void internalAddRoute (GenericRoute *route)
 
GenericRouteinternalRemoveRoute (GenericRoute *route)
 

Static Protected Member Functions

static bool routeLessThan (const GenericRoute *a, const GenericRoute *b)
 

Private Types

typedef std::vector< GenericRoute * > RouteVector
 
typedef std::vector< GenericMulticastRoute * > MulticastRouteVector
 

Private Attributes

IInterfaceTableift = nullptr
 
L3Address routerId
 
L3Address::AddressType addressType = L3Address::NONE
 
bool forwarding = false
 
bool multicastForwarding = false
 
RouteVector routes
 
MulticastRouteVector multicastRoutes
 

Detailed Description

A C++ interface to abstract the functionality of a routing table, regardless of address type.

Member Typedef Documentation

typedef std::vector<GenericRoute *> inet::GenericRoutingTable::RouteVector
private

Constructor & Destructor Documentation

inet::GenericRoutingTable::GenericRoutingTable ( )
46 {
47 }
inet::GenericRoutingTable::~GenericRoutingTable ( )
virtual
50 {
51  for (auto & elem : routes)
52  delete elem;
53  for (auto & elem : multicastRoutes)
54  delete elem;
55 }
MulticastRouteVector multicastRoutes
Definition: GenericRoutingTable.h:49
RouteVector routes
Definition: GenericRoutingTable.h:46

Member Function Documentation

void inet::GenericRoutingTable::addMulticastRoute ( IMulticastRoute entry)
overridevirtual

Adds a multicast route to the routing table.

Routes are allowed to be modified while in the routing table. (There is a notification mechanism that allows routing table internals to be updated on a routing entry change.)

Implements inet::IRoutingTable.

397 {
398  //TODO
399 }
void inet::GenericRoutingTable::addRoute ( IRoute entry)
overridevirtual

Adds a route to the routing table.

Routes are allowed to be modified while in the routing table. (There is a notification mechanism that allows routing table internals to be updated on a routing entry change.)

Implements inet::IRoutingTable.

Referenced by inet::GenericNetworkConfigurator::addStaticRoutes().

329 {
330  Enter_Method("addRoute(...)");
331 
332  GenericRoute *entry = check_and_cast<GenericRoute *>(route);
333 
334  // check that the interface exists
335  if (!entry->getInterface())
336  throw cRuntimeError("addRoute(): interface cannot be nullptr");
337 
338  internalAddRoute(entry);
339 
340  emit(NF_ROUTE_ADDED, entry);
341 }
void internalAddRoute(GenericRoute *route)
Definition: GenericRoutingTable.cc:362
simsignal_t NF_ROUTE_ADDED
Definition: NotifierConsts.cc:57
void inet::GenericRoutingTable::configureInterface ( InterfaceEntry ie)
protectedvirtual

Referenced by initialize().

172 {
173  int metric = (int)(ceil(2e9 / ie->getDatarate())); // use OSPF cost as default
174  int interfaceModuleId = ie->getInterfaceModule() ? ie->getInterfaceModule()->getId() : -1;
175  // mac
176  GenericNetworkProtocolInterfaceData *d = new GenericNetworkProtocolInterfaceData();
177  d->setMetric(metric);
179  d->setAddress(ie->getMacAddress());
180  else if (ie->getInterfaceModule() && addressType == L3Address::MODULEPATH)
181  d->setAddress(ModulePathAddress(interfaceModuleId));
182  else if (ie->getInterfaceModule() && addressType == L3Address::MODULEID)
183  d->setAddress(ModuleIdAddress(interfaceModuleId));
184  ie->setGenericNetworkProtocolData(d);
185 }
L3Address::AddressType addressType
Definition: GenericRoutingTable.h:41
Definition: L3Address.h:49
Definition: L3Address.h:50
Definition: L3Address.h:48
void inet::GenericRoutingTable::configureLoopback ( )
protectedvirtual

Referenced by initialize().

188 {
189 //TODO needed???
190 // InterfaceEntry *ie = ift->getFirstLoopbackInterface()
191 // // add IPv4 info. Set 127.0.0.1/8 as address by default --
192 // // we may reconfigure later it to be the routerId
193 // IPv4InterfaceData *d = new IPv4InterfaceData();
194 // d->setIPAddress(IPv4Address::LOOPBACK_ADDRESS);
195 // d->setNetmask(IPv4Address::LOOPBACK_NETMASK);
196 // d->setMetric(1);
197 // ie->setIPv4Data(d);
198 }
void inet::GenericRoutingTable::configureRouterId ( )
protectedvirtual

Referenced by initialize().

144 {
145  if (routerId.isUnspecified()) { // not yet configured
146  const char *routerIdStr = par("routerId").stringValue();
147  if (!strcmp(routerIdStr, "auto")) { // non-"auto" cases already handled in earlier stage
148  // choose highest interface address as routerId
149  for (int i = 0; i < ift->getNumInterfaces(); ++i) {
150  InterfaceEntry *ie = ift->getInterface(i);
151  if (!ie->isLoopback()) {
152  L3Address interfaceAddr = ie->getGenericNetworkProtocolData()->getAddress();
153  if (routerId.isUnspecified() || routerId < interfaceAddr)
154  routerId = interfaceAddr;
155  }
156  }
157  }
158  }
159 // else // already configured
160 // {
161 // // if there is no interface with routerId yet, assign it to the loopback address;
162 // // TODO find out if this is a good practice, in which situations it is useful etc.
163 // if (getInterfaceByAddress(routerId)==nullptr)
164 // {
165 // InterfaceEntry *lo0 = ift->getFirstLoopbackInterface();
166 // lo0->getGenericNetworkProtocolData()->setAddress(routerId);
167 // }
168 // }
169 }
GenericNetworkProtocolInterfaceData * getGenericNetworkProtocolData() const
Definition: InterfaceEntry.h:224
L3Address routerId
Definition: GenericRoutingTable.h:40
IInterfaceTable * ift
Definition: GenericRoutingTable.h:38
bool isUnspecified() const
Definition: L3Address.cc:133
L3Address getAddress() const
Definition: GenericNetworkProtocolInterfaceData.h:60
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
IRoute * inet::GenericRoutingTable::createRoute ( )
overridevirtual

Implements inet::IRoutingTable.

412 {
413  return new GenericRoute();
414 }
bool inet::GenericRoutingTable::deleteMulticastRoute ( IMulticastRoute entry)
overridevirtual

Deletes the given multicast route from the routing table.

Returns true if the route was deleted, and false if it was not in the routing table.

Implements inet::IRoutingTable.

407 {
408  return false; //TODO
409 }
bool inet::GenericRoutingTable::deleteRoute ( IRoute entry)
overridevirtual

Deletes the given route from the routing table.

Returns true if the route was deleted, and false if it was not in the routing table.

Implements inet::IRoutingTable.

356 {
357  IRoute *route = removeRoute(entry);
358  delete route;
359  return route != nullptr;
360 }
virtual IRoute * removeRoute(IRoute *entry) override
Removes the given route from the routing table, and returns it.
Definition: GenericRoutingTable.cc:343
IMulticastRoute * inet::GenericRoutingTable::findBestMatchingMulticastRoute ( const L3Address origin,
const L3Address group 
) const
overridevirtual

Returns route for a multicast origin and group.

Implements inet::IRoutingTable.

304 {
305  return nullptr; //TODO
306 }
GenericRoute * inet::GenericRoutingTable::findBestMatchingRoute ( const L3Address dest) const
overridevirtual

The routing function.

Performs longest prefix match for the given destination address, and returns the resulting route. Returns nullptr if there is no matching route.

Implements inet::IRoutingTable.

Referenced by getNextHopForDestination(), getOutputInterfaceForDestination(), and inet::GenericNetworkProtocol::routePacket().

266 {
267  //TODO Enter_Method("findBestMatchingRoute(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3)); // note: str().c_str() too slow here
268 
269  // find best match (one with longest prefix)
270  // default route has zero prefix length, so (if exists) it'll be selected as last resort
271  GenericRoute *bestRoute = nullptr;
272  for (auto e : routes) {
273 
274  if (dest.matches(e->getDestinationAsGeneric(), e->getPrefixLength())) {
275  bestRoute = const_cast<GenericRoute *>(e);
276  break;
277  }
278  }
279  return bestRoute;
280 }
const value< double, units::C > e(1.602176487e-19)
RouteVector routes
Definition: GenericRoutingTable.h:46
IRoute * inet::GenericRoutingTable::getDefaultRoute ( ) const
overridevirtual

Finds and returns the default route, or nullptr if it doesn't exist.

Implements inet::IRoutingTable.

320 {
321  // if there is a default route entry, it is the last valid entry
322  auto i = routes.rbegin();
323  if (i != routes.rend() && (*i)->getPrefixLength() == 0)
324  return *i;
325  return nullptr;
326 }
RouteVector routes
Definition: GenericRoutingTable.h:46
InterfaceEntry * inet::GenericRoutingTable::getInterfaceByAddress ( const L3Address address) const
overridevirtual

Returns an interface given by its address.

Returns nullptr if not found.

Implements inet::IRoutingTable.

Referenced by inet::GenericNetworkProtocol::encapsulate().

254 {
255  // collect interface addresses if not yet done
256  for (int i = 0; i < ift->getNumInterfaces(); i++) {
257  InterfaceEntry *ie = ift->getInterface(i);
258  L3Address interfaceAddr = ie->getGenericNetworkProtocolData()->getAddress();
259  if (interfaceAddr == address)
260  return ie;
261  }
262  return nullptr;
263 }
GenericNetworkProtocolInterfaceData * getGenericNetworkProtocolData() const
Definition: InterfaceEntry.h:224
IInterfaceTable * ift
Definition: GenericRoutingTable.h:38
L3Address getAddress() const
Definition: GenericNetworkProtocolInterfaceData.h:60
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
IMulticastRoute * inet::GenericRoutingTable::getMulticastRoute ( int  k) const
overridevirtual

Returns the kth multicast route.

Implements inet::IRoutingTable.

392 {
393  return nullptr; //TODO
394 }
L3Address inet::GenericRoutingTable::getNextHopForDestination ( const L3Address dest) const
overridevirtual

Convenience function based on findBestMatchingRoute().

Returns the gateway for the destination address. Returns the unspecified address if the destination is not in routing table or the gateway field is not filled in in the route.

Implements inet::IRoutingTable.

291 {
292  //TODO Enter_Method("getGatewayForDestAddr(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3)); // note: str().c_str() too slow here
293 
294  const IRoute *e = findBestMatchingRoute(dest);
295  return e ? e->getNextHopAsGeneric() : L3Address();
296 }
virtual GenericRoute * findBestMatchingRoute(const L3Address &dest) const override
The routing function.
Definition: GenericRoutingTable.cc:265
const value< double, units::C > e(1.602176487e-19)
int inet::GenericRoutingTable::getNumMulticastRoutes ( ) const
overridevirtual

Returns the total number of multicast routes.

Implements inet::IRoutingTable.

387 {
388  return 0; //TODO
389 }
int inet::GenericRoutingTable::getNumRoutes ( ) const
overridevirtual

Returns the total number of unicast routes.

Implements inet::IRoutingTable.

309 {
310  return routes.size();
311 }
RouteVector routes
Definition: GenericRoutingTable.h:46
InterfaceEntry * inet::GenericRoutingTable::getOutputInterfaceForDestination ( const L3Address dest) const
overridevirtual

Convenience function based on findBestMatchingRoute().

Returns the output interface for the packets with dest as destination address, or nullptr if the destination is not in routing table.

Implements inet::IRoutingTable.

283 {
284  //TODO Enter_Method("getInterfaceForDestAddr(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3)); // note: str().c_str() too slow here
285 
286  const IRoute *e = findBestMatchingRoute(dest);
287  return e ? e->getInterface() : nullptr;
288 }
virtual GenericRoute * findBestMatchingRoute(const L3Address &dest) const override
The routing function.
Definition: GenericRoutingTable.cc:265
const value< double, units::C > e(1.602176487e-19)
IRoute * inet::GenericRoutingTable::getRoute ( int  k) const
overridevirtual

Returns the kth route.

Implements inet::IRoutingTable.

314 {
315  ASSERT(k >= 0 && (unsigned int)k < routes.size());
316  return routes[k];
317 }
RouteVector routes
Definition: GenericRoutingTable.h:46
const double k
Definition: QAM16Modulation.cc:24
L3Address inet::GenericRoutingTable::getRouterIdAsGeneric ( ) const
overridevirtual

Returns routerId.

Implements inet::IRoutingTable.

236 {
237  return routerId;
238 }
L3Address routerId
Definition: GenericRoutingTable.h:40
void inet::GenericRoutingTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Raises an error.

122 {
123  throw cRuntimeError("This module doesn't process messages");
124 }
void inet::GenericRoutingTable::initialize ( int  stage)
overrideprotectedvirtual
58 {
59  cSimpleModule::initialize(stage);
60 
61  if (stage == INITSTAGE_LOCAL) {
62  // get a pointer to the IInterfaceTable
63  ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
64 
65  const char *addressTypeString = par("addressType");
66  if (!strcmp(addressTypeString, "mac"))
68  else if (!strcmp(addressTypeString, "modulepath"))
70  else if (!strcmp(addressTypeString, "moduleid"))
72  else
73  throw cRuntimeError("Unknown address type");
74  forwarding = par("forwarding").boolValue();
75  multicastForwarding = par("multicastForwarding");
76 
77  WATCH_PTRVECTOR(routes);
78  WATCH_PTRVECTOR(multicastRoutes);
79  WATCH(forwarding);
80  WATCH(multicastForwarding);
81  WATCH(routerId);
82 
83  cModule *host = getContainingNode(this);
84  host->subscribe(NF_INTERFACE_CREATED, this);
85  host->subscribe(NF_INTERFACE_DELETED, this);
86  host->subscribe(NF_INTERFACE_STATE_CHANGED, this);
87  host->subscribe(NF_INTERFACE_CONFIG_CHANGED, this);
88  host->subscribe(NF_INTERFACE_IPv4CONFIG_CHANGED, this);
89  }
90  else if (stage == INITSTAGE_NETWORK_LAYER) {
91  // At this point, all L2 modules have registered themselves (added their
92  // interface entries). Create the per-interface IPv4 data structures.
93  IInterfaceTable *interfaceTable = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
94  for (int i = 0; i < interfaceTable->getNumInterfaces(); ++i)
95  configureInterface(interfaceTable->getInterface(i));
97 
98 // // read routing table file (and interface configuration)
99 // RoutingTableParser parser(ift, this);
100 // if (*filename && parser.readRoutingTableFromFile(filename)==-1)
101 // throw cRuntimeError("Error reading routing table file %s", filename);
102 
103 //TODO
104 // // set routerId if param is not "" (==no routerId) or "auto" (in which case we'll
105 // // do it later in a later stage, after network configurators configured the interfaces)
106 // const char *routerIdStr = par("routerId").stringValue();
107 // if (strcmp(routerIdStr, "") && strcmp(routerIdStr, "auto"))
108 // routerId = IPv4Address(routerIdStr);
109  }
110  else if (stage == INITSTAGE_NETWORK_LAYER_3) {
111  // routerID selection must be after network autoconfiguration assigned interface addresses
113 
114 // // we don't use notifications during initialize(), so we do it manually.
115 // updateNetmaskRoutes();
116 
117  //printRoutingTable();
118  }
119 }
virtual void configureInterface(InterfaceEntry *ie)
Definition: GenericRoutingTable.cc:171
L3Address::AddressType addressType
Definition: GenericRoutingTable.h:41
L3Address routerId
Definition: GenericRoutingTable.h:40
Definition: L3Address.h:49
Initialization of network-layer protocols, stage 3.
Definition: InitStages.h:84
virtual void configureRouterId()
Definition: GenericRoutingTable.cc:143
IInterfaceTable * ift
Definition: GenericRoutingTable.h:38
simsignal_t NF_INTERFACE_CONFIG_CHANGED
Definition: NotifierConsts.cc:51
MulticastRouteVector multicastRoutes
Definition: GenericRoutingTable.h:49
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
Local initializations.
Definition: InitStages.h:35
simsignal_t NF_INTERFACE_STATE_CHANGED
Definition: NotifierConsts.cc:50
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
simsignal_t NF_INTERFACE_CREATED
Definition: NotifierConsts.cc:48
simsignal_t NF_INTERFACE_IPv4CONFIG_CHANGED
Definition: NotifierConsts.cc:53
virtual void configureLoopback()
Definition: GenericRoutingTable.cc:187
Definition: L3Address.h:50
RouteVector routes
Definition: GenericRoutingTable.h:46
bool multicastForwarding
Definition: GenericRoutingTable.h:43
bool forwarding
Definition: GenericRoutingTable.h:42
Definition: L3Address.h:48
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
void inet::GenericRoutingTable::internalAddRoute ( GenericRoute route)
protected

Referenced by addRoute(), and routeChanged().

363 {
364  ASSERT(route->getRoutingTableAsGeneric() == nullptr);
365 
366  // add to tables
367  // we keep entries sorted, so that we can stop at the first match when doing the longest prefix matching
368  auto pos = upper_bound(routes.begin(), routes.end(), route, routeLessThan);
369  routes.insert(pos, route);
370 
371  route->setRoutingTable(this);
372 }
RouteVector routes
Definition: GenericRoutingTable.h:46
static bool routeLessThan(const GenericRoute *a, const GenericRoute *b)
Definition: GenericRoutingTable.cc:211
GenericRoute * inet::GenericRoutingTable::internalRemoveRoute ( GenericRoute route)
protected

Referenced by removeRoute(), and routeChanged().

375 {
376  auto i = std::find(routes.begin(), routes.end(), route);
377  if (i != routes.end()) {
378  ASSERT(route->getRoutingTableAsGeneric() == this);
379  routes.erase(i);
380  route->setRoutingTable(nullptr);
381  return route;
382  }
383  return nullptr;
384 }
RouteVector routes
Definition: GenericRoutingTable.h:46
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
bool inet::GenericRoutingTable::isForwardingEnabled ( ) const
overridevirtual

Forwarding on/off.

Implements inet::IRoutingTable.

Referenced by inet::GenericNetworkProtocol::routePacket().

226 {
227  return forwarding;
228 }
bool forwarding
Definition: GenericRoutingTable.h:42
bool inet::GenericRoutingTable::isLocalAddress ( const L3Address dest) const
overridevirtual

Checks if the address is a local one, i.e.

one of the host's.

Implements inet::IRoutingTable.

Referenced by inet::GenericNetworkProtocol::routePacket().

241 {
242  //TODO: Enter_Method("isLocalAddress(%s)", dest.str().c_str());
243 
244  // collect interface addresses if not yet done
245  for (int i = 0; i < ift->getNumInterfaces(); i++) {
246  L3Address interfaceAddr = ift->getInterface(i)->getGenericNetworkProtocolData()->getAddress();
247  if (interfaceAddr == dest)
248  return true;
249  }
250  return false;
251 }
GenericNetworkProtocolInterfaceData * getGenericNetworkProtocolData() const
Definition: InterfaceEntry.h:224
IInterfaceTable * ift
Definition: GenericRoutingTable.h:38
L3Address getAddress() const
Definition: GenericNetworkProtocolInterfaceData.h:60
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
bool inet::GenericRoutingTable::isLocalMulticastAddress ( const L3Address dest) const
overridevirtual

Checks if the address is in one of the local multicast group address list.

Implements inet::IRoutingTable.

Referenced by inet::GenericNetworkProtocol::routeMulticastPacket().

299 {
300  return dest.isMulticast(); //TODO
301 }
bool inet::GenericRoutingTable::isMulticastForwardingEnabled ( ) const
overridevirtual

Multicast forwarding on/off.

Implements inet::IRoutingTable.

231 {
232  return multicastForwarding;
233 }
bool multicastForwarding
Definition: GenericRoutingTable.h:43
virtual int inet::GenericRoutingTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
52 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::GenericRoutingTable::printRoutingTable ( ) const
overridevirtual

Prints routing table.

Implements inet::IRoutingTable.

417 {
418  for (const auto & elem : routes)
419  EV_INFO << (elem)->getInterface()->getFullPath() << " -> " << (elem)->getDestinationAsGeneric().str() << " as " << (elem)->info() << endl;
420 }
RouteVector routes
Definition: GenericRoutingTable.h:46
void inet::GenericRoutingTable::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Called by the signal handler whenever a change of a category occurs to which this client has subscribed.

127 {
128  // TODO:
129 }
void inet::GenericRoutingTable::refreshDisplay ( ) const
overrideprotectedvirtual
201 {
202 //TODO
203 // char buf[80];
204 // if (routerId.isUnspecified())
205 // sprintf(buf, "%d+%d routes", (int)routes.size(), (int)multicastRoutes.size());
206 // else
207 // sprintf(buf, "routerId: %s\n%d+%d routes", routerId.str().c_str(), (int)routes.size(), (int)multicastRoutes.size());
208 // getDisplayString().setTagArg("t", 0, buf);
209 }
IMulticastRoute * inet::GenericRoutingTable::removeMulticastRoute ( IMulticastRoute entry)
overridevirtual

Removes the given route from the routing table, and returns it.

nullptr is returned of the route was not in the routing table.

Implements inet::IRoutingTable.

402 {
403  return nullptr; //TODO
404 }
IRoute * inet::GenericRoutingTable::removeRoute ( IRoute entry)
overridevirtual

Removes the given route from the routing table, and returns it.

nullptr is returned if the route was not in the routing table.

Implements inet::IRoutingTable.

Referenced by deleteRoute().

344 {
345  Enter_Method("removeRoute(...)");
346 
347  GenericRoute *entry = internalRemoveRoute(check_and_cast<GenericRoute *>(route));
348  if (entry) {
349  emit(NF_ROUTE_DELETED, entry);
350  }
351 
352  return entry;
353 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
GenericRoute * internalRemoveRoute(GenericRoute *route)
Definition: GenericRoutingTable.cc:374
void inet::GenericRoutingTable::routeChanged ( GenericRoute entry,
int  fieldCode 
)
virtual

To be called from route objects whenever a field changes.

Used for maintaining internal data structures and firing "routing table changed" notifications.

Referenced by inet::GenericRoute::changed().

132 {
133  if (fieldCode == IRoute::F_DESTINATION || fieldCode == IRoute::F_PREFIX_LENGTH || fieldCode == IRoute::F_METRIC) { // our data structures depend on these fields
134  entry = internalRemoveRoute(entry);
135  ASSERT(entry != nullptr); // failure means inconsistency: route was not found in this routing table
136  internalAddRoute(entry);
137 
138  //invalidateCache();
139  }
140  emit(NF_ROUTE_CHANGED, entry); // TODO include fieldCode in the notification
141 }
Definition: IRoute.h:64
Definition: IRoute.h:57
simsignal_t NF_ROUTE_CHANGED
Definition: NotifierConsts.cc:59
void internalAddRoute(GenericRoute *route)
Definition: GenericRoutingTable.cc:362
GenericRoute * internalRemoveRoute(GenericRoute *route)
Definition: GenericRoutingTable.cc:374
Definition: IRoute.h:58
bool inet::GenericRoutingTable::routeLessThan ( const GenericRoute a,
const GenericRoute b 
)
staticprotected

Referenced by internalAddRoute().

212 {
213  // helper for sort() in addRoute(). We want routes with longer
214  // prefixes to be at front, so we compare them as "less".
215  // For metric, a smaller value is better (we report that as "less").
216  if (a->getPrefixLength() != b->getPrefixLength())
217  return a->getPrefixLength() > b->getPrefixLength();
218 
219  if (a->getDestinationAsGeneric() != b->getDestinationAsGeneric())
220  return a->getDestinationAsGeneric() < b->getDestinationAsGeneric();
221 
222  return a->getMetric() < b->getMetric();
223 }
value< double, units::m > b
Definition: Units.h:1054

Member Data Documentation

L3Address::AddressType inet::GenericRoutingTable::addressType = L3Address::NONE
private

Referenced by configureInterface(), and initialize().

bool inet::GenericRoutingTable::forwarding = false
private

Referenced by initialize(), and isForwardingEnabled().

IInterfaceTable* inet::GenericRoutingTable::ift = nullptr
private
bool inet::GenericRoutingTable::multicastForwarding = false
private
MulticastRouteVector inet::GenericRoutingTable::multicastRoutes
private

Referenced by initialize(), and ~GenericRoutingTable().

L3Address inet::GenericRoutingTable::routerId
private

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