From 8bc7aee23b53bd2ca577695d9f09a44d4189f4b9 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Thu, 15 Apr 2021 09:40:59 -0700 Subject: [PATCH] Allowing the first time FEC and AN configuration to be pushed to SAI (#1705) **What I did** Allowing the first time configuration for FEC and Autoneg to be pushed to SAI even if they are default. **Why I did it** In orchagent, the port struct is pre-initialized with fec = none and autoneg = false (Default SAI values). However in different hardware the underlying implementation might be different. There can also be requirement where the user values need to be forced. In current logic due to the port struct being initialized with default, fec = none or an = false configurations are not pushed from orchagent to SAI. In order to push it even in default case the conditional checks are modified. --- orchagent/port.h | 2 ++ orchagent/portsorch.cpp | 7 +++++-- tests/test_port.py | 22 ++++++++++++++++++++++ tests/test_port_an.py | 23 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/orchagent/port.h b/orchagent/port.h index 2155764c31d8..f6abce87b01d 100644 --- a/orchagent/port.h +++ b/orchagent/port.h @@ -152,6 +152,8 @@ class Port SystemPortInfo m_system_port_info; SystemLagInfo m_system_lag_info; + bool m_fec_cfg = false; + bool m_an_cfg = false; }; } diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index e01710f2ec6c..b8198628a8e9 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2564,12 +2564,13 @@ void PortsOrch::doPortTask(Consumer &consumer) } else { - if (an != -1 && an != p.m_autoneg) + if (an != -1 && (!p.m_an_cfg || an != p.m_autoneg)) { if (setPortAutoNeg(p.m_port_id, an)) { SWSS_LOG_NOTICE("Set port %s AutoNeg to %u", alias.c_str(), an); p.m_autoneg = an; + p.m_an_cfg = true; m_portList[alias] = p; // Once AN is changed @@ -2702,7 +2703,7 @@ void PortsOrch::doPortTask(Consumer &consumer) if (fec_mode_map.find(fec_mode) != fec_mode_map.end()) { /* reset fec mode upon mode change */ - if (p.m_fec_mode != fec_mode_map[fec_mode]) + if (!p.m_fec_cfg || p.m_fec_mode != fec_mode_map[fec_mode]) { if (p.m_admin_state_up) { @@ -2716,6 +2717,7 @@ void PortsOrch::doPortTask(Consumer &consumer) p.m_admin_state_up = false; p.m_fec_mode = fec_mode_map[fec_mode]; + p.m_fec_cfg = true; if (setPortFec(p, p.m_fec_mode)) { @@ -2733,6 +2735,7 @@ void PortsOrch::doPortTask(Consumer &consumer) { /* Port is already down, setting fec mode*/ p.m_fec_mode = fec_mode_map[fec_mode]; + p.m_fec_cfg = true; if (setPortFec(p, p.m_fec_mode)) { m_portList[alias] = p; diff --git a/tests/test_port.py b/tests/test_port.py index 6df8565072bf..d5edc74adcfc 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -70,6 +70,28 @@ def test_PortNotification(self, dvs, testlog): assert oper_status == "up" + def test_PortFecForce(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","none")]) + ptbl.set("Ethernet0", fvs) + fvs = swsscommon.FieldValuePairs([("fec","rs")]) + ptbl.set("Ethernet4", fvs) + + # validate if fec none is pushed to asic db when set first time + port_oid = adb.port_name_map["Ethernet0"] + expected_fields = {"SAI_PORT_ATTR_FEC_MODE":"SAI_PORT_FEC_MODE_NONE"} + adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + + # 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"} + adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + def test_PortFec(self, dvs, testlog): dvs.runcmd("config interface startup Ethernet0") dvs.runcmd("config interface ip add Ethernet0 10.0.0.0/31") diff --git a/tests/test_port_an.py b/tests/test_port_an.py index 233b5fa02b1d..f5bb86ffcc33 100644 --- a/tests/test_port_an.py +++ b/tests/test_port_an.py @@ -6,6 +6,29 @@ class TestPortAutoNeg(object): + def test_PortAutoNegForce(self, dvs, testlog): + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = dvs.get_asic_db() + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + fvs = swsscommon.FieldValuePairs([("autoneg","off")]) + tbl.set("Ethernet0", fvs) + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + fvs = swsscommon.FieldValuePairs([("autoneg","on"), ("speed", "1000")]) + tbl.set("Ethernet4", fvs) + + # validate if autoneg false is pushed to asic db when set first time + port_oid = adb.port_name_map["Ethernet0"] + expected_fields = {"SAI_PORT_ATTR_AUTO_NEG_MODE":"false"} + adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + + # validate if autoneg true is pushed to asic db when set first time + port_oid = adb.port_name_map["Ethernet4"] + expected_fields = {"SAI_PORT_ATTR_AUTO_NEG_MODE":"true"} + adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + def test_PortAutoNegCold(self, dvs, testlog): db = swsscommon.DBConnector(0, dvs.redis_sock, 0)