#include <TMBoost.h>
Public Member Functions | |
TMBoost () | |
virtual | ~TMBoost () |
virtual void | handleUpdate (TMPacket *pkt) |
virtual void | write2gml (string fname) |
virtual void | handleLinkStateUpdate (LSMPacket *pkt) |
virtual void | calcFIDsFromTM_2_Nodes () |
virtual void | handleMetaDataUpdate (MetaDataPacket *pkt) |
DUMMY. | |
Protected Member Functions | |
virtual void | initialize (int stage) |
virtual int | numInitStages () const |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
virtual void | initializeGraph () |
virtual Vertex | getVertex (string nodeid) |
virtual bool | vertexExists (string nodeid) |
virtual Edge | getEdge (string lid, bool &found) |
virtual string | getFIDFromBoostResult_rec (Vertex src, Vertex dst, vector< Vertex > pre) |
Protected Attributes | |
GraphWrapper< VertexProp, EdgeProp > | g |
Private Types | |
typedef GraphWrapper < VertexProp, EdgeProp > ::Vertex | Vertex |
typedef GraphWrapper < VertexProp, EdgeProp >::Edge | Edge |
typedef GraphWrapper < VertexProp, EdgeProp > ::EdgePair | EdgePair |
typedef GraphWrapper < VertexProp, EdgeProp > ::Graph | Graph |
A Dummy Boost Topology Manager Application. Assigns all the subscribers to the first publisher available.
typedef GraphWrapper<VertexProp,EdgeProp>::Edge TMBoost::Edge [private] |
typedef GraphWrapper<VertexProp,EdgeProp>::EdgePair TMBoost::EdgePair [private] |
typedef GraphWrapper<VertexProp,EdgeProp>::Graph TMBoost::Graph [private] |
typedef GraphWrapper<VertexProp,EdgeProp>::Vertex TMBoost::Vertex [private] |
TMBoost::~TMBoost | ( | ) | [virtual] |
void TMBoost::calcFIDsFromTM_2_Nodes | ( | ) | [virtual] |
Calculates the FID from the Topology Manager to every node of the network according to the shortest path.
00272 { 00273 // predecessor_map 00274 std::vector<Vertex> p(g.getVertexCount()); 00275 // distance_map 00276 std::vector<double> d(g.getVertexCount()); 00277 00278 Vertex src = getVertex(myNodeId); 00279 00280 //XXX::The source is not the Topology manager in the simulation! Be carefull!!! 00281 dijkstra_shortest_paths(g.getGraph(), src, predecessor_map(&p[0]).distance_map(&d[0])); 00282 // For all nodes - update! 00283 for (TMtoNodes::iterator it = tm2nodes.begin(); it!=tm2nodes.end(); ++it){ 00284 00285 Vertex dst = getVertex(it->first); 00286 it->second = lidOR(getFIDFromBoostResult_rec(src, dst, p), getNodeInternalLID(it->first)); 00287 } 00288 // WoW Easier than it sounds! 00289 }
void TMBoost::finish | ( | ) | [protected, virtual] |
The finish function of the Boost Topology Manager.
Reimplemented from TMInterface.
00039 { 00040 TMInterface::finish(); 00041 00042 //Clear Graph 00043 g.clear(); 00044 }
TMBoost::Edge TMBoost::getEdge | ( | string | lid, | |
bool & | found | |||
) | [protected, virtual] |
Get an edge based on the LID...
00124 { 00125 GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend; 00126 for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) { 00127 if (g.properties(*ei).lid.compare(lid)==0) { 00128 found=true; 00129 return *ei; 00130 } 00131 } 00132 found=false; 00133 // ? 00134 return Edge(); 00135 }
string TMBoost::getFIDFromBoostResult_rec | ( | Vertex | src, | |
Vertex | dst, | |||
vector< Vertex > | pre | |||
) | [protected, virtual] |
Visit the predecessor map and calculate FID for a single destination/sub. RECURSIVE
00155 { 00156 00157 Vertex pre_v = pre[dst]; 00158 00159 // Terminal Condition! Add node it 00160 if (dst == src) return ""; 00161 00162 // Get the edge for pre_v - dst. NOT THE OPPOSITE! 00163 std::pair<Edge, bool> edge_res= g.getEdge(pre_v,dst); 00164 if (edge_res.second == false){ 00165 opp_error("*** NO EDGE FOR pre_v - dst: Check topology initializer, THIS SHOULD NEVER HAPPEN"); 00166 return ""; 00167 } 00168 00169 Edge e = edge_res.first; 00170 00171 // Get all the previous recursively 00172 string newfid=getFIDFromBoostResult_rec(src,pre_v,pre); 00173 00174 newfid=lidOR(newfid,g.properties(e).lid); 00175 00176 return newfid; 00177 }
TMBoost::Vertex TMBoost::getVertex | ( | string | nodeid | ) | [protected, virtual] |
Get a vertex by nodeid, it returns UINT_MAX in case that the vertex is not found!
00112 { 00113 00114 GraphWrapper<VertexProp,EdgeProp>::vertex_iterator vi, vend; 00115 for (tie(vi, vend) = g.getVertices(); vi != vend; ++vi) { 00116 if (g.properties(*vi).nodeid.compare(nodeid)==0) return *vi; 00117 } 00118 00119 return UINT_MAX; 00120 00121 }
void TMBoost::handleLinkStateUpdate | ( | LSMPacket * | pkt | ) | [virtual] |
Handles the packets carrying link state status information. -- DUMMY
Implements TMInterface.
00292 { 00293 ev << " - TMBoost::handleLinkStateUpdate" << endl; 00294 00295 int replen = pkt->getRepLen(); 00296 bool found=false; 00297 for (int i=0; i<replen; i++){ 00298 Edge e = getEdge(pkt->getLid(i),found); 00299 if (!found){ 00300 cerr<<"TMBoost: LID NOT FOUND!: "<<pkt->getLid(i)<<endl; 00301 continue; 00302 } 00303 g.properties(e).status = pkt->getLinkStatus(i); 00304 } 00305 00306 //write2gml("/tmp/top.graphml"); 00307 }
void TMBoost::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Handles the messages sent by the Information Item Table module, as well as self messages.
Reimplemented from TMInterface.
00061 { 00062 ev << "Message received!!!" << endl; 00063 00064 //If this message is a Topology manager message 00065 if(TMPacket *tmmsg=dynamic_cast<TMPacket *>(msg)) { 00066 ev << "It's a link status update from " << tmmsg->getSenderModule()->getName() << endl; 00067 handleUpdate(tmmsg); 00068 } 00069 else if(LSMPacket *lsmmsg=dynamic_cast<LSMPacket *>(msg)) { 00070 ev << "It's a link status update from " << lsmmsg->getSenderModule()->getName() << endl; 00071 handleLinkStateUpdate(lsmmsg); 00072 } 00073 00074 delete msg; 00075 }
virtual void TMBoost::handleMetaDataUpdate | ( | MetaDataPacket * | pkt | ) | [inline, virtual] |
void TMBoost::handleUpdate | ( | TMPacket * | pkt | ) | [virtual] |
Handle packet function for Click Modular Router. Called by the handleMessage() function of the Omnet++ module.
Implements TMInterface.
00185 { 00186 00187 ev << " - TMBoost::handleUpdate" << endl; 00188 00189 //Update the Information Items in the Topology Manager 00190 updateInformationItems(pkt); 00191 00192 // Search all the IIems and run alg. for the changed 00193 for (InfoItems::iterator it = ii.begin(); it!=ii.end(); ++it){ 00194 00195 ev << " - Checking: " << it->first << " status: " << it->second.ii_updated << endl; 00196 // Not changed... continue 00197 if (!it->second.ii_updated) continue; 00198 00199 IIDetails *itd = &it->second; 00200 // Check that we have publishers 00201 if (itd->pubs.size() == 0){ 00202 ev << " - SHIT: No Publishers for item " << it->first << "???" << endl; 00203 ev << " - What should i do??? " << endl; 00204 itd->ii_updated = false; 00205 //itd->fid_updated = false; 00206 continue; 00207 } 00208 00209 // Check that we have subscribers 00210 if (itd->subs.size() == 0){ 00211 ev << " - No Subscribers for item " << it->first << endl; 00212 // Cancel the transmission 00213 itd->ii_updated = false; 00214 //itd->fid_updated = true; 00215 // Clear fids for all publishers of the Information Item 00216 for(uint i=0;i<itd->pubs.size();i++) { 00217 itd->pubs[i].fid = ""; 00218 itd->pubs[i].fid_updated = true; 00219 } 00220 continue; 00221 } 00222 00223 // Here we take the 1st publisher! Optimazation could be done! 00224 Vertex src = getVertex(itd->pubs[0].pub); 00225 00226 // Sanity Check 00227 if (src == UINT_MAX){ 00228 opp_error("*** What THE HELL: Check your topology parser, NO VERTEX FOR PUBLISHER ??? "); 00229 continue; 00230 } 00231 00232 // Yay... Do the job... 00233 // predecessor_map 00234 std::vector<Vertex> p(g.getVertexCount()); 00235 // distance_map 00236 std::vector<double> d(g.getVertexCount()); 00237 00238 // THE JOB 00239 ev << " - Going for item " << it->first << " published from vertex " << src << endl; 00240 dijkstra_shortest_paths(g.getGraph(), src, predecessor_map(&p[0]).distance_map(&d[0])); 00241 00242 // Clear fids for all publishers of the Information Item 00243 for(uint i=0;i<itd->pubs.size();i++) 00244 itd->pubs[i].fid = ""; 00245 00246 // Make the fid for ALL subscribers 00247 for (uint i=0; i<itd->subs.size(); ++i){ 00248 Vertex dst = getVertex(itd->subs[i]); 00249 // Get FID src to dst 00250 itd->pubs[0].fid = lidOR(itd->pubs[0].fid, getFIDFromBoostResult_rec(src, dst, p)); 00251 // Add the dst node internal LID! is needed 00252 itd->pubs[0].fid = lidOR(itd->pubs[0].fid, getNodeInternalLID(itd->subs[i])); 00253 00254 //Update the fid_update flag for the selected publisher 00255 itd->pubs[0].fid_updated = true; 00256 } 00257 00258 // Update Flags 00259 //itd->fid_updated = true; // NEWFID 00260 itd->ii_updated = false; // UNMODIFIED SINCE LAST RUN 00261 00262 ev << " - FID Found " << src << ": " << it->second.pubs[0].fid << endl; 00263 00264 } 00265 00266 // Here we should be done! Update all the publishers with new FIDs 00267 updateAllThePublishers(); 00268 00269 }
void TMBoost::initialize | ( | int | stage | ) | [protected, virtual] |
Initialization function
Reimplemented from TMInterface.
00047 { 00048 00049 TMInterface::initialize(stage); 00050 00051 //The TMInterace Initialized at stage 2. To be safe 00052 //let's initialize on stage later. 00053 if(stage==3) { 00054 // At this stage the Topology Manager configuration is fed to Boost++ 00055 initializeGraph(); 00056 //write2gml("InitialGraph.gml"); 00057 } 00058 }
void TMBoost::initializeGraph | ( | ) | [protected, virtual] |
Initialize BGraph from topology
00081 { 00082 00083 for (uint i=0; i<topology.size(); ++i){ 00084 // Check n Add source 00085 Vertex src = getVertex(topology[i].src); 00086 if (src == UINT_MAX){ 00087 VertexProp vp; 00088 vp.nodeid=topology[i].src; 00089 src=g.addVertex(vp); 00090 } 00091 00092 // Check n Add destination 00093 Vertex dst = getVertex(topology[i].dst); 00094 if (dst == UINT_MAX){ 00095 VertexProp vp; 00096 vp.nodeid=topology[i].dst; 00097 dst=g.addVertex(vp); 00098 } 00099 00100 // NOTE: Avoid LOOPs !! 00101 if (dst==src) continue; 00102 00103 // Add edge 00104 EdgeProp ep; 00105 ep.weight = 1; // FIXME:TODO Initial weight! 00106 ep.lid = topology[i].lid; 00107 g.addEdge(src,dst,ep); 00108 } 00109 }
virtual int TMBoost::numInitStages | ( | ) | const [inline, protected, virtual] |
bool TMBoost::vertexExists | ( | string | nodeid | ) | [protected, virtual] |
Check that a vertex exists by nodeid
00138 { 00139 return (!getVertex(nodeid) == UINT_MAX); 00140 }
void TMBoost::write2gml | ( | string | fname | ) | [virtual] |
Extracts the network graph in a xml format, proving the ability of monitoring the network on runtime.
00310 { 00311 // Chinese Language with mixed Greek follows! 00312 std::ofstream fout(fname.c_str()); 00313 if (!fout) return; 00314 00315 string top="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> \n\ 00316 <graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:y=\"http://www.yworks.com/xml/graphml\" xmlns:yed=\"http://www.yworks.com/xml/yed/3\" xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd\"> \n\ 00317 <key id=\"key0\" for=\"node\" attr.name=\"id\" attr.type=\"string\" />\n\ 00318 <key id=\"key1\" for=\"edge\" attr.name=\"weight\" attr.type=\"int\" /> \n\ 00319 <key id=\"key2\" for=\"edge\" attr.name=\"lid\" attr.type=\"string\" />\n\ 00320 <key for=\"edge\" id=\"d12\" yfiles.type=\"edgegraphics\"/> \n\ 00321 <key for=\"node\" id=\"d7\" yfiles.type=\"nodegraphics\"/>\n\ 00322 <graph id=\"G\" edgedefault=\"directed\" parse.nodeids=\"canonical\" parse.edgeids=\"canonical\" parse.order=\"nodesfirst\">\n"; 00323 00324 fout.write(top.c_str(), top.length()); 00325 00326 GraphWrapper<VertexProp,EdgeProp>::vertex_iterator vi, vend; 00327 for (tie(vi, vend) = g.getVertices(); vi != vend; ++vi) { 00328 VertexProp p = g.properties(*vi); 00329 string nodestr="<node id=\""+p.nodeid+"\">\n"; 00330 nodestr+=" <data key=\"key0\">"+p.nodeid+"</data>\n"; 00331 nodestr+=" <data key=\"d7\">\n\ 00332 <y:GenericNode configuration=\"ShinyPlateNode\">\n\ 00333 <y:NodeLabel alignment=\"center\" autoSizePolicy=\"content\" fontFamily=\"Dialog\" fontSize=\"12\" fontStyle=\"plain\" hasBackgroundColor=\"false\" hasLineColor=\"false\" height=\"4.0\" modelName=\"internal\" modelPosition=\"s\" textColor=\"#000000\" visible=\"true\" width=\"4.0\" >"+p.nodeid+"</y:NodeLabel>\n\ 00334 </y:GenericNode>\n\ 00335 </data>\n"; 00336 nodestr+="</node>\n"; 00337 00338 fout.write(nodestr.c_str(), nodestr.length()); 00339 } 00340 00341 int count=0; 00342 GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend; 00343 for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) { 00344 EdgeProp p = g.properties(*ei); 00345 stringstream ss; 00346 ss<<"e"<<count; 00347 count++; 00348 string lid=chararray_to_bin(p.lid); 00349 00350 string edgestr = "<edge id=\""+ss.str()+"\" source=\""+g.getSourceProp(*ei).nodeid+ 00351 "\" target=\""+g.getTargetProp(*ei).nodeid+"\">\n"; 00352 ss.clear(); 00353 ss.str(std::string()); 00354 ss<<p.weight; 00355 edgestr += " <data key=\"key1\">"+ss.str()+"</data>\n"; 00356 edgestr += " <data key=\"key2\">"+lid+"</data>\n"; 00357 edgestr+=" <data key=\"d12\">\n\ 00358 <y:PolyLineEdge>\n\ 00359 <y:Arrows source=\"none\" target=\"delta\"/>\n\ 00360 </y:PolyLineEdge>\n\ 00361 </data>\n"; 00362 edgestr += "</edge>\n"; 00363 fout.write(edgestr.c_str(), edgestr.length()); 00364 } 00365 00366 string bottom=" </graph>\n</graphml>"; 00367 fout.write(bottom.c_str(), bottom.length()); 00368 fout.close(); 00369 }
GraphWrapper<VertexProp, EdgeProp> TMBoost::g [protected] |