Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS-2 網路模擬器介紹與使用 吳賢明國立中興大學 計算機及資訊網路中心中華民國九十三年十月二十七日.

Similar presentations


Presentation on theme: "NS-2 網路模擬器介紹與使用 吳賢明國立中興大學 計算機及資訊網路中心中華民國九十三年十月二十七日."— Presentation transcript:

1 NS-2 網路模擬器介紹與使用 吳賢明國立中興大學 計算機及資訊網路中心中華民國九十三年十月二十七日

2 Agenda 淺談網路模擬 淺談網路模擬 NS2 簡介 NS2 簡介 NS2 架構、安裝與使用 NS2 架構、安裝與使用 視覺化實例演練 視覺化實例演練 Q&A Q&A

3 Methods for network research Analytical Analytical Model Model General expression or close form General expression or close form Emulation Emulation Network testbed Network testbed Lab environment Lab environment Real code Real code Simulation Simulation Virtual network testbed Virtual network testbed

4 Why Simulation Study of implemented protocols and algorithms Study of implemented protocols and algorithms Behavior Behavior Performance Performance Test of unimplemented new protocols and algorithms Test of unimplemented new protocols and algorithms Comparison of results across research efforts Comparison of results across research efforts

5 Simulation -- Advantage Inexpensive, Flexible and Reconfigurable Inexpensive, Flexible and Reconfigurable Network phenomena interested can be reproduced Network phenomena interested can be reproduced Opportunity to study large-scale network Opportunity to study large-scale network Easier comparison of results across research efforts Easier comparison of results across research efforts

6 Simulation -- Disadvantage Important network details may be missed Important network details may be missed Protocols or algorithms must be “added” before simulation can be done Protocols or algorithms must be “added” before simulation can be done High start-up cost High start-up cost Have to be carefully verified before the test results can be used Have to be carefully verified before the test results can be used

7 Network simulators Specific Purpose Specific Purpose ATM ATM Wireless Wireless TCP/IP TCP/IP General Purpose General Purpose Modifiable modules Modifiable modules Modules extensibility Modules extensibility

8 What features should a simulator provide ? Easy network topology setup Easy network topology setup Protocols and application implementation Protocols and application implementation TCP,UDP,… TCP,UDP,… FTP, Telnet, Web, CBR, VBR,… FTP, Telnet, Web, CBR, VBR,… Routing protocols Routing protocols Queue management protocols Queue management protocols Configurability Configurability Extensibility Extensibility

9 Agenda 淺談網路模擬 淺談網路模擬 NS2 簡介 NS2 簡介 NS2 架構、安裝與使用 NS2 架構、安裝與使用 視覺化實例演練 視覺化實例演練 Q&A Q&A

10 What is NS-2 NEST (Network Simulation Testbed)  REAL (Realistic and Large)  NS-1  NS-2 NEST (Network Simulation Testbed)  REAL (Realistic and Large)  NS-1  NS-2 NS-2 is a common network simulator NS-2 is a common network simulator NS-2 is developed by the VINT project in order to reduce duplication of effort within the network research and develop community NS-2 is developed by the VINT project in order to reduce duplication of effort within the network research and develop community NS2 is publicly available at NS2 is publicly available at

11 About NS2 1989: REAL network simulator 1989: REAL network simulatorREAL network simulatorREAL network simulator 1995: DARPA VINT project at LBL, Xerox PARC, UCB, and USC/ISI 1995: DARPA VINT project at LBL, Xerox PARC, UCB, and USC/ISIVINT projectVINT project Present: DARPA SAMAN project and NSF CONSER project Present: DARPA SAMAN project and NSF CONSER projectSAMAN CONSERSAMAN CONSER Collaboration with other researchers including CIRI Collaboration with other researchers including CIRI CIRI

