This article describes the Data Plane Development Kit* (DPDK*) sample applications.
The DPDK sample applications are small standalone applications which demonstrate various features of DPDK. They can be considered a cookbook of DPDK features. A user interested in getting started with DPDK can take the applications, try out the features, and then extend them to fit their needs.
The DPDK Sample Applications
Table 1 shows a list of some of the sample applications that are available in the examples directory of DPDK:
|Command Line||Packet Ordering|
|Ethtool||Precision Time Protocol (PTP) Client|
|Exception Path||Quality of Service (QoS) Metering|
|Hello World||QoS Scheduler|
|Internet Protocol (IP) Fragmentation||Quota and Watermark|
|IP Pipeline||RX/TX Callbacks|
|IP Reassembly||Server Node EFD|
|IPsec Security Gateway||Basic Forwarding/Skeleton App|
|IPv4 Multicast||Tunnel End Point (TEP) Termination|
|Kernel NIC Interface||Timer|
|Network Layer 2 Forwarding + variants||Vhost|
|Network Layer 3 Forwarding + variants||Vhost Xen|
|Link Status Interrupt||VMDQ Forwarding|
|Load Balancer||VMDQ and DCB Forwarding|
|Multi-process||VM Power Management|
Table 1. Some of the DPDK sample applications.
These examples range from simple to reasonably complex but most are designed to demonstrate one particular feature of DPDK. Some of the more interesting examples are highlighted below.
- Hello World: As with most introductions to a programming framework a good place to start is with the Hello World application. The Hello World example sets up the DPDK Environment Abstraction Layer (EAL), and prints a simple "Hello World" message to each of the DPDK-enabled cores. This application doesn’t do any packet formatting but it is a good way to test whether the DPDK environment is compiled and set up properly.
- Basic Forwarding/Skeleton application: The basic forwarding/skeleton contains the minimum amount of code required to enable basic packet forwarding with DPDK. This will allow the user to test and see if their network interfaces are working with DPDK.
- Network Layer 2 Forwarding: The Network Layer 2 forwarding, or L2fwd application, does forwarding based on Ethernet MAC addresses like a simple switch.
- Network Layer 3 Forwarding: The Network Layer 3 forwarding, or L3fwd application, does forwarding based on Internet protocols, IPv4, or IPv6 like a simple router.
- Packet Distributor: The packet distributor demonstrates how to distribute packets arriving on an Rx port to different cores for processing and transmission.
- Multi process application: The multi process application shows how two DPDK processes can work together using queues and memory pools to share information.
- RX/TX Callbacks application: The RX/TX Callbacks sample application is a packet forwarding application that demonstrates the use of user-defined callbacks on received and transmitted packets. The application calculates the latency of the packet between RX (packet arrival) and TX (packet transmission) by adding callbacks to the RX and TX packet processing functions.
- IPSec Security Gateway: The IPSec security gateway application is a minimal example of something closer to a real-world usage example. This is also a good example of an application using the DPDK Cryptodev* framework.
- Precision Time Protocol (PTP) client: The PTP client is another minimal implementation of a real-world application. In this case the application is a PTP client that communicates with a PTP primary clock to synchronize time on a network interface card (NIC) using the IEEE1588 protocol.
- Quality of Service (QoS) Scheduler: The QoS Scheduler application demonstrates the use of DPDK to provide QoS scheduling.
There are many more examples which are documented online at dpdk.org. Each of the documented sample applications show how to compile, configure, and run the application, as well as explaining the main code behind the functionality.
In the next section, we will look at the Network Layer 3 forwarding (L3fwd) sample application in more detail.
The Network Layer 3 Forwarding Sample Application
The Network Layer 3 forwarding, or L3fwd application, demonstrates packet forwarding based on Internet protocol, IPv4, or IPv6 like a simple router. The L3fwd application has two modes of operation, longest prefix match (LPM) and exact match (EM), which demonstrate the use of the DPDK LPM and Hash libraries.
Figure 1 shows a block diagram of the L3fwd application set up to forward packets from a traffic generator using two ports.
Figure 1. The L3fwd application set up to forward packets from a traffic generator.
Longest prefix match (LPM) is a table search method, typically used to find the best route match in IP forwarding applications. The L3fwd application statically configures a set of rules and loads them into an LPM object at initialization time. By default, L3fwd has a statically defined destination LPM table with eight routes, as shown in Table 2.
Table 2. Default LPM routes in L3fwd.
L3fwd uses the IPv4 destination address of the packet to identify its next hop; i.e., the output port ID from the LPM table. It can also route based on IPv6 addresses (from DPDK 17.05).
Exact match (EM) is hash-based table search method to find the best route match in IP forwarding applications. In EM lookup, the search key is represented by a five-tuple value of Source IP address, Destination IP address, Source Port, Destination Port and Protocol. The set of flows used by the application is statically configured and loaded into the hash object at initialization time. By default, L3fwd has a statically defined destination EM table with four routes, as shown in Table 3.
Table 3. Default EM routes in L3fwd.
The next hop, i.e., the output interface for the packet is identified from the EM table entry. EM-based forwarding supports IPv4 and IPv6.
Building the Application
The L3fwd application can be built as shown below. The environment variables used are described in the DPDK Getting Started guides.
$ export RTE_SDK=/path/to/rte_sdk $ export RTE_TARGET=x86_64-native-linuxapp-gcc $ cd $RTE_SDK/examples/l3fwd $ make clean $ make
Running the Application
The command line for the L3fwd application has the following options:
$./build/l3fwd [EAL options] -- -p PORTMASK [-P] [-E] [-L] --config(port,queue,lcore)[,(port,queue,lcore)] [--eth-dest=X,MM:MM:MM:MM:MM:MM] [--enable-jumbo [--max-pkt-len PKTLEN]] [--no-numa] [--hash-entry-num 0x0n] [--ipv6] [--parse-ptype]
This comprises the EAL parameters, which are common to all DPDK applications, and application-specific parameters.
The L3fwd app uses the LPM as the default lookup method. The lookup method can be changed with a command-line option at runtime:
-E: selects the Exact Match lookup method.
-L: selects the LPM lookup method.
Here are some examples of running the L3fwd application.
#LPM $./build/l3fwd -l 1,2 -n 4 -- -p 0x3 -L --config="(0,0,1),(1,0,2)" #EM $./build/l3fwd -l 1,2 -n 4 -- -p 0x3 -E --config="(0,0,1),(1,0,2)" \ --parse-ptype
This article describes an overview of a subset of the DPDK sample applications and then goes into more detail on the L3fwd sample application.
About the Author
Bernard Iremonger is a network software engineer with Intel Corporation. His work is primarily focused on the development of the data plane libraries for DPDK. His contributions include conversion of the DPDK documentation to use the Sphinx* documentation tool, enhancements to the poll mode drivers (PMDs) to support port hot plug and live migration of virtual machines (VMs) with single root IO virtualization (SRIOV) virtual functions (VFs), API extensions to the ixgbe, and i40e PMDs for control of the VFs from the physical function (PF).