Skip to content

Commit

Permalink
move sai mirror manager to use port descriptor
Browse files Browse the repository at this point in the history
Summary:
As titled, move sai mirror manager to use port descriptor to derive the monitor port.

For certain platforms, the monitor port will be a physical port
For DSF platforms, the monitor port can be a physical port (eventor port) or a system port. The system port can be a local or a remote system port.

Just derive the system port handle, derive the adapter key and program the monitor port.

Reviewed By: jasmeetbagga

Differential Revision: D61443902

fbshipit-source-id: 8f13b8c2d67b148a4ad2459076733b6ef89c940e
  • Loading branch information
srikrishnagopu authored and facebook-github-bot committed Aug 20, 2024
1 parent e41e06d commit c1e6de0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
58 changes: 42 additions & 16 deletions fboss/agent/hw/sai/switch/SaiMirrorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -33,7 +34,7 @@ SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeSpan(

SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeErSpan(
const std::shared_ptr<Mirror>& mirror,
PortSaiId monitorPort) {
sai_object_id_t monitorPort) {
auto mirrorTunnel = mirror->getMirrorTunnel().value();
auto headerVersion = mirrorTunnel.srcIp.isV4() ? 4 : 6;
auto truncateSize =
Expand Down Expand Up @@ -62,7 +63,7 @@ SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeErSpan(

SaiMirrorHandle::SaiMirror SaiMirrorManager::addNodeSflow(
const std::shared_ptr<Mirror>& mirror,
PortSaiId monitorPort) {
sai_object_id_t monitorPort) {
auto mirrorTunnel = mirror->getMirrorTunnel().value();
auto headerVersion = mirrorTunnel.srcIp.isV4() ? 4 : 6;
auto truncateSize =
Expand Down Expand Up @@ -109,25 +110,16 @@ void SaiMirrorManager::addNode(const std::shared_ptr<Mirror>& mirror) {
}
auto mirrorHandle =
std::make_unique<SaiMirrorHandle>(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(
Expand Down Expand Up @@ -195,4 +187,38 @@ std::vector<MirrorSaiId> 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
7 changes: 4 additions & 3 deletions fboss/agent/hw/sai/switch/SaiMirrorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>& mirror,
PortSaiId monitorPort);
sai_object_id_t monitorPort);
SaiMirrorHandle::SaiMirror addNodeSflow(
const std::shared_ptr<Mirror>& mirror,
PortSaiId monitorPort);
sai_object_id_t monitorPort);
sai_object_id_t getMonitorPort(const PortDescriptor& portDesc);

SaiStore* saiStore_;
SaiManagerTable* managerTable_;
Expand Down

0 comments on commit c1e6de0

Please sign in to comment.