|
INET Framework for OMNeT++/OMNEST
|
Represents the interface table.
More...
#include <InterfaceTable.h>
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
◆ InterfaceVector
◆ InterfaceTable()
| inet::InterfaceTable::InterfaceTable |
( |
| ) |
|
◆ ~InterfaceTable()
| inet::InterfaceTable::~InterfaceTable |
( |
| ) |
|
|
virtual |
◆ addInterface()
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.
275 throw cRuntimeError(
"InterfaceTable must precede all network interface modules in the node's NED definition");
278 throw cRuntimeError(
"addInterface(): interface '%s' already registered", entry->getInterfaceName());
◆ collectMulticastGroups()
Returns all multicast group address, with it's interfaceId.
Implements inet::IInterfaceTable.
540 #ifdef INET_WITH_IPv4
542 int interfaceId = ie->getInterfaceId();
543 auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
545 int numOfMulticastGroups = ipv4Data->getNumOfJoinedMulticastGroups();
546 for (
int j = 0; j < numOfMulticastGroups; ++j) {
547 mglist.push_back(MulticastGroup(ipv4Data->getJoinedMulticastGroup(j), interfaceId));
550 #endif // ifdef INET_WITH_IPv4
551 #ifdef INET_WITH_IPv6
553 #endif // ifdef INET_WITH_IPv6
◆ deleteInterface()
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.
354 int id = entry->getInterfaceId();
356 throw cRuntimeError(
"deleteInterface(): interface '%s' not found in interface table", entry->getInterfaceName());
◆ discoverConnectingGates()
293 cModule *ifmod = entry;
298 ASSERT(
host !=
nullptr);
299 while (ifmod && ifmod->getParentModule() !=
host)
300 ifmod = ifmod->getParentModule();
302 throw cRuntimeError(
"addInterface(): specified module (%s) is not in this host/router '%s'", entry->getInterfaceFullPath().c_str(), this->getFullPath().c_str());
315 cGate *nwlayerInGate =
nullptr, *nwlayerOutGate =
nullptr;
316 for (GateIterator i(ifmod); !i.end(); i++) {
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());
329 if (
g->getType() == cGate::OUTPUT &&
g->getNextGate() &&
g->getNextGate()->isName(
"ifIn"))
330 nwlayerInGate =
g->getNextGate();
331 if (
g->getType() == cGate::INPUT &&
g->getPreviousGate() &&
g->getPreviousGate()->isName(
"ifOut"))
332 nwlayerOutGate =
g->getPreviousGate();
341 if (nwlayerInGate || nwlayerOutGate) {
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())
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());
Referenced by addInterface().
◆ findFirstLoopbackInterface()
Returns the first interface with the isLoopback flag set.
If there's no loopback, it returns nullptr.
Implements inet::IInterfaceTable.
485 for (
int i = 0; i < n; i++)
◆ findFirstMulticastInterface()
Returns the first multicast capable interface.
If there is no such interface, then returns nullptr.
Implements inet::IInterfaceTable.
507 for (
int i = 0; i < n; i++)
◆ 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.
496 for (
int i = 0; i < n; i++)
◆ findInterfaceByAddress()
Returns an interface given by its address.
Returns nullptr if not found.
Implements inet::IInterfaceTable.
114 if (!address.isUnspecified()) {
119 #ifdef INET_WITH_NEXTHOP
120 if (
auto nextHopData = ie->findProtocolData<NextHopInterfaceData>())
121 if (nextHopData->getAddress() == address)
123 #endif // ifdef INET_WITH_NEXTHOP
125 #ifdef INET_WITH_IPv4
127 if (
auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>())
128 if (ipv4Data->getIPAddress() == address.toIpv4())
131 #endif // ifdef INET_WITH_IPv4
133 #ifdef INET_WITH_IPv6
135 if (
auto ipv6Data = ie->findProtocolData<Ipv6InterfaceData>())
136 if (ipv6Data->hasAddress(address.toIpv6()))
139 #endif // ifdef INET_WITH_IPv6
142 if (ie->getMacAddress() == address.toMac())
147 if (ie->getModuleIdAddress() == address.toModuleId())
152 if (ie->getModulePathAddress() == address.toModulePath())
157 throw cRuntimeError(
"Unknown address type");
Referenced by isLocalAddress().
◆ findInterfaceById()
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 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.
438 ASSERT(
host !=
nullptr);
439 cModule *_ifmod = ifmod;
440 while (ifmod && ifmod->getParentModule() !=
host)
441 ifmod = ifmod->getParentModule();
443 throw cRuntimeError(
"Specified module (%s) is not in this host/router '%s'", _ifmod->getFullPath().c_str(), this->getFullPath().c_str());
445 int nodeInputGateId = -1, nodeOutputGateId = -1;
446 for (GateIterator i(ifmod); !i.end(); i++) {
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();
459 if (nodeInputGateId >= 0)
461 if (!ie && nodeOutputGateId >= 0)
464 ASSERT(!ie || (ie->getNodeInputGateId() == nodeInputGateId && ie->getNodeOutputGateId() == nodeOutputGateId));
◆ findInterfaceByName()
| NetworkInterface * inet::InterfaceTable::findInterfaceByName |
( |
const char * |
name | ) |
const |
|
overridevirtual |
◆ findInterfaceByNodeInputGateId()
| NetworkInterface * inet::InterfaceTable::findInterfaceByNodeInputGateId |
( |
int |
id | ) |
const |
|
overridevirtual |
◆ findInterfaceByNodeOutputGateId()
| NetworkInterface * inet::InterfaceTable::findInterfaceByNodeOutputGateId |
( |
int |
id | ) |
const |
|
overridevirtual |
◆ getBiggestInterfaceId()
| int inet::InterfaceTable::getBiggestInterfaceId |
( |
| ) |
const |
|
overridevirtual |
◆ getFullPath()
| virtual std::string inet::InterfaceTable::getFullPath |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ getHostModule()
| cModule * inet::InterfaceTable::getHostModule |
( |
| ) |
const |
|
overridevirtual |
◆ getInterface()
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.
236 if (pos < 0 || pos >= n)
237 throw cRuntimeError(
"getInterface(): interface index %d out of range 0..%d", pos, n - 1);
244 for (
int i = 0; i < maxId; i++)
Referenced by collectMulticastGroups().
◆ getInterfaceById()
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.
257 throw cRuntimeError(
"getInterfaceById(): no interface with ID=%d",
id);
Referenced by deleteInterface().
◆ getNumInterfaces()
| int inet::InterfaceTable::getNumInterfaces |
( |
| ) |
const |
|
overridevirtual |
◆ handleCrashOperation()
◆ handleMessageWhenUp()
| void inet::InterfaceTable::handleMessageWhenUp |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
◆ handleStartOperation()
◆ handleStopOperation()
◆ initialize()
| void inet::InterfaceTable::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
◆ interfaceChanged()
Implements inet::IInterfaceTable.
375 emit(signalID,
const_cast<NetworkInterfaceChangeDetails *
>(details));
◆ invalidateTmpInterfaceList()
| void inet::InterfaceTable::invalidateTmpInterfaceList |
( |
| ) |
|
|
protectedvirtual |
◆ isInitializeStage()
| virtual bool inet::InterfaceTable::isInitializeStage |
( |
int |
stage | ) |
const |
|
inlineoverridevirtual |
◆ isLocalAddress()
| bool inet::InterfaceTable::isLocalAddress |
( |
const L3Address & |
address | ) |
const |
|
overridevirtual |
◆ 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.
168 if (address.isUnspecified())
171 switch (address.getType()) {
172 #ifdef INET_WITH_IPv4
177 if (
auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>()) {
178 Ipv4Address ipv4Addr = ipv4Data->getIPAddress();
179 Ipv4Address netmask = ipv4Data->getNetmask();
181 return address != ipv4Addr;
187 #endif // ifdef INET_WITH_IPv4
188 #ifdef INET_WITH_IPv6
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;
204 #endif // ifdef INET_WITH_IPv6
212 throw cRuntimeError(
"Unknown address type");
◆ numInitStages()
| virtual int inet::InterfaceTable::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ 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.
◆ refreshDisplay()
| void inet::InterfaceTable::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
75 getDisplayString().setTagArg(
"t", 0, buf);
77 if (par(
"displayAddresses")) {
◆ resetInterfaces()
| void inet::InterfaceTable::resetInterfaces |
( |
| ) |
|
|
protectedvirtual |
◆ updateLinkDisplayString()
| void inet::InterfaceTable::updateLinkDisplayString |
( |
NetworkInterface * |
entry | ) |
const |
|
protectedvirtual |
380 int outputGateId = entry->getNodeOutputGateId();
381 if (outputGateId != -1) {
382 ASSERT(
host !=
nullptr);
383 cGate *outputGate =
host->gate(outputGateId);
384 if (!outputGate->getChannel())
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";
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()
401 || ipv6Data->getAddress(i).isMulticast())
continue;
402 buf << ipv6Data->getAddress(i).str() <<
"/64" <<
"\n";
405 #endif // ifdef INET_WITH_IPv6
406 displayString.setTagArg(
"t", 0, buf.str().c_str());
407 displayString.setTagArg(
"t", 1,
"l");
Referenced by refreshDisplay().
◆ host
| cModule* inet::InterfaceTable::host |
|
protected |
◆ idToInterface
Referenced by addInterface(), deleteInterface(), findFirstLoopbackInterface(), findFirstMulticastInterface(), findFirstNonLoopbackInterface(), findInterfaceByAddress(), findInterfaceById(), findInterfaceByName(), findInterfaceByNodeInputGateId(), findInterfaceByNodeOutputGateId(), getBiggestInterfaceId(), getInterface(), getNumInterfaces(), initialize(), isNeighborAddress(), refreshDisplay(), and resetInterfaces().
◆ tmpInterfaceList
◆ tmpNumInterfaces
| int inet::InterfaceTable::tmpNumInterfaces |
|
mutableprotected |
The documentation for this class was generated from the following files:
AddressType
Definition: L3Address.h:33
virtual NetworkInterface * findInterfaceByNodeOutputGateId(int id) const override
Returns an interface given by its getNodeOutputGateId().
Definition: InterfaceTable.cc:411
virtual int getNumInterfaces() const override
Returns the number of interfaces.
Definition: InterfaceTable.cc:217
virtual NetworkInterface * findInterfaceById(int id) const override
Returns an interface by its Id.
Definition: InterfaceTable.cc:261
@ MODULEID
Definition: L3Address.h:40
virtual NetworkInterface * findInterfaceByNodeInputGateId(int id) const override
Returns an interface given by its getNodeInputGateId().
Definition: InterfaceTable.cc:423
#define INTERFACEIDS_START
Definition: InterfaceTable.cc:38
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
virtual void invalidateTmpInterfaceList()
Definition: InterfaceTable.cc:365
void printSignalBanner(simsignal_t signalID, const cObject *obj, const cObject *details)
Utility function.
Definition: Simsignals.cc:126
@ IPv4
Definition: L3Address.h:35
@ MODULEPATH
Definition: L3Address.h:39
int tmpNumInterfaces
Definition: InterfaceTable.h:69
virtual void updateLinkDisplayString(NetworkInterface *entry) const
Definition: InterfaceTable.cc:378
milli< kg >::type g
Definition: Units.h:1071
friend class NetworkInterface
Definition: IInterfaceTable.h:38
simsignal_t interfaceDeletedSignal
Definition: Simsignals.cc:31
NetworkInterface ** tmpInterfaceList
Definition: InterfaceTable.h:70
cModule * host
Definition: InterfaceTable.h:61
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
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:26
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
InterfaceVector idToInterface
Definition: InterfaceTable.h:66
virtual NetworkInterface * getInterfaceById(int id) const override
Returns an interface by its Id.
Definition: InterfaceTable.cc:253
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
const double k
Definition: Qam1024Modulation.cc:14
virtual NetworkInterface * getInterface(int pos) const override
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
Definition: InterfaceTable.cc:233
@ IPv6
Definition: L3Address.h:36
virtual NetworkInterface * findInterfaceByAddress(const L3Address &address) const override
Returns an interface given by its address.
Definition: InterfaceTable.cc:112
#define Enter_Method(...)
Definition: SelfDoc.h:71
@ MAC
Definition: L3Address.h:38
virtual NetworkInterface * findInterfaceByName(const char *name) const override
Returns an interface given by its name.
Definition: InterfaceTable.cc:468
virtual void discoverConnectingGates(NetworkInterface *entry)
Definition: InterfaceTable.cc:291
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
simsignal_t interfaceCreatedSignal
Definition: Simsignals.cc:30
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
virtual void resetInterfaces()
Definition: InterfaceTable.cc:528
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.