版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、CCU_COMM_ANT LABNS2 教學(xué)CCU_COMM_ANT LABIntroduction 為什麼要用Simulator作模擬?為什麼要用NS2?Open sourceObject-OrientedOTclCCU_COMM_ANT LABOutline 什麼是NS2Tcl簡(jiǎn)介開(kāi)始模擬模擬結(jié)果分析分析結(jié)果圖形化CCU_COMM_ANT LAB什麼是NS2?Network Simulator Version 21989年由Real Network Simulator 改版,目前由SAMAN和CONSER維護(hù)NS is a discrete event simulator targeted
2、 at networking research.CCU_COMM_ANT LABNS2架構(gòu)UIEvent SchedulerNetworkComponentTCLC+TclclOTclCCU_COMM_ANT LAB為什麼要用二種語(yǔ)言 ?用 C+ : 處理封包傳送 更改一些底層或新增 protocols 之類的 C+ Class 不常更動(dòng),執(zhí)行速度快 用 OTcl : 負(fù)責(zé)設(shè)定檔部分 運(yùn)作已編譯過(guò)的 C+ Objects 常會(huì)更動(dòng),執(zhí)行時(shí)需花一點(diǎn)直譯的時(shí)間CCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) ns使用MIT發(fā)展的OTcl (Object Tc
3、l)做為描述、配置、執(zhí)行模擬的語(yǔ)言,OTcl是Tcl的物件導(dǎo)向延伸版本。在使用ns進(jìn)行網(wǎng)路模擬之前,必須先學(xué)會(huì)這個(gè)語(yǔ)言,可以參考ns/otcl/doc目錄下有一份OTcl Tutorial,是一份不錯(cuò)的入門文件。CCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) cont.1: #範(fàn)例:遞迴解費(fèi)氏數(shù) 2: set count 20 ; # The number of Fibonacci numbers to print 3: set num(0) 0; set num(1) 1 ; # First and second seed values 4: put
4、s The first $count Fibonacci numbers: 5: for set i 1 $i $count incr i 1 6: puts $i:t$num(0) 7: set num(1) expr $num(0) + $num(1) 8: incr i 1 9: puts $i:t$num(1) 10: set num(0) expr $num(0) + $num(1) 11: CCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) cont.2: set count 20 ; # The number of Fibonacci num
5、bers to print 3: set num(0) 0; set num(1) 1 ; # First and second seed valuesset count 20 int count = 20; set num(0) 0; set num(1) 1 ;int num2; num0 = 0; num1 = 1; CCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) cont.puts The first $count Fibonacci numbers: do variable substitution variable substitution
6、 does not take place Puts “the first $count Fibonacci numbers”the first 20 Fibonacci numbersPuts the first $count Fibonacci numbersthe first $count Fibonacci numbersCCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) cont.for set i 1 $i $count incr i 1 for ( i = 1 ; i count ; i+ ) 流程控制流程控制(control flow) if
7、-else、switch、while、for、foreach set my_planet earthif $my_planet = earth puts I feel right at home. elseif $my_planet = venus puts This is not my home. else puts I am neither from Earth, nor from Venus.set num_legs 4switch $num_legs 2 puts It could be a human. 4 puts It could be a cow. 6 puts It coul
8、d be an ant. 8 puts It could be a spider. default puts It could be anything.set i 0while $i 5 puts In the while loop, and i = $i incr i 1 CCU_COMM_ANT LABTcl簡(jiǎn)介(Tool Command Language) cont.set num(1) expr $num(0) + $num(1) num1 = num0 + num1; indicate command substitution puts I am expr 10 * 3 years
9、old, and my I.Q. is expr 100 + 75 執(zhí)行的結(jié)果:I am 30 years old, and my I.Q. is 175CCU_COMM_ANT LAB開(kāi)始NS2模擬:模擬環(huán)境介紹CCU_COMM_ANT LABNS2模擬:Tcl Script # 產(chǎn)生一個(gè)模擬的物件set ns new Simulator#針對(duì)不同的資料流定義不同的顏色,這是要給NAM用的$ns color 1 Blue$ns color 2 Red#開(kāi)啟一個(gè)NAM trace fileset nf open out.nam w$ns namtrace-all $nf#開(kāi)啟一個(gè)trace f
10、ile,用來(lái)記錄封包傳送的過(guò)程set nd open out.tr w$ns trace-all $ndCCU_COMM_ANT LABNS2模擬:Tcl Script (cont.)#定義一個(gè)結(jié)束的程序proc finish global ns nf nd $ns flush-trace close $nf close $nd #以背景執(zhí)行的方式去執(zhí)行NAM exec nam out.nam & exit 0CCU_COMM_ANT LABNS2模擬:Tcl Script (cont.)#產(chǎn)生四個(gè)網(wǎng)路節(jié)點(diǎn)set n0 $ns nodeset n1 $ns nodeset n2 $ns
11、 nodeset n3 $ns node#把節(jié)點(diǎn)連接起來(lái) $ns duplex-link $n0 $n2 2Mb 10ms DropTail$ns duplex-link $n1 $n2 2Mb 10ms DropTail$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail#設(shè)定ns2到n3之間的Queue Size為10個(gè)封包大小$ns queue-limit $n2 $n3 10CCU_COMM_ANT LABNS2模擬:Tcl Script (cont.)#設(shè)定節(jié)點(diǎn)的位置,這是要給NAM用的$ns duplex-link-op $n0 $n2 orien
12、t right-down$ns duplex-link-op $n1 $n2 orient right-up$ns duplex-link-op $n2 $n3 orient right#觀測(cè)n2到n3之間queue的變化,這是要給NAM用的$ns duplex-link-op $n2 $n3 queuePos 0.5#建立一條TCP的連線set tcp new Agent/TCP # 創(chuàng)造一個(gè)TCP的Agent $ns attach-agent $n0 $tcp # TCP agent 結(jié)合到 node(n0) # 但就此範(fàn)例光是 TCP 無(wú)法產(chǎn)生任何 Traffic, 所以通常我們都會(huì)再建
13、立一些# Application 的 Protocol 於 TCP 上(如 FTP、Telnet) set ftp new Agent/TCP $ns attach-agent $n3 $sinkCCU_COMM_ANT LABNS2模擬:Tcl Script (cont.)#設(shè)定FTP和CBR資料傳送開(kāi)始和結(jié)束時(shí)間$ns at 0.1 $cbr start$ns at 1.0 $ftp start$ns at 4.0 $ftp stop$ns at 4.5 $cbr stop#結(jié)束TCP的連線$ns at 4.5 $ns detach-agent $n0 $tcp#$ns at #在模擬環(huán)境
14、中,5秒後去呼叫finish來(lái)結(jié)束模擬$ns at 5.0 finish“#開(kāi)始執(zhí)行 scheduler.$ns runCCU_COMM_ANT LABNS2模擬:模擬結(jié)果 0.1 1 2 cbr 1000 - 2 1.0 3.1 0 0 0.1 1 2 cbr 1000 - 2 1.0 3.1 0 0 0.108 1 2 cbr 1000 - 2 1.0 3.1 1 1 0.108 1 2 cbr 1000 - 2 1.0 3.1 1 1r 0.114 1 2 cbr 1000 - 2 1.0 3.1 0 0 0.114 2 3 cbr 1000 - 2 1.0 3.1 0 0 0.114
15、2 3 cbr 1000 - 2 1.0 3.1 0 0 0.116 1 2 cbr 1000 - 2 1.0 3.1 2 2 0.116 1 2 cbr 1000 - 2 1.0 3.1 2 2r 0.122 1 2 cbr 1000 - 2 1.0 3.1 1 1 0.122 2 3 cbr 1000 - 2 1.0 3.1 1 1.event time fromtonodepktnodepkttypeflagsizefidsrcaddrdstaddrseqnumpktid一二三四五六七八九十十一十二CCU_COMM_ANT LABawk語(yǔ)言 數(shù)值分析資料列:awk從資料檔上讀取的基本單位
16、,以trace file為例,awk讀入的第一筆資料列為 ” 0.1 1 2 cbr 1000 - 2 1.0 3.1 0 0”第二筆資料列為 “ 0.1 1 2 cbr 1000 - 2 1.0 3.1 0 0”一般而言,一筆資料列相當(dāng)於資料檔上的一行資料。CCU_COMM_ANT LABawk語(yǔ)言 簡(jiǎn)介程式主要節(jié)構(gòu):Pattern1 Actions1 Pattern2 Actions2 Patternx Actionsx 一般常用關(guān)係判斷式來(lái)當(dāng)成Pattern。例如:x 3 用來(lái)判斷變數(shù)x是否大於3x = 5 用來(lái)判斷變數(shù)x是否等於5awk提供c語(yǔ)言常見(jiàn)的關(guān)係運(yùn)算元,如:、!等等Actio
17、ns是由許多awk指令所構(gòu)成,而awk的指令與c語(yǔ)言中的指令非常類似 。IO指令:print 、 printf( ) 、getline .流程控制指令 : if ( .) . else 、 while() CCU_COMM_ANT LABawk語(yǔ)言 執(zhí)行流程執(zhí)行awk時(shí), 它會(huì)反複進(jìn)行下列四步驟 自動(dòng)從指定的資料檔中讀取一筆資料列。自動(dòng)更新(Update)相關(guān)的內(nèi)建變數(shù)之值。逐次執(zhí)行程式中 所有 的 Pattern Actions 指令。當(dāng)執(zhí)行完程式中所有 Pattern Actions 時(shí),若資料檔中還有未讀取的料,則反覆執(zhí)行步驟1到步驟4。CCU_COMM_ANT LABawk語(yǔ)言 例子B
18、EGIN #程式初始化,設(shè)定一變數(shù)以記錄目前最高處理封包的ID。 highest_packet_id = 0; action = $1; time = $2; node_1 = $3; node_2 = $4; type = $5; flow_id = $8; node_1_address = $9; node_2_address = $10; seq_no = $11; packet_id = $12; CCU_COMM_ANT LABawk語(yǔ)言 例子 (cont.)#記錄封包的傳送時(shí)間 if ( start_timepacket_id = 0 ) start_timepacket_id = time;#記錄CBR (flow_id=2) 的接收時(shí)間 if ( flow_id = 2 & action != d
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 濃硝酸工安全應(yīng)急能力考核試卷含答案
- 2025年三峽電力職業(yè)學(xué)院?jiǎn)握校ㄓ?jì)算機(jī))測(cè)試備考題庫(kù)附答案
- 2025安徽蕪湖鳩江區(qū)村級(jí)后備干部集中招錄工作87人備考題庫(kù)附答案
- 電池制液工持續(xù)改進(jìn)知識(shí)考核試卷含答案
- 鑄管精整操作工持續(xù)改進(jìn)水平考核試卷含答案
- 電子電氣產(chǎn)品環(huán)境試驗(yàn)檢驗(yàn)員操作評(píng)估模擬考核試卷含答案
- 電纜金屬護(hù)套制造工操作技能水平考核試卷含答案
- 禮儀主持人崗前個(gè)人防護(hù)考核試卷含答案
- 2025年上海紡織工業(yè)職工大學(xué)輔導(dǎo)員考試參考題庫(kù)附答案
- 2024年海南州特崗教師招聘筆試真題題庫(kù)附答案
- 化工廠設(shè)備維護(hù)保養(yǎng)培訓(xùn)
- 福建省網(wǎng)絡(luò)安全事件應(yīng)急預(yù)案
- 五育融合課件
- 意識(shí)障礙的判斷及護(hù)理
- 儲(chǔ)能電站安全管理與操作規(guī)程
- 2025年宿遷市泗陽(yáng)縣保安員招聘考試題庫(kù)附答案解析
- 交通安全企業(yè)培訓(xùn)課件
- 2025年廣東省中考物理試卷及答案
- 皮革項(xiàng)目商業(yè)計(jì)劃書
- 主管護(hù)師護(hù)理學(xué)考試歷年真題試卷及答案
- 華文慕課《刑法學(xué)》總論課后作業(yè)答案
評(píng)論
0/150
提交評(píng)論