Skip to content

Commit 2971783

Browse files
author
Stepan Blyschak
committed
[portsorch] Don't flap port when setting speed if port is down
Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 230086b commit 2971783

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

orchagent/port.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class Port
7171
int m_index = 0; // PHY_PORT: index
7272
uint32_t m_mtu = DEFAULT_MTU;
7373
uint32_t m_speed = 0; // Mbps
74-
bool m_autoneg = 0;
74+
bool m_autoneg = false;
75+
bool m_admin_state = false;
7576
sai_object_id_t m_port_id = 0;
7677
sai_port_fec_mode_t m_fec_mode = SAI_PORT_FEC_MODE_NONE;
7778
VlanInfo m_vlan_info;

orchagent/portsorch.cpp

+46-20
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
16741674
*
16751675
* 1. Get supported speed list and validate if the target speed is within the list
16761676
* 2. Get the current port speed and check if it is the same as the target speed
1677-
* 3. Set port admin status to DOWN before changing the speed
1677+
* 3. Set port admin status to DOWN before changing the speed if port is admin UP
16781678
* 4. Set port speed
16791679
*/
16801680
if (speed != 0 && speed != p.m_speed)
@@ -1704,22 +1704,24 @@ void PortsOrch::doPortTask(Consumer &consumer)
17041704
continue;
17051705
}
17061706

1707-
if (getPortSpeed(p.m_port_id, current_speed))
1707+
if (!getPortSpeed(p.m_port_id, current_speed))
17081708
{
1709-
if (speed != current_speed)
1709+
SWSS_LOG_ERROR("Failed to get current speed for port %s", alias.c_str());
1710+
it++;
1711+
continue;
1712+
}
1713+
1714+
if (speed != current_speed)
1715+
{
1716+
bool old_admin_state_up = (p.m_admin_state == true);
1717+
1718+
/* if port is up, set it down before applying speed */
1719+
if (old_admin_state_up)
17101720
{
17111721
if (setPortAdminStatus(p.m_port_id, false))
17121722
{
1713-
if (setPortSpeed(p.m_port_id, speed))
1714-
{
1715-
SWSS_LOG_NOTICE("Set port %s speed to %u", alias.c_str(), speed);
1716-
}
1717-
else
1718-
{
1719-
SWSS_LOG_ERROR("Failed to set port %s speed to %u", alias.c_str(), speed);
1720-
it++;
1721-
continue;
1722-
}
1723+
p.m_admin_state = false;
1724+
m_portList[alias] = p;
17231725
}
17241726
else
17251727
{
@@ -1728,12 +1730,34 @@ void PortsOrch::doPortTask(Consumer &consumer)
17281730
continue;
17291731
}
17301732
}
1731-
}
1732-
else
1733-
{
1734-
SWSS_LOG_ERROR("Failed to get current speed for port %s", alias.c_str());
1735-
it++;
1736-
continue;
1733+
1734+
if (setPortSpeed(p.m_port_id, speed))
1735+
{
1736+
SWSS_LOG_NOTICE("Set port %s speed to %u", alias.c_str(), speed);
1737+
p.m_speed = speed;
1738+
}
1739+
else
1740+
{
1741+
SWSS_LOG_ERROR("Failed to set port %s speed to %u", alias.c_str(), speed);
1742+
it++;
1743+
continue;
1744+
}
1745+
1746+
/* if port was up, set it up back */
1747+
if (old_admin_state_up)
1748+
{
1749+
if (setPortAdminStatus(p.m_port_id, true))
1750+
{
1751+
p.m_admin_state = true;
1752+
m_portList[alias] = p;
1753+
}
1754+
else
1755+
{
1756+
SWSS_LOG_ERROR("Failed to set port admin status UP after speed");
1757+
it++;
1758+
continue;
1759+
}
1760+
}
17371761
}
17381762
}
17391763
m_portList[alias].m_speed = speed;
@@ -1759,10 +1783,12 @@ void PortsOrch::doPortTask(Consumer &consumer)
17591783
}
17601784
}
17611785

1762-
if (!admin_status.empty())
1786+
if (!admin_status.empty() && p.m_admin_state != (admin_status == "up"))
17631787
{
17641788
if (setPortAdminStatus(p.m_port_id, admin_status == "up"))
17651789
{
1790+
p.m_admin_state = admin_status == "up";
1791+
m_portList[alias] = p;
17661792
SWSS_LOG_NOTICE("Set port %s admin status to %s", alias.c_str(), admin_status.c_str());
17671793
}
17681794
else

0 commit comments

Comments
 (0)