以下是.ned文件
killall tor
tor: no process killed
* computer.cc * *创建日期:2015年9月29日 *作者:易卜拉欣 * /
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 -->{ delay = 100ms; } --> B.in1;
B.out1 -->{ delay = 100ms; } --> A.in1;
A.out2 -->{ delay = 200ms; } --> C.in1;
C.out1 -->{ delay = 200ms; } --> A.in2;
C.out2 -->{ delay = 300ms; } --> B.in2;
B.out2 -->{ delay = 300ms; } --> C.in2;
}
/*
//我也将它们粘贴在这里
#include <string.h>
#include <omnetpp.h>
#include <string>
double delay1;
class computer: public cSimpleModule
{
public:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
//----------------------------------------------------------------------
Define_Module(computer);
void computer::initialize()
{
cDelayChannel * channel = check_and_cast<cDelayChannel*>(gate("out1")->getChannel());
delay1 = channel->getDelay().dbl();
cMessage *msg = new cMessage("tictocMsg");
cMessage *ww ; ww=msg;
send(msg, "out1");
cMessage *copy = (cMessage *) msg->dup();send(copy, "out2");
我的问题是如何使用延迟 computer0.out - &gt; {延迟= 100ms ; } - &gt; computer1.in; 在.cc文件中。在源文件中,我有两个变量delay1和delay2。我想在delay1和delay2变量中移动延迟值(100)。怎么做?
答案 0 :(得分:1)
在OMNeT ++ 4.6中读取通道延迟值的示例。
NED文件:
// File: network.ned
simple computer
{
parameters:
gates:
input in1;
output out1;
input in2;
output out2;
}
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 --> { delay = 100ms; } --> B.in1;
B.out1 --> { delay = 100ms; } --> A.in1;
A.out2 --> { delay = 200ms; } --> C.in1;
C.out1 --> { delay = 200ms; } --> A.in2;
C.out2 --> { delay = 300ms; } --> B.in2;
B.out2 --> { delay = 300ms; } --> C.in2;
}
源文件:
// file: computer.cc
#include <string.h>
#include <omnetpp.h>
#include <string>
double delay1;
class computer: public cSimpleModule {
public:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
Define_Module(computer);
void computer::initialize() {
cDelayChannel * channel = check_and_cast<cDelayChannel*>(gate("out1")->getChannel());
delay1 = channel->getDelay().dbl();
EV << "delay = " << delay1 << std::endl;
// other operations...
}
void computer::handleMessage(cMessage *msg) {
}
omnetpp.ini文件:
[General]
network = Network
上面的cc文件是使用OMNeT++ 4.6
为Windows编译的。这是启动模拟后的日志:
** Initializing network
Initializing module Network, stage 0
Network.A: Initializing module Network.A, stage 0
Network.A: delay = 0.1
Network.B: Initializing module Network.B, stage 0
Network.B: delay = 0.1
Network.C: Initializing module Network.C, stage 0
Network.C: delay = 0.2