Skip to content
Snippets Groups Projects
Commit 02964159 authored by Aleksandr Kurbatov's avatar Aleksandr Kurbatov
Browse files

Merge branch 'feature/nat-666-p-to-pe' into 'develop'

promote-p-to-pe role

See merge request !162
parents 59c2fe74 103cb902
No related branches found
No related tags found
1 merge request!162promote-p-to-pe role
Pipeline #88659 passed
Showing
with 833 additions and 9 deletions
......@@ -11,7 +11,7 @@
<as-number>{{ geant_re_as_number }}</as-number>
</local-as>
<group alu:operation="replace">
<group-name>iGEANT-P-ONLY</group-name>
<group-name>{{ geant_bgp_groups.p_only.ipv4 }}</group-name>
<admin-state>enable</admin-state>
<next-hop-self>true</next-hop-self>
<type>internal</type>
......@@ -23,7 +23,7 @@
</family>
</group>
<group alu:operation="replace">
<group-name>iGEANT6-P-ONLY</group-name>
<group-name>{{ geant_bgp_groups.p_only.ipv6 }}</group-name>
<next-hop-self>true</next-hop-self>
<type>internal</type>
<peer-as>{{ geant_re_as_number }}</peer-as>
......@@ -37,12 +37,12 @@
<neighbor xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
<ip-address>{{ pe_ipadd.lo4 }}</ip-address>
<description>{{ pe_fqdn }}</description>
<group>iGEANT-P-ONLY</group>
<group>{{ geant_bgp_groups.p_only.ipv4 }}</group>
</neighbor>
<neighbor xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
<ip-address>{{ pe_ipadd.lo6 }}</ip-address>
<description>{{ pe_fqdn }}</description>
<group>iGEANT6-P-ONLY</group>
<group><{{ geant_bgp_groups.p_only.ipv6 }}/group>
</neighbor>
{% endfor %}
</bgp>
......
---
# vars file for ibg_update
# vars file for ibgp_update
dry_run: "True"
is_verification_workflow: false
verbs:
- add_pe_to_p # Adds all the existing PEs in the P-GROUP on the newly installed P
- add_p_to_pe # Adds the newly installed P to the P-GROUP in all the existing PEs
- check_p_ibgp
- verify_p_ibgp # Validates the config of BGP stanza including neighbors
- remove_p_from_pe # placeholder for future use | Removes the P that is going to be promoted to PE from the P-GROUP on all PEs
- remove_pe_from_p # PE router termination workflow
- remove_pe_from_pe # When decommissiong a PE we remove it from PE-GROUP and P-GROUP on all the PE and P routers
- add_pe_to_pe # placeholder for future use | Adds the newly installed PE (could be an EX-P or a new PE) to the PE-GROUP on all the other PEs
- add_new_pe_to_p # placeholder for future use | Adds the newly installed PE (could be an EX-P or a new PE) the P-GROUP on all the Ps
- promote_p_to_pe # placeholder for future use | Deletes P-GROUP and adds
- add_pe_to_pe_mesh # placeholder for future use | Adds the newly installed PE (could be an EX-P or a new PE) to the PE-GROUP on all the other PEs
- add_pe_mesh_to_pe # placeholder for future use | Adds the newly installed PE (could be an EX-P or a new PE) the P-GROUP on all the Ps
- check_p_ibgp # Check BGP status on the newly provisioned P router
- check_pe_ibgp # Check BGP status on the newly provisioned PE router
- add_all_p_to_pe # Add P routers to the newly promoted PE router
- add_pe_to_all_p # Add newly promoted PE to all existing P routers
wfo_router: "{{ subscription }}"
p_lo_ipv4_address: "{{ wfo_router.router.router_lo_ipv4_address }}"
p_lo_ipv6_address: "{{ wfo_router.router.router_lo_ipv6_address }}"
p_router_fqdn: "{{ wfo_router.router.router_fqdn }}"
subscription_lo_ipv4: "{{ subscription.router.router_lo_ipv4_address }}"
subscription_lo_ipv6: "{{ subscription.router.router_lo_ipv6_address }}"
subscription_fqdn: "{{ subscription.router.router_fqdn }}"
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
---
# defaults file for promote_p_to_pe
---
# handlers file for promote_p_to_pe
galaxy_info:
author: A. Kurbatov
description: GEANT Orchestration and Automation Team
company: GEANT
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: MIT
min_ansible_version: '2.10'
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
galaxy_tags:
- network
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
- name: Set variable to connect to nokia
ansible.builtin.set_fact:
ansible_network_os: nokia.sros.md
ansible_connection: netconf
- name: Check VPRN BGP summary
block:
- name: Get BGP summary
ansible.netcommon.netconf_rpc:
rpc: action
xmlns: "urn:ietf:params:xml:ns:yang:1"
content: |
<global-operations xmlns="urn:nokia.com:sros:ns:yang:sr:oper-global">
<md-cli-raw-command>
<md-cli-input-line>show router service-name "{{ vprn.name | quote }}" bgp summary</md-cli-input-line>
</md-cli-raw-command>
</global-operations>
display: json
register: out
- name: Show BGP summary for VPRN "{{ vprn.name | quote }}"
ansible.builtin.debug:
msg: "{{out.output['rpc-reply']['nokiaoper:results']['nokiaoper:md-cli-output-block'].split('\n')}}"
- name: Merge the variables
ansible.builtin.include_tasks: merge_variables.yaml
- name: Set ansible host to localhost to compile config when router is offline
when:
subscription.router.router_access_via_ts | ansible.builtin.bool
ansible.builtin.set_fact:
ansible_host: "localhost"
ansible_connection: local
- name: Create a folder for all the things
ansible.builtin.file:
path: "/var/tmp/ansible_run_{{ opid }}"
state: directory
mode: '0755'
delegate_to: localhost
- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/pe_base_config.conf"
when: verb == "deploy_pe_base_config"
ansible.builtin.template:
src: "routers/{{ subscription.router.vendor }}/pe_base_config.j2"
dest: "/var/tmp/ansible_run_{{ opid }}/pe_base_config.conf"
lstrip_blocks: true
trim_blocks: true
mode: '0755'
delegate_to: localhost
- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/pe_base_vprn.conf"
when: verb == "deploy_routing_instances"
ansible.builtin.template:
src: "routers/{{ subscription.router.vendor }}/pe_base_vprn.j2"
dest: "/var/tmp/ansible_run_{{ opid }}/pe_base_vprn.conf"
lstrip_blocks: true
trim_blocks: true
mode: '0755'
- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/pe_update_sdp.conf"
when: verb == "update_sdp_mesh"
ansible.builtin.template:
src: "routers/{{ subscription.router.vendor }}/pe_update_sdp.j2"
dest: "/var/tmp/ansible_run_{{ opid }}/pe_update_sdp.conf"
lstrip_blocks: true
trim_blocks: true
mode: '0755'
delegate_to: localhost
- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/delete_default_static_routes.conf"
when: verb == "delete_default_routes"
ansible.builtin.template:
src: "routers/{{ subscription.router.vendor }}/router/delete_default_static_routes.j2"
dest: "/var/tmp/ansible_run_{{ opid }}/delete_default_static_routes.conf"
lstrip_blocks: true
trim_blocks: true
mode: '0755'
delegate_to: localhost
- name: Set back ansible_host to target terminal server if needed
when:
subscription.router.router_access_via_ts | ansible.builtin.bool
ansible.builtin.set_fact:
ansible_host: "{{ subscription.router.router_site.site_ts_address }}"
ansible_connection: netconf
- name: Deploy ISIS overload on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/router/isis_overload.j2') }}"
commit: true
commit_comment: "{{ commit_comment }}"
diff: true
check_mode: false
- name: Deploy PE base_config on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
when: >-
dry_run | ansible.builtin.bool
and verb == "deploy_pe_base_config"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_base_config.j2') }}"
commit: true
validate: true
diff: true
register: output
check_mode: true
- name: Deploy PE base VPRNs on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
when: >-
dry_run | ansible.builtin.bool
and verb == "deploy_routing_instances"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_base_vprn.j2') }}"
commit: true
validate: true
diff: true
register: output
check_mode: true
- name: Deploy SDP mesh on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
when: >-
dry_run | ansible.builtin.bool
and verb == "update_sdp_mesh"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_update_sdp.j2') }}"
commit: true
validate: true
diff: true
register: output
check_mode: true
- name: Delete default routes on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
when: >-
dry_run | ansible.builtin.bool
and verb == "delete_default_routes"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/router/delete_default_static_routes.j2') }}"
commit: true
validate: true
diff: true
register: output
check_mode: true
# - name: Fail if there is any diff
# ansible.builtin.fail:
# msg: Base config drift detected!!!
# when: >
# output.changed | ansible.builtin.bool
# and
# is_verification_workflow | ansible.builtin.bool
- name: Deploy base_config on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
when: >-
not (dry_run | ansible.builtin.bool) and
verb == "deploy_pe_base_config"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_base_config.j2') }}"
commit: true
commit_comment: "{{ commit_comment }}"
diff: true
check_mode: false
- name: Deploy PE base VPRNs on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
when: >-
not (dry_run | ansible.builtin.bool) and
verb == "deploy_routing_instances"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_base_vprn.j2') }}"
commit: true
commit_comment: "{{ commit_comment }}"
diff: true
check_mode: false
- name: Deploy updated SDP mesh on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
when: >-
not (dry_run | ansible.builtin.bool) and
verb == "update_sdp_mesh"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/pe_update_sdp.j2') }}"
commit: true
commit_comment: "{{ commit_comment }}"
diff: true
check_mode: false
- name: Delete default routes on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
when: >-
not (dry_run | ansible.builtin.bool)
and verb == "delete_default_routes"
geant.gap_ansible.nokia_netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ subscription.router.vendor }}/router/delete_default_static_routes.j2') }}"
commit: true
commit_comment: "{{ commit_comment }}"
diff: true
check_mode: false
---
# tasks file for P to PE
- name: Print the usage
when: (verb is not defined) or (verb not in verbs)
ansible.builtin.debug:
msg:
- "'verb' keyword is mandatory. Usage: -e verb=$verb"
- name: Print defined verbs
when: (verb is not defined) or (verb not in verbs)
ansible.builtin.debug:
msg:
- "Allowed verb: {{ item }}"
loop: "{{ verbs }}"
- name: Stop if arguments are incorrect
when: (verb is not defined) or (verb not in verbs)
ansible.builtin.meta: end_play
- name: Import routers variables
ansible.builtin.include_vars:
dir: /opt/ansible_inventory/group_vars/routers
- name: Import variables from 'all'
ansible.builtin.include_vars:
dir: /opt/ansible_inventory/group_vars/all
- name: Set ansible_host to terminal server when router is offline
when: subscription.router.router_access_via_ts | ansible.builtin.bool
ansible.builtin.set_fact:
ansible_host: "{{ subscription.router.router_site.site_ts_address }}"
ansible_port: "{{ subscription.router.router_ts_port }}"
- name: Load netconf connection config
ansible.builtin.set_fact:
ansible_connection: "{{ netconf_access[subscription.router.vendor].ansible_connection }}"
ansible_network_os: "{{ netconf_access[subscription.router.vendor].ansible_network_os }}"
- name: Generate an ID for this run
ansible.builtin.set_fact:
opid: "{{ lookup('community.general.random_string', length=18, special=false) }}"
- name: Print the ID
ansible.builtin.debug:
msg: "{{ opid }}"
- name: Include ISIS overload tasks
when: verb in ['set_isis_overload', 'remove_isis_overload']
ansible.builtin.include_tasks: configure_isis_overload.yaml
- name: Include templates compilation
when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh' , 'deploy_routing_instances', 'delete_default_routes' ]
ansible.builtin.include_tasks: compile.yaml
- name: Include deploy if selected
when: verb in [ 'deploy_pe_base_config', 'update_sdp_mesh', 'deploy_routing_instances', 'delete_default_routes' ]
ansible.builtin.include_tasks: deploy.yaml
- name: Check VPRNs
when: verb == "check_base_ris"
loop: "{{ pe_vprns }}"
loop_control:
loop_var: vprn
ansible.builtin.include_tasks: check_routing_instances.yaml
#
# Preparation of PE-specific vars. E.g. PE CPM filters are extension of P CPM filters.
#
- name: Merge Nokia P CPM filters
ansible.builtin.set_fact:
cpm_filters: "{{ lookup('community.general.merge_variables', 'cpmf__to_merge', pattern_type='suffix') }}"
- name: Prepare PE-specific base config vars
when: verb == "deploy_pe_base_config"
block:
- name: Merge Nokia PE additional CPM filters
ansible.builtin.set_fact:
pe_cpm: "{{ lookup('community.general.merge_variables', 'cpm_pe__to_merge') }}"
- name: Combine P and PE CPM filters
ansible.builtin.set_fact:
cpm_filters: "{{ [cpm_filters, pe_cpm] | community.general.lists_mergeby('family',
list_merge='append') }}"
- name: Combine P and PE prefix-lists
ansible.builtin.set_fact:
nokia_prefix_lists: "{{ [nokia_prefix_lists, nokia_pe_prefix_lists] | community.general.lists_mergeby('name',
list_merge='append') }}"
- name: Select SDP params for l2ciruit-type
ansible.builtin.set_fact:
sdp_type: "{{ (sdp_types | selectattr('id', 'equalto', '1'))[0] }}"
- name: Prepare PE-specific base config vars
when: verb == "deploy_routing_instances"
block:
- name: Combine P and PE prefix-lists
ansible.builtin.set_fact:
nokia_prefix_lists: "{{ [nokia_prefix_lists, nokia_pe_prefix_lists, nokia_pe_ias_prefix_lists] | community.general.lists_mergeby('name',
list_merge='append') }}"
- name: Select SDP params for l2ciruit (epipe) type
when: verb == "update_sdp_mesh"
ansible.builtin.set_fact:
sdp_type: "{{ (sdp_types | selectattr('id', 'equalto', '1'))[0] }}"
<cflowd xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
<cache-size>{{ cflowd.basic.cache_size }}</cache-size>
<enhanced-distribution>{{ cflowd.basic.enhanced_distribution }}</enhanced-distribution>
<overflow>{{ cflowd.basic.overflow }}</overflow>
<template-retransmit>{{ cflowd.basic.template_retransmit }}</template-retransmit>
<active-flow-timeout>{{ cflowd.basic.active_flow_timeout }}</active-flow-timeout>
<inactive-flow-timeout>{{ cflowd.basic.inactive_flow_timeout }}</inactive-flow-timeout>
{% if cflowd.sample_profiles is defined %}
{% for profile in cflowd.sample_profiles %}
<sample-profile>
<profile-id>{{ profile.id }}</profile-id>
<sample-rate>{{ profile.sample_rate }}</sample-rate>
<metering-process>{{ profile.metering_process }}</metering-process>
</sample-profile>
{% endfor %}
{% endif %}
{% if cflowd.collectors is defined %}
{% for collector in cflowd.collectors %}
<collector>
<ip-address>{{ collector.ip }}</ip-address>
<port>{{ collector.port }}</port>
<description>{{ collector.description }}</description>
<template-set>{{ collector.template_set }}</template-set>
<version>{{ collector.version }}</version>
</collector>
{% endfor %}
{% endif %}
</cflowd>
<filter xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
{% if pe_filter_logs is defined %}
{% for log in pe_filter_logs %}
<log alu:operation="replace">
<log-id>{{ log.id }}</log-id>
<description>{{ log.description }}</description>
<destination>
{% if log.destination == 'syslog' %}
<syslog>
<name>1</name>
</syslog>
{% endif %}
</destination>
</log>
{% endfor %}
{% endif %}
</filter>
{% with is_cpm_filter=true, filters=cpm_filters %}
{% include "filters/port_list_definitions.j2" %}
<system>
<security>
<cpm-filter xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
<default-action>{{ cpm_filter_policy.default_action }}</default-action>
{% include "filters/fw_filters.j2" %}
</cpm-filter>
{% endwith %}
</security>
</system>
{# Template is meant to be called from either gen_filters.j2 or cmp_filters.j2 #}
{% for filter in filters %}
{% if filter.family == "ipv4" %}
<ip-filter alu:operation="replace">
{% elif filter.family == "ipv6" %}
<ipv6-filter alu:operation="replace">
{% endif %}
{% if not is_cpm_filter %}
<filter-name>{{ filter.name }}</filter-name>
{% endif %}
{% if filter.offset is defined %}
{% set ns3 = namespace(entry_id = filter.offset | int) %}
{% else %}
{% set ns3 = namespace(entry_id = 10 | int) %}
{% endif %}
{% if is_cpm_filter %}
<admin-state>{{ filter.admin_state }}</admin-state>
{% endif %}
{% for term in filter.terms %}
{% if term.offset is defined %}
{% set ns3 = namespace(entry_id = term.offset | int) %}
{% endif %}
{% if term.from is not defined %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<action>
<{{term.action}}></{{term.action}}>
</action>
</entry>
{% endif %}
{% if term.from is defined %}
{# This is the case for TCP_ESTABLISHED #}
{% if term.from.protocol is defined and term.from.protocol == "tcp" and term.from.tcp_flag is defined %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if filter.family == "ipv4" %}
<protocol>{{ term.from.protocol }}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
<tcp-flags>
<{{ term.from.tcp_flag }}>true</{{ term.from.tcp_flag }}>
</tcp-flags>
</match>
<action>
<{{ term.action }}></{{ term.action }}>
</action>
</entry>
{% set ns3.entry_id = ns3.entry_id + 10 %}
{% endif %}
{# This is to cover CPM-ipv6 ND case where dst_prefix_list is defined, but not src_prefix_list #}
{% if term.from.protocol is defined and term.from.protocol == "ipv6-icmp" and term.from.dst_prefix_list is defined %}
{% for dst_prefix_list_item in term.from.dst_prefix_list %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
<next-header>{{ term.from.protocol }}</next-header>
<dst-ip>
<ipv6-prefix-list>{{term.from.dst_prefix_list[loop.index0]}}</ipv6-prefix-list>
</dst-ip>
</match>
<action>
<{{ term.action }}></{{ term.action }}>
</action>
</entry>
{% set ns3.entry_id = ns3.entry_id + 10 %}
{% endfor %}
{% endif %}
{# Generic ICMP filters with ICMP types #}
{% if term.from.protocol is defined and (term.from.protocol == "icmp" or term.from.protocol == "ipv6-icmp") %}
{% if term.from.icmp_types is defined %}
{% for icmp_type in term.from.icmp_types %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if filter.family == "ipv4" %}
<protocol>{{ term.from.protocol }}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
<icmp>
<type>{{ icmp_type }}</type>
</icmp>
</match>
<action>
<{{ term.action }}></{{ term.action }}>
</action>
</entry>
{% set ns3.entry_id = ns3.entry_id + 10 %}
{% endfor %}
{% endif %}
{% endif %}
{# Case when only need to match on protocol, e.g. PIM #}
{% if term.from.protocol is defined and term.from.protocol in ['pim', '58'] %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if filter.family == "ipv4" %}
<protocol>{{ term.from.protocol }}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
</match>
<action>
<{{ term.action }}></{{ term.action }}>
</action>
</entry>
{% set ns3.entry_id = ns3.entry_id + 10 %}
{% endif %}
{# Case when both src_prefix_list and dst_prefix_list are defined #}
{% if term.from.src_prefix_list is defined %}
{% for src_prefix_list_item in term.from.src_prefix_list%}
{% set src_index = loop.index0 %}
{% if term.from.dst_prefix_list is defined %}
{% for dst_prefix_list_item in term.from.dst_prefix_list %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if term.from.protocol is defined %}
{% if filter.family == "ipv4" %}
<protocol>{{term.from.protocol}}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
{% endif %}
{% include 'filters/port_list_entries.j2' %}
<src-ip>
{% if filter.family == "ipv4" %}
<ip-prefix-list>{{term.from.src_prefix_list[src_index]}}</ip-prefix-list>
{% else %}
<ipv6-prefix-list>{{term.from.src_prefix_list[src_index]}}</ipv6-prefix-list>
{% endif %}
</src-ip>
<dst-ip>
{% if filter.family == "ipv4" %}
<ip-prefix-list>{{term.from.dst_prefix_list[loop.index0]}}</ip-prefix-list>
{% else %}
<ipv6-prefix-list>{{term.from.dst_prefix_list[loop.index0]}}</ipv6-prefix-list>
{% endif %}
</dst-ip>
</match>
{% set ns3.entry_id = ns3.entry_id + 10 %}
<action>
<{{term.action}}></{{term.action}}>
</action>
</entry>
{% endfor %}
{% else %}
{# This is the case of CPM-filters, where destination prefix is not defined #}
<entry>
<entry-id> {{ ns3.entry_id }} </entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if term.from.protocol is defined %}
{% if filter.family == "ipv4" %}
<protocol>{{term.from.protocol}}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
{% endif %}
{% include 'filters/port_list_entries.j2' %}
<src-ip>
{% if filter.family == "ipv4" %}
<ip-prefix-list>{{term.from.src_prefix_list[src_index]}}</ip-prefix-list>
{% else %}
<ipv6-prefix-list>{{term.from.src_prefix_list[src_index]}}</ipv6-prefix-list>
{% endif %}
</src-ip>
</match>
{% set ns3.entry_id = ns3.entry_id + 10 %}
<action>
<{{term.action}}></{{term.action}}>
</action>
</entry>
{% endif %}
{% endfor %}
{% endif %}
{# Case where only DST prefix list is defined #}
{% if term.from.dst_prefix_list is defined %}
{% for dst_prefix_list_item in term.from.dst_prefix_list %}
<entry>
<entry-id>{{ ns3.entry_id }}</entry-id>
<description>{{ term.name }}</description>
{% if term.log is defined %}
<log>{{ term.log }}</log>
{% endif %}
<match>
{% if term.from.protocol is defined %}
{% if filter.family == "ipv4" %}
<protocol>{{term.from.protocol}}</protocol>
{% else %}
<next-header>{{ term.from.protocol }}</next-header>
{% endif %}
{% endif %}
{% include 'filters/port_list_entries.j2' %}
<dst-ip>
{% if filter.family == "ipv4" %}
<ip-prefix-list>{{term.from.dst_prefix_list[loop.index0]}}</ip-prefix-list>
{% else %}
<ipv6-prefix-list>{{term.from.dst_prefix_list[loop.index0]}}</ipv6-prefix-list>
{% endif %}
</dst-ip>
</match>
{% set ns3.entry_id = ns3.entry_id + 10 %}
<action>
<{{term.action}}></{{term.action}}>
</action>
</entry>
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
{# Terms end #}
{% if filter.family == "ipv4" %}
</ip-filter>
{% elif filter.family == "ipv6" %}
</ipv6-filter>
{% endif %}
{% endfor %}
{# This template takes care of configuring connectors and breakouts #}
{% with is_cpm_filter=False, filters=gen_filters %}
{% include "filters/port_list_definitions.j2" %}
<filter xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
{% include "filters/fw_filters.j2" %}
</filter>
{% endwith %}
{# This template takes care of configuring connectors and breakouts #}
<filter xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
<match-list>
{% for filter in filters %}
{% for term in filter.terms %}
{% if term.from.port is defined and term.from.port.__class__.__name__ == 'list'%}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-PORTS</port-list-name>
{%for port in term.from.port %}
<port>
<value>{{port}}</value>
</port>
{% endfor %}
</port-list>
{% endif %}
{% if term.from.src_port is defined and term.from.src_port.__class__.__name__ == 'list'%}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-SRC_PORTS</port-list-name>
{%for port in term.from.src_port %}
<port>
<value>{{port}}</value>
</port>
{% endfor %}
</port-list>
{% endif %}
{% if term.from.dst_port is defined and term.from.dst_port.__class__.__name__ == 'list'%}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-DST_PORTS</port-list-name>
{%for port in term.from.dst_port %}
<port>
<value>{{port}}</value>
</port>
{% endfor %}
</port-list>
{% endif %}
{% if term.from.port_range is defined %}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-PORT_RANGE</port-list-name>
<range>
<start>{{ term.from.port_range.start }}</start>
<end>{{ term.from.port_range.end }}</end>
</range>
</port-list>
{% endif %}
{% if term.from.src_port_range is defined %}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-SRC_PORT_RANGE</port-list-name>
<range>
<start>{{ term.from.src_port_range.start }}</start>
<end>{{ term.from.src_port_range.end }}</end>
</range>
</port-list>
{% endif %}
{% if term.from.dst_port_range is defined %}
<port-list>
<port-list-name>{{filter.name}}-{{term.name}}-DST_PORT_RANGE</port-list-name>
<range>
<start>{{ term.from.dst_port_range.start }}</start>
<end>{{ term.from.dst_port_range.end }}</end>
</range>
</port-list>
{% endif %}
{% endfor %}
{% endfor %}
</match-list>
</filter>
{#This is the case it's a port-list #}
{% if term.from.port is defined and term.from.port.__class__.__name__ == 'list'%}
<port>
<port-list>{{filter.name}}-{{term.name}}-PORTS</port-list>
</port>
{% endif %}
{% if term.from.src_port is defined and term.from.src_port.__class__.__name__ == 'list'%}
<src-port>
<port-list>{{filter.name}}-{{term.name}}-SRC_PORTS</port-list>
</src-port>
{% endif %}
{% if term.from.dst_port is defined and term.from.dst_port.__class__.__name__ == 'list'%}
<dst-port>
<port-list>{{filter.name}}-{{term.name}}-DST_PORTS</port-list>
</dst-port>
{% endif %}
{#This is the case it's a single port #}
{% if term.from.port is defined and term.from.port.__class__.__name__ != 'list'%}
<port>
<eq>{{term.from.port}}</eq>
</port>
{% endif %}
{% if term.from.src_port is defined and term.from.src_port.__class__.__name__ != 'list'%}
<src-port>
<eq>{{term.from.src_port}}</eq>
</src-port>
{% endif %}
{% if term.from.dst_port is defined and term.from.dst_port.__class__.__name__ != 'list'%}
<dst-port>
<eq>{{term.from.dst_port}}</eq>
</dst-port>
{% endif %}
{# Port range #}
{% if term.from.port_range is defined %}
<port>
<port-list>{{filter.name}}-{{term.name}}-PORT_RANGE</port-list>
</port>
{% endif %}
{% if term.from.src_port_range is defined %}
<src-port>
<port-list>{{filter.name}}-{{term.name}}-SRC_PORT_RANGE</port-list>
</src-port>
{% endif %}
{% if term.from.dst_port_range is defined %}
<dst-port>
<port-list>{{filter.name}}-{{term.name}}-DST_PORT_RANGE</port-list>
</dst-port>
{% endif %}
../../../../base_config/templates/routers/nokia/ip_prefix_list.j2
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment