submodule ietf-bgp-neighbor {
  yang-version 1.1;
  belongs-to ietf-bgp {
    prefix bgp;
  }

  import ietf-yang-types {
    prefix yang;
    reference
      "RFC 9911: Common YANG Data Types.";
  }

  import iana-bgp-afi-safi-types {
    prefix bast;
    reference
      "RFC XXXX: YANG Model for Border Gateway Protocol (BGP-4).";
  }
  import ietf-bgp-types {
    prefix ibt;
    reference
      "RFC XXXX: YANG Model for Border Gateway Protocol (BGP-4).";
  }

  import ietf-yang-semver {
    prefix ysv;
    reference
      "I-D.ietf-netmod-yang-semver: YANG Semantic Versioning";
  }

  // Include the common submodule

  include ietf-bgp-common;
  include ietf-bgp-common-multiprotocol;

  organization
    "IETF IDR Working Group";
  contact
    "WG Web:   <http://datatracker.ietf.org/wg/idr>
     WG List:  <idr@ietf.org>

     Authors: Mahesh Jethanandani (mjethanandani at gmail.com),
              Keyur Patel (keyur at arrcus.com),
              Susan Hares (shares at ndzh.com),
              Jeffrey Haas (jeffrey.haas at hpe.com).";

  description
    "This sub-module contains groupings that are specific to the
     neighbor context of the BGP module.

     Copyright (c) 2026 IETF Trust and the persons identified as
     authors of the code. All rights reserved.

     Redistribution and use in source and binary forms, with or
     without modification, is permitted pursuant to, and subject to
     the license terms contained in, the Revised BSD License set
     forth in Section 4.c of the IETF Trust's Legal Provisions
     Relating to IETF Documents
     (https://trustee.ietf.org/license-info).

     This version of this YANG module is part of RFC XXXX
     (https://www.rfc-editor.org/info/rfcXXXX); see the RFC itself
     for full legal notices.

     The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
     NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'NOT RECOMMENDED',
     'MAY', and 'OPTIONAL' in this document are to be interpreted as
     described in BCP 14 (RFC 2119) (RFC 8174) when, and only when,
     they appear in all capitals, as shown here.";

  revision 2026-08-14 {
    description
      "Initial Version";
    ysv:version 0.0.9;
    reference
      "RFC XXXX: YANG Model for Border Gateway Protocol (BGP-4).";
  }

  grouping bgp-neighbor-afi-safi-list {
    description
      "List of address-families associated with the BGP neighbor";
    list afi-safi {
      key "name";
      description
        "AFI, SAFI configuration available for the neighbor or
         group";
      uses mp-afi-safi-config;
      leaf active {
        type boolean;
        config false;
        description
          "This value indicates whether a particular AFI-SAFI has
           been successfully negotiated with the peer. An AFI-SAFI
           may be enabled in the current running configuration, but
           a session restart may be required in order to negotiate
           the new capability.";
      }

      container prefixes {
        config false;
        description
          "Prefix counters for the AFI/SAFI in this BGP session";

        leaf received-pre-policy {
          type yang:zero-based-counter32;
          description
            "The number of prefixes that are received from the
             neighbor before applying any policies. This count is the
             number of prefixes present in the pre-policy
             adj-rib-in-pre table for this AFI/SAFI.";
        }

        leaf received {
          type yang:zero-based-counter32;
          description
            "The number of prefixes that are received from the
             neighbor after applying any policies. This count is the
             number of prefixes present in the adj-rib-in-post table
             for this AFI/SAFI.";
        }

        leaf sent {
          type yang:zero-based-counter32;
          description
            "The number of prefixes that are advertised to the
             neighbor after applying any policies. This count is the
             number of prefixes present in the adj-rib-out-post table
             for this AFI/SAFI.";
        }

        leaf installed {
          type yang:gauge32;
          description
            "The number of prefixes received from the neighbor for
             this AFI/SAFI that are installed in loc-rib table.";
         }

         leaf installed-multiple-paths {
           type yang:gauge32;
           description
             "The number of prefixes received from the neighbor for
              this AFI/SAFI that are used for forwarding.  These
              include route that are:

              - 'elibigle-route' is true.
              - 'best-path' true, or the implementation installs this
                route as part of multiple path load balancing
                procedures.";
        }
      }

      container graceful-restart {
        if-feature "ibt:graceful-restart";
        description
          "Parameters relating to BGP graceful-restart";
        reference
          "RFC 4724: Graceful Restart Mechanism for BGP.";
        uses mp-afi-safi-graceful-restart-config;
        leaf received {
          type boolean;
          config false;
          description
            "This leaf indicates whether the neighbor advertised the
             ability to support graceful-restart for this AFI-SAFI";
          reference
            "RFC 4724: Graceful Restart Mechanism for BGP, Section
             3.";
        }
        leaf advertised {
          type boolean;
          config false;
          description
            "This leaf indicates whether the ability to support
             graceful-restart has been advertised to the peer";
          reference
            "RFC 4724: Graceful Restart Mechanism for BGP, Section
             3.";
        }
        leaf local-forwarding-state-preserved {
          type boolean;
          config false;
          description
            "This leaf indicates whether the local router has
             or would advertise the Forwarding State bit in its
             Graceful Restart capability for this AFI-SAFI.";
          reference
            "RFC 4724: Graceful Restart Mechanism for BGP, Section
             3.";
        }
        leaf forwarding-state-preserved {
          type boolean;
          config false;
          description
            "This leaf indicates whether the neighbor has advertised
             the Forwarding State bit in its Graceful Restart
             capability for this AFI-SAFI.";
          reference
            "RFC 4724: Graceful Restart Mechanism for BGP, Section
             3.";
        }
        leaf end-of-rib-received {
          type boolean;
          config false;
          description
            "This leaf indicates whether the neighbor has advertised
             the End-of-RIB marker for this AFI-SAFI.";
          reference
            "RFC 4724: Graceful Restart Mechanism for BGP, Section
             2.";
        }
      }
      uses mp-all-afi-safi-list-contents;
      uses bgp-neighbor-use-multiple-paths;
    }
  }

  grouping bgp-neighbor-messages-common {
    description
      "BGP neighbor message counters common to received and sent
       messages.";

    leaf total {
      type yang:zero-based-counter32;
      description
        "Total number of BGP messages from this neighbor";
      reference
        "RFC 4273: Definitions of Managed Objects for BGP-4,
        bgpPeerIn/OutTotalMessages.";
    }
    leaf updates {
      type yang:zero-based-counter32;
      description
        "Number of BGP UPDATE messages for this neighbor.";
      reference
        "RFC 4273: Definitions of Managed Objects for BGP-4,
         bgpPeerIn/OutUpdates.";
    }
    leaf update-time {
      type yang:timeticks;
      description
        "Timestamp for the last BGP UPDATE message for the peer.

         The value is the timestamp in seconds relative to
         the Unix Epoch (Jan 1, 1970 00:00:00 UTC).";
      reference
        "RFC 4271: A Border Gateway Protocol 4 (BGP-4), Section 4.3
         RFC 4271: A Border Gateway Protocol 4 (BGP-4), Established
         state.";
    }
    leaf notifications {
      type yang:zero-based-counter32;
      description
        "Number of BGP NOTIFICATION messages indicating an error
         condition has happend for this peer.";
      reference
        "RFC 4271: A Border Gateway Protocol 4 (BGP-4),
         Section 4.5.";
    }
    list afi-safi {
      key "afi-safi-name";
      description
        "Per-AFI-SAFI message counters";

      leaf afi-safi-name {
        type identityref {
          base bast:afi-safi-type;
        }
        description
          "AFI-SAFI for these message counters.";
      }

      leaf updates {
        type yang:zero-based-counter32;
        description
          "Number of BGP UPDATE messages per-AFI-SAFI that may be
           carried in UPDATE (AFI-SAFI 1-1), MP_REACH_NLRI or
           MP_UNREACH_NLRI. This counter is a subset of the total
           updates.";
        reference
          "RFC 4271, Section 4.3: A Border Gateway Protocol 4
           (BGP-4).
           RFC 4760, Sections 3-4: Multiprotocol Extensions for
           BGP-4.";
      }
      leaf route-refresh {
        if-feature "ibt:route-refresh";
        type yang:zero-based-counter32;
        description
          "Number of BGP ROUTE-REFRESH messages for this peer for
           this AFI/SAFI. When enhanced route refresh is supported,
           only subtype 0 is included in this counter.";
        reference
          "RFC 2918: Route Refresh Capability for BGP-4.
           RFC 7313: Enhanced Route Refresh Capability for BGP-4.";
      }

      leaf end-of-rib {
        type yang:zero-based-counter32;
        description
          "BGP speakers that are capable of exchanging End-of-RIB
           markers for a given AFI-SAFI do so by sending an empty
           UPDATE or empty MP_UNREACH_NLRI message.  This counter
           applies to the subset of BGP updates that are End-of-RIB
           markers.";
        reference
          "RFC 4724, Section 2: Graceful Restart Mechanism for BGP";
      }
    }
  }
}
