Skip to content

Commit

Permalink
SONiC CBF MAPs Yang
Browse files Browse the repository at this point in the history
    Why I did it
    Created SONiC Yang model for the following CBF MAPs:
    DSCP_TO_FC_MAP
    EXP_TO_FC

    How I did it
    Defined Yang models for CBF MAPs based on Guideline doc:
    https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md
    and
    https://github.com/Azure/sonic-utilities/blob/master/doc/Command-Reference.md

    How to verify it
    sonic_yang_models package build

    Signed-off-by: v-cjinga@microsoft.com
  • Loading branch information
Cosmin Jinga committed Nov 2, 2021
1 parent 51c9c98 commit b9cc150
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/sonic-yang-mgmt/sonic_yang_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
'MAP_PFC_PRIORITY_TO_QUEUE_LIST',
'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_LIST']

cbf_maps_model = ['DSCP_TO_FC_MAP_LIST',
'EXP_TO_FC_MAP_LIST']

"""
This is the Exception thrown out of all public function of this class.
"""
Expand Down Expand Up @@ -413,7 +416,7 @@ def _yangConvert(val):
return vValue

"""
Xlate a Qos Maps list
Xlate a Maps list
This function will xlate from a dict in config DB to a Yang JSON list
using yang model. Output will be go in self.xlateJson
Expand Down Expand Up @@ -465,7 +468,7 @@ def _yangConvert(val):
}
}
"""
def _xlateQosMapList(self, model, yang, config, table, exceptionList):
def _xlateMapList(self, model, yang, config, table, exceptionList):

#create a dict to map each key under primary key with a dict yang model.
#This is done to improve performance of mapping from values of TABLEs in
Expand Down Expand Up @@ -527,9 +530,9 @@ def _xlateList(self, model, yang, config, table, exceptionList):

#Qos Map lists needs special handling because of inner yang list and
#config db format.
if model['@name'] in qos_maps_model:
self.sysLog(msg="_xlateQosMapList: {}".format(model['@name']))
self._xlateQosMapList(model, yang,config, table, exceptionList)
if model['@name'] in qos_maps_model or model['@name'] in cbf_maps_model:
self.sysLog(msg="_xlateMapList: {}".format(model['@name']))
self._xlateMapList(model, yang, config, table, exceptionList)
return

#create a dict to map each key under primary key with a dict yang model.
Expand Down
2 changes: 2 additions & 0 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
'./yang-models/sonic-scheduler.yang',
'./yang-models/sonic-wred-profile.yang',
'./yang-models/sonic-queue.yang',
'./yang-models/sonic-dscp-fc-map.yang',
'./yang-models/sonic-exp-fc-map.yang',
'./yang-models/sonic-dscp-tc-map.yang',
'./yang-models/sonic-dot1p-tc-map.yang',
'./yang-models/sonic-tc-priority-group-map.yang',
Expand Down
24 changes: 23 additions & 1 deletion src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,29 @@
"scheduler": "TEST@1",
"wred_profile": "Wred1"
}
},
},

"DSCP_TO_FC_MAP": {
"Dscp_to_fc_map1": {
"1": "1",
"20": "2"
},
"Dscp_to_fc_map2": {
"3": "3",
"40": "4"
}
},

"EXP_TO_FC_MAP": {
"Exp_to_fc_map1": {
"1": "1",
"2": "2"
},
"Exp_to_fc_map2": {
"3": "3",
"4": "4"
}
},

"DSCP_TO_TC_MAP": {
"Dscp_to_tc_map1": {
Expand Down
24 changes: 24 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/cbfmaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"DSCP_TO_FC_MAP_CREATE": {
"desc": "Configure a DSCP to Forwarding class map."
},
"DSCP_TO_FC_MAP_CREATE_INVALID_DSCP": {
"desc": "Configure a DSCP to Forwarding class map with invalid key.",
"eStr": "Invalid DSCP"
},
"DSCP_TO_FC_MAP_CREATE_INVALID_FC": {
"desc": "Configure a DSCP to Forwarding class map with invalid value.",
"eStr": "Invalid Forwarding Class"
},
"EXP_TO_FC_MAP_CREATE": {
"desc": "Configure a EXP to Forwarding class map."
},
"EXP_TO_FC_MAP_CREATE_INVALID_EXP": {
"desc": "Configure a EXP to Forwarding class map with invalid key.",
"eStr": "Invalid EXP"
},
"EXP_TO_FC_MAP_CREATE_INVALID_FC": {
"desc": "Configure a EXP to Forwarding class map with invalid value.",
"eStr": "Invalid Forwarding Class"
}
}
159 changes: 159 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests_config/cbfmaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"DSCP_TO_FC_MAP_CREATE": {
"sonic-dscp-fc-map:sonic-dscp-fc-map": {
"sonic-dscp-fc-map:DSCP_TO_FC_MAP": {
"DSCP_TO_FC_MAP_LIST": [
{
"name": "map1",
"DSCP_TO_FC_MAP": [
{
"dscp": "1",
"fc": "1"
},
{
"dscp":"2",
"fc":"2"
}
]
},
{
"name": "map2",
"DSCP_TO_FC_MAP": [
{
"dscp": "1",
"fc": "1"
},
{
"dscp":"2",
"fc":"2"
}
]
}
]
}
}
},

"DSCP_TO_FC_MAP_CREATE_INVALID_DSCP": {
"sonic-dscp-fc-map:sonic-dscp-fc-map": {
"sonic-dscp-fc-map:DSCP_TO_FC_MAP": {
"DSCP_TO_FC_MAP_LIST": [
{
"name": "map3",
"DSCP_TO_FC_MAP": [
{
"dscp": "64",
"fc": "1"
},
{
"dscp":"2",
"fc":"2"
}
]
}
]
}
}
},

"DSCP_TO_FC_MAP_CREATE_INVALID_FC": {
"sonic-dscp-fc-map:sonic-dscp-fc-map": {
"sonic-dscp-fc-map:DSCP_TO_FC_MAP": {
"DSCP_TO_FC_MAP_LIST": [
{
"name": "map3",
"DSCP_TO_FC_MAP": [
{
"dscp": "1",
"fc": "8"
},
{
"dscp":"2",
"fc":"2"
}
]
}
]
}
}
},

"EXP_TO_FC_MAP_CREATE": {
"sonic-exp-fc-map:sonic-exp-fc-map": {
"sonic-exp-fc-map:EXP_TO_FC_MAP": {
"EXP_TO_FC_MAP_LIST": [
{
"name": "map1",
"EXP_TO_FC_MAP": [
{
"exp": "1",
"fc": "1"
},
{
"exp":"2",
"fc":"2"
}
]
},
{
"name": "map2",
"EXP_TO_FC_MAP": [
{
"exp": "1",
"fc": "1"
},
{
"exp":"2",
"fc":"2"
}
]
}
]
}
}
},

"EXP_TO_FC_MAP_CREATE_INVALID_EXP": {
"sonic-exp-fc-map:sonic-exp-fc-map": {
"sonic-exp-fc-map:EXP_TO_FC_MAP": {
"EXP_TO_FC_MAP_LIST": [
{
"name": "map3",
"EXP_TO_FC_MAP": [
{
"exp": "8",
"fc": "1"
},
{
"exp":"2",
"fc":"2"
}
]
}
]
}
}
},

"EXP_TO_FC_MAP_CREATE_INVALID_FC": {
"sonic-exp-fc-map:sonic-exp-fc-map": {
"sonic-exp-fc-map:EXP_TO_FC_MAP": {
"EXP_TO_FC_MAP_LIST": [
{
"name": "map3",
"EXP_TO_FC_MAP": [
{
"exp": "1",
"fc": "8"
},
{
"exp":"2",
"fc":"2"
}
]
}
]
}
}
}
}
68 changes: 68 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-dscp-fc-map.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module sonic-dscp-fc-map {

yang-version 1.1;

namespace "http://github.com/Azure/sonic-dscp-fc-map";

prefix dtm;

organization
"SONiC";

contact
"SONiC";

description
"DSCP_TO_FC_MAP yang Module for SONiC OS";

revision 2021-10-29 {
description
"Initial revision.";
}

container sonic-dscp-fc-map {

container DSCP_TO_FC_MAP {

description "DSCP_TO_FC_MAP part of config_db.json";

list DSCP_TO_FC_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 DSCP_TO_FC_MAP { //this is list inside list for storing mapping between two fields

key "dscp";

leaf dscp {
type string {
pattern "6[0-3]|[1-5][0-9]?|[0-9]?" {
error-message "Invalid DSCP";
error-app-tag dscp-invalid;
}
}
}

leaf fc {
type string {
pattern "[0-7]?" {
error-message "Invalid Forwarding Class";
error-app-tag fc-invalid;
}
}
}
}
}
}
}
}
Loading

0 comments on commit b9cc150

Please sign in to comment.