15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2016 Intel Corporation. 3278f9454SReshma Pattan 410f726efSStephen HemmingerPacket Capture Library 510f726efSStephen Hemminger====================== 6278f9454SReshma Pattan 710f726efSStephen HemmingerThe DPDK ``pdump`` library provides a framework for packet capturing in DPDK. 8278f9454SReshma PattanThe library does the complete copy of the Rx and Tx mbufs to a new mempool and 9278f9454SReshma Pattanhence it slows down the performance of the applications, so it is recommended 10278f9454SReshma Pattanto use this library for debugging purposes. 11278f9454SReshma Pattan 1223516151SReshma PattanThe library uses a generic multi process channel to facilitate communication 1323516151SReshma Pattanbetween primary and secondary process for enabling/disabling packet capture on 1423516151SReshma Pattanports. 1523516151SReshma Pattan 16278f9454SReshma PattanThe library provides the following APIs to initialize the packet capture framework, to enable 1723516151SReshma Pattanor disable the packet capture, and to uninitialize it. 18278f9454SReshma Pattan 19278f9454SReshma Pattan* ``rte_pdump_init()``: 20278f9454SReshma Pattan This API initializes the packet capture framework. 21278f9454SReshma Pattan 22278f9454SReshma Pattan* ``rte_pdump_enable()``: 23278f9454SReshma Pattan This API enables the packet capture on a given port and queue. 2410f726efSStephen Hemminger 2510f726efSStephen Hemminger* ``rte_pdump_enable_bpf()`` 2610f726efSStephen Hemminger This API enables the packet capture on a given port and queue. 2710f726efSStephen Hemminger It also allows setting an optional filter using DPDK BPF interpreter 2810f726efSStephen Hemminger and setting the captured packet length. 29278f9454SReshma Pattan 30278f9454SReshma Pattan* ``rte_pdump_enable_by_deviceid()``: 31278f9454SReshma Pattan This API enables the packet capture on a given device id (``vdev name or pci address``) and queue. 3210f726efSStephen Hemminger 3310f726efSStephen Hemminger* ``rte_pdump_enable_bpf_by_deviceid()`` 3410f726efSStephen Hemminger This API enables the packet capture on a given device id (``vdev name or pci address``) and queue. 3510f726efSStephen Hemminger It also allows setting an optional filter using DPDK BPF interpreter 3610f726efSStephen Hemminger and setting the captured packet length. 37278f9454SReshma Pattan 38278f9454SReshma Pattan* ``rte_pdump_disable()``: 39278f9454SReshma Pattan This API disables the packet capture on a given port and queue. 40278f9454SReshma Pattan 41278f9454SReshma Pattan* ``rte_pdump_disable_by_deviceid()``: 42278f9454SReshma Pattan This API disables the packet capture on a given device id (``vdev name or pci address``) and queue. 43278f9454SReshma Pattan 44278f9454SReshma Pattan* ``rte_pdump_uninit()``: 45278f9454SReshma Pattan This API uninitializes the packet capture framework. 46278f9454SReshma Pattan 47278f9454SReshma Pattan 48278f9454SReshma PattanOperation 49278f9454SReshma Pattan--------- 50278f9454SReshma Pattan 5123516151SReshma PattanThe primary process using ``librte_pdump`` is responsible for initializing the packet 5223516151SReshma Pattancapture framework. The packet capture framework, as part of its initialization, creates the 5323516151SReshma Pattanmulti process channel to facilitate communication with secondary process, so the 5423516151SReshma Pattansecondary process ``app/pdump`` tool is responsible for enabling and disabling the packet capture on ports. 55278f9454SReshma Pattan 56278f9454SReshma PattanImplementation Details 57278f9454SReshma Pattan---------------------- 58278f9454SReshma Pattan 5923516151SReshma PattanThe library API ``rte_pdump_init()``, initializes the packet capture framework by creating the multi process 6023516151SReshma Pattanchannel using ``rte_mp_action_register()`` API. The primary process will listen to secondary process requests 6123516151SReshma Pattanto enable or disable the packet capture over the multi process channel. 62278f9454SReshma Pattan 63278f9454SReshma PattanThe library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture. 6423516151SReshma PattanFor the calls to these APIs from secondary process, the library creates the "pdump enable" request and sends 6523516151SReshma Pattanthe request to the primary process over the multi process channel. The primary process takes this request 6623516151SReshma Pattanand enables the packet capture by registering the Ethernet RX and TX callbacks for the given port or device_id 6723516151SReshma Pattanand queue combinations. Then the primary process will mirror the packets to the new mempool and enqueue them to 6823516151SReshma Pattanthe rte_ring that secondary process have passed to these APIs. 69278f9454SReshma Pattan 7010f726efSStephen HemmingerThe packet ring supports one of two formats. 7110f726efSStephen HemmingerThe default format enqueues copies of the original packets into the rte_ring. 7210f726efSStephen HemmingerIf the ``RTE_PDUMP_FLAG_PCAPNG`` is set, the mbuf data is extended 7310f726efSStephen Hemmingerwith header and trailer to match the format of Pcapng enhanced packet block. 7410f726efSStephen HemmingerThe enhanced packet block has meta-data such as the timestamp, port and queue 7510f726efSStephen Hemmingerthe packet was captured on. 7610f726efSStephen HemmingerIt is up to the application consuming the packets from the ring 7710f726efSStephen Hemmingerto select the format desired. 7810f726efSStephen Hemminger 79278f9454SReshma PattanThe library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture. 8023516151SReshma PattanFor the calls to these APIs from secondary process, the library creates the "pdump disable" request and sends 8123516151SReshma Pattanthe request to the primary process over the multi process channel. The primary process takes this request and 8223516151SReshma Pattandisables the packet capture by removing the Ethernet RX and TX callbacks for the given port or device_id and 8323516151SReshma Pattanqueue combinations. 84278f9454SReshma Pattan 85e9436f54STiwei BieThe library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by calling ``rte_mp_action_unregister()`` 86e9436f54STiwei Biefunction. 87278f9454SReshma Pattan 88278f9454SReshma Pattan 89278f9454SReshma PattanUse Case: Packet Capturing 90278f9454SReshma Pattan-------------------------- 91278f9454SReshma Pattan 92*cbb44143SStephen HemmingerThe DPDK ``app/dpdk-dumpcap`` utility uses this library 93*cbb44143SStephen Hemmingerto capture packets in DPDK. 94