Skip to content

Commit

Permalink
MoD StateDelta and SaiTamManager changes
Browse files Browse the repository at this point in the history
Summary: Add MoD to StateDelta and implement SaiTamManager.

Reviewed By: nivinl

Differential Revision: D65638003

fbshipit-source-id: b8a72b28c72b5c2c9ca669760f22878712dc7b67
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Nov 16, 2024
1 parent 4ed9863 commit 16eb96e
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 24 deletions.
8 changes: 8 additions & 0 deletions fboss/agent/hw/sai/switch/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,14 @@ std::shared_ptr<SwitchState> SaiSwitch::stateChangedImplLocked(
&SaiMirrorManager::addNode,
&SaiMirrorManager::removeMirror);

processDelta(
delta.getMirrorOnDropReportsDelta(),
managerTable_->tamManager(),
lockPolicy,
&SaiTamManager::changeMirrorOnDropReport,
&SaiTamManager::addMirrorOnDropReport,
&SaiTamManager::removeMirrorOnDropReport);

processDelta(
delta.getIpTunnelsDelta(),
managerTable_->tunnelManager(),
Expand Down
29 changes: 19 additions & 10 deletions fboss/agent/hw/sai/switch/SaiTamManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "fboss/agent/hw/sai/api/TamApi.h"
#include "fboss/agent/hw/sai/api/TamEventAgingGroupApi.h"
#include "fboss/agent/hw/sai/store/SaiObject.h"
#include "fboss/agent/state/MirrorOnDropReport.h"

namespace facebook::fboss {

Expand All @@ -23,14 +24,14 @@ using SaiTamEvent = SaiObject<SaiTamEventTraits>;
using SaiTam = SaiObject<SaiTamTraits>;

struct SaiTamHandle {
std::shared_ptr<SaiTamCollector> collector;
std::shared_ptr<SaiTamTransport> transport;
std::shared_ptr<SaiTamReport> report;
std::shared_ptr<SaiTamEventAction> action;
std::shared_ptr<SaiTamTransport> transport;
std::shared_ptr<SaiTamCollector> collector;
#if defined(BRCM_SAI_SDK_DNX_GTE_11_0) && !defined(BRCM_SAI_SDK_DNX_GTE_12_0)
std::shared_ptr<SaiTamEventAgingGroup> agingGroup;
std::vector<std::shared_ptr<SaiTamEventAgingGroup>> agingGroups;
#endif
std::shared_ptr<SaiTamEvent> event;
std::vector<std::shared_ptr<SaiTamEvent>> events;
std::shared_ptr<SaiTam> tam;
SaiManagerTable* managerTable;
~SaiTamHandle();
Expand All @@ -41,22 +42,30 @@ class SaiTamManager {
SaiStore* saiStore,
SaiManagerTable* managerTable,
SaiPlatform* platform);
const SaiTamHandle* getTamHandle() const {
return tamHandle_.get();

void addMirrorOnDropReport(const std::shared_ptr<MirrorOnDropReport>& report);
void removeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& report);
void changeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& oldReport,
const std::shared_ptr<MirrorOnDropReport>& newReport);

const SaiTamHandle* getTamHandle(const std::string& name) const {
return tamHandles_.contains(name) ? tamHandles_.at(name).get() : nullptr;
}
SaiTamHandle* getTamHandle() {
return tamHandle_.get();
SaiTamHandle* getTamHandle(const std::string& name) {
return tamHandles_.contains(name) ? tamHandles_.at(name).get() : nullptr;
}

void gracefulExit() {
tamHandle_.reset();
tamHandles_.clear();
}

private:
SaiStore* saiStore_;
SaiManagerTable* managerTable_;
SaiPlatform* platform_;
std::unique_ptr<SaiTamHandle> tamHandle_;
folly::F14FastMap<std::string, std::unique_ptr<SaiTamHandle>> tamHandles_;
};

} // namespace facebook::fboss
224 changes: 220 additions & 4 deletions fboss/agent/hw/sai/switch/npu/bcm/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,107 @@

#include "fboss/agent/hw/sai/store/SaiStore.h"
#include "fboss/agent/hw/sai/switch/SaiManagerTable.h"
#include "fboss/agent/hw/sai/switch/SaiPortManager.h"
#include "fboss/agent/hw/sai/switch/SaiSwitchManager.h"

#if defined(BRCM_SAI_SDK_DNX_GTE_11_0) && !defined(BRCM_SAI_SDK_DNX_GTE_12_0)
extern "C" {
#ifndef IS_OSS_BRCM_SAI
#include <experimental/saiexperimentaltameventaginggroup.h>
#include <experimental/saitamextensions.h>
#else
#include <saiexperimentaltameventaginggroup.h>
#include <saitamextensions.h>
#endif
}

namespace {
constexpr int kDefaultAgingIntervalUsecs = 10000;
const std::map<int, std::vector<sai_int32_t>> kDropProfiles = {
// TODO(maxgg): enable all profiles once CS00012378634 is fixed
// {0, // Global resources
// {
// SAI_PACKET_DROP_TYPE_MMU_GLOBAL_DRAM_BDBS,
// SAI_PACKET_DROP_TYPE_MMU_GLOBAL_SRAM_BUFFERS,
// SAI_PACKET_DROP_TYPE_MMU_GLOBAL_SRAM_PDBS,
// }},
// {1, // VOQ resources
// {
// SAI_PACKET_DROP_TYPE_MMU_VOQ_SRAM_PDS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_SRAM_BUFFERS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_WORDS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_WORDS_SHARED_MAX_SIZE,
// }},
// {2, // VOQ DRAM block
// {
// SAI_PACKET_DROP_TYPE_MMU_VOQ_DRAM_BLOCK,
// }},
// {3, // VSQ resources
// {
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_SRAM_PDS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_SRAM_BUFFERS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_WORDS_TOTAL_FREE_SHARED,
// SAI_PACKET_DROP_TYPE_MMU_PB_VSQ_WORDS_SHARED_MAX_SIZE,
// }},
// {4, // VSQ D resources
// {
// SAI_PACKET_DROP_TYPE_MMU_VSQ_D_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_D_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_D_WORDS_SHARED_MAX_SIZE,
// }},
// {5, // Queue resolution
// {
// SAI_PACKET_DROP_TYPE_MMU_QUEUE_NUM_RESOLUTION_ERROR,
// SAI_PACKET_DROP_TYPE_MMU_QUEUE_NUM_NOT_VALID,
// }},
{6, // Packet processing
{
SAI_PACKET_DROP_TYPE_MMU_PP_ERROR,
}},
// {7, // Misc
// {
// SAI_PACKET_DROP_TYPE_MMU_ITPP_DELTA_ERROR,
//
// // These should go to event ID 8 once CS00012376944 is fixed
// SAI_PACKET_DROP_TYPE_MMU_DROP_PRECEDENCE_LEVEL,
// SAI_PACKET_DROP_TYPE_MMU_SRAM_RESOURCE_ERROR,
// SAI_PACKET_DROP_TYPE_MMU_EXTERNAL_ERROR,
// SAI_PACKET_DROP_TYPE_MMU_MACSEC_ERROR,
// SAI_PACKET_DROP_TYPE_MMU_TAR_FIFO_FULL,
// SAI_PACKET_DROP_TYPE_MMU_PACKET_SIZE_ERROR,
//
// // These should go to event ID 9 once CS00012376944 is fixed
// SAI_PACKET_DROP_TYPE_MMU_LAG_REMOTE,
// SAI_PACKET_DROP_TYPE_MMU_LAG_PROTECTION,
// SAI_PACKET_DROP_TYPE_MMU_LATENCY,
// SAI_PACKET_DROP_TYPE_MMU_MULTICAST_REPLICATION_ERROR,
// SAI_PACKET_DROP_TYPE_MMU_MULTICAST_FIFO_FULL,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_SYSTEM_RED,
// SAI_PACKET_DROP_TYPE_MMU_VOQ_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_F_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_E_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_C_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_B_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_A_SRAM_PDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_C_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_B_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_A_SRAM_BUFFERS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_C_WORDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_B_WORDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_A_WORDS_SHARED_MAX_SIZE,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_D_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_C_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_B_WRED,
// SAI_PACKET_DROP_TYPE_MMU_VSQ_A_WRED,
// }},
};
} // namespace
#endif

namespace facebook::fboss {

SaiTamHandle::~SaiTamHandle() {
Expand All @@ -16,9 +115,126 @@ SaiTamManager::SaiTamManager(
SaiStore* saiStore,
SaiManagerTable* managerTable,
SaiPlatform* platform)
: saiStore_(saiStore),
managerTable_(managerTable),
platform_(platform),
tamHandle_(std::make_unique<SaiTamHandle>()) {}
: saiStore_(saiStore), managerTable_(managerTable), platform_(platform) {}

void SaiTamManager::addMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& report) {
#if defined(BRCM_SAI_SDK_DNX_GTE_11_0) && !defined(BRCM_SAI_SDK_DNX_GTE_12_0)
// Create report
auto& reportStore = saiStore_->get<SaiTamReportTraits>();
auto reportTraits =
SaiTamReportTraits::CreateAttributes{SAI_TAM_REPORT_TYPE_MOD_OVER_UDP};
auto reportObj = reportStore.setObject(reportTraits, reportTraits);

// Create action
auto& actionStore = saiStore_->get<SaiTamEventActionTraits>();
auto actionTraits =
SaiTamEventActionTraits::CreateAttributes{reportObj->adapterKey()};
auto action = actionStore.setObject(actionTraits, actionTraits);

// Create transport
auto& transportStore = saiStore_->get<SaiTamTransportTraits>();
auto transportTraits = SaiTamTransportTraits::AdapterHostKey{
SAI_TAM_TRANSPORT_TYPE_PORT,
report->getLocalSrcPort(),
report->getCollectorPort(),
report->getMtu(),
folly::MacAddress(report->getSwitchMac()),
folly::MacAddress("02:00:00:00:00:01"), // TODO: use getFirstInterfaceMac
};
auto transport = transportStore.setObject(transportTraits, transportTraits);

// Create collector
auto& collectorStore = saiStore_->get<SaiTamCollectorTraits>();
auto collectorTraits = SaiTamCollectorTraits::CreateAttributes{
report->getLocalSrcIp(),
report->getCollectorIp(),
report->getTruncateSize(),
transport->adapterKey(),
report->getDscp(),
};
auto collector = collectorStore.setObject(collectorTraits, collectorTraits);

std::vector<std::shared_ptr<SaiTamEventAgingGroup>> agingGroups;
std::vector<std::shared_ptr<SaiTamEvent>> events;
std::vector<sai_object_id_t> eventIds;
for (const auto& [eventId, reasons] : kDropProfiles) {
// Create aging group
auto& agingGroupStore = saiStore_->get<SaiTamEventAgingGroupTraits>();
sai_uint16_t agingInterval =
report->getAgingIntervalUsecs().value_or(kDefaultAgingIntervalUsecs) +
eventId;
auto agingGroupTraits = SaiTamEventAgingGroupTraits::CreateAttributes{
SAI_TAM_EVENT_AGING_GROUP_TYPE_VOQ, agingInterval};
auto agingGroup =
agingGroupStore.setObject(agingGroupTraits, agingGroupTraits);
agingGroups.push_back(agingGroup);

// Create event
std::vector<sai_object_id_t> actions{action->adapterKey()};
std::vector<sai_object_id_t> collectors{collector->adapterKey()};
sai_object_id_t agingGroupKey = agingGroup->adapterKey();
SaiTamEventTraits::CreateAttributes eventTraits;
std::get<SaiTamEventTraits::Attributes::Type>(eventTraits) =
SAI_TAM_EVENT_TYPE_PACKET_DROP_STATEFUL;
std::get<SaiTamEventTraits::Attributes::ActionList>(eventTraits) = actions;
std::get<std::optional<SaiTamEventTraits::Attributes::SwitchEventId>>(
eventTraits) = eventId;
std::get<
std::optional<SaiTamEventTraits::Attributes::ExtensionsCollectorList>>(
eventTraits) = collectors;
std::get<std::optional<SaiTamEventTraits::Attributes::PacketDropTypeMmu>>(
eventTraits) = reasons;
std::get<std::optional<SaiTamEventTraits::Attributes::AgingGroup>>(
eventTraits) = agingGroupKey;
auto& eventStore = saiStore_->get<SaiTamEventTraits>();
auto event = eventStore.setObject(eventTraits, eventTraits);
events.push_back(event);
eventIds.push_back(event->adapterKey());
XLOG(DBG4) << "Created event 0x" << std::hex << event->adapterKey()
<< " with aging group 0x" << std::hex << agingGroupKey;
}

// Create tam
std::vector<sai_int32_t> bindpoints = {
SAI_TAM_BIND_POINT_TYPE_SWITCH, SAI_TAM_BIND_POINT_TYPE_PORT};
SaiTamTraits::CreateAttributes tamTraits;
std::get<SaiTamTraits::Attributes::EventObjectList>(tamTraits) = eventIds;
std::get<SaiTamTraits::Attributes::TamBindPointList>(tamTraits) = bindpoints;
auto& tamStore = saiStore_->get<SaiTamTraits>();
auto tam = tamStore.setObject(tamTraits, tamTraits);

// Associate TAM with port
XLOG(DBG3) << "Associating TAM object with port "
<< report->getMirrorPortId();
managerTable_->portManager().setTamObject(
PortID(report->getMirrorPortId()), {tam->adapterKey()});

// Associate TAM with switch
managerTable_->switchManager().setTamObject({tam->adapterKey()});

auto tamHandle = std::make_unique<SaiTamHandle>();
tamHandle->report = reportObj;
tamHandle->action = action;
tamHandle->transport = transport;
tamHandle->collector = collector;
tamHandle->agingGroups = agingGroups;
tamHandle->events = events;
tamHandle->tam = tam;
tamHandles_.emplace(report->getID(), std::move(tamHandle));
#endif
}

void SaiTamManager::removeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& report) {
tamHandles_.erase(report->getID());
}

void SaiTamManager::changeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& oldReport,
const std::shared_ptr<MirrorOnDropReport>& newReport) {
removeMirrorOnDropReport(oldReport);
addMirrorOnDropReport(newReport);
}

} // namespace facebook::fboss
30 changes: 20 additions & 10 deletions fboss/agent/hw/sai/switch/npu/tajo/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ SaiTamManager::SaiTamManager(
SaiStore* saiStore,
SaiManagerTable* managerTable,
SaiPlatform* platform)
: saiStore_(saiStore),
managerTable_(managerTable),
platform_(platform),
tamHandle_(std::make_unique<SaiTamHandle>()) {
: saiStore_(saiStore), managerTable_(managerTable), platform_(platform) {
if (!platform_->getAsic()->isSupported(
HwAsic::Feature::TELEMETRY_AND_MONITORING)) {
return;
Expand Down Expand Up @@ -90,13 +87,26 @@ SaiTamManager::SaiTamManager(
auto& tamStore = saiStore_->get<SaiTamTraits>();
auto tam = tamStore.setObject(tamTraits, tamTraits);

tamHandle_->report = report;
tamHandle_->action = action;
tamHandle_->event = event;
tamHandle_->tam = tam;
tamHandle_->managerTable = managerTable_;
auto tamHandle = std::make_unique<SaiTamHandle>();
tamHandle->report = report;
tamHandle->action = action;
tamHandle->events.push_back(event);
tamHandle->tam = tam;
tamHandle->managerTable = managerTable_;
// associate TAM with switch
managerTable_->switchManager().setTamObject({tamHandle_->tam->adapterKey()});
managerTable_->switchManager().setTamObject({tamHandle->tam->adapterKey()});

tamHandles_.emplace("default", std::move(tamHandle));
}

void SaiTamManager::addMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* report */) {}

void SaiTamManager::removeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* report */) {}

void SaiTamManager::changeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* oldReport */,
const std::shared_ptr<MirrorOnDropReport>& /* newReport */) {}

} // namespace facebook::fboss
10 changes: 10 additions & 0 deletions fboss/agent/hw/sai/switch/oss/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ SaiTamManager::SaiTamManager(
SaiManagerTable* /*managerTable*/,
SaiPlatform* /*platform*/) {}

void SaiTamManager::addMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* report */) {}

void SaiTamManager::removeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* report */) {}

void SaiTamManager::changeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& /* oldReport */,
const std::shared_ptr<MirrorOnDropReport>& /* newReport */) {}

} // namespace facebook::fboss
7 changes: 7 additions & 0 deletions fboss/agent/state/StateDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ MultiSwitchMapDelta<MultiSwitchMirrorMap> StateDelta::getMirrorsDelta() const {
old_->getMirrors().get(), new_->getMirrors().get());
}

MultiSwitchMapDelta<MultiSwitchMirrorOnDropReportMap>
StateDelta::getMirrorOnDropReportsDelta() const {
return MultiSwitchMapDelta<MultiSwitchMirrorOnDropReportMap>(
old_->getMirrorOnDropReports().get(),
new_->getMirrorOnDropReports().get());
}

MultiSwitchMapDelta<MultiSwitchTransceiverMap>
StateDelta::getTransceiversDelta() const {
return MultiSwitchMapDelta<MultiSwitchTransceiverMap>(
Expand Down
Loading

0 comments on commit 16eb96e

Please sign in to comment.