Skip to content

Commit b8e09b4

Browse files
jasmeetbaggameta-codesync[bot]
authored andcommitted
Reconstruct Adj FRR loopback ports during test setup
Summary: Reconstruct `phyLoopbackPortIds_` from the applied switch configuration during `SetUp()` so warm-boot verification has the same port list even though `initialConfig()` is skipped. Preserve the original `config.ports()` ordering and add detailed logging for selected next hops, injection and expected egress ports, and minimum/maximum byte-count ports. ___ Differential Revision: D116105296 fbshipit-source-id: 40592e3508da574217d5d66a091e89b75716a152
1 parent da0de38 commit b8e09b4

1 file changed

Lines changed: 66 additions & 10 deletions

File tree

fboss/agent/test/agent_hw_tests/AgentAdjFrrRouteTests.cpp

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
9696
ProductionFeature::ADJACENCY_FRR};
9797
}
9898

99+
void SetUp() override {
100+
AgentHwTest::SetUp();
101+
if (FLAGS_list_production_feature) {
102+
return;
103+
}
104+
105+
phyLoopbackPortIds_.clear();
106+
const auto config = getSw()->getConfig();
107+
for (const auto& port : *config.ports()) {
108+
if (*port.loopbackMode() == cfg::PortLoopbackMode::PHY) {
109+
phyLoopbackPortIds_.emplace_back(*port.logicalID());
110+
}
111+
}
112+
}
113+
99114
cfg::SwitchConfig initialConfig(
100115
const AgentEnsemble& ensemble) const override {
101116
auto config = utility::onePortPerInterfaceConfig(
@@ -104,13 +119,11 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
104119
true /* interfaceHasSubnet */);
105120
config.udfConfig() =
106121
utility::addUdfAclConfig(utility::kUdfOffsetBthReserved);
107-
phyLoopbackPortIds_.clear();
108122
// BRCM switches require PHY loopback for FRR link
109123
// state detection.
110124
for (auto& port : *config.ports()) {
111125
if (*port.speed() == cfg::PortSpeed::EIGHTHUNDREDG) {
112126
port.loopbackMode() = cfg::PortLoopbackMode::PHY;
113-
phyLoopbackPortIds_.emplace_back(*port.logicalID());
114127
}
115128
}
116129
utility::addFlowletConfigs(
@@ -169,8 +182,19 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
169182
makeNextHop(3, NextHopRole::BACKUP),
170183
makeNextHop(4, NextHopRole::BACKUP),
171184
};
185+
const auto state = getProgrammedState();
172186
if (includePrimaryNextHop) {
173187
nextHops.emplace(makeNextHop(0, NextHopRole::PRIMARY));
188+
const auto primaryPort = phyLoopbackPortIds_.at(0);
189+
XLOG(INFO) << "Selected primary next-hop port: "
190+
<< state->getPorts()->getNode(primaryPort)->getName() << " ("
191+
<< primaryPort << ")";
192+
}
193+
for (size_t i = 1; i < kNumRouteNextHops; ++i) {
194+
const auto backupPort = phyLoopbackPortIds_.at(i);
195+
XLOG(INFO) << "Selected backup next-hop port: "
196+
<< state->getPorts()->getNode(backupPort)->getName() << " ("
197+
<< backupPort << ")";
174198
}
175199
auto routeUpdater = getSw()->getRouteUpdater();
176200
routeUpdater.addRoute(
@@ -202,6 +226,17 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
202226
int packetCount,
203227
const char* egressPortDescription) {
204228
CHECK(!egressPorts.empty());
229+
const auto state = getProgrammedState();
230+
const auto injectionPortState = state->getPorts()->getNode(injectionPort);
231+
XLOG(INFO) << egressPortDescription
232+
<< " injection port: " << injectionPortState->getName() << " ("
233+
<< injectionPort << ")";
234+
for (const auto& egressPort : egressPorts) {
235+
const auto egressPortState = state->getPorts()->getNode(egressPort);
236+
XLOG(INFO) << egressPortDescription
237+
<< " expected egress port: " << egressPortState->getName()
238+
<< " (" << egressPort << ")";
239+
}
205240
auto getOutPkts = [&egressPorts](const auto& portStats) {
206241
uint64_t outPkts{0};
207242
for (auto port : egressPorts) {
@@ -217,9 +252,25 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
217252
WITH_RETRIES({
218253
const auto afterPortStats = getLatestPortStats(egressPorts);
219254
const auto afterOutPkts = getOutPkts(afterPortStats);
220-
const auto [highestOutBytesIncrement, lowestOutBytesIncrement] =
221-
utility::getHighestAndLowestBytesIncrement(
222-
beforePortStats, afterPortStats);
255+
auto lowestOutBytesPort = egressPorts.front();
256+
auto highestOutBytesPort = egressPorts.front();
257+
auto lowestOutBytesIncrement =
258+
*afterPortStats.at(lowestOutBytesPort).outBytes_() -
259+
*beforePortStats.at(lowestOutBytesPort).outBytes_();
260+
auto highestOutBytesIncrement = lowestOutBytesIncrement;
261+
for (const auto& egressPort : egressPorts) {
262+
const auto outBytesIncrement =
263+
*afterPortStats.at(egressPort).outBytes_() -
264+
*beforePortStats.at(egressPort).outBytes_();
265+
if (outBytesIncrement < lowestOutBytesIncrement) {
266+
lowestOutBytesIncrement = outBytesIncrement;
267+
lowestOutBytesPort = egressPort;
268+
}
269+
if (outBytesIncrement > highestOutBytesIncrement) {
270+
highestOutBytesIncrement = outBytesIncrement;
271+
highestOutBytesPort = egressPort;
272+
}
273+
}
223274
const auto deviationPct = lowestOutBytesIncrement == 0
224275
? (highestOutBytesIncrement == 0
225276
? 0.0
@@ -230,10 +281,15 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
230281
XLOG(INFO) << egressPortDescription
231282
<< " out packets before traffic: " << beforeOutPkts
232283
<< ", after traffic: " << afterOutPkts
233-
<< ", lowest out bytes increment: " << lowestOutBytesIncrement
234-
<< ", highest out bytes increment: "
235-
<< highestOutBytesIncrement << ", deviation: " << deviationPct
236-
<< "%";
284+
<< ", lowest out bytes port: "
285+
<< state->getPorts()->getNode(lowestOutBytesPort)->getName()
286+
<< " (" << lowestOutBytesPort
287+
<< "), increment: " << lowestOutBytesIncrement
288+
<< ", highest out bytes port: "
289+
<< state->getPorts()->getNode(highestOutBytesPort)->getName()
290+
<< " (" << highestOutBytesPort
291+
<< "), increment: " << highestOutBytesIncrement
292+
<< ", deviation: " << deviationPct << "%";
237293
EXPECT_EVENTUALLY_EQ(afterOutPkts, beforeOutPkts + packetCount);
238294
EXPECT_EVENTUALLY_TRUE(
239295
utility::isDeviationWithinThreshold(
@@ -317,7 +373,7 @@ class AgentAdjFrrRouteTest : public AgentHwTest {
317373
});
318374
}
319375

320-
mutable std::vector<PortID> phyLoopbackPortIds_;
376+
std::vector<PortID> phyLoopbackPortIds_;
321377
};
322378

323379
TEST_F(AgentAdjFrrRouteTest, routeWithPrimaryAndBackupNhops) {

0 commit comments

Comments
 (0)