OMNetpp學(xué)習(xí)筆記_第1頁(yè)
OMNetpp學(xué)習(xí)筆記_第2頁(yè)
OMNetpp學(xué)習(xí)筆記_第3頁(yè)
OMNetpp學(xué)習(xí)筆記_第4頁(yè)
已閱讀5頁(yè),還剩24頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、1.OMnetpp簡(jiǎn)介OMnetpp作為一種仿真工具(與ns2 , opnet并列),在P2P 仿真方面具有很大的優(yōu)勢(shì)。2.Overview2.1 模塊概念模塊OMnetpp中功能被封裝為一個(gè)個(gè)的模塊。簡(jiǎn)單模塊( simple modules)為基本模塊, 每個(gè)simplemodule完成一個(gè)基本功能。Compound module由多個(gè)simple module組成。massage 是模塊之間通信的媒介,可以包含復(fù)雜的結(jié)構(gòu)體。Gates aretheinputand outputinterfacesof modules;messages aresent outthroughoutputgat

2、es 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 ofone submodule and a gate of the compound module。包傳輸模擬connections可以使用物理鏈路模擬。a

3、nd packet error rate, and may be disabled.支持的參數(shù)有: data rate, propagation delay, bit error rate 這些參數(shù)在 channel 對(duì)象中。參數(shù)Modules 可以擁有參數(shù)。 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 language descriptions (Networ

4、k 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 simulation class library:&g

5、t;>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 dete

6、ction classes2.3 使用OMNetpp一個(gè)OMNetpp model由以下幾部分組成:1. NED 語(yǔ)言拓?fù)涿枋觯?.ned 文件):使用參數(shù), gates 等描述 module 結(jié)構(gòu)。 NED 文件可以用任意 text editor 編輯,但 OMNetpp IDE 提供了兩種方式:圖形與文本。2.消息定義(.msg文件)定義各種消息類(lèi)型。OMNetpp會(huì)將消息定義轉(zhuǎn)換成C+ 類(lèi)。3. 簡(jiǎn)單模塊源文件(Simple module sources):C+ 文件仿真系統(tǒng)包括兩部分:1. 仿真內(nèi)核2. 用戶接口3. NED 語(yǔ)言3.1 NED 概述NED 特點(diǎn):1)層次性:復(fù)雜模塊由

7、簡(jiǎn)單模塊組成2)模塊化3)接口4)繼承性5)包結(jié)構(gòu)的管理:如Java6)內(nèi)部類(lèi)型:(可以定義局部變量)7) Metadata annotations(元數(shù)據(jù)注解?)3.2 NED 開(kāi)始圖 1網(wǎng)絡(luò)舉例這個(gè)網(wǎng)絡(luò)描述如下:/ A network/network Networksubmodules:node1: Node;node2: Node;node3: Node;.connections:node1.port+ <-> datarate=100Mbps; <-> node2.port+; node2.port+ <-> datarate=100Mbps; &l

8、t;-> node4.port+; node4.port+ <-> datarate=100Mbps; <-> node6.port+;.類(lèi)型可以定義channel類(lèi)型/ A Network/network Networktypes:channel C extends ned.DatarateChannel datarate = 100Mbps;submodules:node1: Node;node2: Node;node3: Node;.connections:node1.port+ <->node2.port+ <->node4.por

9、t+ <->.C <-> node2.port+;C <-> node4.port+;C <-> node6.port+;一些簡(jiǎn)單模塊(App, Routing, and Queue)簡(jiǎn)單模塊定義有關(guān)鍵字:simple 。在這個(gè)例子中,我們定義了node為簡(jiǎn)單模塊(trafficgeneration, routing, etc.其實(shí)也挺復(fù)雜的)。應(yīng)當(dāng)定義一些簡(jiǎn)單模塊,然后組合起來(lái)組成一個(gè)復(fù)合模塊(compound module)。一個(gè)流量生成的簡(jiǎn)單模塊,一個(gè)路由模塊,一個(gè)隊(duì)列模塊。( We'll have one simple modul

10、e for traffic generation (App), one for routing (Routing), and onefor queueing up packets to be sent out (Queue))simple Appparameters:int destAddress;.display("i=block/browser");gates:input in;output out;simple Routing.simple Queue.這些放在App.ned, Routing.ned和 Queue.ned文件中。NOTE:module類(lèi)型名稱首字母大

11、寫(xiě),display() 稱作display string一般的, 在 NED 中 -wordsgate , parameter等用小寫(xiě)。NED 區(qū)分大小寫(xiě)。,在圖形環(huán)境中顯示。"i=." 定義默認(rèn)圖標(biāo)。如 display 稱作properties。用來(lái)注釋metadata,可以用于files,modules, parameters, gates, connections, and other objects, and parameter value復(fù)合模塊module Nodeparameters:display("i=misc/node_vs,gold"

12、;);gates:inout port;submodules:app: App;routing: Routing;queuesizeof(port): Queue;connections:routing.localOut -> app.in;routing.localIn <- app.out;for i=0.sizeof(port)-1 routing.outi -> queuei.in;routing.ini <- queuei.out;queuei.line <-> porti;此為node的定義。復(fù)合模塊可以和簡(jiǎn)單模塊一樣,有parameter, g

13、ate 。3.3簡(jiǎn)單模塊simple Queueparameters:int capacity;display("i=block/queue");gates:input in;output out;以上是一個(gè)Queue模塊。參數(shù)都是可選的。動(dòng)作不在NED語(yǔ)言中定義,而是在C+中定義。默認(rèn)情況下,OMNetpp會(huì)在與NED名字相同的C+類(lèi)中尋找(如此例,Queue)。也可以使用下面的方式指定:simple Queueparameters:int capacity;class(mylib:Queue);display("i=block/queue");gat

14、es:input in;output out;如果多個(gè)模塊在同一名字空間中,則可以采用如下的方式namespace(mylib);simple App .simple Router .simple Queue .這樣C+ 類(lèi)為mylib:App, mylib:Routerand mylib:Queue。類(lèi)似于C+ 中類(lèi)的繼承,簡(jiǎn)單模塊之間也可以存在這樣的關(guān)系:simple Queueint capacity;.simple BoundedQueue extends Queuecapacity = 10;該例 BoundedQueue 給 capacity設(shè)置了初始值,這個(gè)模塊使用的類(lèi)與Queu

15、e相同,都是Queue 。若要使用不同的類(lèi),則需要用以下方式:simple PriorityQueue extends Queueclass(PriorityQueue);此時(shí), PriorityQueue使用的類(lèi)為PriorityQueue。3.4 復(fù)合模塊module WirelessHostBasegates:input radioIn;submodules:tcp: TCP;ip: IP;wlan: Ieee80211;connections:tcp.ipOut -> ip.tcpIn;tcp.ipIn <- ip.tcpOut;ip.nicOut+ -> wlan.

16、ipIn;ip.nicIn+ <- wlan.ipOut;wlan.radioIn <- radioIn;module WirelessUser extends WirelessHostBasesubmodules:webAgent: WebAgent;connections:webAgent.tcpOut -> tcp.appIn+;webAgent.tcpIn <- tcp.appOut+;module DesktopUser extends WirelessUsergates:inout ethg;submodules:eth: EthernetNic;conne

17、ctions:ip.nicOut+ -> eth.ipIn;ip.nicIn+ <- eth.ipOut;eth.phy <->ethg; 3.5 Channels(通道)Channel將在尋找C+parameters與 behaviour封裝并與類(lèi)的處理方面與簡(jiǎn)單模connections 塊 相 同相關(guān)聯(lián)。 已 提Channels供的像簡(jiǎn)單模塊,channel有ned.IdealChannel, ned.DelayChanneland ned.DatarateChannel(ned 是包名,可以使用 import ned.*導(dǎo)入這些包)。IdealChannel 沒(méi)有

18、參數(shù),它允許 messages 無(wú)延時(shí)的到達(dá)對(duì)端。 一個(gè) connection 不包含 channel 對(duì)象與包含 IdealChannel 對(duì)象相同。DelayChannel有兩個(gè)參數(shù):delay :double類(lèi)型,標(biāo)明延遲。disabled : boolean類(lèi)型,默認(rèn)為false 。如果為true ,則 channel對(duì)象丟棄所有包。DatarateChannel相比于DelayChannel還有其它的參數(shù):datarate:double類(lèi)型。表示data rate( bps,Kbps, Mbps ,Gbps , etc.),默認(rèn)為0 ,表示無(wú)限帶寬。ber與per代表Bit Erro

19、r Rate與Packet Error Rate。0, 1范圍內(nèi)的double類(lèi)型。當(dāng)channel決定一個(gè)包錯(cuò)誤是否發(fā)生(基于隨機(jī)數(shù)),會(huì)在包對(duì)象中設(shè)置error flag。接收模塊檢查flag,丟棄出錯(cuò)包。默認(rèn)值為0.一個(gè) channel例子:channel C extends ned.DatarateChanneldatarate = 100Mbps;delay = 100us;ber = 1e-10;你可以通過(guò)subclassing的方式增加channel的參數(shù)和屬性。例如增加distance參數(shù):channel DatarateChannel2 extends ned.Datarat

20、eChanneldouble distance unit(m);delay = this.distance / 200000km * 1s;3.6 參數(shù)(parameter )參數(shù)的值可以NED code , configuration (omnetpp.ini), or even, interactively from the usermodule Nodesubmodules:app : App sendIaTime = 3s;packetLength = 1024B; / B=byte.在模塊中直接定義,Aftertheabovedefinition,theapp submodule&#

