1278f9454SReshma Pattan.. BSD LICENSE 2278f9454SReshma Pattan Copyright(c) 2016 Intel Corporation. All rights reserved. 3278f9454SReshma Pattan All rights reserved. 4278f9454SReshma Pattan 5278f9454SReshma Pattan Redistribution and use in source and binary forms, with or without 6278f9454SReshma Pattan modification, are permitted provided that the following conditions 7278f9454SReshma Pattan are met: 8278f9454SReshma Pattan 9278f9454SReshma Pattan * Redistributions of source code must retain the above copyright 10278f9454SReshma Pattan notice, this list of conditions and the following disclaimer. 11278f9454SReshma Pattan * Redistributions in binary form must reproduce the above copyright 12278f9454SReshma Pattan notice, this list of conditions and the following disclaimer in 13278f9454SReshma Pattan the documentation and/or other materials provided with the 14278f9454SReshma Pattan distribution. 15278f9454SReshma Pattan * Neither the name of Intel Corporation nor the names of its 16278f9454SReshma Pattan contributors may be used to endorse or promote products derived 17278f9454SReshma Pattan from this software without specific prior written permission. 18278f9454SReshma Pattan 19278f9454SReshma Pattan THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20278f9454SReshma Pattan "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21278f9454SReshma Pattan LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22278f9454SReshma Pattan A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23278f9454SReshma Pattan OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24278f9454SReshma Pattan SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25278f9454SReshma Pattan LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26278f9454SReshma Pattan DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27278f9454SReshma Pattan THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28278f9454SReshma Pattan (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29278f9454SReshma Pattan OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30278f9454SReshma Pattan 31278f9454SReshma Pattan.. _pdump_library: 32278f9454SReshma Pattan 33278f9454SReshma PattanThe librte_pdump Library 34278f9454SReshma Pattan======================== 35278f9454SReshma Pattan 36278f9454SReshma PattanThe ``librte_pdump`` library provides a framework for packet capturing in DPDK. 37278f9454SReshma PattanThe library does the complete copy of the Rx and Tx mbufs to a new mempool and 38278f9454SReshma Pattanhence it slows down the performance of the applications, so it is recommended 39278f9454SReshma Pattanto use this library for debugging purposes. 40278f9454SReshma Pattan 41278f9454SReshma PattanThe library provides the following APIs to initialize the packet capture framework, to enable 42278f9454SReshma Pattanor disable the packet capture, and to uninitialize it: 43278f9454SReshma Pattan 44278f9454SReshma Pattan* ``rte_pdump_init()``: 45278f9454SReshma Pattan This API initializes the packet capture framework. 46278f9454SReshma Pattan 47278f9454SReshma Pattan* ``rte_pdump_enable()``: 48278f9454SReshma Pattan This API enables the packet capture on a given port and queue. 49278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 50278f9454SReshma Pattan 51278f9454SReshma Pattan* ``rte_pdump_enable_by_deviceid()``: 52278f9454SReshma Pattan This API enables the packet capture on a given device id (``vdev name or pci address``) and queue. 53278f9454SReshma Pattan Note: The filter option in the API is a place holder for future enhancements. 54278f9454SReshma Pattan 55278f9454SReshma Pattan* ``rte_pdump_disable()``: 56278f9454SReshma Pattan This API disables the packet capture on a given port and queue. 57278f9454SReshma Pattan 58278f9454SReshma Pattan* ``rte_pdump_disable_by_deviceid()``: 59278f9454SReshma Pattan This API disables the packet capture on a given device id (``vdev name or pci address``) and queue. 60278f9454SReshma Pattan 61278f9454SReshma Pattan* ``rte_pdump_uninit()``: 62278f9454SReshma Pattan This API uninitializes the packet capture framework. 63278f9454SReshma Pattan 64278f9454SReshma Pattan* ``rte_pdump_set_socket_dir()``: 65278f9454SReshma Pattan This API sets the server and client socket paths. 66278f9454SReshma Pattan Note: This API is not thread-safe. 67278f9454SReshma Pattan 68278f9454SReshma Pattan 69278f9454SReshma PattanOperation 70278f9454SReshma Pattan--------- 71278f9454SReshma Pattan 72278f9454SReshma PattanThe ``librte_pdump`` library works on a client/server model. The server is responsible for enabling or 73278f9454SReshma Pattandisabling the packet capture and the clients are responsible for requesting the enabling or disabling of 74278f9454SReshma Pattanthe packet capture. 75278f9454SReshma Pattan 76278f9454SReshma PattanThe packet capture framework, as part of its initialization, creates the pthread and the server socket in 77278f9454SReshma Pattanthe pthread. The application that calls the framework initialization will have the server socket created, 78*446d42b7SReshma Pattaneither under the path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for 79*446d42b7SReshma Pattanroot user or ``~/.dpdk`` for non root user. 80278f9454SReshma Pattan 81278f9454SReshma PattanApplications that request enabling or disabling of the packet capture will have the client socket created either under 82*446d42b7SReshma Pattanthe path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for root user or 83*446d42b7SReshma Pattan``~/.dpdk`` for not root user to send the requests to the server. The server socket will listen for client requests for 84*446d42b7SReshma Pattanenabling or disabling the packet capture. 85278f9454SReshma Pattan 86278f9454SReshma Pattan 87278f9454SReshma PattanImplementation Details 88278f9454SReshma Pattan---------------------- 89278f9454SReshma Pattan 90278f9454SReshma PattanThe library API ``rte_pdump_init()``, initializes the packet capture framework by creating the pthread and the server 91278f9454SReshma Pattansocket. The server socket in the pthread context will be listening to the client requests to enable or disable the 92278f9454SReshma Pattanpacket capture. 93278f9454SReshma Pattan 94278f9454SReshma PattanThe library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture. 95278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump enable" request and sends 96278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and enable the packet capture 97278f9454SReshma Pattanby registering the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. 98278f9454SReshma PattanThen the server will mirror the packets to the new mempool and enqueue them to the rte_ring that clients have passed 99278f9454SReshma Pattanto these APIs. The server also sends the response back to the client about the status of the request that was processed. 100278f9454SReshma PattanAfter the response is received from the server, the client socket is closed. 101278f9454SReshma Pattan 102278f9454SReshma PattanThe library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture. 103278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump disable" request and sends 104278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and disable the packet 105278f9454SReshma Pattancapture by removing the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. The server 106278f9454SReshma Pattanalso sends the response back to the client about the status of the request that was processed. After the response is 107278f9454SReshma Pattanreceived from the server, the client socket is closed. 108278f9454SReshma Pattan 109278f9454SReshma PattanThe library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by closing the pthread and the 110278f9454SReshma Pattanserver socket. 111278f9454SReshma Pattan 112278f9454SReshma PattanThe library API ``rte_pdump_set_socket_dir()``, sets the given path as either server socket path 113278f9454SReshma Pattanor client socket path based on the ``type`` argument of the API. 114*446d42b7SReshma PattanIf the given path is ``NULL``, default path will be selected, i.e. either ``/var/run/.dpdk`` for root user or ``~/.dpdk`` 115278f9454SReshma Pattanfor non root user. Clients also need to call this API to set their server socket path if the server socket 116278f9454SReshma Pattanpath is different from default path. 117278f9454SReshma Pattan 118278f9454SReshma Pattan 119278f9454SReshma PattanUse Case: Packet Capturing 120278f9454SReshma Pattan-------------------------- 121278f9454SReshma Pattan 122278f9454SReshma PattanThe DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK. 123278f9454SReshma PattanUsers can use this as an example to develop their own packet capturing tools. 124