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

Represents the interface table. More...

#include <InterfaceTable.h>

Inheritance diagram for inet::InterfaceTable:
inet::OperationalBase inet::IInterfaceTable inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

 InterfaceTable ()
 
virtual ~InterfaceTable ()
 
virtual std::string getFullPath () const override
 Module path name. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 Called by the signal handler whenever a change of a category occurs to which this client has subscribed. More...
 
virtual cModule * getHostModule () const override
 Returns the host or router this interface table lives in. More...
 
virtual bool isLocalAddress (const L3Address &address) const override
 Checks if the address is a local one, i.e. More...
 
virtual bool isNeighborAddress (const L3Address &address) const override
 Checks if the address is on the network of one of the interfaces, but not local. More...
 
virtual NetworkInterfacefindInterfaceByAddress (const L3Address &address) const override
 Returns an interface given by its address. More...
 
virtual void addInterface (NetworkInterface *entry) override
 Adds an interface. More...
 
virtual void deleteInterface (NetworkInterface *entry) override
 Deletes the given interface from the table. More...
 
virtual int getNumInterfaces () const override
 Returns the number of interfaces. More...
 
virtual NetworkInterfacegetInterface (int pos) const override
 Returns the NetworkInterface specified by an index 0..numInterfaces-1. More...
 
virtual NetworkInterfacefindInterfaceById (int id) const override
 Returns an interface by its Id. More...
 
virtual NetworkInterfacegetInterfaceById (int id) const override
 Returns an interface by its Id. More...
 
virtual int getBiggestInterfaceId () const override
 Returns the biggest interface Id. More...
 
virtual NetworkInterfacefindInterfaceByNodeOutputGateId (int id) const override
 Returns an interface given by its getNodeOutputGateId(). More...
 
virtual NetworkInterfacefindInterfaceByNodeInputGateId (int id) const override
 Returns an interface given by its getNodeInputGateId(). More...
 
