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

Represents the interface table. More...

#include <InterfaceTable.h>

Inheritance diagram for inet::InterfaceTable:
inet::IInterfaceTable 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 InterfaceEntryfindInterfaceByAddress (const L3Address &address) const override
 Returns an interface given by its address. More...
 
virtual void addInterface (InterfaceEntry *entry) override
 Adds an interface. More...
 
virtual void deleteInterface (InterfaceEntry *entry) override
 Deletes the given interface from the table. More...
 
virtual int getNumInterfaces () const override
 Returns the number of interfaces. More...
 
virtual InterfaceEntrygetInterface (int pos) const override
 Returns the InterfaceEntry specified by an index 0..numInterfaces-1. More...
 
virtual InterfaceEntrygetInterfaceById (int id) const override
 Returns an interface by its Id. More...
 
virtual int getBiggestInterfaceId () const override
 Returns the biggest interface Id. More...
 
virtual InterfaceEntrygetInterfaceByNodeOutputGateId (int id) const override
 Returns an interface given by its getNodeOutputGateId(). More...
 
virtual InterfaceEntrygetInterfaceByNodeInputGateId (int id) const override
 Returns an interface given by its getNodeInputGateId(). More...
 
virtual InterfaceEntrygetInterfaceByNetworkLayerGateIndex (int index) override
 Returns an interface given by its getNetworkLayerGateIndex(). More...
 
virtual InterfaceEntrygetInterfaceByInterfaceModule (cModule *ifmod) const override
 Returns an interface by one of its component module (e.g. More...
 
virtual InterfaceEntrygetInterfaceByName (const char *name) const override
 Returns an interface given by its name. More...
 
virtual InterfaceEntrygetFirstLoopbackInterface () const override
 Returns the first interface with the isLoopback flag set. More...
 
virtual InterfaceEntrygetFirstMulticastInterface () const override
 Returns the first multicast capable interface. More...
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 ILifecycle method. More...
 
virtual MulticastGroupList collectMulticastGroups () const override
 Returns all multicast group address, with it's interfaceId. More...
 
- Public Member Functions inherited from inet::IInterfaceTable
virtual ~IInterfaceTable ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

typedef std::vector< InterfaceEntry * > InterfaceVector
 

Protected Member Functions

virtual void refreshDisplay () const override
 
virtual void updateLinkDisplayString (InterfaceEntry *entry) const
 
virtual void discoverConnectingGates (InterfaceEntry *entry)
 
virtual void interfaceChanged (simsignal_t signalID, const InterfaceEntryChangeDetails *details) override
 
virtual void invalidateTmpInterfaceList ()
 
virtual void resetInterfaces ()
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *) override
 Raises an error. More...
 

Protected Attributes

cModule * host
 
InterfaceVector idToInterface
 
int tmpNumInterfaces
 
InterfaceEntry ** tmpInterfaceList
 

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 InterfaceEntry to the table; after that, IPv4's IIPv4RoutingTable and IPv6's IPv6RoutingTable (an possibly, further L3 protocols) add protocol-specific data on each InterfaceEntry (see IPv4InterfaceData, IPv6InterfaceData, and InterfaceEntry::setIPv4Data(), InterfaceEntry::setIPv6Data())

Interfaces are represented by InterfaceEntry 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 InterfaceEntry 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: NF_INTERFACE_CREATED, NF_INTERFACE_DELETED, NF_INTERFACE_STATE_CHANGED, NF_INTERFACE_CONFIG_CHANGED. State change gets fired for up/down events; all other changes fire as config change.

See also
InterfaceEntry

Member Typedef Documentation

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

Constructor & Destructor Documentation

