<template name="cisco_xr_bgp_neighbors" results="per_template">
<doc>
Template to parse Cisco IOS XR BGP neighbors.

This template requires output of 'show bgp neighbors' command.

Returns a normalized list of dictionaries, one per BGP neighbor, with the
following keys (fields unavailable from this command are set to None/[]):

```yaml
- afi:
  - ipv4_unicast
  - ipv6_unicast
  description: iBGP_Neighbor
  export_policies:
  - PASS-ALL
  hold_time: 180
  import_policies:
  - DENY-ALL
  ipv4_unicast_prefixes_received: 0
  ipv4_unicast_prefixes_sent: 0
  ipv6_unicast_prefixes_received: 0
  ipv6_unicast_prefixes_sent: 0
  keepalive: 60
  local_address: 10.0.0.1
  local_as: '65001'
  local_interface: null
  max_ttl: null
  name: default_10.0.0.42
  peer_group: null
  peering_type: internal
  prefix_list_in: null
  prefix_list_out: null
  remote_address: 10.0.0.42
  remote_as: '65001'
  router_id: 0.0.0.0
  state: opensent
  uptime_seconds: null
  vrf: default
```
</doc>

<macro>
def transform(data):
    from ttp_templates.utils.cisco_xr_process_show_bgp_neighbors import transform_bgp_neighbors
    return transform_bgp_neighbors(data)
</macro>

<input>
commands = [
    "show bgp neighbors",
    "show bgp vrf all neighbors",
]
platform = [
    "cisco_xr",    # netmiko
    "iosxr",       # napalm
    "cisco_iosxr", # scrapli
]
</input>

<group name="neighbors*">
BGP neighbor is {{ remote_address | _start_ }}
BGP neighbor is {{ remote_address | _start_ }}, vrf {{ vrf }}
 Remote AS {{ remote_as | to_int }}, local AS {{ local_as | to_int }}, {{ peering_type }} link
 Description: {{ description | ORPHRASE }}
 Remote router ID {{ router_id }}
  BGP state = {{ bgp_state | ORPHRASE }}
  Hold time is {{ hold_time }}, keepalive interval is {{ keepalive }} seconds

  <group name="address_families*">
 For Address Family: {{ afi_name | ORPHRASE }}
  {{ accepted_prefixes }} accepted prefixes, {{ _bestpaths_ }} are bestpaths
  Prefix advertised {{ prefixes_sent }}, suppressed {{ _suppressed_ }}, withdrawn {{ _withdrawn_ }}
  Policy for incoming advertisements is {{ import_policy | ORPHRASE }}
  Policy for outgoing advertisements is {{ export_policy | ORPHRASE }}
  </group>

  Local host: {{ local_address }}, Local port: {{ ignore }}
  Local host: {{ local_address }}, Local port: {{ ignore }}, IF Handle: {{ ignore }}
</group>

<output macro="transform"/>

</template>