Skip to content

Commit

Permalink
Add per-aging group aging interval config
Browse files Browse the repository at this point in the history
Summary: Add per-aging group aging interval config so that we expose all SDK features.

Reviewed By: nivinl

Differential Revision: D68373543

fbshipit-source-id: 5c75359103a09c9ecc00c6fe4c987b38a772fff9
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Jan 22, 2025
1 parent d832ea8 commit ffe50d8
Show file tree
Hide file tree
Showing 9 changed files with 3,662 additions and 3,618 deletions.
12 changes: 3 additions & 9 deletions fboss/agent/ApplyThriftConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5510,12 +5510,6 @@ ThriftConfigApplier::createMirrorOnDropReport(
? folly::IPAddress(getSwitchIntfIP(new_, InterfaceID(systemPortId)))
: folly::IPAddress(getSwitchIntfIPv6(new_, InterfaceID(systemPortId)));

uint8_t dscp = *config->dscp();
std::optional<int32_t> agingIntervalUsecs;
if (config->agingIntervalUsecs().has_value()) {
agingIntervalUsecs = config->agingIntervalUsecs().value();
}

return std::make_shared<MirrorOnDropReport>(
*config->name(),
PortID(*config->mirrorPortId()),
Expand All @@ -5525,11 +5519,11 @@ ThriftConfigApplier::createMirrorOnDropReport(
*config->collectorPort(),
*config->mtu(),
*config->truncateSize(),
dscp,
agingIntervalUsecs,
static_cast<uint8_t>(*config->dscp()),
getLocalMacAddress().toString(),
utility::getFirstInterfaceMac(new_).toString(),
*config->modEventToConfigMap());
*config->modEventToConfigMap(),
*config->agingGroupAgingIntervalUsecs());
}

std::shared_ptr<MirrorOnDropReport>
Expand Down
13 changes: 8 additions & 5 deletions fboss/agent/hw/sai/switch/npu/bcm/SaiTamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,15 @@ void SaiTamManager::addMirrorOnDropReport(

// Create aging group
auto& agingGroupStore = saiStore_->get<SaiTamEventAgingGroupTraits>();
sai_uint16_t agingInterval =
report->getAgingIntervalUsecs().value_or(kDefaultAgingIntervalUsecs);
auto groupType =
eventCfg.agingGroup().value_or(cfg::MirrorOnDropAgingGroup::GLOBAL);
auto agingIntervals = report->getAgingGroupAgingIntervalUsecs();
auto agingTimeIt = agingIntervals.find(groupType);
sai_uint32_t agingTime = agingTimeIt == agingIntervals.end()
? kDefaultAgingIntervalUsecs
: agingTimeIt->second;
auto agingGroupTraits = SaiTamEventAgingGroupTraits::CreateAttributes{
getMirrorOnDropAgingGroupType(eventCfg.agingGroup().value_or(
cfg::MirrorOnDropAgingGroup::GLOBAL)),
agingInterval};
getMirrorOnDropAgingGroupType(groupType), agingTime};
auto agingGroup =
agingGroupStore.setObject(agingGroupTraits, agingGroupTraits);
agingGroups.push_back(agingGroup);
Expand Down
21 changes: 9 additions & 12 deletions fboss/agent/state/MirrorOnDropReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ MirrorOnDropReport::MirrorOnDropReport(
int16_t mtu,
int16_t truncateSize,
uint8_t dscp,
std::optional<int32_t> agingIntervalUsecs,
std::string switchMac,
std::string firstInterfaceMac,
std::map<int8_t, cfg::MirrorOnDropEventConfig> modEventToConfigMap)
std::map<int8_t, cfg::MirrorOnDropEventConfig> modEventToConfigMap,
std::map<cfg::MirrorOnDropAgingGroup, int32_t> agingGroupAgingIntervalUsecs)
: ThriftStructNode<MirrorOnDropReport, state::MirrorOnDropReportFields>() {
set<switch_state_tags::name>(name);
set<switch_state_tags::mirrorPortId>(mirrorPortId);
Expand All @@ -34,12 +34,11 @@ MirrorOnDropReport::MirrorOnDropReport(
set<switch_state_tags::mtu>(mtu);
set<switch_state_tags::truncateSize>(truncateSize);
set<switch_state_tags::dscp>(dscp);
if (agingIntervalUsecs.has_value()) {
set<switch_state_tags::agingIntervalUsecs>(agingIntervalUsecs.value());
}
set<switch_state_tags::switchMac>(switchMac);
set<switch_state_tags::firstInterfaceMac>(firstInterfaceMac);
set<switch_state_tags::modEventToConfigMap>(modEventToConfigMap);
set<switch_state_tags::agingGroupAgingIntervalUsecs>(
agingGroupAgingIntervalUsecs);
}

std::string MirrorOnDropReport::getID() const {
Expand Down Expand Up @@ -83,13 +82,6 @@ uint8_t MirrorOnDropReport::getDscp() const {
return get<switch_state_tags::dscp>()->cref();
}

std::optional<uint32_t> MirrorOnDropReport::getAgingIntervalUsecs() const {
if (auto agingIntervalUsecs = get<switch_state_tags::agingIntervalUsecs>()) {
return agingIntervalUsecs->cref();
}
return std::nullopt;
}

std::string MirrorOnDropReport::getSwitchMac() const {
return get<switch_state_tags::switchMac>()->cref();
}
Expand All @@ -103,6 +95,11 @@ MirrorOnDropReport::getModEventToConfigMap() const {
return get<switch_state_tags::modEventToConfigMap>()->toThrift();
}

std::map<cfg::MirrorOnDropAgingGroup, int32_t>
MirrorOnDropReport::getAgingGroupAgingIntervalUsecs() const {
return get<switch_state_tags::agingGroupAgingIntervalUsecs>()->toThrift();
}

template struct ThriftStructNode<
MirrorOnDropReport,
state::MirrorOnDropReportFields>;
Expand Down
8 changes: 5 additions & 3 deletions fboss/agent/state/MirrorOnDropReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class MirrorOnDropReport : public ThriftStructNode<
int16_t mtu,
int16_t truncateSize,
uint8_t dscp,
std::optional<int32_t> agingIntervalUsecs,
std::string switchMac,
std::string firstInterfaceMac,
std::map<int8_t, cfg::MirrorOnDropEventConfig> modEventToConfigMap);
std::map<int8_t, cfg::MirrorOnDropEventConfig> modEventToConfigMap,
std::map<cfg::MirrorOnDropAgingGroup, int32_t>
agingGroupAgingIntervalUsecs);