12 Ns Status Periodical release (ns-2.27, Jan 2004) Periodical release (ns-2.27, Jan 2004) ~200K LOC in C++ and Otcl, ~200K LOC in C++ and Otcl, ~120 test suites and 100+ examples ~120 test suites and 100+ examples 392 pages of ns manual 392 pages of ns manual Daily snapshot (with auto-validation) Daily snapshot (with auto-validation) Stability validation Stability validation Platform support Platform support FreeBSD, Linux, Solaris, Windows and Mac FreeBSD, Linux, Solaris, Windows and Mac User base User base > 1k institutes (50 countries), >10k users > 1k institutes (50 countries), >10k users About 300 posts to every month About 300 posts to every

13 Ns functionalities Wired Wired Transportation: TCP,UDP,RTP,SRM Transportation: TCP,UDP,RTP,SRM Traffic sources:web, ftp, telnet, cbr, stochastic Traffic sources:web, ftp, telnet, cbr, stochastic Queuing disciplines:drop-tail, RED, FQ, SFQ, DRR Queuing disciplines:drop-tail, RED, FQ, SFQ, DRR QoS: IntServ and Diffserv QoS: IntServ and Diffserv Emulation Emulation Wireless Wireless Ad hoc routing and mobile IP Ad hoc routing and mobile IP Directed diffusion, sensor-MAC Directed diffusion, sensor-MAC Tracing, visualization, various utilities Tracing, visualization, various utilities

14 “ Ns ” Components Ns, the simulator itself Ns, the simulator itself Nam, the network animator Nam, the network animator Visualize ns (or other) output Visualize ns (or other) output Nam editor: GUI interface to generate ns scripts Nam editor: GUI interface to generate ns scripts Pre-processing: Pre-processing: Traffic and topology generators Traffic and topology generators Post-processing: Post-processing: Simple trace analysis, often in Awk, Perl, or Tcl Simple trace analysis, often in Awk, Perl, or Tcl

15 Ns Models Traffic models and applications: Traffic models and applications: Web, FTP, telnet, constant-bit rate, real audio Web, FTP, telnet, constant-bit rate, real audio Transport protocols: Transport protocols: unicast: TCP (Reno, Vegas, etc.), UDP unicast: TCP (Reno, Vegas, etc.), UDP Multicast: SRM Multicast: SRM Routing and queueing: Routing and queueing: Wired routing, ad hoc rtg and directed diffusion Wired routing, ad hoc rtg and directed diffusion queueing protocols: RED, drop-tail, etc queueing protocols: RED, drop-tail, etc Physical media: Physical media: Wired (point-to-point, LANs), wireless (multiple propagation models), satellite Wired (point-to-point, LANs), wireless (multiple propagation models), satellite

16 Agenda 淺談網路模擬 淺談網路模擬 NS2 簡介 NS2 簡介 NS2 架構、安裝與使用 NS2 架構、安裝與使用 視覺化實例演練 視覺化實例演練 Q&A Q&A

17 NS Architecture Split-Programming Model Split-Programming Model C++ C++ implement the simulation model implement the simulation model Implement data path Implement data path per packet processing, core of ns per packet processing, core of ns fast to run, detailed, complete control fast to run, detailed, complete control OTcl (Tcl script language with Object-oriented extensions developed at MIT ) OTcl (Tcl script language with Object-oriented extensions developed at MIT ) Simulation scenario configurations Simulation scenario configurations Periodic or triggered action Periodic or triggered action Manipulating existing C++ objects Manipulating existing C++ objects fast to write and change fast to write and change

18 NS Architecture Advantage Advantage Reusability Reusability Maintenance Maintenance Disadvantage Disadvantage Performance (speed and memory) Performance (speed and memory) Careful planning of modularity Careful planning of modularity

19 User ’ s view of NS2

20 Architecture view of NS2

21 Resources and Documentations NS2 and related component NS2 and related component Tcl release (required component) Tcl release (required component) Tk release (required component) Tk release (required component) Otcl release 1.8 (required component) Otcl release 1.8 (required component) TclCL release 1.15 (required component) TclCL release 1.15 (required component) Ns release 2.27 (required component) Ns release 2.27 (required component) Nam release 1.10 (optional component) Nam release 1.10 (optional component) Xgraph version 12 (optional component) Xgraph version 12 (optional component) CWeb version 3.4g (optional component) CWeb version 3.4g (optional component) SGB version 1.0 (?) (optional component, builds sgblib for all UNIX type platforms) SGB version 1.0 (?) (optional component, builds sgblib for all UNIX type platforms) Gt-itm gt-itm and sgb2ns 1.1 (optional component) Gt-itm gt-itm and sgb2ns 1.1 (optional component) Zlib version (optional, but required should Nam be used) Zlib version (optional, but required should Nam be used)

22 Resources and Documentation Getting the pieces Getting the pieces Tcl/TK 8.x (Tcl tk-8.4.5): Tcl/TK 8.x (Tcl tk-8.4.5): Otcl(1.8) and TclCL(1.15): Otcl(1.8) and TclCL(1.15): = =30174 ns-2 and nam-1: ns-2 and nam-1: All-at-once All-at-once

23 Resources and Documents Ns and nam build questions Ns and nam build questions Ns mailing list: Ns mailing list: Ns manual and tutorial (in distribution) Ns manual and tutorial (in distribution) TCL: TCL: Otcl tutorial (in distribution): ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html Otcl tutorial (in distribution): ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html

24 Running ns-2 for Windows 9x/2000/XP under Cygwin Cygwin Cygwin Cygwin is a Linux-like environment for Windows Cygwin is a Linux-like environment for Windows ns-2 supports Cygwin ns-2 supports Cygwin Get Cygwin from Get Cygwin from ns-2 installation ns-2 installation From all pieces From all pieces All-at-once All-at-once

25 Cygwin Installation

26 ns-2 installation Get the file : tar.gz Get the file : tar.gzhttp://www.isi.edu/nsnam/dist/ns-allinone tar.gzhttp://www.isi.edu/nsnam/dist/ns-allinone tar.gz Install files Install files #tar zxvf ns-allinone-2.27.tar.gz ns-allinone-2.27.tar.gz #cd ns-allinone-2.27 #install Configure system Configure system Update user environment (~/.bashrc) Update user environment (~/.bashrc) export NS_HOME=/home/XXX/ns-allinone-2.27/ export PATH=$NS_HOME/tcl8.4.5/unix:$NS_HOME/tk8.4.5/unix:$NS_HOME/bin:$PATH export LD_LIBRARY_PATH=$NS_HOME/tcl8.4.5/unix:$NS_HOME/tk8.4.5/unix:\ $NS_HOME/otcl-1.8:$NS_HOME/lib:$LD_LIBRARY_PATH export TCL_LIBRARY=$NS_HOME/tcl8.4.5/library For detail, ref to : For detail, ref to :

27 ns-2 Directory Structure examples C++ source codes validation test Otcl source OTcl code

28 Tcl Basic – Hello World #Define a process named "helloworld" proc helloworld {} { puts "Hello world!!!" puts "Hello world!!!"} # Call the process helloworld Helloworld

29 Tcl Basic – Another Example proc pow {x n} { if {$n == 1} { return $x } if {$n == 1} { return $x } set part [pow $x [expr $n-1]] set part [pow $x [expr $n-1]] return [expr $x*$part] return [expr $x*$part]} set x 10 puts "x is $x" set y [pow $x 2] puts "y is $y" while { $x > 0 } { puts $x puts $x incr x -1 incr x -1}

30 OTcl - An Example from:http://nile.wpi.edu/NS/ # Create a class call "mom" and # add a member function call "greet" Class mom mom instproc greet {} { $self instvar age_ $self instvar age_ puts "$age_ years old mom say: puts "$age_ years old mom say: How are you doing?" How are you doing?"} # Create a child class of "mom" called "kid" # and overide the member function "greet" Class kid -superclass mom kid instproc greet {} { $self instvar age_ $self instvar age_ puts "$age_ years old kid say: puts "$age_ years old kid say: What's up, dude?" What's up, dude?"} # Create a mom and a kid object set each age set a [new mom] $a set age_ 45 set b [new kid] $b set age_ 15 # Calling member function "greet" of each object $a greet $b greet

31 Agenda 淺談網路模擬 淺談網路模擬 NS2 簡介 NS2 簡介 NS2 架構、安裝與使用 NS2 架構、安裝與使用 視覺化實例演練 視覺化實例演練 Q&A Q&A

