TMBoostDD Class Reference

#include <TMBoostDD.h>

Inheritance diagram for TMBoostDD:
TMInterface cSimpleModule cModule cComponent cDefaultList cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

List of all members.

Public Member Functions

 TMBoostDD ()
virtual ~TMBoostDD ()
virtual void handleUpdate (TMPacket *pkt)
virtual void write2gml (string fname)
virtual void handleLinkStateUpdate (LSMPacket *pkt)
virtual void handleMetaDataUpdate (MetaDataPacket *pkt)
virtual void calcFIDsFromTM_2_Nodes ()
bool getReverseEdge (Edge e, Edge &rev)

Protected Member Functions

virtual void initialize (int stage)
virtual int numInitStages () const
virtual void finish ()
virtual void initializeGraph ()
virtual Vertex getVertex (string nodeid)
virtual bool vertexExists (string nodeid)
virtual Edge getEdge (string lid, bool &found)
virtual bool setEdgeWeights (string IIID)
virtual string getFIDFromBoostResult_rec (Vertex src, Vertex dst, vector< Vertex > pre)
virtual vector< string > getPathFromBoostResult_rec (Vertex src, Vertex dst, vector< Vertex > pre)
virtual string getFIDFromPath (vector< string > path)
virtual double getWeightFromBoostResult_rec (Vertex src, Vertex dst, vector< Vertex > pre)
virtual void eliminateWeights_rec (Vertex src, Vertex dst, vector< Vertex > pre, InfoItems::iterator it)
virtual void pathCalculation ()

Protected Attributes

GraphWrapper< VertexProp,
EdgeProp
g
 The graph representation.
weightMap weightmap
 I don't think it is used in this version.

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
typedef property_map< Graph,
edge_weight_t >::type 
weightMap
typedef std::vector< Vertexpredecessormap
typedef std::vector< double > distancemap

Detailed Description

Extended Boost Topology Manager Application. Performs a Destination-Driven shortest path calculation and assigned each Subscriber to the closest Publisher.


Member Typedef Documentation

typedef std::vector<double> TMBoostDD::distancemap [private]
typedef std::vector<Vertex> TMBoostDD::predecessormap [private]
typedef property_map<Graph, edge_weight_t>::type TMBoostDD::weightMap [private]

Constructor & Destructor Documentation

TMBoostDD::TMBoostDD (  ) 

Boost Topology Manager Interface class constructor.

00027 {
00028 
00029 }

TMBoostDD::~TMBoostDD (  )  [virtual]

Boost Topology Manager Interface class destructor.

00033 {
00034 
00035 }


Member Function Documentation

void TMBoostDD::calcFIDsFromTM_2_Nodes (  )  [virtual]

Calculates the FID from the Topology Manager to every node of the network according to the shortest path.

00429                                       {
00430   // predecessor_map
00431   std::vector<Vertex> p(g.getVertexCount());
00432   // distance_map
00433   std::vector<double> d(g.getVertexCount());
00434 
00435   Vertex src = getVertex(myNodeId);
00436 
00437   //XXX::The Topology manager is not path of the network in the simulation! Be carefull!!!
00438   dijkstra_shortest_paths(g.getGraph(), src, predecessor_map(&p[0]).distance_map(&d[0]));
00439   // For all nodes - update!
00440   for (TMtoNodes::iterator it = tm2nodes.begin(); it!=tm2nodes.end(); ++it){
00441     
00442     Vertex dst = getVertex(it->first);
00443     it->second = lidOR(getFIDFromBoostResult_rec(src, dst, p), getNodeInternalLID(it->first));
00444   }
00445   // WoW Easier than it sounds!
00446 }

void TMBoostDD::eliminateWeights_rec ( Vertex  src,
Vertex  dst,
vector< Vertex pre,
InfoItems::iterator  it 
) [protected, virtual]

Visit the predecessor map and turn the weights of the shortest path links to zero. RECURSIVE

