[转] 分析无线trace的awk脚本

http://hi.baidu.com/kevin_wei/blog/item/451f4ff52737e4d1f3d38563.html

可以分析得到包的端到端延迟丢包率
延迟是按接收节点应用层收到时间-发送节点应用层发出时间计算
丢包率是按所有发出的包与所有收到的包算的

顺便一句:aodv丢包率是不是有点高?在50个节点,0~10m/s,随即30对收发大小为512B的数据,场景大小1000M*1000M时,竟然平均达36%。。。。

###################################################
#
# a gawk script. used to get point to point packet delay and packet drop ratio
#
# usage: awk -v step=<timestep> -v delayfile=<yourDelayFile> -v dropfile=<yourDropRatiofile> -f getDelay.awk <yoursoure>
# eg: awk -v step=5.0 -v delayfile=aodv-delay.txt -v dropfile=aodv-drop.txt -f getDelay.awk aodv.tr
#
# for any questions, contact me via cookie.chao@gmail.com
# or http://blog.baisi.net/110511
#
###################################################


BEGIN {
    highest_packet_id = 0;
}

$0 {
    if($7 == "cbr") {
        action = $1;
        time = $2;
        layer = $4;
        packet_id = $6;
       
        #当前节点
        crtlgth = length($3);
        crtlgth -= 2;
        crt_node_id = substr($3,2,crtlgth);
       
        #源节点
        srclgth = index($14, ":");
        srclgth -= 2;
        src_node_id = substr($14,2,srclgth);
       
        #目标节点
        dstlgth = index($15, ":");
        dstlgth -= 1;
        dst_node_id = substr($15,1,dstlgth);
               
        if ( packet_id > highest_packet_id )
            highest_packet_id = packet_id;
       
        if ( start_time[packet_id] == 0 ) start_time[packet_id] = time;
       
        if ( layer == "AGT" && crt_node_id == dst_node_id && action == "r" ) {
            end_time[packet_id] = time;
        }
        else {
            end_time[packet_id] = -1;
        }
    }
}

END {
    base = step;
    total_delay = 0.0;
    num_packets = 0;
    last_packet_id = 0;
   
    for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {                  
        starttime = start_time[packet_id];
        endtime = end_time[packet_id];

        if ( endtime!=-1 && starttime < endtime ) {
            if ( starttime > base ) {
                if(num_packets)     printf "%f %f\n", base, total_delay/num_packets >> delayfile;
                    else            printf "%f %f\n", base, 0 >> delayfile;
                printf "%f %f\n", base, (packet_id-last_packet_id-num_packets)/(packet_id-last_packet_id) >> dropfile;
                base += step;
                total_delay = 0.0;
                num_packets = 0;
                last_packet_id = packet_id;
            }
            packet_duration = endtime - starttime;
            printf "#%f %f %d\n", starttime, packet_duration,packet_id >> delayfile;
            total_delay += packet_duration;
            num_packets ++;

        }
    }    
}

 

posted on 2012-06-29 10:21  haivey  阅读(404)  评论(0)    收藏  举报

导航