NS2中有线网络trace文件分析脚本(awk)

本文根据网络上的资源和自己使用情况总结,如有问题可以联系我。

1.End-to-End Delay

BEGIN {
	highest_packet_id = 0;
}
{
   	action = $1;
   	time = $2;
   	node_1 = $3;
   	node_2 = $4;
   	type = $5;
   	flow_id = $8; 
   	node_1_address = $9;
   	node_2_address = $10; 
   	seq_no = $11;
   	packet_id = $12;
   	if ( packet_id > highest_packet_id )
   		highest_packet_id = packet_id;
  	if ( start_time[packet_id] == 0 )  
        	start_time[packet_id] = time;
  	if ( flow_id == 2 && action != "d" ) {
        	if ( action == "r" ) {
        		end_time[packet_id] = time;
        	}
   	}else{
        	end_time[packet_id] = -1;
   	}
}                                                                                                           
END {
   	for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
        	start = start_time[packet_id];
        	end = end_time[packet_id];
        	packet_duration = end - start;
        	if ( start < end ) printf("%f %f\n", start, packet_duration);
   	}
}

2.Jitter

BEGIN {
	highest_packet_id = 0;
}
{
   	action = $1;
   	time = $2;
   	node_1 = $3;
   	node_2 = $4;
   	type = $5;
  	flow_id = $8;
   	node_1_address = $9;
   	node_2_address = $10;
   	seq_no = $11;
   	packet_id = $12;
   	if ( packet_id > highest_packet_id ) {
           	highest_packet_id = packet_id;
        }
   	if ( start_time[packet_id] == 0 )  {
           	pkt_seqno[packet_id] = seq_no;
           	start_time[packet_id] = time;
   	}
  	if ( flow_id == 2 && action != "d" ) {
     		if ( action == "r" ) {
         		end_time[packet_id] = time;
      		}
   	} else {
      		end_time[packet_id] = -1;
   	}
}                                                       
END {
        last_seqno = 0;
        last_delay = 0;
        seqno_diff = 0;
    	for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
       		start = start_time[packet_id];
       		end = end_time[packet_id];
       		packet_duration = end - start;
       		if ( start < end ) {
               		seqno_diff = pkt_seqno[packet_id] - last_seqno;
               		delay_diff = packet_duration - last_delay;
               		if (seqno_diff == 0) {
                      		jitter =0;
               		} else {
                       		jitter = delay_diff/seqno_diff;
               		}
               		printf("%f %f\n", start, jitter);
              		last_seqno = pkt_seqno[packet_id];
              		last_delay = packet_duration;
       		}
    	}
}

3.Loss

BEGIN {
	fsDrops = 0;
        numFs = 0;
}
{
	action = $1;
   	time = $2;
   	node_1 = $3;
   	node_2 = $4;
   	src = $5;
   	flow_id = $8;
   	node_1_address = $9;
   	node_2_address = $10;
   	seq_no = $11;
   	packet_id = $12;
        if (node_1==1 && node_2==2 && action == "+")
        	numFs++;
        if (flow_id==2 && action == "d")
                fsDrops++;
}
END {
        printf("number of packets sent:%d lost:%d\n", numFs, fsDrops);
}

4.Throughput

BEGIN {
	init=0;
	i=0;
}
{
	action = $1;
        time = $2;
        node_1 = $3;
        node_2 = $4;
        src = $5;
        pktsize = $6;
        flow_id = $8;
        node_1_address = $9;
        node_2_address = $10;
        seq_no = $11;
        packet_id = $12;
        if(action=="r" && node_1==2 && node_2==3 && flow_id==2) {
        	pkt_byte_sum[i+1]=pkt_byte_sum[i]+ pktsize; 
                if(init==0) {
                	start_time = time;
                	init = 1;
		}
                              
		end_time[i] = time;
		i = i+1;
	}
}
END {
	printf("%.2f\t%.2f\n", end_time[0], 0);
        for(j=1 ; j



以上脚本的运行为:awk -f [脚本文件名].awk [trace文件]  > [输出文件]




你可能感兴趣的:(网络模拟器(NS2))