zoukankan      html  css  js  c++  java
  • NS 2.35 柯志亨书实验3笔记TCP UDP模拟 ——计算FTP不同参数:时延、抖动、吞吐率、丢包率awk代码

    计算FTP时延的awk的代码:

    View Code
    # Measure the end to end delay by the trace file
    
    BEGIN{
        # program initialize
        highest_packet_id = 0;
    }
    
    {
        # awk会自动循环执行这个{}
        action = $1;
        time = $2;
        from = $3;
        to = $4;
        type = $5;
        pktsize = $6;
        flow_id = $8;
        src = $9;
        dst = $10;
        seq_no = $11;
        packet_id = $12;
    
        # Record the current max packet ID
        if ( packet_id > highest_packet_id )
            highest_packet_id = packet_id;
    
        # Record the tx time of packet
        if ( start_time[packet_id] == 0 )
            start_time[packet_id] = time;
    
        # FTP flow_id=1
        # Record CBR flow_id=2 rx time
        # 这里既要判断flow=2,没有drop,还要判断recv
        # drop是必须的,因为有可能1-2 recv,2-3 drop了
        # CBR 路径是1-2-3,整条路径上都有可能drop
        if ( flow_id == 1 && action != "d" )
        {
            if (action == "r")
            {
                end_time[packet_id] = time;
            }
        }
        else
            end_time[packet_id] = -1;
    }
    
    END {
    # When read over, start to calculate
        for ( packet_id=0; packet_id<=highest_packet_id; packet_id++ )
        {
            start = start_time[packet_id];
            end = end_time[packet_id];
            duration = start-end;
            if (start<end)
                printf("%f %f\n", start, duration);
        }
    }

    计算FTP抖动的awk的代码:

    View Code
    # Measure the end to end delay jitter by the trace file
    # 计算方法:抖动率由相邻数据包延迟时间差除以数据包序号差得到;
    # jitter = ( (trecvj-tsndj) - (trecvi-tsndi) ) / (j-i), j>i
    
    BEGIN{
        # program initialize
        highest_packet_id = 0;
    }
    
    {
    
    action = $1;
    time = $2;
    from = $3;
    to = $4;
    type = $5;
    pktsize = $6;
    flow_id = $8;
    src = $9;
    dst = $10;
    seq_no = $11;
    packet_id = $12;
    
    # Record the current max packet ID
    if ( packet_id > highest_packet_id )
        highest_packet_id = packet_id;
    
    # Record the tx time of packet
    if ( start_time[packet_id] == 0 )
    {    
        pkt_seqno[packet_id] = seq_no;
        start_time[packet_id] = time;
    }
    
    # FTP flow_id=1
    # Record CBR flow_id=2 rx time
    if ( flow_id == 1 && action != "d" )
    {
        if (action == "r")
        {
            end_time[packet_id] = time;
        }
    }
    else
        end_time[packet_id] = -1;
    }
    
    END {
    # When read over, start to calculate
        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];
            duration = start-end;
            if (start<end)
            {    
                # calc jitter
                seqno_diff = pkt_seqno[packet_id]-last_seqno;
                delay_diff = 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 = duration;
            }
        }
    }

    计算FTP吞吐率的awk的代码:

    View Code
    # Measure the CBR average throughput by the trace file
    # throughput = byte cnt / time interval
    # time interval = cur_time - start_time
    
    BEGIN{
        # program initialize
        init = 0;
        i = 0;
    }
    
    {
    action = $1;
    time = $2;
    from = $3;
    to = $4;
    type = $5;
    pktsize = $6;
    flow_id = $8;
    src = $9;
    dst = $10;
    seq_no = $11;
    packet_id = $12;
    
    if(action=="r" && from==2 && to==3 && flow_id==1)
    {
        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 {
    # When read over, start to calculate
        printf("%.2f\t%.2f\n", end_time[0], 0);
    
        for(j=1;j<i-1;j++)
        {
            # 从开始到当前的平均吞吐率,而不是现在的瞬时吞吐率
            # 这样计算似乎有失准确
            th=pkt_byte_sum[j] / (end_time[j]-start_time) *8 / 1000;
            printf("%.2f\t%.2f\n", end_time[j], th);
        }
        # 书中说,为了画图好看,一开始和最后都设为0,最后的0似乎有点不妥
        #printf("%.2f\t%.2f\n", end_time[0], 0);
    }

    计算FTP包送达率的awk的代码:

    View Code
    # Measure the CBR packet loss rate by the trace file
    
    BEGIN{
        # program initialize
        fsRecv = 0;
        numFs = 0;
    }
    
    {
    action = $1;
    time = $2;
    from = $3;
    to = $4;
    type = $5;
    pktsize = $6;
    flow_id = $8;
    src = $9;
    dst = $10;
    seq_no = $11;
    packet_id = $12;
    
    #### Record FTP flow_id=1
    # Record how many packets sent from n0
    if ( from==0 && to==2 && action=="+" )
        numFs++;
    
    # 不能计算drop的,虽然drop了,但还会重传
    # Record flow_id is 2 and dropped
    if ( from==2 && to==3 && flow_id==1 && action=="r" )
        fsRecv++;
    }
    
    END {
    # When read over, start to calculate
        printf("number of pkts sent:%d, receive:%d, delivery rate:%f\n", numFs,fsRecv,fsRecv/numFs);
    }

    number of pkts sent:246, receive:236, delivery rate:0.959350

    FTP竟然也有丢包,送达率不是100%,这个怎么理解啊?

  • 相关阅读:
    Changing Icon File Of Push Button At Runtime In Oracle Forms 6i
    Set Font Properties On Mouse Hover Of Push Button And Text Items At Run time In Oracle Forms
    Change An Item Property Using Set_Item_Property In Oracle Forms
    Calling / Running a report in Oracle forms 10g / 11g
    Change Or Set Report Object Property At Run Time In Oracle Forms Using Set_Report_Object_Property Command
    Refresh / Updating a form screen in Oracle D2k Forms 6i
    Know How And When To Use System.Message_Level To Control Messages In Oracle Forms
    Perform Cut Copy Paste Operations Using Cut_Region Copy_Region Paste_Region Commands In Oracle Forms
    CHECKBOX_CHECKED built-in in Oracle D2k Forms
    Limiting To Select Only 5 Check Boxes Out Of Ten In Oracle Forms
  • 原文地址:https://www.cnblogs.com/yanhc/p/3073878.html
Copyright © 2011-2022 走看看