Changes in FRR temapltes for multi-asic (#6901)

1. Made the command next-hop-self force only applicable on back-end asic bgp. This is done so that BGPL iBGP session running on backend can send e-BGP learn nexthop. Back end asic FRR is able to recursively resolve the eBGP nexthop in its routing table since it knows about all the connected routes advertise from front end asic.

2. Made all front-end asic bgp use global loopback ip (Loopback0) as router id and back end asic bgp use Loopbacl4096 as ruter-id and originator id for Route-Reflector. This is done so that routes learnt by external peer do not see Loopback4096 as router id in show ip bgp <route-prerfix> output.

3. To handle above change need to pass Loopback4096 from BGP manager for jinja2 template generation. This was missing and this change/fix is needed for this also https://github.com/Azure/sonic-buildimage/blob/master/dockers/docker-fpm-frr/frr/bgpd/templates/dynamic/instance.conf.j2#L27

4. Enhancement to add mult_asic specific bgpd template generation unit test cases.
This commit is contained in:
abdosi 2021-02-26 17:05:15 -08:00 committed by Abhishek Dosi
parent fbc3386825
commit 9dc285ab05
23 changed files with 234 additions and 26 deletions

View File

@ -33,6 +33,7 @@ ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq {{ loop.index * 5 }} permit {{ prefi
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
route-map HIDE_INTERNAL permit 10
set community local-AS
{% set multi_asic = True %}
!
{% endif %}
!
@ -53,7 +54,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %}
!
{# set router-id #}
{% if multi_asic() %}
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% else %}
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}
@ -61,7 +62,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
!
{# advertise loopback #}
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
{% if multi_asic() %}
{% if multi_asic is defined %}
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/32 route-map HIDE_INTERNAL
{% endif %}
!
@ -70,7 +71,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/64
exit-address-family
{% endif %}
{% if multi_asic() %}
{% if multi_asic is defined %}
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") != 'None' %}
address-family ipv6
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/64 route-map HIDE_INTERNAL

View File

@ -10,6 +10,7 @@
neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V4
!
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
neighbor {{ neighbor_addr }} next-hop-self force
neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V4 in
{% endif %}
!
@ -18,6 +19,7 @@
neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V6
!
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
neighbor {{ neighbor_addr }} next-hop-self force
neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V6 in
{% endif %}
{% endif %}
@ -26,7 +28,6 @@
neighbor {{ neighbor_addr }} route-reflector-client
{% endif %}
!
neighbor {{ neighbor_addr }} next-hop-self force
!
neighbor {{ neighbor_addr }} allowas-in 1
neighbor {{ neighbor_addr }} activate

View File

@ -2,6 +2,7 @@
! template: bgpd/templates/internal/policies.conf.j2
!
!
{% from "common/functions.conf.j2" import get_ipv4_loopback_address %}
!
route-map FROM_BGP_INTERNAL_PEER_V4 permit 100
!
@ -10,6 +11,7 @@ route-map TO_BGP_INTERNAL_PEER_V4 permit 100
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
set ipv6 next-hop prefer-global
on-match next
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
!
@ -17,10 +19,10 @@ route-map TO_BGP_INTERNAL_PEER_V6 permit 100
!
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
route-map FROM_BGP_INTERNAL_PEER_V4 permit 2
set originator-id {{ loopback0_ipv4 | ip }}
set originator-id {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 2
set originator-id {{ loopback0_ipv4 | ip }}
set originator-id {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% endif %}
!
! end of template: bgpd/templates/internal/policies.conf.j2

View File

@ -191,6 +191,8 @@ class BGPPeerMgrBase(Manager):
'neighbor_addr': nbr,
'bgp_session': data,
'loopback0_ipv4': lo0_ipv4,
'CONFIG_DB__LOOPBACK_INTERFACE':{ tuple(key.split('|')) : {} for key in self.directory.get_slot("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME)
if '|' in key }
}
if self.check_neig_meta:
neigmeta = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME)
@ -384,4 +386,4 @@ class BGPPeerMgrBase(Manager):
log_crit("Can't read vrf '%s' neighbors: %s" % (vrf, str(err)))
raise Exception("Can't read vrf '%s' neighbors: %s" % (vrf, str(err)))
return peers
return peers

View File

@ -6,9 +6,9 @@
neighbor 10.10.10.10 timers 3 10
address-family ipv4
neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4
neighbor 10.10.10.10 next-hop-self force
neighbor 10.10.10.10 route-map FROM_BGP_INTERNAL_PEER_V4 in
neighbor 10.10.10.10 route-reflector-client
neighbor 10.10.10.10 next-hop-self force
neighbor 10.10.10.10 allowas-in 1
neighbor 10.10.10.10 activate
exit-address-family

View File

@ -6,9 +6,9 @@
neighbor fc::10 timers 3 10
address-family ipv6
neighbor fc::10 peer-group INTERNAL_PEER_V6
neighbor fc::10 next-hop-self force
neighbor fc::10 route-map FROM_BGP_INTERNAL_PEER_V6 in
neighbor fc::10 route-reflector-client
neighbor fc::10 next-hop-self force
neighbor fc::10 allowas-in 1
neighbor fc::10 activate
exit-address-family

View File

@ -6,7 +6,6 @@
neighbor 10.10.10.10 timers 3 10
address-family ipv4
neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4
neighbor 10.10.10.10 next-hop-self force
neighbor 10.10.10.10 allowas-in 1
neighbor 10.10.10.10 activate
exit-address-family

View File

@ -6,7 +6,6 @@
neighbor fc::10 timers 3 10
address-family ipv6
neighbor fc::10 peer-group INTERNAL_PEER_V6
neighbor fc::10 next-hop-self force
neighbor fc::10 allowas-in 1
neighbor fc::10 activate
exit-address-family

View File

@ -4,5 +4,7 @@
"sub_role": "BackEnd"
}
},
"loopback0_ipv4": "10.10.10.10/32"
}
"CONFIG_DB__LOOPBACK_INTERFACE": {
"Loopback4096|10.10.10.10/32": {}
}
}

