Su Wen Department of Computer Science

Slides:



Advertisements
Similar presentations
Wireless Communication : LAB 3
Advertisements

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,
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.
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.
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)
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.
Ns Simulation of IEEE SC546 Project (Fall 2002) SOO IL KIM JISUN YOON
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.
Introduction to NS2 -Network Simulator- -Prepared by Changyong Jung.
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-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,
NS2Work1 LAB 5 Adding New Components High level scripting in otcl Linking otcl and C++ Low level in C++
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.
Network Simulation and Simulator Internals 潘仁義
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.
NS-2 Simulator 최 종 훈 Contents  About NS  Installation  Based on Linux  Based on Windows  Architecture  Using NS-2  Example  References.
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Introduction to ns-2: “The” Network Simulator
Ns By Kulveer Singh.
Karthik Sadasivam Banuprasad Samudrala
Network Performance modelling and simulation
Aga Zhang Dependable Computing Lab
Presentation transcript:

Su Wen Department of Computer Science suwen@dcs.uky.edu ns-2 Network Simulator Su Wen Department of Computer Science suwen@dcs.uky.edu

Background VINT: Virtual InterNet Testbed Intended audience Researchers, Developers, Educators Users from approximately 600 institutes 50 countries Releases Periodic releases (currently 2.1b7, Oct. 2000) Nightly snapshots (probably compiles and works, but “unstable”) Ns is developed for the VINT project, it is intended give researchers, educator and developer a common platform for research. Now ns has become the most popular network simulation tools used by researchers and developers alike. A number of ns versions have been relased

What is NS Discrete event simulator Simulates: Wired world Wireless Object-oriented (C++, Otcl) Simulates: Wired world Point-to-point link, LAN Unicast/multicast routing Transport Application layer Wireless Mobile IP Ad hoc routing Satellite network

Research Using NS intserv/diffserv (QoS) Multicast Transport Routing Reliable multicast Transport TCP Congestion control Application Web caching Multimedia

Current Status ns-2 (2.1b6) Simulator Core Other Components 100K lines of C++ 70K lines of OTcl 30K lines of test suite 20K lines of documentation Other Components Tcl/TK 8.x, OTcl, TclCL, nam-1 Tcl-debug, GT-ITM, xgraph, …

ns Directory Structure ns-allinone Tcl8.0 TK8.0 OTcl tclcl ns-2 nam-1 tcl ... C++ code ex test lib mcast ... examples validation tests OTcl code

Platforms Most UNIX and UNIX-like systems Window 95/98/NT FreeBSD or *BSD Linux Sun Solaris HP, SGI Window 95/98/NT Some work, some does not

Running simulations with ns Compile the simulator core (“ns”) Write a simulation script in Otcl e.g. my-test.tcl Running the simulator e.g. ns my-test.tcl

Hello World simple.tcl arches 74% ns simple.tcl Hello World! set sim [new Simulator] $sim at 1 “puts \“Hello World!\”” $sim at 1.5 “exit” $sim run arches 74% ns simple.tcl Hello World! arches 75%

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

Creating Event Scheduler Create event scheduler set ns [new Simulator] Schedule events $ns at <time> <event> <event>: any legitimate ns/tcl commands e.g [$ftp start] Start scheduler $ns run

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

Tracing Trace packets on all links $ns trace-all [open test.out w] Must appear immediately after creating scheduler Turn on tracing on specific links $ns trace-queue $n0 $n1 <event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr> + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

Creating Network Nodes Links and queuing set n0 [$ns node] $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR

Setup Routing Unicast Multicast $ns rtproto <type> <type>: Static, Session, DV, cost, multi-path Multicast $ns multicast (right after [new Simulator]) $ns mrtproto <type> <type>: CtrMcast, DM, ST, BST

Network Topology: Node Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry Multicast Classifier classifier_ dmux_ entry_ Node entry Multicast Node multiclassifier_ Unicast Node

Network Topology: Link duplex link enqT_ queue_ deqT_ drophead_ drpT_ link_ ttl_ n1 entry_ head_ tracing simplex link

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

Inserting Errors Creating Error Module Inserting Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module ranvar [new RandomVariable/Uniform] Inserting Error Module $ns lossmodel $loss_module $n0 $n1 Link failures

Routing n0 n1 1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry enqT_ queue_ deqT_ drophead_ drpT_ link_ ttl_ n1 entry_ head_ 1

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

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

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

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

Writing a Simulation Script Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic Transmit application-level data

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 CBR, Exponential, Pareto

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

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

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

Emulation in ns Simulator  real network Usage Inject received packets into simulation Emit packets on to live network Usage Subject real implementations to controlled conditions in the simulator Subject simulations to real-world traffic Currently only works on FreeBSD

Summary: Generic Script Structure set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - multicast groups # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation

Cautions People tried best to validate ns with regression tests However: abstraction of the real world is necessary for a simulator You must justify the usage of this simulator based on your research goals

Creating New Components Extending ns in Otcl source your changes in your simulation scripts Extending ns in C++ Change Makefile (if created new files) make depend recompile

C++ Guidelines Decide position in class hierarchy i.e., which class to derive from? Create new packet header (if necessary) Create C++ class, fill in methods Define OTcl linkage (if any) Write OTcl code (if any) Build (and debug)

Class Hierarchy in ns TclObject NsObject Connector Classifier Queue Delay Agent Trace AddrClassifier McastClasifier DropTail RED TCP Enq Deq Drop Reno SACK JS

TCP Jump Start – Step 1 New file: tcp-js.h class JSTCPAgent : public TcpAgent { public: virtual void set_initial_window() { cwnd_ = MAXWIN_; } private: int MAXWIN_; };

TCP Jump Start – Step 2 New file: tcp-js.cc bind(“MAXWIN_”, MAXWIN_); static JSTcpClass : public TclClass { public: JSTcpClass() : TclClass("Agent/TCP/JS") {} TclObject* create(int, const char*const*) { return (new JSTcpAgent()); } }; JSTcpAgent::JSTcpAgent() { bind(“MAXWIN_”, MAXWIN_);

TclObject: Hierarchy and Shadowing OTcl class hierarchy C++ class hierarchy TclObject TclObject static JSTcpClass : public TclClass { public: JSTcpClass():TclClass("Agent/TCP/JS"){} TclObject* create(int,const char*const*) { return (new JSTcpAgent());} }; Agent Agent Agent/TCP/JS JSTcpAgent _o123 *tcp Agent/TCP/JS OTcl shadow object Agent/TCP/JS C++ object

TclObject: Creation and Deletion Agent/TCP/JS constructor Agent/TCP constructor invoke parent TclObject constructor create C++ object invoke parent constructor which C++ object to create? – TclClass JSTCPAgent constructor invoke parent complete initialization complete initialization create OTcl shadow object OTcl C++ do nothing, return TclObject (C++) constructor invoke parent constructor parent (Agent) bind variables and return bind variables and return

TclObject::bind() Link C++ member variables to OTcl object variables TcpAgent::TcpAgent() { bind(“window_”, &wnd_); … … } bind_time(), bind_bool(), bind_bw() OTcl set tcp [new Agent/TCP] $tcp set window_ 200

Initialization of Bound Variables Initialization through OTcl class variables Agent/TCP set window_ 50 Do all initialization of bound variables in ~ns/lib/ns-default.tcl Otherwise a warning will be issued when the shadow object is created

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

TclObject::command() OTcl space no such procedure $tcp send TclObject::unknown{} $tcp cmd send C++ space TcpAgent::command() match “send”? Yes No process and return Invoke parent: return Agent::command()

Calling Otcl functions from C++ Agent/TCP instproc advance {num} { set window_ [expr $window_ + $num] return $window_ } C++ Tcl& tcl = Tcl::instance(); char *result; tcl.evalf(“%s advance %d”, name_, size); result = tcl.result(); wnd_ = atoi(result);

EmbeddedTcl How it works Makefile.in: tcl2c++: provided by TclCL, converts tcl scripts into a C++ static character array Makefile.in: tclsh8.0 bin/tcl-expand.tcl tcl/lib/ns-lib.tcl | tcl2c++ et_ns_lib > gen/ns_tcl.cc

Summary TclObject TclClass Tcl: primitives to access Tcl interpreter Unified interpreted (OTcl) and compiled (C++) class hierarchies Seamless access (procedure call and variable access) between OTcl and C++ TclClass The mechanism that makes TclObject work Tcl: primitives to access Tcl interpreter

Extending ns in OTcl ns-allinone Tcl8.0 TK8.0 OTcl tclcl ns-2 nam-1 ... C++ code ex test mysrc lib mcast ... examples validation tests msg.tcl OTcl code

Add Your Changes into ns source your changes in your sim scripts Or add to tcl/lib/ns-lib.tcl … source ../mysrc/msg.tcl Change Makefile NS_TCL_LIB = \ tcl/mysrc/msg.tcl \ Recompile

Scalability vs Flexibility It’s tempting to write all-OTcl simulation Benefit: quick prototyping Cost: memory + runtime Solution Control the granularity of your split object by migrating methods from OTcl to C++ Conventional Wisdom: C++ for “data” Per packet action OTcl for control Periodic or triggered action

Program size, complexity THE Merit of OTcl Program size, complexity low high C/C++ OTcl split objects Smoothly adjust the granularity of scripting to balance extensibility and performance With complete compatibility with existing simulation scripts

Object Granularity Tips Functionality Per-packet processing  C++ Hooks, frequently changing code  OTcl Data management Complex/large data structure  C++ One-time configuration variables  OTcl

Memory Conservation Tips Avoid trace-all Use arrays for a sequence of variables Instead of n$i, say n($i) Avoid OTcl temporary variables Use dynamic binding delay_bind() instead of bind() See object.{h,cc}

Memory Leaks Purify or dmalloc, but be careful about split objects: for {set i 0} {$i < 500} {incr i} { set a [new RandomVariable/Constant] } It leaks memory, but can’t be detected! Solution Explicitly delete EVERY split object that was new-ed

ns Wireless World Ad hoc routing Mobile IP Satellite networking

Ad hoc Routing Mac Layer: IEEE 802.11 Address Resolution Protocol (ARP) Ad hoc routing protocols: DSDV, DSR,TORA, AODV Radio Propagation Model Friss-space attenuation at near distances Two ray ground at far distances Antenna: an omni-directional antenna having unity gain

Satellite Networking Developed by Tom Henderson (UCB) Supported models Geostationary satellites: bent-pipe and processing-payload Low-Earth-Orbit satellites Example: tcl/ex/sat-*.tcl Much in-development

MobileIP Support Developed by Sun Standard MobileIP Example Require a different Node structure than the MobileNode Co-exists with wired world in ns Standard MobileIP Home Agent, Foreign Agent, MobileHosts… Example ~ns/tcl/ex/wired-cum-wireless.tcl

Visualization Tools nam-1 (Network AniMator Version 1) xgraph Packet-level animation Well supported by ns Turn on tracing $ns namtrace-all [open test.nam w] $ns namtrace-queue $n0 $n1 xgraph Conversion from ns trace to xgraph format

nam

Topology Generation http://www.isi.edu/nsnam/ns/ns-topogen.html

GT-ITM Installation Usage Three graph models Comes with ns-allinone Require Knuth’s cweb and SGB Usage itm <config_file> Three graph models Flat random: Waxman n-level hierarchy Transit-stub

GT-ITM: Transit-Stub Model domains transit-transit link stub-stub link stub domains

Converters for GT-ITM sgb2ns sgb2hier Convert SGB format to ns config file sgb2ns <SGB_file> <OTcl_file> ts2ns: output lists of transit and stub nodes sgb2hier Convert transit-stub information into hierarchical addresses sgb2hierns <SGBFile> <TclFile>

Getting Help ns-2 Webpage ns-2 Mailing List Tutorial Notes http://www.isi.edu/nsnam/ns/ ns-2 Mailing List ns-users@isi.edu Tutorial Notes http://www.isi.edu/nsnam/dist/ns-workshop00

Installation Getting the pieces Other utilities Tcl/TK 8.x (8.0.5 preferred): http://dev.scriptics.com OTcl, TclCL, ns-2, nam-1: http://www.isi.edu/nsnam/dist Other utilities http://www.isi.edu/nsnam/ns/ns-build.html Tcl-debug, GT-ITM, xgraph, …

Resources Tcl (Tool Command Language) OTcl (MIT Object Tcl) http://dev.scriptics.com/scripting OTcl (MIT Object Tcl) ~otcl/doc/tutorial.html (in distribution) ns manual Included in distribution: ~ns/doc http://www.isi.edu/~salehi/ns_doc.ps.gz

Final Word My extended ns dumps OTcl scripts! Find the last 10-20 lines of the dump Is the error related to “_o*** cmd …” ? Check your command() Otherwise, check the otcl script pointed by the error message