Skip to content

Commit

Permalink
tracer support for mirror sample rate
Browse files Browse the repository at this point in the history
Summary: As titled, tracer support for mirror sample rate

Reviewed By: jasmeetbagga

Differential Revision: D62995235

fbshipit-source-id: 580d0672f1388ccf7636d255b6c1b140108b8733
  • Loading branch information
srikrishnagopu authored and facebook-github-bot committed Sep 23, 2024
1 parent f13ca45 commit b72889b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions fboss/agent/ApplyThriftConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4966,15 +4966,17 @@ std::shared_ptr<Mirror> ThriftConfigApplier::createMirror(

uint8_t dscpMark = mirrorConfig->get_dscp();
bool truncate = mirrorConfig->get_truncate();
uint32_t samplingRate = mirrorConfig->samplingRate().has_value()
? mirrorConfig->samplingRate().value()
: 0;

std::optional<PortDescriptor> egressPortDesc;
if (mirrorEgressPort.has_value()) {
egressPortDesc = PortDescriptor(mirrorEgressPort.value());
}

std::optional<uint32_t> samplingRate;
if (mirrorConfig->samplingRate().has_value()) {
samplingRate = mirrorConfig->samplingRate().value();
}

auto mirror = make_shared<Mirror>(
*mirrorConfig->name(),
egressPortDesc,
Expand Down
3 changes: 2 additions & 1 deletion fboss/agent/MirrorManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ std::shared_ptr<Mirror> MirrorManagerImpl<AddrT>::updateMirror(
mirror->getSrcIp(),
mirror->getTunnelUdpPorts(),
mirror->getDscp(),
mirror->getTruncate());
mirror->getTruncate(),
mirror->getSamplingRate());
newMirror->setSwitchId(mirror->getSwitchId());

for (const auto& nexthop : nexthops) {
Expand Down
1 change: 1 addition & 0 deletions fboss/agent/hw/sai/tracer/MirrorApiTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ std::map<int32_t, std::pair<std::string, std::size_t>> _MirrorSessionMap{
SAI_ATTR_MAP(EnhancedRemoteMirror, SrcMacAddress),
SAI_ATTR_MAP(EnhancedRemoteMirror, DstMacAddress),
SAI_ATTR_MAP(EnhancedRemoteMirror, IpHeaderVersion),
SAI_ATTR_MAP(EnhancedRemoteMirror, SampleRate),
SAI_ATTR_MAP(SflowMirror, UdpSrcPort),
SAI_ATTR_MAP(SflowMirror, UdpDstPort),
};
Expand Down
6 changes: 4 additions & 2 deletions fboss/agent/state/Mirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Mirror::Mirror(
std::optional<TunnelUdpPorts> udpPorts,
uint8_t dscp,
bool truncate,
uint32_t samplingRate)
std::optional<uint32_t> samplingRate)
: ThriftStructNode<Mirror, state::MirrorFields>() {
// span mirror is resolved as soon as it is created
// erspan and sflow are resolved when tunnel is set
Expand All @@ -31,7 +31,9 @@ Mirror::Mirror(
set<switch_state_tags::truncate>(truncate);
set<switch_state_tags::configHasEgressPort>(false);
set<switch_state_tags::isResolved>(false);
set<switch_state_tags::samplingRate>(samplingRate);
if (samplingRate.has_value()) {
set<switch_state_tags::samplingRate>(samplingRate.value());
}

if (egressPortDesc.has_value()) {
set<switch_state_tags::egressPortDesc>(egressPortDesc.value().toThrift());
Expand Down
2 changes: 1 addition & 1 deletion fboss/agent/state/Mirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Mirror : public ThriftStructNode<Mirror, state::MirrorFields> {
std::optional<TunnelUdpPorts> udpPorts = std::nullopt,
uint8_t dscp = cfg::switch_config_constants::DEFAULT_MIRROR_DSCP_,
bool truncate = false,
uint32_t samplingRate = 0);
std::optional<uint32_t> samplingRate = std::nullopt);
enum Type { SPAN = 1, ERSPAN = 2, SFLOW = 3 };
std::string getID() const;
std::optional<folly::IPAddress> getDestinationIp() const;
Expand Down

0 comments on commit b72889b

Please sign in to comment.