Skip to content

Commit dbded1f

Browse files
abdosiqiluo-msft
authored andcommitted
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.
1 parent 8f6b345 commit dbded1f

File tree

25 files changed

+399
-26
lines changed

25 files changed

+399
-26
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq {{ loop.index * 5 }} permit {{ prefi
3333
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
3434
route-map HIDE_INTERNAL permit 10
3535
set community local-AS
36+
{% set multi_asic = True %}
3637
!
3738
{% endif %}
3839
!
@@ -54,15 +55,15 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
5455
{% endif %}
5556
!
5657
{# set router-id #}
57-
{% if multi_asic() %}
58+
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
5859
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}
5960
{% else %}
6061
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}
6162
{% endif %}
6263
!
6364
{# advertise loopback #}
6465
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
65-
{% if multi_asic() %}
66+
{% if multi_asic is defined %}
6667
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/32 route-map HIDE_INTERNAL
6768
{% endif %}
6869
!
@@ -71,7 +72,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
7172
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/64
7273
exit-address-family
7374
{% endif %}
74-
{% if multi_asic() %}
75+
{% if multi_asic is defined %}
7576
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") != 'None' %}
7677
address-family ipv6
7778
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/64 route-map HIDE_INTERNAL

dockers/docker-fpm-frr/frr/bgpd/templates/internal/instance.conf.j2

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V4
1212
!
1313
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
14+
neighbor {{ neighbor_addr }} next-hop-self force
1415
neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V4 in
1516
{% endif %}
1617
!
@@ -19,6 +20,7 @@
1920
neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V6
2021
!
2122
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
23+
neighbor {{ neighbor_addr }} next-hop-self force
2224
neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V6 in
2325
{% endif %}
2426
{% endif %}
@@ -27,7 +29,6 @@
2729
neighbor {{ neighbor_addr }} route-reflector-client
2830
{% endif %}
2931
!
30-
neighbor {{ neighbor_addr }} next-hop-self force
3132
!
3233
neighbor {{ neighbor_addr }} activate
3334
exit-address-family

dockers/docker-fpm-frr/frr/bgpd/templates/internal/policies.conf.j2

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@
22
! template: bgpd/templates/internal/policies.conf.j2
33
!
44
!
5+
{% from "common/functions.conf.j2" import get_ipv4_loopback_address %}
56
!
67
route-map FROM_BGP_INTERNAL_PEER_V4 permit 100
78
!
89
route-map TO_BGP_INTERNAL_PEER_V4 permit 100
910
!
1011
!
1112
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
12-
on-match next
1313
set ipv6 next-hop prefer-global
14+
on-match next
1415
!
1516
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
1617
!
1718
route-map TO_BGP_INTERNAL_PEER_V6 permit 100
1819
!
1920
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
2021
route-map FROM_BGP_INTERNAL_PEER_V4 permit 2
21-
set originator-id {{ loopback0_ipv4 | ip }}
22+
set originator-id {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
2223
!
2324
route-map FROM_BGP_INTERNAL_PEER_V6 permit 2
24-
set originator-id {{ loopback0_ipv4 | ip }}
25+
set originator-id {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
2526
{% endif %}
2627
!
2728
! end of template: bgpd/templates/internal/policies.conf.j2

src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def add_peer(self, vrf, nbr, data):
191191
'neighbor_addr': nbr,
192192
'bgp_session': data,
193193
'loopback0_ipv4': lo0_ipv4,
194+
'CONFIG_DB__LOOPBACK_INTERFACE':{ tuple(key.split('|')) : {} for key in self.directory.get_slot("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME)
195+
if '|' in key }
194196
}
195197
if self.check_neig_meta:
196198
neigmeta = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME)
@@ -384,4 +386,4 @@ def load_peers():
384386
log_crit("Can't read vrf '%s' neighbors: %s" % (vrf, str(err)))
385387
raise Exception("Can't read vrf '%s' neighbors: %s" % (vrf, str(err)))
386388

387-
return peers
389+
return peers

src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v4.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
neighbor 10.10.10.10 timers connect 10
88
address-family ipv4
99
neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4
10+
neighbor 10.10.10.10 next-hop-self force
1011
neighbor 10.10.10.10 route-map FROM_BGP_INTERNAL_PEER_V4 in
1112
neighbor 10.10.10.10 route-reflector-client
12-
neighbor 10.10.10.10 next-hop-self force
1313
neighbor 10.10.10.10 activate
1414
exit-address-family
1515
!

src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v6.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
neighbor fc::10 timers connect 10
88
address-family ipv6
99
neighbor fc::10 peer-group INTERNAL_PEER_V6
10+
neighbor fc::10 next-hop-self force
1011
neighbor fc::10 route-map FROM_BGP_INTERNAL_PEER_V6 in
1112
neighbor fc::10 route-reflector-client
12-
neighbor fc::10 next-hop-self force
1313
neighbor fc::10 activate
1414
exit-address-family
1515
!

src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v4.conf

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
neighbor 10.10.10.10 timers connect 10
88
address-family ipv4
99
neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4
10-
neighbor 10.10.10.10 next-hop-self force
1110
neighbor 10.10.10.10 activate
1211
exit-address-family
1312
!

src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v6.conf

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
neighbor fc::10 timers connect 10
88
address-family ipv6
99
neighbor fc::10 peer-group INTERNAL_PEER_V6
10-
neighbor fc::10 next-hop-self force
1110
neighbor fc::10 activate
1211
exit-address-family
1312
!

src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_back.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"sub_role": "BackEnd"
55
}
66
},
7-
"loopback0_ipv4": "10.10.10.10/32"
8-
}
7+
"CONFIG_DB__LOOPBACK_INTERFACE": {
8+
"Loopback4096|10.10.10.10/32": {}
9+
}
10+
}

src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_back.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ route-map FROM_BGP_INTERNAL_PEER_V4 permit 100
66
route-map TO_BGP_INTERNAL_PEER_V4 permit 100
77
!
88
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
9-
on-match next
109
set ipv6 next-hop prefer-global
10+
on-match next
1111
!
1212
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
1313
!

src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_front.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ route-map FROM_BGP_INTERNAL_PEER_V4 permit 100
66
route-map TO_BGP_INTERNAL_PEER_V4 permit 100
77
!
88
route-map FROM_BGP_INTERNAL_PEER_V6 permit 1
9-
on-match next
109
set ipv6 next-hop prefer-global
10+
on-match next
1111
!
1212
route-map FROM_BGP_INTERNAL_PEER_V6 permit 100
1313
!

src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.conf.j2/all.conf

+4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ router bgp 55555
5151
bgp router-id 55.55.55.55
5252
!
5353
network 55.55.55.55/32
54+
network 55.55.55.56/32 route-map HIDE_INTERNAL
5455
!
5556
address-family ipv6
5657
network fc00::1/64
5758
exit-address-family
59+
address-family ipv6
60+
network fc00::2/64 route-map HIDE_INTERNAL
61+
exit-address-family
5862
!
5963
network 10.10.10.1/24
6064
address-family ipv6

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
},
99
"LOOPBACK_INTERFACE": {
1010
"Loopback0|55.55.55.55/32": {},
11-
"Loopback0|fc00::1/128": {}
11+
"Loopback0|fc00::1/128": {},
12+
"Loopback4096|55.55.55.56/32": {},
13+
"Loopback4096|fc00::2/128": {}
1214
},
1315
"VLAN_INTERFACE": {
1416
"Vlan10|10.10.10.1/24": {},

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

+4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ router bgp 55555
3333
bgp router-id 55.55.55.55
3434
!
3535
network 55.55.55.55/32
36+
network 55.55.55.56/32 route-map HIDE_INTERNAL
3637
!
3738
address-family ipv6
3839
network fc00::1/64
3940
exit-address-family
41+
address-family ipv6
42+
network fc00::2/64 route-map HIDE_INTERNAL
43+
exit-address-family
4044
!
4145
network 10.10.10.1/24
4246
address-family ipv6

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
},
88
"LOOPBACK_INTERFACE": {
99
"Loopback0|55.55.55.55/32": {},
10-
"Loopback0|fc00::1/128": {}
10+
"Loopback0|fc00::1/128": {},
11+
"Loopback4096|55.55.55.56/32": {},
12+
"Loopback4096|fc00::2/128": {}
1113
},
1214
"VLAN_INTERFACE": {
1315
"Vlan10|10.10.10.1/24": {},

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

+4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ router bgp 55555
3333
bgp router-id 55.55.55.55
3434
!
3535
network 55.55.55.55/32
36+
network 55.55.55.56/32 route-map HIDE_INTERNAL
3637
!
3738
address-family ipv6
3839
network fc00::1/64
3940
exit-address-family
41+
address-family ipv6
42+
network fc00::2/64 route-map HIDE_INTERNAL
43+
exit-address-family
4044
!
4145
network 10.10.10.1/24
4246
address-family ipv6

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
},
88
"LOOPBACK_INTERFACE": {
99
"Loopback0|55.55.55.55/32": {},
10-
"Loopback0|fc00::1/128": {}
10+
"Loopback0|fc00::1/128": {},
11+
"Loopback4096|55.55.55.56/32": {},
12+
"Loopback4096|fc00::2/128": {}
1113
},
1214
"VLAN_INTERFACE": {
1315
"Vlan10|10.10.10.1/24": {},

src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ link-detect
3636
ip route 0.0.0.0/0 10.10.10.1 200
3737
!!
3838
!
39-
!
4039
! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix
4140
ipv6 route fc00::/64 Loopback0
42-
!
4341
!!
42+
!
4443
! template: bgpd/bgpd.main.conf.j2
4544
!
4645
! bgp multiple-instance
@@ -75,10 +74,14 @@ router bgp 55555
7574
bgp router-id 55.55.55.55
7675
!
7776
network 55.55.55.55/32
77+
network 55.55.55.56/32 route-map HIDE_INTERNAL
7878
!
7979
address-family ipv6
8080
network fc00::1/64
8181
exit-address-family
82+
address-family ipv6
83+
network fc00::2/64 route-map HIDE_INTERNAL
84+
exit-address-family
8285
!
8386
network 10.10.10.1/24
8487
address-family ipv6

src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
},
2222
"LOOPBACK_INTERFACE": {
2323
"Loopback0|55.55.55.55/32": {},
24-
"Loopback0|fc00::1/128": {}
24+
"Loopback0|fc00::1/128": {},
25+
"Loopback4096|55.55.55.56/32": {},
26+
"Loopback4096|fc00::2/128": {}
2527
},
2628
"VLAN_INTERFACE": {
2729
"Vlan10|10.10.10.1/24": {},
@@ -43,4 +45,4 @@
4345
}
4446
}
4547
}
46-
}
48+
}

