Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chassis-packet] minigraph parsing and BGP template changes #8966

Merged
merged 12 commits into from
Oct 19, 2021
10 changes: 5 additions & 5 deletions dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +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' %}
{% set multi_asic = True %}
{% endif %}
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
route-map HIDE_INTERNAL permit 10
set community no-export
{% if constants.bgp.peers is defined and constants.bgp.peers.internal is defined and constants.bgp.peers.internal.community is defined %}
Expand Down Expand Up @@ -63,15 +63,15 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %}
!
{# set router-id #}
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% else %}
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}
{% endif %}
!
{# advertise loopback #}
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/32 route-map HIDE_INTERNAL
{% endif %}
!
Expand All @@ -80,7 +80,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 is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq'%}
{% if multi_asic is defined or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") != 'None' %}
address-family ipv6
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback4096") | ip }}/128 route-map HIDE_INTERNAL
Expand All @@ -102,7 +102,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endblock vlan_advertisement %}
!
!
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' %}
{% if DEVICE_METADATA['localhost']['sub_role'] == 'FrontEnd' or DEVICE_METADATA['localhost']['switch_type'] == 'voq' or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
address-family ipv4
redistribute connected route-map HIDE_INTERNAL
exit-address-family
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
!
! template: bgpd/templates/internal/peer-group.conf.j2
{% from "common/functions.conf.j2" import get_ipv4_loopback_address %}
{% from "common/functions.conf.j2" import get_ipv6_loopback_address %}
!
neighbor INTERNAL_PEER_V4 peer-group
neighbor INTERNAL_PEER_V6 peer-group
address-family ipv4
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}

{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
neighbor INTERNAL_PEER_V4 update-source {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% elif CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
neighbor INTERNAL_PEER_V4 route-reflector-client
{% endif %}
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
Expand All @@ -13,7 +18,9 @@
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
exit-address-family
address-family ipv6
{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
{% if CONFIG_DB__DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
neighbor INTERNAL_PEER_V4 update-source {{ get_ipv6_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback4096") | ip }}
{% elif CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %}
neighbor INTERNAL_PEER_V6 route-reflector-client
{% endif %}
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound
Expand Down
17 changes: 13 additions & 4 deletions src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def __init__(self, common_objs, db_name, table_name, peer_type, check_neig_meta)
if self.check_deployment_id:
deps.append(("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/deployment_id"))

if self.peer_type == 'internal':
deps.append(("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME, "Loopback4096"))

super(BGPPeerMgrBase, self).__init__(
common_objs,
deps,
Expand Down Expand Up @@ -160,11 +163,17 @@ def add_peer(self, vrf, nbr, data):
print_data = vrf, nbr, data
bgp_asn = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["bgp_asn"]
#
lo0_ipv4 = self.get_lo0_ipv4()
lo0_ipv4 = self.get_lo_ipv4("Loopback0|")
if lo0_ipv4 is None:
log_warn("Loopback0 ipv4 address is not presented yet")
return False
#
if self.peer_type == 'internal':
lo4096_ipv4 = self.get_lo_ipv4("Loopback4096|")
if lo4096_ipv4 is None:
log_warn("Loopback4096 ipv4 address is not presented yet")
return False

if "local_addr" not in data:
log_warn("Peer %s. Missing attribute 'local_addr'" % nbr)
else:
Expand Down Expand Up @@ -299,15 +308,15 @@ def apply_op(self, cmd, vrf):
self.cfg_mgr.push(cmd)
return True

def get_lo0_ipv4(self):
def get_lo_ipv4(self, loopback_str):
"""
Extract Loopback0 ipv4 address from the Directory
:return: ipv4 address for Loopback0, None if nothing found
"""
loopback0_ipv4 = None
for loopback in self.directory.get_slot("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME).keys():
if loopback.startswith("Loopback0|"):
loopback0_prefix_str = loopback.replace("Loopback0|", "")
if loopback.startswith(loopback_str):
loopback0_prefix_str = loopback.replace(loopback_str, "")
loopback0_ip_str = loopback0_prefix_str[:loopback0_prefix_str.find('/')]
if TemplateFabric.is_ipv4(loopback0_ip_str):
loopback0_ipv4 = loopback0_ip_str
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-bgpcfgd/bgpcfgd/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def prefix_attr(attr, value):
return None
else:
try:
prefix = netaddr.IPNetwork(str(value))
prefix = netaddr.IPNetwork(str(value).strip())
except (netaddr.NotRegisteredError, netaddr.AddrFormatError, netaddr.AddrConversionError):
return None
return str(getattr(prefix, attr))
Expand Down Expand Up @@ -105,4 +105,4 @@ def pfx_filter(value):
log_err("'%s' is invalid ip address" % ip_address)
else:
table[key] = val
return table
return table
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"CONFIG_DB__DEVICE_METADATA": {
"localhost": {
"type": "SpineRouter",
"sub_role": "BackEnd",
"switch_type": "chassis-packet"
}
},
"CONFIG_DB__LOOPBACK_INTERFACE": {
"Loopback4096|10.10.10.10/32": {},
"Loopback4096|2603:10e2:400::3/128": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
!
! template: bgpd/templates/internal/peer-group.conf.j2
!
neighbor INTERNAL_PEER_V4 peer-group
neighbor INTERNAL_PEER_V6 peer-group
address-family ipv4
neighbor INTERNAL_PEER_V4 update-source 10.10.10.10
neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V4 allowas-in 1
neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in
neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out
exit-address-family
address-family ipv6
neighbor INTERNAL_PEER_V4 update-source 2603:10e2:400::3
neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound
neighbor INTERNAL_PEER_V6 allowas-in 1
neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in
neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out
exit-address-family
!
! end of template: bgpd/templates/internal/peer-group.conf.j2
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64
!
route-map HIDE_INTERNAL permit 10
set community no-export
!
!
router bgp 55555
!
bgp log-neighbor-changes
no bgp default ipv4-unicast
no bgp ebgp-requires-policy
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240
bgp graceful-restart
bgp graceful-restart preserve-fw-state
bgp graceful-restart select-defer-time 45
!
bgp router-id 55.55.55.56
!
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/128 route-map HIDE_INTERNAL
exit-address-family
!
network 10.10.10.1/24
address-family ipv6
network fc01::1/64
Comment on lines +48 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are present in lines 40 and 41, seems repeated here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working on another PR.. will fix it there.

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
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"DEVICE_METADATA": {
"localhost": {
"bgp_asn": "55555",
"sub_role": "FrontEnd",
"switch_type": "chassis-packet"
}
},
"LOOPBACK_INTERFACE": {
"Loopback0|55.55.55.55/32": {},
"Loopback0|fc00::1/128": {},
"Loopback4096|55.55.55.56/32": {},
"Loopback4096|fc00::2/128": {}
},
"VLAN_INTERFACE": {
"Vlan10|10.10.10.1/24": {},
"Vlan10|fc01::1/64": {},
"Vlan20": {"vnet_name": "Vnet1"},
"Vlan20|20.20.20.1/24": {},
"Vlan20|fd01::1/64": {}
},
"constants": {
"bgp": {
"multipath_relax": {
"enabled": true
},
"graceful_restart": {
"enabled": true
},
"maximum_paths": {
"enabled": true
}
}
}
}
6 changes: 6 additions & 0 deletions src/sonic-bgpcfgd/tests/test_sonic-cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def test_bgpd_main_conf_voq_chassis():
"bgpd.main.conf.j2/voq_chassis.json",
"bgpd.main.conf.j2/voq_chassis.conf")

def test_bgpd_main_conf_packet_chassis():
run_test("Chassi packet bgpd.main.conf.j2",
"bgpd/bgpd.main.conf.j2",
"bgpd.main.conf.j2/packet_chassis.json",
"bgpd.main.conf.j2/packet_chassis.conf")

def test_tsa_isolate():
run_test("tsa/bgpd.tsa.isolate.conf.j2",
"bgpd/tsa/bgpd.tsa.isolate.conf.j2",
Expand Down
Loading