From 55a0722a33c19f9693ff441d3b4265876dc92cf3 Mon Sep 17 00:00:00 2001 From: StormLiangMS <89824293+StormLiangMS@users.noreply.github.com> Date: Sat, 5 Mar 2022 09:20:38 +0800 Subject: [PATCH] support BGP_ALLOWED_PREFIXES (#10142) --- src/sonic-yang-models/setup.py | 5 +- .../tests/files/sample_config_db.json | 8 + .../tests/yang_model_tests/tests/bgp.json | 41 ++++- .../yang_model_tests/tests_config/bgp.json | 171 ++++++++++++++++++ .../yang-models/sonic-bgp-allowed-prefix.yang | 102 +++++++++++ 5 files changed, 323 insertions(+), 4 deletions(-) create mode 100644 src/sonic-yang-models/yang-models/sonic-bgp-allowed-prefix.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index d8b9a0d0c4..4295492558 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -85,6 +85,7 @@ setup( './yang-models/sonic-bgp-neighbor.yang', './yang-models/sonic-bgp-peergroup.yang', './yang-models/sonic-bgp-peerrange.yang', + './yang-models/sonic-bgp-allowed-prefix.yang', './yang-models/sonic-breakout_cfg.yang', './yang-models/sonic-buffer-pg.yang', './yang-models/sonic-buffer-pool.yang', @@ -126,11 +127,8 @@ 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', @@ -153,6 +151,7 @@ setup( './cvlyang-models/sonic-bgp-neighbor.yang', './cvlyang-models/sonic-bgp-peergroup.yang', './cvlyang-models/sonic-bgp-peerrange.yang', + './cvlyang-models/sonic-bgp-allowed-prefix.yang', './cvlyang-models/sonic-breakout_cfg.yang', './cvlyang-models/sonic-copp.yang', './cvlyang-models/sonic-crm.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 89a915e72b..e7b03092ef 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1216,6 +1216,14 @@ "peer_group": "PG1" } }, + "BGP_ALLOWED_PREFIXES" :{ + "DEPLOYMENT_ID|4|123:123": { + "default_action": "permit" + }, + "DEPLOYMENT_ID|5": { + "default_action": "permit" + } + }, "ROUTE_MAP_SET": { "map1": { } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json b/src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json index 8f92f2d905..966171888b 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json @@ -157,7 +157,46 @@ }, "BGP_PEERRANGE_ALL_VALID": { "desc": "Configure BGP peer range table." + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_ALL_VALID": { + "desc": "Configue BGP allowed prefix list." + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_DEPLOYMENT": { + "desc": "Invalid default action.", + "eStrKey" : "Pattern" + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_DEFAULT_ACTION": { + "desc": "Invalid default action.", + "eStrKey" : "InvalidValue", + "eStr" : ["default_action"] + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_PREFIXES_IPV4": { + "desc": "Invalid IPv4 prefix.", + "eStrKey" : "Pattern" + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_PREFIXES_IPV6": { + "desc": "Invalid IPv6 prefix.", + "eStrKey" : "Pattern" + }, + "BGP_ALLOWED_PREFIXES_LIST_ALL_VALID": { + "desc": "Configue BGP allowed prefix list." + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_DEPLOYMENT": { + "desc": "Invalid default action.", + "eStrKey" : "Pattern" + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_DEFAULT_ACTION": { + "desc": "Invalid default action.", + "eStrKey" : "InvalidValue", + "eStr" : ["default_action"] + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_PREFIXES_IPV4": { + "desc": "Invalid IPv4 prefix.", + "eStrKey" : "Pattern" + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_PREFIXES_IPV6": { + "desc": "Invalid IPv6 prefix.", + "eStrKey" : "Pattern" } - } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp.json index 62bfdc4269..a6a30bd405 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp.json @@ -1420,6 +1420,177 @@ ] } } + }, + + "BGP_ALLOWED_PREFIXES_COM_LIST_ALL_VALID": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_COM_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "community": "123:123", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + }, + { + "deployment": "DEPLOYMENT_ID", + "id": "5", + "community": "456:456", + "default_action": "permit", + "prefixes_v4": ["10.10.0.0/24", "10.11.0.0/24"], + "prefixes_v6": ["fc00:f1::/64", "fc00:a1::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_DEPLOYMENT": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_COM_LIST": [ + { + "deployment": "DEPLOYMENTID", + "id": "4", + "community": "123:123", + "default_action": "permitall", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_DEFAULT_ACTION": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_COM_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "community": "123:123", + "default_action": "permitall", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_PREFIXES_IPV4": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_COM_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "community": "123:123", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/48", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_COM_LIST_INVALID_PREFIXES_IPV6": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_COM_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "community": "123:123", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0./24"], + "prefixes_v6": ["fc00:f0::/129", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_LIST_ALL_VALID": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + }, + { + "deployment": "DEPLOYMENT_ID", + "id": "5", + "default_action": "permit", + "prefixes_v4": ["10.10.0.0/24", "10.11.0.0/24"], + "prefixes_v6": ["fc00:f1::/64", "fc00:a1::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_DEPLOYMENT": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_LIST": [ + { + "deployment": "DEPLOYMENTID", + "id": "4", + "default_action": "permitall", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_DEFAULT_ACTION": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "default_action": "permitall", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_PREFIXES_IPV4": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/48", "10.1.0.0/24"], + "prefixes_v6": ["fc00:f0::/64", "fc00:a0::/64"] + } + ] + } + } + }, + "BGP_ALLOWED_PREFIXES_LIST_INVALID_PREFIXES_IPV6": { + "sonic-bgp-allowed-prefix:sonic-bgp-allowed-prefix": { + "sonic-bgp-allowed-prefix:BGP_ALLOWED_PREFIXES": { + "BGP_ALLOWED_PREFIXES_LIST": [ + { + "deployment": "DEPLOYMENT_ID", + "id": "4", + "default_action": "permit", + "prefixes_v4": ["10.0.0.0/24", "10.1.0.0./24"], + "prefixes_v6": ["fc00:f0::/129", "fc00:a0::/64"] + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-bgp-allowed-prefix.yang b/src/sonic-yang-models/yang-models/sonic-bgp-allowed-prefix.yang new file mode 100644 index 0000000000..9423879837 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-bgp-allowed-prefix.yang @@ -0,0 +1,102 @@ +module sonic-bgp-allowed-prefix { + namespace "http://github.com/Azure/sonic-bgp-allowed-prefix"; + prefix bgppre; + yang-version 1.1; + + import sonic-bgp-common { + prefix bgpcmn; + } + + import ietf-inet-types { + prefix inet; + } + + import sonic-routing-policy-sets { + prefix rpolsets; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONIC BGP Allowed Prefix"; + + revision 2022-02-26 { + description + "Initial revision."; + } + + container sonic-bgp-allowed-prefix { + container BGP_ALLOWED_PREFIXES { + list BGP_ALLOWED_PREFIXES_COM_LIST { + key "deployment id community"; + + leaf deployment { + type string { + pattern "DEPLOYMENT_ID"; + } + description "BGP allowed prefix list key type"; + } + + leaf id { + type uint32; + description "BGP allowed prefix list deployment id"; + } + + leaf community { + type string; + description "BGP allowed prefix list deployment community"; + } + + leaf default_action { + type rpolsets:routing-policy-action-type; + description "Permit/Deny action for BGP allow prefix list"; + } + + leaf-list prefixes_v4 { + type inet:ipv4-prefix; + description "BGP V4 allowed prefix list"; + } + + leaf-list prefixes_v6 { + type inet:ipv6-prefix; + description "BGP V6 allowed prefix list"; + } + } + + list BGP_ALLOWED_PREFIXES_LIST { + key "deployment id"; + + leaf deployment { + type string { + pattern "DEPLOYMENT_ID"; + } + description "BGP allowed prefix list key type"; + } + + leaf id { + type uint32; + description "BGP allowed prefix list deployment id"; + } + + leaf default_action { + type rpolsets:routing-policy-action-type; + description "Permit/Deny action for BGP allow prefix list"; + } + + leaf-list prefixes_v4 { + type inet:ipv4-prefix; + description "BGP V4 allowed prefix list"; + } + + leaf-list prefixes_v6 { + type inet:ipv6-prefix; + description "BGP V6 allowed prefix list"; + } + } + } + } +}