Skip to content

Commit df7d663

Browse files
Vibhu-gslabgmulocpre-commit-ci[bot]MaheshGSLABClausHolbechArista
authored
Refactor(eos_designs): Refactoring MLAG peer group (#6723)
Co-authored-by: Guillaume Mulocher <gmulocher@arista.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Mahesh Kumar <122076792+MaheshGSLAB@users.noreply.github.com> Co-authored-by: Claus Holbech <holbech@arista.com>
1 parent df7d044 commit df7d663

12 files changed

Lines changed: 112 additions & 140 deletions

File tree

ansible_collections/arista/avd/extensions/molecule/eos_designs_unit_tests/intended/configs/bgp-peer-groups-1.cfg

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ router bgp 65001
116116
neighbor MLAG-IPv4-UNDERLAY-PEER route-map RM-MLAG-PEER-IN in
117117
neighbor MLAG-IPv4-UNDERLAY-PEER send-community
118118
neighbor MLAG-IPv4-UNDERLAY-PEER maximum-routes 12002
119-
neighbor MLAG-IPv4-VRFS-PEER peer group
120-
neighbor MLAG-IPv4-VRFS-PEER remote-as 65001
121-
neighbor MLAG-IPv4-VRFS-PEER next-hop-self
122-
neighbor MLAG-IPv4-VRFS-PEER description Description for mlag_ipv4_vrfs_peer via structured_config
123-
neighbor MLAG-IPv4-VRFS-PEER route-map RM-MLAG-PEER-IN in
124-
neighbor MLAG-IPv4-VRFS-PEER send-community
125-
neighbor MLAG-IPv4-VRFS-PEER maximum-routes 12003
126119
neighbor 192.168.252.204 peer group IPv4-UNDERLAY-PEERS
127120
neighbor 192.168.252.204 remote-as 65001
128121
neighbor 192.168.252.204 description bgp-peer-groups-3_Ethernet1
@@ -140,6 +133,5 @@ router bgp 65001
140133
address-family ipv4
141134
neighbor IPv4-UNDERLAY-PEERS activate
142135
neighbor MLAG-IPv4-UNDERLAY-PEER activate
143-
neighbor MLAG-IPv4-VRFS-PEER activate
144136
!
145137
end

ansible_collections/arista/avd/extensions/molecule/eos_designs_unit_tests/intended/structured_configs/bgp-peer-groups-1.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ router_bgp:
118118
send_community: all
119119
maximum_routes: 12002
120120
route_map_in: RM-MLAG-PEER-IN
121-
- name: MLAG-IPv4-VRFS-PEER
122-
metadata:
123-
type: ipv4
124-
remote_as: '65001'
125-
description: Description for mlag_ipv4_vrfs_peer via structured_config
126-
next_hop_self: true
127-
send_community: all
128-
maximum_routes: 12003
129-
route_map_in: RM-MLAG-PEER-IN
130121
- name: IPv4-UNDERLAY-PEERS
131122
metadata:
132123
type: ipv4
@@ -175,8 +166,6 @@ router_bgp:
175166
peer_groups:
176167
- name: MLAG-IPv4-UNDERLAY-PEER
177168
activate: true
178-
- name: MLAG-IPv4-VRFS-PEER
179-
activate: true
180169
- name: IPv4-UNDERLAY-PEERS
181170
activate: true
182171
service_routing_protocols_model: multi-agent
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
avd_design_future:
2+
remove_redundant_ipv4_unicast_for_peer_groups: true
3+
only_configure_mlag_vrfs_peer_group_when_used: true

ansible_collections/arista/avd/roles/eos_designs/docs/tables/avd-design-future.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-avd/pyavd/_eos_designs/schema/__init__.py

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-avd/pyavd/_eos_designs/schema/schema_fragments/avd_design_future.schema.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ keys:
2626
description: |-
2727
Raise an error if an L3 Port-Channel is configured without any member interfaces.
2828
default: false
29+
only_configure_mlag_vrfs_peer_group_when_used:
30+
type: bool
31+
description: |-
32+
Configure the `mlag_ipv4_vrfs_peer` BGP peer group only when needed.
33+
default: false

python-avd/pyavd/_eos_designs/shared_utils/mlag.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
from re import findall
88
from typing import TYPE_CHECKING, Protocol, cast
99

10-
from pyavd._eos_cli_config_gen.schema import EosCliConfigGen
1110
from pyavd._errors import AristaAvdInvalidInputsError, AristaAvdMissingVariableError
1211
from pyavd._utils import default, get_ip_from_ip_prefix
13-
from pyavd._utils.format_string import AvdStringFormatter
1412
from pyavd.j2filters import natural_sort, range_expand
1513

1614
if TYPE_CHECKING:
1715
from typing import Literal
1816

1917
from pyavd._eos_designs.eos_designs_facts.schema.protocol import EosDesignsFactsProtocol
20-
from pyavd._eos_designs.schema import EosDesigns
21-
from pyavd._eos_designs.structured_config.structured_config_generator import StructCfgs
2218

2319
from . import SharedUtilsProtocol
2420

@@ -235,69 +231,6 @@ def mlag_vrfs_peer_group_name(self: SharedUtilsProtocol) -> str:
235231
return self.inputs.bgp_peer_groups.mlag_ipv4_vrfs_peer.name
236232
return self.inputs.bgp_peer_groups.mlag_ipv4_underlay_peer.name
237233

238-
def update_router_bgp_with_mlag_peer_group(self: SharedUtilsProtocol, router_bgp: EosCliConfigGen.RouterBgp, custom_structured_configs: StructCfgs) -> None:
239-
"""
240-
Update router_bgp structured_config covering the MLAG peer_group(s) and associated address_family activations.
241-
242-
Inserts custom structured configuration into the given custom_structured_configs instance.
243-
244-
This is called from MLAG in the case of BGP underlay routing protocol.
245-
In the case of another underlay routing protocol, it may be called from network_services instead in case there are VRFs with iBGP peerings.
246-
"""
247-
# Only create the underlay peer group if the underlay is BGP or if we reuse the same peer-group from network services.
248-
if self.underlay_bgp or not self.use_separate_peer_group_for_mlag_vrfs:
249-
bgp_peer_group = self.inputs.bgp_peer_groups.mlag_ipv4_underlay_peer
250-
router_bgp.peer_groups.append(self.get_mlag_peer_group(bgp_peer_group, custom_structured_configs))
251-
if not self.underlay_ipv6_numbered:
252-
router_bgp.address_family_ipv4.peer_groups.append(self.get_mlag_peer_group_address_familiy_ipv4(bgp_peer_group, self.inputs.underlay_rfc5549))
253-
if self.underlay_ipv6:
254-
router_bgp.address_family_ipv6.peer_groups.append_new(name=bgp_peer_group.name, activate=True)
255-
256-
if self.use_separate_peer_group_for_mlag_vrfs:
257-
bgp_peer_group = self.inputs.bgp_peer_groups.mlag_ipv4_vrfs_peer
258-
router_bgp.peer_groups.append(self.get_mlag_peer_group(bgp_peer_group, custom_structured_configs))
259-
router_bgp.address_family_ipv4.peer_groups.append(self.get_mlag_peer_group_address_familiy_ipv4(bgp_peer_group, self.inputs.overlay_mlag_rfc5549))
260-
261-
def get_mlag_peer_group(
262-
self: SharedUtilsProtocol,
263-
bgp_peer_group: EosDesigns.BgpPeerGroups.MlagIpv4UnderlayPeer | EosDesigns.BgpPeerGroups.MlagIpv4VrfsPeer,
264-
custom_structured_configs: StructCfgs,
265-
) -> EosCliConfigGen.RouterBgp.PeerGroupsItem:
266-
"""Return structured_config for one MLAG peer_group."""
267-
peer_group_name = bgp_peer_group.name
268-
peer_group = EosCliConfigGen.RouterBgp.PeerGroupsItem(
269-
name=peer_group_name,
270-
remote_as=self.formatted_bgp_as,
271-
next_hop_self=True,
272-
description=AvdStringFormatter().format(self.inputs.mlag_bgp_peer_group_description, mlag_peer=self.mlag_peer),
273-
password=self.get_bgp_password(bgp_peer_group),
274-
bfd=bgp_peer_group.bfd or None,
275-
maximum_routes=bgp_peer_group.maximum_routes,
276-
send_community="all",
277-
)
278-
peer_group.metadata.type = "ipv4"
279-
280-
if bgp_peer_group.structured_config:
281-
custom_structured_configs.nested.router_bgp.peer_groups.obtain(peer_group_name)._deepmerge(
282-
bgp_peer_group.structured_config, list_merge=custom_structured_configs.list_merge_strategy
283-
)
284-
285-
if self.node_config.mlag_ibgp_origin_incomplete:
286-
peer_group.route_map_in = "RM-MLAG-PEER-IN"
287-
288-
return peer_group
289-
290-
def get_mlag_peer_group_address_familiy_ipv4(
291-
self: SharedUtilsProtocol,
292-
bgp_peer_group: EosDesigns.BgpPeerGroups.MlagIpv4UnderlayPeer | EosDesigns.BgpPeerGroups.MlagIpv4VrfsPeer,
293-
rfc5549: bool,
294-
) -> EosCliConfigGen.RouterBgp.AddressFamilyIpv4.PeerGroupsItem:
295-
"""Return structured_config for activation of one MLAG peer_group under address-family IPv4."""
296-
address_family_peer_group = EosCliConfigGen.RouterBgp.AddressFamilyIpv4.PeerGroupsItem(name=bgp_peer_group.name, activate=True)
297-
if rfc5549:
298-
address_family_peer_group.next_hop.address_family_ipv6._update(enabled=True, originate=True)
299-
return address_family_peer_group
300-
301234
@cached_property
302235
def underlay_multicast_pim_mlag_enabled(self: SharedUtilsProtocol) -> bool:
303236
"""

python-avd/pyavd/_eos_designs/structured_config/mlag/__init__.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,6 @@ def mlag_configuration(self) -> None:
250250
mlag_configuration.dual_primary_detection_delay = 5
251251
self.structured_config.mlag_configuration = mlag_configuration
252252

253-
@structured_config_contributor
254-
def route_maps(self) -> None:
255-
"""
256-
Set list of route-maps.
257-
258-
Origin Incomplete for MLAG iBGP learned routes.
259-
260-
TODO: Partially duplicated in network_services. Should be moved to a common class
261-
"""
262-
if not (self.shared_utils.mlag_l3 and self.shared_utils.node_config.mlag_ibgp_origin_incomplete and self.shared_utils.underlay_bgp):
263-
return
264-
265-
route_map = EosCliConfigGen.RouteMapsItem(name="RM-MLAG-PEER-IN")
266-
route_map.sequence_numbers.append_new(
267-
sequence=10,
268-
type="permit",
269-
description="Make routes learned over MLAG Peer-link less preferred on spines to ensure optimal routing",
270-
set=EosCliConfigGen.RouteMapsItem.SequenceNumbersItem.Set(["origin incomplete"]),
271-
)
272-
self.structured_config.route_maps.append(route_map)
273-
274253
@structured_config_contributor
275254
def router_bgp(self) -> None:
276255
"""
@@ -283,7 +262,9 @@ def router_bgp(self) -> None:
283262
return
284263

285264
# MLAG Peer group
286-
self.shared_utils.update_router_bgp_with_mlag_peer_group(self.structured_config.router_bgp, self.custom_structured_configs)
265+
self.structured_config_utils.set_once_peer_group_mlag_ipv4_underlay_peer()
266+
if not self.inputs.avd_design_future.only_configure_mlag_vrfs_peer_group_when_used and self.shared_utils.use_separate_peer_group_for_mlag_vrfs:
267+
self.structured_config_utils.set_once_peer_group_mlag_ipv4_vrfs_peer()
287268

288269
vlan = default(self.shared_utils.mlag_peer_l3_vlan, self.shared_utils.node_config.mlag_peer_vlan)
289270
interface_name = f"Vlan{vlan}"

python-avd/pyavd/_eos_designs/structured_config/network_services/route_maps.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ def route_maps(self: AvdStructuredConfigNetworkServicesProtocol) -> None:
5454
self.structured_config.route_maps.append(route_maps_item)
5555
self._route_maps_vrf_default()
5656

57-
# Note we check the 'flag need_mlag_peer_group' here which is being set by router_bgp logic. So this must run after.
58-
# TODO: Move this logic to a single place instead.
59-
if self.need_mlag_peer_group and self.shared_utils.node_config.mlag_ibgp_origin_incomplete:
60-
self._bgp_mlag_peer_group_route_map()
61-
6257
if self._mlag_ibgp_peering_subnets_without_redistribution:
6358
self.set_once_route_map_connected_to_bgp_vrfs()
6459

@@ -89,23 +84,6 @@ def _route_maps_vrf_default_check(self: AvdStructuredConfigNetworkServicesProtoc
8984

9085
return bool(self.shared_utils.wan_role and self._vrf_default_ipv4_static_routes["redistribute_in_overlay"])
9186

92-
def _bgp_mlag_peer_group_route_map(self: AvdStructuredConfigNetworkServicesProtocol) -> None:
93-
"""
94-
Set one route-map item.
95-
96-
Origin Incomplete for MLAG iBGP learned routes.
97-
98-
TODO: Partially duplicated from mlag. Should be moved to a common class
99-
"""
100-
route_maps_item = EosCliConfigGen.RouteMapsItem(name="RM-MLAG-PEER-IN")
101-
route_maps_item.sequence_numbers.append_new(
102-
sequence=10,
103-
type="permit",
104-
set=EosCliConfigGen.RouteMapsItem.SequenceNumbersItem.Set(["origin incomplete"]),
105-
description="Make routes learned over MLAG Peer-link less preferred on spines to ensure optimal routing",
106-
)
107-
self.structured_config.route_maps.append(route_maps_item)
108-
10987
@run_once_method
11088
def set_once_route_map_connected_to_bgp_vrfs(self: AvdStructuredConfigNetworkServicesProtocol) -> None:
11189
"""

0 commit comments

Comments
 (0)