繁体   English   中英

omnet++ 三个节点(或三个以上)之间的通信

[英]Omnet++ Communication between three node(or more than three)

所以我想配置三个节点如何相互通信,但有两种方式。 我尝试了不同的方法,但所有错误都不同,它甚至没有运行模拟,但这段代码运行模拟 GUI,但无法运行模拟

first NO:
Node 1 --> Node 2 --> Node 3 --> Node 1 --> terminate & display round trip time
Second NO:
Node 1 --> Node 2 --> Node 3 --> Node 1
Node 1 <-- Node 2 <-- Node 3 <-- Node 1

代码如下

.NED 文件代码

network Network
{
    @display("bgb=437,321");

    types:
        simple Test
        {
            gates:
                input input_gate[];
                output output_gate[];
        }

    submodules:
        Node0: Test {
            @display("p=43,85");
        }
        Node1: Test {
            @display("p=173,54");
        }
        test: Test {
            @display("p=183,172");
        }

    connections:


        Node0.output_gate++ --> Node1.input_gate++;
        Node1.output_gate++ --> test.input_gate++;
        test.output_gate++ --> Node0.input_gate++;
        test.output_gate++ --> Node1.input_gate++;
        Node1.output_gate++ --> Node0.input_gate++;
        Node0.output_gate++ --> test.input_gate++;
}

.CC 代码:

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

using namespace omnetpp;
class Test : public cSimpleModule
{
  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;

};

Define_Module(Test);


void Test::initialize()
{

    if (strcmp("Node0", getName()) == 0) {
        cMessage *msg = new cMessage("tictocMsg");
                send(msg,"output_gate");


    }
}

void Test::handleMessage(cMessage *msg){
        send(msg,"output_gate");
}

在网络中,您配置节点之间的连接,而不是数据包必须经过的路由。 所以那部分是不正确的。 事实上,每个节点都必须连接到其他每个节点,然后您必须在 .cc 文件中实现路由逻辑。

第一种情况相对简单,因为您实际上只是在 output 门上接收消息并发送出去。 但您必须使用单个门(不是矢量门)。 这样你的 current.cc 代码就可以工作了。

第二种情况稍微复杂一些。 在这种情况下,任何收到的消息都应该在另一个门上发送出去,所以你必须检查传入消息的门。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM