Skip to content

Commit

Permalink
frr: T6747: migrate protocols to unified FRRender class
Browse files Browse the repository at this point in the history
With FRR 10.0 daemons started to be migrated to integrated FRR mgmtd and a
northbound interface. This led to some drawbacks in the current state how
changes to FRR are handled. The current implementation will use frr-reload.py
and specifies excatly WHICH daemon needs a config update and will only replace
this part inside FRR.

With FRR10 and mgmtd when a partial configuration is sent to mgmtd, it will
remove configuration parts from other daemons like bgpd or ospfd which have
not yet been migrated to mgmtd.

It's not possible to call frr-reload.py with daemon mgmtd - it will error out.

This commit will also change the CLI for static routes:

CLI command "set protocols static route 10.0.0.0/8 next-hop 1.2.3.4 bfd multi-hop
source 1.1.1.1" will be split into:
* set protocols static route 10.0.0.0/8 next-hop 1.2.3.4 bfd source-address 1.1.1.1
* set protocols static route 10.0.0.0/8 next-hop 1.2.3.4 bfd multi-hop

To make the XML blocks reusable, and comply with the FRR CLI - this was actually
a wrong implementation from the beginning as you can not have multiple BFD
source addresses.

CLI command "set protocols static route 10.0.0.0/8 next-hop 1.2.3.4 bfd multi-hop
source 1.1.1.1 profile bar" is changed to:
* set protocols static route 10.0.0.0/8 next-hop 1.2.3.4 bfd profile bar

CLI commands "set protocols static multicast interface-route" is moved to:
* set protocols static multicast route <x.x.x.x/x> interface

To have an identical look and feel with regular static routes.
  • Loading branch information
c-po committed Dec 8, 2024
1 parent fa487c6 commit 8c2ad58
Show file tree
Hide file tree
Showing 41 changed files with 1,376 additions and 1,418 deletions.
14 changes: 10 additions & 4 deletions data/templates/frr/bgpd.frr.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{### MACRO definition for recurring peer patter, this can be either fed by a ###}
{### peer-group or an individual BGP neighbor ###}
{% macro bgp_neighbor(neighbor, config, peer_group=false) %}
{# BGP order or peer-group and remote-as placement must be honored #}
{% if peer_group == true %}
neighbor {{ neighbor }} peer-group
{% elif config.peer_group is vyos_defined %}
neighbor {{ neighbor }} peer-group {{ config.peer_group }}
{% endif %}
{% if config.remote_as is vyos_defined %}
{% if config.remote_as is vyos_defined %}
neighbor {{ neighbor }} remote-as {{ config.remote_as }}
{% endif %}
{% else %}
{% if config.remote_as is vyos_defined %}
neighbor {{ neighbor }} remote-as {{ config.remote_as }}
{% endif %}
{% if config.peer_group is vyos_defined %}
neighbor {{ neighbor }} peer-group {{ config.peer_group }}
{% endif %}
{% endif %}
{% if config.local_role is vyos_defined %}
{% for role, strict in config.local_role.items() %}
Expand Down
28 changes: 16 additions & 12 deletions data/templates/frr/evpn.mh.frr.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
!
interface {{ ifname }}
{% if evpn.es_df_pref is vyos_defined %}
evpn mh es-df-pref {{ evpn.es_df_pref }}
{% endif %}
{% if evpn.es_id is vyos_defined %}
evpn mh es-id {{ evpn.es_id }}
{% endif %}
{% if evpn.es_sys_mac is vyos_defined %}
evpn mh es-sys-mac {{ evpn.es_sys_mac }}
{% endif %}
{% if evpn.uplink is vyos_defined %}
{% if interfaces is vyos_defined %}
{% for if_name, if_config in interfaces.items() %}
interface {{ if_name }}
{% if if_config.evpn.es_df_pref is vyos_defined %}
evpn mh es-df-pref {{ if_config.evpn.es_df_pref }}
{% endif %}
{% if if_config.evpn.es_id is vyos_defined %}
evpn mh es-id {{ if_config.evpn.es_id }}
{% endif %}
{% if if_config.evpn.es_sys_mac is vyos_defined %}
evpn mh es-sys-mac {{ if_config.evpn.es_sys_mac }}
{% endif %}
{% if if_config.evpn.uplink is vyos_defined %}
evpn mh uplink
{% endif %}
{% endif %}
exit
!
{% endfor %}
{% endif %}
1 change: 1 addition & 0 deletions data/templates/frr/fabricd.frr.j2
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ router openfabric {{ name }}
exit
!
{% endfor %}
!
11 changes: 0 additions & 11 deletions data/templates/frr/static_mcast.frr.j2

This file was deleted.

29 changes: 0 additions & 29 deletions data/templates/frr/static_routes_macro.j2

This file was deleted.

95 changes: 86 additions & 9 deletions data/templates/frr/staticd.frr.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,75 @@
{% from 'frr/static_routes_macro.j2' import static_routes %}
{# Common macro for recurroiing options for a static route #}
{% macro route_options(route, interface_or_next_hop, config, table) %}
{# j2lint: disable=jinja-statements-delimeter #}
{% set ip_route = route ~ ' ' ~ interface_or_next_hop %}
{% if config.interface is vyos_defined %}
{% set ip_route = ip_route ~ ' ' ~ config.interface %}
{% endif %}
{% if config.tag is vyos_defined %}
{% set ip_route = ip_route ~ ' tag ' ~ config.tag %}
{% endif %}
{% if config.distance is vyos_defined %}
{% set ip_route = ip_route ~ ' ' ~ config.distance %}
{% endif %}
{% if config.bfd is vyos_defined %}
{% set ip_route = ip_route ~ ' bfd' %}
{% if config.bfd.multi_hop is vyos_defined %}
{% set ip_route = ip_route ~ ' multi-hop' %}
{% if config.bfd.source_address is vyos_defined %}
{% set ip_route = ip_route ~ ' source ' ~ config.bfd.source_address %}
{% endif %}
{% endif %}
{% if config.bfd.profile is vyos_defined %}
{% set ip_route = ip_route ~ ' profile ' ~ config.bfd.profile %}
{% endif %}
{% endif %}
{% if config.vrf is vyos_defined %}
{% set ip_route = ip_route ~ ' nexthop-vrf ' ~ config.vrf %}
{% endif %}
{% if config.segments is vyos_defined %}
{# Segments used in/for SRv6 #}
{% set ip_route = ip_route ~ ' segments ' ~ config.segments %}
{% endif %}
{# Routing table to configure #}
{% if table is vyos_defined %}
{% set ip_route = ip_route ~ ' table ' ~ table %}
{% endif %}
{{ ip_route }}
{%- endmacro -%}
{# Build static IPv4/IPv6 route #}
{% macro static_routes(ip_ipv6, prefix, prefix_config, table=None) %}
{% set route = ip_ipv6 ~ 'route ' ~ prefix %}
{% if prefix_config.interface is vyos_defined %}
{% for interface, interface_config in prefix_config.interface.items() if interface_config.disable is not defined %}
{{ route_options(route, interface, interface_config, table) }}
{% endfor %}
{% endif %}
{% if prefix_config.next_hop is vyos_defined and prefix_config.next_hop is not none %}
{% for next_hop, next_hop_config in prefix_config.next_hop.items() if next_hop_config.disable is not defined %}
{{ route_options(route, next_hop, next_hop_config, table) }}
{% endfor %}
{% endif %}
{% if prefix_config.dhcp_interface is vyos_defined %}
{% set next_hop = prefix_config.dhcp_interface | get_dhcp_router %}
{% if next_hop is vyos_defined %}
{{ ip_ipv6 }} route {{ prefix }} {{ next_hop }} {{ prefix_config.dhcp_interface }} {{ 'table ' ~ table if table is vyos_defined }}
{% endif %}
{% endif %}
{% if prefix_config.blackhole is vyos_defined %}
{{ route_options(route, 'blackhole', prefix_config.blackhole, table) }}
{% elif prefix_config.reject is vyos_defined %}
{{ route_options(route, 'reject', prefix_config.reject, table) }}
{% endif %}
{# j2lint: disable=jinja-statements-delimeter #}
{%- endmacro -%}
!
{% set ip_prefix = 'ip' %}
{% set ipv6_prefix = 'ipv6' %}
{% set ip_prefix = 'ip ' %}
{% set ipv6_prefix = 'ipv6 ' %}
{% if vrf is vyos_defined %}
{# We need to add an additional whitespace in front of the prefix #}
{# when VRFs are in use, thus we use a variable for prefix handling #}
{% set ip_prefix = ' ip' %}
{% set ipv6_prefix = ' ipv6' %}
{% set ip_prefix = ' ip ' %}
{% set ipv6_prefix = ' ipv6 ' %}
vrf {{ vrf }}
{% endif %}
{# IPv4 routing #}
Expand Down Expand Up @@ -47,19 +110,33 @@ exit-vrf
{% for table_id, table_config in table.items() %}
{% if table_config.route is vyos_defined %}
{% for prefix, prefix_config in table_config.route.items() %}
{{ static_routes('ip', prefix, prefix_config, table_id) }}
{% endfor %}
{{ static_routes('ip ', prefix, prefix_config, table_id) }}
{# j2lint: disable=jinja-statements-delimeter #}
{%- endfor %}
{% endif %}
!
{% if table_config.route6 is vyos_defined %}
{% for prefix, prefix_config in table_config.route6.items() %}
{{ static_routes('ipv6', prefix, prefix_config, table_id) }}
{% endfor %}
{{ static_routes('ipv6 ', prefix, prefix_config, table_id) }}
{# j2lint: disable=jinja-statements-delimeter #}
{%- endfor %}
{% endif %}
!
{% endfor %}
{% endif %}
!
{# Multicast route #}
{% if multicast is vyos_defined %}
{% set ip_prefix = 'ip m' %}
{# IPv4 multicast routing #}
{% if multicast.route is vyos_defined %}
{% for prefix, prefix_config in multicast.route.items() %}
{{ static_routes(ip_prefix, prefix, prefix_config) }}
{# j2lint: disable=jinja-statements-delimeter #}
{%- endfor %}
{% endif %}
{% endif %}
!
{% if route_map is vyos_defined %}
ip protocol static route-map {{ route_map }}
!
Expand Down
2 changes: 1 addition & 1 deletion data/templates/frr/zebra.vrf.route-map.frr.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ vrf {{ vrf }}
vni {{ vrf_config.vni }}
{% endif %}
exit-vrf
{% endfor %}
!
{% endfor %}
{% endif %}
2 changes: 1 addition & 1 deletion interface-definitions/include/source-address-ipv4.xml.i
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- include start from source-address-ipv4.xml.i -->
<leafNode name="source-address">
<properties>
<help>IPv4 source address used to initiate connection</help>
<help>IPv4 address used to initiate connection</help>
<completionHelp>
<script>${vyos_completion_dir}/list_local_ips.sh --ipv4</script>
</completionHelp>
Expand Down
17 changes: 17 additions & 0 deletions interface-definitions/include/source-address-ipv6.xml.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- include start from source-address-ipv6.xml.i -->
<leafNode name="source-address">
<properties>
<help>IPv6 address used to initiate connection</help>
<completionHelp>
<script>${vyos_completion_dir}/list_local_ips.sh --ipv6</script>
</completionHelp>
<valueHelp>
<format>ipv6</format>
<description>IPv6 source address</description>
</valueHelp>
<constraint>
<validator name="ipv6-address"/>
</constraint>
</properties>
</leafNode>
<!-- include end -->
8 changes: 8 additions & 0 deletions interface-definitions/include/static/bfd-multi-hop.xml.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- include start from static/bfd-multi-hop.xml.i -->
<leafNode name="multi-hop">
<properties>
<help>Enable BFD multi-hop session (requires source-address)</help>
<valueless/>
</properties>
</leafNode>
<!-- include end -->
36 changes: 0 additions & 36 deletions interface-definitions/include/static/static-route-bfd.xml.i

This file was deleted.

12 changes: 10 additions & 2 deletions interface-definitions/include/static/static-route.xml.i
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@
#include <include/static/static-route-distance.xml.i>
#include <include/static/static-route-interface.xml.i>
#include <include/static/static-route-vrf.xml.i>
#include <include/static/static-route-bfd.xml.i>
<node name="bfd">
<properties>
<help>BFD monitoring</help>
</properties>
<children>
#include <include/bfd/profile.xml.i>
#include <include/static/bfd-multi-hop.xml.i>
#include <include/source-address-ipv4.xml.i>
</children>
</node>
</children>
</tagNode>
</children>
</tagNode>
<!-- include end -->

11 changes: 10 additions & 1 deletion interface-definitions/include/static/static-route6.xml.i
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@
</properties>
<children>
#include <include/generic-disable-node.xml.i>
#include <include/static/static-route-bfd.xml.i>
#include <include/static/static-route-distance.xml.i>
#include <include/static/static-route-interface.xml.i>
#include <include/static/static-route-segments.xml.i>
#include <include/static/static-route-vrf.xml.i>
<node name="bfd">
<properties>
<help>BFD monitoring</help>
</properties>
<children>
#include <include/bfd/profile.xml.i>
#include <include/static/bfd-multi-hop.xml.i>
#include <include/source-address-ipv6.xml.i>
</children>
</node>
</children>
</tagNode>
</children>
Expand Down
Loading

0 comments on commit 8c2ad58

Please sign in to comment.