How to measure packet loss rate, end-to-end delay, and throughput for UDP-based applications?

How to measure the throughput for TCP-based applications?

[Goal]

        In this document, I will use the example in NS by Example (WPI) to show how to measure packet loss rate, end-to-end delay, and throughput for UDP-based applications and how to measure the throughput for TCP-based applications.

 

[Simulation Topology]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


[TCL script]

 

set ns [new Simulator]

 

$ns color 1 Blue

$ns color 2 Red

 

set nf [open out.nam w]

$ns namtrace-all $nf

 

set nd [open out.tr w]

$ns trace-all $nd

 

proc finish {} {

        global ns nf nd udp null sink

        $ns flush-trace

        close $nf

        close $nd

        #after simulation, the sender and receiver trace files are needed to close.

        $udp closefile

        $null closefile

        $sink closefile

        #exec nam out.nam &

        puts "simulation finished"

        exit 0

}

 

 

set s1 [$ns node]

set s2 [$ns node]

 

set r [$ns node]

 

set d [$ns node]

 

$ns duplex-link $s1 $r 2Mb 10ms DropTail

$ns duplex-link $s2 $r 2Mb 10ms DropTail

$ns duplex-link $r $d 1.7Mb 20ms DropTail

 

$ns queue-limit $r $d 10

 

$ns duplex-link-op $s1 $r orient right-down

$ns duplex-link-op $s2 $r orient right-up

$ns duplex-link-op $r $d orient right

 

$ns duplex-link-op $r $d queuePos 0.5

 

set tcp [new Agent/TCP]

$ns attach-agent $s1 $tcp

#use mTcpSink to record the information for TCP-based application at the receiver side.

set sink [new Agent/TCPSink/mTcpSink]

#set sink [new Agent/TCPSink]

#assign the TCP received trace filename

$sink set_filename tcp_sink

$ns attach-agent $d $sink

$ns connect $tcp $sink

$tcp set fid_ 1

 

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

 

#use mUDP to record the information for UDP-based application at the sender side.

set udp [new Agent/mUDP]

#assign the UDP sender trace filename

$udp set_filename sd_udp

$ns attach-agent $s2 $udp

#use mUDP to record the information for UDP-based application at the receiver side.

set null [new Agent/mUdpSink]

#assign the UDP received trace filename

$null set_filename rd_udp

#set null [new Agent/Null]

$ns attach-agent $d $null

$ns connect $udp $null

$udp set fid_ 2

 

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1mb

$cbr set random_ false

 

$ns at 0.1 "$cbr start"

$ns at 1.0 "$ftp start"

$ns at 4.0 "$ftp stop"

$ns at 4.5 "$cbr stop"

$ns at 4.5 "$ns detach-agent $s1 $tcp ; $ns detach-agent $d $sink"

$ns at 5.0 "finish"

 

$ns run

1

2

 

After simulation, you can get the rd_udp, sd_udp, and tcp_sink three trace files.

3

 

The first field in the sd_udp (UDP sender trace file) is packet id, the second is the sending time, and the third is the packet size.

4

 

The first field in the rd_udp (UDP sender trace file) is packet id, the second is the packet sent time, the third is the packet received time, the fourth is the packet end-to-end delay, and the last one is the packet size.

5

 

 

The first field in the tcp_sink (TCP receiver trace file) is packet id, the second is the packet received time, the third is the packet size.

6

 

[Loss rate for UDP-based applications]

1. Calculate the number of records in the UDP sender trace file. You will know how many packets are sent.

7

 

2. Calculate the number of records in the UDP receiver trace file. You will know how many packets are received.

8

3. Then the loss rate will be (550-543)/550 * 100 = 1.27 %

 

[Packet End-to-End Delay for UDP-based applications]

1. From the UDP receiver trace file, we can easily get the packet end-to-end delay (the fourth column).

2. Use awk to obtain the packet id and packet end-to-end delay.

9

10

3. Use gnuplot to draw the figure.

11

 

[Throughput for UDP-based applications]

Use the perl script to get the throughput for UDP-based applications

#Usage: perl measure-throughput.pl <trace file> <granlarity>

 

$infile=$ARGV[0];

 

$granularity=$ARGV[1];

 

$sum=0;

$sum_total=0;

$clock=0;

$maxrate=0;

$init=0;

 

open (DATA,"<$infile")

    || die "Can't open $infile $!";

       

while (<DATA>) {

        @x = split(' ');

       

        if($init==0){

          $start=$x[2];

          $init=1;

            }

        if ($x[2]-$clock <= $granularity)

        {

                    $sum=$sum+$x[4];

                    $sum_total=$sum_total+$x[4];

        }

        else

        {

               $throughput=$sum*8.0/$granularity;

               if ($throughput > $maxrate){

                       $maxrate=$throughput;

               }

                    print STDOUT "$x[2]: $throughput bps\n";

                    $clock=$clock+$granularity;

                    $sum_total=$sum_total+$x[4];

                    $sum=$x[4];

        }

}

 

$endtime=$x[2];

 

$throughput=$sum*8.0/$granularity;

print STDOUT "$x[2]: $throughput bps\n";

$throughput=$sum*8.0/$granularity;

print STDOUT "$x[2]: $throughput bps\n";

$avgrate=$sum_total*8.0/($endtime-$start);

print STDOUT "Average rate: $avgrate bps\n";

print STDOUT "Peak rate: $maxrate bps\n";

 

close DATA;

exit(0);

 

12

 

[Throughput for TCP-based applications]

Use the perl script to get the throughput for TCP-based applications

#Usage: perl measure-TCP.pl <trace file> <granlarity>

 

$infile=$ARGV[0];

 

$granularity=$ARGV[1];

 

$sum=0;

$sum_total=0;

$clock=0;

$init=0;

 

open (DATA,"<$infile")

    || die "Can't open $infile $!";

       

while (<DATA>) {

        @x = split(' ');

       

        if($init==0){

          $start=$x[1];

          $init=1;

        }

 

        if ($x[1]-$clock <= $granularity)

        {

                    $sum=$sum+$x[2];

                    $sum_total=$sum_total+$x[2];

        }

        else

        {

                   $throughput=$sum*8.0/$granularity;

                    print STDOUT "$x[1] $throughput\n";

                   $clock=$clock+$granularity;        

            $sum_total=$sum_total+$x[2];

                $sum=$x[2];

        }  

}

 

$endtime=$x[1];

 

$throughput=$sum*8.0/$granularity;

print STDOUT "$x[1] $throughput\n";

print STDOUT "$sum_total $start $endtime\n";

$avgrate=$sum_total*8.0/($endtime-$start);

print STDOUT "Average rate: $avgrate bps\n";

close DATA;

exit(0);

 

13

 

Last updated: 2012/4/19

 

Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Taiwan

Email: smallko@gmail.com