# Iperf2 與 Iperf3 哪裡大不同
## :memo: 介紹
iperf 是用來測試 Server 與 Client 之間的連線速度工具
:::info
:bulb: **差別 I**
iperf2 能夠測試 TCP 及 UDP
iperf3 只能夠測試 TCP
:bulb: **差別 II**
iperf2 能控制 multiple client requests
iperf3 只能一次建立一條 iperf connection
:bulb: **差別 III** `iperf3不相容iperf2`
Some iperf2 Features Not Supported by iPerf3:
(Bidirectional testing (-d / -r) & Data transmitted from stdin (-I))
:::
## :rocket: iperf2 介紹用法
```javascript
iperf [-u] [-s|-c host] [options]
```
### ==Server==
#### Opts:
```
-s # server mode
-D, --daemon
-p N # listen 那個 port ( Default: 5001 )
-B IP # listen 那個 interface
-u # 用 UDP 去 test speed ( Default: TCP )
-w, --window n[KM] # 更改 TCP window size ( socket buffer size )
```
#### i.e.
所有都用 Default Setting 來執行 Server
```
iperf -s
```
改用 UDP 及 Port 8888 並 bind 其中一個 Interface
```
iperf -s -u -P 5001 -B 192.168.123.254
```
### ==Client==
#### Opts
```
-c # client mode
-t t # 測試幾秒 ( Default 10 secs )
-f [kmKM] # 顯示的單位 ( Kbits, Mbits, KBytes, MBytes )
-i s # 多久一次 report
-p p # server port, default port 5001
-P, --parallel n # number of parallel client threads to run
-w N # 是用來加大 TCP Window Size ( defealt 8 KByte )
```
Default Upload Test Only !! ( C -> S )
#### i.e.
測試 20 秒, Unit: Mbit, 每5秒report一次
```
iperf -c 192.168.123.254 -t 20 -f M -i 5
```
### UDP 測試
iperf uses a **default** of **1Mb/sec** for UDP tests.
#### opts
```
-u # 使用 udp 測試 (Default 是用 tcp)
-b # 限制 bandwidth. --bandwidth n[k/m](bit/sec) requires UDP (-u)
Use the -b flag on the iperf client to specify the UDP bandwidth
```
#### i.e.
```
iperf -c 192.168.88.150 -t 20 -i 5 -u -b 100m
```
#### i.e. 來回測試 (-r / -d)
```
iperf -c 192.168.123.254 -f K -r
```
```
-L N # 是指要 Server 送 data 到 client 的指定 port (client local port)
-r # --tradeoff, 是指先 client upload 完後, server 才再送 data 回 Client
-d # --dualtest, 同時互相傳遞資料 ( duplex )
```
---
## :memo: iperf3 介紹用法
New Features in iperf 3.1
```
-I, --pidfile file write a file with the process ID, most useful when running as a daemon.
--cport : Specify the client-side port.
--sctp use SCTP rather than TCP (Linux, FreeBSD and Solaris).
--udp-counters-64bit : Support very long-running UDP tests, which could cause a counter to overflow
--logfile file : send output to a log file.
```
New Features in iPerf 3.0 :
```
Dynamic server (client/server parameter exchange)
(Most server options from iPerf2 can now be dynamically set by the client)
Client/server results exchange
iPerf API (libiperf) – Provides an easy way to use, customize and extend iPerf functionality
-R, Reverse test mode – Server sends, client receives
-O, --omit N : omit the first n seconds (to ignore TCP slowstart)
-b, --bandwidth n[KM] for TCP (only UDP for IPERF 2): Set target bandwidth to n bits/sec (default 1 Mbit/sec for UDP, unlimited for TCP).
-V, --verbose : more detailed output than before
-J, --json : output in JSON format
-Z, --zerocopy : use a 'zero copy' sendfile() method of sending data. This uses much less CPU. ( Client Opts)
-T, --title str : prefix every output line with this string
-F, --file name : xmit/recv the specified file
-A, --affinity n/n,m : set CPU affinity (cores are numbered from 0 - Linux and FreeBSD only)
-k, --blockcount #[KMG] : number of blocks (packets) to transmit (instead of -t or -n)
-C, --linux-congestion : set congestion control algorithm (Linux and FreeBSD only) (-Z in iPerf2)
```
### ==Server==
```
iperf3 -s -D -i 5 -f M -p 5201 --logfile iperf.log -I iperf.pid
```
```
-f, --format [kmKM] # 'k' = Kbits/sec, 'K' = KBytes/sec
-F, --file name # client-side: read from the file and write to the network, instead of using random data;
# server-side: read from the network and write to the file, instead of throwing the data away.
-i, --interval n # If zero, no periodic reports are printed. Default is zero.
```
### ==Client==
```
-O, --omit n # Omit the first n seconds of the test, to skip past the TCP TCP slowstart period.
-P, --parallel n # The number of simultaneous connections to make to the server. Default is 1.
-R, --reverse # Run in reverse mode (server sends, client receives).
```
---
參考來源:
https://datahunter.org/iperf