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 support to add access-groups on l3-interfaces through network-services #4163

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5451e2e
Feat(eos_designs): Add support to add access-groups on l3-interfaces …
Jun 26, 2024
4a82e03
Using ipaddress module in the code.
Jun 28, 2024
d2bc757
Fixing the logic for acls.
Jul 2, 2024
c01dc9d
Adding convert types to ipv4 acl schema.
Jul 2, 2024
12d2923
Adding new interfaces for the test cases.
Jul 2, 2024
f5e81c7
Removing old tests
Jul 2, 2024
874d6c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 2, 2024
87e1fef
Fixing CI.
Jul 2, 2024
1937d45
Fixing docstring.
Jul 5, 2024
db22cb5
Update code add relevant acls only.
Jul 23, 2024
a5c96aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
23f74c0
Removing unnecessary key from dict.
Jul 23, 2024
6699db2
Remove comments.
Jul 23, 2024
f2bdab7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
9c6c367
Update python-avd/pyavd/_eos_designs/structured_config/network_servic…
laxmikantchintakindi Jul 26, 2024
3283d46
Update python-avd/pyavd/_eos_designs/structured_config/network_servic…
laxmikantchintakindi Jul 26, 2024
3d3629a
Update python-avd/pyavd/_eos_designs/structured_config/network_servic…
laxmikantchintakindi Jul 26, 2024
0b1272b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
67d4f44
Update python-avd/pyavd/_eos_designs/structured_config/network_servic…
laxmikantchintakindi Jul 26, 2024
8f554e8
Adding subinterface tests.
Jul 26, 2024
ed0d9dd
Merge branch 'devel' into access_groups
ClausHolbechArista Jul 26, 2024
90c19da
Merge branch 'devel' into access_groups
ClausHolbechArista Jul 26, 2024
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 @@ -147,6 +147,26 @@ interface Ethernet11
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.30.10/24
!
interface Ethernet12
description test l3 interfaces acls
no shutdown
mtu 9000
no switchport
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.40.10/24
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12 in
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12 out
!
interface Ethernet13
description test l3 interfaces acls
no shutdown
mtu 9000
no switchport
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.40.20/24
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13 in
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13 out
!
interface Ethernet4000
description My test
no shutdown
Expand Down Expand Up @@ -220,6 +240,20 @@ event-handler evpn-blacklist-recovery
delay 300
asynchronous
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
15 deny ip any host 10.10.40.10
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
15 deny ip any host 10.10.40.20
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
remark Some remark will not require source and destination fields.
permit ip host 10.10.40.10 any
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
remark Some remark will not require source and destination fields.
permit ip host 10.10.40.20 any
!
ip routing
no ip routing vrf MGMT
ip routing vrf Tenant_A_L3_VRF_Zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ interface Ethernet11
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.40.20/24
!
interface Ethernet12
description test l3 interfaces acls
no shutdown
mtu 9000
no switchport
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.50.10/24
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12 in
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12 out
!
interface Ethernet13
description test l3 interfaces acls
no shutdown
mtu 9000
no switchport
vrf Tenant_A_L3_VRF_Zone
ip address 10.10.50.20/24
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13 in
ip access-group TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13 out
!
interface Ethernet4000
description My second test
no shutdown
Expand Down Expand Up @@ -201,6 +221,20 @@ hardware tcam
!
ip virtual-router mac-address 00:dc:00:00:00:0a
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
15 deny ip any host 10.10.50.10
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
15 deny ip any host 10.10.50.20
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
remark Some remark will not require source and destination fields.
permit ip host 10.10.50.10 any
!
ip access-list TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
remark Some remark will not require source and destination fields.
permit ip host 10.10.50.20 any
!
ip routing
no ip routing vrf MGMT
ip routing vrf Tenant_A_L3_VRF_Zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,26 @@ ethernet_interfaces:
description: DC1-BL1A descriptions preferred over single description
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet12
peer_type: l3_interface
ip_address: 10.10.40.10/24
mtu: 9000
shutdown: false
description: test l3 interfaces acls
access_group_in: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
access_group_out: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet13
peer_type: l3_interface
ip_address: 10.10.40.20/24
mtu: 9000
shutdown: false
description: test l3 interfaces acls
access_group_in: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
access_group_out: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet7
peer_type: l3_interface
ip_address: 10.10.10.10/24
Expand Down Expand Up @@ -558,6 +578,35 @@ vlans:
- id: 350
name: Tenant_C_WAN_Zone_1
tenant: Tenant_C
ip_access_lists:
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
entries:
- sequence: 15
action: deny
protocol: ip
source: any
destination: 10.10.40.10
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
entries:
- sequence: 15
action: deny
protocol: ip
source: any
destination: 10.10.40.20
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
entries:
- remark: Some remark will not require source and destination fields.
- action: permit
protocol: ip
source: 10.10.40.10
destination: any
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
entries:
- remark: Some remark will not require source and destination fields.
- action: permit
protocol: ip
source: 10.10.40.20
destination: any
ip_igmp_snooping:
globally_enabled: true
ip_virtual_router_mac_address: 00:dc:00:00:00:0a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,26 @@ ethernet_interfaces:
description: DC1-BL1B descriptions preferred over single description
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet12
peer_type: l3_interface
ip_address: 10.10.50.10/24
mtu: 9000
shutdown: false
description: test l3 interfaces acls
access_group_in: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
access_group_out: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet13
peer_type: l3_interface
ip_address: 10.10.50.20/24
mtu: 9000
shutdown: false
description: test l3 interfaces acls
access_group_in: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
access_group_out: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
type: routed
vrf: Tenant_A_L3_VRF_Zone
- name: Ethernet7
peer_type: l3_interface
ip_address: 10.10.20.20/24
Expand Down Expand Up @@ -531,6 +551,35 @@ vlans:
- id: 350
name: Tenant_C_WAN_Zone_1
tenant: Tenant_C
ip_access_lists:
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet12
entries:
- sequence: 15
action: deny
protocol: ip
source: any
destination: 10.10.50.10
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-IN_Ethernet13
entries:
- sequence: 15
action: deny
protocol: ip
source: any
destination: 10.10.50.20
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet12
entries:
- remark: Some remark will not require source and destination fields.
- action: permit
protocol: ip
source: 10.10.50.10
destination: any
- name: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT_Ethernet13
entries:
- remark: Some remark will not require source and destination fields.
- action: permit
protocol: ip
source: 10.10.50.20
destination: any
ip_igmp_snooping:
globally_enabled: true
ip_virtual_router_mac_address: 00:dc:00:00:00:0a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ tenant_a:
enabled: True
description: "Single description"
descriptions: ["DC1-BL1A descriptions preferred over single description", "DC1-BL1B descriptions preferred over single description"]
- interfaces: [Ethernet12, Ethernet13, Ethernet12, Ethernet13]
ClausHolbechArista marked this conversation as resolved.
Show resolved Hide resolved
ip_addresses: [10.10.40.10/24, 10.10.40.20/24, 10.10.50.10/24, 10.10.50.20/24]
nodes: [DC1-BL1A, DC1-BL1A, DC1-BL1B, DC1-BL1B]
mtu: 9000
enabled: True
description: "test l3 interfaces acls"
ipv4_acl_in: TEST-IPV4-ACL-WITH-IP-FIELDS-IN
ipv4_acl_out: TEST-IPV4-ACL-WITH-IP-FIELDS-OUT
# no description nor descriptions is tested in Tenant_OSPF below
- name: Tenant_A_OSPF
vrf_id: 16
Expand Down

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

