[Nexthop][fboss2-dev] Add config and delete traffic-counter CLI - #1521
Open
vybhav-nexthop wants to merge 1 commit into
Open
[Nexthop][fboss2-dev] Add config and delete traffic-counter CLI#1521vybhav-nexthop wants to merge 1 commit into
vybhav-nexthop wants to merge 1 commit into
Conversation
joseph5wu
requested changes
Aug 19, 2026
joseph5wu
left a comment
Contributor
There was a problem hiding this comment.
Please remove the both support and adjust the integration-test
vybhav-nexthop
force-pushed
the
traffic-counter-config
branch
from
August 20, 2026 09:27
89fd9c1 to
ce5f6ca
Compare
fboss2-dev config traffic-counter <name> <types> creates or updates a
named entry in sw.trafficCounters, where types is a comma separated list
of PACKETS,BYTES. The handler upserts by counter name: an existing
counter's types are updated in place, otherwise a new TrafficCounter is
appended. Every wanted type has to be named: a collapsed alias for "all
of them" stops meaning that as soon as a cfg::CounterType is added, and
an optional type argument lets a command line silently narrow a counter
that is already collecting both. Types are stored in a fixed order so the
config does not depend on the order they were typed in.
fboss2-dev delete traffic-counter <name> removes a named counter from
sw.trafficCounters. It refuses while a dataPlaneTrafficPolicy or
cpuTrafficPolicy match action still references the counter, naming the
referring matchers: deleting it would leave a dangling reference that
ApplyThriftConfig rejects ("Invalid config: No counter named ..."). The
deprecated globalEgressTrafficPolicy_DEPRECATED has no agent consumers
and is not scanned.
Both operations are hitless: trafficCounters is consumed at ACL
apply-time in ApplyThriftConfig::updateAclsImpl() and does not require
an agent restart on its own.
ConfigTrafficCounterTest exercises the create+delete round trip against
a real agent: config traffic-counter <name> PACKETS,BYTES -> hitless
commit -> verify it appears in the running config with types [PACKETS,
BYTES] -> delete traffic-counter <name> -> hitless commit -> verify the
running config returns to baseline. The fixture deletes a leftover test
counter before each case, so a run that died between create and delete
leaves the next run a clean config instead of blocking it. The
absent-counter refusal is left to the unit tests, which cover it
directly.
Unit tests cover arg validation, the create/update/no-op execution
paths, unreferenced delete, cpu- and dataplane-policy referenced-counter
refusal, and absent-counter refusal.
vybhav-nexthop
force-pushed
the
traffic-counter-config
branch
from
August 20, 2026 09:49
ce5f6ca to
ec9f184
Compare
Contributor
Author
done |
Contributor
|
@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D117038083. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit runSummary
Background: what a traffic counter is and how it flows through the system
The switch ASIC has hardware counter registers. A
TrafficCounterconfig entry asks for one and gives it a name; thetypesfield says whether it tallies packets, bytes, or both:On its own it counts nothing, because nothing says which packets to count. That link comes from a traffic policy: an ACL is the classifier, a
MatchToActionentry binds the ACL to an action, and the action can carrycounter: "acl-drops", a plain string naming the counter. Config apply resolves the name and ties the ACL's TCAM rule to the counter register (theActionCounterattribute on the SAI ACL entry).From then on the ASIC counts by itself: a packet matches the rule, the register increments, no software in the hot path. The agent periodically polls the register over SAI (
SaiAclTableManager::updateStats) and publishes the value as per-name fb303 stats (acl-drops.packets,acl-drops.bytes)What: Adds the
traffic-counterconfig surface tofboss2-dev, both create and delete, plus an end-to-end integration test.fboss2-dev config traffic-counter <name> <types>creates or updates a named counter insw.trafficCounters, where<types>is a comma separated list ofPACKETS,BYTES. Every wanted type has to be named: a collapsed alias for "all of them" stops meaning that as soon as acfg::CounterTypeis added, and an optional type argument would let a command line silently narrow a counter that is already collecting both.fboss2-dev delete traffic-counter <name>removes a named counter. It refuses while adataPlaneTrafficPolicyorcpuTrafficPolicymatch action still references the counter, and names the referring matchers, since deleting it would leave a dangling reference the agent rejects.Both operations are hitless.
Why:
sw.trafficCountershad no CLI. The delete refusal guards against the agent'sApplyThriftConfigrejection ("Invalid config: No counter named ...") that a dangling reference would cause.How: Both leaves follow the fboss2
CmdHandler/Traitssingle-positional-arg pattern. The delete refusal scans the two liveTrafficPolicyConfighomes (dataPlaneTrafficPolicyandcpuTrafficPolicy.trafficPolicy) forMatchAction.counter, the same set the agent validates. The deprecatedglobalEgressTrafficPolicy_DEPRECATEDhas no agent consumers and is not scanned.Sample usage
Test Plan
Validation ran in our internal tree, which carries this same change. The upstream tree itself was not built locally; this PR's CI is the build verification.
Unit (
cmd_config_test):Delete coverage includes arg validation, unreferenced delete, cpu- and dataplane-policy referenced-counter refusal, and absent-counter refusal.
Integration (
ConfigTrafficCounterTest, run on a DUT via internal CI):CreateThenDelete: programs a counter, commits (hitless), verifies it appears in the running config with the expected types, then deletes it, commits again, and verifies the running config returns to baseline. The fixture deletes a leftover test counter first, so a run that died between create and delete leaves the next run a clean config instead of blocking it.Review Findings
No issues found above confidence threshold (fboss-review, 5 reviewers + verifier).