首页 文章

同时从所有节点发送消息

提问于
浏览
0

以下是.ned文件

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

以下是.cc源文件

#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)
{


}

现在我的问题是在初始化函数中,节点A向B和C发送消息 . 之后,我想从节点B,FROM NODE B向节点A和C发送消息 . 同样,之后我想从节点C发送消息到A和B(如距离矢量协议)我该怎么做?

此外,第二个问题是如何将来自所有节点的消息同时发送到邻居节点i-e A向B,C发送消息; B向A,c发送消息; C发送到A,B . All,A B C同时发送消息?让我简单明了一点 . A向B发送消息如下

以下是.cc源文件

#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){现在如何从C发送消息到A}

A到B C到A?

2 回答

  • 0

    如果我理解你的问题(第一个),你需要做的就是这么简单 .
    在"handleMessage"函数中执行此操作:

    如果i节点“B”并且msg来自“A”:将msgs发送到A和C,就像你在初始化函数中一样 .

    如果i节点“C”并且msg来自“B”:将msgs发送到A和B,就像你在初始化函数中那样 .

    您可以通过msg-> getSource检查发送msg的人(类似于..type
    "msg->",您将看到选项 .

    希望它有所帮助 .

  • 0

    在这样做之前,你必须回答这个问题,C怎么知道B收到了这样的消息?你有2个解决方案:

    • 从网络角度来看逻辑解决方案:在此之前,您必须向C发送一条消息,阻止他们接收此类消息

    • 较少的逻辑解决方案:通过从C模块检查B模块的bool值,并在此时决定发送消息,或者通过在B处创建一个并更好地使用信号并将C模块寄给它(检查omnet doc) .

    祝好运

相关问题