1 Introduction to Ns-2 Zhibin WU WINLAB, ECE Dept. Rutgers U.

Slides:



Advertisements
Similar presentations
Wireless Communication : LAB 3
Advertisements

NS-2 (network simulator) NS by example παρουσίαση Κων/νος Τρούλος.
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,
Ns-2 tutorial Karthik Sadasivam Banuprasad Samudrala CSCI 5931 Network Security Instructor : Dr. T. Andrew Yang.
Network Simulator (NS) Prof. Nelson L. S. da Fonseca State University of Campinas, Brazil.
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.
Dongsoo S. Kim 1.
Winter 2008 Evaluation Tools1 Brief Overview of Networking Evaluation Methods and Tools.
Introduction to Wireless simulations Shao-Cheng Wang.
Simulation of GPRS MS-BS Interface Using ns-Network Simulator Dual Degree Presentation by Richa Jain (96D07007) Department of Electrical Engineering, Indian.
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.
Network Simulator 2 Tejas Vasavada.
1 Network Simulator (NS-2). 2 講義 Network Simulator (NS2) Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據.
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.
Yinfei Pan SUNY Binghamton Computer Science
Jump to first page NS Tutorial: mobile and wireless network simulation Ya Xu USC/ISI September 10th, 1999.
1 Network Simulator (NS-2) Tutorial These slides can be downloaded from:
1 2nd European ns-2 Workshop Polly Huang ETH Zurich April 18 & 19, 2001.
EECS122 - UCB1 Measurements and Modeling Table of Contents 1. Measurements Measurements 2. Modeling and its Shortcomings Modeling and its Shortcomings.
Ns Simulation of IEEE SC546 Project (Fall 2002) SOO IL KIM JISUN YOON
Simulators for Sensor Networks Sagnik Bhattacharya 9/12/2001.
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 ns-2 Noun Choi Oct. 11, Outline Background ns-2 Internals Short demo Troubleshooting Reference links Q & A.
1 / 10 Mobile Networking in ns Speaker : Mark Yang
Introduction to Mobility & Network Simulator 2 (NS-2)
NS2 - Wireless Network Ming-Feng Yang. 2 2 Outline Basic wireless model Extensions wireless model Example - Ad hoc network Example – WLAN Example – Mobile.
Define options(1/2) #channel type set val(chan) Channel/WirelessChannel # radio-propagation model set val(prop) Propagation/TwoRayGround # network interface.
MOBILE IP SOMULATION IN NS2 Presenter: 吳寶緣. Outlines  Overview  Hierarchical Address Format  Hierarchical Address Format-ex  MoblieIP Demo  Additional.
Network Simulator-2 Sandeep singla 1998A2A7540. NS-2 A discrete event simulator Focused on modeling network protocols –Wired, wireless –TCP,UDP,unicast,multicast.
1 Network Simulator Tutorial. 2 Network Simulation * Motivation: Learn fundamentals of evaluating network performance via simulation Overview: fundamentals.
Internet Computing KUT Youn-Hee Han
Network Simulator ns-2. 2 Agenda Introduction Interface Tcl and OTcl TclCL Simulator Wired network Wireless network Program Assignment.
NS-2 Tutorial. Motivation What’s NS-2 Network simulator –Discrete event simulator It covers multiple layers –Application layer, transport layer, network.
Quality evaluation of MPEG4 video transmission over GPRS networks.. Presented by: Abdullah M. Rana Multimedia Communication.
1 Network Simulation and Testing Polly Huang EE NTU
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,
CDA6530: Performance Models of Computers and Networks Chapter 10: Introduction to Network Simulator (NS2) TexPoint fonts used in EMF. Read the TexPoint.
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.
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
© 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.
NS-2 Simulator 최 종 훈 Contents  About NS  Installation  Based on Linux  Based on Windows  Architecture  Using NS-2  Example  References.
Jartel, Sukiswo Sukiswo
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Basics of NS-2 Training in TCL script
Introduction to ns-2: “The” Network Simulator
Planned Activities on Computer Networks for Sunday Academy
Ns By Kulveer Singh.
Karthik Sadasivam Banuprasad Samudrala
TexPoint fonts used in EMF.
Presentation transcript:

1 Introduction to Ns-2 Zhibin WU WINLAB, ECE Dept. Rutgers U.

2 Goals Understanding NS-2 Hands-on Experience with NS2 Ns-2 by Example Write your own scripts Extending NS2 Implementing new functionality

3 Schedule Presentation (60 min) Group Assignments (10 min) Practices (1 Hr) Q & A session (~15 min)

4 Talk Overview What is ns-2? (the evolution) Architecture Basic Tcl/Otcl commands Elements of an ns-2 simulation Example Online Resources & Documentation

