(完整版)OMNetpp学习笔记

上传人:Sc****h 文档编号:142720663 上传时间:2022-08-25 格式:DOC 页数:15 大小:512.50KB
收藏 版权申诉 举报 下载
(完整版)OMNetpp学习笔记_第1页
第1页 / 共15页
(完整版)OMNetpp学习笔记_第2页
第2页 / 共15页
(完整版)OMNetpp学习笔记_第3页
第3页 / 共15页
资源描述:

《(完整版)OMNetpp学习笔记》由会员分享,可在线阅读,更多相关《(完整版)OMNetpp学习笔记(15页珍藏版)》请在装配图网上搜索。

1、1.OMnetpp 简介OMnetpp 作为一种仿真工具(与ns2, opnet 并列),在 P2P 仿真方面具有很大的优势。2.Overview2.1 模块概念模块OMnetpp 中功能被封装为一个个的模块。 简单模块( simple modules )为基本模块,每个 simple module 完成一个基本功能。 Compound module 由多个 simple module 组成。massage 是模块之间通信的媒介,可以包含复杂的结构体。Gates are the input and output interfaces of modules; messages are sent

2、out through output gates and arrive through input gates.Each connection (also called link) is created within a single level of the module hierarchy: within a compound module, one can connect the corresponding gates of two submodules, or a gate of one submodule and a gate of the compound module 。包传输模

3、拟connections 可以使用物理链路模拟。 支持的参数有: data rate, propagation delay, bit error rate and packet error rate, and may be disabled. 这些参数在 channel 对象中。参数Modules 可以拥有参数。 Parameters can be assigned in either the NED files or the configuration file omnetpp.ini.The user defines the structure of the model in NED la

4、nguage descriptions (Network Description).2.2 Programming the AlgorithmsSimulation objects (messages, modules, queues etc.) are represented by C+ classes. They havebeen designed to work together efficiently, creating a powerful simulation programming framework. The following classes are part of the

5、simulation class library:module, gate, parameter, channelmessage, packetcontainer classes (e.g. queue, array)data collection classesstatistic and distribution estimation classes (histograms, P2 algorithm for calculating quantiles etc.)transient detection and result accuracy detection classes2.3 使用 O

6、MNetpp一个 OMNetpp model由以下几部分组成:1. NED 语言拓扑描述( .ned 文件):使用参数, gates 等描述 module 结构。 NED 文件可以用任意 text editor 编辑,但 OMNetpp IDE 提供了两种方式:图形与文本。2. 消息定义( .msg 文件)定义各种消息类型。OMNetpp 会将消息定义转换成C+类。3.简单模块源文件(Simple module sources ): C+文件仿真系统包括两部分:1.仿真内核2.用户接口3. NED 语言3.1 NED 概述NED 特点:1)层次性:复杂模块由简单模块组成2)模块化3)接口4)继

7、承性5)包结构的管理:如Java6)内部类型:(可以定义局部变量)7)Metadata annotations(元数据注解?)3.2 NED 开始图 1网络举例这个网络描述如下:/ A network/network Networksubmodules:node1: Node;node2: Node;node3: Node;.connections:node1.port+ datarate=100Mbps; node2.port+; node2.port+ datarate=100Mbps; node4.port+; node4.port+ datarate=100Mbps; node6.po

8、rt+; .类型可以定义channel 类型/ A Network/network Networktypes:channel C extends ned.DatarateChannel datarate = 100Mbps;submodules:node1: Node;node2: Node;node3: Node;.connections:node1.port+ node2.port+ node4.port+ .C node2.port+;C node4.port+;C node6.port+;一些简单模块(App, Routing, and Queue )简单模块定义有关键字:genera

