Skip to content

Commit 3a982d1

Browse files
authored
Cumulus NVUE: BGP in VRFs (#1972)
1 parent a289f4a commit 3a982d1

File tree

6 files changed

+127
-128
lines changed

6 files changed

+127
-128
lines changed

docs/module/vrf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ These platforms support routing protocols in VRFs:
4646
| Cisco IOS XE[^18v] |[](caveats-csr) |||||
4747
| Cisco Nexus OS ||||
4848
| Cumulus Linux 4.x ||||||
49-
| Cumulus 5.x (NVUE) ||| |||
49+
| Cumulus 5.x (NVUE) ||| |||
5050
| Dell OS10 ||||
5151
| FRR [](caveats-frr) ||||||
5252
| Junos[^Junos] ||||
Lines changed: 3 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,3 @@
1-
{% import "templates/routing/_redistribute.cumulus_nvue.j2" as redistribute with context %}
2-
{% macro advertise_communities(comms) %}
3-
community-advertise:
4-
{% for c in ['standard', 'extended', 'large'] %}
5-
{{ c.replace("standard","regular") }}: {{ 'on' if c in comms else 'off' }}
6-
{% endfor %}
7-
{% endmacro %}
8-
9-
- set:
10-
router:
11-
bgp:
12-
enable: on
13-
vrf:
14-
default:
15-
router:
16-
bgp:
17-
{% if bgp.rr|default(False) %}
18-
route-reflection:
19-
enable: on
20-
{% if bgp.rr_cluster_id is defined %}
21-
cluster-id: {{ bgp.rr_cluster_id }}
22-
{% endif %}
23-
{% endif %}
24-
{% for af in ['ipv4','ipv6'] if bgp[af] is defined %}
25-
{% if loop.first %}
26-
address-family:
27-
{% endif %}
28-
{{ af }}-unicast:
29-
enable: on
30-
{{ redistribute.config(bgp,af=af)|indent(16,first=True) }}
31-
{% set _loopback = [ loopback[af] ] if loopback[af] is defined and bgp.advertise_loopback else [] %}
32-
{% set data = namespace(networks=_loopback) %}
33-
{% for l in interfaces|default([]) if l.bgp.advertise|default("") and l[af] is defined and not 'vrf' in l %}
34-
{% set data.networks = data.networks + [ l[af] ] %}
35-
{% endfor %}
36-
{% for pfx in bgp.originate|default([]) if af == 'ipv4' %}
37-
{% set data.networks = data.networks + [ pfx ] %}
38-
{% endfor %}
39-
{% if data.networks!=[] %}
40-
network:
41-
{% for pfx in data.networks %}
42-
{{ pfx|ipaddr('0') }}: {}
43-
{% endfor %}
44-
{% endif %}
45-
{% endfor %}
46-
autonomous-system: {{ bgp.as }}
47-
{% for n in bgp.neighbors %}
48-
{% if loop.first %}
49-
neighbor:
50-
{% endif %}
51-
{% if n.local_if is defined %}
52-
{{ n.local_if }}:
53-
type: unnumbered
54-
remote-as: {{ n.as }}
55-
address-family:
56-
ipv4-unicast:
57-
enable: {{ 'on' if n.ipv4_rfc8950|default(False) else 'off' }}
58-
community-advertise:
59-
extended: on
60-
ipv6-unicast:
61-
enable: {{ 'on' if n.ipv6|default(False) and n.activate.ipv6|default(False) else 'off' }}
62-
community-advertise:
63-
extended: on
64-
{% endif %}
65-
{% for af in ('ipv4','ipv6') if af in n and n[af] is string %}
66-
{{ n[af] }}:
67-
description: "{{ n.name }}"
68-
{% if n._source_ifname is defined %}
69-
update-source: {{ n._source_ifname }}
70-
{% endif %}
71-
remote-as: {{ 'internal' if n.as==bgp.as else n.as }}
72-
{% if n.local_as is defined %}
73-
local-as:
74-
asn: {{ n.local_as }}
75-
enable: on
76-
{% if n.replace_global_as|default(True) %}
77-
replace: on
78-
prepend: off
79-
{% endif %}
80-
{% endif %}
81-
address-family:
82-
{# NVUE cannot turn off default IPv4 activation, so we have to implement a fix for IPv6 #}
83-
{% if af == 'ipv6' %}
84-
ipv4-unicast:
85-
enable: off
86-
{% endif %}
87-
{{ af }}-unicast:
88-
enable: {{ 'on' if n.activate[af]|default(False) else 'off' }}
89-
{% if 'ibgp' in n.type %}
90-
{% if bgp.next_hop_self|default(False) %}
91-
nexthop-setting: self
92-
{% endif %}
93-
{% if bgp.rr|default('') and not n.rr|default('') %}
94-
route-reflector-client: on
95-
{% endif %}
96-
{% endif %}
97-
{% if n.type in bgp.community|default({}) %}
98-
{{ advertise_communities( bgp.community[n.type] ) }}
99-
{% endif %}
100-
{% endfor %}
101-
{% endfor %}
102-
{% if 'router_id' in bgp %}
103-
router-id: {{ bgp.router_id }}
104-
{% endif %}
105-
{% if bgp.originate is defined %}
106-
static:
107-
{% for pfx in bgp.originate|default([]) %}
108-
{{ pfx|ipaddr('0') }}:
109-
address-family: ipv4-unicast
110-
via:
111-
blackhole:
112-
type: blackhole
113-
{% endfor %}
114-
{% endif %}
1+
{% from "bgp/cumulus_nvue.macro.j2" import bgp_in_vrf with context %}
2+
---
3+
{{ bgp_in_vrf('default', { 'bgp': bgp, 'loopback': loopback, 'af': af } ) }}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{% import "templates/routing/_redistribute.cumulus_nvue.j2" as redistribute with context %}
2+
{% macro advertise_communities(comms) %}
3+
community-advertise:
4+
{% for c in ['standard', 'extended', 'large'] %}
5+
{{ c.replace("standard","regular") }}: {{ 'on' if c in comms else 'off' }}
6+
{% endfor %}
7+
{% endmacro %}
8+
{% macro bgp_in_vrf(vrf_name,vrf) %}
9+
{% set vrf_bgp = vrf.bgp %}
10+
- set:
11+
vrf:
12+
{{ vrf_name }}:
13+
router:
14+
bgp:
15+
enable: on
16+
autonomous-system: {{ bgp.as }}
17+
router-id: {{ vrf_bgp.router_id|default(bgp.router_id) }}
18+
{% if vrf_bgp.rd is defined %}
19+
rd: {{ vrf_bgp.rd }}
20+
{% endif %}
21+
{% if vrf_bgp.rr|default(False) %}
22+
route-reflection:
23+
enable: on
24+
{% if vrf_bgp.rr_cluster_id is defined %}
25+
cluster-id: {{ vrf_bgp.rr_cluster_id }}
26+
{% endif %}
27+
{% endif %}
28+
{% for af in ['ipv4','ipv6'] if vrf.af[af] is defined %}
29+
{% if loop.first %}
30+
address-family:
31+
{% endif %}
32+
{{ af }}-unicast:
33+
enable: on
34+
{{ redistribute.config(vrf_bgp,af=af)|indent(16,first=True) }}
35+
{% set _loopback = [ vrf.loopback[af] ] if vrf.loopback[af] is defined and vrf_bgp.advertise_loopback else [] %}
36+
{% set data = namespace(networks=_loopback) %}
37+
{% for l in interfaces|default([]) if l.bgp.advertise|default("") and l[af] is defined and l.vrf|default('default')==vrf_name %}
38+
{% set data.networks = data.networks + [ l[af] ] %}
39+
{% endfor %}
40+
{% for pfx in vrf_bgp.originate|default([]) if af == 'ipv4' %}
41+
{% set data.networks = data.networks + [ pfx ] %}
42+
{% endfor %}
43+
{% if data.networks!=[] %}
44+
network:
45+
{% for pfx in data.networks %}
46+
{{ pfx|ipaddr('0') }}: {}
47+
{% endfor %}
48+
{% endif %}
49+
{% endfor %}
50+
{% for n in vrf_bgp.neighbors|default([]) %}
51+
{% if loop.first %}
52+
neighbor:
53+
{% endif %}
54+
{% if n.local_if is defined %}
55+
{{ n.local_if }}:
56+
type: unnumbered
57+
remote-as: {{ n.as }}
58+
address-family:
59+
ipv4-unicast:
60+
enable: {{ 'on' if n.ipv4_rfc8950|default(False) else 'off' }}
61+
community-advertise:
62+
extended: on
63+
ipv6-unicast:
64+
enable: {{ 'on' if n.ipv6|default(False) and ('activate' not in n or n.activate.ipv6|default(False)) else 'off' }}
65+
community-advertise:
66+
extended: on
67+
{% endif %}
68+
{% for af in ('ipv4','ipv6') if af in n and n[af] is string %}
69+
{{ n[af] }}:
70+
description: "{{ n.name }}"
71+
{% if n._source_ifname is defined %}
72+
update-source: {{ n._source_ifname }}
73+
{% endif %}
74+
remote-as: {{ 'internal' if n.as==bgp.as else n.as }}
75+
{% if n.local_as is defined %}
76+
local-as:
77+
asn: {{ n.local_as }}
78+
enable: on
79+
{% if n.replace_global_as|default(True) %}
80+
replace: on
81+
prepend: off
82+
{% endif %}
83+
{% endif %}
84+
address-family:
85+
{# NVUE cannot turn off default IPv4 activation, so we have to implement a fix for IPv6 #}
86+
{% if af == 'ipv6' %}
87+
ipv4-unicast:
88+
enable: off
89+
{% endif %}
90+
{{ af }}-unicast:
91+
enable: {{ 'on' if 'activate' not in n or n.activate[af]|default(False) else 'off' }}
92+
{% if 'ibgp' in n.type %}
93+
{% if vrf_bgp.next_hop_self|default(False) %}
94+
nexthop-setting: self
95+
{% endif %}
96+
{% if vrf_bgp.rr|default('') and not n.rr|default('') %}
97+
route-reflector-client: on
98+
{% endif %}
99+
{% endif %}
100+
{% if n.type in vrf_bgp.community|default({}) %}
101+
{{ advertise_communities( vrf_bgp.community[n.type] ) }}
102+
{% endif %}
103+
{% endfor %}
104+
{% endfor %}
105+
{% if vrf_bgp.originate is defined %}
106+
static:
107+
{% for pfx in vrf_bgp.originate|default([]) %}
108+
{{ pfx|ipaddr('0') }}:
109+
address-family: ipv4-unicast
110+
via:
111+
blackhole:
112+
type: blackhole
113+
{% endfor %}
114+
{% endif %}
115+
{% endmacro %}

netsim/ansible/templates/evpn/cumulus_nvue.j2

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@
9696
{% endif %}
9797
router:
9898
bgp:
99-
autonomous-system: {{ vdata.as|default(bgp.as) }}
100-
enable: on
10199
rd: {{ vdata.rd }}
102100
route-export:
103101
to-evpn:
@@ -115,15 +113,6 @@
115113
route-export:
116114
to-evpn:
117115
enable: on
118-
{# This part belongs in the VRF or BGP template, to be moved #}
119-
enable: on
120-
redistribute:
121-
connected:
122-
enable: on
123-
{% if 'ospf' in vdata %}
124-
ospf:
125-
enable: on
126-
{% endif %}
127116
{% endfor %}
128117
{% endfor %}
129118
{% endif %}

netsim/ansible/templates/vrf/cumulus_nvue.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% from "ospf/cumulus_nvue.j2" import vrf_ospf with context %}
2+
{% from "bgp/cumulus_nvue.macro.j2" import bgp_in_vrf with context %}
23

34
- set:
45
vrf:
@@ -9,10 +10,14 @@
910

1011
{% for vname,vdata in vrfs.items() if 'ospf' in vdata %}
1112
{% if vdata.af.ipv4|default(False) %}
12-
{{ vrf_ospf(vname,vdata) }}
13+
{{ vrf_ospf(vname,vdata) }}
1314
{% endif %}
1415
{% endfor %}
1516

17+
{% for vname,vdata in vrfs.items() if 'bgp' in vdata %}
18+
{{ bgp_in_vrf(vname, vdata) }}
19+
{% endfor %}
20+
1621
{% for intf in netlab_interfaces if intf.vrf is defined %}
1722
- set:
1823
{% if intf.type=='loopback' %}

netsim/devices/cumulus_nvue.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ features:
2929
lla: True
3030
bgp:
3131
activate_af: True
32-
import: [ connected, ospf ]
32+
import: [ connected, ospf, vrf ]
3333
ipv6_lla: True
3434
local_as: True
3535
local_as_ibgp: True
@@ -65,6 +65,7 @@ features:
6565
subif_name: "{ifname}.{vlan.access_id}"
6666
vrf:
6767
ospfv2: True
68+
bgp: True
6869
vxlan: True
6970
# vtep6: true # Waiting for https://github.com/CumulusNetworks/ifupdown2/pull/315
7071
clab:

0 commit comments

Comments
 (0)