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

Feat(eos_designs): Add possibility to change network mask for direct WAN HA link #4497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ router path-selection
!
peer static router-ip 192.168.142.7
name cv-pathfinder-edge3B
ipv4 address 10.10.10.1
ipv4 address 10.10.10.2
!
load-balance policy LB-DEFAULT-AVT-POLICY-CONTROL-PLANE
path-group INET
Expand Down Expand Up @@ -226,7 +226,7 @@ interface Ethernet52
no shutdown
mtu 9100
no switchport
ip address 10.10.10.0/31
ip address 10.10.10.1/24
!
interface Loopback0
description ROUTER_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ router path-selection
!
peer static router-ip 192.168.142.6
name cv-pathfinder-edge3A
ipv4 address 10.10.10.0
ipv4 address 10.10.10.1
!
path-group MPLS id 100
keepalive interval 300 milliseconds failure-threshold 5 intervals
Expand Down Expand Up @@ -226,7 +226,7 @@ interface Ethernet52
no shutdown
mtu 9100
no switchport
ip address 10.10.10.1/31
ip address 10.10.10.2/24
!
interface Loopback0
description ROUTER_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ethernet_interfaces:
peer: cv-pathfinder-edge3B
shutdown: false
description: DIRECT LAN HA LINK
ip_address: 10.10.10.0/31
ip_address: 10.10.10.1/24
flow_tracker: null
mtu: 9100
loopback_interfaces:
Expand Down Expand Up @@ -421,7 +421,7 @@ router_path_selection:
- router_ip: 192.168.142.7
name: cv-pathfinder-edge3B
ipv4_addresses:
- 10.10.10.1
- 10.10.10.2
ipsec_profile: DP-PROFILE
load_balance_policies:
- name: LB-DEFAULT-AVT-POLICY-CONTROL-PLANE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ethernet_interfaces:
peer: cv-pathfinder-edge3A
shutdown: false
description: DIRECT LAN HA LINK
ip_address: 10.10.10.1/31
ip_address: 10.10.10.2/24
flow_tracker: null
mtu: 9100
loopback_interfaces:
Expand Down Expand Up @@ -421,7 +421,7 @@ router_path_selection:
- router_ip: 192.168.142.6
name: cv-pathfinder-edge3A
ipv4_addresses:
- 10.10.10.0
- 10.10.10.1
ipsec_profile: DP-PROFILE
load_balance_policies:
- name: LB-DEFAULT-AVT-POLICY-CONTROL-PLANE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ bgp_peer_groups:
- 192.168.142.0/24
- 192.168.143.0/24

fabric_ip_addressing:
wan_ha:
ipv4_prefix_length: 24

wan_stun_dtls_profile_name: profileA

wan_route_servers:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ keys:
convert_types:
- str
description: IPv4 prefix length used for L3 point-to-point uplinks.
wan_ha:
type: dict
description: Allow to manipulate the IP addressing scheme for WAN HA direct subnets.
keys:
ipv4_prefix_length:
type: int
default: 31
min: 1
max: 31
convert_types:
- str
description: IPv4 prefix length used for point-to-point interface for direct WAN HA link.
4 changes: 4 additions & 0 deletions python-avd/pyavd/_eos_designs/shared_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def fabric_ip_addressing_mlag_ipv6_prefix_length(self: SharedUtils) -> int:
def fabric_ip_addressing_p2p_uplinks_ipv4_prefix_length(self: SharedUtils) -> int:
return get(self.hostvars, "fabric_ip_addressing.p2p_uplinks.ipv4_prefix_length", default=31)

@cached_property
def fabric_ip_addressing_wan_ha_ipv4_prefix_length(self: SharedUtils) -> int:
return get(self.hostvars, "fabric_ip_addressing.wan_ha.ipv4_prefix_length", default=31)

@cached_property
def fabric_sflow_uplinks(self: SharedUtils) -> bool | None:
return get(self.hostvars, "fabric_sflow.uplinks")
Expand Down
30 changes: 7 additions & 23 deletions python-avd/pyavd/_eos_designs/shared_utils/wan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING, Literal

from pyavd._errors import AristaAvdError, AristaAvdMissingVariableError
from pyavd._utils import default, get, get_ip_from_ip_prefix, get_ip_from_pool, get_item, strip_empties_from_dict
from pyavd._utils import default, get, get_ip_from_ip_prefix, get_item, strip_empties_from_dict
from pyavd.j2filters import natural_sort

if TYPE_CHECKING:
Expand Down Expand Up @@ -568,7 +568,7 @@ def wan_ha_peer_ip_addresses(self: SharedUtils) -> list:
ip_addresses.append(f"{ip_address}/{prefix_length}")
else:
# Only one supported HA interface today when not using uplinks
ip_addresses.append(self.get_wan_ha_ip_address(local=False))
ip_addresses.append(self.ip_addressing.wan_ha_peer_ip())
return ip_addresses

@cached_property
Expand All @@ -595,35 +595,19 @@ def wan_ha_ip_addresses(self: SharedUtils) -> list:
ip_addresses.append(f"{ip_address}/{prefix_length}")
else:
# Only one supported HA interface today when not using uplinks
ip_addresses.append(self.get_wan_ha_ip_address(local=True))
ip_addresses.append(self.ip_addressing.wan_ha_ip())
return ip_addresses

def get_wan_ha_ip_address(self: SharedUtils, local: bool) -> str | None:
"""
Render ipv4 address for wan_ha_ip_address using dynamically loaded python module.

local: When true, request the first IP address else request the remote peer IP.
TODO: Move this to ip_addressing module to allow for custom logic.
"""
wan_ha_ipv4_pool = get(
@cached_property
def wan_ha_ipv4_pool(self: SharedUtils) -> str:
"""Return the configured wan_ha.ha_ipv4_pool."""
return get(
self.switch_data_combined,
"wan_ha.ha_ipv4_pool",
required=True,
org_key="Missing `wan_ha.ha_ipv4_pool` node settings to allocate an IP address to defined HA interface",
)

first_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, 31, 0, 0)
second_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, 31, 0, 1)

if self.is_first_ha_peer:
local_ip, remote_ip = first_ip_address, second_ip_address
else:
local_ip, remote_ip = second_ip_address, first_ip_address

ip_address = local_ip if local else remote_ip

return f"{ip_address}/31"

def generate_lb_policy_name(self: SharedUtils, name: str) -> str:
"""Returns LB-{name}."""
return f"LB-{name}"
Expand Down
24 changes: 24 additions & 0 deletions python-avd/pyavd/api/ip_addressing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,27 @@ def evpn_underlay_l2_multicast_group(
"""Return IP address to be used for EVPN underlay L2 multicast group."""
offset = vlan_id - 1 + underlay_l2_multicast_group_ipv4_pool_offset
return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0)

def wan_ha_ip(self) -> str:
"""Return the WAN HA local IP address."""
wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool
prefixlen = self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length

if self.shared_utils.is_first_ha_peer:
ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0)
else:
ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1)

return f"{ip_address}/{prefixlen}"

def wan_ha_peer_ip(self) -> str:
"""Return the WAN HA peer IP."""
wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool
prefixlen = self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length

if self.shared_utils.is_first_ha_peer:
ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1)
else:
ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0)

return f"{ip_address}/{prefixlen}"
Loading