diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index e651bb0d37..d511b9898a 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -55,6 +55,7 @@ setup( './yang-models/sonic-types.yang', './yang-models/sonic-versions.yang', './yang-models/sonic-vlan.yang', + './yang-models/sonic-vrf.yang', './yang-models/sonic_yang_tree']), ], zip_safe=False, 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 350882515f..e4bcb56402 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1,5 +1,9 @@ { "SAMPLE_CONFIG_DB_JSON": { + "VRF": { + "Vrf_blue": { + } + }, "PORTCHANNEL": { "PortChannel0003": { "admin_status": "up", @@ -18,6 +22,10 @@ "mtu": "9100" } }, + "PORTCHANNEL_INTERFACE": { + "PortChannel0003": {}, + "PortChannel0004": {"vrf_name": "Vrf_blue"} + }, "PORTCHANNEL_MEMBER": { "PortChannel0003|Ethernet1": {}, "PortChannel0004|Ethernet2": {} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/portchannel.json b/src/sonic-yang-models/tests/yang_model_tests/tests/portchannel.json index d86c26291e..b417accee5 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/portchannel.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/portchannel.json @@ -23,5 +23,21 @@ "desc": "Configure Port in PORTCHANNEL_MEMEBER table which does not exist in PORT table.", "eStrKey": "LeafRef", "eStr": ["port", "name"] + }, + "PORTCHANNEL_INTERFACE_LIST_VRF_TEST": { + "desc": "Configure Vrf name in PORTCHANNEL_INTERFACE table." + }, + "PORTCHANNEL_INTERFACE_LIST_WITH_NO_VRF": { + "desc": "Empty PORTCHANNEL_INTERFACE table." + }, + "PORTCHANNEL_INTERFACE_LIST_VRF_TEST_ON_NON_EXIST_PO": { + "desc": "Configure vrf name on a non existent PortChannel.", + "eStrKey": "LeafRef", + "eStr": ["sonic-portchannel:name"] + }, + "PORTCHANNEL_INTERFACE_LIST_NON_EXIST_VRF_TEST": { + "desc": "Configure a non existent Vrf in PORTCHANNEL_INTERFACE table.", + "eStrKey": "LeafRef", + "eStr": ["sonic-vrf:name"] } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/vrf.json b/src/sonic-yang-models/tests/yang_model_tests/tests/vrf.json new file mode 100644 index 0000000000..a9d9bb0f9d --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/vrf.json @@ -0,0 +1,12 @@ +{ + "VRF_TEST": { + "desc": "Configure VRF in VRF table." + }, + "VRF_TEST_WRONG_NAME": { + "desc": "Configure wrong value for vrf name.", + "eStr" : ["Invalid", "VRF name"] + }, + "VRF_TEST_WITH_FALLBACK": { + "desc": "Configure VRF with fallback in VRF table." + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/portchannel.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/portchannel.json index b04f60b9c1..6f86853faa 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/portchannel.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/portchannel.json @@ -125,5 +125,79 @@ ] } } + }, + "PORTCHANNEL_INTERFACE_LIST_VRF_TEST": { + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [{ + "name": "Vrf_blue" + }] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [{ + "name": "PortChannel0001", + "admin_status": "up" + }] + }, + "sonic-portchannel:PORTCHANNEL_INTERFACE": { + "PORTCHANNEL_INTERFACE_LIST": [{ + "name": "PortChannel0001", + "vrf_name": "Vrf_blue" + }] + } + } + }, + + "PORTCHANNEL_INTERFACE_LIST_WITH_NO_VRF": { + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [{ + "name": "PortChannel0001", + "admin_status": "up" + }] + }, + "sonic-portchannel:PORTCHANNEL_INTERFACE": { + "PORTCHANNEL_INTERFACE_LIST": [{ + "name": "PortChannel0001" + }] + } + } + }, + + "PORTCHANNEL_INTERFACE_LIST_VRF_TEST_ON_NON_EXIST_PO": { + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [{ + "name": "Vrf_blue" + }] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL_INTERFACE": { + "PORTCHANNEL_INTERFACE_LIST": [{ + "name": "PortChannel0001", + "vrf_name": "Vrf_blue" + }] + } + } + }, + + "PORTCHANNEL_INTERFACE_LIST_NON_EXIST_VRF_TEST": { + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [{ + "name": "PortChannel0001", + "admin_status": "up" + }] + }, + "sonic-portchannel:PORTCHANNEL_INTERFACE": { + "PORTCHANNEL_INTERFACE_LIST": [{ + "name": "PortChannel0001", + "vrf_name": "Vrf_blue" + }] + } + } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/vrf.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vrf.json new file mode 100644 index 0000000000..f34d3fbdd5 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vrf.json @@ -0,0 +1,32 @@ +{ + "VRF_TEST": { + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [{ + "name": "Vrf_blue" + }] + } + } + }, + + "VRF_TEST_WRONG_NAME": { + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [{ + "name": "blue" + }] + } + } + }, + + "VRF_TEST_WITH_FALLBACK": { + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [{ + "name": "Vrf_blue", + "fallback": true + }] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-interface.yang b/src/sonic-yang-models/yang-models/sonic-interface.yang index d4423f87d5..912268f86b 100644 --- a/src/sonic-yang-models/yang-models/sonic-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-interface.yang @@ -20,8 +20,16 @@ module sonic-interface { revision-date 2019-07-01; } + import sonic-vrf { + prefix vrf; + } + description "INTERFACE yang Module for SONiC OS"; + revision 2021-03-30 { + description "Modify the type of vrf name"; + } + revision 2019-07-01 { description "First Revision"; } @@ -45,9 +53,8 @@ module sonic-interface { } leaf vrf_name { - type string { - pattern "Vrf[a-zA-Z0-9_-]+"; - length 3..255; + type leafref { + path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name"; } } } diff --git a/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang b/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang index 15bcc9809f..54f622c817 100644 --- a/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang @@ -15,9 +15,17 @@ module sonic-loopback-interface { revision-date 2019-07-01; } + import sonic-vrf { + prefix vrf; + } + description "SONIC LOOPBACK INTERFACE"; + revision 2021-04-05 { + description "Modify the type of vrf name"; + } + revision 2020-02-05 { description "First Revision"; } @@ -34,9 +42,8 @@ module sonic-loopback-interface { } leaf vrf_name { - type string { - pattern "Vrf[a-zA-Z0-9_-]+"; - length 3..255; + type leafref { + path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name"; } } } diff --git a/src/sonic-yang-models/yang-models/sonic-portchannel.yang b/src/sonic-yang-models/yang-models/sonic-portchannel.yang index fe4b6c13dc..8d413cea2b 100644 --- a/src/sonic-yang-models/yang-models/sonic-portchannel.yang +++ b/src/sonic-yang-models/yang-models/sonic-portchannel.yang @@ -1,143 +1,168 @@ module sonic-portchannel { - yang-version 1.1; + yang-version 1.1; - namespace "http://github.com/Azure/sonic-portchannel"; - prefix lag; + namespace "http://github.com/Azure/sonic-portchannel"; + prefix lag; - import sonic-types { - prefix stypes; - revision-date 2019-07-01; - } + import sonic-types { + prefix stypes; + revision-date 2019-07-01; + } - import sonic-extension { - prefix ext; - revision-date 2019-07-01; - } + import sonic-extension { + prefix ext; + revision-date 2019-07-01; + } - import sonic-port { - prefix port; - revision-date 2019-07-01; - } + import sonic-port { + prefix port; + revision-date 2019-07-01; + } - description "PORTCHANNEL yang Module for SONiC OS"; + import sonic-vrf { + prefix vrf; + } - revision 2021-03-15 { - description "Add SONiC PortChannel Interface model"; - } + description "PORTCHANNEL yang Module for SONiC OS"; - revision 2019-07-01 { - description "First Revision"; - } + revision 2021-03-31 { + description "Add PortChannel Interface List with VRF attribute"; + } + + revision 2021-03-15 { + description "Add SONiC PortChannel Interface model"; + } + + revision 2019-07-01 { + description "First Revision"; + } - container sonic-portchannel { + container sonic-portchannel { - container PORTCHANNEL { + container PORTCHANNEL { - description "PORTCHANNEL part of config_db.json"; + description "PORTCHANNEL part of config_db.json"; - list PORTCHANNEL_LIST { + list PORTCHANNEL_LIST { - key "name"; + key "name"; - leaf name { - type string { - length 1..128; - pattern 'PortChannel[0-9]{1,4}'; - } - } + leaf name { + type string { + length 1..128; + pattern 'PortChannel[0-9]{1,4}'; + } + } - leaf-list members { - /* leaf-list members are unique by default */ - type union { - type leafref { - path /port:sonic-port/port:PORT/port:PORT_LIST/port:name; - } - type string { - pattern ""; - } - } - /* Today in SONiC, we do not delete the list once - * created, instead we set to empty list. Due to that - * below default values are needed. - */ - default ""; - } + leaf-list members { + /* leaf-list members are unique by default */ + type union { + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:name; + } + type string { + pattern ""; + } + } + /* Today in SONiC, we do not delete the list once + * created, instead we set to empty list. Due to that + * below default values are needed. + */ + default ""; + } - leaf min_links { - type uint8 { - range 1..128; - } - } + leaf min_links { + type uint8 { + range 1..128; + } + } - leaf description { - type string { - length 1..255; - } - } + leaf description { + type string { + length 1..255; + } + } - leaf mtu { - type uint16 { - range 1..9216; - } - } + leaf mtu { + type uint16 { + range 1..9216; + } + } - leaf admin_status { - mandatory true; - type stypes:admin_status; - } - } /* end of list PORTCHANNEL_LIST */ + leaf admin_status { + mandatory true; + type stypes:admin_status; + } + } /* end of list PORTCHANNEL_LIST */ - } /* end of container PORTCHANNEL */ + } /* end of container PORTCHANNEL */ - container PORTCHANNEL_MEMBER { + container PORTCHANNEL_MEMBER { - description "PORTCHANNEL_MEMBER part of config_db.json"; + description "PORTCHANNEL_MEMBER part of config_db.json"; - list PORTCHANNEL_MEMBER_LIST { + list PORTCHANNEL_MEMBER_LIST { - key "name port"; + key "name port"; - leaf name { - type leafref { - path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; - } - } + leaf name { + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + } - leaf port { - /* key elements are mandatory by default */ - type leafref { - path /port:sonic-port/port:PORT/port:PORT_LIST/port:name; - } - } - } /* end of list PORTCHANNEL_MEMBER_LIST */ + leaf port { + /* key elements are mandatory by default */ + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:name; + } + } + } /* end of list PORTCHANNEL_MEMBER_LIST */ - } /* end of container PORTCHANNEL_MEMBER */ + } /* end of container PORTCHANNEL_MEMBER */ - container PORTCHANNEL_INTERFACE { + container PORTCHANNEL_INTERFACE { - description "PORTCHANNEL_INTERFACE part of config_db.json"; + description "PORTCHANNEL_INTERFACE part of config_db.json"; - list PORTCHANNEL_INTERFACE_IPPREFIX_LIST { + list PORTCHANNEL_INTERFACE_LIST { + key "name"; - key "name ip_prefix"; + leaf name { + /* key elements are mandatory by default */ + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + } - leaf name { - /* key elements are mandatory by default */ - type leafref { - path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; - } - } + leaf vrf_name { + type leafref { + path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name"; + } + } + } /* end of list PORTCHANNEL_INTERFACE_LIST */ - leaf ip_prefix { - /* key elements are mandatory by default */ - type stypes:sonic-ip-prefix; - } - } /* end of list PORTCHANNEL_INTERFACE_IPPREFIX_LIST */ + list PORTCHANNEL_INTERFACE_IPPREFIX_LIST { - } /* end of container PORTCHANNEL_INTERFACE */ + key "name ip_prefix"; - } /* end of container sonic-portchannel */ + leaf name { + /* key elements are mandatory by default */ + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + } + + leaf ip_prefix { + /* key elements are mandatory by default */ + type stypes:sonic-ip-prefix; + } + } /* end of list PORTCHANNEL_INTERFACE_IPPREFIX_LIST */ + + } /* end of container PORTCHANNEL_INTERFACE */ + + } /* end of container sonic-portchannel */ } /* end of module sonic-portchannel */ diff --git a/src/sonic-yang-models/yang-models/sonic-vlan.yang b/src/sonic-yang-models/yang-models/sonic-vlan.yang index dd76db7d2a..2962161ef0 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -24,8 +24,16 @@ module sonic-vlan { revision-date 2019-07-01; } + import sonic-vrf { + prefix vrf; + } + description "VLAN yang Module for SONiC OS"; + revision 2021-03-30 { + description "Modify the type of vrf name"; + } + revision 2019-07-01 { description "First Revision"; } @@ -49,9 +57,8 @@ module sonic-vlan { } leaf vrf_name { - type string { - pattern "Vrf[a-zA-Z0-9_-]+"; - length 3..255; + type leafref{ + path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name"; } } } diff --git a/src/sonic-yang-models/yang-models/sonic-vrf.yang b/src/sonic-yang-models/yang-models/sonic-vrf.yang new file mode 100644 index 0000000000..0d7d0561dd --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-vrf.yang @@ -0,0 +1,49 @@ +module sonic-vrf { + namespace "http://github.com/Azure/sonic-vrf"; + prefix vrf; + + import sonic-extension { + prefix sonic-ext; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONIC VRF"; + + revision 2021-03-30 { + description + "Initial revision."; + } + + container sonic-vrf { + container VRF { + description "Vrf configuration."; + + list VRF_LIST { + key "name"; + + leaf name { + type string { + pattern "Vrf[a-zA-Z0-9_-]+" { + error-message "Invalid VRF name"; + error-app-tag vrf-name-invalid; + } + } + } + + leaf fallback { + type boolean; + default false; + description + "Enable/disable fallback feature which is useful for specified VRF user to access internet through global/main route."; + } + + } /* end of list VRF_LISt */ + } /* end of container VRf */ + } /* end of container sonic-vrf */ +}/* end of module sonic-vrf */