Getting Started with Pktgen

发布时间 2023-11-14 16:07:23作者: ImreW

This section contains instructions on how to get up and running with DPDK and the pktgen traffic generator application.

本节包含有关如何启动和运行 DPDK 和 pktgen 流量生成器应用程序的说明。

These instructions relate to setting up DPDK and pktgen on an Ubuntu desktop system. However, the should work on any recent Linux system with kernel support for hugeTLB/hugepages.

这些说明涉及在 Ubuntu 桌面系统上设置 DPDK 和 pktgen。 然而,它应该适用于任何最新的内核支持巨大TLB/大页的Linux系统。

System requirements

The main system requirement is that the DPDK packet processing framework is supported.

主要系统要求是支持DPDK数据包处理框架。

The DPDK Linux Getting Started Guide has a section on the System Requirements that explains the BIOS, System and Toolchain requirements to compile and run a DPDK based application such as pktgen. Ensure that your system meets those requirements before proceeding.

DPDK Linux 入门指南中有一个关于系统要求的部分,解释了编译和运行基于 DPDK 的应用程序(例如 pktgen)的 BIOS、系统和工具链要求。 在继续之前,请确保您的系统满足这些要求。

You will also need a DPDK supported NIC.

您还需要一个支持 DPDK 的 NIC。

The current version of pktgen was developed and tested using Ubuntu 13.10 x86_64, kernel version 3.5.0-25, on a Westmere Dual socket board running at 2.4GHz with 12GB of ram 6GB per socket.

当前版本的 pktgen 是使用 Ubuntu 13.10 x86_64、内核版本 3.5.0-25 在 Westmere 双插槽板上开发和测试的,运行频率为 2.4GHz,每个插槽 12GB 内存 6GB。

Setting up hugeTLB/hugepage support

To get hugeTLB/hugepage support your Linux kernel must be at least 2.6.33 and the HUGETLBFS kernel option must be enabled.

要获得hugeTLB/hugepage 支持,您的Linux 内核必须至少为2.6.33,并且必须启用HUGETLBFS 内核选项。

The DPDK Linux Getting Started Guide has a section on the Use of Hugepages in the Linux Environment.

DPDK Linux 入门指南中有一个关于在 Linux 环境中使用大页的部分。

Once you have made the required changed make sure you have HUGE TLB support in the kernel with the following commands:

完成所需的更改后,请使用以下命令确保内核中具有巨大的 TLB 支持:

$ grep -i huge /boot/config-2.6.35-24-generic
CONFIG_HUGETLBFS=y
CONFIG_HUGETLB_PAGE=y

$ grep -i huge /proc/meminfo

HugePages_Total:      128
HugePages_Free:       128
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

The values in Total and Free may be different depending on your system.

Total 和 Free 中的值可能会有所不同,具体取决于您的系统。

You will need to edit the /etc/sysctl.conf file to setup the hugepages size:

您需要编辑 /etc/sysctl.conf 文件来设置大页大小:

$ sudo vi /etc/sysctl.conf
Add to the bottom of the file:
vm.nr_hugepages=256

You can configure the vm.nr_hugepages=256 as required. In some cases making it too small will effect the performance of pktgen or cause it to terminate on startup.

您可以根据需要配置vm.nr_hugepages=256。 在某些情况下,将其设置得太小会影响 pktgen 的性能或导致其在启动时终止。

You will also need to edit the /etc/fstab file to mount the hugepages at startup:

您还需要编辑 /etc/fstab 文件以在启动时挂载大页:

$ sudo vi /etc/fstab
Add to the bottom of the file:
huge /mnt/huge hugetlbfs defaults 0 0

$ sudo mkdir /mnt/huge
$ sudo chmod 777 /mnt/huge

You should also reboot your machine as the huge pages must be setup just after boot to make sure there is enough contiguous memory for the 2MB pages.

您还应该重新启动计算机,因为必须在启动后立即设置大页面,以确保有足够的连续内存用于 2MB 页面。

If you start an application that makes extensive use of hugepages, such as Eclipse or WR Workbench, before starting pktgen for the first time after reboot, pktgen may fail to load. In this case you should close the other application that is using hugepages.

如果在重新引导后首次启动 pktgen 之前启动大量使用大页的应用程序(例如 Eclipse 或 WR Workbench),pktgen 可能无法加载。 在这种情况下,您应该关闭其他正在使用大页面的应用程序。

