NS-2 CMU Trace Analysis
Ns-2 has two options to generate traces with different fomats. Basically, you could use
$ns use-newtrace
to create the new follow and the itemized clarification could be found in Ns Manual. A decent reference about the follow is the ns-2 wiki page. See: http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_FormatsBy default, old trace format is used. The source code ./trace/cmu-trace.cc needs to be read to understand it completely. For instance, the function format_ip will explain the trace of IP part.
void
CMUTrace::format_ip(Packet *p, int offset)
{
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
// hack the IP address to convert pkt format to hostid format
// for now until port ids are removed from IP address. -Padma.
int src = Address::instance().get_nodeaddr(ih->saddr());
int dst = Address::instance().get_nodeaddr(ih->daddr());
............
}
void
CMUTrace::format_mac(Packet *p, int offset)
{
else {
sprintf(pt_->buffer() + offset,
" [%x %x %x %x] ",
//*((u_int16_t*) &mh->dh_fc),
mh->dh_duration,
ETHER_ADDR(mh->dh_ra),
ETHER_ADDR(mh->dh_ta),
GET_ETHER_TYPE(mh->dh_body));
}
......
}
|
A typical trace for a CBR traffic is:
s 20.000000000 _0_ AGT --- 6 cbr 512 [0 0 0 0] ------- [0:0 1:0 32 0] [0] 0 0
r 20.000000000 _0_ RTR --- 6 cbr 512 [0 0 0 0] ------- [0:0 1:0 32 0] [0] 0 0
s 20.000000000 _0_ RTR --- 6 cbr 532 [0 0 0 0] ------- [0:0 1:0 32 1] [0] 0 0
s 20.000275000 _0_ MAC --- 6 cbr 584 [13a 1 0 800] ------- [0:0 1:0 32 1] [0] 0 0
r 20.004947063 _1_ MAC --- 6 cbr 532 [13a 1 0 800] ------- [0:0 1:0 32 1] [0] 1 0
s 20.004957063 _1_ MAC --- 0 ACK 38 [0 0 0 0]
r 20.004972063 _1_ AGT --- 6 cbr 532 [13a 1 0 800] ------- [0:0 1:0 32 1] [0] 1 0
r 20.005261125 _0_ MAC --- 0 ACK 38 [0 0 0 0]
Perl script examples to analyze the thorughput, delay, packet loss and jitter from trace file
1) Throughput Analysis
To run the follwing throughput.pl file, run-
$perl throughput.pl out.tr source_node destination_node traffic_type granularity
source_node and destnation_node should be in the form of _node_
traffic_type may be tcp , cbr etc.
$infile=$ARGV[0];
$frm=$ARGV[1];
$tonode=$ARGV[2];
$kind=$ARGV[3];
$granularity=$ARGV[4];
$sum=0;
$clock=0;
%packet_array=();
open (DATA,"<$infile")
|| die "Can't open $infile $!";
while (<DATA>) {
@x=split(' ');
$id=$x[5];
#print STDOUT "time=$x[7]\n";
#if($x[1] ge 2 && $x[1] le 8){
if($x[0] eq 's' && $x[2] eq $frm)
{
$packet_array{$id}=1;
}
if($x[1]-$clock<=$granularity)
{
if($x[0] eq 'r' && $packet_array{$id} eq '1')
{
if($x[3] eq 'AGT')
{
if($x[2] eq $tonode)
{
if($x[6] eq $kind)
{
#$sum=$sum+8*($x[7]-20);
$sum=$sum+8*($x[7]-20);
}
}
}
}
}
else
{
$throughput=$sum/$granularity;
$throughput=$throughput/1000;
print STDOUT "time=$x[1] throughput=$throughput kbps\n";
$clock=$clock+$granularity;
$sum=0;
}
#}
}
$throughput=$sum/$granularity;
$throughput=$throughput/1000;
print STDOUT "time=$x[1] throughput=$throughput kbps\n";
$clock=$clock+$granularity;
$sum=0;
close DATA;
exit(0);
2) Delay Analysis
To run the follwing delay.pl file,
$perl delay.pl out.tr traffic_type source_node destination_node
#!usr/local/bin/perl
if(@ARGV ne 4)
{
print STDERR "Usage: delay.pl <tracefile> <kind_of_packet>\n";
exit;
}
$infile=$ARGV[0];
$kind=$ARGV[1];
$src=$ARGV[2];
$dest=$ARGV[3];
$total_delay=0;
$count=0;
$rcv=0;
%packet_array=();
%src_array=();
%rcv_array=();
open(DATA,"<$infile") || die "Can't open $infile";
while(<DATA>){
@x=split(' ');
$id=$x[5];
if($x[0] eq 's' && $x[2] eq $src){
if($x[3] eq 'AGT' && $x[6] eq $kind)
{
#print STDOUT "I am in send\n";
$packet_array{$id}=$x[1];
$src_array{$id}=$x[2];
}
}
elsif($x[0] eq 'r' && $x[2] eq $dest && $src_array{$id} eq $src){
$rcv_array{$id}=$x[2];
$rcv++;
if($x[3] eq 'AGT' && $x[6] eq $kind)
{
$jitter1 = $jitter2 = $tmp_recv = 0;
$prev_time = $delay = $prev_delay = $processed = 0;
$prev_delay = -1
$delay=$x[1]-$packet_array{$id};
#if($count le 1000){
#print STDOUT "delay in packet no. $id: $delay\n";
#}
$total_delay=$total_delay+$delay;
$count++;
}
}
#if($x[6] eq $kind && $x[3] eq 'AGT' ){
# if ($x[0] eq 's'){
# $packet_array{$id}=$x[1];
# }
# elsif ($x[0] eq 'r'){
# $delay=$x[1]-$packet_array{$id};
# $total_delay=$total_delay+$delay;
# $count=$count+1;
# print STDOUT "Delay: $delay\n";
# }
#}
}
$avg=$total_delay/$count;
print STDOUT "Average delay in transmission of $kind packets was: $avg sec\n";
close DATA;
exit(0);
Packet loss Analysis
To run the follwing packet_loss.pl file, run-
$perl packet_loss.pl out.tr traffic_type
#!/usr/bin/perl
# Total No. of packets transmitted
# Total no. of packets dropped
# Average packet loss rate
$infile=$ARGV[0];
#$fromnode=$ARGV[1];
#$tonode=$ARGV[2];
$kind=$ARGV[1];
$num_packt=0;
$drop_packt=0;
$recv_packt=0;
$bits_transmitted=0;
open(DATA,"<$infile") || die ("Can't open the file $infile");
#print STDOUT "Hello $_";
print STDOUT "*************TRACE ANALYZER*****************\n\n";
while(<DATA>){
@x=split(' ');
#if($x[0] eq 's')
#{
# if($x[] )
#}
if($x[0] eq 's')
{
if($x[3] eq 'AGT' && $x[6] eq $kind){
$send_packt++;
$bits_transmitted+=8*$x[7];
}
}
elsif($x[0] eq 'r'){
if($x[3] eq 'AGT' && $x[6] eq $kind){
$recv_packt++;
}
}
elsif($x[0] eq 'D')
{
$drop_packt++;
}
}
$loss=$send_packt-$recv_packt;
$per_loss=100*$loss/$send_packt;
$bits_transmitted=$bits_transmitted/1024;
print STDOUT "No. of packets transmitted: $send_packt\n";
print STDOUT "No. of packets received: $recv_packt\n";
print STDOUT "No. of packets lost: $loss\n";
print STDOUT "No. of packets dropped: $drop_packt\n";
print STDOUT "Loss percentage : $per_loss %\n";
print STDOUT "Amount of data transmitted : $bits_transmitted Kb \n";
close DATA;
exit 0;
Jitter Analysis
To run the follwing jitter.pl file, run-
$perl jitter.pl out.tr traffic_type source_node destination_node
#!usr/local/bin/perl
if(@ARGV ne 4)
{
exit;
}
$infile=$ARGV[0];
$kind=$ARGV[1];
$src=$ARGV[2];
$dest=$ARGV[3];
$total_delay=0;
$count=0;
$num_rcv=0;
%packet_array=();
%sendTime=();
%recvTime=();
%src_array=();
open(DATA,"<$infile") || die "Can't open $infile";
while(<DATA>){
@x=split(' ');
$id=$x[5];
if($x[0] eq 's' && $x[2] eq $src){
if($x[3] eq 'AGT' && $x[6] eq $kind)
{
#print STDOUT "I am in send\n";
#$packet_array{$id}=$x[1];
$src_array{$id}=$x[2];
$sendTime{$id} = $x[1];
}
}
elsif($x[0] eq 'r' && $x[2] eq $dest && $src_array{$id} eq $src){
$recvTime{$id} = $x[1];
$num_recv++;
if($x[3] eq 'AGT' && $x[6] eq $kind)
{
$jitter1 = $jitter2 = $tmp_recv = 0;
$prev_time = $delay = $prev_delay = $processed = 0;
$prev_delay = -1;
for ($i=0; $processed<$num_recv; $i++) {
if( $recvTime{$id} != 0) {
$tmp_recv++;
if($prev_time != 0) {
$delay = $recvTime{$i} - $prev_time;
$e2eDelay = $recvTime{$i} - $sendTime{$i};
if($delay < 0) {
$delay = 0;
}
if($prev_delay != -1) {
$jitter1 = $jitter1 + abs($e2eDelay - $prev_e2eDelay);
$jitter2 =$jitter2 + abs($delay-$prev_delay);
#$jitter1 = $jitter1 + ($e2eDelay - $prev_e2eDelay);
# $jitter2 = $jitter2 + ($delay-$prev_delay);
}
$prev_delay = $delay;
$prev_e2eDelay = $e2eDelay;
}
$prev_time = $recvTime{$i};
}
$processed++;
}
}
#printf("Mean Jitter = %.2f\n",jitter1*1000/tmp_recv);
#printf("Current Jitter = %.2f\n",jitter2*1000/tmp_recv);
}
}
$havg=$jitter1;
$avg=$havg/$tmp_recv;
print STDOUT "Mean jitter in transmission of $kind packets was: $avg Sec\n";
#print STDOUT "Current jitter in transmission of $kind packets was: ($jitter2*1000)/$tmp_recv \n";
close DATA;
exit(0);
sub abs($value) {
if ($value < 0){
$value = 0-$value;}
return $value;
}
No comments:
Post a Comment