1、Iperf概述
iperf 是一个基于Client/Server的网络性能测试工具,可以测试TCP、UDP和SCTP带宽质量,能够提供网络吞吐率信息,以及震动、丢包率、最大段和最大传输单元大小等统计信息,帮助我们测试网络性能,定位网络瓶颈。
抖动、丢包率 --> 适应于UDP测试
带宽测试 --> 适应于TCP和UDP测试
iperf 优点:纯粹的发送、接收,防止硬盘读写影响测试结果。
缺点:无法计算传输时延
(iperf测试发送大量包,计算出的抖动值,即为连续发送时延差值的平均值)
2、Iperf的ARM平台移植
2.1 下载源码
- 源码下载地址:http://downloads.es.net/pub/iperf/ (测试使用版本:iperf-3-current.tar.gz)
- iperf是一个开源软件,其源码在GitHub上,地址:https://github.com/esnet/iperf
2.2 解压工程源码
- 创建工程目录及源码解压
# mkdir /home/zhangj/iperf
# cp iperf-3-current.tar.gz /home/zhangj/iperf
# cd /home/zhangj/iperf
# tar xvzf iperf-3-current.tar.gz
至此,在 /home/zhangj/iperf/ 目录下,解压出 /iperf-3.6 目录,该目录为iperf的工程源码。
2.3 配置源码及编译、安装
- 配置环境变量
# mkdir /home/zhangj/iperf/install (创建编译生成iperf文件的安装目录)
# export PATH=$PATH:/opt/hisi-linux/x86-arm/arm-hisiv500-linux/bin/
(交叉编译工具路径加入到系统环境变量中,开发环境默认已配置好)
- 生成MakeFile文件
# ./configure --host=arm CC=arm-hisiv500-linux-gcc --prefix=/home/zhangj/iperf/install/
--host: 指定交叉编译工具
--prefix: 指定安装目录,编译后的文件会全部放在安装目录中(注:必须是绝对路径)
- 编译及安装
# make
# make install
- 去除镜像调试信息,缩减程序大小(约缩减50%左右)
# arm-hisiv500-linux-strip iperf3
2.4 解决编译报错
- 报错信息如下:
- 参考解决办法:
A、导入环境变量
export PATH=$PATH:/opt/hisi-linux/x86-arm/arm-hisiv500-linux
B、配置生成Makefile
./configure --host=arm CC=arm-hisiv500-linux-gcc --prefix=/home/zhangj/iperf/install
C、修改/src/makefile.in文件,去掉“-pg”选项
D、备注更改项,注释掉 config.h文件 中的“#define malloc rpl_malloc” 内容;
2.5 说明
iperf有 iperf2版本(命令iperf)和 iperf3版本(命令iperf3)两个版本,两个版本不能混着用,即服务器与客户端使用不同版本的iperf,否则,系统会提示连接错误,信息如下:
“connect failed: Connection refused”
3、Iperf的功能测试
- 测试1Mbps、4Mbps、8Mbps数据传输功能正常,无丢包情况发生。
- Iperf3 配置参数如下:
[root@localhost home]# iperf3 -h
Usage: iperf [-s|-c host] [options]
iperf [-h|--help] [-v|--version]
Server or Client:
-p,--port # server port to listen on/connect to
-f,--format [kmgKMG] format to report: Kbits, Mbits, KBytes,MBytes
-i,--interval # seconds between periodic bandwidthreports
-F,--file name xmit/recv thespecified file
-A,--affinity n/n,m set CPU affinity
-B,--bind <host> bind to a specific interface
-V,--verbose more detailedoutput
-J,--json output in JSONformat
--logfile f sendoutput to a log file
-d,--debug emit debuggingoutput
-v,--version show versioninformation and quit
-h,--help show this messageand 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 clientconnection then exit
Client specific:
-c,--client <host> run in client mode, connecting to<host>
-u,--udp use UDP rather thanTCP
-b,--bandwidth #[KMG][/#] target bandwidth in bits/sec (0 for unlimited)
(default 1 Mbit/secfor UDP, unlimited for TCP)
(optional slash andpacket count for burst mode)
-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 forTCP, 8 KB for UDP)
--cport <port> bind to a specific client port (TCP andUDP, default: ephemeral port)
-P,--parallel # number of parallel client streams torun
-R,--reverse run in reverse mode(server sends, client receives)
-w,--window #[KMG] set window size / socket buffer size
-C,--congestion <algo> set TCPcongestion control algorithm (Linux and FreeBSD only)
-M,--set-mss # set TCP/SCTP maximum segment size (MTU- 40 bytes)
-N,--no-delay set TCP/SCTP nodelay, disabling Nagle's Algorithm
-4,--version4 only use IPv4
-6,--version6 only use IPv6
-S,--tos N set the IP 'type ofservice'
-L,--flowlabel N set the IPv6 flowlabel (only supported on Linux)
-Z,--zerocopy use a 'zero copy'method of sending data
-O,--omit N omit the first nseconds
-T,--title str prefix every outputline with this string
--get-server-output getresults from server
--udp-counters-64bit use64-bit counters in UDP test packets
--no-fq-socket-pacing disablefair-queuing based socket pacing
(Linux only)
[KMG] indicates options that support aK/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at:http://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
- 实际范例测试
服务器:iperf3 -s -i 1
客户端:iperf3 -u -c 192.168.1.60 -b 4M -t 10
显示结果如下:
服务器接收显示:
客户端发送显示:
利用网络管理软件监听网络连接状态,Client指定“-u”模式,即以UDP协议传输报文,网路检测结果如下:
当Client连接时,不指定“-u”,则默认以TCP协议传输报文,网路检测结果如下:
当上述两种模式发送数据完成后,连接与传输网络消失,系统恢复Server对原端口的监听模式,情况如下:
小结:iperf服务器以TCP协议模式监听端口,客户端通过TCP协议连接服务器,但传输使用TCP/UDP协议,则是由客户端发起连接配置时决定的。