Skip to content

Commit

Permalink
Feat: Add support for default route
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Dec 21, 2023
1 parent a43ed77 commit 12ef123
Show file tree
Hide file tree
Showing 31 changed files with 225 additions and 123 deletions.
Expand Up @@ -69,6 +69,7 @@ interface Ethernet1
no shutdown
no switchport
ip address dhcp
dhcp client accept default-route
!
interface Loopback0
description Router_ID
Expand Down
Expand Up @@ -56,6 +56,7 @@ interface Ethernet1
no shutdown
no switchport
ip address dhcp
dhcp client accept default-route
!
interface Loopback0
description Router_ID
Expand Down
Expand Up @@ -71,6 +71,8 @@ interface Vxlan1
ip routing
no ip routing vrf MGMT
!
ip route 0.0.0.0/0 10.8.8.9
!
router bfd
multihop interval 300 min-rx 300 multiplier 3
!
Expand Down
Expand Up @@ -100,6 +100,7 @@ interface Ethernet1
no switchport
flow tracker hardware WAN-FLOW-TRACKER
ip address dhcp
dhcp client accept default-route
!
interface Ethernet2
no shutdown
Expand Down
Expand Up @@ -114,6 +114,8 @@ interface Vxlan1
ip routing
no ip routing vrf MGMT
!
ip route 0.0.0.0/0 10.7.7.6
!
router bfd
multihop interval 300 min-rx 300 multiplier 3
!
Expand Down
Expand Up @@ -105,6 +105,7 @@ interface Ethernet1
no switchport
flow tracker hardware WAN-FLOW-TRACKER
ip address dhcp
dhcp client accept default-route
!
interface Ethernet2
no shutdown
Expand Down
Expand Up @@ -54,6 +54,8 @@ no ip routing vrf MGMT
ip prefix-list PL-LOOPBACKS-EVPN-OVERLAY
seq 10 permit 1.2.3.4/24 eq 32
!
ip route 0.0.0.0/0 192.168.1.3
!
route-map RM-CONN-2-BGP permit 10
match ip address prefix-list PL-LOOPBACKS-EVPN-OVERLAY
!
Expand Down
Expand Up @@ -137,6 +137,7 @@ ethernet_interfaces:
ip_address: dhcp
shutdown: false
type: routed
dhcp_client_accept_default_route: true
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Expand Up @@ -135,6 +135,7 @@ ethernet_interfaces:
ip_address: dhcp
shutdown: false
type: routed
dhcp_client_accept_default_route: true
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Expand Up @@ -135,6 +135,9 @@ ethernet_interfaces:
ip_address: 10.8.8.8/31
shutdown: false
type: routed
static_routes:
- destination_address_prefix: 0.0.0.0/0
gateway: 10.8.8.9
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Expand Up @@ -184,6 +184,7 @@ ethernet_interfaces:
ip_address: dhcp
shutdown: false
type: routed
dhcp_client_accept_default_route: true
flow_tracker:
hardware: WAN-FLOW-TRACKER
- name: Ethernet2
Expand Down
Expand Up @@ -185,6 +185,9 @@ ethernet_interfaces:
type: routed
flow_tracker:
hardware: WAN-FLOW-TRACKER
static_routes:
- destination_address_prefix: 0.0.0.0/0
gateway: 10.7.7.6
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Expand Up @@ -194,6 +194,7 @@ ethernet_interfaces:
ip_address: dhcp
shutdown: false
type: routed
dhcp_client_accept_default_route: true
flow_tracker:
hardware: WAN-FLOW-TRACKER
- name: Ethernet2
Expand Down
Expand Up @@ -92,3 +92,6 @@ ethernet_interfaces:
ip_address: 192.168.42.42/24
shutdown: true
type: routed
static_routes:
- destination_address_prefix: 0.0.0.0/0
gateway: 192.168.1.3
Expand Up @@ -11,7 +11,7 @@ bgp_peer_groups:
- 192.168.30.0/24

