NS-2 Tutorial. Motivation What’s NS-2 Network simulator –Discrete event simulator It covers multiple layers –Application layer, transport layer, network.

Slides:



Advertisements
Similar presentations
Katz, Stoica F04 EECS 122 Introduction to Computer Networks (Fall 2004) Network simulator 2 (ns-2) Department of Electrical Engineering and Computer Sciences.
Advertisements

Wireless Communication : LAB 3
NS-2 (network simulator) NS by example παρουσίαση Κων/νος Τρούλος.
1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)
1 NS Fundamentals (contd..) Padma Haldar USC/ISI.
Network Simulation One tool to simulation network protocols for the Internet is the network simulator (NS) The simulation environment needs to be set-
An Introduction to NS-2 * Gayatri Swamynathan CS 276 TA *some slides are from a presentation by Haobo Yu & Nader Salehi, USC/ISI.
NS-2 Shahin Shayandeh December 2004 Session 2. Ns programming  Create the event scheduler  Turn on tracing  Create network  Setup routing  Insert.
Brief Intro to ns2: The most widely used Network Simulator COMP5416 Advanced Network Technologies Based on: Marc Greis's
Ns-2 Tutorial Exercise (1) Multimedia Networking Group, The Department of Computer Science, UVA Jianping Wang Adopted from Nicolas’s slides Jianping Wang,
LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast.
Ns-2 tutorial Karthik Sadasivam Banuprasad Samudrala CSCI 5931 Network Security Instructor : Dr. T. Andrew Yang.
How to Add a New Protocol in NS2 Xu Leiming CSCW Lab. at CS Dept., Tsinghua Univ. June 1, 2001.
5-Jul-141 S.Pushpalatha, Associate Professor, PSNACET.
Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files.
Winter 2008 Evaluation Tools1 Brief Overview of Networking Evaluation Methods and Tools.
NS TUTORIAL Padma Haldar USC/ISI 09/04/02.
15-744: Computer Networking ns-2 Tutorial Based on slides from John Heidemann, Polly Huang, and Amit Manjhi.
Katz, Stoica F04 EECS 122 Introduction to Computer Networks (Fall 2003) Network simulator 2 (ns-2) Department of Electrical Engineering and Computer Sciences.
CprE 543x – ns-2 Tutorial Zak Abichar, Dept of Electrical and Computer Engineering Iowa State University Ames,
1 Ns Tutorial Alhussein A. Abouzeid Elect. Eng. Dept./U. of Washington Parts of this educational presentation use examples available.
Day 3 Outline Multicast example (from Day 2) Wireless Misc. utilities
15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich.
1 Modified Schedule Day 2 Network AniMator (nam) Examples simple.tcl mcast.tcl Day 3 Wireless (ad-hoc)
1 Network Simulator (NS-2) Tutorial These slides can be downloaded from:
EECS122 - UCB1 Measurements and Modeling Table of Contents 1. Measurements Measurements 2. Modeling and its Shortcomings Modeling and its Shortcomings.
Network Simulator 2(NS2) Yingyue Xu 8/25/2015. Overview: The Network simulator (NS): discrete event simulator for networks. supports wired, wireless,
Network Simulator (NS2) 1 Tutorial on Network Simulator (NS2) Hemant Kumar Rath Infonet Lab, Dept of Electrical Engineering IIT Bombay, Mumbai
Wireless Networking and Systems CSE 590 ns2 tutorial.
10b_ns: CSci551 SP2002 Friday © 2002 John Heidemann1 NS Tutorial, Class 10 CSci551: Computer Networks SP2002 Friday Section John Heidemann.
Introduction to NS2 -Network Simulator- -Prepared by Changyong Jung.
1 Introduction to Ns-2 Zhibin WU WINLAB, ECE Dept. Rutgers U.
Tutorial: The ns-2 Network Simulator Amirali Habibi Shrif Univesity Adapted from: Michael Welzl Institute of Computer Science University of Innsbruck,
NS2 - Appendix Ming-Feng Yang. 2 2 Outline NS2 Models NS2 Directory Structure Extending NS2 in OTcl Extending NS2 in C++ NS2 related links.
JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY Network Simulator – NS-2 1.
Network Simulator-2 Sandeep singla 1998A2A7540. NS-2 A discrete event simulator Focused on modeling network protocols –Wired, wireless –TCP,UDP,unicast,multicast.
NetFlow Very useful for traffic analysis Very useful for traffic analysis Standard sampler: Standard sampler: –Cisco Netflow –Juniper Traffic Sampling.
1 Network Simulator Tutorial. 2 Network Simulation * Motivation: Learn fundamentals of evaluating network performance via simulation Overview: fundamentals.
Internet Computing KUT Youn-Hee Han
1 Network Simulation and Testing Polly Huang EE NTU
1 ns-2 Tutorial Haobo Yu, Nader Salehi USC/ISI
1 NS Fundamentals. USC INFORMATION SCIENCES INSTITUTE 2 OTcl and C++: The Duality C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects ns.
Ns-2 Tutorial (1) Multimedia Networking Group, The Department of Computer Science, UVA Jianping Wang Jianping Wang, 2002 cs757 1.
1 Introduction to NS-2 r Tutorial overview of NS m Create basic NS simulation r Walk-through a simple example m Model specification m Execution and trace.
1 ns-2 Tutorial Polly Huang AT&T Labs Research 11 August, 1999.
Lab 2, Network Simulator ns2 Shiv Kalyanaraman Yong Xia (TA) Satish Raghunath Sept 4,
Network Simulator Tutorial Wireless Networks. Acknowledgements Material is taken from the presentations by Jim Kurose, University of Massachusetts, Amherst.
Network Simulator 2. Introduction Open source network simulator NS uses two languages: C++ and OTcl  C++ is fast to run but slower to change Kernel 
University of Texas at Arlington CSE 5346/4346 High Performance Networks 1 NS-2 Tutorial Choe, Hyun Jung (Stella) Spring 2008 Spring 2008 High Performance.
The Creation of NS2 Simulated Environment ( 1 ) LI Chengbo
TNK092: Network Simulation - Nätverkssimulering Lecture #1: Course basics and a first taste of NS2 Vangelis Angelakis Ph.D.
July 7, 2003 Building a Wireless LAN traffic test case in ns2 Radio Science Laboratory Department of Electrical and Computer Engineering The University.
NS-2 Shahin Shayandeh December 2004 Session 1. Ns-2, the Network Simulator  A discrete event simulator Simple model  Focused on modeling network protocols.
Lab 2, Network Simulator ns2
1 NS-2: the network simulator 15 September 2005 Network Lab., SNU Changjee Joo.
© Algirdas Pakstas CS3026N Network Analysis, Design and Simulation 1 CT3020: Network Planning and Simulation Week 6b Prof.DrTech. Algirdas Pakštas.
DMET 602: Networks and Media Lab Amr El Mougy Yasmeen EssamAlaa Tarek.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
NS-2 Simulator 최 종 훈 Contents  About NS  Installation  Based on Linux  Based on Windows  Architecture  Using NS-2  Example  References.
Overview of VANET Project(2011) on NS2 Perspective Part 1 of 2 Jae-Myeong Lee Human-centric Mobile Computing Lab.
Jartel, Sukiswo Sukiswo
ECE 6610 Sandeep Kakumanu GNAN research Lab
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Network Simulator Tutorial
Choe, Hyun Jung (Stella)
Introduction to ns-2: “The” Network Simulator
Introduction to NS Srinath Perur.
Ns By Kulveer Singh.
Karthik Sadasivam Banuprasad Samudrala
Presentation transcript:

