Skip to content

Commit

Permalink
Try get port operational speed from STATE DB (sonic-net#2119)
Browse files Browse the repository at this point in the history
* Put port operational speed to STATE DB
* Remove previous workaround [orchagent] Put port configuration to APPL_DB according to autoneg mode sonic-net#1769
  • Loading branch information
Junchao-Mellanox authored Mar 1, 2022
1 parent 828cccf commit 0a99f54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 58 deletions.
18 changes: 13 additions & 5 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4934,7 +4934,7 @@ bool PortsOrch::addLag(string lag_alias, uint32_t spa_id, int32_t switch_id)
auto lagport = m_portList.find(lag_alias);
if (lagport != m_portList.end())
{
/* The deletion of bridgeport attached to the lag may still be
/* The deletion of bridgeport attached to the lag may still be
* pending due to fdb entries still present on the lag. Wait
* until the cleanup is done.
*/
Expand Down Expand Up @@ -5628,8 +5628,12 @@ void PortsOrch::doTask(NotificationConsumer &consumer)
SWSS_LOG_NOTICE("%s oper speed is %d", port.m_alias.c_str(), speed);
updateDbPortOperSpeed(port, speed);
}
else
{
updateDbPortOperSpeed(port, 0);
}
}

/* update m_portList */
m_portList[port.m_alias] = port;
}
Expand Down Expand Up @@ -5689,9 +5693,9 @@ void PortsOrch::updateDbPortOperSpeed(Port &port, sai_uint32_t speed)
SWSS_LOG_ENTER();

vector<FieldValueTuple> tuples;
FieldValueTuple tuple("speed", to_string(speed));
tuples.push_back(tuple);
m_portTable->set(port.m_alias, tuples);
string speedStr = speed != 0 ? to_string(speed) : "N/A";
tuples.emplace_back(std::make_pair("speed", speedStr));
m_portStateTable.set(port.m_alias, tuples);

// We don't set port.m_speed = speed here, because CONFIG_DB still hold the old
// value. If we set it here, next time configure any attributes related port will
Expand Down Expand Up @@ -5738,6 +5742,10 @@ void PortsOrch::refreshPortStatus()
SWSS_LOG_INFO("%s oper speed is %d", port.m_alias.c_str(), speed);
updateDbPortOperSpeed(port, speed);
}
else
{
updateDbPortOperSpeed(port, 0);
}
}
}
}
Expand Down
54 changes: 1 addition & 53 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo

void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map)
{
string autoneg;
vector<FieldValueTuple> attrs;
vector<FieldValueTuple> autoneg_attrs;
vector<FieldValueTuple> force_attrs;

auto it = port_cfg_map.begin();
while (it != port_cfg_map.end())
{
Expand All @@ -247,54 +242,7 @@ void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple>
/* No support for port delete yet */
if (op == SET_COMMAND)
{

for (auto i : values)
{
auto field = fvField(i);
if (field == "adv_speeds")
{
autoneg_attrs.push_back(i);
}
else if (field == "adv_interface_types")
{
autoneg_attrs.push_back(i);
}
else if (field == "speed")
{
force_attrs.push_back(i);
}
else if (field == "interface_type")
{
force_attrs.push_back(i);
}
else if (field == "autoneg")
{
autoneg = fvValue(i);
attrs.push_back(i);
}
else
{
attrs.push_back(i);
}
}
if (autoneg == "on") // autoneg is on, only put adv_speeds and adv_interface_types to APPL_DB
{
attrs.insert(attrs.end(), autoneg_attrs.begin(), autoneg_attrs.end());
}
else if (autoneg == "off") // autoneg is off, only put speed and interface_type to APPL_DB
{
attrs.insert(attrs.end(), force_attrs.begin(), force_attrs.end());
}
else // autoneg is not configured, put all attributes to APPL_DB
{
attrs.insert(attrs.end(), autoneg_attrs.begin(), autoneg_attrs.end());
attrs.insert(attrs.end(), force_attrs.begin(), force_attrs.end());
}
p.set(key, attrs);
attrs.clear();
autoneg_attrs.clear();
force_attrs.clear();
autoneg.clear();
p.set(key, values);
}

it = port_cfg_map.erase(it);
Expand Down

0 comments on commit 0a99f54

Please sign in to comment.