NS2 Tutorial Aga Zhang Dependable Computing Lab. Outline Introduction Fundamental Skills - Tcl and OTcl Network Simulator - ns-2 Study Project - Mobile.

Slides:



Advertisements
Similar presentations
1 NS-2 Tutorial COMP R2 University of Manitoba March 4, 2009.
Advertisements

Wireless Communication : LAB 3
Introduction to Network Simulator NS-2 Part I
1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)
An Introduction to NS-2 * Gayatri Swamynathan CS 276 TA *some slides are from a presentation by Haobo Yu & Nader Salehi, USC/ISI.
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.
Network Simulator (NS) Prof. Nelson L. S. da Fonseca State University of Campinas, Brazil.
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.
1 Network Simulation and Testing Polly Huang EE NTU
1 Chapter 3 Otcl Linkage Presenter : 吳龍淵 張群正 2002/03/26.
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,
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.
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Performing RWA Simulation With NS An introduction to NS & RWA simulation constructs.
Wireless Networking and Systems CSE 590 ns2 tutorial.
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 / 10 Mobile Networking in ns Speaker : Mark Yang
NS2 Tutorial for CS740 Jianming Wu *modified from Aga Zhang.
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.
Tcl and Otcl Tutorial Part II Internet Computing KUT Youn-Hee Han.
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.
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
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.
Chapter 15 The Addressing Structure in NS. The Default Address Format 32 lower bits for port-id, 1 higher bit for mcast and the rest 32 higher bits for.
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 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++
Performance Validation of Mobile IP Wireless Networks Presented by Syed Shahzad Ali Advisor Dr. Ravi Pendse.
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
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
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.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
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.
Jae Chung and Mark Claypool
ECE 6610 Sandeep Kakumanu GNAN research Lab
(Modified from Polly Huang’s and last year’s original)
NS2_Trace and Monitoring support 報告者:羅士捷
Introduction to ns-2: “The” Network Simulator
Introduction to NS Srinath Perur.
Karthik Sadasivam Banuprasad Samudrala
Network Performance modelling and simulation
Introduction to ns-2 Noun Choi Oct. 11, 2007.
Aga Zhang Dependable Computing Lab
Presentation transcript:

NS2 Tutorial Aga Zhang Dependable Computing Lab

Outline Introduction Fundamental Skills - Tcl and OTcl Network Simulator - ns-2 Study Project - Mobile IP Conclusions

Introduction NS2 history –Modified from REAL network simulator –Developed through VINT project at UCB –NS1 vs. NS2 NS version2 is a discrete-event driven and object-oriented network simulator –Type of simulation: continuous, discrete event, and combined Events  Packet and Timer R1R2 Ack TCP Packet Retransmit timer start Retransmit

Fundamental Skills (I) Scripting language is used to describe a high-level programming language with relatively transparent syntax button.b text Hello! –command {puts hello} ---- tcl command Scripting language—Unix shells(sh, csh, …), Tcl, Perl,VB, and JavaScript All major computing platforms provide both system programming languages such as C or Java and scripting languages such as Tcl

Fundamental Skills (II) NS2 is written in C++ and OTcl –OTcl = Tcl + OO –C++ implements the code that executed frequently –OTcl configures the system set ns [new Simulator] set n1 [new Node] set n2 [new Node] $ns duplex-link $n1 $n2 5Mb 2ms DropTail n1n2

Tcl – Tool Command Language Start: Typing “tclsh” in Unix shell Instructions using in ns2: proc add2 {a} { set b [expr $a+1] incr b puts “a+2=$b” } add2 55  57 set ll [list a b c] lappend $ll d  a b c d lindex $ll 0  a llength $ll  4 lsearch linsert lreplace split a.b.  a b source file  include foreach info exists varNam info tclversion

OTcl – MIT Object Tcl Class father father instproc init {args} { $self set var_ 0 puts “**var_=$var_” eval $self next $args } father ff  **var_=0 ff info vars  var_ ff set var_  0 ff info class  father father info instances  ff Class son –superclass father son instproc init {args} { puts “no var_” } son ss  no var_ Class son2 –superclass father son instproc init {args} { puts “no var_” $self next $args } son2 ss  no var_ **var_=0

OTcl Linkage set tcp [new Agent/TCP] init Agent/TCP init Agent Create Otcl shadow object TclObject Create C++ object constructor TclObject (C++) constructor parent constructor TcpAgent OTcl C++ static class TcpClass : public TclClass { public: TcpClass() : TclClass( "Agent/TCP" ) {} TclObject* create(int, const char*const*) { return (new TcpAgent );} } class_tcp;

OTcl Linkage (II) Command() Otcl $tcp advance 10 C++ int Agent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcmp(argv[1], “advance") == 0) { int newswq = atoi(argv[2]); return (TCL_OK); } return (Agent::command(argc, argv); }

OTcl Linkage (III) bind(): link C++ member variables to Otcl object variables C++ TcpAgent::TcpAgent() { bind(“window_”, &wnd_); } // bind_time(), bind_bool(), bind_bw() Otcl $tcp set window_ 200 You must setting the initial values of variants in ~ns/tcl/lib/ns- default.tcl

OTcl Linkage (IV) Invoking Otcl procedure and obtaining its results Tcl::instance().evalf("%s Lookup_CIP_RT %d", name(), iph->dst().addr_); nextHop = Tcl::instance().result(); Classifier/Addr/Cip instproc Lookup_CIP_RT { m_addr } { return … } Passing a results string to Otcl Tcl::instance().result(“………”) Buffer

Network Simulator - ns-2 After installing: Add the path of ns2 to your profile, and validate your ns2 Modifying *.cc or *.tcl file if add new one adding its path to makefile(.cc) or ~ns/tcl/lib/ns-lib.tcl(.tcl) Type: make depend  make Or make clean  configure –enable--debug  make

The directory of ns2

Simple code (I) Simple.tcl Run your program  % ns Simple.tcl

Simple code (II)

Simple code (III)

Simple code (IV)

Simple code (V)

Study Project - Mobile IP Configuring mobile node, HA, and FA New packet header Setting timer for advertisement and registration Processing handoff

Configure mobile node, HA, and FA Wired node – set node(0) [$ns_ node] Wireless&wired node routingAgent_ OFF  MN

Motion # Create HA and FA set HA [$ns_ node 1.0.0] set FA [$ns_ node 2.0.0] $HA random-motion 0 $FA random-motion 0 # Position for base-station nodes (HA & FA). $HA set X_ $HA set Y_ $HA set Z_ $FA set X_ $FA set Y_ $FA set Z_ # create a mobilenode $ns_ node-config -wiredRouting OFF set MH [$ns_ node 1.0.1] set node_(0) $MH set HAaddress [AddrParams addr2id [$HA node-addr]] [$MH set regagent_] set home_agent_ $HAaddress # movement of the MH $MH set Z_ $MH set Y_ $MH set X_ # MH starts to move towards FA $ns_ at "$MH setdest " # goes back to HA $ns_ at "$MH setdest " Initial position Close random motion destination speed

Mobile Node Agent 0 1 Node

Base-Station

Packet header Access packet header: hdr_ip *iph = hdr_ip::access(p); hdr_cmn *ch = hdr_cmn::access(p); …………………… iph->dst() = iph->src(); struct hdr_ip { …………………. static int offset_; // required by PacketHeaderManager inline static hdr_ip* access(Packet* p) { return (hdr_ip*) p->access(offset_); } offset_

New MIP packet header Data-structure struct hdr_mip { int haddr_; int ha_; int coa_; MipRegType type_; //MIPT_REG_REQUEST, MIPT_REG_REPLY, MIPT_ADS, MIPT_SOL double lifetime_; int seqno_; static int offset_; inline static hdr_mip* access(const Packet* p) { return (hdr_mip*) p->access(offset_); } }; Setting: ~ns/comm/packet.h and ~ns/tcl/lib/ns-packet.tcl Access: hdr_mip *miph = hdr_mip::access(p) static class MIPHeaderClass : public PacketHeaderClass { public: MIPHeaderClass() : PacketHeaderClass("PacketHeader/MIP", sizeof(hdr_mip)) { bind_offset(&hdr_mip::offset_);} } class_miphdr;

New Agent New Agent for sending registration packet periodically Data-structure class MIPMHAgent : public Agent { public: MIPMHAgent(); void recv(Packet *, Handler *); void timeout(int); protected: void reg(); int ha_; /* home agent address */ int coa_; /* care-of-address */ double reg_rtx_; /* retransmitting time */ SimpleTimer rtx_timer_; RegTimer reg_timer_; double reglftm_;/* registration lifetime */ double adlftm_; /* current ads lifetime */ }; class SimpleTimer : public TimerHandler { public: SimpleTimer(Agent *a) : TimerHandler() { a_ = a; } protected: inline void expire(Event*){ a_>timeout(MIP_TIMER_SIMPLE); } Agent *a_; }; class RegTimer : public TimerHandler { public: RegTimer(MIPMHAgent *a) : TimerHandler() { a_ = a; } protected: Inline void expire(Event *) { a_->timeout(MIP_TIMER_REG);} MIPMHAgent *a_;};

New Agent (II) Time-out void MIPMHAgent::timeout(int tno){ switch (tno) { case MIP_TIMER_SIMPLE: reg(); break; case MIP_TIMER_REG: seqno_++; reg(); break; default: break; } Receiving reply void MIPMHAgent::recv(Packet* p, Handler *){ Tcl& tcl = Tcl::instance(); hdr_mip *miph = hdr_mip::access(p); switch (miph->type_) { case MIPT_REG_REPLY: tcl.evalf("%s update-reg %d", name_, coa_); if (rtx_timer_.status() == TIMER_PENDING) rtx_timer_.cancel(); reg_timer_.resched(miph->lifetime_-0.5); break; case MIPT_ADS: reg(); break; default: Packet::free(p); break; }

New Agent (III) class MIPMHAgent : public Agent { public: MIPMHAgent(); void recv(Packet *, Handler *); ……………………….. SimpleTimer rtx_timer_; RegTimer reg_timer_; }; static class MIPMHAgentClass : public TclClass { MIPMHAgentClass() : TclClass("Agent/MIPMH") {} TclObject* create(int, const char*const*) { return (new MIPMHAgent()); } } class_mipmhagent; MIPMHAgent::MIPMHAgent() { bind("adSize_", &size_); } void MIPMHAgent::recv(Packet* p, Handler *){ hdr_mip *miph = hdr_mip::access(p); switch (miph->type_) { case MIPT_REG_REPLY: tcl.evalf("%s update-reg %d", name_, coa_); break; case MIPT_ADS: reg(); break; default: Packet::free(p); break; } ~ns/tcl/lib/ns-default.tcl

recv() Class ……….. recv(Packet* p, Handler *) Class ……….. recv(Packet* p, Handler *) Class ……….. recv(Packet* p, Handler *)

Processing handoff $ns_ node-config -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \ ……………………………………… Free space model Two-ray ground reflection model Shadowing model ~ns/mac/wireless-phy.cc RXThresh_

Conclusions Tcl/Tk NAM Xgraph New node Node instproc init args { eval $self next $args …………………….. $self mk-default-classifier …………………….. } foreach modname [Node set module_list_] { $self register-module [new RtModule/$modname] } Simulator instproc set-address-format {opt args} {…}

References Tcl/Tk – Nsnam web pages – NS by example – Tutorial – Marc Greis's tutorial Marc Greis's tutorial Discrete-event simulation software –