NS-2 Tutorial

Motivation

What’s NS-2 Network simulator –Discrete event simulator It covers multiple layers –Application layer, transport layer, network layer and link layer. Supports the simulation of –intserv/diffserv, Multicast, Transport, Applications, Wireless (fixed, mobile, satellite) Packet level

Model world as events – simulator has list of events ordered by simulation time – process: take next one, run it, until done – each event happens in an instant of virtual (simulated) time, but takes an arbitrary amount of real time time, but takes an arbitrary amount of real time NS uses simple model: single thread of control => no locking or race conditions to worry about (very easy) Discrete Event Simulation

History and Status REAL variant (1989)  DARPA (LBL, Xerox PARC, UCB, and USC/ISI) (1995) Currently; DARPA; NSF; collaboration with researchers: ACIRI, UCB Daedelus, CMU, Sun Microsystems, NORTEL, Cisco ns-1 ns-2 –100K lines of C++ –70K lines of OTcl –30K lines of test suite –20K lines of documentation Current version is 2.28

ns-2 Programming Languages NS-2 is an object oriented simulator, written in C++, with an OTcl (Object Tool Command Language) interpreter as a front-end.NS-2 is an object oriented simulator, written in C++, with an OTcl (Object Tool Command Language) interpreter as a front-end. Back-end C++ –Defining new agents, protocols and framework. –Manipulations at the byte/bit levels. –if you have to change the behaviour of an existing C++ class in ways that weren't anticipated Front-end Otcl Topologies, scenarios, simulations, … –Script language (easy topology modifications) –if you can do what you want by manipulating existing C++ objects