wan_route_servers:
# Testing having the interface configured with DHPC
# Testing having the interface configured with DHCP
- hostname: autovpn-rr1
path_groups:
- name: INET
Expand Down Expand Up @@ -73,14 +73,17 @@ l3_edge:
wan_carrier: Comcast
wan_circuit_id: 666
ip: dhcp
set_default_route: true
- node: autovpn-rr1
interface: Ethernet1
wan_carrier: ATT
wan_circuit_id: 777
ip: dhcp
# ip: 10.7.7.7/31
set_default_route: true
- node: autovpn-rr2
interface: Ethernet1
wan_carrier: ATT
wan_circuit_id: 888
ip: 10.8.8.8/31
set_default_route: true
peer_ip: 10.8.8.9/31
Expand Up @@ -107,6 +107,7 @@ l3_edge:
interface: Ethernet1
wan_carrier: ATT
wan_circuit_id: 666
set_default_route: true
ip: dhcp
- node: cv-pathfinder-edge
interface: Ethernet2
Expand All @@ -118,6 +119,7 @@ l3_edge:
interface: Ethernet1
wan_carrier: Comcast
wan_circuit_id: 667
set_default_route: true
ip: dhcp
- node: cv-pathfinder-transit
interface: Ethernet2
Expand All @@ -128,7 +130,9 @@ l3_edge:
interface: Ethernet1
wan_carrier: Bouygues Telecom
wan_circuit_id: 777
set_default_route: true
ip: 10.7.7.7/31
peer_ip: 10.7.7.6/31
- node: cv-pathfinder-pathfinder
interface: Ethernet2
wan_carrier: Colt
Expand Down
Expand Up @@ -21,26 +21,28 @@ l3_edge:
l3_interfaces:
# Settings set via profile
- node: l3_edge_l3_interfaces
peer: peer1
peer_interface: eth1
interface: Ethernet1
ip: 192.168.1.2/31
set_default_route: true
peer: peer1
peer_interface: eth1
peer_ip: 192.168.1.3/31
profile: profile1
# DHCP default route
- node: l3_edge_l3_interfaces
peer: peer2
interface: Ethernet2/2
ip: dhcp
dhcp_client_accept_default_route: True
set_default_route: true
# custom descriptipon
- node: l3_edge_l3_interfaces
peer: peer3
interface: Ethernet42
enabled: False
enabled: false
description: This is a custom description
ip: dhcp
# empty description
- node: l3_edge_l3_interfaces
interface: Ethernet43
enabled: False
enabled: false
ip: 192.168.42.42/24
Expand Up @@ -6,8 +6,6 @@
from functools import cached_property
from typing import TYPE_CHECKING

from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item

if TYPE_CHECKING:
from .eos_designs_facts import EosDesignsFacts

Expand All @@ -22,24 +20,13 @@ class WanMixin:
@cached_property
def wan_path_groups(self: EosDesignsFacts) -> list | None:
"""
TODO: Also add the path_groups importing any of our connected path groups.
Need to find out if we need to resolve recursive imports.
Return the list of WAN path_groups directly connected to this router, with a list of dictionaries
containing the (interface, ip_address) in the path_group.
"""
if not self.shared_utils.wan_mode:
return None

res = []
for interface in self.shared_utils.wan_interfaces:
carrier = get(interface, "wan_carrier", required=True)
pg_name = self.shared_utils.get_carrier_path_group(carrier)
if (pg_dict := get_item(res, "name", pg_name)) is None:
res.append(
{
"name": pg_name,
"interfaces": [{"name": get(interface, "interface", required=True), "ip_address": get(interface, "ip", required=True)}],
}
)
else:
pg_dict["interfaces"].append({"name": get(interface, "interface", required=True), "ip_address": get(interface, "ip", required=True)})

return res
return self.shared_utils.wan_local_path_groups
Expand Up @@ -50,4 +50,4 @@ def filtered_l3_interfaces(self: SharedUtils) -> list:
l3_interfaces = [self._apply_profile(l3_interface) for l3_interface in l3_interfaces]

