View
231
Download
6
Embed Size (px)
Citation preview
1
Network Simulator (NS-2)
2
講義 Network Simulator (NS2)
Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據
3
Part 1: 下載
4
http://www.isi.edu/nsnam/ns
5
Step 1
6
Step 2
ns-allinone-2.33.tar.gz約 50MB UP
7
Part 2: 安裝與測試
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
Directory structure
ns-allinone-2.33
tk8.4 bintcl8.4 ns-2.33 nam-1.12…..
Source node(C++)Execute files
AODV
aodv.cc, aodv.h, aodv_packet.h
10
Overview for NS2 structure
C++ network elem ents
Otcl script ns trace fileuser
perl script results
visualisation tool diagram
nam
generates
uses
nam trace file
11
Part 3: 劇本 1
Base station (original data server)
Mobile host
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
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
$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
執行劇本 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
17
18
Useful additional program
NAM: Viewing network simulation traces and real world packet traces
19
自行撰寫劇本產生器
Network size, Number of nodes, Simulation time
EX: ./scenario_generator 1500 1500 50 300 my_scenario.tcl
PS:這隻程式請自行撰寫,之後會繼續用到且延伸。 由於是產生”文字檔”,所以任何語言且可以。
20
Event-driven for Node
1. Create timer AODV.h AODV.cc
… … E9 E8 E7 E6 E5 E4 E3 E2 E1
Simulation Time
Event 1
21
aodv.h
22
aodv.h
23
aodv.h
24
aodv.cc
25
aodv.cc
26
aodv.cc
27
aodv.h
28
aodv.cc
29
How to compile source code? 1. cd /root/ns-allinone-2.33/ns-2.33 2. make
30
aodv.cc
31
32
aodv.cc
33
34
aodv_packet.h
35
aodv.cc
36
aodv.cc
37
aodv.cc
38
aodv.h
39
aodv.cc
40
Part 4: 數據
41
42
aodv.cc
43
44
aodv.cc
45
46
劇本 2: Measure the Round-Trip Time (RTT)
Base station (original data server)
Mobile host
RTT (ms)
data size (bytes)
100 200 300 400 500 1000
Number of node:20, 50Overall query rate: 5Simulation time: 100