From 4338d8293fe51c3d33daf4020cbb0e7a943ad38b Mon Sep 17 00:00:00 2001 From: Prince Sunny Date: Thu, 27 Aug 2020 14:14:04 -0700 Subject: [PATCH] Skip vnet-vxlan interfaces from generating networks (#5251) * Skip Vnet interface from generating networks --- dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2 | 13 ++++++++----- dockers/docker-fpm-frr/frr/common/functions.conf.j2 | 12 ++++++++++++ .../data/sonic-cfggen/bgpd.main.conf.j2/all.json | 5 ++++- .../sonic-cfggen/bgpd.main.conf.j2/defaults.json | 5 ++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2 index c216e24a64..30a399d0af 100644 --- a/dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2 +++ b/dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2 @@ -1,4 +1,4 @@ -{% from "common/functions.conf.j2" import get_ipv4_loopback_address, get_ipv6_loopback_address %} +{% from "common/functions.conf.j2" import get_ipv4_loopback_address, get_ipv6_loopback_address, get_vnet_interfaces %} ! ! template: bgpd/bgpd.main.conf.j2 ! @@ -14,14 +14,17 @@ ip prefix-list PL_LoopbackV4 permit {{ get_ipv4_loopback_address(LOOPBACK_INTERF ipv6 prefix-list PL_LoopbackV6 permit {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | replace('/128', '/64') | ip_network }}/64 {% endif %} ! +{% if VLAN_INTERFACE is defined %} +{% set vnet_intfs = get_vnet_interfaces(VLAN_INTERFACE) %} +{% endif %} {% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} +{% if prefix | ipv4 and name not in vnet_intfs %} ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq {{ loop.index * 5 }} permit {{ prefix }} ! {% endif %} {% endfor %} {% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{% if prefix | ipv6 %} +{% if prefix | ipv6 and name not in vnet_intfs %} ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq {{ loop.index * 5 }} permit {{ prefix }} ! {% endif %} @@ -78,9 +81,9 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} ! {% block vlan_advertisement %} {% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} -{% if prefix | ipv4 %} +{% if prefix | ipv4 and name not in vnet_intfs %} network {{ prefix }} -{% elif prefix | ipv6 %} +{% elif prefix | ipv6 and name not in vnet_intfs %} address-family ipv6 network {{ prefix }} exit-address-family diff --git a/dockers/docker-fpm-frr/frr/common/functions.conf.j2 b/dockers/docker-fpm-frr/frr/common/functions.conf.j2 index 9857f068fe..2049e11414 100644 --- a/dockers/docker-fpm-frr/frr/common/functions.conf.j2 +++ b/dockers/docker-fpm-frr/frr/common/functions.conf.j2 @@ -21,3 +21,15 @@ {% endfor %} {{ L.ip }} {%- endmacro %} + +{% macro get_vnet_interfaces(interfaces) -%} +{% set L = namespace(intfs=[]) %} +{% set vnet_intfs = [] %} +{% for (key, metadata) in interfaces.iteritems() %} +{% if metadata.has_key("vnet_name") %} +{% set vnet_intfs = vnet_intfs.append(key) %} +{% endif %} +{% endfor %} +{% set L.intfs = vnet_intfs %} +{{ L.intfs }} +{%- endmacro %} diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.json b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.json index 36099674ac..3d5d07d95f 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.json +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.json @@ -11,7 +11,10 @@ }, "VLAN_INTERFACE": { "Vlan10|10.10.10.1/24": {}, - "Vlan10|fc01::1/64": {} + "Vlan10|fc01::1/64": {}, + "Vlan20": {"vnet_name": "Vnet1"}, + "Vlan20|20.20.20.1/24": {}, + "Vlan20|fd01::1/64": {} }, "constants": { "bgp": { diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.json b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.json index 2db9bd771c..e841437650 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.json +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.json @@ -11,7 +11,10 @@ }, "VLAN_INTERFACE": { "Vlan10|10.10.10.1/24": {}, - "Vlan10|fc01::1/64": {} + "Vlan10|fc01::1/64": {}, + "Vlan20": {"vnet_name": "Vnet1"}, + "Vlan20|20.20.20.1/24": {}, + "Vlan20|fd01::1/64": {} }, "constants": { "bgp": {