LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-07-2015, 12:18 PM   #1
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Rep: Reputation: Disabled
Unhappy How can I use awk scripts to find the end-to-end delay from the .tr file?


I have finished my .tcl file for the wireless sensor network.
I tried to get the results from the .tr file using the awk scripts, but I did not get anything. Each time it gave an error "division by zero". Please can anyone help?
I have the .tr file and awk script below

.tr file:
https://docs.google.com/file/d/0B3rL...lPVDNFcVk/edit
awk script:
Code:
# ===================================================================

# AWK Script for calculating: 

#     => Average End-to-End Delay.

# ===================================================================

 

BEGIN {

    seqno = -1;    

#    droppedPackets = 0; 

#    receivedPackets = 0; 

    count = 0;

}

{

    if($4 == "AGT" && $1 == "s" && seqno < $6) {

          seqno = $6;

    } 
#	else if(($4 == "AGT") && ($1 == "r")) {

#            receivedPackets++;

#    } else if ($1 == "D" && $7 == "tcp" && $8 > 512){

#            droppedPackets++;            

#  } 

    #end-to-end delay

    if($4 == "AGT" && $1 == "s") {

          start_time[$6] = $2;

    } else if(($7 == "tcp") && ($1 == "r")) {

        end_time[$6] = $2;

    } else if($1 == "D" && $7 == "tcp") {

          end_time[$6] = -1;

    } 

}

 
END {        
  
    for(i=0; i<=seqno; i++) {

          if(end_time[i] > 0) {

              delay[i] = end_time[i] - start_time[i];

                  count++;

        }

            else

            {

                  delay[i] = -1;

            }

    }

    for(i=0; i<=seqno; i++) {

          if(delay[i] > 0) {

              n_to_n_delay = n_to_n_delay + delay[i];

        }         

    }

   n_to_n_delay = n_to_n_delay/count;

 

    print "\n";

#    print "GeneratedPackets            = " seqno+1;

#    print "ReceivedPackets             = " receivedPackets;

#    print "Packet Delivery Ratio      = " receivedPackets/(seqno+1)*100
#"%";

#    print "Total Dropped Packets = " droppedPackets;

    print "Average End-to-End Delay    = " n_to_n_delay * 1000 " ms";

    print "\n";

}
Thank you very much.
 
Old 05-07-2015, 02:57 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
What I see in your code:
1) count set to 0
Code:
 count = 0;
