Skip to content

Commit 63a28ab

Browse files
echuawuechuawu
authored andcommitted
Add background traffic for test_pfc_pause_extra_lossless test
Add background traffic for test_pfc_pause_extra_lossless test in script tests/qos/test_tunnel_qos_remap.py
1 parent 2ba104e commit 63a28ab

File tree

3 files changed

+138
-137
lines changed

3 files changed

+138
-137
lines changed

tests/conftest.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from tests.common.helpers.dut_ports import encode_dut_port_name
4141
from tests.common.helpers.dut_utils import encode_dut_and_container_name
4242
from tests.common.helpers.parallel_utils import InitialCheckState, InitialCheckStatus
43+
from tests.common.helpers.pfcwd_helper import TrafficPorts, select_test_ports, set_pfc_timers
4344
from tests.common.system_utils import docker
4445
from tests.common.testbed import TestbedInfo
4546
from tests.common.utilities import get_inventory_files, wait_until
@@ -2780,3 +2781,117 @@ def start_platform_api_service(duthosts, enum_rand_one_per_hwsku_hostname, local
27802781

27812782
res = localhost.wait_for(host=dut_ip, port=SERVER_PORT, state='started', delay=1, timeout=10)
27822783
assert res['failed'] is False
2784+
2785+
2786+
def update_t1_test_ports(duthost, mg_facts, test_ports, tbinfo):
2787+
"""
2788+
Find out active IP interfaces and use the list to
2789+
remove inactive ports from test_ports
2790+
"""
2791+
ip_ifaces = duthost.get_active_ip_interfaces(tbinfo, asic_index=0)
2792+
port_list = []
2793+
for iface in list(ip_ifaces.keys()):
2794+
if iface.startswith("PortChannel"):
2795+
port_list.extend(
2796+
mg_facts["minigraph_portchannels"][iface]["members"]
2797+
)
2798+
else:
2799+
port_list.append(iface)
2800+
port_list_set = set(port_list)
2801+
for port in list(test_ports.keys()):
2802+
if port not in port_list_set:
2803+
del test_ports[port]
2804+
return test_ports
2805+
2806+
2807+
@pytest.fixture(scope="module")
2808+
def setup_pfc_test(
2809+
duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, conn_graph_facts, tbinfo, # noqa F811
2810+
):
2811+
"""
2812+
Sets up all the parameters needed for the PFC Watchdog tests
2813+
2814+
Args:
2815+
duthost: AnsibleHost instance for DUT
2816+
ptfhost: AnsibleHost instance for PTF
2817+
conn_graph_facts: fixture that contains the parsed topology info
2818+
2819+
Yields:
2820+
setup_info: dictionary containing pfc timers, generated test ports and selected test ports
2821+
"""
2822+
SUPPORTED_T1_TOPOS = {"t1-lag", "t1-64-lag", "t1-56-lag", "t1-28-lag", "t1-32-lag"}
2823+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
2824+
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
2825+
port_list = list(mg_facts['minigraph_ports'].keys())
2826+
neighbors = conn_graph_facts['device_conn'].get(duthost.hostname, {})
2827+
dut_eth0_ip = duthost.mgmt_ip
2828+
vlan_nw = None
2829+
2830+
if mg_facts['minigraph_vlans']:
2831+
# Filter VLANs with one interface inside only(PortChannel interface in case of t0-56-po2vlan topo)
2832+
unexpected_vlans = []
2833+
for vlan, vlan_data in list(mg_facts['minigraph_vlans'].items()):
2834+
if len(vlan_data['members']) < 2:
2835+
unexpected_vlans.append(vlan)
2836+
2837+
# Update minigraph_vlan_interfaces with only expected VLAN interfaces
2838+
expected_vlan_ifaces = []
2839+
for vlan in unexpected_vlans:
2840+
for mg_vl_iface in mg_facts['minigraph_vlan_interfaces']:
2841+
if vlan != mg_vl_iface['attachto']:
2842+
expected_vlan_ifaces.append(mg_vl_iface)
2843+
if expected_vlan_ifaces:
2844+
mg_facts['minigraph_vlan_interfaces'] = expected_vlan_ifaces
2845+
2846+
# gather all vlan specific info
2847+
vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr']
2848+
vlan_prefix = mg_facts['minigraph_vlan_interfaces'][0]['prefixlen']
2849+
vlan_dev = mg_facts['minigraph_vlan_interfaces'][0]['attachto']
2850+
vlan_ips = duthost.get_ip_in_range(
2851+
num=1, prefix="{}/{}".format(vlan_addr, vlan_prefix),
2852+
exclude_ips=[vlan_addr])['ansible_facts']['generated_ips']
2853+
vlan_nw = vlan_ips[0].split('/')[0]
2854+
2855+
# build the port list for the test
2856+
tp_handle = TrafficPorts(mg_facts, neighbors, vlan_nw)
2857+
test_ports = tp_handle.build_port_list()
2858+
2859+
# In T1 topology update test ports by removing inactive ports
2860+
topo = tbinfo["topo"]["name"]
2861+
if topo in SUPPORTED_T1_TOPOS:
2862+
test_ports = update_t1_test_ports(
2863+
duthost, mg_facts, test_ports, tbinfo
2864+
)
2865+
# select a subset of ports from the generated port list
2866+
selected_ports = select_test_ports(test_ports)
2867+
2868+
setup_info = {'test_ports': test_ports,
2869+
'port_list': port_list,
2870+
'selected_test_ports': selected_ports,
2871+
'pfc_timers': set_pfc_timers(),
2872+
'neighbors': neighbors,
2873+
'eth0_ip': dut_eth0_ip
2874+
}
2875+
2876+
if mg_facts['minigraph_vlans']:
2877+
setup_info['vlan'] = {'addr': vlan_addr,
2878+
'prefix': vlan_prefix,
2879+
'dev': vlan_dev
2880+
}
2881+
else:
2882+
setup_info['vlan'] = None
2883+
2884+
# stop pfcwd
2885+
logger.info("--- Stopping Pfcwd ---")
2886+
duthost.command("pfcwd stop")
2887+
2888+
# set poll interval
2889+
duthost.command("pfcwd interval {}".format(setup_info['pfc_timers']['pfc_wd_poll_time']))
2890+
2891+
# set bulk counter chunk size
2892+
logger.info("--- Setting bulk counter polling chunk size ---")
2893+
duthost.command('redis-cli -n 4 hset "FLEX_COUNTER_TABLE|PORT" BULK_CHUNK_SIZE 64'
2894+
' BULK_CHUNK_SIZE_PER_PREFIX "SAI_PORT_STAT_IF_OUT_QLEN:0;SAI_PORT_STAT_IF_IN_FEC:32"')
2895+
2896+
logger.info("setup_info : {}".format(setup_info))
2897+
yield setup_info

tests/pfcwd/conftest.py

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from tests.common.fixtures.ptfhost_utils import pause_garp_service # noqa F401
1111
from tests.common.mellanox_data import is_mellanox_device as isMellanoxDevice
1212
from tests.common.cisco_data import is_cisco_device
13-
from tests.common.helpers.pfcwd_helper import TrafficPorts, set_pfc_timers, select_test_ports
1413
from tests.common.utilities import str2bool
1514

1615
logger = logging.getLogger(__name__)
@@ -80,117 +79,6 @@ def fake_storm(request, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
8079
else request.config.getoption('--fake-storm')
8180

8281

83-
def update_t1_test_ports(duthost, mg_facts, test_ports, tbinfo):
84-
"""
85-
Find out active IP interfaces and use the list to
86-
remove inactive ports from test_ports
87-
"""
88-
ip_ifaces = duthost.get_active_ip_interfaces(tbinfo, asic_index=0)
89-
port_list = []
90-
for iface in list(ip_ifaces.keys()):
91-
if iface.startswith("PortChannel"):
92-
port_list.extend(
93-
mg_facts["minigraph_portchannels"][iface]["members"]
94-
)
95-
else:
96-
port_list.append(iface)
97-
port_list_set = set(port_list)
98-
for port in list(test_ports.keys()):
99-
if port not in port_list_set:
100-
del test_ports[port]
101-
return test_ports
102-
103-
104-
@pytest.fixture(scope="module")
105-
def setup_pfc_test(
106-
duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, conn_graph_facts, tbinfo, # noqa F811
107-
):
108-
"""
109-
Sets up all the parameters needed for the PFC Watchdog tests
110-
111-
Args:
112-
duthost: AnsibleHost instance for DUT
113-
ptfhost: AnsibleHost instance for PTF
114-
conn_graph_facts: fixture that contains the parsed topology info
115-
116-
Yields:
117-
setup_info: dictionary containing pfc timers, generated test ports and selected test ports
118-
"""
119-
SUPPORTED_T1_TOPOS = {"t1-lag", "t1-64-lag", "t1-56-lag", "t1-28-lag", "t1-32-lag"}
120-
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
121-
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
122-
port_list = list(mg_facts['minigraph_ports'].keys())
123-
neighbors = conn_graph_facts['device_conn'].get(duthost.hostname, {})
124-
dut_eth0_ip = duthost.mgmt_ip
125-
vlan_nw = None
126-
127-
if mg_facts['minigraph_vlans']:
128-
# Filter VLANs with one interface inside only(PortChannel interface in case of t0-56-po2vlan topo)
129-
unexpected_vlans = []
130-
for vlan, vlan_data in list(mg_facts['minigraph_vlans'].items()):
131-
if len(vlan_data['members']) < 2:
132-
unexpected_vlans.append(vlan)
133-
134-
# Update minigraph_vlan_interfaces with only expected VLAN interfaces
135-
expected_vlan_ifaces = []
136-
for vlan in unexpected_vlans:
137-
for mg_vl_iface in mg_facts['minigraph_vlan_interfaces']:
138-
if vlan != mg_vl_iface['attachto']:
139-
expected_vlan_ifaces.append(mg_vl_iface)
140-
if expected_vlan_ifaces:
141-
mg_facts['minigraph_vlan_interfaces'] = expected_vlan_ifaces
142-
143-
# gather all vlan specific info
144-
vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr']
145-
vlan_prefix = mg_facts['minigraph_vlan_interfaces'][0]['prefixlen']
146-
vlan_dev = mg_facts['minigraph_vlan_interfaces'][0]['attachto']
147-
vlan_ips = duthost.get_ip_in_range(
148-
num=1, prefix="{}/{}".format(vlan_addr, vlan_prefix),
149-
exclude_ips=[vlan_addr])['ansible_facts']['generated_ips']
150-
vlan_nw = vlan_ips[0].split('/')[0]
151-
152-
topo = tbinfo["topo"]["name"]
153-
154-
# build the port list for the test
155-
config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts']
156-
tp_handle = TrafficPorts(mg_facts, neighbors, vlan_nw, topo, config_facts)
157-
test_ports = tp_handle.build_port_list()
158-
159-
# In T1 topology update test ports by removing inactive ports
160-
if topo in SUPPORTED_T1_TOPOS:
161-
test_ports = update_t1_test_ports(
162-
duthost, mg_facts, test_ports, tbinfo
163-
)
164-
# select a subset of ports from the generated port list
165-
selected_ports = select_test_ports(test_ports)
166-
167-
setup_info = {'test_ports': test_ports,
168-
'port_list': port_list,
169-
'selected_test_ports': selected_ports,
170-
'pfc_timers': set_pfc_timers(),
171-
'neighbors': neighbors,
172-
'eth0_ip': dut_eth0_ip
173-
}
174-
175-
if mg_facts['minigraph_vlans']:
176-
setup_info['vlan'] = {'addr': vlan_addr,
177-
'prefix': vlan_prefix,
178-
'dev': vlan_dev
179-
}
180-
else:
181-
setup_info['vlan'] = None
182-
183-
# stop pfcwd
184-
logger.info("--- Stopping Pfcwd ---")
185-
duthost.command("pfcwd stop")
186-
187-
# set poll interval
188-
duthost.command("pfcwd interval {}".format(setup_info['pfc_timers']['pfc_wd_poll_time']))
189-
190-
logger.info("setup_info : {}".format(setup_info))
191-
yield setup_info
192-
193-
19482
@pytest.fixture(scope="module")
19583
def setup_dut_test_params(
19684
duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, conn_graph_facts, tbinfo, # noqa F811

tests/qos/test_tunnel_qos_remap.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from ptf.testutils import simple_tcp_packet
3535
from tests.common.fixtures.conn_graph_facts import conn_graph_facts, fanout_graph_facts # noqa F401
3636
from tests.common.helpers.pfc_storm import PFCStorm
37+
from tests.common.helpers.pfcwd_helper import send_background_traffic
3738

3839

3940
pytestmark = [
@@ -354,32 +355,27 @@ def test_separated_qos_map_on_tor(ptfhost, rand_selected_dut, rand_unselected_du
354355
counter_poll_config(rand_selected_dut, 'queue', 10000)
355356

356357

357-
def pfc_pause_test(storm_handler, peer_info, prio, ptfadapter, dut, port, queue, pkt, src_port, exp_pkt, dst_ports):
358+
def pfc_pause_test(ptfhost, storm_handler, peer_info, prio, ptfadapter, dut, port, queue, pkt, src_port, exp_pkt,
359+
dst_ports, test_ports_info):
358360
try:
359-
# Start PFC storm from leaf fanout switch
360-
start_pfc_storm(storm_handler, peer_info, prio)
361-
ptfadapter.dataplane.flush()
362-
# Record the queue counter before sending test packet
363-
base_queue_count = get_queue_counter(dut, port, queue, False) # noqa F841
364-
# Send testing packet again
365-
testutils.send_packet(ptfadapter, src_port, pkt, 1)
366-
# The packet should be paused
367-
testutils.verify_no_packet_any(ptfadapter, exp_pkt, dst_ports)
368-
# Check the queue counter didn't increase
369-
queue_count = get_queue_counter(dut, port, queue, False) # noqa F841
370-
# after 10 sec delay in queue counter reading, pfc frames sending might actually had already stopped.
371-
# so bounce back packet might still send out, and queue counter increased accordingly.
372-
# and then caused flaky test faiure.
373-
# temporarily disable the assert queue counter here until find a better solution,
374-
# such as reading counter using sai thrift API
375-
# assert base_queue_count == queue_count
376-
return True
361+
start_pfc_storm(storm_handler, peer_info, prio)
362+
ptfadapter.dataplane.flush()
363+
# Record the queue counter before sending test packet
364+
base_queue_count = get_queue_counter(dut, port, queue, True)
365+
# Send testing packet again
366+
testutils.send_packet(ptfadapter, src_port, pkt, 1)
367+
# The packet should be paused
368+
testutils.verify_no_packet_any(ptfadapter, exp_pkt, dst_ports)
369+
# Check the queue counter didn't increase
370+
queue_count = get_queue_counter(dut, port, queue, False)
371+
assert base_queue_count == queue_count
372+
return True
377373
finally:
378374
stop_pfc_storm(storm_handler)
379375

380376

381377
def test_pfc_pause_extra_lossless_standby(ptfhost, fanouthosts, rand_selected_dut, rand_unselected_dut,
382-
setup_standby_ports_on_rand_selected_tor,
378+
setup_standby_ports_on_rand_selected_tor, setup_pfc_test, # noqa F811
383379
toggle_all_simulator_ports_to_rand_unselected_tor, tbinfo, ptfadapter, conn_graph_facts, fanout_graph_facts, dut_config): # noqa F811
384380
"""
385381
The test case is to verify PFC pause frame can pause extra lossless queues in dualtor deployment.
@@ -389,6 +385,7 @@ def test_pfc_pause_extra_lossless_standby(ptfhost, fanouthosts, rand_selected_du
389385
3. Generate PFC pause on fanout switch (T1 ports)
390386
4. Verify lossless traffic are paused
391387
"""
388+
setup_info = setup_pfc_test
392389
if "cisco-8000" in dut_config["asic_type"]:
393390
pytest.skip("Replacing test with test_pfc_watermark_extra_lossless_standby for Cisco-8000.")
394391
TEST_DATA = {
@@ -440,8 +437,8 @@ def test_pfc_pause_extra_lossless_standby(ptfhost, fanouthosts, rand_selected_du
440437
retry = 0
441438
while retry < PFC_PAUSE_TEST_RETRY_MAX:
442439
try:
443-
if pfc_pause_test(storm_handler, peer_info, prio, ptfadapter, rand_selected_dut, actual_port_name,
444-
queue, pkt, src_port, exp_pkt, dst_ports):
440+
if pfc_pause_test(ptfhost, storm_handler, peer_info, prio, ptfadapter, rand_selected_dut,
441+
actual_port_name, queue, pkt, src_port, exp_pkt, dst_ports, setup_info['test_ports']):
445442
break
446443
except AssertionError as err:
447444
retry += 1
@@ -457,7 +454,7 @@ def test_pfc_pause_extra_lossless_standby(ptfhost, fanouthosts, rand_selected_du
457454

458455

459456
def test_pfc_pause_extra_lossless_active(ptfhost, fanouthosts, rand_selected_dut, rand_unselected_dut,
460-
setup_standby_ports_on_rand_unselected_tor,
457+
setup_standby_ports_on_rand_unselected_tor, setup_pfc_test, # noqa F811
461458
toggle_all_simulator_ports_to_rand_selected_tor, tbinfo, ptfadapter, conn_graph_facts, fanout_graph_facts, dut_config): # noqa F811
462459
"""
463460
The test case is to verify PFC pause frame can pause extra lossless queues in dualtor deployment.
@@ -467,6 +464,7 @@ def test_pfc_pause_extra_lossless_active(ptfhost, fanouthosts, rand_selected_dut
467464
3. Generate PFC pause on fanout switch (Server facing ports)
468465
4. Verify lossless traffic are paused
469466
"""
467+
setup_info = setup_pfc_test
470468
if "cisco-8000" in dut_config["asic_type"]:
471469
pytest.skip("Replacing test with test_pfc_watermark_extra_lossless_active for Cisco-8000.")
472470
TEST_DATA = {
@@ -516,9 +514,9 @@ def test_pfc_pause_extra_lossless_active(ptfhost, fanouthosts, rand_selected_dut
516514
retry = 0
517515
while retry < PFC_PAUSE_TEST_RETRY_MAX:
518516
try:
519-
if pfc_pause_test(storm_handler, peer_info, prio, ptfadapter, rand_selected_dut,
517+
if pfc_pause_test(ptfhost, storm_handler, peer_info, prio, ptfadapter, rand_selected_dut,
520518
dualtor_meta['selected_port'], queue, tunnel_pkt.exp_pkt, src_port, exp_pkt,
521-
dst_ports):
519+
dst_ports, setup_info['test_ports']):
522520
break
523521
except AssertionError as err:
524522
retry += 1

0 commit comments

Comments
 (0)