Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS2 Tutorial – Part II Internet Computing KUT Youn-Hee Han.

Similar presentations


Presentation on theme: "NS2 Tutorial – Part II Internet Computing KUT Youn-Hee Han."— Presentation transcript:

1 NS2 Tutorial – Part II Internet Computing KUT Youn-Hee Han

2 Introduction to NS22 A good example set ns [new Simulator] #Open the Trace files set tracefile1 [open out.tr w] $ns trace-all $tracefile1 #Open the NAM trace file set namfile [open out.nam w] $ns namtrace-all $namfile #Define a 'finish' procedure proc finish {} { global ns tracefile1 namfile $ns flush-trace close $tracefile1 close $namfile exec nam out.nam & exit 0 } #Define different colors for data flow (for NAM) $ns color 1 Blue $ns color 2 Red Ns2 for beginner, p15~

3 Introduction to NS23 A good example #Create six nodex set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns simplex-link $n2 $n3 0.1Mb 100ms DropTail $ns simplex-link $n3 $n2 0.1Mb 100ms DropTail $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns simplex-link-op $n2 $n3 orient right $ns simplex-link-op $n3 $n2 orient left $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link-op $n3 $n5 orient right-down

4 Introduction to NS24 A good example #Set Queue Size of link (n2-n3) to 20 $ns queue-limit $n2 $n3 5 $ns simplex-link-op $n2 $n3 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp $sink $tcp set fid_ 1 $tcp set packetSize_ 552 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp

5 Introduction to NS25 A good example #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n5 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set packetSize_ 1000 $cbr set rate_ 0.01Mb $cbr set random_ false $ns at 0.1 "$ftp start" $ns at 1.0 "$cbr start" $ns at "$ftp stop" $ns at "$cbr stop“ $ns at "finish" $ns run

6 Introduction to NS26 A Node Architecture Classifier Agent Link Agent Node Addr Port Node entry point Local Link - Agents are either protocol endpoints or related objects that generate/fill-in packet fields. - Classifiers: packet demultiplexers.

7 Introduction to NS27 A Link Architecture Enq Trace Deq TraceRcv Trace Drp Trace DelayTTLQueue Link entry point Agent/Null Links: keeps track of “from” and “to” node objects.

8 Introduction to NS28 An Application/Node/Link Architecture Link Application N1 N2 Classifier Agent Node Addr Port Local Classifier Agent Node Addr Port Local Enq TraceDeq TraceRcv Trace Drp Trace DelayTTL Drop head Queue Application

9 Introduction to NS29 Tracing Trace packets on all links set tracefile1 [open out.tr w] $ns trace-all $tracefile tcp tcp r tcp tcp tcp r tcp tcp tcp r tcp ack ack r ack ack ack r ack ack ack r ack [DIY 1] - grep "+ " out.tr > qqq - grep "+ " out.tr | grep "0 2 tcp" > qqq [DIY 2] - Insert the following into ex1.tcl set linkTraceFile [open out_link.tr w] $ns trace-queue $n0 $n2 $linkTraceFile - grep "+ " out_link.tr > qqq2

10 Introduction to NS210 “grep” command Some more example of “grep” command grep "+ " out.tr | grep "0 2 tcp" > qqq  To obtain a file containing all lines of out.tr that begin with “+ “ and includes “0 2 tcp” phrase. grep “^r” out.tr > out2.tr  To obtain a file containing all lines of out.tr that begin with the letter ‘r’. grep -r text *  To obtain a lines which has ‘text’.  The lines come from all files of the current directory. grep –r text *.c  To obtain a lines which has ‘text’.  The lines come from all files of the current directory and the extension is ‘*.c’ grep text */*.c  To obtain a lines which has ‘text’.  The lines come from all files of the current directory’s subdirectory and the extension is ‘*.c’

11 Introduction to NS211 gnuplot Ex1] Make the file, named ‘testplot’ Execute ‘gnuplot’ Type the followings  plot ‘testplot’ w lines 1  plot ‘testplot w points 9  q Ex2] Type the followings  grep "+ " out.tr | grep "0 2 tcp" > qqq Execute ‘gnuplot’  plot ‘qqq’ 2:6 t “size” w lines 1 Ex3] Make the files, ‘fn1’, ‘fn2’, ‘fn3’. Make the file, ‘plotting’, including the codes introduced in Page 37. Execute ‘gnuplot’  Load ‘plotting’


Download ppt "NS2 Tutorial – Part II Internet Computing KUT Youn-Hee Han."

Similar presentations


Ads by Google