{% set pid = ospf.process|default(0) %}

{% macro if_name(n) -%}
{{- ('oc_%s/1_0' if sros_use_openconfig|default(true) else 'i%s')|format(n.ifname) -}}
{%- endmacro %}

updates:
- path: configure/router[router-name=Base]
  val:
   router-id: "{{ ospf.router_id }}"
   ospf:
   - ospf-instance: {{ pid }}
{% if ospf.reference_bandwidth is defined %}
     reference-bandwidth: {{ ospf.reference_bandwidth * 1000 }} # in kbps
{% endif %}
     admin-state: enable
     area:
     - area-id: "{{ ospf.area }}"
       interface:
       - interface-name: "system"
         passive: True
{% for l in interfaces|default([]) if 'ospf' in l %}
     - area-id: "{{ l.ospf.area }}"
       interface:
       - interface-name: "{{ if_name(l) }}"
         passive: {{ l.ospf.passive }}
{%       if l.ospf.bfd|default(False) %}
         bfd-liveness: { }
{%       endif %}
         # mtu: 1500 # SRL defaults to 1500, now supporting global mtu settings
{# TODO: Add support for multi-area adjacencies and 'secondary' interface-type #}
{%       if l.ospf.network_type|default("") in ["broadcast","non-broadcast","point-to-point"] %}
         interface-type: "{{ l.ospf.network_type }}"
{%       endif %}
{%       if l.ospf.cost is defined %}
         metric: {{ l.ospf.cost }}
{%       endif %}
{% endfor %}
