【问题标题】:How to send a reply to root node and at the same time a message to child nodes?如何向根节点发送回复,同时向子节点发送消息?
【发布时间】:2021-10-23 12:50:27
【问题描述】:

在 Omnet++ 中,我创建了一个网络,其中根节点向子节点发送消息。子节点向根节点发送确认并向其子节点发送另一条消息,但我的代码也将消息发送到根节点。我想阻止新消息发送到根节点。 确认代码为:

cGate * sender = msg->getSenderGate();
            for (cModule::GateIterator i(this); !i.end(); i++)
            {
                 cGate *gate = i();
                 std::string gateStr = gate->getName();
                 if (gateStr == "out" && gate->getPathEndGate()->getOwnerModule() == sender->getOwnerModule() )
                 {
                     int senderId = gate->getIndex();
                     cMessage *reply=new cMessage("reply");
                     send(reply, "out", senderId);
                 }

            }

向子节点发送新消息的代码是:

 for (int i = 0; i < gateSize("out"); i++) {

                                    cMessage *l2 = new cMessage ("l2");
                                    send(l2, "out", i);
            }

【问题讨论】:

    标签: c++ simulation omnet++


    【解决方案1】:

    你能用inout门吗?如果是这样,则发送新消息的代码应类似于:

    cGate * sender = msg->getSenderGate();
                for (cModule::GateIterator i(this); !i.end(); i++){
                              if(i!=sender){
                                        cMessage *l2 = new cMessage ("l2");
                                        send(l2, "out", i);
                              }
                }
    

    否则,请考虑制作具有一进一出门的单独接口,然后标记消息来自哪个接口。就像在 INET 框架中一样:MacRelayUnitBase.cc:71

    【讨论】:

      猜你喜欢
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      相关资源
      最近更新 更多