|
INET Framework for OMNeT++/OMNEST
|
#include <macTable.h>
Classes | |
| struct | MAC_compare |
| struct | s_record |
Public Types | |
| enum | e_type { STATIC = 0, DYNAMIC = 1, GROUP = 2 } |
| enum | e_spec { NONE = 0, STP = 1 } |
| typedef std::vector< int > | tPortList |
| typedef enum MACTable::e_type | tType |
| typedef enum MACTable::e_spec | tSpec |
| typedef struct MACTable::s_record | tRecord |
| typedef std::map< MACAddress, tRecord, MAC_compare > | AddressTable |
Public Member Functions | |
| MACTable () | |
| MACTable (int _tableSize) | |
| ~MACTable () | |
| void | update (MACAddress &addr, int port) |
| tSpec | getSpec (MACAddress &addr) |
| tPortList & | getPorts (MACAddress &addr) |
| void | flush () |
| void | enableFasterAging () |
| void | resetAging () |
| const AddressTable * | getTable () |
Protected Member Functions | |
| virtual void | initialize () |
| virtual void | finish () |
Protected Attributes | |
| AddressTable | table |
| tPortList | empty |
| int | addressTableSize |
| simtime_t | agingTime |
| unsigned int | uAgingTime |
| simtime_t | fasterAging |
Private Member Functions | |
| void | initDefaults () |
| void | flushAged () |
| void | removeOldest () |
| void | add (MACAddress addr, int port, tType type, tSpec spec) |
| void | remove (MACAddress addr) |
| void | removePort (MACAddress addr, int port) |
| void | addStatic (MACAddress addr, tPortList ports) |
| void | addGroup (MACAddress addr, tPortList ports) |
| void | addGroupPort (MACAddress addr, int port) |
| void | removeGroup (MACAddress addr) |
| void | removeGroupPort (MACAddress addr, int port) |
| void | alterGroup (MACAddress addr, tPortList ports) |
Definition at line 29 of file macTable.h.
| typedef std::map<MACAddress, tRecord, MAC_compare> MACTable::AddressTable |
Definition at line 68 of file macTable.h.
| typedef std::vector<int> MACTable::tPortList |
Definition at line 37 of file macTable.h.
| typedef struct MACTable::s_record MACTable::tRecord |
| typedef enum MACTable::e_spec MACTable::tSpec |
| typedef enum MACTable::e_type MACTable::tType |
| enum MACTable::e_spec |
Definition at line 47 of file macTable.h.
| enum MACTable::e_type |
Definition at line 9 of file macTable.cc.
{
this->initDefaults();
return;
}
| MACTable::MACTable | ( | int | _tableSize | ) |
Definition at line 14 of file macTable.cc.
{
this->initDefaults();
if (_tableSize < 0) {
this->addressTableSize = 0;
} else {
this->addressTableSize = _tableSize;
}
return;
}
Definition at line 24 of file macTable.cc.
{
return;
}
| void MACTable::add | ( | MACAddress | addr, |
| int | port, | ||
| tType | type, | ||
| tSpec | spec | ||
| ) | [private] |
Definition at line 207 of file macTable.cc.
Referenced by initialize().
{
AddressTable::iterator iter;
iter = this->table.find(addr);
if (iter == this->table.end()) { // record not found
// Observe finite table size
if (this->addressTableSize != 0 && this->table.size() == (unsigned int)addressTableSize) {
EV << "Making room in Address Table by throwing out aged entries.\n";
if (this->table.size() == (unsigned int)addressTableSize) {
removeOldest();
}
}
// Add entry to table
EV << "Adding entry to Address Table: "<< addr << " --> port" << port << "\n";
tRecord entry; // create new entry, with given port & type
entry.addr = addr;
entry.insert_time = simTime();
entry.portList.push_back(port);
entry.type = type;
entry.spec = spec;
this->table[addr] = entry;
} else {
// Update existing entry
EV << "Updating entry in Address Table: "<< addr << " --> port" << port << "\n";
tRecord& entry = iter->second;
entry.insert_time = simTime();
unsigned int i;
for (i = 0; i < entry.portList.size(); i++) { // search through portList for given port
if (entry.portList.at(i) == port) {
break;
}
}
if (i < entry.portList.size()) {
entry.portList.clear();
entry.portList.push_back(port);
}
}
return;
}
| void MACTable::addGroup | ( | MACAddress | addr, |
| tPortList | ports | ||
| ) | [private] |
| void MACTable::addGroupPort | ( | MACAddress | addr, |
| int | port | ||
| ) | [private] |
| void MACTable::addStatic | ( | MACAddress | addr, |
| tPortList | ports | ||
| ) | [private] |
Definition at line 284 of file macTable.cc.
{
AddressTable::iterator iter;
iter = this->table.find(addr);
if (iter == this->table.end()) { // record not found
// Observe finite table size
if (this->addressTableSize != 0 && this->table.size() == (unsigned int)addressTableSize) {
EV << "Making room in Address Table by throwing out aged entries.\n";
if (this->table.size() == (unsigned int)addressTableSize) {
removeOldest();
}
}
// Add entry to table
EV << "Adding static entry to Address Table: "<< addr << " " << ports << std::endl;
tRecord entry; // create new entry, with given port & type
entry.addr = addr;
entry.insert_time = simTime();
entry.portList = ports;
entry.type = STATIC;
entry.spec = NONE;
this->table[addr] = entry;
} else {
// Update existing entry
EV << "Updating entry in Address Table: "<< addr << " " << ports << std::endl;
tRecord& entry = iter->second;
entry.insert_time = simTime();
unsigned int i;
unsigned int c;
for(i = 0; i < ports.size(); i++) { // for all input port number
for(c = 0; c < entry.portList.size(); c++) { // search through whole port vector
if (entry.portList.at(c) == ports.at(i)) { // if port number match
break;
}
}
if (c == entry.portList.size()) { // if port record not found
entry.portList.push_back(ports.at(i)); // insert new
}
}
}
return;
}
| void MACTable::alterGroup | ( | MACAddress | addr, |
| tPortList | ports | ||
| ) | [private] |
| void MACTable::enableFasterAging | ( | ) |
Definition at line 140 of file macTable.cc.
Referenced by stpi::generator(), and stpi::handleBPDU().
{
Enter_Method_Silent();
agingTime = fasterAging;
}
| void MACTable::finish | ( | ) | [protected, virtual] |
Definition at line 376 of file macTable.cc.
{
EV << "ANSA Switch, end of transmission." << std::endl;
return;
}
| void MACTable::flush | ( | ) |
Definition at line 124 of file macTable.cc.
| void MACTable::flushAged | ( | ) | [private] |
Definition at line 170 of file macTable.cc.
Referenced by update().
{
Enter_Method_Silent();
AddressTable::iterator iter;
for (iter = this->table.begin(); iter != this->table.end();) {
AddressTable::iterator cur = iter++; // iter will get invalidated after erase()
tRecord entry = cur->second;
if (entry.type == DYNAMIC && entry.insert_time + agingTime <= simTime()) {
EV << "Removing aged entry from Address Table: " << cur->first << "\n";
this->table.erase(cur);
}
}
return;
}
| MACTable::tPortList & MACTable::getPorts | ( | MACAddress & | addr | ) |
Definition at line 102 of file macTable.cc.
Referenced by ANSASwitchCore::handleAndDispatchFrame(), and ANSASwitchCore::relay().
{
Enter_Method_Silent();
AddressTable::iterator iter = table.find(addr);
if (iter == table.end()) {
// not found
return empty;
}
if ((iter->second.type != STATIC) &&
(iter->second.insert_time + agingTime) <= simTime()) {
// don't use (and throw out) aged entries
EV << "Ignoring and deleting aged entry: "<< iter->first << "\n";
table.erase(iter);
return empty;
}
return iter->second.portList;
}
| MACTable::tSpec MACTable::getSpec | ( | MACAddress & | addr | ) |
Definition at line 80 of file macTable.cc.
{
Enter_Method_Silent();
AddressTable::iterator iter = table.find(addr);
if (iter == table.end()) {
// not found
return NONE;
}
if ((iter->second.type != STATIC) &&
(iter->second.insert_time + agingTime) <= simTime()) {
// don't use (and throw out) aged entries
EV << "Ignoring and deleting aged entry: "<< iter->first << "\n";
table.erase(iter);
return NONE;
}
return iter->second.spec;
}
| const MACTable::AddressTable * MACTable::getTable | ( | ) |
Definition at line 28 of file macTable.cc.
{
return &(this->table);
}
| void MACTable::initDefaults | ( | ) | [private] |
Definition at line 154 of file macTable.cc.
Referenced by initialize(), and MACTable().
{
addressTableSize = 1024; // TODO
/* by IEEE 802.1D-1998
* " The Bridges then use a short value
* to age out dynamic entries
* in the Fitering Database for a period."
* */
fasterAging = 5; // short value to age out ... (5s < 5xHelloTime = 10s)
uAgingTime = 300; // recommended value by IEEE 802.1D-1998 (and later)...
agingTime = uAgingTime; // renew of user defined value, is triggered by STP process and receiving bpdu
return;
}
| void MACTable::initialize | ( | ) | [protected, virtual] |
Definition at line 338 of file macTable.cc.
{
this->initDefaults();
/* TEST */
/*
tPortList tmp0, tmp1;
tmp0.push_back(0);
tmp0.push_back(1);
tmp0.push_back(2);
tmp0.push_back(3);
tmp1.push_back(2);
tmp1.push_back(3);
tmp1.push_back(4);
tmp1.push_back(5);
addStatic(MACAddress("01:00:00:00:00:01"), tmp0);
addStatic(MACAddress("01:00:00:00:00:02"), tmp1);
removePort(MACAddress("01:00:00:00:00:01"), 2);
remove(MACAddress("01:00:00:00:00:02"));
add(MACAddress("01:00:00:00:00:03"), 16, GROUP, NONE);
*/
/* END TEST */
/* IEEE802.1D Table 7-10 Reserved addresses */
// Bridge Group Address -> go to STP
add(MACAddress("01-80-C2-00-00-00"), 0, STATIC, STP);
/* end of table */
WATCH_MAP(this->table);
WATCH(this->addressTableSize);
WATCH(this->agingTime);
WATCH_RW(uAgingTime);
return;
}
| void MACTable::remove | ( | MACAddress | addr | ) | [private] |
Definition at line 253 of file macTable.cc.
| void MACTable::removeGroup | ( | MACAddress | addr | ) | [private] |
| void MACTable::removeGroupPort | ( | MACAddress | addr, |
| int | port | ||
| ) | [private] |
| void MACTable::removeOldest | ( | ) | [private] |
Definition at line 186 of file macTable.cc.
Referenced by add(), addStatic(), and update().
{
Enter_Method_Silent();
AddressTable::iterator oldest = this->table.end();
simtime_t oldestInsertTime = simTime()+1;
for (AddressTable::iterator iter = this->table.begin(); iter != this->table.end(); iter++) {
if (iter->second.type != DYNAMIC && iter->second.insert_time < oldestInsertTime) {
oldest = iter;
oldestInsertTime = iter->second.insert_time;
}
}
if (oldest != this->table.end()) {
EV << "Table full, removing oldest entry: " <<
oldest->first << "\n";
this->table.erase(oldest);
}
return;
}
| void MACTable::removePort | ( | MACAddress | addr, |
| int | port | ||
| ) | [private] |
Definition at line 265 of file macTable.cc.
{
AddressTable::iterator iter;
iter = this->table.find(addr);
if (iter == this->table.end()) { // record not found
return;
} else {
tRecord& entry = iter->second;
tPortList::iterator pIter;
for (pIter = entry.portList.begin(); pIter < entry.portList.end(); pIter++) { // search through portList for given port
if (*pIter == port) {
entry.portList.erase(pIter);
break;
}
}
}
return;
}
| void MACTable::resetAging | ( | ) |
Definition at line 145 of file macTable.cc.
Referenced by stpi::generator(), and stpi::handleBPDU().
{
Enter_Method_Silent();
agingTime = uAgingTime;
}
| void MACTable::update | ( | MACAddress & | addr, |
| int | port | ||
| ) |
Definition at line 34 of file macTable.cc.
Referenced by ANSASwitchCore::handleAndDispatchFrame(), and ANSASwitchCore::learn().
{
Enter_Method_Silent();
flushAged();
AddressTable::iterator iter;
iter = this->table.find(addr);
if (iter == this->table.end()) {
// Observe finite table size
if (this->addressTableSize != 0 && this->table.size() == (unsigned int)addressTableSize) {
EV << "Making room in Address Table by throwing out aged entries.\n";
if (this->table.size() == (unsigned int)addressTableSize) {
removeOldest();
}
}
// Add entry to table
EV << "Adding entry to Address Table: "<< addr << " --> port" << port << "\n";
tRecord entry;
entry.addr = addr;
entry.insert_time = simTime();
entry.portList.push_back(port);
entry.type = DYNAMIC;
entry.spec = NONE;
this->table[addr] = entry;
} else {
// Update existing entry
EV << "Updating entry in Address Table: "<< addr << " --> port" << port << "\n";
tRecord& entry = iter->second;
if (entry.type == DYNAMIC) {
entry.insert_time = simTime();
if (entry.portList.at(0) != port) {
entry.portList.clear();
entry.portList.push_back(port);
}
}
}
return;
}
int MACTable::addressTableSize [protected] |
Definition at line 104 of file macTable.h.
Referenced by add(), addStatic(), initDefaults(), initialize(), MACTable(), and update().
simtime_t MACTable::agingTime [protected] |
Definition at line 105 of file macTable.h.
Referenced by enableFasterAging(), flushAged(), getPorts(), getSpec(), initDefaults(), initialize(), and resetAging().
tPortList MACTable::empty [protected] |
Definition at line 101 of file macTable.h.
Referenced by getPorts().
simtime_t MACTable::fasterAging [protected] |
Definition at line 107 of file macTable.h.
Referenced by enableFasterAging(), and initDefaults().
AddressTable MACTable::table [protected] |
Definition at line 100 of file macTable.h.
Referenced by add(), addStatic(), flush(), flushAged(), getPorts(), getSpec(), getTable(), initialize(), remove(), removeOldest(), removePort(), and update().
unsigned int MACTable::uAgingTime [protected] |
Definition at line 106 of file macTable.h.
Referenced by initDefaults(), initialize(), and resetAging().