virtual NetworkInterfacefindInterfaceByInterfaceModule (cModule *ifmod) const override
 Returns an interface by one of its component module (e.g. More...
 
virtual NetworkInterfacefindInterfaceByName (const char *name) const override
 Returns an interface given by its name. More...
 
virtual NetworkInterfacefindFirstLoopbackInterface () const override
 Returns the first interface with the isLoopback flag set. More...
 
virtual NetworkInterfacefindFirstNonLoopbackInterface () const override
 Returns the first interface with the isLoopback flag unset. More...
 
virtual NetworkInterfacefindFirstMulticastInterface () const override
 Returns the first multicast capable interface. More...
 
virtual bool isInitializeStage (int stage) const override
 Lifecycle method. More...
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
virtual MulticastGroupList collectMulticastGroups () const override
 Returns all multicast group address, with it's interfaceId. More...
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::IInterfaceTable
virtual ~IInterfaceTable ()
 

Protected Types

typedef std::vector< NetworkInterface * > InterfaceVector
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Protected Member Functions

virtual void refreshDisplay () const override
 
virtual void updateLinkDisplayString (NetworkInterface *entry) const
 
virtual void discoverConnectingGates (NetworkInterface *entry)
 
virtual void interfaceChanged (simsignal_t signalID, const NetworkInterfaceChangeDetails *details) override
 
virtual void invalidateTmpInterfaceList ()
 
virtual void resetInterfaces ()
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessageWhenUp (cMessage *) override
 Raises an error. More...
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Protected Attributes

cModule * host
 
InterfaceVector idToInterface
 
int tmpNumInterfaces
 
NetworkInterface ** tmpInterfaceList
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Detailed Description

Represents the interface table.

This object has one instance per host or router. It has methods to manage the interface table, so one can access functionality similar to the "ifconfig" command.

See the NED documentation for general overview.

This is a simple module without gates, it requires function calls to it (message handling does nothing). Methods are provided for reading and updating the interface table.

Interfaces are dynamically registered: at the start of the simulation, every L2 module adds its own NetworkInterface to the table; after that, Ipv4's IIpv4RoutingTable and Ipv6's Ipv6RoutingTable (an possibly, further L3 protocols) add protocol-specific data on each NetworkInterface (see Ipv4InterfaceData, Ipv6InterfaceData, and NetworkInterface::setIPv4Data(), NetworkInterface::setIPv6Data())

Interfaces are represented by NetworkInterface objects.

When interfaces need to be reliably and efficiently identified from other modules, interfaceIds should be used. They are better suited than pointers because when an interface gets removed (see deleteInterface()), it is often impossible/impractical to invalidate all pointers to it, and also because pointers are not necessarily unique (a new NetworkInterface may get allocated exactly at the address of a previously deleted one). Interface Ids are unique (Ids of removed interfaces are not issued again), stale Ids can be detected, and they are also invariant to insertion/deletion.

Clients can get notified about interface changes by subscribing to the following signals on host module: interfaceCreatedSignal, interfaceDeletedSignal, interfaceStateChangedSignal, interfaceConfigChangedSignal. State change gets fired for up/down events; all other changes fire as config change.

See also
NetworkInterface

Member Typedef Documentation

◆ InterfaceVector

typedef std::vector<NetworkInterface *> inet::InterfaceTable::InterfaceVector
protected

Constructor & Destructor Documentation

◆ InterfaceTable()

inet::InterfaceTable::InterfaceTable ( )
47 {
48  host = nullptr;
49  tmpNumInterfaces = -1;
50  tmpInterfaceList = nullptr;
51 }

◆ ~InterfaceTable()

inet::InterfaceTable::~InterfaceTable ( )
virtual
54 {
55  delete[] tmpInterfaceList;
56 }

Member Function Documentation

◆ addInterface()

void inet::InterfaceTable::addInterface ( NetworkInterface entry)
overridevirtual

Adds an interface.

The entry->getInterfaceModule() will be used to discover and fill in getNetworkLayerGateIndex(), getNodeOutputGateId(), and getNodeInputGateId() in NetworkInterface. It should be nullptr if this is a virtual interface (e.g. loopback).

Implements inet::IInterfaceTable.

273 {
274  if (!host)
275  throw cRuntimeError("InterfaceTable must precede all network interface modules in the node's NED definition");
276  // check name is unique
277  if (findInterfaceByName(entry->getInterfaceName()) != nullptr)
278  throw cRuntimeError("addInterface(): interface '%s' already registered", entry->getInterfaceName());
279 
280  // insert
281  entry->setInterfaceId(INTERFACEIDS_START + idToInterface.size());
282  idToInterface.push_back(entry);
284 
285  // fill in networkLayerGateIndex, nodeOutputGateId, nodeInputGateId
287 
288  emit(interfaceCreatedSignal, entry);
289 }

◆ collectMulticastGroups()

MulticastGroupList inet::InterfaceTable::collectMulticastGroups ( ) const
overridevirtual

Returns all multicast group address, with it's interfaceId.

Implements inet::IInterfaceTable.

537 {
538  MulticastGroupList mglist;
539  for (int i = 0; i < getNumInterfaces(); ++i) {
540 #ifdef INET_WITH_IPv4
542  int interfaceId = ie->getInterfaceId();
543  auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
544  if (ipv4Data) {
545  int numOfMulticastGroups = ipv4Data->getNumOfJoinedMulticastGroups();
546  for (int j = 0; j < numOfMulticastGroups; ++j) {
547  mglist.push_back(MulticastGroup(ipv4Data->getJoinedMulticastGroup(j), interfaceId));
548  }
549  }
550 #endif // ifdef INET_WITH_IPv4
551 #ifdef INET_WITH_IPv6
552  // TODO
553 #endif // ifdef INET_WITH_IPv6
554  }
555  return mglist;
556 }

◆ deleteInterface()

void inet::InterfaceTable::deleteInterface ( NetworkInterface entry)
overridevirtual

Deletes the given interface from the table.

Indices of existing interfaces (see getInterface(int)) may change. It is an error if the given interface is not in the table.

Implements inet::IInterfaceTable.

353 {
354  int id = entry->getInterfaceId();
355  if (entry != getInterfaceById(id))
356  throw cRuntimeError("deleteInterface(): interface '%s' not found in interface table", entry->getInterfaceName());
357 
358  emit(interfaceDeletedSignal, entry); // actually, only going to be deleted
359 
360  idToInterface[id - INTERFACEIDS_START] = nullptr;
361  delete entry;
363 }

◆ discoverConnectingGates()

void inet::InterfaceTable::discoverConnectingGates ( NetworkInterface entry)
protectedvirtual
292 {
293  cModule *ifmod = entry;
294  if (!ifmod)
295  return; // virtual interface
296 
297  // ifmod is something like "host.eth[1].mac"; climb up to find "host.eth[1]" from it
298  ASSERT(host != nullptr);
299  while (ifmod && ifmod->getParentModule() != host)
300  ifmod = ifmod->getParentModule();
301  if (!ifmod)
302  throw cRuntimeError("addInterface(): specified module (%s) is not in this host/router '%s'", entry->getInterfaceFullPath().c_str(), this->getFullPath().c_str());
303 
304  // ASSUMPTIONS:
305  // 1. The NIC module (ifmod) may or may not be connected to a network layer module (e.g. Ipv4NetworkLayer or Mpls)
306  // 2. If it *is* connected to a network layer, the network layer module's gates must be called
307  // ifIn[] and ifOut[], and NIC must be connected to identical gate indices in both vectors.
308  // 3. If the NIC module is not connected to another modules ifIn[] and ifOut[] gates, we assume
309  // that it is NOT connected to a network layer, and leave networkLayerGateIndex
310  // in NetworkInterface unfilled.
311  // 4. The NIC may or may not connect to gates of the containing host compound module.
312  //
313 
314  // find gates connected to host / network layer
315  cGate *nwlayerInGate = nullptr, *nwlayerOutGate = nullptr; // ifIn[] and ifOut[] gates in the network layer
316  for (GateIterator i(ifmod); !i.end(); i++) {
317  cGate *g = *i;
318  if (!g)
319  continue;
320 
321  // find the host/router's gates that internally connect to this interface
322  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->getOwnerModule() == host)
323  entry->setNodeOutputGateId(g->getNextGate()->getId());
324  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->getOwnerModule() == host)
325  entry->setNodeInputGateId(g->getPreviousGate()->getId());
326 
327  // TODO revise next code:
328  // find the gate index of networkLayer/networkLayer6/mpls that connects to this interface
329  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->isName("ifIn")) // connected to ifIn in networkLayer?
330  nwlayerInGate = g->getNextGate();
331  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->isName("ifOut")) // connected to ifOut in networkLayer?
332  nwlayerOutGate = g->getPreviousGate();
333  }
334 
335  // consistency checks and setting networkLayerGateIndex:
336 
337  // note: we don't check nodeOutputGateId/nodeInputGateId, because wireless interfaces
338  // are not connected to the host
339 
340  // TODO revise next code:
341  if (nwlayerInGate || nwlayerOutGate) { // connected to a network layer (i.e. to another module's ifIn/ifOut gates)
342  if (!nwlayerInGate || !nwlayerOutGate)
343  throw cRuntimeError("addInterface(): interface module '%s' is connected only to an 'ifOut' or an 'ifIn' gate, must connect to either both or neither", ifmod->getFullPath().c_str());
344  if (nwlayerInGate->getOwnerModule() != nwlayerOutGate->getOwnerModule())
345  throw cRuntimeError("addInterface(): interface module '%s' is connected to 'ifOut' and 'ifIn' gates in different modules", ifmod->getFullPath().c_str());
346  if (nwlayerInGate->getIndex() != nwlayerOutGate->getIndex()) // if both are scalar, that's OK too (index==0)
347  throw cRuntimeError("addInterface(): gate index mismatch: interface module '%s' is connected to different indices in 'ifOut[']/'ifIn[]' gates of the network layer module", ifmod->getFullPath().c_str());
348 // entry->setNetworkLayerGateIndex(nwlayerInGate->getIndex());
349  }
350 }

