1 ns-2 Tutorial Polly Huang AT&T Labs Research 11 August, 1999.

Slides:



Advertisements
Similar presentations
Wireless Communication : LAB 3
Advertisements

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.
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.
Dongsoo S. Kim 1.
Winter 2008 Evaluation Tools1 Brief Overview of Networking Evaluation Methods and Tools.
1 Network Simulation and Testing Polly Huang EE NTU
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 2nd European ns-2 Workshop Day 2 Polly Huang ETH Zurich 18 & 19 April.
Submitters: Stella Pantofel Michael Halperin Igor Berman
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.
Introduction to Network Simulator NS-2 Part II
NS2 Tutorial Aga Zhang Dependable Computing Lab. Outline Introduction Fundamental Skills - Tcl and OTcl Network Simulator - ns-2 Study Project - Mobile.
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 Introduction to Ns-2 Zhibin WU WINLAB, ECE Dept. Rutgers U.
NS2 Tutorial for CS740 Jianming Wu *modified from Aga Zhang.
1 Part III: Extending ns. USC INFORMATION SCIENCES INSTITUTE 2 Outline Extending ns In OTcl In C++ Debugging.
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.
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.
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.
Su Wen Department of Computer Science
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.
Lab 2, Network Simulator ns2 Shiv Kalyanaraman Yong Xia (TA) Satish Raghunath Sept 4,
NS2Work1 LAB 5 Adding New Components High level scripting in otcl Linking otcl and C++ Low level in C++
Network Simulator Tutorial Wireless Networks. Acknowledgements Material is taken from the presentations by Jim Kurose, University of Massachusetts, Amherst.
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.
1 Part II: ns Internals. USC INFORMATION SCIENCES INSTITUTE 2 Outline Fundamental concept Split object: C++/OTcl linkage Plumbing Wired Wireless Scaling.
(Tue) 1 Network Simulator 2 - Introduction for Beginners CNLAB ns - 2 seminar.
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.
Applications and transport agent API 許庭瑋.
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.
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Introduction to ns-2: “The” Network Simulator
Introduction to NS Srinath Perur.
Ns By Kulveer Singh.
Karthik Sadasivam Banuprasad Samudrala
Introduction to ns-2 Noun Choi Oct. 11, 2007.
Aga Zhang Dependable Computing Lab
Presentation transcript:

1 ns-2 Tutorial Polly Huang AT&T Labs Research 11 August, 1999

2 Essentials & Getting Started

3 Outlines Essentials Getting Started Fundamental tcl, otcl and ns Case Studies –Web, TCP, Routing, Queuing

4 Object-Oriented +Reusability +Maintainability –Careful Planning Ahead

5 C++ and otcl Separation C++ for data –per packet action otcl for control –periodic or triggered action +Compromize between composibility and speed –Learning & debugging

6 otcl and C++: The Duality C++ otcl

7 tcl Interpreter With Extents otcl: Object-oriented support tclcl: C++ and otcl linkage Discrete event scheduler Data network (the Internet) components tcl8.0 otcl tclcl ns-2 Event Scheduler Network Component

8 Outlines Essentials Getting Started Fundamental tcl, otcl and ns Case Studies –Web, TCP, Routing, Queuing

9 Installation Getting the pieces –tcl/tk8.0, otcl, tclcl, ns-2, (and nam-1) build.html –subscribe ns-users

10 Hello World - Interactive Mode swallow 71% ns % set ns [new Simulator] _o3 % $ns at 1 “puts \“Hello World!\”” 1 % $ns at 1.5 “exit” 2 % $ns run Hello World! swallow 72%

11 Hello World - Passive Mode simple.tcl set ns [new Simulator] $ns at 1 “puts \“Hello World!\”” $ns at 1.5 “exit” $ns run swallow 74% ns simple.tcl Hello World! swallow 75%

12 Outlines Essentials Getting Started Fundamental tcl, otcl and ns Case Studies –Web, TCP, Routing, Queuing, Wireless

13 Fundamentals tcl otcl: –ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html ns-2 – –

14 Basic tcl proc test {} { set a 43 set b 27 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

15 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 a [new mom] $a set age_ 45 set b [new kid] $b set age_ 15 $a greet $b greet

16 Basic ns-2 Creating the event scheduler Creating network Computing routes Creating connection Creating traffic Inserting errors Tracing

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

18 Creating Network Nodes –set n0 [$ns node] –set n1 [$ns node] Links & Queuing –$ns duplex-link $n0 $n1 – : DropTail, RED, CBQ, FQ, SFQ, DRR

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

20 Computing routes Unicast –$ns rtproto – : Static, Session, DV, cost, multi-path Multicast –$ns multicast (right after [new Simulator]) –$ns mrtproto – : CtrMcast, DM, ST, BST

21 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

22 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

23 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

24 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]

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

26 Inserting 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

27 Tracing Trace packets on all links –$ns trace-all [open test.out w] cbr cbr r cbr Trace packets on all links in nam-1 format –$ns namtrace-all [open test.nam w]

28 Outlines Essentials Getting Started Fundamental tcl, otcl and ns-2 Case Studies

29 Case Studies Routing - Multicast (mcast.tcl) TCP (tcp.tcl) Web (web.tcl & dumbbell.tcl) Queuing - RED (red.tcl)

30 Visualization Tools nam-1 (Network AniMator Version 1) xgraph

31 ns-2 Internal

32 Internals Discrete Event Scheduler Network Topology Routing Transport Application Packet Flow Packet Format

33 Discrete Event Scheduler time_, uid_, next_, handler_ head_ -> handler_ -> handle() time_, uid_, next_, handler_ insert head_ ->

34 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_

35 Network Topology - Link n0n1 enqT_queue_deqT_ drophead_drpT_ link_ttl_ n1 entry_ head_

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

37 Routing (cont.) 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 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

39 Application 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

40 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

41 Packet Format header data ip header tcp header rtp header trace header cmn header... ts_ ptype_ uid_ size_ iface_

42 Extending ns-2 Simulator

43 Outline Making changes Creating new components

44 ns-2 Directory Structure sim tk8.0otclTcltcl8.0ns-2nam-1 tcl extestlib... tcl code example validation test C++ code tcl code core

45 Making Changes in C++ Space Existing code –recompile Addition –change Makefile and recompile

46 Making Changes in otcl Space Existing code –recompile –source Addition –source –change Makefile (NS_TCL_LIB), tcl/ns-lib.tcl (source) and recompile

47 Outline Making changes Creating new components

48 Creating New Components Guidelines Inheritance Hierarchy C++ and otcl Interface Examples –Network layer –Transport layer –Application layer

49 Guidelines Decide its inheritance structure Create the class and fill in the API virtual functions Define otcl linkage functions Write the necessary otcl code to access your agent

50 Class Hierarchy (Partial) TclObject NsObject ConnectorClassifier DelayAddrClassifierAgentMcastClasifierQueueTrace DropTailREDTCPEnqDnqDrop RenoSACK

51 C++ and otcl Linkage TclClass TclObject: bind() method TclObject: command() method class Tcl

52 TclClass TclObject Agent Agent/TCP TclObject Agent TcpAgent NsObject ?? OTclC++ mirroring Static class TcpClass : public TclClass { public: TcpClass() : TclClass(“Agent/TCP”) {} TclObject* create(int, const char*const*) { return (new TcpAgent()); } } class_tcp; Static class TcpClass : public TclClass { public: TcpClass() : TclClass(“Agent/TCP”) {} TclObject* create(int, const char*const*) { return (new TcpAgent()); } } class_tcp;

53 TclObject: bind() C++ TcpAgent::TcpAgent() { bind(“window_”, $wnd_); … } otcl Agent/TCP set window_ 50

54 TclObject: command() C++ Int TcpAgent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcomp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]); … return(TCL_OK); } return (Agent::command(argc, argv); } otcl set tcp [new Agent/TCP] $tcp advance 10

55 Class Tcl C++ Tcl& tcl = Tcl::instance(); if (argc==2) { if (strcmp (argv[1], “now”) == 0) { tcl.resultf(“%g”, clock()); return TCL_OK; } tcl.evalc(“puts hello, world”); tcl.error(“command not found”); } otcl foo now foo whatever

56 Debugging printf() and puts “” gdb tcl debugger – –place debug 1 at the appropriate location –trap to debugger from the script –single stepping through lines of codes –examine data and code using Tcl-ish commands

57 Case Studies Network Layer: Network Interface (packet labeler) Transport Layer: TCP Jump Start Application Layer: Message agent (ping)

58 Case 1: Network Layer Network Interface - Packet Labeler n0n1n2 NetworkInterface ANetworkInterface B

59 Class Hierarchy TclObject NsObject ConnectorClassifier DelayAddrClassifierAgentMcastClasifierQueueTrace DropTailREDTCPEnqDnqDrop RenoSACK Network Interface

60 Network Interface Labeler class NetworkInterface –NetworkInterface() –recv(pkt) pkt->iface() = label_ –send(pkt) target->recv(pkt) –command() label argv {label_ = argv} TclClass(“networkinterface”) C++ otcl NetworkInterfacenetworkinterface set iface [new networkinteface] $iface label A command(): label

61 Case 2: Transport Layer TCP Jump Start –from cwnd += 1 –to cwnd = maxwin

62 Class Hierarchy TclObject NsObject ConnectorClassifier DelayAddrClassifierAgentMcastClasifierQueueTrace DropTailREDTCPEnqDnqDrop RenoSACK JS

63 TCP Jump Start class JSTcpAgent –openwin() –slowdown() TclClass(“Agent/TCP/JS”)

64 Case 3: Application Layer Message sender (ping) n0n1n2 Message Sender

65 Class Hierarchy TclObject NsObject ConnectorClassifier DelayAddrClassifierAgentMcastClasifierQueueTrace DropTailREDTCPEnqDnqDrop RenoSACK MessageAgent

66 Message Sender class MessageAgent –MessageAgent() –recv() –send() –command() send {send()} TclClass(“Agent/Message”) C++otcl MessageAgent Agent/Message set msg [new Agent/Message] $msg send command(): send

67 Special Topics

68 Special Topics Application Level Support Topology and Scenario Generation Wireless/Mobility Support

69 Application: Two-way TCP FullTcp connection –set tcp1 [new Agent/TCP/FullTcp] –set tcp2 [new Agent/TCP/FullTcp] –$ns attach-agent $n1 $tcp1 –$ns attach-agent $n2 $tcp2 –$ns connect $tcp1 $tcp2 –$tcp2 listen

70 Application: TcpApp User data transfer –set app1 [new Application/TcpApp $tcp1] –set app2 [new Application/TcpApp $tcp2] –$app1 connect $app2 –$ns at 1.0 “$app1 send \” \”” – : will be executed when received at the receiver TcpApp

71 Topology Generation topogen.html ntg GT-ITM TIERS rtg Packages n-level flat, ts, n 3-level flat Graph Type prob various spanning t waxman Edge Method

72 Scenario Generation scengeneration.html agent-gen-script.tcl Source generator files –source topo-gen.tcl –source agent-gen.tcl –source route-gen.tcl

73 topo-gen.tcl GT-ITM topology –outfile –type : random or transit_stub –nodes –connection_prob

74 route-gen.tcl Routing –outfile –unicast –multicast

75 agent-gen.tcl Agents –outfile –transport –src –sink –num –start –stop

76 Wireless Support: Setup set ns [new Simulator] set chan [new Channel/WirelessChannel] set prop [new Propagation/TwoRayGround] set topo [new Topography] $topo load_flatgrid $prop topology $topo

77 Wireless Support: MobileNode Creating mobile nodes –set mnode [ -create-mobile-node ] – : dsdv or dsr Node coordinates –$mnode set X_ –$mnode set Y_ –$mnode set Z_ 0

78 Mobility Support: Movement Specified –$ns at 1.0 “$mnode setdest ” Random –$ns at 1.0 “$mnode start”