forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_dump
More file actions
executable file
·2777 lines (2520 loc) · 92.3 KB
/
generate_dump
File metadata and controls
executable file
·2777 lines (2520 loc) · 92.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Generate Sysdump
# creates a snapshot of system state for debugging later.
#
set -u
EXT_SUCCESS=0
EXT_GENERAL=1
EXT_LOCKFAIL=2
EXT_RECVSIG=3
EXT_RETRY=4
EXT_TAR_FAILED=5
EXT_PROCFS_SAVE_FAILED=6
EXT_INTERRUPTED=7
EXT_TERMINATED=8
EXT_INVALID_ARGUMENT=10
TIMEOUT_EXIT_CODE=124
TAR=tar
MKDIR=mkdir
RM=rm
LN=ln
GZIP=gzip
CP=cp
MV=mv
GREP=grep
TOUCH=touch
V=
ALLOW_PROCESS_STOP=
NOOP=false
DO_COMPRESS=true
CMD_PREFIX=
SINCE_DATE="@0" # default is set to January 1, 1970 at 00:00:00 GMT
REFERENCE_FILE=/tmp/reference
TECHSUPPORT_TIME_INFO=`mktemp "/tmp/techsupport_time_info.XXXXXXXXXX"`
BASE=sonic_dump_`hostname`_`date +%Y%m%d_%H%M%S`
DUMPDIR=/var/dump
TARDIR=$DUMPDIR/$BASE
TARFILE=$DUMPDIR/$BASE.tar
LOGDIR=$DUMPDIR/$BASE/dump
PLUGINS_DIR=/usr/local/bin/debug-dump
NUM_ASICS=1
HOME=${HOME:-/root}
USER=${USER:-root}
TIMEOUT_MIN="5"
SKIP_BCMCMD=0
SAVE_STDERR=true
RETURN_CODE=$EXT_SUCCESS
DEBUG_DUMP=false
ROUTE_TAB_LIMIT_DIRECT_ITERATION=24000
IS_SUPERVISOR=false
# lock dirs/files
LOCKDIR="/tmp/techsupport-lock"
PIDFILE="${LOCKDIR}/PID"
# Remove lock directory and exit, let user decide if they want to retry
rm_lock_and_exit()
{
$RM $V -rf ${LOCKDIR}
exit $EXT_RETRY
}
handle_exit()
{
ECODE=$?
echo "Cleaning up working directory $TARDIR"
$RM -rf $TARDIR
echo "Removing lock. Exit: $ECODE" >&2
$RM $V -rf ${LOCKDIR}
# Echo the filename as the last statement if the generation succeeds
if [[ -f $TARFILE && ($ECODE == $EXT_SUCCESS || $ECODE == $RETURN_CODE) ]]; then
echo $TARFILE
fi
}
handle_sigint()
{
echo "Generate Dump received interrupt" >&2
exit $EXT_INTERRUPTED
}
handle_sigterm() {
echo "Dump generation terminated" >&2
finalize
exit $EXT_TERMINATED
}
handle_error() {
if [ "$1" != "0" ]; then
echo "ERR: RC:-$1 observed on line $2" >&2
RETURN_CODE=$EXT_GENERAL
fi
}
escape_quotes() {
echo $1 | sed 's/\"/\\\"/g'
}
save_bcmcmd() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local cmd="$1"
local filename=$2
local filepath="${LOGDIR}/$filename"
local do_gzip=${3:-false}
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local cmd=$(escape_quotes "$cmd")
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
fi
if [ $SKIP_BCMCMD -eq 1 ]; then
echo "Skip $cmd"
return 0
fi
# eval required here to re-evaluate the $cmd properly at runtime
# This is required if $cmd has quoted strings that should be bunched
# as one argument, e.g. vtysh -c "COMMAND HERE" needs to have
# "COMMAND HERE" bunched together as 1 arg to vtysh -c
if $NOOP; then
echo "${timeout_cmd} bash -c \"${cmd}\" &> '${filepath}'"
else
ret=0
eval "${timeout_cmd} bash -c \"${cmd}\" &> '${filepath}'" || ret=$?
if [ $ret -ne 0 ]; then
if [ $ret -eq $TIMEOUT_EXIT_CODE ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
else
RC=0
grep "polling socket timeout: Success" ${filepath} &>/dev/null || RC=$?
if [ $RC -eq 0 ]; then
echo "bcmcmd command timeout. Setting SKIP_BCMCMD to true ..."
SKIP_BCMCMD=1
fi
fi
fi
fi
if $do_gzip; then
gzip ${filepath} 2>/dev/null
filepath="${filepath}.gz"
fi
end_t=$(date +%s%3N)
echo "[ save_bcmcmd:$cmd ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Runs a given bcmcmd command in all namesapces in case of multi ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# cmd: The command to run. Make sure that arguments with spaces have quotes
# filename: the filename to save the output as in $BASE/dump
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_bcmcmd_all_ns() {
trap 'handle_error $? $LINENO' ERR
local do_gzip=${3:-false}
if [[ ( "$NUM_ASICS" > 1 ) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
local cmd="bcmcmd -n $i $1"
local file="$2.$i"
save_bcmcmd "$cmd" "$file" "$do_gzip"
done
else
local cmd="bcmcmd $1"
save_bcmcmd "$cmd" "$2" "$do_gzip"
fi
}
###############################################################################
# Runs a comamnd and saves its output to the file.
# Command gets timedout if it runs for more than TIMEOUT_MIN minutes.
# Globals:
# LOGDIR
# BASE
# MKDIR
# TAR
# TARFILE
# DUMPDIR
# V
# RM
# NOOP
# Arguments:
# cmd: The command to run. Make sure that arguments with spaces have quotes
# filename: the filename to save the output as in $BASE/dump
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# Returns:
# None
###############################################################################
save_cmd() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local cmd="$1"
local filename=$2
local filepath="${LOGDIR}/$filename"
local do_gzip=${3:-false}
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local cleanup_method=${4:-dummy_cleanup_method}
local redirect='&>'
local redirect_eval='2>&1'
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
fi
if ! $SAVE_STDERR
then
redirect=">"
redirect_eval=""
fi
local cmd=$(escape_quotes "$cmd")
local cleanup_method_declration=$(declare -f $cleanup_method)
# eval required here to re-evaluate the $cmd properly at runtime
# This is required if $cmd has quoted strings that should be bunched
# as one argument, e.g. vtysh -c "COMMAND HERE" needs to have
# "COMMAND HERE" bunched together as 1 arg to vtysh -c
if $do_gzip; then
filepath="${filepath}.gz"
# cleanup_method will run in a sub-shell, need declare it first
local cmds="$cleanup_method_declration; $cmd $redirect_eval | $cleanup_method | gzip -c > '${filepath}'"
if $NOOP; then
echo "${timeout_cmd} bash -c \"${cmds}\""
else
RC=0
eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?
if [ $RC -eq $TIMEOUT_EXIT_CODE ]; then
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
elif [ $RC -ne 0 ]; then
echo "Command: $cmds failed with RC $RC"
fi
fi
else
local cmds="$cleanup_method_declration; $cmd | $cleanup_method $redirect '$filepath'"
if $NOOP; then
echo "${timeout_cmd} bash -c \"${cmds}\""
else
RC=0
eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?
if [ $RC -eq $TIMEOUT_EXIT_CODE ]; then
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
elif [ $RC -ne 0 ]; then
echo "Command: $cmds failed with RC $RC"
fi
fi
fi
end_t=$(date +%s%3N)
echo "[ save_cmd:$cmd ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Save all collected data to tar archive.
# Globals:
# DUMPDIR
# TAR
# TARFILE
# V
# BASE
# Arguments:
# None
# Returns:
# None
###############################################################################
save_to_tar() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
$TAR $V -rhf $TARFILE -C $DUMPDIR "$BASE"
end_t=$(date +%s%3N)
echo "[ save_to_tar ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Dummy cleanup method.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
dummy_cleanup_method() {
cat
}
###############################################################################
# Runs a given command in all namesapces in case of multi ASIC platform, in
# default (host) namespace in single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# cmd: The command to run. Make sure that arguments with spaces have quotes
# filename: the filename to save the output as in $BASE/dump
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# Returns:
# None
###############################################################################
save_cmd_all_ns() {
trap 'handle_error $? $LINENO' ERR
local do_zip=${3:-false}
local cleanup_method=${4:-dummy_cleanup_method}
# host or default namespace
save_cmd "$1" "$2" "$do_zip" $cleanup_method
if [[ ( "$NUM_ASICS" > 1 ) ]] ; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
local cmd="sonic-netns-exec asic$i $1"
local file="$2.$i"
save_cmd "$cmd" "$file" "$do_zip" $cleanup_method
done
fi
}
###############################################################################
# Copies a given file from a specified docker to the given target location
# default (host) namespace in single ASIC platform
# Globals:
# None
# Arguments:
# docker: docker name
# filename: the filename to copy
# destination: destination filename
# Returns:
# None
###############################################################################
copy_from_docker() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local docker=$1
local filename=$2
local dstpath=$3
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local touch_cmd="sudo docker exec ${docker} touch ${filename}"
local cp_cmd="sudo docker cp ${docker}:${filename} ${dstpath}"
if $NOOP; then
echo "${timeout_cmd} ${touch_cmd}"
echo "${timeout_cmd} ${cp_cmd}"
else
RC=0
eval "${timeout_cmd} ${touch_cmd}" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $touch_cmd timedout after ${TIMEOUT_MIN} minutes."
fi
eval "${timeout_cmd} ${cp_cmd}" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $cp_cmd timedout after ${TIMEOUT_MIN} minutes."
fi
fi
end_t=$(date +%s%3N)
echo "[ copy_from_docker:${docker}:${filename} ] : $(($end_t-$start_t)) msec" \
>> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Copies a given file from a specified docker to the given target location
# default (host) namespace in single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# docker: docker name
# filename: the filename to copy
# destination: destination filename
# Returns:
# None
###############################################################################
copy_from_masic_docker() {
trap 'handle_error $? $LINENO' ERR
local docker=$1
local filename=$2
local dstpath=$3
if [[ ("$NUM_ASICS" > 1) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
copy_from_docker "$docker$i" "$filename" "$dstpath.$i"
done
else
copy_from_docker "$docker" "$filename" "$dstpath"
fi
}
###############################################################################
# Returns namespace option to be used with vtysh commmand, based on the ASIC ID.
# Returns empty string if no ASIC ID is provided
# Globals:
# None
# Arguments:
# asic_id: (OPTIONAL) ASIC ID
# Returns:
# vtysh namespace option
###############################################################################
get_vtysh_namespace() {
trap 'handle_error $? $LINENO' ERR
local asic_id=${1:-""}
local ns=""
if [[ ( $asic_id = "" ) ]] ; then
ns=""
else
ns=" -n ${asic_id}"
fi
echo "$ns"
}
###############################################################################
# Runs a vtysh command in all namesapces for a multi ASIC platform, and in
# default (host) namespace in single ASIC platforms. Saves its output to the
# file.
# Globals:
# None
# Arguments:
# cmd: the vtysh command to run. This should NOT include vtysh -c
# filename: The filename to save the output as.
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_vtysh() {
trap 'handle_error $? $LINENO' ERR
local vtysh_cmd=$1
local filename=$2
local do_gzip=${3:-false}
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "vtysh -c '${vtysh_cmd}'" "$filename" $do_gzip
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
ns_cmd=$(get_vtysh_namespace $i)
local cmd="vtysh $ns_cmd -c '${vtysh_cmd}'"
local file=$filename.$i
save_cmd "$cmd" "$file" "$do_gzip"
done
fi
}
###############################################################################
# Runs an ip command and saves its output to the file.
# Globals:
# None
# Arguments:
# cmd: the ip command to run sans 'ip'
# filename: Files will be named 'ip.<filename>'
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_ip() {
trap 'handle_error $? $LINENO' ERR
local ip_args=$1
local filename="ip.$2"
local do_gzip=${3:-false}
save_cmd_all_ns "ip $ip_args" "$filename" "$do_gzip"
}
###############################################################################
# Runs a bridge command and saves its output to the file.
# Globals:
# None
# Arguments:
# cmd: the bridge command to run sans 'bridge'
# filename: Files will be named 'bridge.<filename>'
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_bridge() {
trap 'handle_error $? $LINENO' ERR
local br_args=$1
local filename="bridge.$2"
local do_gzip=${3:-false}
save_cmd_all_ns "bridge $br_args" "$filename" $do_gzip
}
###############################################################################
# Dump the bridge L2 information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bridge_info() {
trap 'handle_error $? $LINENO' ERR
save_bridge "fdb show" "fdb"
save_bridge "vlan show" "vlan"
}
###############################################################################
# Iterates all neighbors and runs save_vtysh to save each neighbor's
# advertised-routes and received-routes
# On multi ASIC platform, collects information from all namespaces
# Globals:
# None
# Arguments:
# Optional arg namespace
# Returns:
# None
###############################################################################
save_bgp_neighbor() {
trap 'handle_error $? $LINENO' ERR
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local asic_id=${1:-""}
local ns=$(get_vtysh_namespace $asic_id)
neighbor_list_v4=$(${timeout_cmd} bash -c "vtysh $ns -c 'show ip bgp neighbors' | grep 'BGP neighbor is' | awk -F '[, ]' '{print \$4}' | awk /\\\./")
if [ ! -z "$neighbor_list_v4" ]; then
v4_cmd="vtysh "
for word in $neighbor_list_v4; do
v4_cmd="${v4_cmd} $ns -Ec 'show bgp ipv4 neighbors $word advertised-routes' "
v4_cmd="${v4_cmd} $ns -Ec 'show bgp ipv4 neighbors $word routes' "
done
save_cmd "$v4_cmd" "ip.bgp.neigh.adv.rcv.routes"
fi
neighbor_list_v6=$(${timeout_cmd} bash -c "vtysh $ns -c 'show bgp ipv6 neighbors' | grep 'BGP neighbor is' | awk -F '[, ]' '{print \$4}' | awk /:/")
if [ ! -z "$neighbor_list_v6" ]; then
v6_cmd="vtysh "
for word in $neighbor_list_v6; do
v6_cmd="${v6_cmd} $ns -Ec 'show bgp ipv6 neighbors $word advertised-routes' "
v6_cmd="${v6_cmd} $ns -Ec 'show bgp ipv6 neighbors $word routes' "
done
save_cmd "$v6_cmd" "ipv6.bgp.neigh.adv.rcv.routes"
fi
vrf_list=""
vrf_output=$(${timeout_cmd} bash -c "vtysh $ns -c 'show vrf'")
if [ ! -z $vrf_output]; then
vrf_list= echo $vrf_output | awk -F" " '{print $2}'
fi
if [ ! -z "$vrf_list" ]; then
vrf_cmd="vtysh "
for vrf in $vrf_list; do
neighbor_list=`${timeout_cmd} bash -c "vtysh $ns -c 'show ip bgp vrf $vrf neighbors' | grep 'BGP neighbor is' | awk -F '[, ]' '{print \$4}'"`
for word in $neighbor_list; do
vrf_cmd="${vrf_cmd} $ns -Ec 'show ip bgp vrf $vrf neighbors $word advertised-routes' "
vrf_cmd="${vrf_cmd} $ns -Ec 'show ip bgp vrf $vrf neighbors $word routes' "
done
done
save_cmd "$vrf_cmd" "ip.bgp.neigh.vrf.adv.rcv.routes"
fi
}
###############################################################################
# Iterates all EVPN neighbors and runs save_vtysh to save each neighbor's
# advertised-routes and received-routes
# On multi ASIC platform, collects information from all namespaces
# Globals:
# None
# Arguments:
# Optional arg namespace
# Returns:
# None
###############################################################################
save_bgp_evpn_neighbor() {
trap 'handle_error $? $LINENO' ERR
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local asic_id=${1:-""}
local ns=$(get_vtysh_namespace $asic_id)
evpn_neighbors=$(${timeout_cmd} bash -c "vtysh -c 'show bgp l2vpn evpn summary' | cut -d ' ' -f1")
local parse_neighbors=false
for word in $evpn_neighbors; do
if [[ $word == "Neighbor" ]]; then
parse_neighbors=true
continue
elif [[ $word == "Total" ]]; then
parse_neighbors=false
continue
fi
if [ "$parse_neighbors" = true ]; then
save_cmd "vtysh $ns -c \"show bgp l2vpn evpn neighbors $word advertised-routes\"" "bgp.evpn.neighbor.$word.adv$asic_id"
save_cmd "vtysh $ns -c \"show bgp l2vpn evpn neighbors $word routes\"" "bgp.evpn.neighbor.$word.rcv$asic_id"
fi
done
}
###############################################################################
# Iterates all ASIC namespaces on multi ASIC platform and on default (host)
# namespace on single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bgp_neighbor_all_ns() {
trap 'handle_error $? $LINENO' ERR
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_bgp_neighbor
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
save_bgp_neighbor $i
done
fi
}
###############################################################################
# Iterates all ASIC namespaces on multi ASIC platform and on default (host)
# namespace on single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bgp_evpn_neighbor_all_ns() {
trap 'handle_error $? $LINENO' ERR
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_bgp_evpn_neighbor
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
save_bgp_evpn_neighbor $i
done
fi
}
###############################################################################
# Dump the nat config, iptables rules and conntrack nat entries
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_nat_info() {
trap 'handle_error $? $LINENO' ERR
save_cmd_all_ns "iptables -t nat -nv -L" "nat.iptables"
save_cmd_all_ns "conntrack -j -L" "nat.conntrack"
save_cmd_all_ns "conntrack -j -L | wc" "nat.conntrackcount"
save_cmd_all_ns "conntrack -L" "nat.conntrackall"
save_cmd_all_ns "conntrack -L | wc" "nat.conntrackallcount"
save_cmd_all_ns "show nat config" "nat.config"
}
###############################################################################
# Dump the BFD information from vtysh
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bfd_info() {
trap 'handle_error $? $LINENO' ERR
if $IS_SUPERVISOR; then
return
fi
save_vtysh "show bfd peers" "frr.bfd.peers"
save_vtysh "show bfd peers counters" "frr.bfd.peers.counters"
save_vtysh "show bfd peers json" "frr.bfd.peers.json"
save_vtysh "show bfd peers counters json" "frr.bfd.peers.counters.json"
}
###############################################################################
# Save IP related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_ip_info() {
trap 'handle_error $? $LINENO' ERR
save_ip "link" "link"
save_ip "addr" "addr"
save_ip "rule" "rule"
save_ip "route show table all" "route"
save_ip "neigh" "neigh"
save_ip "-s neigh show nud noarp" "neigh.noarp"
save_ip "-s link" "link.stats"
}
###############################################################################
# Save BGP related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bgp_info() {
trap 'handle_error $? $LINENO' ERR
if $IS_SUPERVISOR; then
return
fi
save_vtysh "show ip bgp summary" "bgp.summary"
save_vtysh "show ip bgp neighbors" "bgp.neighbors"
save_vtysh "show ip bgp" "bgp.table"
save_vtysh "show bgp ipv6 summary" "bgp.ipv6.summary"
save_vtysh "show bgp ipv6 neighbors" "bgp.ipv6.neighbors"
save_vtysh "show bgp ipv6" "bgp.ipv6.table"
save_vtysh "show ip bgp vrf all" "bgp.vrf.all"
save_vtysh "show ip bgp vrf all summary json" "bgp.vrf.all.summary.json"
save_vtysh "show ip bgp vrf all neighbors json" "bgp.vrf.all.neigh.json"
save_vtysh "show ip bgp vrf all nexthop" "bgp.vrf.all.nexthop"
save_vtysh "show ip bgp vrf all update-group" "bgp.vrf.all.nexthop"
save_vtysh "show bgp vrfs json" "bgp.vrf.json"
save_vtysh "show bgp vrf all ipv4 unicast summary json" "bgp.vrf.all.ipv4uc.summary.json"
save_vtysh "show bgp vrf all ipv6 unicast summary json" "bgp.vrf.all.ipv6uc.summary.json"
save_vtysh "show bgp vrf all ipv4 unicast detail json" "bgp.vrf.all.ipv4uc.detail.json"
save_vtysh "show bgp vrf all ipv6 unicast detail json" "bgp.vrf.all.ipv6uc.detail.json"
save_vtysh "show bgp vrf all ipv4 unicast update-group" "bgp.vrf.all.ipv4uc.update_group"
save_vtysh "show bgp vrf all ipv6 unicast update-group" "bgp.vrf.all.ipv6uc.update_group"
save_vtysh "show bgp vrf all ipv4 unicast route-leak json" "bgp.vrf.all.ipv4uc.route_leak.json"
save_vtysh "show bgp vrf all ipv6 unicast route-leak json" "bgp.vrf.all.ipv6uc.route_leak.json"
save_vtysh "show bgp ipv4 labeled-unicast" "bgp.ipv4.labeled_unicast"
save_vtysh "show bgp ipv6 labeled-unicast" "bgp.ipv6.labeled_unicast"
save_vtysh "show bgp mac hash" "bgp.mac.hash"
save_bgp_neighbor_all_ns
}
###############################################################################
# Save EVPN related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_evpn_info() {
trap 'handle_error $? $LINENO' ERR
if $IS_SUPERVISOR; then
return
fi
save_vtysh "show bgp l2vpn evpn" "bgp.l2vpn.evpn"
save_vtysh "show bgp l2vpn evpn summary json" "bgp.evpn.summary.json"
save_vtysh "show bgp l2vpn evpn route" "bgp.evpn.route"
save_vtysh "show bgp l2vpn evpn route detail" "bgp.evpn.route.detail"
save_vtysh "show bgp l2vpn evpn vni json" "bgp.evpn.vni.json"
save_vtysh "show bgp l2vpn evpn import-rt json" "bgp.evpn.import-rt.json"
save_vtysh "show bgp l2vpn evpn vrf-import-rt json" "bgp.evpn.vrf_import-rt.json"
save_vtysh "show bgp l2vpn evpn update-groups" "bgp.evpn.update_groups"
save_vtysh "show bgp l2vpn evpn next-hops json" "bgp.evpn.next_hops.json"
save_vtysh "show bgp vni all" "bgp.vni.all"
save_vtysh "show bgp vni all detail" "bgp.vni.all.detail"
save_vtysh "show evpn vni detail json" "evpn.vni.json"
save_vtysh "show evpn access-vlan json" "evpn.access_vlan.json"
save_vtysh "show evpn arp-cache vni all" "evpn.arp"
save_vtysh "show evpn json" "evpn.json"
save_vtysh "show evpn l2-nh json" "evpn.l2_nh.json"
save_vtysh "show evpn mac vni all" "evpn.mac.vni"
save_vtysh "show evpn arp-cache vni all" "evpn.arp_cache.vni"
save_vtysh "show evpn rmac vni all json" "evpn.rmac.vni.json"
save_vtysh "show evpn next-hops vni all json" "evpn.next_hops.vni.json"
save_bgp_evpn_neighbor_all_ns
}
###############################################################################
# Save FRR related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_frr_info() {
trap 'handle_error $? $LINENO' ERR
if $IS_SUPERVISOR; then
return
fi
save_vtysh "show running-config" "frr.running_config"
save_vtysh "show ip route vrf all nexthop-group" "frr.ip_route.nhg"
save_vtysh "show ipv6 route vrf all nexthop-group" "frr.ip6_route.nhg"
save_vtysh "show zebra fpm stats" "frr.fpm.stats"
save_vtysh "show zebra dplane detailed" "frr.dplane"
save_vtysh "show zebra dplane providers" "frr.dplane.providers"
save_vtysh "show interface vrf all" "frr.interfaces"
save_vtysh "show zebra" "frr.zebra"
save_vtysh "show zebra client" "frr.zebra.client"
save_vtysh "show zebra client summary" "frr.zebra.client.summary"
save_vtysh "show zebra router table summary" "frr.zebra.router.table.summary"
save_vtysh "show vrf" "frr.vrf"
save_vtysh "show vrf vni" "frr.vrf.vni"
save_vtysh "show ip nht vrf all" "frr.ip.nht.vrf.all"
save_vtysh "show ipv6 nht vrf all" "frr.ipv6.nht.vrf.all"
save_vtysh "show mpls table" "frr.mpls.table"
save_vtysh "show mpls fec" "frr.mpls.fec"
save_vtysh "show nexthop-group rib" "frr.nhg.rib"
save_vtysh "show route-map" "frr.route_map"
save_vtysh "show event cpu" "frr.event_cpu"
save_vtysh "show event poll" "frr.event_poll"
save_vtysh "show debugging hashtable" "frr.debugging_hashtable"
save_vtysh "show work-queues" "frr.work_queues"
save_vtysh "show memory" "frr.memory"
save_vtysh "show modules" "frr.modules"
save_vtysh "show version" "frr.version"
save_vtysh "show debugging" "frr.debugging"
save_vtysh "show logging" "frr.logging"
}
###############################################################################
# Save Redis DB contents
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_redis_info() {
trap 'handle_error $? $LINENO' ERR
save_redis "APPL_DB"
save_redis "ASIC_DB"
save_redis "COUNTERS_DB"
# There are secrets in CONFIG_DB need to be cleanup.
save_redis "CONFIG_DB" "CONFIG_DB" remove_secret_from_config_db_dump
save_redis "FLEX_COUNTER_DB"
save_redis "STATE_DB"
save_redis "APPL_STATE_DB"
}
###############################################################################
# Given list of proc files, saves proc files to tar.
# Globals:
# V
# TARDIR
# MKDIR
# CP
# DUMPDIR
# TAR
# RM
# BASE
# TARFILE
# NOOP
# Arguments:
# *procfiles: variable-length list of proc file paths to save
# Returns:
# None
###############################################################################
save_proc() {
trap 'handle_error $? $LINENO' ERR
local procfiles="$@"
$MKDIR $V -p $TARDIR/proc
for f in $procfiles
do
if $NOOP; then
if [ -e $f ]; then
echo "$CP $V -r $f $TARDIR/proc"
fi
else
( [ -e $f ] && $CP $V -r $f $TARDIR/proc ) || echo "$f not found" > $TARDIR/$f
fi
done
chmod ugo+rw -R $DUMPDIR/$BASE/proc
}
###############################################################################
# Given list of sys files, saves sys files to tar.
# Globals:
# V
# TARDIR
# MKDIR
# CP
# DUMPDIR
# TAR
# RM
# BASE
# TARFILE
# NOOP
# Arguments:
# *sysfiles: variable-length list of sys file paths to save
# Returns:
# None
###############################################################################
save_sys() {
trap 'handle_error $? $LINENO' ERR
local sysfiles="$@"
local cp_cmd="sudo cp"
$MKDIR $V -p $TARDIR/sys
for f in $sysfiles
do
if $NOOP; then
if [ -e $f ]; then
echo "$cp_cmd $V -r -p $f $TARDIR/sys"
fi
else
( [ -e $f ] && $cp_cmd $V -r -p $f $TARDIR/sys ) || echo "$f not found" > $TARDIR/$f
fi
done
chmod ugo+rw -R $DUMPDIR/$BASE/sys
}
save_sdk_sysfs() {
trap 'handle_error $? $LINENO' ERR
local src="$1"
local dest="$2"
shift 2
# sys files we do not want to include in dump
local excludes=("$@")
# there are module's sysfs which we cannot access while the module is in fw control
local fw_control_skip_list=(frequency_support frequency hw_present hw_reset low_power_mode power_good power_limit interrupt)
$MKDIR $V -p "$dest"
should_skip() {
local base="$1"
shift
local skip_list=("$@")
for skip in "${skip_list[@]}"; do
[[ "$base" == "$skip" ]] && return 0
done
return 1
}
copy_file_content() {
local f="$1"
local target="$2"
if $NOOP; then
echo "cat $f > $target 2>/dev/null"
else
cat "$f" > "$target" 2>/dev/null
fi
}
# Copy files directly under src
for f in "$src"/*; do
if [[ -f "$f" ]]; then
local base="$(basename "$f")"
should_skip "$base" "${excludes[@]}" && continue
copy_file_content "$f" "$dest/$base"
fi
done
# Copy sub folders
for d in "$src"/*; do
if [[ -d "$d" ]]; then
local subdir_dest="$dest/$(basename "$d")"
$MKDIR $V -p "$subdir_dest"
local present=0 hw_present="" control="" frequency_support=0 only_copy_presence_files=false
[[ -f "$d/control" ]] && control=$(<"$d/control")
[[ -f "$d/present" ]] && present=$(<"$d/present")
# hw_present is supported only for SW control modules
[[ "$control" == "1" && -f "$d/hw_present" ]] && hw_present=$(<"$d/hw_present")
# frequency_support is supported only for SW control modules
[[ "$control" == "1" && -f "$d/frequency_support" ]] && frequency_support=$(<"$d/frequency_support")
# if the module is unplugged, skip the rest of the files
if [[ -n "$hw_present" ]]; then
if [[ "$present" == "0" && "$hw_present" == "0" ]]; then
only_copy_presence_files=true
fi
else
[[ "$present" == "0" ]] && only_copy_presence_files=true
fi
# copy only files inside sub folder, not sub-sub folders
for f in "$d"/*; do
if [[ -f "$f" ]]; then
local base="$(basename "$f")"
should_skip "$base" "${excludes[@]}" && continue
[[ "$control" == "0" ]] && should_skip "$base" "${fw_control_skip_list[@]}" && continue
[[ "$only_copy_presence_files" == true && "$base" != "present" && "$base" != "hw_present" ]] && continue
[[ "$frequency_support" == "0" && "$base" == "frequency" ]] && continue
copy_file_content "$f" "$subdir_dest/$base"
fi
done
fi
done
chmod ugo+rw -R "$dest"
}