00470                                                                                                      {
00471         Vertex pre_v = pre[dst];
00472 
00473         // Terminal Condition! Add node it
00474         if (dst == src) return;
00475 
00476         // Get the edge for pre_v - dst. NOT THE OPPOSITE!
00477         std::pair<Edge, bool> edge_res= g.getEdge(pre_v,dst);
00478         if (edge_res.second == false){
00479                 opp_error("*** NO EDGE FOR pre_v - dst: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00480                 return;
00481         }
00482 
00483         //Get the edge
00484         Edge e = edge_res.first;
00485 
00486         //std::cout << "Link " << g.properties(revedge.first.m_source).nodeid << "-" << g.properties(revedge.first.m_target).nodeid << " has rate " << g.properties(revedge.first).status[QoS_USEDRATE] << " with weight " << g.properties(e).weight << endl;
00487 
00488         //Check if the information item already passes from this link
00489         if(g.properties(e).weight!=0) {
00490                 //Assign the link to zero, for future subscribers to use
00491                 g.properties(e).weight=0;
00492 
00493                 //Get the reverse edge
00494                 Edge rev;
00495                 if(!getReverseEdge(e,rev))
00496                         return;
00497 
00498                 //Assign the selected link with the additional traffic of the new flow if not already assigned
00499                 QoSList param = g.properties(rev).status;
00500 
00501                 //If the necessary parameters exist
00502                 if( param.find(QoS_USEDRATE)!=param.end() && it->second.metadata.find(QoS_BW_M)!=it->second.metadata.end() ) {
00503                         //Add the expected bitrate of the newly assigned Information Item, to the link's used rate
00504                         //std::cout << "Link " << g.properties(edge_rev.first.m_source).nodeid << "-" << g.properties(edge_rev.first.m_target).nodeid << " has rate " << param.find(QoS_USEDRATE)->second << endl;
00505                         g.properties(rev).status[QoS_USEDRATE] += it->second.metadata.find(QoS_BW_M)->second;
00506                         //std::cout << "Now it has rate: " << g.properties(edge_rev.first).status[QoS_USEDRATE] << " with QoS_BW_M " << it->second.metadata.find(QoS_BW_M)->second << endl;
00507                 }
00508                 else {
00509                         //Else print a warning
00510                         ev << "*** TM WARNING: QoS_USEDRATE/QoS_BW_M parameters not available in link weight assignment of routing calculation process." << endl;
00511                 }
00512         }
00513 
00514         // Get all the previous recursively
00515         eliminateWeights_rec(src,pre_v,pre,it);
00516 }

void TMBoostDD::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 }

TMBoostDD::Edge TMBoostDD::getEdge ( string  lid,
bool &  found 
) [protected, virtual]

Get an edge based on the LID...

00110                                                         {
00111         GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend;
00112         for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) {
00113                 if (g.properties(*ei).lid.compare(lid)==0) {
00114                         found=true;
00115                         return *ei;
00116                 }
00117         }
00118         found=false;
00119         // ?
00120         return Edge();
00121 }

string TMBoostDD::getFIDFromBoostResult_rec ( Vertex  src,
Vertex  dst,
vector< Vertex pre 
) [protected, virtual]

Visit the predecessor map and calculate FID for a single destination/sub. RECURSIVE