5 What is ns? A discrete event, packet-level simulator Targeted at networking research Supports the simulation of intserv/diffserv, Multicast, Transport, Applications, Wireless (fixed, mobile, satellite) REAL variant (1989)  DARPA (LBL, Xerox PARC, UCB, and USC/ISI) (1995) Ns-3 Project (Ongoing)

6 Status ns-2 100K lines of C++ 70K lines of OTcl 50K+ lines of test suite, examples, docs Platforms Most UNIX and UNIX-like systems (FreeBSD, Linux, Sun Solaris) Window 95/98/NT with Cygwin (Emulation only for FreeBSD for now)

7 Remember! A simulator model of a real-world system is necessarily a simplification. For example, in simulating TCP No SYN/FIN Equal size segments No variable window advertisement Bugs: “Users of ns are responsible for verifying for themselves that their simulations are not invalidated by bugs”.

8 Architecture: Object-Oriented C++ for “data” Per packet action OTcl for control Periodic or triggered action Modularity (+), re-usability(+), scalability(+) Speed(-), memory(-)

9 OTcl and C++: The Duality C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects ns

10 Script in interactive mode linux21% ns % set ns [new Simulator] _o3 % $ns at 1 “puts \“Hello World!\”” 1 % $ns at 1.5 “exit” 2 % $ns run Hello World! linux21%

11 A script in batch mode #simple.tcl set ns [new Simulator] $ns at 1 “puts \“Hello World!\”” $ns at 1.5 “exit” $ns run linux21% ns simple.tcl Hello World! linux21%

12 Basic Tcl 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

13 Basic OTcl 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

SIMULATE WIRED NETWORK 14

15 Elements of ns-2 Simulation Create the event scheduler [Turn on tracing] Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

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

17 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

18 Tracing Turn on tracing on specific links $ns trace-queue $n0 $n1 $ns namtrace-queue $n0 $n1

19 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

20 Creating Network: LAN LAN $ns make-lan : LL : Queue/DropTail, : MAC/802_3 : Channel

21 Inserting Packet Errors Creating Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] Inserting Error Module $ns lossmodel $loss_module $n0 $n1

22 Network Dynamics Link failures Hooks in routing module to reflect routing changes Four models $ns rtmodel-at up|down $n0 $n1 $ns rtmodel Trace $n0 $n1 $ns rtmodel Exponential { } $n0 $n1 $ns rtmodel Deterministic { } $n0 $n1 Parameter list [ ] [ ]

23 Setup Routing Unicast $ns rtproto : Static, Session, DV, cost, multi-path Multicast $ns multicast (right after [new Simulator]) or set ns [new Simulator –multicast on] $ns mrtproto : CtrMcast, DM, ST, BST (centralized,dense mode, shared tree

24 Creating Connection: UDP UDP set udp [new Agent/UDP] set null [new Agent/Null] $ns attach-agent $n0 $udp $ns attach-agent $n1 $null $ns connect $udp $null

25 Creating Traffic: On Top of UDP CBR set src [new Application/Traffic/CBR] Exponential or Pareto on-off set src [new Application/Traffic/Exponential] set src [new Application/Traffic/Pareto]

26 Creating Connection: TCP TCP set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink

27 Creating Traffic: On Top of TCP FTP set ftp [new Application/FTP] $ftp attach-agent $tcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp

28 Creating Traffic: Trace Driven Trace driven set tfile [new Tracefile] $tfile filename set src [new Application/Traffic/Trace] $src attach-tracefile $tfile : Binary format (native!) inter-packet time (msec) and packet size (byte)

29 Application-Level Simulation Features Build on top of existing transport protocol Transmit user data, e.g., HTTP header Two different solutions TCP: Application/TcpApp UDP: Agent/Message

30 Script Structure for Wired Scenario # parameters and options set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation

SIMULATE WIRELESS NETWORK 31

32 Script Structure: Wireless # parameters and options set ns [new Simulator] # [Turn on tracing] # create MobileNode object (PHY to layer 3 configured) # Create topology # create mobility # Create Layer 4 and above # - UDP/TCP agents # - application and/or setup traffic sources # Post-processing procedures # Start simulation

33 Example: Wireless Scenario 4x4 grid 240m

34 Example: Step 1 Define Parameters set cbr_size 500 set cbr_interval set num_row 4 set time_duration 100

35 Example: Step 2 Protocol Options set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio- propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(rp) DSDV ;# routing protocol

36 Example: Step 3 Scheduler, Trace, Topo, God # # Initialize ns # set ns_ [new Simulator] set tracefd [open simple.tr w] $ns_ trace-all $tracefd # set up topography object # set up topography object set topo [new Topography] set topo [new Topography] $topo load_flatgrid $topo load_flatgrid create-god [expr $num_row * $num_row ] create-god [expr $num_row * $num_row ]

37 Example: Step 4 Create Node Object with protocols $ns_ node-config -adhocRouting $val(rp) -llType $val(ll) \ -macType $val(mac) -ifqType $val(ifq) \ -macType $val(mac) -ifqType $val(ifq) \ -ifqLen $val(ifqlen) -antType $val(ant) \ -ifqLen $val(ifqlen) -antType $val(ant) \ -propType $val(prop) -phyType $val(netif) \ -propType $val(prop) -phyType $val(netif) \ -channel $chan1 -topoInstance $topo \ -channel $chan1 -topoInstance $topo \ -agentTrace ON -routerTrace OFF\ -agentTrace ON -routerTrace OFF\ -macTrace ON \ -macTrace ON \ -movementTrace OFF -movementTrace OFF for {set i 0} {$i < [expr $num_row*$num_row]} {incr i} { set node_($i) [$ns_ node] }

38 Example: Step 5 Create Topology set k 0; while {$k < $num_row } { for {set i 0} {$i < $num_row } {incr i} { for {set i 0} {$i < $num_row } {incr i} { set m [expr $i+$k*$num_row]; set m [expr $i+$k*$num_row]; $node_($m) set X_ [expr $i*240]; $node_($m) set X_ [expr $i*240]; $node_($m) set Y_ [expr $k* ]; $node_($m) set Y_ [expr $k* ]; $node_($m) set Z_ 0.0 $node_($m) set Z_ 0.0 } incr k; incr k;};

Example: Step 6 Create Mobility #Move node 11 from its original place to top-right corner $ns_ at 60.0 "$node_(11) setdest ”

40 Example: Step 7 Set up transport layer (UDP) for {set i 0} {$i < $num_row } {incr i} { for {set i 0} {$i < $num_row } {incr i} { set udp_($i) [new Agent/UDP] set udp_($i) [new Agent/UDP] set null_($i) [new Agent/Null] set null_($i) [new Agent/Null] } $ns_ attach-agent $node_(8) $udp_(0) $ns_ attach-agent $node_(8) $udp_(0) $ns_ attach-agent $node_(4) $udp_(1) $ns_ attach-agent $node_(4) $udp_(1) $ns_ attach-agent $node_(13) $udp_(2) $ns_ attach-agent $node_(13) $udp_(2) $ns_ attach-agent $node_(14) $udp_(3) $ns_ attach-agent $node_(14) $udp_(3) $ns_ attach-agent $node_(11) $null_(0) $ns_ attach-agent $node_(11) $null_(0) $ns_ attach-agent $node_(7) $null_(1) $ns_ attach-agent $node_(7) $null_(1) $ns_ attach-agent $node_(2) $null_(2) $ns_ attach-agent $node_(2) $null_(2) $ns_ attach-agent $node_(3) $null_(3) $ns_ attach-agent $node_(3) $null_(3) for {set i 0} {$i < $num_row } {incr i} { for {set i 0} {$i < $num_row } {incr i} { $ns_ connect $udp_($i) $null_($i) $ns_ connect $udp_($i) $null_($i) }

41 Example: Step 8 Define Traffic Scenario for {set i 0} {$i < $num_row } {incr i} { set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) set packetSize_ $cbr_size $cbr_($i) set interval_ 0.5 $cbr_($i) attach-agent $udp_($i)} $ns_ at "$cbr_(0) start" $ns_ at "$cbr_(1) start" $ns_ at "$cbr_(2) start" $ns_ at "$cbr_(3) start"

42 Example: Step 9 End-of-simulation wrapper (as usual) # Tell nodes when the simulation ends # for {set i 0} {$i < [expr $num_row*$num_row] } {incr i} { $ns_ at [expr $time_duration +10.0] "$node_($i) reset"; } $ns_ at [expr $time_duration +10.0] "finish" $ns_ at [expr $time_duration ] "puts \"NS Exiting...\"; $ns_ halt" proc finish {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run

43 Auxiliary Tools setdest used to generate the positions of nodes and their moving speed and moving directions. setdest -v 1 -n 50 -p 0 -M 20 -t 900 -x y 300 cbrgen.tcl ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] Use “source.tcl” to add the generated file to scipts

44 Resources Tutorials: Marc Greis’s Tutorial ( Ns by example ( Wireless Tutorial ( tutorial/wireless.ppt ) tutorial/wireless.ppt

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

Advanced Topics Trace analysis Architecture of Mobilenode Object Extending NS-2 with new protocols and algorithms More complex changes: Hybrid Node A node with multiple interfaces 46

Group Assignments Download simple.tcl Modifications Node-Configure changes Random topology generation 40-node within 1000x1000 area Random Node Mobility Changeprotocol from UDP to TCP Dynamic Traffic change 47