New upstream version 18.02
[deb_dpdk.git] / doc / guides / prog_guide / pdump_lib.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2016 Intel Corporation.
3
4 .. _pdump_library:
5
6 The librte_pdump Library
7 ========================
8
9 The ``librte_pdump`` library provides a framework for packet capturing in DPDK.
10 The library does the complete copy of the Rx and Tx mbufs to a new mempool and
11 hence it slows down the performance of the applications, so it is recommended
12 to use this library for debugging purposes.
13
14 The library provides the following APIs to initialize the packet capture framework, to enable
15 or disable the packet capture, and to uninitialize it:
16
17 * ``rte_pdump_init()``:
18   This API initializes the packet capture framework.
19
20 * ``rte_pdump_enable()``:
21   This API enables the packet capture on a given port and queue.
22   Note: The filter option in the API is a place holder for future enhancements.
23
24 * ``rte_pdump_enable_by_deviceid()``:
25   This API enables the packet capture on a given device id (``vdev name or pci address``) and queue.
26   Note: The filter option in the API is a place holder for future enhancements.
27
28 * ``rte_pdump_disable()``:
29   This API disables the packet capture on a given port and queue.
30
31 * ``rte_pdump_disable_by_deviceid()``:
32   This API disables the packet capture on a given device id (``vdev name or pci address``) and queue.
33
34 * ``rte_pdump_uninit()``:
35   This API uninitializes the packet capture framework.
36
37 * ``rte_pdump_set_socket_dir()``:
38   This API sets the server and client socket paths.
39   Note: This API is not thread-safe.
40
41
42 Operation
43 ---------
44
45 The ``librte_pdump`` library works on a client/server model. The server is responsible for enabling or
46 disabling the packet capture and the clients are responsible for requesting the enabling or disabling of
47 the packet capture.
48
49 The packet capture framework, as part of its initialization, creates the pthread and the server socket in
50 the pthread. The application that calls the framework initialization will have the server socket created,
51 either under the path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for
52 root user or ``~/.dpdk`` for non root user.
53
54 Applications that request enabling or disabling of the packet capture will have the client socket created either under
55 the path that the application has passed or under the default path i.e. either ``/var/run/.dpdk`` for root user or
56 ``~/.dpdk`` for not root user to send the requests to the server. The server socket will listen for client requests for
57 enabling or disabling the packet capture.
58
59
60 Implementation Details
61 ----------------------
62
63 The library API ``rte_pdump_init()``, initializes the packet capture framework by creating the pthread and the server
64 socket. The server socket in the pthread context will be listening to the client requests to enable or disable the
65 packet capture.
66
67 The library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture.
68 On each call to these APIs, the library creates a separate client socket, creates the "pdump enable" request and sends
69 the request to the server. The server that is listening on the socket will take the request and enable the packet capture
70 by registering the Ethernet RX and TX callbacks for the given port or device_id and queue combinations.
71 Then the server will mirror the packets to the new mempool and enqueue them to the rte_ring that clients have passed
72 to these APIs. The server also sends the response back to the client about the status of the request that was processed.
73 After the response is received from the server, the client socket is closed.
74
75 The library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture.
76 On each call to these APIs, the library creates a separate client socket, creates the "pdump disable" request and sends
77 the request to the server. The server that is listening on the socket will take the request and disable the packet
78 capture by removing the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. The server
79 also sends the response back to the client about the status of the request that was processed. After the response is
80 received from the server, the client socket is closed.
81
82 The library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by closing the pthread and the
83 server socket.
84
85 The library API ``rte_pdump_set_socket_dir()``, sets the given path as either server socket path
86 or client socket path based on the ``type`` argument of the API.
87 If the given path is ``NULL``, default path will be selected, i.e. either ``/var/run/.dpdk`` for root user or ``~/.dpdk``
88 for non root user. Clients also need to call this API to set their server socket path if the server socket
89 path is different from default path.
90
91
92 Use Case: Packet Capturing
93 --------------------------
94
95 The DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK.
96 Users can use this as an example to develop their own packet capturing tools.