Skip to content

Commit dd12a28

Browse files
committed
Set mtu for MACsec
Signed-off-by: Ze Gan <[email protected]>
1 parent dc88d55 commit dd12a28

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

orchagent/macsecorch.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,18 @@ 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", phy->m_original_mtu, port_name.c_str());
1287+
return false;
1288+
}
1289+
12781290
if (phy)
12791291
{
12801292
if (!setPFCForward(port_id, true))
@@ -1542,6 +1554,13 @@ bool MACsecOrch::deleteMACsecPort(
15421554
result &= false;
15431555
}
15441556

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", phy->m_original_mtu, port_name.c_str());
1561+
return false;
1562+
}
1563+
15451564
if (phy)
15461565
{
15471566
if (!setPFCForward(port_id, false))

orchagent/macsecorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ 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;
112113
};
113114
struct MACsecObject
114115
{

orchagent/portsorch.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,34 @@ 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+
11381166
bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu)
11391167
{
11401168
SWSS_LOG_ENTER();
@@ -1144,6 +1172,11 @@ bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu)
11441172
/* mtu + 14 + 4 + 4 = 22 bytes */
11451173
attr.value.u32 = (uint32_t)(mtu + sizeof(struct ether_header) + FCS_LEN + VLAN_TAG_LEN);
11461174

1175+
if (isMACsecPort(id))
1176+
{
1177+
attr.value.u32 += MAX_MACSEC_SECTAG_SIZE;
1178+
}
1179+
11471180
sai_status_t status = sai_port_api->set_port_attribute(id, &attr);
11481181
if (status != SAI_STATUS_SUCCESS)
11491182
{
@@ -7154,3 +7187,24 @@ bool PortsOrch::decrFdbCount(const std::string& alias, int count)
71547187
}
71557188
return true;
71567189
}
7190+
7191+
void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled)
7192+
{
7193+
SWSS_LOG_ENTER();
7194+
7195+
if (enabled)
7196+
{
7197+
m_macsecEnabledPorts.insert(port_id);
7198+
}
7199+
else
7200+
{
7201+
m_macsecEnabledPorts.erase(port_id);
7202+
}
7203+
}
7204+
7205+
bool PortsOrch::isMACsecPort(sai_object_id_t port_id) const
7206+
{
7207+
SWSS_LOG_ENTER();
7208+
7209+
return m_macsecEnabledPorts.find(port_id) != m_macsecEnabledPorts.end();
7210+
}

orchagent/portsorch.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#define FCS_LEN 4
2020
#define VLAN_TAG_LEN 4
21+
#define MAX_MACSEC_SECTAG_SIZE (32)
2122
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
2223
#define PORT_RATE_COUNTER_FLEX_COUNTER_GROUP "PORT_RATE_COUNTER"
2324
#define PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP "PORT_BUFFER_DROP_STAT"
@@ -174,6 +175,11 @@ class PortsOrch : public Orch, public Subject
174175

175176
bool decrFdbCount(const string& alias, int count);
176177

178+
void setMACsecEnabledState(sai_object_id_t port_id, bool enabled);
179+
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);
182+
177183
private:
178184
unique_ptr<Table> m_counterTable;
179185
unique_ptr<Table> m_counterLagTable;
@@ -301,7 +307,6 @@ class PortsOrch : public Orch, public Subject
301307

302308
bool setPortAdminStatus(Port &port, bool up);
303309
bool getPortAdminStatus(sai_object_id_t id, bool& up);
304-
bool setPortMtu(sai_object_id_t id, sai_uint32_t mtu);
305310
bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid);
306311
bool setPortPvid (Port &port, sai_uint32_t pvid);
307312
bool getPortPvid(Port &port, sai_uint32_t &pvid);
@@ -374,8 +379,8 @@ class PortsOrch : public Orch, public Subject
374379
void voqSyncAddLagMember(Port &lag, Port &port);
375380
void voqSyncDelLagMember(Port &lag, Port &port);
376381
unique_ptr<LagIdAllocator> m_lagIdAllocator;
382+
set<sai_object_id_t> m_macsecEnabledPorts;
377383

378384
std::unordered_set<std::string> generateCounterStats(const string& type, bool gearbox = false);
379-
380385
};
381386
#endif /* SWSS_PORTSORCH_H */

0 commit comments

Comments
 (0)