Skip to content
Merged
57 changes: 57 additions & 0 deletions tests/qos/qos_sai_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,3 +2624,60 @@ def change_lag_lacp_timer(self, duthosts, get_src_dst_asic_and_duts, tbinfo, nbr
logger.info(
"Changing lacp timer multiplier to default for %s in %s" % (neighbor_lag_member, peer_device))
vm_host.no_lacp_time_multiplier(neighbor_lag_member)

def copy_and_run_set_cir_script_cisco_8000(self, dut, port, asic="", speed="10000000"):
if dut.facts['asic_type'] != "cisco-8000":
raise RuntimeError("This function should have been called only for cisco-8000.")
dshell_script = f'''
from common import *
from sai_utils import *

def set_port_cir(interface, rate):
mp = get_mac_port(interface)
sch = mp.get_scheduler()
sch.set_credit_cir(rate)
sch.set_credit_eir_or_pir(rate, False)

set_port_cir("{port}", {speed})
print("success")
'''
script_path = "/tmp/set_scheduler.py"
dut.copy(content=dshell_script, dest=script_path)
dut.docker_copy_to_all_asics(
container_name=f"syncd{asic}",
src=script_path,
dst="/")
asic_arg = ""
if asic != "":
asic_arg = f"-n asic{asic}"
output = dut.shell(f"show platform npu script {asic_arg} -s set_scheduler.py")['stdout']
if output != "success":
raise RuntimeError("Couldn't set the scheduler for this interface, pls check the DUT.")

@pytest.fixture(scope="function", autouse=False)
def set_cir_change(self, get_src_dst_asic_and_duts, dutConfig):
dst_port = dutConfig['dutInterfaces'][dutConfig["testPorts"]["dst_port_id"]]
dst_dut = get_src_dst_asic_and_duts['dst_dut']
dst_asic = get_src_dst_asic_and_duts['dst_asic']
dst_index = dst_asic.asic_index

if dst_dut.facts['asic_type'] != "cisco-8000":
yield
return
asic_arg = ""
if dst_index is not None:
asic_arg = f"-n asic{dst_index}"
port_speed = int(dst_dut.shell(
'sonic-db-cli {} APPL_DB HGET '
'\"PORT_TABLE:{}\" \"speed\"'.format(
asic_arg, dst_port))['stdout']) * 1000 * 1000

# Set scheduler to 5 Gbps.
self.copy_and_run_set_cir_script_cisco_8000(
dut=dst_dut, port=dst_port, asic=dst_index, speed=5 * 1000 * 1000 * 1000)

yield

# Set scheduler back to original speed.
self.copy_and_run_set_cir_script_cisco_8000(
dut=dst_dut, port=dst_port, asic=dst_index, speed=int(1.1*port_speed))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to use 1.1*port_speed?

4 changes: 2 additions & 2 deletions tests/qos/test_qos_sai.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ def testQosSaiDot1pPgMapping(

def testQosSaiDwrr(
self, ptfhost, duthosts, get_src_dst_asic_and_duts, dutTestParams, dutConfig, dutQosConfig, change_port_speed,
skip_src_dst_different_asic
skip_src_dst_different_asic, set_cir_change
):
"""
Test QoS SAI DWRR
Expand Down Expand Up @@ -2061,7 +2061,7 @@ def testQosSaiSeparatedDscpToPgMapping(self, duthost, request, ptfhost,

def testQosSaiDwrrWeightChange(
self, get_src_dst_asic_and_duts, ptfhost, dutTestParams, dutConfig, dutQosConfig,
updateSchedProfile, skip_src_dst_different_asic
updateSchedProfile, skip_src_dst_different_asic, set_cir_change
):
"""
Test QoS SAI DWRR runtime weight change
Expand Down