Skip to content

Commit

Permalink
add test case for cli show pfcwd stat (sonic-net#14711)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
sonic-net#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
  • Loading branch information
lipxu authored and vikshaw-Nokia committed Oct 23, 2024
1 parent e42b8a3 commit 36e0966
Show file tree
Hide file tree
Showing 3 changed files with 537 additions and 16 deletions.
63 changes: 54 additions & 9 deletions tests/common/helpers/pfcwd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,60 @@ def has_neighbor_device(setup_pfc_test):
return True


def check_pfc_storm_state(dut, port, queue):
def check_pfc_storm_state(dut, port, queue, expected_state):
"""
Helper function to check if PFC storm is detected/restored on a given queue
"""
pfcwd_stats = dut.show_and_parse("show pfcwd stats")
queue_name = str(port) + ":" + str(queue)
for entry in pfcwd_stats:
if entry["queue"] == queue_name:
logger.info("PFCWD status on queue {} stats: {}".format(queue_name, entry))
return entry['storm detected/restored']
logger.info("PFCWD not triggered on queue {}".format(queue_name))
return None
pfcwd_stat = parser_show_pfcwd_stat(dut, port, queue)
if expected_state == "storm":
if ("storm" in pfcwd_stat[0]['status']) and \
int(pfcwd_stat[0]['storm_detect_count']) > int(pfcwd_stat[0]['restored_count']):
return True
else:
if ("storm" not in pfcwd_stat[0]['status']) and \
int(pfcwd_stat[0]['storm_detect_count']) == int(pfcwd_stat[0]['restored_count']):
return True
return False


def parser_show_pfcwd_stat(dut, select_port, select_queue):
"""
CLI "show pfcwd stats" output:
admin@bjw-can-7060-1:~$ show pfcwd stats
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP # noqa: E501
------------- -------- ------------------------- ------------ ------------ ----------------- ----------------- # noqa: E501
Ethernet112:4 N/A 2/2 100/100 100/100 100/0 100/0 # noqa: E501
admin@bjw-can-7060-1:~$
"""
logger.info("port {} queue {}".format(select_port, select_queue))
pfcwd_stat_output = dut.show_and_parse('show pfcwd stat')

pfcwd_stat = []
for item in pfcwd_stat_output:
port, queue = item['queue'].split(':')
if port != select_port or int(queue) != int(select_queue):
continue
storm_detect_count, restored_count = item['storm detected/restored'].split('/')
tx_ok_count, tx_drop_count = item['tx ok/drop'].split('/')
rx_ok_count, rx_drop_count = item['rx ok/drop'].split('/')
tx_last_ok_count, tx_last_drop_count = item['tx last ok/drop'].split('/')
rx_last_ok_count, rx_last_drop_count = item['rx last ok/drop'].split('/')

parsed_dict = {
'port': port,
'queue': queue,
'status': item['status'],
'storm_detect_count': storm_detect_count,
'restored_count': restored_count,
'tx_ok_count': tx_ok_count,
'tx_drop_count': tx_drop_count,
'rx_ok_count': rx_ok_count,
'rx_drop_count': rx_drop_count,
'tx_last_ok_count': tx_last_ok_count,
'tx_last_drop_count': tx_last_drop_count,
'rx_last_ok_count': rx_last_ok_count,
'rx_last_drop_count': rx_last_drop_count
}
pfcwd_stat.append(parsed_dict)

return pfcwd_stat
Loading

0 comments on commit 36e0966

Please sign in to comment.