blob: a277a57b24ffce703cfb9f926b4e181aba47fe5b [file] [log] [blame]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +02001Using vpptrace.sh for VPP Packet Tracing
2========================================
3
4VPP allows tracing of incoming packets using CLI commands ``trace add``
5and ``show trace`` as explained [here](VPP_PACKET_TRACING_K8S.html), but
6it is a rather cumbersome process.
7
8The buffer for captured packets is limited in size, and once it gets
9full the tracing stops. The user has to manually clear the buffer
10content, and then repeat the trace command to resume the packet capture,
11losing information about all packets received in the meantime.
12
13Packet filtering exposed via the CLI command ``trace filter`` is also
14quite limited in what it can do. Currently there is just one available
15filter, which allows you to keep only packets that include a certain
16node in the trace or exclude a certain node in the trace. It is not
17possible to filter the traffic by its content (e.g., by the
18source/destination IP address, protocol, etc.).
19
20Last but not least, it is not possible to trace packets on a selected
21interface like ``tcpdump``, which allows tracing via the option ``-i``.
22VPP is only able to capture packets on the *RX side* of selected
23*devices* (e.g., dpdk, virtio, af-packet). This means that interfaces
24based on the same device cannot be traced for incoming packets
25individually, but only all at the same time. In Contiv/VPP all pods are
26connected with VPP via the same kind of the TAP interface, meaning that
27it is not possible to capture packets incoming only from one selected
28pod.
29
30Contiv/VPP ships with a simple bash script
31`vpptrace.sh <https://github.com/contiv/vpp/blob/master/scripts/vpptrace.sh>`__,
32which helps alleviate the aforementioned VPP limitations. The script
33automatically re-initializes buffers and traces whenever it is close to
34getting full, in order to avoid packet loss as much as possible. Next it
35allows you to filter packets by the content of the trace. There are two
36modes of filtering: - *substring mode* (default): packet trace must
37contain a given sub-string in order to be included in the output -
38*regex mode*: packet trace must match a given regex in order to be
39printed
40
41The script is still limited, in that capture runs only on the RX side of
42all interfaces that are built on top of selected devices. Using
43filtering, however, it is possible to limit *traffic by interface*
44simply by using the interface name as a substring to match against.
45
46Usage
47-----
48
49Run the script with option ``-h`` to get the usage printed:
50
51::
52
53 Usage: ./vpptrace.sh [-i <VPP-IF-TYPE>]... [-a <VPP-ADDRESS>] [-r] [-f <REGEXP> / <SUBSTRING>]
54 -i <VPP-IF-TYPE> : VPP interface *type* to run the packet capture on (e.g., dpdk-input, virtio-input, etc.)
55 - available aliases:
56 - af-packet-input: afpacket, af-packet, veth
57 - virtio-input: tap (version determined from the VPP runtime config), tap2, tapv2
58 - tapcli-rx: tap (version determined from the VPP config), tap1, tapv1
59 - dpdk-input: dpdk, gbe, phys*
60 - multiple interfaces can be watched at the same time - the option can be repeated with
61 different values
62 - default = dpdk + tap
63 -a <VPP-ADDRESS> : IP address or hostname of the VPP to capture packets from
64 - not supported if VPP listens on a UNIX domain socket
65 - default = 127.0.0.1
66 -r : apply filter string (passed with -f) as a regexp expression
67 - by default the filter is NOT treated as regexp
68 -f : filter string that packet must contain (without -r) or match as regexp (with -r) to be printed
69 - default is no filtering
70
71``VPP-IF-TYPE`` is a repeated option used to select the set of devices
72(e.g., virtio, dpdk, etc.) to capture the incoming traffic. Script
73provides multiple aliases, which are much easier to remember than the
74device names. For ``dpdk-input`` one can enter just ``dpdk``, or
75anything starting with ``phys``, etc. For TAPs, the script is even smart
76enough to find out the TAP version used, which allows to enter just
77``tap`` as the device name.
78
79If ``VPP-IF-TYPE`` is not specified, then the default behaviour is to
80capture from both ``dpdk`` (traffic entering the node from outside) and
81``tap`` (preferred interface type for pod-VPP and host-VPP
82interconnection, receiving node-initiated traffic).
83
84vpptrace.sh can capture packets even from a VPP on a different host,
85provided that VPP-CLI listens on a port, and not on a UNIX domain socket
86(for security reasons IPC is the default communication link, see
87``/etc/vpp/contiv-vswitch.conf``). Enter the destination node IP address
88via the option ``-a``\ (localhost is the default).
89
90The capture can be filtered via the ``-f`` option. The output will
91include only packets whose trace matches contain the given
92expression/sub-string.
93
94Option ``-r`` enables the regex mode for filtering.
95
96Examples
97--------
98
99- Capture all packets entering VPP via ``tapcli-1`` interface **AND**
100 all packets leaving VPP via ``tapcli-1`` that were sent from a pod,
101 or the host on the *same node* (sent from tap, not Gbe):
102
103::
104
105 $ vpptrace.sh -i tap -f "tapcli-1"
106
107 - Capture all packets with source or destination IP address 10.1.1.3:
108
109::
110
111 $ vpptrace.sh -i tap -i dpdk -f "10.1.1.3"
112
113 Or just:
114 $ vpptrace.sh "10.1.1.3"
115
116- Capture all SYN-ACKs received from outside:
117
118::
119
120 $ vpptrace.sh -i dpdk -f "SYN-ACK"