Skip to content

Commit c2741b8

Browse files
committed
Check mirror capability before configuring it or setting it to SAI
Signed-off-by: Stephen Sun <[email protected]>
1 parent a15c357 commit c2741b8

File tree

1 file changed

+194
-20
lines changed

1 file changed

+194
-20
lines changed

doc/port-mirroring/SONiC_Port_Mirroring_HLD.md

Lines changed: 194 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
* [3.3 Switch State Service Design](#33-switch-state-service-design)
2626
* [3.3.1 Orchestration Agent](#331-orchestration-agent)
2727
* [3.3.2 Other Process](#332-other-process)
28-
* [3.4 SAI](#35-sai)
29-
* [3.5 CLI](#36-cli)
30-
* [3.5.1 Data Models](#351-data-models)
31-
* [3.5.2 Configuration Commands](#352-configuration-commands)
32-
* [3.5.3 Show Commands](#353-show-commands)
33-
* [3.5.4 Clear Commands](#354-clear-commands)
34-
* [3.5.5 Debug Commands](#355-debug-commands)
35-
* [3.5.6 Rest API Support](#356-rest-api-support)
36-
* [3.5.7 GNMI Support](#357-gnmi-support)
28+
* [3.4 Mirror Capability Discovery](#34-mirror-capability-discovery)
29+
* [3.5 SAI](#35-sai)
30+
* [3.6 CLI](#36-cli)
31+
* [3.6.1 Data Models](#361-data-models)
32+
* [3.6.2 Configuration Commands](#362-configuration-commands)
33+
* [3.6.3 Show Commands](#363-show-commands)
34+
* [3.6.4 Clear Commands](#364-clear-commands)
35+
* [3.6.5 Debug Commands](#365-debug-commands)
36+
* [3.6.6 Rest API Support](#366-rest-api-support)
37+
* [3.6.7 GNMI Support](#367-gnmi-support)
3738
* [4. Flow Diagrams](#4-flow-diagrams)
3839
* [5. Error Handling](#5-Error-Handling)
3940
* [6. Serviceability and Debug](#6-serviceability-and-debug)
@@ -49,6 +50,7 @@
4950
| Rev | Date | Author | Change Description |
5051
|:---:|:-----------:|:------------------:|--------------------------------------------|
5152
| 0.1 | 05/17/2019 | Rupesh Kumar | Initial version |
53+
| 0.2 | 09/05/2025 | Stephen Sun | Added mirror capability discovery and validation |
5254

5355

5456
# About this Manual
@@ -144,7 +146,28 @@ Existing table PORT_MIRROR_TABLE is enhanced to accept new source and destinatio
144146
### 3.2.2 APP_DB
145147
No tables are introduced in APP_DB
146148
### 3.2.3 STATE_DB
147-
No tables are introduced in STATE_DB.·
149+
150+
#### Table SWITCH_CAPABILITY
151+
152+
Table `SWITCH_CAPABILITY` is not a new table. It has been designed to represent various switch object capabilities supported on the platform.
153+
154+
The following fields are introduced in this design for mirror capability discovery:
155+
156+
```text
157+
PORT_INGRESS_MIRROR_CAPABLE = "true" | "false" ; whether SAI attribute SAI_PORT_ATTR_INGRESS_MIRROR_SESSION is supported
158+
PORT_EGRESS_MIRROR_CAPABLE = "true" | "false" ; whether SAI attribute SAI_PORT_ATTR_EGRESS_MIRROR_SESSION is supported
159+
```
160+
161+
These capabilities are discovered during system initialization by SwitchOrch using `sai_query_attribute_capability()` and stored in STATE_DB under the key `SWITCH_CAPABILITY|switch`.
162+
163+
**Example STATE_DB entry:**
164+
```text
165+
SWITCH_CAPABILITY|switch
166+
PORT_INGRESS_MIRROR_CAPABLE: "true"
167+
PORT_EGRESS_MIRROR_CAPABLE: "false"
168+
```
169+
170+
This indicates that the ASIC supports ingress mirror sessions but does not support egress mirror sessions.
148171

149172
### 3.2.4 ASIC_DB
150173
No changes are introduced in ASIC_DB.·
@@ -163,7 +186,58 @@ Mirror Orchestration agent is modified to support this feature:
163186
- Session with source/destination/direction config will be active once the session created from SAI is programmed on the source ports.
164187
- Populates the mirror attribute SAI structures and pushes the entry to ASIC_DB.·
165188

166-
## 3.4 SAI
189+
## 3.4 Mirror Capability Discovery
190+
191+
The mirror capability discovery feature provides runtime detection and validation of ASIC mirror capabilities to ensure proper configuration and graceful error handling.
192+
193+
### 3.4.1 Capability Discovery Process
194+
195+
The capability discovery process involves multiple layers:
196+
197+
1. **SAI Layer Discovery**: SwitchOrch queries SAI for port mirror capabilities using `sai_query_attribute_capability()` for:
198+
- `SAI_PORT_ATTR_INGRESS_MIRROR_SESSION`
199+
- `SAI_PORT_ATTR_EGRESS_MIRROR_SESSION`
200+
201+
2. **STATE_DB Storage**: Discovered capabilities are stored in STATE_DB under `SWITCH_CAPABILITY|switch`:
202+
- `PORT_INGRESS_MIRROR_CAPABLE`: "true"/"false"
203+
- `PORT_EGRESS_MIRROR_CAPABLE`: "true"/"false"
204+
205+
3. **Runtime Validation**: MirrorOrch validates capabilities before configuring mirror sessions
206+
207+
### 3.4.2 Capability Validation Flow
208+
209+
The capability validation follows this sequence:
210+
211+
1. **User CLI Command**: User executes a mirror session configuration command
212+
2. **CLI Validation**: `is_port_mirror_capability_supported()` function is called
213+
3. **STATE_DB Query**: System queries STATE_DB for mirror capabilities
214+
4. **Direction Validation**: System validates if the requested mirror direction is supported
215+
5. **Result**: Command proceeds if supported, or returns error message if not supported
216+
217+
### 3.4.3 Error Handling
218+
219+
- **CLI Level**: Early validation prevents invalid configurations
220+
- **OrchAgent Level**: Runtime validation with detailed error logging
221+
- **Graceful Degradation**: System continues to function with unsupported features disabled
222+
223+
### 3.4.4 Implementation Components
224+
225+
#### SwitchOrch Enhancements
226+
- New capability constants: `SWITCH_CAPABILITY_TABLE_PORT_INGRESS_MIRROR_CAPABLE`, `SWITCH_CAPABILITY_TABLE_PORT_EGRESS_MIRROR_CAPABLE`
227+
- `querySwitchPortMirrorCapability()`: Discovers and stores capabilities
228+
- Public interface methods: `isPortIngressMirrorSupported()`, `isPortEgressMirrorSupported()`
229+
230+
#### MirrorOrch Enhancements
231+
- Capability validation in `setUnsetPortMirror()`
232+
- Separate validation for ingress and egress directions
233+
- Detailed error logging for unsupported operations
234+
235+
#### CLI Enhancements
236+
- `is_port_mirror_capability_supported()`: Queries STATE_DB for capabilities
237+
- Integration with `validate_mirror_session_config()`
238+
- User-friendly error messages for unsupported directions
239+
240+
## 3.5 SAI
167241
Mirror SAI interface APIs are already defined.
168242
More details about SAI API and attributes are described below SAI Spec @
169243

@@ -226,8 +300,8 @@ https://github.com/opencomputeproject/SAI/blob/master/inc/saimirror.h
226300
SAI_PORT_ATTR_EGRESS_MIRROR_SESSION,
227301
```
228302

229-
## 3.5 CLI
230-
### 3.5.1 Data Models
303+
## 3.6 CLI
304+
### 3.6.1 Data Models
231305
SONiC Yang model and OpenConfig extension models will be introduced for this feature.
232306

233307
## openconfig-mirror-ext
@@ -303,7 +377,7 @@ SONiC Yang model and OpenConfig extension models will be introduced for this fe
303377

304378
```
305379

306-
### 3.5.2 Configuration Commands
380+
### 3.6.2 Configuration Commands
307381

308382
Existing mirror session commands are enhanced to support this feature.
309383
```
@@ -332,7 +406,7 @@ KLISH CLI Support.
332406
**switch(config)# [no] mirror-session <session-name>** <br>
333407
**switch(config-mirror-<session-name>)# [no] destination erspan src_ip <src_ip> dst_ip <dst_ip> dscp < dscp > ttl < ttl > [ gre < gre >] [queue <queue>] [source <src_ifName> direction <rx/tx>**] [policer <policer>]<br>
334408

335-
### 3.5.3 Show Commands
409+
### 3.6.3 Show Commands
336410

337411
The following show command display all the mirror sessions that are configured.
338412

@@ -350,13 +424,13 @@ The following show command display all the mirror sessions that are configured.
350424

351425
KLISH show mirror-session is same as above.
352426

353-
### 3.5.4 Clear Commands
427+
### 3.6.4 Clear Commands
354428
No command variants of config commands take care of clear config.
355429

356-
### 3.5.5 Debug Commands
430+
### 3.6.5 Debug Commands
357431
Not applicable
358432

359-
### 3.5.6 REST API Support
433+
### 3.6.6 REST API Support
360434

361435
- Please check all REST API from link @ https://<switch_ip>/ui link.
362436
- This webserver provides user information about all the REST URLS, REST Data. Return codes.
@@ -379,7 +453,7 @@ The following show command display all the mirror sessions that are configured.
379453
# curl -X DELETE "https://<switch_ip>/restconf/data/sonic-mirror-session:sonic-mirror-session/MIRROR_SESSION/MIRROR_SESSION_LIST=mirr3" -H "accept: application/yang-data+json"
380454
```
381455

382-
### 3.5.7 GNMI Support
456+
### 3.6.7 GNMI Support
383457

384458
- Following GNMI set and get commands will be supported.
385459
```
@@ -399,10 +473,64 @@ The following show command display all the mirror sessions that are configured.
399473

400474
# 5 Error Handling
401475

476+
## 5.1 Basic Error Handling
477+
402478
- show mirror_session command will display any errors during session configuration and current status of session.
403479
- Internal processing errors within SwSS will be logged in syslog with ERROR level
404480
- SAI interaction errors will be logged in syslog
405481

482+
## 5.2 Enhanced Mirror Capability Error Handling
483+
484+
### 5.2.1 Capability Validation Errors
485+
486+
The enhanced error handling system provides comprehensive validation and user-friendly error messages for mirror capability issues:
487+
488+
#### CLI Level Validation
489+
- **Early Detection**: Capability validation occurs before configuration attempts
490+
- **User-Friendly Messages**: Clear error messages indicating unsupported directions
491+
- **Example Error Messages**:
492+
```
493+
Error: Port mirror direction 'rx' is not supported by the ASIC
494+
Error: Port mirror direction 'tx' is not supported by the ASIC
495+
Error: Port mirror direction 'both' is not supported by the ASIC
496+
```
497+
498+
#### OrchAgent Level Validation
499+
- **Runtime Validation**: MirrorOrch validates capabilities before SAI operations
500+
- **Detailed Logging**: Comprehensive error logging for debugging
501+
- **Graceful Degradation**: System continues to function with unsupported features disabled
502+
503+
### 5.2.2 Error Handling Flow
504+
505+
The error handling follows a two-stage validation process:
506+
507+
**Stage 1: CLI Validation**
508+
1. **Configuration Attempt**: User attempts to configure mirror session
509+
2. **CLI Validation**: Early validation checks are performed
510+
3. **Capability Check**: System queries STATE_DB for mirror capabilities
511+
4. **Decision Point**:
512+
- If supported: Proceed to OrchAgent
513+
- If not supported: Return error message to user
514+
515+
**Stage 2: OrchAgent Validation**
516+
1. **OrchAgent Validation**: Runtime validation before SAI operations
517+
2. **Final Decision Point**:
518+
- If supported: Configure SAI attributes
519+
- If not supported: Log error and skip operation
520+
521+
### 5.2.3 Error Recovery and Status Reporting
522+
523+
- **Error Prevention**: CLI validation prevents invalid configurations from being applied
524+
- **Status Reporting**: Clear status reporting in show commands
525+
- **Logging**: Comprehensive logging for troubleshooting and monitoring
526+
- **Graceful Rejection**: System rejects unsupported configurations with clear error messages
527+
528+
### 5.2.4 Backward Compatibility
529+
530+
- **Legacy Support**: Existing configurations continue to work
531+
- **Graceful Migration**: New capability checks don't break existing functionality
532+
- **Default Behavior**: When capability detection fails, system assumes full support for backward compatibility
533+
406534
# 6 Serviceability and Debug
407535

408536
# 7 Warm Boot Support
@@ -417,6 +545,32 @@ Max mirror sessions supported are silicon specific.
417545
|--------------------------|--------------------|
418546
| Max mirror sessions | silicon specific |
419547

548+
# 8.1 Backward Compatibility
549+
550+
## 8.1.1 Mirror Capability Feature Compatibility
551+
552+
The mirror capability discovery and validation feature is designed to be fully backward compatible:
553+
554+
### 8.1.2 Existing Configurations
555+
- **Legacy Support**: All existing mirror session configurations continue to work without modification
556+
- **No Breaking Changes**: Existing CLI commands and configurations remain unchanged
557+
- **Graceful Migration**: New capability checks are additive and don't interfere with existing functionality
558+
559+
### 8.1.3 Capability Detection Fallback
560+
- **Default Behavior**: When capability detection fails, the system assumes full support for backward compatibility
561+
- **Error Handling**: If STATE_DB is unavailable or capability queries fail, the system continues to function
562+
- **Logging**: Capability detection failures are logged but don't prevent normal operation
563+
564+
### 8.1.4 CLI Compatibility
565+
- **Command Compatibility**: All existing CLI commands work exactly as before
566+
- **Error Message Enhancement**: New error messages are only shown when capabilities are explicitly checked
567+
- **Optional Validation**: Capability validation is only performed when direction parameters are specified
568+
569+
### 8.1.5 OrchAgent Compatibility
570+
- **Runtime Validation**: New capability validation is performed at runtime without affecting existing sessions
571+
- **Graceful Degradation**: Unsupported operations are logged but don't crash the system
572+
- **State Preservation**: Existing mirror sessions continue to function regardless of capability status
573+
420574
# 9 Unit Test
421575

422576
## 9.1 CLI Test Cases
@@ -465,4 +619,24 @@ test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerAddRemove PASSED
465619
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerMultiAddRemove PASSED [ 83%]
466620
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerWithAcl PASSED [ 91%]
467621
test_mirror_port_span.py::TestMirror::test_LAGMirorrSpanAddRemove PASSED [100%]
468-
```
622+
```
623+
624+
## 9.2 Mirror Capability Test Cases
625+
626+
### 9.2.1 CLI Capability Validation Tests
627+
628+
The following test cases validate the mirror capability discovery and validation functionality:
629+
630+
| S.No | Test Case Synopsis |
631+
|------|-------------------|
632+
| 20 | Verify that CLI validates mirror direction capabilities before configuration |
633+
| 21 | Verify that CLI returns appropriate error messages for unsupported directions |
634+
| 22 | Verify that CLI allows configuration when capabilities are supported |
635+
| 23 | Verify that CLI capability checking works for both SPAN and ERSPAN sessions |
636+
| 24 | Verify that CLI capability checking is not performed when no direction is specified |
637+
638+
### 9.2.2 Integration Tests
639+
640+
| S.No | Test Case Synopsis |
641+
|------|-------------------|
642+
| 25 | Verify end-to-end capability validation from CLI to SAI |

0 commit comments

Comments
 (0)