INET Framework for OMNeT++/OMNEST
portTable.h
Go to the documentation of this file.
00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 //
00015 
00016 #ifndef __PORTTABLE_H__
00017 #define __PORTTABLE_H__
00018 
00019 #include <omnetpp.h>
00020 #include <vector>
00021 
00022 class PortTable : public cSimpleModule
00023 {
00024   public:
00025 
00026           typedef enum e_port_state {
00027                   OFF = 0,
00028                   BLOCKING = 1,
00029                   DISCARTING = 2,
00030                   LEARNING = 3,
00031                   FORWARDING = 4,
00032           } tPortState;
00033 
00034           typedef struct s_port {
00035                   tPortState state;
00036           } tPort;
00037 
00038           typedef std::vector<tPort> tPortList;
00039 
00040           /* PUBLIC ACCESS */
00041 
00042           tPort getPort(int);
00043           tPortState getState(int);
00044 
00045           /* STP PROCESS MANIPULATION */
00046           void setState(int, tPortState);
00047           void setState(std::vector<int>&, tPortState);
00048           void allState(tPortState);
00049           void allOff();
00050           void off(std::vector<int>&);
00051           void forwarding(std::vector<int>&);
00052 
00053 
00054   private:
00055           int portCount;
00056           tPortList list;
00057 
00058           void initDefault();
00059 
00060   protected:
00061     virtual void initialize();
00062     virtual void handleMessage(cMessage *msg);
00063 
00064 
00065 };
00066 
00067 inline std::ostream& operator<<(std::ostream& os, const PortTable::tPortState s) {
00068 
00069         switch (s){
00070         case PortTable::OFF:
00071                 os << "OFF";
00072                 break;
00073         case PortTable::BLOCKING:
00074                 os << "BLOCKING";
00075                 break;
00076         case PortTable::DISCARTING:
00077                 os << "DISCARTING";
00078                 break;
00079         case PortTable::LEARNING:
00080                 os << "LEARNING";
00081                 break;
00082         case PortTable::FORWARDING:
00083                 os << "FORWARDING";
00084                 break;
00085         default:
00086                 os << "<???>";
00087                 break;
00088         }
00089 
00090         return os;
00091 }
00092 
00093 inline std::ostream& operator<<(std::ostream& os, const PortTable::tPort p) {
00094         os << "PortState: " << p.state;
00095         return os;
00096 }
00097 
00098 #endif