NS : The Network Simulator

Slides:



Advertisements
Similar presentations
Wireless world in NS Padma Haldar USC/ISI.
Advertisements

Introduction to Network Simulator NS-2 Part I
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.
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.
Dongsoo S. Kim 1.
Introduction to Wireless simulations Shao-Cheng Wang.
15-744: Computer Networking ns-2 Tutorial Based on slides from John Heidemann, Polly Huang, and Amit Manjhi.
Network Simulator 2 Tejas Vasavada.
Katz, Stoica F04 EECS 122 Introduction to Computer Networks (Fall 2003) Network simulator 2 (ns-2) Department of Electrical Engineering and Computer Sciences.
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.
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.
Ns Simulation of IEEE SC546 Project (Fall 2002) SOO IL KIM JISUN YOON
Introduction to Network Simulator NS-2 Part II
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.
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.
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.
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 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.
1 Part II: ns Internals. USC INFORMATION SCIENCES INSTITUTE 2 Outline Fundamental concept Split object: C++/OTcl linkage Plumbing Wired Wireless Scaling.
The Creation of NS2 Simulated Environment ( 1 ) LI Chengbo
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
DMET 602: Networks and Media Lab Amr El Mougy Yasmeen EssamAlaa Tarek.
ECE 6610 Sandeep Kakumanu GNAN research Lab
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Chapter 16 Mobile Networking in ns
Mobicom ‘99 Per Johansson, Tony Larsson, Nicklas Hedman
Introduction to ns-2: “The” Network Simulator
Ns By Kulveer Singh.
Karthik Sadasivam Banuprasad Samudrala
Introduction to ns-2 Noun Choi Oct. 11, 2007.
TexPoint fonts used in EMF.
Presentation transcript:

NS : The Network Simulator

NS-2 OVERVIEW Working with NS-2 Extending NS-2

NS Goals Support networking research and education Protocol design, traffic studies, etc Protocol comparison Provide a collaborative environment Freely distributed, open source Share code, protocols, models, etc Allow easy comparison of similar protocols Increase confidence in results More people look at models in more situations Experts develop models Multiple levels of detail in one simulator

The Network Simulator Event driven simulator for networking research. For free, not commercial NS-2 is an object oriented simulator, written in C++, with an OTcl (Object Tool Command Language) interpreter as a front-end. Use OTcl: for configuration, setup, and “one-time”' stuff if you can do what you want by manipulating existing C++ objects Use C++: if you are doing anything that requires processing each packet of a flow if you have to change the behaviour of an existing C++ class in ways that weren't anticipated

Why Two Languages? Simulator 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 change Otcl runs much slower but can be changed quickly For information about the idea of scripting languages and split-language programming, see John Ousterhout. Scripting: Higher-level programming for the 21st century. IEEE Computer, 31(3):23-30, March 1998. For more information about split level programming for network simulation, see Improving simulation for network research. Technical Report 99-702b, University of Southern California, March 1999. (revised September 1999).

Discrete Event Simulation 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 NS uses simple model: single thread of control => no locking or race conditions to worry about (very easy)

Discrete Event Example Consider two nodes Simple t=1, A enqueues pkt on LAN on an Ethernet: queuing t=1.01, LAN dequeues pkt model and triggers B detailed CSMA/CD model t=1.0: A sends pkt to NIC A’s NIC starts carrier sense t=1.005: A’s NIC concludes cs, starts tx t=1.006: B’s NIC begins receiving pkt t=1.01: B’s NIC concludes pkt B’s NIC passes pkt to app

NS Protocols Support Wired Networking Routing: Unicast, Multicast, and Hierarchical Routing etc Transportation: TCP and UDP Traffic sources: web, ftp, telnet, cbr, stochastic Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR QoS: IntServ and Diffserv Wireless Networking Ad hoc routing and mobile IP Directed diffusion, sensor-MAC Satellite Networking Routing and Handoff etc. Infrastructure stats, tracing, error models, etc.

