OMNetpp学习笔记.doc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- OMNetpp 学习 笔记
- 资源描述:
-
1.OMnetpp简介 OMnetpp作为一种仿真工具(与ns2,opnet并列),在P2P仿真方面具有很大的优势。 2.Overview 2.1 模块概念 2.1.1 模块 OMnetpp中功能被封装为一个个的模块。简单模块(simple modules)为基本模块,每个simple module完成一个基本功能。Compound module由多个simple module组成。 2.1.2 Messages, Gates, Links massage是模块之间通信的媒介,可以包含复杂的结构体。 Gates are the input and output interfaces of modules; messages are sent 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。 2.1.3 包传输模拟 connections可以使用物理链路模拟。支持的参数有:data rate, propagation delay, bit error rate and packet error rate, and may be disabled. 这些参数在channel对象中。 2.1.4 参数 Modules 可以拥有参数。Parameters can be assigned in either the NED files or the configuration file omnetpp.ini. 2.1.5 Topology Description Method The user defines the structure of the model in NED language descriptions (Network Description). 2.2 Programming the Algorithms Simulation objects (messages, modules, queues etc.) are represented by C++ classes. They have been designed to work together efficiently, creating a powerful simulation programming framework. The following classes are part of the simulation class library: >>module, gate, parameter, channel >>message, packet >>container classes (e.g. queue, array) >>data collection classes >>statistic and distribution estimation classes (histograms, P2 algorithm for calculating quantiles etc.) >>transient detection and result accuracy detection classes 2.3 使用OMNetpp 2.3.1 building and running simulations 一个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)继承性 5)包结构的管理:如Java 6)内部类型:(可以定义局部变量) 7)Metadata annotations(元数据注解?) 3.2 NED开始 图1 网络举例 这个网络描述如下: // // A network // network Network { submodules: node1: Node; node2: Node; node3: Node; ... connections: node1.port++ <--> {datarate=100Mbps;} <--> node2.port++; node2.port++ <--> {datarate=100Mbps;} <--> node4.port++; node4.port++ <--> {datarate=100Mbps;} <--> node6.port++; ... } 3.2.1 channel类型 可以定义channel 类型 // // A Network // network Network { types: channel C extends ned.DatarateChannel { datarate = 100Mbps; } submodules: node1: Node; node2: Node; node3: Node; ... connections: node1.port++ <--> C <--> node2.port++; node2.port++ <--> C <--> node4.port++; node4.port++ <--> C <--> node6.port++; ... } 3.2.3 一些简单模块( App, Routing, and Queue) 简单模块定义有关键字:simple。在这个例子中,我们定义了node为简单模块(traffic generation, routing, etc. 其实也挺复杂的)。应当定义一些简单模块,然后组合起来组成一个复合模块(compound module)。一个流量生成的简单模块,一个路由模块,一个队列模块。(We'll have one simple module for traffic generation (App), one for routing (Routing), and one for queueing up packets to be sent out (Queue)) simple App { parameters: 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,可以用于 files, modules, parameters, gates, connections, and other objects, and parameter value 3.2.4 复合模块 module Node { parameters: @display("i=misc/node_vs,gold"); gates: inout port[]; submodules: app: App; routing: Routing; queue[sizeof(port)]: Queue; connections: routing.localOut --> app.in; routing.localIn <-- app.out; for i=0..sizeof(port)-1 { routing.out[i] --> queue[i].in; routing.in[i] <-- queue[i].out; queue[i].line <--> port[i]; } } 此为node的定义。复合模块可以和简单模块一样,有parameter,gate。 3.3 简单模块 simple Queue { parameters: int capacity; @display("i=block/queue"); gates: input in; output out; } 以上是一个Queue模块。参数都是可选的。动作不在NED语言中定义,而是在C++中定义。默认情况下,OMNetpp会在与NED名字相同的C++类中寻找(如此例,Queue)。也可以使用下面的方式指定: simple Queue { parameters: int 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::Router and mylib::Queue。 类似于C++中类的继承,简单模块之间也可以存在这样的关系: simple Queue { int capacity; ... } simple BoundedQueue extends Queue { capacity = 10; } 该例BoundedQueue给capacity设置了初始值,这个模块使用的类与Queue相同,都是Queue。 若要使用不同的类,则需要用以下方式: simple PriorityQueue extends Queue { @class(PriorityQueue); } 此时,PriorityQueue使用的类为PriorityQueue。 3.4 复合模块 module WirelessHostBase { gates: input radioIn; submodules: tcp: TCP; ip: IP; wlan: Ieee80211; connections: tcp.ipOut --> ip.tcpIn; tcp.ipIn <-- ip.tcpOut; ip.nicOut++ --> wlan.ipIn; ip.nicIn++ <-- wlan.ipOut; wlan.radioIn <-- radioIn; } module WirelessUser extends WirelessHostBase { submodules: webAgent: WebAgent; connections: webAgent.tcpOut --> tcp.appIn++; webAgent.tcpIn <-- tcp.appOut++; } module DesktopUser extends WirelessUser { gates: inout ethg; submodules: eth: EthernetNic; connections: ip.nicOut++ --> eth.ipIn; ip.nicIn++ <-- eth.ipOut; eth.phy <--> ethg; } 3.5 Channels(通道) Channel 将parameters与behaviour封装并与connections相关联。Channels像简单模块,在寻找C++类的处理方面与简单模块相同。已提供的channel有 ned.IdealChannel, ned.DelayChannel and ned.DatarateChannel(ned是包名,可以使用import ned.* 导入这些包)。 l IdealChannel没有参数,它允许messages无延时的到达对端。一个connection不包含channel对象与包含IdealChannel对象相同。 l DelayChannel有两个参数: ü delay:double类型,标明延迟。 ü disabled:boolean类型,默认为false。如果为true,则channel对象丢弃所有包。 l DatarateChannel相比于DelayChannel还有其它的参数: ü 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.DatarateChannel { datarate = 100Mbps; delay = 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 user module Node { submodules: app : App { sendIaTime = 3s; packetLength = 1024B; // B=byte } ... } 在模块中直接定义,After the above definition, the app submodule's parameters cannot be changed from omnetpp.ini.(在模块中定义的无法在ini文件中修改) 值(value) 在configuration中可以这样定义: **.sendIaTime = 100ms **.sendIaTime = 2s + exponential(100ms) 可以指定默认或需要用户给出: **.sendIaTime = default //在NED中用=default(...)给出 **.sendIaTime = ask 参数值放在模块中还是放在配置文件中:在模块中被认为是模块的一部分(模块的性质),一般是常数。在配置中则可以在每次试验中改变。 表达式 binary and logical XOR are # and ## \^ has been reassigned to power-of + 可以代表字串连接 volaile 这个关键字标明该参数在每次读的过程中都要重新evaluate一次。而其他参数则在刚开始的时候evaluate,之后再不会evaluate。对于读取随机数等在过程中变化的,则需要利用该参数。 (是否就是在仿真过程中不断变化的参数就需要利用该关键字?) Units simple App { parameters: volatile double sendIaTime @unit(s) = default(exponential(350ms)); volatile int packetLength @unit(byte) = default(4KB); ... } 文档意思好像是说可以兼容单位:如 @unit(s) accepts milliseconds, nanoseconds, minutes, hours, etc.由OMNet++定义。 XML 参数 提供复杂输入,可以将这些输入写在单独的文件中。 simple TrafGen { 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", "profile[@id='gen1']"); } trafGen2 : TrafGen { profile = xmldoc("all.xml", "profile[@id='gen2']"); } } <?xml> <root> <profile id="gen1"> <param>3</param> <param>5</param> </profile> <profile id="gen2"> <param>9</param> </profile> </root> 3.7 gates 三种:input output inout output是一个向量,由一组output,具体值取决于参数。 simple Classifier { parameters: int numCategories; gates: input in; output out[numCategories]; } 可以动态变化: simple Sink { gates: input in[]; } 可以有些不被连接(例为定义grid上的节点,在grid边上的node会有少于四个的连接) simple GridNode { gates: inout neighbour[4] @loose; } WirelessNode below is expected to receive messages (radio transmissions) via direct sending, so its radioIn gate is marked with Unknown LaTeX command\fprop @directIn .(不懂有什么用) simple WirelessNode { gates: input radioIn @directIn; } 首先定义了一个tree节点,可以指向任意多个孩子节点。在此基础上extend一个二叉树节点,指向两个孩子。 simple TreeNode { gates: inout parent; inout children[]; } simple BinaryTreeNode extends TreeNode { gates: children[2]; } 3.8 子模块 module Node { submodules: routing: Routing; // a submodule queue[sizeof(port)]: Queue; // submodule vector 类似数组 ... } 还能这么组合?!有点犀利 module Host { parameters: bool withTCP = default(true); submodules: tcp[withTCP ? 1 : 0]: TCP; // conditional submodule ... connections: tcp[0].ipOut --> ip.tcpIn if withTCP; tcp[0].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 connections Chain module Chain parameters: int count; submodules: node[count] : Node { gates: port[2]; } connections allowunconnected: for i = 0..count-2 { node[i].port[1] <--> node[i+1].port[0]; } } Binary Tree simple BinaryTreeNode { gates: inout left; inout right; inout parent; } module BinaryTree { parameters: int height; submodules: node[2^height-1]: BinaryTreeNode; connections allowunconnected: for i=0..2^(height-1)-2 { node[i].left <--> node[2*i+1].parent; node[i].right <--> node[2*i+2].parent; } } 默认每个gate必须要有连接,否则会出错。使用allowunconnected参数,则可以忽略这个限制。 Random Graph module RandomGraph { parameters: int count; double connectedness; // 0.0<x<1.0 submodules: node[count]: Node { gates: in[count]; out[count]; } connections allowunconnected: for i=0..count-1, for j=0..count-1 { node[i].out[j] --> node[j].in[i] if i!=j && uniform(0,1)<connectedness; } } 3.10.1 connection patterns ``Subgraph of a Full Graph'' for i=0..N-1, for j=0..N-1 { node[i].out[...] --> node[j].in[...] if condition(i,j); } ``Connections of Each Node'' for i=0..Nnodes, for j=0..Nconns(i)-1 { node[i].out[j] --> node[rightNodeIndex(i,j)].in[j]; } rightNodeIndex(i,j)函数是什么意思?是自己定义的吧 ``Enumerate All Connections'' for i=0..Nconnections-1 { node[leftNodeIndex(i)].out[...] --> node[rightNodeIndex(i)].in[...]; } 此处leftNodeIndex(i)与rightNodeIndex(i)也是自己定义的吧? 3.11 submodule type as parameter like关键字: network Net6 { parameters: string nodeType; submodules: node[6]: <nodeType> like INode { address = index; } connections: ... } <nodeType>在这里应该向泛型一样的东东。由参数直指定。 相应的NED 申明 moduleinterface INode { parameters: int address; gates: inout port[]; } module SensorNode like INode { parameters: int address; ... gates: inout port[]; ... } 3.12 性质 (Metadata Annotations) @display,@class, @namespace, @unit, @prompt, @loose, @directIn (这一部分感觉非常灵活,没有掌握) 3.13 继承 关键字:extend, like 3.14 包(packages) 类似Java的文件管理机制。展开阅读全文
咨信网温馨提示:1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。




OMNetpp学习笔记.doc



实名认证













自信AI助手
















微信客服
客服QQ
发送邮件
意见反馈



链接地址:https://www.zixin.com.cn/doc/10922260.html