Skip to content

Commit 587e630

Browse files
daallyxieca
authored andcommitted
Add CLI support for configurable drop counters (sonic-net#688)
* 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 <[email protected]> * 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
1 parent 0ada5cf commit 587e630

File tree

13 files changed

+1363
-3
lines changed

13 files changed

+1363
-3
lines changed

clear/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def pfccounters():
194194
command = "pfcstat -c"
195195
run_command(command)
196196

197+
@cli.command()
198+
def dropcounters():
199+
"""Clear drop counters"""
200+
command = "dropstat -c clear"
201+
run_command(command)
202+
197203
#
198204
# 'clear watermarks
199205
#

config/main.py

+73
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,79 @@ def incremental(file_name):
16141614
command = "acl-loader update incremental {}".format(file_name)
16151615
run_command(command)
16161616

1617+
1618+
#
1619+
# 'dropcounters' group ('config dropcounters ...')
1620+
#
1621+
1622+
@config.group()
1623+
def dropcounters():
1624+
"""Drop counter related configuration tasks"""
1625+
pass
1626+
1627+
1628+
#
1629+
# 'install' subcommand ('config dropcounters install')
1630+
#
1631+
@dropcounters.command()
1632+
@click.argument("counter_name", type=str, required=True)
1633+
@click.argument("counter_type", type=str, required=True)
1634+
@click.argument("reasons", type=str, required=True)
1635+
@click.option("-a", "--alias", type=str, help="Alias for this counter")
1636+
@click.option("-g", "--group", type=str, help="Group for this counter")
1637+
@click.option("-d", "--desc", type=str, help="Description for this counter")
1638+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1639+
def install(counter_name, alias, group, counter_type, desc, reasons, verbose):
1640+
"""Install a new drop counter"""
1641+
command = "dropconfig -c install -n '{}' -t '{}' -r '{}'".format(counter_name, counter_type, reasons)
1642+
if alias:
1643+
command += " -a '{}'".format(alias)
1644+
if group:
1645+
command += " -g '{}'".format(group)
1646+
if desc:
1647+
command += " -d '{}'".format(desc)
1648+
1649+
run_command(command, display_cmd=verbose)
1650+
1651+
1652+
#
1653+
# 'delete' subcommand ('config dropcounters delete')
1654+
#
1655+
@dropcounters.command()
1656+
@click.argument("counter_name", type=str, required=True)
1657+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1658+
def delete(counter_name, verbose):
1659+
"""Delete an existing drop counter"""
1660+
command = "dropconfig -c uninstall -n {}".format(counter_name)
1661+
run_command(command, display_cmd=verbose)
1662+
1663+
1664+
#
1665+
# 'add_reasons' subcommand ('config dropcounters add_reasons')
1666+
#
1667+
@dropcounters.command()
1668+
@click.argument("counter_name", type=str, required=True)
1669+
@click.argument("reasons", type=str, required=True)
1670+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1671+
def add_reasons(counter_name, reasons, verbose):
1672+
"""Add reasons to an existing drop counter"""
1673+
command = "dropconfig -c add -n {} -r {}".format(counter_name, reasons)
1674+
run_command(command, display_cmd=verbose)
1675+
1676+
1677+
#
1678+
# 'remove_reasons' subcommand ('config dropcounters remove_reasons')
1679+
#
1680+
@dropcounters.command()
1681+
@click.argument("counter_name", type=str, required=True)
1682+
@click.argument("reasons", type=str, required=True)
1683+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1684+
def remove_reasons(counter_name, reasons, verbose):
1685+
"""Remove reasons from an existing drop counter"""
1686+
command = "dropconfig -c remove -n {} -r {}".format(counter_name, reasons)
1687+
run_command(command, display_cmd=verbose)
1688+
1689+
16171690
#
16181691
# 'ecn' command ('config ecn ...')
16191692
#

doc/Command-Reference.md

+189
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
* [BGP config commands](#bgp-config-commands)
3434
* [DHCP Relay](#dhcp-relay)
3535
* [DHCP Relay config commands](#dhcp-relay-config-commands)
36+
* [Drop Counters](#drop-counters)
37+
* [Drop Counter show commands](#drop-counters-show-commands)
38+
* [Drop Counter config commands](#drop-counters-config-commands)
39+
* [Drop Counter clear commands](#drop-counters-clear-commands)
3640
* [ECN](#ecn)
3741
* [ECN show commands](#ecn-show-commands)
3842
* [ECN config commands](#ecn-config-commands)
@@ -1739,6 +1743,191 @@ This command is used to delete a configured DHCP Relay Destination IP address fr
17391743
Go Back To [Beginning of the document](#) or [Beginning of this section](#dhcp-relay)
17401744
17411745
1746+
# Drop Counters
1747+
1748+
This section explains all the Configurable Drop Counters show commands and configuration options that are supported in SONiC.
1749+
1750+
### Drop Counters show commands
1751+
1752+
**show dropcounters capabilities**
1753+
1754+
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.
1755+
1756+
- Usage:
1757+
```
1758+
show dropcounters capabilities
1759+
```
1760+
1761+
- Examples:
1762+
```
1763+
admin@sonic:~$ show dropcounters capabilities
1764+
Counter Type Total
1765+
-------------------- -------
1766+
PORT_INGRESS_DROPS 3
1767+
SWITCH_EGRESS_DROPS 2
1768+
1769+
PORT_INGRESS_DROPS:
1770+
L2_ANY
1771+
SMAC_MULTICAST
1772+
SMAC_EQUALS_DMAC
1773+
INGRESS_VLAN_FILTER
1774+
EXCEEDS_L2_MTU
1775+
SIP_CLASS_E
1776+
SIP_LINK_LOCAL
1777+
DIP_LINK_LOCAL
1778+
UNRESOLVED_NEXT_HOP
1779+
DECAP_ERROR
1780+
1781+
SWITCH_EGRESS_DROPS:
1782+
L2_ANY
1783+
L3_ANY
1784+
A_CUSTOM_REASON
1785+
```
1786+
1787+
**show dropcounters configuration**
1788+
1789+
This command is used to show the current running configuration of the drop counters on this device.
1790+
1791+
- Usage:
1792+
```
1793+
show dropcounters configuration [-g <group name>]
1794+
```
1795+
1796+
- Examples:
1797+
```
1798+
admin@sonic:~$ show dropcounters configuration
1799+
Counter Alias Group Type Reasons Description
1800+
-------- -------- ----- ------------------ ------------------- --------------
1801+
DEBUG_0 RX_LEGIT LEGIT PORT_INGRESS_DROPS SMAC_EQUALS_DMAC Legitimate port-level RX pipeline drops
1802+
INGRESS_VLAN_FILTER
1803+
DEBUG_1 TX_LEGIT None SWITCH_EGRESS_DROPS EGRESS_VLAN_FILTER Legitimate switch-level TX pipeline drops
1804+
1805+
admin@sonic:~$ show dropcounters configuration -g LEGIT
1806+
Counter Alias Group Type Reasons Description
1807+
-------- -------- ----- ------------------ ------------------- --------------
1808+
DEBUG_0 RX_LEGIT LEGIT PORT_INGRESS_DROPS SMAC_EQUALS_DMAC Legitimate port-level RX pipeline drops
1809+
INGRESS_VLAN_FILTER
1810+
```
1811+
1812+
**show dropcounters counts**
1813+
1814+
This command is used to show the current statistics for the configured drop counters. Standard drop counters are displayed as well for convenience.
1815+
1816+
Because clear (see below) is handled on a per-user basis different users may see different drop counts.
1817+
1818+
- Usage:
1819+
```
1820+
show dropcounters counts [-g <group name>] [-t <counter type>]
1821+
```
1822+
1823+
- Example:
1824+
```
1825+
admin@sonic:~$ show dropcounters counts
1826+
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS RX_LEGIT
1827+
--------- ------- -------- ---------- -------- ---------- ---------
1828+
Ethernet0 U 10 100 0 0 20
1829+
Ethernet4 U 0 1000 0 0 100
1830+
Ethernet8 U 100 10 0 0 0
1831+
1832+
DEVICE TX_LEGIT
1833+
------ --------
1834+
sonic 1000
1835+
1836+
admin@sonic:~$ show dropcounters counts -g LEGIT
1837+
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS RX_LEGIT
1838+
--------- ------- -------- ---------- -------- ---------- ---------
1839+
Ethernet0 U 10 100 0 0 20
1840+
Ethernet4 U 0 1000 0 0 100
1841+
Ethernet8 U 100 10 0 0 0
1842+
1843+
admin@sonic:~$ show dropcounters counts -t SWITCH_EGRESS_DROPS
1844+
DEVICE TX_LEGIT
1845+
------ --------
1846+
sonic 1000
1847+
```
1848+
1849+
### Drop Counters config commands
1850+
1851+
**config dropcounters install**
1852+
1853+
This command is used to initialize a new drop counter. The user must specify a name, type, and initial list of drop reasons.
1854+
1855+
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.
1856+
1857+
- Usage:
1858+
```
1859+
admin@sonic:~$ sudo config dropcounters install <counter name> <counter type> <reasons list> [-d <description>] [-g <group>] [-a <alias>]
1860+
```
1861+
1862+
- Example:
1863+
```
1864+
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
1865+
```
1866+
1867+
**config dropcounters add_reasons**
1868+
1869+
This command is used to add drop reasons to an already initialized counter.
1870+
1871+
This command will fail if any of the specified drop reasons are not supported.
1872+
1873+
- Usage:
1874+
```
1875+
admin@sonic:~$ sudo config dropcounters add_reasons <counter name> <reasons list>
1876+
```
1877+
1878+
- Example:
1879+
```
1880+
admin@sonic:~$ sudo config dropcounters add_reasons DEBUG_2 [SIP_CLASS_E]
1881+
```
1882+
1883+
**config dropcounters remove_reasons**
1884+
1885+
This command is used to remove drop reasons from an already initialized counter.
1886+
1887+
- Usage:
1888+
```
1889+
admin@sonic:~$ sudo config dropcounters remove_reasons <counter name> <reasons list>
1890+
```
1891+
1892+
- Example:
1893+
```
1894+
admin@sonic:~$ sudo config dropcounters remove_reasons DEBUG_2 [SIP_CLASS_E]
1895+
```
1896+
1897+
**config dropcounters delete**
1898+
1899+
This command is used to delete a drop counter.
1900+
1901+
- Usage:
1902+
```
1903+
admin@sonic:~$ sudo config dropcounters delete <counter name>
1904+
```
1905+
1906+
- Example:
1907+
```
1908+
admin@sonic:~$ sudo config dropcounters delete DEBUG_2
1909+
```
1910+
1911+
### Drop Counters clear commands
1912+
1913+
**sonic-clear dropcounters**
1914+
1915+
This comnmand is used to clear drop counters. This is done on a per-user basis.
1916+
1917+
- Usage:
1918+
```
1919+
admin@sonic:~$ sonic-clear dropcounters
1920+
```
1921+
1922+
- Example:
1923+
```
1924+
admin@sonic:~$ sonic-clear dropcounters
1925+
Cleared drop counters
1926+
```
1927+
1928+
Go Back To [Beginning of the document](#) or [Beginning of this section](#drop-counters)
1929+
1930+
17421931
## ECN
17431932
17441933
This section explains all the Explicit Congestion Notification (ECN) show commands and ECN configuation options that are supported in SONiC.

0 commit comments

Comments
 (0)