inet::InterfaceTable::InterfaceTable ( )
56 {
57  host = nullptr;
58  tmpNumInterfaces = -1;
59  tmpInterfaceList = nullptr;
60 }
int tmpNumInterfaces
Definition: InterfaceTable.h:80
cModule * host
Definition: InterfaceTable.h:72
InterfaceEntry ** tmpInterfaceList
Definition: InterfaceTable.h:81
inet::InterfaceTable::~InterfaceTable ( )
virtual
63 {
64  for (auto & elem : idToInterface)
65  delete elem;
66  delete[] tmpInterfaceList;
67 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry ** tmpInterfaceList
Definition: InterfaceTable.h:81

Member Function Documentation

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

Adds an interface.

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

Implements inet::IInterfaceTable.

268 {
269  if (!host)
270  throw cRuntimeError("InterfaceTable must precede all network interface modules in the node's NED definition");
271  // check name is unique
272  if (getInterfaceByName(entry->getName()) != nullptr)
273  throw cRuntimeError("addInterface(): interface '%s' already registered", entry->getName());
274 
275  // insert
276  entry->setInterfaceId(INTERFACEIDS_START + idToInterface.size());
277  entry->setInterfaceTable(this);
278  idToInterface.push_back(entry);
280 
281  // fill in networkLayerGateIndex, nodeOutputGateId, nodeInputGateId
283 
284  emit(NF_INTERFACE_CREATED, entry);
285 }
virtual void discoverConnectingGates(InterfaceEntry *entry)
Definition: InterfaceTable.cc:287
virtual void invalidateTmpInterfaceList()
Definition: InterfaceTable.cc:359
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:47
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
virtual InterfaceEntry * getInterfaceByName(const char *name) const override
Returns an interface given by its name.
Definition: InterfaceTable.cc:467
cModule * host
Definition: InterfaceTable.h:72
simsignal_t NF_INTERFACE_CREATED
Definition: NotifierConsts.cc:48
MulticastGroupList inet::InterfaceTable::collectMulticastGroups ( ) const
overridevirtual

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

Implements inet::IInterfaceTable.

528 {
529  MulticastGroupList mglist;
530  for (int i = 0; i < getNumInterfaces(); ++i) {
531 #ifdef WITH_IPv4
532  InterfaceEntry *ie = getInterface(i);
533  int interfaceId = ie->getInterfaceId();
534  if (ie->ipv4Data()) {
535  int numOfMulticastGroups = ie->ipv4Data()->getNumOfJoinedMulticastGroups();
536  for (int j = 0; j < numOfMulticastGroups; ++j) {
537  mglist.push_back(MulticastGroup(ie->ipv4Data()->getJoinedMulticastGroup(j), interfaceId));
538  }
539  }
540 #endif // ifdef WITH_IPv4
541 #ifdef WITH_IPv6
542  // TODO
543 #endif // ifdef WITH_IPv6
544  }
545  return mglist;
546 }
virtual InterfaceEntry * getInterface(int pos) const override
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
Definition: InterfaceTable.cc:236
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
virtual int getNumInterfaces() const override
Returns the number of interfaces.
Definition: InterfaceTable.cc:220
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:36
void inet::InterfaceTable::deleteInterface ( InterfaceEntry 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.

347 {
348  int id = entry->getInterfaceId();
349  if (entry != getInterfaceById(id))
350  throw cRuntimeError("deleteInterface(): interface '%s' not found in interface table", entry->getName());
351 
352  emit(NF_INTERFACE_DELETED, entry); // actually, only going to be deleted
353 
354  idToInterface[id - INTERFACEIDS_START] = nullptr;
355  delete entry;
357 }
virtual void invalidateTmpInterfaceList()
Definition: InterfaceTable.cc:359
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:47
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
virtual InterfaceEntry * getInterfaceById(int id) const override
Returns an interface by its Id.
Definition: InterfaceTable.cc:256
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
void inet::InterfaceTable::discoverConnectingGates ( InterfaceEntry entry)
protectedvirtual

Referenced by addInterface().

288 {
289  cModule *ifmod = entry->getInterfaceModule();
290  if (!ifmod)
291  return; // virtual interface
292 
293  // ifmod is something like "host.eth[1].mac"; climb up to find "host.eth[1]" from it
294  ASSERT(host != nullptr);
295  while (ifmod && ifmod->getParentModule() != host)
296  ifmod = ifmod->getParentModule();
297  if (!ifmod)
298  throw cRuntimeError("addInterface(): specified module (%s) is not in this host/router '%s'", entry->getInterfaceModule()->getFullPath().c_str(), this->getFullPath().c_str());
299 
300  // ASSUMPTIONS:
301  // 1. The NIC module (ifmod) may or may not be connected to a network layer module (e.g. IPv4NetworkLayer or MPLS)
302  // 2. If it *is* connected to a network layer, the network layer module's gates must be called
303  // ifIn[] and ifOut[], and NIC must be connected to identical gate indices in both vectors.
304  // 3. If the NIC module is not connected to another modules ifIn[] and ifOut[] gates, we assume
305  // that it is NOT connected to a network layer, and leave networkLayerGateIndex
306  // in InterfaceEntry unfilled.
307  // 4. The NIC may or may not connect to gates of the containing host compound module.
308  //
309 
310  // find gates connected to host / network layer
311  cGate *nwlayerInGate = nullptr, *nwlayerOutGate = nullptr; // ifIn[] and ifOut[] gates in the network layer
312  for (GateIterator i(ifmod); !i.end(); i++) {
313  cGate *g = *i;
314  if (!g)
315  continue;
316 
317  // find the host/router's gates that internally connect to this interface
318  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->getOwnerModule() == host)
319  entry->setNodeOutputGateId(g->getNextGate()->getId());
320  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->getOwnerModule() == host)
321  entry->setNodeInputGateId(g->getPreviousGate()->getId());
322 
323  // find the gate index of networkLayer/networkLayer6/mpls that connects to this interface
324  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->isName("ifIn")) // connected to ifIn in networkLayer?
325  nwlayerInGate = g->getNextGate();
326  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->isName("ifOut")) // connected to ifOut in networkLayer?
327  nwlayerOutGate = g->getPreviousGate();
328  }
329 
330  // consistency checks and setting networkLayerGateIndex:
331 
332  // note: we don't check nodeOutputGateId/nodeInputGateId, because wireless interfaces
333  // are not connected to the host
334 
335  if (nwlayerInGate || nwlayerOutGate) { // connected to a network layer (i.e. to another module's ifIn/ifOut gates)
336  if (!nwlayerInGate || !nwlayerOutGate)
337  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());
338  if (nwlayerInGate->getOwnerModule() != nwlayerOutGate->getOwnerModule())
339  throw cRuntimeError("addInterface(): interface module '%s' is connected to 'ifOut' and 'ifIn' gates in different modules", ifmod->getFullPath().c_str());
340  if (nwlayerInGate->getIndex() != nwlayerOutGate->getIndex()) // if both are scalar, that's OK too (index==0)
341  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());
342  entry->setNetworkLayerGateIndex(nwlayerInGate->getIndex());
343  }
344 }
cModule * host
Definition: InterfaceTable.h:72
virtual std::string getFullPath() const override
Module path name.
Definition: InterfaceTable.h:104
milli< kg >::type g
Definition: Units.h:900
InterfaceEntry * inet::InterfaceTable::findInterfaceByAddress ( const L3Address address) const
overridevirtual

