Examples of Performance Analysis using NS

来源:互联网 发布:长沙招聘网络推广 编辑:程序博客网 时间:2024/05/17 03:11
Performance Analysis of Drop Tail Queues(the NS script is here:click here )

  • Constructing the Simulation Network

    The classic performance analysis network:

    • Link 0-1 is the bottleneck link
    • N flows share the bottleneck link

    NS script to construct this network:

    # ##################################################################### Create bottleneck and dest nodes  set n2 [$ns node]  set n3 [$ns node]# ##################################################################### Create bottleneck link (between bottleneck nodes n2-n3)  $ns duplex-link $n2 $n3 0.7Mb 20ms DropTail# ##################################################################### Set Queue Size of bottleneck link (n2-n3)  $ns queue-limit $n2 $n3 100# ##################################################################### Set number of sources  set NumbSrc 3# ##################################################################### Use a for-loop to create $NumbSrc source nodes  for {set j 1} {$j<=$NumbSrc} { incr j } {     set S($j) [$ns node]  }# ##################################################################### This part is used to start the sources at random times# ##################################################################### Create a random generator for starting the ftp and# for bottleneck link delays  set rng [new RNG]  $rng seed 2# ##################################################################### parameters for random variables for begenning of ftp connections  set RVstart [new RandomVariable/Uniform]  $RVstart set min_ 0  $RVstart set max_ 7  $RVstart use-rng $rng# ##################################################################### Define RANDOM starting times for each connection# And set (possible random) delay for connection from sources to Node 0  for {set i 1} {$i<=$NumbSrc} { incr i } {     set startT($i)  [expr [$RVstart value]]     set dly($i) 1     puts "startT($i)  $startT($i) sec"     puts $param "startT($i)  $startT($i) sec"  }# ##################################################################### Create links between source and bottleneck#  1. Select the delay from each source to bottleneck node#  2. Set queue size (#packets)  for {set j 1} {$j<=$NumbSrc} { incr j } {     $ns duplex-link $S($j) $n2 10Mb $dly($j)ms DropTail     $ns queue-limit $S($j) $n2 20  }# ##################################################################### Orient the links  $ns duplex-link-op $n2 $n3 orient right  $ns duplex-link-op $S(1) $n2 orient right-down  $ns duplex-link-op $S(2) $n2 orient right  $ns duplex-link-op $S(3) $n2 orient right-up# ##################################################################### Create TCP Sources  for {set j 1} {$j<=$NumbSrc} { incr j } {     set tcp_src($j) [new Agent/TCP/Reno]     $tcp_src($j) set window_ 8000  }# ##################################################################### Color the packets  $tcp_src(1) set fid_ 1  $ns color 1 red  $tcp_src(2) set fid_ 2  $ns color 2 yellow  $tcp_src(3) set fid_ 3  $ns color 3 blue# ##################################################################### Create TCP Destinations  for {set j 1} {$j<=$NumbSrc} { incr j } {     set tcp_snk($j) [new Agent/TCPSink]  }# ##################################################################### Schedule START events for the FTP agents:  for {set i 1} {$i<=$NumbSrc} { incr i } {     $ns at $startT($i) "$ftp($i) start"     $ns at $SimDuration "$ftp($i) stop"  }  



  • Obtaining TCP CWND Window information (in general)

    • This is done through the classic "plotWindow" procedure that reschedules itself.

    • This version of "plotWindow" can be used for multiple TCP sources:

      # ##################################################################### plotWindow(tcpSource file k): Write CWND of k tcpSources in file  proc plotWindow {tcpSource file k} {     global ns NumbSrc     set time 0.03     set now [$ns now]     set cwnd [$tcpSource set cwnd_]     if {$k == 1} {        puts -nonewline $file "$now \t $cwnd \t"     } else {     if {$k < $NumbSrc } {        puts -nonewline $file "$cwnd \t"        }     }     if { $k == $NumbSrc } {        puts -nonewline $file "$cwnd \n"     }     if { $k == $NumbSrc } {        puts -nonewline $file "$cwnd \n"     }     $ns at [expr $now+$time] "plotWindow $tcpSource $file $k"  }Usage:# ##################################################################### Start plotWindow() for all tcp sources  for {set j 1} {$j<=$NumbSrc} { incr j } {     $ns at 0.1 "plotWindow $tcp_src($j) $windowVsTime $j"  }  

    • The output format is as follows:

        TIME   Win_flow1   Win_flow2   Win_flow3 ....   Win_flowN 

    • Use the following plot commands in gnuplot toplot the window trends for each TCP flow:

        plot "windowFile" using 1:2 t "Flow 1" w lines 1, \       "windowFile" using 1:3 t "Flow 2" w lines 2, \       "windowFile" using 1:4 t "Flow 3" w lines 3 



  • Obtaining Queue Length information (in general)

    • (Current) Queue length information can be obtained byqueue monitoring - see: click here

    • Code in NS script to obtain queue length information:

      # ##################################################################### Monitor avg queue length of link ($n2,$n3)  set qfile [$ns monitor-queue $n2 $n3  [open queue.tr w] 0.05]  [$ns link $n2 $n3] queue-sample-timeout; 

    • Process output with:

         plot "queue.tr" using 1:5 t "Queue Length" w lines 1 



  • Obtaining Throughput (Goodput) information from a TCP connection(Perl program: click here)

    • Drop Tail queues does not provide built-in tracing facilityto recorded average and current queue length information(RED queues do)

    • The trace information (ns trace-all - click here) containsenough information to determine the TCP (good) throughputof any TCP connection.

    • Recall the structure of the trace record:

    • The Seq Number starts with 0 when simulation begins

    • Therefore, we can determine the (good) throughput of a TCPconnection by looking at theSeq Number received by the destination node of the TCP connection !

    • Here is a PERL script that can be used to generatea plot of the throughput information of a TCP connection: (you can get the Perl script here:click here)

      NOTES:

      • @x = split(' ') tokenizeseach input line into an array of strings
      • x[0] is the first element (i.e., event), we look for "r" (receive)events
      • x[1] is the first element (event)

      # ##################################################################### Usage: ##   perl throughput     #                    ## Example: plot the throughput of connection 2.0 - 1.0 every 0.5 sec##perl throughput  out.tr  1 2.0 1.0  0.5# ##################################################################### ############################################################## Get input file (first arg)   $infile=$ARGV[0];# ############################################################## Get node that receives packets (second arg)   $destnode=$ARGV[1];   $fromport=$ARGV[2];   $toport=$ARGV[3];# ############################################################## Get time granularity (time interval width   $granularity=$ARGV[4];# ###################################################################### We compute how many bytes were transmitted during time interval # specified by granularity parameter in seconds   $sum=0;   $grantsum=0;   $clock=0;# ###################################################################### Open input file   open (DATA,"<$infile") || die "Can't open $infile $!";     while ()    {# Tokenize line using space as separator      @x = split(' ');# column 1 is time: Check for next epoch      if ($x[1]-$clock <= $granularity)      {# checking if the event (column 0) corresponds to a reception          if ($x[0] eq 'r')          { # checking if the destination (column 3) corresponds to node in arg 1            if ($x[3] eq $destnode && $x[8] eq $fromport && $x[9] eq $toport)             { #checking if the packet type is TCP               if ($x[4] eq 'tcp')                {                  $sum=$sum+$x[5];  $grantsum=$grantsum+$x[5];               }            }         }      }      else# One interval has passed, compute throughput      {            $throughput=0.000008*$sum/$granularity;         print STDOUT "$clock $throughput\n";         $clock=$clock+$granularity; if ($x[0] eq 'r' && $x[3] eq $destnode && $x[8] eq $fromport      && $x[9] eq $toport && $x[4] eq 'tcp')         {    $sum=$x[5];    $grantsum=$grantsum+$x[5]; } else         {    $sum=0; }         while ($x[1]-$clock > $granularity)         {            print STDOUT "$clock 0.0\n";            $clock=$clock+$granularity;         }      }      }   $throughput=0.000008*$sum/$granularity;   print STDOUT "$clock $throughput\n";   $clock=$clock+$granularity;   print "Avg throughput $fromport - $toport = ", $grantsum/$clock, "\n";   close DATA;   exit(0);  

    • How to perform throughput analysis

      • Look at the NAM network and find the destination node(in our example, the TCP sinks are attached to node 1

      • Look inside the trace file and find some like with destination = 1.?

        Example:

        r 0.005749 2 0 tcp 40 ------- 1 2.0 1.0 0 0...r 0.026206 0 1 tcp 40 ------- 1 2.0 1.0 0 0  

        • The first packet is in transit at node 0 towards the finaldestination 1 (received on port 0).

        • The received packet is received by node 1 and it is alsothe final destination node - so this packet counts towardsthe (good) throughput)

        • Write down the src-node.src-port and dest-node.dest.port:

                  2.0    1.0 
          You need these as input parameters for the "throughput" script.

      • To compute the throughput of the TCP connection (2.0 -> 1.0) over 0.5 secinterval, use:

             throughput trace-file  1  2.0  1.0  0.5 > plotdata  

      • You will get a two column output:

             Time   Throughput (in MBytes/sec) 
        that you can use gnuplot to plot the trend:

          Run:

            gnuplot  gnuplot> plot "plotdata" using 1:2 title "TCP throughput" with lines 1  

  • A more space-efficient throughput trace-file

    • If all you want is to study the throughput of TCP connections,you can save a lot of disk space by filtering the trace recordsinside the NS script (see:click here)

    • Here is a PERL script that only write the RECEIVED packetsby a given node out:

      (The Perl script is here: click here )

      # ######################################################################### throughput-filter: PERL utility for reducing the trace-file size ## ## Usage:  ## ##   When you open the trace-file in NS, use this command: ## ##      set file1 [open "| perl thruput-filter destNode > trace-file" w]  ## ######################################################################### ############################################################## Get node that receives packets    $tonode=$ARGV[0];# ######################################################################### <STDIN> is the standard input stream, already opened !     while (<STDIN>) {# Tokenize line using space as separator      $line=$_;      @x = split(' ');# checking if the event (column 0) corresponds to a reception       if ($x[0] eq 'r')      {# checking if the destination corresponds to node in arg         if ($x[3] eq $tonode)          {     print STDOUT $line         }      }   }   exit(0); 

    • To use this filter, open the trace-file in your NS script using:

        set file1 [open "| perl thruput-filter destNode > trace-file" w]  


