|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // (C) 2005 Vojtech Janota 00003 // (C) 2003 Xuan Thang Nguyen 00004 // 00005 // This library is free software, you can redistribute it 00006 // and/or modify 00007 // it under the terms of the GNU Lesser General Public License 00008 // as published by the Free Software Foundation; 00009 // either version 2 of the License, or any later version. 00010 // The library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00013 // See the GNU Lesser General Public License for more details. 00014 // 00015 00016 #ifndef __INET_LIBTABLE_H 00017 #define __INET_LIBTABLE_H 00018 00019 #include <omnetpp.h> 00020 #include <vector> 00021 #include <string> 00022 #include "ConstType.h" 00023 #include "IPAddress.h" 00024 #include "IPDatagram.h" 00025 00026 // label operations 00027 #define PUSH_OPER 0 00028 #define SWAP_OPER 1 00029 #define POP_OPER 2 00030 00034 struct LabelOp 00035 { 00036 int label; 00037 int optcode; 00038 }; 00039 00040 typedef std::vector<LabelOp> LabelOpVector; 00041 00045 class INET_API LIBTable: public cSimpleModule 00046 { 00047 public: 00048 struct LIBEntry 00049 { 00050 int inLabel; 00051 std::string inInterface; 00052 00053 LabelOpVector outLabel; 00054 std::string outInterface; 00055 00056 // FIXME colors in nam, temporary solution 00057 int color; 00058 }; 00059 00060 protected: 00061 IPAddress routerId; 00062 int maxLabel; 00063 std::vector<LIBEntry> lib; 00064 00065 protected: 00066 virtual void initialize(int stage); 00067 virtual int numInitStages() const {return 5;} 00068 virtual void handleMessage(cMessage *msg); 00069 00070 // static configuration 00071 virtual void readTableFromXML(const cXMLElement* libtable); 00072 00073 public: 00074 // label management 00075 virtual bool resolveLabel(std::string inInterface, int inLabel, 00076 LabelOpVector& outLabel, std::string& outInterface, int& color); 00077 00078 virtual int installLibEntry(int inLabel, std::string inInterface, const LabelOpVector& outLabel, 00079 std::string outInterface, int color); 00080 00081 virtual void removeLibEntry(int inLabel); 00082 00083 // utility 00084 static LabelOpVector pushLabel(int label); 00085 static LabelOpVector swapLabel(int label); 00086 static LabelOpVector popLabel(); 00087 }; 00088 00089 std::ostream & operator<<(std::ostream & os, const LIBTable::LIBEntry & lib); 00090 std::ostream & operator<<(std::ostream & os, const LabelOpVector& label); 00091 00092 #endif 00093