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

  import ietf-netconf-acm  { prefix nacm; }
  import ietf-yang-push    { prefix yp; }
  import ietf-yang-library {
    prefix yanglib;
    description
      "Requires revision 2019-01-04 or a revision derived from it.";
  }
  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 YANG-Push related server
     capabilities.

     The module contains
     - capabilities related to the amount of notifications the
     server can send out. (Note that for a specific subscription
     the server MAY still allow only longer periods or smaller
     updates depending on e.g. actual load conditions.)
     - specification of which data nodes support on-change
     notifications.

     Capability values on a
     smaller, more specific part of the server's data always override
     more generic values. The hierarchy of specifications from generic
     to more specific is:
      1) top level values valid for all datastores
      2) values for a specific datastore (including the special
        'all' datastore identifier)
      3) Value for a specific data node and its contained sub-tree
        in one of the datastores. Such capability values are inherited
        down the containment tree unless a more specific value is
        provided, as described in 4)
      4) A contained, smaller, more specific sub-tree in a specific
        datastore (could be a single leaf)

      Any capability value MAY be absent if a more generic capability
      value is already provided or if the server is not capable of
      providing a value.

     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) 2019 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
     (http://trustee.ietf.org/license-info).

     This version of this YANG module is part of RFC XXXX; see
     the RFC itself for full legal notices.";

  revision 2019-08-13 {
    description
      "Initial version";
    reference
      "RFC XXX: Yang-Push Notification Capabilities";
  }

  container datastore-subscription-capabilities {
    config false;
    description
      "YANG-Push related server capabilities";

    grouping datastore-subscription-throughput-capabilities {
      description "Capability values that affect the amount of
        notifications the server can send out.";

      choice update-period {
        description
          "Supported update-period values.";
        leaf minimum-update-period {
          type uint32;
          units "centiseconds";
          description
            "Minimum update period supported for a
            periodic subscription.";
        }

        leaf-list supported-update-period {
          type uint32;
          units "centiseconds";
          description
            "Specific supported update period values
            for a periodic subscription.";
        }
      }

      leaf max-objects-per-update {
        type uint32 {
              range "1..max";
        }
        description
          "Maximum number of objects that can be sent
           in an update.";
      }

      leaf minimum-dampening-period {
        if-feature yp:on-change ;
        type uint32;
        units "centiseconds";
        description
          "The minimum dampening period supported for on-change
           subscriptions.";
      }
    }

    uses datastore-subscription-throughput-capabilities {
      description "Top level throughput capabilities.
        These values can be overridden by values provided per
        datastore or for individual data nodes in a datastore.";
    }

    list datastore-capabilities {
      key datastore ;
      description "Capabilities values per datastore.
        For non-NMDA servers the config=false data is considered
        as if it was part of the running datastore.

        Indicates per datastore throughput capabilities.

        Indicates per datastore the data nodes for which the
        server is capable of sending on-change notifications.
        If a datastore implemented by the server is not specified
        in this list and there is no list element for 'all' datastores
        the datastore does not support any on-change notifications.

        On-change notifications SHALL be sent for a config=true
        data node if one of the following is true:
        - if it is a top level data-node and is not specified in the
        per-node-capabilities list and on-change-supported-for-config
        is true; or
        - notifications are sent for its parent data node and it is
        not specified in the per-node-capabilities list; or
        - it is specified in the per-node-capabilities list and has
        an on-change-supported value true.

        On-change notifications SHALL be sent for a config=false
        data node if one of the following is true:
        - if it is a top level data-node (a config=false data node with
        a config=true parent SHALL be treated as a top level data node)
        and is not specified in the per-node-capabilities list and
        on-change-supported-for-state is true; or
        - notifications are sent for its parent data node
        which is also config=false and it is not specified in the
        per-node-capabilities list; or
        - it is specified in the per-node-capabilities list and has
        an on-change-supported value true";

      leaf datastore {
        type union {
          type leafref {
            path /yanglib:yang-library/yanglib:datastore/yanglib:name ;
          }
          type enumeration {
            enum all ;
          }
        }
        must '. != "all" or count(..) = "1" ' {
          error-message
            "If 'all' is present individual datastores cannot be " +
              "specified.";
        }
        description "The datastore for which capabilities are defined.";
      }

      uses datastore-subscription-throughput-capabilities {
        description "Throughput capabilities for a datastore.
          These values will override top level values and can be
          overridden by values provided for individual data nodes
          in a datastore.";
      }

      leaf on-change-supported-for-config {
        if-feature yp:on-change ;
        type boolean;
        default "true";
        description
          "Specifies the default value for
           top level config=true data nodes for the
           on-change-supported capability.";
      }

      leaf on-change-supported-for-state {
        if-feature yp:on-change ;
        type boolean;
        default "false";
        description
          "Specifies the default value for
           top level config=false data nodes for the
           on-change-supported capability.";
      }

      list per-node-capabilities {
        key "node-selector";
        description
          "A list of data nodes that have either a throughput or
           on-change-notification capability specifically defined.

           Should be used only when specific data nodes support
           capabilities that are different from capabilities
           of their parent nodes or the default for the datastore.";

        leaf node-selector {
          type nacm:node-instance-identifier;
          description
            "Selects the data nodes for which
             a capability is specified.";
        }

        uses datastore-subscription-throughput-capabilities {
          description "Throughput capabilities for a specific data node.
            These values will override top level or datastore
            specific values.";
        }

        leaf on-change-supported {
          if-feature yp:on-change ;
          type boolean;
          mandatory true;
          description
            "Specifies whether the server is capable of
             sending on-change notifications for the selected
             data nodes.";
        }
      }
    }
  }
}