8 changes: 8 additions & 0 deletions python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6365,6 +6365,14 @@ $defs:
type: int
convert_types:
- str
ipv4_acl_in:
type: str
convert_types:
- int
ipv4_acl_out:
type: str
convert_types:
- int
ospf:
type: dict
description: OSPF interface configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ $defs:
type: int
convert_types:
- str
ipv4_acl_in:
gmuloc marked this conversation as resolved.
Show resolved Hide resolved
type: str
convert_types:
- int
ipv4_acl_out:
type: str
convert_types:
- int
ospf:
type: dict
description: OSPF interface configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def ethernet_interfaces(self: AvdStructuredConfigNetworkServices) -> list | None
"flow_tracker": self.shared_utils.get_flow_tracker(l3_interface, "l3_interfaces"),
}

if self._l3_interface_acls is not None:
interface.update(
{
"access_group_in": get(self._l3_interface_acls, f"{interface_name}..ipv4_acl_in..name", separator=".."),
"access_group_out": get(self._l3_interface_acls, f"{interface_name}..ipv4_acl_out..name", separator=".."),
}
)

if "." in interface_name:
# This is a subinterface so we need to ensure that the parent is created
parent_interface_name, subif_id = interface_name.split(".", maxsplit=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def ip_access_lists(self: AvdStructuredConfigNetworkServices) -> list | None:
for acl in interface_acls.values():
append_if_not_duplicate(ip_access_lists, "name", acl, context="IPv4 Access lists for SVI", context_keys=["name"])

if self._l3_interface_acls:
l3_interface_acls = self._l3_interface_acls
for l3_interface_acl in l3_interface_acls.values():
laxmikantchintakindi marked this conversation as resolved.
Show resolved Hide resolved
for acl in l3_interface_acl.values():
append_if_not_duplicate(ip_access_lists, "name", acl, context="IPv4 Access lists for L3 interface", context_keys=["name"])

for ie_policy_type in self._filtered_internet_exit_policy_types:
acls = self._acl_internet_exit(ie_policy_type)
if acls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,51 @@ def get_internet_exit_nat_pool_and_profile(
def _filtered_internet_exit_policy_types(self: AvdStructuredConfigNetworkServices) -> list:
return sorted(set(internet_exit_policy["type"] for internet_exit_policy in self._filtered_internet_exit_policies))

@cached_property
def _l3_interface_acls(self: AvdStructuredConfigNetworkServices):
laxmikantchintakindi marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns a dict of interfaces and ACLs set on the interfaces.
{
<interface_name>: {
"ipv4_acl_in": <generated_ipv4_acl>,
"ipv4_acl_out": <generated_ipv4_acl>,
}
}
Only contains interfaces with ACLs and only the ACLs that are set,
so use `get(self._l3_interface_acls, f"{interface_name}..ipv4_acl_in", separator="..")` to get the value.
"""

if not self.shared_utils.network_services_l3:
return None

l3_interface_acls = {}
for tenant in self.shared_utils.filtered_tenants:
for vrf in tenant["vrfs"]:
for l3_interface in vrf["l3_interfaces"]:
for interface_idx, interface in enumerate(l3_interface["interfaces"]):
ipv4_acl_in = get(l3_interface, "ipv4_acl_in")
laxmikantchintakindi marked this conversation as resolved.
Show resolved Hide resolved
ipv4_acl_out = get(l3_interface, "ipv4_acl_out")
if ipv4_acl_in is None and ipv4_acl_out is None:
MaheshGSLAB marked this conversation as resolved.
Show resolved Hide resolved
continue
interface_name = interface
interface_ip: str | None = l3_interface["ip_addresses"][interface_idx]
interface_ip = str(ipaddress.ip_interface(interface_ip).ip)
node = l3_interface["nodes"][interface_idx]
if node == self.shared_utils.hostname:
if ipv4_acl_in is not None:
l3_interface_acls.setdefault(interface_name, {})["ipv4_acl_in"] = self.shared_utils.get_ipv4_acl(
name=ipv4_acl_in,
interface_name=interface_name,
interface_ip=interface_ip,
)
if ipv4_acl_out is not None:
l3_interface_acls.setdefault(interface_name, {})["ipv4_acl_out"] = self.shared_utils.get_ipv4_acl(
name=ipv4_acl_out,
interface_name=interface_name,
interface_ip=interface_ip,
)
laxmikantchintakindi marked this conversation as resolved.
Show resolved Hide resolved
return l3_interface_acls

@cached_property
def _filtered_internet_exit_policies(self: AvdStructuredConfigNetworkServices) -> list:
"""
Expand Down
Loading