diff --git a/config/main.py b/config/main.py index 7ce6cae9bf..ec752299ac 100755 --- a/config/main.py +++ b/config/main.py @@ -727,6 +727,28 @@ def ecn(profile, rmax, rmin, ymax, ymin, gmax, gmin, verbose): run_command(command, display_cmd=verbose) +# +# 'pfc' group +# + +@interface.group() +def pfc(): + """Set PFC configuration.""" + pass + + +# +# 'pfc asymmetric' command +# + +@pfc.command() +@click.argument('status', type=click.Choice(['on', 'off'])) +@click.argument('interface', type=click.STRING) +def asymmetric(status, interface): + """Set asymmetric PFC configuration.""" + run_command("pfc config asymmetric {0} {1}".format(status, interface)) + + # # 'platform' group # @@ -759,5 +781,6 @@ def interface_mode_alias(): alias_mode = "alias" set_interface_mode(alias_mode) + if __name__ == '__main__': cli() diff --git a/data/etc/bash_completion.d/pfc b/data/etc/bash_completion.d/pfc new file mode 100644 index 0000000000..652429afa5 --- /dev/null +++ b/data/etc/bash_completion.d/pfc @@ -0,0 +1,8 @@ +_pfc_completion() { + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _PFC_COMPLETE=complete $1 ) ) + return 0 +} + +complete -F _pfc_completion -o default pfc; diff --git a/pfc/__init__.py b/pfc/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pfc/main.py b/pfc/main.py new file mode 100644 index 0000000000..c2f6e0d31f --- /dev/null +++ b/pfc/main.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python + +import os +import click +import swsssdk +from tabulate import tabulate +from natsort import natsorted + + +def configPfcAsym(interface, pfc_asym): + """ + PFC handler to configure asymmentric PFC. + """ + + configdb = swsssdk.ConfigDBConnector() + configdb.connect() + + configdb.mod_entry("PORT", interface, {'pfc_asym': pfc_asym}) + + +def showPfcAsym(interface): + """ + PFC handler to display asymmetric PFC information. + """ + + i = {} + table = [] + key = [] + + header = ('Interface', 'Asymmetric') + + configdb = swsssdk.ConfigDBConnector() + configdb.connect() + + if interface: + db_keys = configdb.keys(configdb.CONFIG_DB, 'PORT|{0}'.format(interface)) + else: + db_keys = configdb.keys(configdb.CONFIG_DB, 'PORT|*') + + for i in db_keys or [None]: + if i: + key = i.split('|')[-1] + + if key and key.startswith('Ethernet'): + entry = configdb.get_entry('PORT', key) + table.append([key, entry.get('pfc_asym', 'N/A')]) + + sorted_table = natsorted(table) + + print '\n' + print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="") + print '\n' + + +@click.group() +def cli(): + """ + Utility entry point. + """ + pass + + +@cli.group() +def config(): + """Config PFC information""" + pass + + +@config.command() +@click.argument('status', type=click.Choice(['on', 'off'])) +@click.argument('interface', type=click.STRING) +def asymmetric(status, interface): + """Set asymmetric PFC configuration.""" + configPfcAsym(interface, status) + + +@cli.group() +def show(): + """Show PFC information""" + pass + + +@show.command() +@click.argument('interface', type=click.STRING, required=False) +def asymmetric(interface): + """Show asymmetric PFC information""" + showPfcAsym(interface) diff --git a/setup.py b/setup.py index 3f6a7f73ce..7144637a72 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ def get_test_suite(): 'debug', 'pfcwd', 'sfputil', + 'pfc', 'psuutil', 'show', 'sonic_installer', @@ -74,6 +75,7 @@ def get_test_suite(): 'debug = debug.main:cli', 'pfcwd = pfcwd.main:cli', 'sfputil = sfputil.main:cli', + 'pfc = pfc.main:cli', 'psuutil = psuutil.main:cli', 'show = show.main:cli', 'sonic-clear = clear.main:cli', diff --git a/show/main.py b/show/main.py index b779652efb..52e9ed850b 100755 --- a/show/main.py +++ b/show/main.py @@ -447,6 +447,30 @@ def counters(interfacename, clear, verbose): run_command(cmd, display_cmd=verbose) +# +# 'pfc' group ### +# + +@interfaces.group(cls=AliasedGroup, default_if_no_args=False) +def pfc(): + """Show PFC information""" + pass + + +# +# 'pfc status' command ### +# + +@pfc.command() +@click.argument('interface', type=click.STRING, required=False) +def status(interface): + """Show PFC information""" + if interface is None: + interface = "" + + run_command("pfc show asymmetric {0}".format(interface)) + + # # 'mac' command ("show mac ...") # @@ -1117,6 +1141,7 @@ def ecn(): proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) click.echo(proc.stdout.read()) + # # 'reboot-cause' command ("show reboot-cause") # @@ -1146,5 +1171,6 @@ def line(): cmd = "consutil show" run_command(cmd, display_cmd=verbose) + if __name__ == '__main__': cli()