Skip to content

Commit 7cf55ff

Browse files
stepanblyschakyxieca
authored andcommitted
[portsorch] Change speed set flow (sonic-net#764)
- Cache port admin status and speed in port structure in initializePort(); - Don't flap port if port is already down during speed set; - Don't set admin status if desired status is already set; - Set admin status as last step in doPortTask() Signed-off-by: Stepan Blyschak <[email protected]>
1 parent a6d60f2 commit 7cf55ff

File tree

3 files changed

+77
-41
lines changed

3 files changed

+77
-41
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_up = 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

+74-40
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,25 @@ bool PortsOrch::setPortAdminStatus(sai_object_id_t id, bool up)
542542
return true;
543543
}
544544

545+
bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up)
546+
{
547+
SWSS_LOG_ENTER();
548+
549+
sai_attribute_t attr;
550+
attr.id = SAI_PORT_ATTR_ADMIN_STATE;
551+
552+
sai_status_t status = sai_port_api->get_port_attribute(id, 1, &attr);
553+
if (status != SAI_STATUS_SUCCESS)
554+
{
555+
SWSS_LOG_ERROR("Failed to get admin status for port pid:%lx", id);
556+
return false;
557+
}
558+
559+
up = attr.value.booldata;
560+
561+
return true;
562+
}
563+
545564
bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu)
546565
{
547566
SWSS_LOG_ENTER();
@@ -1731,45 +1750,43 @@ void PortsOrch::doPortTask(Consumer &consumer)
17311750
}
17321751
else
17331752
{
1734-
sai_uint32_t current_speed;
1735-
17361753
if (!isSpeedSupported(alias, p.m_port_id, speed))
17371754
{
17381755
it++;
17391756
continue;
17401757
}
17411758

1742-
if (getPortSpeed(p.m_port_id, current_speed))
1759+
if (p.m_admin_state_up)
17431760
{
1744-
if (speed != current_speed)
1761+
/* Bring port down before applying speed */
1762+
if (!setPortAdminStatus(p.m_port_id, false))
17451763
{
1746-
if (setPortAdminStatus(p.m_port_id, false))
1747-
{
1748-
if (setPortSpeed(p.m_port_id, speed))
1749-
{
1750-
SWSS_LOG_NOTICE("Set port %s speed to %u", alias.c_str(), speed);
1751-
}
1752-
else
1753-
{
1754-
SWSS_LOG_ERROR("Failed to set port %s speed to %u", alias.c_str(), speed);
1755-
it++;
1756-
continue;
1757-
}
1758-
}
1759-
else
1760-
{
1761-
SWSS_LOG_ERROR("Failed to set port admin status DOWN to set speed");
1762-
it++;
1763-
continue;
1764-
}
1764+
SWSS_LOG_ERROR("Failed to set port %s admin status DOWN to set speed", alias.c_str());
1765+
it++;
1766+
continue;
1767+
}
1768+
1769+
p.m_admin_state_up = false;
1770+
m_portList[alias] = p;
1771+
1772+
if (!setPortSpeed(p.m_port_id, speed))
1773+
{
1774+
SWSS_LOG_ERROR("Failed to set port %s speed to %u", alias.c_str(), speed);
1775+
it++;
1776+
continue;
17651777
}
17661778
}
17671779
else
17681780
{
1769-
SWSS_LOG_ERROR("Failed to get current speed for port %s", alias.c_str());
1770-
it++;
1771-
continue;
1781+
/* Port is already down, setting speed */
1782+
if (!setPortSpeed(p.m_port_id, speed))
1783+
{
1784+
SWSS_LOG_ERROR("Failed to set port %s speed to %u", alias.c_str(), speed);
1785+
it++;
1786+
continue;
1787+
}
17721788
}
1789+
SWSS_LOG_NOTICE("Set port %s speed to %u", alias.c_str(), speed);
17731790
}
17741791
m_portList[alias].m_speed = speed;
17751792
}
@@ -1794,20 +1811,6 @@ void PortsOrch::doPortTask(Consumer &consumer)
17941811
}
17951812
}
17961813

1797-
if (!admin_status.empty())
1798-
{
1799-
if (setPortAdminStatus(p.m_port_id, admin_status == "up"))
1800-
{
1801-
SWSS_LOG_NOTICE("Set port %s admin status to %s", alias.c_str(), admin_status.c_str());
1802-
}
1803-
else
1804-
{
1805-
SWSS_LOG_ERROR("Failed to set port %s admin status to %s", alias.c_str(), admin_status.c_str());
1806-
it++;
1807-
continue;
1808-
}
1809-
}
1810-
18111814
if (!fec_mode.empty())
18121815
{
18131816
if (fec_mode_map.find(fec_mode) != fec_mode_map.end())
@@ -1848,6 +1851,23 @@ void PortsOrch::doPortTask(Consumer &consumer)
18481851
continue;
18491852
}
18501853
}
1854+
1855+
/* Last step set port admin status */
1856+
if (!admin_status.empty() && (p.m_admin_state_up != (admin_status == "up")))
1857+
{
1858+
if (setPortAdminStatus(p.m_port_id, admin_status == "up"))
1859+
{
1860+
p.m_admin_state_up = (admin_status == "up");
1861+
m_portList[alias] = p;
1862+
SWSS_LOG_NOTICE("Set port %s admin status to %s", alias.c_str(), admin_status.c_str());
1863+
}
1864+
else
1865+
{
1866+
SWSS_LOG_ERROR("Failed to set port %s admin status to %s", alias.c_str(), admin_status.c_str());
1867+
it++;
1868+
continue;
1869+
}
1870+
}
18511871
}
18521872
}
18531873
else
@@ -2412,6 +2432,20 @@ bool PortsOrch::initializePort(Port &port)
24122432
port.m_oper_status = SAI_PORT_OPER_STATUS_DOWN;
24132433
}
24142434

2435+
/* initialize port admin status */
2436+
if (!getPortAdminStatus(port.m_port_id, port.m_admin_state_up))
2437+
{
2438+
SWSS_LOG_ERROR("Failed to get initial port admin status %s", port.m_alias.c_str());
2439+
return false;
2440+
}
2441+
2442+
/* initialize port admin speed */
2443+
if (!getPortSpeed(port.m_port_id, port.m_speed))
2444+
{
2445+
SWSS_LOG_ERROR("Failed to get initial port admin speed %d", port.m_speed);
2446+
return false;
2447+
}
2448+
24152449
/*
24162450
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
24172451
*/

orchagent/portsorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class PortsOrch : public Orch, public Subject
161161
bool initPort(const string &alias, const set<int> &lane_set);
162162

163163
bool setPortAdminStatus(sai_object_id_t id, bool up);
164+
bool getPortAdminStatus(sai_object_id_t id, bool& up);
164165
bool setPortMtu(sai_object_id_t id, sai_uint32_t mtu);
165166
bool setPortPvid (Port &port, sai_uint32_t pvid);
166167
bool getPortPvid(Port &port, sai_uint32_t &pvid);

0 commit comments

Comments
 (0)