Skip to content

add the tx_err related commands #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
81 changes: 76 additions & 5 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,71 @@ def shutdown(ctx, interface_name):
elif interface_name.startswith("PortChannel"):
config_db.mod_entry("PORTCHANNEL", interface_name, {"admin_status": "down"})

#
# 'tx_error_threshold' subgroup
#

@interface.group()
@click.pass_context
def tx_error_threshold(ctx):
"""Set or del threshold of tx error statistics"""
pass

#
# 'set' subcommand
#
@tx_error_threshold.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_tx_err_threshold', metavar='<interface_tx_err_threshold>', required=True, type=int)
def set(ctx, interface_name, interface_tx_err_threshold):
"""Set threshold of tx error statistics"""
if interface_name is None:
ctx.fail("'interface_name' is None!")

config_db = ctx.obj['config_db']
if get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

if interface_name_is_valid(interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")

if interface_name.startswith("Ethernet"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to further check whether this port exists on this switch

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved.

config_db.set_entry("TX_ERR_CFG", (interface_name), {"tx_error_threshold": interface_tx_err_threshold})
else:
ctx.fail("Only Ethernet interfaces are supported")

#
# 'clear' subcommand
#
@tx_error_threshold.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
def clear(ctx, interface_name):
"""Clear threshold of tx error statistics"""
if interface_name is None:
ctx.fail("'interface_name' is None!")

config_db = ctx.obj["config_db"]
if get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

if interface_name_is_valid(interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")

if config_db.get_entry('TX_ERR_CFG', interface_name):
if interface_name.startswith("Ethernet"):
config_db.set_entry("TX_ERR_CFG", (interface_name), None)
else:
ctx.fail("Only Ethernet interfaces are supported")
else:
ctx.fail("Tx Error threshold hasn't been configured on the interface")


#
# 'speed' subcommand
#
Expand Down Expand Up @@ -952,9 +1017,6 @@ def add(ctx, interface_name, ip_addr):
config_db.set_entry("PORTCHANNEL_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
elif interface_name.startswith("Vlan"):
config_db.set_entry("VLAN_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
elif interface_name.startswith("Loopback"):
config_db.set_entry("LOOPBACK_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})


#
# 'del' subcommand
Expand All @@ -978,8 +1040,6 @@ def remove(ctx, interface_name, ip_addr):
config_db.set_entry("PORTCHANNEL_INTERFACE", (interface_name, ip_addr), None)
elif interface_name.startswith("Vlan"):
config_db.set_entry("VLAN_INTERFACE", (interface_name, ip_addr), None)
elif interface_name.startswith("Loopback"):
config_db.set_entry("LOOPBACK_INTERFACE", (interface_name, ip_addr), None)

#
# 'acl' group ('config acl ...')
Expand Down Expand Up @@ -1127,6 +1187,17 @@ def naming_mode_alias():
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
set_interface_naming_mode('alias')

#
# 'tx_error_stat_poll_period' subcommand ('config tx_error_stat_poll_period')
#
@config.command()
@click.argument('period', metavar='<period>', required=True, type=int)
def tx_error_stat_poll_period(period):
"""Set polling period of tx error statistics, 0 for disable, xxx for default"""
config_db = ConfigDBConnector()
config_db.connect()
config_db.set_entry("TX_ERR_CFG", ("GLOBAL_PERIOD"), {"tx_error_check_period": period})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if "period" is a valid number.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved.



if __name__ == '__main__':
config()
36 changes: 36 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,42 @@ def status(interfacename, verbose):
run_command(cmd, display_cmd=verbose)


@interfaces.command()
@click.argument('interfacename', required=False)
def tx_error(interfacename):
"""Show Interface tx_error information"""

state_db = SonicV2Connector(host='127.0.0.1')
state_db.connect(state_db.STATE_DB, False) # Make one attempt only
TABLE_NAME_SEPARATOR = '|'
prefix_statedb = "TX_ERR_STATE|"
_hash = '{}{}'.format(prefix_statedb, '*')
# DBInterface keys() method
txerr_keys = state_db.keys(state_db.STATE_DB, _hash)
appl_db = SonicV2Connector(host='127.0.0.1')
appl_db.connect(appl_db.APPL_DB, False)
prefix_appldb = "TX_ERR_APPL:"
_hash = '{}{}'.format(prefix_statedb, "*")
txerr_appl_keys = appl_db.keys(appl_db.APPL_DB, _hash)
table = []
for k in txerr_keys:
k = k.replace(prefix_statedb, "")
r = []
r.append(k)

r.append(state_db.get(state_db.STATE_DB, prefix_statedb + k, "tx_status"))
entry = appl_db.get_all(appl_db.APPL_DB, prefix_appldb + k)
if 'tx_error_stati' not in entry:
r.append("")
else:
r.append(entry['tx_error_stati'])

table.append(r)

header = ['Port', 'status', 'statistics']
click.echo(tabulate(table, header))


# 'counters' subcommand ("show interfaces counters")
@interfaces.group(invoke_without_command=True)
@click.option('-a', '--printall', is_flag=True)
Expand Down