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

This module configures generic routing tables for a network. More...

#include <GenericNetworkConfigurator.h>

Inheritance diagram for inet::GenericNetworkConfigurator:
inet::NetworkConfiguratorBase 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::NetworkConfiguratorBase
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::LinkOut *linkOut, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractWirelessNeighbors (Topology &topology, const char *wirelessId, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractDeviceNeighbors (Topology &topology, Node *node, LinkInfo *linkInfo, std::set< InterfaceEntry * > &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 (InterfaceEntry *interfaceEntry)
 
virtual const char * getWirelessId (InterfaceEntry *interfaceEntry)
 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, InterfaceEntry *interfaceEntry)
 
virtual Topology::LinkOutfindLinkOut (Node *node, int gateId)
 
virtual InterfaceInfofindInterfaceInfo (Node *node, InterfaceEntry *interfaceEntry)
 
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, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceIPv6Address (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceMACAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceModulePathAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceModuleIdAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 

Protected Attributes

bool addStaticRoutesParameter
 
Topology topology
 
- Protected Attributes inherited from inet::NetworkConfiguratorBase
double minLinkWeight = NaN
 
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...
 
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 (InterfaceEntry *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 IIPv4RoutingTableroutingTableOf (cModule *host)
 The function tries to look up the IIPv4RoutingTable module as submodule "routingTable" or "networkLayer.routingTable" within the host/router module. More...
 
virtual IPv6RoutingTableroutingTable6Of (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 GenericRoutingTablefindGenericRoutingTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual cModule * findHostWithAddress (const L3Address &addr)
 Find the Host with the specified address. More...
 

Detailed Description

This module configures generic routing tables for a network.

For more info please see the NED file.

Member Function Documentation

void inet::GenericNetworkConfigurator::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.

Referenced by initialize().

58 {
59  // TODO: it should be configurable (via xml?) which nodes need static routes filled in automatically
60  // add static routes for all routing tables
61  for (int i = 0; i < topology.getNumNodes(); i++) {
62  Node *sourceNode = (Node *)topology.getNode(i);
63  if (isBridgeNode(sourceNode))
64  continue;
65  GenericRoutingTable *sourceRoutingTable = dynamic_cast<GenericRoutingTable *>(sourceNode->routingTable);
66 
67  // calculate shortest paths from everywhere to sourceNode
68  // we are going to use the paths in reverse direction (assuming all links are bidirectional)
70 
71  // add a route to all destinations in the network
72  for (int j = 0; j < topology.getNumNodes(); j++) {
73  // extract destination
74  Node *destinationNode = (Node *)topology.getNode(j);
75  if (sourceNode == destinationNode)
76  continue;
77  if (destinationNode->getNumPaths() == 0)
78  continue;
79  if (isBridgeNode(destinationNode))
80  continue;
81 
82  //int destinationGateId = destinationNode->getPath(0)->getLocalGateId();
83  IInterfaceTable *destinationInterfaceTable = destinationNode->interfaceTable;
84 
85  // determine next hop interface
86  // find next hop interface (the last IP interface on the path that is not in the source node)
87  Node *node = destinationNode;
88  Link *link = nullptr;
89  InterfaceInfo *nextHopInterfaceInfo = nullptr;
90  while (node != sourceNode) {
91  link = (Link *)node->getPath(0);
92  if (node != sourceNode && !isBridgeNode(node) && link->sourceInterfaceInfo && link->sourceInterfaceInfo->interfaceEntry->getGenericNetworkProtocolData())
93  nextHopInterfaceInfo = static_cast<InterfaceInfo *>(link->sourceInterfaceInfo);
94  node = (Node *)node->getPath(0)->getRemoteNode();
95  }
96 
97  // determine source interface
98  if (nextHopInterfaceInfo && link->destinationInterfaceInfo && link->destinationInterfaceInfo->addStaticRoute) {
99  InterfaceEntry *nextHopInterfaceEntry = nextHopInterfaceInfo->interfaceEntry;
100  InterfaceEntry *sourceInterfaceEntry = link->destinationInterfaceInfo->interfaceEntry;
101  // add the same routes for all destination interfaces (IP packets are accepted from any interface at the destination)
102  for (int j = 0; j < destinationInterfaceTable->getNumInterfaces(); j++) {
103  InterfaceEntry *destinationInterfaceEntry = destinationInterfaceTable->getInterface(j);
104  if (!destinationInterfaceEntry->getGenericNetworkProtocolData())
105  continue;
106  L3Address destinationAddress = destinationInterfaceEntry->getGenericNetworkProtocolData()->getAddress();
107  if (!destinationInterfaceEntry->isLoopback() && !destinationAddress.isUnspecified() && nextHopInterfaceEntry->getGenericNetworkProtocolData()) {
108  GenericRoute *route = new GenericRoute();
109  route->setSourceType(IRoute::MANUAL);
110  route->setDestination(destinationAddress);
111  route->setInterface(sourceInterfaceEntry);
112  L3Address nextHopAddress = nextHopInterfaceEntry->getGenericNetworkProtocolData()->getAddress();
113  if (nextHopAddress != destinationAddress)
114  route->setNextHop(nextHopAddress);
115  EV_DEBUG << "Adding route " << sourceInterfaceEntry->getFullPath() << " -> " << destinationInterfaceEntry->getFullPath() << " as " << route->info() << endl;
116  sourceRoutingTable->addRoute(route);
117  }
118  }
119  }
120  }
121  }
122 }
void calculateWeightedSingleShortestPathsTo(Node *target)
Apply the Dijkstra algorithm to find all shortest paths to the given graph node.
Definition: Topology.cc:412
IInterfaceTable * interfaceTable
Definition: NetworkConfiguratorBase.h:53
GenericNetworkProtocolInterfaceData * getGenericNetworkProtocolData() const
Definition: InterfaceEntry.h:224
Node * getNode(int i)
Returns pointer to the ith node in the graph.
Definition: Topology.cc:356
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:522
virtual bool isBridgeNode(Node *node)
Definition: NetworkConfiguratorBase.cc:245
L3Address getAddress() const
Definition: GenericNetworkProtocolInterfaceData.h:60
manually added static route
Definition: IRoute.h:40
Topology topology
Definition: GenericNetworkConfigurator.h:42
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
void inet::GenericNetworkConfigurator::dumpRoutes ( Topology topology)
protectedvirtual

Referenced by initialize().

125 {
126  for (int i = 0; i < topology.getNumNodes(); i++) {
127  Node *node = (Node *)topology.getNode(i);
128  if (node->routingTable) {
129  EV_INFO << "Node " << node->module->getFullPath() << endl;
130  node->routingTable->printRoutingTable();
131  if (node->routingTable->getNumMulticastRoutes() > 0)
132  ; // TODO: node->routingTable->printMulticastRoutingTable();
133  }
134  }
135 }
Node * getNode(int i)
Returns pointer to the ith node in the graph.
Definition: Topology.cc:356
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:522
cModule * module
Definition: NetworkConfiguratorBase.h:52
Topology topology
Definition: GenericNetworkConfigurator.h:42
IRoutingTable * inet::GenericNetworkConfigurator::findRoutingTable ( Node node)
overrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

53 {
54  return L3AddressResolver().findGenericRoutingTableOf(node->module);
55 }
L3AddressResolver()
Definition: L3AddressResolver.h:89
void inet::GenericNetworkConfigurator::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

30 {
32  if (stage == INITSTAGE_NETWORK_LAYER_3) {
33  long initializeStartTime = clock();
34  Topology topology;
35  // extract topology into the Topology object, then fill in a LinkInfo[] vector
36  TIME(extractTopology(topology));
37  // dump the result if requested
38  if (par("dumpTopology").boolValue())
39  TIME(dumpTopology(topology));
40  // calculate shortest paths, and add corresponding static routes
41  if (par("addStaticRoutes").boolValue())
42  TIME(addStaticRoutes(topology));
43  // dump routes to module output
44  if (par("dumpRoutes").boolValue())
45  TIME(dumpRoutes(topology));
46  printElapsedTime("initialize", initializeStartTime);
47  }
48 }
virtual void dumpTopology(Topology &topology)
Definition: NetworkConfiguratorBase.cc:600
virtual void initialize(int stage) override
Definition: NetworkConfiguratorBase.cc:55
virtual void addStaticRoutes(Topology &topology)
Adds static routes to all routing tables in the network.
Definition: GenericNetworkConfigurator.cc:57
Initialization of network-layer protocols, stage 3.
Definition: InitStages.h:84
void printElapsedTime(const char *name, long startTime)
Definition: INETDefs.h:94
virtual void extractTopology(Topology &topology)
Extracts network topology by walking through the module hierarchy.
Definition: NetworkConfiguratorBase.cc:63
Topology topology
Definition: GenericNetworkConfigurator.h:42
#define TIME(CODE)
Definition: INETDefs.h:99
virtual void dumpRoutes(Topology &topology)
Definition: GenericNetworkConfigurator.cc:124

Member Data Documentation

bool inet::GenericNetworkConfigurator::addStaticRoutesParameter
protected
Topology inet::GenericNetworkConfigurator::topology
protected

Referenced by initialize().


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