21、39;sparameterscannotbechanged fromomnetpp.ini. (在模塊中定義的無(wú)法在ini文件中修改)值( value )在 configuration 中可以這樣定義:*.sendIaTime = 100ms*.sendIaTime = 2s + exponential(100ms)可以指定默認(rèn)或需要用戶給出:*.sendIaTime = default/在 NED 中用 =default(.)給出*.sendIaTime = ask參數(shù)值放在模塊中還是放在配置文件中:在模塊中被認(rèn)為是模塊的一部分(模塊的性質(zhì)),一般是常數(shù)。在配置中則可以在每次試驗(yàn)中改變。表達(dá)

22、式binary and logical XOR are#and#has been reassigned topower-of+可以代表字串連接volaile這個(gè)關(guān)鍵字標(biāo)明該參數(shù)在每次讀的過(guò)程中都要重新evaluate一次。而其他參數(shù)則在剛開(kāi)始的時(shí)候 evaluate ,之后再不會(huì) evaluate 。對(duì)于讀取隨機(jī)數(shù)等在過(guò)程中變化的,則需要利用該參數(shù)。(是否就是在仿真過(guò)程中不斷變化的參數(shù)就需要利用該關(guān)鍵字?)Unitssimple Appparameters:volatile double sendIaTimevolatile int packetLengthunit(s)unit(byte)=

23、 default(exponential(350ms);= default(4KB);.文檔意思好像是說(shuō)可以兼容單位:如unit(s)acceptsmilliseconds,nanoseconds,minutes,hours, etc.由 OMNet+定義。XML參數(shù)提供復(fù)雜輸入,可以將這些輸入寫(xiě)在單獨(dú)的文件中。simple TrafGen parameters:xml profile;gates:output out;module Node submodules:trafGen1 : TrafGen profile = xmldoc("data.xml");.使用xml類(lèi)

24、型與xmldoc ()操作。也可以這樣:module Node submodules:trafGen1 : TrafGen profile = xmldoc("all.xml", "profileid='gen1'");trafGen2 : TrafGen profile = xmldoc("all.xml", "profileid='gen2'");<?xml><root><profile id="gen1"><para

25、m>3</param><param>5</param></profile><profile id="gen2"><param>9</param></profile></root>3.7 gates三種: input output inoutoutput是一個(gè)向量,由一組output ,具體值取決于參數(shù)。simple Classifier parameters:int numCategories;gates:input in;output outnumCatego

26、ries;可以動(dòng)態(tài)變化:simple Sink gates:input in;可以有些不被連接(例為定義grid 上的節(jié)點(diǎn),在grid 邊上的node 會(huì)有少于四個(gè)的連接)simple GridNode gates:inout neighbour4loose;WirelessNodebelow is expected to receive messages (radio transmissions) viadirect sending, so itsradioIngate is marked withUnknown LaTeX commandfpropdirectIn.(不懂有什么用)simp

27、le WirelessNode gates:input radioIndirectIn;首先定義了一個(gè)tree 節(jié)點(diǎn),可以指向任意多個(gè)孩子節(jié)點(diǎn)。在此基礎(chǔ)上extend一個(gè)二叉樹(shù)節(jié)點(diǎn),指向兩個(gè)孩子。simple TreeNode gates:inout parent;inout children;simple BinaryTreeNode extends TreeNode gates:children2;3.8 子模塊module Nodesubmodules:routing: Routing;/ a submodulequeuesizeof(port): Queue;/ submodule v

28、ector類(lèi)似數(shù)組.還能這么組合?!有點(diǎn)犀利module Hostparameters:bool withTCP = default(true);submodules:tcpwithTCP ? 1 : 0: TCP;/ conditionalsubmodule .connections:tcp0.ipOut -> ip.tcpIn if withTCP;tcp0.ipIn <- ip.tcpOut if withTCP;.3.9 connection<-> ''.就是用一個(gè)connection將兩個(gè)gates連接。Channel的說(shuō)明就寫(xiě)在中間,如:.

29、<-> 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 connectionsC

30、hainmodule Chainparameters:int 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:

31、 BinaryTreeNode;connections allowunconnected:for i=0.2(height-1)-2 nodei.left <-> node2*i+1.parent;nodei.right <-> node2*i+2.parent;默認(rèn)每個(gè)gate 必須要有連接,否則會(huì)出錯(cuò)。使用allowunconnected參數(shù),則可以忽略這個(gè)限制。Random Graphmodule RandomGraph parameters:int count;double connectedness; / 0.0<x<1.0submodules:nodecount: Node gates:incount;outcount;conne

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論