# Generated by sros.gnmi.j2 template
updates:
- path: configure/router[router-name=Base]
  val:
   router-id: "{{ bgp.router_id }}"
   autonomous-system: {{ bgp.as }}
   bgp:
    ebgp-default-reject-policy:
     import: False
     export: False
    multipath:
     ibgp: {{ 16 if 'ixr' in clab.type else 64 }}
     ebgp: {{ 16 if 'ixr' in clab.type else 64 }}
    min-route-advertisement: 1 # Be aggressive about sending updates
    connect-retry: 5           # Retry frequently, suitable in DC context
    client-reflect: {{ bgp.rr|default('')|bool }}
    # family: cannot disable this
    # ipv4: False # Enabled by default, disable globally and set per group
    group:
{% set ibgp_v4 = ['ibgp-ipv4'] if 'ipv4' in loopback and loopback['ipv4'] else [] %}
{% set ibgp_v6 = ['ibgp-ipv6'] if 'ipv6' in loopback and loopback['ipv6'] else [] %}
{%  for c in ['ebgp']+ibgp_v4+ibgp_v6 %}
{%  set bgp_type=c[:4] %}
    - group-name: "{{c}}"
      admin-state: enable
      family:
       ipv4: {{ 'ipv4' in bgp.address_families[bgp_type] }}
       ipv6: {{ 'ipv6' in bgp.address_families[bgp_type] }}
      import:
       policy: ["accept_all"]
      export:
       policy: ["accept_all"]
{%    if bgp.community[ bgp_type ]|default([]) %}
      send-communities:
{%     if not ('standard' in bgp.community[ bgp_type ] or 'both' in bgp.community[ bgp_type ]) %}
       standard: False
{%     endif %}
{%     if not ('extended' in bgp.community[ bgp_type ] or 'both' in bgp.community[ bgp_type ]) %}
       extended: False
{%     endif %}
{%     if not ('large' in bgp.community[ bgp_type ]) %}
       large: False
{%     endif %}
{%    endif %}
{%    if c!='ebgp' %}
      local-address: "{{ loopback[ c[5:] ]|ipaddr('address') }}"
{%    if bgp.rr|default('')|bool %}
      cluster:
        cluster-id: "{{ bgp.rr_cluster_id|default(False) or bgp.router_id }}"
{%    elif bgp.next_hop_self|default(false) %}
      next-hop-self: True
{%    endif %}
{%    endif %}

{%  endfor %}
    neighbor:
{%  for n in bgp.neighbors %}
{%  for af in ['ipv4','ipv6'] if n[af] is defined %}
    - ip-address: "{{ n[af] }}"
      description: "{{ n.name }}"
      peer-as: {{ n.as }}
      group: "{{ 'ebgp' if n.type=='ebgp' else (n.type+'-'+af) }}"
{%    if n.local_as is defined %}
      local-as:
       as-number: {{ n.local_as }}
{%    endif %}
{%  endfor %}
{%  endfor %}

- path: configure/policy-options/policy-statement[name=accept_all]
  val:
   default-action:
    action-type: accept
