diff --git a/fboss/agent/ApplyThriftConfig.cpp b/fboss/agent/ApplyThriftConfig.cpp index 8e8569b79972a..3fa7a035a7742 100644 --- a/fboss/agent/ApplyThriftConfig.cpp +++ b/fboss/agent/ApplyThriftConfig.cpp @@ -1241,24 +1241,29 @@ void ThriftConfigApplier::processReachabilityGroup( } } - auto updateReachabilityGroupListSize = - [&](const auto fabricSwitchId, const auto reachabilityGroupListSize) { - auto matcher = HwSwitchMatcher(std::unordered_set( - {static_cast(fabricSwitchId)})); - if (new_->getSwitchSettings() - ->getNodeIf(matcher.matcherString()) - ->getReachabilityGroupListSize() != reachabilityGroupListSize) { - auto newMultiSwitchSettings = new_->getSwitchSettings()->clone(); - auto newSwitchSettings = - newMultiSwitchSettings->getNodeIf(matcher.matcherString()) - ->clone(); - newSwitchSettings->setReachabilityGroupListSize( - reachabilityGroupListSize); - newMultiSwitchSettings->updateNode( - matcher.matcherString(), newSwitchSettings); - new_->resetSwitchSettings(newMultiSwitchSettings); - } - }; + auto updateReachabilityGroups = [&](const auto fabricSwitchId, + const auto& + destinationId2ReachabilityGroup) { + std::vector reachabilityGroups; + for (const auto& [_, groupId] : destinationId2ReachabilityGroup) { + reachabilityGroups.push_back(groupId); + } + + auto matcher = HwSwitchMatcher( + std::unordered_set({static_cast(fabricSwitchId)})); + auto currReachabilityGroups = new_->getSwitchSettings() + ->getNodeIf(matcher.matcherString()) + ->getReachabilityGroups(); + if (currReachabilityGroups != reachabilityGroups) { + auto newMultiSwitchSettings = new_->getSwitchSettings()->clone(); + auto newSwitchSettings = + newMultiSwitchSettings->getNodeIf(matcher.matcherString())->clone(); + newSwitchSettings->setReachabilityGroups(reachabilityGroups); + newMultiSwitchSettings->updateNode( + matcher.matcherString(), newSwitchSettings); + new_->resetSwitchSettings(newMultiSwitchSettings); + } + }; bool parallelVoqLinks = haveParallelLinksToInterfaceNodes( cfg_, @@ -1320,8 +1325,7 @@ void ThriftConfigApplier::processReachabilityGroup( newPort->setReachabilityGroupId(reachabilityGroupId); } } - updateReachabilityGroupListSize( - fabricSwitchId, destinationId2ReachabilityGroup.size()); + updateReachabilityGroups(fabricSwitchId, destinationId2ReachabilityGroup); } } } diff --git a/fboss/agent/test/ReachabilityGroupTests.cpp b/fboss/agent/test/ReachabilityGroupTests.cpp index 81008600a1f82..29a6a789385e9 100644 --- a/fboss/agent/test/ReachabilityGroupTests.cpp +++ b/fboss/agent/test/ReachabilityGroupTests.cpp @@ -32,15 +32,7 @@ class ReachabilityGroupTest : public ::testing::Test { const auto& state = sw_->getState(); for (const auto& [_, switchSettings] : std::as_const(*state->getSwitchSettings())) { - if (expectedSize > 0) { - EXPECT_TRUE(switchSettings->getReachabilityGroupListSize().has_value()); - EXPECT_EQ( - switchSettings->getReachabilityGroupListSize().value(), - expectedSize); - } else { - EXPECT_FALSE( - switchSettings->getReachabilityGroupListSize().has_value()); - } + EXPECT_EQ(switchSettings->getReachabilityGroups().size(), expectedSize); } }