Skip to content

Commit

Permalink
[QoS]Sai-thrift support for Credit_WD enable disable code changes in …
Browse files Browse the repository at this point in the history
…sonic-mgmt qos_test (sonic-net#13041)

To implement & verify the changes added from sai-thrift to enable/disable credit-watchdog voq capability.
PR# opencomputeproject/SAI#2010
  • Loading branch information
ansrajpu-git authored Jun 28, 2024
1 parent 86a4e8a commit f811478
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
66 changes: 26 additions & 40 deletions tests/saitests/py3/sai_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
interface_to_front_mapping = {}

from switch import (sai_thrift_port_tx_enable, # noqa E402
sai_thrift_port_tx_disable)
sai_thrift_port_tx_disable,
sai_thrift_credit_wd_enable,
sai_thrift_credit_wd_disable)

DATA_PLANE_QUEUE_LIST = ["0", "1", "2", "3", "4", "5", "6", "7"]
DEFAULT_QUEUE_SCHEDULER_CONFIG = {"0": "scheduler.0",
Expand Down Expand Up @@ -189,50 +191,34 @@ def sai_thrift_port_tx_enable(
else:
sai_thrift_port_tx_enable(client, asic_type, port_list, target=target)
if self.platform_asic and self.platform_asic == "broadcom-dnx" and last_port:
# need to enable watchdog on the source asic using cint script
cmd = "bcmcmd -n {} \"BCMSAI credit-watchdog enable\"".format(self.src_asic_index)
stdOut, stdErr, retValue = self.exec_cmd_on_dut(self.src_server_ip,
self.test_params['dut_username'],
self.test_params['dut_password'],
cmd)
if retValue != 0 or 'Success rv = 0' not in stdOut[1]:
# Retry credit-wd command max 3 times on failure
while count < 3:
# need to enable watchdog on the source asic
# max 3 retries
while count < 3:
retValue = sai_thrift_credit_wd_enable(self.src_client)
if retValue == 0:
break
else:
print("Retrying credit_wd_enable")
time.sleep(5)
stdOut, stdErr, retValue = self.exec_cmd_on_dut(self.src_server_ip,
self.test_params['dut_username'],
self.test_params['dut_password'],
cmd)
if stdOut and 'Success rv = 0' in stdOut[1]:
break
count += 1
assert 'Success rv = 0' in stdOut[1] if stdOut else retValue == 0,\
"enable wd failed '{}' on asic '{}' on '{}'".format(cmd, self.src_asic_index, self.src_server_ip)
time.sleep(1)
count += 1
assert retValue == 0, "enable wd failed on asic '{}' on '{}' with error '{}'".format(
self.src_asic_index, self.src_server_ip, retValue)

def sai_thrift_port_tx_disable(self, client, asic_type, port_list, target='dst', disable_port_by_block_queue=True):
count = 0
if self.platform_asic and self.platform_asic == "broadcom-dnx":
# need to enable watchdog on the source asic using cint script
cmd = "bcmcmd -n {} \"BCMSAI credit-watchdog disable\"".format(self.src_asic_index)
stdOut, stdErr, retValue = self.exec_cmd_on_dut(self.src_server_ip,
self.test_params['dut_username'],
self.test_params['dut_password'],
cmd)
if retValue != 0 or 'Success rv = 0' not in stdOut[1]:
# Retry credit-wd command max 3 times on failure
while count < 3:
print("Retrying credit_wd_enable")
time.sleep(5)
stdOut, stdErr, retValue = self.exec_cmd_on_dut(self.src_server_ip,
self.test_params['dut_username'],
self.test_params['dut_password'],
cmd)
if stdOut and 'Success rv = 0' in stdOut[1]:
break
count += 1
assert 'Success rv = 0' in stdOut[1] if stdOut else retValue == 0, \
"disable wd failed '{}' on asic '{}' on '{}'".format(cmd, self.src_asic_index, self.src_server_ip)
# need to disable watchdog on the source asic
# max 3 retries
while count < 3:
retValue = sai_thrift_credit_wd_disable(self.src_client)
if retValue == 0:
break
else:
print("Retrying credit_wd_disable")
time.sleep(1)
count += 1
assert retValue == 0, "disable wd failed on asic '{}' on '{}' with error '{}'".format(
self.src_asic_index, self.src_server_ip, retValue)

if asic_type == 'mellanox' and disable_port_by_block_queue:
self.disable_mellanox_egress_data_plane(port_list)
Expand Down
20 changes: 19 additions & 1 deletion tests/saitests/py3/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
SAI_SWITCH_ATTR_PORT_NUMBER, SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE,\
SAI_VLAN_MEMBER_ATTR_VLAN_ID, SAI_PORT_STAT_IF_IN_UCAST_PKTS,\
SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS, SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS, SAI_PORT_STAT_IF_OUT_QLEN, \
SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES
SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES, SAI_SWITCH_ATTR_CREDIT_WD


from switch_sai_thrift.sai_headers import SAI_SWITCH_ATTR_SRC_MAC_ADDRESS, SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST
Expand Down Expand Up @@ -773,6 +773,24 @@ def sai_thrift_port_tx_enable(client, asic_type, port_ids, target='dst'):
client.sai_thrift_set_port_attribute(port_list[target][port_id], attr)


def sai_thrift_credit_wd_disable(client):
# Disable credit-watchdog on target asic index
attr_value = sai_thrift_attribute_value_t(booldata=0)
attr = sai_thrift_attribute_t(
id=SAI_SWITCH_ATTR_CREDIT_WD, value=attr_value)
status = client.sai_thrift_set_switch_attribute(attr)
return status


def sai_thrift_credit_wd_enable(client):
# Enable credit-watchdog on target asic-index
attr_value = sai_thrift_attribute_value_t(booldata=1)
attr = sai_thrift_attribute_t(
id=SAI_SWITCH_ATTR_CREDIT_WD, value=attr_value)
status = client.sai_thrift_set_switch_attribute(attr)
return status


def sai_thrift_read_port_counters(client, asic_type, port):
port_cnt_ids = []
port_cnt_ids.append(SAI_PORT_STAT_IF_OUT_DISCARDS)
Expand Down

0 comments on commit f811478

Please sign in to comment.