32 Using ns Problem Simulation model Setup/run simulation with ns Result analysis Modify ns

33 TCP congestion control

34 Connection Initialization SSTHRESH Reached Slow Start Congestion Avoidance Fast Retransmission Congestion Notified Retransmit Timeout Exponential Backoff Timeout Again Congestion Window Reduced to 1

35 Simple Simulation Example I Display Result with nam Animation n0n1 tcp FTP sink FTP sec 1.7 mbps, 20 ms n2 2 mbps, 10 ms

36 #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf global ns nf $ns flush-trace $ns flush-trace #Close the NAM trace file #Close the NAM trace file close $nf close $nf #Execute NAM on the trace file #Execute NAM on the trace file exec nam out.nam & exec nam out.nam & exit 0 exit 0} #Create three nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n1 1.7Mb 20ms DropTail $ns duplex-link $n2 $n0 2Mb 10ms DropTail #Set Queue Size of link (n0-n1) to 5 $ns queue-limit $n0 $n1 5 #Give node position (for NAM) $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n2 $n0 orient right #Monitor the queue for link (n0-n1). (for NAM) $ns duplex-link-op $n0 $n1 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP] $tcp set class_ 2 $ns attach-agent $n2 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Schedule events for the FTP agents $ns at 0.5 "$ftp start" $ns at 3.0 "$ftp stop" #Call the finish procedure after 4 seconds of #simulation time $ns at 4.0 "finish" #Run the simulation $ns run Source of Example I

37 Simple Simulation Example II Display Result with nam Animation n0n1 tcp1 FTP1 sink1 FTP sec tcp2 FTP2 sink2 n2 n3 3.5 FTP2 2 mbps, 20 ms 2 mbps, 10 ms

38 ….. #Create four nodes …. #Create links between the nodes …. #Set Queue Size of link (n0-n1) to 5 …. #Give node position (for NAM) …. #Monitor the queue for link (n0-n1). (for NAM) …. #Setup a TCP connection set tcp1 [new Agent/TCP] set tcp2 [new Agent/TCP] $tcp1 set class_ 2 $tcp2 set class_ 2 $ns attach-agent $n2 $tcp1 $ns attach-agent $n3 $tcp2 set sink1 [new Agent/TCPSink] set sink2 [new Agent/TCPSink] $ns attach-agent $n1 $sink1 $ns attach-agent $n1 $sink2 $ns connect $tcp1 $sink1 $ns connect $tcp2 $sink2 $tcp1 set fid_ 1 $tcp2 set fid_ 2 #Setup two FTP over TCP connection set ftp1 [new Application/FTP] set ftp2 [new Application/FTP] $ftp1 attach-agent $tcp1 $ftp2 attach-agent $tcp2 $ftp1 set type_ FTP $ftp2 set type_ FTP #Schedule events for the FTP agents $ns at 0 "$ftp2 start" $ns at 0.5 "$ftp1 start" $ns at 3.0 "$ftp1 stop" $ns at 3.5 "$ftp2 stop" #Call the finish procedure after 4 seconds of #simulation time $ns at 4.0 "finish" #Run the simulation $ns run Source of Example II

39 Simple Simulation Example III Display Result with nam Animation n0n1 tcp FTP sink1 ftp sec udp cbr null n2 n3 3.5 cbr 2 mbps, 20 ms 2 mbps, 10 ms Size : 1 kByte Rate: 1 mbps

40 …. #Setup a TCP connection set tcp [new Agent/TCP] $tcp set class_ 2 $ns attach-agent $n2 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n3 $udp set null [new Agent/Null] $ns attach-agent $n1 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false #Schedule events for the CBR and FTP agents $ns at 0 "$cbr start" $ns at 0.5 "$ftp start" $ns at 3.0 "$ftp stop" $ns at 3.5 "$cbr stop" #Call the finish procedure after 4 seconds of #simulation time $ns at 4.0 "finish" #Print CBR packet size and interval puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval_]" #Run the simulation $ns run Source of Example III

