1 / 25

ns-2 Tutorial

ns-2 Tutorial . Deepak Bansal bansal@mit.edu http://nms.lcs.mit.edu/~bansal 15 September, 2000 (Modified from Polly Huang’s and last year’s original). Why ns?. Ubiquity of Tcl, C, C++ languages Access to source code Discrete event simulator Protocols TCP, UDP, FTP, HTTP, DSR,

zena
Télécharger la présentation

ns-2 Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ns-2 Tutorial Deepak Bansal bansal@mit.edu http://nms.lcs.mit.edu/~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 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 % 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 athena% ns % set a 24 % set b 15 % set c [expr $a + $b] % set colors {red green blue purple}

  9. % Class Bagel .% set abagel [new Bagel] _o11 % $abagel info class Bagel % Bagel info instances _o11 % 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 % $abagel toast something's burning! Basic otcl

  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 • set n0 [$ns node] • set n1 [$ns node] • Links & Queuing • $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR

  13. FTP TCP 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 1Mb n0 n1 10ms

  14. ns-2 Internal

  15. n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 1 dmux_ dmux_ 1 0 entry_ entry_ classifier_ classifier_ Link n1-n0 Routing Link n0-n1

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

  17. Application/FTP dst_=0.0 dst_=1.0 0 1 1 0 Application n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier Agent/TCPSink Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

  18. dst_=0.0 dst_=1.0 0 1 1 0 Packet Flow n0 n1 Port Classifier Application/FTP Port Classifier Addr Classifier Addr Classifier Agent/TCPSink Agent/TCP 0 0 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 C++ otcl

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

  22. mirroring C++ OTcl TclObject TclObject NsObject ?? Agent Agent FBIAgent Agent/FBI TclClass • 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++ FBIAgent::FBIAgent() { bind(“age_”, age_); … } • otcl Agent/FBI set age_ 10

  24. TclObject: command() • C++ 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]

More Related