Top Banner
1 Network Simulator (NS-2)
46

Network Simulator (NS-2)

Mar 19, 2016

Download

Documents

tadhg

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 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Network Simulator (NS-2)

1

Network Simulator (NS-2)

Page 2: Network Simulator (NS-2)

2

講義 Network Simulator (NS2)

Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據

Page 3: Network Simulator (NS-2)

3

Part 1: 下載

Page 4: Network Simulator (NS-2)

4

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

Page 5: Network Simulator (NS-2)

5

Step 1

Page 6: Network Simulator (NS-2)

6

Step 2

ns-allinone-2.33.tar.gz約 50MB UP

Page 7: Network Simulator (NS-2)

7

Part 2: 安裝與測試

Page 8: Network Simulator (NS-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

Page 9: Network Simulator (NS-2)

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

Page 10: Network Simulator (NS-2)

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

Page 11: Network Simulator (NS-2)

11

Part 3: 劇本 1

Base station (original data server)

Mobile host

Page 12: Network Simulator (NS-2)

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

Page 13: Network Simulator (NS-2)

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

Page 14: Network Simulator (NS-2)

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

Page 15: Network Simulator (NS-2)

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

Page 16: Network Simulator (NS-2)

16

Page 17: Network Simulator (NS-2)

17

Page 18: Network Simulator (NS-2)

18

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

Page 19: Network Simulator (NS-2)

19

自行撰寫劇本產生器 Network size, Number of nodes, Simulation time

EX: ./scenario_generator 1500 1500 50 300 my_scenario.tcl

PS:這隻程式請自行撰寫,之後會繼續用到且延伸。 由於是產生”文字檔”,所以任何語言且可以。

Page 20: Network Simulator (NS-2)

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

Page 21: Network Simulator (NS-2)

21

aodv.h

Page 22: Network Simulator (NS-2)

22

aodv.h

Page 23: Network Simulator (NS-2)

23

aodv.h

Page 24: Network Simulator (NS-2)

24

aodv.cc

Page 25: Network Simulator (NS-2)

25

aodv.cc

Page 26: Network Simulator (NS-2)

26

aodv.cc

Page 27: Network Simulator (NS-2)

27

aodv.h

Page 28: Network Simulator (NS-2)

28

aodv.cc

Page 29: Network Simulator (NS-2)

29

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

Page 30: Network Simulator (NS-2)

30

aodv.cc

Page 31: Network Simulator (NS-2)

31

Page 32: Network Simulator (NS-2)

32

aodv.cc

Page 33: Network Simulator (NS-2)

33

Page 34: Network Simulator (NS-2)

34

aodv_packet.h

Page 35: Network Simulator (NS-2)

35

aodv.cc

Page 36: Network Simulator (NS-2)

36

aodv.cc

Page 37: Network Simulator (NS-2)

37

aodv.cc

Page 38: Network Simulator (NS-2)

38

aodv.h

Page 39: Network Simulator (NS-2)

39

aodv.cc

Page 40: Network Simulator (NS-2)

40

Part 4: 數據

Page 41: Network Simulator (NS-2)

41

Page 42: Network Simulator (NS-2)

42

aodv.cc

Page 43: Network Simulator (NS-2)

43

Page 44: Network Simulator (NS-2)

44

aodv.cc

Page 45: Network Simulator (NS-2)

45

Page 46: Network Simulator (NS-2)

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