diff --git a/src/sonic-yang-mgmt/sonic_yang_ext.py b/src/sonic-yang-mgmt/sonic_yang_ext.py index c1624e69581e..bb8163265987 100644 --- a/src/sonic-yang-mgmt/sonic_yang_ext.py +++ b/src/sonic-yang-mgmt/sonic_yang_ext.py @@ -18,7 +18,8 @@ 'DSCP_TO_FC_MAP_LIST', 'EXP_TO_FC_MAP_LIST', 'CABLE_LENGTH_LIST', - 'MPLS_TC_TO_TC_MAP_LIST' + 'MPLS_TC_TO_TC_MAP_LIST', + 'TC_TO_DSCP_MAP_LIST' ] # Workaround for those fields who is defined as leaf-list in YANG model but have string value in config DB. diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 93ae40c902f5..c6f7d92b77d1 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -196,6 +196,7 @@ def run(self): './yang-models/sonic-tc-priority-group-map.yang', './yang-models/sonic-tc-queue-map.yang', './yang-models/sonic-peer-switch.yang', + './yang-models/sonic-tc-dscp-map.yang', './yang-models/sonic-pfc-priority-queue-map.yang', './yang-models/sonic-pfc-priority-priority-group-map.yang', './yang-models/sonic-logger.yang', 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 ac347440893a..36a21caecdc9 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2278,6 +2278,17 @@ } }, + "TC_TO_DSCP_MAP": { + "tc_to_dscp_map1": { + "1": "1", + "2": "2" + }, + "tc_to_dscp_map2": { + "3": "3", + "4": "4" + } + }, + "MAP_PFC_PRIORITY_TO_QUEUE": { "pfc_prio_to_q_map1": { "1": "1", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/qosmaps.json b/src/sonic-yang-models/tests/yang_model_tests/tests/qosmaps.json index c89e8e89ce25..2997410384df 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/qosmaps.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/qosmaps.json @@ -109,5 +109,19 @@ "PORT_QOS_MAP_APPLY_INVALID_PFC": { "desc": "Configure port pfc enable with invalid pfc priority.", "eStrKey": "Pattern" + }, + + "TC_TO_DSCP_MAP_CRETAE": { + "desc": "Configure a Traffic class to DSCP map." + }, + + "TC_TO_DSCP_MAP_CREATE_INVALID_TC": { + "desc": "Configure a Traffic class to DSCP with invalid key.", + "eStr": "Invalid Traffic Class" + }, + + "TC_TO_DSCP_MAP_CREATE_INVALID_DSCP": { + "desc": "Configure a Traffic class to DSCP map with invalid value.", + "eStr": "Invalid DSCP" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/qosmaps.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/qosmaps.json index 355187b497dc..b67a559ac5ff 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/qosmaps.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/qosmaps.json @@ -855,6 +855,92 @@ ] } } - } + }, + "TC_TO_DSCP_MAP_CRETAE": { + "sonic-tc-dscp-map:sonic-tc-dscp-map": { + "sonic-tc-dscp-map:TC_TO_DSCP_MAP": { + "TC_TO_DSCP_MAP_LIST": [ + { + "name": "map1", + "TC_TO_DSCP_MAP": [ + { + "tc": "1", + "dscp": "1" + }, + { + "tc":"2", + "dscp":"2" + }, + { + "tc": "8", + "dscp": "8" + } + ] + }, + { + "name": "map2", + "TC_TO_DSCP_MAP": [ + { + "tc": "1", + "dscp": "1" + }, + { + "tc":"2", + "dscp":"2" + }, + { + "tc": "8", + "dscp": "8" + } + ] + } + ] + } + } + }, + + "TC_TO_DSCP_MAP_CREATE_INVALID_TC": { + "sonic-tc-dscp-map:sonic-tc-dscp-map": { + "sonic-tc-dscp-map:TC_TO_DSCP_MAP": { + "TC_TO_DSCP_MAP_LIST": [ + { + "name": "map3", + "TC_TO_DSCP_MAP": [ + { + "tc": "16", + "dscp": "1" + }, + { + "tc":"2", + "dscp":"2" + } + ] + } + ] + } + } + }, + + "TC_TO_DSCP_MAP_CREATE_INVALID_DSCP": { + "sonic-tc-dscp-map:sonic-tc-dscp-map": { + "sonic-tc-dscp-map:TC_TO_DSCP_MAP": { + "TC_TO_DSCP_MAP_LIST": [ + { + "name": "map3", + "TC_TO_DSCP_MAP": [ + { + "tc": "1", + "dscp": "64" + }, + { + "tc":"2", + "dscp":"2" + } + ] + } + ] + } + } + } } diff --git a/src/sonic-yang-models/yang-models/sonic-tc-dscp-map.yang b/src/sonic-yang-models/yang-models/sonic-tc-dscp-map.yang new file mode 100644 index 000000000000..3698fe04b3e9 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-tc-dscp-map.yang @@ -0,0 +1,67 @@ +module sonic-tc-dscp-map { + + yang-version 1.1; + + namespace "http://github.com/sonic-net/sonic-tc-dscp-map"; + + prefix tdm; + + import sonic-types { + prefix stypes; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "TC_TO_DSCP_MAP yang Module for SONiC OS"; + + revision 2025-01-10 { + description + "Initial revision."; + } + + container sonic-tc-dscp-map { + + container TC_TO_DSCP_MAP { + + description "TC_TO_DSCP_MAP part of config_db.json"; + + list TC_TO_DSCP_MAP_LIST { + + key "name"; + + leaf name { + type string { + pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,31})'; + length 1..32 { + error-message "Invalid length for map name."; + error-app-tag map-name-invalid-length; + } + } + } + + list TC_TO_DSCP_MAP { //this is list inside list for storing mapping between two fields + + key "tc"; + + leaf tc { + type stypes:tc_type; + } + + leaf dscp { + type string { + pattern "6[0-3]|[1-5][0-9]?|[0-9]?" { + error-message "Invalid DSCP"; + error-app-tag dscp-invalid; + } + } + } + } + } + } + } +}