src/sonic-config-engine/sonic-cfggen

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ from functools import partial
4141
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
4242
from portconfig import get_port_config, get_breakout_mode
4343
from redis_bcc import RedisBytecodeCache
44-
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic
44+
from sonic_py_common.multi_asic import get_asic_id_from_name
4545
from sonic_py_common import device_info
4646
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
4747

@@ -251,8 +251,6 @@ def _get_jinja2_env(paths):
251251
env.filters['ip_network'] = ip_network
252252
for attr in ['ip', 'network', 'prefixlen', 'netmask', 'broadcast']:
253253
env.filters[attr] = partial(prefix_attr, attr)
254-
# Pass the is_multi_asic function as global
255-
env.globals['multi_asic'] = is_multi_asic
256254

257255
return env
258256

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
!
2+
! template: bgpd/bgpd.conf.j2
3+
!
4+
!
5+
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
6+
! generated by templates/quagga/bgpd.conf.j2 with config DB data
7+
! file: bgpd.conf
8+
!
9+
!
10+
! template: common/daemons.common.conf.j2
11+
!
12+
hostname multi_npu_platform_01
13+
password zebra
14+
enable password zebra
15+
!
16+
log syslog informational
17+
log facility local4
18+
!
19+
! end of template: common/daemons.common.conf.j2!
20+
agentx
21+
!
22+
!
23+
!
24+
! template: bgpd/bgpd.main.conf.j2
25+
!
26+
! bgp multiple-instance
27+
!
28+
! BGP configuration
29+
!
30+
! TSA configuration
31+
!
32+
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
33+
!
34+
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
35+
!
36+
!
37+
route-map HIDE_INTERNAL permit 10
38+
set community local-AS
39+
!
40+
!
41+
router bgp 65100
42+
!
43+
bgp log-neighbor-changes
44+
no bgp default ipv4-unicast
45+
no bgp ebgp-requires-policy
46+
!
47+
bgp bestpath as-path multipath-relax
48+
!
49+
bgp graceful-restart restart-time 240
50+
bgp graceful-restart
51+
bgp graceful-restart preserve-fw-state
52+
!
53+
bgp router-id 8.0.0.5
54+
!
55+
network 10.1.0.32/32
56+
network 8.0.0.5/32 route-map HIDE_INTERNAL
57+
!
58+
address-family ipv6
59+
network fc00:1::32/64
60+
exit-address-family
61+
address-family ipv6
62+
network fd00:4::32/64 route-map HIDE_INTERNAL
63+
exit-address-family
64+
!
65+
!
66+
!
67+
!
68+
address-family ipv4
69+
maximum-paths 64
70+
exit-address-family
71+
address-family ipv6
72+
maximum-paths 64
73+
exit-address-family
74+
!
75+
! end of template: bgpd/bgpd.main.conf.j2
76+
!!
77+
! end of template: bgpd/bgpd.conf.j2
78+
!

0 commit comments

Comments
 (0)