diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index e16e6342ea..e0547d8330 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -74,6 +74,7 @@ Table of Contents * [Restapi](#restapi) * [System Port](#system-port) * [Tacplus Server](#tacplus-server) + * [TC to DSCP map](#tc-to-dscp-map) * [TC to Priority group map](#tc-to-priority-group-map) * [TC to Queue map](#tc-to-queue-map) * [Telemetry](#telemetry) @@ -2363,6 +2364,21 @@ and is listed in this table. } ``` +### TC to DSCP map + +```json +{ + "TC_TO_DSCP_MAP": { + "AZURE": { + "5": "10", + "6": "20" + } + } +} +``` + +**Note:** +* configuration is mandatory when packet trimming Asymmetric DSCP mode is used ### TC to Priority group map @@ -2515,7 +2531,8 @@ and try sending it on a different queue to deliver a packet drop notification to ***TRIMMING*** -``` +Symmetric DSCP and static queue: +```json { "SWITCH_TRIMMING": { "GLOBAL": { @@ -2527,7 +2544,22 @@ and try sending it on a different queue to deliver a packet drop notification to } ``` +Asymmetric DSCP and dynamic queue: +```json +{ + "SWITCH_TRIMMING": { + "GLOBAL": { + "size": "128", + "dscp_value": "from-tc", + "tc_value": "8", + "queue_index": "dynamic" + } + } +} +``` + **Note:** +* when `dscp_value` is set to `from-tc`, the `tc_value` is used for mapping to DSCP * when `queue_index` is set to `dynamic`, the `dscp_value` is used for mapping to queue ### Versions diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 167962c595..ad26395085 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -370,7 +370,8 @@ "SWITCH_TRIMMING": { "GLOBAL": { "size": "128", - "dscp_value": "48", + "dscp_value": "from-tc", + "tc_value": "6", "queue_index": "6" } }, diff --git a/src/sonic-yang-models/tests/yang_model_pytests/test_trimming.py b/src/sonic-yang-models/tests/yang_model_pytests/test_trimming.py index a8a580d2f0..65da792871 100644 --- a/src/sonic-yang-models/tests/yang_model_pytests/test_trimming.py +++ b/src/sonic-yang-models/tests/yang_model_pytests/test_trimming.py @@ -3,19 +3,26 @@ class TestTrimming: @pytest.mark.parametrize( - "index", [ - pytest.param('6', id="static"), - pytest.param('dynamic', id="dynamic") + "queue", [ + pytest.param('6', id="queue-static"), + pytest.param('dynamic', id="queue-dynamic") ] ) - def test_valid_data(self, yang_model, index): + @pytest.mark.parametrize( + "dscp", [ + pytest.param('48', id="dscp-symmetric"), + pytest.param('from-tc', id="dscp-asymmetric") + ] + ) + def test_valid_data(self, yang_model, dscp, queue): data = { "sonic-trimming:sonic-trimming": { "sonic-trimming:SWITCH_TRIMMING": { "GLOBAL": { "size": "128", - "dscp_value": "48", - "queue_index": index + "dscp_value": dscp, + "tc_value": "6", + "queue_index": queue } } } @@ -45,7 +52,7 @@ def test_neg_size(self, yang_model, size, error_message): @pytest.mark.parametrize( "dscp,error_message", [ pytest.param('-1', 'Invalid value', id="min-1"), - pytest.param('64', 'Invalid DSCP value', id="max+1") + pytest.param('64', 'Invalid value', id="max+1") ] ) def test_neg_dscp_value(self, yang_model, dscp, error_message): @@ -62,17 +69,36 @@ def test_neg_dscp_value(self, yang_model, dscp, error_message): yang_model.load_data(data, error_message) @pytest.mark.parametrize( - "index,error_message", [ + "tc,error_message", [ + pytest.param('-1', 'Invalid value', id="min-1"), + pytest.param('256', 'Invalid value', id="max+1") + ] + ) + def test_neg_tc_value(self, yang_model, tc, error_message): + data = { + "sonic-trimming:sonic-trimming": { + "sonic-trimming:SWITCH_TRIMMING": { + "GLOBAL": { + "tc_value": tc + } + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "queue,error_message", [ pytest.param('-1', 'Invalid value', id="min-1"), pytest.param('256', 'Invalid value', id="max+1") ] ) - def test_neg_queue_index(self, yang_model, index, error_message): + def test_neg_queue_index(self, yang_model, queue, error_message): data = { "sonic-trimming:sonic-trimming": { "sonic-trimming:SWITCH_TRIMMING": { "GLOBAL": { - "queue_index": index + "queue_index": queue } } } diff --git a/src/sonic-yang-models/yang-models/sonic-trimming.yang b/src/sonic-yang-models/yang-models/sonic-trimming.yang index f524b1bc7f..2cb6e654fb 100644 --- a/src/sonic-yang-models/yang-models/sonic-trimming.yang +++ b/src/sonic-yang-models/yang-models/sonic-trimming.yang @@ -25,19 +25,31 @@ module sonic-trimming { } leaf dscp_value { - description "DSCP value assigned to a packet after trimming"; - type uint8 { - range "0..63" { - error-message "Invalid DSCP value"; - error-app-tag dscp-invalid; + description + "DSCP value assigned to a packet after trimming. + When set to from-tc, the tc_value is used for mapping to the DSCP"; + type union { + type uint8 { + range "0..63" { + error-message "Invalid DSCP value"; + error-app-tag dscp-invalid; + } + } + type string { + pattern "from-tc"; } } } + leaf tc_value { + description "TC value assigned to a packet after trimming"; + type uint8; + } + leaf queue_index { description "Queue index to use for transmission of a packet after trimming. - When set to dynamic, the dscp_value is used for mapping to queue"; + When set to dynamic, the dscp_value is used for mapping to the queue"; type union { type uint8; type string {