Skip to content

Commit ff937d3

Browse files
frr bgp conf template handling switch_type == voq (#24158)
when switch_type is voq, it could either be a single asic or multi-asic or even a voq_chassis bgpd.main.conf.j2 needs to handle the single asic case differently than the multi-asic or voq_chassis. A new filter file_exists is now used within j2 files to look for chasssisdb.conf and determine if its a voq_chassis Incase of unit test, the test just runs with a json file only. Hence using a chassisdb_conf_present in it to represent the chassis case When assigning the loopback0 address, handle the single asic voq case.
1 parent 4794f1d commit ff937d3

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq {{ loop.index * 5 }} permit {{ prefi
4242
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
4343
{% set multi_asic = True %}
4444
{% endif %}
45-
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
45+
{% if DEVICE_METADATA['localhost']['switch_type'] == 'voq' and ('chassisdb_conf_present' in DEVICE_METADATA['localhost'] or
46+
'/usr/share/sonic/platform/chassisdb.conf' | file_exists) %}
47+
{% set voq_chassis = True %}
48+
{% endif %}
49+
{% if multi_asic is defined or voq_chassis is defined or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
4650
ip prefix-list V4_P2P_IP permit 0.0.0.0/0 ge 31 le 31
4751
!
4852
ipv6 prefix-list V6_P2P_IP permit ::/0 ge 126 le 126
@@ -104,7 +108,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
104108
!
105109
{% endif %}
106110
{# set router-id #}
107-
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
111+
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or voq_chassis is defined or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
108112
{% if 'bgp_router_id' in DEVICE_METADATA['localhost'] %}
109113
bgp router-id {{ DEVICE_METADATA["localhost"]["bgp_router_id"] }}
110114
{% elif lo4096_ipv4 is not none %}
@@ -122,7 +126,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
122126
{% if lo0_ipv4 is not none %}
123127
network {{ lo0_ipv4 }}/32
124128
{% endif %}
125-
{% if lo4096_ipv4 is not none and ((multi_asic is defined and DEVICE_METADATA['localhost']['switch_type'] != 'chassis-packet') or (DEVICE_METADATA['localhost']['switch_type'] == 'voq')) %}
129+
{% if lo4096_ipv4 is not none and ((multi_asic is defined and DEVICE_METADATA['localhost']['switch_type'] != 'chassis-packet') or (voq_chassis is defined)) %}
126130
network {{ lo4096_ipv4 }}/32 route-map HIDE_INTERNAL
127131
{% endif %}
128132
!
@@ -133,13 +137,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
133137
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/128
134138
{% else %}
135139
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/64
136-
{% if DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
140+
{% if voq_chassis is defined or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
137141
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/128 route-map HIDE_INTERNAL
138142
{% endif %}
139143
{% endif %}
140144
exit-address-family
141145
{% endif %}
142-
{% if ((multi_asic is defined and DEVICE_METADATA['localhost']['switch_type'] != 'chassis-packet') or (DEVICE_METADATA['localhost']['switch_type'] == 'voq')) %}
146+
{% if ((multi_asic is defined and DEVICE_METADATA['localhost']['switch_type'] != 'chassis-packet') or (voq_chassis is defined)) %}
143147
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") != 'None' %}
144148
address-family ipv6
145149
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/128 route-map HIDE_INTERNAL
@@ -161,7 +165,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
161165
{% endblock vlan_advertisement %}
162166
!
163167
!
164-
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
168+
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or voq_chassis is defined or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
165169
address-family ipv4
166170
redistribute connected route-map V4_CONNECTED_ROUTES
167171
exit-address-family

dockers/docker-fpm-frr/frr/bgpd/templates/monitors/peer-group.conf.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
!
22
! template: bgpd/templates/BGPMON/peer-group.conf.j2
33
!
4+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'voq' and ('chassisdb_conf_present' in CONFIG_DB__DEVICE_METADATA['localhost'] or
5+
'/usr/share/sonic/platform/chassisdb.conf' | file_exists) %}
6+
{% set voq_chassis = True %}
7+
{% endif %}
48
neighbor BGPMON peer-group
5-
{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'voq' or CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
9+
{% if voq_chassis is defined or CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
610
neighbor BGPMON update-source Loopback4096
711
{% elif loopback0_ipv4 %}
812
neighbor BGPMON update-source {{ loopback0_ipv4 | ip }}

src/sonic-bgpcfgd/bgpcfgd/template.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import jinja2
55
import netaddr
6+
import os
67

78
from .log import log_err
89

@@ -15,6 +16,7 @@ def __init__(self, template_path = '/usr/share/sonic/templates'):
1516
j2_env.filters['ipv4'] = self.is_ipv4
1617
j2_env.filters['ipv6'] = self.is_ipv6
1718
j2_env.filters['pfx_filter'] = self.pfx_filter
19+
j2_env.filters['file_exists'] = self.file_exists_filter
1820
for attr in ['ip', 'network', 'prefixlen', 'netmask']:
1921
j2_env.filters[attr] = partial(self.prefix_attr, attr)
2022
self.env = j2_env
@@ -106,3 +108,7 @@ def pfx_filter(value):
106108
else:
107109
table[key] = val
108110
return table
111+
112+
@staticmethod
113+
def file_exists_filter(path):
114+
return os.path.isfile(path)

src/sonic-bgpcfgd/tests/data/monitors/peer-group.conf/param_chassis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"CONFIG_DB__DEVICE_METADATA": {
33
"localhost": {
44
"type": "SpineRouter",
5+
"chassisdb_conf_present" : "true",
56
"switch_type": "voq"
67
}
78
}

src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/voq_chassis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"bgp_asn": "55555",
55
"sub_role": "",
66
"switch_type": "voq",
7+
"chassisdb_conf_present" : "true",
78
"type": "SpineRouter"
89
}
910
},

src/sonic-config-engine/sonic-cfggen

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def load_namespace_config():
191191
if not SonicDBConfig.isInit():
192192
SonicDBConfig.initialize()
193193

194+
def file_exists_filter(path):
195+
return os.path.isfile(path)
196+
194197
class FormatConverter:
195198
"""Convert config DB based schema to legacy minigraph based schema for backward capability.
196199
We will move to DB schema and remove this class when the config templates are modified.
@@ -294,6 +297,7 @@ def _get_jinja2_env(paths):
294297
env.filters['pfx_filter'] = pfx_filter
295298
env.filters['ip_network'] = ip_network
296299
env.filters['get_primary_addr'] = get_primary_addr
300+
env.filters['file_exists'] = file_exists_filter
297301
for attr in ['ip', 'network', 'prefixlen', 'netmask', 'broadcast']:
298302
env.filters[attr] = partial(prefix_attr, attr)
299303

0 commit comments

Comments
 (0)