NS - Models Traffic models and applications: Web, FTP, telnet, constant-bit rate(CBR), real audio Transport protocols: Unicast: TCP (Reno,Vegas,FullTcp,TcpSack,..), UDP Multicast: SRM (Scalable Reliable Multicast) For More Information : http://www.icir.org/floyd/srm.html Routing and queuing: Wired routing, Ad Hoc routing and directed diffusion Queuing protocols: RED(Random Early Drop), drop-tail, .. Physical media: Wired (point-to-point, LANs), wireless (multiple propagation models), satellite

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

NS - Components Ns, the simulator itself Nam, the network animator Visualize ns (or other) output Nam editor: GUI interface to generate ns scripts Pre-processing: Traffic and topology generators Post-processing: Simple trace analysis, often in Awk, Perl, or Tcl

Other Network Simulators OPNET (http://www.opnet.com) • Commercial Software • Support Windows and Unix • Graphical Interface • Not free GloMoSim (http://pcl.cs.ucla.edu/projects/glomosim) • Simulation environment for wireless network • Scalable to support thousands of nodes • Using layered approach to build different simulation layers • Free for educational users

Help & Resources Ns is not a polished and finished product but the result of an on-going effort of research and development. Supporting OS: FreeBSD, Linux, SunOS, and Solaris, (Windows) Getting Start NS main web page: http://www.isi.edu/nsnam/ns/ Tutorials: http://www.isi.edu/nsnam/ns/tutorial/index.html http://www.isi.edu/nsnam/ns/ns-tutorial/ NS Manual: http://www.isi.edu/nsnam/ns/ns-documentation.html NS Installation Problems, Bug Fixes, and Help http://www.isi.edu/nsnam/ns/ns-problems.html#ns-2.1b9 Source tree courtesy of Shailesh Hingole http://bottleneck.shacknet.nu

Working with NS-2

Install NS-2 • Download software package from: http://www.isi.edu/nsnam/ns/ Easy installation way: all at once • The latest version is 2.1b9a released on July 3, 2002. It contains - Tkrelease 8.3.2 - Otcl release 1.0a8 - TclCL release 1.0b12 - Tcl release 8.3.2 - Ns release 2.1b9a - Nam release 1.0a11a - Xgraph version 12 - CWebversion 3.4g - SGB version 1.0 - Gt-itm gt-itm and sgb2ns 1.1 - Zlib version 1.1.3

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

Running NS-2 Program

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

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

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> <pkt> <flags> <fid> type size <src> <dst> <seq> <uid> + 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 r : receive (at Node); d : Drop ( At Queue) + : enqueue(At Queue); - : Dequeue(At Queue)

Creating Network Point-to-Point Network Defining Nodes set n0 [$ns node] set n1 [$ns node] Connecting Nodes $ns_ <linktype> $n0 $n1 <bandwidth> <delay> <queuetype> <linktype> : simplex-link, duplex-link <queuetype>: DropTail, RED, CBQ, FQ, SFQ, DRR LAN(‘cau PP can’t capture sharing & contentation properties of LAN) $ns_ make-lan “$n0 $n1” $bw $delay LL Queue/DropTail Mac/Csma/Cd

Setup Routes Unicast $ns_ rtproto <type> <list of Nodes> <type> : Static, Session, DV(Dynamic), Manual, etc.(Default is Static) <list of Nodes> : Nodes to run this protocol(Default is all Nodes) Cost Assignment $ns_ cost $n0 $n1 10 MultiPath Routing Node set multipath_ 1 // All Nodes $n1 set multipath_ 1 // only Node 1 Multicast $ns_ multicast (right after [new simulator]) $ns_ mrtproto <type> <type> : CtrMcast, DM(dense Model), ST(shared Tree Model) & BST(Bi-directional Shared Tree Model)

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

Creating Connection TCP set newtcp [new Agent/TCP] [$newtcp set window_ 20] set newtcpsink [new Agent/TCPSink] $ns attach-agent $n0 $newtcp $ns attach-agent $n1 $newtcpsink $ns connect $newtcp $newtcpsink UDP similar replace tcpsink & TCPSink by null & NULL Note : Not all TCP implementations can be used as SOURCE / SINK

Creating Traffic: On Top of TCP FTP set ftp [new Application/FTP] $ftp attach-agent $newtcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $newtcp CBR, Exponential, Pareto set src [new Application/Traffic/CBR]

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

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

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

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

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

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

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

Wireless Simulation MobileNode inherits from Node object. MobileNode = Node + ability to move + receive/transmit signals from a wireless channel. No link object is used Ad-hoc routing protocols DSDV, AODV, TORA, DSR Different network stack for channel access Supports movement / traffic scenarios Movement is always flat (z=0)

Ad Hoc Routing – An Example Scenario 2 mobile nodes moving within 500mX500m flat topology using DSDV ad hoc routing protocol TCP traffic

An Example – Step 1 # Define Global Variables # create simulator set ns_ [new Simulator] # create a topology in a 500m x 500m area set topo [new Topography] $topo load_flatgrid 500 500

Example : Two Mobile Node establish a TCP session between them over a 500x500 grid.

An Example – Step 2 # Define standard ns/nam trace # ns trace set tracefd [open demo.tr w] $ns_ trace-all $tracefd # nam trace set namtrace [open demo.nam w] $ns_ namtrace-all-wireless $namtrace 500 500

An Example – Step 3 # Create God set god [create-god 2] God: store an array of the smallest number of hops required to reach one node to an other Optimal case against which to compare routing protocol performance Automatically generated by scenario file

An Example – Step 4 # Define how a mobile node should be created $ns_ node-config \ -adhocRouting DSDV \ -llType LL \ -macType Mac/802_11 \ -ifqLen 50 \ -ifqType Queue/DropTail/PriQueue \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \ -topoInstance $topo -agentTrace ON \ -routerTrace OFF \ -macTrace OFF

An Example – Step 5 Single Node # Create a mobile node, attach it to the channel set node_(0) [$ns_ node] # disable random motion $node_(0) random-motion 0 Set of Nodes Use “for” loop to create 2 or more nodes: for {set i < 0} {$i < 2} {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 }

An Example – Step 6 # Define node movement model source movement-scenario-files # Define traffic model source traffic-scenario-files

Scenario Generator: Movement Mobile Movement Generator setdest -n <num_of_nodes> -p <pausetime> -s <maxspeed> -t <simtime> -x <maxx> -y <maxy> Source: ns-2.1b9/indep-utils/cmu-scen-gen/setdest/ Random movement $node start

An Example – Step 6 Node Movement $node_(0) set X_ 200.00 $node_(0) set Y_ 400.00 $node_(1) set Y_ 350.00 $node_(0) set Z_ 0.00 $node_(1) set Z_ 0.00 $ns_ at 10 $node_(0) setdest 400.00 300.00 5.00 $ns_ at 12 $node_(1) setdest 300.00 150.00 10.00 Always test your changes/debug with a small set of nodes like above

Scenario Generator: Traffic Generating traffic pattern files CBR traffic ns cbrgen.tcl [-type cbf|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] TCP traffic ns tcpgen.tcl [-nn nodes] [-seed seed] Source: ns-2.1b9/indep-utils/cmu-scen-gen/

A Traffic Scenario set newtcp [new Agent/TCP] [$newtcp set window_ 20] set newtcpsink [newAgent/TCPSink] $ns attach-agent $node_(0) $newtcp $ns attach-agent $node_(1) $newtcpsink Set app [new Application/FTP] $app_(0) attach-agent $newtcp $ns_ connect $newtcp $newtcpsink $newtcpsink listen $ns_ at 5.00 "$app_(0) start"

An Example – Step 7 # Define node initial position in nam for {set i 0} {$i < 2 } { incr i} { $ns_ initial_node_position $node($i) 20 } set val_(stop) 50.0 # Tell ns/nam the simulation stop time for { set i 0} { $i < 2} {incr I} { $ns_ at $val(stop).0 “$node_($I) reset”; $ns_ at $val_(stop).0001 “stop” $ns_ at $val_(stop).0002 “$ns_ halt” proc stop { } { global ns_ tracefd close $tracefd # Start your simulation $ns_ run

Internals: Relevant Components

Mobile Node

Mobile Node : Components Link Layer Same as LAN, but with a separate ARP module Sends queries to ARP ARP Resolves IP address to hardware(MAC) address Broadcasts ARP query Interface Queue Gives priority to routing protocols packets Has packet filtering capacity MAC 802.11 RTS/CTS/DATA/ACK for unicast Sends DATA directly for broadcast SMAC (work under progress)

Mobile Node : Components Network Interface (PHY) Used by mobile node to access channel Stamps outgoing pkts with meta-data Interface with radio/antenna models Radio Propagation Model Friss-space model – attenuation at near distance Two-ray ground reflection model for far distance Shadowing model – probabilistic Antenna Omni-directional, unity gain Wireless Channel Duplicate packets to all mobile nodes attached to the Channel except the sender It is the receiver’s responsibility to decide if it will Accept the packet

SMAC SMAC – MAC designed for sensor networks Similar RTS/CTS/DATA/ACK like 802.11 Additional sleep-wakeup cycles Reduces energy consumptions during idle phases Much in development

Energy Extension Node is energy-aware Define node by adding new options: $ns_ node-config \ -energyModel $energymodel \ -initialEnergy 100.0 \ -txPower 0.6 \ -rxPower 0.2

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

A Brief on 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

Extending NS-2

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

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

Two Imp. Tcl files ns-default.tcl: The default values for configurable parameters for various network components are located here. Since most of network components are implemented in C++, the configurable parameters are actually C++ variables made available to OTcl via an OTcl linkage function, bind(C++_variable_name, OTcl_variable_name).   ns-packet.tcl: The packet header format initialization implementation is located here. When you create a new packet header, you should register the header in this file to make the packet header initialization process to include your header into the header stack format and give you the offset of your header in the stack.

Extending NS in C++ 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)