Referenced by addInterface().

◆ findFirstLoopbackInterface()

NetworkInterface * inet::InterfaceTable::findFirstLoopbackInterface ( ) const
overridevirtual

Returns the first interface with the isLoopback flag set.

If there's no loopback, it returns nullptr.

Implements inet::IInterfaceTable.

482 {
483  Enter_Method("findFirstLoopbackInterface");
484  int n = idToInterface.size();
485  for (int i = 0; i < n; i++)
486  if (idToInterface[i] && idToInterface[i]->isLoopback())
487  return idToInterface[i];
488 
489  return nullptr;
490 }

◆ findFirstMulticastInterface()

NetworkInterface * inet::InterfaceTable::findFirstMulticastInterface ( ) const
overridevirtual

Returns the first multicast capable interface.

If there is no such interface, then returns nullptr.

Implements inet::IInterfaceTable.

504 {
505  Enter_Method("findFirstMulticastInterface");
506  int n = idToInterface.size();
507  for (int i = 0; i < n; i++)
508  if (idToInterface[i] && idToInterface[i]->isMulticast() && !idToInterface[i]->isLoopback())
509  return idToInterface[i];
510 
511  return nullptr;
512 }

◆ findFirstNonLoopbackInterface()

NetworkInterface * inet::InterfaceTable::findFirstNonLoopbackInterface ( ) const
overridevirtual

