Skip to content

Commit 2a2bd9f

Browse files
committed
sonic-utilities: WRED stats feature changes on sonic-utilities
* New script for wredstat CLI commands * portstat script updated to accomodate WRED port stats * counterpoll script updated to support wredport and wredqueue counters * CLi to script mapping changes * UT for the new script changes * CLI command reference document updated Signed-off-by: rpmarvell <rperumal@marvell.com>
1 parent 3a9995b commit 2a2bd9f

File tree

14 files changed

+2439
-8
lines changed

14 files changed

+2439
-8
lines changed

clear/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,16 @@ def clear_pwm_pg_shared():
261261

262262
@cli.group()
263263
def queue():
264-
"""Clear queue WM"""
264+
"""Clear queue"""
265265
pass
266266

267+
@queue.command()
268+
def wredcounters():
269+
"""Clear queue wredcounters"""
270+
command = ['wredstat', '-c']
271+
run_command(command)
272+
273+
267274
@queue.group()
268275
def watermark():
269276
"""Clear queue user WM. One does not simply clear WM, root is required"""

counterpoll/main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,72 @@ def disable(ctx):
382382
fc_info['FLEX_COUNTER_STATUS'] = 'disable'
383383
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "FLOW_CNT_ROUTE", fc_info)
384384

385+
# WRED queue counter commands
386+
@cli.group()
387+
@click.pass_context
388+
def wredqueue(ctx):
389+
""" WRED queue counter commands """
390+
ctx.obj = ConfigDBConnector()
391+
ctx.obj.connect()
392+
393+
@wredqueue.command()
394+
@click.argument('poll_interval', type=click.IntRange(100, 30000))
395+
@click.pass_context
396+
def interval(ctx, poll_interval):
397+
""" Set wred queue counter query interval """
398+
wred_queue_info = {}
399+
wred_queue_info['POLL_INTERVAL'] = poll_interval
400+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
401+
402+
@wredqueue.command()
403+
@click.pass_context
404+
def enable(ctx):
405+
""" Enable wred queue counter query """
406+
wred_queue_info = {}
407+
wred_queue_info['FLEX_COUNTER_STATUS'] = 'enable'
408+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
409+
410+
@wredqueue.command()
411+
@click.pass_context
412+
def disable(ctx):
413+
""" Disable wred queue counter query """
414+
wred_queue_info = {}
415+
wred_queue_info['FLEX_COUNTER_STATUS'] = 'disable'
416+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
417+
418+
# WRED port counter commands
419+
@cli.group()
420+
@click.pass_context
421+
def wredport(ctx):
422+
""" WRED port counter commands """
423+
ctx.obj = ConfigDBConnector()
424+
ctx.obj.connect()
425+
426+
@wredport.command()
427+
@click.argument('poll_interval', type=click.IntRange(100, 30000))
428+
@click.pass_context
429+
def interval(ctx, poll_interval):
430+
""" Set wred port counter query interval """
431+
wred_port_info = {}
432+
wred_port_info['POLL_INTERVAL'] = poll_interval
433+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
434+
435+
@wredport.command()
436+
@click.pass_context
437+
def enable(ctx):
438+
""" Enable wred port counter query """
439+
wred_port_info = {}
440+
wred_port_info['FLEX_COUNTER_STATUS'] = 'enable'
441+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
442+
443+
@wredport.command()
444+
@click.pass_context
445+
def disable(ctx):
446+
""" Disable wred port counter query """
447+
wred_port_info = {}
448+
wred_port_info['FLEX_COUNTER_STATUS'] = 'disable'
449+
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
450+
385451
@cli.command()
386452
def show():
387453
""" Show the counter configuration """
@@ -399,6 +465,8 @@ def show():
399465
tunnel_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'TUNNEL')
400466
trap_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'FLOW_CNT_TRAP')
401467
route_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'FLOW_CNT_ROUTE')
468+
wred_queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_QUEUE')
469+
wred_port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_PORT')
402470

403471
header = ("Type", "Interval (in ms)", "Status")
404472
data = []
@@ -427,6 +495,10 @@ def show():
427495
if route_info:
428496
data.append(["FLOW_CNT_ROUTE_STAT", route_info.get("POLL_INTERVAL", DEFLT_10_SEC),
429497
route_info.get("FLEX_COUNTER_STATUS", DISABLE)])
498+
if wred_queue_info:
499+
data.append(["WRED_ECN_QUEUE_STAT", wred_queue_info.get("POLL_INTERVAL", DEFLT_10_SEC), wred_queue_info.get("FLEX_COUNTER_STATUS", DISABLE)])
500+
if wred_port_info:
501+
data.append(["WRED_ECN_PORT_STAT", wred_port_info.get("POLL_INTERVAL", DEFLT_1_SEC), wred_port_info.get("FLEX_COUNTER_STATUS", DISABLE)])
430502

431503
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
432504

doc/Command-Reference.md

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,15 +3784,16 @@ The "current-mode" subcommand is used to display current breakout mode for all i
37843784
37853785
**show interfaces counters**
37863786
3787-
This show command displays packet counters for all interfaces since the last time the counters were cleared. To display l3 counters "rif" subcommand can be used. There is no facility to display counters for one specific l2 interface. For l3 interfaces a single interface output mode is present. Optional argument "-a" provides two additional columns - RX-PPS and TX_PPS.
3788-
Optional argument "-p" specify a period (in seconds) with which to gather counters over.
3787+
This show command displays packet counters for all interfaces(except the "show interface detailed" command) since the last time the counters were cleared. To display l3 counters "rif" subcommand can be used. There is no facility to display counters for one specific l2 interface. For l3 interfaces a single interface output mode is present. Optional argument "-a" provides two additional columns - RX-PPS and TX_PPS.
3788+
Optional argument "-p" specify a period (in seconds) with which to gather counters over. To display the detailed per-interface counters "detailed <interface-name>" subcommand can be used.
37893789
37903790
- Usage:
37913791
```
37923792
show interfaces counters [-a|--printall] [-p|--period <period>]
37933793
show interfaces counters errors
37943794
show interfaces counters rates
37953795
show interfaces counters rif [-p|--period <period>] [-i <interface_name>]
3796+
show interfaces counters detailed <interface_name>
37963797
```
37973798
37983799
- Example:
@@ -3898,6 +3899,56 @@ Optionally, you can specify a period (in seconds) with which to gather counters
38983899
Ethernet24 U 173 16.09 KB/s 0.00% 0 0 0 169 11.39 KB/s 0.00% 0 0 0
38993900
```
39003901
3902+
The "detailed" subcommand is used to display more detailed interface counters. Along with tx/rx counters, it also displays the WRED drop counters.
3903+
3904+
- Example:
3905+
```
3906+
admin@sonic:~$ show interfaces counters detailed Ethernet8
3907+
Packets Received 64 Octets..................... 0
3908+
Packets Received 65-127 Octets................. 0
3909+
Packets Received 128-255 Octets................ 0
3910+
Packets Received 256-511 Octets................ 0
3911+
Packets Received 512-1023 Octets............... 0
3912+
Packets Received 1024-1518 Octets.............. 0
3913+
Packets Received 1519-2047 Octets.............. 0
3914+
Packets Received 2048-4095 Octets.............. 0
3915+
Packets Received 4096-9216 Octets.............. 0
3916+
Packets Received 9217-16383 Octets............. 0
3917+
3918+
Total Packets Received Without Errors.......... 0
3919+
Unicast Packets Received....................... 0
3920+
Multicast Packets Received..................... 0
3921+
Broadcast Packets Received..................... 0
3922+
3923+
Jabbers Received............................... N/A
3924+
Fragments Received............................. N/A
3925+
Undersize Received............................. 0
3926+
Overruns Received.............................. 0
3927+
3928+
Packets Transmitted 64 Octets.................. 0
3929+
Packets Transmitted 65-127 Octets.............. 0
3930+
Packets Transmitted 128-255 Octets............. 0
3931+
Packets Transmitted 256-511 Octets............. 0
3932+
Packets Transmitted 512-1023 Octets............ 0
3933+
Packets Transmitted 1024-1518 Octets........... 0
3934+
Packets Transmitted 1519-2047 Octets........... 0
3935+
Packets Transmitted 2048-4095 Octets........... 0
3936+
Packets Transmitted 4096-9216 Octets........... 0
3937+
Packets Transmitted 9217-16383 Octets.......... 0
3938+
3939+
Total Packets Transmitted Successfully......... 0
3940+
Unicast Packets Transmitted.................... 0
3941+
Multicast Packets Transmitted.................. 0
3942+
Broadcast Packets Transmitted.................. 0
3943+
3944+
WRED Green Dropped Packets..................... 0
3945+
WRED Yellow Dropped Packets.................... 0
3946+
WRED Red Dropped Packets....................... 0
3947+
WRED Total Dropped Packets..................... 0
3948+
3949+
Time Since Counters Last Cleared............... None
3950+
```
3951+
39013952
- NOTE: Interface counters can be cleared by the user with the following command:
39023953
39033954
```
@@ -7984,6 +8035,7 @@ This sub-section explains the following queue parameters that can be displayed u
79848035
2) queue watermark
79858036
3) priority-group watermark
79868037
4) queue persistent-watermark
8038+
5) queue wredcounters
79878039
79888040
79898041
**show queue counters**
@@ -8177,6 +8229,83 @@ This command displays the user persistet-watermark for the queues (Egress shared
81778229
admin@sonic:~$ sonic-clear priority-group drop counters
81788230
```
81798231
8232+
**show queue wredcounters**
8233+
8234+
This command displays wred-drop packet/byte and ecn-marked packet/byte counters for all queues of all ports or one specific-port given as arguement.
8235+
This command can be used to clear the counters for all queues of all ports. Note that port specific clear is not supported.
8236+
8237+
- Usage:
8238+
```
8239+
show queue wredcounters [<interface_name>]
8240+
```
8241+
8242+
- Example:
8243+
```
8244+
admin@sonic:~$ show queue wredcounters
8245+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8246+
--------- ----- -------------- --------------- --------------- ----------------
8247+
8248+
Ethernet0 UC0 0 0 0 0
8249+
Ethernet0 UC1 0 0 0 0
8250+
Ethernet0 UC2 0 0 0 0
8251+
Ethernet0 UC3 0 0 0 0
8252+
Ethernet0 UC4 0 0 0 0
8253+
Ethernet0 UC5 0 0 0 0
8254+
Ethernet0 UC6 0 0 0 0
8255+
Ethernet0 UC7 0 0 0 0
8256+
Ethernet0 UC8 0 0 0 0
8257+
Ethernet0 UC9 0 0 0 0
8258+
Ethernet0 MC0 0 0 0 0
8259+
Ethernet0 MC1 0 0 0 0
8260+
Ethernet0 MC2 0 0 0 0
8261+
Ethernet0 MC3 0 0 0 0
8262+
Ethernet0 MC4 0 0 0 0
8263+
Ethernet0 MC5 0 0 0 0
8264+
Ethernet0 MC6 0 0 0 0
8265+
Ethernet0 MC7 0 0 0 0
8266+
Ethernet0 MC8 0 0 0 0
8267+
Ethernet0 MC9 0 0 0 0
8268+
8269+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8270+
--------- ----- -------------- --------------- --------------- ----------------
8271+
8272+
Ethernet4 UC0 0 0 0 0
8273+
Ethernet4 UC1 0 0 0 0
8274+
Ethernet4 UC2 0 0 0 0
8275+
Ethernet4 UC3 0 0 0 0
8276+
Ethernet4 UC4 0 0 0 0
8277+
Ethernet4 UC5 0 0 0 0
8278+
Ethernet4 UC6 0 0 0 0
8279+
Ethernet4 UC7 0 0 0 0
8280+
Ethernet4 UC8 0 0 0 0
8281+
Ethernet4 UC9 0 0 0 0
8282+
Ethernet4 MC0 0 0 0 0
8283+
Ethernet4 MC1 0 0 0 0
8284+
Ethernet4 MC2 0 0 0 0
8285+
Ethernet4 MC3 0 0 0 0
8286+
Ethernet4 MC4 0 0 0 0
8287+
Ethernet4 MC5 0 0 0 0
8288+
Ethernet4 MC6 0 0 0 0
8289+
Ethernet4 MC7 0 0 0 0
8290+
Ethernet4 MC8 0 0 0 0
8291+
Ethernet4 MC9 0 0 0 0
8292+
8293+
...
8294+
```
8295+
8296+
Optionally, you can specify an interface name in order to display only that particular interface
8297+
8298+
- Example:
8299+
```
8300+
admin@sonic:~$ show queue wredcounters Ethernet72
8301+
```
8302+
8303+
- NOTE: Queue counters can be cleared by the user with the following command:
8304+
```
8305+
admin@sonic:~$ sonic-clear queue wredcounters
8306+
```
8307+
8308+
81808309
#### Buffer Pool
81818310
81828311
This sub-section explains the following buffer pool parameters that can be displayed using "show buffer_pool" command.

scripts/portstat

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ NStats = namedtuple("NStats", "rx_ok, rx_err, rx_drop, rx_ovr, tx_ok,\
5353
tx_64, tx_65_127, tx_128_255, tx_256_511, tx_512_1023, tx_1024_1518, tx_1519_2047, tx_2048_4095, tx_4096_9216, tx_9217_16383,\
5454
tx_uca, tx_mca, tx_bca, tx_all,\
5555
rx_jbr, rx_frag, rx_usize, rx_ovrrun,\
56-
fec_corr, fec_uncorr, fec_symbol_err")
56+
fec_corr, fec_uncorr, fec_symbol_err,\
57+
wred_grn_drp_pkt, wred_ylw_drp_pkt, wred_red_drp_pkt, wred_tot_drp_pkt")
5758
header_all = ['IFACE', 'STATE', 'RX_OK', 'RX_BPS', 'RX_PPS', 'RX_UTIL', 'RX_ERR', 'RX_DRP', 'RX_OVR',
5859
'TX_OK', 'TX_BPS', 'TX_PPS', 'TX_UTIL', 'TX_ERR', 'TX_DRP', 'TX_OVR']
5960
header_std = ['IFACE', 'STATE', 'RX_OK', 'RX_BPS', 'RX_UTIL', 'RX_ERR', 'RX_DRP', 'RX_OVR',
@@ -70,7 +71,14 @@ RateStats = namedtuple("RateStats", ratestat_fields)
7071
The order and count of statistics mentioned below needs to be in sync with the values in portstat script
7172
So, any fields added/deleted in here should be reflected in portstat script also
7273
"""
73-
BUCKET_NUM = 45
74+
BUCKET_NUM = 49
75+
76+
wred_green_pkt_stat_capable = "False"
77+
wred_yellow_pkt_stat_capable = "False"
78+
wred_red_pkt_stat_capable = "False"
79+
wred_total_pkt_stat_capable = "False"
80+
is_wred_stats_reqd = True
81+
7482
counter_bucket_dict = {
7583
0:['SAI_PORT_STAT_IF_IN_UCAST_PKTS', 'SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS'],
7684
1:['SAI_PORT_STAT_IF_IN_ERRORS'],
@@ -116,7 +124,11 @@ counter_bucket_dict = {
116124
41:['SAI_PORT_STAT_IP_IN_RECEIVES'],
117125
42:['SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES'],
118126
43:['SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES'],
119-
44:['SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS']
127+
44:['SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS'],
128+
45:['SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS'],
129+
46:['SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS'],
130+
47:['SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS'],
131+
48:['SAI_PORT_STAT_WRED_DROPPED_PACKETS']
120132
}
121133

122134
STATUS_NA = 'N/A'
@@ -157,6 +169,32 @@ class Portstat(object):
157169
Collect the statisitics from all the asics present on the
158170
device and store in a dict
159171
"""
172+
global BUCKET_NUM
173+
174+
global wred_green_pkt_stat_capable
175+
global wred_yellow_pkt_stat_capable
176+
global wred_red_pkt_stat_capable
177+
global wred_total_pkt_stat_capable
178+
global is_wred_stats_reqd
179+
180+
wred_green_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_GREEN_DROP_COUNTER","isSupported")
181+
wred_yellow_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_YELLOW_DROP_COUNTER","isSupported")
182+
wred_red_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_RED_DROP_COUNTER","isSupported")
183+
wred_total_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_TOTAL_DROP_COUNTER","isSupported")
184+
185+
# Remove the unsupported stats from the counter dict
186+
if ((is_wred_stats_reqd == False) or (wred_green_pkt_stat_capable != "true")) and ('SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
187+
del counter_bucket_dict['SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS']
188+
BUCKET_NUM = (BUCKET_NUM - 1)
189+
if ((is_wred_stats_reqd == False) or (wred_yellow_pkt_stat_capable != "true")) and ('SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
190+
del counter_bucket_dict['SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS']
191+
BUCKET_NUM = (BUCKET_NUM - 1)
192+
if ((is_wred_stats_reqd == False) or (wred_red_pkt_stat_capable != "true")) and ('SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
193+
del counter_bucket_dict['SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS']
194+
BUCKET_NUM = (BUCKET_NUM - 1)
195+
if ((is_wred_stats_reqd == False) or (wred_total_pkt_stat_capable != "true")) and ('SAI_PORT_STAT_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
196+
del counter_bucket_dict['SAI_PORT_STAT_WRED_DROPPED_PACKETS']
197+
BUCKET_NUM = (BUCKET_NUM - 1)
160198

161199
cnstat_dict, ratestat_dict = self.get_cnstat()
162200
self.cnstat_dict.update(cnstat_dict)
@@ -170,6 +208,8 @@ class Portstat(object):
170208
"""
171209
Get the counters from specific table.
172210
"""
211+
212+
173213
fields = ["0"]*BUCKET_NUM
174214

175215
_, fvs = counter_table.get(PortCounter(), port)
@@ -400,9 +440,22 @@ class Portstat(object):
400440
print("Multicast Packets Transmitted.................. {}".format(ns_diff(cntr.tx_mca, old_cntr.tx_mca)))
401441
print("Broadcast Packets Transmitted.................. {}".format(ns_diff(cntr.tx_bca, old_cntr.tx_bca)))
402442

443+
if wred_green_pkt_stat_capable == "true" or wred_yellow_pkt_stat_capable == "true" or wred_red_pkt_stat_capable == "true" or wred_total_pkt_stat_capable == "true":
444+
print("")
445+
if wred_green_pkt_stat_capable == "true":
446+
print("WRED Green Dropped Packets..................... {}".format(ns_diff(cntr.wred_grn_drp_pkt, old_cntr.wred_grn_drp_pkt)))
447+
if wred_yellow_pkt_stat_capable == "true":
448+
print("WRED Yellow Dropped Packets.................... {}".format(ns_diff(cntr.wred_ylw_drp_pkt, old_cntr.wred_ylw_drp_pkt)))
449+
if wred_red_pkt_stat_capable == "true":
450+
print("WRED Red Dropped Packets....................... {}".format(ns_diff(cntr.wred_red_drp_pkt, old_cntr.wred_red_drp_pkt)))
451+
if wred_total_pkt_stat_capable == "true":
452+
print("WRED Total Dropped Packets..................... {}".format(ns_diff(cntr.wred_tot_drp_pkt, old_cntr.wred_tot_drp_pkt)))
453+
print("")
454+
403455
print("Time Since Counters Last Cleared............... " + str(cnstat_old_dict.get('time')))
404456

405457

458+
406459
def cnstat_diff_print(self, cnstat_new_dict, cnstat_old_dict,
407460
ratestat_dict, intf_list, use_json,
408461
print_all, errors_only, fec_stats_only,
@@ -632,6 +685,12 @@ Examples:
632685
namespace = None
633686
display_option = constants.DISPLAY_ALL
634687

688+
global is_wred_stats_reqd
689+
690+
if errors_only or rates_only or fec_stats_only:
691+
is_wred_stats_reqd = False
692+
693+
635694
portstat = Portstat(namespace, display_option)
636695
cnstat_dict, ratestat_dict = portstat.get_cnstat_dict()
637696

0 commit comments

Comments
 (0)