awk scripts for analysis of trace files in ns2
Packet delivery ratio
awk script
BEGIN {
sendLine = 0;
recvLine = 0;
fowardLine = 0;
}
$0 ~/^s.* AGT/ {
sendLine ++ ;
}
$0 ~/^r.* AGT/ {
recvLine ++ ;
}
$0 ~/^f.* RTR/ {
fowardLine ++ ;
}
END {
printf "s:%d r:%d, r/s Ratio:%.4f, f:%d \n", sendLine, recvLine, (recvLine/sendLine),fowardLine;
}
End to end delay
awk script
BEGIN {
seqno = -1;
count = 0;
}
{
if($4 == "AGT" && $1 == "s" && seqno < $6) {
seqno = $6;
}
#end-to-end delay
if($4 == "AGT" && $1 == "s") {
start_time[$6] = $2;
} else if(($7 == "tcp"||$7=="cbr") && ($1 == "r")) {
end_time[$6] = $2;
} else if($1 == "D" && ($7 == "tcp"$7=="cbr") {
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<=seqno; 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 "Average End-to-End Delay = " n_to_n_delay * 1000 " ms";
print "\n";
}
Control Overhead(Normalized routing overhead)
Note: Add control packets in the (routing packet)conditions as per your protocol
awk script
BEGIN{
recvd = 0;#################### to calculate total number of data packets received
rt_pkts = 0;################## to calculate total number of routing packets received
}
{
##### Check if it is a data packet
if (( $1 == "r") && ( $7 == "cbr" || $7 =="tcp" ) && ( $4=="AGT" )) recvd++;
##### Check if it is a routing packet
if (($1 == "s" || $1 == "f") && $4 == "RTR" && ($7 =="udp" || $7 == "AODV" || $7 =="message" || $7 =="AOMDV" || $7 =="OLSR")) rt_pkts++;
}
END{
printf("##################################################################################\n");
printf("\n");
printf("total no of data packets\t%d\n",recvd);
printf("\ntotal no of routing packets\t%d\n",rt_pkts);
printf(" Normalized Routing Load = %.3f\n", rt_pkts/recvd);
printf("\n");
printf("##################################################################################\n");
}
Throughput
Note: Change packet size as per mentioned in your tcl script
awk script
BEGIN {
recvdSize = 0
startTime = 400
stopTime = 0
}
{
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
# Store start time
if (level == "AGT" && event == "s" && pkt_size >= 512) {
if (time < startTime) {
startTime = time
}
}
# Update total received packets' size and store packets arrival time
if (level == "AGT" && event == "r" && pkt_size >= 512) {
if (time > stopTime) {
stopTime = time
}
recvdSize += pkt_size
}
}
END {
printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)
}
How to apply awk?
awk -f pdr.awk out.tr
Packet delivery ratio
awk script
BEGIN {
sendLine = 0;
recvLine = 0;
fowardLine = 0;
}
$0 ~/^s.* AGT/ {
sendLine ++ ;
}
$0 ~/^r.* AGT/ {
recvLine ++ ;
}
$0 ~/^f.* RTR/ {
fowardLine ++ ;
}
END {
printf "s:%d r:%d, r/s Ratio:%.4f, f:%d \n", sendLine, recvLine, (recvLine/sendLine),fowardLine;
}
End to end delay
awk script
BEGIN {
seqno = -1;
count = 0;
}
{
if($4 == "AGT" && $1 == "s" && seqno < $6) {
seqno = $6;
}
#end-to-end delay
if($4 == "AGT" && $1 == "s") {
start_time[$6] = $2;
} else if(($7 == "tcp"||$7=="cbr") && ($1 == "r")) {
end_time[$6] = $2;
} else if($1 == "D" && ($7 == "tcp"$7=="cbr") {
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<=seqno; 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 "Average End-to-End Delay = " n_to_n_delay * 1000 " ms";
print "\n";
}
Control Overhead(Normalized routing overhead)
Note: Add control packets in the (routing packet)conditions as per your protocol
awk script
BEGIN{
recvd = 0;#################### to calculate total number of data packets received
rt_pkts = 0;################## to calculate total number of routing packets received
}
{
##### Check if it is a data packet
if (( $1 == "r") && ( $7 == "cbr" || $7 =="tcp" ) && ( $4=="AGT" )) recvd++;
##### Check if it is a routing packet
if (($1 == "s" || $1 == "f") && $4 == "RTR" && ($7 =="udp" || $7 == "AODV" || $7 =="message" || $7 =="AOMDV" || $7 =="OLSR")) rt_pkts++;
}
END{
printf("##################################################################################\n");
printf("\n");
printf("total no of data packets\t%d\n",recvd);
printf("\ntotal no of routing packets\t%d\n",rt_pkts);
printf(" Normalized Routing Load = %.3f\n", rt_pkts/recvd);
printf("\n");
printf("##################################################################################\n");
}
Throughput
Note: Change packet size as per mentioned in your tcl script
awk script
BEGIN {
recvdSize = 0
startTime = 400
stopTime = 0
}
{
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
# Store start time
if (level == "AGT" && event == "s" && pkt_size >= 512) {
if (time < startTime) {
startTime = time
}
}
# Update total received packets' size and store packets arrival time
if (level == "AGT" && event == "r" && pkt_size >= 512) {
if (time > stopTime) {
stopTime = time
}
recvdSize += pkt_size
}
}
END {
printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)
}
How to apply awk?
awk -f pdr.awk out.tr
How i add this scrip in AODV.tcl
ReplyDeleteplease Reply me at gauttam2008@gmail.com
Thank you Suraj ji
You do not need to add this to tcl. Just apply it to trace file generated.
ReplyDeletee.g.
awk -f pdr.awk out.tr
excuse me sir, i wank to ask
Deletewhether the same awk for wireless 802.11 with 802.15.4 ?
if different, if you have awk for 802.15.4 sir?
thank you sir
do u have facebook account?
ReplyDeletesir i need a awk file for ns2 pls sir help me
ReplyDeletepls send me the codings to calculate energy
ReplyDeletecan it is possible to draw routing graph in ns2
ReplyDeletehow to plot the xgraph using this awk scripts?
ReplyDeletehave you found an answer?
Deletei still don't know how to plot xgraph using this awk scripts!
sir can u pls help me to calculate round trip delay
ReplyDeleteUse two - two diamentional arrays
ReplyDelete1. First array to use packet id and node id as index and to record departure time at sender node
e.g. at packet departure time
departureTime[nodeid][packetid]= time;
2. second array to use packet id and node id as index and to record arrival time at sender node
e.g. at packet arrival time
arrivalTime[nodeid][packetid]= time;
delay = arrivalTime[nodeid][packetid]- departureTime[nodeid][packetid];
you will get round trip delay for each packet which is supposed to be and successfully delivered at given node
Dear sir,
ReplyDeleteFirst Iwould like to thank you very much for your precious time. you take too much time to give reply to each and every one of us.
would you mind helping me the source code for wormhole attack detection and prevention in MANET with Modified AODV using ns-2.35 please.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletehi sir:
ReplyDeletekindly sir, help me for calculating throughput and end to end delay. i do not know how to calculate that.
thanks
This comment has been removed by a blog administrator.
ReplyDelete