15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2016 Intel Corporation. 3278f9454SReshma Pattan 4278f9454SReshma Pattan.. _pdump_library: 5278f9454SReshma Pattan 6278f9454SReshma PattanThe librte_pdump Library 7278f9454SReshma Pattan======================== 8278f9454SReshma Pattan 9278f9454SReshma PattanThe ``librte_pdump`` library provides a framework for packet capturing in DPDK. 10278f9454SReshma PattanThe library does the complete copy of the Rx and Tx mbufs to a new mempool and 11278f9454SReshma Pattanhence it slows down the performance of the applications, so it is recommended 12278f9454SReshma Pattanto use this library for debugging purposes. 13278f9454SReshma Pattan 14278f9454SReshma PattanThe library provides the following APIs to initialize the packet capture framework, to enable 15278f9454SReshma Pattanor disable the packet capture, and to uninitialize it: 16278f9454SReshma Pattan 17278f9454SReshma Pattan* ``rte_pdump_init()``: 18278f9454SReshma Pattan This API initializes the packet capture framework. 19278f9454SReshma Pattan 20278f9454SReshma Pattan* ``rte_pdump_enable()``: 21278f9454SReshma Pattan This API enables the packet capture on a given port and queue. 22278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 23278f9454SReshma Pattan 24278f9454SReshma Pattan* ``rte_pdump_enable_by_deviceid()``: 25278f9454SReshma Pattan This API enables the packet capture on a given device id (``vdev name or pci address``) and queue. 26278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 27278f9454SReshma Pattan 28278f9454SReshma Pattan* ``rte_pdump_disable()``: 29278f9454SReshma Pattan This API disables the packet capture on a given port and queue. 30278f9454SReshma Pattan 31278f9454SReshma Pattan* ``rte_pdump_disable_by_deviceid()``: 32278f9454SReshma Pattan This API disables the packet capture on a given device id (``vdev name or pci address``) and queue. 33278f9454SReshma Pattan 34278f9454SReshma Pattan* ``rte_pdump_uninit()``: 35278f9454SReshma Pattan This API uninitializes the packet capture framework. 36278f9454SReshma Pattan 37278f9454SReshma Pattan 38278f9454SReshma PattanOperation 39278f9454SReshma Pattan--------- 40278f9454SReshma Pattan 41278f9454SReshma PattanThe ``librte_pdump`` library works on a client/server model. The server is responsible for enabling or 42278f9454SReshma Pattandisabling the packet capture and the clients are responsible for requesting the enabling or disabling of 43278f9454SReshma Pattanthe packet capture. 44278f9454SReshma Pattan 45278f9454SReshma PattanThe packet capture framework, as part of its initialization, creates the pthread and the server socket in 46278f9454SReshma Pattanthe pthread. The application that calls the framework initialization will have the server socket created, 47446d42b7SReshma Pattaneither under the path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for 48446d42b7SReshma Pattanroot user or ``~/.dpdk`` for non root user. 49278f9454SReshma Pattan 50278f9454SReshma PattanApplications that request enabling or disabling of the packet capture will have the client socket created either under 51446d42b7SReshma Pattanthe path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for root user or 52446d42b7SReshma Pattan``~/.dpdk`` for not root user to send the requests to the server. The server socket will listen for client requests for 53446d42b7SReshma Pattanenabling or disabling the packet capture. 54278f9454SReshma Pattan 55278f9454SReshma Pattan 56278f9454SReshma PattanImplementation Details 57278f9454SReshma Pattan---------------------- 58278f9454SReshma Pattan 59*e9436f54STiwei BieThe library API ``rte_pdump_init()``, initializes the packet capture framework by creating the pdump server by calling 60*e9436f54STiwei Bie``rte_mp_action_register()`` function. The server will listen to the client requests to enable or disable the 61278f9454SReshma Pattanpacket capture. 62278f9454SReshma Pattan 63278f9454SReshma PattanThe library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture. 64278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump enable" request and sends 65278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and enable the packet capture 66278f9454SReshma Pattanby registering the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. 67278f9454SReshma PattanThen the server will mirror the packets to the new mempool and enqueue them to the rte_ring that clients have passed 68278f9454SReshma Pattanto these APIs. The server also sends the response back to the client about the status of the request that was processed. 69278f9454SReshma PattanAfter the response is received from the server, the client socket is closed. 70278f9454SReshma Pattan 71278f9454SReshma PattanThe library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture. 72278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump disable" request and sends 73278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and disable the packet 74278f9454SReshma Pattancapture by removing the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. The server 75278f9454SReshma Pattanalso sends the response back to the client about the status of the request that was processed. After the response is 76278f9454SReshma Pattanreceived from the server, the client socket is closed. 77278f9454SReshma Pattan 78*e9436f54STiwei BieThe library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by calling ``rte_mp_action_unregister()`` 79*e9436f54STiwei Biefunction. 80278f9454SReshma Pattan 81278f9454SReshma Pattan 82278f9454SReshma PattanUse Case: Packet Capturing 83278f9454SReshma Pattan-------------------------- 84278f9454SReshma Pattan 85278f9454SReshma PattanThe DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK. 86278f9454SReshma PattanUsers can use this as an example to develop their own packet capturing tools. 87