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

This module provides the global static configuration for the IPv4RoutingTable and the IPv4 network interfaces of all nodes in the network. More...

#include <IPv4NetworkConfigurator.h>

Inheritance diagram for inet::IPv4NetworkConfigurator:
inet::NetworkConfiguratorBase inet::L3AddressResolver

Classes

class  InterfaceInfo
 Represents an interface in the network. More...
 
class  Node
 Represents a node in the network. More...
 
class  RouteInfo
 Simplified route representation used by the optimizer. More...
 
class  RoutingTableInfo
 Simplified routing table representation used by the optimizer. More...
 
class  Topology
 

Public Member Functions

virtual void computeConfiguration ()
 Computes the IPv4 network configuration for all nodes in the network. More...
 
virtual void configureAllInterfaces ()
 Configures all interfaces in the network based on the current network configuration. More...
 
virtual void configureInterface (InterfaceEntry *interfaceEntry)
 Configures the provided interface based on the current network configuration. More...
 
virtual void configureAllRoutingTables ()
 Configures all routing tables in the network based on the current network configuration. More...
 
virtual void configureRoutingTable (IIPv4RoutingTable *routingTable)
 Configures the provided routing table based on the current network configuration. More...
 
- 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...
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void initialize (int stage) override
 
virtual void readInterfaceConfiguration (Topology &topology)
 Reads interface elements from the configuration file and stores result. More...
 
virtual void readMulticastGroupConfiguration (Topology &topology)
 Reads multicast-group elements from the configuration file and stores the result. More...
 
virtual void readManualRouteConfiguration (Topology &topology)
 Reads route elements from configuration file and stores the result. More...
 
virtual void readManualMulticastRouteConfiguration (Topology &topology)
 Reads multicast-route elements from configuration file and stores the result. More...
 
virtual void assignAddresses (Topology &topology)
 Assigns the addresses for all interfaces based on the parameters given in the configuration file. More...
 
virtual void addStaticRoutes (Topology &topology, cXMLElement *element)
 Adds static routes to all routing tables in the network. More...
 
virtual void optimizeRoutes (std::vector< IPv4Route * > &routes)
 Destructively optimizes the given IPv4 routes by merging some of them. More...
 
void ensureConfigurationComputed (Topology &topology)
 
void configureInterface (InterfaceInfo *interfaceInfo)
 
void configureRoutingTable (Node *node)
 
virtual void dumpConfiguration ()
 Prints the current network configuration to the module output. More...
 
virtual void dumpLinks (Topology &topology)
 
virtual void dumpAddresses (Topology &topology)
 
virtual void dumpRoutes (Topology &topology)
 
virtual void dumpConfig (Topology &topology)
 
virtual InterfaceInfocreateInterfaceInfo (NetworkConfiguratorBase::Topology &topology, NetworkConfiguratorBase::Node *node, LinkInfo *linkInfo, InterfaceEntry *interfaceEntry) override
 
virtual void parseAddressAndSpecifiedBits (const char *addressAttr, uint32_t &outAddress, uint32_t &outAddressSpecifiedBits)
 
virtual bool linkContainsMatchingHostExcept (LinkInfo *linkInfo, Matcher *hostMatcher, cModule *exceptModule)
 
virtual const char * getMandatoryAttribute (cXMLElement *element, const char *attr)
 
virtual void resolveInterfaceAndGateway (Node *node, const char *interfaceAttr, const char *gatewayAttr, InterfaceEntry *&outIE, IPv4Address &outGateway, Topology &topology)
 
virtual InterfaceInfofindInterfaceOnLinkByNode (LinkInfo *linkInfo, cModule *node)
 
virtual InterfaceInfofindInterfaceOnLinkByNodeAddress (LinkInfo *linkInfo, IPv4Address address)
 
virtual LinkInfofindLinkOfInterface (Topology &topology, InterfaceEntry *interfaceEntry)
 
virtual IRoutingTablefindRoutingTable (NetworkConfiguratorBase::Node *node) override
 
void collectCompatibleInterfaces (const std::vector< InterfaceInfo * > &interfaces, std::vector< InterfaceInfo * > &compatibleInterfaces, uint32 &mergedAddress, uint32 &mergedAddressSpecifiedBits, uint32 &mergedAddressIncompatibleBits, uint32 &mergedNetmask, uint32 &mergedNetmaskSpecifiedBits, uint32 &mergedNetmaskIncompatibleBits)
 Returns a subset of the given interfaces that have compatible address and netmask specifications. More...
 
bool containsRoute (const std::vector< IPv4Route * > &routes, IPv4Route *route)
 
bool routesHaveSameColor (IPv4Route *route1, IPv4Route *route2)
 Returns true if the two routes are the same except their address prefix and netmask. More...
 
int findRouteIndexWithSameColor (const std::vector< IPv4Route * > &routes, IPv4Route *route)
 Returns the index of the first route that has the same color. More...
 
bool routesCanBeSwapped (RouteInfo *routeInfo1, RouteInfo *routeInfo2)
 Returns true if swapping two ADJACENT routes in the routing table does not change the table's meaning. More...
 
bool routesCanBeNeighbors (const std::vector< RouteInfo * > &routeInfos, int i, int j)
 Returns true if the routes can be neighbors by repeatedly swapping routes in the routing table without changing their meaning. More...
 
bool interruptsOriginalRoute (const RoutingTableInfo &routingTableInfo, int begin, int end, RouteInfo *originalRouteInfo)
 Returns true if the original route is interrupted by any of the routes in the routing table between begin and end. More...
 
bool interruptsAnyOriginalRoute (const RoutingTableInfo &routingTableInfo, int begin, int end, const std::vector< RouteInfo * > &originalRouteInfos)
 Returns true if any of the original routes is interrupted by any of the routes in the routing table between begin and end. More...
 
bool interruptsSubsequentOriginalRoutes (const RoutingTableInfo &routingTableInfo, int index)
 Returns true if any of the original routes attached to the routes in the routing table below index are interrupted by the route at index. More...
 
void checkOriginalRoutes (const RoutingTableInfo &routingTableInfo, const std::vector< RouteInfo * > &originalRouteInfos)
 Asserts that all original routes are still routed the same way as by the original routing table. More...
 
void findLongestCommonDestinationPrefix (uint32 destination1, uint32 netmask1, uint32 destination2, uint32 netmask2, uint32 &destinationOut, uint32 &netmaskOut)
 Returns the longest shared address prefix and netmask by iterating through bits from left to right. More...
 
void addOriginalRouteInfos (RoutingTableInfo &routingTableInfo, int begin, int end, const std::vector< RouteInfo * > &originalRouteInfos)
 Adds all of the original routes to the matching optimized routes between begin and end. More...
 
bool tryToMergeTwoRoutes (RoutingTableInfo &routingTableInfo, int i, int j, RouteInfo *routeInfoI, RouteInfo *routeInfoJ)
 Try to merge two routes that have the same color and could be neighbours in table without changing the table's meaning. More...
 
bool tryToMergeAnyTwoRoutes (RoutingTableInfo &routingTableInfo)
 Iteratively checks if any two routes can be aggressively merged without changing the meaning of all original routes. More...
 
bool getInterfaceIPv4Address (L3Address &ret, InterfaceEntry *interfaceEntry, bool netmask) override
 
- Protected Member Functions inherited from inet::NetworkConfiguratorBase
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 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 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)
 

Static Protected Member Functions

static bool compareInterfaceInfos (InterfaceInfo *i, InterfaceInfo *j)
 

Protected Attributes

bool assignAddressesParameter
 
bool assignDisjunctSubnetAddressesParameter
 
bool addStaticRoutesParameter
 
bool addSubnetRoutesParameter
 
bool addDefaultRoutesParameter
 
bool optimizeRoutesParameter
 
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
}
 

Detailed Description

This module provides the global static configuration for the IPv4RoutingTable and the IPv4 network interfaces of all nodes in the network.

For more info please see the NED file.

Member Function Documentation

void inet::IPv4NetworkConfigurator::addOriginalRouteInfos ( RoutingTableInfo routingTableInfo,
int  begin,
int  end,
const std::vector< RouteInfo * > &  originalRouteInfos 
)
protected

Adds all of the original routes to the matching optimized routes between begin and end.

Referenced by tryToMergeTwoRoutes().

1522 {
1523  for (auto & originalRouteInfo : originalRouteInfos) {
1524  IPv4NetworkConfigurator::RouteInfo *matchingRouteInfo = routingTableInfo.findBestMatchingRouteInfo(originalRouteInfo->destination, begin, end);
1525  ASSERT(matchingRouteInfo && matchingRouteInfo->color == originalRouteInfo->color);
1526  matchingRouteInfo->originalRouteInfos.push_back(originalRouteInfo);
1527  }
1528 }
void inet::IPv4NetworkConfigurator::addStaticRoutes ( Topology topology,
cXMLElement *  element 
)
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 computeConfiguration().