Returns the first interface with the isLoopback flag unset.

If there's no non-loopback, it returns nullptr.

Implements inet::IInterfaceTable.

493 {
494  Enter_Method("findFirstNonLoopbackInterface");
495  int n = idToInterface.size();
496  for (int i = 0; i < n; i++)
497  if (idToInterface[i] && !idToInterface[i]->isLoopback())
498  return idToInterface[i];
499 
500  return nullptr;
501 }

◆ findInterfaceByAddress()

NetworkInterface * inet::InterfaceTable::findInterfaceByAddress ( const L3Address address) const
overridevirtual

Returns an interface given by its address.

Returns nullptr if not found.

Implements inet::IInterfaceTable.

113 {
114  if (!address.isUnspecified()) {
115  L3Address::AddressType addrType = address.getType();
116  for (auto& elem : idToInterface) {
117  NetworkInterface *ie = elem;
118  if (ie) {
119 #ifdef INET_WITH_NEXTHOP
120  if (auto nextHopData = ie->findProtocolData<NextHopInterfaceData>())
121  if (nextHopData->getAddress() == address)
122  return ie;
123 #endif // ifdef INET_WITH_NEXTHOP
124  switch (addrType) {
125 #ifdef INET_WITH_IPv4
126  case L3Address::IPv4:
127  if (auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>())
128  if (ipv4Data->getIPAddress() == address.toIpv4())
129  return ie;
130  break;
131 #endif // ifdef INET_WITH_IPv4
132 
133 #ifdef INET_WITH_IPv6
134  case L3Address::IPv6:
135  if (auto ipv6Data = ie->findProtocolData<Ipv6InterfaceData>())
136  if (ipv6Data->hasAddress(address.toIpv6()))
137  return ie;
138  break;
139 #endif // ifdef INET_WITH_IPv6
140 
141  case L3Address::MAC:
142  if (ie->getMacAddress() == address.toMac())
143  return ie;
144  break;
145 
146  case L3Address::MODULEID:
147  if (ie->getModuleIdAddress() == address.toModuleId())
148  return ie;
149  break;
150 
152  if (ie->getModulePathAddress() == address.toModulePath())
153  return ie;
154  break;
155 
156  default:
157  throw cRuntimeError("Unknown address type");
158  break;
159  }
160  }
161  }
162  }
163  return nullptr;
164 }

Referenced by isLocalAddress().

◆ findInterfaceById()

NetworkInterface * inet::InterfaceTable::findInterfaceById ( int  id) const
overridevirtual

Returns an interface by its Id.

Ids are guaranteed to be invariant to interface deletions/additions. Returns nullptr if there is no such interface (This allows detecting stale IDs without raising an error.)

Implements inet::IInterfaceTable.

262 {
263  id -= INTERFACEIDS_START;
264  return (id < 0 || id >= (int)idToInterface.size()) ? nullptr : idToInterface[id];
265 }

Referenced by getInterfaceById().

◆ findInterfaceByInterfaceModule()

NetworkInterface * inet::InterfaceTable::findInterfaceByInterfaceModule ( cModule *  ifmod) const
overridevirtual

Returns an interface by one of its component module (e.g.

PPP). Returns nullptr if not found.

Implements inet::IInterfaceTable.

436 {
437  // ifmod is something like "host.eth[1].mac"; climb up to find "host.eth[1]" from it
438  ASSERT(host != nullptr);
439  cModule *_ifmod = ifmod;
440  while (ifmod && ifmod->getParentModule() != host)
441  ifmod = ifmod->getParentModule();
442  if (!ifmod)
443  throw cRuntimeError("Specified module (%s) is not in this host/router '%s'", _ifmod->getFullPath().c_str(), this->getFullPath().c_str());
444 
445  int nodeInputGateId = -1, nodeOutputGateId = -1;
446  for (GateIterator i(ifmod); !i.end(); i++) {
447  cGate *g = *i;
448  if (!g)
449  continue;
450 
451  // find the host/router's gates that internally connect to this interface
452  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->getOwnerModule() == host)
453  nodeOutputGateId = g->getNextGate()->getId();
454  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->getOwnerModule() == host)
455  nodeInputGateId = g->getPreviousGate()->getId();
456  }
457 
458  NetworkInterface *ie = nullptr;
459  if (nodeInputGateId >= 0)
460  ie = findInterfaceByNodeInputGateId(nodeInputGateId);
461  if (!ie && nodeOutputGateId >= 0)
462  ie = findInterfaceByNodeOutputGateId(nodeOutputGateId);
463 
464  ASSERT(!ie || (ie->getNodeInputGateId() == nodeInputGateId && ie->getNodeOutputGateId() == nodeOutputGateId));
465  return ie;
466 }

◆ findInterfaceByName()

NetworkInterface * inet::InterfaceTable::findInterfaceByName ( const char *  name) const
overridevirtual

Returns an interface given by its name.

Returns nullptr if not found.

Implements inet::IInterfaceTable.

469 {
470  Enter_Method("findInterfaceByName");
471  if (!name)
472  return nullptr;
473  int n = idToInterface.size();
474  for (int i = 0; i < n; i++)
475  if (idToInterface[i] && !strcmp(name, idToInterface[i]->getInterfaceName()))
476  return idToInterface[i];
477 
478  return nullptr;
479 }

Referenced by addInterface().

◆ findInterfaceByNodeInputGateId()

NetworkInterface * inet::InterfaceTable::findInterfaceByNodeInputGateId ( int  id) const
overridevirtual

Returns an interface given by its getNodeInputGateId().

Returns nullptr if not found.

Implements inet::IInterfaceTable.

424 {
425  // linear search is OK because normally we have don't have many interfaces and this func is rarely called
426  Enter_Method("findInterfaceByNodeInputGateId");
427  int n = idToInterface.size();
428  for (int i = 0; i < n; i++)
429  if (idToInterface[i] && idToInterface[i]->getNodeInputGateId() == id)
430  return idToInterface[i];
431 
432  return nullptr;
433 }

Referenced by findInterfaceByInterfaceModule().

◆ findInterfaceByNodeOutputGateId()

NetworkInterface * inet::InterfaceTable::findInterfaceByNodeOutputGateId ( int  id) const
overridevirtual

Returns an interface given by its getNodeOutputGateId().

Returns nullptr if not found.

Implements inet::IInterfaceTable.

412 {
413  // linear search is OK because normally we have don't have many interfaces and this func is rarely called
414  Enter_Method("findInterfaceByNodeOutputGateId");
415  int n = idToInterface.size();
416  for (int i = 0; i < n; i++)
417  if (idToInterface[i] && idToInterface[i]->getNodeOutputGateId() == id)
418  return idToInterface[i];
419 
420  return nullptr;
421 }

Referenced by findInterfaceByInterfaceModule().

◆ getBiggestInterfaceId()

int inet::InterfaceTable::getBiggestInterfaceId ( ) const
overridevirtual

Returns the biggest interface Id.

Implements inet::IInterfaceTable.

268 {
269  return INTERFACEIDS_START + idToInterface.size() - 1;
270 }

◆ getFullPath()

virtual std::string inet::InterfaceTable::getFullPath ( ) const
inlineoverridevirtual

Module path name.

Implements inet::IInterfaceTable.

93 { return cSimpleModule::getFullPath(); }

◆ getHostModule()

cModule * inet::InterfaceTable::getHostModule ( ) const
overridevirtual

Returns the host or router this interface table lives in.

Implements inet::IInterfaceTable.

102 {
103  ASSERT(host != nullptr);
104  return host;
105 }

◆ getInterface()

NetworkInterface * inet::InterfaceTable::getInterface ( int  pos) const
overridevirtual

Returns the NetworkInterface specified by an index 0..numInterfaces-1.

Throws an error if index is out of range.

Note that this index is NOT the same as interfaceId! Indices are not guaranteed to stay the same after interface addition/deletion, so cannot be used to reliably identify the interface. Use interfaceId to refer to interfaces from other modules or from messages/packets.

Implements inet::IInterfaceTable.

234 {
235  int n = getNumInterfaces(); // also fills tmpInterfaceList
236  if (pos < 0 || pos >= n)
237  throw cRuntimeError("getInterface(): interface index %d out of range 0..%d", pos, n - 1);
238 
239  if (!tmpInterfaceList) {
240  // collect non-nullptr elements into tmpInterfaceList[]
242  int k = 0;
243  int maxId = idToInterface.size();
244  for (int i = 0; i < maxId; i++)
245  if (idToInterface[i])
247 
248  }
249 
250  return tmpInterfaceList[pos];
251 }

Referenced by collectMulticastGroups().

◆ getInterfaceById()

NetworkInterface * inet::InterfaceTable::getInterfaceById ( int  id) const
overridevirtual

