Skip to content

Commit 28cfb2b

Browse files
committed
Fix issue if MTU wasn't set
Signed-off-by: Ze Gan <[email protected]>
1 parent e3ce7ca commit 28cfb2b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

orchagent/portsorch.cpp

+39-2
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,30 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up)
11611161
return true;
11621162
}
11631163

1164+
bool PortsOrch::getPortMtu(const Port& port, sai_uint32_t &mtu)
1165+
{
1166+
SWSS_LOG_ENTER();
1167+
1168+
sai_attribute_t attr;
1169+
attr.id = SAI_PORT_ATTR_MTU;
1170+
1171+
sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr);
1172+
1173+
if (status != SAI_STATUS_SUCCESS)
1174+
{
1175+
return false;
1176+
}
1177+
1178+
mtu = attr.value.u32 - (uint32_t)(sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
1179+
1180+
if (isMACsecPort(port.m_port_id))
1181+
{
1182+
mtu -= MAX_MACSEC_SECTAG_SIZE;
1183+
}
1184+
1185+
return true;
1186+
}
1187+
11641188
bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
11651189
{
11661190
SWSS_LOG_ENTER();
@@ -1188,7 +1212,10 @@ bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
11881212
}
11891213
}
11901214

1191-
setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu);
1215+
if (m_gearboxEnabled)
1216+
{
1217+
setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu);
1218+
}
11921219
SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, port.m_port_id);
11931220
return true;
11941221
}
@@ -4551,6 +4578,13 @@ bool PortsOrch::initializePort(Port &port)
45514578
return false;
45524579
}
45534580

4581+
/* initialize port mtu */
4582+
if (!getPortMtu(port, port.m_mtu))
4583+
{
4584+
SWSS_LOG_ERROR("Failed to get initial port mtu %d", port.m_mtu);
4585+
return false;
4586+
}
4587+
45544588
/*
45554589
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
45564590
*/
@@ -7451,7 +7485,10 @@ void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled)
74517485
m_macsecEnabledPorts.erase(port_id);
74527486
}
74537487

7454-
setPortMtu(p, p.m_mtu);
7488+
if (p.m_mtu)
7489+
{
7490+
setPortMtu(p, p.m_mtu);
7491+
}
74557492
}
74567493

74577494
bool PortsOrch::isMACsecPort(sai_object_id_t port_id) const

orchagent/portsorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class PortsOrch : public Orch, public Subject
311311

312312
bool setPortAdminStatus(Port &port, bool up);
313313
bool getPortAdminStatus(sai_object_id_t id, bool& up);
314+
bool getPortMtu(const Port& port, sai_uint32_t &mtu);
314315
bool setPortMtu(const Port& port, sai_uint32_t mtu);
315316
bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid);
316317
bool setPortPvid (Port &port, sai_uint32_t pvid);

0 commit comments

Comments
 (0)