Skip to content

Commit c63e9ea

Browse files
authored
[trim]: Add Packet Trimming Drop Counters CLI (sonic-net#3993)
HLD: sonic-net/SONiC#2033 What I did Implemented CLI for Packet Trimming Drop Counters feature How I did it Integrated Packet Trimming Drop Counters interface into config and show CLI root How to verify it Run Packet Trimming CLI UTs Previous command output (if the output of a command-line utility has changed) admin@sonic:/home/admin# show interfaces counters trim Ethernet0 IFACE STATE TRIM_PKTS --------- ------- ----------- Ethernet0 U 100 New command output (if the output of a command-line utility has changed) admin@sonic:/home/admin# show interfaces counters trim Ethernet0 IFACE STATE TRIM_PKTS TRIM_TX_PKTS TRIM_DRP_PKTS --------- ------- ----------- -------------- --------------- Ethernet0 U 100 50 50
1 parent 50df9ea commit c63e9ea

33 files changed

+3125
-804
lines changed

clear/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ def srv6counters():
225225
command = ["srv6stat", "-c"]
226226
run_command(command)
227227

228+
229+
@cli.command()
230+
def switchcounters():
231+
"""Clear switch counters"""
232+
command = ["switchstat", "-c"]
233+
run_command(command)
234+
228235
#
229236
# 'clear watermarks
230237
#

counterpoll/main.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import click
2-
import json
3-
from flow_counter_util.route import exit_if_route_flow_counter_not_support
4-
from swsscommon.swsscommon import ConfigDBConnector
2+
import utilities_common.cli as clicommon
3+
54
from tabulate import tabulate
65
from sonic_py_common import device_info
6+
from flow_counter_util.route import exit_if_route_flow_counter_not_support
7+
from swsscommon.swsscommon import ConfigDBConnector
8+
from swsscommon.swsscommon import CFG_FLEX_COUNTER_TABLE_NAME as CFG_FLEX_COUNTER_TABLE
9+
710

811
BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
912
PORT_BUFFER_DROP = "PORT_BUFFER_DROP"
@@ -540,6 +543,56 @@ def disable(ctx): # noqa: F811
540543
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "SRV6", srv6_info)
541544

542545

546+
# Switch counter commands
547+
@cli.group()
548+
def switch():
549+
""" Switch counter commands """
550+
pass
551+
552+
553+
@switch.command()
554+
@clicommon.pass_db
555+
@click.argument("poll_interval", type=click.IntRange(1000, 60000))
556+
def interval(db, poll_interval): # noqa: F811
557+
""" Set switch counter query interval """
558+
table = CFG_FLEX_COUNTER_TABLE
559+
key = "SWITCH"
560+
561+
data = {
562+
"POLL_INTERVAL": poll_interval
563+
}
564+
565+
db.cfgdb.mod_entry(table, key, data)
566+
567+
568+
@switch.command()
569+
@clicommon.pass_db
570+
def enable(db): # noqa: F811
571+
""" Enable switch counter query """
572+
table = CFG_FLEX_COUNTER_TABLE
573+
key = "SWITCH"
574+
575+
data = {
576+
"FLEX_COUNTER_STATUS": ENABLE
577+
}
578+
579+
db.cfgdb.mod_entry(table, key, data)
580+
581+
582+
@switch.command()
583+
@clicommon.pass_db
584+
def disable(db): # noqa: F811
585+
""" Disable switch counter query """
586+
table = CFG_FLEX_COUNTER_TABLE
587+
key = "SWITCH"
588+
589+
data = {
590+
"FLEX_COUNTER_STATUS": DISABLE
591+
}
592+
593+
db.cfgdb.mod_entry(table, key, data)
594+
595+
543596
@cli.command()
544597
def show():
545598
""" Show the counter configuration """
@@ -561,6 +614,7 @@ def show():
561614
wred_queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_QUEUE')
562615
wred_port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_PORT')
563616
srv6_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'SRV6')
617+
switch_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'SWITCH')
564618