1216 {
1217  // set node weights
1218  const char *metric = autorouteElement->getAttribute("metric");
1219  if (metric == nullptr)
1220  metric = "hopCount";
1221  cXMLElement defaultNodeElement("node", "", nullptr);
1222  cXMLElementList nodeElements = autorouteElement->getChildrenByTagName("node");
1223  for (int i = 0; i < topology.getNumNodes(); i++) {
1224  cXMLElement *selectedNodeElement = &defaultNodeElement;
1225  Node *node = (Node *)topology.getNode(i);
1226  for (auto & nodeElement : nodeElements) {
1227  const char* hosts = nodeElement->getAttribute("hosts");
1228  if (hosts == nullptr)
1229  hosts = "**";
1230  Matcher nodeHostsMatcher(hosts);
1231  std::string hostFullPath = node->module->getFullPath();
1232  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
1233  if (nodeHostsMatcher.matchesAny() || nodeHostsMatcher.matches(hostShortenedFullPath.c_str()) || nodeHostsMatcher.matches(hostFullPath.c_str())) {
1234  selectedNodeElement = nodeElement;
1235  break;
1236  }
1237  }
1238  double weight = computeNodeWeight(node, metric, selectedNodeElement);
1239  EV_DEBUG << "Setting node weight, node = " << node->module->getFullPath() << ", weight = " << weight << endl;
1240  node->setWeight(weight);
1241  }
1242  // set link weights
1243  cXMLElement defaultLinkElement("link", "", nullptr);
1244  cXMLElementList linkElements = autorouteElement->getChildrenByTagName("link");
1245  for (int i = 0; i < topology.getNumNodes(); i++) {
1246  Node *node = (Node *)topology.getNode(i);
1247  for (int j = 0; j < node->getNumInLinks(); j++) {
1248  cXMLElement *selectedLinkElement = &defaultLinkElement;
1249  Link *link = (Link *)node->getLinkIn(j);
1250  for (auto & linkElement : linkElements) {
1251  const char* interfaces = linkElement->getAttribute("interfaces");
1252  if (interfaces == nullptr)
1253  interfaces = "**";
1254  Matcher linkInterfaceMatcher(interfaces);
1255  std::string sourceFullPath = link->sourceInterfaceInfo->getFullPath();
1256  std::string sourceShortenedFullPath = sourceFullPath.substr(sourceFullPath.find('.') + 1);
1257  std::string destinationFullPath = link->destinationInterfaceInfo->getFullPath();
1258  std::string destinationShortenedFullPath = destinationFullPath.substr(destinationFullPath.find('.') + 1);
1259  if (linkInterfaceMatcher.matchesAny() ||
1260  linkInterfaceMatcher.matches(sourceFullPath.c_str()) || linkInterfaceMatcher.matches(sourceShortenedFullPath.c_str()) ||
1261  linkInterfaceMatcher.matches(destinationFullPath.c_str()) || linkInterfaceMatcher.matches(destinationShortenedFullPath.c_str()))
1262  {
1263  selectedLinkElement = linkElement;
1264  break;
1265  }
1266  }
1267  double weight = computeLinkWeight(link, metric, selectedLinkElement);
1268  EV_DEBUG << "Setting link weight, link = " << link << ", weight = " << weight << endl;
1269  link->setWeight(weight);
1270  }
1271  }
1272  // add static routes for all routing tables
1273  const char* sourceHosts = autorouteElement->getAttribute("sourceHosts");
1274  if (sourceHosts == nullptr)
1275  sourceHosts = "**";
1276  const char* destinationInterfaces = autorouteElement->getAttribute("destinationInterfaces");
1277  if (destinationInterfaces == nullptr)
1278  destinationInterfaces = "**";
1279  Matcher sourceHostsMatcher(sourceHosts);
1280  Matcher destinationInterfacesMatcher(destinationInterfaces);
1281  for (int i = 0; i < topology.getNumNodes(); i++) {
1282  Node *sourceNode = (Node *)topology.getNode(i);
1283  std::string hostFullPath = sourceNode->module->getFullPath();
1284  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
1285  if (!sourceHostsMatcher.matchesAny() && !sourceHostsMatcher.matches(hostShortenedFullPath.c_str()) && !sourceHostsMatcher.matches(hostFullPath.c_str()))
1286  continue;
1287  if (isBridgeNode(sourceNode))
1288  continue;
1289  // calculate shortest paths from everywhere to sourceNode
1290  // we are going to use the paths in reverse direction (assuming all links are bidirectional)
1292  // check if adding the default routes would be ok (this is an optimization)
1293  if (addDefaultRoutesParameter && sourceNode->interfaceInfos.size() == 1 && sourceNode->interfaceInfos[0]->linkInfo->gatewayInterfaceInfo && sourceNode->interfaceInfos[0]->addDefaultRoute) {
1294  InterfaceInfo *sourceInterfaceInfo = static_cast<InterfaceInfo *>(sourceNode->interfaceInfos[0]);
1295  InterfaceEntry *sourceInterfaceEntry = sourceInterfaceInfo->interfaceEntry;
1296  InterfaceInfo *gatewayInterfaceInfo = static_cast<InterfaceInfo *>(sourceInterfaceInfo->linkInfo->gatewayInterfaceInfo);
1297  //InterfaceEntry *gatewayInterfaceEntry = gatewayInterfaceInfo->interfaceEntry;
1298 
1299  // add a network route for the local network using ARP
1300  IPv4Route *route = new IPv4Route();
1301  route->setDestination(sourceInterfaceInfo->getAddress().doAnd(sourceInterfaceInfo->getNetmask()));
1302  route->setGateway(IPv4Address::UNSPECIFIED_ADDRESS);
1303  route->setNetmask(sourceInterfaceInfo->getNetmask());
1304  route->setInterface(sourceInterfaceEntry);
1305  route->setSourceType(IPv4Route::MANUAL);
1306  sourceNode->staticRoutes.push_back(route);
1307 
1308  // add a default route towards the only one gateway
1309  route = new IPv4Route();
1310  IPv4Address gateway = gatewayInterfaceInfo->getAddress();
1311  route->setDestination(IPv4Address::UNSPECIFIED_ADDRESS);
1312  route->setNetmask(IPv4Address::UNSPECIFIED_ADDRESS);
1313  route->setGateway(gateway);
1314  route->setInterface(sourceInterfaceEntry);
1315  route->setSourceType(IPv4Route::MANUAL);
1316  sourceNode->staticRoutes.push_back(route);
1317 
1318  // skip building and optimizing the whole routing table
1319  EV_DEBUG << "Adding default routes to " << sourceNode->getModule()->getFullPath() << ", node has only one (non-loopback) interface\n";
1320  }
1321  else {
1322  // add a route to all destinations in the network
1323  for (int j = 0; j < topology.getNumNodes(); j++) {
1324  // extract destination
1325  Node *destinationNode = (Node *)topology.getNode(j);
1326  if (sourceNode == destinationNode)
1327  continue;
1328  if (destinationNode->getNumPaths() == 0)
1329  continue;
1330  if (isBridgeNode(destinationNode))
1331  continue;
1332 
1333  // determine next hop interface
1334  // find next hop interface (the last IP interface on the path that is not in the source node)
1335  Node *node = destinationNode;
1336  Link *link = nullptr;
1337  InterfaceInfo *nextHopInterfaceInfo = nullptr;
1338  while (node != sourceNode) {
1339  link = (Link *)node->getPath(0);
1340  if (node != sourceNode && !isBridgeNode(node) && link->sourceInterfaceInfo)
1341  nextHopInterfaceInfo = static_cast<InterfaceInfo *>(link->sourceInterfaceInfo);
1342  node = (Node *)node->getPath(0)->getRemoteNode();
1343  }
1344 
1345  // determine source interface
1346  if (nextHopInterfaceInfo && link->destinationInterfaceInfo && link->destinationInterfaceInfo->addStaticRoute) {
1347  InterfaceEntry *sourceInterfaceEntry = link->destinationInterfaceInfo->interfaceEntry;
1348  // add the same routes for all destination interfaces (IP packets are accepted from any interface at the destination)
1349  for (int j = 0; j < (int)destinationNode->interfaceInfos.size(); j++) {
1350  InterfaceInfo *destinationInterfaceInfo = static_cast<InterfaceInfo *>(destinationNode->interfaceInfos[j]);
1351  std::string destinationFullPath = destinationInterfaceInfo->interfaceEntry->getFullPath();
1352  std::string destinationShortenedFullPath = destinationFullPath.substr(destinationFullPath.find('.') + 1);
1353  if (!destinationInterfacesMatcher.matchesAny() &&
1354  !destinationInterfacesMatcher.matches(destinationFullPath.c_str()) &&
1355  !destinationInterfacesMatcher.matches(destinationShortenedFullPath.c_str()))
1356  continue;
1357  InterfaceEntry *destinationInterfaceEntry = destinationInterfaceInfo->interfaceEntry;
1358  IPv4Address destinationAddress = destinationInterfaceInfo->getAddress();
1359  IPv4Address destinationNetmask = destinationInterfaceInfo->getNetmask();
1360  if (!destinationInterfaceEntry->isLoopback() && !destinationAddress.isUnspecified()) {
1361  IPv4Route *route = new IPv4Route();
1362  IPv4Address gatewayAddress = nextHopInterfaceInfo->getAddress();
1363  if (addSubnetRoutesParameter && destinationNode->interfaceInfos.size() == 1 && destinationNode->interfaceInfos[0]->linkInfo->gatewayInterfaceInfo
1364  && destinationNode->interfaceInfos[0]->addSubnetRoute)
1365  {
1366  route->setDestination(destinationAddress.doAnd(destinationNetmask));
1367  route->setNetmask(destinationNetmask);
1368  }
1369  else {
1370  route->setDestination(destinationAddress);
1371  route->setNetmask(IPv4Address::ALLONES_ADDRESS);
1372  }
1373  route->setInterface(sourceInterfaceEntry);
1374  if (gatewayAddress != destinationAddress)
1375  route->setGateway(gatewayAddress);
1376  route->setSourceType(IPv4Route::MANUAL);
1377  if (containsRoute(sourceNode->staticRoutes, route))
1378  delete route;
1379  else {
1380  sourceNode->staticRoutes.push_back(route);
1381  EV_DEBUG << "Adding route " << sourceInterfaceEntry->getFullPath() << " -> " << destinationInterfaceEntry->getFullPath() << " as " << route->info() << endl;
1382  }
1383  }
1384  }
1385  }
1386  }
1387 
1388  // optimize routing table to save memory and increase lookup performance
1390  optimizeRoutes(sourceNode->staticRoutes);
1391  }
1392  }
1393 }
void calculateWeightedSingleShortestPathsTo(Node *target)
Apply the Dijkstra algorithm to find all shortest paths to the given graph node.
Definition: Topology.cc:412
LinkOut * getPath(int) const
Returns the next link in the ith shortest paths towards the target node.
Definition: Topology.h:179
bool addSubnetRoutesParameter
Definition: IPv4NetworkConfigurator.h:128
virtual double computeLinkWeight(Link *link, const char *metric, cXMLElement *parameters)
Definition: NetworkConfiguratorBase.cc:298
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
bool optimizeRoutesParameter
Definition: IPv4NetworkConfigurator.h:130
virtual bool isBridgeNode(Node *node)
Definition: NetworkConfiguratorBase.cc:245
virtual void optimizeRoutes(std::vector< IPv4Route * > &routes)
Destructively optimizes the given IPv4 routes by merging some of them.
Definition: IPv4NetworkConfigurator.cc:1631
static const IPv4Address UNSPECIFIED_ADDRESS
0.0.0.0
Definition: IPv4Address.h:102
bool containsRoute(const std::vector< IPv4Route * > &routes, IPv4Route *route)
Definition: IPv4NetworkConfigurator.cc:1207
bool addDefaultRoutesParameter
Definition: IPv4NetworkConfigurator.h:129
Topology topology
Definition: IPv4NetworkConfigurator.h:133
manually added static route
Definition: IRoute.h:40
LinkIn * getLinkIn(int i)
Returns ith incoming link of graph node.
Definition: Topology.cc:33
static const IPv4Address ALLONES_ADDRESS
255.255.255.255
Definition: IPv4Address.h:105
virtual double computeNodeWeight(Node *node, const char *metric, cXMLElement *parameters)
Definition: NetworkConfiguratorBase.cc:285
void inet::IPv4NetworkConfigurator::assignAddresses ( Topology topology)
protectedvirtual

Assigns the addresses for all interfaces based on the parameters given in the configuration file.

See the NED file for details.

Referenced by computeConfiguration().

389 {
390  int bitSize = sizeof(uint32) * 8;
391  std::vector<uint32> assignedNetworkAddresses;
392  std::vector<uint32> assignedNetworkNetmasks;
393  std::vector<uint32> assignedInterfaceAddresses;
394  std::map<uint32, InterfaceEntry *> assignedAddressToInterfaceEntryMap;
395 
396  // iterate through all links and process them separately one by one
397  for (auto & selectedLink : topology.linkInfos) {
398  std::vector<InterfaceInfo *> unconfiguredInterfaces;
399  for (auto & element : selectedLink->interfaceInfos)
400  unconfiguredInterfaces.push_back(static_cast<InterfaceInfo *>(element));
401  // repeat until all interfaces of the selected link become configured
402  // and assign addresses to groups of interfaces having compatible address and netmask specifications
403  while (unconfiguredInterfaces.size() != 0) {
404  // STEP 1.
405  uint32 mergedAddress; // compatible bits of the merged address (both 0 and 1 are address bits)
406  uint32 mergedAddressSpecifiedBits; // mask for the valid compatible bits of the merged address (0 means unspecified, 1 means specified)
407  uint32 mergedAddressIncompatibleBits; // incompatible bits of the merged address (0 means compatible, 1 means incompatible)
408  uint32 mergedNetmask; // compatible bits of the merged netmask (both 0 and 1 are netmask bits)
409  uint32 mergedNetmaskSpecifiedBits; // mask for the compatible bits of the merged netmask (0 means unspecified, 1 means specified)
410  uint32 mergedNetmaskIncompatibleBits; // incompatible bits of the merged netmask (0 means compatible, 1 means incompatible)
411  std::vector<InterfaceInfo *> compatibleInterfaces; // the list of compatible interfaces
412  collectCompatibleInterfaces(unconfiguredInterfaces, compatibleInterfaces, mergedAddress, mergedAddressSpecifiedBits, mergedAddressIncompatibleBits, mergedNetmask, mergedNetmaskSpecifiedBits, mergedNetmaskIncompatibleBits);
413 
414  // STEP 2.
415  // determine the valid range of netmask length by searching from left to right the last 1 and the first 0 bits
416  // also consider the incompatible bits of the address to limit the range of valid netmasks accordingly
417  int minimumNetmaskLength = bitSize - getLeastSignificantBitIndex(mergedNetmask & mergedNetmaskSpecifiedBits, 1, bitSize); // 0 means 0.0.0.0, bitSize means 255.255.255.255
418  int maximumNetmaskLength = bitSize - 1 - getMostSignificantBitIndex(~mergedNetmask & mergedNetmaskSpecifiedBits, 1, -1); // 0 means 0.0.0.0, bitSize means 255.255.255.255
419  maximumNetmaskLength = std::min(maximumNetmaskLength, bitSize - 1 - getMostSignificantBitIndex(mergedAddressIncompatibleBits, 1, -1));
420 
421  // make sure there are enough bits to configure a unique address for all interface
422  // the +2 means that all-0 and all-1 addresses are ruled out
423  int compatibleInterfaceCount = compatibleInterfaces.size() + 2;
424  int interfaceAddressBitCount = getRepresentationBitCount(compatibleInterfaceCount);
425  maximumNetmaskLength = std::min(maximumNetmaskLength, bitSize - interfaceAddressBitCount);
426  EV_TRACE << "Netmask valid length range: " << minimumNetmaskLength << " - " << maximumNetmaskLength << endl;
427 
428  // STEP 3.
429  // determine network address and network netmask by iterating through valid netmasks from longest to shortest
430  int netmaskLength = -1;
431  uint32 networkAddress = 0; // network part of the addresses (e.g. 10.1.1.0)
432  uint32 networkNetmask = 0; // netmask for the network (e.g. 255.255.255.0)
433  ASSERT(maximumNetmaskLength < bitSize);
434  for (netmaskLength = maximumNetmaskLength; netmaskLength >= minimumNetmaskLength; netmaskLength--) {
435  ASSERT(netmaskLength < bitSize);
436  networkNetmask = ~(~((uint32)0) >> netmaskLength);
437  EV_TRACE << "Trying network netmask: " << IPv4Address(networkNetmask) << " : " << netmaskLength << endl;
438  networkAddress = mergedAddress & mergedAddressSpecifiedBits & networkNetmask;
439  uint32 networkAddressUnspecifiedBits = ~mergedAddressSpecifiedBits & networkNetmask; // 1 means the network address unspecified
440  uint32 networkAddressUnspecifiedPartMaximum = 0;
441  for (int i = 0; i < (int)assignedNetworkAddresses.size(); i++) {
442  uint32 assignedNetworkAddress = assignedNetworkAddresses[i];
443  uint32 assignedNetworkNetmask = assignedNetworkNetmasks[i];
444  uint32 assignedNetworkAddressMaximum = assignedNetworkAddress | ~assignedNetworkNetmask;
445  EV_TRACE << "Checking against assigned network address " << IPv4Address(assignedNetworkAddress) << endl;
446  if ((assignedNetworkAddress & ~networkAddressUnspecifiedBits) == (networkAddress & ~networkAddressUnspecifiedBits)) {
447  uint32 assignedAddressUnspecifiedPart = getPackedBits(assignedNetworkAddressMaximum, networkAddressUnspecifiedBits);
448  if (assignedAddressUnspecifiedPart > networkAddressUnspecifiedPartMaximum)
449  networkAddressUnspecifiedPartMaximum = assignedAddressUnspecifiedPart;
450  }
451  }
452  uint32 networkAddressUnspecifiedPartLimit = getPackedBits(~(uint32)0, networkAddressUnspecifiedBits) + (uint32)1;
453  EV_TRACE << "Counting from: " << networkAddressUnspecifiedPartMaximum + (uint32)1 << " to: " << networkAddressUnspecifiedPartLimit << endl;
454 
455  // we start with +1 so that the network address will be more likely different
456  for (uint32 networkAddressUnspecifiedPart = networkAddressUnspecifiedPartMaximum; networkAddressUnspecifiedPart <= networkAddressUnspecifiedPartLimit; networkAddressUnspecifiedPart++) {
457  networkAddress = setPackedBits(networkAddress, networkAddressUnspecifiedBits, networkAddressUnspecifiedPart);
458  EV_TRACE << "Trying network address: " << IPv4Address(networkAddress) << endl;
459 
460  // count interfaces that have the same address prefix
461  int interfaceCount = 0;
462  for (auto & assignedInterfaceAddress : assignedInterfaceAddresses)
463  if ((assignedInterfaceAddress & networkNetmask) == networkAddress)
464  interfaceCount++;
465 
466  if (assignDisjunctSubnetAddressesParameter && interfaceCount != 0)
467  continue;
468  EV_TRACE << "Matching interface count: " << interfaceCount << endl;
469 
470  // check if there's enough room for the interface addresses
471  if ((1 << (bitSize - netmaskLength)) >= interfaceCount + compatibleInterfaceCount)
472  goto found;
473  }
474  }
475  found: if (netmaskLength < minimumNetmaskLength || netmaskLength > maximumNetmaskLength)
476  throw cRuntimeError("Failed to find address prefix (using %s with specified bits %s) and netmask (length from %d bits to %d bits) for interface %s and %d other interface(s). Please refine your parameters and try again!",
477  IPv4Address(mergedAddress).str().c_str(), IPv4Address(mergedAddressSpecifiedBits).str().c_str(), minimumNetmaskLength, maximumNetmaskLength,
478  compatibleInterfaces[0]->interfaceEntry->getFullPath().c_str(), compatibleInterfaces.size() - 1);
479  EV_TRACE << "Selected netmask length: " << netmaskLength << endl;
480  EV_TRACE << "Selected network address: " << IPv4Address(networkAddress) << endl;
481  EV_TRACE << "Selected network netmask: " << IPv4Address(networkNetmask) << endl;
482 
483  // STEP 4.
484  // determine the complete IP address for all compatible interfaces
485  for (auto & compatibleInterface : compatibleInterfaces) {
486  InterfaceEntry *interfaceEntry = compatibleInterface->interfaceEntry;
487  uint32 interfaceAddress = compatibleInterface->address & ~networkNetmask;
488  uint32 interfaceAddressSpecifiedBits = compatibleInterface->addressSpecifiedBits;
489  uint32 interfaceAddressUnspecifiedBits = ~interfaceAddressSpecifiedBits & ~networkNetmask; // 1 means the interface address is unspecified
490  uint32 interfaceAddressUnspecifiedPartMaximum = 0;
491  for (auto & assignedInterfaceAddress : assignedInterfaceAddresses) {
492  uint32 otherInterfaceAddress = assignedInterfaceAddress;
493  if ((otherInterfaceAddress & ~interfaceAddressUnspecifiedBits) == ((networkAddress | interfaceAddress) & ~interfaceAddressUnspecifiedBits)) {
494  uint32 otherInterfaceAddressUnspecifiedPart = getPackedBits(otherInterfaceAddress, interfaceAddressUnspecifiedBits);
495  if (otherInterfaceAddressUnspecifiedPart > interfaceAddressUnspecifiedPartMaximum)
496  interfaceAddressUnspecifiedPartMaximum = otherInterfaceAddressUnspecifiedPart;
497  }
498  }
499  interfaceAddressUnspecifiedPartMaximum++;
500  interfaceAddress = setPackedBits(interfaceAddress, interfaceAddressUnspecifiedBits, interfaceAddressUnspecifiedPartMaximum);
501 
502  // determine the complete address and netmask for interface
503  uint32 completeAddress = networkAddress | interfaceAddress;
504  uint32 completeNetmask = networkNetmask;
505 
506  // check if we could really find a unique IP address
507  if (assignedAddressToInterfaceEntryMap.find(completeAddress) != assignedAddressToInterfaceEntryMap.end())
508  throw cRuntimeError("Failed to configure unique address for %s. Please refine your parameters and try again!", interfaceEntry->getFullPath().c_str());
509  assignedAddressToInterfaceEntryMap[completeAddress] = compatibleInterface->interfaceEntry;
510  assignedInterfaceAddresses.push_back(completeAddress);
511 
512  // configure interface with the selected address and netmask
513  EV_DEBUG << "Setting interface address, interface = " << compatibleInterface->getFullPath() << ", address = " << IPv4Address(completeAddress) << ", netmask = " << IPv4Address(completeNetmask) << endl;
514  compatibleInterface->address = completeAddress;
515  compatibleInterface->addressSpecifiedBits = 0xFFFFFFFF;
516  compatibleInterface->netmask = completeNetmask;
517  compatibleInterface->netmaskSpecifiedBits = 0xFFFFFFFF;
518 
519  // remove configured interface
520  unconfiguredInterfaces.erase(find(unconfiguredInterfaces, compatibleInterface));
521  }
522 
523  // register the network address and netmask as being used
524  assignedNetworkAddresses.push_back(networkAddress);
525  assignedNetworkNetmasks.push_back(networkNetmask);
526  }
527  }
528 }
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
int getRepresentationBitCount(uint32 count)
Returns how many bits are needed to represent count different values.
Definition: IPv4NetworkConfigurator.cc:238
bool assignDisjunctSubnetAddressesParameter
Definition: IPv4NetworkConfigurator.h:126
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
void collectCompatibleInterfaces(const std::vector< InterfaceInfo * > &interfaces, std::vector< InterfaceInfo * > &compatibleInterfaces, uint32 &mergedAddress, uint32 &mergedAddressSpecifiedBits, uint32 &mergedAddressIncompatibleBits, uint32 &mergedNetmask, uint32 &mergedNetmaskSpecifiedBits, uint32 &mergedNetmaskIncompatibleBits)
Returns a subset of the given interfaces that have compatible address and netmask specifications...
Definition: IPv4NetworkConfigurator.cc:326
uint32_t uint32
Definition: Compat.h:30
Topology topology
Definition: IPv4NetworkConfigurator.h:133
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::IPv4NetworkConfigurator::checkOriginalRoutes ( const RoutingTableInfo routingTableInfo,
const std::vector< RouteInfo * > &  originalRouteInfos 
)
protected

