|
INET Framework for OMNeT++/OMNEST
|
This module handles the mapping between interface IDs and MAC addresses.
More...
#include <MacForwardingTable.h>
|
| virtual int | getUnicastAddressForwardingInterface (const MacAddress &address, unsigned int vid=0) const override |
| |
| virtual void | setUnicastAddressForwardingInterface (int interfaceId, const MacAddress &address, unsigned int vid=0) override |
| |
| virtual void | removeUnicastAddressForwardingInterface (int interfaceId, const MacAddress &address, unsigned int vid=0) override |
| |
| virtual void | learnUnicastAddressForwardingInterface (int interfaceId, const MacAddress &address, unsigned int vid=0) override |
| |
| virtual std::vector< int > | getMulticastAddressForwardingInterfaces (const MacAddress &address, unsigned int vid=0) const override |
| |
| virtual void | addMulticastAddressForwardingInterface (int interfaceId, const MacAddress &address, unsigned int vid=0) override |
| |
| virtual void | removeMulticastAddressForwardingInterface (int interfaceId, const MacAddress &address, unsigned int vid=0) override |
| |
| virtual void | removeForwardingInterface (int interfaceId) override |
| |
| virtual void | replaceForwardingInterface (int oldInterfaceId, int newInterfaceId) override |
| |
| virtual | ~OperationalMixin () |
| | }@ More...
|
| |
| virtual | ~ILifecycle () |
| |
This module handles the mapping between interface IDs and MAC addresses.
See the NED definition for details. NOTE that interfaceIds (interfaceId parameters) are actually the corresponding ID of the port interface. i.e. this is an interfaceId and NOT an index of the some kind in a gate vector.
◆ ForwardingTable
◆ ForwardingTableKey
◆ MulticastForwardingTable
◆ addMulticastAddressForwardingInterface()
| void inet::MacForwardingTable::addMulticastAddressForwardingInterface |
( |
int |
interfaceId, |
|
|
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| |
|
overridevirtual |
◆ clearTable()
| void inet::MacForwardingTable::clearTable |
( |
| ) |
|
|
protectedvirtual |
◆ getMulticastAddressForwardingInterfaces()
| std::vector< int > inet::MacForwardingTable::getMulticastAddressForwardingInterfaces |
( |
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| const |
|
overridevirtual |
Implements inet::IMacForwardingTable.
200 Enter_Method(
"getMulticastAddressForwardingInterfaces");
201 ASSERT(address.isMulticast());
205 return std::vector<int>();
207 return it->second.interfaceIds;
◆ getUnicastAddressForwardingInterface()
| int inet::MacForwardingTable::getUnicastAddressForwardingInterface |
( |
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| const |
|
overridevirtual |
Implements inet::IMacForwardingTable.
139 ASSERT(!address.isMulticast());
144 else if (it->second.insertionTime <= simTime() -
agingTime) {
145 EV_TRACE <<
"Ignoring aged entry: " << it->first <<
" --> " << it->second <<
"\n";
149 return it->second.interfaceId;
◆ handleCrashOperation()
| virtual void inet::MacForwardingTable::handleCrashOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ handleMessage()
| void inet::MacForwardingTable::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
◆ handleMessageWhenUp()
| void inet::MacForwardingTable::handleMessageWhenUp |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
◆ handleParameterChange()
| void inet::MacForwardingTable::handleParameterChange |
( |
const char * |
name | ) |
|
|
overrideprotectedvirtual |
65 if (name !=
nullptr) {
66 if (!strcmp(name,
"forwardingTable")) {
◆ handleStartOperation()
| virtual void inet::MacForwardingTable::handleStartOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ handleStopOperation()
| virtual void inet::MacForwardingTable::handleStopOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ initialize()
| void inet::MacForwardingTable::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
◆ initializeTable()
| void inet::MacForwardingTable::initializeTable |
( |
| ) |
|
|
protectedvirtual |
For lifecycle: initialize entries for the vlanForwardingTable by reading them from a file (if specified by a parameter)
383 const char *forwardingTableFile = par(
"forwardingTableFile");
384 if (forwardingTableFile && *forwardingTableFile)
◆ isInitializeStage()
| virtual bool inet::MacForwardingTable::isInitializeStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStartStage()
| virtual bool inet::MacForwardingTable::isModuleStartStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStopStage()
| virtual bool inet::MacForwardingTable::isModuleStopStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ learnUnicastAddressForwardingInterface()
| void inet::MacForwardingTable::learnUnicastAddressForwardingInterface |
( |
int |
interfaceId, |
|
|
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| |
|
overridevirtual |
Implements inet::IMacForwardingTable.
180 ASSERT(!address.isMulticast());
188 else if (it->second.insertionTime != SimTime::getMaxTime()) {
190 AddressEntry& entry = it->second;
191 entry.interfaceId = interfaceId;
192 entry.insertionTime = simTime();
◆ numInitStages()
| virtual int inet::MacForwardingTable::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ parseForwardingTableParameter()
| void inet::MacForwardingTable::parseForwardingTableParameter |
( |
| ) |
|
|
protectedvirtual |
357 auto forwardingTable = check_and_cast<cValueArray *>(par(
"forwardingTable").objectValue());
359 cValueMap *entry = check_and_cast<cValueMap *>(
forwardingTable->get(i).objectValue());
360 auto vlan = entry->containsKey(
"vlan") ? entry->get(
"vlan").intValue() : 0;
361 auto macAddressString = entry->get(
"address").stringValue();
364 throw cRuntimeError(
"Cannot resolve MAC address of '%s'", macAddressString);
365 MacAddress macAddress = l3Address.toMac();
366 auto interfaceName = entry->get(
"interface").stringValue();
367 auto networkInterface =
ifTable->findInterfaceByName(interfaceName);
368 if (networkInterface ==
nullptr)
369 throw cRuntimeError(
"Cannot find network interface '%s'", interfaceName);
370 if (macAddress.isMulticast())
Referenced by handleParameterChange(), and initializeTable().
◆ printState()
| void inet::MacForwardingTable::printState |
( |
| ) |
|
|
protectedvirtual |
Prints cached data.
251 EV << endl <<
"MAC Address Table" << endl;
252 EV <<
"VLAN ID MAC IfId Inserted" << endl;
254 EV << elem.first.first <<
" " << elem.first.second <<
" " << elem.second.interfaceId <<
" " << elem.second.insertionTime << endl;
◆ readForwardingTable()
| void inet::MacForwardingTable::readForwardingTable |
( |
const char * |
fileName | ) |
|
|
protectedvirtual |
Pre-reads in entries for Address Table during initialization.
292 FILE *fp = fopen(fileName,
"r");
294 throw cRuntimeError(
"cannot open address table file `%s'", fileName);
298 for (
int lineno = 0; (line = fgetline(fp)) !=
nullptr;
delete[] line) {
306 char *vlanIdStr = strtok(line,
" \t");
308 char *macAddressStr = strtok(
nullptr,
" \t");
310 char *interfaceName = strtok(
nullptr,
" \t");
312 char *endptr =
nullptr;
315 if (!vlanIdStr || *vlanIdStr ==
'#')
319 if (!vlanIdStr || !macAddressStr || !interfaceName)
320 throw cRuntimeError(
"line %d invalid in address table file `%s'", lineno, fileName);
325 unsigned int vlanId = strtol(vlanIdStr, &endptr, 10);
326 if (!endptr || *endptr)
327 throw cRuntimeError(
"error in line %d in address table file `%s': VLAN ID '%s' unresolved", lineno, fileName, vlanIdStr);
332 throw cRuntimeError(
"error in line %d in address table file `%s': MAC address '%s' unresolved", lineno, fileName, macAddressStr);
333 MacAddress macAddress = addr.toMac();
336 int interfaceId = -1;
337 auto ie =
ifTable->findInterfaceByName(interfaceName);
339 long int num = strtol(interfaceName, &endptr, 10);
340 if (endptr && *endptr ==
'\0')
341 ie =
ifTable->findInterfaceById(num);
344 throw cRuntimeError(
"error in line %d in address table file `%s': interface '%s' not found", lineno, fileName, interfaceName);
345 interfaceId = ie->getInterfaceId();
348 AddressEntry entry(vlanId, interfaceId, 0);
Referenced by initializeTable().
◆ refreshDisplay()
| void inet::MacForwardingTable::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
◆ removeAgedEntriesFromAllVlans()
| void inet::MacForwardingTable::removeAgedEntriesFromAllVlans |
( |
| ) |
|
|
protectedvirtual |
Remove aged entries from all VLANs.
269 AddressEntry& entry = cur->second;
270 if (entry.insertionTime <= simTime() -
agingTime) {
271 EV <<
"Removing aged entry from Address Table: "
272 << cur->first.first <<
" " << cur->first.second <<
" --> interfaceId " << cur->second.interfaceId <<
"\n";
Referenced by removeAgedEntriesIfNeeded().
◆ removeAgedEntriesIfNeeded()
| void inet::MacForwardingTable::removeAgedEntriesIfNeeded |
( |
| ) |
|
|
protectedvirtual |
◆ removeForwardingInterface()
| void inet::MacForwardingTable::removeForwardingInterface |
( |
int |
interfaceId | ) |
|
|
overridevirtual |
◆ removeMulticastAddressForwardingInterface()
| void inet::MacForwardingTable::removeMulticastAddressForwardingInterface |
( |
int |
interfaceId, |
|
|
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| |
|
overridevirtual |
Implements inet::IMacForwardingTable.
227 Enter_Method(
"removeMulticastAddressForwardingInterface");
228 ASSERT(address.isMulticast());
232 throw cRuntimeError(
"Cannot find entry");
233 if (
contains(it->second.interfaceIds, interfaceId))
234 throw cRuntimeError(
"Cannot find interface");
235 remove(it->second.interfaceIds, interfaceId);
◆ removeUnicastAddressForwardingInterface()
| void inet::MacForwardingTable::removeUnicastAddressForwardingInterface |
( |
int |
interfaceId, |
|
|
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| |
|
overridevirtual |
◆ replaceForwardingInterface()
| void inet::MacForwardingTable::replaceForwardingInterface |
( |
int |
oldInterfaceId, |
|
|
int |
newInterfaceId |
|
) |
| |
|
overridevirtual |
Implements inet::IMacForwardingTable.
261 if (elem.second.interfaceId == oldInterfaceId)
262 elem.second.interfaceId = newInterfaceId;
◆ resolveDirective()
| const char * inet::MacForwardingTable::resolveDirective |
( |
char |
directive | ) |
const |
|
overrideprotectedvirtual |
◆ setAgingTime()
| void inet::MacForwardingTable::setAgingTime |
( |
simtime_t |
agingTime | ) |
|
|
overrideprotectedvirtual |
◆ setUnicastAddressForwardingInterface()
| void inet::MacForwardingTable::setUnicastAddressForwardingInterface |
( |
int |
interfaceId, |
|
|
const MacAddress & |
address, |
|
|
unsigned int |
vid = 0 |
|
) |
| |
|
overridevirtual |
◆ updateDisplayString()
| void inet::MacForwardingTable::updateDisplayString |
( |
| ) |
const |
|
protectedvirtual |
115 if (getEnvir()->isGUI()) {
117 getDisplayString().setTagArg(
"t", 0, text);
Referenced by refreshDisplay().
◆ operator<< [1/3]
| std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const AddressEntry & |
entry |
|
) |
| |
|
friend |
38 return os <<
"{interfaceId=" << entry.interfaceId <<
", insertionTime=" << entry.insertionTime <<
"}";
◆ operator<< [2/3]
43 return os <<
"{VID=" << key.first <<
", addr=" << key.second <<
"}";
◆ operator<< [3/3]
48 return os <<
"{interfaceIds=" << entry.interfaceIds <<
"}";
◆ agingTime
| simtime_t inet::MacForwardingTable::agingTime |
|
protected |
◆ forwardingTable
Referenced by clearTable(), getUnicastAddressForwardingInterface(), initialize(), learnUnicastAddressForwardingInterface(), parseForwardingTableParameter(), printState(), readForwardingTable(), removeAgedEntriesFromAllVlans(), removeForwardingInterface(), removeUnicastAddressForwardingInterface(), replaceForwardingInterface(), resolveDirective(), and setUnicastAddressForwardingInterface().
◆ ifTable
◆ lastPurge
| simtime_t inet::MacForwardingTable::lastPurge |
|
protected |
◆ multicastForwardingTable
The documentation for this class was generated from the following files:
MulticastForwardingTable multicastForwardingTable
Definition: MacForwardingTable.h:58
void remove(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:107
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
std::pair< unsigned int, MacAddress > ForwardingTableKey
Definition: MacForwardingTable.h:50
ForwardingTable forwardingTable
Definition: MacForwardingTable.h:57
virtual void initializeTable()
For lifecycle: initialize entries for the vlanForwardingTable by reading them from a file (if specifi...
Definition: MacForwardingTable.cc:377
@ ADDR_MAC
Definition: L3AddressResolver.h:72
virtual void setUnicastAddressForwardingInterface(int interfaceId, const MacAddress &address, unsigned int vid=0) override
Definition: MacForwardingTable.cc:152
virtual void updateDisplayString() const
Definition: MacForwardingTable.cc:113
simtime_t agingTime
Definition: MacForwardingTable.h:55
virtual void removeAgedEntriesFromAllVlans()
Remove aged entries from all VLANs.
Definition: MacForwardingTable.cc:266
#define EV_FIELD(...)
Definition: INETDefs.h:112
virtual void addMulticastAddressForwardingInterface(int interfaceId, const MacAddress &address, unsigned int vid=0) override
Definition: MacForwardingTable.cc:210
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
simtime_t lastPurge
Definition: MacForwardingTable.h:56
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
virtual void clearTable()
For lifecycle: clears all entries from the vlanForwardingTable.
Definition: MacForwardingTable.cc:388
virtual void parseForwardingTableParameter()
Definition: MacForwardingTable.cc:355
#define Enter_Method(...)
Definition: SelfDoc.h:71
virtual void removeAgedEntriesIfNeeded()
Definition: MacForwardingTable.cc:280
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
virtual void readForwardingTable(const char *fileName)
Pre-reads in entries for Address Table during initialization.
Definition: MacForwardingTable.cc:290
#define EV_ENDL
Definition: INETDefs.h:114
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.
ModuleRefByPar< IInterfaceTable > ifTable
Definition: MacForwardingTable.h:59