2) count is supposed to be incremented here:
Code:
 for(i=0; i<=seqno; i++) {

          if(end_time[i] > 0) {

              delay[i] = end_time[i] - start_time[i];

                  count++;
3) division by value of count here (apparently not incremented over the initial value of zero):
Code:
 n_to_n_delay = n_to_n_delay/count;
For whatever reason, step 2 is not being processed. Try stepping though your code to find out why.
 
1 members found this post helpful.
Old 05-07-2015, 03:36 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Besides the information from @bigrigdriver :


Not all the old awk scripts are actually usable as is with ns2 / any random trace file.
All "end to end" scripts :
en2end-delay.awk
end-to-end.awk
Endtoenddelay.awk
End-to-End-Delay.awk
delay-e2e.awk
e2e.awk
e2edelay.awk
... The scripts are available from `awk-and-perl_scripts_12.2014.tar.gz'
https://drive.google.com/file/d/0B7S...ew?usp=sharing


-
 
1 members found this post helpful.
Old 05-08-2015, 12:10 PM   #4
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
thanks for your help, i used file ''perl"
Code:
#!/usr/bin/perl
#
#Program to calculate end to end delay.
#
#1. Program reads the trace file, finds for combination of 's' source event and 'AGT' packet type. 
#2. For this combination, the program takes the packet id and timestamp.
#3. Within the same file, the program searches for a combination of 'r' receive event and 'AGT' packet type.
#4. For this combination, the program takes the packet id and compares with previous packet id. If they are same, timestamp is noted.
#5. Difference between step 4 timestamp and step 3 timestamp gives the end to end delay for that packet.
#6. Delays are aggregated and average delay is found.
#

#use strict;
use warnings;

$SIG{INT} = sub {
	my (@stack, $level);
	while(1)
	{
		my ($pkg, $fn, $ln, $sub) = caller($level++);
		if (!($pkg or $fn or $ln or $sub)) {
			for (my $i = 0; $i < @stack; $i++) {
				print " " x $i, $stack[$i], "\n";
			}
			exit;
		}
		unshift @stack, "-> $pkg: $fn (line $ln) sub $sub";
	}
};

#Input trace file
my($infile) =$ARGV[0]; 

#Keep track of variables
my($enqueue_time) = 0;
my($receive_time) = 0;
my($packet_id) = 0;
my($delay) = 0;
my($total_receive_count) = 0;
my($sum_of_delay) = 0;
my($average_delay) = 0;
my($simulation_time) = 0;
my($file_position) = 0;
my (@x);

open(DATA,"<","$infile" ) || die "could't open $infile$!";

while(<DATA>)
{
	@x=split(' ');
	if(($x[0] eq 's') && ($x[3] eq 'AGT'))
	{
		$file_position = tell(DATA);
		$enqueue_time = $x[1];
		$packet_id = $x[5];
		while(<DATA>)
		{
           @x=split(' ');
			if(($x[0] eq 'r') && ($x[3] eq 'AGT'))
			{
				if(($x[5] == $packet_id))
				{
					$receive_time = $x[1];
					$total_receive_count++;
					$delay = $receive_time - $enqueue_time;
					$sum_of_delay = $sum_of_delay + $delay;

					#Following is for debug.
					$delay = $delay * 1000;
					print("\nDelay:$delay");

					last;
				}
			}
		}
		#Continue to search for next 's' event from where the previous 's' was found.
		#So move to the same line where previous 's' event was found.
	seek(DATA,$file_position,SEEK_SET);
	}
	#While(<DATA>) takes care of moving to the next line.
}

$simulation_time = $x[1];

print("\n Simulation Time = $simulation_time seconds");
print("\n Total Receive Count = $total_receive_count");

if($total_receive_count != 0 )
{
	$average_delay = $sum_of_delay / $total_receive_count;
	$average_delay = $average_delay * 1000;
	print("\n Average End to End Delay = $average_delay milliseconds");
}
else
{
	print("\n No packet received.");
}

print("\n");
print("\n");
close DATA;
exit(0);
and i type
Code:
perl avgdelay.pl leach.tr
Is my result correct?
Code:
 Simulation Time = 276.70000 seconds
 Total Receive Count = 28152
 Average End to End Delay = 38.5367725412756 milliseconds

Last edited by viethd92; 05-10-2015 at 03:58 AM.
 
Old 05-09-2015, 09:13 PM   #5
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
There is not a packet to be dropped in my trace file. Is it normal?
 
Old 05-10-2015, 01:44 AM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Re #5.

You can do extra checks with the other available scripts, e.g. :
droppackets.awk
packetloss.pl
packet-loss-ratio.awk
packetloss.sh
totalpacketsreceived.awk
totalpacketssent.awk
PacketDeliveryRatio.awk

? I don't know if your script is meant to show "packet to be dropped in trace .." ?
Or if your trace file shows any packet drops ?


-
 
1 members found this post helpful.
Old 05-10-2015, 04:23 AM   #7
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
I use command:
Code:
ns ns-2.34/tcl/ex/wireless.tcl -sc ns-2.34/mit/uAMPS/sims/nodescen -rp leach -x 100 -y 100 -nn 101 -stop 600 -eq_energy 1 -init_energy 1 -filename LEACH1 -dirname leach_dir -topo ns-2.34/mit/uAMPS/sims/100nodes.txt -num_clusters 5 -bs_x 50 -bs_y 50 2> leach_dir/leach.err > leach_dir/leach.out
And in my trace file, There is not a 'd' label (in 1st column)
https://docs.google.com/file/d/0B3rL...tkM004S0k/edit
Is correct ?

Last edited by viethd92; 05-10-2015 at 04:43 AM.
 
Old 05-10-2015, 04:46 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Re #7.

Please compare with other examples of "leach.tr".

This one is with a default ./test , i.e. default settings in leach_test
https://drive.google.com/file/d/0B7S...ew?usp=sharing


-
 
1 members found this post helpful.
Old 05-10-2015, 11:41 AM   #9
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
There is not a difference between my trace file and your trace file in #8. Awk files in #6 don't have a result which i want. Why does it like this? Help me!

Last edited by viethd92; 05-10-2015 at 11:45 AM.
 
Old 05-10-2015, 01:25 PM   #10
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Re #9.

I don't know. Sorry.
 
1 members found this post helpful.
Old 05-11-2015, 12:02 AM   #11
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Can u show me the meaning of fields in trace file?
Code:
s 11.007514174 _11_ AGT  --- 968 rca 4016 [0 b000000 0 0] ------- [s 11 59 -1] 
r 11.007514175 _35_ AGT  --- 963 rca 304 [0 3b000000 ffff0008 0] ------- [D 59 59 -1]
thanks for your help!
 
Old 05-11-2015, 01:45 AM   #12
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Re #11.

NS-2 Trace Formats :
http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats
 
1 members found this post helpful.
Old 05-12-2015, 03:42 AM   #13
viethd92
LQ Newbie
 
Registered: May 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Dear knudfl
Can u use awk files in #6 to run with your trace file (#8) and give me your result? Please.
 
Old 12-20-2015, 06:40 AM   #14
hbenlabbes
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Rep: Reputation: Disabled
Energy trace for each node (WSN) in perl or awk

any one, have Energy trace for each node (WSN) in perl or awk for trace file tr
Thanks.
 
  


Reply

Tags
awk-ns2, leach, ns2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Measure packet loss rate, jitter, and end-to-end delay godfather9112 Linux - Software 0 11-12-2014 01:44 PM
[SOLVED] end to end delay calculation in satellite links awk file problem-ns2.35 rianariana Linux - Software 3 11-23-2013 09:46 AM
Errors while using awk script for calculating average end to end delay in ns2 NS2User2012 Linux - Networking 4 02-17-2013 11:20 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 10:49 AM
Running a Crafted bash script yelds 'Unexpected end of file' at the end of the file MCLover1337 Linux - General 5 10-15-2011 08:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration