35
Date : 2010/11/23 Speaker : Chia-Wen Lu 1

Date : 2010/11/23 Speaker : Chia-Wen Lu 1. Network Simulation Introduction to NS2 Simple Simulation Example 2

Embed Size (px)

Citation preview

Page 1: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Date : 2010/11/23Speaker : Chia-Wen Lu

1

Page 2: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Network SimulationIntroduction to NS2Simple Simulation Example

2

Page 3: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Network SimulationIntroduction to NS2Simple Simulation Example

3

Page 4: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Suppose you devise a great protocol. How do you show that it’s great?

- Experiment

- Mathematical model - graph theory

- Simulation - programming (e.g., C++ or NS2)

4

Page 5: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

advantage disadvantageExperiment •realistic •expensive

•sometime not possible

Mathematical model

•insight •assumptions

Simulation •easy (cheap)•verification

•not much insight•assumptions

5

Page 6: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Platform: - hardware , software, or hybrid Developer: - commercial or in-house Source code: - open or close Paradigm: - time-dependent/non-time-dependent; time-driven/event-driven

6

Page 7: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

simulation performance

- execution speed

- scalability

- fidelity

- cost Network Layer

- free: NS2, GloMoSim

- commercial: Opnet , QualNet7

Page 8: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Network SimulationIntroduction to NS2Simple Simulation Example

8

Page 9: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Network Simulator (Version 2)

- widely known as NS2

- event driven simulation tool

- wired / wireless network, protocols

(e.g. routing algorithms, TCP, UDP)

9

Page 10: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

11

Events a, b, and c are executed in order

- example program 1 initialize {system states} 2 initialize {list of events} 3 while {state != finalState} % or while {this.event != Null} 4 expunge the previous event from list of events; 5 set SimClock := time of current event; 6 execute this.event 7 end while

Page 11: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Run by a set of events (schedule list)

Time gap between two events is not fixed

Simulation advance from one event to another

Event may induce one or more events

new event is usually inserted into the list

12

Page 12: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Gathering information right after every event execution Simulation finishes

- at a pre-specified time

- when there is no more event

13

Page 13: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Point-to-point wired communication link

- a one-way communication

14

Page 14: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

15

Arrival: - a packet arrival eventComplete: - a successful packet transmission event

Page 15: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Packet Servicetime

Arrivaltime

Completetime

P1 3 0 3

P2 2 2 5

P3 1 4 6

16

P1 0

P2 2

P3 4

P1 3

P2 5

P3 6

Page 16: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

17

Page 17: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

two key languages C++

- defines the internal mechanism of the simulation Objects

Otcl (Object-oriented Tool Command Language ) - sets up simulation scenarios

Linked together using TclCL

18

Page 18: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

19

Page 19: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Two language architecture: C++ and OTcl C++

- compiler - fast to run (run on machine codes) - slow to change (need compilation)

OTcl - interpreter - slow to run; fast to change

Why two languages? C++ coding styles

20

Page 20: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Compile and create “prog.exe” - recompile for every minor changes (e.g., number of nodes, link speed)

21

Page 21: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

C++ coding with input arguments - use parameters input argument - e.g., “prog <num_node> <link_speed>” - what if there are too many parameters?

22

Page 22: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

C++ coding with input files - put input parameters in a configuration file - no need to change C++ code - one input argument—the filename - NS2 style!! - configuration file is called “Tcl Simulation script”

23

Page 23: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Start from Tcl simulation script For each line: - execution path: Tcl -> Otcl -> C++ - returning path: C++ -> OTcl -> Tcl (next line)

24

Page 24: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Network SimulationIntroduction to NS2Simple Simulation Example

25

Page 25: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

26

Page 26: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

4 nodes : n0, n1, n2, n3

n0 and n2 =>2 Mbps 頻寬 ,10 ms 傳遞延遲時間 n1 and n2 =>2 Mbps 頻寬 ,10 ms 傳遞延遲時間

n2 and n3 =>1.7 Mbps 頻寬 ,20 ms 傳遞延遲時間

FTP session is based on TCP

CBR session is based on UDP

27

Page 27: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

# 產生一個模擬的物件set ns [new Simulator]#產生傳輸節點 (n0,n1)set n0 [$ns node]set n1 [$ns node]#產生路由器節點 (n2)set n2 [$ns node]#產生資料接收節點 (n3)set n3 [$ns node]

28

Page 28: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

#n0-n2 ,2Mbps 頻寬 ,10ms 傳遞延遲時間$ns duplex-link $n0 $n2 2Mb 10ms DropTail

#n1-n2,2Mbps 頻寬 ,10ms 傳遞延遲時間$ns duplex-link $n1 $n2 2Mb 10ms DropTail

#n2-n3, 1.7Mbps 頻寬 ,20ms 傳遞延遲時間$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

29

Page 29: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

# 建立 UDP 連線 (n1 到 n3)

set udp [new Agent/mUDP]$ns attach-agent $n1 $udpset null [new Agent/mUdpSink]$ns attach-agent $n3 $null$ns connect $udp $null

30

Page 30: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

# 在 UDP 連線之上建立 CBR 應用程式

set cbr [new Application/Traffic/CBR]$cbr attach-agent $udp$cbr set type_ CBR

31

Page 31: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

# 設定 FTP 和 CBR 資料傳送開始和結束時間

$ns at 0.1 "$cbr start"$ns at 1.0 "$ftp start"$ns at 4.0 "$ftp stop"$ns at 4.5 "$cbr stop"

32

Page 32: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

# 執行模擬$ns run

33

Page 33: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

34

Page 34: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Introduction to Network Simulator NS2 by T. Issariyakul and E. Hossain.

http://www.ns2ultimate.com/ http://www.ece.ubc.ca/~teerawat/NS2.htm

35

Page 35: Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2

Q & A

36