xref: /dpdk/doc/guides/prog_guide/pdump_lib.rst (revision 278f945402c55497c614de3f46b1a7660782eaf9)
1*278f9454SReshma Pattan..  BSD LICENSE
2*278f9454SReshma Pattan    Copyright(c) 2016 Intel Corporation. All rights reserved.
3*278f9454SReshma Pattan    All rights reserved.
4*278f9454SReshma Pattan
5*278f9454SReshma Pattan    Redistribution and use in source and binary forms, with or without
6*278f9454SReshma Pattan    modification, are permitted provided that the following conditions
7*278f9454SReshma Pattan    are met:
8*278f9454SReshma Pattan
9*278f9454SReshma Pattan    * Redistributions of source code must retain the above copyright
10*278f9454SReshma Pattan    notice, this list of conditions and the following disclaimer.
11*278f9454SReshma Pattan    * Redistributions in binary form must reproduce the above copyright
12*278f9454SReshma Pattan    notice, this list of conditions and the following disclaimer in
13*278f9454SReshma Pattan    the documentation and/or other materials provided with the
14*278f9454SReshma Pattan    distribution.
15*278f9454SReshma Pattan    * Neither the name of Intel Corporation nor the names of its
16*278f9454SReshma Pattan    contributors may be used to endorse or promote products derived
17*278f9454SReshma Pattan    from this software without specific prior written permission.
18*278f9454SReshma Pattan
19*278f9454SReshma Pattan    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*278f9454SReshma Pattan    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*278f9454SReshma Pattan    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*278f9454SReshma Pattan    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*278f9454SReshma Pattan    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*278f9454SReshma Pattan    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*278f9454SReshma Pattan    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*278f9454SReshma Pattan    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*278f9454SReshma Pattan    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*278f9454SReshma Pattan    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*278f9454SReshma Pattan    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*278f9454SReshma Pattan
31*278f9454SReshma Pattan.. _pdump_library:
32*278f9454SReshma Pattan
33*278f9454SReshma PattanThe librte_pdump Library
34*278f9454SReshma Pattan========================
35*278f9454SReshma Pattan
36*278f9454SReshma PattanThe ``librte_pdump`` library provides a framework for packet capturing in DPDK.
37*278f9454SReshma PattanThe library does the complete copy of the Rx and Tx mbufs to a new mempool and
38*278f9454SReshma Pattanhence it slows down the performance of the applications, so it is recommended
39*278f9454SReshma Pattanto use this library for debugging purposes.
40*278f9454SReshma Pattan
41*278f9454SReshma PattanThe library provides the following APIs to initialize the packet capture framework, to enable
42*278f9454SReshma Pattanor disable the packet capture, and to uninitialize it:
43*278f9454SReshma Pattan
44*278f9454SReshma Pattan* ``rte_pdump_init()``:
45*278f9454SReshma Pattan  This API initializes the packet capture framework.
46*278f9454SReshma Pattan
47*278f9454SReshma Pattan* ``rte_pdump_enable()``:
48*278f9454SReshma Pattan  This API enables the packet capture on a given port and queue.
49*278f9454SReshma Pattan  Note: The filter option in the API is a place holder for future enhancements.
50*278f9454SReshma Pattan
51*278f9454SReshma Pattan* ``rte_pdump_enable_by_deviceid()``:
52*278f9454SReshma Pattan  This API enables the packet capture on a given device id (``vdev name or pci address``) and queue.
53*278f9454SReshma Pattan  Note: The filter option in the API is a place holder for future enhancements.
54*278f9454SReshma Pattan
55*278f9454SReshma Pattan* ``rte_pdump_disable()``:
56*278f9454SReshma Pattan  This API disables the packet capture on a given port and queue.
57*278f9454SReshma Pattan
58*278f9454SReshma Pattan* ``rte_pdump_disable_by_deviceid()``:
59*278f9454SReshma Pattan  This API disables the packet capture on a given device id (``vdev name or pci address``) and queue.
60*278f9454SReshma Pattan
61*278f9454SReshma Pattan* ``rte_pdump_uninit()``:
62*278f9454SReshma Pattan  This API uninitializes the packet capture framework.
63*278f9454SReshma Pattan
64*278f9454SReshma Pattan* ``rte_pdump_set_socket_dir()``:
65*278f9454SReshma Pattan  This API sets the server and client socket paths.
66*278f9454SReshma Pattan  Note: This API is not thread-safe.
67*278f9454SReshma Pattan
68*278f9454SReshma Pattan
69*278f9454SReshma PattanOperation
70*278f9454SReshma Pattan---------
71*278f9454SReshma Pattan
72*278f9454SReshma PattanThe ``librte_pdump`` library works on a client/server model. The server is responsible for enabling or
73*278f9454SReshma Pattandisabling the packet capture and the clients are responsible for requesting the enabling or disabling of
74*278f9454SReshma Pattanthe packet capture.
75*278f9454SReshma Pattan
76*278f9454SReshma PattanThe packet capture framework, as part of its initialization, creates the pthread and the server socket in
77*278f9454SReshma Pattanthe pthread. The application that calls the framework initialization will have the server socket created,
78*278f9454SReshma Pattaneither under the path that the application has passed or under the default path i.e. either ``/var/run`` for
79*278f9454SReshma Pattanroot user or ``$HOME`` for non root user.
80*278f9454SReshma Pattan
81*278f9454SReshma PattanApplications that request enabling or disabling of the packet capture will have the client socket created either under
82*278f9454SReshma Pattanthe path that the application has passed or under the default path i.e. either ``/var/run/`` for root user or ``$HOME``
83*278f9454SReshma Pattanfor not root user to send the requests to the server.
84*278f9454SReshma PattanThe server socket will listen for client requests for enabling or disabling the packet capture.
85*278f9454SReshma Pattan
86*278f9454SReshma Pattan
87*278f9454SReshma PattanImplementation Details
88*278f9454SReshma Pattan----------------------
89*278f9454SReshma Pattan
90*278f9454SReshma PattanThe library API ``rte_pdump_init()``, initializes the packet capture framework by creating the pthread and the server
91*278f9454SReshma Pattansocket. The server socket in the pthread context will be listening to the client requests to enable or disable the
92*278f9454SReshma Pattanpacket capture.
93*278f9454SReshma Pattan
94*278f9454SReshma PattanThe library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture.
95*278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump enable" request and sends
96*278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and enable the packet capture
97*278f9454SReshma Pattanby registering the Ethernet RX and TX callbacks for the given port or device_id and queue combinations.
98*278f9454SReshma PattanThen the server will mirror the packets to the new mempool and enqueue them to the rte_ring that clients have passed
99*278f9454SReshma Pattanto these APIs. The server also sends the response back to the client about the status of the request that was processed.
100*278f9454SReshma PattanAfter the response is received from the server, the client socket is closed.
101*278f9454SReshma Pattan
102*278f9454SReshma PattanThe library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture.
103*278f9454SReshma PattanOn each call to these APIs, the library creates a separate client socket, creates the "pdump disable" request and sends
104*278f9454SReshma Pattanthe request to the server. The server that is listening on the socket will take the request and disable the packet
105*278f9454SReshma Pattancapture by removing the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. The server
106*278f9454SReshma Pattanalso sends the response back to the client about the status of the request that was processed. After the response is
107*278f9454SReshma Pattanreceived from the server, the client socket is closed.
108*278f9454SReshma Pattan
109*278f9454SReshma PattanThe library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by closing the pthread and the
110*278f9454SReshma Pattanserver socket.
111*278f9454SReshma Pattan
112*278f9454SReshma PattanThe library API ``rte_pdump_set_socket_dir()``, sets the given path as either server socket path
113*278f9454SReshma Pattanor client socket path based on the ``type`` argument of the API.
114*278f9454SReshma PattanIf the given path is ``NULL``, default path will be selected, i.e. either ``/var/run/`` for root user or ``$HOME``
115*278f9454SReshma Pattanfor non root user. Clients also need to call this API to set their server socket path if the server socket
116*278f9454SReshma Pattanpath is different from default path.
117*278f9454SReshma Pattan
118*278f9454SReshma Pattan
119*278f9454SReshma PattanUse Case: Packet Capturing
120*278f9454SReshma Pattan--------------------------
121*278f9454SReshma Pattan
122*278f9454SReshma PattanThe DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK.
123*278f9454SReshma PattanUsers can use this as an example to develop their own packet capturing tools.
124