所以我想配置三个节点如何相互通信,但有两种方式。我尝试了不同的方法,但所有错误都不同,它甚至没有运行模拟,但是这段代码运行了模拟 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");
}