如何在omnet ++中获取cTopology?

时间:2019-05-09 08:53:28

标签: omnet++ inet

我想获取邻居地址列表(处于传输范围内的节点)。我在omnet ++手册上找到了此代码,但是在编译时,出现了“ cTopology”中没有名为“ extractByModuleType”的成员的错误,我确实回到了cTopology类,并且函数“ extractByModuleType()”不存在。我尝试了其他功能,但没有成功。请,如果有人知道如何访问cTopology,请回答我的问题。

最诚挚的问候;

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;
  }
}

1 个答案:

答案 0 :(得分:0)

应该是

topo.extractByNedTypeName("Host");

根据文档。

此外,您指示要获取“传输范围”中的节点列表。因此,假设您有一个无线网络,节点之间没有连接。 cTopology根据连接发现拓扑,并且无线网络没有任何拓扑,因此无论如何您都不会获得有意义的结果。

除非您的节点没有移动,并且您实际上在相邻节点之间创建了连接。这样的回答给了我帮助,该怎么做:Connect, repetitively, nodes based at their euclidean distance in omnet++

如果您确实连接了它们,则只需遍历所有连接即可到达邻居节点,而您将不需要任何cTopology魔术。