Skip to content

Commit eb034f9

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 3037959 commit eb034f9

File tree

14 files changed

+2451
-20
lines changed

14 files changed

+2451
-20
lines changed

clear/main.py

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

277277
@cli.group()
278278
def queue():
279-
"""Clear queue WM"""
279+
"""Clear queue"""
280280
pass
281281

282+
@queue.command()
283+
def wredcounters():
284+
"""Clear queue wredcounters"""
285+
command = ['wredstat', '-c']
286+
run_command(command)
287+
288+
282289
@queue.group()
283290
def watermark():
284291
"""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
@@ -4547,15 +4547,16 @@ The "current-mode" subcommand is used to display current breakout mode for all i
45474547

45484548
**show interfaces counters**
45494549

4550-
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.
4551-
Optional argument "-p" specify a period (in seconds) with which to gather counters over.
4550+
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.
4551+
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.
45524552

45534553
- Usage:
45544554
```
45554555
show interfaces counters [-a|--printall] [-p|--period <period>]
45564556
show interfaces counters errors
45574557
show interfaces counters rates
45584558
show interfaces counters rif [-p|--period <period>] [-i <interface_name>]
4559+
show interfaces counters detailed <interface_name>
45594560
```
45604561

45614562
- Example:
@@ -4661,6 +4662,56 @@ Optionally, you can specify a period (in seconds) with which to gather counters
46614662
Ethernet24 U 173 16.09 KB/s 0.00% 0 0 0 169 11.39 KB/s 0.00% 0 0 0
46624663
```
46634664

4665+
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.
4666+
4667+
- Example:
4668+
```
4669+
admin@sonic:~$ show interfaces counters detailed Ethernet8
4670+
Packets Received 64 Octets..................... 0
4671+
Packets Received 65-127 Octets................. 0
4672+
Packets Received 128-255 Octets................ 0
4673+
Packets Received 256-511 Octets................ 0
4674+
Packets Received 512-1023 Octets............... 0
4675+
Packets Received 1024-1518 Octets.............. 0
4676+
Packets Received 1519-2047 Octets.............. 0
4677+
Packets Received 2048-4095 Octets.............. 0
4678+
Packets Received 4096-9216 Octets.............. 0
4679+
Packets Received 9217-16383 Octets............. 0
4680+
4681+
Total Packets Received Without Errors.......... 0
4682+
Unicast Packets Received....................... 0
4683+
Multicast Packets Received..................... 0
4684+
Broadcast Packets Received..................... 0
4685+
4686+
Jabbers Received............................... N/A
4687+
Fragments Received............................. N/A
4688+
Undersize Received............................. 0
4689+
Overruns Received.............................. 0
4690+
4691+
Packets Transmitted 64 Octets.................. 0
4692+
Packets Transmitted 65-127 Octets.............. 0
4693+
Packets Transmitted 128-255 Octets............. 0
4694+
Packets Transmitted 256-511 Octets............. 0
4695+
Packets Transmitted 512-1023 Octets............ 0
4696+
Packets Transmitted 1024-1518 Octets........... 0
4697+
Packets Transmitted 1519-2047 Octets........... 0
4698+
Packets Transmitted 2048-4095 Octets........... 0
4699+
Packets Transmitted 4096-9216 Octets........... 0
4700+
Packets Transmitted 9217-16383 Octets.......... 0
4701+
4702+
Total Packets Transmitted Successfully......... 0
4703+
Unicast Packets Transmitted.................... 0
4704+
Multicast Packets Transmitted.................. 0
4705+
Broadcast Packets Transmitted.................. 0
4706+
4707+
WRED Green Dropped Packets..................... 0
4708+
WRED Yellow Dropped Packets.................... 0
4709+
WRED Red Dropped Packets....................... 0
4710+
WRED Total Dropped Packets..................... 0
4711+
4712+
Time Since Counters Last Cleared............... None
4713+
```
4714+
46644715
- NOTE: Interface counters can be cleared by the user with the following command:
46654716

46664717
```
@@ -8827,6 +8878,7 @@ This sub-section explains the following queue parameters that can be displayed u
88278878
2) queue watermark
88288879
3) priority-group watermark
88298880
4) queue persistent-watermark
8881+
5) queue wredcounters
88308882
88318883
88328884
**show queue counters**
@@ -9020,6 +9072,83 @@ This command displays the user persistet-watermark for the queues (Egress shared
90209072
admin@sonic:~$ sonic-clear priority-group drop counters
90219073
```
90229074
9075+
**show queue wredcounters**
9076+
9077+
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.
9078+
This command can be used to clear the counters for all queues of all ports. Note that port specific clear is not supported.
9079+
9080+
- Usage:
9081+
```
9082+
show queue wredcounters [<interface_name>]
9083+
```
9084+
9085+
- Example:
9086+
```
9087+
admin@sonic:~$ show queue wredcounters
9088+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
9089+
--------- ----- -------------- --------------- --------------- ----------------
9090+
9091+
Ethernet0 UC0 0 0 0 0
9092+
Ethernet0 UC1 0 0 0 0
9093+
Ethernet0 UC2 0 0 0 0
9094+
Ethernet0 UC3 0 0 0 0
9095+
Ethernet0 UC4 0 0 0 0
9096+
Ethernet0 UC5 0 0 0 0
9097+
Ethernet0 UC6 0 0 0 0
9098+
Ethernet0 UC7 0 0 0 0
9099+
Ethernet0 UC8 0 0 0 0
9100+
Ethernet0 UC9 0 0 0 0
9101+
Ethernet0 MC0 0 0 0 0
9102+
Ethernet0 MC1 0 0 0 0
9103+
Ethernet0 MC2 0 0 0 0
9104+
Ethernet0 MC3 0 0 0 0
9105+
Ethernet0 MC4 0 0 0 0
9106+
Ethernet0 MC5 0 0 0 0
9107+
Ethernet0 MC6 0 0 0 0
9108+
Ethernet0 MC7 0 0 0 0
9109+
Ethernet0 MC8 0 0 0 0
9110+
Ethernet0 MC9 0 0 0 0
9111+
9112+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
9113+
--------- ----- -------------- --------------- --------------- ----------------
9114+
9115+
Ethernet4 UC0 0 0 0 0
9116+
Ethernet4 UC1 0 0 0 0
9117+
Ethernet4 UC2 0 0 0 0
9118+
Ethernet4 UC3 0 0 0 0
9119+
Ethernet4 UC4 0 0 0 0
9120+
Ethernet4 UC5 0 0 0 0
9121+
Ethernet4 UC6 0 0 0 0
9122+
Ethernet4 UC7 0 0 0 0
9123+
Ethernet4 UC8 0 0 0 0
9124+
Ethernet4 UC9 0 0 0 0
9125+
Ethernet4 MC0 0 0 0 0
9126+
Ethernet4 MC1 0 0 0 0
9127+
Ethernet4 MC2 0 0 0 0
9128+
Ethernet4 MC3 0 0 0 0
9129+
Ethernet4 MC4 0 0 0 0
9130+
Ethernet4 MC5 0 0 0 0
9131+
Ethernet4 MC6 0 0 0 0
9132+
Ethernet4 MC7 0 0 0 0
9133+
Ethernet4 MC8 0 0 0 0
9134+
Ethernet4 MC9 0 0 0 0
9135+
9136+
...
9137+
```
9138+
9139+
Optionally, you can specify an interface name in order to display only that particular interface
9140+
9141+
- Example:
9142+
```
9143+
admin@sonic:~$ show queue wredcounters Ethernet72
9144+
```
9145+
9146+
- NOTE: Queue counters can be cleared by the user with the following command:
9147+
```
9148+
admin@sonic:~$ sonic-clear queue wredcounters
9149+
```
9150+
9151+
90239152
#### Buffer Pool
90249153
90259154
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)
@@ -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)