0

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?

Vijay Rana
  • 35
  • 1
  • 8
  • 1
    what is the questions here? – user4786271 Mar 03 '16 at 08:55
  • How do I extract link information and feed it to an empty graph "ListGraph g;" with the corresponding nodes? Basically I am trying to extract the topology of given network and then feed this information to the Lemon Library Graph. – Vijay Rana Mar 03 '16 at 11:59

1 Answers1

1

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
}
Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
  • But at the same time I want the links to be extracted as well. I tried out the code by parsing through node list and checking for its remote node(if any) and adding it to the Lemon Graph(using g.addarc(u,v)) but still its ineffective. Some hints would be good. – Vijay Rana Mar 06 '16 at 14:37
  • Could you explain what do you mean writing "ineffective"? Are there compile-time or run-time errors? Does `extractByNedTypeName()` method recognize all nodes you expected? Which type of network do you use - wired or wireless? – Jerzy D. Mar 07 '16 at 21:02
  • I meant ineffective in the case of edges(links) which I am trying to extract. I have got the nodes. For each node I am checking the linkOuts and the corresponding remote node and then adding the edge in the graph.The resulting graph doesn't have all the links as it should be. – Vijay Rana Mar 08 '16 at 10:31
  • Could you provide code you use to adding edges to lemon graph as well as ned file of your network? – Jerzy D. Mar 08 '16 at 14:51
  • for(int j = 0; jgetNode(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++; This is the code I used. Parsing each node for checking neighboring node and then adding it. – Vijay Rana Mar 08 '16 at 15:05
  • How the `nodeList` is declared and assigned? Does `i` is index of node from `cTopology` object? Or maybe you edit your question and paste the code with declaration of all variables. – Jerzy D. Mar 08 '16 at 15:40
  • I have added nodeList later. "i" is just the counter. Due to limited comment length I didnt include the outerloop in the above code:- for (ListDigraph::NodeIt n(g); n != INVALID; ++n) { int i = 0;//counter int numOutLinks = topo->getNode(i)->getNumOutLinks(); g.addNode(); std::vector nodeList; nodeName[n] = (char*)topo->getNode(i)->getModule(); nodeList.push_back(nodeName[n]); After this the above code continues. NodeList contains the name of the nodes as omnet++ node in the network. This is just to differentiate nodes. – Vijay Rana Mar 08 '16 at 16:15
  • Could you edit your main question and paste your code in your **main question**? Without the whole code it is difficult to help you... Moreover, what is `nodeName`? And `(char*)topo->getNode(i)->getModule()` is incorrect - you should write `topo->getNode(i)->getModule()->getName()`. – Jerzy D. Mar 08 '16 at 17:40
  • I have edited the code in the main question. Please can you tell me where I am going wrong in my code for extracting the link information. – Vijay Rana Mar 09 '16 at 13:21
  • oh! right. So you mean to say I should consider each node from omnet graph at a time, then check for its outlinks and then add it in my Lemon Graph? – Vijay Rana Mar 12 '16 at 09:53
  • 1
    Yes, I think it is the best way. – Jerzy D. Mar 12 '16 at 16:59
  • I declared "ListDigraph::NodeMap nodeName(g);" for finding particular node through the node names. But NodeMap doesnt have find() functor as normal std::map has. So if I have to parse through it then how would I achieve it? – Vijay Rana Mar 22 '16 at 16:26
  • 1
    I do not see other possibility than add own method for searching in `NodeMap`. I have extended my answer with an example of this function. – Jerzy D. Mar 22 '16 at 18:19
  • I didn't get this declaration "ListDigraph::NodeIt::Node findNodeMap(args..)". Shouldn't it be ListDigraph::Node findNodeMap(args..)? – Vijay Rana Mar 22 '16 at 19:38
  • Yes, it could be `ListDigraph::Node findNodeMap(...)`. – Jerzy D. Mar 22 '16 at 19:48