From ca728200ba3fe66459907482a18c22b626c5b85c Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 15 Aug 2023 10:23:22 -0700 Subject: [PATCH] [FEC] Adding support of override based on attribute query of SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE (#2874) --- orchagent/portsorch.cpp | 42 +++++++++++++++++++++++++++++++++ orchagent/portsorch.h | 2 ++ tests/test_port_fec_override.py | 30 +++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/test_port_fec_override.py diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 3b1e2b557f..346d65417f 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -512,6 +512,18 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vectorset_port_attribute(port_obj, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set fec override %d to port pid:%" PRIx64, attr.value.booldata, port_obj); + task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + SWSS_LOG_INFO("Set fec override %d to port pid:%" PRIx64, attr.value.booldata, port_obj); + return true; +} + bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode) { SWSS_LOG_ENTER(); @@ -1521,6 +1555,10 @@ bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode) } } + if (fec_override_sup && !setPortFecOverride(port.m_port_id, true)) + { + return false; + } setGearboxPortsAttr(port, SAI_PORT_ATTR_FEC_MODE, &fec_mode); SWSS_LOG_NOTICE("Set port %s FEC mode %d", port.m_alias.c_str(), fec_mode); @@ -2524,6 +2562,10 @@ bool PortsOrch::setGearboxPortAttr(const Port &port, dest_port_type_t port_type, m_gearboxTable->hset(key, speed_attr, to_string(speed)); SWSS_LOG_NOTICE("BOX: Updated APPL_DB key:%s %s %d", key.c_str(), speed_attr.c_str(), speed); } + else if (id == SAI_PORT_ATTR_FEC_MODE && fec_override_sup && !setPortFecOverride(dest_port_id, true)) + { + return false; + } } else { diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 00246bff3d..a6009c089c 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -322,6 +322,7 @@ class PortsOrch : public Orch, public Subject map m_bridge_port_ref_count; NotificationConsumer* m_portStatusNotificationConsumer; + bool fec_override_sup = false; swss::SelectableTimer *m_port_state_poller = nullptr; @@ -379,6 +380,7 @@ class PortsOrch : public Orch, public Subject bool setPortPvid (Port &port, sai_uint32_t pvid); bool getPortPvid(Port &port, sai_uint32_t &pvid); bool setPortFec(Port &port, sai_port_fec_mode_t fec_mode); + bool setPortFecOverride(sai_object_id_t port_obj, bool fec_override); bool setPortPfcAsym(Port &port, sai_port_priority_flow_control_mode_t pfc_asym); bool getDestPortId(sai_object_id_t src_port_id, dest_port_type_t port_type, sai_object_id_t &des_port_id); diff --git a/tests/test_port_fec_override.py b/tests/test_port_fec_override.py new file mode 100644 index 0000000000..acd6b9bbbb --- /dev/null +++ b/tests/test_port_fec_override.py @@ -0,0 +1,30 @@ +import time +import os +import pytest + +from swsscommon import swsscommon + +DVS_ENV = ["HWSKU=Mellanox-SN2700"] + +class TestPort(object): + def test_PortFecOverride(self, dvs, testlog): + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = dvs.get_asic_db() + + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + + # set fec + fvs = swsscommon.FieldValuePairs([("fec","rs")]) + ptbl.set("Ethernet4", fvs) + + # validate if fec rs is pushed to asic db when set first time + port_oid = adb.port_name_map["Ethernet4"] + expected_fields = {"SAI_PORT_ATTR_FEC_MODE":"SAI_PORT_FEC_MODE_RS", "SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE":"true"} + adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + + +# Add Dummy always-pass test at end as workaroud +# for issue when Flaky fail on final test it invokes module tear-down before retrying +def test_nonflaky_dummy(): + pass +