1. 程式人生 > >我的openwrt學習筆記(二十):WIFI 無線傳輸速率測試-iperf

我的openwrt學習筆記(二十):WIFI 無線傳輸速率測試-iperf

Iperf是一個TCP/IP和UDP/IP的效能測量工具,能夠提供網路吞吐率資訊,以及震動、丟包率、最大段和最大傳輸單元大小等統計資訊;從而能夠幫助我們測試網路效能,定位網路瓶頸。

現在ubuntu單虛擬機器不同終端以及不同虛擬機器之間的測試為例說明如何安裝以及使用,然後提供MT7688  openwrt平臺交叉編譯的方法。

使用這個工具的目的是為了測試MTK7688開發板上面的wifi效能,所以後面還需要對其進行交叉編譯!

ubuntu下iperf的安裝

Iperf 安裝

linux@ubuntu:~$ sudo apt-get install iperf

[sudo] password for linux:

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following NEW packages will be installed:

  iperf

0 upgraded, 1 newly installed, 0 to remove and 615 not upgraded.

Need to get 54.0 kB of archives.

After this operation, 169 kB of additional disk space will be used.

Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise/universe iperf i386 2.0.5-2.1 [54.0 kB]

Fetched 54.0 kB in 0s (71.7 kB/s)

Selecting previously unselected package iperf.

(Reading database ... 149737 files and directories currently installed.)

Unpacking iperf (from .../iperf_2.0.5-2.1_i386.deb) ...

Processing triggers for doc-base ...

Processing 1 added doc-base file...

Processing triggers for man-db ...

Setting up iperf (2.0.5-2.1) ...

linux@ubuntu:~$ iperf -V

Usage: iperf [-s|-c host] [options]

Try `iperf --help' for more information.

linux@ubuntu:~$ iperf -v

iperf version 2.0.5 (08 Jul 2010) pthreads

1.同一虛擬機器,不同終端

終端1

linux@ubuntu:~$ iperf -s

------------------------------------------------------------

Server listening on TCP port 5001

TCP window size: 85.3 KByte (default)

------------------------------------------------------------

[  4] local 192.168.0.127 port 5001 connected with 192.168.0.127 port 34052

[ ID] Interval       Transfer     Bandwidth

[  4]  0.0-10.0 sec  38.9 GBytes  33.4 Gbits/sec

終端2

linux@ubuntu:~$ iperf -c 192.168.0.127

------------------------------------------------------------

Client connecting to 192.168.0.127, TCP port 5001

TCP window size:  334 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 34052 connected with 192.168.0.127 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0-10.0 sec  38.9 GBytes  33.4 Gbits/sec

2.不同虛擬機器 TCP iperf測試

虛擬機器1

linux@ubuntu:~$ iperf -s

------------------------------------------------------------

Server listening on TCP port 5001

TCP window size: 85.3 KByte (default)

------------------------------------------------------------

[  4] local 192.168.0.160 port 5001 connected with 192.168.0.127 port 60192

[ ID] Interval       Transfer     Bandwidth

[  4]  0.0-10.0 sec  4.80 GBytes  4.12 Gbits/sec

虛擬機器2

linux@ubuntu:~$ iperf -c 192.168.0.160

------------------------------------------------------------

Client connecting to 192.168.0.160, TCP port 5001

TCP window size: 21.0 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 60192 connected with 192.168.0.160 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0-10.0 sec  4.80 GBytes  4.13 Gbits/sec

3.不同虛擬機器 udp iperf測試

虛擬機器1

^Clinux@ubuntu:~$ iperf -s -u

------------------------------------------------------------

Server listening on UDP port 5001

Receiving 1470 byte datagrams

UDP buffer size:  160 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.160 port 5001 connected with 192.168.0.127 port 39359

[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams

[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec   0.044 ms    0/  893 (0%)

虛擬機器2

linux@ubuntu:~$ iperf -c 192.168.0.160 -u

------------------------------------------------------------

Client connecting to 192.168.0.160, UDP port 5001

Sending 1470 byte datagrams

UDP buffer size:  160 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 39359 connected with 192.168.0.160 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec

[  3] Sent 893 datagrams

[  3] Server Report:

[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec   0.043 ms    0/  893 (0%)

-i制定輸出間隔

linux@ubuntu:~$ iperf -c 192.168.0.160 -u -i 2

------------------------------------------------------------

Client connecting to 192.168.0.160, UDP port 5001

Sending 1470 byte datagrams

UDP buffer size:  160 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 35034 connected with 192.168.0.160 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0- 2.0 sec   257 KBytes  1.05 Mbits/sec

[  3]  2.0- 4.0 sec   256 KBytes  1.05 Mbits/sec

[  3]  4.0- 6.0 sec   256 KBytes  1.05 Mbits/sec

[  3]  6.0- 8.0 sec   257 KBytes  1.05 Mbits/sec

[  3]  8.0-10.0 sec   256 KBytes  1.05 Mbits/sec

[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec

[  3] Sent 893 datagrams

[  3] Server Report:

[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec   0.056 ms    0/  893 (0%)

-b制定頻寬

linux@ubuntu:~$ iperf -c 192.168.0.160 -u -i 2 -b 2M

------------------------------------------------------------

Client connecting to 192.168.0.160, UDP port 5001

Sending 1470 byte datagrams

UDP buffer size:  160 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 39060 connected with 192.168.0.160 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0- 2.0 sec   490 KBytes  2.01 Mbits/sec

[  3]  2.0- 4.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  4.0- 6.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  6.0- 8.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  8.0-10.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  0.0-10.0 sec  2.39 MBytes  2.00 Mbits/sec

[  3] Sent 1702 datagrams

[  3] Server Report:

[  3]  0.0-10.0 sec  2.39 MBytes  2.00 Mbits/sec   0.099 ms    0/ 1702 (0%)

-t指定測試時間

linux@ubuntu:~$ iperf -c 192.168.0.160 -u -i 2 -b 2M -t 30

------------------------------------------------------------

Client connecting to 192.168.0.160, UDP port 5001

Sending 1470 byte datagrams

UDP buffer size:  160 KByte (default)

------------------------------------------------------------

[  3] local 192.168.0.127 port 37215 connected with 192.168.0.160 port 5001

[ ID] Interval       Transfer     Bandwidth

[  3]  0.0- 2.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  2.0- 4.0 sec   490 KBytes  2.01 Mbits/sec

[  3]  4.0- 6.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  6.0- 8.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  8.0-10.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 10.0-12.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 12.0-14.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 14.0-16.0 sec   490 KBytes  2.01 Mbits/sec

[  3] 16.0-18.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 18.0-20.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 20.0-22.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 22.0-24.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 24.0-26.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 26.0-28.0 sec   488 KBytes  2.00 Mbits/sec

[  3] 28.0-30.0 sec   488 KBytes  2.00 Mbits/sec

[  3]  0.0-30.0 sec  7.15 MBytes  2.00 Mbits/sec

[  3] Sent 5103 datagrams

[  3] Server Report:

[  3]  0.0-30.0 sec  7.15 MBytes  2.00 Mbits/sec   0.036 ms    0/ 5102 (0%)

[  3]  0.0-30.0 sec  1 datagrams received out-of-order

5. 交叉編譯iperf

 1)下載iperf-2.0.5-source.tar.gz

 2)解壓,並進行編譯配置

./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc LD=mipsel-openwrt-linux-ld ac_cv_func_malloc_0_nonnull=yes

echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.cache

./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc LD=mipsel-openwrt-linux-ld -cache-file=arm-linux.cache

 3)編譯

出現的錯誤以及警告解決方法:

a.     mips-openwrt-linux-gcc: warning: environment variable'STAGING_DIR' not defined

解決辦法是在命令列輸入:

export STAGING_DIR=(你的OpenWrt目錄的絕對路徑)/staging_dir

exportSTAGING_DIR=/home/linux/mt7688/openwrt-3.10.14/staging_dir

b.undefinedreference to `rpl_malloc'

