Skip to content

Commit e8ad4a8

Browse files
ausphamlipxu
andauthored
Fix #14711 cherry pick from #15850 (#15946)
* add test case for cli show pfcwd stat (#14711) What is the motivation for this PR? #11169 How did you do it? Add a new test case to cover "pfcwd show stats" cmd Trigger PFC storm with action drop or forward send_tx_egress and send_rx_ingress execute CMD 'show pfcwd stat' and ensure the output is expected How did you verify/test it? https://elastictest.org/scheduler/testplan/66f268ae4216a91fd43d97b6 https://elastictest.org/scheduler/testplan/66f268880369ccd340b3ea60 * chore: fix conflict with #14580 Signed-off-by: Austin Pham <austinpham@microsoft.com> --------- Signed-off-by: Austin Pham <austinpham@microsoft.com> Co-authored-by: Liping Xu <108326363+lipxu@users.noreply.github.com>
1 parent 8be236e commit e8ad4a8

3 files changed

Lines changed: 537 additions & 16 deletions

File tree

tests/pfcwd/files/pfcwd_helper.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,60 @@ def has_neighbor_device(setup_pfc_test):
565565
return True
566566

567567

568-
def check_pfc_storm_state(dut, port, queue):
568+
def check_pfc_storm_state(dut, port, queue, expected_state):
569569
"""
570570
Helper function to check if PFC storm is detected/restored on a given queue
571571
"""
572-
pfcwd_stats = dut.show_and_parse("show pfcwd stats")
573-
queue_name = str(port) + ":" + str(queue)
574-
for entry in pfcwd_stats:
575-
if entry["queue"] == queue_name:
576-
logger.info("PFCWD status on queue {} stats: {}".format(queue_name, entry))
577-
return entry['storm detected/restored']
578-
logger.info("PFCWD not triggered on queue {}".format(queue_name))
579-
return None
572+
pfcwd_stat = parser_show_pfcwd_stat(dut, port, queue)
573+
if expected_state == "storm":
574+
if ("storm" in pfcwd_stat[0]['status']) and \
575+
int(pfcwd_stat[0]['storm_detect_count']) > int(pfcwd_stat[0]['restored_count']):
576+
return True
577+
else:
578+
if ("storm" not in pfcwd_stat[0]['status']) and \
579+
int(pfcwd_stat[0]['storm_detect_count']) == int(pfcwd_stat[0]['restored_count']):
580+
return True
581+
return False
582+
583+
584+
def parser_show_pfcwd_stat(dut, select_port, select_queue):
585+
"""
586+
CLI "show pfcwd stats" output:
587+
admin@bjw-can-7060-1:~$ show pfcwd stats
588+
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP # noqa: E501
589+
------------- -------- ------------------------- ------------ ------------ ----------------- ----------------- # noqa: E501
590+
Ethernet112:4 N/A 2/2 100/100 100/100 100/0 100/0 # noqa: E501
591+
admin@bjw-can-7060-1:~$
592+
"""
593+
logger.info("port {} queue {}".format(select_port, select_queue))
594+
pfcwd_stat_output = dut.show_and_parse('show pfcwd stat')
595+
596+
pfcwd_stat = []
597+
for item in pfcwd_stat_output:
598+
port, queue = item['queue'].split(':')
599+
if port != select_port or int(queue) != int(select_queue):
600+
continue
601+
storm_detect_count, restored_count = item['storm detected/restored'].split('/')
602+
tx_ok_count, tx_drop_count = item['tx ok/drop'].split('/')
603+
rx_ok_count, rx_drop_count = item['rx ok/drop'].split('/')
604+
tx_last_ok_count, tx_last_drop_count = item['tx last ok/drop'].split('/')
605+
rx_last_ok_count, rx_last_drop_count = item['rx last ok/drop'].split('/')
606+
607+
parsed_dict = {
608+
'port': port,
609+
'queue': queue,
610+
'status': item['status'],
611+
'storm_detect_count': storm_detect_count,
612+
'restored_count': restored_count,
613+
'tx_ok_count': tx_ok_count,
614+
'tx_drop_count': tx_drop_count,
615+
'rx_ok_count': rx_ok_count,
616+
'rx_drop_count': rx_drop_count,
617+
'tx_last_ok_count': tx_last_ok_count,
618+
'tx_last_drop_count': tx_last_drop_count,
619+
'rx_last_ok_count': rx_last_ok_count,
620+
'rx_last_drop_count': rx_last_drop_count
621+
}
622+
pfcwd_stat.append(parsed_dict)
623+
624+
return pfcwd_stat

0 commit comments

Comments
 (0)