Skip to content

Commit 989748b

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 <[email protected]>
1 parent 659ba24 commit 989748b

File tree

14 files changed

+2439
-8
lines changed

14 files changed

+2439
-8
lines changed

clear/main.py

+8-1
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

+72
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

+131-2
Original file line numberDiff line numberDiff line change
@@ -4190,15 +4190,16 @@ The "current-mode" subcommand is used to display current breakout mode for all i
41904190
41914191
**show interfaces counters**
41924192
4193-
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.
4194-
Optional argument "-p" specify a period (in seconds) with which to gather counters over.
4193+
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.
4194+
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.
41954195
41964196
- Usage:
41974197
```
41984198
show interfaces counters [-a|--printall] [-p|--period <period>]
41994199
show interfaces counters errors
42004200
show interfaces counters rates
42014201
show interfaces counters rif [-p|--period <period>] [-i <interface_name>]
4202+
show interfaces counters detailed <interface_name>
42024203
```
42034204
42044205
- Example:
@@ -4304,6 +4305,56 @@ Optionally, you can specify a period (in seconds) with which to gather counters
43044305
Ethernet24 U 173 16.09 KB/s 0.00% 0 0 0 169 11.39 KB/s 0.00% 0 0 0
43054306
```
43064307
4308+
The "detailed" subcommand is used to display more detailed interface counters. Along with tx/rx counters, it also displays the WRED drop counters that are supported on the platform.
4309+
4310+
- Example:
4311+
```
4312+
admin@sonic:~$ show interfaces counters detailed Ethernet8
4313+
Packets Received 64 Octets..................... 0
4314+
Packets Received 65-127 Octets................. 0
4315+
Packets Received 128-255 Octets................ 0
4316+
Packets Received 256-511 Octets................ 0
4317+
Packets Received 512-1023 Octets............... 0
4318+
Packets Received 1024-1518 Octets.............. 0
4319+
Packets Received 1519-2047 Octets.............. 0
4320+
Packets Received 2048-4095 Octets.............. 0
4321+
Packets Received 4096-9216 Octets.............. 0
4322+
Packets Received 9217-16383 Octets............. 0
4323+
4324+
Total Packets Received Without Errors.......... 0
4325+
Unicast Packets Received....................... 0
4326+
Multicast Packets Received..................... 0
4327+
Broadcast Packets Received..................... 0
4328+
4329+
Jabbers Received............................... N/A
4330+
Fragments Received............................. N/A
4331+
Undersize Received............................. 0
4332+
Overruns Received.............................. 0
4333+
4334+
Packets Transmitted 64 Octets.................. 0
4335+
Packets Transmitted 65-127 Octets.............. 0
4336+
Packets Transmitted 128-255 Octets............. 0
4337+
Packets Transmitted 256-511 Octets............. 0
4338+
Packets Transmitted 512-1023 Octets............ 0
4339+
Packets Transmitted 1024-1518 Octets........... 0
4340+
Packets Transmitted 1519-2047 Octets........... 0
4341+
Packets Transmitted 2048-4095 Octets........... 0
4342+
Packets Transmitted 4096-9216 Octets........... 0
4343+
Packets Transmitted 9217-16383 Octets.......... 0
4344+
4345+
Total Packets Transmitted Successfully......... 0
4346+
Unicast Packets Transmitted.................... 0
4347+
Multicast Packets Transmitted.................. 0
4348+
Broadcast Packets Transmitted.................. 0
4349+
4350+
WRED Green Dropped Packets..................... 0
4351+
WRED Yellow Dropped Packets.................... 0
4352+
WRED Red Dropped Packets....................... 0
4353+
WRED Total Dropped Packets..................... 0
4354+
4355+
Time Since Counters Last Cleared............... None
4356+
```
4357+
43074358
- NOTE: Interface counters can be cleared by the user with the following command:
43084359
43094360
```
@@ -8390,6 +8441,7 @@ This sub-section explains the following queue parameters that can be displayed u
83908441
2) queue watermark
83918442
3) priority-group watermark
83928443
4) queue persistent-watermark
8444+
5) queue wredcounters
83938445
83948446
83958447
**show queue counters**
@@ -8583,6 +8635,83 @@ This command displays the user persistet-watermark for the queues (Egress shared
85838635
admin@sonic:~$ sonic-clear priority-group drop counters
85848636
```
85858637
8638+
**show queue wredcounters**
8639+
8640+
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.
8641+
This command can be used to clear the counters for all queues of all ports. Note that port specific clear is not supported.
8642+
8643+
- Usage:
8644+
```
8645+
show queue wredcounters [<interface_name>]
8646+
```
8647+
8648+
- Example:
8649+
```
8650+
admin@sonic:~$ show queue wredcounters
8651+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8652+
--------- ----- -------------- --------------- --------------- ----------------
8653+
8654+
Ethernet0 UC0 0 0 0 0
8655+
Ethernet0 UC1 0 0 0 0
8656+
Ethernet0 UC2 0 0 0 0
8657+
Ethernet0 UC3 0 0 0 0
8658+
Ethernet0 UC4 0 0 0 0
8659+
Ethernet0 UC5 0 0 0 0
8660+
Ethernet0 UC6 0 0 0 0
8661+
Ethernet0 UC7 0 0 0 0
8662+
Ethernet0 UC8 0 0 0 0
8663+
Ethernet0 UC9 0 0 0 0
8664+
Ethernet0 MC0 0 0 0 0
8665+
Ethernet0 MC1 0 0 0 0
8666+
Ethernet0 MC2 0 0 0 0
8667+
Ethernet0 MC3 0 0 0 0
8668+
Ethernet0 MC4 0 0 0 0
8669+
Ethernet0 MC5 0 0 0 0
8670+
Ethernet0 MC6 0 0 0 0
8671+
Ethernet0 MC7 0 0 0 0
8672+
Ethernet0 MC8 0 0 0 0
8673+
Ethernet0 MC9 0 0 0 0
8674+
8675+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8676+
--------- ----- -------------- --------------- --------------- ----------------
8677+
8678+
Ethernet4 UC0 0 0 0 0
8679+
Ethernet4 UC1 0 0 0 0
8680+
Ethernet4 UC2 0 0 0 0
8681+
Ethernet4 UC3 0 0 0 0
8682+
Ethernet4 UC4 0 0 0 0
8683+
Ethernet4 UC5 0 0 0 0
8684+
Ethernet4 UC6 0 0 0 0
8685+
Ethernet4 UC7 0 0 0 0
8686+
Ethernet4 UC8 0 0 0 0
8687+
Ethernet4 UC9 0 0 0 0
8688+
Ethernet4 MC0 0 0 0 0
8689+
Ethernet4 MC1 0 0 0 0
8690+
Ethernet4 MC2 0 0 0 0
8691+
Ethernet4 MC3 0 0 0 0
8692+
Ethernet4 MC4 0 0 0 0
8693+
Ethernet4 MC5 0 0 0 0
8694+
Ethernet4 MC6 0 0 0 0
8695+
Ethernet4 MC7 0 0 0 0
8696+
Ethernet4 MC8 0 0 0 0
8697+
Ethernet4 MC9 0 0 0 0
8698+
8699+
...
8700+
```
8701+
8702+
Optionally, you can specify an interface name in order to display only that particular interface
8703+
8704+
- Example:
8705+
```
8706+
admin@sonic:~$ show queue wredcounters Ethernet72
8707+
```
8708+
8709+
- NOTE: Queue counters can be cleared by the user with the following command:
8710+
```
8711+
admin@sonic:~$ sonic-clear queue wredcounters
8712+
```
8713+
8714+
85868715
#### Buffer Pool
85878716
85888717
This sub-section explains the following buffer pool parameters that can be displayed using "show buffer_pool" command.

scripts/portstat

+62-3
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)
@@ -399,9 +439,22 @@ class Portstat(object):
399439
print("Multicast Packets Transmitted.................. {}".format(ns_diff(cntr['tx_mca'], old_cntr['tx_mca'])))
400440
print("Broadcast Packets Transmitted.................. {}".format(ns_diff(cntr['tx_bca'], old_cntr['tx_bca'])))
401441

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

404456

457+
405458
def cnstat_diff_print(self, cnstat_new_dict, cnstat_old_dict,
406459
ratestat_dict, intf_list, use_json,
407460
print_all, errors_only, fec_stats_only,
@@ -631,6 +684,12 @@ Examples:
631684
namespace = None
632685
display_option = constants.DISPLAY_ALL
633686

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

0 commit comments

Comments
 (0)