How can I use awk scripts to find the end-to-end delay from the .tr file?
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
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
#!/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
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
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 ?
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.