Why Two Languages Simulator had two distinct requirementsSimulator had two distinct requirements –Detailed simulation of Protocol(Run-time speed) –Varying parameters or configuration(Change model & rerun) C++ is fast to run but slower to changeC++ is fast to run but slower to change Otcl runs much slower but can be changed quicklyOtcl runs much slower but can be changed quickly

OTcl and C++: The Duality C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects ns Split Object: Object created in Otcl has a corresponding object in C++.

ns Directory Structure TK8.0OTcltclclTcl8.0ns-2nam-1 tcl extest lib... examples validation tests C++ code OTcl code ns-allinone mcast

Network Topology: Node n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry Unicast Node Multicast Classifier classifier_ dmux_ entry_ Node entry Multicast Node multiclassifier_ Classifier : Address, Multicast, Multipath, Hash

Network Topology: Link n0n1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_ tracing simplex link duplex link

Routing n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry 0 1 enqT_queue_deqT_ drophead_drpT_ link_ttl_ n1 entry _ head_

Routing (con’t) n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0

Transport 0 1 n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0

Application: Traffic Generator 0 1 n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0 Application/FTP

Plumbing: Packet Flow 0 1 n0n1 Addr Classifier Port Classifier entry_ 0 Agent/TCP Addr Classifier Port Classifier entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink dst_=1.0 dst_=0.0 Application/FTP

Running NS-2 Program

Resources Tcl (Tool Command Language) – OTcl (MIT Object Tcl) –~otcl/doc/tutorial.html (in distribution) ns manual –Included in distribution: ~ns/doc – documentation.html

Outline What’s NS-2 NS-2 Structures TCL(Tool Command Language) Basics OTCL Basics Examples

Basic Syntax Tcl commands are evaluated in two steps: First the Tcl interpreter parses the commands into words, performing substitution along the way. Then a command procedure process the words to produce a result string. Each command has a separate command procedure.

Tcl Basics Basic syntax –command arg1 arg2 arg3 … –command is either the name of a built-in command or a Tcl procedure Three basic steps –Argument grouping –variable substitution, command substitution –Command invocation

First example: hello world! Hello world! –puts stdout {Hello World!} Two points to emphasize –Arguments are interpreted by the command –Curly braces are used to group words together into a single argument

More examples set var 5 –=> 5 set b $var –=> 5 The set command is used to assign a value to a variable

Variable Substitution Variable substitution –i: the character ‘i’. –$i: the variable i. –set v1 6 –set v2 $v1 (variable substitution)

Command Substitution –set value [expr $v1+ $v2] –=> set value 12 –Rewirte the outer command by using the result of the nested command Operation substitution –set i wrong number of arguments –set i {5 + 6} –set i [5 + 6] invalid command –set i [expr 5 + 6] 11

Math Expressions –expr 8 / 2 => 4 –set len [expr [string length foobar] + 7] =>13

Grouping Grouping: group words (argument) together into one argument Grouping with curly braces –Curly braces prevent substitution in the group Grouping with double quotes –Double quotes allow substitution to occur in the group Example: –set a hello => hello –puts stdout “ The length of $a is [string length $a]." => The length of hello is 5 –puts stdout { The length of $a is [string length $a].} =>The length of $a is [string length $a]

More on Tcl Control Structures –if {condition} then {…….} –for {set i 0} {$i < 10} {incr i 2} {……} Procedures –proc proc_name {arg1 arg2…} { ……}

Example set a 43 set b 27 proc test { a b } { set c [expr $a + $b] set d [expr [expr $a - $b] * $c] for {set k 0} {$k < 10} {incr k} { if {$k < 5} { puts “k < 5, pow = [expr pow($d, $k)]” } else { puts “k >= 5, mod = [expr $d % $k]” } test 43 27

Results k < 5, pow = 1.0 k < 5, pow = k < 5, pow = k < 5, pow = k < 5, pow = k >= 5, mod = 0 k >= 5, mod = 4 k >= 5, mod = 0 k >= 5, mod = 4

OTcl Basics Creating a class –Class class_name –Class class_name –superclass Base_class Defining instance procedures –class_name instproc proc_name {args} {…..} Defining instance variables –$self instvar variable_name (inside a class method)

OTcl Basics Creating an instance –set new_inst [new class_name] Calling an instance procedure –$new_inst proc_name {args} Using an instance value –$new_inst set v1 10 –set v2 [$new_inst set v1]

Examples Class Mom Mom instproc greet {} { $self instvar age_ puts “$age_ years old mom: How are you doing?” } Class Kid -superclass Mom Kid instproc greet {} { $self instvar age_ puts “$age_ years old kid: What’s up, dude?” } set mom [new Mom] $mom set age_ 45 set kid [new Kid] $kid set age_ 15 $mom greet $kid greet 45 years old mom: How are you doing? 15 years old kid: What's up, dude?

NS2, and all of it's peer programs & dependencies are installed in/usr/ns/ on the Fedora machines in the Main Undergraduate Lab in Math Sciences. It is also available on the compute servers csc, csd, and cse. Some notes:

(1) You *must* put /usr/ns/otcl-1.9 and /usr/ns/lib into your LD_LIBRARY_PATH environment variable. –If you are using csh or tcsh, you can set it like: setenv LD_LIBRARY_PATH /usr/ns/otcl- 1.9:/usr/ns/lib –If you are using sh or bash, you can set it like: export LD_LIBRARY_PATH=/usr/ns/otcl- 1.9:/usr/ns/lib

(2) You *must* put /usr/ns/tcl8.4.5/library into your TCL_LIBRARY environment variable. Otherwise ns/nam will complain during startup. –If you are using csh or tcsh, you can set it like: setenv TCL_LIBRARY /usr/ns/tcl8.4.5/library –If you are using sh or bash, you can set it like: export TCL_LIBRARY=/usr/ns/tcl8.4.5/library

(3)You *should* put /usr/ns/bin into your PATH environment variable. Otherwise you will have to type the full path to ns/nam when you want to run them. –If you are using csh or tcsh, you can set it like: setenv PATH /usr/ns/bin:$PATH –If you are using sh or bash, you can set it like: export PATH=/usr/ns/bin:$PATH

Elements of ns-2 Simulation Step 1: Create the event scheduler Step 2: Turn on tracing Step 3:Create network topology Step 4: Create transport connection Step 5: Create traffic on top of transport connection

Topology

Step 1: Creating Event Scheduler Create event scheduler –set ns [new Simulator] Schedule events –$ns at – : any legitimate ns/tcl commands Start scheduler –$ns run

Step 2: Tracing Trace packets on all links –$ns trace-all [open test.out w] cbr cbr r cbr Trace packets on all links in nam format –$ns namtrace-all [open test.nam w] Must appear immediately after creating scheduler

Tracing Trace all –set nf [open out.ns w] –$ns trace-all $nf Turn on tracing on specific links

Step 3: Creating Network Nodes –set n0 [$ns node] –set n1 [$ns node] Links and queuing –$ns duplex-link $n0 $n1 – : DropTail, RED, CBQ, FQ, SFQ, DRR

#Create 6 nodes for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } #Create a duplex link between the nodes $ns duplex-link $n(0) $n(4) 10Mb 10ms DropTail $ns duplex-link $n(1) $n(4) 10Mb 10ms DropTail $ns duplex-link $n(4) $n(5) 1.5Mb 10ms DropTail $ns duplex-link $n(5) $n(3) 10Mb 10ms DropTail $ns duplex-link $n(5) $n(2) 10Mb 10ms DropTail $ns queue-limit $n(4) $n(5) 20

Step 4: Creat transport conneciton TCP TCP #Create a TCP agent and attach it to node n(0) #set up connection between node 0 and node 3 set src_tcp [new Agent/TCP/Reno] $ns attach-agent $n(0) $src_tcp set dst_tcp [new Agent/TCPSink/DelAck] $ns attach-agent $n(3) $dst_tcp $ns connect $src_tcp $dst_tcp

Step 4: Creat transport conneciton UDP UDP # UDP flow between n1 and n7 set src_udp [new Agent/UDP] $ns attach-agent $n(1) $src_udp set dst_udp [new Agent/LossMonitor] $ns attach-agent $n(2) $dst_udp $ns connect $src_udp $dst_udp

Step 5: Creating Traffic (On Top of UDP) CBR #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $src_udp $cbr set type_ CBR $cbr set packetSize_ 512 $cbr set rate_ 0.8Mb

Creating Traffic: (On Top of TCP) FTP set ftp [new Application/FTP] $ftp attach-agent $src_tcp $ftp set packetSize_ 512

Things to Remember Topology, agents, sources, start Connect the agents –Slot not found error Start/Stop the sources In procedures, declare global variables before use “$ns run” – last line