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

#include <NetworkConfiguratorBase.h>

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

Classes

class  InterfaceInfo
 Represents an interface in the network. More...
 
class  InterfaceMatcher
 
class  Link
 Represents a connection (wired or wireless) in the network. More...
 
class  LinkInfo
 Represents a "link" in the network. More...
 
class  Matcher
 
class  Node
 Represents a node in the network. More...
 
class  Topology
 Represents the network topology. More...
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void extractTopology (Topology &topology)
 Extracts network topology by walking through the module hierarchy. More...
 
virtual void extractWiredNeighbors (Topology &topology, Topology::LinkOut *linkOut, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractWirelessNeighbors (Topology &topology, const char *wirelessId, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
 
virtual void extractDeviceNeighbors (Topology &topology, Node *node, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &deviceNodesVisited)
 
virtual InterfaceInfodetermineGatewayForLink (LinkInfo *linkInfo)
 If this link has exactly one node that connects to other links as well, we can assume it is a "gateway" and return that (we'll use it in routing); otherwise return nullptr. More...
 
virtual double computeNodeWeight (Node *node, const char *metric, cXMLElement *parameters)
 
virtual double computeLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual double computeWiredLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual double computeWirelessLinkWeight (Link *link, const char *metric, cXMLElement *parameters)
 
virtual bool isBridgeNode (Node *node)
 
virtual bool isWirelessInterface (InterfaceEntry *interfaceEntry)
 
virtual const char * getWirelessId (InterfaceEntry *interfaceEntry)
 If this function returns the same string for two wireless interfaces, they will be regarded as being in the same wireless network. More...
 
virtual InterfaceInfocreateInterfaceInfo (Topology &topology, Node *node, LinkInfo *linkInfo, InterfaceEntry *interfaceEntry)
 
virtual Topology::LinkOutfindLinkOut (Node *node, int gateId)
 
virtual InterfaceInfofindInterfaceInfo (Node *node, InterfaceEntry *interfaceEntry)
 
virtual IInterfaceTablefindInterfaceTable (Node *node)
 
virtual IRoutingTablefindRoutingTable (Node *node)
 
virtual void dumpTopology (Topology &topology)
 
- Protected Member Functions inherited from inet::L3AddressResolver
virtual bool getIPv4AddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getIPv6AddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getMACAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getModulePathAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getModuleIdAddressFrom (L3Address &retAddr, IInterfaceTable *ift, bool netmask)
 
virtual bool getInterfaceIPv4Address (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceIPv6Address (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceMACAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceModulePathAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 
virtual bool getInterfaceModuleIdAddress (L3Address &ret, InterfaceEntry *ie, bool mask)
 

Protected Attributes

double minLinkWeight = NaN
 
cXMLElement * configuration = nullptr
 

Additional Inherited Members

- Public Types inherited from inet::L3AddressResolver
enum  {
  ADDR_IPv4 = 1, ADDR_IPv6 = 2, ADDR_MAC = 4, ADDR_MODULEPATH = 8,
  ADDR_MODULEID = 16, ADDR_MASK = 32
}
 
- Public Member Functions inherited from inet::L3AddressResolver
 L3AddressResolver ()
 
virtual ~L3AddressResolver ()
 
virtual L3Address resolve (const char *str, int addrType=DEFAULT_ADDR_TYPE)
 Accepts dotted decimal notation ("127.0.0.1"), module name of the host or router ("host[2]"), and empty string (""). More...
 
virtual std::vector< L3Addressresolve (std::vector< std::string > strs, int addrType=DEFAULT_ADDR_TYPE)
 Utility function: Calls resolve() for each item in the string vector, and returns the result in an address vector. More...
 
virtual bool tryResolve (const char *str, L3Address &result, int addrType=DEFAULT_ADDR_TYPE)
 Similar to resolve(), but returns false (instead of throwing an error) if the address cannot be resolved because the given host (or interface) doesn't have an address assigned yet. More...
 
virtual L3Address addressOf (cModule *host, int addrType=DEFAULT_ADDR_TYPE)
 Returns IPv4 or IPv6 address of the given host or router. More...
 
virtual L3Address addressOf (cModule *host, const char *ifname, int addrType=DEFAULT_ADDR_TYPE)
 Similar to addressOf(), but only looks at the given interface. More...
 
virtual L3Address addressOf (cModule *host, cModule *destmod, int addrType=DEFAULT_ADDR_TYPE)
 Returns IPv4 or IPv6 address of the given host or router. More...
 
virtual L3Address routerIdOf (cModule *host)
 Returns the router Id of the given router. More...
 
virtual L3Address getAddressFrom (IInterfaceTable *ift, int addrType=DEFAULT_ADDR_TYPE)
 Returns the IPv4 or IPv6 address of the given host or router, given its IInterfaceTable module. More...
 
virtual L3Address getAddressFrom (InterfaceEntry *ie, int addrType=DEFAULT_ADDR_TYPE)
 Returns the IPv4 or IPv6 address of the given interface (of a host or router). More...
 
virtual IInterfaceTableinterfaceTableOf (cModule *host)
 The function tries to look up the IInterfaceTable module as submodule "interfaceTable" or "networkLayer.interfaceTable" within the host/router module. More...
 
virtual IIPv4RoutingTableroutingTableOf (cModule *host)
 The function tries to look up the IIPv4RoutingTable module as submodule "routingTable" or "networkLayer.routingTable" within the host/router module. More...
 
virtual IPv6RoutingTableroutingTable6Of (cModule *host)
 The function tries to look up the IPv6RoutingTable module as submodule "routingTable6" or "networkLayer.routingTable6" within the host/router module. More...
 
virtual IInterfaceTablefindInterfaceTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual IIPv4RoutingTablefindIPv4RoutingTableOf (cModule *host)
 Like routingTableOf(), but doesn't throw error if not found. More...
 
virtual IPv6RoutingTablefindIPv6RoutingTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual GenericRoutingTablefindGenericRoutingTableOf (cModule *host)
 Like interfaceTableOf(), but doesn't throw error if not found. More...
 
virtual cModule * findHostWithAddress (const L3Address &addr)
 Find the Host with the specified address. More...
 

Member Function Documentation

double inet::NetworkConfiguratorBase::computeLinkWeight ( Link link,
const char *  metric,
cXMLElement *  parameters 
)
protectedvirtual

Referenced by inet::IPv4NetworkConfigurator::addStaticRoutes().

299 {
300  if ((link->sourceInterfaceInfo && isWirelessInterface(link->sourceInterfaceInfo->interfaceEntry)) ||
301  (link->destinationInterfaceInfo && isWirelessInterface(link->destinationInterfaceInfo->interfaceEntry)))
302  return computeWirelessLinkWeight(link, metric, parameters);
303  else
304  return computeWiredLinkWeight(link, metric, parameters);
305 }
virtual bool isWirelessInterface(InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:250
virtual double computeWirelessLinkWeight(Link *link, const char *metric, cXMLElement *parameters)
Definition: NetworkConfiguratorBase.cc:348
virtual double computeWiredLinkWeight(Link *link, const char *metric, cXMLElement *parameters)
Definition: NetworkConfiguratorBase.cc:307
double inet::NetworkConfiguratorBase::computeNodeWeight ( Node node,
const char *  metric,
cXMLElement *  parameters 
)
protectedvirtual

Referenced by inet::IPv4NetworkConfigurator::addStaticRoutes().

286 {
287  const char *costAttribute = parameters->getAttribute("cost");
288  if (costAttribute != nullptr)
289  return parseCostAttribute(costAttribute);
290  else {
291  if (node->routingTable && !node->routingTable->isForwardingEnabled())
292  return INFINITY;
293  else
294  return 0;
295  }
296 }
#define INFINITY
Definition: Topology.h:29
double inet::NetworkConfiguratorBase::computeWiredLinkWeight ( Link link,
const char *  metric,
cXMLElement *  parameters 
)
protectedvirtual
308 {
309  const char *costAttribute = parameters->getAttribute("cost");
310  if (costAttribute != nullptr)
311  return parseCostAttribute(costAttribute);
312  else {
313  Topology::LinkOut *linkOut = static_cast<Topology::LinkOut *>(static_cast<Topology::Link *>(link));
314  if (!strcmp(metric, "hopCount"))
315  return 1;
316  else if (!strcmp(metric, "delay")) {
317  cDatarateChannel *transmissionChannel = dynamic_cast<cDatarateChannel *>(linkOut->getLocalGate()->getTransmissionChannel());
318  if (transmissionChannel != nullptr)
319  return transmissionChannel->getDelay().dbl();
320  else
321  return minLinkWeight;
322  }
323  else if (!strcmp(metric, "dataRate")) {
324  cChannel *transmissionChannel = linkOut->getLocalGate()->getTransmissionChannel();
325  if (transmissionChannel != nullptr) {
326  double dataRate = transmissionChannel->getNominalDatarate();
327  return dataRate != 0 ? 1 / dataRate : minLinkWeight;
328  }
329  else
330  return minLinkWeight;
331  }
332  else if (!strcmp(metric, "errorRate")) {
333  cDatarateChannel *transmissionChannel = dynamic_cast<cDatarateChannel *>(linkOut->getLocalGate()->getTransmissionChannel());
334  if (transmissionChannel) {
335  InterfaceInfo *sourceInterfaceInfo = link->sourceInterfaceInfo;
336  double bitErrorRate = transmissionChannel->getBitErrorRate();
337  double packetErrorRate = 1.0 - pow(1.0 - bitErrorRate, sourceInterfaceInfo->interfaceEntry->getMTU());
338  return minLinkWeight - log(1 - packetErrorRate);
339  }
340  else
341  return minLinkWeight;
342  }
343  else
344  throw cRuntimeError("Unknown metric");
345  }
346 }
double minLinkWeight
Definition: NetworkConfiguratorBase.h:159
double inet::NetworkConfiguratorBase::computeWirelessLinkWeight ( Link link,
const char *  metric,
cXMLElement *  parameters 
)
protectedvirtual
349 {
350  const char *costAttribute = parameters->getAttribute("cost");
351  if (costAttribute != nullptr)
352  return parseCostAttribute(costAttribute);
353  else {
354  if (!strcmp(metric, "hopCount"))
355  return 1;
356 #ifdef WITH_RADIO
357  else if (!strcmp(metric, "delay")) {
358  // compute the delay between the two interfaces using a dummy transmission
359  const InterfaceInfo *transmitterInterfaceInfo = link->sourceInterfaceInfo;
360  const InterfaceInfo *receiverInterfaceInfo = link->destinationInterfaceInfo;
361  cModule *transmitterInterfaceModule = transmitterInterfaceInfo->interfaceEntry->getInterfaceModule();
362  cModule *receiverInterfaceModule = receiverInterfaceInfo->interfaceEntry->getInterfaceModule();
363  const IRadio *transmitterRadio = check_and_cast<IRadio *>(transmitterInterfaceModule->getSubmodule("radio"));
364  const IRadio *receiverRadio = check_and_cast<IRadio *>(receiverInterfaceModule->getSubmodule("radio"));
365  const cPacket *macFrame = new cPacket();
366  const IRadioMedium *radioMedium = receiverRadio->getMedium();
367  const ITransmission *transmission = transmitterRadio->getTransmitter()->createTransmission(transmitterRadio, macFrame, simTime());
368  const IArrival *arrival = radioMedium->getPropagation()->computeArrival(transmission, receiverRadio->getAntenna()->getMobility());
369  return arrival->getStartPropagationTime().dbl();
370  }
371  else if (!strcmp(metric, "dataRate")) {
372  cModule *transmitterInterfaceModule = link->sourceInterfaceInfo->interfaceEntry->getInterfaceModule();
373  IRadio *transmitterRadio = check_and_cast<IRadio *>(transmitterInterfaceModule->getSubmodule("radio"));
374  const FlatTransmitterBase *transmitter = dynamic_cast<const FlatTransmitterBase *>(transmitterRadio->getTransmitter());
375  double dataRate = transmitter ? transmitter->getBitrate().get() : 0;
376  return dataRate != 0 ? 1 / dataRate : minLinkWeight;
377  }
378  else if (!strcmp(metric, "errorRate")) {
379  // compute the packet error rate between the two interfaces using a dummy transmission
380  const InterfaceInfo *transmitterInterfaceInfo = link->sourceInterfaceInfo;
381  const InterfaceInfo *receiverInterfaceInfo = link->destinationInterfaceInfo;
382  cModule *transmitterInterfaceModule = transmitterInterfaceInfo->interfaceEntry->getInterfaceModule();
383  cModule *receiverInterfaceModule = receiverInterfaceInfo->interfaceEntry->getInterfaceModule();
384  const IRadio *transmitterRadio = check_and_cast<IRadio *>(transmitterInterfaceModule->getSubmodule("radio"));
385  const IRadio *receiverRadio = check_and_cast<IRadio *>(receiverInterfaceModule->getSubmodule("radio"));
386  const IRadioMedium *medium = receiverRadio->getMedium();
387  cPacket *macFrame = new cPacket();
388  macFrame->setByteLength(transmitterInterfaceInfo->interfaceEntry->getMTU());
389  const ITransmission *transmission = transmitterRadio->getTransmitter()->createTransmission(transmitterRadio, macFrame, simTime());
390  const IArrival *arrival = medium->getPropagation()->computeArrival(transmission, receiverRadio->getAntenna()->getMobility());
391  const IListening *listening = receiverRadio->getReceiver()->createListening(receiverRadio, arrival->getStartTime(), arrival->getEndTime(), arrival->getStartPosition(), arrival->getEndPosition());
392  const INoise *noise = medium->getBackgroundNoise() != nullptr ? medium->getBackgroundNoise()->computeNoise(listening) : nullptr;
393  const IReception *reception = medium->getAnalogModel()->computeReception(receiverRadio, transmission, arrival);
394  const IInterference *interference = new Interference(noise, new std::vector<const IReception *>());
395  const ISNIR *snir = medium->getAnalogModel()->computeSNIR(reception, noise);
396  const IReceiver *receiver = receiverRadio->getReceiver();
397  const ReceptionIndication *receptionIndication = receiver->computeReceptionIndication(snir);
398  bool isReceptionPossible = receiver->computeIsReceptionPossible(listening, reception, IRadioSignal::SIGNAL_PART_WHOLE);
399  double packetErrorRate = isReceptionPossible ? receptionIndication->getPacketErrorRate() : 1;
400  delete receptionIndication;
401  delete snir;
402  delete interference;
403  delete reception;
404  delete listening;
405  delete arrival;
406  delete transmission;
407  delete macFrame;
408  // we want to have a maximum PER product along the path,
409  // but still minimize the hop count if the PER is negligible
410  return minLinkWeight - log(1 - packetErrorRate);
411  }
412 #endif
413  else
414  throw cRuntimeError("Unknown metric");
415  }
416 }
virtual const IArrival * computeArrival(const ITransmission *transmission, IMobility *mobility) const =0
Returns the time and space coordinates when the transmission arrives at the object that moves with th...
This interface represents how a receiver is listening on the radio channel.
Definition: IListening.h:33
This interface represents the reception of a transmission at a receiver.
Definition: IReception.h:35
virtual bool computeIsReceptionPossible(const IListening *listening, const ITransmission *transmission) const =0
Returns whether the reception of the provided transmission is possible or not independently of the re...
const value_type & get() const
Definition: Units.h:89
virtual const IPropagation * getPropagation() const =0
Returns the radio signal propagation model of this radio medium.
This interface represents the interference related to a reception.
Definition: IInterference.h:33
virtual const IRadio * getReceiver() const =0
Class generated from inet/physicallayer/contract/packetlevel/RadioControlInfo.msg:69 by nedtool...
Definition: RadioControlInfo_m.h:200
virtual const ITransmission * createTransmission(const IRadio *transmitter, const cPacket *macFrame, const simtime_t startTime) const =0
Returns a transmission which describes the radio signal corresponding to the provided mac frame...
virtual double getPacketErrorRate() const
double minLinkWeight
Definition: NetworkConfiguratorBase.h:159
Definition: ISNIR.h:28
virtual const Coord getStartPosition() const =0
This interface represents a physical device that is capable of transmitting and receiving radio signa...
Definition: IRadio.h:44
virtual const simtime_t getEndTime() const =0
virtual const ITransmitter * getTransmitter() const =0
Returns the transmitter part of this radio.
This interface represents a meaningless radio signal.
Definition: INoise.h:30
virtual const simtime_t getStartTime() const =0
This interface represents the whole radio medium.
Definition: IRadioMedium.h:51
virtual const simtime_t getStartPropagationTime() const =0
virtual bps getBitrate() const
Definition: FlatTransmitterBase.h:46
This interface represents the space and time coordinates of a transmission arriving at a receiver...
Definition: IArrival.h:36
virtual const ReceptionIndication * computeReceptionIndication(const ISNIR *snir) const =0
Returns the reception indication (control info) that is sent up to the MAC.
virtual const Coord getEndPosition() const =0
Definition: Interference.h:27
Definition: FlatTransmitterBase.h:27
This interface represents the transmission of a radio signal.
Definition: ITransmission.h:41
virtual const IReceptionAnalogModel * getAnalogModel() const =0
Returns the analog model of the received signal.
This interface represents a physical device (a part of the radio) which converts electric signals int...
Definition: IReceiver.h:52
NetworkConfiguratorBase::InterfaceInfo * inet::NetworkConfiguratorBase::createInterfaceInfo ( Topology topology,
Node node,
LinkInfo linkInfo,
InterfaceEntry interfaceEntry 
)
protectedvirtual

Reimplemented in inet::IPv4NetworkConfigurator.

516 {
517  InterfaceInfo *interfaceInfo = new InterfaceInfo(node, linkInfo, ie);
518  node->interfaceInfos.push_back(interfaceInfo);
519  topology.interfaceInfos[ie] = interfaceInfo;
520  return interfaceInfo;
521 }
NetworkConfiguratorBase::InterfaceInfo * inet::NetworkConfiguratorBase::determineGatewayForLink ( LinkInfo linkInfo)
protectedvirtual

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.

481 {
482  InterfaceInfo *gatewayInterfaceInfo = nullptr;
483  for (auto & interfaceInfo : linkInfo->interfaceInfos) {
484  IInterfaceTable *interfaceTable = interfaceInfo->node->interfaceTable;
485  IRoutingTable *routingTable = interfaceInfo->node->routingTable;
486 
487  // count how many (non-loopback) interfaces this node has
488  int numInterfaces = 0;
489  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
490  if (!interfaceTable->getInterface(i)->isLoopback())
491  numInterfaces++;
492 
493 
494  if (numInterfaces > 1 && routingTable && routingTable->isForwardingEnabled()) {
495  // node has at least one more interface, supposedly connecting to another link
496  if (gatewayInterfaceInfo)
497  return nullptr; // we already found one gateway, this makes it ambiguous! report "no gateway"
498  else
499  gatewayInterfaceInfo = interfaceInfo; // remember gateway
500  }
501  }
502  return gatewayInterfaceInfo;
503 }
void inet::NetworkConfiguratorBase::dumpTopology ( Topology topology)
protectedvirtual

Referenced by inet::IPv4NetworkConfigurator::dumpConfiguration(), and inet::GenericNetworkConfigurator::initialize().

601 {
602  for (int i = 0; i < topology.getNumNodes(); i++) {
603  Node *node = (Node *)topology.getNode(i);
604  EV_INFO << "Node " << node->module->getFullPath() << endl;
605  for (int j = 0; j < node->getNumOutLinks(); j++) {
606  Topology::LinkOut *linkOut = node->getLinkOut(j);
607  ASSERT(linkOut->getLocalNode() == node);
608  Node *remoteNode = (Node *)linkOut->getRemoteNode();
609  EV_INFO << " -> " << remoteNode->module->getFullPath() << endl;
610  }
611  for (int j = 0; j < node->getNumInLinks(); j++) {
612  Topology::LinkIn *linkIn = node->getLinkIn(j);
613  ASSERT(linkIn->getLocalNode() == node);
614  Node *remoteNode = (Node *)linkIn->getRemoteNode();
615  EV_INFO << " <- " << remoteNode->module->getFullPath() << endl;
616  }
617  }
618 }
void inet::NetworkConfiguratorBase::extractDeviceNeighbors ( Topology topology,
Node node,
LinkInfo linkInfo,
std::set< InterfaceEntry * > &  interfacesSeen,
std::vector< Node * > &  deviceNodesVisited 
)
protectedvirtual
216 {
217  deviceNodesVisited.push_back(node);
218  IInterfaceTable *interfaceTable = node->interfaceTable;
219  if (interfaceTable) {
220  // switch and access point
221  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++) {
222  InterfaceEntry *interfaceEntry = interfaceTable->getInterface(i);
223  if (!interfaceEntry->isLoopback() && interfacesSeen.count(interfaceEntry) == 0) {
224  if (isWirelessInterface(interfaceEntry))
225  extractWirelessNeighbors(topology, getWirelessId(interfaceEntry), linkInfo, interfacesSeen, deviceNodesVisited);
226  else {
227  Topology::LinkOut *linkOut = findLinkOut(node, interfaceEntry->getNodeOutputGateId());
228  if (linkOut)
229  extractWiredNeighbors(topology, linkOut, linkInfo, interfacesSeen, deviceNodesVisited);
230  }
231  }
232  }
233  }
234  else {
235  // hub and bus
236  for (int i = 0; i < node->getNumOutLinks(); i++) {
237  Topology::LinkOut *linkOut = node->getLinkOut(i);
238  extractWiredNeighbors(topology, linkOut, linkInfo, interfacesSeen, deviceNodesVisited);
239  }
240  }
241 }
virtual const char * getWirelessId(InterfaceEntry *interfaceEntry)
If this function returns the same string for two wireless interfaces, they will be regarded as being ...
Definition: NetworkConfiguratorBase.cc:423
virtual void extractWiredNeighbors(Topology &topology, Topology::LinkOut *linkOut, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
Definition: NetworkConfiguratorBase.cc:167
virtual bool isWirelessInterface(InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:250
virtual Topology::LinkOut * findLinkOut(Node *node, int gateId)
Definition: NetworkConfiguratorBase.cc:255
virtual void extractWirelessNeighbors(Topology &topology, const char *wirelessId, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
Definition: NetworkConfiguratorBase.cc:189
void inet::NetworkConfiguratorBase::extractTopology ( Topology topology)
protectedvirtual

Extracts network topology by walking through the module hierarchy.

Creates vertices from modules having property. Creates edges from connections (wired and wireless) between network interfaces.

Referenced by inet::IPv4NetworkConfigurator::computeConfiguration(), and inet::GenericNetworkConfigurator::initialize().

64 {
65  // extract topology
66  topology.extractByProperty("networkNode");
67  EV_DEBUG << "Topology found " << topology.getNumNodes() << " nodes\n";
68 
69  // extract nodes, fill in interfaceTable and routingTable members in node
70  for (int i = 0; i < topology.getNumNodes(); i++) {
71  Node *node = (Node *)topology.getNode(i);
72  cModule *module = node->getModule();
73  node->module = module;
74  node->interfaceTable = findInterfaceTable(node);
75  node->routingTable = findRoutingTable(node);
76  }
77 
78  // extract links and interfaces
79  std::set<InterfaceEntry *> interfacesSeen;
80  for (int i = 0; i < topology.getNumNodes(); i++) {
81  Node *node = (Node *)topology.getNode(i);
82  IInterfaceTable *interfaceTable = node->interfaceTable;
83  if (interfaceTable) {
84  for (int j = 0; j < interfaceTable->getNumInterfaces(); j++) {
85  InterfaceEntry *interfaceEntry = interfaceTable->getInterface(j);
86  if (!interfaceEntry->isLoopback() && interfacesSeen.count(interfaceEntry) == 0) {
87  if (isBridgeNode(node))
88  createInterfaceInfo(topology, node, nullptr, interfaceEntry);
89  else {
90  interfacesSeen.insert(interfaceEntry);
91  // create a new network link
92  LinkInfo *linkInfo = new LinkInfo();
93  topology.linkInfos.push_back(linkInfo);
94  // store interface as belonging to the new network link
95  InterfaceInfo *interfaceInfo = createInterfaceInfo(topology, node, isBridgeNode(node) ? nullptr : linkInfo, interfaceEntry);
96  linkInfo->interfaceInfos.push_back(interfaceInfo);
97  // visit neighbors (and potentially the whole LAN, recursively)
98  if (isWirelessInterface(interfaceEntry)) {
99  std::vector<Node *> empty;
100  const char *wirelessId = getWirelessId(interfaceEntry);
101  extractWirelessNeighbors(topology, wirelessId, linkInfo, interfacesSeen, empty);
102  }
103  else {
104  Topology::LinkOut *linkOut = findLinkOut(node, interfaceEntry->getNodeOutputGateId());
105  if (linkOut) {
106  std::vector<Node *> empty;
107  extractWiredNeighbors(topology, linkOut, linkInfo, interfacesSeen, empty);
108  }
109  }
110  }
111  }
112  }
113  }
114  }
115 
116  // annotate links with interfaces
117  for (int i = 0; i < topology.getNumNodes(); i++) {
118  Node *node = (Node *)topology.getNode(i);
119  for (int j = 0; j < node->getNumOutLinks(); j++) {
120  Topology::LinkOut *linkOut = node->getLinkOut(j);
121  Link *link = (Link *)linkOut;
122  Node *localNode = (Node *)linkOut->getLocalNode();
123  if (localNode->interfaceTable)
124  link->sourceInterfaceInfo = findInterfaceInfo(localNode, localNode->interfaceTable->getInterfaceByNodeOutputGateId(linkOut->getLocalGateId()));
125  Node *remoteNode = (Node *)linkOut->getRemoteNode();
126  if (remoteNode->interfaceTable)
127  link->destinationInterfaceInfo = findInterfaceInfo(remoteNode, remoteNode->interfaceTable->getInterfaceByNodeInputGateId(linkOut->getRemoteGateId()));
128  }
129  }
130 
131  // collect wireless LAN interface infos into a map
132  std::map<std::string, std::vector<InterfaceInfo *> > wirelessIdToInterfaceInfosMap;
133  for (auto & entry : topology.interfaceInfos) {
134  InterfaceInfo *interfaceInfo = entry.second;
135  InterfaceEntry *interfaceEntry = interfaceInfo->interfaceEntry;
136  if (!interfaceEntry->isLoopback() && isWirelessInterface(interfaceEntry)) {
137  const char *wirelessId = getWirelessId(interfaceEntry);
138  wirelessIdToInterfaceInfosMap[wirelessId].push_back(interfaceInfo);
139  }
140  }
141 
142  // add extra links between all pairs of wireless interfaces within a LAN (full graph)
143  for (auto & entry : wirelessIdToInterfaceInfosMap) {
144  std::vector<InterfaceInfo *>& interfaceInfos = entry.second;
145  for (int i = 0; i < (int)interfaceInfos.size(); i++) {
146  InterfaceInfo *interfaceInfoI = interfaceInfos.at(i);
147  for (int j = i + 1; j < (int)interfaceInfos.size(); j++) {
148  // assume bidirectional links
149  InterfaceInfo *interfaceInfoJ = interfaceInfos.at(j);
150  Link *linkIJ = new Link();
151  linkIJ->sourceInterfaceInfo = interfaceInfoI;
152  linkIJ->destinationInterfaceInfo = interfaceInfoJ;
153  topology.addLink(linkIJ, interfaceInfoI->node, interfaceInfoJ->node);
154  Link *linkJI = new Link();
155  linkJI->sourceInterfaceInfo = interfaceInfoJ;
156  linkJI->destinationInterfaceInfo = interfaceInfoI;
157  topology.addLink(linkJI, interfaceInfoJ->node, interfaceInfoI->node);
158  }
159  }
160  }
161 
162  // determine gatewayInterfaceInfo for all linkInfos
163  for (auto & linkInfo : topology.linkInfos)
164  linkInfo->gatewayInterfaceInfo = determineGatewayForLink(linkInfo);
165 }
virtual const char * getWirelessId(InterfaceEntry *interfaceEntry)
If this function returns the same string for two wireless interfaces, they will be regarded as being ...
Definition: NetworkConfiguratorBase.cc:423
virtual void extractWiredNeighbors(Topology &topology, Topology::LinkOut *linkOut, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
Definition: NetworkConfiguratorBase.cc:167
virtual IInterfaceTable * findInterfaceTable(Node *node)
Definition: NetworkConfiguratorBase.cc:505
virtual bool isWirelessInterface(InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:250
virtual Topology::LinkOut * findLinkOut(Node *node, int gateId)
Definition: NetworkConfiguratorBase.cc:255
virtual bool isBridgeNode(Node *node)
Definition: NetworkConfiguratorBase.cc:245
virtual InterfaceInfo * createInterfaceInfo(Topology &topology, Node *node, LinkInfo *linkInfo, InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:515
virtual InterfaceInfo * determineGatewayForLink(LinkInfo *linkInfo)
If this link has exactly one node that connects to other links as well, we can assume it is a "gatewa...
Definition: NetworkConfiguratorBase.cc:480
const char empty[]
Definition: ConstType.h:37
virtual IRoutingTable * findRoutingTable(Node *node)
Definition: NetworkConfiguratorBase.cc:510
virtual void extractWirelessNeighbors(Topology &topology, const char *wirelessId, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &nodesVisited)
Definition: NetworkConfiguratorBase.cc:189
virtual InterfaceInfo * findInterfaceInfo(Node *node, InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:264
void inet::NetworkConfiguratorBase::extractWiredNeighbors ( Topology topology,
Topology::LinkOut linkOut,
LinkInfo linkInfo,
std::set< InterfaceEntry * > &  interfacesSeen,
std::vector< Node * > &  nodesVisited 
)
protectedvirtual
168 {
169  Node *node = (Node *)linkOut->getRemoteNode();
170  int inputGateId = linkOut->getRemoteGateId();
171  IInterfaceTable *interfaceTable = node->interfaceTable;
172  if (!isBridgeNode(node)) {
173  InterfaceEntry *interfaceEntry = interfaceTable->getInterfaceByNodeInputGateId(inputGateId);
174  if (!interfaceEntry) {
175  // no such interface (node is probably down); we should probably get the information from our (future) internal database
176  }
177  else if (interfacesSeen.count(interfaceEntry) == 0) {
178  InterfaceInfo *neighborInterfaceInfo = createInterfaceInfo(topology, node, linkInfo, interfaceEntry);
179  linkInfo->interfaceInfos.push_back(neighborInterfaceInfo);
180  interfacesSeen.insert(interfaceEntry);
181  }
182  }
183  else {
184  if (!contains(deviceNodesVisited, node))
185  extractDeviceNeighbors(topology, node, linkInfo, interfacesSeen, deviceNodesVisited);
186  }
187 }
virtual bool isBridgeNode(Node *node)
Definition: NetworkConfiguratorBase.cc:245
virtual InterfaceInfo * createInterfaceInfo(Topology &topology, Node *node, LinkInfo *linkInfo, InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:515
virtual void extractDeviceNeighbors(Topology &topology, Node *node, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &deviceNodesVisited)
Definition: NetworkConfiguratorBase.cc:215
bool contains(const std::vector< T > &v, const T &a)
Definition: stlutils.h:69
void inet::NetworkConfiguratorBase::extractWirelessNeighbors ( Topology topology,
const char *  wirelessId,
LinkInfo linkInfo,
std::set< InterfaceEntry * > &  interfacesSeen,
std::vector< Node * > &  nodesVisited 
)
protectedvirtual
190 {
191  for (int nodeIndex = 0; nodeIndex < topology.getNumNodes(); nodeIndex++) {
192  Node *node = (Node *)topology.getNode(nodeIndex);
193  IInterfaceTable *interfaceTable = node->interfaceTable;
194  if (interfaceTable) {
195  for (int j = 0; j < interfaceTable->getNumInterfaces(); j++) {
196  InterfaceEntry *interfaceEntry = interfaceTable->getInterface(j);
197  if (!interfaceEntry->isLoopback() && interfacesSeen.count(interfaceEntry) == 0 && isWirelessInterface(interfaceEntry)) {
198  if (!strcmp(getWirelessId(interfaceEntry), wirelessId)) {
199  if (!isBridgeNode(node)) {
200  InterfaceInfo *interfaceInfo = createInterfaceInfo(topology, node, linkInfo, interfaceEntry);
201  linkInfo->interfaceInfos.push_back(interfaceInfo);
202  interfacesSeen.insert(interfaceEntry);
203  }
204  else {
205  if (!contains(deviceNodesVisited, node))
206  extractDeviceNeighbors(topology, node, linkInfo, interfacesSeen, deviceNodesVisited);
207  }
208  }
209  }
210  }
211  }
212  }
213 }
virtual const char * getWirelessId(InterfaceEntry *interfaceEntry)
If this function returns the same string for two wireless interfaces, they will be regarded as being ...
Definition: NetworkConfiguratorBase.cc:423
virtual bool isWirelessInterface(InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:250
virtual bool isBridgeNode(Node *node)
Definition: NetworkConfiguratorBase.cc:245
virtual InterfaceInfo * createInterfaceInfo(Topology &topology, Node *node, LinkInfo *linkInfo, InterfaceEntry *interfaceEntry)
Definition: NetworkConfiguratorBase.cc:515
virtual void extractDeviceNeighbors(Topology &topology, Node *node, LinkInfo *linkInfo, std::set< InterfaceEntry * > &interfacesSeen, std::vector< Node * > &deviceNodesVisited)
Definition: NetworkConfiguratorBase.cc:215
bool contains(const std::vector< T > &v, const T &a)
Definition: stlutils.h:69
NetworkConfiguratorBase::InterfaceInfo * inet::NetworkConfiguratorBase::findInterfaceInfo ( Node node,
InterfaceEntry interfaceEntry 
)
protectedvirtual
265 {
266  for (auto & interfaceInfo : node->interfaceInfos)
267  if (interfaceInfo->interfaceEntry == interfaceEntry)
268  return interfaceInfo;
269 
270  return nullptr;
271 }
IInterfaceTable * inet::NetworkConfiguratorBase::findInterfaceTable ( Node node)
protectedvirtual
506 {
507  return L3AddressResolver::findInterfaceTableOf(node->module);
508 }
virtual IInterfaceTable * findInterfaceTableOf(cModule *host)
Like interfaceTableOf(), but doesn&#39;t throw error if not found.
Definition: L3AddressResolver.cc:453
Topology::LinkOut * inet::NetworkConfiguratorBase::findLinkOut ( Node node,
int  gateId 
)
protectedvirtual
256 {
257  for (int i = 0; i < node->getNumOutLinks(); i++)
258  if (node->getLinkOut(i)->getLocalGateId() == gateId)
259  return node->getLinkOut(i);
260 
261  return nullptr;
262 }
IRoutingTable * inet::NetworkConfiguratorBase::findRoutingTable ( Node node)
protectedvirtual

Reimplemented in inet::IPv4NetworkConfigurator, and inet::GenericNetworkConfigurator.

511 {
512  return nullptr;
513 }
const char * inet::NetworkConfiguratorBase::getWirelessId ( InterfaceEntry interfaceEntry)
protectedvirtual

If this function returns the same string for two wireless interfaces, they will be regarded as being in the same wireless network.

(The actual value of the string doesn't count.)

424 {
425  // use the configuration
426  cModule *hostModule = interfaceEntry->getInterfaceTable()->getHostModule();
427  std::string hostFullPath = hostModule->getFullPath();
428  std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find('.') + 1);
429  cXMLElementList wirelessElements = configuration->getChildrenByTagName("wireless");
430  for (auto & wirelessElement : wirelessElements) {
431  const char *hostAttr = wirelessElement->getAttribute("hosts"); // "host* router[0..3]"
432  const char *interfaceAttr = wirelessElement->getAttribute("interfaces"); // i.e. interface names, like "eth* ppp0"
433  try {
434  // parse host/interface expressions
435  Matcher hostMatcher(hostAttr);
436  Matcher interfaceMatcher(interfaceAttr);
437 
438  // Note: "hosts", "interfaces" must ALL match on the interface for the rule to apply
439  if ((hostMatcher.matchesAny() || hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str())) &&
440  (interfaceMatcher.matchesAny() || interfaceMatcher.matches(interfaceEntry->getFullName())))
441  {
442  const char *idAttr = wirelessElement->getAttribute("id"); // identifier of wireless connection
443  return idAttr ? idAttr : wirelessElement->getSourceLocation();
444  }
445  }
446  catch (std::exception& e) {
447  throw cRuntimeError("Error in XML <wireless> element at %s: %s", wirelessElement->getSourceLocation(), e.what());
448  }
449  }
450  cModule *interfaceModule = interfaceEntry->getInterfaceModule();
451  cModule *mgmtModule = interfaceModule->getSubmodule("mgmt");
452  if (mgmtModule != nullptr) {
453  if (mgmtModule->hasPar("ssid") && *mgmtModule->par("ssid").stringValue())
454  return mgmtModule->par("ssid");
455  else if (mgmtModule->hasPar("accessPointAddress") && *mgmtModule->par("accessPointAddress").stringValue())
456  return mgmtModule->par("accessPointAddress");
457  }
458  cModule *agentModule = interfaceModule->getSubmodule("agent");
459  if (agentModule != nullptr) {
460  if (agentModule->hasPar("default_ssid") && *agentModule->par("default_ssid").stringValue())
461  return agentModule->par("default_ssid");
462  }
463 #ifdef WITH_RADIO
464  cModule *radioModule = interfaceModule->getSubmodule("radio");
465  const IRadio *radio = dynamic_cast<const IRadio *>(radioModule);
466  if (radio != nullptr) {
467  const cModule *mediumModule = check_and_cast<const cModule *>(radio->getMedium());
468  return mediumModule->getFullName();
469  }
470 #endif
471 
472  // default: put all such wireless interfaces on the same LAN
473  return "SSID";
474 }
virtual const IRadioMedium * getMedium() const =0
Returns the radio medium where this radio is transmitting and receiving radio signals.
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
const value< double, units::C > e(1.602176487e-19)
This interface represents a physical device that is capable of transmitting and receiving radio signa...
Definition: IRadio.h:44
virtual void inet::NetworkConfiguratorBase::handleMessage ( cMessage *  msg)
inlineoverrideprotectedvirtual

Reimplemented in inet::IPv4NetworkConfigurator.

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

Reimplemented in inet::IPv4NetworkConfigurator, and inet::GenericNetworkConfigurator.

Referenced by inet::GenericNetworkConfigurator::initialize(), and inet::IPv4NetworkConfigurator::initialize().

56 {
57  if (stage == INITSTAGE_LOCAL) {
58  minLinkWeight = par("minLinkWeight");
59  configuration = par("config");
60  }
61 }
cXMLElement * configuration
Definition: NetworkConfiguratorBase.h:160
Local initializations.
Definition: InitStages.h:35
double minLinkWeight
Definition: NetworkConfiguratorBase.h:159
bool inet::NetworkConfiguratorBase::isBridgeNode ( Node node)
protectedvirtual

Referenced by inet::GenericNetworkConfigurator::addStaticRoutes(), and inet::IPv4NetworkConfigurator::addStaticRoutes().

246 {
247  return !node->routingTable || !node->interfaceTable;
248 }
bool inet::NetworkConfiguratorBase::isWirelessInterface ( InterfaceEntry interfaceEntry)
protectedvirtual

Referenced by inet::IPv4NetworkConfigurator::dumpConfig().

251 {
252  return !strncmp(interfaceEntry->getName(), "wlan", 4);
253 }
virtual int inet::NetworkConfiguratorBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented in inet::IPv4NetworkConfigurator.

163 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116

Member Data Documentation

double inet::NetworkConfiguratorBase::minLinkWeight = NaN
protected

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