Skip to content

Commit b8f618c

Browse files
committed
Support port mtu update w/o gearbox
1 parent 16cae21 commit b8f618c

File tree

4 files changed

+38
-60
lines changed

4 files changed

+38
-60
lines changed

orchagent/macsecorch.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -1275,17 +1275,7 @@ bool MACsecOrch::createMACsecPort(
12751275
phy);
12761276
});
12771277

1278-
if (!m_port_orch->getPortMtu(port.m_port_id, macsec_port.m_original_mtu))
1279-
{
1280-
SWSS_LOG_WARN("Cannot get Port MTU at the port %s", port_name.c_str());
1281-
return false;
1282-
}
1283-
m_port_orch->setMACsecEnabledState(port.m_port_id, true);
1284-
if (!m_port_orch->setPortMtu(port.m_port_id, macsec_port.m_original_mtu))
1285-
{
1286-
SWSS_LOG_WARN("Cannot set MTU to %u at the MACsec enabled port %s", macsec_port.m_original_mtu, port_name.c_str());
1287-
return false;
1288-
}
1278+
m_port_orch->setMACsecEnabledState(port_id, true);
12891279

12901280
if (phy)
12911281
{
@@ -1554,12 +1544,7 @@ bool MACsecOrch::deleteMACsecPort(
15541544
result &= false;
15551545
}
15561546

1557-
m_port_orch->setMACsecEnabledState(port.m_port_id, false);
1558-
if (!m_port_orch->setPortMtu(port.m_port_id, macsec_port.m_original_mtu))
1559-
{
1560-
SWSS_LOG_WARN("Cannot set MTU to %u at the port %s", macsec_port.m_original_mtu, port_name.c_str());
1561-
return false;
1562-
}
1547+
m_port_orch->setMACsecEnabledState(port_id, false);
15631548

15641549
if (phy)
15651550
{

orchagent/macsecorch.h

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class MACsecOrch : public Orch
109109
bool m_sci_in_sectag;
110110
bool m_enable;
111111
uint32_t m_original_ipg;
112-
uint32_t m_original_mtu;
113112
};
114113
struct MACsecObject
115114
{

orchagent/portsorch.cpp

+32-37
Original file line numberDiff line numberDiff line change
@@ -1135,60 +1135,35 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up)
11351135
return true;
11361136
}
11371137

1138-
bool PortsOrch::getPortMtu(sai_object_id_t id, sai_uint32_t &mtu)
1139-
{
1140-
SWSS_LOG_ENTER();
1141-
1142-
sai_attribute_t attr;
1143-
attr.id = SAI_PORT_ATTR_MTU;
1144-
1145-
sai_status_t status = sai_port_api->get_port_attribute(id, 1, &attr);
1146-
1147-
if (status != SAI_STATUS_SUCCESS)
1148-
{
1149-
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
1150-
if (handle_status != task_success)
1151-
{
1152-
return parseHandleSaiStatusFailure(handle_status);
1153-
}
1154-
}
1155-
1156-
mtu = attr.value.u32 - (uint32_t)(sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
1157-
1158-
if (isMACsecPort(id))
1159-
{
1160-
mtu -= MAX_MACSEC_SECTAG_SIZE;
1161-
}
1162-
1163-
return true;
1164-
}
1165-
1166-
bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu)
1138+
bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
11671139
{
11681140
SWSS_LOG_ENTER();
11691141

11701142
sai_attribute_t attr;
11711143
attr.id = SAI_PORT_ATTR_MTU;
11721144
/* mtu + 14 + 4 + 4 = 22 bytes */
1173-
attr.value.u32 = (uint32_t)(mtu + sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
1145+
mtu += (uint32_t)(sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
1146+
attr.value.u32 = mtu;
11741147

1175-
if (isMACsecPort(id))
1148+
if (isMACsecPort(port.m_port_id))
11761149
{
11771150
attr.value.u32 += MAX_MACSEC_SECTAG_SIZE;
11781151
}
11791152

1180-
sai_status_t status = sai_port_api->set_port_attribute(id, &attr);
1153+
sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
11811154
if (status != SAI_STATUS_SUCCESS)
11821155
{
11831156
SWSS_LOG_ERROR("Failed to set MTU %u to port pid:%" PRIx64 ", rv:%d",
1184-
attr.value.u32, id, status);
1157+
attr.value.u32, port.m_port_id, status);
11851158
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
11861159
if (handle_status != task_success)
11871160
{
11881161
return parseHandleSaiStatusFailure(handle_status);
11891162
}
11901163
}
1191-
SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, id);
1164+
1165+
setGearboxPortsAttr(port, SAI_PORT_ATTR_MTU, &mtu);
1166+
SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, port.m_port_id);
11921167
return true;
11931168
}
11941169

@@ -2021,7 +1996,7 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_
20211996
/*
20221997
* If Gearbox is enabled and this is a Gearbox port then set the attributes accordingly.
20231998
*/
2024-
bool PortsOrch::setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value)
1999+
bool PortsOrch::setGearboxPortsAttr(const Port &port, sai_port_attr_t id, void *value)
20252000
{
20262001
bool status = false;
20272002

@@ -2039,7 +2014,7 @@ bool PortsOrch::setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value)
20392014
* If Gearbox is enabled and this is a Gearbox port then set the specific lane attribute.
20402015
* Note: the appl_db is also updated (Gearbox config_db tables are TBA).
20412016
*/
2042-
bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value)
2017+
bool PortsOrch::setGearboxPortAttr(const Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value)
20432018
{
20442019
sai_status_t status = SAI_STATUS_SUCCESS;
20452020
sai_object_id_t dest_port_id;
@@ -2093,6 +2068,15 @@ bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_p
20932068
}
20942069
SWSS_LOG_NOTICE("BOX: Set %s lane %s %d", port.m_alias.c_str(), speed_attr.c_str(), speed);
20952070
break;
2071+
case SAI_PORT_ATTR_MTU:
2072+
attr.id = id;
2073+
attr.value.u32 = *static_cast<sai_uint32_t*>(value);
2074+
if (LINE_PORT_TYPE == port_type && isMACsecPort(dest_port_id))
2075+
{
2076+
attr.value.u32 += MAX_MACSEC_SECTAG_SIZE;
2077+
}
2078+
SWSS_LOG_NOTICE("BOX: Set %s MTU %d", port.m_alias.c_str(), attr.value.u32);
2079+
break;
20962080
default:
20972081
return false;
20982082
}
@@ -3302,7 +3286,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
33023286

33033287
if (mtu != 0 && mtu != p.m_mtu)
33043288
{
3305-
if (setPortMtu(p.m_port_id, mtu))
3289+
if (setPortMtu(p, mtu))
33063290
{
33073291
p.m_mtu = mtu;
33083292
m_portList[alias] = p;
@@ -6686,6 +6670,8 @@ bool PortsOrch::initGearboxPort(Port &port)
66866670
SWSS_LOG_NOTICE("BOX: Connected Gearbox ports; system-side:0x%" PRIx64 " to line-side:0x%" PRIx64, systemPort, linePort);
66876671
m_gearboxPortListLaneMap[port.m_port_id] = make_tuple(systemPort, linePort);
66886672
port.m_line_side_id = linePort;
6673+
saiOidToAlias[systemPort] = port.m_alias;
6674+
saiOidToAlias[linePort] = port.m_alias;
66896675

66906676
/* Add gearbox system/line port name map to counter table */
66916677
FieldValueTuple tuple(port.m_alias + "_system", sai_serialize_object_id(systemPort));
@@ -7192,6 +7178,13 @@ void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled)
71927178
{
71937179
SWSS_LOG_ENTER();
71947180

7181+
Port p;
7182+
if (!getPort(port_id, p))
7183+
{
7184+
SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, port_id);
7185+
return;
7186+
}
7187+
71957188
if (enabled)
71967189
{
71977190
m_macsecEnabledPorts.insert(port_id);
@@ -7200,6 +7193,8 @@ void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled)
72007193
{
72017194
m_macsecEnabledPorts.erase(port_id);
72027195
}
7196+
7197+
setPortMtu(p, p.m_mtu);
72037198
}
72047199

72057200
bool PortsOrch::isMACsecPort(sai_object_id_t port_id) const

orchagent/portsorch.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#define FCS_LEN 4
2020
#define VLAN_TAG_LEN 4
21-
#define MAX_MACSEC_SECTAG_SIZE (32)
21+
#define MAX_MACSEC_SECTAG_SIZE 32
2222
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
2323
#define PORT_RATE_COUNTER_FLEX_COUNTER_GROUP "PORT_RATE_COUNTER"
2424
#define PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP "PORT_BUFFER_DROP_STAT"
@@ -177,8 +177,6 @@ class PortsOrch : public Orch, public Subject
177177

178178
void setMACsecEnabledState(sai_object_id_t port_id, bool enabled);
179179
bool isMACsecPort(sai_object_id_t port_id) const;
180-
bool getPortMtu(sai_object_id_t id, sai_uint32_t &mtu);
181-
bool setPortMtu(sai_object_id_t id, sai_uint32_t mtu);
182180

183181
private:
184182
unique_ptr<Table> m_counterTable;
@@ -307,6 +305,7 @@ class PortsOrch : public Orch, public Subject
307305

308306
bool setPortAdminStatus(Port &port, bool up);
309307
bool getPortAdminStatus(sai_object_id_t id, bool& up);
308+
bool setPortMtu(const Port& port, sai_uint32_t mtu);
310309
bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid);
311310
bool setPortPvid (Port &port, sai_uint32_t pvid);
312311
bool getPortPvid(Port &port, sai_uint32_t &pvid);
@@ -321,8 +320,8 @@ class PortsOrch : public Orch, public Subject
321320
void initPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id);
322321
task_process_status setPortSpeed(Port &port, sai_uint32_t speed);
323322
bool getPortSpeed(sai_object_id_t id, sai_uint32_t &speed);
324-
bool setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value);
325-
bool setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value);
323+
bool setGearboxPortsAttr(const Port &port, sai_port_attr_t id, void *value);
324+
bool setGearboxPortAttr(const Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value);
326325

327326
task_process_status setPortAdvSpeeds(sai_object_id_t port_id, std::vector<sai_uint32_t>& speed_list);
328327

0 commit comments

Comments
 (0)