Skip to content

Commit 3e74182

Browse files
committed
Initial Commit for Chassis in Packet mode and multi-asic.
• Internal BGP Peering between LCx-ASICy is done using Loopback4096 • Internal BGP Peer will be classified as BGP_INTERNAL_NEIGHBOR with source updated as Loopback4096 • DEVICE_METADATA will have “switch_type” define as “chassis-packet”. We already have “voq” define. This will be used in BGP template. • Static Routes are define using SONiC schema. * Fixed Vlan Sub Interface Parsing in Graph when configured on Port-Channel. * Added Unit test cases of graph and BGP template changes. Signed-off-by: Abhishek Dosi <[email protected]>
1 parent 7126f88 commit 3e74182

16 files changed

Lines changed: 743 additions & 31 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +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
{% set multi_asic = True %}
3535
{% endif %}
36-
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
36+
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
3737
route-map HIDE_INTERNAL permit 10
3838
set community no-export
3939
{% if constants.bgp.peers is defined and constants.bgp.peers.internal is defined and constants.bgp.peers.internal.community is defined %}
@@ -63,15 +63,15 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
6363
{% endif %}
6464
!
6565
{# set router-id #}
66-
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
66+
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
6767
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}
6868
{% else %}
6969
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}
7070
{% endif %}
7171
!
7272
{# advertise loopback #}
7373
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
74-
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
74+
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
7575
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/32 route-map HIDE_INTERNAL
7676
{% endif %}
7777
!
@@ -80,7 +80,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
8080
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/64
8181
exit-address-family
8282
{% endif %}
83-
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq'%}
83+
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
8484
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") != 'None' %}
8585
address-family ipv6
8686
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/128 route-map HIDE_INTERNAL
@@ -102,7 +102,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
102102
{% endblock vlan_advertisement %}
103103
!
104104
!
105-
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
105+
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
106106
address-family ipv4
107107
redistribute connected route-map HIDE_INTERNAL
108108
exit-address-family

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
!
22
! template: bgpd/templates/internal/peer-group.conf.j2
3+
{% from "common/functions.conf.j2" import get_ipv4_loopback_address %}
4+
{% from "common/functions.conf.j2" import get_ipv6_loopback_address %}
35
!
46
neighbor INTERNAL_PEER_V4 peer-group
57
neighbor INTERNAL_PEER_V6 peer-group
68
address-family ipv4
7-
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
9+
10+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
11+
neighbor INTERNAL_PEER_V4 update-source {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
12+
{% elif CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
813
neighbor INTERNAL_PEER_V4 route-reflector-client
914
{% endif %}
1015
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
@@ -13,7 +18,9 @@
1318
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
1419
exit-address-family
1520
address-family ipv6
16-
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
21+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
22+
neighbor INTERNAL_PEER_V4 update-source {{ get_ipv6_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
23+
{% elif CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
1724
neighbor INTERNAL_PEER_V6 route-reflector-client
1825
{% endif %}
1926
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound

src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def __init__(self, common_objs, db_name, table_name, peer_type, check_neig_meta)
125125
if self.check_deployment_id:
126126
deps.append(("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/deployment_id"))
127127

128+
if self.peer_type == 'internal':
129+
deps.append(("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME, "Loopback4096"))
130+
128131
super(BGPPeerMgrBase, self).__init__(
129132
common_objs,
130133
deps,
@@ -160,11 +163,17 @@ def add_peer(self, vrf, nbr, data):
160163
print_data = vrf, nbr, data
161164
bgp_asn = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["bgp_asn"]
162165
#
163-
lo0_ipv4 = self.get_lo0_ipv4()
166+
lo0_ipv4 = self.get_lo_ipv4("Loopback0|")
164167
if lo0_ipv4 is None:
165168
log_warn("Loopback0 ipv4 address is not presented yet")
166169
return False
167170
#
171+
if self.peer_type == 'internal':
172+
lo4096_ipv4 = self.get_lo_ipv4("Loopback4096|")
173+
if lo4096_ipv4 is None:
174+
log_warn("Loopback4096 ipv4 address is not presented yet")
175+
return False
176+
168177
if "local_addr" not in data:
169178
log_warn("Peer %s. Missing attribute 'local_addr'" % nbr)
170179
else:
@@ -299,15 +308,15 @@ def apply_op(self, cmd, vrf):
299308
self.cfg_mgr.push(cmd)
300309
return True
301310

302-
def get_lo0_ipv4(self):
311+
def get_lo_ipv4(self, loopback_str):
303312
"""
304313
Extract Loopback0 ipv4 address from the Directory
305314
:return: ipv4 address for Loopback0, None if nothing found
306315
"""
307316
loopback0_ipv4 = None
308317
for loopback in self.directory.get_slot("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME).keys():
309-
if loopback.startswith("Loopback0|"):
310-
loopback0_prefix_str = loopback.replace("Loopback0|", "")
318+
if loopback.startswith(loopback_str):
319+
loopback0_prefix_str = loopback.replace(loopback_str, "")
311320
loopback0_ip_str = loopback0_prefix_str[:loopback0_prefix_str.find('/')]
312321
if TemplateFabric.is_ipv4(loopback0_ip_str):
313322
loopback0_ipv4 = loopback0_ip_str

src/sonic-bgpcfgd/bgpcfgd/template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def prefix_attr(attr, value):
7575
return None
7676
else:
7777
try:
78-
prefix = netaddr.IPNetwork(str(value))
78+
prefix = netaddr.IPNetwork(str(value).strip())
7979
except (netaddr.NotRegisteredError, netaddr.AddrFormatError, netaddr.AddrConversionError):
8080
return None
8181
return str(getattr(prefix, attr))
@@ -105,4 +105,4 @@ def pfx_filter(value):
105105
log_err("'%s' is invalid ip address" % ip_address)
106106
else:
107107
table[key] = val
108-
return table
108+
return table
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"CONFIG_DB__DEVICE_METADATA": {
3+
"localhost": {
4+
"type": "SpineRouter",
5+
"sub_role": "BackEnd",
6+
"switch_type": "chassis-packet"
7+
}
8+
},
9+
"CONFIG_DB__LOOPBACK_INTERFACE": {
10+
"Loopback4096|10.10.10.10/32": {},
11+
"Loopback4096|2603:10e2:400::3/128": {}
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
!
2+
! template: bgpd/templates/internal/peer-group.conf.j2
3+
!
4+
neighbor INTERNAL_PEER_V4 peer-group
5+
neighbor INTERNAL_PEER_V6 peer-group
6+
address-family ipv4
7+
neighbor INTERNAL_PEER_V4 update-source 10.10.10.10
8+
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
9+
neighbor INTERNAL_PEER_V4 allowas-in 1
10+
neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in
11+
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
12+
exit-address-family
13+
address-family ipv6
14+
neighbor INTERNAL_PEER_V4 update-source 2603:10e2:400::3
15+
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound
16+
neighbor INTERNAL_PEER_V6 allowas-in 1
17+
neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in
18+
neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out
19+
exit-address-family
20+
!
21+
! end of template: bgpd/templates/internal/peer-group.conf.j2
22+
!
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
!
2+
! template: bgpd/bgpd.main.conf.j2
3+
!
4+
! bgp multiple-instance
5+
!
6+
! BGP configuration
7+
!
8+
! TSA configuration
9+
!
10+
ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32
11+
!
12+
ipv6 prefix-list PL_LoopbackV6 permit fc00::/64
13+
!
14+
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24
15+
!
16+
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64
17+
!
18+
route-map HIDE_INTERNAL permit 10
19+
set community no-export
20+
!
21+
!
22+
router bgp 55555
23+
!
24+
bgp log-neighbor-changes
25+
no bgp default ipv4-unicast
26+
no bgp ebgp-requires-policy
27+
!
28+
bgp bestpath as-path multipath-relax
29+
!
30+
bgp graceful-restart restart-time 240
31+
bgp graceful-restart
32+
bgp graceful-restart preserve-fw-state
33+
bgp graceful-restart select-defer-time 45
34+
!
35+
bgp router-id 55.55.55.56
36+
!
37+
network 55.55.55.55/32
38+
network 55.55.55.56/32 route-map HIDE_INTERNAL
39+
!
40+
address-family ipv6
41+
network fc00::1/64
42+
exit-address-family
43+
address-family ipv6
44+
network fc00::2/128 route-map HIDE_INTERNAL
45+
exit-address-family
46+
!
47+
network 10.10.10.1/24
48+
address-family ipv6
49+
network fc01::1/64
50+
exit-address-family
51+
!
52+
address-family ipv4
53+
redistribute connected route-map HIDE_INTERNAL
54+
exit-address-family
55+
address-family ipv6
56+
redistribute connected route-map HIDE_INTERNAL
57+
exit-address-family
58+
!
59+
address-family ipv4
60+
maximum-paths 64
61+
exit-address-family
62+
address-family ipv6
63+
maximum-paths 64
64+
exit-address-family
65+
!
66+
! end of template: bgpd/bgpd.main.conf.j2
67+
!
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"DEVICE_METADATA": {
3+
"localhost": {
4+
"bgp_asn": "55555",
5+
"sub_role": "FrontEnd",
6+
"switch_type": "chassis-packet"
7+
}
8+
},
9+
"LOOPBACK_INTERFACE": {
10+
"Loopback0|55.55.55.55/32": {},
11+
"Loopback0|fc00::1/128": {},
12+
"Loopback4096|55.55.55.56/32": {},
13+
"Loopback4096|fc00::2/128": {}
14+
},
15+
"VLAN_INTERFACE": {
16+
"Vlan10|10.10.10.1/24": {},
17+
"Vlan10|fc01::1/64": {},
18+
"Vlan20": {"vnet_name": "Vnet1"},
19+
"Vlan20|20.20.20.1/24": {},
20+
"Vlan20|fd01::1/64": {}
21+
},
22+
"constants": {
23+
"bgp": {
24+
"multipath_relax": {
25+
"enabled": true
26+
},
27+
"graceful_restart": {
28+
"enabled": true
29+
},
30+
"maximum_paths": {
31+
"enabled": true
32+
}
33+
}
34+
}
35+
}

src/sonic-bgpcfgd/tests/test_sonic-cfggen.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def test_bgpd_main_conf_voq_chassis():
5151
"bgpd.main.conf.j2/voq_chassis.json",
5252
"bgpd.main.conf.j2/voq_chassis.conf")
5353

54+
def test_bgpd_main_conf_packet_chassis():
55+
run_test("Chassi packet bgpd.main.conf.j2",
56+
"bgpd/bgpd.main.conf.j2",
57+
"bgpd.main.conf.j2/packet_chassis.json",
58+
"bgpd.main.conf.j2/packet_chassis.conf")
59+
5460
def test_tsa_isolate():
5561
run_test("tsa/bgpd.tsa.isolate.conf.j2",
5662
"bgpd/tsa/bgpd.tsa.isolate.conf.j2",

0 commit comments

Comments
 (0)