Skip to content

Commit 8bc7aee

Browse files
authored
Allowing the first time FEC and AN configuration to be pushed to SAI (sonic-net#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.
1 parent d0dd6ee commit 8bc7aee

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

orchagent/port.h

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class Port
152152
SystemPortInfo m_system_port_info;
153153
SystemLagInfo m_system_lag_info;
154154

155+
bool m_fec_cfg = false;
156+
bool m_an_cfg = false;
155157
};
156158

157159
}

orchagent/portsorch.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -2564,12 +2564,13 @@ void PortsOrch::doPortTask(Consumer &consumer)
25642564
}
25652565
else
25662566
{
2567-
if (an != -1 && an != p.m_autoneg)
2567+
if (an != -1 && (!p.m_an_cfg || an != p.m_autoneg))
25682568
{
25692569
if (setPortAutoNeg(p.m_port_id, an))
25702570
{
25712571
SWSS_LOG_NOTICE("Set port %s AutoNeg to %u", alias.c_str(), an);
25722572
p.m_autoneg = an;
2573+
p.m_an_cfg = true;
25732574
m_portList[alias] = p;
25742575

25752576
// Once AN is changed
@@ -2702,7 +2703,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
27022703
if (fec_mode_map.find(fec_mode) != fec_mode_map.end())
27032704
{
27042705
/* reset fec mode upon mode change */
2705-
if (p.m_fec_mode != fec_mode_map[fec_mode])
2706+
if (!p.m_fec_cfg || p.m_fec_mode != fec_mode_map[fec_mode])
27062707
{
27072708
if (p.m_admin_state_up)
27082709
{
@@ -2716,6 +2717,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
27162717

27172718
p.m_admin_state_up = false;
27182719
p.m_fec_mode = fec_mode_map[fec_mode];
2720+
p.m_fec_cfg = true;
27192721

27202722
if (setPortFec(p, p.m_fec_mode))
27212723
{
@@ -2733,6 +2735,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
27332735
{
27342736
/* Port is already down, setting fec mode*/
27352737
p.m_fec_mode = fec_mode_map[fec_mode];
2738+
p.m_fec_cfg = true;
27362739
if (setPortFec(p, p.m_fec_mode))
27372740
{
27382741
m_portList[alias] = p;

tests/test_port.py

+22
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ def test_PortNotification(self, dvs, testlog):
7070

7171
assert oper_status == "up"
7272

73+
def test_PortFecForce(self, dvs, testlog):
74+
db = swsscommon.DBConnector(0, dvs.redis_sock, 0)
75+
adb = dvs.get_asic_db()
76+
77+
ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE")
78+
79+
# set fec
80+
fvs = swsscommon.FieldValuePairs([("fec","none")])
81+
ptbl.set("Ethernet0", fvs)
82+
fvs = swsscommon.FieldValuePairs([("fec","rs")])
83+
ptbl.set("Ethernet4", fvs)
84+
85+
# validate if fec none is pushed to asic db when set first time
86+
port_oid = adb.port_name_map["Ethernet0"]
87+
expected_fields = {"SAI_PORT_ATTR_FEC_MODE":"SAI_PORT_FEC_MODE_NONE"}
88+
adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields)
89+
90+
# validate if fec rs is pushed to asic db when set first time
91+
port_oid = adb.port_name_map["Ethernet4"]
92+
expected_fields = {"SAI_PORT_ATTR_FEC_MODE":"SAI_PORT_FEC_MODE_RS"}
93+
adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields)
94+
7395
def test_PortFec(self, dvs, testlog):
7496
dvs.runcmd("config interface startup Ethernet0")
7597
dvs.runcmd("config interface ip add Ethernet0 10.0.0.0/31")

tests/test_port_an.py

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77

88
class TestPortAutoNeg(object):
9+
def test_PortAutoNegForce(self, dvs, testlog):
10+
11+
db = swsscommon.DBConnector(0, dvs.redis_sock, 0)
12+
adb = dvs.get_asic_db()
13+
14+
tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE")
15+
fvs = swsscommon.FieldValuePairs([("autoneg","off")])
16+
tbl.set("Ethernet0", fvs)
17+
18+
tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE")
19+
fvs = swsscommon.FieldValuePairs([("autoneg","on"), ("speed", "1000")])
20+
tbl.set("Ethernet4", fvs)
21+
22+
# validate if autoneg false is pushed to asic db when set first time
23+
port_oid = adb.port_name_map["Ethernet0"]
24+
expected_fields = {"SAI_PORT_ATTR_AUTO_NEG_MODE":"false"}
25+
adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields)
26+
27+
# validate if autoneg true is pushed to asic db when set first time
28+
port_oid = adb.port_name_map["Ethernet4"]
29+
expected_fields = {"SAI_PORT_ATTR_AUTO_NEG_MODE":"true"}
30+
adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields)
31+
932
def test_PortAutoNegCold(self, dvs, testlog):
1033

1134
db = swsscommon.DBConnector(0, dvs.redis_sock, 0)

0 commit comments

Comments
 (0)