diff --git a/fboss/agent/hw/sai/switch/SaiMirrorManager.cpp b/fboss/agent/hw/sai/switch/SaiMirrorManager.cpp index d637fdc7b6b32..2745364ee716e 100644 --- a/fboss/agent/hw/sai/switch/SaiMirrorManager.cpp +++ b/fboss/agent/hw/sai/switch/SaiMirrorManager.cpp @@ -10,6 +10,7 @@ #include "fboss/agent/hw/sai/switch/SaiMirrorManager.h" #include "fboss/agent/hw/sai/switch/SaiPortManager.h" +#include "fboss/agent/hw/sai/switch/SaiSystemPortManager.h" #include "fboss/agent/FbossError.h" #include "fboss/agent/hw/sai/store/SaiStore.h" @@ -23,7 +24,7 @@ namespace facebook::fboss { SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeSpan( - PortSaiId monitorPort) { + sai_object_id_t monitorPort) { SaiLocalMirrorTraits::AdapterHostKey k{ SAI_MIRROR_SESSION_TYPE_LOCAL, monitorPort}; SaiLocalMirrorTraits::CreateAttributes attributes = k; @@ -33,7 +34,7 @@ SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeSpan( SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeErSpan( const std::shared_ptr& mirror, - PortSaiId monitorPort) { + sai_object_id_t monitorPort) { auto mirrorTunnel = mirror->getMirrorTunnel().value(); auto headerVersion = mirrorTunnel.srcIp.isV4() ? 4 : 6; auto truncateSize = @@ -62,7 +63,7 @@ SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeErSpan( SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeSflow( const std::shared_ptr& mirror, - PortSaiId monitorPort) { + sai_object_id_t monitorPort) { auto mirrorTunnel = mirror->getMirrorTunnel().value(); auto headerVersion = mirrorTunnel.srcIp.isV4() ? 4 : 6; auto truncateSize = @@ -109,25 +110,16 @@ void SaiMirrorManager::addNode(const std::shared_ptr& mirror) { } auto mirrorHandle = std::make_unique(mirror->getID(), managerTable_); - auto egressPortDesc = mirror->getEgressPortDesc().value(); - auto monitorPortHandle = - managerTable_->portManager().getPortHandle(egressPortDesc.phyPortID()); - if (!monitorPortHandle) { - throw FbossError( - "Failed to find sai port for egress port for mirroring: ", - mirror->getEgressPortDesc().value().phyPortID()); - } + auto monitorPort = getMonitorPort(mirror->getEgressPortDesc().value()); if (mirror->getMirrorTunnel().has_value()) { auto mirrorTunnel = mirror->getMirrorTunnel().value(); if (mirrorTunnel.udpPorts.has_value()) { - mirrorHandle->mirror = - addNodeSflow(mirror, monitorPortHandle->port->adapterKey()); + mirrorHandle->mirror = addNodeSflow(mirror, monitorPort); } else { - mirrorHandle->mirror = - addNodeErSpan(mirror, monitorPortHandle->port->adapterKey()); + mirrorHandle->mirror = addNodeErSpan(mirror, monitorPort); } } else { - mirrorHandle->mirror = addNodeSpan(monitorPortHandle->port->adapterKey()); + mirrorHandle->mirror = addNodeSpan(monitorPort); } mirrorHandles_.emplace(mirror->getID(), std::move(mirrorHandle)); managerTable_->portManager().programMirrorOnAllPorts( @@ -195,4 +187,38 @@ std::vector SaiMirrorManager::getAllMirrorSessionOids() const { return mirrorSaiIds; } +sai_object_id_t SaiMirrorManager::getMonitorPort( + const PortDescriptor& portDesc) { + sai_object_id_t monitorPort; + switch (portDesc.type()) { + case PortDescriptor::PortType::PHYSICAL: { + auto portHandle = + managerTable_->portManager().getPortHandle(portDesc.phyPortID()); + if (!portHandle) { + throw FbossError( + "Failed to find sai port for egress port for mirroring: ", + portDesc.phyPortID()); + } + monitorPort = portHandle->port->adapterKey(); + break; + } + case PortDescriptor::PortType::SYSTEM_PORT: { + auto systemPortHandle = + managerTable_->systemPortManager().getSystemPortHandle( + portDesc.sysPortID()); + if (!systemPortHandle) { + throw FbossError( + "Failed to find sai system port for egress port for mirroring: ", + portDesc.sysPortID()); + } + monitorPort = systemPortHandle->systemPort->adapterKey(); + break; + } + case PortDescriptor::PortType::AGGREGATE: { + throw FbossError("Invalid agg port desc type received for mirroring"); + } + } + return monitorPort; +} + } // namespace facebook::fboss diff --git a/fboss/agent/hw/sai/switch/SaiMirrorManager.h b/fboss/agent/hw/sai/switch/SaiMirrorManager.h index 28ae1afdd2387..c9f145c415f42 100644 --- a/fboss/agent/hw/sai/switch/SaiMirrorManager.h +++ b/fboss/agent/hw/sai/switch/SaiMirrorManager.h @@ -64,13 +64,14 @@ class SaiMirrorManager { private: SaiMirrorHandle* FOLLY_NULLABLE getMirrorHandleImpl(const std::string& mirrorId) const; - SaiMirrorHandle::SaiMirror addNodeSpan(PortSaiId monitorPort); + SaiMirrorHandle::SaiMirror addNodeSpan(sai_object_id_t monitorPort); SaiMirrorHandle::SaiMirror addNodeErSpan( const std::shared_ptr& mirror, - PortSaiId monitorPort); + sai_object_id_t monitorPort); SaiMirrorHandle::SaiMirror addNodeSflow( const std::shared_ptr& mirror, - PortSaiId monitorPort); + sai_object_id_t monitorPort); + sai_object_id_t getMonitorPort(const PortDescriptor& portDesc); SaiStore* saiStore_; SaiManagerTable* managerTable_;