|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 20 Martin Danko 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 #ifndef CRITICALNESSANALYZER_H 00020 #define CRITICALNESSANALYZER_H 00021 00022 #include <omnetpp.h> 00023 #include <fstream> 00024 00025 00026 namespace CA { 00027 00028 class NeighborRecord { 00029 std::string name; 00030 double cost; 00031 public: 00032 NeighborRecord() {name = ""; cost = 0.0;} 00033 NeighborRecord(std::string n_name, double n_cost) {name = n_name; cost = n_cost;} 00034 00035 std::string getName() {return name;} 00036 void setName(std::string n_name) {name = n_name;} 00037 00038 double getCost() {return cost;} 00039 void setCost(double n_cost) {cost = n_cost;} 00040 00041 }; 00042 00043 class RouterRecord { 00044 00045 private: 00046 cModule *pModule; 00047 std::string name; 00048 00049 std::vector<NeighborRecord> neighbors; 00050 00051 int criticalness; 00052 00053 00054 public: 00055 RouterRecord() {name = ""; neighbors.clear(); criticalness = 0; pModule = NULL;} 00056 RouterRecord(std::string n_name, cModule *mod) {name = n_name; neighbors.clear(); criticalness = 0; pModule = mod;} 00057 00058 cModule *getModule() {return pModule;} 00059 00060 std::string getName() {return name;} 00061 void setName(std::string n_name) {name = n_name;} 00062 00063 int getCriticalness() {return criticalness;} 00064 void setCriticalness(int n_criticalness) {criticalness = n_criticalness;} 00065 00066 int getNeighborsNum() {return neighbors.size();} 00067 NeighborRecord getNeighbor(int i) {return neighbors.at(i);} 00068 void addNeighbor(NeighborRecord &n_neighbor) {neighbors.push_back(n_neighbor);} 00069 }; 00070 00071 inline std::ostream& operator<< (std::ostream& ostr, RouterRecord& rec) 00072 { 00073 ostr << rec.getName() << " ... " ; 00074 ostr << " Criticalness: " << rec.getCriticalness() << "%"; 00075 00076 if(rec.getCriticalness() == 100) 00077 ostr << " this node is Critical Point"; 00078 if(rec.getCriticalness() == 0) 00079 ostr << " this node is Universal Point"; 00080 00081 return ostr; 00082 } 00083 00084 00085 class Path { 00086 00087 private: 00088 std::vector<std::string> path; 00089 00090 double cost; 00091 00092 public: 00093 Path() {path.clear(); cost = 0.0; } 00094 00095 00096 double getCost() {return cost;} 00097 void setCost(double n_cost) {cost = n_cost;} 00098 00099 std::vector<std::string> &getPath() {return path;} 00100 void addNode(std::string &node, double n_cost) {path.push_back(node); cost += n_cost;} 00101 void removeLastNode() {path.pop_back();} 00102 bool isInPath(std::string &node); 00103 00104 00105 }; 00106 00107 inline std::ostream& operator<< (std::ostream& ostr, Path& path) 00108 { 00109 ostr << "Cost: " << path.getCost() << " Path: "; 00110 std::vector<std::string> tp = path.getPath(); 00111 00112 for (std::vector<std::string>::iterator it = tp.begin(); it!=tp.end(); ++it) 00113 { 00114 if(it == tp.begin()) 00115 ostr << *it; 00116 else 00117 ostr << " -> "<< *it; 00118 } 00119 return ostr; 00120 } 00121 00122 } 00123 00124 00125 class CriticalnessAnalyzer : public cSimpleModule 00126 { 00127 private: 00128 00129 std::string startNode; 00130 std::string destNode; 00131 00132 bool analyze; 00133 00134 std::vector<CA::RouterRecord> routers; 00135 00136 CA::Path tempPath; 00137 std::vector<CA::Path> paths; 00138 00139 protected: 00140 00141 virtual void initialize(); 00142 virtual void handleMessage(cMessage *msg); 00143 00144 00145 public: 00146 00147 std::vector<CA::RouterRecord>::iterator getRouterRecord(std::string &name); 00148 void generatePaths(std::string &name); 00149 void sortByCost(); 00150 void calculateCriticalness(); 00151 bool existRouter(std::string &name); 00152 void updateDisplayString(); 00153 void writeResultsToFile(); 00154 00155 00156 }; 00157 00158 #endif