Returns an interface by its Id.

Ids are guaranteed to be invariant to interface deletions/additions. Throws an error if there is no such interface.

Implements inet::IInterfaceTable.

254 {
256  if (ie == nullptr)
257  throw cRuntimeError("getInterfaceById(): no interface with ID=%d", id);
258  return ie;
259 }

Referenced by deleteInterface().

◆ getNumInterfaces()

int inet::InterfaceTable::getNumInterfaces ( ) const
overridevirtual

Returns the number of interfaces.

Implements inet::IInterfaceTable.

218 {
219  if (tmpNumInterfaces == -1) {
220  // count non-nullptr elements
221  int n = 0;
222  int maxId = idToInterface.size();
223  for (int i = 0; i < maxId; i++)
224  if (idToInterface[i])
225  n++;
226 
227  tmpNumInterfaces = n;
228  }
229 
230  return tmpNumInterfaces;
231 }

Referenced by collectMulticastGroups(), getInterface(), and refreshDisplay().

◆ handleCrashOperation()

void inet::InterfaceTable::handleCrashOperation ( LifecycleOperation operation)
overridevirtual

Implements inet::OperationalMixin< cSimpleModule >.

524 {
525  resetInterfaces();
526 }

◆ handleMessageWhenUp()

void inet::InterfaceTable::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Raises an error.

Implements inet::OperationalMixin< cSimpleModule >.

87 {
88  throw cRuntimeError("This module doesn't process messages");
89 }

◆ handleStartOperation()

void inet::InterfaceTable::handleStartOperation ( LifecycleOperation operation)
overridevirtual

Implements inet::OperationalMixin< cSimpleModule >.

515 {
516 }

◆ handleStopOperation()

void inet::InterfaceTable::handleStopOperation ( LifecycleOperation operation)
overridevirtual

Implements inet::OperationalMixin< cSimpleModule >.

519 {
520  resetInterfaces();
521 }

◆ initialize()

void inet::InterfaceTable::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

59 {
61 
62  if (stage == INITSTAGE_LOCAL) {
63  // get a pointer to the host module
64  host = getContainingNode(this);
65  WATCH_PTRVECTOR(idToInterface);
66  }
67 }

◆ interfaceChanged()

void inet::InterfaceTable::interfaceChanged ( simsignal_t  signalID,
const NetworkInterfaceChangeDetails details 
)
overrideprotectedvirtual

Implements inet::IInterfaceTable.

373 {
374  Enter_Method("interfaceChanged");
375  emit(signalID, const_cast<NetworkInterfaceChangeDetails *>(details));
376 }

◆ invalidateTmpInterfaceList()

void inet::InterfaceTable::invalidateTmpInterfaceList ( )
protectedvirtual
366 {
367  tmpNumInterfaces = -1;
368  delete[] tmpInterfaceList;
369  tmpInterfaceList = nullptr;
370 }

Referenced by addInterface(), and deleteInterface().

◆ isInitializeStage()

virtual bool inet::InterfaceTable::isInitializeStage ( int  stage) const
inlineoverridevirtual

Lifecycle method.

Implements inet::OperationalMixin< cSimpleModule >.

226 { return stage == INITSTAGE_LINK_LAYER; }

◆ isLocalAddress()

bool inet::InterfaceTable::isLocalAddress ( const L3Address address) const
overridevirtual

Checks if the address is a local one, i.e.

one of the host's.

Implements inet::IInterfaceTable.

108 {
109  return findInterfaceByAddress(address) != nullptr;
110 }

◆ isModuleStartStage()

virtual bool inet::InterfaceTable::isModuleStartStage ( int  stage) const
inlineoverridevirtual

◆ isModuleStopStage()

virtual bool inet::InterfaceTable::isModuleStopStage ( int  stage) const
inlineoverridevirtual

◆ isNeighborAddress()

bool inet::InterfaceTable::isNeighborAddress ( const L3Address address) const
overridevirtual

Checks if the address is on the network of one of the interfaces, but not local.

Implements inet::IInterfaceTable.

