This topic shows you how to use Pktgen to test the network performance of an ECS instance.
This example shows how to use Pktgen to test network performance.
Step 1: Prepare the environment
Prepare two servers: a sender and a receiver. Add a network interface controller to each server—one for logon and one for testing. Ensure that the two test network interface controllers can communicate with each other. Then, run the ifconfig command to record the IP address and MAC address of both test network interface controllers. You will need this information to configure the traffic stream.
Step 2: Install the software
CentOS 6 reached end of life (EOL). In accordance with Linux community rules, all content was removed from the following CentOS 6 repository address: http://mirror.centos.org/centos-6/. If you continue to use the default CentOS 6 repository on Alibaba Cloud, an error is reported. To use specific installation packages of CentOS 6, change the CentOS 6 repository address. For more information, see How do I change CentOS 6 repository addresses?
Perform the following steps on both the sender and the receiver.
-
Connect to the Linux ECS instance. For details, see Connect to a Linux instance using Workbench.
-
Run the following commands to create the
pktgendirectory.cd /root/ mkdir pktgen -
Run the following command to change to the
pktgendirectory.cd pktgen -
Run the following command to download the Pktgen, Lua, and DPDK installation packages.
wget https://git.dpdk.org/apps/pktgen-dpdk/snapshot/pktgen-dpdk-pktgen-3.6.5.zip https://www.lua.org/ftp/lua-5.4.3.tar.gz https://fast.dpdk.org/rel/dpdk-18.11.11.tar.xzNoteNote: The versions of Pktgen, Lua, and DPDK must be compatible to avoid compilation errors. This topic uses the versions listed as an example, but you can use other compatible versions.
-
Run the following commands to decompress the installation packages.
tar -Jxvf dpdk-18.11.11.tar.xz tar -zxvf lua-5.4.3.tar.gz unzip pktgen-dpdk-pktgen-3.6.5.zip -
If dependencies are missing during compilation, run the commands for your operating system to install the required packages.
-
CentOS 7
yum -y install kernel-devel.x86_64 yum -y install numactl-devel.x86_64 yum -y install elfutils-libelf-devel yum -y install libpcap-devel -
CentOS 8
NoteIn CentOS 8, the
libpcap-develpackage is not installed by default. You must install it manually.Before running the following commands, switch the mirror repository as instructed in How to switch the mirror repository for CentOS 8 after EOL?. Then, add the following content to the
CentOS-PowerTools.repofile that you created.[PowerTools] name=CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ http://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ gpgcheck=0 enabled=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-Officialdnf config-manager --add-repo /etc/yum.repos.d/CentOS-PowerTools.repo dnf config-manager --set-enabled PowerTools dnf -y upgrade libmodulemd dnf -y install kernel-devel.x86_64 dnf -y install elfutils-libelf-devel dnf -y install numactl-devel.x86_64 dnf -y install libpcap-devel
-
-
Run the following commands to compile and install DPDK.
cd dpdk-stable-18.11.11 make config T=x86_64-native-linuxapp-gcc make all -j32 cd .. -
Run the following commands to compile and install Lua.
cd lua-5.4.3 make make install cd .. -
Run the following commands to compile and install Pktgen.
cd pktgen-dpdk-pktgen-3.6.5/ export RTE_SDK=/root/pktgen/dpdk-stable-18.11.11/ export RTE_TARGET=build make -j32
Step 3: Bind the driver to VFIO
Perform the following steps on both the sender and the receiver.
-
Run the following command to check the
/proc/cmdlinefile and ensure that the GRUB configuration for the operating system includesintel_iommu=on.cat /proc/cmdlineThe system displays output similar to the following. If the parameter is not present, follow these steps to add it.
BOOT_IMAGE=/boot/vmlinuz-3.10.0-XXXX.19.1.el7.x86_64 root=UUID=9f2d3e15-XXXX-XXXX-8385-0165b4b67864 ro crashkernel=auto spectre_v2=retpoline rhgb quiet net.ifnames=0 console=tty0 console=ttyS0,115200n8 noibrs intel_iommu=on-
Run the following command to edit the
/etc/default/grubfile.vim /etc/default/grub -
Press the
ikey to enter insert mode. Addintel_iommu=onto the GRUB_CMDLINE_LINUX line. The modified content is shown below.
-
To save your changes and close the file, press the
Esckey, enter:wq, and press Enter. -
Run the following command to update the configuration.
grub2-mkconfig -o /boot/grub2/grub.cfg -
Run the following command to restart the server.
reboot
-
-
Run the following commands to load the vfio and vfio-pci drivers.
modprobe vfio modprobe vfio-pci -
Run the following command to configure the
noniommu_mode.echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode -
Run the following command to view and record the
bus-infovalue of the network interface controller.ethtool -i eth1NoteNote: This example uses the
eth1network interface controller. Replaceeth1with the actual name in your environment.The system displays similar output.
driver: virtio_net version: 1.0.0 firmware-version: expansion-rom-version: bus-info: 0000:00:08.0 supports-statistics: no supports-test: no supports-eeprom-access: no supports-register-dump: no supports-priv-flags: no -
Run the following command to unbind the
virtiodriver from theeth1network interface controller.ImportantThis example unbinds the
virtiodriver from theeth1network interface controller. This action will cause a network interruption, so we recommend performing it during off-peak hours.echo "[$Bus-info]" > /sys/bus/pci/drivers/virtio-pci/unbindNoteNote: Replace
[$Bus-info]with thebus-infovalue that you obtained in the previous step. -
Run the following command to bind the
bus-infoto thevfio-pcidriver./root/pktgen/dpdk-stable-18.11.11/usertools/dpdk-devbind.py -b vfio-pci [$Bus-info]NoteThis example is for a CentOS 8.3 (Python 3.6.8) environment. To run the Python script, modify the command as follows:
python3 /root/pktgen/dpdk-stable-18.11.11/usertools/dpdk-devbind.py -b vfio-pci [$Bus-info]
Step 4: Configure huge pages
On both the sender and the receiver, run the command that corresponds to the number of nodes on your system.
-
Dual-node
echo 8000 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages echo 8000 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages -
Single-node
echo 8000 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
Step 5: Start Pktgen
Perform the following steps on both the sender and the receiver.
-
In the
pktgen-dpdk-pktgen-3.6.5directory, run the following command to start Pktgen../app/build/pktgen -c 0x1ffff -n 4 --socket-mem 16000 -w [$Bus-info] -- -P -m "[1-16:1-16].0"NoteNote:
-
0x1ffff: Specifies the CPU core mask for the process. The lowest-bit core handles shell control, while the others send and receive packets on the port. -
"[1-16:1-16].0": Specifies the CPU core numbers. The core numbers must be within the range that the mask defines for sending and receiving packets.-
1-16(before the colon) is for receiving packets. -
1-16(after the colon) is for sending packets. -
.0indicates port 0.
-
-
If the sending performance is insufficient, you can adjust the CPU range. Note that using more CPUs for sending packets requires more huge pages. The Pktgen process may stop if not enough huge pages are allocated.
The system displays similar output and enters the Pktgen terminal.
Copyright (c) <2010-2019>, Intel Corporation. All rights reserved. Powered by DPDK EAL: Detected 64 lcore(s) EAL: Detected 1 NUMA nodes EAL: Multi-process socket /var/run/dpdk/rte/mp_socket EAL: No free hugepages reported in hugepages-1048576kB EAL: Probing VFIO support... EAL: VFIO support initialized EAL: PCI device 0000:00:08.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 1af4:1000 net_virtio EAL: using IOMMU type 8 (No-IOMMU) Lua 5.4.3 Copyright (C) 1994-2021 Lua.org, PUC-Rio *** Copyright (c) <2010-2019>, Intel Corporation. All rights reserved. *** Pktgen created by: Keith Wiles -- >>> Powered by DPDK <<< Initialize Port 0 -- TxQ 16, RxQ 16, Src MAC 00:16:3e:24:9b:a4 Port 0: Link Up - speed 10000 Mbps - full-duplex <Enable promiscuous mode> RX/TX processing lcore: 1 rx: 1 tx: 1 RX/TX processing lcore: 2 rx: 1 tx: 1 RX/TX processing lcore: 3 rx: 1 tx: 1 RX/TX processing lcore: 4 rx: 1 tx: 1 - Ports 0-0 of 1 <Main Page> Copyright (c) <2010-2019>, Intel Corporation Flags:Port : P-----R--------:0 Link State : <UP-10000-FD> ----TotalRate---- Pkts/s Max/Rx : 1/0 1/0 Max/Tx : 0/0 0/0 MBits/s Rx/Tx : 0/0 0/0 Broadcast : 0 Multicast : 0 Sizes 64 : 0 65-127 : 0 128-255 : 0 256-511 : 0 512-1023 : 0 1024-1518 : 0 Runts/Jumbos : 2/0 ARP/ICMP Pkts : 2/0 Errors Rx/Tx : 0/0 Total Rx Pkts : 2 Tx Pkts : 0 Rx MBs : 0 Tx MBs : 0 : Pattern Type : abcd... Tx Count/% Rate : Forever /100% Pkt Size/Tx Burst : 64 / 64 Port Src/Dest : 1234 / 5678 Pkt Type:VLAN ID : IPv4 / UDP:0001 802.1p CoS/DSCP/IPP : 0/ 0/ 0 VxLAN Flg/Grp/vid : 0000/ 0/ 0 IP Destination : 192.168.X.X Source : 192.168.X.X/24 MAC Destination : 00:00:00:00:00:00 Source : 00:XX:XX:24:9b:a4 PCI Vendor/Addr : 1af4:1000/00:08.0 -- Pktgen Ver: 3.6.5 (DPDK 18.11.11) Powered by DPDK (pid:4873) ------------- Pktgen:/> -
-
On the sender, run the following commands in the Pktgen terminal to configure the traffic stream.
set 0 proto udp range 0 src mac start [$MAC] range 0 src mac min [$MAC] range 0 src mac inc 00:00:00:00:00:00 range 0 dst mac start ee:ff:ff:ff:ff:ff range 0 dst mac min ee:ff:ff:ff:ff:ff range 0 dst mac inc 00:00:00:00:00:00 range 0 src port start 10000 range 0 src port min 10000 range 0 src port max 10000 range 0 src port inc 0 range 0 dst port start 2000 range 0 dst port min 2000 range 0 dst port max 2255 range 0 dst port inc 1 range 0 proto udp range 0 src ip start [$Local_IP] range 0 src ip min [$Local_IP] range 0 src ip inc 0.0.0.0 range 0 size start 64 range 0 size min 64 range 0 size max 64 range 0 size inc 0 range 0 dst ip start [$Receive_IP] range 0 dst ip min [$Receive_IP] range 0 dst ip inc 0.0.0.0 enable all rangeNoteNote:
-
[$MAC]is the MAC address of the sender. -
[$Local_IP]is the IP address of the sender. -
[$Receive_IP]is the IP address of the receiver.
-
-
In the Pktgen terminal, run the following command on the sender to start sending traffic.
start 0Review the traffic data on the sender and receiver:
-
Sender
-iPorts 0-0 of 1 <Main Page> Copyright (c) <2010-2019>, Intel Corporation Flags:Port : P-----R--------:0 1/0 Link State : <UP-10000-FD> ----TotalRate---- Pkts/s Max/Rx : 1/0 1/0 Max/Tx : 14906304/14904704 14906304/14904704 MBits/s Rx/Tx : 0/10015 0/10015 Broadcast : 0 Multicast : 0 Sizes 64 : 0 65-127 : 0 128-255 : 0 256-511 : 0 512-1023 : 0 1024-1518 : 0 Runts/Jumbos : 16/0 ARP/ICMP Pkts : 16/0 Errors Rx/Tx : 0/0 Total Rx Pkts : 16 Tx Pkts : 1655962864 -
Receiver
- Ports 0-0 of 1 <Main Page> Copyright (c) <2010-2019>, Intel Corporation Flags:Port : P--------------:0 Link State : <UP-10000-FD> ----TotalRate---- Pkts/s Max/Rx : 14911585/14910795 14911585/14910795 Max/Tx : 0/0 0/0 MBits/s Rx/Tx : 10020/0 10020/0 Broadcast : 0 Multicast : 0 Sizes 64 : 1862740038 65-127 : 0 128-255 : 0 256-511 : 0 512-1023 : 0 1024-1518 : 0 Runts/Jumbos : 6/0 ARP/ICMP Pkts : 6/0 Errors Rx/Tx : 0/0 Total Rx Pkts : 2298743466 Tx Pkts : 0 Rx MBs : 1544755 Tx MBs : 0 : Pattern Type : abcd... Tx Count/% Rate : Forever /100% Pkt Size/Tx Burst : 64 / 64 Port Src/Dest : 1234 / 5678 Pkt Type:VLAN ID : IPv4 / TCP:0001 802.1p CoS/DSCP/IPP : 0/ 0/ 0 VxLAN Flg/Grp/vid : 0000/ 0/ 0 IP Destination : 192.168.X.1 Source : 192.168.X.X/24 MAC Destination : 00:00:00:00:00:00 Source : 00:XX:XX:24:2d:55 PCI Vendor/Addr : 1af4:1000/00:08.0 -- Pktgen Ver: 3.6.5 (DPDK 18.11.11) Powered by DPDK (pid:4072) -------------
-
-
To stop the traffic, run the following command on the sender.
stop 0