{% import "vyos.bgp-macro.j2" as bgpcfg %}

set protocols bgp local-as {{ bgp.as }}


set protocols bgp address-family ipv4-unicast rd vpn export {{ vdata.rd }}

{% for af in ['ipv4','ipv6'] if af in vdata.af %}
set protocols bgp address-family {{ af }}-unicast rd vpn export {{ vdata.rd }}
set protocols bgp address-family {{ af }}-unicast route-target vpn import "{{ vdata.import|join(' ') }}"
set protocols bgp address-family {{ af }}-unicast route-target vpn export "{{ vdata.export|join(' ') }}"
set protocols bgp address-family {{ af }}-unicast import vpn
set protocols bgp address-family {{ af }}-unicast export vpn
set protocols bgp address-family {{ af }}-unicast label vpn export auto
{% endfor %}


{% for af in ['ipv4','ipv6'] if af in vdata.af %}
set protocols bgp address-family {{ af }}-unicast redistribute connected
{%   if vdata.ospf is defined %}
set protocols bgp address-family {{ af }}-unicast redistribute ospf
{%   endif %}
{% endfor %}

{% for n in vdata.bgp.neighbors|default([]) %}
{%   for af in ['ipv4','ipv6'] if n[af] is defined %}
{{     bgpcfg.neighbor(n,n[af],bgp) }}
{{     bgpcfg.neighbor_af(n,n[af],bgp,af) }}
{%   endfor %}
{% endfor %}
