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.
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.
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.
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.