MACRelayUnitBase.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Andras Varga; CTIE, Monash University, Australia
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 
00019 #ifndef __INET_MACRELAYUNITBASE_H
00020 #define __INET_MACRELAYUNITBASE_H
00021 
00022 #include <omnetpp.h>
00023 #include <map>
00024 #include <string>
00025 #include "MACAddress.h"
00026 
00027 class EtherFrame;
00028 
00029 
00036 class INET_API MACRelayUnitBase : public cSimpleModule
00037 {
00038   public:
00039     // An entry of the Address Lookup Table
00040     struct AddressEntry
00041     {
00042         int portno;              // Input port
00043         simtime_t insertionTime; // Arrival time of Lookup Address Table entry
00044     };
00045 
00046   protected:
00047     struct MAC_compare
00048     {
00049         bool operator()(const MACAddress& u1, const MACAddress& u2) const
00050             {return u1.compareTo(u2) < 0;}
00051     };
00052 
00053     typedef std::map<MACAddress, AddressEntry, MAC_compare> AddressTable;
00054 
00055     // Parameters controlling how the switch operates
00056     int numPorts;               // Number of ports of the switch
00057     int addressTableSize;       // Maximum size of the Address Table
00058     simtime_t agingTime;        // Determines when Ethernet entries are to be removed
00059 
00060     AddressTable addresstable;  // Address Lookup Table
00061 
00062     int seqNum;                 // counter for PAUSE frames
00063 
00064   protected:
00068     virtual void initialize();
00069 
00077     virtual void handleAndDispatchFrame(EtherFrame *frame, int inputport);
00078 
00083     virtual void broadcastFrame(EtherFrame *frame, int inputport);
00084 
00088     virtual void readAddressTable(const char* fileName);
00089 
00093     virtual void updateTableWithAddress(MACAddress& address, int portno);
00094 
00098     virtual int getPortForAddress(MACAddress& address);
00099 
00103     virtual void printAddressTable();
00104 
00108     virtual void removeAgedEntriesFromTable();
00109 
00113     virtual void removeOldestTableEntry();
00114 
00119     virtual void sendPauseFrame(int portno, int pauseUnits);
00120 
00121 };
00122 
00123 #endif
00124 
00125