Commit 86015ee
committed
[show][generate_dump] Add optional tcpdump packet capture to "show techsupport"
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>1 parent ec69c33 commit 86015ee
3 files changed
Lines changed: 252 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| |||
69 | 80 | | |
70 | 81 | | |
71 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
72 | 90 | | |
73 | 91 | | |
74 | 92 | | |
| |||
102 | 120 | | |
103 | 121 | | |
104 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
105 | 202 | | |
106 | 203 | | |
107 | 204 | | |
| |||
2633 | 2730 | | |
2634 | 2731 | | |
2635 | 2732 | | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
2636 | 2738 | | |
2637 | 2739 | | |
2638 | 2740 | | |
| |||
2865 | 2967 | | |
2866 | 2968 | | |
2867 | 2969 | | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
2868 | 2978 | | |
2869 | 2979 | | |
2870 | | - | |
| 2980 | + | |
2871 | 2981 | | |
2872 | 2982 | | |
2873 | 2983 | | |
| |||
3044 | 3154 | | |
3045 | 3155 | | |
3046 | 3156 | | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
3047 | 3165 | | |
3048 | 3166 | | |
3049 | 3167 | | |
3050 | | - | |
| 3168 | + | |
3051 | 3169 | | |
3052 | 3170 | | |
3053 | 3171 | | |
| |||
3101 | 3219 | | |
3102 | 3220 | | |
3103 | 3221 | | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
3104 | 3245 | | |
3105 | 3246 | | |
3106 | 3247 | | |
3107 | 3248 | | |
3108 | 3249 | | |
3109 | 3250 | | |
3110 | 3251 | | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
3111 | 3268 | | |
3112 | 3269 | | |
3113 | 3270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1796 | 1796 | | |
1797 | 1797 | | |
1798 | 1798 | | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
1799 | 1806 | | |
1800 | | - | |
| 1807 | + | |
| 1808 | + | |
1801 | 1809 | | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
1802 | 1827 | | |
1803 | 1828 | | |
1804 | 1829 | | |
| |||
1825 | 1850 | | |
1826 | 1851 | | |
1827 | 1852 | | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
1828 | 1862 | | |
1829 | 1863 | | |
1830 | 1864 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
0 commit comments