[orchagent][MirrorOrch] Add sampled port mirroring support to MirrorOrch#4488
[orchagent][MirrorOrch] Add sampled port mirroring support to MirrorOrch#4488Janetxxx wants to merge 8 commits into
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds sampled port mirroring support to MirrorOrch (orchagent), extending mirror session configuration to optionally create and attach a SAI SamplePacket object and to program ports using sampled-mirroring attributes instead of full-mirror attributes.
Changes:
- Extend
MirrorEntryand CONFIG_DB parsing to supportsample_rateandtruncate_size. - Create/remove SAI SamplePacket objects when
sample_rate > 0and wire them into session activation/deactivation. - Update per-port mirroring programming to use
SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE+SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSIONfor sampled mirroring.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| orchagent/mirrororch.h | Adds sampled-mirroring fields to MirrorEntry and declares helper APIs / updated port programming signature. |
| orchagent/mirrororch.cpp | Parses new CONFIG_DB fields, creates/removes SamplePacket, and programs ports for sampled mirroring. |
01e7dc0 to
bc52765
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
bc52765 to
ccbb144
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ccbb144 to
987a4e4
Compare
|
/azp run |
- MirrorEntry: add sample_rate, truncate_size, samplepacketId fields - createEntry: parse sample_rate and truncate_size from CONFIG_DB - createEntry: validate sampled mirroring only supports RX direction - activateSession: create SamplePacket (TYPE=MIRROR_SESSION) when sample_rate > 0 - deactivateSession: remove SamplePacket before removing mirror session - setUnsetPortMirror: sampled path uses INGRESS_SAMPLEPACKET_ENABLE + INGRESS_SAMPLE_MIRROR_SESSION instead of INGRESS_MIRROR_SESSION - setUnsetPortMirror: rollback on partial failure - createSamplePacket/removeSamplePacket: new helper functions - setSessionState: include sample_rate and truncate_size Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Janet Cui <janet970527@gmail.com>
|
Azure Pipelines successfully started running 1 pipeline(s). |
987a4e4 to
8cfd52d
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
banidoru
left a comment
There was a problem hiding this comment.
- Resource leak: samplepacket not cleaned up if port mirror config fails after samplepacket creation succeeds in
activateSession - Silent fallthrough: egress + sample_rate > 0 silently uses full-mirror path in
setUnsetPortMirror— needs defensive guard - Undefined OID usage:
createSamplePacketmay use garbage samplepacketId after SAI failure if handleSaiCreateStatus returns task_success - Naming inconsistency: new fields use snake_case vs existing camelCase convention
banidoru
left a comment
There was a problem hiding this comment.
- In
setUnsetPortMirror, thesample_rate > 0 && ingresscheck is insufficient. Ifingressis false, the function silently falls through to the non-sampled path. Add a guard to explicitly reject sampled egress mirroring. - In
activateSession, a resource leak can occur. IfcreateSamplePacketsucceeds butconfigurePortMirrorSessionfails, the created samplepacket is not cleaned up. - In
createSamplePacket, ifcreate_samplepacketfails, the code may log a success message and return true ifhandleSaiCreateStatusreturnstask_success, leading to the use of an uninitializedsamplepacketId. - In
deactivateSession, ifremoveSamplePacketfails, the error is logged but the function proceeds. This can lead to a resource leak. The function should returnfalseon failure.
banidoru
left a comment
There was a problem hiding this comment.
to_uint<uint32_t>can throw on malformed config input, crashing orchagent instead of returningtask_invalid_entrydeactivateSessionclears ports before removing samplepacket — if samplepacket removal fails, state is half-torn-down with no recovery pathcreateSamplePacketlogs success and returns true even when SAI create failed (if handleSaiCreateStatus returns task_success) — OID may be garbage- Resource leak: samplepacket not cleaned up when
configurePortMirrorSessionfails after successfulcreateSamplePacket
| return false; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Half-deactivated state on samplepacket removal failure: At this point, configurePortMirrorSession(name, session, false) has already succeeded — ports are unconfigured. If removeSamplePacket fails and returns false, the mirror session and samplepacket SAI objects remain, but the ports no longer reference them. A subsequent retry of deactivateSession will attempt configurePortMirrorSession(false) again on already-cleared ports.
Consider restructuring so samplepacket removal failure still proceeds to remove the mirror session (log and continue), or skip port unconfiguration on retry if ports are already cleared.
There was a problem hiding this comment.
Still open — this concern (half-deactivated state) is not addressed in the new commits.
Signed-off-by: Janet Cui <janet970527@gmail.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
banidoru
left a comment
There was a problem hiding this comment.
Re-review (iteration 2) — new updateEntry commit reviewed.
updateEntryis delete+recreate: This works but is disruptive — it tears down the active mirror session (deactivates ports, removes SAI objects) and recreates from scratch, causing a traffic-mirroring gap. For mutable fields, consider updating in-place; for immutable fields, the delete+recreate approach is acceptable but should be documented.- Duplicate entry guard removed from
createEntry: The old duplicate check (task_duplicated) was removed. NowcreateEntryno longer guards against duplicates — it relies on the caller (doTask) to checksessionExists()first. If any other caller invokescreateEntrydirectly on an existing session, it will silently overwrite state. Consider keeping a defensive check or adding an assert. updateEntrydoesn't validate delete side-effects: IfdeleteEntrypartially succeeds (e.g., deactivation fails mid-way but entry is removed from map),createEntrywill proceed on potentially inconsistent SAI state.- All prior review concerns remain unaddressed — resource leaks, rollback gaps, STATE_DB persistence, LAG handling, naming, input validation, unit tests, etc. are still open.
banidoru
left a comment
There was a problem hiding this comment.
- STATE_DB Persistence: and are still not persisted to STATE_DB, which is necessary for warm-restart scenarios.
- Unit Tests: No new unit tests have been added to cover the new sampled mirroring logic, including success, failure, and rollback paths.
- LAG Port Handling: The sampled mirroring implementation does not correctly handle LAG ports; it attempts to configure the LAG object itself rather than its members.
- Resource Leaks: There are multiple paths where objects can be leaked upon partial failures during session activation or deactivation.
- Error Handling: Several error paths have insufficient or incorrect error handling, such as silent fallthroughs and uncaught exceptions from string-to-integer conversions.
|
Azure Pipelines successfully started running 1 pipeline(s). |
c979e04 to
aa86f38
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
aa86f38 to
7478d5c
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
7478d5c to
d479e35
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
d479e35 to
6603185
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
6603185 to
1f9eb70
Compare
|
/azp run |
1f9eb70 to
2935ddc
Compare
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Janet Cui <janet970527@gmail.com>
2935ddc to
da47032
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Closing this PR and merging contents into #4502 |
What I did
Depends on: #4502
Adds sampled port mirroring support to MirrorOrch (orchagent), extending mirror session configuration to optionally create and attach a SAI SamplePacket object and to program ports using sampled-mirroring attributes instead of full-mirror attributes.
Why I did it
Added sampled port mirroring with truncation support on ERSPAN sessions
How I verified it
Details if related