23
NS2 - Overview Ming-Feng Yang

NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

  • View
    226

  • Download
    7

Embed Size (px)

Citation preview

Page 1: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

NS2 - Overview

Ming-Feng Yang

Page 2: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

22

Outline

Introduction

OTcl

Trace File

NAM

Xgraph

Page 3: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

33

Introduction

Why Simulator? 省錢 - 減少測試設備的購置成本 省時 - 加速演算法(協定)的修改調整 可依需求設定在任何的網路環境下來進行模擬

Page 4: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

44

Introduction

NS2 vs. OPNET

NS2 OPNET

作業系統 UNIX/Windows UNIX/Windowsopen source 是 否使用介面 圖形 / 文字 圖形使用對象 主要在研究及學術界 商業性質較高費用需求 否 是

Page 5: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

55

Introduction

Why NS2? 免費 open source - 新增、修改協定容易 研究標準 - 具公信力

Page 6: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

66

Introduction

NS2 源由 全名 - Network Simulator version 2

改版自 REAL network simulator (1989)

由 VINT project ( UCB )所開發 目前由 SAMAN 和 CONSER 負責維護

Page 7: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

77

Introduction

NS2 特性 離散事件模擬( discrete-event )

由事件所驅動,紀錄不同時間不同事件之狀態 物件導向架構( object-oriented )

可重用性( Reusability ) 可維護性( Maintainability ) :

Page 8: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

88

Introduction

NS2 架構

OTcl

TclCL Netw

ork C

omponentsTcl

EventScheduler

C/C++

UI Tcl: Tool Command Language

OTcl: Object-Oriented Tcl

TclCL: C++ and OTcl linkage

Event Scheduler: event-driven

Network Components:

• Agent: TCP 、 UDP…

• Traffic Generator: FTP 、 CBR…

UI: User Interface

Page 9: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

99

Introduction

C++ 處理封包傳送 修改或新增 agents 、 protocols…

不常更動 , 執行速度快

OTcl 處理網路情境( scenario )模擬 運作已編譯過的 C++ 物件 常會更動 , 執行速度較慢( interpreter )

Page 10: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1010

Introduction

OTcl and C++ : The Duality

C++ OTcl

Pure C++objects

Pure OTclobjects

C++/OTcl split objects

ns

OTcl to call C ++ : command(), tcl.result() C++ to call OTcl: tcl.eval()

Page 11: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1111

Introduction

TCP/IP 、 NS2 和 OSI 7-Layer 的大致對應關係

Page 12: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1212

Introduction

NS2 模擬流程修改或新增協定( C++ )

建立網路情境( OTcl )

執行模擬( NS2 )

模擬結果( Trace File )

結果分析( Nam, Xgraph … )

Page 13: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1313

OTcl

variables 設定set x 100

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

# 設定 y 變數, y 值為 200

set z [expr $x+$y]

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

set a [set b 100]

# 設定 a = b = 100

set array_(1) 21

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

Page 14: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1414

OTcl

if 的範例if { $k>4 } {

puts " k > 4 "

}

else {

puts " k < = 4 "

}

# 如果變數 k 大於 4, 則顯示出 "k > 4", 反之則顯示 "k < =4

Page 15: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1515

OTcl

while 的範例set b 0

set i 100

while {$i > = 0} {

set b [expr $b+$i]

incr i -1

}

# 如在 i 大於等於 0 的情況下 , 則將 b 的值和 i 相加並再回傳給 b, 然後 i 再減 1

Page 16: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1616

OTcl

for 的範例for {set i 100} {$i > =0} {incr i -1} {

# for 迴圈內所要執行的程式碼}

procedure 的範例proc show {} {

# 副程式內容 }

# 定義一個叫做 show 的副程式

Page 17: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1717

Trace File

Page 18: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1818

Trace File

Trace File 中各欄位的定義 1 :代表事件的類別

r :代表目的端收到 packet

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

2 :代表事件發生的時間 3 :代表 packet 的 source node

4 :代表 packet 的 destination node

5 :代表 packet 的類別

Page 19: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

1919

Trace File

Trace File 中各欄位的定義( Cont. ) 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 lay

er protocol's )

12 :代表 packet 的 id ( unique )

Page 20: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

2020

NAM

Nam 是一個能將 NS2 模擬結果視覺化顯示出來的工具,它能顯示封包的流向和 Drop 等資訊

執行方式 nam < trace-file >

Page 21: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

2121

NAM

NAM 中有關 Node 的選項: color, shape, label,

label color $node color red

# 設定 node 顏色

$node shape square ( circle, square, and hexagon )# 設定 node 形狀(預設圓形)$node label "Text"

# 設定 node 的標籤$node label-color blue

# 設定 node 標籤的顏色

Page 22: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

2222

NAM

NAM 中有關 Link 的選項: color, label, label col

or$ns duplex-link-op $n1 $n2 color green

# 設定 Link 顏色

$ns duplex-link-op $n1 $n2 label "Text"

# 設定 Link 的標籤$ns duplex-link-op $n1 $n2 label-color blue

# 設定 Link 標籤的顏色

Page 23: NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph

2323

Xgraph

Xgraph 可根據包含 x 軸和 y 軸資訊的檔案,畫出曲線圖

執行方式 xgraph < 檔名 >