Skip to content

Commit

Permalink
Add PFC counter agent test
Browse files Browse the repository at this point in the history
Summary:
Add a test to validate that PFC counters are incremented when a PFC frame is received.

Also updated ProductionFeatures. No need to update HW asic files since they already have PFC declared correctly.

Reviewed By: nivinl

Differential Revision: D62414831

fbshipit-source-id: 93887febcfcf134cfa771c8799f5ce486d09c220
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Sep 16, 2024
1 parent 3d4261d commit 265f3f7
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
92 changes: 92 additions & 0 deletions fboss/agent/test/agent_hw_tests/AgentPfcTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.

#include "fboss/agent/TxPacket.h"
#include "fboss/agent/packet/PktFactory.h"
#include "fboss/agent/test/AgentHwTest.h"
#include "fboss/agent/test/utils/ConfigUtils.h"
#include "fboss/agent/test/utils/PfcTestUtils.h"
#include "fboss/lib/CommonUtils.h"

namespace facebook::fboss {

class AgentPfcTest : public AgentHwTest {
public:
cfg::SwitchConfig initialConfig(
const AgentEnsemble& ensemble) const override {
auto config = utility::onePortPerInterfaceConfig(
ensemble.getSw(),
ensemble.masterLogicalPortIds(),
true /*interfaceHasSubnet*/);
return config;
}

std::vector<production_features::ProductionFeature>
getProductionFeaturesVerified() const override {
return {production_features::ProductionFeature::PFC};
}

protected:
void sendPfcFrame(const std::vector<PortID>& portIds, uint8_t classVector) {
for (auto portId : portIds) {
// Construct PFC payload with fixed quanta 0x00F0.
// See https://github.com/archjeb/pfctest for frame structure.
std::vector<uint8_t> payload{
0x01, 0x01, 0x00, classVector, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0,
0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0,
};
std::vector<uint8_t> padding(28, 0);
payload.insert(payload.end(), padding.begin(), padding.end());

// Send it out
auto vlanId = utility::firstVlanID(getProgrammedState());
auto intfMac = utility::getFirstInterfaceMac(getProgrammedState());
auto srcMac = utility::MacAddressGenerator().get(intfMac.u64NBO() + 1);
auto pkt = utility::makeEthTxPacket(
getSw(),
vlanId,
srcMac,
folly::MacAddress("01:80:C2:00:00:01"), // MAC control address
ETHERTYPE::ETHERTYPE_EPON, // Ethertype for PFC frames
std::move(payload));
getSw()->sendPacketOutOfPortAsync(std::move(pkt), portId);
}
}
};

TEST_F(AgentPfcTest, verifyPfcCounters) {
std::vector<PortID> portIds = {
masterLogicalInterfacePortIds()[0], masterLogicalInterfacePortIds()[1]};
std::vector<int> losslessPgIds = {2};

auto setup = [&]() {
auto cfg = getAgentEnsemble()->getCurrentConfig();
utility::setupPfcBuffers(cfg, portIds, losslessPgIds);
applyNewConfig(cfg);

for (auto portId : portIds) {
auto inPfc = getLatestPortStats(portId).get_inPfc_();
for (auto [qos, value] : inPfc) {
EXPECT_EQ(value, 0);
}
}
};

auto verify = [&]() {
sendPfcFrame(portIds, 0xFF);

WITH_RETRIES({
for (auto portId : portIds) {
// We map pgIds to PFC priorities 1:1, so check for the same IDs.
auto inPfc = getLatestPortStats(portId).get_inPfc_();
ASSERT_EVENTUALLY_GE(inPfc.size(), losslessPgIds.size());
for (int pgId : losslessPgIds) {
EXPECT_EVENTUALLY_EQ(inPfc[pgId], 1);
}
}
});
};

verifyAcrossWarmBoots(setup, verify);
}

} // namespace facebook::fboss
2 changes: 2 additions & 0 deletions fboss/agent/test/agent_hw_tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cpp_library(
"AgentOlympicQosTests.cpp",
"AgentOverflowTestBase.cpp",
"AgentPacketSendTests.cpp",
"AgentPfcTests.cpp",
"AgentPortBandWidthTests.cpp",
"AgentPrbsTests.cpp",
"AgentQueuePerHostL2Tests.cpp",
Expand Down Expand Up @@ -117,6 +118,7 @@ cpp_library(
"//fboss/agent/test/utils:mirror_test_utils",
"//fboss/agent/test/utils:olympic_qos_utils",
"//fboss/agent/test/utils:packet_snooper",
"//fboss/agent/test/utils:pfc_test_utils",
"//fboss/agent/test/utils:pkt_test_utils",
"//fboss/agent/test/utils:port_stats_test_utils",
"//fboss/agent/test/utils:port_test_utils",
Expand Down

0 comments on commit 265f3f7

Please sign in to comment.