Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -759,5 +781,6 @@ def interface_mode_alias():
alias_mode = "alias"
set_interface_mode(alias_mode)


if __name__ == '__main__':
cli()
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/pfc
Original file line number Diff line number Diff line change
@@ -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;
Empty file added pfc/__init__.py
Empty file.
87 changes: 87 additions & 0 deletions pfc/main.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_test_suite():
'debug',
'pfcwd',
'sfputil',
'pfc',
'psuutil',
'show',
'sonic_installer',
Expand Down Expand Up @@ -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',
Expand Down
26 changes: 26 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...")
#
Expand Down Expand Up @@ -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")
#
Expand Down Expand Up @@ -1146,5 +1171,6 @@ def line():
cmd = "consutil show"
run_command(cmd, display_cmd=verbose)


if __name__ == '__main__':
cli()