Bouchra BOUNAB
Bouchra BOUNAB

Reputation: 113

How can I get cTopology in omnet++?

I want to get the list of neighbor addresses (nodes that are in transmission range). I found this code on omnet++ manual, but when I compile, I get the error of no member named 'extractByModuleType' in 'cTopology', i did go back to the class cTopology, and the function 'extractByModuleType()' does not exist. I tried other functions but I did not succeed. Please, if someone knows how to access cTopology answer my question.

Best regards;

cTopology topo;
topo.extractByModuleType("Host", nullptr);
for (int i = 0; i < topo.getNumNodes(); i++) {
  cTopology::Node *node = topo.getNode(i);
  EV << "Node i=" << i << " is " << node->getModule()->getFullPath() << endl;
  EV << " It has " << node->getNumOutLinks() << " conns to other nodes\n";
  EV << " and " << node->getNumInLinks() << " conns from other nodes\n";

  EV << " Connections to other modules are:\n";
  for (int j = 0; j < node->getNumOutLinks(); j++) {
    cTopology::Node *neighbour = node->getLinkOut(j)->getRemoteNode();
    cGate *gate = node->getLinkOut(j)->getLocalGate();
    EV << " " << neighbour->getModule()->getFullPath()
       << " through gate " << gate->getFullName() << endl;
  }
}

Upvotes: 2

Views: 248

Answers (1)

Rudi
Rudi

Reputation: 6681

That should be

topo.extractByNedTypeName("Host");

according to the documentation.

Additionally, you indicate that you want to get the list of the nodes in 'transmission range'. So presumably, you have a wireless network where there are no connections between the nodes. cTopology discovers topology based on the connections and a wireless network does not have any, so you will not get meaningful results anyway.

Unless your nodes are not moving and you actually create a connection between neighboring nodes. This SO answer my give you help, how to do that: Connect, repetitively, nodes based at their euclidean distance in omnet++

If you do connect them, then you just have to iterate through all your connections to reach the neighbor nodes and you will not need any cTopology magic.

Upvotes: 2

Related Questions