41 Trace Analysis Open NAM trace file Open NAM trace file set nam_file_var [open out_nam_file w] $ns namtrace-all $file_var Open raw data trace file Open raw data trace file set data_file_var [open out_data_file w] $ns trace-all $data_file_var

42 NAM trace file example …. V -t * -v 1.0a5 -a 0 A -t * -n 1 -p 0 -o 0xffffffff -c 31 -a 1 A -t * -h 1 -m s 0 c -t * -i 1 -n Blue n -t * -a 0 -s 0 -S UP -v circle -c black -i black n -t * -a 1 -s 1 -S UP -v circle -c black -i black n -t * -a 2 -s 2 -S UP -v circle -c black -i black l -t * -s 0 -d 1 -S UP -r D c black -o right l -t * -s 2 -d 0 -S UP -r D c black -o right q -t * -s 1 -d 0 -a 0.5 q -t * -s 0 -d 1 -a t 0.5 -s 2 -d 0 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} - -t 0.5 -s 2 -d 0 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} h -t 0.5 -s 2 -d 0 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} r -t s 2 -d 0 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} + -t s 0 -d 1 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} - -t s 0 -d 1 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} h -t s 0 -d 1 -p tcp -e 40 -c 1 -i 0 -a 1 -x { null} …. Read and interpreted by NAM for animation display

43 Raw data trace file format and example (from example III) … cbr cbr r cbr cbr cbr r cbr cbr cbr r cbr cbr cbr r cbr …. eventtimefromnodetonodepkttypepktsizeflagsfidsrcaddrdstaddrseqnumpktid r : receive (at to node) +: enqueue (at queue) - : dequeue (at queue) d : drop (at queue) node.port

44 Jitter Monitor

45 RED Queue Monitor Example An example by Polly Huang from r1r2 tcp1 ftp1 sink1 ftp sec tcp2 ftp2 sink2 s1 s2 ftp1 1.5 mbps, 20 ms 10 mbps, 2 ms 10 mbps, 3 ms 0 s3 max_win=15 max_win=15 RED(size=25) 10 mbps, 4 ms

46 .... set tcp1 [$ns create-connection TCP/Reno $node_(s1) TCPSink $node_(s3) 0] $tcp1 set window_ 15 set tcp2 [$ns create-connection TCP/Reno $node_(s2) TCPSink $node_(s3) 1] $tcp2 set window_ 15 set ftp1 [$tcp1 attach-source FTP] set ftp2 [$tcp2 attach-source FTP] # Tracing a queue set redq [[$ns link $node_(r1) $node_(r2)] queue] set tchan_ [open all.q w] $redq trace curq_ $redq trace ave_ $redq attach $tchan_.... proc finish {} { global tchan_ global tchan_ set awkCode { set awkCode {{ if ($1 == "Q" && NF>2) { if ($1 == "Q" && NF>2) { print $2, $3 >> "temp.q"; set end $2 } else if ($1 == "a" && NF>2) else if ($1 == "a" && NF>2) print $2, $3 >> "temp.a"; print $2, $3 >> "temp.a";} } set f [open temp.queue w] puts $f "TitleText: red" puts $f "Device: Postscript" if { [info exists tchan_] } { close $tchan_ } exec rm -f temp.q temp.a exec touch temp.a temp.q exec awk $awkCode all.q puts $f \"queue exec cat temp.q $f puts $f \n\"ave_queue exec cat temp.a $f close $f exec xgraph -bb -tk -x time -y queue temp.queue & exit 0 } $ns run

47 RED Queue Monitor Example

48 More … OTcl linkage (with C++ classes) OTcl linkage (with C++ classes) Variable export Variable export Control command export Control command export Recompilation Recompilation Extend NS-2 Extend NS-2 Modify existed object Modify existed object Add new application Add new application Add new agent Add new agent … NS-2 main page NS-2 main page

49 Q & A


Download ppt "NS-2 網路模擬器介紹與使用 吳賢明國立中興大學 計算機及資訊網路中心中華民國九十三年十月二十七日."

Similar presentations


Ads by Google