Presentation is loading. Please wait.

Presentation is loading. Please wait.

(Modified from Polly Huang’s and last year’s original)

Similar presentations


Presentation on theme: "(Modified from Polly Huang’s and last year’s original)"— Presentation transcript:

1 (Modified from Polly Huang’s and last year’s original)
ns-2 Tutorial Deepak Bansal 15 September, 2000 (Modified from Polly Huang’s and last year’s original)

2 Why ns? Ubiquity of Tcl, C, C++ languages Access to source code
Discrete event simulator Protocols TCP, UDP, FTP, HTTP, DSR, Wired and wireless media Topology generation Nam visualization tool Standard in research community

3 What is ns? ns is a language
object-oriented tcl (otcl) + extensions for building network simulations. Otcl: object oriented support tclcl: C++ and otcl linkage objects otcl C++ objects Base language Tcl Give an historical perspective? You should probably mention nam here or even on the next page. tclcl ns

4 nam-1

5 ns on Athena Sun workstations
Accessing the course locker: add 6.899 type “ns” or “nam” at your prompt /mit/6.899/software/ns-allinone-2.1b6/bin runs on Linux platforms only (not on Sun!) on Sun, older version of ns exists in sipbnet. For more information, see course web page.

6 Tutorial Roadmap Programming in Tcl and Otcl
Creating simulations in ns Adding new primitives to ns Tracing

7 Tcl and Otcl Language Basics

8 Basic tcl athena% ns % proc occur {value list} { set count 0
% set a 24 % set b 15 % set c [expr $a + $b] % set colors {red green blue purple} % proc occur {value list} { set count 0 foreach el $list { if $el == $value { incr count } return $count % set nblues [occur blue $colors] % puts “I have $nblues blues” I have 1 blues Ask who has ever used Tcl? How many people have ever extended the Tcl interpreter before? I think, give everything with the interpreter. Then mention that, of course, you could put all of these commands together into a file. Pass them to ns and ns will execute them sequentially.

9 Basic otcl % Class Bagel % Bagel instproc toast {} {
.% set abagel [new Bagel] _o11 % $abagel info class Bagel % Bagel info instances % Bagel instproc init {args} { $self instvar toasted_ set toasted_ 0 eval $self next $args } % Bagel instproc toast {} { $self instvar toasted_ incr toasted_ if {$toasted>1} then { error "something's burning!" } return {} % $abagel toast something's burning! May consider adding another slide to this to illustrate superclasses.

10 Basic ns-2

11 Creating Event Scheduler
Create scheduler set ns [new Simulator] Schedule event $ns at <time> <event> <event>: any legitimate ns/tcl commands Start scheduler $ns run

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

13 Creating a simple simulation
# Create a topology Set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail # Add agents set tcp [$ns create-connection Agent/TCP $n0 Agent/TCPSink $n1 0] set ftp [$tcp attach-app FTP] # Create a schedule $ns at 0.5 "$ftp start" $ns at 4.5 "$ftp stop" #Run the simulation $ns run FTP TCP FTP How are you going to fit this whole thing onto one slide? Consider making one slide for the topology, one time to schedule the events. TCP 1Mb n0 n1 10ms

14 ns-2 Internal

15 Routing 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

16 Transport n0 n1 1 1 Port Classifier 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

17 Application n0 n1 1 1 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

18 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

19 Extending ns-2 Simulator

20 otcl and C++: The Duality
C++ for data per packet action otcl for control periodic or triggered action

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

22 TclClass TclObject Agent Agent/FBI FBIAgent NsObject ?? OTcl C++
mirroring Static class FBIClass : public TclClass { public: FBIClass() : TclClass(“Agent/FBI”) {} TclObject* create(int, const char*const*) { return (new FBIAgent()); } } class_fbi;

23 TclObject: bind() C++ otcl FBIAgent::FBIAgent() { }
bind(“age_”, age_); } otcl Agent/FBI set age_ 10

24 TclObject: command() C++ otcl
Int FBIAgent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcomp(argv[1], “mature”) == 0) { age_ += atoi(argv[2]); return(TCL_OK); } return (Agent::command(argc, argv); otcl set mulder [new Agent/FBI] $mulder mature 20

25 Tracing Trace all packets on all links
$ns trace-all [open out.w w] <event> <time> <from> <to> <pkt> <size> - - <flowid> <src> <dst> <seqno> <aseqno> Trace all packets on all links in nam-1 format $ns namtrace-all [open out.w w]


Download ppt "(Modified from Polly Huang’s and last year’s original)"

Similar presentations


Ads by Google