# Filter to only include l3_interfaces with our hostname as node
return [l3_interface for l3_interface in l3_interfaces if self.hostname == get(l3_interface, "node", required=True)]
return [l3_interface for l3_interface in l3_interfaces if self.hostname == get(l3_interface, "node")]
Expand Up @@ -65,23 +65,23 @@ def wan_interfaces(self: SharedUtils) -> list:

wan_interfaces = []
for interface in self.filtered_l3_interfaces:
# Potentially needs to resolve profile
if get(interface, "wan_carrier") is not None:
# TODO - may need to validate the path_group here
wan_interfaces.append(interface)

return wan_interfaces

@cached_property
def wan_local_carriers(self: SharedUtils) -> list:
"""
List of carriers present on this router based on the wan_interfaces
TODO maybe a list of name is enough
List of carriers present on this router based on the wan_interfaces with the associated WAN interfaces
interfaces:
- name: ...
ip: ...
"""
if self.wan_mode is None:
if not self.wan_role:
return []
local_carriers = []

local_carriers_dict = {}
global_carriers = get(self.hostvars, "wan_carriers", required=True)
for interface in self.wan_interfaces:
iface_carrier = interface.get("wan_carrier")
Expand All @@ -92,46 +92,51 @@ def wan_local_carriers(self: SharedUtils) -> list:
required=True,
custom_error_msg=f"WAN carrier {iface_carrier} is not in the available carriers defined in `wan_carriers`",
)
local_carriers.append(carrier)

return local_carriers
local_carriers_dict.setdefault(carrier["name"], carrier | {"interfaces": []})["interfaces"].append(
{"name": get(interface, "interface", required=True), "ip_address": get(interface, "ip", required=True)}
)

return list(local_carriers_dict.values())

def get_carrier_path_group(self: SharedUtils, carrier: str) -> str:
def get_carrier_path_group(self: SharedUtils, carrier: str) -> dict:
"""
Returns the path_group associated to a carrier name as defined in `wan_carriers`.
Returns the path_group dict from `wan_path_groups` associated to a carrier name as defined in `wan_carriers`.
"""
global_carriers = get(self.hostvars, "wan_carriers", required=True)
global_path_groups = get(self.hostvars, "wan_path_groups", required=True)

return get_item(
path_group_name = get_item(
global_carriers,
"name",
carrier,
required=True,
custom_error_msg=f"WAN carrier {carrier} is not in the available carriers defined in `wan_carriers`",
)["path_group"]

return get_item(
global_path_groups,
"name",
path_group_name,
required=True,
custom_error_msg=f"WAN path_group {path_group_name} defined for a WAN carrier is not in the available path_groups defined in `wan_path_groups`",
)

@cached_property
def wan_local_path_groups(self: SharedUtils) -> list:
"""
List of path_groups present on this router based on the local carriers
TODO maybe a list of name is enough
List of path_groups present on this router based on the local carriers.
Also add for each path_groups the local interfaces in a data structure
interfaces:
- name: ...
ip: ...
"""
if self.wan_mode is None:
return []

local_path_groups = []
global_path_groups = get(self.hostvars, "wan_path_groups", required=True)
local_path_groups_names = set(carrier.get("path_group") for carrier in self.wan_local_carriers)

for path_group_name in local_path_groups_names:
path_group = get_item(
global_path_groups,
"name",
path_group_name,
required=True,
custom_error_msg=f"WAN path_group {path_group_name} defined for a WAN carrier is not in the available path_groups defined in `wan_path_groups`",
)
local_path_groups.append(path_group)
local_path_groups_dict = {}
for carrier in self.wan_local_carriers:
path_group = self.get_carrier_path_group(carrier["name"])
local_path_groups_dict.setdefault(path_group["name"], path_group | {"interfaces": []})["interfaces"].extend(carrier.get("interfaces", []))

return local_path_groups
return list(local_path_groups_dict.values())

0 comments on commit 12ef123

Please sign in to comment.