{% macro ospf_config(pid,af,vrf,ospf,vrf_interfaces) %}
- path: network-instance[name={{ vrf|default('default') }}]
  val:
   router-id: {{ ospf.router_id }}
   protocols:
    ospf:
     instance:
     - name: "{{ pid }}"
       version: {{ 'ospf-v2' if af=='ipv4' else 'ospf-v3' }}
{%     if af!='ipv4' %}
       address-family: ipv6-unicast
{%     endif %}
       admin-state: enable
       max-ecmp-paths: 64
{%     if ospf.reference_bandwidth is defined %}
       reference-bandwidth: {{ ospf.reference_bandwidth * 1000 }} # in kbps
{%     endif %}
       area:
{%     if vrf=='default' %}
       - area-id: {{ ospf.area }}
         interface:
         - interface-name: system0.0
           passive: True
{%     endif %}
{%     for l in vrf_interfaces if (l.vlan is not defined or l.vlan.mode|default('irb')!='bridge') and l.subif_index is not defined %}
{%      set if_name_index = l.ifname.split('.') %}
{%      set if_name = if_name_index[0] if l.type!='stub' else "lo0" %}
{%      set if_index = if_name_index[1] if if_name_index|length > 1 else l.ifindex if l.type=='stub' else '0' %}
{%      if 'ospf' not in l %}
       # OSPF not configured on external interface {{ if_name }}
{%      else %}
       - area-id: {{ l.ospf.area }}
         interface:
         - interface-name: {{ if_name }}.{{ if_index }}
           passive: {{ ospf.passive | default(False) }}
{%         if l.ospf.network_type|default("") in ["broadcast","point-to-point"] %}
           interface-type: "{{ l.ospf.network_type }}"
{%         endif %}
           failure-detection:
            enable-bfd: {{ l.ospf.bfd|default(False) }}
{%         if l.ospf.cost is defined %}
           metric: {{ l.ospf.cost }}
{%         endif %}
{%     endif %}
{%     endfor %}
{% endmacro %}
