Skip to content

Commit 30592d7

Browse files
daiwei1983facebook-github-bot
authored andcommitted
enhance SaiRouteManager to keep track of routes with invalid metadata
Summary: This is follow-up of S466640. Enhance SaiRouteManager to keep track of a list of routes with invalid metadata, i.e. routes have class id 2 but nexthop is not pointing to cpu port Reviewed By: jasmeetbagga Differential Revision: D67951124 fbshipit-source-id: 96fa44e0e30e63fe32f880f4fd74006f9070951b
1 parent 18d9eb6 commit 30592d7

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

fboss/agent/Utils.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1155,4 +1155,12 @@ int numFabricLevels(const std::map<int64_t, cfg::DsfNode>& dsfNodes) {
11551155
});
11561156
return maxFabricLevel;
11571157
}
1158+
1159+
const std::vector<cfg::AclLookupClass>& getToCpuClassIds() {
1160+
static const std::vector<cfg::AclLookupClass> toCpuClassIds = {
1161+
cfg::AclLookupClass::DST_CLASS_L3_LOCAL_1,
1162+
cfg::AclLookupClass::DST_CLASS_L3_LOCAL_2,
1163+
};
1164+
return toCpuClassIds;
1165+
}
11581166
} // namespace facebook::fboss

fboss/agent/Utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,6 @@ CpuCosQueueId hwQueueIdToCpuCosQueueId(
457457
const HwAsic* asic,
458458
HwSwitchFb303Stats* hwswitchStats);
459459
int numFabricLevels(const std::map<int64_t, cfg::DsfNode>& dsfNodes);
460+
461+
const std::vector<cfg::AclLookupClass>& getToCpuClassIds();
460462
} // namespace facebook::fboss

fboss/agent/hw/sai/switch/SaiRouteManager.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "fboss/agent/hw/sai/switch/SaiRouteManager.h"
12+
#include "fboss/agent/Utils.h"
1213

1314
#include "fboss/agent/hw/sai/store/SaiStore.h"
1415
#include "fboss/agent/hw/sai/switch/SaiCounterManager.h"
@@ -426,6 +427,9 @@ void SaiRouteManager::addOrUpdateRoute(
426427
routeHandle->route = route;
427428
routeHandle->nexthopHandle_ = nextHopHandle;
428429
routeHandle->counterHandle_ = counterHandle;
430+
if (!newRoute->isConnected()) {
431+
checkMetadata(entry);
432+
}
429433
}
430434

431435
template <typename AddrT>
@@ -596,6 +600,34 @@ SaiRouteManager::refOrCreateManagedRouteNextHop(
596600
return managedRouteNextHop;
597601
}
598602

603+
void SaiRouteManager::checkMetadata(SaiRouteTraits::RouteEntry entry) {
604+
auto route = getRouteObject(entry);
605+
if (!route) {
606+
return;
607+
}
608+
auto attributes = route->attributes();
609+
auto metadata =
610+
std::get<std::optional<SaiRouteTraits::Attributes::Metadata>>(attributes);
611+
auto nexthop = std::get<std::optional<SaiRouteTraits::Attributes::NextHopId>>(
612+
attributes);
613+
const auto& toCpuClassIds = getToCpuClassIds();
614+
if (metadata.has_value() && metadata.value().value() &&
615+
std::find(
616+
toCpuClassIds.begin(),
617+
toCpuClassIds.end(),
618+
static_cast<cfg::AclLookupClass>(metadata.value().value())) !=
619+
toCpuClassIds.end() &&
620+
nexthop.has_value() &&
621+
nexthop.value() !=
622+
static_cast<sai_object_id_t>(
623+
managerTable_->switchManager().getCpuPort())) {
624+
// invalid
625+
XLOG(FATAL) << "found invalid route entry with class id value "
626+
<< std::to_string(metadata.value().value())
627+
<< " but cpu is not nexthop: " << entry.toString();
628+
}
629+
}
630+
599631
template <typename NextHopTraitsT>
600632
ManagedRouteNextHop<NextHopTraitsT>::ManagedRouteNextHop(
601633
PortSaiId cpuPort,

fboss/agent/hw/sai/switch/SaiRouteManager.h

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class SaiRouteManager {
136136
std::shared_ptr<SaiObject<SaiRouteTraits>> getRouteObject(
137137
SaiRouteTraits::AdapterHostKey routeKey);
138138

139+
void checkMetadata(SaiRouteTraits::RouteEntry entry);
140+
139141
private:
140142
SaiRouteHandle* getRouteHandleImpl(
141143
const SaiRouteTraits::RouteEntry& entry) const;

0 commit comments

Comments
 (0)