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

SR Linux: prefix filters and match.prefix in routing policies #1311

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
64 changes: 49 additions & 15 deletions netsim/ansible/templates/routing/srlinux.j2
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
updates:
{#
Prefix filters
#}
{% for pf_name,pf_list in routing.prefix|default({})|items %}
- path: /routing-policy/prefix-set[name={{ pf_name }}]
value:
prefix:
{% for p_entry in pf_list %}{# Iterate over prefix list entries #}
{% for p_af in af if p_af in p_entry %}{# Iterate over address families in the prefix list entry #}
- ip-prefix: {{ p_entry[p_af] }}
{% if p_entry.min[p_af] is defined or p_entry.max[p_af] is defined %}
mask-length-range: {{
p_entry.min[p_af]|default(p_entry[p_af]|ipaddr('prefix')) }}..{{
p_entry.max[p_af]|default(32 if p_af == 'ipv4' else 128) }}
{% else %}
mask-length-range: exact
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}

{#
Routing policies
#}
{% for rp_name,rp_list in routing.policy|default({})|items %}
- path: /routing-policy/policy[name={{ rp_name }}]
value:
statement:
{% for entry in rp_list %}
- name: rpe_{{ entry.sequence }}
action:
policy-result: accept
bgp:
{% if 'locpref' in entry.set %}
local-preference:
set: {{ entry.set.locpref }}
{% endif %}
{% if 'med' in entry.set %}
med:
set: {{ entry.set.med }}
{% endif %}
{% endfor %}
default-action:
policy-result: reject
statement:
{% for entry in rp_list %}
- name: rpe_{{ entry.sequence }}
{% if 'match' in entry %}
match:
{% if entry.match.prefix is defined %}
prefix-set: {{ entry.match.prefix }}
{% endif %}
{% endif %}
action:
policy-result: {{ 'accept' if entry.action == 'permit' else 'reject' }}
{% if entry.set.locpref is defined or entry.set.med is defined %}
bgp:
{% if 'locpref' in entry.set %}
local-preference:
set: {{ entry.set.locpref }}
{% endif %}
{% if 'med' in entry.set %}
med:
set: {{ entry.set.med }}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
17 changes: 15 additions & 2 deletions netsim/devices/srlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
from . import _Quirks,need_ansible_collection
from ..utils import log

def check_prefix_deny(node: Box) -> None:
for pf_name,pf_list in node.get('routing.prefix',{}).items():
for p_entry in pf_list:
if p_entry.get('action',None) == 'deny':
log.error(
f'SR Linux does not support "deny" action in prefix filters (node {node.name} prefix filter {pf_name})',
log.IncorrectValue,
'quirks')
break

class SRLINUX(_Quirks):

@classmethod
Expand All @@ -26,7 +36,7 @@ def device_quirks(self, node: Box, topology: Box) -> None:
if len(vrf['import']) > 1 or len(vrf['export']) > 1:
if 'evpn' not in mods:
log.error(
f'Inter-VRF route leaking on ({node.name}) only supported in combination with BGP EVPN.\n',
f'Inter-VRF route leaking on ({node.name}) only supported in combination with BGP EVPN',
log.IncorrectType,
'quirks')
break
Expand All @@ -42,7 +52,7 @@ def device_quirks(self, node: Box, topology: Box) -> None:
for c,vals in topology.get('bgp.community',[]).items():
if 'extended' not in vals:
log.error(
f'SR Linux on ({node.name}) does not support filtering out extended communities for BGP. {c}:{vals}\n',
f'SR Linux on ({node.name}) does not support filtering out extended communities for BGP. {c}:{vals}',
Warning,
'quirks')

Expand All @@ -53,5 +63,8 @@ def device_quirks(self, node: Box, topology: Box) -> None:
log.IncorrectValue,
'quirks')

if 'routing' in mods and node.get('routing.prefix',None):
check_prefix_deny(node)

def check_config_sw(self, node: Box, topology: Box) -> None:
need_ansible_collection(node,'nokia.srlinux',version='0.5.0')
3 changes: 3 additions & 0 deletions netsim/devices/srlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ features:
default: true
routing:
policy:
match:
prefix: True
set: [ locpref, med ]
prefix: True
sr: True
vlan:
model: router
Expand Down
8 changes: 6 additions & 2 deletions netsim/extra/bgp.policy/srlinux.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
- path: /network-instance[name={{vrf}}]/protocols/bgp/group[group-name=intf-{{ n.local_if }}]/{{ p_path }}
{% else %}
- path: /network-instance[name={{vrf}}]/protocols/bgp/neighbor[peer-address={{ n[af]|ipaddr('address') }}]/{{ p_path }}
{% endif %}
{% endif %}
{% if direction == 'out' %}
value: [ {{ vrf }}_bgp_export, {{ n.policy[direction] }} ]
{% endfor %}
{% else %}
value: [ {{ n.policy[direction] }} ]
{% endif %}
{% endfor %}
{%- endmacro %}

replace:
Expand Down