大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
tictoc12.ned文件
//input:指定当前门是输入门,只能和输出门连接,只能接受消息
//output:当前门是输出门,只能和输入门连接,只能发送消息
//inout:既是输入门又是输出门,既能发送消息也能接受消息
simple Txc12
{
parameters:
@display("i=block/routing");
gates:
inout gate[]; // declare two way connections声明双向连接
}
// using two way connections to further simplify the network definition
network Tictoc12
{
types:
channel Channel extends ned.DelayChannel {
delay = 100ms;
}
submodules:
tic[6]: Txc12;
connections:
tic[0].gate++ <--> Channel <--> tic[1].gate++;
tic[1].gate++ <--> Channel <--> tic[2].gate++;
tic[1].gate++ <--> Channel <--> tic[4].gate++;
tic[3].gate++ <--> Channel <--> tic[4].gate++;
tic[4].gate++ <--> Channel <--> tic[5].gate++;
}
Txc12.cc文件
//输入输出门向量,随机消息发送
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
/** * Let's make it more interesting by using several (n) `tic' modules, * and connecting every module to every other. For now, let's keep it * simple what they do: module 0 generates a message, and the others * keep tossing it around in random directions until it arrives at * module 2. */
class Txc12 : public cSimpleModule
{
protected:
virtual void forwardMessage(cMessage *msg);
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Txc12);
void Txc12::initialize()
{
if (getIndex() == 0) {
// Boot the process scheduling the initial message as a self-message.
char msgname[20];
sprintf(msgname, "tic-%d", getIndex());
cMessage *msg = new cMessage(msgname);
scheduleAt(0.0, msg);
}
}
void Txc12::handleMessage(cMessage *msg)
{
if (getIndex() == 3) {
// Message arrived.
EV << "Message " << msg << " arrived.\n";
delete msg;
}
else {
// We need to forward the message.
forwardMessage(msg);
}
}
void Txc12::forwardMessage(cMessage *msg)
{
// In this example, we just pick a random gate to send it on.在这个例子中,我们只需选择一个随机门来发送它。
// We draw a random number between 0 and the size of gate `gate[]'.我们画了一个介于0和“gate[]”大小之间的随机数。
int n = gateSize("gate");
int k = intuniform(0, n-1);
EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
// $o and $i suffix is used to identify the input/output part of a two way gate。$o和$i后缀用于标识双向门的输入/输出部分
//inout门发送消息,门的名称+“$o”表示输出门,门的名称+“$i”表示输入门
send(msg, "gate$o", k);
}
omnetpp.ini
[Config Tictoc12]
network = Tictoc12
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/234383.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...