From 018a6495da079f39c798c34ffc9a9923255c4490 Mon Sep 17 00:00:00 2001 From: "sabari@broadcom" <45473507+gitsabari@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:09:58 -0800 Subject: [PATCH] [yang] added mclag sonic yang (#7622) #### How I did it Added mclag sonic yang file for the MCLAG enhancements as per HLD: Azure/SONiC#596 #### How to verify it try rest APIs #### Description for the changelog Added mclag sonic yang --- src/sonic-yang-models/setup.py | 4 + .../tests/files/sample_config_db.json | 51 ++- .../tests/yang_model_tests/tests/mclag.json | 32 ++ .../yang_model_tests/tests_config/mclag.json | 356 ++++++++++++++++++ .../yang-models/sonic-mclag.yang | 172 +++++++++ 5 files changed, 613 insertions(+), 2 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/mclag.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/mclag.json create mode 100644 src/sonic-yang-models/yang-models/sonic-mclag.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 70c14476e2..756ef83dab 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -122,7 +122,11 @@ setup( './yang-models/sonic-versions.yang', './yang-models/sonic-vlan.yang', './yang-models/sonic-vrf.yang', + + './yang-models/sonic-mclag.yang', + './yang-models/sonic-vlan-sub-interface.yang', + './yang-models/sonic-warm-restart.yang', './yang-models/sonic-lldp.yang', './yang-models/sonic-scheduler.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 fd3476d6dd..71ffcc1556 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -93,6 +93,16 @@ "tpid": "0x9200", "mtu": "9100", "lacp_key": "auto" + }, + "PortChannel2": { + "admin_status": "up", + "min_links": "1", + "members": [ + "Ethernet12" + ], + "tpid": "0x9200", + "mtu": "9100", + "lacp_key": "auto" } }, "PORTCHANNEL_INTERFACE": { @@ -103,7 +113,8 @@ }, "PORTCHANNEL_MEMBER": { "PortChannel0003|Ethernet1": {}, - "PortChannel0004|Ethernet2": {} + "PortChannel0004|Ethernet2": {}, + "PortChannel2|Ethernet12": {} }, "VLAN_INTERFACE": { "Vlan111": { @@ -309,7 +320,17 @@ "vlanid": "777", "mtu": "9216", "admin_status": "up" + }, + "Vlan12": { + "description": "mclag session ve", + "dhcp_servers": [ + "12.1.1.1" + ], + "vlanid": "12", + "mtu": "9216", + "admin_status": "up" } + }, "DEVICE_NEIGHBOR": { "Ethernet112": { @@ -909,6 +930,9 @@ }, "Vlan111|PortChannel0003": { "tagging_mode": "untagged" + }, + "Vlan12|PortChannel2": { + "tagging_mode": "tagged" } }, "LOOPBACK_INTERFACE": { @@ -1197,6 +1221,7 @@ "trap_group": "queue1_group1" } }, + "AUTO_TECHSUPPORT": { "GLOBAL": { "state" : "enabled", @@ -1331,7 +1356,6 @@ "type": "DWRR", "weight": "20" }, - "TEST@1": { "cbs": "1024", "cir": "1280000", @@ -1480,6 +1504,28 @@ } }, + + "MCLAG_DOMAIN": { + "123": { + "source_ip": "12.1.1.1", + "peer_ip": "12.1.1.2", + "peer_link": "PortChannel2", + "keepalive_interval": "1", + "session_timeout": "30" + } + }, + "MCLAG_INTERFACE": { + "123|PortChannel0004": { + "if_type": "PortChannel" + } + }, + "MCLAG_UNIQUE_IP": { + "Vlan12": { + "unique_ip": "enable" + } + }, + + "MIRROR_SESSION": { "erspan": { "dscp": "10", @@ -1498,6 +1544,7 @@ "Ethernet3", "Ethernet4" ] + } } }, diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/mclag.json b/src/sonic-yang-models/tests/yang_model_tests/tests/mclag.json new file mode 100644 index 0000000000..b7f3c69e1d --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/mclag.json @@ -0,0 +1,32 @@ +{ + "MCLAG_VALID_DOMAIN_CFG_TEST": { + "desc": "valid mclag configuration test" + }, + "MCLAG_VALID_DOMAIN_PEERLINK_ETH_TEST": { + "desc": "valid mclag configuration test with peer link ethernet" + }, + "MCLAG_INVALID_DOMAIN_IDS_TEST": { + "desc": "configure mclag domain id in range", + "eStr": "MCLAG Domain ID out of range" + }, + "MCLAG_INVALID_KEEPALIVE_TEST": { + "desc": "configure mclag keepalive values in range", + "eStr" : "MCLAG Domain keepalive interval out of range" + }, + "MCLAG_INVALID_SESSION_TIMEOUT_TEST": { + "desc": "configure mclag session timeout in range", + "eStr" : "MCLAG Domain session timeout out of range" + }, + "MCLAG_INVALID_KEEPALIVE_MUST_COND_TEST": { + "desc": "Invalid session and keepalive multiplier", + "eStr" : "(keepalive interval * 3) <= session_timeout value" + }, + "MCLAG_INTERFACE_DOMAIN_ABSENT_TEST": { + "desc": "mclag interface configured without domain", + "eStrKey" : "LeafRef" + }, + "MCLAG_UNIQUE_IP_DOMAIN_ABSENT_TEST": { + "desc": "mclag unique ip configured without domain", + "eStr" : "mclag not configured" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/mclag.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mclag.json new file mode 100644 index 0000000000..fdb2661a97 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mclag.json @@ -0,0 +1,356 @@ +{ + "MCLAG_VALID_DOMAIN_CFG_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + }, + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet10", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet10", + "speed": 25000 + } + ] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [ + { + "admin_status": "up", + "members": [ + "Ethernet0" + ], + "min_links": "1", + "mtu": "9100", + "lacp_key": "auto", + "name": "PortChannel2" + }, + { + "admin_status": "up", + "members": [ + "Ethernet10" + ], + "min_links": "1", + "mtu": "9100", + "lacp_key": "auto", + "name": "PortChannel10" + } + ] + } + }, + + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan12" + }, + { + "name": "Vlan100" + } + ] + }, + "sonic-vlan:VLAN_MEMBER": { + "VLAN_MEMBER_LIST": [ + { + "port": "PortChannel10", + "tagging_mode": "tagged", + "name": "Vlan100" + }, + { + "port": "PortChannel2", + "tagging_mode": "tagged", + "name": "Vlan12" + }, + { + "port": "PortChannel2", + "tagging_mode": "tagged", + "name": "Vlan100" + } + ] + }, + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan12" + } + ], + "VLAN_INTERFACE_IPPREFIX_LIST": [ + { + "family": "IPv4", + "ip-prefix": "12.1.1.1/24", + "scope": "global", + "name": "Vlan12" + } + ] + } + }, + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "123", + "source_ip": "12.1.1.1", + "peer_ip" : "12.1.1.2", + "peer_link": "PortChannel2", + "keepalive_interval" : "1", + "session_timeout": "30" + } + ] + }, + "sonic-mclag:MCLAG_INTERFACE": { + "MCLAG_INTERFACE_LIST": [ + { + "domain_id": "123", + "if_name" : "PortChannel10", + "if_type" : "Portchannel" + } + ] + } + } + }, + "MCLAG_VALID_DOMAIN_PEERLINK_ETH_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + }, + { + "admin_status": "up", + "alias": "eth4", + "description": "Ethernet4", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet4", + "speed": 25000 + } + ] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [ + { + "admin_status": "up", + "members": [ + "Ethernet0" + ], + "min_links": "1", + "mtu": "9100", + "lacp_key": "auto", + "name": "PortChannel2" + } + ] + } + }, + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan12" + } + ] + }, + "sonic-vlan:VLAN_MEMBER": { + "VLAN_MEMBER_LIST": [ + { + "port": "PortChannel2", + "tagging_mode": "tagged", + "name": "Vlan12" + } + ] + }, + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan12" + } + ], + "VLAN_INTERFACE_IPPREFIX_LIST": [ + { + "family": "IPv4", + "ip-prefix": "12.1.1.1/24", + "scope": "global", + "name": "Vlan12" + } + ] + } + }, + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "123", + "source_ip": "12.1.1.1", + "peer_ip" : "12.1.1.2", + "peer_link": "Ethernet4", + "keepalive_interval" : "1", + "session_timeout": "30" + } + ] + } + } + }, + "MCLAG_INVALID_DOMAIN_IDS_TEST": { + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "0", + "source_ip": "1.1.1.1" + }, + { + "domain_id": "4096", + "source_ip": "1.1.1.1" + } + + ] + } + } + }, + "MCLAG_INVALID_KEEPALIVE_TEST": { + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "123", + "source_ip": "1.1.1.1", + "keepalive_interval" : "0", + "session_timeout": "30" + }, + { + "domain_id": "123", + "source_ip": "1.1.1.1", + "keepalive_interval" : "61", + "session_timeout": "30" + } + ] + } + } + }, + "MCLAG_INVALID_SESSION_TIMEOUT_TEST": { + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "123", + "source_ip": "1.1.1.1", + "keepalive_interval" : "1", + "session_timeout": "0" + }, + { + "domain_id": "123", + "source_ip": "1.1.1.1", + "keepalive_interval" : "1", + "session_timeout": "3601" + } + ] + } + } + }, + "MCLAG_INVALID_KEEPALIVE_MUST_COND_TEST": { + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_DOMAIN": { + "MCLAG_DOMAIN_LIST": [ + { + "domain_id": "123", + "source_ip": "1.1.1.1", + "keepalive_interval" : "40", + "session_timeout": "30" + } + ] + } + } + }, + "MCLAG_INTERFACE_DOMAIN_ABSENT_TEST": { + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_INTERFACE": { + "MCLAG_INTERFACE_LIST": [ + { + "domain_id": "1001", + "if_name" : "PortChannel10", + "if_type" : "Portchannel" + }, + { + "domain_id": "2001", + "if_name" : "PortChannel20", + "if_type" : "Portchannel" + } + + ] + } + } + }, + "MCLAG_UNIQUE_IP_DOMAIN_ABSENT_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet12", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet12", + "speed": 25000 + } + ] + } + }, + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan12" + } + ] + }, + "sonic-vlan:VLAN_MEMBER": { + "VLAN_MEMBER_LIST": [ + { + "port": "Ethernet12", + "tagging_mode": "tagged", + "name": "Vlan12" + } + ] + }, + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan12" + } + ] + } + }, + + "sonic-mclag:sonic-mclag": { + "sonic-mclag:MCLAG_UNIQUE_IP": { + "MCLAG_UNIQUE_IP_LIST": [ + { + "if_name" : "Vlan12", + "unique_ip": "enable" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-mclag.yang b/src/sonic-yang-models/yang-models/sonic-mclag.yang new file mode 100644 index 0000000000..39e4c0b2b4 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-mclag.yang @@ -0,0 +1,172 @@ +module sonic-mclag { + namespace "http://github.com/Azure/sonic-mclag"; + prefix smclag; + yang-version 1.1; + + + import ietf-yang-types { + prefix yang; + } + + import ietf-inet-types { + prefix inet; + } + + import sonic-types { + prefix stypes; + } + + import sonic-port { + prefix prt; + } + + import sonic-portchannel { + prefix lag; + } + + // Comment sonic-vlan import here until libyang back-links issue is resolved for VLAN leaf reference. + //import sonic-vlan { + // prefix vlan; + //} + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONIC MCLAG"; + + revision 2019-10-01 { + description + "Initial revision."; + } + + container sonic-mclag { + + container MCLAG_DOMAIN { + + list MCLAG_DOMAIN_LIST { + key "domain_id"; + max-elements 1; + + leaf domain_id { + description "MCLAG Domain ID"; + type uint16 { + range "1..4095" { + error-message "MCLAG Domain ID out of range"; + } + } + } + + leaf source_ip { + type inet:ipv4-address; + description "MCLAG Domain source ip address for session between MCLAG Peers"; + } + leaf peer_ip { + type inet:ipv4-address; + description "MCLAG Domain peer ip address for session between MCLAG Peers"; + } + leaf peer_link { + description "MCLAG Domain peer link, data backup path link between MCLAG peers"; + type union { + type leafref { + path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:name"; + } + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + } + } + leaf keepalive_interval { + description "keepalive interval in seconds for MCLAG session between peers"; + type uint16 { + range "1..60" { + error-message "MCLAG Domain keepalive interval out of range"; + error-app-tag keepalive_interval-invalid; + } + } + default 1; + } + leaf session_timeout { + description "Session timeout in seconds for MCLAG session between peers"; + type uint16 { + range "1..3600" { + error-message "MCLAG Domain session timeout out of range"; + error-app-tag session_timeout-invalid; + } + } + default 30; + } + must "(keepalive_interval * 3) <= session_timeout" { + error-message "(keepalive interval * 3) <= session_timeout value"; + error-app-tag keepalive_session_multiplier-invalid; + } + } + } + + container MCLAG_INTERFACE { + + list MCLAG_INTERFACE_LIST { + description "List of MCLAG interfaces"; + key "domain_id if_name"; + + leaf domain_id { + description "List of MCLAG interfaces"; + type leafref { + path "../../../MCLAG_DOMAIN/MCLAG_DOMAIN_LIST/domain_id"; + } + } + + leaf if_name { + description "MCLAG interface name"; + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + } + leaf if_type { + description "MCLAG interface type, placeholder field to create instance"; + type string; + } + } + } + + container MCLAG_UNIQUE_IP { + + list MCLAG_UNIQUE_IP_LIST { + description "List of VLANs allowed to have unique ip addresses on MCLAG Peer nodes"; + key "if_name"; + + must "count(../../MCLAG_DOMAIN/MCLAG_DOMAIN_LIST/domain_id) != 0" { + error-message "mclag not configured"; + error-app-tag mclag-invalid; + } + + // Comment VLAN leaf reference here until libyang back-links issue is resolved and use VLAN string pattern + //must + // "count(/vlan:sonic-vlan/vlan:VLAN_INTERFACE/vlan:VLAN_INTERFACE_IPPREFIX_LIST[vlan:name=current()/if_name]) = 0" { + // error-message "remove configured ip/v6 address and reconfigure after separate ip configuration"; + // error-app-tag vlan-intf-ip-invalid; + // } + + leaf if_name { + description "Vlan interface name on which MCLAG unique ip config is done"; + // Comment VLAN leaf reference here until libyang back-links issue is resolved and use VLAN string pattern + //type leafref { + // path "/vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name"; + //} + type string { + pattern 'Vlan([0-9]{1,3}|[1-3][0-9]{3}|[4][0][0-8][0-9]|[4][0][9][0-4])'; + } + } + leaf unique_ip { + description "unique ip enable, by default disable"; + type enumeration { + enum enable; + } + } + } + } + } +}