module ietf-system-capabilities {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-system-capabilities";
  prefix sysc;

  import ietf-netconf-acm {
    prefix nacm;
    reference
      "RFC 8341: Network Configuration Access Control Model";
  }
  import ietf-yang-library {
    prefix yanglib;
    description
      "This module requires ietf-yang-library to be implemented.
       Revision 2019-01-04 or a revision derived from it
       is REQUIRED.";
    reference
      "RFC8525: YANG Library";
  }

  organization
    "IETF NETCONF (Network Configuration) Working Group";
  contact
    "WG Web:   <https://datatracker.ietf.org/wg/netconf/>
     WG List:  <mailto:netconf@ietf.org>

     Editor:   Balazs Lengyel
               <mailto:balazs.lengyel@ericsson.com>";
  description
    "This module specifies a structure to specify system
     capabilities for a server or a publisher. System capabilities
     may include capabilities of a NETCONF or RESTCONF server or a
     notification publisher.

     This module does not contain any specific capabilities, it only
     provides a structure where containers containing the actual
     capabilities are augmented in.

     Capability values can be specified on system level,
     datastore level (by selecting all nodes in the datastore) or
     for specific data nodes of a specific datastore (and their
     contained sub-trees).
     Capability values specified for a specific datastore or
     node-set override values specified on the system/publisher level.

     To find a capability value for a specific data node in a
     specific datastore the user SHALL:

     1) search for a datastore-capabilities list entry for
     the specific datastore. When stating a specific capability, the
     relative path for any specific capability must be the same
     under the system-capabilities container and under the
     per-node-capabilities list: the same grouping for defining
     the capabilities MUST be used.

     2) If the datastore entry is found within that entry, process all
     per-node-capabilities entries in the order they appear in the list.
     The first entry that specifies the specific capability and has a
     node-selector selecting the specific data node defines the
     capability value.

     3) If the capability value is not found above and the specific
     capability is specified under the system-capabilities container
     (outside the datastore-capabilities list), this value shall be
     used.

     4) If no values are found in the previous steps, the
     system/publisher is not capable of providing a value. Possible
     reasons are: it is unknown, the capability is changing for some
     reason, there is no specified limit, etc. In this case the
     system's behavior is unspecified.
     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.

     Copyright (c) 2021 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 Simplified 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.";

  // RFC Ed.: replace XXXX with actual RFC number and remove this
  // note.

  revision 2021-04-02 {
    description
      "Initial version
       NOTE TO RFC EDITOR:
       (1)Please replace the above revision date to
         the date of RFC publication when published.
       (2) Please replace the date in the file name
         (ietf-system-capabilities@2021-04-02.yang)
         to the date of RFC publication.
       (3) Please replace the following reference
         with RFC number when published
         (i.e. RFC xxxx).";
    reference
      "RFC XXXX: YANG Modules describing Capabilities for Systems
       and Datastore Update Notifications";
  }

  container system-capabilities {
    config false;
    description
      "System capabilities.
       Capability values specified here at the system level
       are valid for all datastores and are used when the
       capability is not specified on the datastore level
       or for specific data nodes.";

    /*
     * "Augmentation point for system level capabilities."
     */

    list datastore-capabilities {
      key "datastore";
      description
        "Capabilities values per datastore.

         For non-NMDA servers/publishers 'config false' data is
         considered as if it was part of the running datastore.";
      leaf datastore {
        type leafref {
          path
            "/yanglib:yang-library/yanglib:datastore/yanglib:name";
        }
        description
          "The datastore for which capabilities are defined.
           Only one specific datastore can be specified
           e.g., ds:conventional, which represents a set of
           configuration datastores, must not be used.";
      }
      list per-node-capabilities {
        description
          "Each list entry specifies capabilities for the selected
           data nodes. The same capabilities apply for the data nodes
           in the subtree below the selected nodes.

           The system SHALL order the entries according to their
           precedence. The order of the entries MUST NOT change unless
           the underlying capabilities also change.

           Note that the longest patch matching can be achieved
           by ordering more specific matches before less
           specific ones.";
        choice node-selection {
          description
            "A method to select some or all nodes within a datastore.";
          leaf node-selector {
            type nacm:node-instance-identifier;
            description
              "Selects the data nodes for which capabilities are
               specified. The special value '/' denotes all data nodes
               in the datastore, consistent with the path leaf node on
               page 41 [RFC8341].";
            reference
              "RFC 8341: Network Configuration Access Control Model";
          }
        }
        /*
         * "Augmentation point for datastore or data node level
         * capabilities."
         */
      }
    }
  }
}
