Network Simulator NS 2 1 l Network Simulator

  • Slides: 46
Download presentation
Network Simulator (NS 2) 1

Network Simulator (NS 2) 1

講義 l Network Simulator (NS 2) l l Part 1: 下載 Part 2: 安裝與測試

講義 l Network Simulator (NS 2) l l Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據 2

Part 1: 下載 3

Part 1: 下載 3

http: //www. isi. edu/nsnam/ns 4

http: //www. isi. edu/nsnam/ns 4

Step 1 5

Step 1 5

ns-allinone-2. 33. tar. gz 約50 MB UP Step 2 6

ns-allinone-2. 33. tar. gz 約50 MB UP Step 2 6

l Setup for Linux-based systems l If the file is put at /root l

l Setup for Linux-based systems l If the file is put at /root l l l 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 l 安裝流程 l http: //140. 116. 72. 80/~smallko/ns 2/setup. htm § § 中文教學網站-柯志亨(Chih-Heng, Ke) http: //140. 116. 72. 80/~smallko/ns 2. htm 8

Directory structure ns-allinone-2. 33 tcl 8. 4 tk 8. 4 bin Execute files ….

Directory structure ns-allinone-2. 33 tcl 8. 4 tk 8. 4 bin Execute files …. . ns-2. 33 nam-1. 12 Source node (C++) AODV aodv. cc, aodv. h, aodv_packet. h 9

Overview for NS 2 structure 10

Overview for NS 2 structure 10

Part 3: 劇本 1 Base station (original data server) Mobile host 11

Part 3: 劇本 1 Base station (original data server) Mobile host 11

l l l l l l set ns_ [new Simulator] set tracefd [open Trace

l l l l l l set ns_ [new Simulator] set tracefd [open Trace w] $ns_ trace-all $tracefd BS_MH_1. tcl set nf [open BS_MH_nam w] $ns_ namtrace-all-wireless $nf 1550 set topo [new Topography] $topo load_flatgrid 1550 create-god 3 $ns_ node-config -adhoc. Routing AODV -ll. Type LL -mac. Type Mac/802_11 -ifq. Type Queue/Drop. Tail/Pri. Queue -ifq. Len 50 -ant. Type Antenna/Omni. Antenna -prop. Type Propagation/Two. Ray. Ground -phy. Type Phy/Wireless. Phy -channel. Type Channel/Wireless. Channel -topo. Instance $topo -agent. Trace ON -router. Trace ON -mac. Trace OFF -movement. Trace OFF 12

l l l l for {set i 0} {$i < 3 } {incr i}

l l l l for {set i 0} {$i < 3 } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 } set udp 0 [new Agent/UDP] set null 0 [new Agent/Null] $ns_ attach-agent $node_(1) $udp 0 $ns_ attach-agent $node_(2) $null 0 $ns_ connect $udp 0 $null 0 set cbr 0 [new Application/Traffic/CBR] $cbr 0 set type_ CBR $cbr 0 set packet_size_ 500 $cbr 0 set interval_ 0. 5 $cbr 0 attach-agent $udp 0 13

l l l l l $node_(0) set X_ 1 $node_(0) set Y_ 1 $ns_

l l l l l $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 1" $node_(2) set X_ 500 $node_(2) set Y_ 400 $ns_ at 0 "$node_(2) setdest 500 400 1" $ns_ at 100 "$cbr 0 start" $ns_ at 100 "$cbr 0 stop" $ns_ at 100 "stop" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd exit 0 } $ns_ run 14

執行劇本 l Step 1: cd /root/ns-allinone-2. 33 l Step 2: cd bin l Step

執行劇本 l Step 1: cd /root/ns-allinone-2. 33 l Step 2: cd bin l Step 3: . /ns my_scenario. tcl l Option l Step 4: . /nam BS_MH_nam 15

16

16

17

17

Useful additional program l NAM: Viewing network simulation traces and real world packet traces

Useful additional program l NAM: Viewing network simulation traces and real world packet traces 18

自行撰寫劇本產生器 l Network size, Number of nodes, Simulation time l EX: . /scenario_generator 1500

自行撰寫劇本產生器 l Network size, Number of nodes, Simulation time l EX: . /scenario_generator 1500 50 300 my_scenario. tcl l PS: 這隻程式請自行撰寫,之後會繼續用到且延伸。 由於是產生”文字檔”,所以任何語言且可以。 l 19

Event-driven for Node l 1. Create timer l AODV. h l AODV. cc Event

Event-driven for Node l 1. Create timer l AODV. h l AODV. cc Event 1 … … E 9 E 8 E 7 E 6 E 5 E 4 E 3 E 2 E 1 Simulation Time 20

aodv. h 21

aodv. h 21

aodv. h 22

aodv. h 22

aodv. h 23

aodv. h 23

aodv. cc 24

aodv. cc 24

aodv. cc 25

aodv. cc 25

aodv. cc 26

aodv. cc 26

aodv. h 27

aodv. h 27

aodv. cc 28

aodv. cc 28

l l l How to compile source code? 1. cd /root/ns-allinone-2. 33/ns-2. 33 2.

l l l How to compile source code? 1. cd /root/ns-allinone-2. 33/ns-2. 33 2. make 29

aodv. cc 30

aodv. cc 30

31

31

aodv. cc 32

aodv. cc 32

33

33

aodv_packet. h 34

aodv_packet. h 34

aodv. cc 35

aodv. cc 35

aodv. cc 36

aodv. cc 36

aodv. cc 37

aodv. cc 37

aodv. h 38

aodv. h 38

aodv. cc 39

aodv. cc 39

Part 4: 數據 40

Part 4: 數據 40

41

41

aodv. cc 42

aodv. cc 42

43

43

aodv. cc 44

aodv. cc 44

45

45

劇本 2: Measure the Round-Trip Time (RTT) Base station (original data server) Mobile host

劇本 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 200 300 400 500 1000 data size (bytes) 46