Skip to content

Commit

Permalink
Update logic to configure router bgp even without underlay/overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausHolbechArista committed Aug 23, 2024
1 parent 7a0dbe9 commit 20fe937
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
35 changes: 35 additions & 0 deletions python-avd/pyavd/_eos_designs/shared_utils/filtered_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,38 @@ def get_additional_svi_config(svi_config: dict, svi: dict, vrf: dict) -> None:
ospf_keys.append({"id": ospf_key["id"], "hash_algorithm": ospf_key.get("hash_algorithm", "sha512"), "key": ospf_key["key"]})
if ospf_keys:
svi_config.update({"ospf_authentication": ospf_authentication, "ospf_message_digest_keys": ospf_keys})

def bgp_in_network_services(self: SharedUtils) -> bool:
"""
True if any VRFs are enabled for BGP.
Used to enable router_bgp even if there is no overlay or underlay routing protocol.
"""
if not self.network_services_l3:
return False

return any(self.bgp_enabled_for_vrf(vrf) for tenant in self.filtered_tenants for vrf in tenant["vrfs"])

def bgp_enabled_for_vrf(self: SharedUtils, vrf: dict) -> bool:
"""
True if the given VRF should be included under Router BGP.
- If bgp.enabled is set to True, we will always configure the VRF.
- If bgp.enabled is set to False, we will never configure the VRF.
Otherwise we will autodetect:
- If the VRF is part of an overlay we will configure BGP for it.
- If any BGP peers are configured we will configure BGP for it.
- If uplink type is p2p_vrfs and the vrf is included in uplink VRFs.
"""
if (bgp_enabled := get(vrf, "bgp.enabled")) is not None:
return bgp_enabled

vrf_address_families = [af for af in vrf.get("address_families", ["evpn"]) if af in self.overlay_address_families]
return any(
[
vrf_address_families,
vrf["bgp_peers"],
(self.uplink_type == "p2p-vrfs" and vrf["name"] in (self.get_switch_fact("uplink_switch_vrfs", required=False) or [])),
]
)
1 change: 1 addition & 0 deletions python-avd/pyavd/_eos_designs/shared_utils/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def bgp(self: SharedUtils) -> bool:
self.overlay_routing_protocol in ["ebgp", "ibgp"]
and (self.evpn_role in ["client", "server"] or self.mpls_overlay_role in ["client", "server"])
)
or self.bgp_in_network_services
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,17 @@ def _router_bgp_vrfs(self: AvdStructuredConfigNetworkServices) -> list | None:

for tenant in self.shared_utils.filtered_tenants:
for vrf in tenant["vrfs"]:
# If bgp.enabled is set to True, we will always configure the VRF.
# If bgp.enabled is set to False, we will never configure the VRF.
# Otherwise we will autodetect:
# - if the VRF is part of an overlay we will configure BGP for it.
# - if any BGP peers are configured we will configure BGP for it.
# - if uplink type is p2p_vrfs and the vrf is included in uplink VRFs.

if (bgp_enabled := get(vrf, "bgp.enabled")) is False:
if not self.shared_utils.bgp_enabled_for_vrf(vrf):
continue

vrf_address_families = [af for af in vrf.get("address_families", ["evpn"]) if af in self.shared_utils.overlay_address_families]
vrf_name = vrf["name"]
if not any(
[
bgp_enabled,
vrf_address_families,
vrf["bgp_peers"],
(
self.shared_utils.uplink_type == "p2p-vrfs"
and vrf_name in (self.shared_utils.get_switch_fact("uplink_switch_vrfs", required=False) or [])
),
]
):
continue

bgp_vrf = {
"name": vrf_name,
# Adding router_id here to avoid reordering structured config for all hosts. TODO: Remove router_id.
"router_id": None,
"eos_cli": get(vrf, "bgp.raw_eos_cli"),
"struct_cfg": get(vrf, "bgp.structured_config"),
}

if vrf_address_families:
if vrf_address_families := [af for af in vrf.get("address_families", ["evpn"]) if af in self.shared_utils.overlay_address_families]:
# For EVPN configs get evpn keys and continue after the elif block below.
self._update_router_bgp_vrf_evpn_or_mpls_cfg(bgp_vrf, vrf, vrf_address_families)

Expand Down

0 comments on commit 20fe937

Please sign in to comment.