Skip to content

Commit

Permalink
Add CLI support for configurable drop counters (sonic-net#688)
Browse files Browse the repository at this point in the history
* Add CLI support for configurable drop counters
- Adds dropconfig script to configure drop counters
- Adds dropstat script to show and clear drop counters
- Adds handlers for drop counters to show, config, and sonic-clear

Signed-off-by: Danny Allen <daall@microsoft.com>

* Update command naming

* Add safety check for unsupported drop counters/reasons

* Make drop reasons more easily readable

* Respond to community feedback

* Update test to match command

* Add reference for show commands

* Finish command reference

* Fix error messages

* Update command name

* Make subcommands less verbose

* Add safety check for number of counters in use
  • Loading branch information
daall authored and yxieca committed Nov 19, 2019
1 parent 0ada5cf commit 587e630
Show file tree
Hide file tree
Showing 13 changed files with 1,363 additions and 3 deletions.
6 changes: 6 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def pfccounters():
command = "pfcstat -c"
run_command(command)

@cli.command()
def dropcounters():
"""Clear drop counters"""
command = "dropstat -c clear"
run_command(command)

#
# 'clear watermarks
#
Expand Down
73 changes: 73 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,79 @@ def incremental(file_name):
command = "acl-loader update incremental {}".format(file_name)
run_command(command)


#
# 'dropcounters' group ('config dropcounters ...')
#

@config.group()
def dropcounters():
"""Drop counter related configuration tasks"""
pass


#
# 'install' subcommand ('config dropcounters install')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.argument("counter_type", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option("-a", "--alias", type=str, help="Alias for this counter")
@click.option("-g", "--group", type=str, help="Group for this counter")
@click.option("-d", "--desc", type=str, help="Description for this counter")
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def install(counter_name, alias, group, counter_type, desc, reasons, verbose):
"""Install a new drop counter"""
command = "dropconfig -c install -n '{}' -t '{}' -r '{}'".format(counter_name, counter_type, reasons)
if alias:
command += " -a '{}'".format(alias)
if group:
command += " -g '{}'".format(group)
if desc:
command += " -d '{}'".format(desc)

run_command(command, display_cmd=verbose)


#
# 'delete' subcommand ('config dropcounters delete')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def delete(counter_name, verbose):
"""Delete an existing drop counter"""
command = "dropconfig -c uninstall -n {}".format(counter_name)
run_command(command, display_cmd=verbose)


#
# 'add_reasons' subcommand ('config dropcounters add_reasons')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def add_reasons(counter_name, reasons, verbose):
"""Add reasons to an existing drop counter"""
command = "dropconfig -c add -n {} -r {}".format(counter_name, reasons)
run_command(command, display_cmd=verbose)


#
# 'remove_reasons' subcommand ('config dropcounters remove_reasons')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def remove_reasons(counter_name, reasons, verbose):
"""Remove reasons from an existing drop counter"""
command = "dropconfig -c remove -n {} -r {}".format(counter_name, reasons)
run_command(command, display_cmd=verbose)


#
# 'ecn' command ('config ecn ...')
#
Expand Down
189 changes: 189 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
* [BGP config commands](#bgp-config-commands)
* [DHCP Relay](#dhcp-relay)
* [DHCP Relay config commands](#dhcp-relay-config-commands)
* [Drop Counters](#drop-counters)
* [Drop Counter show commands](#drop-counters-show-commands)
* [Drop Counter config commands](#drop-counters-config-commands)
* [Drop Counter clear commands](#drop-counters-clear-commands)
* [ECN](#ecn)
* [ECN show commands](#ecn-show-commands)
* [ECN config commands](#ecn-config-commands)
Expand Down Expand Up @@ -1739,6 +1743,191 @@ This command is used to delete a configured DHCP Relay Destination IP address fr
Go Back To [Beginning of the document](#) or [Beginning of this section](#dhcp-relay)
# Drop Counters
This section explains all the Configurable Drop Counters show commands and configuration options that are supported in SONiC.
### Drop Counters show commands
**show dropcounters capabilities**
This command is used to show the drop counter capabilities that are available on this device. It displays the total number of drop counters that can be configured on this device as well as the drop reasons that can be configured for the counters.
- Usage:
```
show dropcounters capabilities
```
- Examples:
```
admin@sonic:~$ show dropcounters capabilities
Counter Type Total
-------------------- -------
PORT_INGRESS_DROPS 3
SWITCH_EGRESS_DROPS 2

PORT_INGRESS_DROPS:
L2_ANY
SMAC_MULTICAST
SMAC_EQUALS_DMAC
INGRESS_VLAN_FILTER
EXCEEDS_L2_MTU
SIP_CLASS_E
SIP_LINK_LOCAL
DIP_LINK_LOCAL
UNRESOLVED_NEXT_HOP
DECAP_ERROR

SWITCH_EGRESS_DROPS:
L2_ANY
L3_ANY
A_CUSTOM_REASON
```
**show dropcounters configuration**
This command is used to show the current running configuration of the drop counters on this device.
- Usage:
```
show dropcounters configuration [-g <group name>]
```
- Examples:
```
admin@sonic:~$ show dropcounters configuration
Counter Alias Group Type Reasons Description
-------- -------- ----- ------------------ ------------------- --------------
DEBUG_0 RX_LEGIT LEGIT PORT_INGRESS_DROPS SMAC_EQUALS_DMAC Legitimate port-level RX pipeline drops
INGRESS_VLAN_FILTER
DEBUG_1 TX_LEGIT None SWITCH_EGRESS_DROPS EGRESS_VLAN_FILTER Legitimate switch-level TX pipeline drops

admin@sonic:~$ show dropcounters configuration -g LEGIT
Counter Alias Group Type Reasons Description
-------- -------- ----- ------------------ ------------------- --------------
DEBUG_0 RX_LEGIT LEGIT PORT_INGRESS_DROPS SMAC_EQUALS_DMAC Legitimate port-level RX pipeline drops
INGRESS_VLAN_FILTER
```
**show dropcounters counts**
This command is used to show the current statistics for the configured drop counters. Standard drop counters are displayed as well for convenience.
Because clear (see below) is handled on a per-user basis different users may see different drop counts.
- Usage:
```
show dropcounters counts [-g <group name>] [-t <counter type>]
```
- Example:
```
admin@sonic:~$ show dropcounters counts
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS RX_LEGIT
--------- ------- -------- ---------- -------- ---------- ---------
Ethernet0 U 10 100 0 0 20
Ethernet4 U 0 1000 0 0 100
Ethernet8 U 100 10 0 0 0

DEVICE TX_LEGIT
------ --------
sonic 1000

admin@sonic:~$ show dropcounters counts -g LEGIT
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS RX_LEGIT
--------- ------- -------- ---------- -------- ---------- ---------
Ethernet0 U 10 100 0 0 20
Ethernet4 U 0 1000 0 0 100
Ethernet8 U 100 10 0 0 0

admin@sonic:~$ show dropcounters counts -t SWITCH_EGRESS_DROPS
DEVICE TX_LEGIT
------ --------
sonic 1000
```
### Drop Counters config commands
**config dropcounters install**
This command is used to initialize a new drop counter. The user must specify a name, type, and initial list of drop reasons.
This command will fail if the given name is already in use, if the type of counter is not supported, or if any of the specified drop reasons are not supported. It will also fail if all avaialble counters are already in use on the device.
- Usage:
```
admin@sonic:~$ sudo config dropcounters install <counter name> <counter type> <reasons list> [-d <description>] [-g <group>] [-a <alias>]
```
- Example:
```
admin@sonic:~$ sudo config dropcounters install DEBUG_2 PORT_INGRESS_DROPS [EXCEEDS_L2_MTU,DECAP_ERROR] -d "More port ingress drops" -g BAD -a BAD_DROPS
```
**config dropcounters add_reasons**
This command is used to add drop reasons to an already initialized counter.
This command will fail if any of the specified drop reasons are not supported.
- Usage:
```
admin@sonic:~$ sudo config dropcounters add_reasons <counter name> <reasons list>
```
- Example:
```
admin@sonic:~$ sudo config dropcounters add_reasons DEBUG_2 [SIP_CLASS_E]
```
**config dropcounters remove_reasons**
This command is used to remove drop reasons from an already initialized counter.
- Usage:
```
admin@sonic:~$ sudo config dropcounters remove_reasons <counter name> <reasons list>
```
- Example:
```
admin@sonic:~$ sudo config dropcounters remove_reasons DEBUG_2 [SIP_CLASS_E]
```
**config dropcounters delete**
This command is used to delete a drop counter.
- Usage:
```
admin@sonic:~$ sudo config dropcounters delete <counter name>
```
- Example:
```
admin@sonic:~$ sudo config dropcounters delete DEBUG_2
```
### Drop Counters clear commands
**sonic-clear dropcounters**
This comnmand is used to clear drop counters. This is done on a per-user basis.
- Usage:
```
admin@sonic:~$ sonic-clear dropcounters
```
- Example:
```
admin@sonic:~$ sonic-clear dropcounters
Cleared drop counters
```
Go Back To [Beginning of the document](#) or [Beginning of this section](#drop-counters)
## ECN
This section explains all the Explicit Congestion Notification (ECN) show commands and ECN configuation options that are supported in SONiC.
Expand Down
Loading

0 comments on commit 587e630

Please sign in to comment.