BIOS settings

In the BIOS make sure that the HPET High Precision Event Timer is enabled. Also make sure hyper-threading is enabled. See the DPDK documentation on enabling additional BIOS functionality for more details.

在 BIOS 中,确保已启用 HPET 高精度事件计时器。 还要确保启用超线程。 有关更多详细信息,请参阅有关启用其他 BIOS 功能的 DPDK 文档。

Terminal display

The pktgen output display requires 132 columns and about 42 lines to display correctly. The author uses an xterm of 132x42, but you can also have a larger display and maybe a bit smaller. If you are displaying more then 4-6 ports then you will need a wider display.

pktgen 输出显示需要 132 列和大约 42 行才能正确显示。 作者使用的 xterm 为 132x42,但您也可以拥有更大的显示器,也可以更小一些。 如果您显示的端口超过 4-6 个,那么您将需要更宽的显示器。

Pktgen allows you to view a set ports via the page runtime command if they do not all fit on the screen at one time, see commands.

Pktgen 允许您通过页面运行时命令查看一组端口(如果它们一次不能全部显示在屏幕上),请参阅命令。

Pktgen uses VT100 control codes display its output screens, which means your terminal must support VT100.

Pktgen 使用 VT100 控制代码显示其输出屏幕,这意味着您的终端必须支持 VT100。

It is also best to set your terminal background to black when working with the default pktgen color scheme.

使用默认的 pktgen 配色方案时,最好将终端背景设置为黑色。

Get the source code

Pktgen requires the DPDK source code to build.

Pktgen 需要 DPDK 源代码来构建。

The main dpdk and pktgen git repositories are hosted on dpdk.org.

主要的 dpdk 和 pktgen git 存储库托管在 dpdk.org 上。

The dpdk code can be cloned as follows:

dpdk代码可以克隆如下:

git clone git://dpdk.org/dpdk
# or:
git clone http://dpdk.org/git/dpdk

The pktgen code can be cloned as follows:

pktgen 代码可以克隆如下:

git clone git://dpdk.org/apps/pktgen-dpdk
# or:
git clone http://dpdk.org/git/apps/pktgen-dpdk

In the instructions below the repository close directories are referred to as DPDKInstallDir and PktgenInstallDir.

在下面的说明中,存储库关闭目录称为 DPDKInstallDir 和 PktgenInstallDir。

You will also require the Linux kernel headers to allow DPDK to build its kernel modules. On Ubuntu you can install them as follows (where the version matches the kernel version):

您还需要 Linux 内核头文件以允许 DPDK 构建其内核模块。 在 Ubuntu 上,您可以按如下方式安装它们(其中版本与内核版本匹配):

$ sudo apt-get install linux-headers-3.5.0-32-generic

DPDK can also work with a libpcap driver which is sometimes useful for testing without a real NIC or for low speed packet capture. Install the libpcap development libs using your package manage. For example:

DPDK 还可以与 libpcap 驱动程序一起使用,该驱动程序有时对于没有真实 NIC 的测试或低速数据包捕获很有用。 使用包管理器安装 libpcap 开发库。 例如:

$ sudo apt-get install libpcap-dev

Build DPDK and Pktgen

Set up the environmental variables required by DPDK:

设置DPDK所需的环境变量:

export RTE_SDK=<DPDKInstallDir>
export RTE_TARGET=x86_64-native-linux-gcc
or
export RTE_TARGET=x86_64-native-linuxapp-gcc
# or use clang if you have it installed:
export RTE_TARGET=x86_64-native-linux-clang
or
export RTE_TARGET=x86_64-native-linuxapp-clang

Create the DPDK build tree:

$ cd $RTE_SDK
$ make install T=x86_64-native-linux-gcc
or
$ make install T=x86_64-native-linuxapp-gcc

This above command will create the x86_64-pktgen-linux-gcc directory in the top level of the $RTE_SDK directory. It will also build the basic DPDK libraries, kernel modules and build tree.

上述命令将在 $RTE_SDK 目录的顶层创建 x86_64-pktgen-linux-gcc 目录。 它还将构建基本的 DPDK 库、内核模块和构建树。

Pktgen can then be built as follows:

然后可以按如下方式构建 Pktgen:

$ cd <PktgenInstallDir>
$ make

Setting up your environment

In the PktgenInstallDir/tools level directory there is run.py script, which should be run once per boot with the -s option to setup the ports. The same configuration file is also used to run pktgen by removing the -s option.

在 PktgenInstallDir/tools 级别目录中有 run.py 脚本,该脚本应在每次启动时运行一次,并使用 -s 选项来设置端口。 通过删除 -s 选项,还可以使用相同的配置文件来运行 pktgen。

The run.py script will do the sudo to root internally, which means the sudo is not required.

run.py 脚本将在内部对 root 执行 sudo,这意味着不需要 sudo。

The script contains the commands required to set up the environment:

该脚本包含设置环境所需的命令:

$ cd <PktgenInstallDir>/tools
$ ./run.py -s default  # setup system using the cfg/default.cfg file

The run.py script is a python script and tries to configure the system to run a DPDK application. You will probably have to change the configuration files to match your system.

run.py 脚本是一个 python 脚本,尝试配置系统以运行 DPDK 应用程序。 您可能需要更改配置文件以匹配您的系统。

To run pktgen with the default.cfg configuration:

要使用 default.cfg 配置运行 pktgen:

$ cd <PktgenInstallDir>/tools
$ run.py default

The run.py command use python data files to configure setup and run pktgen. The configuration files are located in the PktgenInstallDir/cfg directory. These files allow for setup and running pktgen and can be configured to match you system or new configuration files can be created.

run.py 命令使用 python 数据文件来配置安装程序并运行 pktgen。 配置文件位于 PktgenInstallDir/cfg 目录中。 这些文件允许设置和运行 pktgen,并且可以进行配置以匹配您的系统,或者可以创建新的配置文件。

Here is the default.cfg file:

这是default.cfg 文件:

# Setup configuration
setup = {
 'devices': [
     '81:00.0 81:00.1 81:00.2 81:00.3',
     '85:00.0 85:00.1 85:00.2 85:00.3',
     '83:00.0'
     ],

 'opts': [
     '-b igb_uio'
     ]
 }

# Run command and options
run = {
 'dpdk': [
     '-l 1,1-5,10-13',
     '-n 4',
     '--proc-type auto',
     '--log-level 7',
     '--socket-mem 2048,2048',
     '--file-prefix pg'
     ],

 'blocklist': [
     #'-b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3',
     #'-b 85:00.0 -b 85:00.1 -b 85:00.2 -b 85:00.3',
     '-b 81:00.0 -b 81:00.1',
     '-b 85:00.0 -b 85:00.1',
     '-b 83:00.0'
     ],

 'pktgen': [
     '-T',
     '-P',
     '--crc-strip',
     '-m [2:3].0',
     '-m [4:5].1',
     '-m [10:11].2',
     '-m [12:13].3',
     ],

 'misc': [
     '-f themes/black-yellow.theme'
    ]
}

We have two sections one for setup and the other for running pktgen.

我们有两个部分,一个用于设置,另一个用于运行 pktgen。

The modprobe uio command, in the setup script, loads the UIO support module into the kernel as well as loafing the igb-uio.ko module.

设置脚本中的 modprobe uio 命令将 UIO 支持模块加载到内核中,并闲置 igb-uio.ko 模块。

The two echo commands, in the setup script, set up the huge pages for a two socket system. If you only have a single socket system then remove the second echo command. The last command in the script is used to display the hugepage setup.

设置脚本中的两个 echo 命令为两个套接字系统设置了大页面。 如果您只有一个套接字系统,则删除第二个 echo 命令。 脚本中的最后一个命令用于显示大页面设置。

You may also wish to edit your .bashrc.profile or .cshrc files to permanently add the environment variables that you set up above:

您可能还希望编辑 .bashrc、.profile 或 .cshrc 文件以永久添加上面设置的环境变量:

export RTE_SDK=<DPDKInstallDir>
export RTE_TARGET=x86_64-native-linux-gcc
or
export RTE_TARGET=x86_64-native-linux-appgcc

Running the application

Once the above steps have been completed and the pktgen application has been compiled you can run it using the commands shown in the Running Pktgen section.

完成上述步骤并编译 pktgen 应用程序后,您可以使用“运行 Pktgen”部分中显示的命令来运行它。