-
Notifications
You must be signed in to change notification settings - Fork 661
/
main.py
executable file
·2656 lines (2206 loc) · 84.8 KB
/
main.py
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
import json
import os
import subprocess
import sys
import re
import click
import lazy_object_proxy
import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
import utilities_common.multi_asic as multi_asic_util
from importlib import reload
from natsort import natsorted
from sonic_py_common import device_info
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from tabulate import tabulate
from utilities_common import util_base
from utilities_common.db import Db
from datetime import datetime
import utilities_common.constants as constants
from utilities_common.general import load_db_config
from json.decoder import JSONDecodeError
from sonic_py_common.general import getstatusoutput_noshell_pipe
# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), "..")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
import mock_tables.mock_multi_asic
reload(mock_tables.mock_multi_asic)
reload(mock_tables.dbconnector)
mock_tables.dbconnector.load_namespace_config()
except KeyError:
pass
from . import acl
from . import bgp_common
from . import chassis_modules
from . import dropcounters
from . import fabric
from . import feature
from . import fgnhg
from . import flow_counters
from . import gearbox
from . import interfaces
from . import kdump
from . import kube
from . import muxcable
from . import nat
from . import platform
from . import p4_table
from . import processes
from . import reboot_cause
from . import sflow
from . import vlan
from . import vnet
from . import vxlan
from . import system_health
from . import warm_restart
from . import plugins
from . import syslog
from . import dns
from . import bgp_cli
from . import stp
# Global Variables
PLATFORM_JSON = 'platform.json'
HWSKU_JSON = 'hwsku.json'
PORT_STR = "Ethernet"
BMP_STATE_DB = 'BMP_STATE_DB'
VLAN_SUB_INTERFACE_SEPARATOR = '.'
GEARBOX_TABLE_PHY_PATTERN = r"_GEARBOX_TABLE:phy:*"
COMMAND_TIMEOUT = 300
# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
def get_routing_stack():
result = None
command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1 | head -n 1"
try:
stdout = subprocess.check_output(command, shell=True, text=True, timeout=COMMAND_TIMEOUT)
result = stdout.rstrip('\n')
except Exception as err:
click.echo('Failed to get routing stack: {}'.format(err), err=True)
return result
# Global Routing-Stack variable
routing_stack = get_routing_stack()
# Read given JSON file
def readJsonFile(fileName):
try:
with open(fileName) as f:
result = json.load(f)
except Exception as e:
click.echo(str(e))
raise click.Abort()
return result
def run_command(command, display_cmd=False, return_cmd=False, shell=False):
if not shell:
command_str = ' '.join(command)
else:
command_str = command
if display_cmd:
click.echo(click.style("Command: ", fg='cyan') + click.style(command_str, fg='green'))
# No conversion needed for intfutil commands as it already displays
# both SONiC interface name and alias name for all interfaces.
if clicommon.get_interface_naming_mode() == "alias" and not command_str.startswith("intfutil"):
clicommon.run_command_in_alias_mode(command, shell=shell)
raise sys.exit(0)
proc = subprocess.Popen(command, shell=shell, text=True, stdout=subprocess.PIPE)
while True:
if return_cmd:
output = proc.communicate()[0]
return output
output = proc.stdout.readline()
if output == "" and proc.poll() is not None:
break
if output:
click.echo(output.rstrip('\n'))
rc = proc.poll()
if rc != 0:
sys.exit(rc)
def get_cmd_output(cmd):
proc = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE)
return proc.communicate()[0], proc.returncode
def get_config_json_by_namespace(namespace):
cmd = ['sonic-cfggen', '-d', '--print-data']
if namespace is not None and namespace != multi_asic.DEFAULT_NAMESPACE:
cmd += ['-n', namespace]
stdout, rc = get_cmd_output(cmd)
if rc:
click.echo("Failed to get cmd output '{}':rc {}".format(cmd, rc))
raise click.Abort()
try:
config_json = json.loads(stdout)
except JSONDecodeError as e:
click.echo("Failed to load output '{}':{}".format(cmd, e))
raise click.Abort()
return config_json
# Lazy global class instance for SONiC interface name to alias conversion
iface_alias_converter = lazy_object_proxy.Proxy(lambda: clicommon.InterfaceAliasConverter())
#
# Display all storm-control data
#
def display_storm_all():
""" Show storm-control """
header = ['Interface Name', 'Storm Type', 'Rate (kbps)']
body = []
config_db = ConfigDBConnector()
config_db.connect()
table = config_db.get_table('PORT_STORM_CONTROL')
#To avoid further looping below
if not table:
return
sorted_table = natsorted(table)
for storm_key in sorted_table:
interface_name = storm_key[0]
storm_type = storm_key[1]
#interface_name, storm_type = storm_key.split(':')
data = config_db.get_entry('PORT_STORM_CONTROL', storm_key)
if not data:
return
kbps = data['kbps']
body.append([interface_name, storm_type, kbps])
click.echo(tabulate(body, header, tablefmt="grid"))
#
# Get storm-control configurations per interface append to body
#
def get_storm_interface(intf, body):
storm_type_list = ['broadcast','unknown-unicast','unknown-multicast']
config_db = ConfigDBConnector()
config_db.connect()
table = config_db.get_table('PORT_STORM_CONTROL')
#To avoid further looping below
if not table:
return
for storm_type in storm_type_list:
storm_key = intf + '|' + storm_type
data = config_db.get_entry('PORT_STORM_CONTROL', storm_key)
if data:
kbps = data['kbps']
body.append([intf, storm_type, kbps])
#
# Display storm-control data of given interface
#
def display_storm_interface(intf):
""" Show storm-control """
storm_type_list = ['broadcast','unknown-unicast','unknown-multicast']
header = ['Interface Name', 'Storm Type', 'Rate (kbps)']
body = []
config_db = ConfigDBConnector()
config_db.connect()
table = config_db.get_table('PORT_STORM_CONTROL')
#To avoid further looping below
if not table:
return
for storm_type in storm_type_list:
storm_key = intf + '|' + storm_type
data = config_db.get_entry('PORT_STORM_CONTROL', storm_key)
if data:
kbps = data['kbps']
body.append([intf, storm_type, kbps])
click.echo(tabulate(body, header, tablefmt="grid"))
def connect_config_db():
"""
Connects to config_db
"""
config_db = ConfigDBConnector()
config_db.connect()
return config_db
def is_gearbox_configured():
"""
Checks whether Gearbox is configured or not
"""
app_db = SonicV2Connector()
app_db.connect(app_db.APPL_DB)
keys = app_db.keys(app_db.APPL_DB, '*')
# If any _GEARBOX_TABLE:phy:* records present in APPL_DB, then the gearbox is configured
if any(re.match(GEARBOX_TABLE_PHY_PATTERN, key) for key in keys):
return True
else:
return False
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?'])
#
# 'cli' group (root group)
#
# This is our entrypoint - the main "show" command
# TODO: Consider changing function name to 'show' for better understandability
@click.group(cls=clicommon.AliasedGroup, context_settings=CONTEXT_SETTINGS)
@click.pass_context
def cli(ctx):
"""SONiC command line - 'show' command"""
# Load database config files
load_db_config()
ctx.obj = Db()
# Add groups from other modules
cli.add_command(acl.acl)
cli.add_command(chassis_modules.chassis)
cli.add_command(dropcounters.dropcounters)
cli.add_command(fabric.fabric)
cli.add_command(feature.feature)
cli.add_command(fgnhg.fgnhg)
cli.add_command(flow_counters.flowcnt_route)
cli.add_command(flow_counters.flowcnt_trap)
cli.add_command(kdump.kdump)
cli.add_command(interfaces.interfaces)
cli.add_command(kdump.kdump)
cli.add_command(kube.kubernetes)
cli.add_command(muxcable.muxcable)
cli.add_command(nat.nat)
cli.add_command(platform.platform)
cli.add_command(p4_table.p4_table)
cli.add_command(processes.processes)
cli.add_command(reboot_cause.reboot_cause)
cli.add_command(sflow.sflow)
cli.add_command(vlan.vlan)
cli.add_command(vnet.vnet)
cli.add_command(vxlan.vxlan)
cli.add_command(system_health.system_health)
cli.add_command(warm_restart.warm_restart)
cli.add_command(dns.dns)
cli.add_command(stp.spanning_tree)
# syslog module
cli.add_command(syslog.syslog)
# Add greabox commands only if GEARBOX is configured
if is_gearbox_configured():
cli.add_command(gearbox.gearbox)
# bgp module
cli.add_command(bgp_cli.BGP)
#
# 'vrf' command ("show vrf")
#
def get_interface_bind_to_vrf(config_db, vrf_name):
"""Get interfaces belong to vrf
"""
tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE', 'VLAN_SUB_INTERFACE']
data = []
for table_name in tables:
interface_dict = config_db.get_table(table_name)
if interface_dict:
for interface in interface_dict:
if 'vrf_name' in interface_dict[interface] and vrf_name == interface_dict[interface]['vrf_name']:
data.append(interface)
return data
@cli.command()
@click.argument('vrf_name', required=False)
def vrf(vrf_name):
"""Show vrf config"""
config_db = ConfigDBConnector()
config_db.connect()
header = ['VRF', 'Interfaces']
body = []
vrf_dict = config_db.get_table('VRF')
if vrf_dict:
vrfs = []
if vrf_name is None:
vrfs = list(vrf_dict.keys())
elif vrf_name in vrf_dict:
vrfs = [vrf_name]
for vrf in vrfs:
intfs = get_interface_bind_to_vrf(config_db, vrf)
intfs = natsorted(intfs)
if len(intfs) == 0:
body.append([vrf, ""])
else:
body.append([vrf, intfs[0]])
for intf in intfs[1:]:
body.append(["", intf])
click.echo(tabulate(body, header))
#
# 'events' command ("show event-counters")
#
@cli.command()
def event_counters():
"""Show events counter"""
# dump keys as formatted
counters_db = SonicV2Connector(host='127.0.0.1')
counters_db.connect(counters_db.COUNTERS_DB, retry_on=False)
header = ['name', 'count']
keys = counters_db.keys(counters_db.COUNTERS_DB, 'COUNTERS_EVENTS*')
table = []
for key in natsorted(keys):
key_list = key.split(':')
data_dict = counters_db.get_all(counters_db.COUNTERS_DB, key)
table.append((key_list[1], data_dict["value"]))
if table:
click.echo(tabulate(table, header, tablefmt='simple', stralign='right'))
else:
click.echo('No data available in COUNTERS_EVENTS\n')
#
# 'arp' command ("show arp")
#
@cli.command()
@click.argument('ipaddress', required=False)
@click.option('-if', '--iface')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def arp(ipaddress, iface, verbose):
"""Show IP ARP table"""
cmd = ['nbrshow', '-4']
if ipaddress is not None:
cmd += ['-ip', str(ipaddress)]
if iface is not None:
if clicommon.get_interface_naming_mode() == "alias":
if not ((iface.startswith("PortChannel")) or
(iface.startswith("eth"))):
iface = iface_alias_converter.alias_to_name(iface)
cmd += ['-if', str(iface)]
run_command(cmd, display_cmd=verbose)
#
# 'ndp' command ("show ndp")
#
@cli.command()
@click.argument('ip6address', required=False)
@click.option('-if', '--iface')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ndp(ip6address, iface, verbose):
"""Show IPv6 Neighbour table"""
cmd = ['nbrshow', '-6']
if ip6address is not None:
cmd += ['-ip', str(ip6address)]
if iface is not None:
cmd += ['-if', str(iface)]
run_command(cmd, display_cmd=verbose)
def is_mgmt_vrf_enabled(ctx):
"""Check if management VRF is enabled"""
if ctx.invoked_subcommand is None:
cmd = ['sonic-cfggen', '-d', '--var-json', "MGMT_VRF_CONFIG"]
p = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try :
mvrf_dict = json.loads(p.stdout.read())
except ValueError:
print("MGMT_VRF_CONFIG is not present.")
return False
# if the mgmtVrfEnabled attribute is configured, check the value
# and return True accordingly.
if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']:
if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"):
#ManagementVRF is enabled. Return True.
return True
return False
#
# 'storm-control' group
# "show storm-control [interface <interface>]"
#
@cli.group('storm-control', invoke_without_command=True)
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
@click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend')
@click.pass_context
def storm_control(ctx, namespace, display):
""" Show storm-control """
header = ['Interface Name', 'Storm Type', 'Rate (kbps)']
body = []
if ctx.invoked_subcommand is None:
if namespace is None:
display_storm_all()
else:
interfaces = multi_asic.multi_asic_get_ip_intf_from_ns(namespace)
for intf in interfaces:
get_storm_interface(intf, body)
click.echo(tabulate(body, header, tablefmt="grid"))
@storm_control.command('interface')
@click.argument('interface', metavar='<interface>',required=True)
def interface(interface, namespace, display):
if multi_asic.is_multi_asic() and namespace not in multi_asic.get_namespace_list():
ctx = click.get_current_context()
ctx.fail('-n/--namespace option required. provide namespace from list {}'.format(multi_asic.get_namespace_list()))
if interface:
display_storm_interface(interface)
#
# 'mgmt-vrf' group ("show mgmt-vrf ...")
#
@cli.group('mgmt-vrf', invoke_without_command=True)
@click.argument('routes', required=False, type=click.Choice(["routes"]))
@click.pass_context
def mgmt_vrf(ctx,routes):
"""Show management VRF attributes"""
if is_mgmt_vrf_enabled(ctx) is False:
click.echo("\nManagementVRF : Disabled")
return
else:
if routes is None:
click.echo("\nManagementVRF : Enabled")
click.echo("\nManagement VRF interfaces in Linux:")
cmd = ['ip', '-d', 'link', 'show', 'mgmt']
run_command(cmd)
cmd = ['ip', 'link', 'show', 'vrf', 'mgmt']
run_command(cmd)
else:
click.echo("\nRoutes in Management VRF Routing Table:")
cmd = ['ip', 'route', 'show', 'table', '5000']
run_command(cmd)
#
# 'management_interface' group ("show management_interface ...")
#
@cli.group(name='management_interface', cls=clicommon.AliasedGroup)
def management_interface():
"""Show management interface parameters"""
pass
# 'address' subcommand ("show management_interface address")
@management_interface.command()
def address ():
"""Show IP address configured for management interface"""
config_db = ConfigDBConnector()
config_db.connect()
# Fetching data from config_db for MGMT_INTERFACE
mgmt_ip_data = config_db.get_table('MGMT_INTERFACE')
for key in natsorted(list(mgmt_ip_data.keys())):
click.echo("Management IP address = {0}".format(key[1]))
click.echo("Management Network Default Gateway = {0}".format(mgmt_ip_data[key]['gwaddr']))
#
# 'snmpagentaddress' group ("show snmpagentaddress ...")
#
@cli.group('snmpagentaddress', invoke_without_command=True)
@click.pass_context
def snmpagentaddress (ctx):
"""Show SNMP agent listening IP address configuration"""
config_db = ConfigDBConnector()
config_db.connect()
agenttable = config_db.get_table('SNMP_AGENT_ADDRESS_CONFIG')
header = ['ListenIP', 'ListenPort', 'ListenVrf']
body = []
for agent in agenttable:
body.append([agent[0], agent[1], agent[2]])
click.echo(tabulate(body, header))
#
# 'snmptrap' group ("show snmptrap ...")
#
@cli.group('snmptrap', invoke_without_command=True)
@click.pass_context
def snmptrap (ctx):
"""Show SNMP agent Trap server configuration"""
config_db = ConfigDBConnector()
config_db.connect()
traptable = config_db.get_table('SNMP_TRAP_CONFIG')
header = ['Version', 'TrapReceiverIP', 'Port', 'VRF', 'Community']
body = []
for row in traptable:
if row == "v1TrapDest":
ver=1
elif row == "v2TrapDest":
ver=2
else:
ver=3
body.append([ver, traptable[row]['DestIp'], traptable[row]['DestPort'], traptable[row]['vrf'], traptable[row]['Community']])
click.echo(tabulate(body, header))
#
# 'subinterfaces' group ("show subinterfaces ...")
#
@cli.group(cls=clicommon.AliasedGroup)
def subinterfaces():
"""Show details of the sub port interfaces"""
pass
# 'subinterfaces' subcommand ("show subinterfaces status")
@subinterfaces.command()
@click.argument('subinterfacename', type=str, required=False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def status(subinterfacename, verbose):
"""Show sub port interface status information"""
cmd = ['intfutil', '-c', 'status']
if subinterfacename is not None:
sub_intf_sep_idx = subinterfacename.find(VLAN_SUB_INTERFACE_SEPARATOR)
if sub_intf_sep_idx == -1:
print("Invalid sub port interface name")
return
if clicommon.get_interface_naming_mode() == "alias":
subinterfacename = iface_alias_converter.alias_to_name(subinterfacename)
cmd += ['-i', str(subinterfacename)]
else:
cmd += ['-i', 'subport']
run_command(cmd, display_cmd=verbose)
#
# 'pfc' group ("show pfc ...")
#
@cli.group(cls=clicommon.AliasedGroup)
def pfc():
"""Show details of the priority-flow-control (pfc) """
pass
# 'counters' subcommand ("show interfaces pfccounters")
@pfc.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def counters(namespace, display, verbose):
"""Show pfc counters"""
cmd = ['pfcstat', '-s', str(display)]
if namespace is not None:
cmd += ['-n', str(namespace)]
run_command(cmd, display_cmd=verbose)
@pfc.command()
@click.argument('interface', type=click.STRING, required=False)
@multi_asic_util.multi_asic_click_option_namespace
def priority(interface, namespace):
"""Show pfc priority"""
cmd = ['pfc', 'show', 'priority']
if interface is not None and clicommon.get_interface_naming_mode() == "alias":
interface = iface_alias_converter.alias_to_name(interface)
if interface is not None:
cmd += [str(interface)]
if namespace is not None:
cmd += ['-n', str(namespace)]
run_command(cmd)
@pfc.command()
@click.argument('interface', type=click.STRING, required=False)
@multi_asic_util.multi_asic_click_option_namespace
def asymmetric(interface, namespace):
"""Show asymmetric pfc"""
cmd = ['pfc', 'show', 'asymmetric']
if interface is not None and clicommon.get_interface_naming_mode() == "alias":
interface = iface_alias_converter.alias_to_name(interface)
if interface is not None:
cmd += [str(interface)]
if namespace is not None:
cmd += ['-n', str(namespace)]
run_command(cmd)
# 'pfcwd' subcommand ("show pfcwd...")
@cli.group(cls=clicommon.AliasedGroup)
def pfcwd():
"""Show details of the pfc watchdog """
pass
@pfcwd.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def config(namespace, display, verbose):
"""Show pfc watchdog config"""
cmd = ['pfcwd', 'show', 'config', '-d', str(display)]
if namespace is not None:
cmd += ['-n', str(namespace)]
run_command(cmd, display_cmd=verbose)
@pfcwd.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def stats(namespace, display, verbose):
"""Show pfc watchdog stats"""
cmd = ['pfcwd', 'show', 'stats', '-d', str(display)]
if namespace is not None:
cmd += ['-n', str(namespace)]
run_command(cmd, display_cmd=verbose)
#
# 'watermark' group ("show watermark telemetry interval")
#
@cli.group(cls=clicommon.AliasedGroup)
def watermark():
"""Show details of watermark """
pass
@watermark.group()
def telemetry():
"""Show watermark telemetry info"""
pass
@telemetry.command('interval')
def show_tm_interval():
"""Show telemetry interval"""
command = ['watermarkcfg', '--show-interval']
run_command(command)
#
# 'queue' group ("show queue ...")
#
@cli.group(cls=clicommon.AliasedGroup)
def queue():
"""Show details of the queues """
pass
# 'counters' subcommand ("show queue counters")
@queue.command()
@click.argument('interfacename', required=False)
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.option('--json', is_flag=True, help="JSON output")
@click.option('--voq', is_flag=True, help="VOQ counters")
@click.option('--nonzero', is_flag=True, help="Non Zero Counters")
def counters(interfacename, namespace, display, verbose, json, voq, nonzero):
"""Show queue counters"""
cmd = ["queuestat"]
if interfacename is not None:
if clicommon.get_interface_naming_mode() == "alias":
interfacename = iface_alias_converter.alias_to_name(interfacename)
if interfacename is not None:
cmd += ['-p', str(interfacename)]
if namespace is not None:
cmd += ['-n', str(namespace)]
if json:
cmd += ["-j"]
if voq:
cmd += ["-V"]
if nonzero:
cmd += ["-nz"]
run_command(cmd, display_cmd=verbose)
#
# 'watermarks' subgroup ("show queue watermarks ...")
#
@queue.group()
def watermark():
"""Show user WM for queues"""
pass
# 'unicast' subcommand ("show queue watermarks unicast")
@watermark.command('unicast')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def wm_q_uni(namespace):
"""Show user WM for unicast queues"""
command = ['watermarkstat', '-t', 'q_shared_uni']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
# 'multicast' subcommand ("show queue watermarks multicast")
@watermark.command('multicast')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def wm_q_multi(namespace):
"""Show user WM for multicast queues"""
command = ['watermarkstat', '-t', 'q_shared_multi']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
# 'all' subcommand ("show queue watermarks all")
@watermark.command('all')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def wm_q_all(namespace):
"""Show user WM for all queues"""
command = ['watermarkstat', '-t', 'q_shared_all']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
#
# 'persistent-watermarks' subgroup ("show queue persistent-watermarks ...")
#
@queue.group(name='persistent-watermark')
def persistent_watermark():
"""Show persistent WM for queues"""
pass
# 'unicast' subcommand ("show queue persistent-watermarks unicast")
@persistent_watermark.command('unicast')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def pwm_q_uni(namespace):
"""Show persistent WM for unicast queues"""
command = ['watermarkstat', '-p', '-t', 'q_shared_uni']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
# 'multicast' subcommand ("show queue persistent-watermarks multicast")
@persistent_watermark.command('multicast')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def pwm_q_multi(namespace):
"""Show persistent WM for multicast queues"""
command = ['watermarkstat', '-p', '-t', 'q_shared_multi']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
# 'all' subcommand ("show queue persistent-watermarks all")
@persistent_watermark.command('all')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def pwm_q_all(namespace):
"""Show persistent WM for all queues"""
command = ['watermarkstat', '-p', '-t', 'q_shared_all']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
#
# 'priority-group' group ("show priority-group ...")
#
@cli.group(name='priority-group', cls=clicommon.AliasedGroup)
def priority_group():
"""Show details of the PGs """
@priority_group.group()
def watermark():
"""Show priority-group user WM"""
pass
@watermark.command('headroom')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def wm_pg_headroom(namespace):
"""Show user headroom WM for pg"""
command = ['watermarkstat', '-t', 'pg_headroom']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
@watermark.command('shared')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def wm_pg_shared(namespace):
"""Show user shared WM for pg"""
command = ['watermarkstat', '-t', 'pg_shared']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
@priority_group.group()
def drop():
"""Show priority-group"""
pass
@drop.command('counters')
@multi_asic_util.multi_asic_click_option_namespace
def pg_drop_counters(namespace):
"""Show dropped packets for priority-group"""
command = ['pg-drop', '-c', 'show']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
@priority_group.group(name='persistent-watermark')
def persistent_watermark():
"""Show priority-group persistent WM"""
pass
@persistent_watermark.command('headroom')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def pwm_pg_headroom(namespace):
"""Show persistent headroom WM for pg"""
command = ['watermarkstat', '-p', '-t', 'pg_headroom']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
@persistent_watermark.command('shared')
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def pwm_pg_shared(namespace):
"""Show persistent shared WM for pg"""
command = ['watermarkstat', '-p', '-t', 'pg_shared']
if namespace is not None:
command += ['-n', str(namespace)]
run_command(command)
#
# 'buffer_pool' group ("show buffer_pool ...")
#
@cli.group(name='buffer_pool', cls=clicommon.AliasedGroup)
def buffer_pool():