std::string getID() const;
PortID getMirrorPortId() const;
Expand All @@ -46,10 +47,11 @@ class MirrorOnDropReport : public ThriftStructNode<
int16_t getMtu() const;
int16_t getTruncateSize() const;
uint8_t getDscp() const;
std::optional<uint32_t> getAgingIntervalUsecs() const;
std::string getSwitchMac() const;
std::string getFirstInterfaceMac() const;
std::map<int8_t, cfg::MirrorOnDropEventConfig> getModEventToConfigMap() const;
std::map<cfg::MirrorOnDropAgingGroup, int32_t>
getAgingGroupAgingIntervalUsecs() const;

private:
// Inherit the constructors required for clone()
Expand Down
31 changes: 20 additions & 11 deletions fboss/agent/state/tests/MirrorOnDropReportTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ cfg::MirrorOnDropReport makeReportCfg(const std::string& ip) {
report.mtu() = 1500;
report.truncateSize() = 128;
report.dscp() = 0;
report.agingIntervalUsecs() = 100;
report.modEventToConfigMap()[0] = makeEventConfig(
std::nullopt,
{cfg::MirrorOnDropReasonAggregation::INGRESS_PACKET_PROCESSING_DISCARDS});
Expand All @@ -57,6 +56,8 @@ cfg::MirrorOnDropReport makeReportCfg(const std::string& ip) {
cfg::MirrorOnDropReasonAggregation::
INGRESS_DESTINATION_CONGESTION_DISCARDS,
});
report.agingGroupAgingIntervalUsecs()[cfg::MirrorOnDropAgingGroup::PORT] =
100;
return report;
}

