1

In Omnet++, I have created a network in which a root node sent a message to child nodes. The child node sends an acknowledgment to the root node and sends another message to its child nodes but my code also sends the message to the root node. I want to prevent the new message from sending to the root node. The code for acknowledgment is:

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

            }

and the code for sending a new message to child nodes are:

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

                                    cMessage *l2 = new cMessage ("l2");
                                    send(l2, "out", i);
            }
hzeb
  • 11
  • 3

1 Answers1

0

Can you use inout gates. If so, make the code for sending the new message should be similar to:

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

Otherwise, consider making individual interfaces with one in and one out gate, then marking which interface the message came from. Like in the INET Framework: MacRelayUnitBase.cc:71

EdL
  • 415
  • 4
  • 12