Iperf使用教程、移植到ARM、移植时遇到的问题解决

iperf是一个基于Client/Server的网络性能测试工具,可以测试TCP、UDP和SCTP带宽质量,能够提供网络吞吐率信息,以及震动、丢包率,最大段和最大传输单元大小等统计信息,帮助我们测试网络性能,定位网络瓶颈。其中抖动和丢包率适应于UDP测试,二带宽测试适应于TCP和UDP。

iperf的好处是纯粹发包和接收,防止硬盘拖后腿,影响测试结果。对于时延,iperf无能无力。但是iperf能够计算抖动。在iperf测试中需要发送大量的包,因此计算出来的抖动值,就是连续发送时延差值的平均值。

iperf是一个开源软件,其源码在GitHub上,地址:https://github.com/esnet/iperf

1 下载

下载最新版本源码包,下载地址:http://downloads.es.net/pub/iperf/。本文以 iperf-3.0.3.tar.gz 版本为例。

2 解压

$ mkdir ~/iperf
$ cp iperf-3.0.3.tar.gz ~/iperf
$ cd ~/iperf
$ tar xzf iperf-3.0.3.tar.gz
$ cd iperf-3.0.3/

命令中的“~”表示当前用户目录,比如在Linux主机上面工作的用户是:veryarm,那么命令中的“~”就代表路径:/home/veryarm/目录。

3 配置


   
   
  1. $ mkdir ../install
  2. $ export PATH=$PATH :/usr/local/arm- 2010q1/bin #交叉编译工具路径加入系统环境变量!
  3. $ ./configure --host=arm-none-linux-gnueabi --prefix= /home/veryarm /iperf/install

其中,

  • --host: 指定交叉编译工具,一般为arm-none-linux-gnueabi、arm-linux-gnueabihf、arm-linux等,具体要和目标板用的交叉编译工具对应。
  • --prefix: 指定安装目录,编译后的文件会全部放在安装目录中。必须是绝对路径!

4 编译


   
   
  1. $ make # 编译,如果是多核CPU,如四核,使用make -j4可提高编译速度
  2. $ make install # 安装

完成后,文件会自动安装到上面指定的 install 目录。

 5 去除调试信息并压缩

使用交叉编译工具 strip 去除镜像的调试信息,在不影响使程序使用的情况下,程序大小一般可以减小50%左右。本程序我们仅用到其中2个文件,bin下的iperf3 和 lib下的libiperf.so.0.0.0。


   
   
  1. $ cd ../install # 进入安装目录
  2. $ arm-none-linux-gnueabi-strip bin/iperf3 # 去除iperf3镜像调试信息
  3. $ arm-none-linux-gnueabi-strip lib/libiperf.so. 0. 0. 0 # 去除共享库的调试信息
  4. $ rm lib/libiperf.a lib/libiperf.la # 删除两个不用的库文件
  5. $ tar jcf iperf- 3.0. 3.tar.bz2 bin lib # 压缩bin和lib目录

 

6 复制

将打包后的 iperf-3.0.3.tar.bz2 压缩包通过U盘、FTP或者NFS等方式拷贝到目标板,并分别解压到/bin和/sbin目录。


   
   
  1. $ cp iperf- 3.0. 3.tar.bz2 ~ # 将复制压缩包到目标板用户目录
  2. $ tar jxf iperf- 3.0. 3.tar.bz2 bin -C /usr # 解压镜像到/usr/bin
  3. $ tar jxf iperf- 3.0. 3.tar.bz2 lib -C /usr # 解压库文件到/usr/lib

 

7 使用

iperf有iperf2版本(命令iperf)和iperf3版本(命令iperf3),现在很多Linux系统和目标板系统默认有iperf2,而这两个版本又不能混着用,也就是说,如果服务器运行iperf2,而目标板上运行 iperf3 是无法测试的,会提示“connect failed: Connection refused”错误。

有鉴于此,本文重点以新版的 iperf3 为例进行测试。

(1)电脑安装iperf

复制第1步下载的源码到电脑上,在Ubuntu(或其他机器)上,使用以下命令安装 iperf3 到电脑上:


   
   
  1. $ cd iperf- 3.0. 3/
  2. $ ./configure
  3. $ make
  4. $ sudo make install

iperf3程序会自动安装到/usr/local/bin目录下,其共享库则安装到/usr/local/lib/目录下。

如果运行 iperf 命令时提示“iperf3: error while loading shared libraries: libiperf.so.0: cannot open shared object file: No such file or directory”错误,制作一个软连接可解决,命令如下:

sudo ln -s /usr/local/lib/libiperf.so.0.0.0 /usr/lib/iperf.so.0

(2)启动服务器iperf

在Ubuntu上,以服务端方式启动:

$ iperf3 -s -i 1

参数说明:

  • -s:以服务器方式启动
  • -i:以秒为单位显示报告间隔
  • -w:指定TCP窗口大小,默认是8KB

(3)启动客户端

在目标板上,以客户端方式连接到服务端,测试10秒钟。

 $ iperf3 -c 192.168.1.100 -i 1 -w 448k -t 10
   
   

参数说明:

  • -c:以client模式启动,随后跟着服务器的IP地址
  • -t:测试时间,默认10秒

执行后,服务器端显示:

