Skip to content

Commit 452cbc1

Browse files
authored
[macsecorch]: Add IPG adjusting for MACsec gearbox model (sonic-net#1925)
* Add IPGadjusting for MACsec gearbox model Signed-off-by: Ze Gan <[email protected]> * fix bug Signed-off-by: Ze Gan <[email protected]> * fix bug Signed-off-by: Ze Gan <[email protected]> * Polish variable name and comment Signed-off-by: Ze Gan <[email protected]> * Set IPG to optional Signed-off-by: Ze Gan <[email protected]> * refactor code Signed-off-by: Ze Gan <[email protected]>
1 parent f248e26 commit 452cbc1

File tree

6 files changed

+166
-37
lines changed

6 files changed

+166
-37
lines changed

lib/gearboxutils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ std::map<int, gearbox_phy_t> GearboxUtils::loadPhyMap(Table *gearboxTable)
189189
{
190190
phy.context_id = std::stoi(val.second);
191191
}
192+
else if (val.first == "macsec_ipg")
193+
{
194+
phy.macsec_ipg = std::stoi(val.second);
195+
}
192196
}
193197
gearboxPhyMap[phy.phy_id] = phy;
194198
}

lib/gearboxutils.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct
4545
uint32_t address;
4646
uint32_t bus_id;
4747
uint32_t context_id;
48+
uint32_t macsec_ipg;
4849
} gearbox_phy_t;
4950

5051
typedef struct

orchagent/macsecorch.cpp

+88-33
Original file line numberDiff line numberDiff line change
@@ -382,24 +382,27 @@ class MACsecOrchContext
382382
return m_macsec_sa;
383383
}
384384

385-
private:
386-
MACsecOrchContext(MACsecOrch *orch) : m_orch(orch),
387-
m_port_name(nullptr),
388-
m_direction(SAI_MACSEC_DIRECTION_EGRESS),
389-
m_sci(nullptr),
390-
m_an(nullptr),
391-
m_port(nullptr),
392-
m_macsec_obj(nullptr),
393-
m_port_id(nullptr),
394-
m_switch_id(nullptr),
395-
m_macsec_port(nullptr),
396-
m_acl_table(nullptr),
397-
m_macsec_sc(nullptr),
398-
m_macsec_sa(nullptr)
385+
const gearbox_phy_t* get_gearbox_phy()
399386
{
387+
if (m_gearbox_phy)
388+
{
389+
return m_gearbox_phy;
390+
}
391+
auto switch_id = get_switch_id();
392+
if (switch_id == nullptr || get_port() == nullptr)
393+
{
394+
SWSS_LOG_ERROR("Switch/Port wasn't provided");
395+
return nullptr;
396+
}
397+
if (*switch_id == gSwitchId)
398+
{
399+
return nullptr;
400+
}
401+
m_gearbox_phy = m_orch->m_port_orch->getGearboxPhy(*get_port());
402+
return m_gearbox_phy;
400403
}
401404

402-
const Port *get_port()
405+
Port *get_port()
403406
{
404407
if (m_port == nullptr)
405408
{
@@ -424,6 +427,24 @@ class MACsecOrchContext
424427
return m_port.get();
425428
}
426429

430+
private:
431+
MACsecOrchContext(MACsecOrch *orch) : m_orch(orch),
432+
m_port_name(nullptr),
433+
m_direction(SAI_MACSEC_DIRECTION_EGRESS),
434+
m_sci(nullptr),
435+
m_an(nullptr),
436+
m_port(nullptr),
437+
m_macsec_obj(nullptr),
438+
m_port_id(nullptr),
439+
m_switch_id(nullptr),
440+
m_macsec_port(nullptr),
441+
m_acl_table(nullptr),
442+
m_macsec_sc(nullptr),
443+
m_macsec_sa(nullptr),
444+
m_gearbox_phy(nullptr)
445+
{
446+
}
447+
427448
MACsecOrch *m_orch;
428449
std::shared_ptr<std::string> m_port_name;
429450
sai_macsec_direction_t m_direction;
@@ -440,6 +461,7 @@ class MACsecOrchContext
440461

441462
MACsecOrch::MACsecSC *m_macsec_sc;
442463
sai_object_id_t *m_macsec_sa;
464+
const gearbox_phy_t *m_gearbox_phy;
443465
};
444466

