一些OMNET使用心得
一些菜鸡学习心得,如果有错的话希望大佬能帮忙指出,感激不尽!!
(底层组织结构是大佬帮忙写的,感谢大佬带入门)
- 项目组织
\prj
\prjname
\simulation
\results
package.ned
omnet.ini
network.ned
…
\src
package.ned
host.ned
host.cc
host.h
…
其中ned主要负责简单模块、复杂模块、网络等的组件与拓扑的描述。h文件来声明,c文件来定义模块的行为。
如简单的tictoc项目:
- tictoc.ned
simple Txc1
{
gates:
input in;
output out;
}
- tictoc.h
class Txc1 : public cSimpleModule
{
protected:
// The following redefined virtual function holds the algorithm.
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
- tictoc.cc
Define_Module(Txc1);
void Txc1::initialize()
{
// Initialize is called at the beginning of the simulation.
// To bootstrap the tic-toc-tic-toc process, one of the modules needs
// to send the first message. Let this be `tic'.
// Am I Tic or Toc?
if (strcmp("tic", getName()) == 0) {
// create and send first message on gate "out". "tictocMsg" is an
// arbitrary string which will be the name of the message object.
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}
void Txc1::handleMessage(cMessage *msg)
{
// The handleMessage() method is called whenever a message arrives
// at the module. Here, we just send it to the other module, through
// gate `out'. Because both `tic' and `toc' does the same, the message
// will bounce between the two.
send(msg, "out"); // send out the message
}
而ini文件则是进行网络的配置,如:
[Tictoc1]
network = Tictoc1
以上是最简单的网络配置,后续还可以通过在ned中定义一些参数然后在ini中修改它来配置需要的网络。
复杂的网络则会在src文件夹中定义简单模块与复杂模块,然后在simulation文件夹中定义网络的ned及ini文件。
- 新建项目
File->new->OMNET++ Project
填写项目名称:
->NEXT->选择空项目/带src和simulation文件夹的项目。网络上的简易教程多为空项目,但带俩文件夹的项目后续会更适合复杂network的组织。
一般情况下,simulation文件夹放网络模块文件及ini配置,src文件夹放组织网络的简单及复杂模块(如node、host等)
三、简单模块与复杂模块的介绍及拼装网络
这部分以简易自组织网络为例介绍简单模块与复杂模块的ned部分。
简单的maclayer.ned:
package tdma_mac_demo;
//此处定义文件位置,处于tdma_mac_demo/src/maclayer.ned
//若需要在tdma_mac_demo/文件夹下但/src以外的地方(如simulation)引用它
//则需要import tdma_mac_demo/maclayer.ned
simple MacLayer
{
parameters:
@display("i=block/routing");
int numSlots = default(10);
double slotDuration @unit(s) = default(500ms);
string slotAllocate = default("");
gates:
input upperIn;
output upperOut;
input phyIn;
output phyOut;
}
简单来说,简单模块都是这个样子:
package ……;
simple ……
{
parameters:
……
gates:
input ……;
output ……;
}
而用简单模块的复杂模块则长这个样子:
package ……;
simple Node
{
parameters:
……
gates:
input ……;
output ……;
}
submodules:
trafficGen: TrafficGen {
……
}
macLayer: MacLayer {
……
}
phyLayer: PhyLayer {
……
}
connections:
trafficGen.lowerOut --> macLayer.upperIn;
……
}
再把复杂模块node拼装成一个网络network:
package tdma_mac_demo.simulations;
import tdma_mac_demo.DemoNode;
network DemoNetwork
{
parameters:
@display("bgb=500,500");
int nodenum = default(5);
types:
channel Channel extends ned.DatarateChannel
{
datarate = 100Mbps;
delay = default(100ms);
}
submodules:
node[nodenum]: DemoNode;
connections:
for i=0..sizeof(node[0].radioIn) , for j = 0..sizeof(node[0].radioIn){
node[i].radioOut++ --> Channel --> node[j].radioIn++ if i!=j ;}
}
很显然,parameters指参数,default()为默认,默认后就可以在ini快乐的更改它了~
gates指门(用来连接);submodule为子模块;connections指连接,用-->或者<--来表示。Channel为信道,可以直接继承(extends)omnet库中的信道类型,直接在types中定义一些参数的值。
注:
在parameters中可以用@class属性明确指定C++类,若未指定则默认当前文件夹的下的同名文件。
在ned中定义的参数,可以直接赋值,也可以设为默认后在ini文件中配置它。而在ini文件中赋值并不能覆盖ned中的赋值。参数还有一些属性,如@mutable、@unit、@derectIn等。
更具体可以参照《OMNET++与网络仿真 赵永利 张杰 著》及其他教程。
四、简单模块行为描述
首先举一个例子,下述是Txc1.h文件。和普通的C++类一样的声明,但继承简单模块cSimpleModule,initialize()、handleMessage()也是必须的——须在.cc文件中进行初始化及处理信息的描述。
class Txc1 : public cSimpleModule
{
protected:
// The following redefined virtual function holds the algorithm.
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
然后看Txc1.cc文件:
Define_Module(Txc1);
void Txc1::initialize()
{
// Initialize is called at the beginning of the simulation.
// To bootstrap the tic-toc-tic-toc process, one of the modules needs
// to send the first message. Let this be `tic'.
// Am I Tic or Toc?
if (strcmp("tic", getName()) == 0) {
// create and send first message on gate "out". "tictocMsg" is an
// arbitrary string which will be the name of the message object.
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}
void Txc1::handleMessage(cMessage *msg)
{
// The handleMessage() method is called whenever a message arrives
// at the module. Here, we just send it to the other module, through
// gate `out'. Because both `tic' and `toc' does the same, the message
// will bounce between the two.
send(msg, "out"); // send out the message
}
在仿真时会自动运行上述两个函数,也可以加入其他函数的声明及定义,但需要要initialize()和handleMessage()来call它们。
initialize()和handleMessage()都如其名,进行初始化和处理消息,初始化函数则是在仿真进行的开始对模块进行初始化,可以将ned中的参数导入,初始化变量等。处理消息函数则是在消息来到时自行调用该函数对msg进行处理,这个msg包括外来消息及自消息。
这个自消息则是一个新概念,比如modula A可以自己给自己发消息,用scheduleAfter ( delaytime, msg),在delaytime后发送msg给自己,就像定闹钟,到时间了告诉自己该起床、开会等等。
写不动了……
一些OMNET使用心得相关推荐
- 【OMNet++】OMNet++初学-进阶-精进历程分享
OMNeT进入国内时间并不长,国内专业和流派大多一直停留在OPNeT.NS等传统的仿真软件上.相比"古老的软件",业界新生代"OMNeT"的使用简单,界面交互良 ...
- Java EE学习心得
–Java EE学习心得 1. 称为编程专家的秘诀是: 思考-----编程--------思考------编程--.. 编程不能一步到位,不能一上来就编,必须先思考如何写,怎样写?然后再编程 ...
- 测试心得:微图书销售小程序
测试心得:微图书销售小程序 前言 这个学期差不多也将近结束,经过大半个学期,从项目需求的确认和项目文档的编写,到一步步的设计与实现,现在终于到了测试阶段,但是我们在测试阶段也暴露出了很多bug,但是每 ...
- java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得
该文章出自:http://www.cnblogs.com/hucn/p/3572384.html 分析工具:http://www.blogjava.net/jjshcc/archive/2014/03 ...
- 计算机财务应用实验心得,计算机会计实习心得-20210628124643.doc-原创力文档
计算机会计实习心得 计算机会计实习心得1 毕业实践环节是大学生在完成全部课程后.走向社会之前最真实的一个模拟实验,对于我们财会专业的学生,平时注意注重理论学习,缺乏实践锻炼,因此实习显得尤为重要.在本 ...
- html5考试总结300字,期中考心得300字5
为了检验学生半个学期所学的知识而进行的一次考试,有利于学生比较正式地检验自己平时的学习水平,根据这个成绩,学生可以及时的调整学习心态和方法,更有效率地进行下一阶段的学习,期中考试主要考察学生前半学期的 ...
- Assembly学习心得
http://blog.csdn.net/etmonitor/ Assembly学习心得 说明: 最近开始准备把学到的.NET知识重新整理一遍,眼过千遍不如手过一遍,所以我准备记下我的学习心得,已备参 ...
- 什么叫安装文件索引服务器,搜出精彩 玩转Windows 2008系统心得
[IT168 专稿]不少朋友已经在不经意间与Windows Server 2008系统进行了亲密接触,在一段时间的接触之后,不知大家对该系统的文件搜索功能会有什么样的体会?其实,Windows Ser ...
- mysql主从数据库含义_(转)Mysql数据库主从心得整理
管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本的主从,本博文属于总结性的,有一部分是摘自网络,大部分是根据自己管理的心得和经验所写,整理了一下,分享给各位同行,希望对 ...
最新文章
- 西南交通大学计算机专硕调剂,2019年西南交通大学接收调剂信息
- python基础菜鸟教程-菜鸟教程学习python
- Rancher2.0中邮件通知的设置
- android另类工具,[置顶] android应用程序开发另解及Android SDK工具集的另类用法
- java的case_java中的switch case语句使用详解
- Uep的ajaxform和ajaxgrid组件获取数据源
- python和.net的区别_c#教程之.net和C#的区别
- linux未设置为接受端口,Simple gawk server
- 毛发及眼球的渲染技术
- postgresql客户端使用
- 免焊vga3加6接线图_高清 VGA免焊接头3+6+9 VGA快速接头 免焊公头 3排15针 15针插头...
- 转载一些Unity插件及资源
- 巴塞尔iii_巴塞尔协议——银行风控实施的超级系统工程 之二
- 怎样抠图怎么把背景换成白色?几个步骤教你轻松掌握
- 两年工作经验,离职了...
- 消灭老鼠c语言题目,老鼠智力题-关于老鼠的智力题-关于老鼠的话题-33IQ
- MapReduce中加强内容
- 求大神帮忙解答!!!急!!!
- Python爬虫验证码识别四
- android live 电视 源码,GitHub - mxiaoguang/LivePlayback: Android TV直播电视节目 ,包含各央视频道及卫视频道...