LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2012, 01:04 AM   #1
ns-2_learning
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
Please help me NS2 Programming : AWK script error


Dear friends,

I have some problems using my awk script to calculate end to end delay and packet loss ratio (script in below).

Here is some error :

root@doan-laptop:/home/doan/Desktop# awk -f delay_throughput_AODV_edit2.awk tracefile_doan.tr
Total Delay ms:0.000000
Total Sent AGT CBR Packets :0.000000
Total Drop RTR Packets :0.000000
Number of RTR received packets:0.000000
Number of Agent CBR received packets:0.000000
awk: delay_throughput_AODV_edit2.awk:85: (FILENAME=tracefile_doan.tr FNR=269) fatal: division by zero attempted

Here is my sample trace file :

s 0.009250072 57 70.00 10.00 -99 0 (null) 183473412 --- 8 DSRCApp 800 [0 0 0 0] ------- [57:0 -1:0 32 0]
r 0.011019409 6 60.00 0.00 -99 0 (null) 170745444 --- 5 DSRCApp 800 [0 ffffffff 1f 0] ------- [31:0 -1:0 32 0]
r 0.011019409 56 60.00 10.00 -99 0 (null) 183160868 --- 5 DSRCApp 800 [0 ffffffff 1f 0] ------- [31:0 -1:0 32 0]
s 0.013383680 98 230.00 15.00 -99 0 (null) 193661108 --- 13 DSRCApp 800 [0 0 0 0] ------- [98:0 -1:0 32 0]
s 0.013404596 52 20.00 10.00 -99 0 (null) 182149948 --- 6 DSRCApp 828 [0 ffffffff 34 0] ------- [52:0 -1:0 32 0]
D 0.013404863 85 100.00 15.00 -99 0 (null) 190281692 PXB 1 DSRCApp 828 ------- [90:0 -1:0 32 0]
D 0.013404863 85 100.00 15.00 -99 0 (null) 190281692 PXB 6 DSRCApp 828 ------- [52:0 -1:0 32 0]
s 0.014901910 64 140.00 10.00 -99 0 (null) 185211700 --- 14 DSRCApp 800 [0 0 0 0] ------- [64:0 -1:0 32 0]
r 0.015660613 27 20.00 5.00 -99 0 (null) 175958180 --- 6 DSRCApp 800 [0 ffffffff 34 0] ------- [52:0 -1:0 32 0]
r 0.015660613 77 20.00 15.00 -99 0 (null) 188372588 --- 6 DSRCApp 800 [0 ffffffff 34 0] ------- [52:0 -1:0 32 0]
s 0.015732031 55 50.00 10.00 -99 0 (null) 182892532 --- 3 DSRCApp 828 [0 ffffffff 37 0] ------- [55:0 -1:0 32 0]
s 0.015732031 55 50.00 10.00 -99 0 (null) 182854132 --- 3 DSRCApp 828 ------- [55:0 -1:0 32 0]

Here is for awk script :


BEGIN {
nSentPackets = 0 ;
nReceivedPackets = 0 ;
nAGTReceivedPackets = 0;
nDropPackets = 0;
rTotalDelay = 0.0 ; #total delay
Max=0;
nrtr = 0; # number of the routing control packets
traffic=0;
}

#######################################################################
{
strEvent = $1 ; rTime = $2 ; strNode= $3 ;
strAgt = $8 ; idPacket = $11 ;
strType = $12 ; packetSize= $13 ;

if (idPacket>Max)
Max=idPacket;
#looping over all the packets in the trace file to check whether it is a data packet or a control packet

if ( strAgt == "AGT" && strType == "cbr" )
{
if ( strEvent == "s" )
{
nSentPackets += 1 ;
rSentTime[ idPacket ] = rTime ; # this takes care for the sent agent packets
}
else if (strEvent == "r")
{
nAGTReceivedPackets += 1 ;
rReceivedTime[ idPacket ] = rTime ;
}
}

if ( strAgt == "RTR" && strType == "cbr" )
{
if ( strEvent == "r" )
{
nReceivedPackets += 1 ;# this takes care for the received agent packets

}
else if (strEvent == "D")
{
nDropPackets += 1; # this takes care of dropped packets

}
}


# AODV control packets have a string type of AODV
# need to calculate the traffic in terms of the packet size

if ( strgAgt == "RTR" && strType == "AODV")

{ if (strEvent == "s")

{ nrtr++;
traffic = traffic+packetSize;
}
}



}

#######################################################################

END {
# need to calculate now the total delay (end to end delay)
# id of the packet starts from 0 since the array starting index is 0
for (idPacket=0 ;idPacket<=Max; idPacket++) {
if(rReceivedTime[idPacket]>0 && rSentTime[idPacket]>0) {
rTotalDelay+=rReceivedTime[idPacket]-rSentTime[idPacket];
}
}

#we are using the 802.11p of frequency 5.9 GHz
#parameters of 802.11p are set for 10MHz bandwidth
printf("Total Delay ms:%f \n", 1000*rTotalDelay);
printf("Total Sent AGT CBR Packets :%f \n", nSentPackets);
printf("Total Drop RTR Packets :%f \n", nDropPackets);
printf("Number of RTR received packets:%f\n", nReceivedPackets);
printf("Number of Agent CBR received packets:%f\n", nAGTReceivedPackets);
printf("Average Delay ms:%f \n", 1000*rTotalDelay/nAGTReceivedPackets);
printf("Packet Delivery ratio PDR %f\n",(nAGTReceivedPackets)/nSentPackets);
printf(" The throughput in bits per second is %f\n",300*8*nAGTReceivedPackets/100);
printf(" The spectral Efficiency in b/s/Hz is %f\n",300*8*nAGTReceivedPackets/(100*10000));
printf("\n");



}

Thanks,

Sincerely yours,
Doan
 
Old 10-29-2012, 05:57 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,564

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Firstly, always place code and data in [code][/code] tags so it is readable and formatting is preserved.

As to your error:
Code:
awk: delay_throughput_AODV_edit2.awk:85: (FILENAME=tracefile_doan.tr FNR=269) fatal: division by zero attempted
Look at line 85 and check all the variables for the values that would be stored on reading the 269th line of your input file?
 
Old 02-17-2014, 10:59 AM   #3
xptional
LQ Newbie
 
Registered: Mar 2011
Location: France
Distribution: Ubuntu 14.04 LTS, Dell Latitude E5400
Posts: 26

Rep: Reputation: 11
Hello Doan,

I am facing the problems of exploiting the same trace type file.
Did you solve your problem ? If YES, please,
Could you share it ?

Thank you so much.
 
  


Reply


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
Execution of awk script gives error message for invalid character tanggo81 Linux - Kernel 2 06-26-2010 03:35 AM
Error on awk script sebelk Programming 6 10-16-2009 08:44 AM
awk shell script error ApacheRoseXbones Linux - Newbie 5 07-18-2008 01:06 PM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 08:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration