### :school: TEEP 2024_RT LAB_ORAN DPDK
#### :book: Technology Background
:::success
List the essential information of this chapter.
1. Networking Programming - iPerf
:::
---
### Networking Programming - iPerf
#### What is iPerf?
iPerf is a simple, free, cross-platform and commonly-used tool for network performance measurement and testing. It supports several protocols (TCP, UDP, SCTP with IPv4 and IPv6) and parameters. iPerf is available for multiple operating systems such as Linux or Windows. It is used by network administrators and engineers to diagnose network issues, optimize performance, and conduct network experiments. iPerf is also used in performance testing and benchmarking of network devices.
Moreover, iPerf can be simply used for network stress testing. For this purpose users should choose the UDP protocol, because TCP automatically carries out rate-limiting to adapt to the available bandwidth. To do it correctly, the user must choose a bandwidth far above what the connection can handle. For example, if a user wants to stress a 10 Mbps connection, they should send about 100 Mbps traffic (using -b parameter).
#### iPerf usage
It is possible to automate network bandwidth measurements using iPerf. In my personal opinion, Python is one of the best choices for this purpose. If we want to use iPerf2 we can use pyperf2 (keep in mind this is 0.2 version) or build a script which runs iPerf script from the command line and collect the output (in this case -y parameter could be useful - report as a comma-separated values).
For iPerf3, a Python module is available here. It is still in its initial version but can be useful for simple measurements. If you want to explore this topic, please check this post about automating bandwidth testing.
iPerf could be used to saturate high speed links, but we must bear in mind that iPerf needs a lot of resources like CPU and memory. Theoretically, iPerf could be used to test links up to 100Gbps, but at such high values a better idea is to use professional, dedicated traffic generators. Moreover, achieving this high network speed often requires the use of specialized hardware and network configurations, such as link aggregation (LAG).
#### iPerf - the usefull options

#### Pros and cons of iPerf
1. iPerf pros
* Supports most popular protocols like TCP, UDP and SCTP. It can be used to test e.g. bandwidth, latency or packet loss.
* iPerf is cross-platform - can be used on Linux, Windows, MacOS, Android, x86, ARM and different network devices.
* iPerf has a simple command-line interface that allows users to quickly start testing their network.
* It is free - anyone can download iPerf and use it to test their own topology.
* It is open-source - anyone can clone and optimize it.
* iPerf is pre-installed on selected systems and devices, for example on TrueNAS.
3. iPerf cons
* Poor community support.
* Existing bugs are not addressed and fixed.
* We have to monitor resources to ensure that reported values are correct and that no throttling occurs.
* Resources should be manually assigned to prevent concurrency between iPerf and other tasks performed by the OS.
* iPerf has no option to generate reports. Users have to use additional tools to generate reports - currently there are no available valuable tools worth recommending, so the best way is to do it by oneself.
* Using iPerf requires basic networking knowledge from the user which could be challenging for some.
* iPerf does not provide many configuration options to set up packets and to control how packets should be sent.
* iPerf3 is not backward compatible with iPerf2.
* iPerf needs a lot of resources when generating high volumes of traffic. CPU power and memory will be very loaded. CPU isolation is good to avoid given that iPerf will share CPU with other tasks on the server, but still we have to monitor resources and tweak the operating system to get maximum performance - e.g. set the governor in performance mode.
#### iPerf Use Case
1. How to check iperf command version
```=
iperf -v
```

2. How to Check Network Performance in Server Mode
If you want to run iperf command in Server mode then you need to use -s option with iperf command as shown below. Also if you want to check transfer bandwidth size in KBytes/sec then you need to use -f option and specify the unit.
```=
iperf -s -f K
```

3. How to Start iperf Server on UDP Port
If you want to start iperf Server on UDP Port instead of starting in default TCP Port then you need to use -u option with iperf command as shown below. In this example we are trying to start iperf in Server mode on default UDP Port 5001 using iperf -s -u command
```=
iperf -s -u
```

4. How to measure bidirectional bandwidths sequentially
If you want to measure bidirectional bandwidths sequentially then you need to use -r option with iperf command as shown below. In this example we are connecting Server 192.168.0.100 on Port 5001 to perform bidirectional tests sequentially.
```=
iperf -c 192.168.0.100 -r
```

5. How to measure bidirectional bandwidths simultaneously
If you want to measure bidirectional bandwidths simultaneously then you need to use -d option with iperf command as shown below. In this example we are connecting Server 192.168.0.100 on Port 5001 to perform bidirectional tests simultaneously.
```=
iperf -c 192.168.0.100 -d
```

6. How to Check UDP Network Statistics in Detail
If you want to check all the UDP Network Statistics like Transfer Bandwidth, Jitter, Packet Loss etc then you need to use below iperf commands. In client end, we will send the data to connect to UDP Port on Server 192.168.0.100 using bandwidth of 10 Mbits/sec.
```=
iperf -c 192.168.0.100 -u -b 10m
```

7. How to Launch Parallel Network Bandwidth Tests
If you want to run parallel network bandwidth tests then you need to use -P option iperf command and specify the number of connections as shown below. In this example we are trying to launch 4 Parallel Network Bandwidth tests by connecting 192.168.0.100 Server on Port 5001.
```=
iperf -c 192.168.0.100 -P 4
```

8. How to Test TCP Connection Using Maximum Segment Size
If you want to test TCP Connection using maximum segment size then you need to use -m option with iperf command as shown below. Usually MSS will have the size range from 0-65535 bytes. Hence by specifying -m option with iperf command will use the maximum segment size of 65535 bytes for TCP testing.
```=
iperf -c 192.168.0.100 -m
```

9. How to check other options of iperf commands in Linux
If you want to check all the other options available with iperf command then you need to use iperf --help command as shown below.
```=
iperf --help
```
