Skip to content

Commit e1005dd

Browse files
stepanblyschakmssonicbld
authored andcommitted
[portsorch] process only updated APP_DB fields when port is already created (#3025)
* [portsorch] process only updated APP_DB fields when port is already created What I did Fixing an issue when setting some port attribute in APPL_DB triggers serdes parameters to be re-programmed with port toggling. Made portsorch to handle only those attributes that were pushed to APPL_DB, so that serdes programming happens only by xcvrd's request to do so.
1 parent 4a9b7ee commit e1005dd

File tree

4 files changed

+86
-18
lines changed

4 files changed

+86
-18
lines changed

orchagent/port/porthlpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ bool PortHelper::parsePortConfig(PortConfig &port) const
910910
}
911911
}
912912

913-
return this->validatePortConfig(port);
913+
return true;
914914
}
915915

916916
bool PortHelper::validatePortConfig(PortConfig &port) const

orchagent/port/porthlpr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class PortHelper final
2626
std::string getAdminStatusStr(const PortConfig &port) const;
2727

2828
bool parsePortConfig(PortConfig &port) const;
29+
bool validatePortConfig(PortConfig &port) const;
2930

3031
private:
3132
std::string getFieldValueStr(const PortConfig &port, const std::string &field) const;
@@ -50,6 +51,4 @@ class PortHelper final
5051
bool parsePortRole(PortConfig &port, const std::string &field, const std::string &value) const;
5152
bool parsePortAdminStatus(PortConfig &port, const std::string &field, const std::string &value) const;
5253
bool parsePortDescription(PortConfig &port, const std::string &field, const std::string &value) const;
53-
54-
bool validatePortConfig(PortConfig &port) const;
5554
};

orchagent/portsorch.cpp

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,28 +3287,59 @@ void PortsOrch::doPortTask(Consumer &consumer)
32873287

32883288
if (op == SET_COMMAND)
32893289
{
3290-
auto &fvMap = m_portConfigMap[key];
3291-
3292-
for (const auto &cit : kfvFieldsValues(keyOpFieldsValues))
3290+
auto parsePortFvs = [&](auto& fvMap) -> bool
32933291
{
3294-
auto fieldName = fvField(cit);
3295-
auto fieldValue = fvValue(cit);
3292+
for (const auto &cit : kfvFieldsValues(keyOpFieldsValues))
3293+
{
3294+
auto fieldName = fvField(cit);
3295+
auto fieldValue = fvValue(cit);
32963296

3297-
SWSS_LOG_INFO("FIELD: %s, VALUE: %s", fieldName.c_str(), fieldValue.c_str());
3297+
SWSS_LOG_INFO("FIELD: %s, VALUE: %s", fieldName.c_str(), fieldValue.c_str());
32983298

3299-
fvMap[fieldName] = fieldValue;
3300-
}
3299+
fvMap[fieldName] = fieldValue;
3300+
}
3301+
3302+
pCfg.fieldValueMap = fvMap;
3303+
3304+
if (!m_portHlpr.parsePortConfig(pCfg))
3305+
{
3306+
return false;
3307+
}
33013308

3302-
pCfg.fieldValueMap = fvMap;
3309+
return true;
3310+
};
33033311

3304-
if (!m_portHlpr.parsePortConfig(pCfg))
3312+
if (m_portList.find(key) == m_portList.end())
33053313
{
3306-
it = taskMap.erase(it);
3307-
continue;
3314+
// Aggregate configuration while the port is not created.
3315+
auto &fvMap = m_portConfigMap[key];
3316+
3317+
if (!parsePortFvs(fvMap))
3318+
{
3319+
it = taskMap.erase(it);
3320+
continue;
3321+
}
3322+
3323+
if (!m_portHlpr.validatePortConfig(pCfg))
3324+
{
3325+
it = taskMap.erase(it);
3326+
continue;
3327+
}
3328+
3329+
/* Collect information about all received ports */
3330+
m_lanesAliasSpeedMap[pCfg.lanes.value] = pCfg;
33083331
}
3332+
else
3333+
{
3334+
// Port is already created, gather updated field-values.
3335+
std::unordered_map<std::string, std::string> fvMap;
33093336

3310-
/* Collect information about all received ports */
3311-
m_lanesAliasSpeedMap[pCfg.lanes.value] = pCfg;
3337+
if (!parsePortFvs(fvMap))
3338+
{
3339+
it = taskMap.erase(it);
3340+
continue;
3341+
}
3342+
}
33123343

33133344
// TODO:
33143345
// Fix the issue below
@@ -3424,6 +3455,9 @@ void PortsOrch::doPortTask(Consumer &consumer)
34243455
PortSerdesAttrMap_t serdes_attr;
34253456
getPortSerdesAttr(serdes_attr, pCfg);
34263457

3458+
// Saved configured admin status
3459+
bool admin_status = p.m_admin_state_up;
3460+
34273461
if (pCfg.autoneg.is_set)
34283462
{
34293463
if (!p.m_an_cfg || p.m_autoneg != pCfg.autoneg.value)
@@ -3975,6 +4009,13 @@ void PortsOrch::doPortTask(Consumer &consumer)
39754009
/* create host_tx_ready field in state-db */
39764010
initHostTxReadyState(p);
39774011

4012+
// Restore admin status if the port was brought down
4013+
if (admin_status != p.m_admin_state_up)
4014+
{
4015+
pCfg.admin_status.is_set = true;
4016+
pCfg.admin_status.value = admin_status;
4017+
}
4018+
39784019
/* Last step set port admin status */
39794020
if (pCfg.admin_status.is_set)
39804021
{

tests/mock_tests/portsorch_ut.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,6 @@ namespace portsorch_test
882882
std::deque<KeyOpFieldsValuesTuple> kfvSerdes = {{
883883
"Ethernet0",
884884
SET_COMMAND, {
885-
{ "admin_status", "up" },
886885
{ "idriver" , "0x6,0x6,0x6,0x6" }
887886
}
888887
}};
@@ -909,6 +908,35 @@ namespace portsorch_test
909908
ASSERT_EQ(_sai_set_admin_state_down_count, ++current_sai_api_call_count);
910909
ASSERT_EQ(_sai_set_admin_state_up_count, current_sai_api_call_count);
911910

911+
// Configure non-serdes attribute that does not trigger admin state change
912+
std::deque<KeyOpFieldsValuesTuple> kfvMtu = {{
913+
"Ethernet0",
914+
SET_COMMAND, {
915+
{ "mtu", "1234" },
916+
}
917+
}};
918+
919+
// Refill consumer
920+
consumer->addToSync(kfvMtu);
921+
922+
_hook_sai_port_api();
923+
current_sai_api_call_count = _sai_set_admin_state_down_count;
924+
925+
// Apply configuration
926+
static_cast<Orch*>(gPortsOrch)->doTask();
927+
928+
_unhook_sai_port_api();
929+
930+
ASSERT_TRUE(gPortsOrch->getPort("Ethernet0", p));
931+
ASSERT_TRUE(p.m_admin_state_up);
932+
933+
// Verify mtu is set
934+
ASSERT_EQ(p.m_mtu, 1234);
935+
936+
// Verify no admin-disable then admin-enable
937+
ASSERT_EQ(_sai_set_admin_state_down_count, current_sai_api_call_count);
938+
ASSERT_EQ(_sai_set_admin_state_up_count, current_sai_api_call_count);
939+
912940
// Dump pending tasks
913941
std::vector<std::string> taskList;
914942
gPortsOrch->dumpPendingTasks(taskList);

0 commit comments

Comments
 (0)