send messages from all nodes at the same time

2019-09-19 07:25发布

following is the .ned file

simple computer
{
    parameters:

    gates:
        input in1;
        output out1;
        input in2;
        output out2;

}

//
// TODO documentation
//
network Network
{
    @display("bgb=538,302");
    submodules:
        A: computer {
            @display("p=30,88");
        }
        B: computer {
            @display("p=344,96");
        }
        C: computer {
            @display("p=209,199");
        }
    connections:

        A.out1 --> B.in1;
        B.out1 --> A.in1;

        A.out2 --> C.in1;
        C.out1 --> A.in2;

        C.out2 --> B.in2;
        B.out2 --> C.in2;
}

following is .cc source file

#include <string.h>
#include <omnetpp.h>
#include <string>

class computer: public cSimpleModule
{
  public:


    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
};
//----------------------------------------------------------------------

Define_Module(computer);
void computer::initialize()
{

    if (strcmp("A", getName()) == 0)
    {

       send(msg, "out1");
       cMessage *copy = (cMessage *) msg->dup();
       send(copy, "out2");
    }
}


void computer::handleMessage(cMessage *msg)
{


}

Now my question is that in the initialize function node A sends message to B and C. After that i want to send message from node B , FROM NODE B to node A and C. Similarly after that i want to send message from node C to A and B (like distance vector protocol) How can i do that?

Moreover the second question is that how can i send message from all the nodes at the same time to the neighbor nodes i-e A sending message to B,C ; B sending message to A,c ; C sending to A,B. All, A B C sending messages at the same time? Let me make it more brief and clear. A sends message to B as follows

following is .cc source file

#include <string.h>
#include <omnetpp.h>
#include <string>

class computer: public cSimpleModule
{
  public:


    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
};
//----------------------------------------------------------------------

Define_Module(computer);
void computer::initialize()
{

    if (strcmp("A", getName()) == 0)
    {

       send(msg, "out1");

    }
}

handleMessage(cMessage *msg) { Now how to send message from C TO A }

A to B C to A?

标签: omnet++
2条回答
姐就是有狂的资本
2楼-- · 2019-09-19 07:43

Before doing so, you must answer to this questio, how C can know that B received such msg ? You have 2 solutions:

  1. Logic solution from a networking point of view: Before doing so you have to sent a message to C preventing them of the reception of such msg
  2. Less logical solution: By checking a bool value at B module from C module, and decide at this moment to send a message, or better use signals by creating one at B and suscribing to it the C module (check omnet++ doc).

Good luck

查看更多
Explosion°爆炸
3楼-- · 2019-09-19 07:48

If i understand your question (the first), what u need to do it's simple.
In "handleMessage" function do this:

if i node "B" and the msg come from "A": send msgs to A and C like u do in initialize function.

if i node "C" and the msg come from "B": send msgs to A and B like u do in initialize function.

You can check who send the msg with msg->getSource (something like that..type
"msg->" and you will see the options.

Hope it's help.

查看更多
登录 后发表回答