From eadb5492546a69fefdea00cbe846f246f405bc88 Mon Sep 17 00:00:00 2001 From: Zhixin Zhu <44230426+zhixzhu@users.noreply.github.com> Date: Tue, 7 Jan 2025 02:18:32 +0800 Subject: [PATCH] Ignore failure in setPortPfcAsym if SAI_STATUS_NOT_SUPPORTED (#3430) * ignore failure in setPortPfcAsym if SAI_STATUS_NOT_SUPPORTED * return true on setPortPfcAsym SAI_STATUS_NOT_SUPPORTED, since false will make doPortTask keep repeating --- orchagent/portsorch.cpp | 4 ++ tests/mock_tests/portsorch_ut.cpp | 67 +++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 4a96d74473..de9c1ef772 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2073,6 +2073,10 @@ bool PortsOrch::setPortPfcAsym(Port &port, sai_port_priority_flow_control_mode_t if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to set PFC mode %d to port id 0x%" PRIx64 " (rc:%d)", pfc_asym, port.m_port_id, status); + if (status == SAI_STATUS_NOT_SUPPORTED) + { + return true; + } task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status); if (handle_status != task_success) { diff --git a/tests/mock_tests/portsorch_ut.cpp b/tests/mock_tests/portsorch_ut.cpp index 0d698b8451..2dfee93b2e 100644 --- a/tests/mock_tests/portsorch_ut.cpp +++ b/tests/mock_tests/portsorch_ut.cpp @@ -98,6 +98,8 @@ namespace portsorch_test uint32_t _sai_set_link_event_damping_algorithm_count; uint32_t _sai_set_link_event_damping_config_count; int32_t _sai_link_event_damping_algorithm = 0; + bool set_pfc_asym_not_supported = false; + uint32_t set_pfc_asym_failures; sai_redis_link_event_damping_algo_aied_config_t _sai_link_event_damping_config = {0, 0, 0, 0, 0}; sai_status_t _ut_stub_sai_set_port_attribute( @@ -114,9 +116,15 @@ namespace portsorch_test /* Simulating failure case */ return SAI_STATUS_FAILURE; } - else if (attr[0].id == SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED) - { - _sai_set_pfc_mode_count++; + else if (attr[0].id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE) + { + _sai_set_pfc_mode_count++; + /* Simulating failure case */ + if (set_pfc_asym_not_supported) + { + set_pfc_asym_failures++; + return SAI_STATUS_NOT_SUPPORTED; + } } else if (attr[0].id == SAI_PORT_ATTR_ADMIN_STATE) { @@ -2430,6 +2438,59 @@ namespace portsorch_test mock_port_fec_modes = old_mock_port_fec_modes; _unhook_sai_port_api(); } + + /* + * Test case: SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE is not supported by vendor + **/ + TEST_F(PortsOrchTest, PortPFCNotSupported) + { + _hook_sai_port_api(); + Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME); + std::deque entries; + + set_pfc_asym_not_supported = true; + // Get SAI default ports to populate DB + auto ports = ut_helper::getInitialSaiPorts(); + + for (const auto &it : ports) + { + portTable.set(it.first, it.second); + } + + // Set PortConfigDone + portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } }); + + // refill consumer + gPortsOrch->addExistingData(&portTable); + + // Apply configuration : + // create ports + static_cast(gPortsOrch)->doTask(); + + uint32_t current_sai_api_call_count = _sai_set_pfc_mode_count; + + entries.push_back({"Ethernet0", "SET", + { + { "pfc_asym", "off"} + }}); + auto consumer = dynamic_cast(gPortsOrch->getExecutor(APP_PORT_TABLE_NAME)); + consumer->addToSync(entries); + static_cast(gPortsOrch)->doTask(); + entries.clear(); + + ASSERT_EQ(_sai_set_pfc_mode_count, ++current_sai_api_call_count); + ASSERT_EQ(set_pfc_asym_failures, 1); + + set_pfc_asym_not_supported = false; + + vector ts; + + gPortsOrch->dumpPendingTasks(ts); + ASSERT_TRUE(ts.empty()); + + _unhook_sai_port_api(); + } + TEST_F(PortsOrchTest, PortTestSAIFailureHandling) { _hook_sai_port_api();