9、tion, routing, etc.simple 。在这个例子中,我们定义了node其实也挺复杂的) 。应当定义一些简单模块,为简单模块(traffic然后组合起来组成一个复合模块( compound module )。一个流量生成的简单模块,一个路由模块,一个队列模块。( Well have one simple module for traffic generation (App), one for routing (Routing), and one for queueing up packets to be sent out (Queue) )simple Appparameters

10、:int destAddress;.display(i=block/browser);gates:input in;output out;simple Routing.simple Queue.这些放在App.ned, Routing.ned 和 Queue.ned 文件中。NOTE:module 类型名称首字母大写,gate, parameter 等用小写。 NED区分大小写。display()称作 display string ,在图形环境中显示。i=. 定义默认图标。一般的, 在 NED中 -words 如 display 称作 properties 。用来注释 metadata ,可以

11、用于 files, modules, parameters, gates, connections, and other objects, and parameter value复合模块module Nodeparameters:display(i=misc/node_vs,gold);gates:inout port;submodules:app: App;routing: Routing;queuesizeof(port): Queue;connections:routing.localOut - app.in;routing.localIn queuei.in;routing.ini -

12、 queuei.out;queuei.line porti;此为 node 的定义。复合模块可以和简单模块一样,有parameter , gate 。3.3 简单模块simple Queueparameters:int capacity;display(i=block/queue);gates:input in;output out;以上是一个Queue 模块。参数都是可选的。动作不在NED 语言中定义,而是在C+ 中定义。默认情况下, OMNetpp 会在与 NED 名字相同的 C+ 类中寻找(如此例,Queue )。也可以使用下面的方式指定:simple Queueparameters:i

13、nt capacity;class(mylib:Queue);display(i=block/queue);gates:input in;output out;如果多个模块在同一名字空间中,则可以采用如下的方式namespace(mylib);simple App .simple Router .simple Queue .这样 C+ 类为 mylib:App, mylib:Routerand mylib:Queue 。类似于 C+ 中类的继承,简单模块之间也可以存在这样的关系:simple Queueint capacity;.simple BoundedQueue extends Queu

14、ecapacity = 10;该例 BoundedQueue给 capacity 设置了初始值,这个模块使用的类与 Queue 相同,都是 Queue。若要使用不同的类,则需要用以下方式:simple PriorityQueue extends Queueclass(PriorityQueue);此时, PriorityQueue 使用的类为PriorityQueue 。3.4 复合模块module WirelessHostBasegates:input radioIn;submodules:tcp: TCP;ip: IP;wlan: Ieee80211;connections:tcp.ipO

15、ut - ip.tcpIn;tcp.ipIn wlan.ipIn;ip.nicIn+ - wlan.ipOut;wlan.radioIn tcp.appIn+;webAgent.tcpIn eth.ipIn;ip.nicIn+ - eth.ipOut;eth.phy ethg;3.5 Channels(通道)Channel 将 parameters 与 behaviour 封装并与 connections 相关联。Channels 像简单模块,在 寻 找 C+ 类 的 处 理 方 面 与 简 单 模 块 相 同 。 已 提 供 的 channel 有ned.IdealChannel, ned.

16、DelayChanneland ned.DatarateChannel(ned 是包名,可以使用 import ned.*导入这些包)。IdealChannel没有参数,它允许 messages 无延时的到达对端。 一个 connection不包含 channel对象与包含 IdealChannel 对象相同。DelayChannel有两个参数:? delay :double 类型,标明延迟。? disabled :boolean 类型,默认为 false 。如果为 true ,则 channel 对象丢弃所有包。DatarateChannel相比于 DelayChannel还有其它的参数:?

17、datarate :double 类型。表示data rate( bps, Kbps, Mbps,Gbps, etc.) ,默认为 0,表示无限带宽。? ber 与 per 代表 Bit Error Rate 与 Packet Error Rate 。 0, 1 范围内的 double 类型。当channel 决定一个包错误是否发生(基于随机数) ,会在包对象中设置 error flag 。接收模块检查 flag ,丢弃出错包。默认值为 0.一个 channel 例子:channel C extends ned.DatarateChanneldatarate = 100Mbps;delay =

18、 100us;ber = 1e-10;你可以通过 subclassing的方式增加 channel 的参数和属性。例如增加distance 参数:channel DatarateChannel2 extends ned.DatarateChannel double distance unit(m);delay = this.distance / 200000km * 1s;3.6 参数( parameter )参数的值可以NED code, configuration ( omnetpp.ini), or even, interactively from the usermodule Node

19、submodules:app : App sendIaTime = 3s;packetLength = 1024B; / B=byte.在模块中直接定义,Afterthe abovedefinition,theapp submodulesparameterscannotbechanged fromomnetpp.ini.(在模块中定义的无法在ini 文件中修改 )值( value)在 configuration 中可以这样定义:*.sendIaTime = 100ms*.sendIaTime = 2s + exponential(100ms)可以指定默认或需要用户给出:*.sendIaTime

20、 = default /在 NED中用 =default(.)给出*.sendIaTime = ask参数值放在模块中还是放在配置文件中:在模块中被认为是模块的一部分(模块的性质),一般是常数。在配置中则可以在每次试验中改变。表达式binary and logical XOR are# and # has been reassigned topower-of+ 可以代表字串连接volaile这个关键字标明该参数在每次读的过程中都要重新evaluate 一次。而其他参数则在刚开始的时候 evaluate ,之后再不会 evaluate 。对于读取随机数等在过程中变化的,则需要利用该参数。(是否就

21、是在仿真过程中不断变化的参数就需要利用该关键字?)Unitssimple Appparameters:volatile double sendIaTimevolatile int packetLengthunit(s)unit(byte)= default(exponential(350ms);= default(4KB);.文档意思好像是说可以兼容单位:如 unit(s) accepts milliseconds, nanoseconds, minutes, hours, etc. 由 OMNet+ 定义。XML 参数提供复杂输入,可以将这些输入写在单独的文件中。simple TrafGen

22、 parameters:xml profile;gates:output out;module Node submodules:trafGen1 : TrafGen profile = xmldoc(data.xml);.使用 xml 类型与 xmldoc()操作。也可以这样:module Node submodules:trafGen1 : TrafGen profile = xmldoc(all.xml, profileid=gen1);trafGen2 : TrafGen profile = xmldoc(all.xml, profileid=gen2);3593.7 gates三种:

23、input output inoutoutput 是一个向量,由一组output ,具体值取决于参数。simple Classifier parameters:int numCategories;gates:input in;output outnumCategories;可以动态变化:simple Sink gates:input in;可以有些不被连接(例为定义grid 上的节点,在grid 边上的 node 会有少于四个的连接)simple GridNode gates:inout neighbour4loose;WirelessNode below is expected to rec

24、eive messages (radio transmissions) viadirect sending, so itsradioIngate is marked withUnknown LaTeX commandfpropdirectIn.(不懂有什么用)simple WirelessNode gates:input radioIndirectIn ;首先定义了一个tree节点,可以指向任意多个孩子节点。在此基础上extend一个二叉树节点,指向两个孩子。simple TreeNode gates:inout parent;inout children;simple BinaryTreeN

25、ode extends TreeNode gates:children2;3.8 子模块module Nodesubmodules:routing: Routing;/ a submodulequeuesizeof(port): Queue; / submodule vector类似数组.还能这么组合?!有点犀利module Hostparameters:bool withTCP = default(true);submodules:tcpwithTCP ? 1 : 0: TCP; / conditional submodule.connections:tcp0.ipOut - ip.tcpI

26、n if withTCP;tcp0.ipIn - ip.tcpOut if withTCP;.3.9 connection .就是用一个connection 将两个 gates 连接。Channel 的说明就写在中间,如:. delay=10ms; . delay=10ms; ber=1e-8; . C . BBone cost=100; length=52km; ber=1e-8; . display(ls=red); . BBone display(ls=green,2); .3.10 multiple connectionsChainmodule Chainparameters:int

27、count;submodules:nodecount : Node gates:port2;connections allowunconnected:for i = 0.count-2 nodei.port1 nodei+1.port0;Binary Treesimple BinaryTreeNode gates:inout left;inout right;inout parent;module BinaryTree parameters:int height;submodules:node2height-1: BinaryTreeNode;connections allowunconnec

28、ted:for i=0.2(height-1)-2 nodei.left node2*i+1.parent;nodei.right node2*i+2.parent;默认每个gate 必须要有连接,否则会出错。使用allowunconnected参数,则可以忽略这个限制。Random Graphmodule RandomGraph parameters:int count;double connectedness; / 0.0x nodej.iniif i!=j & uniform(0,1) nodej.in. if condition(i,j);Connections of Each Nod

29、efor i=0.Nnodes, for j=0.Nconns(i)-1 nodei.outj - noderightNodeIndex(i,j).inj;rightNodeIndex(i,j) 函数是什么意思?是自己定义的吧Enumerate All Connectionsfor i=0.Nconnections-1 nodeleftNodeIndex(i).out. -noderightNodeIndex(i).in.;此处 leftNodeIndex(i) 与 rightNodeIndex(i) 也是自己定义的吧?3.11 submodule type as parameterlike

30、关键字:network Net6parameters:string nodeType;submodules:node6: likeINode address = index;connections:.在这里应该向泛型一样的东东。由参数直指定。相应的 NED 申明moduleinterfaceINodeparameters:int address;gates:inout port;module SensorNode like INodeparameters:int address;.gates:inout port;.3.12 性质 (Metadata Annotations)display ,class, namespace,unit, prompt, loose, directIn(这一部分感觉非常灵活,没有掌握)3.13继承关键字: extend , like3.14包( packages)类似 Java 的文件管理机制。

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!