|
INET Framework for OMNeT++/OMNEST
|
00001 00002 /* 00003 -- TODO -- 00004 - VLAN ID 00005 - VLAN ifaces mapping 00006 00007 00008 */ 00009 00010 00011 00012 #ifndef __VLANTABLE_H__ 00013 #define __VLANTABLE_H__ 00014 00015 00016 00017 #include "IPAddress.h" 00018 #include "IPAddressResolver.h" 00019 #include "IRoutingTable.h" 00020 #include "RoutingTableAccess.h" 00021 #include "IInterfaceTable.h" 00022 #include "InterfaceTableAccess.h" 00023 #include "IPDatagram.h" 00024 #include "TCPSegment.h" 00025 #include "UDPPacket.h" 00026 #include "NotificationBoard.h" 00027 #include "MACAddress.h" 00028 #include "Ethernet.h" 00029 #include "EtherFrame_m.h" 00030 00031 00032 #include <string> 00033 #include <vector> 00034 00035 00036 #define VLANCOUNT 32 00037 00038 class INET_API VLANTable : public cSimpleModule 00039 { 00040 public: 00041 00042 VLANTable(); 00043 ~VLANTable(); 00044 00045 00046 /* VLAN -> Port mapping */ 00047 typedef enum e_tag_action { 00048 REMOVE = 0, 00049 INCLUDE = 1, 00050 NONE = -1, 00051 } tTagAction; 00052 00053 typedef struct s_vid_port { 00054 int port; 00055 tTagAction action; 00056 } tVIDPort; 00057 00058 typedef std::vector<tVIDPort> tVIDPortList; 00059 00060 typedef struct s_vid_record { 00061 int VID; 00062 std::string name; 00063 tVIDPortList portList; 00064 } tVIDRecord; 00065 00066 /* Port -> VLAN mapping */ 00067 typedef struct s_port_vid { 00068 int port; 00069 int VID; 00070 } tPortVIDRecord; 00071 00072 00073 typedef std::vector<tVIDRecord> VIDTable; 00074 typedef std::vector<tPortVIDRecord> PortVIDTable; 00075 00076 /* MGMT */ 00077 const VIDTable * getTaggedTable(); 00078 const PortVIDTable * getUntaggedTable(); 00079 00080 /* PUBLIC ACCESS METHODS */ 00081 tVIDPortList getPorts(int VID); 00082 int getVID(int Port); 00083 bool isAllowed(int VID, int _port); 00084 tTagAction getTag(int VID, int _port); 00085 00086 /* MGMT */ 00087 void add(int VID, tVIDPortList& _portList); 00088 void addTagged(int VID, std::vector<int>& ports); 00089 void addUntagged(int VID, std::vector<int>& ports); 00090 00091 void setVLANName(int, std::string&); 00092 00093 void addPortVID(int _port, int _VID); 00094 void setPortVID(int _port, int _VID); 00095 00096 void delPort(int _port, int _VID); 00097 00098 void regVLAN(unsigned int); 00099 std::vector<unsigned int> getVLANList(); 00100 00101 void initDefault(); 00102 00103 /* add empty records at the end of existing until given VLAN, inclusive*/ 00104 void extendTable(int VLAN); 00105 00106 private: 00107 VIDTable vidTable; 00108 PortVIDTable portVIDTable; 00109 tVIDPortList empty; 00110 00111 tVIDRecord emptyVID; 00112 00113 std::vector<unsigned int> vlanList; 00114 00115 int portCount; 00116 00117 00118 protected: 00119 00120 virtual void initialize(int stage); 00121 virtual int numInitStages() const {return 1;} 00122 virtual void finish(); 00123 00124 00125 00126 }; 00127 00128 inline std::ostream& operator<<(std::ostream& os, const VLANTable::tTagAction a) { 00129 switch (a) { 00130 case VLANTable::INCLUDE: 00131 os << "T"; 00132 break; 00133 case VLANTable::REMOVE: 00134 os << "U"; 00135 break; 00136 case VLANTable::NONE: 00137 os << "??"; 00138 break; 00139 } 00140 return os; 00141 } 00142 00143 00144 inline std::ostream& operator<<(std::ostream& os, const VLANTable::tVIDPortList l) { 00145 os << "["; 00146 for (unsigned int i = 0; i < l.size(); i++) { 00147 if (i != 0) { 00148 os << ", "; 00149 } 00150 os << l.at(i).port << l.at(i).action; 00151 } 00152 os << "]"; 00153 return os; 00154 } 00155 00156 inline std::ostream& operator<<(std::ostream& os, const VLANTable::tPortVIDRecord r) { 00157 os << "Port " << r.port << " accessing VLAN " << r.VID; 00158 return os; 00159 } 00160 00161 inline std::ostream& operator<<(std::ostream& os, const VLANTable::tVIDRecord r) { 00162 os << "VLAN " << r.VID << " at ports " << r.portList; 00163 return os; 00164 } 00165 00166 #endif 00167