必須新增ac_cv_func_malloc_0_nonnull=yes,否則編譯時會報錯undefined reference to `rpl_malloc'

./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc LD=mipsel-openwrt-linux-ld ac_cv_func_malloc_0_nonnull=yes

echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.cache

./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc LD=mipsel-openwrt-linux-ld -cache-file=arm-linux.cache

linux@ubuntu:~/linux_c/iperf-2.0.5/src$ file iperf

iperf: ELF 32-bit LSB executable, MIPS,MIPS32 rel2 version 1, dynamically linked (usesshared libs), with unknown capability 0xf41 = 0x756e6700, with unknowncapability 0x70100 = 0x3040000, not stripped

發現預設是動態檔案,最好可以編譯成靜態,可惜無法編譯成功,看資訊是因為libstdc++.so.6缺乏部分函式定義

linux@ubuntu:~/linux_c/iperf-2.0.5/src$ cd../

linux@ubuntu:~/linux_c/iperf-2.0.5$./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gccLD=mipsel-openwrt-linux-ld ac_cv_func_malloc_0_nonnull=yes CFLAGS=-static –無法編譯成功,注意要先make clean

4)下載到開發板進行 測試

./iperf: can't load library 'libstdc++.so.6'
交叉編譯工具鏈有的這個庫,需要把工具鏈中的檔案拷貝進開發板的/usr/lib

root@OpenWrt:/tmp# ./iperf -c 192.168.0.107
------------------------------------------------------------
Client connecting to 192.168.0.107, TCP port 5001
TCP window size: 20.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.143 port 44193 connected with 192.168.0.107 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  94.8 MBytes  79.3 Mbits/sec
root@OpenWrt:/tmp# ./iperf -l 2048 -c 192.168.0.107
------------------------------------------------------------
Client connecting to 192.168.0.107, TCP port 5001
TCP window size: 20.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.143 port 44194 connected with 192.168.0.107 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  78.7 MBytes  66.1 Mbits/sec

6. ixcharit測試工具

用的無線網絡卡測試 ;無線對有線,無線對無線