From edc0883b34caffd2a88257d2b0ca8fd2a754cd02 Mon Sep 17 00:00:00 2001 From: byu343 Date: Tue, 22 Jun 2021 04:36:48 -0700 Subject: [PATCH] [MACsec]: Support switchId and portId for gearbox (#1717) Signed-off-by: Boyang Yu --- orchagent/macsecorch.cpp | 24 ++++++++++++++++++++---- orchagent/port.h | 3 +++ orchagent/portsorch.cpp | 4 ++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/orchagent/macsecorch.cpp b/orchagent/macsecorch.cpp index e6e37fbf7a19..c5510a16fa51 100644 --- a/orchagent/macsecorch.cpp +++ b/orchagent/macsecorch.cpp @@ -231,8 +231,14 @@ class MACsecOrchContext { return nullptr; } - m_port_id = std::make_unique(port->m_port_id); - // TODO: If the MACsec was enabled at the gearbox, should use line port id as the port id. + if (port->m_line_side_id != SAI_NULL_OBJECT_ID) + { + m_port_id = std::make_unique(port->m_line_side_id); + } + else + { + m_port_id = std::make_unique(port->m_port_id); + } } return m_port_id.get(); } @@ -241,12 +247,22 @@ class MACsecOrchContext { if (m_switch_id == nullptr) { - if (gSwitchId == SAI_NULL_OBJECT_ID) + auto port = get_port(); + sai_object_id_t switchId; + if (port == nullptr || port->m_switch_id == SAI_NULL_OBJECT_ID) + { + switchId = gSwitchId; + } + else + { + switchId = port->m_switch_id; + } + if (switchId == SAI_NULL_OBJECT_ID) { SWSS_LOG_ERROR("Switch ID cannot be found"); return nullptr; } - m_switch_id = std::make_unique(gSwitchId); + m_switch_id = std::make_unique(switchId); } return m_switch_id.get(); } diff --git a/orchagent/port.h b/orchagent/port.h index 28dc5a731a68..dc9f9d1334ad 100644 --- a/orchagent/port.h +++ b/orchagent/port.h @@ -162,6 +162,9 @@ class Port SystemPortInfo m_system_port_info; SystemLagInfo m_system_lag_info; + sai_object_id_t m_switch_id = 0; + sai_object_id_t m_line_side_id = 0; + bool m_fec_cfg = false; bool m_an_cfg = false; }; diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 3238ee795e45..81866a9ae109 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -5650,6 +5650,9 @@ bool PortsOrch::initGearboxPort(Port &port) sai_deserialize_object_id(phyOidStr, phyOid); + SWSS_LOG_NOTICE("BOX: Gearbox port %s assigned phyOid 0x%" PRIx64, port.m_alias.c_str(), phyOid); + port.m_switch_id = phyOid; + /* Create SYSTEM-SIDE port */ attrs.clear(); @@ -5815,6 +5818,7 @@ bool PortsOrch::initGearboxPort(Port &port) SWSS_LOG_NOTICE("BOX: Connected Gearbox ports; system-side:0x%" PRIx64 " to line-side:0x%" PRIx64, systemPort, linePort); m_gearboxPortListLaneMap[port.m_port_id] = make_tuple(systemPort, linePort); + port.m_line_side_id = linePort; } }