00001 /* 00002 * Copyright (C) 2003 CTIE, Monash University 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 00020 #ifndef _MACRELAYUNITBASE_H 00021 #define _MACRELAYUNITBASE_H 00022 00023 #include <omnetpp.h> 00024 #include <map> 00025 #include <string> 00026 #include "MACAddress.h" 00027 00028 class EtherFrame; 00029 00030 00037 class MACRelayUnitBase : public cSimpleModule 00038 { 00039 Module_Class_Members(MACRelayUnitBase,cSimpleModule,0); 00040 00041 protected: 00042 // An entry of the Address Lookup Table 00043 struct AddressEntry 00044 { 00045 int portno; // Input port 00046 double insertionTime; // Arrival time of Lookup Address Table entry 00047 }; 00048 00049 struct MAC_compare 00050 { 00051 bool operator()(const MACAddress& u1, const MACAddress& u2) const 00052 {return u1.compareTo(u2) < 0;} 00053 }; 00054 00055 typedef std::map<MACAddress, AddressEntry, MAC_compare> AddressTable; 00056 00057 // Parameters controlling how the switch operates 00058 int numPorts; // Number of ports of the switch 00059 int addressTableSize; // Size of the Address Table 00060 simtime_t agingTime; // Determines when Ethernet entries are to be removed 00061 00062 AddressTable addresstable; // Address Lookup Table 00063 00064 int seqNum; // counter for PAUSE frames 00065 00066 protected: 00070 void initialize(); 00071 00079 void handleAndDispatchFrame(EtherFrame *frame, int inputport); 00080 00085 void broadcastFrame(EtherFrame *frame, int inputport); 00086 00090 void readAddressTable(const char* fileName); 00091 00095 void updateTableWithAddress(MACAddress& address, int portno); 00096 00100 int getPortForAddress(MACAddress& address); 00101 00105 void printAddressTable(); 00106 00110 void removeAgedEntriesFromTable(); 00111 00115 void removeOldestTableEntry(); 00116 00121 void sendPauseFrame(int portno, int pauseUnits); 00122 00123 }; 00124 00125 #endif 00126 00127
1.2.17