167 {
168  if (address.isUnspecified())
169  return false;
170 
171  switch (address.getType()) {
172 #ifdef INET_WITH_IPv4
173  case L3Address::IPv4:
174  for (auto& elem : idToInterface) {
175  NetworkInterface *ie = elem;
176  if (ie) {
177  if (auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>()) {
178  Ipv4Address ipv4Addr = ipv4Data->getIPAddress();
179  Ipv4Address netmask = ipv4Data->getNetmask();
180  if (Ipv4Address::maskedAddrAreEqual(address.toIpv4(), ipv4Addr, netmask))
181  return address != ipv4Addr;
182  }
183  }
184  }
185  break;
186 
187 #endif // ifdef INET_WITH_IPv4
188 #ifdef INET_WITH_IPv6
189  case L3Address::IPv6:
190  for (auto& elem : idToInterface) {
191  NetworkInterface *ie = elem;
192  if (ie) {
193  if (auto ipv6Data = ie->findProtocolData<Ipv6InterfaceData>()) {
194  for (int j = 0; j < ipv6Data->getNumAdvPrefixes(); j++) {
195  const Ipv6InterfaceData::AdvPrefix& advPrefix = ipv6Data->getAdvPrefix(j);
196  if (address.toIpv6().matches(advPrefix.prefix, advPrefix.prefixLength))
197  return address != advPrefix.prefix;
198  }
199  }
200  }
201  }
202  break;
203 
204 #endif // ifdef INET_WITH_IPv6
205  case L3Address::MAC:
207  case L3Address::MODULEID:
208  // TODO
209  break;
210 
211  default:
212  throw cRuntimeError("Unknown address type");
213  }
214  return false;
215 }

◆ numInitStages()

virtual int inet::InterfaceTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
96 { return NUM_INIT_STAGES; }

◆ receiveSignal()

void inet::InterfaceTable::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overridevirtual

Called by the signal handler whenever a change of a category occurs to which this client has subscribed.

92 {
93  Enter_Method("%s", cComponent::getSignalName(signalID));
94 
95  // nothing needed here at the moment
96  printSignalBanner(signalID, obj, details);
97 }

◆ refreshDisplay()

void inet::InterfaceTable::refreshDisplay ( ) const
overrideprotectedvirtual
70 {
72 
73  char buf[80];
74  sprintf(buf, "%d interfaces", getNumInterfaces());
75  getDisplayString().setTagArg("t", 0, buf);
76 
77  if (par("displayAddresses")) {
78  for (auto& elem : idToInterface) {
79  NetworkInterface *ie = elem;
80  if (ie)
82  }
83  }
84 }

◆ resetInterfaces()

void inet::InterfaceTable::resetInterfaces ( )
protectedvirtual
529 {
530  int n = idToInterface.size();
531  for (int i = 0; i < n; i++)
532  if (idToInterface[i])
533  idToInterface[i]->resetInterface();
534 }

Referenced by handleCrashOperation(), and handleStopOperation().

◆ updateLinkDisplayString()

void inet::InterfaceTable::updateLinkDisplayString ( NetworkInterface entry) const
protectedvirtual
379 {
380  int outputGateId = entry->getNodeOutputGateId();
381  if (outputGateId != -1) {
382  ASSERT(host != nullptr);
383  cGate *outputGate = host->gate(outputGateId);
384  if (!outputGate->getChannel())
385  return;
386  cDisplayString& displayString = outputGate->getDisplayString();
387  std::stringstream buf;
388  buf << entry->getFullName() << "\n";
389 #ifdef INET_WITH_IPv4
390  auto ipv4Data = entry->findProtocolData<Ipv4InterfaceData>();
391  if (ipv4Data && !(ipv4Data->getIPAddress().isUnspecified())) {
392  buf << ipv4Data->getIPAddress().str() << "/" << ipv4Data->getNetmask().getNetmaskLength() << "\n";
393  }
394 #endif // ifdef INET_WITH_IPv4
395 #ifdef INET_WITH_IPv6
396  auto ipv6Data = entry->findProtocolData<Ipv6InterfaceData>();
397  if (ipv6Data && ipv6Data->getNumAddresses() > 0) {
398  for (int i = 0; i < ipv6Data->getNumAddresses(); i++) {
399  if (ipv6Data->getAddress(i).isSolicitedNodeMulticastAddress()
400  //|| (ipv6Data->getAddress(i).isLinkLocal() && ipv6Data->getAddress(i).)
401  || ipv6Data->getAddress(i).isMulticast()) continue;
402  buf << ipv6Data->getAddress(i).str() << "/64" << "\n";
403  }
404  }
405 #endif // ifdef INET_WITH_IPv6
406  displayString.setTagArg("t", 0, buf.str().c_str());
407  displayString.setTagArg("t", 1, "l");
408  }
409 }

Referenced by refreshDisplay().

Member Data Documentation

