diff --git a/config/main.py b/config/main.py index 2190c82fd8..364d8e50d1 100755 --- a/config/main.py +++ b/config/main.py @@ -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='', required=True) +@click.argument('interface_tx_err_threshold', metavar='', 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"): + 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='', 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 # @@ -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 @@ -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 ...') @@ -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='', 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}) + if __name__ == '__main__': config() diff --git a/show/main.py b/show/main.py index a11a20c7a2..37d0a1968e 100755 --- a/show/main.py +++ b/show/main.py @@ -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)