Skip to content

[switchorch][mirrororch]: Add sampled port mirroring with truncation support (#4502)#254

Merged
Janetxxx merged 1 commit into
202607from
dev/janetcui/port-mirror
Jun 30, 2026
Merged

[switchorch][mirrororch]: Add sampled port mirroring with truncation support (#4502)#254
Janetxxx merged 1 commit into
202607from
dev/janetcui/port-mirror

Conversation

@Janetxxx

Copy link
Copy Markdown
Member

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.

…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.
@Janetxxx Janetxxx requested a review from prsunny as a code owner June 30, 2026 05:09
@Janetxxx Janetxxx merged commit 16a5a98 into 202607 Jun 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant