Omnet++直接使用Node的Index发送消息

Send message directly using the Index of Node in Omnet++

我有一个网络拓扑结构,其中包括 36 个 lcn.One,其中在 network topology 中大约有 42 个传感器节点。传感数据后我想将数据发送到 gcn.To 这样做,数据必须将 lcn 跳到 lcn.I 使用 gates.I 只是转发 packet.However 我想将数据包直接发送到指定的中继 node.When 我输入;

 send(packet,"lcnIO$", 7); 

它通常给我门大小错误,因为最大门大小是 8。我怎样才能实现 this.I 意思是我想从 lcn 0.Both 直接发送数据包到 lcn 7 其中有对角线连接彼此之间。

send 命令只能通过具有给定索引的 own 门发送消息。 没有简单的方法可以从索引选择的节点向量中向一个节点发送消息。
我建议你在每次连接结束时检查模块的索引。此外,您必须考虑到,该节点可能与索引选择的节点没有连接。
假设:

  • lcn 节点中的输出门称为 out
  • 输出门out是一个向量
  • 节点要发送packetdestIndex选择的lcn节点

你可以使用这段OMNeT++代码:

const char * gateName = "out";
int destIndex = 7; // index of destination lcn
cGate *destGate = NULL;
bool found = false;

int i = 0;
int gateSize = gate(gateName, 0)->size();

do {
    destGate = gate(gateName, i++);
    cGate *nextGate = destGate->getNextGate();
    if (nextGate && nextGate->getOwnerModule()->getIndex() == destIndex) {
        found = true;
        send(packet, destGate);
    }
} while (!found && i < gateSize);
// here: found equals to false means that a packet was not sent