Monday, 24 December 2012

CALCULATING DROP PACKETS IN NS2,

BEGIN {

    packet_lost3 = 0;
    packet_lost1=0;
    packet_lost2=0;
    packet_lost_total=0;
    total_throughput = 0
    final = 0
    time_ini = 0.0
    count = 0
}
{
    ackn = $5
    event = $1
   
    time = $2
    node = 0
    flowid= $8
    from_node = $3
    to_node= $4 #from node should be 2
    source = $9
    dest= $10
    #I HAVE THREE SOURCES SO I USED THREE PACKET LOSTS       #print(time)
    #print(flowid)
    #print(from_node)

    if(event  == "d"  && source ="0.0" && dest == "11.0") {
       
        packet_lost3 = packet_lost3+1;
        }
    if(event  == "d"  && source ="2.0" && dest == "11.2") {
       
        packet_lost2 = packet_lost2+1;
        }
    if(event  == "d"  && source ="1.0" && dest == "11.1") {
       
        packet_lost1 = packet_lost1+1;
        }
   
}


END {
        print("*******************")
        print("packet drop on source 1 : " , packet_lost1)
        print("*******************")
        print("packet drop on source  2: " , packet_lost2)
        print("*******************")
        print("packet drop on source 3 : " , packet_lost3)
#TOTAL LOST COUNT
        packet_lost_total = packet_lost1+packet_lost2+packet_lost3;
        print("*******************")
        print("Total packet drop= : " , packet_lost_total)
        print("*******************")



}



#save this file as .awk file ex = packet_lost.awk then run for any trace file which is in output of any tcl file in ns2.
# then run the following command in terminal

awk -f "packet_lost.awk" out.tr  


#replace out.tr with your out put file name and change the source and dest in awk file according to your trace file.

No comments:

Post a Comment