iperf的使用

实际操作

1、背景
开发板通过USB与PC相连,开发板会被枚举成USB网卡,通过网卡进行通信。通过USB连接后,开发板串口生成usb0网卡,内容如下:

开发板
1
2
3
4
5
6
7
8
@android:/ # ifconfig -a
usb0 Link encap:Ethernet HWaddr 8a:18:0b:ee:24:78
inet addr:172.30.100.121 Bcast:172.30.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:14 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2461 TX bytes:144

PC的ubuntu下识别到新的网卡enp0s20f0u10,内容如下:

ubuntu
1
2
3
4
5
6
7
enp0s20f0u10 Link encap:Ethernet  HWaddr de:3b:4e:04:3f:17  
inet6 addr: fe80::ecbb:42d7:4e7:a3c6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:560 (560.0 B) TX bytes:4396 (4.3 KB)

iperf client通常表示数据的发送者,所以这里PC的ubuntu做为client。
iperf server表示数据的接收者,所以这里开发板做为server。

2、测试TCP步骤

  • 配置同一网段的ip:
    在开发板串口配置usb0网卡的ip:ifconfig usb0 192.168.4.1 netmask 255.255.255.0 up
    在ubuntu配置enp0s20f0u10网卡的ip:sudo ifconfig enp0s20f0u10 192.168.4.2 netmask 255.255.255.0 up

  • 开发板配置server,端口号为80

开发板
1
2
3
4
5
@android:/ # ./var/iperf -s -p 80
------------------------------------------------------------
Server listening on TCP port 80
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
  • ubuntu配置client
ubuntu
1
2
3
4
5
victor@victor-HP:~# iperf -c 192.168.4.1 -p 80
------------------------------------------------------------
Client connecting to 192.168.4.1, TCP port 80
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
  • 测试结果:

当上面的步骤执行之后,可以看到测试的数据,server端log如下:

开发板
1
2
3
4
5
6
7
8
@android:/ # ./var/iperf -s -p 80                                             
------------------------------------------------------------
Server listening on TCP port 80
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.4.1 port 80 connected with 192.168.4.2 port 60906
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 186 MBytes 156 Mbits/sec

client端log如下:

ubuntu
1
2
3
4
5
6
7
8
victor@victor-HP:~# iperf -c 192.168.4.1 -p 80
------------------------------------------------------------
Client connecting to 192.168.4.1, TCP port 80
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.4.2 port 60906 connected with 192.168.4.1 port 80
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 186 MBytes 156 Mbits/sec

3、测试UDP步骤
在上述命令的基础上加上-u的参数,指定UDP测试,UDP的测试结果为:

开发板
1
2
3
4
5
6
7
8
9
@android:/ # ./var/iperf -s -p 80 -u
------------------------------------------------------------
Server listening on UDP port 80
Receiving 1470 byte datagrams
UDP buffer size: 224 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.4.1 port 80 connected with 192.168.4.2 port 59627
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0-60.0 sec 7.50 MBytes 1.05 Mbits/sec 0.099 ms 0/ 5351 (0%)
ubuntu
1
2
3
4
5
6
7
8
9
10
11
12
victor@victor-HP:~# iperf -c 192.168.4.1 -p 80 -t 60 -u
------------------------------------------------------------
Client connecting to 192.168.4.1, UDP port 80
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.4.2 port 59627 connected with 192.168.4.1 port 80
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-60.0 sec 7.50 MBytes 1.05 Mbits/sec
[ 3] Sent 5351 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 7.50 MBytes 1.05 Mbits/sec 0.098 ms 0/ 5351 (0%)

上述得到UDP的带宽为 1.05Mb/s,明显少了很多, 这是因为默认情况下,iPerf将UDP客户端的带宽限制为每秒1 Mbit。可以通过以下命令测试UDP的带宽:

ubuntu
1
2
3
4
5
6
7
8
9
10
11
12
13
victor@victor-HP:~# iperf -c 172.30.100.11 -p 80 -u -b 1000m
------------------------------------------------------------
Client connecting to 172.30.100.11, UDP port 80
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 172.30.100.12 port 56174 connected with 172.30.100.11 port 80
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 184 MBytes 155 Mbits/sec
[ 3] Sent 131516 datagrams
[ 3] Server Report:
[ 3] 0.0-10.0 sec 178 MBytes 149 Mbits/sec 0.198 ms 4429/131515 (3.4%)
[ 3] 0.0-10.0 sec 1 datagrams received out-of-order

-b 1000m告诉客户端我们希望尽可能达到每秒1000 Mbits的最大值。 -b标志仅在使用UDP连接时有效,因为iPerf未在TCP客户端上设置带宽限制。


参考资料

Title:iperf的使用

Author:Victor Huang

Time:2019-08-11 / 14:08

Link:http://wowothink.com/5ed212d1/

License: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)