Getting statistics from NIC (Network Interface Card) in DPDK
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 how to get statistics from NIC (Network Interface Card) 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 NIC statistics in DPDK.
What are NIC Statistics?
NIC (Network Interface Card) maintains some statistics while transmitting/receiving the packets. These statistics are maintained by NIC inside its own hardware registers. DPDK framework provides special APIs to access these statistic values.
Below are some of the important statistics maintained by a particular NIC.
Receive Packets: Total packets received by the NIC.
Transmit Packets: Total packets transmitted by the NIC.
Receive Bytes: Total bytes received by the NIC.
Transmit Bytes: Total bytes transmitted by the NIC.
Receive Errors: Total number of erroneous received packets.
Transmit Errors: Total number of failed transmitted packets.
Missed Packets: Total of receive packets dropped by the NIC hardware because there are no available buffer (i.e. receive queues are full).
No Receive Memory Buffers Count: Total number of receive memory buffer allocation failures while NIC tries to receive the packet.
Writing DPDK application
Finally, we can write our packet processing DPDK application in C++. 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 ./getting-nic-statistics --lcores=0 -n 4 --
Congratulations! You have run a DPDK application which gets statistics from NIC and prints it every three seconds. The main thread of our DPDK application is running on core 0 and transmits a packet on a regular interval and gets the statistics from NIC every three second and prints it. All of this is being done without the involvement of Linux Kernel.
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 on a regular interval and gets statistics from NIC every three second and print it. We also discussed about the different kind of statistics which are maintained by NIC.
Feel free to write me in the comments if you are unable to perform the steps successfully, mentioned in this article.
Subscribe to my newsletter
Read articles from Muhammad Awais Khalid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Muhammad Awais Khalid
Muhammad Awais Khalid
I am a software engineer. During my career, I have developed high performance software solutions in multiple domains. I have expertise in: C/C++, Linux, Data Plane Development Kit (DPDK), VoIP (Voice Over IP) Lawful Interception Systems, Parallel Computing, GPU Computing