!
router bgp {{ bgp.as }}
 address-family evpn
{% if evpn.transport|default('vxlan') == 'mpls' %}
  neighbor default encapsulation mpls next-hop-self source-interface Loopback0
{% endif %}
!
{% for n in bgp.neighbors if n.ipv4 is defined and n.evpn|default(False) %}
  neighbor {{ n.ipv4 }} activate
{% endfor %}
{% if vlans is defined %}
{%   for v in vlans.values() if v.evpn.evi is defined and v.evpn.bundle is not defined %}
!
 vlan {{ v.id }}
  rd {{ v.evpn.rd }}
  route-target import {{ v.evpn.import|join(' ') }}
  route-target export {{ v.evpn.export|join(' ') }}
  redistribute learned
{%   endfor %}
{% endif %}
{% if vrfs is defined %}
{%   for n,v in vrfs.items() if v.evpn.vlans is defined %}
!
 vlan-aware-bundle {{ n }}
  rd {{ v.rd }}
  route-target import {{ v.import|join(' ') }}
  route-target export {{ v.export|join(' ') }}
  redistribute learned
  vlan {{ v.evpn.vlan_ids|join(',') }}
{%   endfor %}
{% endif %}
{% if vrfs is defined %}
{%   for n,v in vrfs.items() if v.af is defined %}
!
 vrf {{ n }}
  rd {{ v.rd }}
  route-target import evpn {{ v.import|join(' ') }}
  route-target export evpn {{ v.export|join(' ') }}
  redistribute connected
{%   endfor %}
{% endif %}
{% if vrfs is defined %}
{%   for n,v in vrfs.items() if v.evpn.transit_vni is defined %}
{%     if loop.first %}
!
interface vxlan 1
{%     endif %}
 vxlan vrf {{ n }} vni {{ v.evpn.transit_vni }}
{%   endfor %}
{% endif %}
