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 InterfaceEntry *ie)
 Returns the index of the first selector that matches the interface. More...
 

Private Member Functions

bool linkContainsMatchingHost (const InterfaceEntry *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: , , , and . The value of these attributes are space separated name patterns. ...

  • : specifies the names of the host module of the interface. Qualified names are accepted, but not required.
  • : specifies the names of the interfaces
  • : specifies the names of the hosts which the interface is connected to
  • : 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

inet::InterfaceMatcher::InterfaceMatcher ( const cXMLElementList &  selectors)
78 {
79  for (auto & xmlSelector : xmlSelectors) {
80  cXMLElement *interfaceElement = xmlSelector;
81  const char *hostAttr = interfaceElement->getAttribute("hosts"); // "host* router[0..3]"
82  const char *interfaceAttr = interfaceElement->getAttribute("names"); // i.e. interface names, like "eth* ppp0"
83 
84  const char *towardsAttr = interfaceElement->getAttribute("towards"); // neighbor host names, like "ap switch"
85  const char *amongAttr = interfaceElement->getAttribute("among"); // neighbor host names, like "host[*] router1"
86 
87  if (amongAttr && *amongAttr) { // among="X Y Z" means hosts = "X Y Z" towards = "X Y Z"
88  if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
89  throw cRuntimeError("The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s", interfaceElement->getSourceLocation());
90  towardsAttr = hostAttr = amongAttr;
91  }
92 
93  try {
94  selectors.push_back(new Selector(hostAttr, interfaceAttr, towardsAttr, this));
95  }
96  catch (std::exception& e) {
97  throw cRuntimeError("Error in XML <interface> element at %s: %s", interfaceElement->getSourceLocation(), e.what());
98  }
99  }
100 }
const value< double, units::C > e(1.602176487e-19)
std::vector< Selector * > selectors
Definition: InterfaceMatcher.h:74
inet::InterfaceMatcher::~InterfaceMatcher ( )
103 {
104  for (auto & elem : selectors)
105  delete elem;
106 }
std::vector< Selector * > selectors
Definition: InterfaceMatcher.h:74

Member Function Documentation

void inet::InterfaceMatcher::collectNeighbors ( cGate *  outGate,
std::vector< cModule * > &  hostNodes,
std::vector< cModule * > &  deviceNodes,
cModule *  exludedNode 
) const
private

Referenced by linkContainsMatchingHost().

156 {
157  cGate *neighborGate = findRemoteGate(outGate);
158  if (!neighborGate)
159  return;
160 
161  cModule *neighborNode = neighborGate->getOwnerModule();
162  if (hasInterfaceTable(neighborNode)) {
163  // neighbor is a host or router
164  if (neighborNode != excludedNode && !contains(hostNodes, neighborNode))
165  hostNodes.push_back(neighborNode);
166  }
167  else {
168  // assume that neighbor is an L2 or L1 device (bus/hub/switch/bridge/access point/etc); visit all its output links
169  if (!contains(deviceNodes, neighborNode)) {
170  if (neighborNode != excludedNode)
171  deviceNodes.push_back(neighborNode);
172  for (cModule::GateIterator it(neighborNode); !it.end(); it++) {
173  cGate *gate = *it;
174  if (gate->getType() == cGate::OUTPUT)
175  collectNeighbors(gate, hostNodes, deviceNodes, excludedNode);
176  }
177  }
178  }
179 }
bool contains(const std::vector< T > &v, const T &a)
Definition: stlutils.h:69
void collectNeighbors(cGate *outGate, std::vector< cModule * > &hostNodes, std::vector< cModule * > &deviceNodes, cModule *exludedNode) const
Definition: InterfaceMatcher.cc:155
int inet::InterfaceMatcher::findMatchingSelector ( const InterfaceEntry ie)

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

Referenced by inet::PIMInterfaceTable::addInterface(), inet::PIMInterfaceTable::configureInterfaces(), inet::RIPRouting::configureInterfaces(), and inet::RIPRouting::receiveSignal().

112 {
113  for (int i = 0; i < (int)selectors.size(); i++)
114  if (selectors[i]->matches(ie))
115  return i;
116 
117  return -1;
118 }
std::vector< Selector * > selectors
Definition: InterfaceMatcher.h:74
bool inet::InterfaceMatcher::linkContainsMatchingHost ( const InterfaceEntry ie,
const Matcher hostMatcher 
) const
private

Referenced by inet::InterfaceMatcher::Selector::matches().

135 {
136  int outGateId = ie->getNodeOutputGateId();
137  cModule *node = ie->getInterfaceTable()->getHostModule();
138  cGate *outGate = node->gate(outGateId);
139 
140  std::vector<cModule *> hostNodes;
141  std::vector<cModule *> deviceNodes;
142  collectNeighbors(outGate, hostNodes, deviceNodes, node);
143 
144  for (auto neighbour : hostNodes) {
145 
146  std::string hostFullPath = neighbour->getFullPath();
147  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
148  if (hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str()))
149  return true;
150  }
151 
152  return false;
153 }
void collectNeighbors(cGate *outGate, std::vector< cModule * > &hostNodes, std::vector< cModule * > &deviceNodes, cModule *exludedNode) const
Definition: InterfaceMatcher.cc:155

Member Data Documentation

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

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