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_cli_config_gen): Add support for ingress in system.control_plane.ipv4/6_access_group #4481

Closed
wants to merge 17 commits into from

Conversation

Vibhu-gslab
Copy link
Contributor

Change Summary

Add support for ingress in system.control_plane.ipv4/6_access_group

s1-spine1(config-system-cp)#ip access-group ?
  WORD     Access list name
  ingress  Specify default CP ACL for inbound packets

s1-spine1(config-system-cp)#ipv6 access-group ?
  WORD     Access list name
  ingress  Specify default CP ACL for inbound packets

Related Issue(s)

Fixes #4467

Component(s) name

arista.avd.eos_cli_config_gen

How to test

CI

Checklist

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

@Vibhu-gslab Vibhu-gslab self-assigned this Sep 17, 2024
@github-actions github-actions bot added role: eos_cli_config_gen issue related to eos_cli_config_gen role state: CI Updated CI scenario have been updated in the PR state: Documentation role Updated labels Sep 17, 2024
Copy link

Review docs on Read the Docs

To test this pull request:

# Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-4481
# Activate the virtual environment
source test-avd-pr-4481/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/Vibhu-gslab/avd.git@ingress#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/Vibhu-gslab/avd.git#/ansible_collections/arista/avd/,ingress --force
# Optional: Install AVD examples
cd test-avd-pr-4481
ansible-playbook arista.avd.install_examples

@Vibhu-gslab Vibhu-gslab changed the title Refactor(eos_cli_config_gen):Add support for ingress in system.control_plane.ipv4/6_access_group Refactor(eos_cli_config_gen): Add support for ingress in system.control_plane.ipv4/6_access_group Sep 17, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the state: conflict PR with conflict label Oct 17, 2024
Copy link

Conflicts have been resolved. A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the state: conflict PR with conflict label Oct 21, 2024
{% set cp_ipv4_access_grp = "ip access-group " ~ acl_set.acl_name %}
{% if acl_set.vrf is arista.avd.defined %}
{% set cp_ipv4_access_grp = cp_ipv4_access_grp ~ " vrf " ~ acl_set.vrf %}
{% for acl_set in system.control_plane.ipv4_access_groups | arista.avd.natural_sort %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix the j2 template for vrf default and none case. So if vrf is default or none then we have to render the only last command.
Like from your example
ipv4_access_groups:
- acl_name: "acl4_1"
- acl_name: "acl4_3"
vrf: default
it should render the only below config:
ip access-group acl4_3 in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can as well optionally simply pick first IPv4 and IPv6 out of all with either "missing" VRF or those where it is set to default. EoS takes last line from overlapping commands pushed to conf or conf session because it simply overwrites previous ones. As we generate designed configuration state for the device - we should probably avoid generating commands which would be overwriting each other (although EoS would be OK with it).

ip access-group acl4_3 vrf default in
ip access-group ingress default acl4_4
ip access-group acl4_5 vrf red_3 in
ip access-group ingress vrf red_4 in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order is not correct

s1-leaf1(config-system-cp)#sh ac
system control-plane
   tcp mss ceiling ipv4 1344 ipv6 1366
   ip access-group ingress default acl4_4
   ip access-group acl4_3 in
   ip access-group acl4_2 vrf red in
   ip access-group acl4_2 vrf red_1 in
   ip access-group acl4_5 vrf red_3 in
   ip access-group ingress vrf red_4 in
   ipv6 access-group ingress default acl6_4
   ipv6 access-group acl6_3 in
   ipv6 access-group acl6_2 vrf blue in
   ipv6 access-group acl6_2 vrf blue_1 in
   ipv6 access-group ingress vrf blue_2 in
s1-leaf1(config-system-cp)#

{% set cp_ipv4_access_grp = cp_ipv4_access_grp ~ " vrf " ~ acl_set.vrf %}
{% for acl_set in system.control_plane.ipv4_access_groups | arista.avd.natural_sort %}
{% if acl_set.ingress_default is arista.avd.defined(true) %}
{% set cp_ipv4_access_grp = "ip access-group ingress default " ~ acl_set.acl_name %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Right now neither schema nor J2 enforces only one default ingress ACL for IPv4 and IPv6 (although EoS will only allow one, because there can be only one implicit per ipv4/iv6).

Defining multiple ACLs as ingress_default: true renders all lines:

    ipv4_access_groups:
      - acl_name: "acl4_4"
        vrf: red_2
        ingress_default: true
      - acl_name: "acl4_6"
        vrf: red_5
        ingress_default: true
    ipv6_access_groups:
      - acl_name: "acl6_4"
        ingress_default: true
      - acl_name: "acl6_6"
        ingress_default: true
   ip access-group ingress default acl4_4
   ip access-group ingress default acl4_6

   ipv6 access-group ingress default acl6_4
   ipv6 access-group ingress default acl6_6

Maybe we could at least only render first "ingress default" per address family, and treat all others as regular (per-vrf ACLs)

# Line 8
+ {% set ns = namespace(ipv4_ingress_default_set=false, ipv6_ingress_default_set=false) %}

# Line [29:]
-{%     for acl_set in system.control_plane.ipv4_access_groups | arista.avd.natural_sort %}
+{%     for acl_set in sorted_ipv4_access_groups | arista.avd.natural_sort %}
-{%         if acl_set.ingress_default is arista.avd.defined(true) %}
+{%         if acl_set.ingress_default is arista.avd.defined(true) and ns.ipv4_ingress_default_set is not arista.avd.defined(true) %}
{%             set cp_ipv4_access_grp = "ip access-group ingress default " ~ acl_set.acl_name %}
+{%             set ns.ipv4_ingress_default_set = true %}
{%         else %}
{%             set cp_ipv4_access_grp = "ip access-group " ~ acl_set.acl_name %}
{%             if acl_set.vrf is arista.avd.defined %}
{%                 set cp_ipv4_access_grp = cp_ipv4_access_grp ~ " vrf " ~ acl_set.vrf %}
{%             endif %}
{%             set cp_ipv4_access_grp = cp_ipv4_access_grp ~ " in" %}
{%         endif %}
   {{ cp_ipv4_access_grp }}
{%     endfor %}
{#     control_plane access_groups ipv6 #}
{%     if system.control_plane.ipv6_access_groups is arista.avd.defined %}
{%         set with_vrf_non_default = system.control_plane.ipv6_access_groups | selectattr('vrf', 'arista.avd.defined') | rejectattr('vrf', 'equalto', 'default') | arista.avd.natural_sort | arista.avd.natural_sort('vrf') %}
{%         set without_vrf = system.control_plane.ipv6_access_groups | rejectattr('vrf', 'arista.avd.defined') | arista.avd.natural_sort %}
{%         set with_vrf_default = system.control_plane.ipv6_access_groups | selectattr('vrf', 'arista.avd.defined') | selectattr('vrf', 'equalto', 'default') | arista.avd.natural_sort %}
{%         set sorted_ipv6_access_groups =  without_vrf | list + with_vrf_default | list + with_vrf_non_default | list %}
{%     endif %}
-{%     for acl_set in system.control_plane.ipv6_access_groups | arista.avd.natural_sort %}
+{%     for acl_set in sorted_ipv6_access_groups | arista.avd.natural_sort %}
-{%         if acl_set.ingress_default is arista.avd.defined(true) %}
+{%         if acl_set.ingress_default is arista.avd.defined(true) and ns.ipv6_ingress_default_set is not arista.avd.defined(true) %}
{%             set cp_ipv6_access_grp = "ipv6 access-group ingress default " ~ acl_set.acl_name %}
+{%             set ns.ipv6_ingress_default_set = true %}
{%         else %}
{%             set cp_ipv6_access_grp = "ipv6 access-group " ~ acl_set.acl_name %}
{%             if acl_set.vrf is arista.avd.defined %}
{%                 set cp_ipv6_access_grp = cp_ipv6_access_grp ~ " vrf " ~ acl_set.vrf %}
{%             endif %}
{%             set cp_ipv6_access_grp = cp_ipv6_access_grp ~ " in" %}
{%         endif %}
   {{ cp_ipv6_access_grp }}
{%     endfor %}

Copy link
Contributor

@ClausHolbechArista ClausHolbechArista Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default here is the default VRF, so I think there are some misunderstandings about the data model and EOS CLI.

EDIT:

So there are

[no|default] ip access-group ACL_NAME [ ( VRF_VRF_KW ( VRF_VRF_DYNAMIC | VRF_VRF_DEFAULT ) ) ] in
[no|default] ip access-group ingress default ACL_NAME
[no|default] ipv6 access-group ACL_NAME [ ( VRF_VRF_KW ( VRF_VRF_DYNAMIC | VRF_VRF_DEFAULT ) ) ] in
[no|default] ipv6 access-group ingress default ACL_NAME

We should have ipv4_access_group_ingress_default: <str> and ipv6_access_group_ingress_default: <str>.
And then keep the vrf access groups as they are Today.

ip access-group acl4_3 vrf default in
ip access-group ingress default acl4_4
ip access-group acl4_5 vrf red_3 in
ip access-group ingress vrf red_4 in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add to this comment:

  • EoS treats missing VRF and VRF default as the same.
   ip access-group acl4_1 in
   ip access-group acl4_3 vrf default in

will end up in running-config as ip access-group acl4_3 in (last command overwrites previous ones)

  • Order seems to be the following:
  1. tcp mss ceiling.*
  2. ip access-group ingress default.*
  3. ip access-group <IPv4_ACL_NAME> in # IPv4 ACL for default` VRF. Can be only one
  4. ip access-group <IPv4_ACL_NAME> vrf <VRF_NAME> in # Sorted by VRF name

Same ordering applies to IPv6.

Example:

avd-ci-leaf2(config-s-s19)#system control-plane
avd-ci-leaf2(config-s-s19-system-cp)#   tcp mss ceiling ipv4 1344 ipv6 1366
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_1 in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_2 vrf red in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_2 vrf red_1 in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_3 vrf default in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group ingress default acl4_4
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_5 vrf red_3 in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group acl4_6 vrf red_5 in
avd-ci-leaf2(config-s-s19-system-cp)#   ip access-group ingress vrf red_4 in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group acl6_1 in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group acl6_2 vrf blue in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group acl6_2 vrf blue_1 in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group acl6_3 vrf default in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group ingress default acl6_4
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group acl6_6 in
avd-ci-leaf2(config-s-s19-system-cp)#   ipv6 access-group ingress vrf blue_2 in
avd-ci-leaf2(config-s-s19-system-cp)#show session-config diffs 
--- system:/running-config
+++ session:/s19-session-config
+system control-plane
+   tcp mss ceiling ipv4 1344 ipv6 1366
+   ip access-group ingress default acl4_4
+   ip access-group acl4_3 in
+   ip access-group acl4_2 vrf red in
+   ip access-group acl4_2 vrf red_1 in
+   ip access-group acl4_5 vrf red_3 in
+   ip access-group ingress vrf red_4 in
+   ip access-group acl4_6 vrf red_5 in
+   ipv6 access-group ingress default acl6_4
+   ipv6 access-group acl6_6 in
+   ipv6 access-group acl6_2 vrf blue in
+   ipv6 access-group acl6_2 vrf blue_1 in
+   ipv6 access-group ingress vrf blue_2 in
avd-ci-leaf2(config-s-s19-system-cp)#

{% set cp_ipv4_access_grp = "ip access-group " ~ acl_set.acl_name %}
{% if acl_set.vrf is arista.avd.defined %}
{% set cp_ipv4_access_grp = cp_ipv4_access_grp ~ " vrf " ~ acl_set.vrf %}
{% for acl_set in system.control_plane.ipv4_access_groups | arista.avd.natural_sort %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can as well optionally simply pick first IPv4 and IPv6 out of all with either "missing" VRF or those where it is set to default. EoS takes last line from overlapping commands pushed to conf or conf session because it simply overwrites previous ones. As we generate designed configuration state for the device - we should probably avoid generating commands which would be overwriting each other (although EoS would be OK with it).

@Vibhu-gslab Vibhu-gslab marked this pull request as draft November 5, 2024 09:24
@Vibhu-gslab Vibhu-gslab marked this pull request as ready for review November 7, 2024 11:18
@github-actions github-actions bot added the state: conflict PR with conflict label Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the state: conflict PR with conflict label Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link

sonarcloud bot commented Nov 8, 2024

@ClausHolbechArista ClausHolbechArista changed the title Refactor(eos_cli_config_gen): Add support for ingress in system.control_plane.ipv4/6_access_group Feat(eos_cli_config_gen): Add support for ingress in system.control_plane.ipv4/6_access_group Nov 8, 2024
@ClausHolbechArista
Copy link
Contributor

Moving to draft since we the changes needs to be reworked to match EOS CLI. Reach out if we need to discuss.

@ClausHolbechArista ClausHolbechArista marked this pull request as draft November 11, 2024 08:25
@Vibhu-gslab
Copy link
Contributor Author

Closing this PR and fixing the issue in PR: #4710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
role: eos_cli_config_gen issue related to eos_cli_config_gen role state: CI Updated CI scenario have been updated in the PR state: Documentation role Updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include ingress option in system.control_plane.ipv4/6_access_group data model
5 participants