Adding New Classes variables procedures New Class otcl New Class bind() command() otcl TclClass() New Class variables procedures C++

New Packet Header Enable Tracing(packet.h) enum packet_t { PT_TCP, …, PT_<NewName1>, PT_NTYPE // This must be Last one } class p_info { ….. name_[PT_<NewName1>] = “<NewName2>”; name_[PT_NTYPE] = “undefined”; … Register New Header (tcl/lib/ns-packet.tcl) foreach prot { { common off_cmn_ } …. { <NewName2> off_<NewName3>_ }

TclObject::bind() Link C++ member variables to OTcl object variables TcpAgent::TcpAgent() { bind(“window_”, &wnd_); … … } 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

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

Calling C++ functions from Otcl 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); OTcl set tcp [new Agent/TCP] $tcp advance 10

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

Credit CMU UC Berkeley Sun Microsystem Inc. USC/ISI

Installing NS-2.1b9 Download may take a long time, so I have kept a copy of it on topaz under /usr/work/mkumar. If you have login for cs server, you can access it by using mkumar@topaz.cs.binghamton.edu:/home/grad/mkumar/ns-allinone-2.1b9.tar.gz as src Sun/Linux Error Message : tclsh/namespace : Invalid command/command not found Soln. : touch ~tcl8.3.2/generic/tclStubInit.c Error Message On Linux: common/tclAppInit.cc:103: parse error before `::‘ Soln. edit ns-2.1b9/common/tclAppInit.cc put a space or two between the colons on that line.  It will end up looking like this:       asm volatile ("fldcw %0" :  : "m" (cw)); Error Message On Sun Machines : gcc: pic: No such file or directory (and/or) gcc: unrecognized option `-K' Soln. Line 139 in otcl-1.0a8/configure.in, line 17 in otcl-1.0a8/Makefile.in & Line 4266/4273 in otcl-1.0a8/configure Replace "-K pic” by “-fpic”