xref: /dpdk/doc/guides/howto/packet_capture_framework.rst (revision 8d23ce8f5ee9f34acd1646b01ae6d862f5fd2aa2)
15630257fSFerruh Yigit..  SPDX-License-Identifier: BSD-3-Clause
2*8d23ce8fSStephen Hemminger    Copyright(c) 2017-2021 Intel Corporation.
3629122b8SReshma Pattan
4*8d23ce8fSStephen HemmingerDPDK packet capture libraries and tools
5*8d23ce8fSStephen Hemminger=======================================
6629122b8SReshma Pattan
7629122b8SReshma PattanThis document describes how the Data Plane Development Kit (DPDK) Packet
8629122b8SReshma PattanCapture Framework is used for capturing packets on DPDK ports. It is intended
9629122b8SReshma Pattanfor users of DPDK who want to know more about the Packet Capture feature and
10629122b8SReshma Pattanfor those who want to monitor traffic on DPDK-controlled devices.
11629122b8SReshma Pattan
12*8d23ce8fSStephen HemmingerThe DPDK packet capture framework was introduced in DPDK v16.07
13*8d23ce8fSStephen Hemmingerand enhanced in 21.11.
14*8d23ce8fSStephen HemmingerThe DPDK packet capture framework consists of the libraries
15*8d23ce8fSStephen Hemmingerfor collecting packets ``librte_pdump``
16*8d23ce8fSStephen Hemmingerand writing packets to a file ``librte_pcapng``.
17*8d23ce8fSStephen HemmingerThere is an application: ``dpdk-pdump``.
18629122b8SReshma Pattan
19629122b8SReshma PattanIntroduction
20629122b8SReshma Pattan------------
21629122b8SReshma Pattan
22*8d23ce8fSStephen HemmingerThe :doc:`librte_pdump <../prog_guide/pdump_lib>` library provides the API
23*8d23ce8fSStephen Hemmingerrequired to allow users to initialize the packet capture framework
24*8d23ce8fSStephen Hemmingerand to enable or disable packet capture.
25*8d23ce8fSStephen HemmingerThe library works on a multi-process communication model
26*8d23ce8fSStephen Hemmingerand its usage is recommended for debugging purposes.
27629122b8SReshma Pattan
28*8d23ce8fSStephen HemmingerThe :doc:`librte_pcapng <../prog_guide/pcapng_lib>` library provides the API
29*8d23ce8fSStephen Hemmingerto format packets and write them to a file in Pcapng format.
30629122b8SReshma Pattan
3123516151SReshma PattanThe application which initializes the packet capture framework will be a primary process
3223516151SReshma Pattanand the application that enables or disables the packet capture will
3323516151SReshma Pattanbe a secondary process. The primary process sends the Rx and Tx packets from the DPDK ports
3423516151SReshma Pattanto the secondary process.
35629122b8SReshma Pattan
36629122b8SReshma PattanIn DPDK the ``testpmd`` application can be used to initialize the packet
3723516151SReshma Pattancapture framework and acts as a server, and the ``dpdk-pdump`` tool acts as a
38629122b8SReshma Pattanclient. To view Rx or Tx packets of ``testpmd``, the application should be
39629122b8SReshma Pattanlaunched first, and then the ``dpdk-pdump`` tool. Packets from ``testpmd``
40629122b8SReshma Pattanwill be sent to the tool, which then sends them on to the Pcap PMD device and
41629122b8SReshma Pattanthat device writes them to the Pcap file or to an external interface depending
42629122b8SReshma Pattanon the command-line option used.
43629122b8SReshma Pattan
44629122b8SReshma PattanSome things to note:
45629122b8SReshma Pattan
46629122b8SReshma Pattan* The ``dpdk-pdump`` tool can only be used in conjunction with a primary
47629122b8SReshma Pattan  application which has the packet capture framework initialized already. In
48629122b8SReshma Pattan  dpdk, only ``testpmd`` is modified to initialize packet capture framework,
49629122b8SReshma Pattan  other applications remain untouched. So, if the ``dpdk-pdump`` tool has to
50629122b8SReshma Pattan  be used with any application other than the testpmd, the user needs to
51629122b8SReshma Pattan  explicitly modify that application to call the packet capture framework
52629122b8SReshma Pattan  initialization code. Refer to the ``app/test-pmd/testpmd.c`` code and look
53629122b8SReshma Pattan  for ``pdump`` keyword to see how this is done.
54629122b8SReshma Pattan
5579238624SCiara Power* The ``dpdk-pdump`` tool depends on the libpcap based PMD.
56629122b8SReshma Pattan
57629122b8SReshma Pattan
58629122b8SReshma PattanTest Environment
59629122b8SReshma Pattan----------------
60629122b8SReshma Pattan
61629122b8SReshma PattanThe overview of using the Packet Capture Framework and the ``dpdk-pdump`` tool
62629122b8SReshma Pattanfor packet capturing on the DPDK port in
63629122b8SReshma Pattan:numref:`figure_packet_capture_framework`.
64629122b8SReshma Pattan
65629122b8SReshma Pattan.. _figure_packet_capture_framework:
66629122b8SReshma Pattan
67629122b8SReshma Pattan.. figure:: img/packet_capture_framework.*
68629122b8SReshma Pattan
69629122b8SReshma Pattan   Packet capturing on a DPDK port using the dpdk-pdump tool.
70629122b8SReshma Pattan
71629122b8SReshma Pattan
72629122b8SReshma PattanRunning the Application
73629122b8SReshma Pattan-----------------------
74629122b8SReshma Pattan
75629122b8SReshma PattanThe following steps demonstrate how to run the ``dpdk-pdump`` tool to capture
76629122b8SReshma PattanRx side packets on dpdk_port0 in :numref:`figure_packet_capture_framework` and
77629122b8SReshma Pattaninspect them using ``tcpdump``.
78629122b8SReshma Pattan
79629122b8SReshma Pattan#. Launch testpmd as the primary application::
80629122b8SReshma Pattan
8179238624SCiara Power     sudo <build_dir>/app/dpdk-testpmd -c 0xf0 -n 4 -- -i --port-topology=chained
82629122b8SReshma Pattan
83629122b8SReshma Pattan#. Launch the pdump tool as follows::
84629122b8SReshma Pattan
8579238624SCiara Power     sudo <build_dir>/app/dpdk-pdump -- \
86629122b8SReshma Pattan          --pdump 'port=0,queue=*,rx-dev=/tmp/capture.pcap'
87629122b8SReshma Pattan
88629122b8SReshma Pattan#. Send traffic to dpdk_port0 from traffic generator.
89629122b8SReshma Pattan   Inspect packets captured in the file capture.pcap using a tool
90629122b8SReshma Pattan   that can interpret Pcap files, for example tcpdump::
91629122b8SReshma Pattan
92629122b8SReshma Pattan     $tcpdump -nr /tmp/capture.pcap
93629122b8SReshma Pattan     reading from file /tmp/capture.pcap, link-type EN10MB (Ethernet)
94629122b8SReshma Pattan     11:11:36.891404 IP 4.4.4.4.whois++ > 3.3.3.3.whois++: UDP, length 18
95629122b8SReshma Pattan     11:11:36.891442 IP 4.4.4.4.whois++ > 3.3.3.3.whois++: UDP, length 18
96629122b8SReshma Pattan     11:11:36.891445 IP 4.4.4.4.whois++ > 3.3.3.3.whois++: UDP, length 18
97