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

Utility class for configuring interfaces. More...

#include <InterfaceMatcher.h>

Classes

class  Matcher
 
struct  Selector
 

Public Member Functions

 InterfaceMatcher (const cXMLElementList &selectors)
 
 ~InterfaceMatcher ()
 
int findMatchingSelector (const NetworkInterface *ie)
 Returns the index of the first selector that matches the interface. More...
 

Private Member Functions

bool linkContainsMatchingHost (const NetworkInterface *ie, const Matcher &hostMatcher) const
 
void collectNeighbors (cGate *outGate, std::vector< cModule * > &hostNodes, std::vector< cModule * > &deviceNodes, cModule *exludedNode) const
 

Private Attributes

std::vector< Selector * > selectors
 

Detailed Description

Utility class for configuring interfaces.

It is assumed that the configuration is described by an xml document. Each element in the configuration applies parameters to a set of interfaces. These interfaces are selected by a set of selector attributes: @hosts, @names, @towards, and @among. The value of these attributes are space separated name patterns. ...

  • @hosts: specifies the names of the host module of the interface. Qualified names are accepted, but not required.
  • @names: specifies the names of the interfaces
  • @towards: specifies the names of the hosts which the interface is connected to
  • @among: specifies the names of hosts, and select the interfaces of those hosts that are connected to that hosts among="X Y Z" is the same as hosts="X Y Z" towards="X Y Z"

If there are more selector attributes in an element, all of them are required to match.

Constructor & Destructor Documentation

◆ InterfaceMatcher()

inet::InterfaceMatcher::InterfaceMatcher ( const cXMLElementList &  selectors)
66 {
67  for (auto& xmlSelector : xmlSelectors) {
68  cXMLElement *interfaceElement = xmlSelector;
69  const char *hostAttr = interfaceElement->getAttribute("hosts"); // "host* router[0..3]"
70  const char *interfaceAttr = interfaceElement->getAttribute("names"); // i.e. interface names, like "eth* ppp0"
71 
72  const char *towardsAttr = interfaceElement->getAttribute("towards"); // neighbor host names, like "ap switch"
73  const char *amongAttr = interfaceElement->getAttribute("among"); // neighbor host names, like "host[*] router1"
74 
75  if (amongAttr && *amongAttr) { // among="X Y Z" means hosts = "X Y Z" towards = "X Y Z"
76  if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
77  throw cRuntimeError("The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s", interfaceElement->getSourceLocation());
78  towardsAttr = hostAttr = amongAttr;
79  }
80 
81  try {
82  selectors.push_back(new Selector(hostAttr, interfaceAttr, towardsAttr, this));
83  }
84  catch (std::exception& e) {
85  throw cRuntimeError("Error in XML <interface> element at %s: %s", interfaceElement->getSourceLocation(), e.what());
86  }
87  }
88 }

◆ ~InterfaceMatcher()

inet::InterfaceMatcher::~InterfaceMatcher ( )
91 {
92  for (auto& elem : selectors)
93  delete elem;
94 }

Member Function Documentation

◆ collectNeighbors()

void inet::InterfaceMatcher::collectNeighbors ( cGate *  outGate,
std::vector< cModule * > &  hostNodes,
std::vector< cModule * > &  deviceNodes,
cModule *  exludedNode 
) const
private
144 {
145  cGate *neighborGate = findRemoteGate(outGate);
146  if (!neighborGate)
147  return;
148 
149  cModule *neighborNode = neighborGate->getOwnerModule();
150  if (hasInterfaceTable(neighborNode)) {
151  // neighbor is a host or router
152  if (neighborNode != excludedNode && !contains(hostNodes, neighborNode))
153  hostNodes.push_back(neighborNode);
154  }
155  else {
156  // assume that neighbor is an L2 or L1 device (bus/hub/switch/bridge/access point/etc); visit all its output links
157  if (!contains(deviceNodes, neighborNode)) {
158  if (neighborNode != excludedNode)
159  deviceNodes.push_back(neighborNode);
160  for (cModule::GateIterator it(neighborNode); !it.end(); it++) {
161  cGate *gate = *it;
162  if (gate->getType() == cGate::OUTPUT)
163  collectNeighbors(gate, hostNodes, deviceNodes, excludedNode);
164  }
165  }
166  }
167 }

Referenced by linkContainsMatchingHost().

◆ findMatchingSelector()

int inet::InterfaceMatcher::findMatchingSelector ( const NetworkInterface ie)

Returns the index of the first selector that matches the interface.

100 {
101  for (int i = 0; i < (int)selectors.size(); i++)
102  if (selectors[i]->matches(ie))
103  return i;
104 
105  return -1;
106 }

Referenced by inet::PimInterfaceTable::addInterface(), inet::PimInterfaceTable::configureInterfaces(), inet::Rip::receiveSignal(), and inet::Rip::startRIPRouting().

◆ linkContainsMatchingHost()

bool inet::InterfaceMatcher::linkContainsMatchingHost ( const NetworkInterface ie,
const Matcher hostMatcher 
) const
private
123 {
124  int outGateId = ie->getNodeOutputGateId();
125  cModule *node = ie->getInterfaceTable()->getHostModule();
126  cGate *outGate = node->gate(outGateId);
127 
128  std::vector<cModule *> hostNodes;
129  std::vector<cModule *> deviceNodes;
130  collectNeighbors(outGate, hostNodes, deviceNodes, node);
131 
132  for (auto neighbour : hostNodes) {
133 
134  std::string hostFullPath = neighbour->getFullPath();
135  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
136  if (hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str()))
137  return true;
138  }
139 
140  return false;
141 }

Member Data Documentation

◆ selectors

std::vector<Selector *> inet::InterfaceMatcher::selectors
private

The documentation for this class was generated from the following files:
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
inet::InterfaceMatcher::selectors
std::vector< Selector * > selectors
Definition: InterfaceMatcher.h:60
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::InterfaceMatcher::collectNeighbors
void collectNeighbors(cGate *outGate, std::vector< cModule * > &hostNodes, std::vector< cModule * > &deviceNodes, cModule *exludedNode) const
Definition: InterfaceMatcher.cc:143