Skip to content

Commit

Permalink
Fix oper FEC retrieval after warmboot (sonic-net#3100)
Browse files Browse the repository at this point in the history
Updating oper FEC status in state_db after warm-reboot as part of refresh port status call
  • Loading branch information
dgsudharsan authored and mssonicbld committed Apr 9, 2024
1 parent 344b28f commit 8fd34c1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7694,6 +7694,18 @@ void PortsOrch::refreshPortStatus()
{
updateDbPortOperSpeed(port, 0);
}
sai_port_fec_mode_t fec_mode;
string fec_str = "N/A";
if (oper_fec_sup && getPortOperFec(port, fec_mode))
{
if (!m_portHlpr.fecToStr(fec_str, fec_mode))
{
SWSS_LOG_ERROR("Error unknown fec mode %d while querying port %s fec mode",
static_cast<std::int32_t>(fec_mode), port.m_alias.c_str());
fec_str = "N/A";
}
}
updateDbPortOperFec(port,fec_str);
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/mock_tests/portsorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ namespace portsorch_test
attr_list[0].value.s32 = _sai_port_fec_mode;
status = SAI_STATUS_SUCCESS;
}
else if (attr_count== 1 && attr_list[0].id == SAI_PORT_ATTR_OPER_STATUS)
{
attr_list[0].value.u32 = (uint32_t)SAI_PORT_OPER_STATUS_UP;
status = SAI_STATUS_SUCCESS;
}
else
{
status = pold_sai_port_api->get_port_attribute(port_id, attr_count, attr_list);
Expand Down Expand Up @@ -1166,6 +1171,7 @@ namespace portsorch_test
{
_hook_sai_port_api();
Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME);
Table statePortTable = Table(m_state_db.get(), STATE_PORT_TABLE_NAME);
std::deque<KeyOpFieldsValuesTuple> entries;

not_support_fetching_fec = false;
Expand Down Expand Up @@ -1215,6 +1221,33 @@ namespace portsorch_test

ASSERT_EQ(fec_mode, SAI_PORT_FEC_MODE_RS);

gPortsOrch->refreshPortStatus();
std::vector<FieldValueTuple> values;
statePortTable.get("Ethernet0", values);
bool fec_found = false;
for (auto &valueTuple : values)
{
if (fvField(valueTuple) == "fec")
{
fec_found = true;
ASSERT_TRUE(fvValue(valueTuple) == "rs");
}
}
ASSERT_TRUE(fec_found == true);

/*Mock an invalid fec mode with high value*/
_sai_port_fec_mode = 100;
gPortsOrch->refreshPortStatus();
statePortTable.get("Ethernet0", values);
fec_found = false;
for (auto &valueTuple : values)
{
if (fvField(valueTuple) == "fec")
{
fec_found = true;
ASSERT_TRUE(fvValue(valueTuple) == "N/A");
}
}
mock_port_fec_modes = old_mock_port_fec_modes;
_unhook_sai_port_api();
}
Expand Down

0 comments on commit 8fd34c1

Please sign in to comment.