Awk Scripting to Interpret the Trace File

Use awk or perl scripting language to interpret the trace file. For this example, I use the trace file which is generated from https://alkautsarpens.wordpress.com/2008/05/13/limited-queue/ . I want to know, how to interpret that trace file using awk. using awk can filter the trace file, hence we can know Bytes sent entered queue node 0,Bytes sent de-queue node 0, number of packets entered queue node 0, number of packets de-queue node 0, total number of packets dropped at node 2, Bytes all packets received at node 3, etc.

out_example4.tr , trace file which is generated by example4.tcl

+ 0.1 1 2 cbr 1000 ——- 2 1.0 3.1 0 0
– 0.1 1 2 cbr 1000 ——- 2 1.0 3.1 0 0
+ 0.108 1 2 cbr 1000 ——- 2 1.0 3.1 1 1
– 0.108 1 2 cbr 1000 ——- 2 1.0 3.1 1 1
r 0.114 1 2 cbr 1000 ——- 2 1.0 3.1 0 0

d 1.337868 2 3 tcp 1040 ——- 1 0.0 3.0 26 193

columns trace file :
Event – Event time – Link from node – Link to node – Packet type – Size byte – flag – Flow id – Src addr of packet – Dst addr – Seq No – Packet id.

Events : + pkt entered link queue, pkt dequeued from link queue, r pkt received by its destination, d pkt has been dropped.

Create awk file : awk_example4.awk :

BEGIN {tottcpquen0=0; tottcpdquen0=0; numpactquen0=0; numpactdquen0=0; totcbrquen1=0; totcbrdquen1=0; numpactquen1=0; numpactdquen1=0; tottcpquen2=0; tottcpdquen2=0; numpactquen2=0; numpactdquen2=0; totcbrquen2=0; totcbrdquen2=0; numcbrquen2=0; numcbrdquen2=0; dropcbr=0;droptcp=0; totdrop=0; totrecvcbrn3=0; totrecvtcpn3=0; totrecvn3=0; numrecvtcpn3=0; numrecvcbrn3=0; numrecvn3=0}
{
if ($1==”+” && $3==”0″ && $5==”tcp”) {tottcpquen0=tottcpquen0+$6;numpactquen0=numpactquen0+1}
if ($1==”-” && $3==”0″ && $5==”tcp”) {tottcpdquen0=tottcpdquen0+$6;numpactdquen0=numpactdquen0+1}

if ($1==”+” && $3==”1″ && $5==”cbr”) {totcbrquen0=totcbrquen0+$6;numpactquen1=numpactquen1+1}
if ($1==”-” && $3==”1″ && $5==”cbr”) {totcbrdquen0=totcbrdquen0+$6;numpactdquen1=numpactdquen1+1}

if ($1==”+” && $3==”2″ && $4==”3″ && $5==”tcp”) {tottcpquen2=tottcpquen2+$6;numpactquen2=numpactquen2+1}
if ($1==”-” && $3==”2″ && $4==”3″ && $5==”tcp”) {tottcpdquen2=tottcpdquen2+$6;numpactdquen2=numpactdquen2+1}

if ($1==”+” && $3==”2″ && $4==”3″ && $5==”cbr”) {totcbrquen2=totcbrquen2+$6;numcbrquen2=numcbrquen2+1}
if ($1==”-” && $3==”2″ && $4==”3″ && $5==”cbr”) {totcbrdquen2=totcbrdquen2+$6;numcbrdquen2=numcbrdquen2+1}

if ($1==”d” && $3==”2″ && $4==”3″ && $5==”tcp”) {droptcp=droptcp+1}
if ($1==”d” && $3==”2″ && $4==”3″ && $5==”cbr”) {dropcbr=dropcbr+1}
if ($1==”d” && $3==”2″) {totdrop=totdrop+1}

if ($1==”r” && $3==”2″ && $4==”3″ && $5==”tcp”) {totrecvtcpn3=totrecvtcpn3+$6;numrecvtcpn3=numrecvtcpn3+1}
if ($1==”r” && $3==”2″ && $4==”3″ && $5==”cbr”) {totrecvcbrn3=totrecvcbrn3+$6;numrecvcbrn3=numrecvcbrn3+1}
if ($1==”r” && $3==”2″ && $4==”3″) {totrecvn3=totrecvn3+$6; numrecvn3=numrecvn3+1}

}
END {print “Bytes sent entered queue node 0 (tcp packet):” tottcpquen0 “\nBytes sent de-queue node 0 (tcp packet):” tottcpdquen0 “\nnumber of packets entered queue node 0 (tcp packet):” numpactquen0 “\nnumber of packets de-queue node 0 (tcp packet):” numpactdquen0 “\n\nBytes sent entered queue node 1 (cbr packet):” totcbrquen0 “\nBytes sent de-queue node 1 (cbr packet):” totcbrdquen0 “\nnumber of packets entered queue node 1 (cbr packet):” numpactquen1 “\nnumber of packets de-queue node 1 (cbr packet):” numpactdquen1 “\n\nBytes sent entered queue node 2 (tcp packet):” tottcpquen2 “\nBytes sent de-queue node 2 (tcp packet):” tottcpdquen2 “\nnumber of packets entered queue node 2 (tcp packet):” numpactquen2 “\nnumber of packets de-queue node 2 (tcp packet):” numpactdquen2 “\nnumber of tcp packets dropped at node 2 : ” droptcp “\n\nBytes sent entered queue node 2 (cbr packet):” totcbrquen2 “\nBytes sent de-queue node 2 (cbr packet):” totcbrdquen2 “\nnumber of packets entered queue node 2 (cbr packet):” numcbrquen2 “\nnumber of packets de-queue node 2 (cbr packet):” numcbrdquen2 “\nnumber of cbr packets dropped at node 2 : ” dropcbr “\n\ntotal number of packets dropped at node 2 : ” totdrop “\n\nBytes tcp packets received at node 3:” totrecvtcpn3 “\nBytes cbr packets received at node 3:” totrecvcbrn3 “\nBytes all packets received at node 3:” totrecvn3 “\nnumber of tcp packets received at node 3 : ” numrecvtcpn3 “\nnumber of cbr packets received at node 3 : ” numrecvcbrn3 “\nnumber of all packets received at node 3 : ” numrecvn3; }

Run at terminal :

networklab@networklab-desktop:~/ns/cobans/start$ awk -f awk_example4.awk out_example4.tr

Result :

Bytes sent entered queue node 0 (tcp packet):254840
Bytes sent de-queue node 0 (tcp packet):254840
number of packets entered queue node 0 (tcp packet):246
number of packets de-queue node 0 (tcp packet):246

Bytes sent entered queue node 1 (cbr packet):550000
Bytes sent de-queue node 1 (cbr packet):550000
number of packets entered queue node 1 (cbr packet):550
number of packets de-queue node 1 (cbr packet):550

Bytes sent entered queue node 2 (tcp packet):254840
Bytes sent de-queue node 2 (tcp packet):244440
number of packets entered queue node 2 (tcp packet):246
number of packets de-queue node 2 (tcp packet):236
number of tcp packets dropped at node 2 : 10

Bytes sent entered queue node 2 (cbr packet):550000
Bytes sent de-queue node 2 (cbr packet):542000
number of packets entered queue node 2 (cbr packet):550
number of packets de-queue node 2 (cbr packet):542
number of cbr packets dropped at node 2 : 8

total number of packets dropped at node 2 : 18

Bytes tcp packets received at node 3:244440
Bytes cbr packets received at node 3:542000
Bytes all packets received at node 3:786440
number of tcp packets received at node 3 : 236
number of cbr packets received at node 3 : 542
number of all packets received at node 3 : 778

We can see that the total number of dropped packet at node 2 is 18.

Next : Generate graphics using Gnuplot of GNU

Reference :

Chinese Song : Dream Pursuer

May 15, 2008
Taipei City
High Speed Network Lab

Udin Harun

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: