1 / 11

NS2 Tutorial – Part II

NS2 Tutorial – Part II. Internet Computing Laboratory @ KUT Youn-Hee Han. 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

georgefrank
Télécharger la présentation

NS2 Tutorial – Part II

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. NS2 Tutorial – Part II Internet Computing Laboratory @ KUT Youn-Hee Han

  2. 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~ Introduction to NS2

  3. 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 Introduction to NS2

  4. 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 Introduction to NS2

  5. 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 124.0 "$ftp stop" $ns at 124.5 "$cbr stop“ $ns at 125.0 "finish" $ns run Introduction to NS2

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

  7. A Link Architecture Links: keeps track of “from” and “to” node objects. Link entry point Queue Deq Trace Delay TTL Rcv Trace Enq Trace Agent/Null Drp Trace Introduction to NS2

  8. N1 N2 Node Node Local Local Agent Agent Classifier Classifier Port Port Addr Addr Classifier Classifier Enq Trace Queue Deq Trace Delay TTL Rcv Trace Application Application Drop head Drp Trace Link Link An Application/Node/Link Architecture Introduction to NS2

  9. Tracing • Trace packets on all links • set tracefile1 [open out.tr w] • $ns trace-all $tracefile1 • <event> <time> <from> <to> <pkt> <size> ---<flowid> <src> <dst> <seqno> <pkt id> + 0.1 0 2 tcp 40 ------- 1 0.0 4.0 0 0 - 0.1 0 2 tcp 40 ------- 1 0.0 4.0 0 0 r 0.11016 0 2 tcp 40 ------- 1 0.0 4.0 0 0 + 0.11016 2 3 tcp 40 ------- 1 0.0 4.0 0 0 - 0.11016 2 3 tcp 40 ------- 1 0.0 4.0 0 0 r 0.21336 2 3 tcp 40 ------- 1 0.0 4.0 0 0 + 0.21336 3 4 tcp 40 ------- 1 0.0 4.0 0 0 - 0.21336 3 4 tcp 40 ------- 1 0.0 4.0 0 0 r 0.254 3 4 tcp 40 ------- 1 0.0 4.0 0 0 + 0.254 4 3 ack 40 ------- 1 4.0 0.0 0 1 - 0.254 4 3 ack 40 ------- 1 4.0 0.0 0 1 r 0.29464 4 3 ack 40 ------- 1 4.0 0.0 0 1 + 0.29464 3 2 ack 40 ------- 1 4.0 0.0 0 1 - 0.29464 3 2 ack 40 ------- 1 4.0 0.0 0 1 r 0.39784 3 2 ack 40 ------- 1 4.0 0.0 0 1 + 0.39784 2 0 ack 40 ------- 1 4.0 0.0 0 1 - 0.39784 2 0 ack 40 ------- 1 4.0 0.0 0 1 r 0.408 2 0 ack 40 ------- 1 4.0 0.0 0 1 [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 Introduction to NS2

  10. “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’ Introduction to NS2

  11. 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’, includingthe codes introduced in Page 37. • Execute ‘gnuplot’ • Load ‘plotting’ 1 12 23 34 45 56 57 58 69 710 8 90.0 90.0100.0 100.0110.0 110.0120.0 120.0 90.0 110.0100.0 130.0110.0 150.0120.0 170.0 90.0 120.0100.0 150.0110.0 180.0120.0 200.0 Introduction to NS2

More Related