network-programming - iperf如何在udp中报告丢包

标签 network-programming tcp udpclient iperf

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

在 UDP 协议(protocol)中,数据报没有收到任何确认。 但是,iperf 以何种方式报告或计算数据包丢失? iperf 工具如何知道传输的数据报是否收到。 我想知道这个。

最佳答案

由于双方都使用了 iperf,iperf 确定在每个数据包之后接收什么。

基本上, Iperf 工具检查序列号在它收到的每个数据报中递增。如果序列号没有递增 1 ,则数据报丢失。如果我们收到一个序列号小于前一个序列号的数据报,那么 iperf 会收到一个乱序的数据包。
您可以引用 iperf 源代码以便更好地理解。 https://github.com/esnet/iperf/blob/master/src/iperf_udp.c

From iperf source code-

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);
}

关于network-programming - iperf如何在udp中报告丢包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51911474/

相关文章:

c++ - cpp中的UDP套接字永远循环

c++ - 在linux中接收无序的udp数据包

iphone - 有没有办法使用 CFStreamCreatePairWithSocketToHost() 获取套接字引用?

Android通过套接字发送大文件

无法分配请求的地址 - 可能的原因?

c# - 如果我在c#中发送0有效负载数据,udp数据包的大小是多少?

c# - UDP套接字无法将数据包发送到DHCP地址

java - 我可以识别所有连接到 wifi 网络的 android 的主机名吗?

Linux版Windows "nonpaged pool"这种东西存在吗?

java - 无法使用 java InetAddress 找到主机,但可以使用 curl 找到主机