From 0cdef2ebc6a87a2ab93cb9c8aa177923622c4b90 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Thu, 25 Aug 2022 08:46:45 -0700 Subject: [PATCH] [YANG] add peer switch model (#11828) Why I did it Address issue #10966 sign-off: Jing Zhang zhangjing@microsoft.com How I did it Add sonic-peer-switch.yang and unit tests. How to verify it Compile Compile target/python-wheels/sonic_yang_mgmt-1.0-py3-none-any.whl and target/python-wheels/sonic_yang_models-1.0-py3-none-any.whl. Which release branch to backport (provide reason below if selected) 201811 201911 202006 202012 202106 202111 202205 Description for the changelog Link to config_db schema for YANG module changes https://github.com/sonic-net/sonic-buildimage/blob/b721ff87b976a6a38bdd65443ea3bc686014e783/src/sonic-yang-models/doc/Configuration.md#peer-switch --- src/sonic-yang-models/doc/Configuration.md | 142 ++++++++++-------- src/sonic-yang-models/setup.py | 1 + .../tests/files/sample_config_db.json | 5 + .../yang_model_tests/tests/peer-switch.json | 13 ++ .../tests_config/peer-switch.json | 39 +++++ .../yang-models/sonic-peer-switch.yang | 49 ++++++ 6 files changed, 185 insertions(+), 64 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/peer-switch.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/peer-switch.json create mode 100644 src/sonic-yang-models/yang-models/sonic-peer-switch.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 6c01344f63..2167cab027 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -36,6 +36,7 @@ Table of Contents * [MAP_PFC_PRIORITY_TO_QUEUE](#map_pfc_priority_to_queue) * [NTP Global Configuration](#ntp-global-configuration) * [NTP and SYSLOG servers](#ntp-and-syslog-servers) + * [Peer Switch](#peer-switch) * [Policer](#policer) * [Port](#port) * [Port Channel](#port-channel) @@ -724,13 +725,13 @@ This kind of profiles will be handled by buffer manager and won't be applied to ### Data Plane L3 Interfaces -IP configuration for data plane are defined in **INTERFACE**, **VLAN_SUB_INTERFACE**, -**PORTCHANNEL_INTERFACE** and **VLAN_INTERFACE** table. The objects -in all four tables have the interface (could be physical port, port -channel, vlan or vlan sub interface) that IP address is attached to as first-level key, and -IP prefix as second-level key. IP interface address objects don't have any attributes. -IP interface attributes, resides in those tables as well, key is the interface name -and value is a list of field-values representing the interface attributes, e.g. loopback action. +IP configuration for data plane are defined in **INTERFACE**, **VLAN_SUB_INTERFACE**, +**PORTCHANNEL_INTERFACE** and **VLAN_INTERFACE** table. The objects +in all four tables have the interface (could be physical port, port +channel, vlan or vlan sub interface) that IP address is attached to as first-level key, and +IP prefix as second-level key. IP interface address objects don't have any attributes. +IP interface attributes, resides in those tables as well, key is the interface name +and value is a list of field-values representing the interface attributes, e.g. loopback action. ``` { @@ -738,27 +739,27 @@ and value is a list of field-values representing the interface attributes, e.g. "Ethernet0|10.0.0.0/31": {}, "Ethernet4|10.0.0.2/31": {}, "Ethernet8|10.0.0.4/31": {} - "Ethernet8": { - "loopback_action": "drop" - } + "Ethernet8": { + "loopback_action": "drop" + } }, - + "PORTCHANNEL_INTERFACE": { "PortChannel01|10.0.0.56/31": {}, "PortChannel01|FC00::71/126": {}, "PortChannel02|10.0.0.58/31": {}, "PortChannel02|FC00::75/126": {} }, - + "VLAN_INTERFACE": { "Vlan1000|192.168.0.1/27": {} - }, - -"VLAN_SUB_INTERFACE": { - "Ethernet4.1|10.0.0.2/31": {}, - "Ethernet4.1": { - "loopback_action": "drop" - } + }, + +"VLAN_SUB_INTERFACE": { + "Ethernet4.1|10.0.0.2/31": {}, + "Ethernet4.1": { + "loopback_action": "drop" + } } } ``` @@ -1114,51 +1115,64 @@ These information are configured in individual tables. Domain name or IP address of the server is used as object key. Currently there are no attributes in those objects. -***NTP server*** -``` -{ - "NTP_SERVER": { - "2.debian.pool.ntp.org": {}, - "1.debian.pool.ntp.org": {}, - "3.debian.pool.ntp.org": {}, - "0.debian.pool.ntp.org": {} - }, - - "NTP_SERVER": { - "23.92.29.245": {}, - "204.2.134.164": {} - } -} -``` - -***Syslog server*** -``` -{ - "SYSLOG_SERVER": { - "10.0.0.5": {}, - "10.0.0.6": {}, - "10.11.150.5": {} - }, - - "SYSLOG_SERVER" : { - "2.2.2.2": { - "source": "1.1.1.1", - "port": "514", - "vrf": "default" - }, - "4.4.4.4": { - "source": "3.3.3.3", - "port": "514", - "vrf": "mgmt" - }, - "2222::2222": { - "source": "1111::1111", - "port": "514", - "vrf": "Vrf-Data" - } - } -} -``` +***NTP server*** +``` +{ + "NTP_SERVER": { + "2.debian.pool.ntp.org": {}, + "1.debian.pool.ntp.org": {}, + "3.debian.pool.ntp.org": {}, + "0.debian.pool.ntp.org": {} + }, + + "NTP_SERVER": { + "23.92.29.245": {}, + "204.2.134.164": {} + } +} +``` + +***Syslog server*** +``` +{ + "SYSLOG_SERVER": { + "10.0.0.5": {}, + "10.0.0.6": {}, + "10.11.150.5": {} + }, + + "SYSLOG_SERVER" : { + "2.2.2.2": { + "source": "1.1.1.1", + "port": "514", + "vrf": "default" + }, + "4.4.4.4": { + "source": "3.3.3.3", + "port": "514", + "vrf": "mgmt" + }, + "2222::2222": { + "source": "1111::1111", + "port": "514", + "vrf": "Vrf-Data" + } + } +} +``` + +### Peer Switch + +Below is an exmaple of the peer switch table configuration. +``` +{ + "PEER_SWITCH": { + "vlab-05": { + "address_ipv4": "10.1.0.33" + } + } +} +``` ### Policer diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index ee4f7e55bc..f5ff5b5fe5 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -152,6 +152,7 @@ setup( './yang-models/sonic-storm-control.yang', './yang-models/sonic-tc-priority-group-map.yang', './yang-models/sonic-tc-queue-map.yang', + './yang-models/sonic-peer-switch.yang', './yang-models/sonic-pfc-priority-queue-map.yang', './yang-models/sonic-pfc-priority-priority-group-map.yang', './yang-models/sonic-port-qos-map.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 db7798f318..c7d199fa9f 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1798,6 +1798,11 @@ } }, + "PEER_SWITCH": { + "vlab-05": { + "address_ipv4": "10.1.0.33" + } + }, "POLICER": { "everflow_static_policer": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/peer-switch.json b/src/sonic-yang-models/tests/yang_model_tests/tests/peer-switch.json new file mode 100644 index 0000000000..b8ee10dbdf --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/peer-switch.json @@ -0,0 +1,13 @@ +{ + "PEER_SWITCH_LOAD_NORMAL": { + "desc": "Load PEER_SWITCH for dualtor device." + }, + "PEER_SWITCH_MISSING_DEVICE__NAME": { + "desc": "Load PEER_SWITCH missing PEER Device name.", + "eStrKey": "Mandatory" + }, + "PEER_SWITCH_INVALID_IP_ADDRESS": { + "desc": "Load PEER_SWITCH with invalid IPv4 Address.", + "eStrKey": "Pattern" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/peer-switch.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/peer-switch.json new file mode 100644 index 0000000000..e3857fc392 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/peer-switch.json @@ -0,0 +1,39 @@ +{ + "PEER_SWITCH_LOAD_NORMAL": { + "sonic-peer-switch:sonic-peer-switch": { + "sonic-peer-switch:PEER_SWITCH": { + "PEER_SWITCH_LIST": [ + { + "peer_switch": "vlab-05", + "address_ipv4": "10.1.0.33" + } + ] + } + } + }, + + "PEER_SWITCH_MISSING_DEVICE__NAME": { + "sonic-peer-switch:sonic-peer-switch": { + "sonic-peer-switch:PEER_SWITCH": { + "PEER_SWITCH_LIST": [ + { + "address_ipv4": "10.1.0.33" + } + ] + } + } + }, + + "PEER_SWITCH_INVALID_IP_ADDRESS": { + "sonic-peer-switch:sonic-peer-switch": { + "sonic-peer-switch:PEER_SWITCH": { + "PEER_SWITCH_LIST": [ + { + "peer_switch": "vlab-05", + "address_ipv4": "10.1.0.33/32" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-peer-switch.yang b/src/sonic-yang-models/yang-models/sonic-peer-switch.yang new file mode 100644 index 0000000000..79a94c95c2 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-peer-switch.yang @@ -0,0 +1,49 @@ +module sonic-peer-switch { + yang-version 1.1; + namespace "http://github.com/Azure/sonic-peer-switch"; + prefix peer_switch; + + import ietf-inet-types { + prefix inet; + } + + import sonic-types { + prefix stypes; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONiC DualToR peer switch data"; + + revision 2022-08-23 { + description + "Initial revision"; + } + + container sonic-peer-switch { + container PEER_SWITCH { + list PEER_SWITCH_LIST { + max-elements 1; + + key "peer_switch"; + + leaf peer_switch { + type stypes:hostname; + + description "SONiC DualToR peer host name."; + } + + leaf address_ipv4 { + type inet:ipv4-address; + + description "SONiC DualToR peer's IPv4 address."; + } + } + } + } +}