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

This module configures NextHopRoutingTable modules for a network. More...

#include <NextHopNetworkConfigurator.h>

Inheritance diagram for inet::NextHopNetworkConfigurator:
inet::L3NetworkConfiguratorBase inet::L3AddressResolver

Protected Member Functions

virtual void initialize (int stage) override
 
virtual IRoutingTablefindRoutingTable (Node *node) override
 
virtual void addStaticRoutes (Topology &topology)
 Adds static routes to all routing tables in the network. More...
 
virtual void dumpRoutes (Topology &topology)
 
- Protected Member Functions inherited from inet::L3NetworkConfiguratorBase
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void extractTopology (Topology &topology)
 Extracts network topology by walking through the module hierarchy. More...
 
virtual void extractWiredNeighbors (Topology &topology, Topology::Link *linkOut, LinkInfo *linkInfo, std::map< int, NetworkInterface * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractWirelessNeighbors (Topology &topology, const char *wirelessId, LinkInfo *linkInfo, std::map< int, NetworkInterface * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractDeviceNeighbors (Topology &topology, Node *node, LinkInfo *linkInfo, std::map< int, NetworkInterface * > &interfacesSeen, std::vector< Node * > &deviceNodesVisited)
 
virtual InterfaceInfodetermineGatewayForLink (LinkInfo *linkInfo)
 If this link has exactly one node that connects to other links as well, we can assume it is a "gateway" and return that (we'll use it in routing); otherwise return nullptr. More...
 
virtual double computeNodeWeight (Node *node, const char *metric, cXMLElement *parameters)
 
virtual double computeLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual double computeWiredLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual double computeWirelessLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual bool isBridgeNode (Node *node)
 
virtual bool isWirelessInterface (NetworkInterface *networkInterface)
 
virtual std::string getWirelessId (NetworkInterface *networkInterface)
 If this function returns the same string for two wireless interfaces, they will be regarded as being in the same wireless network. More...
 
virtual InterfaceInfocreateInterfaceInfo (Topology &topology, Node *node, LinkInfo *linkInfo, NetworkInterface *networkInterface)
 
virtual Topology::LinkfindLinkOut (Node *node, int gateId)
 
virtual InterfaceInfofindInterfaceInfo (Node *node, NetworkInterface *networkInterface)
 
virtual IInterfaceTablefindInterfaceTable (Node *node)
 
virtual void dumpTopology (Topology &topology)
 
- Protected Member Functions inherited from inet::L3AddressResolver
virtual bool getIpv4AddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getIpv6AddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getMacAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getModulePathAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getModuleIdAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getInterfaceIpv4Address (L3Address &ret, NetworkInterface *ie, bool mask)
 
virtual bool getInterfaceIpv6Address (L3Address &ret, NetworkInterface *ie, bool mask)
 
virtual bool getInterfaceMacAddress (L3Address &ret, NetworkInterface *ie, bool mask)
 
virtual bool getInterfaceModulePathAddress (L3Address &ret, NetworkInterface *ie, bool mask)
 
virtual bool getInterfaceModuleIdAddress (L3Address &ret, NetworkInterface *ie, bool mask)
 
virtual void doCollectNetworkNodes (cModule *parent, std::vector< cModule * > &result)
 

Protected Attributes

bool addStaticRoutesParameter
 
Topology topology
 
- Protected Attributes inherited from inet::L3NetworkConfiguratorBase
double minLinkWeight = NaN
 
bool configureIsolatedNetworksSeparatly = false
 
cXMLElement * configuration = nullptr
 

Additional Inherited Members

- Public Types inherited from inet::L3AddressResolver
enum  {
  ADDR_IPv4 = 1, ADDR_IPv6 = 2, ADDR_MAC = 4, ADDR_MODULEPATH = 8,
  ADDR_MODULEID = 16, ADDR_MASK = 32
}
 
- Public Member Functions inherited from inet::L3AddressResolver
 L3AddressResolver ()
 
virtual ~L3AddressResolver ()
 
virtual L3Address resolve (const char *str, int addrType=DEFAULT_ADDR_TYPE)
 Accepts dotted decimal notation ("127.0.0.1"), module name of the host or router ("host[2]"), and empty string (""). More...
 
virtual std::vector< L3Addressresolve (std::vector< std::string > strs, int addrType=DEFAULT_ADDR_TYPE)
 Utility function: Calls resolve() for each item in the string vector, and returns the result in an address vector. More...
 
virtual bool tryResolve (const char *str, L3Address &result, int addrType=DEFAULT_ADDR_TYPE)
 Similar to resolve(), but returns false (instead of throwing an error) if the address cannot be resolved because the given host (or interface) doesn't have an address assigned yet. More...
 
bool tryParse (L3Address &result, const char *addr, int addrType=DEFAULT_ADDR_TYPE)
 
virtual L3Address addressOf (cModule *host, int addrType=DEFAULT_ADDR_TYPE)
 Returns Ipv4 or Ipv6 address of the given host or router. More...
 
virtual L3Address addressOf (cModule *host, const char *ifname, int addrType=DEFAULT_ADDR_TYPE)
 Similar to addressOf(), but only looks at the given interface. More...
 
virtual L3Address addressOf (cModule *host, cModule *destmod, int addrType=DEFAULT_ADDR_TYPE)
 Returns Ipv4 or Ipv6 address of the given host or router. More...
 
virtual L3Address routerIdOf (cModule *host)
 Returns the router Id of the given router. More...
 
virtual L3Address getAddressFrom (IInterfaceTable *ift, int addrType=DEFAULT_ADDR_TYPE)
 Returns the Ipv4 or Ipv6 address of the given host or router, given its IInterfaceTable module. More...
 
virtual L3Address getAddressFrom (NetworkInterface *ie, int addrType=DEFAULT_ADDR_TYPE)
 Returns the Ipv4 or Ipv6 address of the given interface (of a host or router). More...
 
virtual IInterfaceTableinterfaceTableOf (cModule *host)
 The function tries to look up the IInterfaceTable module as submodule "interfaceTable" or "networkLayer.interfaceTable" within the host/router module. More...
 
virtual IIpv4RoutingTablegetIpv4RoutingTableOf (cModule *host)
 The function tries to look up the IIpv4RoutingTable module as submodule "routingTable" or "networkLayer.routingTable" within the host/router module. More...
 
virtual Ipv6RoutingTablegetIpv6RoutingTableOf (cModule *host)
 The function tries to look up the Ipv6RoutingTable module as submodule "routingTable6" or "networkLayer.routingTable6" within the host/router module. More...
 
virtual IInterfaceTablefindInterfaceTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual IIpv4RoutingTablefindIpv4RoutingTableOf (cModule *host)
 Like routingTableOf(), but doesn't throw error if not found. More...
 
virtual Ipv6RoutingTablefindIpv6RoutingTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual NextHopRoutingTablefindNextHopRoutingTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual std::vector< cModule * > collectNetworkNodes ()
 Collect modules that represent network nodes, as denoted by the @networkNode(true) annotation. More...
 
virtual cModule * findHostWithAddress (const L3Address &addr)
 Find the Host with the specified address. More...
 
virtual NetworkInterfacefindInterfaceWithMacAddress (const MacAddress &addr)
 Find the interface with the specified MAC address. More...
 
virtual cModule * findHostWithMacAddress (const MacAddress &addr)
 Find the host with the specified MAC address. More...
 

Detailed Description

This module configures NextHopRoutingTable modules for a network.

For more info please see the NED file.

Member Function Documentation

◆ addStaticRoutes()

void inet::NextHopNetworkConfigurator::addStaticRoutes ( Topology topology)
protectedvirtual

Adds static routes to all routing tables in the network.

The algorithm uses Dijkstra's weighted shortest path algorithm. May add default routes and subnet routes if possible and requested.

46 {
47  // TODO it should be configurable (via xml?) which nodes need static routes filled in automatically
48  // add static routes for all routing tables
49  for (int i = 0; i < topology.getNumNodes(); i++) {
50  Node *sourceNode = (Node *)topology.getNode(i);
51  if (isBridgeNode(sourceNode))
52  continue;
53  NextHopRoutingTable *sourceRoutingTable = dynamic_cast<NextHopRoutingTable *>(sourceNode->routingTable);
54 
55  // calculate shortest paths from everywhere to sourceNode
56  // we are going to use the paths in reverse direction (assuming all links are bidirectional)
58 
59  // add a route to all destinations in the network
60  for (int j = 0; j < topology.getNumNodes(); j++) {
61  // extract destination
62  Node *destinationNode = (Node *)topology.getNode(j);
63  if (sourceNode == destinationNode)
64  continue;
65  if (destinationNode->getNumPaths() == 0)
66  continue;
67  if (isBridgeNode(destinationNode))
68  continue;
69  if (std::isinf(destinationNode->getDistanceToTarget()))
70  continue;
71 
72 // int destinationGateId = destinationNode->getPath(0)->getLocalGateId();
73  IInterfaceTable *destinationInterfaceTable = destinationNode->interfaceTable;
74 
75  // determine next hop interface
76  // find next hop interface (the last IP interface on the path that is not in the source node)
77  Node *node = destinationNode;
78  Link *link = nullptr;
79  InterfaceInfo *nextHopInterfaceInfo = nullptr;
80  while (node != sourceNode) {
81  link = (Link *)node->getPath(0);
82  if (node != sourceNode && !isBridgeNode(node) && link->sourceInterfaceInfo && link->sourceInterfaceInfo->networkInterface->findProtocolData<NextHopInterfaceData>())
83  nextHopInterfaceInfo = static_cast<InterfaceInfo *>(link->sourceInterfaceInfo);
84  node = (Node *)node->getPath(0)->getLinkOutRemoteNode();
85  }
86 
87  // determine source interface
88  if (nextHopInterfaceInfo && link->destinationInterfaceInfo && link->destinationInterfaceInfo->addStaticRoute) {
89  NetworkInterface *nextHopNetworkInterface = nextHopInterfaceInfo->networkInterface;
90  NetworkInterface *sourceNetworkInterface = link->destinationInterfaceInfo->networkInterface;
91  // add the same routes for all destination interfaces (IP packets are accepted from any interface at the destination)
92  for (int j = 0; j < destinationInterfaceTable->getNumInterfaces(); j++) {
93  NetworkInterface *destinationNetworkInterface = destinationInterfaceTable->getInterface(j);
94  auto destIeNextHopInterfaceData = destinationNetworkInterface->findProtocolData<NextHopInterfaceData>();
95  if (destIeNextHopInterfaceData == nullptr)
96  continue;
97  L3Address destinationAddress = destIeNextHopInterfaceData->getAddress();
98  if (!destinationNetworkInterface->isLoopback() && !destinationAddress.isUnspecified() && nextHopNetworkInterface->findProtocolData<NextHopInterfaceData>()) {
99  NextHopRoute *route = new NextHopRoute();
100  route->setSourceType(IRoute::MANUAL);
101  route->setDestination(destinationAddress);
102  route->setInterface(sourceNetworkInterface);
103  L3Address nextHopAddress = nextHopNetworkInterface->getProtocolData<NextHopInterfaceData>()->getAddress();
104  if (nextHopAddress != destinationAddress)
105  route->setNextHop(nextHopAddress);
106  EV_DEBUG << "Adding route " << sourceNetworkInterface->getInterfaceFullPath() << " -> " << destinationNetworkInterface->getInterfaceFullPath() << " as " << route->str() << endl;
107  sourceRoutingTable->addRoute(route);
108  }
109  }
110  }
111  }
112  }
113 }

Referenced by initialize().

◆ dumpRoutes()

void inet::NextHopNetworkConfigurator::dumpRoutes ( Topology topology)
protectedvirtual
116 {
117  for (int i = 0; i < topology.getNumNodes(); i++) {
118  Node *node = (Node *)topology.getNode(i);
119  if (node->routingTable) {
120  EV_INFO << "Node " << node->module->getFullPath() << endl;
121  node->routingTable->printRoutingTable();
122  if (node->routingTable->getNumMulticastRoutes() > 0)
123  ; // TODO node->routingTable->printMulticastRoutingTable();
124  }
125  }
126 }

Referenced by initialize().

◆ findRoutingTable()

IRoutingTable * inet::NextHopNetworkConfigurator::findRoutingTable ( Node node)
overrideprotectedvirtual

Reimplemented from inet::L3NetworkConfiguratorBase.

41 {
42  return L3AddressResolver().findNextHopRoutingTableOf(node->module);
43 }

◆ initialize()

void inet::NextHopNetworkConfigurator::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::L3NetworkConfiguratorBase.

18 {
20  if (stage == INITSTAGE_NETWORK_CONFIGURATION) {
21  long initializeStartTime = clock();
22  Topology topology;
23  // extract topology into the Topology object, then fill in a LinkInfo[] vector
25  // dump the result if requested
26  if (par("dumpTopology"))
28  // calculate shortest paths, and add corresponding static routes
29  if (par("addStaticRoutes"))
31  // dump routes to module output
32  if (par("dumpRoutes"))
34  printElapsedTime("initialize", initializeStartTime);
35  }
36 }

Member Data Documentation

◆ addStaticRoutesParameter

bool inet::NextHopNetworkConfigurator::addStaticRoutesParameter
protected

◆ topology

Topology inet::NextHopNetworkConfigurator::topology
protected

The documentation for this class was generated from the following files:
inet::L3NetworkConfiguratorBase::extractTopology
virtual void extractTopology(Topology &topology)
Extracts network topology by walking through the module hierarchy.
Definition: L3NetworkConfiguratorBase.cc:63
inet::INITSTAGE_NETWORK_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_CONFIGURATION
Initialization of network configuration (e.g.
inet::L3NetworkConfiguratorBase::Node::module
cModule * module
Definition: L3NetworkConfiguratorBase.h:33
inet::Topology::calculateWeightedSingleShortestPathsTo
void calculateWeightedSingleShortestPathsTo(Node *target) const
Apply the Dijkstra algorithm to find all shortest paths to the given graph node.
Definition: Topology.cc:406
inet::L3NetworkConfiguratorBase::dumpTopology
virtual void dumpTopology(Topology &topology)
Definition: L3NetworkConfiguratorBase.cc:645
inet::NextHopNetworkConfigurator::addStaticRoutes
virtual void addStaticRoutes(Topology &topology)
Adds static routes to all routing tables in the network.
Definition: NextHopNetworkConfigurator.cc:45
inet::IRoute::MANUAL
@ MANUAL
manually added static route
Definition: IRoute.h:29
inet::NextHopNetworkConfigurator::dumpRoutes
virtual void dumpRoutes(Topology &topology)
Definition: NextHopNetworkConfigurator.cc:115
inet::L3NetworkConfiguratorBase::isBridgeNode
virtual bool isBridgeNode(Node *node)
Definition: L3NetworkConfiguratorBase.cc:264
inet::Topology::getNode
Node * getNode(int i) const
Returns pointer to the ith node in the graph.
Definition: Topology.cc:348
inet::NetworkInterface::findProtocolData
const T * findProtocolData() const
Returns the protocol data for the provided type or returns nullptr if no such protocol data is found.
Definition: NetworkInterface.h:299
inet::L3NetworkConfiguratorBase::Node::interfaceTable
IInterfaceTable * interfaceTable
Definition: L3NetworkConfiguratorBase.h:34
inet::L3NetworkConfiguratorBase::initialize
virtual void initialize(int stage) override
Definition: L3NetworkConfiguratorBase.cc:54
inet::Topology::getNumNodes
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:516
inet::L3AddressResolver::L3AddressResolver
L3AddressResolver()
Definition: L3AddressResolver.h:79
TIME
#define TIME(CODE)
Definition: INETDefs.h:96
inet::NextHopNetworkConfigurator::topology
Topology topology
Definition: NextHopNetworkConfigurator.h:29
inet::IInterfaceTable::getInterface
virtual NetworkInterface * getInterface(int pos) const =0
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
inet::printElapsedTime
void printElapsedTime(const char *name, long startTime)
Definition: INETDefs.h:91