ns2 (network simulator version 2)

Post on 30-Dec-2015

85 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

NS2 (Network Simulator version 2). 國立中正大學資訊工程研究所 無線暨行動通訊研究室 報告人:江昭佑 指導教授:陳裕賢 副教授 日期: 92 年 11 月 19 日. Outline. Introduction and the elements of ns2 Overview Tcl Script Overview nam Animation How to analyze the performance of protocols How to run wireless simulations in ns - PowerPoint PPT Presentation

TRANSCRIPT

無線暨行動通訊實驗室 1

NS2 (Network Simulator version 2)

國立中正大學資訊工程研究所無線暨行動通訊研究室

報告人:江昭佑指導教授:陳裕賢 副教授日期: 92 年 11 月 19 日

無線暨行動通訊實驗室 2

Outline

Introduction and the elements of ns2 Overview Tcl Script Overview nam Animation How to analyze the performance of protocols How to run wireless simulations in ns

Generating node-movement and traffic-connection files for large wireless scenarios

Homework

無線暨行動通訊實驗室 3

Introduction and the elements of ns2

無線暨行動通訊實驗室 4

Introduction

1. 在 1.0 秒時 , 假設 A 點送出了一個封包; 2. 在 1.005 秒時 , A 點上的網路卡開始解析封包 , 並進行傳送; 3. 在 1.006 秒時 , B 點收到了 A 點送過來的封包; 4. 在 1.1 秒時 , B 點的網路卡解析封包 , 並送給 B 點的應用程

NS is a discrete event simulator targeted at networking research

無線暨行動通訊實驗室 5

The elements of NS2

OTcl (version 1.0a8) Tcl (version 8.3.2) Tk (version 8.3.2) Nam (version 1.9) Tclcl (version 1.0b13) Xgraph (version 12.1)

無線暨行動通訊實驗室 6

Simplified User’s View of NS

無線暨行動通訊實驗室 7

C++ and OTcl

無線暨行動通訊實驗室 8

Architectural View of NS

無線暨行動通訊實驗室 9

The Procedure of using NS2

無線暨行動通訊實驗室 10

Overview Tcl Script

無線暨行動通訊實驗室 11

What is Tcl/Tk Tcl/Tk 是什麼

Tcl/Tk 是一個跨平臺 (cross-platform)﹑ 可擴充 (extensible) 的高階 scripting 語言 , 可用以發展 GUI 應用程式

還有那些具有相近優點的語言可以考慮 Java, Perl/Tk, Python/Tk, Guile/Tk

Tcl/Tk 的優缺點 基本功能簡單易上手;程式囉嗦 沒有複雜的資料結構 incr Tcl 可提供物件導向功能,但受限於語言基本架構,很難

把所有重要物件導向功能完整表達 . Tk 提供的功能幾乎已成為所有此類 ( 跨平臺 , 可擴充 ) 語

言的標準 GUI 元件。也可以 ( 不太精確地 ) 說: Tk 語言不僅跨平臺, Tk 的觀念與術語甚至跨程式語言,對於程式設計師而言,是具有前瞻性,值得長期投資心力學習的工具 (Tool Kit)

無線暨行動通訊實驗室 12

Introduction of OTcl syntax(set variable number)

# 設定 x 變數, x 值為 100( 注意這 100 是字串 ) set x 100

# 設定 y 變數, y 值為 200 set y 200

# 透過 expr 將 $x $y 當成數字作數學運算 , 並設定 z 變數為 300 set z [expr $x+$y]

# 設定 a = b = 100 set a [set b 100]

# 設定一個陣列叫 array_, 並把 array_(1) 的值設為 27 set array_(1) 21

無線暨行動通訊實驗室 13

Introduction of OTcl syntax(if-else)

