forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[asymmetric pfc]: Implement CLI utility for asymmetric PFC (sonic-net…
…#229) Signed-off-by: Volodymyr Samotiy <volodymyrs@mellanox.com>
- Loading branch information
1 parent
c14d917
commit 04a62dd
Showing
6 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters