Skip to content

Commit

Permalink
Refactor: Fix prefixes for control plane application
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Jan 15, 2024
1 parent bec88c2 commit 2bd8255
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.31.1/32 192.168.31.2/32
!
ip routing
ip routing vrf IT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.30.0/24 192.168.31.2/32
!
ip routing
no ip routing vrf MGMT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.30.0/24 192.168.31.1/32
!
ip routing
no ip routing vrf MGMT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.44.1/32
!
ip routing
ip routing vrf IT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.42.0/24 192.168.43.0/24
!
ip routing
no ip routing vrf MGMT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.42.0/24 192.168.43.0/24 192.168.44.3/32 6.6.6.6/32
!
ip routing
no ip routing vrf MGMT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.42.0/24 192.168.43.0/24 192.168.44.2/32 6.6.6.6/32
!
ip routing
no ip routing vrf MGMT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ application traffic recognition
application-profile voice
!
field-set ipv4 prefix CONTROL-PLANE-APP-DEST-PREFIXES
42.42.42.42/32
192.168.44.1/32
!
ip routing
ip routing vrf IT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.31.1/32
- 192.168.31.2/32
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.31.2/32
- 192.168.30.0/24
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.31.1/32
- 192.168.30.0/24
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.44.1/32
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.42.0/24
- 192.168.43.0/24
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down Expand Up @@ -420,8 +421,6 @@ metadata:
sites:
- name: Site422
id: 422
location:
address: Somewhere
- name: AVD_Land_East
id: 43
zones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.44.3/32
- 6.6.6.6/32
- 192.168.42.0/24
- 192.168.43.0/24
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down Expand Up @@ -406,8 +409,6 @@ metadata:
sites:
- name: Site422
id: 422
location:
address: Somewhere
- name: AVD_Land_East
id: 43
zones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.44.2/32
- 6.6.6.6/32
- 192.168.42.0/24
- 192.168.43.0/24
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down Expand Up @@ -436,8 +439,6 @@ metadata:
sites:
- name: Site422
id: 422
location:
address: Somewhere
- name: AVD_Land_East
id: 43
zones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ application_traffic_recognition:
ipv4_prefixes:
- name: CONTROL-PLANE-APP-DEST-PREFIXES
prefix_values:
- 42.42.42.42/32
- 192.168.44.1/32
dps_interfaces:
- name: Dps1
description: DPS Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ cv_pathfinder_regions:
sites:
- name: Site422
id: 422
location: Somewhere
- name: AVD_Land_East
id: 43
description: AVD Region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def wan_role(self: SharedUtils) -> str | None:
raise AristaAvdError("'wan_role' client requires 'evpn_role' client.")
return wan_role

@cached_property
def wan_listen_ranges(self) -> list:
return get(
self.bgp_peer_groups["wan_overlay_peers"],
"listen_range_prefixes",
required=True,
org_key="bgp_peer_groups.wan_overlay_peers.listen_range_prefixes",
)

@cached_property
def cv_pathfinder_role(self: SharedUtils) -> str | None:
if self.underlay_router is False or self.wan_mode != "cv-pathfinder":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ def _generate_control_plane_application_profile(self, app_dict: dict) -> None:
ipv4_prefixes_field_sets = get(app_dict, "field_sets.ipv4_prefixes", [])
if get_item(ipv4_prefixes_field_sets, "name", self._wan_cp_app_dst_prefix) is not None:
return
# pathfinder_router_ids = [wan_rs_data.get("router_id") for wan_rs, wan_rs_data in self.shared_utils.wan_route_servers.items()]
pathfinder_router_ids = ["42.42.42.42/32"]
pathfinder_router_ids = [f"{wan_rs_data.get('router_id')}/32" for wan_rs, wan_rs_data in self.shared_utils.filtered_wan_route_servers.items()]
if self.shared_utils.wan_role == "server":
pathfinder_router_ids.extend(self.shared_utils.wan_listen_ranges)

app_dict.setdefault("field_sets", {}).setdefault("ipv4_prefixes", []).append(
{
"name": self._wan_cp_app_dst_prefix,
Expand Down Expand Up @@ -143,7 +145,7 @@ def _append_object_to_list_of_dicts(path: str, obj_name: str, list_of_dicts: lis
obj_name=application_profile,
list_of_dicts=application_profiles,
message=(
f"The application profile {application_profile} used in one of the policies "
f"The application profile {application_profile} used in policy {policy['name']} "
"is not defined in 'application_traffic_recognition.application_profiles'."
),
)
Expand All @@ -156,7 +158,7 @@ def _append_object_to_list_of_dicts(path: str, obj_name: str, list_of_dicts: lis
obj_name=application_profile,
list_of_dicts=application_profiles,
message=(
f"The application profile {application_profile} used in one of the policies "
f"The application profile {application_profile} used in policy {policy['name']} "
"is not defined in 'application_traffic_recognition.application_profiles'."
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def _augmented_cv_pathfinder_policies(self) -> list:
default_virtual_topology = get(avt_policy, "default_virtual_topology", required=True)
if not get(default_virtual_topology, "drop_unmatched", default=False):
application_profile = get(default_virtual_topology, "application_profile", default="default")
self._assert_application_profile_exist(application_profile)
cv_pathfinder_policy["matches"].append(
{
"application_profile": application_profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def _autovpn_policies(self) -> list:
for rule_id, application_virtual_topology in enumerate(get(policy, "application_virtual_topologies", []), start=1):
name = get(application_virtual_topology, "name", default=f"{policy['name']}_{application_virtual_topology['application_profile']}")
application_profile = get(application_virtual_topology, "application_profile", required=True)
self._assert_application_profile_exist(application_profile)
autovpn_policy.setdefault("rules", []).append(
{
"id": 10 * (rule_id + rule_id_offset),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,23 +404,3 @@ def _default_vrf_policy(self) -> dict:
).copy()
default_policy["is_default"] = True
return default_policy

def _assert_application_profile_exist(self, application_profile: str) -> None:
"""
Check that the application_profile name exists in the `application_traffic_recognition` block
or is `default`
otherwise raise AristaAvdMissingVariableError
"""
if application_profile == "default":
return
application_profiles = get(self._hostvars, "application_traffic_recognition.application_profiles", [])
get_item(
application_profiles,
"name",
application_profile,
required=True,
custom_error_msg=(
f"The application profile {application_profile} used in one of the policies "
"is not defined in 'application_traffic_recognition.application_profiles'."
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _bgp_listen_ranges(self) -> list | None:
"peer_group": self.shared_utils.bgp_peer_groups["wan_overlay_peers"]["name"],
"remote_as": self.shared_utils.bgp_as,
}
for prefix in self._wan_listen_ranges
for prefix in self.shared_utils.wan_listen_ranges
] or None

def _generate_base_peer_group(self, pg_type: str, pg_name: str, maximum_routes: int = 0) -> dict:
Expand Down Expand Up @@ -479,7 +479,7 @@ def _neighbors(self) -> list | None:
neighbors.append(neighbor)

if self.shared_utils.wan_role == "client":
if not self._router_id_in_listen_ranges(self._wan_listen_ranges):
if not self._router_id_in_listen_ranges(self.shared_utils.wan_listen_ranges):
raise AristaAvdError(
f"Loopback0 IP {self.shared_utils.router_id} is not in the Route Reflector listen range prefixes"
" 'bgp_peer_groups.wan_overlay_peers.listen_range_prefixes'."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ def _append_peer(self, peers_dict: dict, peer_name: str, peer_facts: dict) -> No
def _is_wan_server_with_peers(self) -> bool:
return self.shared_utils.wan_role == "server" and len(self.shared_utils.filtered_wan_route_servers) > 0

@cached_property
def _wan_listen_ranges(self):
return get(self.shared_utils.bgp_peer_groups["wan_overlay_peers"], "listen_range_prefixes", required=True)

def _stun_server_profile_name(self, wan_route_server_name: str, path_group_name: str, interface_name: str) -> str:
"""
Return a string to use as the name of the stun server_profile
Expand Down

0 comments on commit 2bd8255

Please sign in to comment.