【协议森林】iperf3使用方法及原理

iperf3是一款用于测量TCP/IP和UDP/IP性能的工具,支持多种操作系统。它可以测试带宽、延迟,并调整各种参数如窗口大小、传输速率等。在服务器端,iperf3可以设置为守护进程模式,而客户端则能指定连接目标、带宽限制等。通过setsockopt函数,可以调整TCP_NODELAY、TCP_MAXSEG等选项。测试结果显示了不同时间段内的传输速率。
摘要由CSDN通过智能技术生成

1.简述

Iperf 是一个 TCP/IP 和 UDP/IP 的性能测量工具,通过调谐各种参数可以测试TCP的最大带宽,并报告带宽、延迟,最大段和最大传输单元大小等统计信息。Iperf可以运行于Linux/BSD、Unix及Windows等操作系统。

2.使用

root@ubuntu:/home/totosun/Desktop/iperf-3.2-STABLE/iperf-3.2-STABLE/src# ./iperf3 -h
Usage: iperf3 [-s|-c host] [options]
       iperf3 [-h|--help] [-v|--version]

Server or Client:
  -p, --port      #         server port to listen on/connect to
  -f, --format   [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits
  -i, --interval  #         seconds between periodic throughput reports
  -F, --file name           xmit/recv the specified file
  -A, --affinity n/n,m      set CPU affinity
  -B, --bind      <host>    bind to a specific interface
  -V, --verbose             more detailed output
  -J, --json                output in JSON format
  --logfile f               send output to a log file
  --forceflush              force flushing output at every interval
  -d, --debug               emit debugging output
  -v, --version             show version information and quit
  -h, --help                show this message and quit
Server specific:
  -s, --server              run in server mode
  -D, --daemon              run the server as a daemon
  -I, --pidfile file        write PID file
  -1, --one-off             handle one client connection then exit
  --rsa-private-key-path    path to the RSA private key used to decrypt
                            authentication credentials
  --authorized-users-path   path to the configuration file containing user
                            credentials
Client specific:
  -c, --client    <host>    run in client mode, connecting to <host>
  -u, --udp                 use UDP rather than TCP
  --connect-timeout #       timeout for control connection setup (ms)
  -b, --bitrate #[KMG][/#]  target bitrate in bits/sec (0 for unlimited)
                            (default 1 Mbit/sec for UDP, unlimited for TCP)
                            (optional slash and packet count for burst mode)
  --pacing-timer #[KMG]     set the timing for pacing, in microseconds (default 1000)
  --fq-rate #[KMG]          enable fair-queuing based socket pacing in
                            bits/sec (Linux only)
  -t, --time      #         time in seconds to transmit for (default 10 secs)
  -n, --bytes     #[KMG]    number of bytes to transmit (instead of -t)
  -k, --blockcount #[KMG]   number of blocks (packets) to transmit (instead of -t or -n)
  -l, --len       #[KMG]    length of buffer to read or write
                            (default 128 KB for TCP, dynamic or 1 for UDP)
  --cport         <port>    bind to a specific client port (TCP and UDP, default: ephemeral port)
  -P, --parallel  #         number of parallel client streams to run
  -R, --reverse             run in reverse mode (server sends, client receives)
  -w, --window    #[KMG]    set window size / socket buffer size
  -C, --congestion <algo>   set TCP congestion control algorithm (Linux and FreeBSD only)
  -M, --set-mss   #         set TCP/SCTP maximum segment size (MTU - 40 bytes)
  -N, --no-delay            set TCP/SCTP no delay, disabling Nagle's Algorithm
  -4, --version4            only use IPv4
  -6, --version6            only use IPv6
  -S, --tos N               set the IP type of service, 0-255
  --dscp N or --dscp val    set the IP dscp value, either 0-63 or symbolic
  -L, --flowlabel N         set the IPv6 flow label (only supported on Linux)
  -Z, --zerocopy            use a 'zero copy' method of sending data
  -O, --omit N              omit the first n seconds
  -T, --title str           prefix every output line with this string
  --get-server-output       get results from server
  --udp-counters-64bit      use 64-bit counters in UDP test packets
  --username                username for authentication
  --rsa-public-key-path     path to the RSA public key used to encrypt
                            authentication credentials

window:

iperf3.exe -s

在这里插入图片描述
客户端:

iperf3 -c 192.168.208.200 -t 60 -P 6
#指定窗口大小
iperf3 -c 192.168.208.200 -t 60 -P 6  -w 8K 

在这里插入图片描述

3.原理分析

iperf3相关命令实现原理函数

    setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt))
    setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt))
    setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt))
    setsockopt(s, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt))
    setsockopt(s, SOL_SOCKET, SO_MAX_PACING_RATE, &fqrate, sizeof(fqrate))
    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))
    setsockopt(s, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)
    setsockopt(s, IPPROTO_TCP, TCP_CONGESTION, test->congestion, strlen(test->congestion))

在这里插入图片描述
客户端与服务器互换,要分清server和客户端读写方向,两者差异比较大。

Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.208.200, port 22238
[  5] local 192.168.208.209 port 5201 connected to 192.168.208.200 port 22239
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   106 MBytes   892 Mbits/sec
[  5]   1.00-2.00   sec   105 MBytes   880 Mbits/sec
[  5]   2.00-3.00   sec   114 MBytes   954 Mbits/sec
[  5]   3.00-4.00   sec   114 MBytes   956 Mbits/sec
[  5]   4.00-5.00   sec   106 MBytes   895 Mbits/sec
[  5]   5.00-6.00   sec   113 MBytes   950 Mbits/sec
[  5]   6.00-7.00   sec   105 MBytes   882 Mbits/sec
[  5]   7.00-8.00   sec  98.1 MBytes   822 Mbits/sec
[  5]   8.00-9.00   sec   111 MBytes   930 Mbits/sec
[  5]   9.00-10.00  sec   109 MBytes   918 Mbits/sec
[  5]  10.00-10.04  sec  3.93 MBytes   958 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.04  sec  1.06 GBytes   908 Mbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

在这里插入图片描述

4.抓包对比

在这里插入图片描述
在这里插入图片描述

加入讨论

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值