diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 4ca8d065c6..1928643c28 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -82,6 +82,7 @@ setup( './yang-models/sonic-bgp-common.yang', './yang-models/sonic-bgp-global.yang', './yang-models/sonic-bgp-monitor.yang', + './yang-models/sonic-bgp-internal-neighbor.yang', './yang-models/sonic-bgp-neighbor.yang', './yang-models/sonic-bgp-peergroup.yang', './yang-models/sonic-bgp-peerrange.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 8c5a8c0af9..505c92ba96 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -103,18 +103,32 @@ "tpid": "0x9200", "mtu": "9100", "lacp_key": "auto" + }, + "PortChannel42": { + "admin_status": "up", + "members": [ + "Ethernet-BP0", + "Ethernet-BP4" + ], + "min_links": "2", + "mtu": "9100", + "tpid": "0x8100" } }, "PORTCHANNEL_INTERFACE": { "PortChannel0003": { "nat_zone": "1" }, - "PortChannel0004": {"vrf_name": "Vrf_blue"} + "PortChannel0004": {"vrf_name": "Vrf_blue"}, + "PortChannel42|10.1.0.1/31": {}, + "PortChannel42|2603:10e2:400:1::2/126": {} }, "PORTCHANNEL_MEMBER": { "PortChannel0003|Ethernet1": {}, "PortChannel0004|Ethernet2": {}, - "PortChannel2|Ethernet12": {} + "PortChannel2|Ethernet12": {}, + "PortChannel42|Ethernet-BP0": {}, + "PortChannel42|Ethernet-BP4": {} }, "VLAN_INTERFACE": { "Vlan111": { @@ -734,7 +748,33 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up" - } + }, + "Ethernet-BP0": { + "admin_status": "up", + "alias": "Eth4-ASIC0", + "asic_port_name": "Eth4-ASIC0", + "description": "ASIC2:Eth0-ASIC2", + "index": "0", + "lanes": "17,18,19,20", + "mtu": "9100", + "pfc_asym": "off", + "role": "Int", + "speed": "40000", + "tpid": "0x8100" + }, + "Ethernet-BP4": { + "admin_status": "up", + "alias": "Eth5-ASIC0", + "asic_port_name": "Eth5-ASIC0", + "description": "ASIC2:Eth1-ASIC2", + "index": "1", + "lanes": "21,22,23,24", + "mtu": "9100", + "pfc_asym": "off", + "role": "Int", + "speed": "40000", + "tpid": "0x8100" + } }, "ACL_TABLE": { "V4-ACL-TABLE": { @@ -1704,8 +1744,30 @@ "send_sci": "true", "rekey_period": "3600" } - } + }, + "BGP_INTERNAL_NEIGHBOR": { + "10.1.0.0": { + "asn": "64850", + "holdtime": "180", + "keepalive": "60", + "local_addr": "10.1.0.1", + "name": "ASIC1", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + }, + "2603:10e2:400:1::1": { + "asn": "64850", + "holdtime": "180", + "keepalive": "60", + "local_addr": "2603:10e2:400:1::2", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + } + } }, "SAMPLE_CONFIG_DB_UNKNOWN": { "UNKNOWN_TABLE": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/bgp_internal.json b/src/sonic-yang-models/tests/yang_model_tests/tests/bgp_internal.json new file mode 100644 index 0000000000..3438b70c8c --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/bgp_internal.json @@ -0,0 +1,17 @@ +{ + "BGP_INTERNAL_TEST": { + "desc": "Load bgp internal neighbor table with ipv4 and ipv6 neighbors." + }, + "BGP_INTERNAL_INVALID_ASN_TEST": { + "desc": "Load bgp internal neighbor table with ipv4 neighbor having incorrect asn.", + "eStr": ["Internal iBGP neighbors should have same ASN as defined in device metadata"] + }, + "BGP_INVALID_LOCAL_ADDRESS_FAMILY_TEST": { + "desc": "Load bgp internal ipv4 neighboripv6 local address.", + "eStr": ["local address and neighbor address family doesnt match"] + }, + "BGP_LOCAL_ADDRESS_ABSENT_TEST": { + "desc":"Load bgp internal neighbor table no local address.", + "eStrKey" : "Mandatory" + } +} \ No newline at end of file diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp_internal.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp_internal.json new file mode 100644 index 0000000000..07a26ab345 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp_internal.json @@ -0,0 +1,128 @@ +{ + "BGP_INTERNAL_TEST": { + "sonic-bgp-internal-neighbor:sonic-bgp-internal-neighbor": { + "sonic-bgp-internal-neighbor:BGP_INTERNAL_NEIGHBOR": { + "BGP_INTERNAL_NEIGHBOR_LIST": [ + { + "neighbor": "10.0.0.1", + "asn": "65001", + "holdtime": "180", + "keepalive": "60", + "local_addr": "10.0.0.2", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + }, + { + "neighbor": "2603:10e2:400:1::1", + "asn": "65001", + "holdtime": "180", + "keepalive": "60", + "local_addr": "2603:10e2:400:1::2", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + } + ] + } + }, + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "65001", + "default_bgp_status": "up", + "hostname": "MASIC", + "platform": "multi-asic" + } + } + } + }, + "BGP_INTERNAL_INVALID_ASN_TEST": { + "sonic-bgp-internal-neighbor:sonic-bgp-internal-neighbor": { + "sonic-bgp-internal-neighbor:BGP_INTERNAL_NEIGHBOR": { + "BGP_INTERNAL_NEIGHBOR_LIST": [ + { + "neighbor": "10.0.0.1", + "asn": "65002", + "holdtime": "180", + "keepalive": "60", + "local_addr": "10.0.0.2", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + } + ] + } + }, + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "65001", + "default_bgp_status": "up", + "hostname": "MASIC", + "platform": "multi-asic" + } + } + } + }, + "BGP_INVALID_LOCAL_ADDRESS_FAMILY_TEST": { + "sonic-bgp-internal-neighbor:sonic-bgp-internal-neighbor": { + "sonic-bgp-internal-neighbor:BGP_INTERNAL_NEIGHBOR": { + "BGP_INTERNAL_NEIGHBOR_LIST": [ + { + "neighbor": "10.0.0.1", + "asn": "65001", + "holdtime": "180", + "keepalive": "60", + "local_addr": "2603:10e2:400:1::5", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + } + ] + } + }, + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "65001", + "default_bgp_status": "up", + "hostname": "MASIC", + "platform": "multi-asic" + } + } + } + }, + "BGP_LOCAL_ADDRESS_ABSENT_TEST": { + "sonic-bgp-internal-neighbor:sonic-bgp-internal-neighbor": { + "sonic-bgp-internal-neighbor:BGP_INTERNAL_NEIGHBOR": { + "BGP_INTERNAL_NEIGHBOR_LIST": [ + { + "neighbor": "2603:10e2:400:1::1", + "asn": "65001", + "holdtime": "180", + "keepalive": "60", + "name": "ASIC0", + "nhopself": "0", + "rrclient": "0", + "admin_status": "up" + } + ] + } + }, + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "65001", + "default_bgp_status": "up", + "hostname": "MASIC", + "platform": "multi-asic" + } + } + } + } +} \ No newline at end of file diff --git a/src/sonic-yang-models/yang-models/sonic-bgp-internal-neighbor.yang b/src/sonic-yang-models/yang-models/sonic-bgp-internal-neighbor.yang new file mode 100644 index 0000000000..69a089f7ca --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-bgp-internal-neighbor.yang @@ -0,0 +1,58 @@ +module sonic-bgp-internal-neighbor { + namespace "http://github.com/Azure/sonic-bgp-internal-neighbor"; + prefix bgpintnbr; + yang-version 1.1; + + import ietf-inet-types { + prefix inet; + } + + import sonic-device_metadata { + prefix dm; + } + + import sonic-bgp-common { + prefix bgpcmn; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONIC BGP Internal Neighbor for multi asic platforms"; + + revision 2021-04-10 { + description + "Initial revision."; + } + + container sonic-bgp-internal-neighbor { + container BGP_INTERNAL_NEIGHBOR { + list BGP_INTERNAL_NEIGHBOR_LIST { + description "List for internal neighbors in multi asic platforms"; + key "neighbor"; + leaf neighbor { + type inet:ip-address; + description "BGP Neighbor address"; + } + uses bgpcmn:sonic-bgp-cmn-neigh { + refine asn { + must "(current() = /dm:sonic-device_metadata/dm:DEVICE_METADATA/dm:localhost/dm:bgp_asn)" { + error-message "Internal iBGP neighbors should have same ASN as defined in device metadata"; + } + } + refine local_addr { + mandatory true; + must "((contains(../neighbor, '.') and contains(current(), '.')) or + (contains(../neighbor, ':') and contains(current(), ':')))" { + error-message "local address and neighbor address family doesnt match"; + } + } + } + } + } + } +} \ No newline at end of file