INET Framework for OMNeT++/OMNEST
portTable.cc
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 #include "portTable.h"
00017 
00018 Define_Module(PortTable);
00019 
00020 
00021 /* PUBLIC ACCESS */
00022 
00023 PortTable::tPort PortTable::getPort(int port) {
00024         Enter_Method_Silent();
00025         if (port < 0 || port >= portCount) {
00026                 error("PortTable: exceeded portTable limit in getPort() / getState()");
00027         }
00028 
00029         return list.at(port);
00030 
00031 }
00032 PortTable::tPortState PortTable::getState(int port) {
00033         Enter_Method_Silent();
00034         return getPort(port).state;
00035 }
00036 
00037 /* STP PROCESS MANIPULATION */
00038 void PortTable::setState(int port, PortTable::tPortState state) {
00039         Enter_Method_Silent();
00040         if (port < 0 || port >= portCount) {
00041                 error("PortTable: exceeded portTable limit in setState()");
00042         }
00043         list.at(port).state = state;
00044 
00045         return;
00046 }
00047 
00048 void PortTable::setState(std::vector<int>& pList, PortTable::tPortState state) {
00049         Enter_Method_Silent();
00050         for (unsigned int i = 0; i < pList.size(); i++) {
00051                 setState(pList.at(i), state);
00052         }
00053         return;
00054 }
00055 
00056 void PortTable::allState(PortTable::tPortState state) {
00057         Enter_Method_Silent();
00058         for (unsigned int i = 0; i < (unsigned int)portCount; i++) {
00059                 setState(i, state);
00060         }
00061         return;
00062 }
00063 
00064 void PortTable::allOff() {
00065         Enter_Method_Silent();
00066         allState(OFF);
00067         return;
00068 }
00069 
00070 void PortTable::off(std::vector<int>& pList) {
00071         Enter_Method_Silent();
00072                 setState(pList, OFF);
00073 
00074         return;
00075 }
00076 
00077 void PortTable::forwarding(std::vector<int>& pList) {
00078         Enter_Method_Silent();
00079                 setState(pList, FORWARDING);
00080 
00081         return;
00082 }
00083 
00084 
00085 /* -- private -- */
00086 
00087 void PortTable::initDefault() {
00088         tPort tmp;
00089         tmp.state = FORWARDING;
00090         list.insert(list.begin(), portCount, tmp);
00091         return;
00092 }
00093 
00094 /* -- protected --*/
00095 
00096 void PortTable::initialize()
00097 {
00098         portCount = par("portCount");
00099 
00100         initDefault();
00101 
00102         WATCH_VECTOR(list);
00103         return;
00104 }
00105 
00106 void PortTable::handleMessage(cMessage *msg)
00107 {
00108 
00109 }
00110