Skip to content

Commit c88d845

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

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

orchagent/portsorch.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,34 @@ 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+
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
1176+
if (handle_status != task_success)
1177+
{
1178+
return false;
1179+
}
1180+
}
1181+
1182+
mtu = attr.value.u32 - (uint32_t)(sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
1183+
1184+
if (isMACsecPort(port.m_port_id))
1185+
{
1186+
mtu -= MAX_MACSEC_SECTAG_SIZE;
1187+
}
1188+
1189+
return true;
1190+
}
1191+
11641192
bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
11651193
{
11661194
SWSS_LOG_ENTER();
@@ -1188,7 +1216,10 @@ bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
11881216
}
11891217
}
11901218

1191-
setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu);
1219+
if (m_gearboxEnabled)
1220+
{
1221+
setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu);
1222+
}
11921223
SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, port.m_port_id);
11931224
return true;
11941225
}
@@ -4551,6 +4582,13 @@ bool PortsOrch::initializePort(Port &port)
45514582
return false;
45524583
}
45534584

4585+
/* initialize port mtu */
4586+
if (!getPortMtu(port, port.m_mtu))
4587+
{
4588+
SWSS_LOG_ERROR("Failed to get initial port mtu %d", port.m_mtu);
4589+
return false;
4590+
}
4591+
45544592
/*
45554593
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
45564594
*/

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)