@@ -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
10271071bool 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 ;
0 commit comments