[show][generate_dump] Add optional tcpdump packet capture to "show techsupport"#4639
Open
vaishnav-nexthop wants to merge 1 commit into
Open
[show][generate_dump] Add optional tcpdump packet capture to "show techsupport"#4639vaishnav-nexthop wants to merge 1 commit into
vaishnav-nexthop wants to merge 1 commit into
Conversation
|
|
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…chsupport"
Why
---
`show techsupport` collects a rich snapshot of device state, but it is
purely a point-in-time view: it has no visibility into the traffic that
was actually on the wire while the dump was taken. For a large class of
network troubleshooting, packet-level evidence is exactly what is needed,
and today it has to be gathered out of band with a separate tcpdump
invocation and then manually correlated with the techsupport archive.
This adds packet capture as a first-class, optional part of techsupport.
When enabled, traffic is captured for the duration of the collection and
the resulting pcap is bundled into the same techsupport tarball, so a
single command produces both the device state and a matching capture
taken over the same window, as one self-contained artifact. This is
useful across the board -- protocol exchanges (BGP, BFD, LACP, LLDP,
ARP/ND, DHCP), data-plane forwarding and drop analysis, and any
investigation where seeing the packets matters -- and the optional BPF
filter lets the operator scope the capture to just the traffic of
interest.
What
----
A new, opt-in tcpdump capture for `show techsupport`, disabled by default.
show techsupport --with-tcpdump
[--tcpdump-duration <seconds>] # 1-300, default 60
[--tcpdump-packet-limit <count>] # 1-100000, default 10000
[--tcpdump-filter <bpf-expression>] # e.g. 'udp port 3784'
The tuning options are only meaningful together with --with-tcpdump; if
they are supplied without it the command fails fast with a clear error
rather than silently ignoring them.
How
---
show/main.py
- Adds the four Click options above and forwards them to generate_dump
as -T/-P/-L/-F. --tcpdump-duration and --tcpdump-packet-limit use
click.IntRange so out-of-range values are rejected at the CLI; the
documented defaults are applied when --with-tcpdump is given without
explicit values.
scripts/generate_dump
- start_tcpdump_capture(): launches `tcpdump -i any` in the background
at the start of collection so the capture overlaps data gathering.
The capture is self-bounding via tcpdump's native options -G/-W
(wall-clock duration) and -c (packet count), whichever is reached
first, and -s 0 keeps full-length packets. An optional BPF filter is
appended. tcpdump availability is checked first, and the capture is
skipped gracefully (without failing techsupport) when it is absent.
- wait_tcpdump_capture(): waits for the capture to finish. It is called
*before* save_to_tar, because save_to_tar archives the dump directory
by file content; awaiting the capture first guarantees the completed
pcap is on disk and included in the archive instead of a truncated
snapshot. In the common case (data collection outlasts the capture)
the wait returns immediately.
- handle_exit(): kills any still-running capture so an interrupt or
timeout cannot leave an orphan tcpdump process behind.
- getopts gains -T/-P/-L/-F, with validation that -P/-L/-F require -T.
The pcap is written as tcpdump_<duration>s_<timestamp>.pcap inside the
dump directory and therefore appears in the final techsupport archive.
Backward compatibility
-----------------------
The feature is entirely opt-in. Without --with-tcpdump, generate_dump and
`show techsupport` behave exactly as before.
Testing
-------
tests/techsupport_test.py adds coverage for the CLI-to-generate_dump
option mapping (defaults and explicit values), the requirement that the
tuning options be used together with --with-tcpdump, IntRange bound
enforcement, and a regression test asserting that wait_tcpdump_capture
runs before save_to_tar in generate_dump.
Signed-off-by: vaishnav-nexthop <vaishnav@nexthop.ai>
vaishnav-nexthop
force-pushed
the
add-tcpdump-capture-to-techsupport
branch
from
June 23, 2026 18:35
86015ee to
f8e5d54
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
vaishnav-nexthop
marked this pull request as ready for review
June 24, 2026 11:06
Collaborator
|
Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks! ---Powered by SONiC BuildBot
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
Added an optional, opt-in tcpdump packet capture to
show techsupport.show techsupportcollects a rich snapshot of device state, but it is apoint-in-time view with no visibility into the traffic that was on the wire
while the dump was taken. For a large class of troubleshooting, packet-level
evidence is exactly what is needed, and today it has to be gathered out of band
with a separate
tcpdumpinvocation and then manually correlated with thetechsupport archive.
This makes packet capture a first-class, optional part of techsupport: when
enabled, traffic is captured for the duration of the collection and the
resulting pcap is bundled into the same techsupport tarball, so a single command
produces both the device state and a matching capture taken over the same
window. An optional BPF filter lets the operator scope the capture to just the
traffic of interest (e.g. a protocol, port, or host).
The feature is disabled by default — existing
show techsupport/generate_dumpbehavior is unchanged unless--with-tcpdumpis passed.New options:
--with-tcpdump--tcpdump-duration <seconds>--tcpdump-packet-limit <count>--tcpdump-filter <bpf>udp port 3784The tuning options require
--with-tcpdump; supplying them without it fails fastwith a clear error rather than being silently ignored.
How I did it
show/main.pygenerate_dumpas-T/-P/-L/-F.--tcpdump-durationand--tcpdump-packet-limituseclick.IntRange, so out-of-range values are rejected at the CLI; documenteddefaults are applied when
--with-tcpdumpis given without explicit values.scripts/generate_dumpstart_tcpdump_capture()launchestcpdump -i anyin the background at thestart of collection so the capture overlaps data gathering. The capture is
self-bounding via tcpdump's native
-G/-W(wall-clock duration) and-c(packet count), whichever is reached first;
-s 0keeps full-length packets.tcpdump availability is checked first and the capture is skipped gracefully
(without failing techsupport) if it is absent.
wait_tcpdump_capture()waits for the capture to finish, and is invokedbefore
save_to_tar.save_to_tararchives the dump directory by filecontent, so awaiting the capture first guarantees the completed pcap is on disk
and included in the archive rather than a truncated snapshot. In the common
case (data collection outlasts the capture) the wait returns immediately.
handle_exit()kills any still-running capture so an interrupt or timeoutcannot leave an orphan tcpdump process behind.
getoptsgains-T/-P/-L/-F, with validation that-P/-L/-Frequire
-T.The pcap is written as
tcpdump_<duration>s_<timestamp>.pcapinside the dumpdirectory and therefore appears in the final techsupport archive.
How to verify it
Unit tests (
tests/techsupport_test.py):generate_dumpoption mapping, for both defaults and explicit values.--with-tcpdump(usage error otherwise).IntRangebounds are enforced for duration and packet limit.wait_tcpdump_captureruns beforesave_to_tar.Manual:
Error path:
New command output (if the output of a command-line utility has changed)