@@ -1674,7 +1674,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
1674
1674
*
1675
1675
* 1. Get supported speed list and validate if the target speed is within the list
1676
1676
* 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
1678
1678
* 4. Set port speed
1679
1679
*/
1680
1680
if (speed != 0 && speed != p.m_speed )
@@ -1704,22 +1704,24 @@ void PortsOrch::doPortTask(Consumer &consumer)
1704
1704
continue ;
1705
1705
}
1706
1706
1707
- if (getPortSpeed (p.m_port_id , current_speed))
1707
+ if (! getPortSpeed (p.m_port_id , current_speed))
1708
1708
{
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)
1710
1720
{
1711
1721
if (setPortAdminStatus (p.m_port_id , false ))
1712
1722
{
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;
1723
1725
}
1724
1726
else
1725
1727
{
@@ -1728,12 +1730,34 @@ void PortsOrch::doPortTask(Consumer &consumer)
1728
1730
continue ;
1729
1731
}
1730
1732
}
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
+ }
1737
1761
}
1738
1762
}
1739
1763
m_portList[alias].m_speed = speed;
@@ -1759,10 +1783,12 @@ void PortsOrch::doPortTask(Consumer &consumer)
1759
1783
}
1760
1784
}
1761
1785
1762
- if (!admin_status.empty ())
1786
+ if (!admin_status.empty () && p. m_admin_state != (admin_status == " up " ) )
1763
1787
{
1764
1788
if (setPortAdminStatus (p.m_port_id , admin_status == " up" ))
1765
1789
{
1790
+ p.m_admin_state = admin_status == " up" ;
1791
+ m_portList[alias] = p;
1766
1792
SWSS_LOG_NOTICE (" Set port %s admin status to %s" , alias.c_str (), admin_status.c_str ());
1767
1793
}
1768
1794
else
0 commit comments