[YANG] add YANG model support for CABLE_LENGTH (#9273)

Why I did it
Add YANG model support for table CABLE_LENGTH

How I did it
Add the YANG model file
Add the test description file and config file
add list CABLE_LENGTH_LIST to the qos_maps_model list in sonic-yang-ext, as it has an inner list.

How to verify it
Build sonic-yang-model and sonic-yang-mgmt
This commit is contained in:
Longxiang Lyu 2021-12-10 01:34:01 +08:00 committed by GitHub
parent e3c0a888c9
commit b88f68b1d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 271 additions and 2 deletions

View File

@ -8,14 +8,17 @@ from json import dump, dumps, loads
from xmltodict import parse from xmltodict import parse
from glob import glob from glob import glob
Type_1_list_maps_model = ['DSCP_TO_TC_MAP_LIST', Type_1_list_maps_model = [
'DSCP_TO_TC_MAP_LIST',
'DOT1P_TO_TC_MAP_LIST', 'DOT1P_TO_TC_MAP_LIST',
'TC_TO_PRIORITY_GROUP_MAP_LIST', 'TC_TO_PRIORITY_GROUP_MAP_LIST',
'TC_TO_QUEUE_MAP_LIST', 'TC_TO_QUEUE_MAP_LIST',
'MAP_PFC_PRIORITY_TO_QUEUE_LIST', 'MAP_PFC_PRIORITY_TO_QUEUE_LIST',
'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_LIST', 'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_LIST',
'DSCP_TO_FC_MAP_LIST', 'DSCP_TO_FC_MAP_LIST',
'EXP_TO_FC_MAP_LIST'] 'EXP_TO_FC_MAP_LIST',
'CABLE_LENGTH_LIST'
]
""" """
This is the Exception thrown out of all public function of this class. This is the Exception thrown out of all public function of this class.

View File

@ -90,6 +90,7 @@ setup(
'./yang-models/sonic-buffer-port-egress-profile-list.yang', './yang-models/sonic-buffer-port-egress-profile-list.yang',
'./yang-models/sonic-buffer-profile.yang', './yang-models/sonic-buffer-profile.yang',
'./yang-models/sonic-buffer-queue.yang', './yang-models/sonic-buffer-queue.yang',
'./yang-models/sonic-cable-length.yang',
'./yang-models/sonic-copp.yang', './yang-models/sonic-copp.yang',
'./yang-models/sonic-crm.yang', './yang-models/sonic-crm.yang',
'./yang-models/sonic-device_metadata.yang', './yang-models/sonic-device_metadata.yang',

View File

@ -377,6 +377,12 @@
"20.1.1.1": {}, "20.1.1.1": {},
"2001:aa:aa::aa": {} "2001:aa:aa::aa": {}
}, },
"CABLE_LENGTH": {
"AZURE": {
"Ethernet0": "5m",
"Ethernet1": "5m"
}
},
"PORT": { "PORT": {
"Ethernet0": { "Ethernet0": {
"alias": "Eth1/1", "alias": "Eth1/1",

View File

@ -0,0 +1,16 @@
{
"CABLE_LENGTH_TEST": {
"desc": "Configure CABLE_LENGTH table."
},
"CABLE_LENGTH_NAME_TEST": {
"desc": "Configure CABLE_LENGTH table with different name other than AZURE."
},
"CABLE_LENGTH_NON_EXISTING_PORT_TEST": {
"desc": "Configure CABLE_LENGTH table with non-existing port.",
"eStrKey": "LeafRef"
},
"CABLE_LENGTH_INVALID_LENGTH_FORMAT_TEST": {
"desc": "Configure CABLE_LENGTH table with invalid length string.",
"eStr": "Invalid cable length"
}
}

View File

@ -0,0 +1,182 @@
{
"CABLE_LENGTH_TEST": {
"sonic-cable-length:sonic-cable-length": {
"sonic-cable-length:CABLE_LENGTH": {
"CABLE_LENGTH_LIST": [
{
"name": "AZURE",
"CABLE_LENGTH": [
{
"port": "Ethernet8",
"length": "5m"
},
{
"port": "Ethernet12",
"length": "5m"
}
]
}
]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"name": "Ethernet8",
"admin_status": "up",
"alias": "Ethernet8/1",
"description": "Ethernet8",
"lanes": "45,46,47,48",
"mtu": 9000,
"speed": 100000
},
{
"name": "Ethernet12",
"admin_status": "up",
"alias": "Ethernet12/1",
"description": "Ethernet12",
"lanes": "49,50,51,52",
"mtu": 9000,
"speed": 100000
}
]
}
}
},
"CABLE_LENGTH_NAME_TEST": {
"sonic-cable-length:sonic-cable-length": {
"sonic-cable-length:CABLE_LENGTH": {
"CABLE_LENGTH_LIST": [
{
"name": "SONIC",
"CABLE_LENGTH": [
{
"port": "Ethernet8",
"length": "5m"
},
{
"port": "Ethernet12",
"length": "5m"
}
]
}
]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"name": "Ethernet8",
"admin_status": "up",
"alias": "Ethernet8/1",
"description": "Ethernet8",
"lanes": "45,46,47,48",
"mtu": 9000,
"speed": 100000
},
{
"name": "Ethernet12",
"admin_status": "up",
"alias": "Ethernet12/1",
"description": "Ethernet12",
"lanes": "49,50,51,52",
"mtu": 9000,
"speed": 100000
}
]
}
}
},
"CABLE_LENGTH_NON_EXISTING_PORT_TEST": {
"sonic-cable-length:sonic-cable-length": {
"sonic-cable-length:CABLE_LENGTH": {
"CABLE_LENGTH_LIST": [
{
"name": "AZURE",
"CABLE_LENGTH": [
{
"port": "Ethernet8",
"length": "5m"
},
{
"port": "Ethernet16",
"length": "5m"
}
]
}
]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"name": "Ethernet8",
"admin_status": "up",
"alias": "Ethernet8/1",
"description": "Ethernet8",
"lanes": "45,46,47,48",
"mtu": 9000,
"speed": 100000
},
{
"name": "Ethernet12",
"admin_status": "up",
"alias": "Ethernet12/1",
"description": "Ethernet12",
"lanes": "49,50,51,52",
"mtu": 9000,
"speed": 100000
}
]
}
}
},
"CABLE_LENGTH_INVALID_LENGTH_FORMAT_TEST": {
"sonic-cable-length:sonic-cable-length": {
"sonic-cable-length:CABLE_LENGTH": {
"CABLE_LENGTH_LIST": [
{
"name": "AZURE",
"CABLE_LENGTH": [
{
"port": "Ethernet8",
"length": "5m"
},
{
"port": "Ethernet12",
"length": "5"
}
]
}
]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"name": "Ethernet8",
"admin_status": "up",
"alias": "Ethernet8/1",
"description": "Ethernet8",
"lanes": "45,46,47,48",
"mtu": 9000,
"speed": 100000
},
{
"name": "Ethernet12",
"admin_status": "up",
"alias": "Ethernet12/1",
"description": "Ethernet12",
"lanes": "49,50,51,52",
"mtu": 9000,
"speed": 100000
}
]
}
}
}
}

View File

@ -0,0 +1,61 @@
module sonic-cable-length {
yang-version 1.1;
namespace "http://github.com/Azure/sonic-cable-length";
prefix cable-length;
import sonic-port {
prefix port;
}
description "CABLE_LENGTH YANG module for SONiC OS";
revision 2021-11-11 {
description "Initial version";
}
container sonic-cable-length {
container CABLE_LENGTH {
description "CABLE_LENGTH part of config_db.json";
list CABLE_LENGTH_LIST {
key "name";
leaf name {
type string {
pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,31})' {
error-message "Invalid cable length list name.";
error-app-tag cable-length-invalid-list-name;
}
length 1..32 {
error-message "Invalid length for the cable length list name.";
error-app-tag cable-length-invalid-list-name-length;
}
}
}
list CABLE_LENGTH {
key "port";
leaf port {
type leafref {
path /port:sonic-port/port:PORT/port:PORT_LIST/port:name;
}
}
leaf length {
type string {
pattern '[0-9]+m' {
error-message "Invalid cable length.";
error-app-tag cable-length-invalid-length;
}
}
}
}
}
}
}
}