if 的範例 範例說明 : 如果變數 k 大於 4, 則顯示出 “ k > 4”, 反之則顯示 “ k < =4 ” ,要注意的是 if 後面接的是大括號 “ {” ,不同於我們在 C 語言中所寫的 “ (” 。

if { $k>4 } { puts " k > 4 " } else { puts " k < = 4 " }

while 的範例 範例說明:下面程式,代表一個 while 如在 i 大於等於 0 的情況下,則將 b 的值和 i 相加並再回傳給 b ,然後 i 再減 1

set b 0 set i 100 while {$i > = 0} { set b [expr $b+$i] incr i -1 } for 的範例 for {set i 100} {$i > =0} {incr i -1} { # for 迴圈內所要執行的程式碼 }

無線暨行動通訊實驗室 14

Introduction of OTcl syntax(sub-function)

# 定義一個叫做 show 的 procedure proc show {} { ... # 副程式內容 ... }

# 範例 : ( 計算 x 階乘的 procedure) proc fac {x} { if {$x < 0} { error "Invalid argument $x: must be a positive integer" } elseif {$x < = 1} { return 1 } else { return [expr $x * [fac [expr $x-1]]] } }

無線暨行動通訊實驗室 15

A Sample Tcl Script

無線暨行動通訊實驗室 16

A Sample Tcl Script

無線暨行動通訊實驗室 17

A Sample OTcl Script

無線暨行動通訊實驗室 18

A Sample OTcl Script

無線暨行動通訊實驗室 19

Overview nam Animation

無線暨行動通訊實驗室 20

Nam tool

Nam is a Tcl/TK based animation tool for viewing network simulation traces and real world packet traces. It supports topology layout, packet level animation, and various data inspection tools.

無線暨行動通訊實驗室 21

Nam environment

無線暨行動通訊實驗室 22

Nam example (Rate-based Pacing Animation )

無線暨行動通訊實驗室 23

Nam example (Rate-based Pacing Animation )

無線暨行動通訊實驗室 24

Xgraph tool

無線暨行動通訊實驗室 25

How to analyze the performance of protocols

無線暨行動通訊實驗室 26

Trace file 假如我們的 tcp script 有做 trace-all 的動作 , 那當

我們執行完 ns2 之後 , 就會產生一個紀錄的檔案 , 而這個檔案主要就是紀錄一些 packet 在我們模擬中的傳輸情況 . 我們可以試著去打開這個檔案來研究看看 , 如下 :

無線暨行動通訊實驗室 27

Definition of flags 1 代表事件的類別

r :代表目的端收到 packet + :代表 packet 放入 queue 中 - :代表 packet 從 queue 中取出 d :代表 queue 已經滿了,這個 packet 被 drop 掉

2 代表事件發生的時間 3 代表 packet 的 source node 4 代表 packet 的 destination node 5 代表 packet 的類別 6 代表 packet 的大小 (encoded in IP header) 7 代表 packet 的 flags 8 代表 connection(flow) 的 id 9 代表 source address ( node.port ) 10 代表 destinations address ( node.port ) 11 代表 packet 的 sequence number ( network layer protocol's ) 12 代表 packet 的 id ( unique )

無線暨行動通訊實驗室 28

How to run wireless simulations in ns

無線暨行動通訊實驗室 29

Tcl program in wireless scenario

set val(chan) Channel/WirelessChannel set val(prop) Propagation/TwoRayGround set val(netif) Phy/WirelessPhy set val(mac) Mac/802_11 set val(ifq) Queue/DropTail/PriQueue set val(ll) LL set val(ant) Antenna/OmniAntenna set val(x) 670 ;# X dimension of the topography set val(y) 670 ;# Y dimension of the topography set val(ifqlen) 50 ;# max packet in ifq set val(seed) 0.0 set val(adhocRouting) DSR set val(nn) 3 ;# how many nodes are simulated set val(cp) "../mobility/scene/cbr-3-test" set val(sc) "../mobility/scene/scen-3-test" set val(stop) 2000.0 ;# simulation time

無線暨行動通訊實驗室 30

Tcl program in wireless scenario

set tracefd [open wireless1-out.tr w] ;# for wireless traces

$ns_ trace-all $tracefd

set namtrace [open wireless1-out.nam w] ;# for nam tracing

$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

無線暨行動通訊實驗室 31

Tcl program in wireless scenario

# # Define node movement model # puts "Loading connection pattern...“source $val(cp) # # Define traffic model # puts "Loading scenario file..." source $val(sc)

無線暨行動通訊實驗室 32

Tcl program in wireless scenario

$ns_ at 50 "$node_(2) setdest 369.4 170.5 3.37“

$god_ set-dist 1 2 2

無線暨行動通訊實驗室 33

Tcl program in wireless scenario

# Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it

according to your # scenario size. # The function must be called after mobility

model is defined $ns_ initial_node_pos $node_($i) 20 }

無線暨行動通訊實驗室 34

Tcl program in wireless scenario

puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"

puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"

puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"

無線暨行動通訊實驗室 35

Tcl program in wireless scenario

ns wireless1.tcl

無線暨行動通訊實驗室 36

Creating random traffic-pattern for wireless scenarios

ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate]

ns cbrgen.tcl -type cbr -nn 10 -seed 1.0 -mc 8 -rate 4.0 > cbr-10-test

無線暨行動通訊實驗室 37

Creating random traffic-pattern for wireless scenarios

./setdest [-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] [-x maxx] [-y maxy] > [outdir/movement-file]

./setdest -n 20 -p 2.0 -s 10.0 -t 200 -x 500 -y 500 >

scen-20-test

無線暨行動通訊實驗室 38

Reference

http://www.isi.edu/nsnam/ns/tutorial/index.html (tutorial for the network simulator)

http://nile.wpi.edu/NS/ (ns by example) http://netlab.cse.yzu.edu.tw/ns2/ns2_websit

e/ (learning ns website)

無線暨行動通訊實驗室 39

Homework

Performance Evaluation of Ad Hoc Routing Protocols using ns2 simulations Dynamic Source Routing (DSR) Ad-Hoc On-Demand Distance Vector Routing

(AODV) Temporally Order Routing Algorithm (TORA) Destination-Sequenced Distance-Vector

(DSDV)

無線暨行動通訊實驗室 40

Simulation model

Traffic models ~/ns/indep-utils/cmu-scen-gen

Mobility models ~ns/indep-utils/cmu-scen-gen/setdest

無線暨行動通訊實驗室 41

Performance Matrics

Packet delivery fraction The ratio of the data packets delivered to the

destinations to those generated by the CBR sources. Average end-to-end delay of data packets

This includes all possible delays caused by buffering during route discovery latency, queuing at the interface queue, retransmission delays at the MAC, and propagation and transfer times.

無線暨行動通訊實驗室 42

Performance Metrics

Normalized routing load The number of routing packets transmitted per data

packet delivered at the destination. Each hop-wise transmission of a routing packet is counted as one transmission.

無線暨行動通訊實驗室 43

Detail of Performance Metrics Evaluating Packet delivery fraction (pdf)

Calculate the number of “sent packets” that have the trace form Calculate the number of “received packets” of the trace form Packet delivery fraction (pdf %) = (received packets / sent

packets) *100 Evaluating Average End-End packet delivery time

For each packet with id of trace level (AGT) and type (CBR), calculate the send(s) time(s) and the receive(r) time(t) and average it

Evaluating Normalized routing load Normalized routing load = (routing packets sent) / receives

無線暨行動通訊實驗室 44

Examples(PDF v.s. Pause time)

Packet Delivery Fraction (PDF)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

Pause time (secs)

Packet

delivery

fra

cti

on

(%

)

AODV, 20 sources

DSR, 20 sources

DSDV, 20 sources

無線暨行動通訊實驗室 45

Examples (Average End-to-End delay v.s. Pause time)

Average End-End delay

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0 10 20 30 40 50 60 70 80 90 100

Pause time (secs)

Ave

rag

e d

elay

(se

cs) AODV, 20 sources

DSR, 20 sources

DSDV, 20 sources

無線暨行動通訊實驗室 46

Basic and Advanced function

Basic Area is 500X500m The number of nodes is 20

Advanced function Comparison of different number of nodes Comparison of different size of area

無線暨行動通訊實驗室 47

~ ~ The End ~ ~

Thank you for your attention to my presentation !

top related