【问题标题】:send messages from all nodes at the same time同时从所有节点发送消息
【发布时间】:2015-10-09 22:31:35
【问题描述】:

下面是 .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、从节点 B 向节点 A 和 C 发送消息。同样,之后我想从节点发送消息节点 C 到 A 和 B(如距离矢量协议)我该怎么做?

此外,第二个问题是我如何同时从所有节点向相邻节点发送消息,即 A 向 B、C 发送消息; B 向 A,c 发送消息; C发送给A,B。全部,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?

【问题讨论】:

    标签: omnet++


    【解决方案1】:

    如果我理解你的问题(第一个),你需要做的很简单。
    在“handleMessage”函数中这样做:

    如果我的节点“B”和消息来自“A”: 像您在初始化函数中所做的那样,将消息发送到 A 和 C。

    如果我节点“C”和消息来自“B”: 像你在初始化函数中那样向 A 和 B 发送消息。

    您可以使用 msg->getSource 检查谁发送了 msg(类似这样的..type
    "msg->" 你会看到选项。

    希望对你有所帮助。

    【讨论】:

    • 好的,让我让它更简短易懂。
    • void computer::initialize() { if (strcmp("A", getName()) == 0) { send(msg, "out1"); } } A 正在向 B 发送消息。好的 B 收到来自 A 的消息
    • 现在我想在 B 收到 A 的消息后将消息从 C 发送到 A。怎么做?
    【解决方案2】:

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

    1. 从网络角度看的逻辑解决方案:在这样做之前 您必须向 C 发送一条消息,以防止他们收到 这样的味精
    2. 不太合乎逻辑的解决方案:通过检查 B 处的布尔值 模块来自 C 模块,并决定此时发送消息, 或通过在 B 处创建一个信号并订阅它来更好地使用信号 C 模块(查看 omnet++ 文档)。

    祝你好运

    【讨论】:

      猜你喜欢
      • 2012-04-10
      • 2021-10-23
      • 2014-11-20
      • 2021-07-26
      • 2015-07-30
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多