|
INET Framework for OMNeT++/OMNEST
|
Represents the routing table.
More...
#include <Ipv4RoutingTable.h>
|
| virtual int | getNumRoutes () const override |
| | Returns the total number of routes (unicast, multicast, plus the default route). More...
|
| |
| virtual Ipv4Route * | getRoute (int k) const override |
| | Returns the kth route. More...
|
| |
| virtual Ipv4Route * | getDefaultRoute () const override |
| | Finds and returns the default route, or nullptr if it doesn't exist. More...
|
| |
| virtual void | addRoute (Ipv4Route *entry) override |
| | Adds a route to the routing table. More...
|
| |
| virtual Ipv4Route * | removeRoute (Ipv4Route *entry) override |
| | Removes the given route from the routing table, and returns it. More...
|
| |
| virtual bool | deleteRoute (Ipv4Route *entry) override |
| | Removes the given route from the routing table, and delete it. More...
|
| |
| virtual int | getNumMulticastRoutes () const override |
| | Returns the total number of multicast routes. More...
|
| |
| virtual Ipv4MulticastRoute * | getMulticastRoute (int k) const override |
| | Returns the kth multicast route. More...
|
| |
| virtual void | addMulticastRoute (Ipv4MulticastRoute *entry) override |
| | Adds a multicast route to the routing table. More...
|
| |
| virtual Ipv4MulticastRoute * | removeMulticastRoute (Ipv4MulticastRoute *entry) override |
| | Removes the given route from the routing table, and returns it. More...
|
| |
| virtual bool | deleteMulticastRoute (Ipv4MulticastRoute *entry) override |
| | Deletes the given multicast route from the routing table. More...
|
| |
| virtual void | purge () override |
| | Deletes invalid routes from the routing table. More...
|
| |
| virtual std::vector< Ipv4Address > | gatherAddresses () const override |
| | Utility function: Returns a vector of all addresses of the node. More...
|
| |
| virtual void | routeChanged (Ipv4Route *entry, int fieldCode) override |
| | To be called from route objects whenever a field changes. More...
|
| |
| virtual void | multicastRouteChanged (Ipv4MulticastRoute *entry, int fieldCode) override |
| | To be called from multicast route objects whenever a field changes. More...
|
| |
| virtual bool | handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override |
| | ILifecycle method. 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 NetworkInterface * | getInterfaceByAddress (const L3Address &address) const override |
| | Returns an interface given by its address. More...
|
| |
| virtual IRoute * | findBestMatchingRoute (const L3Address &dest) const override |
| | The routing function. More...
|
| |
| virtual NetworkInterface * | getOutputInterfaceForDestination (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...
|
| |
| virtual bool | isLocalMulticastAddress (const L3Address &dest) const override |
| | Checks if the address is in one of the local multicast group address list. More...
|
| |
| virtual IMulticastRoute * | findBestMatchingMulticastRoute (const L3Address &origin, const L3Address &group) const override |
| | Returns route for a multicast origin and group. More...
|
| |
| virtual IRoute * | createRoute () override |
| |
| virtual void | addRoute (IRoute *entry) override |
| | Adds a route to the routing table. More...
|
| |
| virtual IRoute * | removeRoute (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 void | addMulticastRoute (IMulticastRoute *entry) override |
| | Adds a multicast route to the routing table. More...
|
| |
| virtual IMulticastRoute * | removeMulticastRoute (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...
|
| |
Represents the routing table.
This object has one instance per host or router. It has methods to manage the route table and the interface table, so one can achieve functionality similar to the "route" and "ifconfig" commands.
See the NED documentation for general overview.
This is a simple module without gates, it requires function calls to it (message handling does nothing). Methods are provided for reading and updating the interface table and the route table, as well as for unicast and multicast routing.
Interfaces are dynamically registered: at the start of the simulation, every L2 module adds its own interface entry to the table.
The route table is read from a file (RoutingTableParser); the file can also fill in or overwrite interface settings. The route table can also be read and modified during simulation, typically by routing protocol implementations (e.g. OSPF).
Entries in the route table are represented by Ipv4Route objects. Ipv4Route objects can be polymorphic: if a routing protocol needs to store additional data, it can simply subclass from Ipv4Route, and add the derived object to the table.
Uses RoutingTableParser to read routing files (.irt, .mrt).
- See also
- NetworkInterface, Ipv4InterfaceData, Ipv4Route
◆ AddressSet
◆ MulticastRouteVector
◆ OutInterface
◆ OutInterfaceVector
◆ RouteVector
◆ RoutingCache
◆ Ipv4RoutingTable()
| inet::Ipv4RoutingTable::Ipv4RoutingTable |
( |
| ) |
|
|
inline |
◆ ~Ipv4RoutingTable()
| inet::Ipv4RoutingTable::~Ipv4RoutingTable |
( |
| ) |
|
|
virtual |
◆ addMulticastRoute() [1/2]
| virtual void inet::Ipv4RoutingTable::addMulticastRoute |
( |
IMulticastRoute * |
entry | ) |
|
|
inlineoverrideprivatevirtual |
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.
Referenced by addMulticastRoute().
◆ addMulticastRoute() [2/2]
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::IIpv4RoutingTable.
◆ addRoute() [1/2]
| void inet::Ipv4RoutingTable::addRoute |
( |
Ipv4Route * |
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::IIpv4RoutingTable.
537 EV_INFO <<
"add route " << entry->str() <<
"\n";
◆ addRoute() [2/2]
| virtual void inet::Ipv4RoutingTable::addRoute |
( |
IRoute * |
entry | ) |
|
|
inlineoverrideprivatevirtual |
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.
377 {
addRoute(check_and_cast<Ipv4Route *>(entry)); }
Referenced by addRoute().
◆ configureRouterId()
| void inet::Ipv4RoutingTable::configureRouterId |
( |
| ) |
|
|
protectedvirtual |
108 const char *routerIdStr = par(
"routerId");
109 if (!strcmp(routerIdStr,
"auto")) {
111 for (
int i = 0; i <
ift->getNumInterfaces(); ++i) {
112 NetworkInterface *ie =
ift->getInterface(i);
113 if (!ie->isLoopback()) {
114 auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
115 if (ipv4Data && ipv4Data->getIPAddress().getInt() >
routerId.
getInt()) {
116 routerId = ipv4Data->getIPAddress();
126 NetworkInterface *lo0 =
CHK(
ift->findFirstLoopbackInterface());
127 auto ipv4Data = lo0->getProtocolDataForUpdate<Ipv4InterfaceData>();
◆ createNewRoute()
| Ipv4Route * inet::Ipv4RoutingTable::createNewRoute |
( |
| ) |
|
|
protectedvirtual |
783 return new Ipv4Route();
◆ createRoute()
| virtual IRoute* inet::Ipv4RoutingTable::createRoute |
( |
| ) |
|
|
inlineoverridevirtual |
◆ deleteInterfaceRoutes()
| void inet::Ipv4RoutingTable::deleteInterfaceRoutes |
( |
const NetworkInterface * |
entry | ) |
|
|
protectedvirtual |
201 Ipv4Route *route = *it;
202 if (route->getInterface() == entry) {
205 ASSERT(route->getRoutingTable() ==
this);
217 Ipv4MulticastRoute *route = *it;
218 if (route->getInInterface() && route->getInInterface()->getInterface() == entry) {
221 ASSERT(route->getRoutingTable() ==
this);
226 if (route->removeOutInterface(entry)) {
◆ deleteMulticastRoute() [1/2]
| virtual bool inet::Ipv4RoutingTable::deleteMulticastRoute |
( |
IMulticastRoute * |
entry | ) |
|
|
inlineoverrideprivatevirtual |
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.
Referenced by deleteMulticastRoute().
◆ deleteMulticastRoute() [2/2]
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::IIpv4RoutingTable.
673 if (entry !=
nullptr) {
674 ASSERT(entry->getRoutingTable() ==
this);
678 return entry !=
nullptr;
◆ deleteRoute() [1/2]
| bool inet::Ipv4RoutingTable::deleteRoute |
( |
Ipv4Route * |
entry | ) |
|
|
overridevirtual |
Removes the given route from the routing table, and delete it.
Returns true if the route was deleted, and false if it was not in the routing table.
Implements inet::IIpv4RoutingTable.
573 if (entry !=
nullptr) {
574 EV_INFO <<
"delete route " << entry->str() <<
"\n";
575 ASSERT(entry->getRoutingTable() ==
this);
579 return entry !=
nullptr;
◆ deleteRoute() [2/2]
| virtual bool inet::Ipv4RoutingTable::deleteRoute |
( |
IRoute * |
entry | ) |
|
|
inlineoverrideprivatevirtual |
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.
379 {
return deleteRoute(check_and_cast<Ipv4Route *>(entry)); }
Referenced by deleteRoute().
◆ findBestMatchingMulticastRoute() [1/2]
Returns route for a multicast source and multicast group.
Implements inet::IIpv4RoutingTable.
435 Enter_Method(
"getMulticastRoutesFor(%u.%u.%u.%u, %u.%u.%u.%u)",
436 origin.getDByte(0), origin.getDByte(1), origin.getDByte(2), origin.getDByte(3),
437 group.getDByte(0), group.getDByte(1), group.getDByte(2), group.getDByte(3));
442 if (
e->isValid() &&
e->matches(origin, group))
◆ findBestMatchingMulticastRoute() [2/2]
◆ findBestMatchingRoute() [1/2]
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::IIpv4RoutingTable.
393 Enter_Method(
"findBestMatchingRoute(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
397 if (it->second ==
nullptr || it->second->isValid())
403 Ipv4Route *bestRoute =
nullptr;
407 bestRoute =
const_cast<Ipv4Route *
>(
e);
◆ findBestMatchingRoute() [2/2]
| virtual IRoute* inet::Ipv4RoutingTable::findBestMatchingRoute |
( |
const L3Address & |
dest | ) |
const |
|
inlineoverridevirtual |
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 findBestMatchingRoute().
◆ findInterfaceByLocalBroadcastAddress()
Returns the interface entry having the specified address as its local broadcast address.
Implements inet::IIpv4RoutingTable.
334 Enter_Method(
"findInterfaceByLocalBroadcastAddress(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
336 for (
int i = 0; i <
ift->getNumInterfaces(); i++) {
337 NetworkInterface *ie =
ift->getInterface(i);
338 if (!ie->isBroadcast())
340 Ipv4Address interfaceAddr = ie->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
341 Ipv4Address broadcastAddr = interfaceAddr.makeBroadcastAddress(ie->getProtocolData<Ipv4InterfaceData>()->getNetmask());
342 if (broadcastAddr == dest)
◆ gatherAddresses()
| std::vector< Ipv4Address > inet::Ipv4RoutingTable::gatherAddresses |
( |
| ) |
const |
|
overridevirtual |
Utility function: Returns a vector of all addresses of the node.
Implements inet::IIpv4RoutingTable.
287 std::vector<Ipv4Address> addressvector;
289 for (
int i = 0; i <
ift->getNumInterfaces(); ++i)
290 addressvector.push_back(
ift->getInterface(i)->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
291 return addressvector;
◆ getDefaultRoute()
| Ipv4Route * inet::Ipv4RoutingTable::getDefaultRoute |
( |
| ) |
const |
|
overridevirtual |
Finds and returns the default route, or nullptr if it doesn't exist.
Implements inet::IIpv4RoutingTable.
459 for (RouteVector::const_reverse_iterator i =
routes.rbegin(); i !=
routes.rend() && (*i)->getNetmask().isUnspecified(); ++i) {
◆ getGatewayForDestAddr()
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::IIpv4RoutingTable.
427 Enter_Method(
"getGatewayForDestAddr(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
430 return e ?
e->getGateway() : Ipv4Address();
◆ getHostModule()
| cModule * inet::Ipv4RoutingTable::getHostModule |
( |
| ) |
|
|
overridevirtual |
◆ getInterfaceByAddress() [1/2]
Returns an interface given by its address.
Returns nullptr if not found.
Implements inet::IIpv4RoutingTable.
298 Enter_Method(
"getInterfaceByAddress(%u.%u.%u.%u)", addr.getDByte(0), addr.getDByte(1), addr.getDByte(2), addr.getDByte(3));
299 return ift->findInterfaceByAddress(addr);
◆ getInterfaceByAddress() [2/2]
◆ getInterfaceForDestAddr()
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::IIpv4RoutingTable.
419 Enter_Method(
"getInterfaceForDestAddr(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
422 return e ?
e->getInterface() :
nullptr;
◆ getMulticastRoute()
◆ getNextHopForDestination()
| virtual L3Address inet::Ipv4RoutingTable::getNextHopForDestination |
( |
const L3Address & |
dest | ) |
const |
|
inlineoverridevirtual |
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.
◆ getNumMulticastRoutes()
| virtual int inet::Ipv4RoutingTable::getNumMulticastRoutes |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ getNumRoutes()
| virtual int inet::Ipv4RoutingTable::getNumRoutes |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the total number of routes (unicast, multicast, plus the default route).
Implements inet::IRoutingTable.
◆ getOutputInterfaceForDestination()
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.
◆ getRoute()
| Ipv4Route * inet::Ipv4RoutingTable::getRoute |
( |
int |
k | ) |
const |
|
overridevirtual |
◆ getRouterId()
| virtual Ipv4Address inet::Ipv4RoutingTable::getRouterId |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ getRouterIdAsGeneric()
| virtual L3Address inet::Ipv4RoutingTable::getRouterIdAsGeneric |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ handleMessage()
| void inet::Ipv4RoutingTable::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
Raises an error.
146 throw cRuntimeError(
"This module doesn't process messages");
◆ handleOperationStage()
ILifecycle method.
Implements inet::ILifecycle.
749 int stage = operation->getCurrentStage();
750 if (
dynamic_cast<ModuleStartOperation *
>(operation)) {
753 const char *filename = par(
"routingFile");
754 RoutingTableParser parser(
ift,
this);
755 if (*filename && parser.readRoutingTableFromFile(filename) == -1)
756 throw cRuntimeError(
"Error reading routing table file %s", filename);
764 else if (
dynamic_cast<ModuleStopOperation *
>(operation)) {
771 else if (
dynamic_cast<ModuleCrashOperation *
>(operation)) {
◆ initialize()
| void inet::Ipv4RoutingTable::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
55 cSimpleModule::initialize(stage);
66 ift.reference(
this,
"interfaceTableModule",
true);
82 NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule(
"status")) : nullptr;
87 const char *routerIdStr = par(
"routerId");
88 if (strcmp(routerIdStr,
"") && strcmp(routerIdStr,
"auto"))
91 const char *filename = par(
"routingFile");
92 RoutingTableParser parser(
ift,
this);
93 if (*filename && parser.readRoutingTableFromFile(filename) == -1)
94 throw cRuntimeError(
"Error reading routing table file %s", filename);
◆ internalAddMulticastRoute()
602 if (!entry->getOriginNetmask().isValidNetmask())
603 throw cRuntimeError(
"addMulticastRoute(): wrong netmask %s in multicast route", entry->getOriginNetmask().str().c_str());
605 if ((entry->getOrigin().getInt() & ~entry->getOriginNetmask().getInt()) != 0)
606 throw cRuntimeError(
"addMulticastRoute(): suspicious route: origin IP address %s has bits set outside netmask %s",
607 entry->getOrigin().str().c_str(), entry->getOriginNetmask().str().c_str());
609 if (!entry->getMulticastGroup().isUnspecified() && !entry->getMulticastGroup().isMulticast())
610 throw cRuntimeError(
"addMulticastRoute(): group address (%s) is not a multicast address",
611 entry->getMulticastGroup().str().c_str());
614 if (entry->getInInterface() && !entry->getInInterface()->getInterface()->isMulticast())
615 throw cRuntimeError(
"addMulticastRoute(): input interface must be multicast capable");
617 for (
unsigned int i = 0; i < entry->getNumOutInterfaces(); i++) {
618 Ipv4MulticastRoute::OutInterface *outInterface = entry->getOutInterface(i);
620 throw cRuntimeError(
"addMulticastRoute(): output interface cannot be nullptr");
621 else if (!outInterface->getInterface()->isMulticast())
622 throw cRuntimeError(
"addMulticastRoute(): output interface must be multicast capable");
623 else if (entry->getInInterface() && outInterface->getInterface() == entry->getInInterface()->getInterface())
624 throw cRuntimeError(
"addMulticastRoute(): output interface cannot be the same as the input interface");
634 entry->setRoutingTable(
this);
◆ internalAddRoute()
| void inet::Ipv4RoutingTable::internalAddRoute |
( |
Ipv4Route * |
entry | ) |
|
|
protected |
495 if (!entry->getNetmask().isValidNetmask())
496 throw cRuntimeError(
"addRoute(): wrong netmask %s in route", entry->getNetmask().str().c_str());
498 if (entry->getNetmask().getInt() != 0 && (entry->getDestination().getInt() & entry->getNetmask().getInt()) == 0)
499 throw cRuntimeError(
"addRoute(): all bits of destination address %s is 0 inside non zero netmask %s",
500 entry->getDestination().str().c_str(), entry->getNetmask().str().c_str());
502 if ((entry->getDestination().getInt() & ~entry->getNetmask().getInt()) != 0)
503 throw cRuntimeError(
"addRoute(): suspicious route: destination IP address %s has bits set outside netmask %s",
504 entry->getDestination().str().c_str(), entry->getNetmask().str().c_str());
507 if (!entry->getInterface())
508 throw cRuntimeError(
"addRoute(): interface cannot be nullptr");
511 if (entry->getNetmask().isUnspecified()) {
513 if (oldDefaultRoute !=
nullptr)
526 auto pos = upper_bound(
routes.begin(),
routes.end(), entry, RouteLessThan(*
this));
527 routes.insert(pos, entry);
529 entry->setRoutingTable(
this);
◆ internalRemoveMulticastRoute()
◆ internalRemoveRoute()
◆ invalidateCache()
| void inet::Ipv4RoutingTable::invalidateCache |
( |
| ) |
|
|
protectedvirtual |
◆ isAdminDistEnabled()
| virtual bool inet::Ipv4RoutingTable::isAdminDistEnabled |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ isForwardingEnabled()
| virtual bool inet::Ipv4RoutingTable::isForwardingEnabled |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ isLocalAddress() [1/2]
| bool inet::Ipv4RoutingTable::isLocalAddress |
( |
const Ipv4Address & |
dest | ) |
const |
|
overridevirtual |
Checks if the address is a local one, i.e.
one of the host's.
Implements inet::IIpv4RoutingTable.
306 Enter_Method(
"isLocalAddress(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
307 return ift->isLocalAddress(dest);
◆ isLocalAddress() [2/2]
| virtual bool inet::Ipv4RoutingTable::isLocalAddress |
( |
const L3Address & |
dest | ) |
const |
|
inlineoverridevirtual |
◆ isLocalBroadcastAddress()
| bool inet::Ipv4RoutingTable::isLocalBroadcastAddress |
( |
const Ipv4Address & |
dest | ) |
const |
|
overridevirtual |
Checks if the address is a local network broadcast address, i.e.
one of the broadcast addresses derived from the interface addresses and netmasks.
Implements inet::IIpv4RoutingTable.
313 Enter_Method(
"isLocalBroadcastAddress(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
317 for (
int i = 0; i <
ift->getNumInterfaces(); i++) {
318 NetworkInterface *ie =
ift->getInterface(i);
319 if (!ie->isBroadcast())
321 Ipv4Address interfaceAddr = ie->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
322 Ipv4Address broadcastAddr = interfaceAddr.makeBroadcastAddress(ie->getProtocolData<Ipv4InterfaceData>()->getNetmask());
323 if (!broadcastAddr.isUnspecified()) {
◆ isLocalMulticastAddress() [1/2]
| bool inet::Ipv4RoutingTable::isLocalMulticastAddress |
( |
const Ipv4Address & |
dest | ) |
const |
|
overridevirtual |
Checks if the address is in one of the local multicast group address list.
Implements inet::IIpv4RoutingTable.
350 Enter_Method(
"isLocalMulticastAddress(%u.%u.%u.%u)", dest.getDByte(0), dest.getDByte(1), dest.getDByte(2), dest.getDByte(3));
352 for (
int i = 0; i <
ift->getNumInterfaces(); i++) {
353 NetworkInterface *ie =
ift->getInterface(i);
354 if (ie->getProtocolData<Ipv4InterfaceData>()->isMemberOfMulticastGroup(dest))
◆ isLocalMulticastAddress() [2/2]
| virtual bool inet::Ipv4RoutingTable::isLocalMulticastAddress |
( |
const L3Address & |
dest | ) |
const |
|
inlineoverridevirtual |
◆ isMulticastForwardingEnabled()
| virtual bool inet::Ipv4RoutingTable::isMulticastForwardingEnabled |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ multicastRouteChanged()
| void inet::Ipv4RoutingTable::multicastRouteChanged |
( |
Ipv4MulticastRoute * |
entry, |
|
|
int |
fieldCode |
|
) |
| |
|
overridevirtual |
To be called from multicast route objects whenever a field changes.
Used for maintaining internal data structures and firing "routing table changed" notifications.
Implements inet::IIpv4RoutingTable.
697 ASSERT(entry !=
nullptr);
◆ multicastRouteLessThan()
586 if (a->getOriginNetmask() !=
b->getOriginNetmask())
587 return a->getOriginNetmask() >
b->getOriginNetmask();
590 if (a->getOrigin() !=
b->getOrigin())
591 return a->getOrigin() <
b->getOrigin();
594 if (a->getMulticastGroup() !=
b->getMulticastGroup())
595 return a->getMulticastGroup() >
b->getMulticastGroup();
597 return a->getMetric() <
b->getMetric();
◆ numInitStages()
| virtual int inet::Ipv4RoutingTable::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ printMulticastRoutingTable()
| void inet::Ipv4RoutingTable::printMulticastRoutingTable |
( |
| ) |
const |
|
overridevirtual |
For debugging.
Implements inet::IIpv4RoutingTable.
263 EV <<
"-- Multicast routing table --\n";
264 EV <<
stringf(
"%-16s %-16s %-16s %-6s %-6s %s\n",
265 "Source",
"Netmask",
"Group",
"Metric",
"In",
"Outs");
269 EV <<
stringf(
"%-16s %-16s %-16s %-6d %-6s ",
270 route->getOrigin().isUnspecified() ?
"*" : route->getOrigin().str().c_str(),
271 route->getOriginNetmask().isUnspecified() ?
"*" : route->getOriginNetmask().str().c_str(),
272 route->getMulticastGroup().isUnspecified() ?
"*" : route->getMulticastGroup().str().c_str(),
274 !route->getInInterface() ?
"*" : route->getInInterface()->getInterface()->getInterfaceName());
275 for (
unsigned int i = 0; i < route->getNumOutInterfaces(); i++) {
278 EV << route->getOutInterface(i)->getInterface()->getInterfaceName();
◆ printRoutingTable()
| void inet::Ipv4RoutingTable::printRoutingTable |
( |
| ) |
const |
|
overridevirtual |
For debugging.
Implements inet::IRoutingTable.
243 EV <<
"-- Routing table --\n";
244 EV <<
stringf(
"%-16s %-16s %-16s %-4s %-16s %s\n",
245 "Destination",
"Netmask",
"Gateway",
"Iface",
"",
"Metric");
249 NetworkInterface *interfacePtr = route->getInterface();
250 EV <<
stringf(
"%-16s %-16s %-16s %-4s %-16s %6d\n",
251 route->getDestination().isUnspecified() ?
"*" : route->getDestination().str().c_str(),
252 route->getNetmask().isUnspecified() ?
"*" : route->getNetmask().str().c_str(),
253 route->getGateway().isUnspecified() ?
"*" : route->getGateway().str().c_str(),
254 !interfacePtr ?
"*" : interfacePtr->getInterfaceName(),
255 !interfacePtr ?
"(*)" : (std::string(
"(") + interfacePtr->getProtocolData<Ipv4InterfaceData>()->getIPAddress().str() +
")").c_str(),
◆ purge()
| void inet::Ipv4RoutingTable::purge |
( |
| ) |
|
|
overridevirtual |
Deletes invalid routes from the routing table.
Invalid routes are those where the isValid() method returns false.
Implements inet::IIpv4RoutingTable.
364 Ipv4Route *route = *it;
365 if (route->isValid())
370 ASSERT(route->getRoutingTable() ==
this);
378 Ipv4MulticastRoute *route = *it;
379 if (route->isValid())
384 ASSERT(route->getRoutingTable() ==
this);
◆ receiveSignal()
| void inet::Ipv4RoutingTable::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.
151 if (getSimulation()->getContextType() == CTX_INITIALIZE)
154 Enter_Method(
"%s", cComponent::getSignalName(signalID));
165 const NetworkInterface *entry = check_and_cast<const NetworkInterface *>(obj);
171 const auto *ieChangeDetails = check_and_cast<const NetworkInterfaceChangeDetails *>(obj);
172 auto fieldId = ieChangeDetails->getFieldId();
174 const auto *entry = ieChangeDetails->getNetworkInterface();
◆ refreshDisplay()
| void inet::Ipv4RoutingTable::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
141 getDisplayString().setTagArg(
"t", 0, buf);
◆ removeMulticastRoute() [1/2]
|
|
inlineoverrideprivatevirtual |
◆ removeMulticastRoute() [2/2]
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::IIpv4RoutingTable.
661 if (entry !=
nullptr) {
662 ASSERT(entry->getRoutingTable() ==
this);
664 entry->setRoutingTable(
nullptr);
◆ removeRoute() [1/2]
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::IIpv4RoutingTable.
558 if (entry !=
nullptr) {
559 EV_INFO <<
"remove route " << entry->str() <<
"\n";
560 ASSERT(entry->getRoutingTable() ==
this);
562 entry->setRoutingTable(
nullptr);
◆ removeRoute() [2/2]
| virtual IRoute* inet::Ipv4RoutingTable::removeRoute |
( |
IRoute * |
entry | ) |
|
|
inlineoverrideprivatevirtual |
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.
378 {
return removeRoute(check_and_cast<Ipv4Route *>(entry)); }
Referenced by removeRoute().
◆ routeChanged()
| void inet::Ipv4RoutingTable::routeChanged |
( |
Ipv4Route * |
entry, |
|
|
int |
fieldCode |
|
) |
| |
|
overridevirtual |
To be called from route objects whenever a field changes.
Used for maintaining internal data structures and firing "routing table changed" notifications.
Implements inet::IIpv4RoutingTable.
685 ASSERT(entry !=
nullptr);
◆ routeLessThan()
| bool inet::Ipv4RoutingTable::routeLessThan |
( |
const Ipv4Route * |
a, |
|
|
const Ipv4Route * |
b |
|
) |
| const |
|
protected |
472 if (a->getNetmask() !=
b->getNetmask())
473 return a->getNetmask() >
b->getNetmask();
475 if (a->getDestination() !=
b->getDestination())
476 return a->getDestination() <
b->getDestination();
481 if (
useAdminDist && (a->getAdminDist() !=
b->getAdminDist()))
482 return a->getAdminDist() <
b->getAdminDist();
485 return a->getMetric() <
b->getMetric();
◆ setRouterId()
| void inet::Ipv4RoutingTable::setRouterId |
( |
Ipv4Address |
a | ) |
|
|
overridevirtual |
◆ updateNetmaskRoutes()
| void inet::Ipv4RoutingTable::updateNetmaskRoutes |
( |
| ) |
|
|
protectedvirtual |
706 for (
unsigned int k = 0;
k <
routes.size();
k++) {
708 auto it =
routes.begin() + (
k--);
709 Ipv4Route *route = *it;
712 ASSERT(route->getRoutingTable() ==
this);
721 PatternMatcher interfaceNameMatcher(
netmaskRoutes,
false,
true,
true);
722 for (
int i = 0; i <
ift->getNumInterfaces(); i++) {
723 NetworkInterface *ie =
ift->getInterface(i);
724 if (ie->isUp() && interfaceNameMatcher.matches(ie->getFullName())) {
725 auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
729 route->setSource(ie);
730 route->setDestination(ipv4Data->getIPAddress().doAnd(ipv4Data->getNetmask()));
731 route->setNetmask(ipv4Data->getNetmask());
732 route->setGateway(Ipv4Address());
734 route->setMetric(ipv4Data->getMetric());
735 route->setInterface(ie);
736 route->setRoutingTable(
this);
737 auto pos = upper_bound(
routes.begin(),
routes.end(), route, RouteLessThan(*
this));
738 routes.insert(pos, route);
◆ forwarding
| bool inet::Ipv4RoutingTable::forwarding = false |
|
protected |
◆ ift
◆ isNodeUp
| bool inet::Ipv4RoutingTable::isNodeUp = false |
|
protected |
◆ localBroadcastAddresses
| AddressSet inet::Ipv4RoutingTable::localBroadcastAddresses |
|
mutableprotected |
◆ multicastForward
| bool inet::Ipv4RoutingTable::multicastForward = false |
|
protected |
◆ multicastRoutes
◆ netmaskRoutes
| const char* inet::Ipv4RoutingTable::netmaskRoutes = nullptr |
|
protected |
◆ routerId
◆ routes
◆ routingCache
◆ useAdminDist
| bool inet::Ipv4RoutingTable::useAdminDist = false |
|
protected |
The documentation for this class was generated from the following files:
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
#define CHK(x)
Definition: INETDefs.h:87
Stage
Definition: ModuleOperations.h:75
@ F_MULTICASTGROUP
Definition: Ipv4Route.h:150
@ F_STATE
Definition: NetworkInterface.h:146
uint32_t getInt() const
Returns the address as an uint32_t in host byte order (e.g.
Definition: Ipv4Address.h:186
virtual bool deleteMulticastRoute(Ipv4MulticastRoute *entry) override
Deletes the given multicast route from the routing table.
Definition: Ipv4RoutingTable.cc:669
@ F_DESTINATION
Definition: IRoute.h:47
virtual Ipv4Route * createNewRoute()
Definition: Ipv4RoutingTable.cc:781
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:53
static bool multicastRouteLessThan(const Ipv4MulticastRoute *a, const Ipv4MulticastRoute *b)
Definition: Ipv4RoutingTable.cc:582
bool multicastForward
Definition: Ipv4RoutingTable.h:71
virtual NetworkInterface * getInterfaceForDestAddr(const Ipv4Address &dest) const override
Convenience function based on findBestMatchingRoute().
Definition: Ipv4RoutingTable.cc:417
@ dDirectlyConnected
Definition: IRoute.h:61
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
RouteVector routes
Definition: Ipv4RoutingTable.h:94
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:29
simsignal_t routeChangedSignal
Definition: Simsignals.cc:43
const value< double, units::C > e(1.602176487e-19)
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
void printSignalBanner(simsignal_t signalID, const cObject *obj, const cObject *details)
Utility function.
Definition: Simsignals.cc:126
Stage
Definition: ModuleOperations.h:25
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
virtual bool deleteRoute(Ipv4Route *entry) override
Removes the given route from the routing table, and delete it.
Definition: Ipv4RoutingTable.cc:567
virtual void updateNetmaskRoutes()
Definition: Ipv4RoutingTable.cc:703
virtual Ipv4Route * getRoute(int k) const override
Returns the kth route.
Definition: Ipv4RoutingTable.cc:449
virtual void addRoute(Ipv4Route *entry) override
Adds a route to the routing table.
Definition: Ipv4RoutingTable.cc:532
static const Ipv4Address ALLONES_ADDRESS
255.255.255.255
Definition: Ipv4Address.h:94
simsignal_t mrouteDeletedSignal
Definition: Simsignals.cc:45
simsignal_t interfaceDeletedSignal
Definition: Simsignals.cc:31
@ F_CARRIER
Definition: NetworkInterface.h:146
void internalAddRoute(Ipv4Route *entry)
Definition: Ipv4RoutingTable.cc:493
virtual void addMulticastRoute(Ipv4MulticastRoute *entry) override
Adds a multicast route to the routing table.
Definition: Ipv4RoutingTable.cc:637
virtual Ipv4MulticastRoute * getMulticastRoute(int k) const override
Returns the kth multicast route.
Definition: Ipv4RoutingTable.h:313
@ F_ORIGINMASK
Definition: Ipv4Route.h:150
Ipv4Address routerId
Definition: Ipv4RoutingTable.h:68
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
static bool maskedAddrAreEqual(const Ipv4Address &addr1, const Ipv4Address &addr2, const Ipv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: Ipv4Address.cc:249
@ F_ORIGIN
Definition: Ipv4Route.h:150
simsignal_t mrouteAddedSignal
Definition: Simsignals.cc:44
Stage
Definition: ModuleOperations.h:48
Ipv4MulticastRoute * internalRemoveMulticastRoute(Ipv4MulticastRoute *entry)
Definition: Ipv4RoutingTable.cc:644
virtual void invalidateCache()
Definition: Ipv4RoutingTable.cc:235
simsignal_t interfaceStateChangedSignal
Definition: Simsignals.cc:32
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
virtual int getNumMulticastRoutes() const override
Returns the total number of multicast routes.
Definition: Ipv4RoutingTable.h:308
virtual int getNumRoutes() const override
Returns the total number of routes (unicast, multicast, plus the default route).
Definition: Ipv4RoutingTable.h:273
std::string str(bool printUnspec=true) const
Returns the string representation of the address (e.g.
Definition: Ipv4Address.cc:98
bool isNodeUp
Definition: Ipv4RoutingTable.h:72
value< int64_t, units::b > b
Definition: Units.h:1241
simsignal_t routeAddedSignal
Definition: Simsignals.cc:41
std::string stringf(const char *fmt,...)
Accepts a printf-like argument list, and returns the result in a string.
Definition: INETUtils.cc:110
ModuleRefByPar< IInterfaceTable > ift
Definition: Ipv4RoutingTable.h:66
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
virtual Ipv4Route * getDefaultRoute() const override
Finds and returns the default route, or nullptr if it doesn't exist.
Definition: Ipv4RoutingTable.cc:456
virtual Ipv4MulticastRoute * removeMulticastRoute(Ipv4MulticastRoute *entry) override
Removes the given route from the routing table, and returns it.
Definition: Ipv4RoutingTable.cc:655
const double k
Definition: Qam1024Modulation.cc:14
@ STAGE_CRASH
Definition: ModuleOperations.h:76
virtual bool isLocalAddress(const Ipv4Address &dest) const override
Checks if the address is a local one, i.e.
Definition: Ipv4RoutingTable.cc:304
virtual const Ipv4MulticastRoute * findBestMatchingMulticastRoute(const Ipv4Address &origin, const Ipv4Address &group) const override
Returns route for a multicast source and multicast group.
Definition: Ipv4RoutingTable.cc:433
bool forwarding
Definition: Ipv4RoutingTable.h:70
virtual Ipv4Route * removeRoute(Ipv4Route *entry) override
Removes the given route from the routing table, and returns it.
Definition: Ipv4RoutingTable.cc:552
@ UP
Definition: NodeStatus.h:28
#define Enter_Method(...)
Definition: SelfDoc.h:71
void internalAddMulticastRoute(Ipv4MulticastRoute *entry)
Definition: Ipv4RoutingTable.cc:600
simsignal_t routeDeletedSignal
Definition: Simsignals.cc:42
virtual void configureRouterId()
Definition: Ipv4RoutingTable.cc:105
MulticastRouteVector multicastRoutes
Definition: Ipv4RoutingTable.h:97
simsignal_t interfaceIpv4ConfigChangedSignal
Definition: Simsignals.cc:35
bool useAdminDist
Definition: Ipv4RoutingTable.h:73
RoutingCache routingCache
Definition: Ipv4RoutingTable.h:81
virtual NetworkInterface * getInterfaceByAddress(const Ipv4Address &address) const override
Returns an interface given by its address.
Definition: Ipv4RoutingTable.cc:296
Ipv4Route * internalRemoveRoute(Ipv4Route *entry)
Definition: Ipv4RoutingTable.cc:541
simsignal_t mrouteChangedSignal
Definition: Simsignals.cc:46
virtual Ipv4Address getGatewayForDestAddr(const Ipv4Address &dest) const override
Convenience function based on findBestMatchingRoute().
Definition: Ipv4RoutingTable.cc:425
INET_API InitStage INITSTAGE_ROUTER_ID_ASSIGNMENT
Initialization of network addresses.
virtual void deleteInterfaceRoutes(const NetworkInterface *entry)
Definition: Ipv4RoutingTable.cc:197
@ F_PREFIX_LENGTH
Definition: IRoute.h:48
const char * netmaskRoutes
Definition: Ipv4RoutingTable.h:69
AddressSet localBroadcastAddresses
Definition: Ipv4RoutingTable.h:86
simsignal_t interfaceCreatedSignal
Definition: Simsignals.cc:30
@ F_METRIC
Definition: IRoute.h:54
@ STAGE_TRANSPORT_LAYER
Definition: ModuleOperations.h:30
simsignal_t interfaceConfigChangedSignal
Definition: Simsignals.cc:33
bool isUnspecified() const
True if all four address bytes are zero.
Definition: Ipv4Address.h:165
@ F_METRIC
Definition: Ipv4Route.h:150
virtual Ipv4Address getRouterId() const override
Returns routerId.
Definition: Ipv4RoutingTable.h:198
@ IFACENETMASK
comes from an interface's netmask
Definition: IRoute.h:30
virtual bool isLocalMulticastAddress(const Ipv4Address &dest) const override
Checks if the address is in one of the local multicast group address list.
Definition: Ipv4RoutingTable.cc:348
virtual Ipv4Route * findBestMatchingRoute(const Ipv4Address &dest) const override
The routing function.
Definition: Ipv4RoutingTable.cc:391