Performance Analysis of RED Queues(the NS script is here:click here )
  • The DropTail simulation script is modified slightly to performsimulation on RED queues, as follows:

    1. First, change the bottleneck queue (n2,n3) into a RED queue:

      # ##################################################################### Create RED links between bottleneck nodes  $ns duplex-link $n2 $n3 0.7Mb 20ms RED

    2. The RED queue component does provide a "trace" feature thatyou can activate to see the average and current queue length:

      # ##################################################################### Monitor avg queue length of RED link ($n2,$n3) in file "red-queue.tr"  set traceq [open red-queue.tr w]- open a trace file for RED  set redq [[$ns link $n2 $n3] queue]- get the RED queue  $redq trace curq_    - Tell the RED queue to trace changes       to its variable curq_ (current Q len)  $redq trace ave_    - Tell the RED queue to trace changes       to its variable ave_ (average Q len)  $redq attach $traceq    - Send the trace data to file "traceq"

      The output of the "traceq" file will look like this:

            Trace      code  Time       Value (unit = #packets)    --------------------------------------a   0.106137   0.00569799Q   0.106137   1<--- first packet arrivesa   0.148626   0.00556923Q   0.148626   0<--- first packet departeda   0.1491     0.00553749a   0.155392   0.00550594a   0.155865   0.0111726Q   0.155865   1<--- second packet arrives....  

      NOTE: The default buffer unit in RED queue is #packets

      You can change it to operate in "byte" mode: click here

    3. To obtain a plot of average and current queue length of the RED queue:

      • Use "grep a REDtrace-file" and "grep Q REDtrace-file"to separate the different inputs lines:

           grep a red-queue.tr > ave.tr   grep Q red-queue.tr > cur.tr 

      • Use the following command in gnuplot to plot columns 2 and 3from the input file:

          plot "ave.tr" using 2:3 t "Average Qlength" w lines 1, \       "cur.tr" using 2:3 t "Current Qlength" w lines 2 


Plotting Performance Graphs with GNUPLOT

  • Some GNUPLOT documents

    • Quick intro: click here
    • Length manual: click here

  • Basic plot command

     plot "data" using 1:2 title "Flow 1" with lines 1 
    Make a line plot with color 1 using columns 1 and 2 from file "data"
     plot "data" using 1:2 title "Flow 1" with lines 1 \       "data" using 1:3 t "Flow 2" w lines 2
    Make a plot containing 2 line plots. First, a line plot withcolor 1 using columns 1 and 2 from file "data" and second with color 2 using columns 1 and 3 from file "data"

  • GNUPLOT command files

    • You can execute prepared GNUPLOT command files with the "load"command:

       load "gnuplot-script"  
      Execute the stored commands inside the file "gnuplot-script"

    • Example, stored the previous "plot" commands in a file anduse "load" to run them

  • Postscript Output

     set out "plot.ps" set size 0.7, 0.7 set terminal postscript portrait color   replot set terminal x11 set size 1,1 
    These commands first changes the output to the file "plot.ps. Then changes the size and the terminal to a "color postscript device" and replot the figure (the figure will now be saved as a postscript file).

    The last 2 command reset the terminal back to the X-window display and resize to normal.

     set out "plot.ps" set size 0.7, 0.7 set terminal postscript portrait mono  replot set terminal x11 set size 1,1
    Same, now with mono-color

    • Save as Postscript GNUPLOT scripts

      • Save as color postscript script: click here
      • Save as mono postscript script: click here

      • Usage:
             set out "plot.ps"     load "gp-color-ps"    or load "gp-mono-ps" 


Example of TCP Performance Analysis
  • Drop Tail

    • Current queue length for Drop Tail queue:(see: click here )
                     
    • TCP Congestion Window: (see: click here )
                 
    • Avg throughput (over 0.05 sec) for Drop Tail queue:(see: click here )
                   

      Average throughputs:

      • Flow 1 = 0.35 MBytes/sec
      • Flow 2 = 0.17 MBytes/sec
      • Flow 3 = 0.16 MBytes/sec



  • RED Queue

    • Current and average queue length for RED queue:(see: click here )
                     
    • TCP Congestion Window: (see: click here )
                     
    • Avg throughput (over 0.05 sec) for Drop Tail queue:(see: click here )
                   

      Average throughputs:

      • Flow 1 = 0.267 MBytes/sec
      • Flow 2 = 0.183 MBytes/sec
      • Flow 3 = 0.241 MBytes/sec

原创粉丝点击