350 likes | 376 Views
Explore the fundamentals of network simulation using NS2, including event-driven simulation, NS2 architecture, and a practical simulation example of a queuing system. Learn about language composition in NS2 and how to set up simulation scenarios efficiently.
E N D
Date : 2010/11/23 Speaker : Chia-Wen Lu NS2
Outline • Network Simulation • Introduction to NS2 • Simple Simulation Example
Outline • Network Simulation • Introduction to NS2 • Simple Simulation Example
Network Simulation (1) • 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)
Network Simulation (3) • Platform: - hardware , software, or hybrid • Developer: - commercial or in-house • Source code: - openor close • Paradigm: -time-dependent/non-time-dependent; time-driven/event-driven
Network Simulation (4) • simulation performance - execution speed - scalability - fidelity - cost • Network Layer - free: NS2, GloMoSim - commercial: Opnet , QualNet
Outline • Network Simulation • Introduction to NS2 • Simple Simulation Example
NS2 • Network Simulator (Version 2) - widely known as NS2 - event driven simulation tool - wired / wireless network, protocols (e.g. routing algorithms, TCP, UDP)
Event-Driven Simulation (1) • 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
Event-Driven Simulation (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
Event-Driven Simulation (3) • Gathering information right after every event execution • Simulation finishes - at a pre-specified time - when there is no more event
A Simulation Example: A Single-Channel Queuing System • Point-to-point wired communication link - a one-way communication
Two-event • Arrival: • - a packet arrival event • Complete: • - a successful packet transmission event
Example of Two-event P1 3 P2 5 P3 6 P1 0 P2 2 P3 4
NS2 Architecture (1) TCL Otcl C++
NS2 Architecture (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
NS2: C++ and OTcl Composition • 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
Three C++ Coding Styles - Styles (1) • Compile and create “prog.exe” - recompile for every minor changes (e.g., number of nodes, link speed)
Three C++ Coding Styles - Styles (2) • C++ coding with input arguments - use parameters input argument - e.g., “prog <num_node> <link_speed>” - what if there are too many parameters?
Three C++ Coding Styles - Styles (3) • 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”
NS2 process • Start from Tcl simulation script • For each line: - execution path: Tcl -> Otcl -> C++ - returning path: C++ -> OTcl -> Tcl (next line)
Outline • Network Simulation • Introduction to NS2 • Simple Simulation Example
(Cont.) • 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
(Cont.) # 產生一個模擬的物件 set ns [new Simulator] #產生傳輸節點(n0,n1) set n0 [$ns node] set n1 [$ns node] #產生路由器節點(n2) set n2 [$ns node] #產生資料接收節點(n3) set n3 [$ns node]
(Cont.) #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
(Cont.) # 建立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
(Cont.) #在UDP連線之上建立CBR應用程式 set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR
(Cont.) #設定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"
(Cont.) #執行模擬 $ns run
Reference • Introduction to Network Simulator NS2 by T. Issariyakul and E. Hossain. • http://www.ns2ultimate.com/ • http://www.ece.ubc.ca/~teerawat/NS2.htm