我怎样才能在 omnet++ 中获得 cTopology?

How can I get cTopology in omnet++?

我想获取邻居地址列表(传输范围内的节点)。我在 omnet++ 手册上找到了这段代码,但是当我编译时,我得到了 'cTopology' 中没有名为 'extractByModuleType' 的成员的错误,我确实回到了 class 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;
  }
}

应该是

topo.extractByNedTypeName("Host");

根据文档。

此外,您表示要获取 'transmission range' 中的节点列表。据推测,您有一个无线网络,其中节点之间没有 没有 连接。 cTopology 根据连接发现拓扑,而无线网络没有任何拓扑,因此您无论如何都不会得到有意义的结果。

除非您的节点没有移动并且您实际上在相邻节点之间创建了连接。这个 SO 回答我给你帮助,如何做到这一点:

如果您确实连接了它们,那么您只需遍历所有连接以到达相邻节点,您将不需要任何 cTopology 魔法。