iperf如何报告udp

时间:2018-08-18 18:24:51

标签: network-programming tcp-ip udpclient iperf

Iperf是计算吞吐量的众所周知的工具。 当我在linuxpc上使用iperf尝试udp吞吐量时, 它报告说有10%的数据包丢失。

在UDP协议中,数据报不接收任何确认。 但是,iperf用什么方式报告或计算数据包丢失? iperf工具将如何知道发送的数据报是否收到。 我对此感到奇怪。

1 个答案:

答案 0 :(得分:0)

由于双方都使用了iperf,因此iperf可以确定每个数据包之后将收到什么。

基本上, Iperf工具检查在接收到的每个数据报中序列号是否递增。如果序列号未按1递增,则表示数据报丢失。如果我们收到的数据报的序列号小于先前的序列,则iperf接收到乱序的数据包。
您可以参考iperf源代码以更好地理解。 https://github.com/esnet/iperf/blob/master/src/iperf_udp.c

  

来自iperf源代码-

if (pcount >= sp->packet_count + 1) {

    /* Forward, but is there a gap in sequence numbers? */
    if (pcount > sp->packet_count + 1) {
    /* There's a gap so count that as a loss. */
    sp->cnt_error += (pcount - 1) - sp->packet_count;
    }
    /* Update the highest sequence number seen so far. */
    sp->packet_count = pcount;
} else {

    /* 
     * Sequence number went backward (or was stationary?!?).
     * This counts as an out-of-order packet.
     */
    sp->outoforder_packets++;

    /*
     * If we have lost packets, then the fact that we are now
     * seeing an out-of-order packet offsets a prior sequence
     * number gap that was counted as a loss.  So we can take
     * away a loss.
     */
    if (sp->cnt_error > 0)
    sp->cnt_error--;

    /* Log the out-of-order packet */
    if (sp->test->debug) 
    fprintf(stderr, "OUT OF ORDER - incoming packet sequence %" PRIu64 " but expected sequence %d on stream %d", pcount, sp->packet_count, sp->socket);
}