445467
/* MACsec Orchagent */
@@ -592,7 +614,9 @@ task_process_status MACsecOrch::taskUpdateMACsecPort(
592614
port_attr,
593615
*ctx.get_macsec_obj(),
594616
*ctx.get_port_id(),
595-
*ctx.get_switch_id()))
617+
*ctx.get_switch_id(),
618+
*ctx.get_port(),
619+
ctx.get_gearbox_phy()))
596620
{
597621
return task_failed;
598622
}
@@ -602,7 +626,9 @@ task_process_status MACsecOrch::taskUpdateMACsecPort(
602626
*macsec_port_itr->second,
603627
port_name,
604628
*ctx.get_macsec_obj(),
605-
*ctx.get_port_id());
629+
*ctx.get_port_id(),
630+
*ctx.get_port(),
631+
ctx.get_gearbox_phy());
606632
});
607633
}
608634
if (!updateMACsecPort(*ctx.get_macsec_port(), port_attr))
@@ -644,7 +670,9 @@ task_process_status MACsecOrch::taskDisableMACsecPort(
644670
*ctx.get_macsec_port(),
645671
port_name,
646672
*ctx.get_macsec_obj(),
647-
*ctx.get_port_id()))
673+
*ctx.get_port_id(),
674+
*ctx.get_port(),
675+
ctx.get_gearbox_phy()))
648676
{
649677
result = task_failed;
650678
}
@@ -906,16 +934,18 @@ bool MACsecOrch::createMACsecPort(
906934
const std::string &port_name,
907935
const TaskArgs &port_attr,
908936
const MACsecObject &macsec_obj,
909-
sai_object_id_t line_port_id,
910-
sai_object_id_t switch_id)
937+
sai_object_id_t port_id,
938+
sai_object_id_t switch_id,
939+
Port &port,
940+
const gearbox_phy_t* phy)
911941
{
912942
SWSS_LOG_ENTER();
913943

914944
RecoverStack recover;
915945

916946
if (!createMACsecPort(
917947
macsec_port.m_egress_port_id,
918-
line_port_id,
948+
port_id,
919949
switch_id,
920950
SAI_MACSEC_DIRECTION_EGRESS))
921951
{
@@ -929,7 +959,7 @@ bool MACsecOrch::createMACsecPort(
929959

930960
if (!createMACsecPort(
931961
macsec_port.m_ingress_port_id,
932-
line_port_id,
962+
port_id,
933963
switch_id,
934964
SAI_MACSEC_DIRECTION_INGRESS))
935965
{
@@ -982,38 +1012,52 @@ bool MACsecOrch::createMACsecPort(
9821012

9831013
if (!initMACsecACLTable(
9841014
macsec_port.m_egress_acl_table,
985-
line_port_id,
1015+
port_id,
9861016
switch_id,
9871017
SAI_MACSEC_DIRECTION_EGRESS,
9881018
macsec_port.m_sci_in_sectag))
9891019
{
9901020
SWSS_LOG_WARN("Cannot init the ACL Table at the port %s.", port_name.c_str());
9911021
return false;
9921022
}
993-
recover.add_action([this, &macsec_port, line_port_id]() {
1023+
recover.add_action([this, &macsec_port, port_id]() {
9941024
this->deinitMACsecACLTable(
9951025
macsec_port.m_egress_acl_table,
996-
line_port_id,
1026+
port_id,
9971027
SAI_MACSEC_DIRECTION_EGRESS);
9981028
});
9991029

10001030
if (!initMACsecACLTable(
10011031
macsec_port.m_ingress_acl_table,
1002-
line_port_id,
1032+
port_id,
10031033
switch_id,
10041034
SAI_MACSEC_DIRECTION_INGRESS,
10051035
macsec_port.m_sci_in_sectag))
10061036
{
10071037
SWSS_LOG_WARN("Cannot init the ACL Table at the port %s.", port_name.c_str());
10081038
return false;
10091039
}
1010-
recover.add_action([this, &macsec_port, line_port_id]() {
1040+
recover.add_action([this, &macsec_port, port_id]() {
10111041
this->deinitMACsecACLTable(
10121042
macsec_port.m_ingress_acl_table,
1013-
line_port_id,
1043+
port_id,
10141044
SAI_MACSEC_DIRECTION_INGRESS);
10151045
});
10161046

1047+
if (phy && phy->macsec_ipg != 0)
1048+
{
1049+
if (!m_port_orch->getPortIPG(port.m_port_id, macsec_port.m_original_ipg))
1050+
{
1051+
SWSS_LOG_WARN("Cannot get Port IPG at the port %s", port_name.c_str());
1052+
return false;
1053+
}
1054+
if (!m_port_orch->setPortIPG(port.m_port_id, phy->macsec_ipg))
1055+
{
1056+
SWSS_LOG_WARN("Cannot set MACsec IPG to %u at the port %s", phy->macsec_ipg, port_name.c_str());
1057+
return false;
1058+
}
1059+
}
1060+
10171061
SWSS_LOG_NOTICE("MACsec port %s is created.", port_name.c_str());
10181062

10191063
std::vector<FieldValueTuple> fvVector;
@@ -1026,7 +1070,7 @@ bool MACsecOrch::createMACsecPort(
10261070

10271071
bool MACsecOrch::createMACsecPort(
10281072
sai_object_id_t &macsec_port_id,
1029-
sai_object_id_t line_port_id,
1073+
sai_object_id_t port_id,
10301074
sai_object_id_t switch_id,
10311075
sai_macsec_direction_t direction)
10321076
{
@@ -1039,7 +1083,7 @@ bool MACsecOrch::createMACsecPort(
10391083
attr.value.s32 = direction;
10401084
attrs.push_back(attr);
10411085
attr.id = SAI_MACSEC_PORT_ATTR_PORT_ID;
1042-
attr.value.oid = line_port_id;
1086+
attr.value.oid = port_id;
10431087
attrs.push_back(attr);
10441088
sai_status_t status = sai_macsec_api->create_macsec_port(
10451089
&macsec_port_id,
@@ -1141,7 +1185,9 @@ bool MACsecOrch::deleteMACsecPort(
11411185
const MACsecPort &macsec_port,
11421186
const std::string &port_name,
11431187
const MACsecObject &macsec_obj,
1144-
sai_object_id_t line_port_id)
1188+
sai_object_id_t port_id,
1189+
Port &port,
1190+
const gearbox_phy_t* phy)
11451191
{
11461192
SWSS_LOG_ENTER();
11471193

@@ -1179,13 +1225,13 @@ bool MACsecOrch::deleteMACsecPort(
11791225
}
11801226
}
11811227

1182-
if (!deinitMACsecACLTable(macsec_port.m_ingress_acl_table, line_port_id, SAI_MACSEC_DIRECTION_INGRESS))
1228+
if (!deinitMACsecACLTable(macsec_port.m_ingress_acl_table, port_id, SAI_MACSEC_DIRECTION_INGRESS))
11831229
{
11841230
SWSS_LOG_WARN("Cannot deinit ingress ACL table at the port %s.", port_name.c_str());
11851231
result &= false;
11861232
}
11871233

1188-
if (!deinitMACsecACLTable(macsec_port.m_egress_acl_table, line_port_id, SAI_MACSEC_DIRECTION_EGRESS))
1234+
if (!deinitMACsecACLTable(macsec_port.m_egress_acl_table, port_id, SAI_MACSEC_DIRECTION_EGRESS))
11891235
{
11901236
SWSS_LOG_WARN("Cannot deinit egress ACL table at the port %s.", port_name.c_str());
11911237
result &= false;
@@ -1203,6 +1249,15 @@ bool MACsecOrch::deleteMACsecPort(
12031249
result &= false;
12041250
}
12051251

1252+
if (phy && phy->macsec_ipg != 0)
1253+
{
1254+
if (!m_port_orch->setPortIPG(port.m_port_id, macsec_port.m_original_ipg))
1255+
{
1256+
SWSS_LOG_WARN("Cannot set MACsec IPG to %u at the port %s", macsec_port.m_original_ipg, port_name.c_str());
1257+
result &= false;
1258+
}
1259+
}
1260+
12061261
m_state_macsec_port.del(port_name);
12071262

12081263
return true;

orchagent/macsecorch.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class MACsecOrch : public Orch
9494
bool m_enable_encrypt;
9595
bool m_sci_in_sectag;
9696
bool m_enable;
97+
uint32_t m_original_ipg;
9798
};
9899
struct MACsecObject
99100
{
@@ -115,19 +116,23 @@ class MACsecOrch : public Orch
115116
const std::string &port_name,
116117
const TaskArgs & port_attr,
117118
const MACsecObject &macsec_obj,
118-
sai_object_id_t line_port_id,
119-
sai_object_id_t switch_id);
119+
sai_object_id_t port_id,
120+
sai_object_id_t switch_id,
121+
Port &port,
122+
const gearbox_phy_t* phy);
120123
bool createMACsecPort(
121124
sai_object_id_t &macsec_port_id,
122-
sai_object_id_t line_port_id,
125+
sai_object_id_t port_id,
123126
sai_object_id_t switch_id,
124127
sai_macsec_direction_t direction);
125128
bool updateMACsecPort(MACsecPort &macsec_port, const TaskArgs & port_attr);
126129
bool deleteMACsecPort(
127130
const MACsecPort &macsec_port,
128131
const std::string &port_name,
129132
const MACsecObject &macsec_obj,
130-
sai_object_id_t line_port_id);
133+
sai_object_id_t port_id,
134+
Port &port,
135+
const gearbox_phy_t* phy);
131136
bool deleteMACsecPort(sai_object_id_t macsec_port_id);
132137

133138
/* MACsec Flow */

orchagent/portsorch.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -5991,6 +5991,65 @@ bool PortsOrch::initGearboxPort(Port &port)
59915991
return true;
59925992
}
59935993

5994+
const gearbox_phy_t* PortsOrch::getGearboxPhy(const Port &port)
5995+
{
5996+
auto gearbox_interface = m_gearboxInterfaceMap.find(port.m_index);
5997+
if (gearbox_interface == m_gearboxInterfaceMap.end())
5998+
{
5999+
return nullptr;
6000+
}
6001+
6002+
auto phy = m_gearboxPhyMap.find(gearbox_interface->second.phy_id);
6003+
if (phy == m_gearboxPhyMap.end())
6004+
{
6005+
SWSS_LOG_ERROR("Gearbox Phy %d dones't exist", gearbox_interface->second.phy_id);
6006+
return nullptr;
6007+
}
6008+
6009+
return &phy->second;
6010+
}
6011+
6012+
bool PortsOrch::getPortIPG(sai_object_id_t port_id, uint32_t &ipg)
6013+
{
6014+
sai_attribute_t attr;
6015+
attr.id = SAI_PORT_ATTR_IPG;
6016+
6017+
sai_status_t status = sai_port_api->get_port_attribute(port_id, 1, &attr);
6018+
6019+
if (status != SAI_STATUS_SUCCESS)
6020+
{
6021+
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
6022+
if (handle_status != task_success)
6023+
{
6024+
return parseHandleSaiStatusFailure(handle_status);
6025+
}
6026+
}
6027+
6028+
ipg = attr.value.u32;
6029+
6030+
return true;
6031+
}
6032+
6033+
bool PortsOrch::setPortIPG(sai_object_id_t port_id, uint32_t ipg)
6034+
{
6035+
sai_attribute_t attr;
6036+
attr.id = SAI_PORT_ATTR_IPG;
6037+
attr.value.u32 = ipg;
6038+
6039+
sai_status_t status = sai_port_api->set_port_attribute(port_id, &attr);
6040+
6041+
if (status != SAI_STATUS_SUCCESS)
6042+
{
6043+
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
6044+
if (handle_status != task_success)
6045+
{
6046+
return parseHandleSaiStatusFailure(handle_status);
6047+
}
6048+
}
6049+
6050+
return true;
6051+
}
6052+
59946053
bool PortsOrch::getSystemPorts()
59956054
{
59966055
sai_status_t status;

orchagent/portsorch.h

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class PortsOrch : public Orch, public Subject
152152

153153
bool getRecircPort(Port &p, string role);
154154

155+
const gearbox_phy_t* getGearboxPhy(const Port &port);
156+
157+
bool getPortIPG(sai_object_id_t port_id, uint32_t &ipg);
158+
bool setPortIPG(sai_object_id_t port_id, uint32_t ipg);
159+
155160
private:
156161
unique_ptr<Table> m_counterTable;
157162
unique_ptr<Table> m_counterLagTable;

0 commit comments

Comments
 (0)