|
INET Framework for OMNeT++/OMNEST
|
00001 /* 00002 * Author: Zdenek Kraus 00003 * email: xkraus00@stud.fit.vutbr.cz 00004 * created: 2010-02-12 00005 * 00006 */ 00007 00008 00009 /* 00010 -- TODO -- 00011 - VLAN ID 00012 - VLAN ifaces mapping 00013 00014 00015 */ 00016 00017 #ifndef __MACTABLE_H__ 00018 #define __MACTABLE_H__ 00019 00020 00021 #include "MACAddress.h" 00022 #include "Ethernet.h" 00023 #include "EtherFrame_m.h" 00024 00025 #include <string> 00026 #include <vector> 00027 00028 00029 class MACTable : public cSimpleModule 00030 { 00031 public: 00032 MACTable(); 00033 MACTable(int _tableSize); 00034 ~MACTable(); 00035 00036 00037 typedef std::vector<int> tPortList; 00038 00039 /* record types */ 00040 typedef enum e_type { 00041 STATIC = 0, // standart values and inserted by MGMT 00042 DYNAMIC = 1, // inserted by learning process, aged out 00043 GROUP = 2, // inserted by Group MGMT process 00044 } tType; 00045 00046 /* special definition */ 00047 typedef enum e_spec { 00048 NONE = 0, 00049 STP = 1, // switching to STP ports 00050 } tSpec; 00051 00052 /* enahanced MAC table record */ 00053 typedef struct s_record { 00054 MACAddress addr; // mac address 00055 simtime_t insert_time; // time of insertion od update for ageing process 00056 tPortList portList; // list of destination ports (multiple ports for group adresses) 00057 tType type; // record type = {static, dynamic, group} 00058 tSpec spec; // address specialities 00059 } tRecord; 00060 00061 /* compare structure for std::map */ 00062 struct MAC_compare{ 00063 bool operator()(const MACAddress& u1, const MACAddress& u2) const 00064 {return u1.compareTo(u2) < 0;} 00065 }; 00066 00067 /* table map type */ 00068 typedef std::map<MACAddress, tRecord, MAC_compare> AddressTable; 00069 00070 /* PUBLIC METHODS */ 00071 void update(MACAddress& addr, int port); 00072 tSpec getSpec(MACAddress& addr); 00073 tPortList& getPorts(MACAddress& addr); 00074 void flush(); 00075 void enableFasterAging(); // Aging ~ Ageing by Longman dictionary of contemporary english http://ldoceonline.com/ 00076 void resetAging(); 00077 00078 00079 const AddressTable * getTable(); 00080 00081 private: 00082 void initDefaults(); 00083 00084 /* MGMT */ 00085 void flushAged(); 00086 void removeOldest(); 00087 void add(MACAddress addr, int port, tType type, tSpec spec); 00088 void remove(MACAddress addr); 00089 void removePort(MACAddress addr, int port); 00090 void addStatic(MACAddress addr, tPortList ports); 00091 00092 /* mCast */ 00093 void addGroup(MACAddress addr, tPortList ports); // TODO 00094 void addGroupPort(MACAddress addr, int port); // TODO 00095 void removeGroup(MACAddress addr); // TODO 00096 void removeGroupPort(MACAddress addr, int port); // TODO 00097 void alterGroup(MACAddress addr, tPortList ports); // TODO 00098 00099 protected: 00100 AddressTable table; 00101 tPortList empty; 00102 00103 00104 int addressTableSize; // Maximum size of the Address Table 00105 simtime_t agingTime; // Determines when Ethernet entries are to be removed 00106 unsigned int uAgingTime; // user defined value (or default) for STP aging reset 00107 simtime_t fasterAging; // for STP topology change faster Aging 00108 00109 virtual void initialize(); // TODO 00110 virtual void finish(); // TODO 00111 00112 00113 }; 00114 00115 inline std::ostream& operator<<(std::ostream& os, const MACTable::tPortList l) { 00116 os << "["; 00117 for (unsigned int i = 0; i < l.size(); i++) { 00118 if (i != 0) { 00119 os << ", "; 00120 } 00121 os << l.at(i); 00122 } 00123 os << "]"; 00124 return os; 00125 } 00126 00127 inline std::ostream& operator<<(std::ostream& os, const MACTable::tType t) { 00128 switch (t) { 00129 case MACTable::STATIC: 00130 os << "Static"; 00131 break; 00132 case MACTable::DYNAMIC: 00133 os << "Dynamic"; 00134 break; 00135 case MACTable::GROUP: 00136 os << "Group"; 00137 break; 00138 } 00139 00140 return os; 00141 } 00142 00143 inline std::ostream& operator<<(std::ostream& os, const MACTable::tSpec s) { 00144 switch (s) { 00145 case MACTable::NONE: 00146 os << "None"; 00147 break; 00148 case MACTable::STP: 00149 os << "STP"; 00150 break; 00151 default: 00152 os << "???"; 00153 break; 00154 } 00155 00156 return os; 00157 } 00158 00159 inline std::ostream& operator<<(std::ostream& os, const MACTable::tRecord& addr) { 00160 os << addr.type; 00161 if (addr.spec != MACTable::NONE) { 00162 os << "(" << addr.spec << ")"; 00163 } 00164 os << " " << addr.portList << " @" << addr.insert_time; 00165 return os; 00166 } 00167 00168 #endif 00169