[switchorch][mirrororch]: Add sampled port mirroring with truncation support#4502
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds SwitchOrch startup capability discovery for sampled port mirroring and samplepacket truncation, publishing results into SWITCH_CAPABILITY|switch for consumption by other components (e.g., MirrorOrch/CLI) to enable runtime feature gating.
Changes:
- Introduces new capability keys for ingress/egress sampled mirror and samplepacket truncation in
switchorch.h. - Adds
SwitchOrch::querySwitchSampledMirrorCapability()to query SAI attribute capabilities and store results in STATE_DB. - Exposes new
SwitchOrchgetters for sampled mirror and truncation support flags.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| orchagent/switchorch.h | Adds new capability key macros, new public support getters, and a private query method declaration. |
| orchagent/switchorch.cpp | Calls the new query at startup and implements SAI capability discovery + STATE_DB publishing. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
5d5de0a to
3f09e7a
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
3f09e7a to
239ac81
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
e839e2e to
ae43ab0
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ae43ab0 to
06b869a
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
06b869a to
427887c
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…ed ERSPAN route/session/sFlow/samplepacket state before and after every test Signed-off-by: Janet Cui <janet970527@gmail.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…p rollback Signed-off-by: Janet Cui <janet970527@gmail.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Discussed and addressed comments offline. Approving the PR |
|
@Janetxxx , this is pretty big for 202605 backport. Wouldn't prefer a CP - @r12f , @vaibhavhd , @yxieca for viz |
|
@Janetxxx , would you asses the PR for cherry-pick?
|
|
Thanks for your comment @prsunny, I manually built an image with this PR included and ran the existing port mirroring tests |
|
@prsunny 2. Yes, these changes are opt-in. Sampled mirroring only activates when users specify
|
|
Manually cherry-picked into 202607 Azure/sonic-swss.msft#254 |



What I did
Adds sampled port mirroring with packet truncation support. This PR targets and validates the ERSPAN use case, which is the primary motivation for the feature in the HLD (sonic-net/SONiC#2296).
SwitchOrch — capability discovery
During init, queries SAI via
sai_query_attribute_capability()and publishes toSTATE_DBunderSWITCH_CAPABILITY|switch:PORT_INGRESS_SAMPLE_MIRROR_CAPABLE(SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION)PORT_EGRESS_SAMPLE_MIRROR_CAPABLE(SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION)SAMPLEPACKET_TRUNCATION_CAPABLE(SAI_SAMPLEPACKET_ATTR_TRUNCATE_ENABLE)MirrorOrch — SamplePacket lifecycle
sample_rateis set. Direction-aware binding: RX usesINGRESS_SAMPLEPACKET_ENABLE+INGRESS_SAMPLE_MIRROR_SESSION, TX uses theEGRESS_*equivalents, and BOTH binds ingress and egress with one SAMPLEPACKET.truncate_sizewithout an explicitsample_ratedefaults the rate to 1 (sample every packet).INGRESS_SAMPLEPACKET_ENABLEprevents silent overwrite.SflowOrch
sflowAddPort()/sflowUpdateSampleDirection()checkINGRESS/EGRESS_SAMPLEPACKET_ENABLEbefore binding and reject if the port's samplepacket slot is already owned by a non-sFlow featureWhy I did it
This is part of the sampled port mirroring with truncation feature. It enables per-port hardware-based sampling on ERSPAN mirror sessions, reducing mirror bandwidth by only mirroring 1 out of every N packets with optional packet truncation.
How I verified it
Unit (mock) tests
switchorch_ut.cpp,mirrororch_ut.cpp:VS integration tests
truncate_sizewithoutsample_ratedefaults tosample_rate=1sample_rateabsentDetails if related