Accepted connection from 192.168.1.250, port 55010
[ 5] local 192.168.1.100 port 5201 connected to 192.168.1.250 port 55011
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-1.07 sec 2.12 MBytes 16.7 Mbits/sec 
[ 5] 1.07-2.06 sec 2.38 MBytes 20.2 Mbits/sec 
[ 5] 2.06-3.10 sec 2.38 MBytes 19.1 Mbits/sec 
[ 5] 3.10-4.08 sec 2.38 MBytes 20.4 Mbits/sec 
[ 5] 4.08-5.07 sec 2.62 MBytes 22.2 Mbits/sec 
[ 5] 5.07-6.00 sec 2.38 MBytes 21.4 Mbits/sec 
[ 5] 6.00-7.06 sec 2.75 MBytes 21.7 Mbits/sec 
[ 5] 7.06-8.10 sec 2.50 MBytes 20.2 Mbits/sec 
[ 5] 8.10-9.10 sec 2.50 MBytes 21.0 Mbits/sec 
[ 5] 9.10-10.06 sec 2.50 MBytes 21.9 Mbits/sec 
[ 5] 10.06-10.10 sec 128 KBytes 26.0 Mbits/sec 
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 5] 0.00-10.10 sec 24.6 MBytes 20.5 Mbits/sec 7 sender
[ 5] 0.00-10.10 sec 24.6 MBytes 20.5 Mbits/sec receive

客户端显示:

Connecting to host 192.168.1.100, port 5201
[ 4] local 192.168.1.250 port 55011 connected to 192.168.1.100 port 5201
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.03 sec 2.25 MBytes 18.4 Mbits/sec 4 96.2 KBytes 
[ 4] 1.03-2.02 sec 2.38 MBytes 20.0 Mbits/sec 0 112 KBytes 
[ 4] 2.02-3.06 sec 2.38 MBytes 19.2 Mbits/sec 1 90.5 KBytes 
[ 4] 3.06-4.02 sec 2.38 MBytes 20.7 Mbits/sec 0 96.2 KBytes 
[ 4] 4.02-5.02 sec 2.62 MBytes 22.1 Mbits/sec 0 106 KBytes 
[ 4] 5.02-6.03 sec 2.62 MBytes 21.9 Mbits/sec 1 76.4 KBytes 
[ 4] 6.03-7.02 sec 2.50 MBytes 21.0 Mbits/sec 0 100 KBytes 
[ 4] 7.02-8.00 sec 2.38 MBytes 20.4 Mbits/sec 0 112 KBytes 
[ 4] 8.00-9.06 sec 2.62 MBytes 20.8 Mbits/sec 1 89.1 KBytes 
[ 4] 9.06-10.03 sec 2.50 MBytes 21.7 Mbits/sec 0 105 KBytes 
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.03 sec 24.6 MBytes 20.6 Mbits/sec 7 sender
[ 4] 0.00-10.03 sec 24.6 MBytes 20.6 Mbits/sec receiver

iperf Done.

以上信息显示,当前网卡传输速度约为 20Mbit/s,下载速度 2.5 Mbit/s。

8 iperf参数

除了以上参数,我们还可以在iperf中使用下面的参数。

(1)通用参数

  • -f:后接[k|m|K|M],分别表示以Kbits,Mbits,Kbytes,Mbytes显示报告,默认以Mbits以单位,例如,
$ iperf3 –c 192.168.22.100 –f K
 
 
  • -o:将报告和错误信息输出到文件,例如,
iperf3c 192.168.1.100 -o iperf.log
 
 
  • -p:指定服务器端使用的端口或客户端的端口。

 
 
  1. $ iperf3 –c 192.168. 22.66 –p 1234
  2. $ iperf3 –s –p 1234
  • -u:指定使用udp协议
  • -M:指定TCP数据包的最大mtu值。
  • -N:设定TCP不延迟

(2)服务器端

  • -D:以服务方式运行iperf,例如,
$ iperf3 -s –D
  • -R:停止iperf服务,针对-D

(3)客户端

  • -d:同时进行双向传输测试
  • -n:指定传输的字节数。
KaTeX parse error: Expected 'EOF', got '&' at position 1: &̲nbsp;iperf3 -c …PATH:/opt/hisi-linux/x86-arm/arm-hisiv500-linux

   ./configure --host=arm  CC=arm-hisiv500-linux-gcc --prefix=/home/iperf/install

3… 在第四步交叉编译的时候遇到的错误。 

   如果make通不过的话就到 config.h 中把 #define malloc rpl_malloc 注释掉。

修改makefile.in 里面的配置.

src/Makefile.in 613行 地方两行,去掉-pg参数.修改后如下

复制代码
##iperf3_profile_CFLAGS = -pg -g
iperf3_profile_CFLAGS = -g
iperf3_profile_LDADD = libiperf.la
##iperf3_profile_LDFLAGS = -pg -g
iperf3_profile_LDFLAGS = -g

Specify the sources and various flags for the test cases

t_timer_SOURCES = t_timer.c

复制代码

 hisi uclib 如果不修改上面两行则会出现如下错误

/opt/hisi-Linux/x86-arm/arm-hisiv300-linux/bin/…/lib/gcc/arm-hisiv300-linux-uclibcgnueabi/4.8.3/…/…/…/…/arm-hisiv300-linux-uclibcgnueabi/bin/ld: cannotfind gcrt1.o: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [iperf3_profile] Error 1
make[2]: Leaving directory /home/ll/work2016/opensource/iperf-3.1.2/src'<br style="margin:0px;padding:0px;">make[1]: *** [all] Error 2<br style="margin:0px;padding:0px;">make[1]: Leaving directory/home/ll/work2016/opensource/iperf-3.1.2/src’
make: *** [all-recursive] Error 1






  •                     <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">2</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/qq_31186123">
                    <img src="https://profile.csdnimg.cn/3/B/E/3_qq_31186123" class="avatar_pic" username="qq_31186123">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/4.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/qq_31186123" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">再闹东海7</a></span>
                                            </div>
                    <div class="text"><span>发布了42 篇原创文章</span> · <span>获赞 97</span> · <span>访问量 13万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=qq_31186123" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值