Learning DPDK : L2 forwarding app

This application is called l2fwd and can be found in examples folder of DPDK distribution.

The idea behind this sample application is to capture traffic on one port and after modifying its source and destination MAC addresses send it out adjacent port. Each core is designated to receive traffic on the only one port.


The following DPDK API groups used in the app could be identified according to its purpose:

  • Global initialization
  • Port (device) initialization
  • Start threads
  • RX/TX and modify the packets

It has to be noted that no RX/TX operations could be performed on the port before it is initialized.

Global initialization

First of all initialization of the whole library has to be requested using rte_eal_init provided with command line parameters, where user can specify number of CPU cores to be used and other requirements.

Secondly memory pools and port queues have to be setup. TX and RX pools are created using rte_mempool_create that is configured with buffer size, ring depth, cache size and optional NUMA socket parameter.

Port initialization

RX and TX queues are configured using rte_eth_rx_queue_setup and rte_eth_tx_queue_setup respectfully.

RX queue is provided with the pointer to an appropriate memory pool to get buffers for the received packets and a depth (number of RX) descriptors is chosen. Both queues are configured with ring threshold registers.

Thirdly DPDK enabled ports, called devices, are enumerated by probing over PCI bus using rte_eal_pci_probe. As a result rte_eth_dev_count returns the number of discovered devices. Ports are configured using rte_eth_dev_configure and started using rte_eth_dev_start.

Start threads

The infinite loop responsible for forwarding traffic is started using rte_eal_remote_launch on every slave core but master that is responsible for gathering statistics.

RX/TX and modify the packets

Packets are captured not individually but in groups, called bursts, using rte_eth_rx_burst. Those packets are modified and combined in other bursts waiting for transmission.

As soon as a TX burst of packets is full it is sent out of the port using rte_eth_tx_burst.

Note that releasing packet buffers is not required after send while unsent packets have to be released to a memory pool.


4 thoughts on “Learning DPDK : L2 forwarding app

  1. Perhaps the example code has been updated since this blog post. I couldn’t find a call to rte_eal_pci_probe() or rte_eth_dev_count() in main.c.


    • Sorry, rte_eth_dev_count() is in main.c, but rte_eal_pci_probe() is not.

      Also rte_eal_remote_launch() appears to be replaced with rte_eal_mp_remote_launch().


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s