Using Pktgen-DPDK
Server Network
Lastmod: 2024-06-17
Published: 2024-06-13

Overview

I wanted to perform a load test with short packets, so I tried using Pktgen-DPDK.

It is necessary to enable IOMMU beforehand. IOMMU Activation Memo

Environment

EnvironmentVersion
Ubuntu22.04
DPDK23.11.1
Pktgen-DPDKmain branch
NICIntel X520 DA2

Installing Required Packages

  • Install dependencies

    sudo apt-get update
    sudo apt-get install -y git build-essential libnuma-dev python3-pyelftools linux-headers-$(uname -r) meson ninja-build
    

Building and Installing DPDK

  • Download the DPDK library

    wget https://fast.dpdk.org/rel/dpdk-23.11.1.tar.xz
    tar xf dpdk-23.11.1.tar.xz
    cd dpdk-stable-23.11.1
    
  • Build DPDK

    meson setup build
    ninja -C build
    
  • Install

    ninja -C build install
    ldconfig
    

Configuring Hugepages

  • Configure hugepages DPDK uses large memory pages (hugepages) to achieve high performance.

    echo "vm.nr_hugepages=1024" > /etc/sysctl.d/90-hugapage.conf
    sysctl --system
    

Building and Installing Pktgen-DPDK

  • Pktgen-DPDK

    git clone https://github.com/pktgen/Pktgen-DPDK.git
    cd Pktgen-DPDK
    
  • Build

    meson setup build
    ninja -C build
    
  • Install

    ninja -C build install
    

Binding Network Interfaces

  • Check network interfaces

    dpdk-devbind.py --status
    
    Network devices using kernel driver
    ===================================
    0000:07:00.0 'RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet Controller 8168' if=enp7s0 drv=r8169 unused=
    0000:09:00.0 '82599ES 10-Gigabit SFI/SFP+ Network Connection 10fb' if=enp9s0f0 drv=ixgbe unused=
    0000:09:00.1 '82599ES 10-Gigabit SFI/SFP+ Network Connection 10fb' if=enp9s0f1 drv=ixgbe unused=
    
  • Bind to vfio-pci

    dpdk-devbind.py --bind=vfio-pci 0000:09:00.1
    
  • If you get Error: Driver 'vfio-pci' is not loaded. Load the vfio-pci driver

    modprobe vfio-pci
    
  • Verify binding

    dpdk-devbind.py --status
    Network devices using DPDK-compatible driver
    ============================================
    0000:09:00.1 '82599ES 10-Gigabit SFI/SFP+ Network Connection 10fb' drv=vfio-pci unused=ixgbe
    

    It’s OK if drv=vfio-pci

Using Pktgen-DPDK

  • Start Pktgen-DPDK

    pktgen -l 0-1 -n 2 --proc-type auto --socket-mem 512 -- -P -m "[1-2].0"
    
  • DPDK options

    • -l 0-1
      • Use logical cores 0-1 for DPDK
    • -n 2
      • Use 2 memory channels
    • –proc-type auto
      • Automatically determine the process type
    • –socket-mem 512
      • Allocate 512MB to socket 0
  • pktgen options

    • -P
      • Enable promiscuous mode
    • -m “[1-2].0”
      • Specify core allocation for each port. In this case, assign ports 1 and 2 to core 0.

Sending Packets

reset 0
set 0 dst mac XX:XX:XX:XX:XX:XX // Destination MAC address
set 0 dst ip 192.168.3.2        // Destination IP address
set 0 src ip 192.168.3.1/24     // Source IP address
set 0 size 64                   // Payload size
start 0

Conclusion

With this setup, you should be able to send around 10Mpps of short packets from the NIC.
This can simulate a DDoS-like situation! I tried using Pktgen-DPDK for this purpose.