470 likes | 711 Views
Network Simulator (NS-2). 講義. Network Simulator (NS2) Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據. Part 1: 下載. http://www.isi.edu/nsnam/ns. Step 1. ns-allinone-2.33.tar.gz. 約 50MB UP. Step 2. Part 2: 安裝與測試. Setup for Linux-based systems If the file is put at /root
E N D
講義 • Network Simulator (NS2) • Part 1: 下載 • Part 2: 安裝與測試 • Part 3: 劇本 • Part 4: 數據
ns-allinone-2.33.tar.gz 約50MB UP Step 2
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
Directory structure ns-allinone-2.33 ….. tcl8.4 tk8.4 bin ns-2.33 nam-1.12 Source node (C++) Execute files AODV aodv.cc, aodv.h, aodv_packet.h
Part 3: 劇本1 Base station (original data server) Mobile host
BS_MH_1.tcl • 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
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
$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
執行劇本 • 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
Useful additional program • NAM: Viewing network simulation traces and real world packet traces
自行撰寫劇本產生器 • Network size, Number of nodes, Simulation time • EX: ./scenario_generator 1500 1500 50 300 my_scenario.tcl • PS:這隻程式請自行撰寫,之後會繼續用到且延伸。 • 由於是產生”文字檔”,所以任何語言且可以。
Event-driven for Node • 1. Create timer • AODV.h • AODV.cc Event 1 Simulation Time
How to compile source code? • 1. cd /root/ns-allinone-2.33/ns-2.33 • 2. make
劇本2: Measure the Round-Trip Time (RTT) Base station (original data server) Mobile host RTT (ms) Number of node:20, 50 Overall query rate: 5 Simulation time: 100 1000 100 200 300 400 500 data size (bytes)