BEGIN {
     for (i in send) {
                 send[i] = 0
         }
   for (i in rev) {
                 recv[i] = 0
         }
delay=0
avg_delay=0
num=0
}
{
 source=$5
 target=$7
 packet_size=$11
 packet_number=$6
 time=$2
 if($1=="s" &&  $4=="RTR")
 {
	
   send[packet_number]=time
 }
 if($1=="r" &&   $4=="RTR" &&  recv[packet_number]==0)
 {

   recv[packet_number]=time
 }

}
END {
	  # Compute average delay
        for (i in recv)
	 {
		if((send[i]!="" && recv[i]!="")&& (recv[i] - send[i] > 0))
		{
                		 delay += recv[i] - send[i]
              		         num ++
		}
#print recv[i] "-" send[i] "num=" num "i=" i "delay=" delay
       	 }
 
       
         if (num != 0) {
                 avg_delay = delay / num
         } else {
                 avg_delay = 0
         }
     # print "average delay=" avg_delay " total delay=" delay
print  "average delay=" avg_delay 

}