View File

@ -7,6 +7,7 @@ route-map TO_BGP_INTERNAL_PEER_V4 permit 100
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
set ipv6 next-hop prefer-global
on-match next
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
!

View File

@ -7,6 +7,7 @@ route-map TO_BGP_INTERNAL_PEER_V4 permit 100
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
set ipv6 next-hop prefer-global
on-match next
!
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
!

View File

@ -56,10 +56,14 @@ router bgp 55555
bgp router-id 55.55.55.55
!
network 55.55.55.55/32
network 55.55.55.56/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00::1/64
exit-address-family
address-family ipv6
network fc00::2/64 route-map HIDE_INTERNAL
exit-address-family
!
address-family ipv6
network fc01::1/64

View File

@ -8,7 +8,9 @@
},
"LOOPBACK_INTERFACE": {
"Loopback0|55.55.55.55/32": {},
"Loopback0|fc00::1/128": {}
"Loopback0|fc00::1/128": {},
"Loopback4096|55.55.55.56/32": {},
"Loopback4096|fc00::2/128": {}
},
"VLAN_INTERFACE": {
"Vlan10|10.10.10.1/24": {},

View File

@ -34,10 +34,14 @@ router bgp 55555
bgp router-id 55.55.55.55
!
network 55.55.55.55/32
network 55.55.55.56/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00::1/64
exit-address-family
address-family ipv6
network fc00::2/64 route-map HIDE_INTERNAL
exit-address-family
!
network 10.10.10.1/24
address-family ipv6

View File

@ -7,7 +7,9 @@
},
"LOOPBACK_INTERFACE": {
"Loopback0|55.55.55.55/32": {},
"Loopback0|fc00::1/128": {}
"Loopback0|fc00::1/128": {},
"Loopback4096|55.55.55.56/32": {},
"Loopback4096|fc00::2/128": {}
},
"VLAN_INTERFACE": {
"Vlan10|10.10.10.1/24": {},

View File

@ -34,10 +34,14 @@ router bgp 55555
bgp router-id 55.55.55.55
!
network 55.55.55.55/32
network 55.55.55.56/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00::1/64
exit-address-family
address-family ipv6
network fc00::2/64 route-map HIDE_INTERNAL
exit-address-family
!
network 10.10.10.1/24
address-family ipv6

View File

@ -7,7 +7,9 @@
},
"LOOPBACK_INTERFACE": {
"Loopback0|55.55.55.55/32": {},
"Loopback0|fc00::1/128": {}
"Loopback0|fc00::1/128": {},
"Loopback4096|55.55.55.56/32": {},
"Loopback4096|fc00::2/128": {}
},
"VLAN_INTERFACE": {
"Vlan10|10.10.10.1/24": {},

View File

@ -3,7 +3,6 @@
! generated by templates/frr.conf.j2 with config DB data
! file: frr.conf
!
!
! template: common/daemons.common.conf.j2
!
hostname test_hostname
@ -18,7 +17,6 @@ agentx
!
! Enable nht through default route
ip nht resolve-via-default
!
! Enable link-detect (default disabled)
interface Ethernet4
link-detect
@ -54,11 +52,9 @@ ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 10.10.10.1/24
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc01::1/64
!
!
route-map HIDE_INTERNAL permit 10
set community local-AS
!
!
router bgp 55555
!
bgp log-neighbor-changes
@ -73,16 +69,19 @@ router bgp 55555
bgp router-id 55.55.55.55
!
network 55.55.55.55/32
network 55.55.55.56/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00::1/64
exit-address-family
address-family ipv6
network fc00::2/64 route-map HIDE_INTERNAL
exit-address-family
!
address-family ipv6
network fc01::1/64
exit-address-family
network 10.10.10.1/24
!
!
address-family ipv4
redistribute connected route-map HIDE_INTERNAL

View File

@ -21,7 +21,9 @@
},
"LOOPBACK_INTERFACE": {
"Loopback0|55.55.55.55/32": {},
"Loopback0|fc00::1/128": {}
"Loopback0|fc00::1/128": {},
"Loopback4096|55.55.55.56/32": {},
"Loopback4096|fc00::2/128": {}
},
"VLAN_INTERFACE": {
"Vlan10|10.10.10.1/24": {},
@ -43,4 +45,4 @@
}
}
}
}
}

View File

@ -45,7 +45,7 @@ from functools import partial
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
from portconfig import get_port_config
from sonic_py_common.device_info import get_platform, get_system_mac
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic, get_asic_device_id
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
from redis_bcc import RedisBytecodeCache
from collections import OrderedDict
@ -237,8 +237,6 @@ def _get_jinja2_env(paths):
env.filters['ip_network'] = ip_network
for attr in ['ip', 'network', 'prefixlen', 'netmask']:
env.filters[attr] = partial(prefix_attr, attr)
# Pass the is_multi_asic function as global
env.globals['multi_asic'] = is_multi_asic
return env

View File

@ -0,0 +1,77 @@
!
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf
!
!
! template: common/daemons.common.conf.j2
!
hostname multi_npu_platform_01
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
! end of template: common/daemons.common.conf.j2!
agentx
!
!
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
!
route-map HIDE_INTERNAL permit 10
set community local-AS
!
!
router bgp 65100
!
bgp log-neighbor-changes
no bgp default ipv4-unicast
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240
bgp graceful-restart
bgp graceful-restart preserve-fw-state
!
bgp router-id 8.0.0.5
!
network 10.1.0.32/32
network 8.0.0.5/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00:1::32/64
exit-address-family
address-family ipv6
network fd00:4::32/64 route-map HIDE_INTERNAL
exit-address-family
!
!
!
!
address-family ipv4
maximum-paths 64
exit-address-family
address-family ipv6
maximum-paths 64
exit-address-family
!
! end of template: bgpd/bgpd.main.conf.j2
!!
! end of template: bgpd/bgpd.conf.j2
!

View File

@ -0,0 +1,83 @@
!
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf
!
!
! template: common/daemons.common.conf.j2
!
hostname multi_npu_platform_01
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
! end of template: common/daemons.common.conf.j2!
agentx
!
!
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
!
route-map HIDE_INTERNAL permit 10
set community local-AS
!
!
router bgp 65100
!
bgp log-neighbor-changes
no bgp default ipv4-unicast
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240
bgp graceful-restart
bgp graceful-restart preserve-fw-state
!
bgp router-id 10.1.0.32
!
network 10.1.0.32/32
network 8.0.0.0/32 route-map HIDE_INTERNAL
!
address-family ipv6
network fc00:1::32/64
exit-address-family
address-family ipv6
network fd00:1::32/64 route-map HIDE_INTERNAL
exit-address-family
!
!
!
address-family ipv4
redistribute connected route-map HIDE_INTERNAL
exit-address-family
address-family ipv6
redistribute connected route-map HIDE_INTERNAL
exit-address-family
!
address-family ipv4
maximum-paths 64
exit-address-family
address-family ipv6
maximum-paths 64
exit-address-family
!
! end of template: bgpd/bgpd.main.conf.j2
!!
! end of template: bgpd/bgpd.conf.j2
!

View File

@ -1,3 +1,4 @@
import filecmp
import json
import os
import shutil
@ -26,6 +27,7 @@ class TestMultiNpuCfgGen(TestCase):
self.port_config = []
for asic in range(NUM_ASIC):
self.port_config.append(os.path.join(self.test_data_dir, "sample_port_config-{}.ini".format(asic)))
self.output_file = os.path.join(self.test_dir, 'output')
def run_script(self, argument, check_stderr=False):
print '\n Running sonic-cfggen ' + argument
@ -44,6 +46,22 @@ class TestMultiNpuCfgGen(TestCase):
def run_diff(self, file1, file2):
return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True)
def run_frr_asic_case(self, template, target, asic, port_config):
template_dir = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', "frr")
conf_template = os.path.join(template_dir, template)
constants = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'constants', 'constants.yml')
cmd_args = asic, self.sample_graph, port_config, constants, conf_template, template_dir, self.output_file
cmd = "-n %s -m %s -p %s -y %s -t %s -T %s > %s" % cmd_args
self.run_script(cmd)
original_filename = os.path.join(self.test_dir, 'sample_output', target)
r = filecmp.cmp(original_filename, self.output_file)
diff_output = self.run_diff(original_filename, self.output_file) if not r else ""
return r, "Diff:\n" + diff_output
def run_script_for_asic(self,argument,asic, port_config=None):
argument = "{} -n asic{} ".format(argument, asic)
if port_config:
@ -349,3 +367,8 @@ class TestMultiNpuCfgGen(TestCase):
}
}
)
def test_bgpd_frr_frontendasic(self):
self.assertTrue(*self.run_frr_asic_case('bgpd/bgpd.conf.j2', 'bgpd_frr_frontend_asic.conf', "asic0", self.port_config[0]))
def test_bgpd_frr_backendasic(self):
self.assertTrue(*self.run_frr_asic_case('bgpd/bgpd.conf.j2', 'bgpd_frr_backend_asic.conf', "asic3", self.port_config[3]))