Asserts that all original routes are still routed the same way as by the original routing table.

Referenced by optimizeRoutes().

1489 {
1490  // assert that all original routes are routed with the same color
1491  for (auto & originalRouteInfo : originalRouteInfos) {
1492  IPv4NetworkConfigurator::RouteInfo *matchingRouteInfo = routingTableInfo.findBestMatchingRouteInfo(originalRouteInfo->destination);
1493  if (!(matchingRouteInfo && matchingRouteInfo->color == originalRouteInfo->color))
1494  ASSERT(false);
1495  }
1496 }
void inet::IPv4NetworkConfigurator::collectCompatibleInterfaces ( const std::vector< InterfaceInfo * > &  interfaces,
std::vector< InterfaceInfo * > &  compatibleInterfaces,
uint32 mergedAddress,
uint32 mergedAddressSpecifiedBits,
uint32 mergedAddressIncompatibleBits,
uint32 mergedNetmask,
uint32 mergedNetmaskSpecifiedBits,
uint32 mergedNetmaskIncompatibleBits 
)
protected

Returns a subset of the given interfaces that have compatible address and netmask specifications.

Determine the merged address and netmask specifications according to the following table. The '?' symbol means the bit is unspecified, the 'X' symbol means the bit is incompatible. | * | 0 | 1 | ? | | 0 | 0 | X | 0 | | 1 | X | 1 | 1 | | ? | 0 | 1 | ? |

Referenced by assignAddresses().

330 {
331  ASSERT(compatibleInterfaces.empty());
332  mergedAddress = mergedAddressSpecifiedBits = mergedAddressIncompatibleBits = 0;
333  mergedNetmask = mergedNetmaskSpecifiedBits = mergedNetmaskIncompatibleBits = 0;
334 
335  for (auto & interface : interfaces) {
336  IPv4NetworkConfigurator::InterfaceInfo *candidateInterface = interface;
337  InterfaceEntry *ie = candidateInterface->interfaceEntry;
338 
339  // extract candidate interface configuration data
340  uint32 candidateAddress = candidateInterface->address;
341  uint32 candidateAddressSpecifiedBits = candidateInterface->addressSpecifiedBits;
342  uint32 candidateNetmask = candidateInterface->netmask;
343  uint32 candidateNetmaskSpecifiedBits = candidateInterface->netmaskSpecifiedBits;
344  EV_TRACE << "Trying to merge " << ie->getFullPath() << " interface with address specification: " << IPv4Address(candidateAddress) << " / " << IPv4Address(candidateAddressSpecifiedBits) << endl;
345  EV_TRACE << "Trying to merge " << ie->getFullPath() << " interface with netmask specification: " << IPv4Address(candidateNetmask) << " / " << IPv4Address(candidateNetmaskSpecifiedBits) << endl;
346 
347  // determine merged netmask bits
348  uint32 commonNetmaskSpecifiedBits = mergedNetmaskSpecifiedBits & candidateNetmaskSpecifiedBits;
349  uint32 newMergedNetmask = mergedNetmask | (candidateNetmask & candidateNetmaskSpecifiedBits);
350  uint32 newMergedNetmaskSpecifiedBits = mergedNetmaskSpecifiedBits | candidateNetmaskSpecifiedBits;
351  uint32 newMergedNetmaskIncompatibleBits = mergedNetmaskIncompatibleBits | ((mergedNetmask & commonNetmaskSpecifiedBits) ^ (candidateNetmask & commonNetmaskSpecifiedBits));
352 
353  // skip interface if there's a bit where the netmasks are incompatible
354  if (newMergedNetmaskIncompatibleBits != 0)
355  continue;
356 
357  // determine merged address bits
358  uint32 commonAddressSpecifiedBits = mergedAddressSpecifiedBits & candidateAddressSpecifiedBits;
359  uint32 newMergedAddress = mergedAddress | (candidateAddress & candidateAddressSpecifiedBits);
360  uint32 newMergedAddressSpecifiedBits = mergedAddressSpecifiedBits | candidateAddressSpecifiedBits;
361  uint32 newMergedAddressIncompatibleBits = mergedAddressIncompatibleBits | ((mergedAddress & commonAddressSpecifiedBits) ^ (candidateAddress & commonAddressSpecifiedBits));
362 
363  // skip interface if there's a bit where the netmask is 1 and the addresses are incompatible
364  if ((newMergedNetmask & newMergedNetmaskSpecifiedBits & newMergedAddressIncompatibleBits) != 0)
365  continue;
366 
367  // store merged address bits
368  mergedAddress = newMergedAddress;
369  mergedAddressSpecifiedBits = newMergedAddressSpecifiedBits;
370  mergedAddressIncompatibleBits = newMergedAddressIncompatibleBits;
371 
372  // store merged netmask bits
373  mergedNetmask = newMergedNetmask;
374  mergedNetmaskSpecifiedBits = newMergedNetmaskSpecifiedBits;
375  mergedNetmaskIncompatibleBits = newMergedNetmaskIncompatibleBits;
376 
377  // add interface to the list of compatible interfaces
378  compatibleInterfaces.push_back(candidateInterface);
379  EV_TRACE << "Merged address specification: " << IPv4Address(mergedAddress) << " / " << IPv4Address(mergedAddressSpecifiedBits) << " / " << IPv4Address(mergedAddressIncompatibleBits) << endl;
380  EV_TRACE << "Merged netmask specification: " << IPv4Address(mergedNetmask) << " / " << IPv4Address(mergedNetmaskSpecifiedBits) << " / " << IPv4Address(mergedNetmaskIncompatibleBits) << endl;
381  }
382  // sort compatibleInterfaces moving the most constrained interfaces first
383  // (stable sort tp garantee identical order if the interfaces are similarly constrained)
384  std::stable_sort(compatibleInterfaces.begin(), compatibleInterfaces.end(), compareInterfaceInfos);
385  EV_TRACE << "Found " << compatibleInterfaces.size() << " compatible interfaces" << endl;
386 }
static bool compareInterfaceInfos(InterfaceInfo *i, InterfaceInfo *j)
Definition: IPv4NetworkConfigurator.cc:312
uint32_t uint32
Definition: Compat.h:30
bool inet::IPv4NetworkConfigurator::compareInterfaceInfos ( InterfaceInfo i,
InterfaceInfo j 
)
staticprotected

Referenced by collectCompatibleInterfaces().

313 {
314  return i->addressSpecifiedBits > j->addressSpecifiedBits;
315 }
void inet::IPv4NetworkConfigurator::computeConfiguration ( )
virtual

Computes the IPv4 network configuration for all nodes in the network.

The result of the computation is only stored in the network configurator.

Referenced by ensureConfigurationComputed().

82 {
83  EV_INFO << "Computing static network configuration (addresses and routes).\n";
84  long initializeStartTime = clock();
85  topology.clear();
86  // extract topology into the Topology object, then fill in a LinkInfo[] vector
88  // read the configuration from XML; it will serve as input for address assignment
90  // assign addresses to IPv4 nodes
93  // read and configure multicast groups from the XML configuration
95  // read and configure manual routes from the XML configuration
97  // read and configure manual multicast routes from the XML configuration
99  // calculate shortest paths, and add corresponding static routes
101  cXMLElementList autorouteElements = configuration->getChildrenByTagName("autoroute");
102  if (autorouteElements.size() == 0) {
103  cXMLElement defaultAutorouteElement("autoroute", "", nullptr);
104  TIME(addStaticRoutes(topology, &defaultAutorouteElement));
105  }
106  else {
107  for (auto & autorouteElement : autorouteElements)
108  TIME(addStaticRoutes(topology, autorouteElement));
109  }
110  }
111  printElapsedTime("computeConfiguration", initializeStartTime);
112 }
bool addStaticRoutesParameter
Definition: IPv4NetworkConfigurator.h:127
virtual void readManualRouteConfiguration(Topology &topology)
Reads route elements from configuration file and stores the result.
Definition: IPv4NetworkConfigurator.cc:935
virtual void addStaticRoutes(Topology &topology, cXMLElement *element)
Adds static routes to all routing tables in the network.
Definition: IPv4NetworkConfigurator.cc:1215
virtual void assignAddresses(Topology &topology)
Assigns the addresses for all interfaces based on the parameters given in the configuration file...
Definition: IPv4NetworkConfigurator.cc:388
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
void printElapsedTime(const char *name, long startTime)
Definition: INETDefs.h:94
virtual void readInterfaceConfiguration(Topology &topology)
Reads interface elements from the configuration file and stores result.
Definition: IPv4NetworkConfigurator.cc:549
bool assignAddressesParameter
Definition: IPv4NetworkConfigurator.h:125
virtual void readMulticastGroupConfiguration(Topology &topology)
Reads multicast-group elements from the configuration file and stores the result. ...
Definition: IPv4NetworkConfigurator.cc:873
virtual void extractTopology(Topology &topology)
Extracts network topology by walking through the module hierarchy.
Definition: NetworkConfiguratorBase.cc:63
Topology topology
Definition: IPv4NetworkConfigurator.h:133
virtual void readManualMulticastRouteConfiguration(Topology &topology)
Reads multicast-route elements from configuration file and stores the result.
Definition: IPv4NetworkConfigurator.cc:996
#define TIME(CODE)
Definition: INETDefs.h:99
void clear()
Deletes the topology stored in the object.
Definition: Topology.cc:86
void inet::IPv4NetworkConfigurator::configureAllInterfaces ( )
virtual

Configures all interfaces in the network based on the current network configuration.

140 {
142  EV_INFO << "Configuring all network interfaces.\n";
143  for (int i = 0; i < topology.getNumNodes(); i++) {
144  Node *node = (Node *)topology.getNode(i);
145  for (auto & elem : node->interfaceInfos) {
146  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(elem);
147  if (interfaceInfo->configure)
148  configureInterface(interfaceInfo);
149  }
150  }
151 }
void ensureConfigurationComputed(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:114
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 void configureInterface(InterfaceEntry *interfaceEntry)
Configures the provided interface based on the current network configuration.
Definition: IPv4NetworkConfigurator.cc:153
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::configureAllRoutingTables ( )
virtual

Configures all routing tables in the network based on the current network configuration.

165 {
167  EV_INFO << "Configuring all routing tables.\n";
168  for (int i = 0; i < topology.getNumNodes(); i++) {
169  Node *node = (Node *)topology.getNode(i);
170  if (node->routingTable)
171  configureRoutingTable(node);
172  }
173 }
void ensureConfigurationComputed(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:114
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 void configureRoutingTable(IIPv4RoutingTable *routingTable)
Configures the provided routing table based on the current network configuration. ...
Definition: IPv4NetworkConfigurator.cc:175
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::configureInterface ( InterfaceEntry interfaceEntry)
virtual

Configures the provided interface based on the current network configuration.

Referenced by configureAllInterfaces(), and inet::IPv4NodeConfigurator::configureInterface().

154 {
156  auto it = topology.interfaceInfos.find(interfaceEntry);
157  if (it != topology.interfaceInfos.end()) {
158  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(it->second);
159  if (interfaceInfo->configure)
160  configureInterface(interfaceInfo);
161  }
162 }
std::map< InterfaceEntry *, InterfaceInfo * > interfaceInfos
Definition: NetworkConfiguratorBase.h:118
void ensureConfigurationComputed(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:114
virtual void configureInterface(InterfaceEntry *interfaceEntry)
Configures the provided interface based on the current network configuration.
Definition: IPv4NetworkConfigurator.cc:153
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::configureInterface ( InterfaceInfo interfaceInfo)
protected
187 {
188  EV_DETAIL << "Configuring network interface " << interfaceInfo->getFullPath() << ".\n";
189  InterfaceEntry *interfaceEntry = interfaceInfo->interfaceEntry;
190  IPv4InterfaceData *interfaceData = interfaceEntry->ipv4Data();
191  if (interfaceInfo->mtu != -1)
192  interfaceEntry->setMtu(interfaceInfo->mtu);
193  if (interfaceInfo->metric != -1)
194  interfaceData->setMetric(interfaceInfo->metric);
196  interfaceData->setIPAddress(IPv4Address(interfaceInfo->address));
197  interfaceData->setNetmask(IPv4Address(interfaceInfo->netmask));
198  }
199  // TODO: should we leave joined multicast groups first?
200  for (auto & multicastGroup : interfaceInfo->multicastGroups)
201  interfaceData->joinMulticastGroup(multicastGroup);
202 }
bool assignAddressesParameter
Definition: IPv4NetworkConfigurator.h:125
void inet::IPv4NetworkConfigurator::configureRoutingTable ( IIPv4RoutingTable routingTable)
virtual

Configures the provided routing table based on the current network configuration.

Referenced by configureAllRoutingTables(), and inet::IPv4NodeConfigurator::configureRoutingTable().

176 {
178  // TODO: avoid linear search
179  for (int i = 0; i < topology.getNumNodes(); i++) {
180  Node *node = (Node *)topology.getNode(i);
181  if (node->routingTable == routingTable)
182  configureRoutingTable(node);
183  }
184 }
void ensureConfigurationComputed(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:114
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 void configureRoutingTable(IIPv4RoutingTable *routingTable)
Configures the provided routing table based on the current network configuration. ...
Definition: IPv4NetworkConfigurator.cc:175
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::configureRoutingTable ( Node node)
protected
205 {
206  EV_DETAIL << "Configuring routing table of " << node->getModule()->getFullPath() << ".\n";
207  for (int i = 0; i < (int)node->staticRoutes.size(); i++) {
208  IPv4Route *original = node->staticRoutes[i];
209  IPv4Route *clone = new IPv4Route();
210  clone->setMetric(original->getMetric());
211  clone->setSourceType(original->getSourceType());
212  clone->setSource(original->getSource());
213  clone->setDestination(original->getDestination());
214  clone->setNetmask(original->getNetmask());
215  clone->setGateway(original->getGateway());
216  clone->setInterface(original->getInterface());
217  node->routingTable->addRoute(clone);
218  }
219  for (int i = 0; i < (int)node->staticMulticastRoutes.size(); i++) {
220  IPv4MulticastRoute *original = node->staticMulticastRoutes[i];
221  IPv4MulticastRoute *clone = new IPv4MulticastRoute();
222  clone->setMetric(original->getMetric());
223  clone->setSourceType(original->getSourceType());
224  clone->setSource(original->getSource());
225  clone->setOrigin(original->getOrigin());
226  clone->setOriginNetmask(original->getOriginNetmask());
227  clone->setInInterface(original->getInInterface());
228  clone->setMulticastGroup(original->getMulticastGroup());
229  for (int j = 0; j < (int)original->getNumOutInterfaces(); j++)
230  clone->addOutInterface(new IMulticastRoute::OutInterface(*original->getOutInterface(j)));
231  node->routingTable->addMulticastRoute(clone);
232  }
233 }
bool inet::IPv4NetworkConfigurator::containsRoute ( const std::vector< IPv4Route * > &  routes,
IPv4Route route 
)
protected

Referenced by addStaticRoutes().

1208 {
1209  for (auto & rt : routes)
1210  if (*rt == *route)
1211  return true;
1212  return false;
1213 }
IPv4NetworkConfigurator::InterfaceInfo * inet::IPv4NetworkConfigurator::createInterfaceInfo ( NetworkConfiguratorBase::Topology topology,
NetworkConfiguratorBase::Node node,
LinkInfo linkInfo,
InterfaceEntry interfaceEntry 
)
overrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

531 {
532  InterfaceInfo *interfaceInfo = new InterfaceInfo(static_cast<IPv4NetworkConfigurator::Node *>(node), linkInfo, ie);
533  IPv4InterfaceData *ipv4Data = ie->ipv4Data();
534  if (ipv4Data) {
535  IPv4Address address = ipv4Data->getIPAddress();
536  IPv4Address netmask = ipv4Data->getNetmask();
537  if (!address.isUnspecified()) {
538  interfaceInfo->address = address.getInt();
539  interfaceInfo->addressSpecifiedBits = 0xFFFFFFFF;
540  interfaceInfo->netmask = netmask.getInt();
541  interfaceInfo->netmaskSpecifiedBits = 0xFFFFFFFF;
542  }
543  }
544  node->interfaceInfos.push_back(interfaceInfo);
545  topology.interfaceInfos[ie] = interfaceInfo;
546  return interfaceInfo;
547 }
std::map< InterfaceEntry *, InterfaceInfo * > interfaceInfos
Definition: NetworkConfiguratorBase.h:118
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::dumpAddresses ( Topology topology)
protectedvirtual

Referenced by dumpConfiguration().

702 {
703  for (int i = 0; i < (int)topology.linkInfos.size(); i++) {
704  EV_INFO << "Link " << i << endl;
705  LinkInfo *linkInfo = topology.linkInfos[i];
706  for (auto & interfaceInfo : linkInfo->interfaceInfos) {
707  InterfaceEntry *interfaceEntry = interfaceInfo->interfaceEntry;
708  cModule *host = interfaceInfo->node->module;
709  EV_INFO << " " << host->getFullName() << " / " << interfaceEntry->info() << endl;
710  }
711  }
712 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::dumpConfig ( Topology topology)
protectedvirtual

Referenced by dumpConfiguration().

728 {
729  FILE *f;
730  f = fopen(par("dumpConfig").stringValue(), "w");
731  if (!f)
732  throw cRuntimeError("Cannot write configurator output file");
733  fprintf(f, "<config>\n");
734 
735  // interfaces
736  for (auto & linkInfo : topology.linkInfos) {
737  for (auto & element : linkInfo->interfaceInfos) {
738  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
739  InterfaceEntry *interfaceEntry = interfaceInfo->interfaceEntry;
740  IPv4InterfaceData *interfaceData = interfaceEntry->ipv4Data();
741  std::stringstream stream;
742  stream << " <interface hosts=\"" << interfaceInfo->node->module->getFullPath() << "\" names=\"" << interfaceEntry->getName()
743  << "\" address=\"" << interfaceData->getIPAddress() << "\" netmask=\"" << interfaceData->getNetmask()
744  << "\" metric=\"" << interfaceData->getMetric()
745  << "\"/>" << endl;
746  fprintf(f, "%s", stream.str().c_str());
747  }
748  }
749 
750  // multicast groups
751  for (auto & linkInfo : topology.linkInfos) {
752  for (auto & element : linkInfo->interfaceInfos) {
753  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
754  InterfaceEntry *interfaceEntry = interfaceInfo->interfaceEntry;
755  IPv4InterfaceData *interfaceData = interfaceEntry->ipv4Data();
756  int numOfMulticastGroups = interfaceData->getNumOfJoinedMulticastGroups();
757  if (numOfMulticastGroups > 0) {
758  std::stringstream stream;
759  stream << " <multicast-group hosts=\"" << interfaceInfo->node->module->getFullPath() << "\" interfaces=\"" << interfaceEntry->getName() << "\" address=\"";
760  for (int k = 0; k < numOfMulticastGroups; k++) {
761  IPv4Address address = interfaceData->getJoinedMulticastGroup(k);
762  if (k)
763  stream << " ";
764  stream << address.str();
765  }
766  stream << "\"/>" << endl;
767  fprintf(f, "%s", stream.str().c_str());
768  }
769  }
770  }
771 
772  // wireless links
773  for (auto & linkInfo: topology.linkInfos) {
774  bool hasWireless = false;
775  for (auto & element : linkInfo->interfaceInfos) {
776  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
777  if (isWirelessInterface(interfaceInfo->interfaceEntry))
778  hasWireless = true;
779  }
780  if (hasWireless) {
781  bool first = true;
782  std::stringstream stream;
783  stream << " <wireless interfaces=\"";
784  for (auto & element : linkInfo->interfaceInfos) {
785  if (!first)
786  stream << " ";
787  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
788  if (isWirelessInterface(interfaceInfo->interfaceEntry)) {
789  stream << interfaceInfo->node->module->getFullPath() << "%" << interfaceInfo->interfaceEntry->getName();
790  first = false;
791  }
792  }
793  stream << "\"/>" << endl;
794  fprintf(f, "%s", stream.str().c_str());
795  }
796  }
797 
798  // routes
799  for (int i = 0; i < topology.getNumNodes(); i++) {
800  Node *node = (Node *)topology.getNode(i);
801  IIPv4RoutingTable *routingTable = dynamic_cast<IIPv4RoutingTable *>(node->routingTable);
802  if (routingTable) {
803  for (int j = 0; j < routingTable->getNumRoutes(); j++) {
804  IPv4Route *route = routingTable->getRoute(j);
805  std::stringstream stream;
806  IPv4Address netmask = route->getNetmask();
807  IPv4Address gateway = route->getGateway();
808  stream << " <route hosts=\"" << node->module->getFullPath();
809  stream << "\" destination=\"";
810  if (route->getDestination().isUnspecified())
811  stream << "*";
812  else
813  stream << route->getDestination();
814  stream << "\" netmask=\"";
815  if (route->getNetmask().isUnspecified())
816  stream << "*";
817  else
818  stream << route->getNetmask();
819  stream << "\" gateway=\"";
820  if (route->getGateway().isUnspecified())
821  stream << "*";
822  else
823  stream << route->getGateway();
824  stream << "\" interface=\"" << route->getInterfaceName() << "\" metric=\"" << route->getMetric() << "\"/>" << endl;
825  fprintf(f, "%s", stream.str().c_str());
826  }
827  }
828  }
829 
830  // multicast routes
831  for (int i = 0; i < topology.getNumNodes(); i++) {
832  Node *node = (Node *)topology.getNode(i);
833  IIPv4RoutingTable *routingTable = dynamic_cast<IIPv4RoutingTable *>(node->routingTable);
834  if (routingTable) {
835  for (int j = 0; j < routingTable->getNumMulticastRoutes(); j++) {
836  IPv4MulticastRoute *route = routingTable->getMulticastRoute(j);
837  std::stringstream stream;
838  stream << " <multicast-route hosts=\"" << node->module->getFullPath();
839  stream << "\" source=\"";
840  if (route->getOrigin().isUnspecified())
841  stream << "*";
842  else
843  stream << route->getOrigin();
844  stream << "\" netmask=\"";
845  if (route->getOriginNetmask().isUnspecified())
846  stream << "*";
847  else
848  stream << route->getOriginNetmask();
849  stream << "\" groups=\"";
850  if (route->getMulticastGroup().isUnspecified())
851  stream << "*";
852  else
853  stream << route->getMulticastGroup();
854  if (route->getInInterface())
855  stream << "\" parent=\"" << route->getInInterface()->getInterface()->getName();
856  stream << "\" children=\"";
857  for (unsigned int k = 0; k < route->getNumOutInterfaces(); k++) {
858  if (k)
859  stream << " ";
860  stream << route->getOutInterface(k)->getInterface()->getName();
861  }
862  stream << "\" metric=\"" << route->getMetric() << "\"/>" << endl;
863  fprintf(f, "%s", stream.str().c_str());
864  }
865  }
866  }
867 
868  fprintf(f, "</config>");
869  fflush(f);
870  fclose(f);
871 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
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 isWirelessInterface(InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:250
cModule * module
Definition: NetworkConfiguratorBase.h:52
#define stringValue()
Definition: NedFunctions.cc:24
Topology topology
Definition: IPv4NetworkConfigurator.h:133
const double k
Definition: QAM16Modulation.cc:24
void inet::IPv4NetworkConfigurator::dumpConfiguration ( )
protectedvirtual

Prints the current network configuration to the module output.

Referenced by initialize().

121 {
122  // print topology to module output
123  if (par("dumpTopology").boolValue())
125  // print links to module output
126  if (par("dumpLinks").boolValue())
128  // print unicast and multicast addresses and other interface data to module output
129  if (par("dumpAddresses").boolValue())
131  // print routes to module output
132  if (par("dumpRoutes").boolValue())
134  // print current configuration to an XML file
135  if (!isEmpty(par("dumpConfig")))
137 }
virtual void dumpTopology(Topology &topology)
Definition: NetworkConfiguratorBase.cc:600
virtual void dumpAddresses(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:701
virtual void dumpLinks(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:689
Topology topology
Definition: IPv4NetworkConfigurator.h:133
#define TIME(CODE)
Definition: INETDefs.h:99
bool isEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:35
virtual void dumpConfig(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:727
virtual void dumpRoutes(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:714
void inet::IPv4NetworkConfigurator::dumpLinks ( Topology topology)
protectedvirtual

Referenced by dumpConfiguration().

690 {
691  for (int i = 0; i < (int)topology.linkInfos.size(); i++) {
692  EV_INFO << "Link " << i << endl;
693  LinkInfo *linkInfo = topology.linkInfos[i];
694  for (auto & element : linkInfo->interfaceInfos) {
695  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
696  EV_INFO << " " << interfaceInfo->interfaceEntry->getFullPath() << endl;
697  }
698  }
699 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::dumpRoutes ( Topology topology)
protectedvirtual

Referenced by dumpConfiguration().

715 {
716  for (int i = 0; i < topology.getNumNodes(); i++) {
717  Node *node = (Node *)topology.getNode(i);
718  if (node->routingTable) {
719  EV_INFO << "Node " << node->module->getFullPath() << endl;
720  check_and_cast<IIPv4RoutingTable *>(node->routingTable)->printRoutingTable();
721  if (node->routingTable->getNumMulticastRoutes() > 0)
722  check_and_cast<IIPv4RoutingTable *>(node->routingTable)->printMulticastRoutingTable();
723  }
724  }
725 }
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: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::ensureConfigurationComputed ( Topology topology)
protected

Referenced by configureAllInterfaces(), configureAllRoutingTables(), configureInterface(), configureRoutingTable(), and initialize().

115 {
116  if (topology.getNumNodes() == 0)
118 }
virtual void computeConfiguration()
Computes the IPv4 network configuration for all nodes in the network.
Definition: IPv4NetworkConfigurator.cc:81
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:522
Topology topology
Definition: IPv4NetworkConfigurator.h:133
IPv4NetworkConfigurator::InterfaceInfo * inet::IPv4NetworkConfigurator::findInterfaceOnLinkByNode ( LinkInfo linkInfo,
cModule *  node 
)
protectedvirtual

Referenced by resolveInterfaceAndGateway().

1165 {
1166  for (auto & element : linkInfo->interfaceInfos) {
1167  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
1168  if (interfaceInfo->interfaceEntry->getInterfaceTable()->getHostModule() == node)
1169  return interfaceInfo;
1170  }
1171  return nullptr;
1172 }
IPv4NetworkConfigurator::InterfaceInfo * inet::IPv4NetworkConfigurator::findInterfaceOnLinkByNodeAddress ( LinkInfo linkInfo,
IPv4Address  address 
)
protectedvirtual

Referenced by resolveInterfaceAndGateway().

1175 {
1176  for (auto & element : linkInfo->interfaceInfos) {
1177  // if the interface has this address, found
1178  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
1179  if (interfaceInfo->address == address.getInt())
1180  return interfaceInfo;
1181 
1182  // if some other interface of the same node has the address, we accept that too
1183  NetworkConfiguratorBase::Node *node = interfaceInfo->node;
1184  for (auto & it : node->interfaceInfos)
1185  if (static_cast<InterfaceInfo *>(it)->getAddress() == address)
1186  return interfaceInfo;
1187 
1188  }
1189  return nullptr;
1190 }
IPv4NetworkConfigurator::LinkInfo * inet::IPv4NetworkConfigurator::findLinkOfInterface ( Topology topology,
InterfaceEntry interfaceEntry 
)
protectedvirtual

Referenced by resolveInterfaceAndGateway().

1193 {
1194  for (auto & linkInfo : topology.linkInfos) {
1195  for (int j = 0; j < (int)linkInfo->interfaceInfos.size(); j++)
1196  if (linkInfo->interfaceInfos[j]->interfaceEntry == ie)
1197  return linkInfo;
1198  }
1199  return nullptr;
1200 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::findLongestCommonDestinationPrefix ( uint32  destination1,
uint32  netmask1,
uint32  destination2,
uint32  netmask2,
uint32 destinationOut,
uint32 netmaskOut 
)
protected

Returns the longest shared address prefix and netmask by iterating through bits from left to right.

Referenced by tryToMergeTwoRoutes().

1502 {
1503  netmaskOut = 0;
1504  destinationOut = 0;
1505  for (int bitIndex = 31; bitIndex >= 0; bitIndex--) {
1506  uint32 mask = 1 << bitIndex;
1507  if ((destination1 & mask) == (destination2 & mask) &&
1508  (netmask1 & mask) != 0 && (netmask2 & mask) != 0)
1509  {
1510  netmaskOut |= mask;
1511  destinationOut |= destination1 & mask;
1512  }
1513  else
1514  break;
1515  }
1516 }
uint32_t uint32
Definition: Compat.h:30
int inet::IPv4NetworkConfigurator::findRouteIndexWithSameColor ( const std::vector< IPv4Route * > &  routes,
IPv4Route route 
)
protected

Returns the index of the first route that has the same color.

Referenced by optimizeRoutes().

1409 {
1410  for (int i = 0; i < (int)routes.size(); i++)
1411  if (routesHaveSameColor(routes[i], route))
1412  return i;
1413 
1414  return -1;
1415 }
bool routesHaveSameColor(IPv4Route *route1, IPv4Route *route2)
Returns true if the two routes are the same except their address prefix and netmask.
Definition: IPv4NetworkConfigurator.cc:1399
IRoutingTable * inet::IPv4NetworkConfigurator::findRoutingTable ( NetworkConfiguratorBase::Node node)
overrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

1203 {
1204  return L3AddressResolver().findIPv4RoutingTableOf(node->module);
1205 }
L3AddressResolver()
Definition: L3AddressResolver.h:89
bool inet::IPv4NetworkConfigurator::getInterfaceIPv4Address ( L3Address ret,
InterfaceEntry interfaceEntry,
bool  netmask 
)
overrideprotectedvirtual

Reimplemented from inet::L3AddressResolver.

1711 {
1712  auto it = topology.interfaceInfos.find(interfaceEntry);
1713  if (it == topology.interfaceInfos.end())
1714  return false;
1715  else {
1716  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(it->second);
1717  if (interfaceInfo->configure)
1718  ret = netmask ? interfaceInfo->getNetmask() : interfaceInfo->getAddress();
1719  return interfaceInfo->configure;
1720  }
1721 }
std::map< InterfaceEntry *, InterfaceInfo * > interfaceInfos
Definition: NetworkConfiguratorBase.h:118
Topology topology
Definition: IPv4NetworkConfigurator.h:133
const char * inet::IPv4NetworkConfigurator::getMandatoryAttribute ( cXMLElement *  element,
const char *  attr 
)
protectedvirtual

Referenced by readManualRouteConfiguration().

928 {
929  const char *value = element->getAttribute(attr);
930  if (isEmpty(value))
931  throw cRuntimeError("<%s> element is missing mandatory attribute \"%s\" at %s", element->getTagName(), attr, element->getSourceLocation());
932  return value;
933 }
bool isEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:35
virtual void inet::IPv4NetworkConfigurator::handleMessage ( cMessage *  msg)
inlineoverrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

164 { throw cRuntimeError("this module doesn't handle messages, it runs only in initialize()"); }
void inet::IPv4NetworkConfigurator::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

65 {
67  if (stage == INITSTAGE_LOCAL) {
68  assignAddressesParameter = par("assignAddresses");
69  assignDisjunctSubnetAddressesParameter = par("assignDisjunctSubnetAddresses");
70  addStaticRoutesParameter = par("addStaticRoutes");
71  addSubnetRoutesParameter = par("addSubnetRoutes");
72  addDefaultRoutesParameter = par("addDefaultRoutes");
73  optimizeRoutesParameter = par("optimizeRoutes");
74  }
75  else if (stage == INITSTAGE_NETWORK_LAYER)
77  else if (stage == INITSTAGE_LAST)
79 }
bool addStaticRoutesParameter
Definition: IPv4NetworkConfigurator.h:127
void ensureConfigurationComputed(Topology &topology)
Definition: IPv4NetworkConfigurator.cc:114
bool addSubnetRoutesParameter
Definition: IPv4NetworkConfigurator.h:128
virtual void initialize(int stage) override
Definition: NetworkConfiguratorBase.cc:55
bool assignDisjunctSubnetAddressesParameter
Definition: IPv4NetworkConfigurator.h:126
Operations that no other initializations can depend on, e.g.
Definition: InitStages.h:111
bool optimizeRoutesParameter
Definition: IPv4NetworkConfigurator.h:130
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
Local initializations.
Definition: InitStages.h:35
virtual void dumpConfiguration()
Prints the current network configuration to the module output.
Definition: IPv4NetworkConfigurator.cc:120
bool assignAddressesParameter
Definition: IPv4NetworkConfigurator.h:125
bool addDefaultRoutesParameter
Definition: IPv4NetworkConfigurator.h:129
Topology topology
Definition: IPv4NetworkConfigurator.h:133
bool inet::IPv4NetworkConfigurator::interruptsAnyOriginalRoute ( const RoutingTableInfo routingTableInfo,
int  begin,
int  end,
const std::vector< RouteInfo * > &  originalRouteInfos 
)
protected

Returns true if any of the original routes is interrupted by any of the routes in the routing table between begin and end.

Referenced by interruptsSubsequentOriginalRoutes(), and tryToMergeTwoRoutes().

1462 {
1463  if (begin < end)
1464  for (auto & originalRouteInfo : originalRouteInfos)
1465  if (interruptsOriginalRoute(routingTableInfo, begin, end, originalRouteInfo))
1466  return true;
1467 
1468  return false;
1469 }
bool interruptsOriginalRoute(const RoutingTableInfo &routingTableInfo, int begin, int end, RouteInfo *originalRouteInfo)
Returns true if the original route is interrupted by any of the routes in the routing table between b...
Definition: IPv4NetworkConfigurator.cc:1451
bool inet::IPv4NetworkConfigurator::interruptsOriginalRoute ( const RoutingTableInfo routingTableInfo,
int  begin,
int  end,
RouteInfo originalRouteInfo 
)
protected

Returns true if the original route is interrupted by any of the routes in the routing table between begin and end.

Referenced by interruptsAnyOriginalRoute().

1452 {
1453  IPv4NetworkConfigurator::RouteInfo *matchingRouteInfo = routingTableInfo.findBestMatchingRouteInfo(originalRouteInfo->destination, begin, end);
1454  return matchingRouteInfo && matchingRouteInfo->color != originalRouteInfo->color;
1455 }
bool inet::IPv4NetworkConfigurator::interruptsSubsequentOriginalRoutes ( const RoutingTableInfo routingTableInfo,
int  index 
)
protected

Returns true if any of the original routes attached to the routes in the routing table below index are interrupted by the route at index.

Referenced by tryToMergeTwoRoutes().

1476 {
1477  for (int i = index + 1; i < (int)routingTableInfo.routeInfos.size(); i++) {
1478  IPv4NetworkConfigurator::RouteInfo *routeInfo = routingTableInfo.routeInfos.at(i);
1479  if (interruptsAnyOriginalRoute(routingTableInfo, index, index + 1, routeInfo->originalRouteInfos))
1480  return true;
1481  }
1482  return false;
1483 }
bool interruptsAnyOriginalRoute(const RoutingTableInfo &routingTableInfo, int begin, int end, const std::vector< RouteInfo * > &originalRouteInfos)
Returns true if any of the original routes is interrupted by any of the routes in the routing table b...
Definition: IPv4NetworkConfigurator.cc:1461
bool inet::IPv4NetworkConfigurator::linkContainsMatchingHostExcept ( LinkInfo linkInfo,
Matcher hostMatcher,
cModule *  exceptModule 
)
protectedvirtual

Referenced by readInterfaceConfiguration(), and readMulticastGroupConfiguration().

675 {
676  for (auto & element : linkInfo->interfaceInfos) {
677  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
678  cModule *hostModule = interfaceInfo->interfaceEntry->getInterfaceTable()->getHostModule();
679  if (hostModule == exceptModule)
680  continue;
681  std::string hostFullPath = hostModule->getFullPath();
682  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
683  if (hostMatcher->matches(hostShortenedFullPath.c_str()) || hostMatcher->matches(hostFullPath.c_str()))
684  return true;
685  }
686  return false;
687 }
virtual int inet::IPv4NetworkConfigurator::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

163 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::IPv4NetworkConfigurator::optimizeRoutes ( std::vector< IPv4Route * > &  routes)
protectedvirtual

Destructively optimizes the given IPv4 routes by merging some of them.

The resulting routes might be different in that they will route packets that the original routes did not. Nevertheless the following invariant holds: any packet routed by the original routes will still be routed the same way by the optimized routes.

Referenced by addStaticRoutes().

1632 {
1633  // The basic idea: if two routes "do the same" (same output interface, gateway, etc) and
1634  // match "similar" addresses, one can try to move them to be neighbors in the table and
1635  // replace them with a single route which contains their longest common prefix as address
1636  // prefix -- provided that this operation doesn't affect the meaning of the routing table
1637  // for "existing" addresses. (We don't care about changing the routing for addresses that
1638  // we know don't occur in our currently configured network.) We can repeatedly merge routes
1639  // in this way until it's not possible any more. Of course, the result also depends on
1640  // which pairs of routes we merge, and in which order.
1641 
1642  // STEP 1.
1643  // instead of working with IPv4 routes we transform them into the internal representation of the optimizer.
1644  // routes are classified based on their action (gateway, interface, type, source, metric, etc.) and a color is assigned to them.
1645  RoutingTableInfo routingTableInfo;
1646  std::vector<IPv4Route *> colorToRoute; // a mapping from color to route action (interface, gateway, metric, etc.)
1647 #ifndef NDEBUG
1648  std::vector<RouteInfo *> originalRouteInfos; // a copy of the original routes in the optimizer's format
1649 #endif // ifndef NDEBUG
1650 
1651  // build colorToRouteColor, originalRouteInfos and initial routeInfos in routingTableInfo
1652  for (auto & originalRoute : originalRoutes) {
1653  int color = findRouteIndexWithSameColor(colorToRoute, originalRoute);
1654  if (color == -1) {
1655  color = colorToRoute.size();
1656  colorToRoute.push_back(originalRoute);
1657  }
1658 
1659  // create original route and determine its color
1660  RouteInfo *originalRouteInfo = new RouteInfo(color, originalRoute->getDestination().getInt(), originalRoute->getNetmask().getInt());
1661 #ifndef NDEBUG
1662  originalRouteInfos.push_back(originalRouteInfo);
1663 #endif // ifndef NDEBUG
1664 
1665  // create a copy of the original route that can be destructively optimized later
1666  RouteInfo *optimizedRouteInfo = new RouteInfo(*originalRouteInfo);
1667  optimizedRouteInfo->originalRouteInfos.push_back(originalRouteInfo);
1668  routingTableInfo.originalRouteInfos.push_back(originalRouteInfo);
1669  routingTableInfo.addRouteInfo(optimizedRouteInfo);
1670  }
1671 
1672 #ifndef NDEBUG
1673  checkOriginalRoutes(routingTableInfo, originalRouteInfos);
1674 #endif // ifndef NDEBUG
1675 
1676  // STEP 2.
1677  // from now on we are only working with the internal data structures called RouteInfo and RoutingTableInfo.
1678  // the main optimizer loop runs until it cannot merge any two routes.
1679  while (tryToMergeAnyTwoRoutes(routingTableInfo))
1680  ;
1681 
1682 #ifndef NDEBUG
1683  checkOriginalRoutes(routingTableInfo, originalRouteInfos);
1684 #endif // ifndef NDEBUG
1685 
1686  // STEP 3.
1687  // convert the optimized routes to new optimized IPv4 routes based on the saved colors
1688  std::vector<IPv4Route *> optimizedRoutes;
1689  for (auto & routeInfo : routingTableInfo.routeInfos) {
1690  IPv4Route *routeColor = colorToRoute[routeInfo->color];
1691  IPv4Route *optimizedRoute = new IPv4Route();
1692  optimizedRoute->setDestination(IPv4Address(routeInfo->destination));
1693  optimizedRoute->setNetmask(IPv4Address(routeInfo->netmask));
1694  optimizedRoute->setInterface(routeColor->getInterface());
1695  optimizedRoute->setGateway(routeColor->getGateway());
1696  optimizedRoute->setSourceType(routeColor->getSourceType());
1697  optimizedRoute->setMetric(routeColor->getMetric());
1698  optimizedRoutes.push_back(optimizedRoute);
1699  delete routeInfo;
1700  }
1701 
1702  // delete original routes, we destructively modify them
1703  for (auto & originalRoute : originalRoutes)
1704  delete originalRoute;
1705 
1706  // copy optimized routes to original routes and return
1707  originalRoutes = optimizedRoutes;
1708 }
bool tryToMergeAnyTwoRoutes(RoutingTableInfo &routingTableInfo)
Iteratively checks if any two routes can be aggressively merged without changing the meaning of all o...
Definition: IPv4NetworkConfigurator.cc:1610
int findRouteIndexWithSameColor(const std::vector< IPv4Route * > &routes, IPv4Route *route)
Returns the index of the first route that has the same color.
Definition: IPv4NetworkConfigurator.cc:1408
void checkOriginalRoutes(const RoutingTableInfo &routingTableInfo, const std::vector< RouteInfo * > &originalRouteInfos)
Asserts that all original routes are still routed the same way as by the original routing table...
Definition: IPv4NetworkConfigurator.cc:1488
void inet::IPv4NetworkConfigurator::parseAddressAndSpecifiedBits ( const char *  addressAttr,
uint32_t &  outAddress,
uint32_t &  outAddressSpecifiedBits 
)
protectedvirtual

Referenced by readInterfaceConfiguration().

654 {
655  // change "10.0.x.x" to "10.0.0.0" (for address) and "255.255.0.0" (for specifiedBits)
656  std::string address;
657  std::string specifiedBits;
658  cStringTokenizer tokenizer(addressAttr, ".");
659  while (tokenizer.hasMoreTokens()) {
660  std::string token = tokenizer.nextToken();
661  address += (token == "x") ? "0." : (token + ".");
662  specifiedBits += (token == "x") ? "0." : "255.";
663  }
664  address = address.substr(0, address.size() - 1);
665  specifiedBits = specifiedBits.substr(0, specifiedBits.size() - 1);
666 
667  if (!IPv4Address::isWellFormed(address.c_str()) || !IPv4Address::isWellFormed(specifiedBits.c_str()))
668  throw cRuntimeError("Malformed IPv4 address or netmask constraint '%s'", addressAttr);
669 
670  outAddress = IPv4Address(address.c_str()).getInt();
671  outAddressSpecifiedBits = IPv4Address(specifiedBits.c_str()).getInt();
672 }
static bool isWellFormed(const char *text)
Returns true if the format of the string corresponds to an IPv4 address with the dotted notation ("19...
Definition: IPv4Address.cc:269
void inet::IPv4NetworkConfigurator::readInterfaceConfiguration ( Topology topology)
protectedvirtual

Reads interface elements from the configuration file and stores result.

Referenced by computeConfiguration().

550 {
551  using namespace xmlutils;
552 
553  std::set<InterfaceInfo *> interfacesSeen;
554  cXMLElementList interfaceElements = configuration->getChildrenByTagName("interface");
555 
556  for (auto & interfaceElement : interfaceElements) {
557  const char *hostAttr = interfaceElement->getAttribute("hosts"); // "host* router[0..3]"
558  const char *interfaceAttr = interfaceElement->getAttribute("names"); // i.e. interface names, like "eth* ppp0"
559 
560  // TODO: "switch" egyebkent sztem nem muxik most, de kellene!
561  const char *towardsAttr = interfaceElement->getAttribute("towards"); // neighbor host names, like "ap switch"
562  const char *amongAttr = interfaceElement->getAttribute("among"); // neighbor host names, like "host[*] router1"
563  const char *addressAttr = interfaceElement->getAttribute("address"); // "10.0.x.x"
564  const char *netmaskAttr = interfaceElement->getAttribute("netmask"); // "255.255.x.x"
565  const char *mtuAttr = interfaceElement->getAttribute("mtu"); // integer
566  const char *metricAttr = interfaceElement->getAttribute("metric"); // integer
567  const char *groupsAttr = interfaceElement->getAttribute("groups"); // list of multicast addresses
568  bool addStaticRouteAttr = getAttributeBoolValue(interfaceElement, "add-static-route", true);
569  bool addDefaultRouteAttr = getAttributeBoolValue(interfaceElement, "add-default-route", true);
570  bool addSubnetRouteAttr = getAttributeBoolValue(interfaceElement, "add-subnet-route", true);
571 
572  if (amongAttr && *amongAttr) { // among="X Y Z" means hosts = "X Y Z" towards = "X Y Z"
573  if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
574  throw cRuntimeError("The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s", interfaceElement->getSourceLocation());
575  towardsAttr = hostAttr = amongAttr;
576  }
577 
578  try {
579  // parse host/interface/towards expressions
580  Matcher hostMatcher(hostAttr);
581  Matcher interfaceMatcher(interfaceAttr);
582  Matcher towardsMatcher(towardsAttr);
583 
584  // parse address/netmask constraints
585  bool haveAddressConstraint = isNotEmpty(addressAttr);
586  bool haveNetmaskConstraint = isNotEmpty(netmaskAttr);
587 
588  uint32_t address, addressSpecifiedBits, netmask, netmaskSpecifiedBits;
589  if (haveAddressConstraint)
590  parseAddressAndSpecifiedBits(addressAttr, address, addressSpecifiedBits);
591  if (haveNetmaskConstraint)
592  parseAddressAndSpecifiedBits(netmaskAttr, netmask, netmaskSpecifiedBits);
593 
594  // configure address/netmask constraints on matching interfaces
595  for (auto & linkInfo : topology.linkInfos) {
596  for (int j = 0; j < (int)linkInfo->interfaceInfos.size(); j++) {
597  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(linkInfo->interfaceInfos[j]);
598  if (interfacesSeen.count(interfaceInfo) == 0) {
599  cModule *hostModule = interfaceInfo->interfaceEntry->getInterfaceTable()->getHostModule();
600  std::string hostFullPath = hostModule->getFullPath();
601  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
602 
603  // Note: "hosts", "interfaces" and "towards" must ALL match on the interface for the rule to apply
604  if ((hostMatcher.matchesAny() || hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str())) &&
605  (interfaceMatcher.matchesAny() || interfaceMatcher.matches(interfaceInfo->interfaceEntry->getFullName())) &&
606  (towardsMatcher.matchesAny() || linkContainsMatchingHostExcept(linkInfo, &towardsMatcher, hostModule)))
607  {
608  EV_DEBUG << "Processing interface configuration for " << interfaceInfo->getFullPath() << endl;
609 
610  // unicast address constraints
611  interfaceInfo->configure = haveAddressConstraint;
612  if (interfaceInfo->configure) {
613  interfaceInfo->address = address;
614  interfaceInfo->addressSpecifiedBits = addressSpecifiedBits;
615  if (haveNetmaskConstraint) {
616  interfaceInfo->netmask = netmask;
617  interfaceInfo->netmaskSpecifiedBits = netmaskSpecifiedBits;
618  }
619  }
620 
621  // route flags
622  interfaceInfo->addStaticRoute = addStaticRouteAttr;
623  interfaceInfo->addDefaultRoute = addDefaultRouteAttr;
624  interfaceInfo->addSubnetRoute = addSubnetRouteAttr;
625 
626  // mtu
627  if (isNotEmpty(mtuAttr))
628  interfaceInfo->mtu = atoi(mtuAttr);
629 
630  // metric
631  if (isNotEmpty(metricAttr))
632  interfaceInfo->metric = atoi(metricAttr);
633 
634  // groups
635  if (isNotEmpty(groupsAttr)) {
636  cStringTokenizer tokenizer(groupsAttr);
637  while (tokenizer.hasMoreTokens())
638  interfaceInfo->multicastGroups.push_back(IPv4Address(tokenizer.nextToken()));
639  }
640 
641  interfacesSeen.insert(interfaceInfo);
642  }
643  }
644  }
645  }
646  }
647  catch (std::exception& e) {
648  throw cRuntimeError("Error in XML <interface> element at %s: %s", interfaceElement->getSourceLocation(), e.what());
649  }
650  }
651 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
bool getAttributeBoolValue(const cXMLElement *node, const char *attrName, bool defVal)
Definition: XMLUtils.cc:159
virtual bool linkContainsMatchingHostExcept(LinkInfo *linkInfo, Matcher *hostMatcher, cModule *exceptModule)
Definition: IPv4NetworkConfigurator.cc:674
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
bool isNotEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:40
virtual void parseAddressAndSpecifiedBits(const char *addressAttr, uint32_t &outAddress, uint32_t &outAddressSpecifiedBits)
Definition: IPv4NetworkConfigurator.cc:653
const value< double, units::C > e(1.602176487e-19)
Topology topology
Definition: IPv4NetworkConfigurator.h:133
void inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration ( Topology topology)
protectedvirtual

Reads multicast-route elements from configuration file and stores the result.

Referenced by computeConfiguration().

997 {
998  cXMLElementList routeElements = configuration->getChildrenByTagName("multicast-route");
999  for (auto & routeElement : routeElements) {
1000  const char *hostAttr = routeElement->getAttribute("hosts");
1001  const char *sourceAttr = routeElement->getAttribute("source"); // source address (L3AddressResolver syntax)
1002  const char *netmaskAttr = routeElement->getAttribute("netmask"); // default: 255.255.255.255; alternative notation: "/23"
1003  const char *groupsAttr = routeElement->getAttribute("groups"); // addresses of the multicast groups, default: 0.0.0.0, matching all groups
1004  const char *parentAttr = routeElement->getAttribute("parent"); // name of expected input interface
1005  const char *childrenAttr = routeElement->getAttribute("children"); // names of output interfaces
1006  const char *metricAttr = routeElement->getAttribute("metric");
1007 
1008  try {
1009  // parse and check the attributes
1010  IPv4Address source;
1011  if (!isEmpty(sourceAttr) && strcmp(sourceAttr, "*"))
1012  source = resolve(sourceAttr, L3AddressResolver::ADDR_IPv4).toIPv4();
1013  IPv4Address netmask;
1014  if (!isEmpty(netmaskAttr) && strcmp(netmaskAttr, "*")) {
1015  if (netmaskAttr[0] == '/')
1016  netmask = IPv4Address::makeNetmask(atoi(netmaskAttr + 1));
1017  else
1018  netmask = IPv4Address(netmaskAttr);
1019  }
1020 
1021  if (!netmask.isValidNetmask())
1022  throw cRuntimeError("Wrong netmask %s", netmask.str().c_str());
1023 
1024  std::vector<IPv4Address> groups;
1025  if (isEmpty(groupsAttr))
1026  groups.push_back(IPv4Address::UNSPECIFIED_ADDRESS);
1027  else {
1028  cStringTokenizer tokenizer(groupsAttr);
1029  while (tokenizer.hasMoreTokens()) {
1030  IPv4Address group = IPv4Address(tokenizer.nextToken());
1031  if (!group.isMulticast())
1032  throw cRuntimeError("Address '%s' in groups attribute is not multicast.", group.str().c_str());
1033  groups.push_back(group);
1034  }
1035  }
1036 
1037  // find matching host(s), and add the route
1038  Matcher atMatcher(hostAttr);
1039  InterfaceMatcher childrenMatcher(childrenAttr);
1040  for (int i = 0; i < topology.getNumNodes(); i++) {
1041  Node *node = (Node *)topology.getNode(i);
1042  if (node->routingTable && node->routingTable->isMulticastForwardingEnabled()) {
1043  std::string hostFullPath = node->module->getFullPath();
1044  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
1045  if (atMatcher.matches(hostShortenedFullPath.c_str()) || atMatcher.matches(hostFullPath.c_str())) {
1046  InterfaceEntry *parent = nullptr;
1047  if (!isEmpty(parentAttr)) {
1048  parent = node->interfaceTable->getInterfaceByName(parentAttr);
1049  if (!parent)
1050  throw cRuntimeError("Parent interface '%s' not found.", parentAttr);
1051  if (!parent->isMulticast())
1052  throw cRuntimeError("Parent interface '%s' is not multicast.", parentAttr);
1053  }
1054 
1055  std::vector<InterfaceEntry *> children;
1056  for (auto & element : node->interfaceInfos) {
1057  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(element);
1058  InterfaceEntry *ie = interfaceInfo->interfaceEntry;
1059  if (ie != parent && ie->isMulticast() && childrenMatcher.matches(interfaceInfo))
1060  children.push_back(ie);
1061  }
1062 
1063  for (auto & group : groups) {
1064  // create and add route
1065  IPv4MulticastRoute *route = new IPv4MulticastRoute();
1066  route->setSourceType(IMulticastRoute::MANUAL);
1067  route->setOrigin(source);
1068  route->setOriginNetmask(netmask);
1069  route->setMulticastGroup(group);
1070  route->setInInterface(parent ? new IPv4MulticastRoute::InInterface(parent) : nullptr);
1071  if (isNotEmpty(metricAttr))
1072  route->setMetric(atoi(metricAttr));
1073  for (auto & child : children)
1074  route->addOutInterface(new IPv4MulticastRoute::OutInterface(child, false /*TODO:isLeaf*/));
1075  node->staticMulticastRoutes.push_back(route);
1076  }
1077  }
1078  }
1079  }
1080  }
1081  catch (std::exception& e) {
1082  throw cRuntimeError("Error in XML <multicast-route> element at %s: %s", routeElement->getSourceLocation(), e.what());
1083  }
1084  }
1085 }
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
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
cModule * module
Definition: NetworkConfiguratorBase.h:52
bool isNotEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:40
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 ("").
Definition: L3AddressResolver.cc:46
const value< double, units::C > e(1.602176487e-19)
Definition: L3AddressResolver.h:80
static const IPv4Address UNSPECIFIED_ADDRESS
0.0.0.0
Definition: IPv4Address.h:102
Topology topology
Definition: IPv4NetworkConfigurator.h:133
static IPv4Address makeNetmask(int length)
Creates and returns a netmask with the given length.
Definition: IPv4Address.h:335
manually added static route
Definition: IRoute.h:154
bool isEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:35
IPv4Address toIPv4() const
Definition: L3Address.h:76
void inet::IPv4NetworkConfigurator::readManualRouteConfiguration ( Topology topology)
protectedvirtual

Reads route elements from configuration file and stores the result.

Referenced by computeConfiguration().

936 {
937  cXMLElementList routeElements = configuration->getChildrenByTagName("route");
938  for (auto & routeElement : routeElements) {
939  const char *hostAttr = getMandatoryAttribute(routeElement, "hosts");
940  const char *destinationAttr = getMandatoryAttribute(routeElement, "destination"); // destination address (L3AddressResolver syntax)
941  const char *netmaskAttr = routeElement->getAttribute("netmask"); // default: 255.255.255.255; alternative notation: "/23"
942  const char *gatewayAttr = routeElement->getAttribute("gateway"); // next hop address (L3AddressResolver syntax)
943  const char *interfaceAttr = routeElement->getAttribute("interface"); // output interface name
944  const char *metricAttr = routeElement->getAttribute("metric");
945 
946  try {
947  // parse and check the attributes
948  IPv4Address destination;
949  if (!isEmpty(destinationAttr) && strcmp(destinationAttr, "*"))
950  destination = resolve(destinationAttr, L3AddressResolver::ADDR_IPv4).toIPv4();
951  IPv4Address netmask;
952  if (!isEmpty(netmaskAttr) && strcmp(netmaskAttr, "*")) {
953  if (netmaskAttr[0] == '/')
954  netmask = IPv4Address::makeNetmask(atoi(netmaskAttr + 1));
955  else
956  netmask = IPv4Address(netmaskAttr);
957  }
958  if (!netmask.isValidNetmask())
959  throw cRuntimeError("Wrong netmask %s", netmask.str().c_str());
960  if (isEmpty(interfaceAttr) && isEmpty(gatewayAttr))
961  throw cRuntimeError("Incomplete route: either gateway or interface (or both) must be specified");
962 
963  // find matching host(s), and add the route
964  Matcher atMatcher(hostAttr);
965  for (int i = 0; i < topology.getNumNodes(); i++) {
966  Node *node = (Node *)topology.getNode(i);
967  if (node->routingTable) {
968  std::string hostFullPath = node->module->getFullPath();
969  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
970  if (atMatcher.matches(hostShortenedFullPath.c_str()) || atMatcher.matches(hostFullPath.c_str())) {
971  // determine the gateway (its address towards this node!) and the output interface for the route (must be done per node)
972  InterfaceEntry *ie;
973  IPv4Address gateway;
974  resolveInterfaceAndGateway(node, interfaceAttr, gatewayAttr, ie, gateway, topology);
975 
976  // create and add route
977  IPv4Route *route = new IPv4Route();
978  route->setSourceType(IRoute::MANUAL);
979  route->setDestination(destination);
980  route->setNetmask(netmask);
981  route->setGateway(gateway); // may be unspecified
982  route->setInterface(ie);
983  if (isNotEmpty(metricAttr))
984  route->setMetric(atoi(metricAttr));
985  node->staticRoutes.push_back(route);
986  }
987  }
988  }
989  }
990  catch (std::exception& e) {
991  throw cRuntimeError("Error in XML <route> element at %s: %s", routeElement->getSourceLocation(), e.what());
992  }
993  }
994 }
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
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
cModule * module
Definition: NetworkConfiguratorBase.h:52
bool isNotEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:40
virtual const char * getMandatoryAttribute(cXMLElement *element, const char *attr)
Definition: IPv4NetworkConfigurator.cc:927
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 ("").
Definition: L3AddressResolver.cc:46
const value< double, units::C > e(1.602176487e-19)
virtual void resolveInterfaceAndGateway(Node *node, const char *interfaceAttr, const char *gatewayAttr, InterfaceEntry *&outIE, IPv4Address &outGateway, Topology &topology)
Definition: IPv4NetworkConfigurator.cc:1087
Definition: L3AddressResolver.h:80
Topology topology
Definition: IPv4NetworkConfigurator.h:133
static IPv4Address makeNetmask(int length)
Creates and returns a netmask with the given length.
Definition: IPv4Address.h:335
manually added static route
Definition: IRoute.h:40
bool isEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:35
IPv4Address toIPv4() const
Definition: L3Address.h:76
void inet::IPv4NetworkConfigurator::readMulticastGroupConfiguration ( Topology topology)
protectedvirtual

Reads multicast-group elements from the configuration file and stores the result.

Referenced by computeConfiguration().

874 {
875  cXMLElementList multicastGroupElements = configuration->getChildrenByTagName("multicast-group");
876  for (auto & multicastGroupElement : multicastGroupElements) {
877  const char *hostAttr = multicastGroupElement->getAttribute("hosts");
878  const char *interfaceAttr = multicastGroupElement->getAttribute("interfaces");
879  const char *addressAttr = multicastGroupElement->getAttribute("address");
880  const char *towardsAttr = multicastGroupElement->getAttribute("towards"); // neighbor host names, like "ap switch"
881  const char *amongAttr = multicastGroupElement->getAttribute("among");
882 
883  if (amongAttr && *amongAttr) { // among="X Y Z" means hosts = "X Y Z" towards = "X Y Z"
884  if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
885  throw cRuntimeError("The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s", multicastGroupElement->getSourceLocation());
886  towardsAttr = hostAttr = amongAttr;
887  }
888 
889  try {
890  Matcher hostMatcher(hostAttr);
891  Matcher interfaceMatcher(interfaceAttr);
892  Matcher towardsMatcher(towardsAttr);
893 
894  // parse group addresses
895  std::vector<IPv4Address> multicastGroups;
896  cStringTokenizer tokenizer(addressAttr);
897  while (tokenizer.hasMoreTokens()) {
898  IPv4Address addr = IPv4Address(tokenizer.nextToken());
899  if (!addr.isMulticast())
900  throw cRuntimeError("Non-multicast address %s found in the multicast-group element", addr.str().c_str());
901  multicastGroups.push_back(addr);
902  }
903 
904  for (auto & linkInfo : topology.linkInfos) {
905  for (int k = 0; k < (int)linkInfo->interfaceInfos.size(); k++) {
906  InterfaceInfo *interfaceInfo = static_cast<InterfaceInfo *>(linkInfo->interfaceInfos[k]);
907  cModule *hostModule = interfaceInfo->interfaceEntry->getInterfaceTable()->getHostModule();
908  std::string hostFullPath = hostModule->getFullPath();
909  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
910 
911  if ((hostMatcher.matchesAny() || hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str())) &&
912  (interfaceMatcher.matchesAny() || interfaceMatcher.matches(interfaceInfo->interfaceEntry->getFullName())) &&
913  (towardsMatcher.matchesAny() || linkContainsMatchingHostExcept(linkInfo, &towardsMatcher, hostModule)))
914  {
915  for (auto & multicastGroup : multicastGroups)
916  interfaceInfo->multicastGroups.push_back(multicastGroup);
917  }
918  }
919  }
920  }
921  catch (std::exception& e) {
922  throw cRuntimeError("Error in XML <multicast-group> element at %s: %s", multicastGroupElement->getSourceLocation(), e.what());
923  }
924  }
925 }
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
virtual bool linkContainsMatchingHostExcept(LinkInfo *linkInfo, Matcher *hostMatcher, cModule *exceptModule)
Definition: IPv4NetworkConfigurator.cc:674
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
const value< double, units::C > e(1.602176487e-19)
Topology topology
Definition: IPv4NetworkConfigurator.h:133
const double k
Definition: QAM16Modulation.cc:24
void inet::IPv4NetworkConfigurator::resolveInterfaceAndGateway ( Node node,
const char *  interfaceAttr,
const char *  gatewayAttr,
InterfaceEntry *&  outIE,
IPv4Address outGateway,
Topology topology 
)
protectedvirtual

Referenced by readManualRouteConfiguration().

1089 {
1090  // resolve interface name
1091  if (isEmpty(interfaceAttr)) {
1092  outIE = nullptr;
1093  }
1094  else {
1095  outIE = node->interfaceTable->getInterfaceByName(interfaceAttr);
1096  if (!outIE)
1097  throw cRuntimeError("Host/router %s has no interface named \"%s\"",
1098  node->module->getFullPath().c_str(), interfaceAttr);
1099  }
1100 
1101  // if gateway is not specified, we are done
1102  if (isEmpty(gatewayAttr) || !strcmp(gatewayAttr, "*")) {
1103  outGateway = IPv4Address();
1104  return; // outInterface also already done -- we're done
1105  }
1106 
1107  ASSERT(isNotEmpty(gatewayAttr)); // see "if" above
1108 
1109  // check syntax of gatewayAttr, and obtain an initial value
1110  outGateway = resolve(gatewayAttr, L3AddressResolver::ADDR_IPv4).toIPv4();
1111 
1112  IPv4Address gatewayAddressOnCommonLink;
1113 
1114  if (!outIE) {
1115  // interface is not specified explicitly -- we must deduce it from the gateway.
1116  // It is expected that the gateway is on the same link with the configured node,
1117  // and then we pick the interface which connects to that link.
1118 
1119  // loop through all links, and find the one that contains both the
1120  // configured node and the gateway
1121  for (auto & linkInfo : topology.linkInfos) {
1122  InterfaceInfo *gatewayInterfaceOnLink = findInterfaceOnLinkByNodeAddress(linkInfo, outGateway);
1123  if (gatewayInterfaceOnLink) {
1124  InterfaceInfo *nodeInterfaceOnLink = findInterfaceOnLinkByNode(linkInfo, node->module);
1125  if (nodeInterfaceOnLink) {
1126  outIE = nodeInterfaceOnLink->interfaceEntry;
1127  gatewayAddressOnCommonLink = gatewayInterfaceOnLink->getAddress();
1128  break;
1129  }
1130  }
1131  }
1132  if (!outIE)
1133  throw cRuntimeError("Host/router %s has no interface towards \"%s\"",
1134  node->module->getFullPath().c_str(), gatewayAttr);
1135  }
1136 
1137  // Now we have both the interface and the gateway. Still, we may need to modify
1138  // the gateway address by picking the address of a different interface of the gateway --
1139  // the address of the interface which is towards the configured node (i.e. on the same link)
1140  //
1141  // gatewayAttr may be an IP address, or a module name, or modulename+interfacename
1142  // in a syntax accepted by L3AddressResolver. If the gatewayAttr is a concrete IP address
1143  // or contains a gateway interface name (L3AddressResolver accepts it after a "/"), we're done
1144  if (IPv4Address::isWellFormed(gatewayAttr) || strchr(gatewayAttr, '/') != nullptr)
1145  return;
1146 
1147  // At this point, gatewayAttr must be a modulename string, so we can freely pick the
1148  // interface that's towards the configured node
1149  if (!gatewayAddressOnCommonLink.isUnspecified())
1150  outGateway = gatewayAddressOnCommonLink;
1151  else {
1152  // find the gateway interface that's on the same link as outIE
1153 
1154  // first, find which link outIE is on...
1155  LinkInfo *linkInfo = findLinkOfInterface(topology, outIE);
1156 
1157  // then find which gateway interface is on that link
1158  InterfaceInfo *gatewayInterface = findInterfaceOnLinkByNodeAddress(linkInfo, outGateway);
1159  if (gatewayInterface)
1160  outGateway = gatewayInterface->getAddress();
1161  }
1162 }
virtual LinkInfo * findLinkOfInterface(Topology &topology, InterfaceEntry *interfaceEntry)
Definition: IPv4NetworkConfigurator.cc:1192
virtual InterfaceInfo * findInterfaceOnLinkByNodeAddress(LinkInfo *linkInfo, IPv4Address address)
Definition: IPv4NetworkConfigurator.cc:1174
std::vector< LinkInfo * > linkInfos
Definition: NetworkConfiguratorBase.h:117
bool isNotEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:40
static bool isWellFormed(const char *text)
Returns true if the format of the string corresponds to an IPv4 address with the dotted notation ("19...
Definition: IPv4Address.cc:269
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 ("").
Definition: L3AddressResolver.cc:46
Definition: L3AddressResolver.h:80
Topology topology
Definition: IPv4NetworkConfigurator.h:133
bool isEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:35
virtual InterfaceInfo * findInterfaceOnLinkByNode(LinkInfo *linkInfo, cModule *node)
Definition: IPv4NetworkConfigurator.cc:1164
IPv4Address toIPv4() const
Definition: L3Address.h:76
bool inet::IPv4NetworkConfigurator::routesCanBeNeighbors ( const std::vector< RouteInfo * > &  routeInfos,
int  i,
int  j 
)
protected

Returns true if the routes can be neighbors by repeatedly swapping routes in the routing table without changing their meaning.

Referenced by tryToMergeAnyTwoRoutes().

1436 {
1437  int begin = std::min(i, j);
1438  int end = std::max(i, j);
1439  IPv4NetworkConfigurator::RouteInfo *beginRouteInfo = routeInfos.at(begin);
1440  for (int index = begin + 1; index < end; index++)
1441  if (!routesCanBeSwapped(beginRouteInfo, routeInfos.at(index)))
1442  return false;
1443 
1444  return true;
1445 }
bool routesCanBeSwapped(RouteInfo *routeInfo1, RouteInfo *routeInfo2)
Returns true if swapping two ADJACENT routes in the routing table does not change the table&#39;s meaning...
Definition: IPv4NetworkConfigurator.cc:1420
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
bool inet::IPv4NetworkConfigurator::routesCanBeSwapped ( RouteInfo routeInfo1,
RouteInfo routeInfo2 
)
protected

Returns true if swapping two ADJACENT routes in the routing table does not change the table's meaning.

Referenced by routesCanBeNeighbors().

1421 {
1422  if (routeInfo1->color == routeInfo2->color)
1423  return true; // these two routes send the packet in the same direction (same gw/iface), doesn't matter which one we use -> can be swapped
1424  else {
1425  // unrelated routes can also be swapped
1426  uint32 netmask = routeInfo1->netmask & routeInfo2->netmask;
1427  return (routeInfo1->destination & netmask) != (routeInfo2->destination & netmask);
1428  }
1429 }
uint32_t uint32
Definition: Compat.h:30
bool inet::IPv4NetworkConfigurator::routesHaveSameColor ( IPv4Route route1,
IPv4Route route2 
)
protected

Returns true if the two routes are the same except their address prefix and netmask.

If it returns true we say that the routes have the same color.

Referenced by findRouteIndexWithSameColor().

1400 {
1401  return route1->getSourceType() == route2->getSourceType() && route1->getMetric() == route2->getMetric() &&
1402  route1->getGateway() == route2->getGateway() && route1->getInterface() == route2->getInterface();
1403 }
bool inet::IPv4NetworkConfigurator::tryToMergeAnyTwoRoutes ( RoutingTableInfo routingTableInfo)
protected

Iteratively checks if any two routes can be aggressively merged without changing the meaning of all original routes.

The merged route will have the longest shared address prefix and netmask with the two merged routes. This optimization might change the meaning of the routing table in that it will route packets that it did not route before. Nevertheless, any packet routed by the original routing table will still be routed the same way by the optimized routing table. Returns true if two routes has been merged, otherwise returns false.

Referenced by optimizeRoutes().

1611 {
1612  for (int i = 0; i < (int)routingTableInfo.routeInfos.size(); i++) {
1613  IPv4NetworkConfigurator::RouteInfo *routeInfoI = routingTableInfo.routeInfos.at(i);
1614 
1615  // iterate backward so that we try to merge routes having longer netmasks first.
1616  // this results in smaller changes and allows more symmetric optimization.
1617  for (int j = i - 1; j >= 0; j--) {
1618  IPv4NetworkConfigurator::RouteInfo *routeInfoJ = routingTableInfo.routeInfos.at(j);
1619 
1620  // we can only merge neighbor routes having the same color
1621  if (routeInfoI->color == routeInfoJ->color && routesCanBeNeighbors(routingTableInfo.routeInfos, i, j)) {
1622  // it is worth to actually try to merge them
1623  if (tryToMergeTwoRoutes(routingTableInfo, i, j, routeInfoI, routeInfoJ))
1624  return true;
1625  }
1626  }
1627  }
1628  return false;
1629 }
bool tryToMergeTwoRoutes(RoutingTableInfo &routingTableInfo, int i, int j, RouteInfo *routeInfoI, RouteInfo *routeInfoJ)
Try to merge two routes that have the same color and could be neighbours in table without changing th...
Definition: IPv4NetworkConfigurator.cc:1538
bool routesCanBeNeighbors(const std::vector< RouteInfo * > &routeInfos, int i, int j)
Returns true if the routes can be neighbors by repeatedly swapping routes in the routing table withou...
Definition: IPv4NetworkConfigurator.cc:1435
bool inet::IPv4NetworkConfigurator::tryToMergeTwoRoutes ( RoutingTableInfo routingTableInfo,
int  i,
int  j,
RouteInfo routeInfoI,
RouteInfo routeInfoJ 
)
protected

Try to merge two routes that have the same color and could be neighbours in table without changing the table's meaning.

There are two merge opportunities: (1) one route's network contains the other one (then the second can be dropped), and (2) use a shorter common prefix that covers both (this is only possible if this doesn't interfere with existing routes in the table). Returns true if the two routes have been merged, otherwise returns false.

Referenced by tryToMergeAnyTwoRoutes().

1539 {
1540  // determine longest shared address prefix and netmask by iterating through bits from left to right
1541  uint32 netmask;
1542  uint32 destination;
1543  findLongestCommonDestinationPrefix(routeInfoI->destination, routeInfoI->netmask, routeInfoJ->destination, routeInfoJ->netmask, destination, netmask);
1544 
1545  // create the merged route
1546  RouteInfo *mergedRouteInfo = new RouteInfo(routeInfoI->color, destination, netmask);
1547  routeInfoI->enabled = false;
1548  routeInfoJ->enabled = false;
1549  int m = routingTableInfo.addRouteInfo(mergedRouteInfo);
1550  ASSERT(m > i && m > j);
1551 
1552  // check if all the original routes are still routed the same way by the optimized routing table.
1553  // check optimization: instead of checking all the original routes, check only those which can go wrong due to the merge.
1554  // (assuming the previous configuration was correct)
1555  // - the original routes on I and J are going to be routed by M after the merge, so check if the routes in between don't interrupt them
1556  // - the original routes following M can be accidentally overridden by M (being larger than the sum of I and J), so verify that M does not interrupt them
1557  // note that the condition is not symmetric because I follows J so it requires fewer checks and we do use that.
1558  if (!interruptsAnyOriginalRoute(routingTableInfo, j + 1, i, routeInfoJ->originalRouteInfos) && // check that original routes on J are not interrupted between J and I
1559  !interruptsAnyOriginalRoute(routingTableInfo, i + 1, m, routeInfoJ->originalRouteInfos) && // check that original routes on J are not interrupted between I and M
1560  !interruptsAnyOriginalRoute(routingTableInfo, i + 1, m, routeInfoI->originalRouteInfos) && // check that original routes on I are not interrupted between I and M
1561  !interruptsSubsequentOriginalRoutes(routingTableInfo, m)) // check that the original routes after M are not interrupted by M
1562  {
1563  // now we know that the merge does not conflict with any route in the routing table.
1564  // the next thing to do is to maintain the original routes attached to the optimized ones.
1565  // move original routes from the to be deleted I route to the capturing routes.
1566  addOriginalRouteInfos(routingTableInfo, i + 1, m + 1, routeInfoI->originalRouteInfos);
1567 
1568  // move original routes from the to be deleted J route to the capturing routes.
1569  addOriginalRouteInfos(routingTableInfo, j + 1, m + 1, routeInfoJ->originalRouteInfos);
1570 
1571  // move original routes from the routes following the merged one if necessary.
1572  for (int k = m + 1; k < (int)routingTableInfo.routeInfos.size(); k++) {
1573  IPv4NetworkConfigurator::RouteInfo *followingRouteInfo = routingTableInfo.routeInfos.at(k);
1574  for (int l = 0; l < (int)followingRouteInfo->originalRouteInfos.size(); l++) {
1575  IPv4NetworkConfigurator::RouteInfo *originalRouteInfo = followingRouteInfo->originalRouteInfos.at(l);
1576  if (!((originalRouteInfo->destination ^ mergedRouteInfo->destination) & mergedRouteInfo->netmask)) {
1577  followingRouteInfo->originalRouteInfos.erase(followingRouteInfo->originalRouteInfos.begin() + l);
1578  ASSERT(mergedRouteInfo->color == originalRouteInfo->color);
1579  mergedRouteInfo->originalRouteInfos.push_back(originalRouteInfo);
1580  l--;
1581  }
1582  }
1583  }
1584  routingTableInfo.removeRouteInfo(routeInfoI);
1585  routingTableInfo.removeRouteInfo(routeInfoJ);
1586 #ifndef NDEBUG
1587  //checkOriginalRoutes(routingTableInfo, originalRouteInfos);
1588 #endif // ifndef NDEBUG
1589  delete routeInfoI;
1590  delete routeInfoJ;
1591  return true;
1592  }
1593  else {
1594  // merge failed; restore original state
1595  routeInfoI->enabled = true;
1596  routeInfoJ->enabled = true;
1597  routingTableInfo.removeRouteInfo(mergedRouteInfo);
1598  delete mergedRouteInfo;
1599  return false;
1600  }
1601 }
void addOriginalRouteInfos(RoutingTableInfo &routingTableInfo, int begin, int end, const std::vector< RouteInfo * > &originalRouteInfos)
Adds all of the original routes to the matching optimized routes between begin and end...
Definition: IPv4NetworkConfigurator.cc:1521
uint32_t uint32
Definition: Compat.h:30
void findLongestCommonDestinationPrefix(uint32 destination1, uint32 netmask1, uint32 destination2, uint32 netmask2, uint32 &destinationOut, uint32 &netmaskOut)
Returns the longest shared address prefix and netmask by iterating through bits from left to right...
Definition: IPv4NetworkConfigurator.cc:1501
bool interruptsSubsequentOriginalRoutes(const RoutingTableInfo &routingTableInfo, int index)
Returns true if any of the original routes attached to the routes in the routing table below index ar...
Definition: IPv4NetworkConfigurator.cc:1475
bool interruptsAnyOriginalRoute(const RoutingTableInfo &routingTableInfo, int begin, int end, const std::vector< RouteInfo * > &originalRouteInfos)
Returns true if any of the original routes is interrupted by any of the routes in the routing table b...
Definition: IPv4NetworkConfigurator.cc:1461
const double k
Definition: QAM16Modulation.cc:24
value< double, units::m > m
Definition: Units.h:1047

Member Data Documentation

bool inet::IPv4NetworkConfigurator::addDefaultRoutesParameter
protected

Referenced by addStaticRoutes(), and initialize().

bool inet::IPv4NetworkConfigurator::addStaticRoutesParameter
protected

Referenced by computeConfiguration(), and initialize().

bool inet::IPv4NetworkConfigurator::addSubnetRoutesParameter
protected

Referenced by addStaticRoutes(), and initialize().

bool inet::IPv4NetworkConfigurator::assignAddressesParameter
protected
bool inet::IPv4NetworkConfigurator::assignDisjunctSubnetAddressesParameter
protected

Referenced by assignAddresses(), and initialize().

bool inet::IPv4NetworkConfigurator::optimizeRoutesParameter
protected

Referenced by addStaticRoutes(), and initialize().


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