extending ns
play

Extending ns Extending ns In OTcl In C++ Debugging Padma Haldar - PDF document

Outline Extending ns Extending ns In OTcl In C++ Debugging Padma Haldar USC/ISI 1 2 ns Directory Structure Extending ns in OTcl ns-allinone If you dont want to compile source your changes in your sim Tcl8.3 TK8.3


  1. Outline Extending ns � Extending ns � In OTcl � In C++ � Debugging Padma Haldar USC/ISI 1 2 ns Directory Structure Extending ns in OTcl ns-allinone � If you don’t want to compile � source your changes in your sim Tcl8.3 TK8.3 OTcl tclcl ns-2 nam-1 scripts � Otherwise tcl ... C+ + code � Modifying code; recompile � Adding new files ex test lib mcast ... • Change Makefile (NS_TCL_LIB), examples validation tests tcl/lib/ns-lib.tcl OTcl code • Recompile 3 4 Example: Agent/Message Agent/Message pkt: 64 bytes Receiver-side of arbitrary processing string S R C n2 n4 C cross 128Kb, 50ms traffic n0 n1 � A UDP agent (without UDP header) 10Mb, 1ms 10Mb, 1ms � Up to 64 bytes user message S n3 R n5 � Good for fast prototyping a simple idea msg agent � Usage requires extending ns functionality 5 6 1

  2. Agent/Message: Step 1 Agent/Message: Step 2 � Define sender � Define sender packet processing class Sender class Sender –superclass superclass Agent/Message Agent/Message Sender Sender instproc instproc recv recv msg msg { # Message format: “ # Message format: “Addr Addr Op Op SeqNo SeqNo” $self $self instvar instvar agent_addr agent_addr _ Sender instproc Sender instproc send send-next {} { next {} { set sdr set sdr [lindex lindex $msg msg 0] 0] $self instvar $self instvar seq seq_ _ agent_addr agent_addr_ set seq set seq [lindex lindex $msg msg 2] 2] $self send “$ $self send “$agent_addr agent_addr_ send $ _ send $seq seq_” _” puts "Sender gets puts "Sender gets ack ack $seq seq from $ from $sdr sdr " incr seq incr seq_ } global ns global ns $ns at [ $ns at [expr expr [$ns now]+0.1] "$self send [$ns now]+0.1] "$self send-next" next" } 7 8 Agent/Message: Step 3 Agent/Message: Step 4 � Define receiver packet processing � Scheduler and tracing Class Receiver –superclass Class Receiver superclass Agent/Message Agent/Message # Create scheduler # Create scheduler Receiver Receiver instproc instproc recv recv msg msg { set ns [new Simulator] set ns [new Simulator] $self $self instvar instvar agent_addr agent_addr _ set set sdr sdr [lindex lindex $msg msg 0] 0] # Turn on Tracing # Turn on Tracing set seq set seq [lindex lindex $msg msg 2] 2] set fd set fd [new “ [new “message.tr message.tr” w] ” w] puts “Receiver gets seq puts “Receiver gets seq $seq seq from $ from $sdr sdr ” $ns trace $ns trace-all $ all $ fd fd $self send “$addr $self send “$ addr _ _ ack ack $seq seq” } 9 10 Agent/Message: Step 5 Agent/Message: Step 6 � Topology � Routing for {set i 0} {$i < 6} { for {set i 0} {$i < 6} {incr incr i} { i} { set set n($i n($i) [$ns node] ) [$ns node] # Packet loss produced by # Packet loss produced by queueing queueing } $ns duplex $ns duplex-link $n(0) $n(1) 128kb 50ms link $n(0) $n(1) 128kb 50ms DropTail DropTail $ns duplex $ns duplex-link $n(1) $n(4) 10Mb 1ms link $n(1) $n(4) 10Mb 1ms DropTail DropTail # Routing protocol: let’s run distance # Routing protocol: let’s run distance $ns duplex-link $n(1) $n(5) 10Mb 1ms $ns duplex link $n(1) $n(5) 10Mb 1ms DropTail DropTail vector vector $ns duplex $ns duplex-link $n(0) $n(2) 10Mb 1ms link $n(0) $n(2) 10Mb 1ms DropTail DropTail $ns rtproto $ns rtproto DV DV $ns duplex $ns duplex-link $n(0) $n(3) 10Mb 1ms link $n(0) $n(3) 10Mb 1ms DropTail DropTail $ns queue $ns queue-limit $n(0) $n(1) 5 limit $n(0) $n(1) 5 $ns queue-limit $n(1) $n(0) 5 $ns queue limit $n(1) $n(0) 5 11 12 2

  3. Agent/Message: Step 7 Agent/Message: Step 8 � Cross traffic � Message agents set sdr set sdr [new Sender] [new Sender] set udp0 [new Agent/UDP] set udp0 [new Agent/UDP] $ns attach $ns attach -agent $n(2) $udp0 agent $n(2) $udp0 $sdr sdr set set seq seq_ 0 _ 0 set null0 [new Agent/NULL] set null0 [new Agent/NULL] $sdr sdr set set packetSize packetSize_ 1000 _ 1000 $ns attach -agent $n(4) $null0 $ns attach agent $n(4) $null0 $ns connect $udp0 $null0 $ns connect $udp0 $null0 set rcvr set rcvr [new Receiver] [new Receiver] $rcvr rcvr set set packetSize packetSize_ 40 _ 40 set exp0 [new set exp0 [new Application/Traffic/Exponential] Application/Traffic/Exponential] $ns attach $ns attach-agent $n(3) $ agent $n(3) $sdr sdr $exp0 set rate_ 128k $exp0 set rate_ 128k $ns attach $ns attach-agent $n(5) $ agent $n(5) $rcvr rcvr $exp0 attach -agent $udp0 $exp0 attach agent $udp0 $ns connect $sdr $ns connect $ sdr $rcvr rcvr $ns at 1.0 “$exp0 start” $ns at 1.0 “$exp0 start” $ns at 1.1 “$sdr $ns at 1.1 “$ sdr send send-next” next” 13 14 Agent/Message: Step 9 Agent/Message: Result � End-of-simulation wrapper (as usual) � Example output > ./ns > ./ns msg.tcl msg.tcl Receiver gets Receiver gets seq seq 0 from 3 0 from 3 $ns at 2.0 finish $ns at 2.0 finish Sender gets ack Sender gets ack 0 from 5 0 from 5 proc finish {} { proc finish {} { Receiver gets seq Receiver gets seq 1 from 3 1 from 3 Sender gets ack Sender gets ack 1 from 5 1 from 5 global ns fd global ns fd Receiver gets Receiver gets seq seq 2 from 3 2 from 3 $ns flush-trace $ns flush trace Sender gets ack Sender gets ack 2 from 5 2 from 5 Receiver gets Receiver gets seq seq 3 from 3 3 from 3 close $ close $fd fd Sender gets Sender gets ack ack 3 from 5 3 from 5 exit 0 exit 0 Receiver gets Receiver gets seq seq 4 from 3 4 from 3 } Sender gets ack Sender gets ack 4 from 5 4 from 5 Receiver gets seq Receiver gets seq 5 from 3 5 from 3 $ns run $ns run 15 16 Add Your Changes into ns Add Your Change into ns ns-allinone � tcl/lib/ns-lib.tcl Class Simulator Class Simulator … Tcl8.3 TK8.3 OTcl tclcl ns-2 nam-1 source ../mysrc/msg.tcl source ../ mysrc/msg.tcl � Makefile NS_TCL_LIB = \ NS_TCL_LIB = tcl ... C+ + code tcl/mysrc/msg.tcl tcl/mysrc/msg.tcl \ … mysrc lib mcast ... ex test � Or: change Makefile.in, make distclean , make distclean then ./configure ./configure -- --enable enable-debug , debug , examples validation tests msg.tcl make depend and and make make depend make OTcl code 17 18 3

  4. Outline Extending ns in C++ � Extending ns � Modifying code � In OTcl � make depend � In C++ � Recompile • New components � Adding code in new files � Change Makefile � make depend � recompile 19 20 Creating New Components Guidelines � Guidelines � Decide position in class hierarchy � Two styles � I.e., which class to derive from? � New agent based on existing packet � Create new packet header (if headers necessary) � Add new packet header � Create C++ class, fill in methods � Define OTcl linkage (if any) � Write OTcl code (if any) � Build (and debug) 21 22 New Agent, Old Header TCP Jump Start – Step 1 TclObject Handler � TCP jump start NsObject � Wide-open transmission window at the beginning Connector Classifier � From cwnd _ += 1 To cwnd cwnd_ += 1 cwnd_ = _ = MAXWIN_ MAXWIN_ Queue Delay Agent Trace AddrClassifier McastClasifier DropTail RED TCP Enq Deq Drop Reno SACK JS 23 24 4

  5. TCP Jump Start – Step 2 TCP Jump Start – Step 3 � New file: tcp-js.cc � New file: tcp-js.h static JSTcpClass : public TclClass { public: JSTcpClass () : TclClass("Agent/TCP/JS") class class JSTCPAgent JSTCPAgent : public : public TcpAgent TcpAgent { {} public: public: TclObject* create(int, const char*const*) { virtual void set_initial_window virtual void set_initial_window() { () { return (new JSTcpAgent ()); cwnd cwnd_ = MAXWIN_; _ = MAXWIN_; } } }; JSTcpAgent::JSTcpAgent () { private: private: bind(“MAXWIN _”, MAXWIN_); int int MAXWIN_; MAXWIN_; } }; }; 25 26 Packet Format New Packet Header � Create new header structure ts_ cmn header � Enable tracing support of new header ptype_ header � Create static class for OTcl linkage ip header (packet.h) uid_ data tcp header � Enable new header in OTcl (tcl/lib/ns- size_ packet.tcl) rtp header � This does not apply when you add a iface_ trace header new field into an existing header! ... 27 28 How Packet Header Works Example: Agent/Message Packet � New packet header for 64-byte PacketHeader/ Common next_ message hdrlen_ size determined bits_ � New transport agent to process this hdr_cmn at compile time new header PacketHeader/ I P size determined size determined hdr_ip at compile time at simulator PacketHeader/ TCP startup time ( PacketHeaderManager) size determined hdr_tcp at compile time … … 29 30 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend