Skip to content
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

Add CLI support for configurable drop counters #688

Merged
merged 12 commits into from
Nov 19, 2019
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 dropcounter():
daall marked this conversation as resolved.
Show resolved Hide resolved
"""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 @@ -1591,6 +1591,79 @@ def incremental(file_name):
command = "acl-loader update incremental {}".format(file_name)
run_command(command)


#
# 'dropcounter' group ('config dropcounter ...')
#

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


#
# 'initialize_counter' subcommand ('config dropcounter initialize_counter')
#
@dropcounter.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 initialize_counter(counter_name, alias, group, counter_type, desc, reasons, verbose):
daall marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize 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_counter' subcommand ('config dropcounter delete_counter')
#
@dropcounter.command()
@click.argument("counter_name", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def delete_counter(counter_name, verbose):
daall marked this conversation as resolved.
Show resolved Hide resolved
"""Delete an existing drop counter"""
command = "dropconfig -c uninstall -n {}".format(counter_name)
daall marked this conversation as resolved.
Show resolved Hide resolved
run_command(command, display_cmd=verbose)


#
# 'add_reasons' subcommand ('config dropcounter add_reasons')
#
@dropcounter.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 dropcounter remove_reasons')
#
@dropcounter.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
191 changes: 191 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,193 @@ 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 dropcounter 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 dropcounter capabilities
```

- Examples:
```
admin@sonic:~$ show dropcounter capabilities
Counter Type Total
-------------------- -------
PORT_INGRESS_DROPS 3
PORT_EGRESS_DROPS 0
SWITCH_EGRESS_DROPS 2
SWITCH_INGRESS_DROPS 0

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 dropcounter configuration**

This command is used to show the current running configuration of the drop counters on this device.

- Usage:
```
show dropcounter configuration [-g <group name>]
```

- Examples:
```
admin@sonic:~$ show dropcounter 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 dropcounter 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 dropcounter 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 dropcounter counts [-g <group name>] [-t <counter type>]
```

- Example:
```
admin@sonic:~$ show dropcounter 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 dropcounter 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 dropcounter counts -t SWITCH_EGRESS_DROPS
DEVICE TX_LEGIT
------ --------
sonic 1000
```

### Drop Counters config commands

**config dropcounter initialize_counter**

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 dropcounter initialize_counter <counter name> <counter type> <reasons list> [-d <description>] [-g <group>] [-a <alias>]
```

- Example:
```
admin@sonic:~$ sudo config dropcounter initialize_counter DEBUG_2 PORT_INGRESS_DROPS [EXCEEDS_L2_MTU,DECAP_ERROR] -d "More port ingress drops" -g BAD -a BAD_DROPS
```

**config dropcounter 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 dropcounter add_reasons <counter name> <reasons list>
```

- Example:
```
admin@sonic:~$ sudo config dropcounter add_reasons DEBUG_2 [SIP_CLASS_E]
```

**config dropcounter remove_reasons**

This command is used to remove drop reasons from an already initialized counter.

- Usage:
```
admin@sonic:~$ sudo config dropcounter remove_reasons <counter name> <reasons list>
```

- Example:
```
admin@sonic:~$ sudo config dropcounter remove_reasons DEBUG_2 [SIP_CLASS_E]
```

**config dropcounter delete_counter**

This command is used to delete a drop counter.

- Usage:
```
admin@sonic:~$ sudo config dropcounter delete_counter <counter name>
```

- Example:
```
admin@sonic:~$ sudo config dropcounter delete_counter DEBUG_2
```

### Drop Counters clear commands

**sonic-clear dropcounter**

This comnmand is used to clear drop counters. This is done on a per-user basis.

- Usage:
```
admin@sonic:~$ sonic-clear dropcounter
```

- Example:
```
admin@sonic:~$ sonic-clear dropcounter
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