Concept of Offloading in DPDK - IPv4 Checksum Offloading
Introduction
In this article, I have explained about a basic DPDK application which reads the packets from NIC interface. In this article we will learn about the concept of offloading in DPDK. If you are passionate about fast packet processing using DPDK then this article is for you.
Setting up DPDK environment
The DPDK environment setup includes binding the NIC to the specific kernel modules to access them directly and setting up huge pages. All of this is explained in detail in the last article. Kindly go through it in case you need to setup your DPDK environment.
Before we write our application we need to learn about concept of offloading in DPDK.
What is Offloading in DPDK
Offloading in DPDK means transferring certain responsibilities of a DPDK application to NIC hardware i.e. instead of doing a certain task in application, we can ask NIC to do it inside its hardware while a packet is being received or transmitted. In this way we can save CPU resources. Offloading makes our DPDK application faster because of the fact that we transfer certain tasks to NIC instead of doing it in the software (DPDK application).
There are two types of offloading:
Transmit Offloading: These are the tasks performed by the NIC while transmitting the packet. The task is performed on each packet before it is transmitted on the physical layer.
Some of the examples are:
IPv4 Checksum Offloading: NIC will compute the IPv4 checksum before packet transmission.
IPv6 Checksum Offloading: NIC will compute the IPv6 checksum before packet transmission.
Receive Offloading: These are the tasks performed by the NIC after it receives the packet and before it delivers this packet to DPDK application. The task is performed on each received packet.
Some of the examples are:
IPv4 Checksum Offloading: NIC will check the IPv4 checksum of the packet after it is received. It will set the flags in the packet if the checksum is good, bad or unknown. DPDK application can read these flags.
Timestamp Offloading: NIC will timestamp the received packets. DPDK application will be able to read the time stamps.
VLAN Strip Offloading: NIC will strip/remove the VLAN header from the received packet before the DPDK application reads this packet.
There are other examples of offloading as well. We will discuss them in later articles.
Writing DPDK application
Finally, we can write our IPv4 checksum offloading DPDK application in C++. In this DPDK application, we will implement TX IPv4 checksum offloading i.e. our DPDK application will not be computing the IPv4 checksum of a packet which is to be transmitted. NIC will compute it before the actual transmission occurs.
The written DPDK application is present at: github.com/awaiskhalidawan/dpdk-tutorials
Below are the steps to build and run the application:
git clone https://github.com/awaiskhalidawan/dpdk-tutorials.git
cd dpdk-tutorials/
mkdir build
cd build
cmake ..
make
The application binaries will be generated in dpdk-tutorials/bin folder after the successful execution of above steps.
To finally run the DPDK application:
cd dpdk-tutorials/bin
sudo ./ipv4-checksum-calculation-offloading-to-nic --lcores=0 -n 4 --
Congratulations! You have run a DPDK application which implements a TX IPv4 checksum offloading. The main thread of our DPDK application is running on core 0 and transmits a packet on a regular interval. NIC calculates the IPv4 checksum before actually transmitting the packet over the physical layer. In this way we save our computational resources by not doing it software (DPDK application).
There is an extensive explanations of DPDK APIs as well as the code flow in the code of this application. Don't forget to go through the code while you run this DPDK application.
Note: A DPDK application must be run with sudo for now as DPDK abstraction layer requires sudo privileges. I will write a detailed article later on about how to run DPDK applications without sudo privileges.
Summary
In this article, a simple DPDK application is written and executed. This application sends a packet and offloads the IPv4 checksum calculation to NIC. We also discussed about offloading in DPDK and its different types.
Feel free to write me in the comments if you are unable to perform the steps successfully, mentioned in this article.