Expand All @@ -71,15 +72,19 @@ TEST_F(MirrorOnDropReportTest, CreateReportV4) {
EXPECT_TRUE(report->getLocalSrcIp().isV4());
EXPECT_FALSE(report->getSwitchMac().empty());
EXPECT_FALSE(report->getFirstInterfaceMac().empty());
EXPECT_TRUE(report->getModEventToConfigMap().size() == 2);
EXPECT_TRUE(
EXPECT_EQ(report->getModEventToConfigMap().size(), 2);
EXPECT_EQ(
report->getModEventToConfigMap()[0].agingGroup().value_or(
cfg::MirrorOnDropAgingGroup::GLOBAL) ==
cfg::MirrorOnDropAgingGroup::GLOBAL),
cfg::MirrorOnDropAgingGroup::GLOBAL);
EXPECT_TRUE(
EXPECT_EQ(
report->getModEventToConfigMap()[1].agingGroup().value_or(
cfg::MirrorOnDropAgingGroup::GLOBAL) ==
cfg::MirrorOnDropAgingGroup::GLOBAL),
cfg::MirrorOnDropAgingGroup::PORT);
EXPECT_EQ(
report->getAgingGroupAgingIntervalUsecs()
[cfg::MirrorOnDropAgingGroup::PORT],
100);
}

TEST_F(MirrorOnDropReportTest, CreateReportV6) {
Expand All @@ -93,15 +98,19 @@ TEST_F(MirrorOnDropReportTest, CreateReportV6) {
EXPECT_TRUE(report->getLocalSrcIp().isV6());
EXPECT_FALSE(report->getSwitchMac().empty());
EXPECT_FALSE(report->getFirstInterfaceMac().empty());
EXPECT_TRUE(report->getModEventToConfigMap().size() == 2);
EXPECT_TRUE(
EXPECT_EQ(report->getModEventToConfigMap().size(), 2);
EXPECT_EQ(
report->getModEventToConfigMap()[0].agingGroup().value_or(
cfg::MirrorOnDropAgingGroup::GLOBAL) ==
cfg::MirrorOnDropAgingGroup::GLOBAL),
cfg::MirrorOnDropAgingGroup::GLOBAL);
EXPECT_TRUE(
EXPECT_EQ(
report->getModEventToConfigMap()[1].agingGroup().value_or(
cfg::MirrorOnDropAgingGroup::GLOBAL) ==
cfg::MirrorOnDropAgingGroup::GLOBAL),
cfg::MirrorOnDropAgingGroup::PORT);
EXPECT_EQ(
report->getAgingGroupAgingIntervalUsecs()
[cfg::MirrorOnDropAgingGroup::PORT],
100);
}

} // namespace facebook::fboss
3 changes: 2 additions & 1 deletion fboss/agent/switch_config.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,15 @@ struct MirrorOnDropReport {
// Contents of the dropped packet will be truncated when mirroring.
7: i16 truncateSize = 128;
8: byte dscp = 0;
// At most one mirrored packet will be sent per port/PG/VOQ within an interval.
9: optional i32 agingIntervalUsecs;
10: map<
byte,
list<MirrorOnDropReasonAggregation>
> eventIdToDropReasons_DEPRECATED (deprecated);
// Configuration for each event ID.
11: map<byte, MirrorOnDropEventConfig> modEventToConfigMap;
// Aging interval (how often to send packets) for each aging group in usecs.
12: map<MirrorOnDropAgingGroup, i32> agingGroupAgingIntervalUsecs;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions fboss/agent/switch_state.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ struct MirrorOnDropReportFields {
list<switch_config.MirrorOnDropReasonAggregation>
> eventIdToDropReasons_DEPRECATED;
14: map<byte, switch_config.MirrorOnDropEventConfig> modEventToConfigMap;
15: map<
switch_config.MirrorOnDropAgingGroup,
i32
> agingGroupAgingIntervalUsecs;
}

struct ControlPlaneFields {
Expand Down
5 changes: 4 additions & 1 deletion fboss/agent/test/agent_hw_tests/AgentMirrorOnDropTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ class AgentMirrorOnDropTest : public AgentHwTest {
report.mtu() = 1500;
report.truncateSize() = kTruncateSize;
report.dscp() = 0;
report.agingIntervalUsecs() = 100;
report.modEventToConfigMap() = modEventToConfigMap;
report.agingGroupAgingIntervalUsecs()[cfg::MirrorOnDropAgingGroup::GLOBAL] =
100;
report.agingGroupAgingIntervalUsecs()[cfg::MirrorOnDropAgingGroup::PORT] =
200;
config->mirrorOnDropReports()->push_back(report);
}

Expand Down
Loading

0 comments on commit ffe50d8

Please sign in to comment.