00141                                                                                      {
00142  
00143         Vertex pre_v = pre[dst];
00144 
00145         // Terminal Condition! Add node it
00146         if (dst == src) return "";
00147 
00148         // Get the edge for pre_v - dst. NOT THE OPPOSITE!
00149         std::pair<Edge, bool> edge_res= g.getEdge(pre_v,dst);
00150         if (edge_res.second == false){
00151                 opp_error("*** NO EDGE FOR pre_v - dst: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00152         return "";
00153         }
00154 
00155         Edge e = edge_res.first;
00156 
00157         // Get all the previous recursively
00158         string newfid=getFIDFromBoostResult_rec(src,pre_v,pre);
00159 
00160         newfid=lidOR(newfid,g.properties(e).lid);
00161 
00162         return newfid;
00163 }

string TMBoostDD::getFIDFromPath ( vector< string >  path  )  [protected, virtual]

00166                                                     {
00167         //The variable to OR the various lids
00168         string newfid="";
00169 
00170         //For all elements of the path, calculate the FID
00171         for(uint i=0;i<path.size();i++) {
00172                 newfid=lidOR(newfid,path[i]);
00173         }
00174 
00175         return newfid;
00176 }

vector< string > TMBoostDD::getPathFromBoostResult_rec ( Vertex  src,
Vertex  dst,
vector< Vertex pre 
) [protected, virtual]

Visit the predecessor map and find out all the path lids. RECURSIVE

00179                                                                                                {
00180         //Find the next hop
00181         Vertex pre_v = pre[dst];
00182         //The variable to preserve the path lid so far found
00183         vector<string> path;
00184 
00185         // Terminal Condition! Add node it
00186         if (dst == src) return path;
00187 
00188         // Get the edge for pre_v - dst. NOT THE OPPOSITE!
00189         std::pair<Edge, bool> edge_res= g.getEdge(dst,pre_v);
00190         if (edge_res.second == false){
00191                 opp_error("*** NO EDGE FOR pre_v - dst: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00192                 return path;
00193         }
00194 
00195         Edge e = edge_res.first;
00196 
00197         // Get all the previous recursively
00198         path=getPathFromBoostResult_rec(src,pre_v,pre);
00199 
00200         path.push_back(g.properties(e).lid);
00201 
00202         return path;
00203 }

bool TMBoostDD::getReverseEdge ( Edge  e,
Edge rev 
)

Given a network link, it return the reverse one. Useful function because of the destination driven approach, followed in this algorithm.

00657                                                 {
00658         //Reverse the given edge's end points
00659         std::pair<Edge, bool> edge_res= g.getEdge(e.m_target,e.m_source);
00660 
00661         //Check if edge exists
00662         if (edge_res.second == false){
00663                 opp_error("*** NO EDGE FOUND WHILE REVERSING: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00664                 return false;
00665         }
00666 
00667         //Get the edge
00668         rev = edge_res.first;
00669 
00670         return true;
00671 }

TMBoostDD::Vertex TMBoostDD::getVertex ( string  nodeid  )  [protected, virtual]

Get a vertex by nodeid, it returns UINT_MAX in case that the vertex is not found!

00098                                                  {
00099 
00100         GraphWrapper<VertexProp,EdgeProp>::vertex_iterator vi, vend;
00101         for (tie(vi, vend) = g.getVertices(); vi != vend; ++vi) {
00102           if (g.properties(*vi).nodeid.compare(nodeid)==0) return *vi;
00103         }
00104 
00105         return UINT_MAX;
00106 
00107 }

double TMBoostDD::getWeightFromBoostResult_rec ( Vertex  src,
Vertex  dst,
vector< Vertex pre 
) [protected, virtual]

Visit the predecessor map and calculate path weight for a single destination/sub. RECURSIVE

00218                                                                                         {
00219 
00220         Vertex pre_v = pre[dst];
00221 
00222         // Terminal Condition! Add node it
00223         if (dst == src) return(0);
00224 
00225         // Get the edge for pre_v - dst. NOT THE OPPOSITE!
00226         std::pair<Edge, bool> edge_res= g.getEdge(pre_v,dst);
00227         if (edge_res.second == false){
00228                 opp_error("*** NO EDGE FOR pre_v - dst: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00229         return(0);
00230         }
00231 
00232         Edge e = edge_res.first;
00233 
00234         // Get all the previous recursively
00235         double weight=getWeightFromBoostResult_rec(src,pre_v,pre);
00236 
00237         weight+=g.properties(e).weight;
00238 
00239         return weight;
00240 }

void TMBoostDD::handleLinkStateUpdate ( LSMPacket pkt  )  [virtual]

Handles the packets carrying link state status information. -- DUMMY

Implements TMInterface.

00449                                                    {
00450   ev << " - TMBoostDD::handleLinkStateUpdate" << endl;
00451   
00452   int replen = pkt->getRepLen();
00453   bool found=false;
00454   for (int i=0; i<replen; i++){
00455     Edge e = getEdge(pkt->getLid(i),found);
00456     if (!found){
00457         opp_error("TMBoostDD: LID NOT FOUND!: ");
00458         continue;
00459     }
00460     g.properties(e).status = pkt->getLinkStatus(i);
00461   }
00462   
00463   //write2gml("/tmp/top.graphml");
00464 }

void TMBoostDD::handleMetaDataUpdate ( MetaDataPacket pkt  )  [virtual]

Handles the MetaData packets received directly from the publishers.

Implements TMInterface.

00590                                                         {
00591         updateInformationItemMetaData(pkt);
00592 }

void TMBoostDD::handleUpdate ( TMPacket pkt  )  [virtual]

Handle packet function for Click Modular Router. Called by the handleMessage() function of the Omnet++ module.

Implements TMInterface.

00246                                             {
00247   
00248   ev << " - TMBoostDD::handleUpdate" << endl;
00249 
00250   //Update the Information Items in the Topology Manager and return the Information Item ID in a hex form
00251   string hex_id = updateInformationItems(tmpkt);
00252 
00253   //Call the path calculation function for all changes Information Items
00254   // ------------------------------------- //
00255   // ----- PATH CALCULATION FUNCTION ----- //
00256   // ------------------------------------- //
00257   pathCalculation();
00258   // ------------------------------------- //
00259 
00260   // Here we should be done! Update all the publishers with new FIDs
00261   updateAllThePublishers();
00262 }

void TMBoostDD::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 TMBoostDD::initializeGraph (  )  [protected, virtual]

Initialize BGraph from topology

00064                                {
00065   
00066         for (uint i=0; i<topology.size(); ++i){
00067                 // Check n Add source
00068                 Vertex src = getVertex(topology[i].src);
00069                 if (src == UINT_MAX){
00070                         VertexProp vp;
00071                         vp.nodeid=topology[i].src;
00072                         src=g.addVertex(vp);
00073                 }
00074 
00075                 // Check n Add destination
00076                 Vertex dst = getVertex(topology[i].dst);
00077                 if (dst == UINT_MAX){
00078                         VertexProp vp;
00079                         vp.nodeid=topology[i].dst;
00080                         dst=g.addVertex(vp);
00081                 }
00082 
00083                 // NOTE: Avoid LOOPs !!
00084                 if (dst==src) continue;
00085 
00086                 // Add edge
00087                 EdgeProp ep;
00088                 ep.weight = 1; // FIXME:TODO Initial weight!
00089                 ep.lid = topology[i].lid;
00090                 g.addEdge(src,dst,ep);
00091         }
00092 
00093         //Setting the weights map
00094         weightmap = get(edge_weight, g.getGraph());
00095 }

virtual int TMBoostDD::numInitStages (  )  const [inline, protected, virtual]

Returns the number of initialization stages.

Reimplemented from TMInterface.

00074 {return 5;};

void TMBoostDD::pathCalculation (  )  [protected, virtual]

Call the path calculation function for the requested Information Item, as well as for all changed Information Items

00264                                 {
00265   //std::cout << endl << simTime() << endl;
00266   ev << " - TMBoostDD::pathCalculation" << endl;
00267 
00268   // Search all the IItems and run algorithm for the changed
00269   for (InfoItems::iterator it = ii.begin(); it!=ii.end(); ++it) {
00270     
00271     ev << "   - Checking: " << it->first << " status: " << it->second.ii_updated << endl;
00272     // Not changed... continue
00273     if (!it->second.ii_updated) continue;
00274 
00275     IIDetails  *itd = &it->second;
00276     // Check that we have publishers
00277     if (itd->pubs.size() == 0){
00278       ev << "   - SHIT: No Publishers for item " << it->first << "???" << endl;
00279       ev << "    - What should i do??? " << endl;
00280       itd->ii_updated = false;
00281       continue;
00282     }
00283     
00284     // Check that we have subscribers
00285     if (itd->subs.size() == 0){
00286       ev << "   - No Subscribers for item " << it->first << endl;
00287       // Cancel the transmission
00288       itd->ii_updated = false;
00289       // Clear fids for all publishers of the Information Item
00290           for(uint i=0;i<itd->pubs.size();i++) {
00291                   itd->pubs[i].fid = "";
00292                   itd->pubs[i].fid_updated = true;
00293           }
00294       continue;
00295     }
00296 
00297     //Set the weight-map weight for the Dijkstra operation. If the II was not found, then continue to the next one
00298         if(!setEdgeWeights(it->first))
00299                   continue;
00300 
00301         //Save the value of weight for all of the edges and save in order to replace them after the LID calculation process is finished
00302         GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend;
00303         for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei)
00304                   weightmap[*ei] = g.properties(*ei).weight;
00305 
00306     // Clear fids and paths for all publishers of the Information Item
00307     for(uint i=0;i<itd->pubs.size();i++) {
00308         //Clear fids
00309         itd->pubs[i].fid = "";
00310         //Clear the link paths
00311         itd->pubs[i].paths.empty();
00312         //Update the fid_update flag for the selected publisher
00313         itd->pubs[i].fid_updated=true;
00314     }
00315 
00316     /*
00317          * The weight vector collects the link weight of every path from the examined subscriber to
00318          * every publisher. Therefore for it has the following format:
00319          *
00320          *                                                    Number of Pubs
00321          *                                      |-----------------------------------------|
00322          *      Number of Subs  |P1-S*|P2-S*|P3-S*|P4-S*| ... | ... | ... |
00323          *                                      |-----------------------------------------|
00324          */
00325 
00326     //Vector for counting the weight of the path for each publisher source
00327     std::vector<double> weight_vector( itd->pubs.size() );
00328 
00329     //std::cout << "For Information Item " << it->first << endl;
00330 
00331         // ---------------------------------------------------------------------------------- //
00332     // -------- Find path from every subscriber and check who is the best one.    ------- //
00333         // -------- This is a Destination-Driven algorithm, that additionally assigns ------- //
00334         // -------- the subscribers to the source, instead of only calculating paths. ------- //
00335     // ---------------------------------------------------------------------------------- //
00336     for(uint sindex=0;sindex<itd->subs.size();sindex++) {
00337     
00338                 // Each subscriber is checked, and its shortest path will be calculated
00339                 Vertex dst = getVertex(itd->subs[sindex]);
00340 
00341                 // Sanity Check
00342                 if (dst == UINT_MAX){
00343                   opp_error("*** What THE HELL: Check your topology parser, NO VERTEX FOR SUBSCRIBER ??? ");
00344                   continue;
00345                 }
00346 
00347                 // Yay... Do the job...
00348                 // predecessor_map
00349                 std::vector<Vertex> p(g.getVertexCount());
00350                 // distance_map
00351                 std::vector<double> d(g.getVertexCount());
00352 
00353                 ev << "   - Going for item " << it->first << " subscribed by vertex " << dst << endl;
00354 
00355                 dijkstra_shortest_paths(g.getGraph(), dst, predecessor_map(&p[0]).distance_map(&d[0]));
00356 
00357                 //Compute the weight for each of the shortest paths. NOTE THAT THE PATH IS REVERSELY CALCULATED
00358                 //FROM THE DESTINATION TO THE SOUTCE (DESTINATION-DRIVEN)!
00359                 for (uint i=0; i<itd->pubs.size(); ++i){
00360                         Vertex tempsrc = getVertex(itd->pubs[i].pub);
00361                         weight_vector[i]=getWeightFromBoostResult_rec(dst, tempsrc, p);
00362                 }
00363 
00364                 //Find the shortest path with the least weight and set its weight to zero for the
00365                 //next path calculations to use it.
00366                 int minPos=std::min_element(weight_vector.begin(),weight_vector.end())-weight_vector.begin();
00367 
00368                 //Select as src the best found publisher
00369                 Vertex src = getVertex(itd->pubs[minPos].pub);
00370 
00371                 //For all edges, compute their weights according to the QoS requirements of the Information Item
00372                 /*GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend;
00373                 for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) {
00374 
00375                         //THE WEIGHTS SHOULD BE PLACED IN REVERSE BECAUSE THE ROUTE FINDING ALGORITHM IS DESTINATION DRIVEN
00376                         //THIS IS WHY THE EDGE FOUND WILL BE REPLACED WITH THE SAME LINK BUT WITH REVERSED END-POINTS!
00377                         Edge rev = *ei;
00378                         std::pair<Edge, bool> edge_res= g.getEdge(rev.m_target,rev.m_source);
00379                         if (edge_res.second == false){
00380                                 opp_error("*** NO EDGE FOUND WHILE REVERSING: Check topology initializer, THIS SHOULD NEVER HAPPEN");
00381                                 return;
00382                         }
00383 
00384                         //Get the edge
00385                         Edge e = edge_res.first;
00386 
00387                         //GET THE PARAMETERS OF THE INITIAL LINK, IN ORDER TO COMPUTE THE PROPER VALUES FOR THE REVERSE
00388                         QoSList param=g.properties(*ei).status;
00389 
00390                         std::cout << g.properties(rev.m_source).nodeid << "-" << g.properties(rev.m_target).nodeid << " has rate " << param.find(QoS_USEDRATE)->second << " and QoS_BW_M: " << it->second.metadata.find(QoS_BW_M)->second << endl;
00391                 }*/
00392 
00393                 //Set the weights of the shortest path edges to zero, so that they will preferred by future
00394                 //path calculations.
00395                 eliminateWeights_rec(dst, src, p, it);
00396 
00397                 //std::cout << simTime() << endl;
00398                 //std::cout << itd->subs[sindex] << " goes to " << itd->pubs[minPos].pub << " with weight " << weight_vector[minPos] << endl;
00399 
00400                 // ---------------------------------------------------------- //
00401                 // ------------- FID Calculation Process Starts ------------- //
00402                 // ---------------------------------------------------------- //
00403                 //Get the path lids from the specified source to the specified destination
00404                 vector<string> boostPath=getPathFromBoostResult_rec(dst, src, p);
00405                 itd->pubs[minPos].paths.insert(itd->pubs[minPos].paths.end(),boostPath.begin(),boostPath.end());
00406                 // Get FID src to dst
00407                 itd->pubs[minPos].fid = lidOR(itd->pubs[minPos].fid, getFIDFromPath(itd->pubs[minPos].paths));
00408                 // Add the dst node internal LID! is needed
00409                 itd->pubs[minPos].fid = lidOR(itd->pubs[minPos].fid, getNodeInternalLID(itd->subs[sindex]));
00410                 // ---------------------------------------------------------- //
00411                 // ------------ FID Calculation Process Finishes ------------ //
00412                 // ---------------------------------------------------------- //
00413     }
00414     //std::cout << endl;
00415 
00416     // Update Flags
00417         //itd->fid_updated = true; // NEWFID
00418         itd->ii_updated = false; // UNMODIFIED SINCE LAST RUN
00419 
00420         //Restore the edge weights
00421         for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei)
00422                 g.properties(*ei).weight = weightmap[*ei];
00423   }
00424 
00425   ev << " - TMBoostDD::pathCalculation - completed" << endl;
00426 }

bool TMBoostDD::setEdgeWeights ( string  IIID  )  [protected, virtual]

Set the weight for the specified edge, according to the report sent by the network modules.

00519                                           {
00520 
00521         //Find the Information Item, in the list of all the known ones
00522         InfoItems::iterator it=ii.find(IIID);
00523 
00524         if(it==ii.end()) {
00525                 ev << "Unknown Information Item requested in TM, " << endl;
00526                 return(false);
00527         }
00528 
00529         //For all edges, compute their weights according to the QoS requirements of the Information Item
00530         GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend;
00531         for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) {
00532 
00533                 //THE WEIGHTS SHOULD BE PLACED IN REVERSE BECAUSE THE ROUTE FINDING ALGORITHM IS DESTINATION DRIVEN
00534                 //THIS IS WHY THE EDGE FOUND WILL BE REPLACED WITH THE SAME LINK BUT WITH REVERSED END-POINTS!
00535                 //Get the reverse edge
00536                 Edge e;
00537                 if(!getReverseEdge(*ei,e))
00538                         continue;
00539 
00540                 //GET THE PARAMETERS OF THE INITIAL LINK, IN ORDER TO COMPUTE THE PROPER VALUES FOR THE REVERSE
00541                 QoSList param=g.properties(*ei).status;
00542 
00543                 //Make sure we have all the necessary QoS parameters for the weight computation
00544                 if(param.find(QoS_USEDRATE)!=param.end() && param.find(QoS_CAPACITY_M)!=param.end() /*&&  param.find(QoS_COST)!=param.end()*/ &&
00545                    it->second.metadata.find(QoS_BW_M)!=it->second.metadata.end() && it->second.metadata.find(QoS_FLOW)!=it->second.metadata.end()) {
00546                         //std::cout << "Setting "<< g.properties(rev.m_source).nodeid << "-" << g.properties(rev.m_target).nodeid << " has rate " << param.find(QoS_USEDRATE)->second << " and QoS_BW_M: " << it->second.metadata.find(QoS_BW_M)->second << endl;
00547 
00548                         //If the link is empty
00549                         if(param.find(QoS_USEDRATE)->second==0) {
00550                                 g.properties(e).weight = 1;
00551                                 weightmap[e]=g.properties(e).weight;
00552                         }
00553                         //If there are any links that have space for the new stream calculate with a weight given by the selected formula
00554                         else if( (param.find(QoS_CAPACITY_M)->second - param.find(QoS_USEDRATE)->second) > it->second.metadata.find(QoS_BW_M)->second) {
00555                                 g.properties(e).weight = (double)pow((double)(param.find(QoS_CAPACITY_M)->second - param.find(QoS_USEDRATE)->second)/param.find(QoS_CAPACITY_M)->second,3);
00556                                 weightmap[e]=g.properties(e).weight;
00557                         }
00558                         //If the link is full...
00559                         else {
00560                                 //Check if the Information Item is currently passing through the examined link
00561                                 bool pass=false;
00562                                 for(uint i=0;i<it->second.pubs.size();i++) {
00563                                         if(find(it->second.pubs[i].paths.begin(),it->second.pubs[i].paths.end(),g.properties(e).lid) != it->second.pubs[i].paths.end())
00564                                                 pass=true;
00565                                 }
00566 
00567                                 //If it is passing calculate with a weight given by the selected formula
00568                                 if(pass) {
00569                                         g.properties(e).weight = (double)pow((double)(param.find(QoS_CAPACITY_M)->second - param.find(QoS_USEDRATE)->second)/param.find(QoS_CAPACITY_M)->second,3);
00570                                         weightmap[e]=g.properties(e).weight;
00571                                 }
00572                                 //Otherwise give it a big weight
00573                                 else {
00574                                         g.properties(e).weight = 10;
00575                                         weightmap[e]=g.properties(e).weight;
00576                                 }
00577                         }
00578                 }
00579                 //Else there are no statistic for this link, so give a big weight
00580                 else {
00581                         g.properties(e).weight = 10;
00582                         weightmap[e]=g.properties(e).weight;
00583                 }
00584         }
00585         //std::cout << endl;
00586         return(true);
00587 }

bool TMBoostDD::vertexExists ( string  nodeid  )  [protected, virtual]

Check that a vertex exists by nodeid

00124                                          {
00125         return (!getVertex(nodeid) == UINT_MAX);
00126 }

void TMBoostDD::write2gml ( string  fname  )  [virtual]

Extracts the network graph in a xml format, proving the ability of monitoring the network on runtime.

00595                                      {
00596         // Chinese Language with mixed Greek follows!
00597         std::ofstream fout(fname.c_str());
00598         if (!fout) return;
00599 
00600         string top="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> \n\
00601         <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\
00602         <key id=\"key0\" for=\"node\" attr.name=\"id\" attr.type=\"string\" />\n\
00603         <key id=\"key1\" for=\"edge\" attr.name=\"weight\" attr.type=\"int\" /> \n\
00604         <key id=\"key2\" for=\"edge\" attr.name=\"lid\" attr.type=\"string\" />\n\
00605         <key for=\"edge\" id=\"d12\" yfiles.type=\"edgegraphics\"/> \n\
00606         <key for=\"node\" id=\"d7\" yfiles.type=\"nodegraphics\"/>\n\
00607         <graph id=\"G\" edgedefault=\"directed\" parse.nodeids=\"canonical\" parse.edgeids=\"canonical\" parse.order=\"nodesfirst\">\n";
00608 
00609         fout.write(top.c_str(), top.length());
00610 
00611         GraphWrapper<VertexProp,EdgeProp>::vertex_iterator vi, vend;
00612         for (tie(vi, vend) = g.getVertices(); vi != vend; ++vi) {
00613                 VertexProp p = g.properties(*vi);
00614                 string nodestr="<node id=\""+p.nodeid+"\">\n";
00615                 nodestr+=" <data key=\"key0\">"+p.nodeid+"</data>\n";
00616                 nodestr+=" <data key=\"d7\">\n\
00617                   <y:GenericNode configuration=\"ShinyPlateNode\">\n\
00618                    <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\
00619                   </y:GenericNode>\n\
00620                  </data>\n";
00621                 nodestr+="</node>\n";
00622 
00623                 fout.write(nodestr.c_str(), nodestr.length());
00624         }
00625 
00626         int count=0;
00627         GraphWrapper<VertexProp,EdgeProp>::edge_iterator ei, eend;
00628         for (tie(ei, eend) = g.getEdges(); ei != eend; ++ei) {
00629                 EdgeProp p = g.properties(*ei);
00630                 stringstream ss;
00631                 ss<<"e"<<count;
00632                 count++;
00633                 string lid=chararray_to_bin(p.lid);
00634 
00635                 string edgestr = "<edge id=\""+ss.str()+"\" source=\""+g.getSourceProp(*ei).nodeid+
00636                                   "\" target=\""+g.getTargetProp(*ei).nodeid+"\">\n";
00637                 ss.clear();
00638                 ss.str(std::string());
00639                 ss<<p.weight;
00640                 edgestr += " <data key=\"key1\">"+ss.str()+"</data>\n";
00641                 edgestr += " <data key=\"key2\">"+lid+"</data>\n";
00642                 edgestr+=" <data key=\"d12\">\n\
00643                   <y:PolyLineEdge>\n\
00644                         <y:Arrows source=\"none\" target=\"delta\"/>\n\
00645                   </y:PolyLineEdge>\n\
00646                  </data>\n";
00647                 edgestr += "</edge>\n";
00648                 fout.write(edgestr.c_str(), edgestr.length());
00649         }
00650 
00651         string bottom=" </graph>\n</graphml>";
00652         fout.write(bottom.c_str(), bottom.length());
00653         fout.close();
00654 }


Member Data Documentation

The graph representation.

I don't think it is used in this version.


The documentation for this class was generated from the following files:
Generated on Thu Jun 14 17:12:42 2012 for PAL by  doxygen 1.6.3