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

时间:2022-12-28 23:35:37

计算FTP时延的awk的代码:

NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算FTP不同参数:时延、抖动、吞吐率、丢包率awk代码NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算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);
    }
}

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

计算FTP抖动的awk的代码:

NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算FTP不同参数:时延、抖动、吞吐率、丢包率awk代码NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算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;
        }
    }
}

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

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

NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算FTP不同参数:时延、抖动、吞吐率、丢包率awk代码NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算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);
}

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

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

NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算FTP不同参数:时延、抖动、吞吐率、丢包率awk代码NS 2.35 柯志亨书-实验3笔记-TCP UDP模拟 ——计算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%,这个怎么理解啊?