Download presentation
Presentation is loading. Please wait.
1
1 Network Simulator (NS-2)
2
2 講義 Network Simulator (NS2) Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據
3
3 Part 1: 下載
4
4 http://www.isi.edu/nsnam/ns
5
5 Step 1
6
6 Step 2 ns-allinone-2.33.tar.gz 約 50MB UP
7
7 Part 2: 安裝與測試
8
8 Setup for Linux-based systems If the file is put at /root Step 1: cd /root Step 2: tar zxvf ns-allinone-2.33.tar.gz Step 3: cd /root/ns-allinone-2.33 Step 4:./install Setup for windows-based systems 安裝流程 http://140.116.72.80/~smallko/ns2/setup.htm 中文教學網站 - 柯志亨 (Chih-Heng, Ke) http://140.116.72.80/~smallko/ns2/ns2.htm
9
9 Directory structure ns-allinone-2.33 tk8.4 bin tcl8.4 ns-2.33nam-1.12 ….. Source node (C++) Execute files AODV aodv.cc, aodv.h, aodv_packet.h
10
10 Overview for NS2 structure
11
11 Part 3: 劇本 1 Base station (original data server) Mobile host
12
12 set ns_ [new Simulator] set tracefd [open Trace w] $ns_ trace-all $tracefd set nf [open BS_MH_nam w] $ns_ namtrace-all-wireless $nf 1550 1550 set topo [new Topography] $topo load_flatgrid 1550 1550 create-god 3 $ns_ node-config -adhocRouting AODV \ -llType LL \ -macType Mac/802_11 \ -ifqType Queue/DropTail/PriQueue \ -ifqLen 50 \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF BS_MH_1.tcl
13
13 for {set i 0} {$i < 3 } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 } set udp0 [new Agent/UDP] set null0 [new Agent/Null] $ns_ attach-agent $node_(1) $udp0 $ns_ attach-agent $node_(2) $null0 $ns_ connect $udp0 $null0 set cbr0 [new Application/Traffic/CBR] $cbr0 set type_ CBR $cbr0 set packet_size_ 500 $cbr0 set interval_ 0.5 $cbr0 attach-agent $udp0
14
14 $node_(0) set X_ 1 $node_(0) set Y_ 1 $ns_ at 0 "$node_(0) setdest 1 1 1" $node_(1) set X_ 500 $node_(1) set Y_ 500 $ns_ at 0 "$node_(1) setdest 500 500 1" $node_(2) set X_ 500 $node_(2) set Y_ 400 $ns_ at 0 "$node_(2) setdest 500 400 1" $ns_ at 100 "$cbr0 start" $ns_ at 100 "$cbr0 stop" $ns_ at 100 "stop" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd exit 0 } $ns_ run
15
15 執行劇本 Step 1: cd /root/ns-allinone-2.33 Step 2: cd bin Step 3:./ns my_scenario.tcl Option Step 4:./nam BS_MH_nam
16
16
17
17
18
18 Useful additional program NAM: Viewing network simulation traces and real world packet traces
19
19 自行撰寫劇本產生器 Network size, Number of nodes, Simulation time EX:./scenario_generator 1500 1500 50 300 my_scenario.tcl PS: 這隻程式請自行撰寫,之後會繼續用到且延伸。 由於是產生 ” 文字檔 ” ,所以任何語言且可以。
20
20 Event-driven for Node 1. Create timer AODV.h AODV.cc ……E9E8E7E6E5E4E3E2E1 Simulation Time Event 1
21
21 aodv.h
22
22 aodv.h
23
23 aodv.h
24
24 aodv.cc
25
25 aodv.cc
26
26 aodv.cc
27
27 aodv.h
28
28 aodv.cc
29
29 How to compile source code? 1. cd /root/ns-allinone-2.33/ns-2.33 2. make
30
30 aodv.cc
31
31
32
32 aodv.cc
33
33
34
34 aodv_packet.h
35
35 aodv.cc
36
36 aodv.cc
37
37 aodv.cc
38
38 aodv.h
39
39 aodv.cc
40
40 Part 4: 數據
41
41
42
42 aodv.cc
43
43
44
44 aodv.cc
45
45
46
46 劇本 2: Measure the Round-Trip Time (RTT) Base station (original data server) Mobile host RTT (ms) data size (bytes) 100 200300400500 1000 Number of node:20, 50 Overall query rate: 5 Simulation time: 100
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.