◆ host

◆ idToInterface

◆ tmpInterfaceList

NetworkInterface** inet::InterfaceTable::tmpInterfaceList
mutableprotected

◆ tmpNumInterfaces

int inet::InterfaceTable::tmpNumInterfaces
mutableprotected

The documentation for this class was generated from the following files:
inet::L3Address::AddressType
AddressType
Definition: L3Address.h:33
inet::InterfaceTable::findInterfaceByNodeOutputGateId
virtual NetworkInterface * findInterfaceByNodeOutputGateId(int id) const override
Returns an interface given by its getNodeOutputGateId().
Definition: InterfaceTable.cc:411
inet::InterfaceTable::getNumInterfaces
virtual int getNumInterfaces() const override
Returns the number of interfaces.
Definition: InterfaceTable.cc:217
inet::InterfaceTable::findInterfaceById
virtual NetworkInterface * findInterfaceById(int id) const override
Returns an interface by its Id.
Definition: InterfaceTable.cc:261
inet::L3Address::MODULEID
@ MODULEID
Definition: L3Address.h:40
inet::InterfaceTable::findInterfaceByNodeInputGateId
virtual NetworkInterface * findInterfaceByNodeInputGateId(int id) const override
Returns an interface given by its getNodeInputGateId().
Definition: InterfaceTable.cc:423
INTERFACEIDS_START
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:38
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::InterfaceTable::invalidateTmpInterfaceList
virtual void invalidateTmpInterfaceList()
Definition: InterfaceTable.cc:365
inet::printSignalBanner
void printSignalBanner(simsignal_t signalID, const cObject *obj, const cObject *details)
Utility function.
Definition: Simsignals.cc:126
inet::L3Address::IPv4
@ IPv4
Definition: L3Address.h:35
inet::L3Address::MODULEPATH
@ MODULEPATH
Definition: L3Address.h:39
inet::InterfaceTable::tmpNumInterfaces
int tmpNumInterfaces
Definition: InterfaceTable.h:69
inet::InterfaceTable::updateLinkDisplayString
virtual void updateLinkDisplayString(NetworkInterface *entry) const
Definition: InterfaceTable.cc:378
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::IInterfaceTable::NetworkInterface
friend class NetworkInterface
Definition: IInterfaceTable.h:38
inet::interfaceDeletedSignal
simsignal_t interfaceDeletedSignal
Definition: Simsignals.cc:31
inet::InterfaceTable::tmpInterfaceList
NetworkInterface ** tmpInterfaceList
Definition: InterfaceTable.h:70
inet::InterfaceTable::host
cModule * host
Definition: InterfaceTable.h:61
inet::Ipv4Address::maskedAddrAreEqual
static bool maskedAddrAreEqual(const Ipv4Address &addr1, const Ipv4Address &addr2, const Ipv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: Ipv4Address.cc:249
inet::ModuleStopOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
inet::MulticastGroupList
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:26
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::InterfaceTable::idToInterface
InterfaceVector idToInterface
Definition: InterfaceTable.h:66
inet::InterfaceTable::getInterfaceById
virtual NetworkInterface * getInterfaceById(int id) const override
Returns an interface by its Id.
Definition: InterfaceTable.cc:253
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::InterfaceTable::getInterface
virtual NetworkInterface * getInterface(int pos) const override
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
Definition: InterfaceTable.cc:233
inet::L3Address::IPv6
@ IPv6
Definition: L3Address.h:36
inet::InterfaceTable::findInterfaceByAddress
virtual NetworkInterface * findInterfaceByAddress(const L3Address &address) const override
Returns an interface given by its address.
Definition: InterfaceTable.cc:112
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::L3Address::MAC
@ MAC
Definition: L3Address.h:38
inet::InterfaceTable::findInterfaceByName
virtual NetworkInterface * findInterfaceByName(const char *name) const override
Returns an interface given by its name.
Definition: InterfaceTable.cc:468
inet::InterfaceTable::discoverConnectingGates
virtual void discoverConnectingGates(NetworkInterface *entry)
Definition: InterfaceTable.cc:291
inet::ModuleStartOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
inet::interfaceCreatedSignal
simsignal_t interfaceCreatedSignal
Definition: Simsignals.cc:30
inet::OperationalMixin< cSimpleModule >::refreshDisplay
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
inet::InterfaceTable::resetInterfaces
virtual void resetInterfaces()
Definition: InterfaceTable.cc:528
inet::INITSTAGE_LINK_LAYER
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.