Lemon graph from Omnet++ network

230 views Asked by At

I am trying to extract a graph of network from omnet++ and feed the information of nodes and links to the Lemon graph. The part of the problem is easy to deal with. Using the code:

    cTopology *topo = new cTopology("topo");
    std::vector<std::string> nedTypes;
    nedTypes.push_back("inet.node.inet.StandardHost");
    topo->extractByNedTypeName(nedTypes);
    int numNodes = topo->getNumNodes();
    EV << "cTopology found " << topo->getNumNodes() << " nodes\n";

    ListDigraph g;
    ListDigraph::NodeMap<std::string> nodeName(g);

    for (ListDigraph::NodeIt n(g); n != INVALID; ++n)
    {
        int i = 0;//counter
        int numOutLinks =  topo->getNode(i)->getNumOutLinks();
        g.addNode();
        std::vector<std::string> nodeList;

        nodeName[n] = topo->getNode(i)->getModule()->getName();
        nodeList.push_back(nodeName[n]);

        for(int j = 0; j<numOutLinks; j++)
        {
            cTopology::LinkOut* lOut = topo->getNode(i)->getLinkOut(j);
            cTopology::Node *rNode = lOut->getRemoteNode();
            for (auto& nlist : nodeList)
                {
                     auto nodeFound = std::find(std::begin(nlist), std::end(nlist), rNode);
                if(nodeFound != std::end(nlist)){
                     g.addNode();
                     g.addArc(g.nodeFromId(i), g.nodeFromId(i+1));
                }
            }
        } i++;

Somehow I am getting the list of nodes and now I am trying to get the link information as well. That is, nodes and the links between them as well. How do I get the links information and feed it to Lemon graph and what is wrong in the approach I used in the code?

1

There are 1 answers

15
Jerzy D. On

The method extractByNedTypeName() needs the fully qualified NED type name, i.e. including the package. In INET the StandardHost is usually in package inet.node.inet, therefore you should write:

nedTypes.push_back("inet.node.inet.StandardHost");

EDIT
The loop for (ListDigraph::NodeIt n(g); n != INVALID; ++n) is never executed because graph g has been just created and it is empty. The outer loop should be something like:
for(int j = 0; j<numOutLinks; j++).

EDIT2
Because of lack of find for NodeMap one has to write own function, for example:

ListDigraph::NodeIt::Node findNodeMap(const ListDigraph::NodeMap<std::string> & map, const ListDigraph & g,
    std::string txt) {
    ListDigraph::NodeIt it(g);
    for (; it != INVALID; ++it) {
        if (map[it] == txt) 
            break;
    }
    return it;
}

An example of using it:

ListDigraph::NodeMap<std::string> nodeName(g);
// ... filling nodeName
std::string str = "node1";
ListDigraph::NodeIt::Node node = findNodeMap(nodeName, g, str);
if (node != INVALID) {
    // node with name from str was found
}