Skip to content

Commit

Permalink
Fix MirrorOnDropReport removal error
Browse files Browse the repository at this point in the history
Summary: Fix TAM object removal error due to dangling references from switch and port.

Reviewed By: nivinl

Differential Revision: D66789586

fbshipit-source-id: 598d54f3a8375f96dbbebbeb34fb57c43de5e394
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Dec 5, 2024
1 parent 130d3c0 commit 729a6da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions fboss/agent/hw/sai/switch/SaiTamManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class SaiTamManager {
}

private:
void updateTamObjectOnSwitchAndPort(PortID portId);

SaiStore* saiStore_;
SaiManagerTable* managerTable_;
SaiPlatform* platform_;
Expand Down
40 changes: 29 additions & 11 deletions fboss/agent/hw/sai/switch/npu/bcm/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ SaiTamManager::SaiTamManager(
void SaiTamManager::addMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& report) {
#if defined(BRCM_SAI_SDK_DNX_GTE_11_0)
XLOG(INFO) << "Creating MirrorOnDropReport " << report->getID();

// Create report
auto& reportStore = saiStore_->get<SaiTamReportTraits>();
auto reportTraits =
Expand Down Expand Up @@ -180,8 +182,8 @@ void SaiTamManager::addMirrorOnDropReport(
auto event = eventStore.setObject(eventTraits, eventTraits);
events.push_back(event);
eventIds.push_back(event->adapterKey());
+XLOG(INFO) << "Created event ID " << eventId << " with tam event "
<< event->adapterKey() << " and aging group " << agingGroupKey;
XLOG(INFO) << "Created event ID " << eventId << " with tam event "
<< event->adapterKey() << " and aging group " << agingGroupKey;
}

// Create tam
Expand All @@ -193,15 +195,6 @@ void SaiTamManager::addMirrorOnDropReport(
auto& tamStore = saiStore_->get<SaiTamTraits>();
auto tam = tamStore.setObject(tamTraits, tamTraits);

// Associate TAM with port
XLOG(INFO) << "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;
Expand All @@ -212,12 +205,24 @@ void SaiTamManager::addMirrorOnDropReport(
tamHandle->tam = tam;
tamHandle->portId = report->getMirrorPortId();
tamHandles_.emplace(report->getID(), std::move(tamHandle));

// Associate TAM with port
XLOG(INFO) << "Associating TAM object " << tam->adapterKey()
<< " with switch and port " << report->getMirrorPortId();
updateTamObjectOnSwitchAndPort(report->getMirrorPortId());
#endif
}

void SaiTamManager::removeMirrorOnDropReport(
const std::shared_ptr<MirrorOnDropReport>& report) {
XLOG(INFO) << "Removing MirrorOnDropReport " << report->getID();
auto handle = std::move(tamHandles_[report->getID()]);
tamHandles_.erase(report->getID());

// Unbind the TAM object from port and switch before letting it destruct.
XLOG(INFO) << "Unassociating TAM object " << handle->tam->adapterKey()
<< " from switch and port " << report->getMirrorPortId();
updateTamObjectOnSwitchAndPort(handle->portId);
}

void SaiTamManager::changeMirrorOnDropReport(
Expand All @@ -235,4 +240,17 @@ std::vector<PortID> SaiTamManager::getAllMirrorOnDropPortIds() {
return portIds;
}

void SaiTamManager::updateTamObjectOnSwitchAndPort(PortID portId) {
std::vector<sai_object_id_t> portTamIds;
std::vector<sai_object_id_t> switchTamIds;
for (const auto& [_, tamHandle] : tamHandles_) {
if (tamHandle->portId == portId) {
portTamIds.push_back(tamHandle->tam->adapterKey());
}
switchTamIds.push_back(tamHandle->tam->adapterKey());
}
managerTable_->portManager().setTamObject(portId, portTamIds);
managerTable_->switchManager().setTamObject(switchTamIds);
}

} // namespace facebook::fboss
2 changes: 2 additions & 0 deletions fboss/agent/hw/sai/switch/npu/tajo/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ std::vector<PortID> SaiTamManager::getAllMirrorOnDropPortIds() {
return {};
}

void SaiTamManager::updateTamObjectOnSwitchAndPort(PortID /* portId */) {}

} // namespace facebook::fboss
2 changes: 2 additions & 0 deletions fboss/agent/hw/sai/switch/oss/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ std::vector<PortID> SaiTamManager::getAllMirrorOnDropPortIds() {
return {};
}

void SaiTamManager::updateTamObjectOnSwitchAndPort(PortID /* portId */) {}

} // namespace facebook::fboss

0 comments on commit 729a6da

Please sign in to comment.