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 14*23516151SReshma PattanThe library uses a generic multi process channel to facilitate communication 15*23516151SReshma Pattanbetween primary and secondary process for enabling/disabling packet capture on 16*23516151SReshma Pattanports. 17*23516151SReshma Pattan 18278f9454SReshma PattanThe library provides the following APIs to initialize the packet capture framework, to enable 19*23516151SReshma Pattanor disable the packet capture, and to uninitialize it. 20278f9454SReshma Pattan 21278f9454SReshma Pattan* ``rte_pdump_init()``: 22278f9454SReshma Pattan This API initializes the packet capture framework. 23278f9454SReshma Pattan 24278f9454SReshma Pattan* ``rte_pdump_enable()``: 25278f9454SReshma Pattan This API enables the packet capture on a given port and queue. 26278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 27278f9454SReshma Pattan 28278f9454SReshma Pattan* ``rte_pdump_enable_by_deviceid()``: 29278f9454SReshma Pattan This API enables the packet capture on a given device id (``vdev name or pci address``) and queue. 30278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 31278f9454SReshma Pattan 32278f9454SReshma Pattan* ``rte_pdump_disable()``: 33278f9454SReshma Pattan This API disables the packet capture on a given port and queue. 34278f9454SReshma Pattan 35278f9454SReshma Pattan* ``rte_pdump_disable_by_deviceid()``: 36278f9454SReshma Pattan This API disables the packet capture on a given device id (``vdev name or pci address``) and queue. 37278f9454SReshma Pattan 38278f9454SReshma Pattan* ``rte_pdump_uninit()``: 39278f9454SReshma Pattan This API uninitializes the packet capture framework. 40278f9454SReshma Pattan 41278f9454SReshma Pattan 42278f9454SReshma PattanOperation 43278f9454SReshma Pattan--------- 44278f9454SReshma Pattan 45*23516151SReshma PattanThe primary process using ``librte_pdump`` is responsible for initializing the packet 46*23516151SReshma Pattancapture framework. The packet capture framework, as part of its initialization, creates the 47*23516151SReshma Pattanmulti process channel to facilitate communication with secondary process, so the 48*23516151SReshma Pattansecondary process ``app/pdump`` tool is responsible for enabling and disabling the packet capture on ports. 49278f9454SReshma Pattan 50278f9454SReshma PattanImplementation Details 51278f9454SReshma Pattan---------------------- 52278f9454SReshma Pattan 53*23516151SReshma PattanThe library API ``rte_pdump_init()``, initializes the packet capture framework by creating the multi process 54*23516151SReshma Pattanchannel using ``rte_mp_action_register()`` API. The primary process will listen to secondary process requests 55*23516151SReshma Pattanto enable or disable the packet capture over the multi process channel. 56278f9454SReshma Pattan 57278f9454SReshma PattanThe library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture. 58*23516151SReshma PattanFor the calls to these APIs from secondary process, the library creates the "pdump enable" request and sends 59*23516151SReshma Pattanthe request to the primary process over the multi process channel. The primary process takes this request 60*23516151SReshma Pattanand enables the packet capture by registering the Ethernet RX and TX callbacks for the given port or device_id 61*23516151SReshma Pattanand queue combinations. Then the primary process will mirror the packets to the new mempool and enqueue them to 62*23516151SReshma Pattanthe rte_ring that secondary process have passed to these APIs. 63278f9454SReshma Pattan 64278f9454SReshma PattanThe library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture. 65*23516151SReshma PattanFor the calls to these APIs from secondary process, the library creates the "pdump disable" request and sends 66*23516151SReshma Pattanthe request to the primary process over the multi process channel. The primary process takes this request and 67*23516151SReshma Pattandisables the packet capture by removing the Ethernet RX and TX callbacks for the given port or device_id and 68*23516151SReshma Pattanqueue combinations. 69278f9454SReshma Pattan 70e9436f54STiwei BieThe library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by calling ``rte_mp_action_unregister()`` 71e9436f54STiwei Biefunction. 72278f9454SReshma Pattan 73278f9454SReshma Pattan 74278f9454SReshma PattanUse Case: Packet Capturing 75278f9454SReshma Pattan-------------------------- 76278f9454SReshma Pattan 77278f9454SReshma PattanThe DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK. 78278f9454SReshma PattanUsers can use this as an example to develop their own packet capturing tools. 79