measure-jitter.awk
上传用户:sy0851
上传日期:2014-07-16
资源大小:4k
文件大小:2k
源码类别:

网络

开发平台:

Unix_Linux

  1. #This program is used to calculate the jitters for CBR
  2. # jitter =((recvtime(j)-sendtime(j))-(recvtime(i)-sendtime(i)))/(j-i),  j > i
  3.  BEGIN {
  4. # Initialization
  5.      highest_packet_id = 0;
  6. }
  7. {
  8.    action = $1;
  9.    time = $2;
  10.    #from = $3;
  11.    #to = $4;
  12.    type = $7;
  13.    pktsize = $8;
  14.    #flow_id = $8;
  15.    src = $10;
  16.    dst = $11;
  17.    #seq_no = $11;
  18.    packet_id = $6;
  19.  
  20.    if ( packet_id > highest_packet_id ) {
  21.            highest_packet_id = packet_id;
  22.         }
  23.  
  24. #Record the transmission time
  25.    if ( start_time[packet_id] == 0 )  {
  26.            # Record the sequence number
  27.            pkt_seqno[packet_id] = seq_no;
  28.            start_time[packet_id] = time;
  29.    }
  30.  
  31. #Record the receiving time for CBR (flow_id=2)
  32.    if ( type=="cbr" && action != "d" ) {
  33.       if ( action == "r" ) {
  34.              end_time[packet_id] = time;
  35.       }
  36.     } else {
  37.       end_time[packet_id] = -1;
  38.    }
  39. }                                                       
  40. END {
  41.         last_seqno = 0;
  42.         last_delay = 0;
  43.         seqno_diff = 0;
  44.  
  45.     for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
  46.        start = start_time[packet_id];
  47.        end = end_time[packet_id];
  48.        packet_duration = end - start;
  49.  
  50.        if ( start < end ) {
  51.                seqno_diff = pkt_seqno[packet_id] - last_seqno;
  52.                delay_diff = packet_duration - last_delay;
  53.                if (seqno_diff == 0) {
  54.                        jitter =0;
  55.                } else {
  56.                        jitter = delay_diff/seqno_diff;
  57.                }
  58.                printf("%f %fn", start, jitter);
  59.                last_seqno = pkt_seqno[packet_id];
  60.                last_delay = packet_duration;
  61.        }
  62.     }
  63. }