From 9ec471adc95b9cea1ffcdc6686a875f5ed70f9fe Mon Sep 17 00:00:00 2001 From: Ze Gan Date: Wed, 3 Aug 2022 02:32:22 +0000 Subject: [PATCH] Fix issue if MTU wasn't set Signed-off-by: Ze Gan --- orchagent/portsorch.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- orchagent/portsorch.h | 1 + 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 4f684e88e9..1daf56ad9b 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1161,6 +1161,30 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up) return true; } +bool PortsOrch::getPortMtu(const Port& port, sai_uint32_t &mtu) +{ + SWSS_LOG_ENTER(); + + sai_attribute_t attr; + attr.id = SAI_PORT_ATTR_MTU; + + sai_status_t status = sai_port_api->get_port_attribute(port.m_port_id, 1, &attr); + + if (status != SAI_STATUS_SUCCESS) + { + return false; + } + + mtu = attr.value.u32 - (uint32_t)(sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN); + + if (isMACsecPort(port.m_port_id)) + { + mtu -= MAX_MACSEC_SECTAG_SIZE; + } + + return true; +} + bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu) { SWSS_LOG_ENTER(); @@ -1188,7 +1212,10 @@ bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu) } } - setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu); + if (m_gearboxEnabled) + { + setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu); + } SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, port.m_port_id); return true; } @@ -4551,6 +4578,12 @@ bool PortsOrch::initializePort(Port &port) return false; } + /* initialize port mtu */ + if (!getPortMtu(port, port.m_mtu)) + { + SWSS_LOG_ERROR("Failed to get initial port mtu %d", port.m_mtu); + } + /* * always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB. */ @@ -7451,7 +7484,10 @@ void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled) m_macsecEnabledPorts.erase(port_id); } - setPortMtu(p, p.m_mtu); + if (p.m_mtu) + { + setPortMtu(p, p.m_mtu); + } } bool PortsOrch::isMACsecPort(sai_object_id_t port_id) const diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 8708efdb9d..4880112958 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -311,6 +311,7 @@ class PortsOrch : public Orch, public Subject bool setPortAdminStatus(Port &port, bool up); bool getPortAdminStatus(sai_object_id_t id, bool& up); + bool getPortMtu(const Port& port, sai_uint32_t &mtu); bool setPortMtu(const Port& port, sai_uint32_t mtu); bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid); bool setPortPvid (Port &port, sai_uint32_t pvid);