




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1Network Simulator (NS-2)I-Wei Ting (丁義偉)2009/3/312OutlinelPart 1: IntroductionlPart 2: NS2 directory structurelPart 3: Network Scenario 3A: What is network simulator?lNS is a discrete event simulator targeted at networking research. Ns provides substantial support for simulation of TCP, routing, an
2、d multicast protocols over wired and wireless (local and satellite) networks. lNS began as the REAL network simulator in 1989 and has evolved over the past few years. lIn 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. lIn 1996, the first ver
3、sion of ns2 was release.4Versionlns-2.34 pending lns-2.33 released on March 31, 2008 l.l.lns-2.30 released on Sept 26, 2006 l. lns-2.1b9 released on Sat Apr 13 16:26:33 PDT 2002 l.lns-2.0a1 Wed Nov 6 13:57:31 PST 1996 lv1.0a1 Mon Jul 31 16:05:08 PDT 1995 /nsnam/ns/CHANGES.html5Why w
4、e use it?lNew protocol is not easily implemented in real.l(development, money, time, device, people)lNew protocol is not easily verified in the world.l(mobile IP, ad hocetc, more nodes or network topology)lNew protocol is not easily compared othersl(How to convince other people?)lNetwork Simulator s
5、imulates protocol layersl(physical, datalink, network, transport, applicatoin)6B: Where do I get NS2?/nsnam/ns7Step 18Step 29C: What platforms does NS2 run on and how to install NS2?lOperation systemsl(FreeBSD, Linux, SunOS, Solaris, Windows)lSetup for Linux-based systemlIf the file
6、 is put at /rootlStep 1: cd /rootlStep 2: tar zxvf ns-allinone-2.30.tar.gz lStep 3: cd /root/ns-allinone-2.30lStep 4: ./installlSetup for win9x/2000/XPl中文教學(xué)網(wǎng)站-柯志亨(Chih-Heng, Ke)l0/smallko/ns2/ns2.html安裝流程l0/smallko/ns2/setup.htm註註:在裝在裝cygwin時(shí),要自已勾選全部的套件,以免時(shí),要自已勾選全
7、部的套件,以免lost套件,無法套件,無法compiler過去。過去。10D: Where can I find documentation for NS2? /nsnam/ns/ns-documentation.htmldownload11E: Where are some tutorial I can start from? /nsnam/ns/tutorial/index.html12F: What protocols does NS2 support?lApplication layer: Traffic models
8、 and applicationslWeb, FTP, telnet, constant-bit rate, real audiolTranslation layer: Transport protocolslUnicast: TCP(Reno,Vegas,etc.), UDPlMulticast: SRMlNetwork layer: Routing and queueinglWired routing: Dijkstra,DV lWireless routing: mobile IPlAd hoc routing :DSR,AODV,TORA,DSDVlQueueing protocols
9、: RED, drop-tail, SFQ etclData link layerlEthernet, 802.11lPhysical layerlWired(point-to-point, LANs), wireless (multiple propagation models)1314Part 2: NS2 structurelA: Why use two programming language?lB: Overview for NS2 structurelC: Directory structurelD: How to run a scenario in NS215A: Why usi
10、ng two programming language to implement?l第一:需要一種程式設(shè)計(jì)語言,能夠有效率的處理位元組(Byte),封包標(biāo)頭(Packet Header)等資訊,需要應(yīng)用合適的演算法在大量的資料上。因此,程式內(nèi)部的運(yùn)行速度(run-time speed)就非常重要。(c+)l第二: 許多網(wǎng)路中的研究工作都圍繞著網(wǎng)路元件和環(huán)境參數(shù)的設(shè)置和改變而進(jìn)行的,需要在短時(shí)間內(nèi)快速的開發(fā)和模擬出所需要的網(wǎng)路環(huán)境(scenarios),並且方便修改和發(fā)現(xiàn)、修復(fù)。在這種情形下,(run-around time)就顯得很重要了,因?yàn)槟M環(huán)境的建立和參數(shù)資訊的配置只需要運(yùn)行一次。(O
11、tcl)lNS2 is an object-oriented, discrete event driven network simulator developed at UC Berkely written in C+ and OTcl. lC+ for “data”lPer packet actionlOTcl for “control”lPeriodic or triggered action16B: Overview for NS2 structureC+ network elementsOtcl scriptns trace fileuserperl scriptresultsvisu
12、alisation tooldiagramnamgeneratesusesnam trace file17Event-driven simulatorE9E8E7E6E5E4E3E2E1Simulation TimeEvent 118C: Directory structure (After install)ns-allinone-2.30tk8.4bintcl8.4ns-2.30nam-1.12.Source node(C+)Execute files19D: How to run a scenario in NS2 (linux-based)lStep 1: cd /root/ns-all
13、inone-2.30lStep 2: cd binlStep 3: ./ns my_scenario.tcl2021Part 3: Network ScenariolA: What is network scenario?lB: How to write a simple scenariolC: How to run a scenario in NS2 (linux-based)lD: How to get the trace file?22A: What is network scenario? (人、事、時(shí)、地、物) /nsnam/ns/tutorial/
14、index.html23B: How to write a simple scenario?l1.建立一個(gè)模擬器物件 (Must) set ns new Simulatorset ns new Simulatorl2.開啟一個(gè)nam trace 檔案 (Option) set set nfnf open open out.namout.nam w w $ns $ns namtracenamtrace-all $-all $nfnf l3.宣告一個(gè)finish程序(Must) proc finish global ns nf $ns flush-trace # Close the trace f
15、ile close $nf # Execute nam on the trace file exec nam out.nam & exit 0 24(simulation environment) (simulation environment) l1.建立節(jié)點(diǎn)及其屬性lWired nodelWireless nodelwireless mobile IPlad-hoc networksl2.建立節(jié)點(diǎn)之間的實(shí)體連線及其性質(zhì)l3.建立傳輸?shù)膽?yīng)用程式及其傳輸速率251、建立有線的節(jié)點(diǎn)、建立有線的節(jié)點(diǎn) (Created wired nodes) lset my_node0 $ns nodel
16、set my_node1 $ns node2、建立實(shí)體連線、建立實(shí)體連線 (Created physical link)l$ns duplex-link $n0 $n2 2Mb 10ms SFQl$ns simple-link $n1 $n2 3Mb 2ms REDl雙向、單向,頻寬,延遲時(shí)間,佇列的種類 (DropTail, FQ, SFQ, RED, CBQ)3、設(shè)定佇列的大小、設(shè)定佇列的大小 (set queue length) l $ns queue-limit $my_node0 $my_node1 504、設(shè)定節(jié)點(diǎn)及連線的設(shè)定節(jié)點(diǎn)及連線的label、顏色、顏色(color) (Op
17、tion)$ns duplex-link-op $n0 $n1 color green”$ns duplex-link-op $n0 $n1 label“l(fā)ine1”265、設(shè)定連線的成本、設(shè)定連線的成本 (link cost)6、設(shè)定繞路、設(shè)定繞路(routing)屬性屬性l$ns cost $my_node1 $my_node2 10l$ns cost $my_node0 $my_node2 5l預(yù)設(shè) :static routingl靜態(tài) routing : $ns rtproto Staticl動(dòng)態(tài) routing : $ns rtproto DVl$ns rtproto DV $n1
18、$n2 $n3277、建立、建立UTP連線連線set udp0 new Agent/UDP #建立Agent$ns attach-agent $n0 $udp0#此Agent連於n0節(jié)點(diǎn)上set cbr0 new Application/Traffic/CBR #應(yīng)用程式$cbr0 set packetSize_ 400 #封包大小(bytes)$cbr0 set interval_ 0.25 #設(shè)定傳送的間隔$cbr0 attach-agent $udp0set sink new Agent/LossMonitor #建立接受端$ns attach-agent $n3 $sink #接受端節(jié)
19、點(diǎn)$ns connect $udp0 $sink #將傳送端及接受端連在一起288、建立、建立FTP連線連線set tcp new Agent/TCP #建立TCP連線$ns attach-agent $n0 $tcp #將此TCP連至n0節(jié)點(diǎn) set ftp new Application/FTP #建立一個(gè)FTP應(yīng)用程式 $ftp attach-agent $tcp #將此FTP連至TCP物件set sink new Agent/TCPSink #建立TCP的接受端 $ns attach-agent $n3 $sink #將接受端連至n3節(jié)點(diǎn) $ns connect $tcp $sink
20、#將傳送端及接受端連在一起 29l此部份要安排事件發(fā)生的前後順序 例如:l 第2秒, 節(jié)點(diǎn)開始傳輸封包到節(jié)點(diǎn) 第3秒, 節(jié)點(diǎn)開始傳輸封包到節(jié)點(diǎn) 第17秒, 節(jié)點(diǎn)結(jié)束傳送 第16秒, C節(jié)點(diǎn)結(jié)束傳送(time schedular, event occur) $ns at 2 $cbr0 start $ns at 17 “$cbr0 stop” $ns at 3 $ftp start $ns at 16 “$ftp stop” $ns at 20 finish $ns rtmodel-at 1.0 down $my_node1 $my_node$ns rtmodel-at 2.0 up $my_n
21、ode1 $my_node2l設(shè)定某連線中斷及修復(fù)301. set ns new Simulator2. set nf open out.nam w3. $ns namtrace-all $nf4. proc finish 5. global ns nf6. $ns flush-trace7. close $nf8. exec ./nam out.nam &9. exit 010 11. set n0 $ns node12. set n1 $ns node13. set n2 $ns node14. set n3 $ns node15. $ns duplex-link $n0 $n2
22、2Mb 10ms DropTail16. $ns duplex-link $n1 $n2 2Mb 10ms DropTail17. $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail18. $ns queue-limit $n2 $n3 10(Any Editor: notepad,ultra-editor) (Option)(Option)31 19. set tcp new Agent/TCP 20. $ns attach-agent $n0 $tcp 21. set sink new Agent/TCPSink 22. $ns attach-agent
23、 $n3 $sink 23. $ns connect $tcp $sink 24. set ftp new Application/FTP 25. $ftp attach-agent $tcp 26. set udp new Agent/UDP 27. $ns attach-agent $n1 $udp 28. set null new Agent/LossMonitor 29. $ns attach-agent $n3 $null 30. $ns connect $udp $null 31. set cbr new Application/Traffic/CBR 32. $cbr attac
24、h-agent $udp 33. $cbr set packet_size_ 1000 34. $cbr set interval_ 0.253235. $ns at 0.1 $cbr start36. $ns at 1.0 $ftp start37. $ns at 4.0 $ftp stop38. $ns at 4.5 $cbr stop39. $ns at 5.0 finish40. $ns run33C: How to run a scenario in NS2 (linux-based)lStep 1: cd /root/ns-allinone-2.30lStep 2: cd binl
25、Step 3: ./ns my_scenario.tcl34Useful additional programlNAM: Viewing network simulation traces and real world packet traces3536123456789101112r1.340958 32ack40-23.20.111181+1.340958 20ack40-23.20.111181-1.340958 20ack40-23.20.111181+1.341225 23cbr210-00.03.184166-1.341225 23cbr210-00.03.184166r1.453
26、111 10tcp60-20.13.29781+1.453111 02tcp60-20.13.29781d1.453111 02tcp60-20.13.29781C: How to get the trace file?set my_trace open demo1.tr w$ns trace-all $my_trace37每個(gè)欄位所代表的意義如下: 1.代表事件的類別 r:代表目的端收到packet +:代表 packet 放入 queue 中 -:代表 packet 從 queue 中取出 d:代表 queue 已經(jīng)滿了,這個(gè) packet 被 drop 掉 2.代表事件發(fā)生的時(shí)間 3.代
27、表 packet 的 source node 4.代表 packet 的 destination node 5.代表 packet 的類別 6.代表 packet 的大小 (encoded in IP header) 7.代表 packet 的 flags 8.代表 connection(flow) 的 id 9.代表 source address ( node.port ) 10.代表 destinations address ( node.port ) 11.代表 packet 的 sequence number ( network layer protocols ) 12.代表 pack
28、et 的 id ( unique ) 38lSet f1 open demo1.record wlproc record global null f1set ns Simulator instanceset time 0.1set now $ns nowset bw $null set bytes_ puts $f1 “$now $bw”$null set bytes_ 0$ns at expr $now+$time “record”l$ns at 0.0 “record”lLossMonitorlnlost_ :Number of packets lostlnpkts_ :Number of
29、 packets receivedlbytes_ :Number of bytes receivedllastPktTime_ :Time at which the last packet was receivedlexpected_ :The expected sequence number of the next packet39Network SettinglSender:Node 1, 2, 3lReceiver:Node 7lUsing CBRlPacket Size:1000(k)lTime Interval:1 (s)lSimulation Time:15 (s)40Tcl Co
30、de#Create a simulator objectset ns new Simulator#Define different colors for data flows$ns color 1 Blue$ns color 2 Red$ns color 3 Green#Open the nam trace fileset nf open out.nam w$ns namtrace-all $nf#Open the trace fileset nd open out.tr w$ns trace-all $nd41Tcl Code#Define a finish procedureproc fi
31、nish global ns nd nf $ns flush-trace#Close the trace fileclose $ndclose $nf#Execute nam on the trace file exec nam out.nam & exit 042Tcl Code#Create four nodesset s0 $ns nodeset s1 $ns nodeset s2 $ns nodeset r0 $ns nodeset r1 $ns nodeset r2 $ns nodeset d $ns node#Create links between the nodes$n
32、s duplex-link $s0 $r0 10Mb 10ms DropTail$ns duplex-link $s1 $r0 10Mb 10ms DropTail$ns duplex-link $s2 $r1 10Mb 10ms DropTail$ns duplex-link $r0 $r2 10Mb 10ms DropTail$ns duplex-link $r1 $r2 10Mb 10ms DropTail$ns duplex-link $r2 $d 10Mb 10ms DropTails0s1s2r1r0r2d43Tcl Code#Set position of each node$n
33、s duplex-link-op $s0 $r0 orient right-down$ns duplex-link-op $s1 $r0 orient right-up$ns duplex-link-op $s2 $r1 orient right-up$ns duplex-link-op $r0 $r2 orient right-down$ns duplex-link-op $r1 $r2 orient right-up$ns duplex-link-op $r2 $d orient right#Monitor the queue for the link$ns duplex-link-op
34、$r0 $r2 queuePos 0.5$ns duplex-link-op $r1 $r2 queuePos 0.5$ns duplex-link-op $r2 $d queuePos 0.544Tcl Code#Set flow ID$udp0 set fid_ 1$udp1 set fid_ 2$udp2 set fid_ 3#Schedule events for the CBR agents$ns at 0.0 $cbr0 start$ns at 0.0 $cbr1 start$ns at 0.0 $cbr2 start$ns at 15.0 $cbr0 stop$ns at 15.
35、0 $cbr1 stop$ns at 15.0 $cbr2 stop“#Call the finish procedure after 5 seconds of simulation time$ns at 15.0 finish#Run the simulation$ns run45Simulation46Analyze Resultlout.tr+ 0 1 3 cbr 1000 - 2 1.0 6.1 0 1- 0 1 3 cbr 1000 - 2 1.0 6.1 0 1+ 0 1 3 cbr 1000 - 2 1.0 6.1 1 2+ 0 1 3 cbr 1000 - 2 1.0 6.1
36、2 3+ 0 1 3 cbr 1000 - 2 1.0 6.1 3 4+ 0 1 3 cbr 1000 - 2 1.0 6.1 4 5+ 0 2 4 cbr 1000 - 3 2.0 6.1 0 6- 0 2 4 cbr 1000 - 3 2.0 6.1 0 6+ 0 2 4 cbr 1000 - 3 2.0 6.1 1 7.47Analyze ResultEventTimeFromTo nodePkt nodePkt typeFlags sizeFidSrc addrDst addrSeqNumPkt id+013cbr100021.06.101-013cbr100021.06.101+01
37、3cbr100021.06.112+013cbr100021.06.123+013cbr100021.06.134+013cbr100021.06.145+024cbr100032.06.106-024cbr100032.06.107+024cbr100032.06.118eventr:receive(at to_node)+:enqueue(at queue)-:dequeue(at queue)d:drop (at queue)Src addr:(node).(port)Dst addr:(node).(port)48awk measure delayBEGIN #程式初始化,設(shè)定一變數(shù)以
38、記錄目前最高處理封包的ID。 highest_packet_id = 0; action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; 49awk measure delay#記錄目前最高的packet ID if ( packet_id highest_packet_id ) highest_packet_id = packet_id; #記錄封包的傳送時(shí)間 if ( start_timepacket_id = 0 ) start_timepacket_id = time; #記錄CBR (flow_id=1) 的接收時(shí)間 if ( flow_id = 3 & action != d ) if ( action = r ) end_timepacket_id = time; else #把不是flow_id=2的封包或者是flow_id=2但此封包被drop的時(shí)間設(shè)為-1 end_timepacket_id = -1; 50awk measure delayEND #當(dāng)資料列全部讀取完後,開始計(jì)算有效封包的端點(diǎn)到端點(diǎn)延遲時(shí)間 for ( pack
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年石家莊貨運(yùn)從業(yè)資格考試模擬考試題目及答案
- 茉莉花茶代理合同7篇
- 古箏采購合同范本
- 廠區(qū)道路修路合同范本
- 企業(yè)經(jīng)營貸款服務(wù)合同范本
- 上半年工作總結(jié)開頭
- 儒學(xué)大師邀請(qǐng)合同范本
- 動(dòng)物防疫練習(xí)題庫與答案
- 病理學(xué)與病理生理學(xué)習(xí)題庫與參考答案
- 一年級(jí)法制教育教案
- 礦山機(jī)械傷害安全培訓(xùn)
- 2025貴州省黔東南州直屬事業(yè)單位招聘202人易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 2025年語文高考復(fù)習(xí)計(jì)劃解析
- 新生兒腸道病毒感染
- 2025年度專業(yè)酒店裝修承攬合同
- 2025年度5G基站建設(shè)勞務(wù)合同范本
- (完整版)班主任量化考核細(xì)則
- 2025年中國鐵路鄭州局集團(tuán)有限公司招聘筆試參考題庫含答案解析
- 2025年上半年永春縣農(nóng)文旅發(fā)展集團(tuán)限公司公開招聘若干名工作人員易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 家庭康復(fù)服務(wù)的商業(yè)價(jià)值與發(fā)展趨勢(shì)
- 2025年?;髽I(yè)安全教育培訓(xùn)計(jì)劃
評(píng)論
0/150
提交評(píng)論