Learn about NS-2 directory structure, simulation scenarios, protocols supported, and how to run and write scenarios. NS-2 is a discrete event simulator for networking research.
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Outline • Part 1: Introduction • Part 2: NS2 directory structure • Part 3: Network Scenario
A: What is network simulator? • NS is a discrete event simulator targeted at networking research. Ns provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks. • NS began as the REAL network simulator in 1989 and has evolved over the past few years. • In 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. • In 1996, the first version of ns2 was release.
Version • ns-2.34 pending • ns-2.33 released on March 31, 2008 • .. • .. • ns-2.30 released on Sept 26, 2006 • .. • ns-2.1b9 released on Sat Apr 13 16:26:33 PDT 2002 • .. • ns-2.0a1 Wed Nov 6 13:57:31 PST 1996 • v1.0a1 Mon Jul 31 16:05:08 PDT 1995 http://www.isi.edu/nsnam/ns/CHANGES.html
Why we use it? • New protocol is not easily implemented in real. • (development, money, time, device, people) • New protocol is not easily verified in the world. • (mobile IP, ad hoc…etc, more nodes or network topology) • New protocol is not easily compared others • (How to convince other people?) • Network Simulator simulates protocol layers • (physical, datalink, network, transport, applicatoin)
C: What platforms does NS2 run on and how to install NS2? • Operation systems • (FreeBSD, Linux, SunOS, Solaris, Windows) • Setup for Linux-based system • If the file is put at /root • Step 1: cd /root • Step 2: tar zxvf ns-allinone-2.30.tar.gz • Step 3: cd /root/ns-allinone-2.30 • Step 4: ./install • Setup for win9x/2000/XP • 中文教學網站-柯志亨(Chih-Heng, Ke) • http://140.116.72.80/~smallko/ns2/ns2.htm • 安裝流程 • http://140.116.72.80/~smallko/ns2/setup.htm 註:在裝cygwin時,要自已勾選全部的套件,以免lost套件,無法compiler過去。
F: What protocols does NS2 support? • Application layer: Traffic models and applications • Web, FTP, telnet, constant-bit rate, real audio • Translation layer: Transport protocols • Unicast: TCP(Reno,Vegas,etc.), UDP • Multicast: SRM • Network layer: Routing and queueing • Wired routing: Dijkstra,DV • Wireless routing: mobile IP • Ad hoc routing :DSR,AODV,TORA,DSDV • Queueing protocols: RED, drop-tail, SFQ etc • Data link layer • Ethernet, 802.11 • Physical layer • Wired(point-to-point, LANs), wireless (multiple propagation models)…
Part 2: NS2 structure • A: Why use two programming language? • B: Overview for NS2 structure • C: Directory structure • D: How to run a scenario in NS2
A: Why using two programming language to implement? • 第一:需要一種程式設計語言,能夠有效率的處理位元組(Byte),封包標頭(Packet Header)等資訊,需要應用合適的演算法在大量的資料上。因此,程式內部的運行速度(run-time speed)就非常重要。(c++) • 第二: 許多網路中的研究工作都圍繞著網路元件和環境參數的設置和改變而進行的,需要在短時間內快速的開發和模擬出所需要的網路環境(scenarios),並且方便修改和發現、修復。在這種情形下,(run-around time)就顯得很重要了,因為模擬環境的建立和參數資訊的配置只需要運行一次。(Otcl) • NS2 is an object-oriented, discrete event driven network simulator developed at UC Berkely written in C++ and OTcl. • C++ for “data” • Per packet action • OTcl for “control” • Periodic or triggered action
Part 3: Network Scenario • A: What is network scenario? • B: How to write a simple scenario • C: How to run a scenario in NS2 (linux-based) • D: How to get the trace file?
B: How to write a simple scenario? • 1.建立一個模擬器物件 (Must) set ns [new Simulator] • 2.開啟一個nam trace 檔案 (Option) set nf [open out.nam w] $ns namtrace-all $nf • 3.宣告一個finish程序(Must) proc finish {} { global ns nf $ns flush-trace # Close the trace file close $nf # Execute nam on the trace file exec nam out.nam & exit 0 }
Set f1 [open demo1.record w] • proc record { } { global null f1 set ns [Simulator instance] set time 0.1 set now [$ns now] set bw [$null set bytes_ ] puts $f1 “$now $bw” $null set bytes_ 0 $ns at [expr $now+$time] “record” } • $ns at 0.0 “record” • LossMonitor • nlost_ :Number of packets lost • npkts_ :Number of packets received • bytes_ :Number of bytes received • lastPktTime_ :Time at which the last packet was received • expected_ :The expected sequence number of the next packet
Network Setting • Sender:Node 1, 2, 3 • Receiver:Node 7 • Using CBR • Packet Size:1000(k) • Time Interval:1 (s) • Simulation Time:15 (s)
Tcl Code #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red $ns color 3 Green #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Open the trace file set nd [open out.tr w] $ns trace-all $nd
Tcl Code #Define a 'finish' procedure proc finish {} { global ns nd nf $ns flush-trace #Close the trace file close $nd close $nf #Execute nam on the trace file exec nam out.nam & exit0 }
Tcl Code #Create four nodes set s0 [$ns node] set s1 [$ns node] set s2 [$ns node] set r0 [$ns node] set r1 [$ns node] set r2 [$ns node] set d [$ns node] #Create links between the nodes $ns duplex-link $s0 $r0 10Mb 10ms DropTail $ns duplex-link $s1 $r0 10Mb 10ms DropTail $ns duplex-link $s2 $r1 10Mb 10ms DropTail $ns duplex-link $r0 $r2 10Mb 10ms DropTail $ns duplex-link $r1 $r2 10Mb 10ms DropTail $ns duplex-link $r2 $d 10Mb 10ms DropTail s0 r0 s1 r2 d r1 s2
Tcl Code #Set position of each node $ns duplex-link-op $s0 $r0 orient right-down $ns duplex-link-op $s1 $r0 orient right-up $ns duplex-link-op $s2 $r1 orient right-up $ns duplex-link-op $r0 $r2 orient right-down $ns duplex-link-op $r1 $r2 orient right-up $ns duplex-link-op $r2 $d orient right #Monitor the queue for the link $ns duplex-link-op $r0 $r2 queuePos 0.5 $ns duplex-link-op $r1 $r2 queuePos 0.5 $ns duplex-link-op $r2 $d queuePos 0.5
Tcl Code #Set flow ID $udp0 set fid_ 1 $udp1 set fid_ 2 $udp2 set fid_ 3 #Schedule events for the CBR agents $ns at 0.0 "$cbr0 start" $ns at 0.0 "$cbr1 start" $ns at 0.0 "$cbr2 start" $ns at 15.0 "$cbr0 stop" $ns at 15.0 "$cbr1 stop" $ns at 15.0 "$cbr2 stop“ #Call the finish procedure after 5 seconds of simulation time $ns at 15.0 "finish" #Run the simulation $ns run