LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk scripts for trace file (https://www.linuxquestions.org/questions/linux-newbie-8/awk-scripts-for-trace-file-874039/)

mikes1313 04-09-2011 05:27 PM

awk scripts for trace file
 
Hi this is a sample of my trace file

s 5.000000000 _10_ AGT --- 0 cbr 50 [0 0 0 0] [energy 100.000000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [10:0 0:0 32 0] [0] 0 0
r 5.000000000 _10_ RTR --- 0 cbr 50 [0 0 0 0] [energy 100.000000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [10:0 0:0 32 0] [0] 0 0
s 5.000000000 _10_ RTR --- 0 AODV 48 [0 0 0 0] [energy 100.000000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [10:255 -1:255 30 0] [0x2 1 1 [0 0] [10 4]] (REQUEST)
N -t 5.002585 -n 0 -e 99.996369
N -t 5.002585 -n 8 -e 99.996369
N -t 5.002585 -n 95 -e 99.996369
r 5.005202005 _0_ RTR --- 0 AODV 48 [0 ffffffff a 800] [energy 99.996369 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [10:255 -1:255 30 0] [0x2 1 1 [0 0] [10 4]] (REQUEST)
s 5.005202005 _0_ RTR --- 0 AODV 44 [0 0 0 0] [energy 99.996369 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [0:255 10:255 30 10] [0x4 1 [0 4] 10.000000] (REPLY)
r 5.005202054 _8_ RTR --- 0 AODV 48 [0 ffffffff a 800] [energy 99.996369 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [10:255 -1:255 30 0] [0x2 1 1 [0 0] [10 4]] (REQUEST)
r 5.005202130 _95_ RTR --- 0 AODV 48 [0 ffffffff a 800] [energy 99.996369 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [10:255 -1:255 30 0] [0x2 1 1 [0 0] [10 4]] (REQUEST)
N -t 5.006807 -n 10 -e 99.996318
N -t 5.006807 -n 8 -e 99.996321
N -t 5.006807 -n 95 -e 99.996321
s 5.009520941 _95_ RTR --- 0 AODV 48 [0 ffffffff a 800] [energy 99.996321 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
N -t 5.009866 -n 8 -e 99.996251
N -t 5.009866 -n 28 -e 99.996364
N -t 5.009866 -n 68 -e 99.996364
N -t 5.009866 -n 0 -e 99.996245
N -t 5.009866 -n 10 -e 99.996248
s 5.012243695 _8_ RTR --- 0 AODV 48 [0 ffffffff a 800] [energy 99.996251 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [8:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
r 5.012483018 _8_ RTR --- 0 AODV 48 [0 ffffffff 5f 800] [energy 99.996251 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
r 5.012483028 _28_ RTR --- 0 AODV 48 [0 ffffffff 5f 800] [energy 99.996364 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
r 5.012483070 _68_ RTR --- 0 AODV 48 [0 ffffffff 5f 800] [energy 99.996364 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
r 5.012483070 _0_ RTR --- 0 AODV 48 [0 ffffffff 5f 800] [energy 99.996245 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
r 5.012483071 _10_ RTR --- 0 AODV 48 [0 ffffffff 5f 800] [energy 99.996226 ei 0.004 es 0.000 et 0.000 er 0.000] ------- [95:255 -1:255 29 0] [0x2 2 1 [0 0] [10 4]] (REQUEST)
N -t 5.013549 -n 0 -e 99.996175
N -t 5.013549 -n 10 -e 99.996155
N -t 5.013549 -n 95 -e 99.996178
N -t 5.013549 -n 28 -e 99.996294


I have used the following end to end delay awk script :

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

# AWK Script for calculating:

# => Send,

# => Received, and

# => Dropped packets, with packets

# => Delivery Ration and Average End-to-End Delay.

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



BEGIN {

seqno = -1;

droppedPackets = 0;

receivedPackets = 0;

count = 0;

}

{

#packet delivery ratio

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<count; 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";

}

and I got this message : Average end to end delay = -nan ms

I can't really understand what is the problem.

Can somebody provide my scripts for energy consumption, e2edelay,throughput, sent-received-dropped packets, jitter that works for AODV routing protocol.

How can by an awk script extract an Xgraph.


Thanks a lot
MIKE

grail 04-10-2011 02:59 AM

So first of all, please use [code][/code] tags to enclose code so it is at least readable.

I am not sure that with the provided input this code was ever going to work.
On a quick look I see that end_time variable is only ever set when at least $7 == tcp. The problem here is that the string 'tcp' is not in the input at all??
Also the seqno is never any bigger than 0 so the loops in END related to this will only ever loop once.

Combining the above means that by the time you get to the following line:
Code:

n_to_n_delay = n_to_n_delay/count;
You will receive 0/0 which in itself is not going to work.

So we either need better data to look at or you need to rethink some of the logic.

lucky89 04-25-2012 10:14 AM

hello sir
can you give me the script.tcl of this example, a want to learn how do you add the energy!
and do you see your problem of awk because i have the same probleme??
thanks in advance

David the H. 04-26-2012 03:13 AM

This thread is over a year old now and the opening poster never bothered to come back and reply after the first post. Do you really think you're going to get an answer?


If you have a similar problem of your own, it's generally better to start a new thread for it. You can link back to any older ones if appropriate. Don't reopen old threads unless you have something important to add to that discussion in particular.

ines8989 04-10-2013 08:52 AM

awk script
 
Hi
i want to simulate an awk script to have throuĝhput graph for tcp connection ( my awk file is named linktcp) and has this format
BEGIN {
packet_size= 1500
total_throughput = 0
final = 0
time_ini = 1.0
count = 0
}
{
ackn = $5
event = $1
time = $2
node = 0
flowid= $8
from_node = $3
to_node= $4
#print(event)
#print(time)
#print(flowid)
#print(from_node)
#from node should be 2
if(event == "r" && flowid == "1" && from_node == "0" && time_ini >= time && ackn == "tcp" ) {
#remember always immediately after if there will be start of the “{“ .not in next line
total_throughput = total_throughput + packet_size
++count
}
if(event == "r" && flowid == "1" && from_node == "0" && time_ini <= time &&ackn == "tcp") {
#print(count)
count = 0
final = total_throughput + final
#print(total_throughput)
total_throughput = (total_throughput *8)/1000
printf("%f\t%f\n" , time_ini , total_throughput )
total_throughput = 0
time_ini = time_ini + 1
}
}
END {

final = (((final *8)/1000 ) / time)
print("Total Throughput for TCP : " , final)
for (i = 1.00 ; i <= time_ini ; i++) printf("%f\t%f\n" , i , final )
}
to plot the graph of throughput :i wrote this little script below and i named it 'parametre1':
set title 'Tcp-Throughput'
set xlabel 'Time (s)'
set ylabel 'throughput (Mbs)'
set autoscale
plot 'linktcp' w linespoints title 'throughput-of-TCP'
But i tape in the terminal this command to plot the graph with gnuplot : i have this result
gnuplot> load 'parametre1'
"parametre1", line 5: warning: Skipping unreadable file "linktcp"
"parametre1", line 5: No data in plot

Help me please i don't understand what to do
Thanks for you

grail 04-10-2013 09:29 AM

Quote:

Help me please i don't understand what to do
The first thing you need to do is start your own question and not continue a question from last year.

doussa 04-18-2013 05:06 AM

Hi friends,
Can anyone help me to integrate multi hops notion in leach protocol .
please I need your help as soon as possible and I will be grateful.

David the H. 04-18-2013 05:11 PM

Is anyone actually reading this thread? :rolleyes:


All times are GMT -5. The time now is 04:42 PM.