Skip to content

Commit 8c2320b

Browse files
authored
[pfcwd] For zero buffer pfcwd detection logic, verify forward action on Rx (#5665)
Signed-off-by: Neetha John <[email protected]> For platforms that use the zero buffer detection logic for pfcwd, modify the testcase to check for ingress traffic getting forwarded. Related to sonic-net/sonic-swss#2279 How did you verify/test it? Ran the test with these changes on Mellanox platform and it passed
1 parent f4ce5fb commit 8c2320b

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

tests/pfcwd/test_pfcwd_function.py

+44-24
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates")
2020
EXPECT_PFC_WD_DETECT_RE = ".* detected PFC storm .*"
2121
EXPECT_PFC_WD_RESTORE_RE = ".*storm restored.*"
22-
WD_ACTION_MSG_PFX = { "dontcare": "Verify PFCWD detection when queue buffer is not empty and proper function of drop action",
23-
"drop": "Verify proper function of drop action",
24-
"forward": "Verify proper function of forward action"
22+
WD_ACTION_MSG_PFX = { "dontcare": "Verify PFCWD detection when queue buffer is not empty and proper function of pfcwd drop action",
23+
"drop": "Verify proper function of pfcwd drop action",
24+
"forward": "Verify proper function of pfcwd forward action"
2525
}
2626
MMU_ACTIONS = ['change', 'noop', 'restore', 'noop']
2727
DB_SEPARATORS = {'0': ':', '4': '|'}
@@ -183,32 +183,35 @@ def get_mmu_params(dut, port):
183183

184184
class PfcPktCntrs(object):
185185
""" PFCwd counter retrieval and verifications """
186-
def __init__(self, dut, action):
186+
def __init__(self, dut, rx_action, tx_action):
187187
"""
188188
Args:
189189
dut(AnsibleHost) : dut instance
190190
action(string): PFCwd action for traffic test
191191
"""
192192
self.dut = dut
193-
self.action = action if action != "dontcare" else "drop"
194-
if self.action != "forward":
193+
self.rx_action = rx_action
194+
self.tx_action = tx_action
195+
if self.tx_action != "forward":
195196
self.pkt_cntrs_tx = ['PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST']
196-
self.pkt_cntrs_rx = ['PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST']
197197
self.err_msg_tx = [("Tx drop cnt check failed: Tx drop before: {} Tx drop after: {} "
198198
"Expected (diff): {} Obtained: {}"),
199199
"Tx drop last cnt check failed: Expected: {} Obtained: {}"
200200
]
201-
self.err_msg_rx = [("Rx drop cnt check failed: Rx drop before: {} Rx drop after: {} "
202-
"Expected (diff): {} Obtained: {}"),
203-
"Rx drop last cnt check failed: Expected: {} Obtained: {}"
204-
]
205201
else:
206202
self.pkt_cntrs_tx = ['PFC_WD_QUEUE_STATS_TX_PACKETS', 'PFC_WD_QUEUE_STATS_TX_PACKETS_LAST']
207-
self.pkt_cntrs_rx = ['PFC_WD_QUEUE_STATS_RX_PACKETS', 'PFC_WD_QUEUE_STATS_RX_PACKETS_LAST']
208203
self.err_msg_tx = [("Tx forward cnt check failed: Tx forward before: {} Tx forward after: {} "
209204
"Expected (diff): {} Obtained: {}"),
210205
"Tx forward last cnt check failed: Expected: {} Obtained: {}"
211206
]
207+
if self.rx_action != "forward":
208+
self.pkt_cntrs_rx = ['PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST']
209+
self.err_msg_rx = [("Rx drop cnt check failed: Rx drop before: {} Rx drop after: {} "
210+
"Expected (diff): {} Obtained: {}"),
211+
"Rx drop last cnt check failed: Expected: {} Obtained: {}"
212+
]
213+
else:
214+
self.pkt_cntrs_rx = ['PFC_WD_QUEUE_STATS_RX_PACKETS', 'PFC_WD_QUEUE_STATS_RX_PACKETS_LAST']
212215
self.err_msg_rx = [("Rx forward cnt check failed: Rx forward before: {} Rx forward after: {} "
213216
"Expected (diff): {} Obtained: {}"),
214217
"Rx forward last cnt check failed: Expected: {} Obtained: {}"
@@ -241,7 +244,7 @@ def verify_pkt_cnts(self, port_type, pkt_cnt):
241244
port_type(string) : the type of port (eg. portchannel, vlan, interface)
242245
pkt_cnt(int) : Number of test packets sent from the PTF
243246
"""
244-
logger.info("--- Checking Tx {} cntrs ---".format(self.action))
247+
logger.info("--- Checking Tx {} cntrs ---".format(self.tx_action))
245248
tx_diff = self.cntr_val["tx_end"] - self.cntr_val["tx_begin"]
246249
if (port_type in ['vlan', 'interface'] and tx_diff != pkt_cnt) or tx_diff <= 0:
247250
err_msg = self.err_msg_tx[0].format(self.cntr_val["tx_begin"], self.cntr_val["tx_end"], pkt_cnt, tx_diff)
@@ -251,7 +254,7 @@ def verify_pkt_cnts(self, port_type, pkt_cnt):
251254
err_msg = self.err_msg_tx[1].format(pkt_cnt, self.cntr_val["tx_last"])
252255
pytest_assert(err_msg)
253256

254-
logger.info("--- Checking Rx {} cntrs ---".format(self.action))
257+
logger.info("--- Checking Rx {} cntrs ---".format(self.rx_action))
255258
rx_diff = self.cntr_val["rx_end"] - self.cntr_val["rx_begin"]
256259
if (port_type in ['vlan', 'interface'] and rx_diff != pkt_cnt) or rx_diff <= 0:
257260
err_msg = self.err_msg_rx[0].format(self.cntr_val["rx_begin"], self.cntr_val["rx_end"], pkt_cnt, rx_diff)
@@ -574,16 +577,16 @@ def fill_buffer(self):
574577
ptf_runner(self.ptf, "ptftests", "pfc_wd.PfcWdTest", "ptftests", params=ptf_params,
575578
log_file=log_file)
576579

577-
def verify_wd_func(self, action):
580+
def verify_wd_func(self, action, rx_action, tx_action):
578581
"""
579582
PTF traffic send and verify
580583
581584
Args:
582585
action(string) : PTF traffic test action
583586
"""
584-
logger.info("--- Verify PFCwd function for action {} ---".format(action))
585-
self.verify_tx_egress(action)
586-
self.verify_rx_ingress(action)
587+
logger.info("--- Verify PFCwd function for pfcwd action {}, Tx traffic action {}, Rx traffic action {} ---".format(action, tx_action, rx_action))
588+
self.verify_tx_egress(tx_action)
589+
self.verify_rx_ingress(rx_action)
587590
self.verify_other_pfc_queue()
588591
self.verify_other_pfc_pg()
589592

@@ -636,7 +639,7 @@ def storm_detect_path(self, dut, port, action):
636639
loganalyzer.analyze(marker)
637640
self.stats.get_pkt_cnts(self.queue_oid, begin=True)
638641
# test pfcwd functionality on a storm
639-
self.traffic_inst.verify_wd_func(action if action != "dontcare" else "drop")
642+
self.traffic_inst.verify_wd_func(action, self.rx_action, self.tx_action)
640643
return loganalyzer
641644

642645
def storm_restore_path(self, dut, loganalyzer, port, action):
@@ -687,6 +690,14 @@ def run_test(self, dut, port, action, mmu_action=None):
687690
logger.info("--- Verify PFCwd counters for port {} ---".format(port))
688691
self.stats.verify_pkt_cnts(self.pfc_wd['port_type'], self.pfc_wd['test_pkt_count'])
689692

693+
def set_traffic_action(self, duthost, action):
694+
action = action if action != "dontcare" else "drop"
695+
if duthost.facts["asic_type"] == "mellanox":
696+
self.rx_action = "forward"
697+
else:
698+
self.rx_action = action
699+
self.tx_action = action
700+
690701
def test_pfcwd_actions(self, request, fake_storm, setup_pfc_test, fanout_graph_facts, ptfhost, duthosts, rand_one_dut_hostname, fanouthosts):
691702
"""
692703
PFCwd functional test
@@ -713,6 +724,8 @@ def test_pfcwd_actions(self, request, fake_storm, setup_pfc_test, fanout_graph_f
713724
self.peer_dev_list = dict()
714725
self.fake_storm = fake_storm
715726
self.storm_hndle = None
727+
self.rx_action = None
728+
self.tx_action = None
716729

717730
for idx, port in enumerate(self.ports):
718731
logger.info("")
@@ -727,8 +740,9 @@ def test_pfcwd_actions(self, request, fake_storm, setup_pfc_test, fanout_graph_f
727740
actions = ['dontcare', 'drop']
728741
for action in actions:
729742
try:
730-
self.stats = PfcPktCntrs(self.dut, action)
731-
logger.info("{} on port {}".format(WD_ACTION_MSG_PFX[action], port))
743+
self.set_traffic_action(duthost, action)
744+
self.stats = PfcPktCntrs(self.dut, self.rx_action, self.tx_action)
745+
logger.info("{} on port {}: Tx traffic action {}, Rx traffic action {} ".format(WD_ACTION_MSG_PFX[action], port, self.tx_action, self.rx_action))
732746
self.run_test(self.dut, port, action)
733747
except Exception as e:
734748
pytest.fail(str(e))
@@ -784,7 +798,10 @@ def test_pfcwd_mmu_change(self, request, fake_storm, setup_pfc_test, fanout_grap
784798
self.storm_hndle = None
785799
logger.info("---- Testing on port {} ----".format(port))
786800
self.setup_test_params(port, setup_info['vlan'], init=True, mmu_params=True)
787-
self.stats = PfcPktCntrs(self.dut, "drop")
801+
self.rx_action = None
802+
self.tx_action = None
803+
self.set_traffic_action(duthost, "drop")
804+
self.stats = PfcPktCntrs(self.dut, self.rx_action, self.tx_action)
788805

789806
try:
790807
for idx, mmu_action in enumerate(MMU_ACTIONS):
@@ -848,6 +865,8 @@ def test_pfcwd_port_toggle(self, request, fake_storm, setup_pfc_test, fanout_gra
848865
self.peer_dev_list = dict()
849866
self.fake_storm = fake_storm
850867
self.storm_hndle = None
868+
self.rx_action = None
869+
self.tx_action = None
851870
action = "dontcare"
852871

853872
for idx, port in enumerate(self.ports):
@@ -860,9 +879,10 @@ def test_pfcwd_port_toggle(self, request, fake_storm, setup_pfc_test, fanout_gra
860879
self.timers['pfc_wd_wait_for_restore_time'] = int(pfc_wd_restore_time_large / 1000 * 2)
861880

862881
try:
882+
self.set_traffic_action(duthost, action)
863883
# Verify that PFC storm is detected and restored
864-
self.stats = PfcPktCntrs(self.dut, action)
865-
logger.info("{} on port {}".format(WD_ACTION_MSG_PFX[action], port))
884+
self.stats = PfcPktCntrs(self.dut, self.rx_action, self.tx_action)
885+
logger.info("{} on port {}. Tx traffic action {}, Rx traffic action {}".format(WD_ACTION_MSG_PFX[action], port, self.tx_action, self.rx_action))
866886
self.run_test(self.dut, port, action)
867887

868888
# Toggle test port and verify that PFC storm is not detected

tests/pfcwd/test_pfcwd_warm_reboot.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,28 @@ def verify_rx_ingress(self, wd_action):
276276
ptf_runner(self.ptf, "ptftests", "pfc_wd.PfcWdTest", "ptftests", params=ptf_params,
277277
log_file=log_file)
278278

279-
def verify_wd_func(self, detect=True):
279+
def verify_wd_func(self, dut, detect=True):
280280
"""
281281
PTF traffic send and verify
282282
283283
Args:
284284
detect(bool) : if the current iteration is a storm detect or not (default: True)
285285
"""
286286
if detect:
287+
rx_action = "drop"
288+
tx_action = "drop"
287289
wd_action="drop"
288290
else:
291+
rx_action = "forward"
292+
tx_action = "forward"
289293
wd_action = "forward"
290-
logger.info("--- Verify PFCwd function for action {} ---".format(wd_action))
291-
self.verify_tx_egress(wd_action)
292-
self.verify_rx_ingress(wd_action)
294+
295+
if dut.facts['asic_type'] == 'mellanox':
296+
rx_action = "forward"
297+
298+
logger.info("--- Verify PFCwd function for pfcwd action {}, Tx traffic {}, Rx traffic {} ---".format(wd_action, tx_action, rx_action))
299+
self.verify_tx_egress(tx_action)
300+
self.verify_rx_ingress(rx_action)
293301

294302

295303
class TestPfcwdWb(SetupPfcwdFunc):
@@ -411,7 +419,7 @@ def run_test(self, port, queue, detect=True, storm_start=True, first_detect_afte
411419
logger.info("--- Storm restoration path for port {} queue {} ---".format(port, queue))
412420
self.storm_restore_path(port, queue)
413421
# test pfcwd functionality on a storm/restore
414-
self.traffic_inst.verify_wd_func(detect=detect)
422+
self.traffic_inst.verify_wd_func(self.dut, detect=detect)
415423

416424
@pytest.fixture(autouse=True)
417425
def pfcwd_wb_test_cleanup(self):

0 commit comments

Comments
 (0)