[switchorch][mirrororch]: Add sampled port mirroring with truncation support (#4502)#254
Merged
Merged
Conversation
…support (#4502) 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 to STATE_DB under SWITCH_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 Creates/binds a single SAMPLEPACKET object when sample_rate is set. Direction-aware binding: RX uses INGRESS_SAMPLEPACKET_ENABLE + INGRESS_SAMPLE_MIRROR_SESSION, TX uses the EGRESS_* equivalents, and BOTH binds ingress and egress with one SAMPLEPACKET. Truncation implies sampling: truncate_size without an explicit sample_rate defaults the rate to 1 (sample every packet). Capability gating: rejects the session when the required per-direction sampled mirroring (ingress/egress) is not supported; skips truncation if unsupported. Session update is delete-and-recreate only; in-place SET on an existing key is treated as a duplicate and ignored. Cross-feature guard with sFlow: get-before-set on INGRESS_SAMPLEPACKET_ENABLE prevents silent overwrite.
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.
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 to STATE_DB under SWITCH_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
Creates/binds a single SAMPLEPACKET object when sample_rate is set. Direction-aware binding: RX uses INGRESS_SAMPLEPACKET_ENABLE + INGRESS_SAMPLE_MIRROR_SESSION, TX uses the EGRESS_* equivalents, and BOTH binds ingress and egress with one SAMPLEPACKET. Truncation implies sampling: truncate_size without an explicit sample_rate defaults the rate to 1 (sample every packet). Capability gating: rejects the session when the required per-direction sampled mirroring (ingress/egress) is not supported; skips truncation if unsupported. Session update is delete-and-recreate only; in-place SET on an existing key is treated as a duplicate and ignored. Cross-feature guard with sFlow: get-before-set on INGRESS_SAMPLEPACKET_ENABLE prevents silent overwrite.