NS2

advertisement
Date : 2010/11/23
Speaker : Chia-Wen Lu
1



Network Simulation
Introduction to NS2
Simple Simulation Example
2



Network Simulation
Introduction to NS2
Simple Simulation Example
3

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
Experiment
advantage
disadvantage
•realistic
•expensive
•sometime not
possible
Mathematical model •insight
Simulation
•easy (cheap)
•verification
•assumptions
•not much insight
•assumptions
5
 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
 simulation
performance
- execution speed
- scalability
- fidelity
- cost
 Network Layer
- free: NS2, GloMoSim
- commercial: Opnet , QualNet
7



Network Simulation
Introduction to NS2
Simple Simulation Example
8
 Network
Simulator (Version 2)
- widely known as NS2
- event driven simulation tool
- wired / wireless network, protocols
(e.g. routing algorithms, TCP, UDP)
9
 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
11

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
 Gathering information right after every event execution
 Simulation finishes
- at a pre-specified time
- when there is no more event
13

Point-to-point wired communication link
- a one-way communication
14
Arrival:
- a packet arrival event
Complete:
- a successful packet transmission event
15
P1
3
P1
0
P2
2
P2
5
P3
4
P3
6
Packet
Service
time
Arrival
time
Complete
time
P1
3
0
3
P2
2
2
5
P3
1
4
6
16
17

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
19

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

Compile and create “prog.exe”
- recompile for every minor changes
(e.g., number of nodes, link speed)
21

C++ coding with input arguments
- use parameters input argument
- e.g., “prog <num_node> <link_speed>”
- what if there are too many parameters?
22

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


Start from Tcl simulation script
For each line:
- execution path: Tcl -> Otcl -> C++
- returning path: C++ -> OTcl -> Tcl (next line)
24



Network Simulation
Introduction to NS2
Simple Simulation Example
25
26

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
# 產生一個模擬的物件
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
#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
# 建立UDP連線(n1 到 n3)
set udp [new Agent/mUDP]
$ns attach-agent $n1 $udp
set null [new Agent/mUdpSink]
$ns attach-agent $n3 $null
$ns connect $udp $null
30
#在UDP連線之上建立CBR應用程式
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
31
#設定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
#執行模擬
$ns run
33
34



Introduction to Network Simulator NS2 by T.
Issariyakul and E. Hossain.
http://www.ns2ultimate.com/
http://www.ece.ubc.ca/~teerawat/NS2.htm
35
Q&A
36
Download