565619
header = ("Type", "Interval (in ms)", "Status")
566620
data = []
@@ -598,6 +652,12 @@ def show():
598652
if srv6_info:
599653
data.append(["SRV6_STAT", srv6_info.get("POLL_INTERVAL", DEFLT_10_SEC),
600654
srv6_info.get("FLEX_COUNTER_STATUS", DISABLE)])
655+
if switch_info:
656+
data.append([
657+
"SWITCH_STAT",
658+
switch_info.get("POLL_INTERVAL", DEFLT_60_SEC),
659+
switch_info.get("FLEX_COUNTER_STATUS", DISABLE)
660+
])
601661

602662
if is_dpu(configdb) and eni_info:
603663
data.append(["ENI_STAT", eni_info.get("POLL_INTERVAL", DEFLT_10_SEC),

doc/Command-Reference.md

Lines changed: 111 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
* [Radius](#radius)
170170
* [Radius show commands](#show-radius-commands)
171171
* [Radius config commands](#Radius-config-commands)
172+
* [Switch](#switch)
173+
* [Switch Show commands](#switch-show-commands)
174+
* [Switch Clear commands](#switch-clear-commands)
172175
* [sFlow](#sflow)
173176
* [sFlow Show commands](#sflow-show-commands)
174177
* [sFlow Config commands](#sflow-config-commands)
@@ -5213,6 +5216,10 @@ The "detailed" subcommand is used to display more detailed interface counters. A
52135216
WRED Red Dropped Packets....................... 0
52145217
WRED Total Dropped Packets..................... 0
52155218

5219+
Trimmed Packets................................ 0
5220+
Trimmed Sent Packets........................... 0
5221+
Trimmed Dropped Packets........................ 0
5222+
52165223
Time Since Counters Last Cleared............... None
52175224
```
52185225

@@ -5273,11 +5280,11 @@ The "trim" subcommand is used to display the interface packet trimming related s
52735280
- Example:
52745281
```
52755282
admin@sonic:~$ show interfaces counters trim
5276-
IFACE STATE TRIM_PKTS
5277-
---------- ------- -----------
5278-
Ethernet0 U 0
5279-
Ethernet8 U 100
5280-
Ethernet16 U 200
5283+
IFACE STATE TRIM_PKTS TRIM_TX_PKTS TRIM_DRP_PKTS
5284+
---------- ------- ----------- -------------- ---------------
5285+
Ethernet0 U 0 0 0
5286+
Ethernet8 U 100 100 0
5287+
Ethernet16 U 200 100 100
52815288
```
52825289

52835290
**show interfaces description**
@@ -9893,28 +9900,28 @@ This command can be used to clear the counters for all queues of all ports. Note
98939900
...
98949901

98959902
admin@sonic:~$ show queue counters --trim
9896-
Port TxQ Trim/pkts
9897-
--------- ----- -----------
9898-
Ethernet0 UC0 0
9899-
Ethernet0 UC1 0
9900-
Ethernet0 UC2 0
9901-
Ethernet0 UC3 0
9902-
Ethernet0 UC4 0
9903-
Ethernet0 UC5 0
9904-
Ethernet0 UC6 0
9905-
Ethernet0 UC7 0
9906-
Ethernet0 UC8 0
9907-
Ethernet0 UC9 0
9908-
Ethernet0 MC0 N/A
9909-
Ethernet0 MC1 N/A
9910-
Ethernet0 MC2 N/A
9911-
Ethernet0 MC3 N/A
9912-
Ethernet0 MC4 N/A
9913-
Ethernet0 MC5 N/A
9914-
Ethernet0 MC6 N/A
9915-
Ethernet0 MC7 N/A
9916-
Ethernet0 MC8 N/A
9917-
Ethernet0 MC9 N/A
9903+
Port TxQ Trim/pkts TrimSent/pkts TrimDrop/pkts
9904+
--------- ----- ----------- --------------- ---------------
9905+
Ethernet0 UC0 0 0 0
9906+
Ethernet0 UC1 100 100 0
9907+
Ethernet0 UC2 200 100 100
9908+
Ethernet0 UC3 300 300 0
9909+
Ethernet0 UC4 400 200 200
9910+
Ethernet0 UC5 500 500 0
9911+
Ethernet0 UC6 600 300 300
9912+
Ethernet0 UC7 700 700 0
9913+
Ethernet0 UC8 800 400 400
9914+
Ethernet0 UC9 900 900 0
9915+
Ethernet0 MC0 N/A N/A N/A
9916+
Ethernet0 MC1 N/A N/A N/A
9917+
Ethernet0 MC2 N/A N/A N/A
9918+
Ethernet0 MC3 N/A N/A N/A
9919+
Ethernet0 MC4 N/A N/A N/A
9920+
Ethernet0 MC5 N/A N/A N/A
9921+
Ethernet0 MC6 N/A N/A N/A
9922+
Ethernet0 MC7 N/A N/A N/A
9923+
Ethernet0 MC8 N/A N/A N/A
9924+
Ethernet0 MC9 N/A N/A N/A
99189925
```
99199926

99209927
Optionally, you can specify an interface name in order to display only that particular interface
@@ -10328,6 +10335,83 @@ This command is to config the radius server for various parameter listed.
1032810335
timeout Specify RADIUS server global timeout <1 - 60>
1032910336

1033010337
```
10338+
10339+
# Switch
10340+
10341+
This section explains the various show, configuration and clear commands available for users.
10342+
10343+
### Switch Show commands
10344+
10345+
This subsection explains how to display switch configuration or stats.
10346+
10347+
**show switch counters**
10348+
10349+
This command displays switch stats.
10350+
10351+
- Usage:
10352+
```bash
10353+
show switch counters [OPTIONS]
10354+
show switch counters all [OPTIONS]
10355+
show switch counters trim [OPTIONS]
10356+
show switch counters detailed [OPTIONS]
10357+
```
10358+
10359+
- Options:
10360+
- _-p,--period_: display stats over a specified period (in seconds)
10361+
- _-d,--display_: show internal interfaces
10362+
- _-n,--namespace_: namespace name or all
10363+
- _-j,--json_: display in JSON format
10364+
- _-v,--verbose_: enable verbose output
10365+
10366+
- Example:
10367+
```bash
10368+
admin@sonic:~$ show switch counters
10369+
TrimSent/pkts TrimDrop/pkts
10370+
--------------- ---------------
10371+
100 100
10372+
10373+
admin@sonic:~$ show switch counters all
10374+
TrimSent/pkts TrimDrop/pkts
10375+
--------------- ---------------
10376+
100 100
10377+
10378+
admin@sonic:~$ show switch counters trim
10379+
TrimSent/pkts TrimDrop/pkts
10380+
--------------- ---------------
10381+
100 100
10382+
10383+
admin@sonic:~$ show switch counters detailed
10384+
Trimmed Sent Packets........................... 100
10385+
Trimmed Dropped Packets........................ 100
10386+
10387+
admin@sonic:~$ show switch counters --json
10388+
{
10389+
"trim_drop": "100",
10390+
"trim_sent": "100"
10391+
}
10392+
```
10393+
10394+
### Switch Clear commands
10395+
10396+
This subsection explains how to clear switch stats.
10397+
10398+
**sonic-clear switchcounters**
10399+
10400+
This command is used to clear switch counters.
10401+
10402+
- Usage:
10403+
```bash
10404+
sonic-clear switchcounters
10405+
```
10406+
10407+
- Examples:
10408+
```bash
10409+
admin@sonic:~$ sonic-clear switchcounters
10410+
Cleared switch counters
10411+
```
10412+
10413+
Go Back To [Beginning of the document](#) or [Beginning of this section](#switch)
10414+
1033110415
## sFlow
1033210416

1033310417
### sFlow Show commands

0 commit comments

Comments
 (0)