Returns an interface given by its address.

Returns nullptr if not found.

Implements inet::IInterfaceTable.

Referenced by isLocalAddress().

122 {
123  if (!address.isUnspecified()) {
124  L3Address::AddressType addrType = address.getType();
125  for (auto & elem : idToInterface) {
126  InterfaceEntry *ie = elem;
127  if (ie) {
128 #ifdef WITH_GENERIC
129  if (ie->getGenericNetworkProtocolData() && ie->getGenericNetworkProtocolData()->getAddress() == address)
130  return ie;
131 #endif // ifdef WITH_GENERIC
132  switch (addrType) {
133 #ifdef WITH_IPv4
134  case L3Address::IPv4:
135  if (ie->ipv4Data() && ie->ipv4Data()->getIPAddress() == address.toIPv4())
136  return ie;
137  break;
138 #endif // ifdef WITH_IPv4
139 
140 #ifdef WITH_IPv6
141  case L3Address::IPv6:
142  if (ie->ipv6Data() && ie->ipv6Data()->hasAddress(address.toIPv6()))
143  return ie;
144  break;
145 #endif // ifdef WITH_IPv6
146 
147  case L3Address::MAC:
148  if (ie->getMacAddress() == address.toMAC())
149  return ie;
150  break;
151 
152  case L3Address::MODULEID:
153  if (ie->getModuleIdAddress() == address.toModuleId())
154  return ie;
155  break;
156 
158  if (ie->getModulePathAddress() == address.toModulePath())
159  return ie;
160  break;
161 
162  default:
163  throw cRuntimeError("Unknown address type");
164  break;
165  }
166  }
167  }
168  }
169  return nullptr;
170 }
Definition: L3Address.h:47
Definition: L3Address.h:49
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
Definition: L3Address.h:50
AddressType
Definition: L3Address.h:44
Definition: L3Address.h:48
Definition: L3Address.h:46
int inet::InterfaceTable::getBiggestInterfaceId ( ) const
overridevirtual

Returns the biggest interface Id.

Implements inet::IInterfaceTable.

263 {
264  return INTERFACEIDS_START + idToInterface.size() - 1;
265 }
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:47
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getFirstLoopbackInterface ( ) const
overridevirtual

Returns the first interface with the isLoopback flag set.

(If there's no loopback, it returns nullptr – but this should never happen because InterfaceTable itself registers a loopback interface on startup.)

Implements inet::IInterfaceTable.

481 {
482  Enter_Method_Silent();
483  int n = idToInterface.size();
484  for (int i = 0; i < n; i++)
485  if (idToInterface[i] && idToInterface[i]->isLoopback())
486  return idToInterface[i];
487 
488  return nullptr;
489 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getFirstMulticastInterface ( ) const
overridevirtual

Returns the first multicast capable interface.

If there is no such interface, then returns nullptr.

Implements inet::IInterfaceTable.

492 {
493  Enter_Method_Silent();
494  int n = idToInterface.size();
495  for (int i = 0; i < n; i++)
496  if (idToInterface[i] && idToInterface[i]->isMulticast() && !idToInterface[i]->isLoopback())
497  return idToInterface[i];
498 
499  return nullptr;
500 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
virtual std::string inet::InterfaceTable::getFullPath ( ) const
inlineoverridevirtual

Module path name.

Implements inet::IInterfaceTable.

Referenced by discoverConnectingGates(), and getInterfaceByInterfaceModule().

104 { return cSimpleModule::getFullPath(); }
cModule * inet::InterfaceTable::getHostModule ( ) const
overridevirtual

Returns the host or router this interface table lives in.

Implements inet::IInterfaceTable.

111 {
112  ASSERT(host != nullptr);
113  return host;
114 }
cModule * host
Definition: InterfaceTable.h:72
InterfaceEntry * inet::InterfaceTable::getInterface ( int  pos) const
overridevirtual

Returns the InterfaceEntry 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.

Referenced by collectMulticastGroups().

237 {
238  int n = getNumInterfaces(); // also fills tmpInterfaceList
239  if (pos < 0 || pos >= n)
240  throw cRuntimeError("getInterface(): interface index %d out of range 0..%d", pos, n - 1);
241 
242  if (!tmpInterfaceList) {
243  // collect non-nullptr elements into tmpInterfaceList[]
244  tmpInterfaceList = new InterfaceEntry *[n];
245  int k = 0;
246  int maxId = idToInterface.size();
247  for (int i = 0; i < maxId; i++)
248  if (idToInterface[i])
250 
251  }
252 
253  return tmpInterfaceList[pos];
254 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
InterfaceEntry ** tmpInterfaceList
Definition: InterfaceTable.h:81
const double k
Definition: QAM16Modulation.cc:24
virtual int getNumInterfaces() const override
Returns the number of interfaces.
Definition: InterfaceTable.cc:220
InterfaceEntry * inet::InterfaceTable::getInterfaceById ( 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.

Referenced by deleteInterface().

257 {
258  id -= INTERFACEIDS_START;
259  return (id < 0 || id >= (int)idToInterface.size()) ? nullptr : idToInterface[id];
260 }
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:47
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getInterfaceByInterfaceModule ( cModule *  ifmod) const
overridevirtual

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

PPP). Returns nullptr if not found.

Implements inet::IInterfaceTable.

435 {
436  // ifmod is something like "host.eth[1].mac"; climb up to find "host.eth[1]" from it
437  ASSERT(host != nullptr);
438  cModule *_ifmod = ifmod;
439  while (ifmod && ifmod->getParentModule() != host)
440  ifmod = ifmod->getParentModule();
441  if (!ifmod)
442  throw cRuntimeError("addInterface(): specified module (%s) is not in this host/router '%s'", _ifmod->getFullPath().c_str(), this->getFullPath().c_str());
443 
444  int nodeInputGateId = -1, nodeOutputGateId = -1;
445  for (GateIterator i(ifmod); !i.end(); i++) {
446  cGate *g = *i;
447  if (!g)
448  continue;
449 
450  // find the host/router's gates that internally connect to this interface
451  if (g->getType() == cGate::OUTPUT && g->getNextGate() && g->getNextGate()->getOwnerModule() == host)
452  nodeOutputGateId = g->getNextGate()->getId();
453  if (g->getType() == cGate::INPUT && g->getPreviousGate() && g->getPreviousGate()->getOwnerModule() == host)
454  nodeInputGateId = g->getPreviousGate()->getId();
455  }
456 
457  InterfaceEntry *ie = nullptr;
458  if (nodeInputGateId >= 0)
459  ie = getInterfaceByNodeInputGateId(nodeInputGateId);
460  if (!ie && nodeOutputGateId >= 0)
461  ie = getInterfaceByNodeOutputGateId(nodeOutputGateId);
462 
463  ASSERT(!ie || (ie->getNodeInputGateId() == nodeInputGateId && ie->getNodeOutputGateId() == nodeOutputGateId));
464  return ie;
465 }
cModule * host
Definition: InterfaceTable.h:72
virtual std::string getFullPath() const override
Module path name.
Definition: InterfaceTable.h:104
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
virtual InterfaceEntry * getInterfaceByNodeInputGateId(int id) const override
Returns an interface given by its getNodeInputGateId().
Definition: InterfaceTable.cc:410
milli< kg >::type g
Definition: Units.h:900
virtual InterfaceEntry * getInterfaceByNodeOutputGateId(int id) const override
Returns an interface given by its getNodeOutputGateId().
Definition: InterfaceTable.cc:398
InterfaceEntry * inet::InterfaceTable::getInterfaceByName ( const char *  name) const
overridevirtual

Returns an interface given by its name.

Returns nullptr if not found.

Implements inet::IInterfaceTable.

Referenced by addInterface().

468 {
469  Enter_Method_Silent();
470  if (!name)
471  return nullptr;
472  int n = idToInterface.size();
473  for (int i = 0; i < n; i++)
474  if (idToInterface[i] && !strcmp(name, idToInterface[i]->getName()))
475  return idToInterface[i];
476 
477  return nullptr;
478 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getInterfaceByNetworkLayerGateIndex ( int  index)
overridevirtual

Returns an interface given by its getNetworkLayerGateIndex().

Returns nullptr if not found.

Implements inet::IInterfaceTable.

423 {
424  // linear search is OK because normally we have don't have many interfaces and this func is rarely called
425  Enter_Method_Silent();
426  int n = idToInterface.size();
427  for (int i = 0; i < n; i++)
428  if (idToInterface[i] && idToInterface[i]->getNetworkLayerGateIndex() == index)
429  return idToInterface[i];
430 
431  return nullptr;
432 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getInterfaceByNodeInputGateId ( int  id) const
overridevirtual

Returns an interface given by its getNodeInputGateId().

Returns nullptr if not found.

Implements inet::IInterfaceTable.

Referenced by getInterfaceByInterfaceModule().

411 {
412  // linear search is OK because normally we have don't have many interfaces and this func is rarely called
413  Enter_Method_Silent();
414  int n = idToInterface.size();
415  for (int i = 0; i < n; i++)
416  if (idToInterface[i] && idToInterface[i]->getNodeInputGateId() == id)
417  return idToInterface[i];
418 
419  return nullptr;
420 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
InterfaceEntry * inet::InterfaceTable::getInterfaceByNodeOutputGateId ( int  id) const
overridevirtual

Returns an interface given by its getNodeOutputGateId().

Returns nullptr if not found.

Implements inet::IInterfaceTable.

Referenced by getInterfaceByInterfaceModule().

399 {
400  // linear search is OK because normally we have don't have many interfaces and this func is rarely called
401  Enter_Method_Silent();
402  int n = idToInterface.size();
403  for (int i = 0; i < n; i++)
404  if (idToInterface[i] && idToInterface[i]->getNodeOutputGateId() == id)
405  return idToInterface[i];
406 
407  return nullptr;
408 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
int inet::InterfaceTable::getNumInterfaces ( ) const
overridevirtual

Returns the number of interfaces.

Implements inet::IInterfaceTable.

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

221 {
222  if (tmpNumInterfaces == -1) {
223  // count non-nullptr elements
224  int n = 0;
225  int maxId = idToInterface.size();
226  for (int i = 0; i < maxId; i++)
227  if (idToInterface[i])
228  n++;
229 
230  tmpNumInterfaces = n;
231  }
232 
233  return tmpNumInterfaces;
234 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
int tmpNumInterfaces
Definition: InterfaceTable.h:80
void inet::InterfaceTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Raises an error.

97 {
98  throw cRuntimeError("This module doesn't process messages");
99 }
bool inet::InterfaceTable::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overridevirtual

ILifecycle method.

Implements inet::ILifecycle.

503 {
504  Enter_Method_Silent();
505  if (dynamic_cast<NodeStartOperation *>(operation)) {
506  }
507  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
509  resetInterfaces();
510  }
511  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
513  resetInterfaces();
514  }
515  return true;
516 }
virtual void resetInterfaces()
Definition: InterfaceTable.cc:518
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
Definition: NodeOperations.h:127
Definition: NodeOperations.h:77
void inet::InterfaceTable::initialize ( int  stage)
overrideprotectedvirtual
70 {
71  cSimpleModule::initialize(stage);
72 
73  if (stage == INITSTAGE_LOCAL) {
74  // get a pointer to the host module
75  host = getContainingNode(this);
76  WATCH_PTRVECTOR(idToInterface);
77  }
78 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
cModule * host
Definition: InterfaceTable.h:72
Local initializations.
Definition: InitStages.h:35
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
void inet::InterfaceTable::interfaceChanged ( simsignal_t  signalID,
const InterfaceEntryChangeDetails details 
)
overrideprotectedvirtual

Implements inet::IInterfaceTable.

367 {
368  Enter_Method_Silent();
369  emit(signalID, const_cast<InterfaceEntryChangeDetails *>(details));
370 }
void inet::InterfaceTable::invalidateTmpInterfaceList ( )
protectedvirtual

Referenced by addInterface(), and deleteInterface().

360 {
361  tmpNumInterfaces = -1;
362  delete[] tmpInterfaceList;
363  tmpInterfaceList = nullptr;
364 }
int tmpNumInterfaces
Definition: InterfaceTable.h:80
InterfaceEntry ** tmpInterfaceList
Definition: InterfaceTable.h:81
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.

117 {
118  return findInterfaceByAddress(address) != nullptr;
119 }
virtual InterfaceEntry * findInterfaceByAddress(const L3Address &address) const override
Returns an interface given by its address.
Definition: InterfaceTable.cc:121
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.

173 {
174  if (address.isUnspecified())
175  return false;
176 
177  switch (address.getType()) {
178 #ifdef WITH_IPv4
179  case L3Address::IPv4:
180  for (auto & elem : idToInterface) {
181  InterfaceEntry *ie = elem;
182  if (ie && ie->ipv4Data()) {
183  IPv4Address ipv4Addr = ie->ipv4Data()->getIPAddress();
184  IPv4Address netmask = ie->ipv4Data()->getNetmask();
185  if (IPv4Address::maskedAddrAreEqual(address.toIPv4(), ipv4Addr, netmask))
186  return address != ipv4Addr;
187  }
188  }
189  break;
190 
191 #endif // ifdef WITH_IPv4
192 #ifdef WITH_IPv6
193  case L3Address::IPv6:
194  for (auto & elem : idToInterface) {
195  InterfaceEntry *ie = elem;
196  if (ie && ie->ipv6Data()) {
197  IPv6InterfaceData *ipv6Data = ie->ipv6Data();
198  for (int j = 0; j < ipv6Data->getNumAdvPrefixes(); j++) {
199  const IPv6InterfaceData::AdvPrefix& advPrefix = ipv6Data->getAdvPrefix(j);
200  if (address.toIPv6().matches(advPrefix.prefix, advPrefix.prefixLength))
201  return address != advPrefix.prefix;
202  }
203  }
204  }
205  break;
206 
207 #endif // ifdef WITH_IPv6
208  case L3Address::MAC:
210  case L3Address::MODULEID:
211  // TODO
212  break;
213 
214  default:
215  throw cRuntimeError("Unknown address type");
216  }
217  return false;
218 }
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:260
Definition: L3Address.h:47
Definition: L3Address.h:49
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
Definition: L3Address.h:50
Definition: L3Address.h:48
Definition: L3Address.h:46
virtual int inet::InterfaceTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
107 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
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.

102 {
103  // nothing needed here at the moment
104  Enter_Method_Silent();
105  printNotificationBanner(signalID, obj);
106 }
void printNotificationBanner(simsignal_t signalID, const cObject *obj)
Utility function.
Definition: NotifierConsts.cc:109
void inet::InterfaceTable::refreshDisplay ( ) const
overrideprotectedvirtual
81 {
82  char buf[80];
83  sprintf(buf, "%d interfaces", getNumInterfaces());
84  getDisplayString().setTagArg("t", 0, buf);
85 
86  if (par("displayAddresses").boolValue()) {
87  for (auto & elem : idToInterface) {
88  InterfaceEntry *ie = elem;
89  if (ie)
91  }
92  }
93 
94 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
friend class InterfaceEntry
Definition: IInterfaceTable.h:48
virtual void updateLinkDisplayString(InterfaceEntry *entry) const
Definition: InterfaceTable.cc:372
virtual int getNumInterfaces() const override
Returns the number of interfaces.
Definition: InterfaceTable.cc:220
void inet::InterfaceTable::resetInterfaces ( )
protectedvirtual

Referenced by handleOperationStage().

519 {
520  int n = idToInterface.size();
521  for (int i = 0; i < n; i++)
522  if (idToInterface[i])
523  idToInterface[i]->resetInterface();
524 
525 }
InterfaceVector idToInterface
Definition: InterfaceTable.h:77
void inet::InterfaceTable::updateLinkDisplayString ( InterfaceEntry entry) const
protectedvirtual

Referenced by refreshDisplay().

373 {
374  int outputGateId = entry->getNodeOutputGateId();
375  if (outputGateId != -1) {
376  ASSERT(host != nullptr);
377  cGate *outputGate = host->gate(outputGateId);
378  if (!outputGate->getChannel())
379  return;
380  cDisplayString& displayString = outputGate->getDisplayString();
381  std::ostringstream buf;
382  buf << entry->getFullName();
383 #ifdef WITH_IPv4
384  if (entry->ipv4Data()) {
385  buf << "\n" << entry->ipv4Data()->getIPAddress().str() << "/" << entry->ipv4Data()->getNetmask().getNetmaskLength();
386  }
387 #endif // ifdef WITH_IPv4
388 #ifdef WITH_IPv6
389  if (entry->ipv6Data() && entry->ipv6Data()->getNumAddresses() > 0) {
390  buf << "\n" << entry->ipv6Data()->getPreferredAddress().str();
391  }
392 #endif // ifdef WITH_IPv6
393  displayString.setTagArg("t", 0, buf.str().c_str());
394  displayString.setTagArg("t", 1, "l");
395  }
396 }
cModule * host
Definition: InterfaceTable.h:72

Member Data Documentation

InterfaceEntry** inet::InterfaceTable::tmpInterfaceList
mutableprotected
int inet::InterfaceTable::tmpNumInterfaces
mutableprotected

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