前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tiktok案例分析_metaobject

tiktok案例分析_metaobject

作者头像
全栈程序员站长
发布2022-11-15 14:58:12
3250
发布2022-11-15 14:58:12
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

tictoc12.ned文件

代码语言:javascript
复制
//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文件

代码语言:javascript
复制
//输入输出门向量,随机消息发送
#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

代码语言:javascript
复制
[Config Tictoc12]
network = Tictoc12

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/234383.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年11月2日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档