2

我是 Omnet++ 的新手,我正在尝试模拟 Wifi 网络。我已经成功创建了一个由 AP 和一些节点组成的网络,并且所有节点都能够连接到 AP。

我想要做的是,一旦所有节点都连接到 AP,一个节点(基于其 IP 地址)应该向网络中的另一个节点发送消息。我已经创建了包含所有必填字段的 .msg 文件,并且消息编译器成功地将其编译为相应的 _m.h 和 _m.cc 文件。我希望将此消息发送到另一个节点。如何进行此操作?我知道它必须与 handleMessage() 函数有关,但我找不到包含该函数的文件。

提前感谢您的任何帮助。

4

2 回答 2

0

您可以在同一项目或文件夹中的 .cc 文件中找到该函数。通常,.cc 文件的名称接近于 .ned 文件的名称,该文件包含主机或节点的详细信息,或者您在项目中调用它的任何名称。

于 2015-09-18T09:51:39.897 回答
0

要发送初始消息,您必须send()在初始化节点时使用。

来自tictoc 教程

void Txc1::initialize()
{
    // Initialize is called at the beginning of the simulation.
    // To bootstrap the tic-toc-tic-toc process, one of the modules needs
    // to send the first message. Let this be `tic'.

    // Am I Tic or Toc?
    if (strcmp("tic", getName()) == 0)
    {
        // create and send first message on gate "out". "tictocMsg" is an
        // arbitrary string which will be the name of the message object.
        cMessage *msg = new cMessage("tictocMsg");
        send(msg, "out");
    }
}

然后你希望节点能够做出反应。他们的反应可以是沉默的——只需接受消息并将其删除,或者发送另一条消息作为回报。

为此,您需要handleMessage()在节点.cc文件中实现该功能。

void Txc1::handleMessage(cMessage *msg)
{
    // The handleMessage() method is called whenever a message arrives
    // at the module. Here, we just send it to the other module, through
    // gate `out'. Because both `tic' and `toc' does the same, the message
    // will bounce between the two.
    send(msg, "out");
}
于 2015-08-23T13:45:21.257 回答