INET Framework for OMNeT++/OMNEST
CriticalnessAnalyzer Class Reference

#include <CriticalnessAnalyzer.h>

List of all members.

Public Member Functions

std::vector< CA::RouterRecord >
::iterator 
getRouterRecord (std::string &name)
void generatePaths (std::string &name)
void sortByCost ()
void calculateCriticalness ()
bool existRouter (std::string &name)
void updateDisplayString ()
void writeResultsToFile ()

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Private Attributes

std::string startNode
std::string destNode
bool analyze
std::vector< CA::RouterRecordrouters
CA::Path tempPath
std::vector< CA::Pathpaths

Detailed Description

Definition at line 125 of file CriticalnessAnalyzer.h.


Member Function Documentation

Definition at line 148 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{
  int pathNum = paths.size();
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    int p = 0;
    std::string name = it->getName();
    
    
    for (std::vector<CA::Path>::iterator pit = paths.begin(); pit!=paths.end(); ++pit)
    {
      if(pit->isInPath(name))
        ++p;
    }
    it->setCriticalness((int)((p*100)/pathNum));
  }  
}
bool CriticalnessAnalyzer::existRouter ( std::string &  name)

Definition at line 166 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    if(it->getName() == name)
      return true;
  }
  return false;
}
void CriticalnessAnalyzer::generatePaths ( std::string &  name)

Definition at line 91 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{
  std::vector<CA::RouterRecord>::iterator it = getRouterRecord(name);
  
  if(it !=routers.end())
  {
    for(int i = 0; i < it->getNeighborsNum(); ++i)
    {
      std::string neighName = it->getNeighbor(i).getName();
      double cost = it->getNeighbor(i).getCost();
      double actCost = tempPath.getCost(); 
      
      if (neighName == destNode)
      {
        tempPath.addNode(neighName, cost);
        paths.push_back(tempPath);
        tempPath.removeLastNode();
        tempPath.setCost(actCost);
      }
      else if (!tempPath.isInPath(neighName))
      {
        tempPath.addNode(neighName, cost);
        generatePaths(neighName);
        tempPath.removeLastNode();
        tempPath.setCost(actCost);
      }
    }
  }
  
}
std::vector< CA::RouterRecord >::iterator CriticalnessAnalyzer::getRouterRecord ( std::string &  name)

Definition at line 80 of file CriticalnessAnalyzer.cc.

Referenced by generatePaths().

{
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
     if(name == it->getName())
      return it;
  }
  return routers.end();
}
void CriticalnessAnalyzer::handleMessage ( cMessage *  msg) [protected, virtual]

Definition at line 75 of file CriticalnessAnalyzer.cc.

{
    ASSERT(false);
}
void CriticalnessAnalyzer::initialize ( ) [protected, virtual]

Definition at line 24 of file CriticalnessAnalyzer.cc.

{

if(par("analyze"))
{
  cTopology topology;
  
  topology.extractByNedTypeName(cStringTokenizer("inet.ansa.ANSARouter").asVector());
  
  routers.clear();
  
  for(int i = 0; i < topology.getNumNodes(); ++i)
  {
    cTopology::Node *node = topology.getNode(i);
    
    CA::RouterRecord router(node->getModule()->getName(), node->getModule());
    
    for(int j = 0; j < node->getNumOutLinks(); ++j)
    {
      cTopology::LinkOut  *link = node->getLinkOut(j);
      double cost = (100000000 / link->getLocalGate()->getTransmissionChannel()->par("datarate").doubleValue());
      std::string name = link->getRemoteNode()->getModule()->getName();
      
      CA::NeighborRecord neigh(name, cost);
      router.addNeighbor(neigh);
    }
    
    routers.push_back(router);
    
  }

  startNode = (const char *) par("startNode");
  if(!existRouter(startNode))
    error("Error - Start node %s doesn't exist", startNode.c_str());
  
  destNode = (const char *) par("destNode");
  if(!existRouter(destNode))
    error("Error - Destination node %s doesn't exist", destNode.c_str());
  
  tempPath.addNode(startNode, 0.0);
  generatePaths(startNode);
  sortByCost();
  calculateCriticalness();
  updateDisplayString();
  writeResultsToFile();
  
  WATCH_VECTOR(paths);
  WATCH_VECTOR(routers);
}  
}

Definition at line 122 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{
  std::vector<CA::Path> tmpPaths;
  
  while (paths.size() > 0)
  {
    int i = 0;
    int index = 0;
    double cost = paths.at(0).getCost();
    
    for (std::vector<CA::Path>::iterator it = paths.begin(); it!=paths.end(); ++it)
    {
      if(it->getCost() < cost)
      {
        cost = it->getCost();
        index = i;
      }
      ++i;
    }
    tmpPaths.push_back(paths.at(index));
    paths.erase(paths.begin() + index);   
  }
  
  paths = tmpPaths;
}

Definition at line 176 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {  
      int cr = it->getCriticalness();
      char buf[80];
      sprintf(buf, "Criticalness: %d%%", cr);
       
      if(cr == 100 )
      {
        it->getModule()->getDisplayString().setTagArg("i",1,"red");
      }
      else if (cr == 0)
      {
        it->getModule()->getDisplayString().setTagArg("i",1,"yellow");
      }
      it->getModule()->getDisplayString().setTagArg("t",0,buf);
  }

}

Definition at line 197 of file CriticalnessAnalyzer.cc.

Referenced by initialize().

{ 
  std::ofstream outFile;
  outFile.open ("results/CPAnalysis.csv");
  
  outFile << ";TotCost";
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    outFile << ";"<< it->getName();
  }
   outFile << "\n";
  
  int i = 1;
  
  for (std::vector<CA::Path>::iterator pit = paths.begin(); pit!=paths.end(); ++pit)
  {
    outFile << i << ";" << pit->getCost();
    for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
    {
      std::string name = it->getName();
      if(pit->isInPath(name))
        outFile << ";x";
      else
        outFile << ";";
    }
    outFile << "\n";
    ++i;
  }
  
  outFile << "CP;";
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    if(it->getCriticalness() == 100)
      outFile << ";x";
    else
      outFile << ";";
  }
  outFile << "\n";
  
  outFile << "UP;";
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    if(it->getCriticalness() == 0)
      outFile << ";x";
    else
      outFile << ";";
  }
  outFile << "\n";
  
  outFile << "Criticalness;";
  for (std::vector<CA::RouterRecord>::iterator it = routers.begin(); it!=routers.end(); ++it)
  {
    outFile << ";" << it->getCriticalness() << "%";
  }
  outFile << "\n";
  
  outFile.close();
}

Member Data Documentation

Definition at line 132 of file CriticalnessAnalyzer.h.

std::string CriticalnessAnalyzer::destNode [private]

Definition at line 130 of file CriticalnessAnalyzer.h.

Referenced by generatePaths(), and initialize().

std::string CriticalnessAnalyzer::startNode [private]

Definition at line 129 of file CriticalnessAnalyzer.h.

Referenced by initialize().

Definition at line 136 of file CriticalnessAnalyzer.h.

Referenced by generatePaths(), and initialize().


The documentation for this class was generated from the following files: