Skip to content

[VRF]: FRR config templates support VRF #3047

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
103 changes: 84 additions & 19 deletions dockers/docker-fpm-frr/bgpd.conf.default.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% block bgp %}
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}
{% block bgp_init %}
{# block bgp_init #}
!
! bgp multiple-instance
!
Expand Down Expand Up @@ -28,7 +29,53 @@ route-map FROM_BGPMON_V4 deny 10
route-map TO_BGPMON_V4 permit 10
!
{% endif %}
{% set vrf_lo_intf = {} %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% set intf_vrf = 'global' %}
{% if LOOPBACK_INTERFACE.has_key(name) and LOOPBACK_INTERFACE[name].has_key('vrf_name') %}
{% set intf_vrf = LOOPBACK_INTERFACE[name]['vrf_name'] %}
{% endif %}
{% if vrf_lo_intf.has_key(intf_vrf) or vrf_lo_intf.update({intf_vrf:[]}) %}
{% endif %}
{% if name not in vrf_lo_intf[intf_vrf] and vrf_lo_intf[intf_vrf].append(name) %}
{% endif %}
{% endfor %}
{% set vrf_routers = [] %}
{% set vrf_bgp_nbr = {} %}
{% for nbr_key in BGP_NEIGHBOR %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to put this into bgpd.peer template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can not move out because peer-group PEER_V4/PEER_V6 need config in these vrfs.

{% if nbr_key | length == 2 %}
{% set nbr_vrf = nbr_key[0] %}
{% set nbr_addr = nbr_key[1] %}
{% else %}
{% set nbr_vrf = 'global' %}
{% set nbr_addr = nbr_key %}
{% endif %}
{% if nbr_vrf in vrf_routers or vrf_routers.append(nbr_vrf) %}
{% endif %}
{% if vrf_bgp_nbr.has_key(nbr_vrf) or vrf_bgp_nbr.update({nbr_vrf:{}}) %}
{% endif %}
{% if vrf_bgp_nbr[nbr_vrf].update({nbr_addr:BGP_NEIGHBOR[nbr_key]}) %}
{% endif %}
{% endfor %}
{% set vrf_bgp_pr = {} %}
{% for pr_key in BGP_PEER_RANGE %}
{% set pr_vrf = 'global' %}
{% if BGP_PEER_RANGE[pr_key].has_key('vrf_name') %}
{% set pr_vrf = BGP_PEER_RANGE[pr_key]['vrf_name'] %}
{% endif %}
{% if pr_vrf not in vrf_routers and vrf_routers.append(pr_vrf) %}
{% endif %}
{% if vrf_bgp_pr.has_key(pr_vrf) or vrf_bgp_pr.update({pr_vrf:{}}) %}
{% endif %}
{% if vrf_bgp_pr[pr_vrf].update({pr_key:BGP_PEER_RANGE[pr_key]}) %}
{% endif %}
{% endfor %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to put all the code inside of bgpcfgd?
Currently this change put a huge amount of logic inside of the jinja2.
Can we put all the logic into bgpcfgd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not just peer_range, there are configs even peer. If to aware vrf in conf, we have to loop all vrfs. Now vrfs get from BGP_NEIGHBOR and BGP_PEER_RANGE. Theoretically speaking, all can be put into bgpcfgd, then no j2 template left. But that would be a huge work.

{% for vrf in vrf_routers|sort %}
{% if vrf == 'global' %}
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% else %}
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} vrf {{ vrf }}
{% endif %}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast
Expand All @@ -37,36 +84,46 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
bgp graceful-restart preserve-fw-state
{% endif %}
{% set vrf_lo0 = "" %}
{% if vrf_lo_intf[vrf] | length > 0 %}
{% set vrf_lo0 = vrf_lo_intf[vrf][0] %}
{% endif %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
{% if prefix | ipv4 and name == vrf_lo0 %}
bgp router-id {{ prefix | ip }}
{% endif %}
{% endfor %}
{# advertise loopback #}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
{% if prefix | ipv4 and name == vrf_lo0 %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
{% elif prefix | ipv6 and name == vrf_lo0 %}
address-family ipv6
network {{ prefix | ip }}/64
exit-address-family
{% endif %}
{% endfor %}
{% endblock bgp_init %}
{% endif %}
{% block vlan_advertisement %}
{# endblock bgp_init #}
{# block vlan_advertisement #}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% set vlan_intf_vrf = 'global' %}
{% if VLAN_INTERFACE.has_key(name) and VLAN_INTERFACE[name].has_key('vrf_name') %}
{% set vlan_intf_vrf = VLAN_INTERFACE[name]['vrf_name'] %}
{% endif %}
{% if vlan_intf_vrf == vrf %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
address-family ipv6
network {{ prefix }}
exit-address-family
{% endif %}
{% endif %}
{% endfor %}
{% endblock vlan_advertisement %}
{% block bgp_sessions %}
{% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %}
{# endblock vlan_advertisement #}
{# block bgp_sessions #}
{% if vrf_bgp_nbr.has_key(vrf) %}
{% for neighbor_addr, bgp_session in vrf_bgp_nbr[vrf]|dictsort %}
{% if bgp_session['asn'] | int != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
Expand Down Expand Up @@ -121,10 +178,11 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %}
{% endif %}
{% endfor %}
{% endblock bgp_sessions %}
{% block bgp_peers_with_range %}
{% if BGP_PEER_RANGE %}
{% for bgp_peer in BGP_PEER_RANGE.values() %}
{% endif %}
{# endblock bgp_sessions #}
{# block bgp_peers_with_range #}
{% if vrf_bgp_pr.has_key(vrf) %}
{% for peer_key, bgp_peer in vrf_bgp_pr[vrf]|dictsort %}
neighbor {{ bgp_peer['name'] }} peer-group
neighbor {{ bgp_peer['name'] }} passive
{% if bgp_peer['peer_asn'] is defined %}
Expand All @@ -137,8 +195,12 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_peer['src_address'] is defined %}
neighbor {{ bgp_peer['name'] }} update-source {{ bgp_peer['src_address'] | ip }}
{% else %}
{% set vrf_lo1 = "" %}
{% if vrf_lo_intf[vrf] | length > 1 %}
{% set vrf_lo1 = vrf_lo_intf[vrf][1] %}
{% endif %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback1' %}
{% if name == vrf_lo1 %}
neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }}
{% endif %}
{% endfor %}
Expand All @@ -158,12 +220,12 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
exit-address-family
{% endfor %}
{% endif %}
{% endblock bgp_peers_with_range %}
{% block bgp_monitors %}
{# endblock bgp_peers_with_range #}
{# block bgp_monitors #}
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
neighbor BGPMON_V4 peer-group
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
{% if prefix | ipv4 and name == vrf_lo0 %}
neighbor BGPMON_V4 update-source {{ prefix | ip }}
{% endif %}
{% endfor %}
Expand All @@ -178,5 +240,8 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ neighbor_addr }} activate
{% endfor %}
{% endif %}
{% endblock bgp_monitors %}
{# endblock bgp_monitors #}
!
{% endfor %}
{% endif %}
{% endblock bgp %}
2 changes: 0 additions & 2 deletions dockers/docker-fpm-frr/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ agentx
{% endif %}
!
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}
maximum-paths 64
!
route-map ISOLATE permit 10
set as-path prepend {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %}
Expand Down
Loading