# [ns] End to End Delay and Packet Delivery Ratio

```

Dear Users

Here is the awk code for calculating end to end delay and packet delivery ratio
while generating traffic from wired node and receiving packets on mobile nodes.

Best Regards

Shahid H Abbassi

BEGIN {

seqno = -1;

droppedPackets = 0;

generatedpackets = 0;

count = 0;

}

{

#packet delivery ratio

if(\$5 == "cbr" && \$1 == "+" && seqno < \$12) {

seqno = \$12;
generatedpackets++;
start_time[\$12] = \$2;
#print "start_time ="start_time[\$12]"\n" \$12;

} else if((\$7 == "cbr") && (\$1 == "r")) {

end_time[\$6] = \$2;
#print "end_time ="end_time[\$6]"\n" \$6;

} else if (\$1 == "D" && \$7 == "cbr" && \$8 > 200){

droppedPackets++;
end_time[\$6] = -1;
#print "end_time ="end_time[\$6]"\n" \$6;

}

}

END {

#print "seqno=" seqno;

for(i=0; i<=seqno; i++) {

if(end_time[i] > 0) {

delay[i] = end_time[i] - start_time[i];

n_to_n_delay = n_to_n_delay + delay[i];

#print "delay=" delay[i];

#print "n_to_n_delay=" n_to_n_delay;

count++;

}

else
{

delay[i] = 0;

}

}

n_to_n_delay = n_to_n_delay/count;

print "\n";

print "GeneratedPackets = " generatedpackets;

print "Packet Delivery Ratio = " receivedPackets/generatedpackets*100 "%";

print "Total Dropped Packets = " droppedPackets;

print "Average End-to-End Delay = " n_to_n_delay * 1000 " ms";

print "\n";

}

```