Skip to content

Commit a22be8b

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 Signed-off-by: rpmarvell <[email protected]>
1 parent 7443b9e commit a22be8b

File tree

9 files changed

+2263
-5
lines changed

9 files changed

+2263
-5
lines changed

clear/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ def clear_wm_q_all():
288288
command = ['watermarkstat', '-c', '-t', 'q_shared_all']
289289
run_command(command)
290290

291+
@queue.group(name='wredcounters')
292+
def wredcounters():
293+
"""Clear queue wredcounters"""
294+
command = "wredstat -c"
295+
run_command(command)
296+
291297
@queue.group(name='persistent-watermark')
292298
def persistent_watermark():
293299
"""Clear queue persistent WM. One does not simply clear WM, root is required"""

counterpoll/main.py

+74
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,74 @@ 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+
def wredqueue():
388+
""" WRED queue counter commands """
389+
390+
@wredqueue.command()
391+
@click.argument('poll_interval', type=click.IntRange(100, 30000))
392+
def interval(poll_interval):
393+
""" Set wred queue counter query interval """
394+
configdb = ConfigDBConnector()
395+
configdb.connect()
396+
wred_queue_info = {}
397+
if poll_interval is not None:
398+
wred_queue_info['POLL_INTERVAL'] = poll_interval
399+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
400+
401+
@wredqueue.command()
402+
def enable():
403+
""" Enable wred queue counter query """
404+
configdb = ConfigDBConnector()
405+
configdb.connect()
406+
wred_queue_info = {}
407+
wred_queue_info['FLEX_COUNTER_STATUS'] = 'enable'
408+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
409+
410+
@wredqueue.command()
411+
def disable():
412+
""" Disable wred queue counter query """
413+
configdb = ConfigDBConnector()
414+
configdb.connect()
415+
wred_queue_info = {}
416+
wred_queue_info['FLEX_COUNTER_STATUS'] = 'disable'
417+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_QUEUE", wred_queue_info)
418+
419+
# WRED port counter commands
420+
@cli.group()
421+
def wredport():
422+
""" WRED port counter commands """
423+
424+
@wredport.command()
425+
@click.argument('poll_interval', type=click.IntRange(100, 30000))
426+
def interval(poll_interval):
427+
""" Set wred port counter query interval """
428+
configdb = ConfigDBConnector()
429+
configdb.connect()
430+
wred_port_info = {}
431+
if poll_interval is not None:
432+
wred_port_info['POLL_INTERVAL'] = poll_interval
433+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
434+
435+
@wredport.command()
436+
def enable():
437+
""" Enable wred port counter query """
438+
configdb = ConfigDBConnector()
439+
configdb.connect()
440+
wred_port_info = {}
441+
wred_port_info['FLEX_COUNTER_STATUS'] = 'enable'
442+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
443+
444+
@wredport.command()
445+
def disable():
446+
""" Disable wred port counter query """
447+
configdb = ConfigDBConnector()
448+
configdb.connect()
449+
wred_port_info = {}
450+
wred_port_info['FLEX_COUNTER_STATUS'] = 'disable'
451+
configdb.mod_entry("FLEX_COUNTER_TABLE", "WRED_ECN_PORT", wred_port_info)
452+
385453
@cli.command()
386454
def show():
387455
""" Show the counter configuration """
@@ -399,6 +467,8 @@ def show():
399467
tunnel_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'TUNNEL')
400468
trap_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'FLOW_CNT_TRAP')
401469
route_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'FLOW_CNT_ROUTE')
470+
wred_queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_QUEUE')
471+
wred_port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'WRED_ECN_PORT')
402472

403473
header = ("Type", "Interval (in ms)", "Status")
404474
data = []
@@ -427,6 +497,10 @@ def show():
427497
if route_info:
428498
data.append(["FLOW_CNT_ROUTE_STAT", route_info.get("POLL_INTERVAL", DEFLT_10_SEC),
429499
route_info.get("FLEX_COUNTER_STATUS", DISABLE)])
500+
if wred_queue_info:
501+
data.append(["WRED_ECN_QUEUE_STAT", wred_queue_info.get("POLL_INTERVAL", DEFLT_10_SEC), wred_queue_info.get("FLEX_COUNTER_STATUS", DISABLE)])
502+
if wred_port_info:
503+
data.append(["WRED_ECN_PORT_STAT", wred_port_info.get("POLL_INTERVAL", DEFLT_1_SEC), wred_port_info.get("FLEX_COUNTER_STATUS", DISABLE)])
430504

431505
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
432506

doc/Command-Reference.md

+78
Original file line numberDiff line numberDiff line change
@@ -7984,6 +7984,7 @@ This sub-section explains the following queue parameters that can be displayed u
79847984
2) queue watermark
79857985
3) priority-group watermark
79867986
4) queue persistent-watermark
7987+
5) queue wredcounters
79877988
79887989
79897990
**show queue counters**
@@ -8177,6 +8178,83 @@ This command displays the user persistet-watermark for the queues (Egress shared
81778178
admin@sonic:~$ sonic-clear priority-group drop counters
81788179
```
81798180
8181+
**show queue wredcounters**
8182+
8183+
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.
8184+
This command can be used to clear the counters for all queues of all ports. Note that port specific clear is not supported.
8185+
8186+
- Usage:
8187+
```
8188+
show queue wredcounters [<interface_name>]
8189+
```
8190+
8191+
- Example:
8192+
```
8193+
admin@sonic:~$ show queue wredcounters
8194+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8195+
--------- ----- -------------- --------------- --------------- ----------------
8196+
8197+
Ethernet0 UC0 0 0 0 0
8198+
Ethernet0 UC1 0 0 0 0
8199+
Ethernet0 UC2 0 0 0 0
8200+
Ethernet0 UC3 0 0 0 0
8201+
Ethernet0 UC4 0 0 0 0
8202+
Ethernet0 UC5 0 0 0 0
8203+
Ethernet0 UC6 0 0 0 0
8204+
Ethernet0 UC7 0 0 0 0
8205+
Ethernet0 UC8 0 0 0 0
8206+
Ethernet0 UC9 0 0 0 0
8207+
Ethernet0 MC0 0 0 0 0
8208+
Ethernet0 MC1 0 0 0 0
8209+
Ethernet0 MC2 0 0 0 0
8210+
Ethernet0 MC3 0 0 0 0
8211+
Ethernet0 MC4 0 0 0 0
8212+
Ethernet0 MC5 0 0 0 0
8213+
Ethernet0 MC6 0 0 0 0
8214+
Ethernet0 MC7 0 0 0 0
8215+
Ethernet0 MC8 0 0 0 0
8216+
Ethernet0 MC9 0 0 0 0
8217+
8218+
Port TxQ WredDrp/pkts WredDrp/bytes EcnMarked/pkts EcnMarked/bytes
8219+
--------- ----- -------------- --------------- --------------- ----------------
8220+
8221+
Ethernet4 UC0 0 0 0 0
8222+
Ethernet4 UC1 0 0 0 0
8223+
Ethernet4 UC2 0 0 0 0
8224+
Ethernet4 UC3 0 0 0 0
8225+
Ethernet4 UC4 0 0 0 0
8226+
Ethernet4 UC5 0 0 0 0
8227+
Ethernet4 UC6 0 0 0 0
8228+
Ethernet4 UC7 0 0 0 0
8229+
Ethernet4 UC8 0 0 0 0
8230+
Ethernet4 UC9 0 0 0 0
8231+
Ethernet4 MC0 0 0 0 0
8232+
Ethernet4 MC1 0 0 0 0
8233+
Ethernet4 MC2 0 0 0 0
8234+
Ethernet4 MC3 0 0 0 0
8235+
Ethernet4 MC4 0 0 0 0
8236+
Ethernet4 MC5 0 0 0 0
8237+
Ethernet4 MC6 0 0 0 0
8238+
Ethernet4 MC7 0 0 0 0
8239+
Ethernet4 MC8 0 0 0 0
8240+
Ethernet4 MC9 0 0 0 0
8241+
8242+
...
8243+
```
8244+
8245+
Optionally, you can specify an interface name in order to display only that particular interface
8246+
8247+
- Example:
8248+
```
8249+
admin@sonic:~$ show queue wredcounters Ethernet72
8250+
```
8251+
8252+
- NOTE: Queue counters can be cleared by the user with the following command:
8253+
```
8254+
admin@sonic:~$ sonic-clear queue wredcounters
8255+
```
8256+
8257+
81808258
#### Buffer Pool
81818259
81828260
This sub-section explains the following buffer pool parameters that can be displayed using "show buffer_pool" command.

scripts/portstat

+52-4
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,13 @@ 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+
7481
counter_bucket_dict = {
7582
0:['SAI_PORT_STAT_IF_IN_UCAST_PKTS', 'SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS'],
7683
1:['SAI_PORT_STAT_IF_IN_ERRORS'],
@@ -116,7 +123,11 @@ counter_bucket_dict = {
116123
41:['SAI_PORT_STAT_IP_IN_RECEIVES'],
117124
42:['SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES'],
118125
43:['SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES'],
119-
44:['SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS']
126+
44:['SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS'],
127+
45:['SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS'],
128+
46:['SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS'],
129+
47:['SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS'],
130+
48:['SAI_PORT_STAT_WRED_DROPPED_PACKETS']
120131
}
121132

122133
STATUS_NA = 'N/A'
@@ -170,6 +181,32 @@ class Portstat(object):
170181
"""
171182
Get the counters from specific table.
172183
"""
184+
185+
global BUCKET_NUM
186+
187+
global wred_green_pkt_stat_capable
188+
global wred_yellow_pkt_stat_capable
189+
global wred_red_pkt_stat_capable
190+
global wred_total_pkt_stat_capable
191+
wred_green_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_GREEN_DROP_PKT_COUNTER","isSupported")
192+
wred_yellow_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_YELLOW_DROP_PKT_COUNTER","isSupported")
193+
wred_red_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_RED_DROP_PKT_COUNTER","isSupported")
194+
wred_total_pkt_stat_capable = self.db.get(self.db.STATE_DB, "PORT_COUNTER_CAPABILITIES|WRED_ECN_PORT_WRED_TOTAL_DROP_PKT_COUNTER","isSupported")
195+
196+
# Remove the unsupported stats from the counter dict
197+
if wred_green_pkt_stat_capable != "true" and ('SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
198+
del counter_bucket_dict['SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS']
199+
BUCKET_NUM = (BUCKET_NUM - 1)
200+
if wred_yellow_pkt_stat_capable != "true" and ('SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
201+
del counter_bucket_dict['SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS']
202+
BUCKET_NUM = (BUCKET_NUM - 1)
203+
if wred_red_pkt_stat_capable != "true" and ('SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
204+
del counter_bucket_dict['SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS']
205+
BUCKET_NUM = (BUCKET_NUM - 1)
206+
if wred_total_pkt_stat_capable != "true" and ('SAI_PORT_STAT_WRED_DROPPED_PACKETS' in counter_bucket_dict.keys()):
207+
del counter_bucket_dict['SAI_PORT_STAT_WRED_DROPPED_PACKETS']
208+
BUCKET_NUM = (BUCKET_NUM - 1)
209+
173210
fields = ["0"]*BUCKET_NUM
174211

175212
_, fvs = counter_table.get(PortCounter(), port)
@@ -399,9 +436,20 @@ class Portstat(object):
399436
print("Unicast Packets Transmitted.................... {}".format(ns_diff(cntr.tx_uca, old_cntr.tx_uca)))
400437
print("Multicast Packets Transmitted.................. {}".format(ns_diff(cntr.tx_mca, old_cntr.tx_mca)))
401438
print("Broadcast Packets Transmitted.................. {}".format(ns_diff(cntr.tx_bca, old_cntr.tx_bca)))
402-
403439
print("Time Since Counters Last Cleared............... " + str(cnstat_old_dict.get('time')))
404440

441+
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":
442+
print("")
443+
if wred_green_pkt_stat_capable == "true":
444+
print("WRED Green Dropped Packets..................... {}".format(ns_diff(cntr.wred_grn_drp_pkt, old_cntr.wred_grn_drp_pkt)))
445+
if wred_yellow_pkt_stat_capable == "true":
446+
print("WRED Yellow Dropped Packets.................... {}".format(ns_diff(cntr.wred_ylw_drp_pkt, old_cntr.wred_ylw_drp_pkt)))
447+
if wred_red_pkt_stat_capable == "true":
448+
print("WRED Red Dropped Packets....................... {}".format(ns_diff(cntr.wred_red_drp_pkt, old_cntr.wred_red_drp_pkt)))
449+
if wred_total_pkt_stat_capable == "true":
450+
print("WRED Total Dropped Packets..................... {}".format(ns_diff(cntr.wred_tot_drp_pkt, old_cntr.wred_tot_drp_pkt)))
451+
452+
405453

406454
def cnstat_diff_print(self, cnstat_new_dict, cnstat_old_dict,
407455
ratestat_dict, intf_list, use_json,

0 commit comments

Comments
 (0)