<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc>
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="2"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<rfc category="std"
  docName="draft-ahuang-netconf-notif-yang-05"
  ipr="trust200902"
  consensus="true"
  submissionType="IETF"
  updates="RFC5277 RFC8639 RFC7951 RFC9254">
  <front>
    <title abbrev="NETCONF Event Notification YANG">YANG model
    for NETCONF Event Notifications</title>

    <author fullname="Alex Huang Feng" initials="A." surname="Huang Feng">
      <organization>INSA-Lyon</organization>

      <address>
        <postal>
          <street/>

          <city>Lyon</city>

          <region/>

          <code/>

          <country>France</country>
        </postal>

        <phone/>

        <facsimile/>

        <email>alex.huang-feng@insa-lyon.fr</email>

        <uri/>
      </address>
    </author>

    <author fullname="Pierre Francois" initials="P." surname="Francois">
      <organization>INSA-Lyon</organization>

      <address>
        <postal>
          <street/>

          <city>Lyon</city>

          <region/>

          <code/>

          <country>France</country>
        </postal>

        <phone/>

        <facsimile/>

        <email>pierre.francois@insa-lyon.fr</email>

        <uri/>
      </address>
    </author>

    <author fullname="Thomas Graf" initials="T" surname="Graf">
      <organization>Swisscom</organization>

      <address>
        <postal>
          <street>Binzring 17</street>

          <city>Zurich</city>

          <code>8045</code>

          <country>Switzerland</country>
        </postal>

        <email>thomas.graf@swisscom.com</email>
      </address>
    </author>

    <author fullname="Benoit Claise" initials="B" surname="Claise">
      <organization>Huawei</organization>

      <address>
        <email>benoit.claise@huawei.com</email>
      </address>
    </author>

    <date day="17" month="June" year="2024"/>

    <abstract>
      <t>This document defines the structure of NETCONF Event Notification in a
      YANG model to be used in NETCONF environments. The definition of this YANG
      model allows the encoding of NETCONF Event Notifications in YANG compatible
      encodings such as JSON and CBOR.</t>
    </abstract>

    <note title="Requirements Language">
      <t>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
      <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when,
      they appear in all capitals, as shown here.</t>
    </note>
  </front>

  <middle>
    <section anchor="introduction" title="Introduction">

      <t>NETCONF Event Notifications <xref target="RFC5277"/> and
      YANG-Push <xref target="RFC8639"/> allow NETCONF 
      <xref target="RFC6241"/> servers and YANG-Push publishers to send notifications to
      a data collection. The NETCONF client and the YANG-Push receiver decodes the message
      and optionally validates the header and the content before forward it to the next process.
      This schema validation process ensures to not break the data processing
      chain.</t>

      <t>The structure of a NETCONF Event notification has been
      defined in <xref target="RFC5277"/> using a XML Schema 
      <xref target="W3C.REC-xml-20001006"/> allowing NETCONF nodes
      to validate the header schema of the notification message when it is encoded in XML.
      However, when these notifications are sent using YANG-Push
      <xref target="RFC8639"/><xref target="RFC8641"/>, they can be encoded in other
      encodings such as JSON <xref target="RFC7951"/> or CBOR <xref target="RFC9254"/>.
      In such cases, the model defined in <xref target="RFC5277"/> cannot be used to
      validate the notification header.
      </t>

      <t>This document defines the content of the header of such notifications
      allowing implementations to validate the schema of the notifications when they are encoded
      in other encodings than XML. A YANG 1.1 <xref target="RFC7950"/> model
      is defined for such purposes.</t>

      <t>This document updates <xref target="RFC5277"/>, <xref target="RFC8639"/>
      and <xref target="RFC7951"/> specifying how a Notification header should be
      encoded. RESTCONF Notifications <xref target="RFC8040"/> are out of scope
      of this document.</t>
    </section>

    <section title="Relationship to past documents">

      <t>This section exposes the relationship to <xref target="RFC5277"/>,
      <xref target="RFC8639"/>, <xref target="RFC7951"/> and <xref target="RFC9254"/>.</t>

      <section title="Relationship to RFC5277">
        <t><xref target="RFC5277"/> defines a mechanism for NETCONF nodes to
        send notifications to a collector. These are the key relationships
        between the current document and <xref target="RFC5277"/>:
        </t>

        <t>
          <ul>
            <li>Section 2.1 of <xref target="RFC5277"/> defines how to configure
            a subscription to receive NETCONF Event Notifications. The RPCs are
            defined in the XML schema in Section 3.4 of <xref target="RFC5277"/>.
            This document does not update or add any new RPCs to this schema.</li>

            <li>The notification structure is defined in Section 4 of <xref target="RFC5277"/>
            using a XML schema. This document defines the structure of the notification
            in XML, JSON and CBOR in <xref target="struct-notif"/>. In XML, the same
            structure is used.</li>
          </ul>
        </t>
      </section>

      <section title="Relationship to RFC8639">
        <t>Subscribed Notifications <xref target="RFC8639"/> defines a mechanism 
        on top of <xref target="RFC5277"/> to stream notifications from
        the NETCONF node. These are the key relationships between the current
        document and <xref target="RFC8639"/>:</t>

        <t>
          <ul>
            <li>Section 1.4 of <xref target="RFC8639"/> states that the 
            the solution uses the notification structure defined in
            <xref target="RFC5277"/>. This document replaces this structure
            using a YANG module allowing JSON and CBOR encodings.</li>
          </ul>
        </t>
      </section>

      <section title="Relationship to RFC7951">
        <t><xref target="RFC7951"/> defines how YANG data is encoded using JSON.
        These are the key relationship points between the current document and 
        <xref target="RFC7951"/>:
        </t>

        <t>
          <ul>
            <li><xref target="RFC7951"/> does not define explicitely how a YANG
            notification should be encoded using JSON encoding. This document
            specifies the structure of such notification for JSON when these are
            used in a NETCONF <xref target="RFC6241"/> environment.</li>
          </ul>
        </t>
      </section>

      <section title="Relationship to RFC9254">
        <t><xref target="RFC9254"/> defines how YANG data is encoded using CBOR.
        These are the key relationship points between the current document and 
        <xref target="RFC9254"/>:
        </t>

        <t>
          <ul>
            <li><xref target="RFC9254"/> does not define explicitely how a YANG
            notification should be encoded using CBOR encoding. <xref target="RFC9254"/>
            states that Notifications are container-like instances which does not follow
            how notifications are encoded in XML and JSON encodings.
            This document replaces this statement and ensures consistency between the
            different notification structures in YANG. This structure is to be used
            within NETCONF <xref target="RFC6241"/> environments.</li>
          </ul>
        </t>
      </section>

      
    </section>

    <section title="Differences to draft-ietf-netconf-notification-messages">
      <t>Note to the RFC-Editor: Please remove this section before publishing.</t>

      <t><xref target="I-D.ietf-netconf-notification-messages"/> proposes
      a structure to send multiple notifications in a single message.
      Unlike <xref target="I-D.ietf-netconf-notification-messages"/>,
      this document defines a YANG module to encode NETCONF Notifications
      with encodings other than XML, which is currently not existing.
      The structure for NETCONF notifications is defined in 
      <xref target="RFC5277"/> using a XSD, but there is no YANG module
      defining the structure of the notification message sent by a server
      when the message is encoded in JSON <xref target="RFC7951"/>
      or CBOR <xref target="RFC9254"/>.</t>
    </section>

    <section anchor="struct-notif" title="NETCONF Notification structure">

      <t>This section defines how NETCONF YANG Notifications are structured in
      XML, JSON and CBOR encodings. The same namespace "ietf-notification" is
      used to be compliant with <xref target="RFC5277"/>.</t>

      <section title="XML Structure">
        <t>The same structure as defined in Section 4 of <xref target="RFC5277"/>
        is used. The structure uses the XML namespace that has been defined in
        <xref target="RFC5277"/>:</t>

        <artwork align="left"><![CDATA[
  urn:ietf:params:xml:ns:netconf:notification:1.0
        ]]></artwork>

        <t>Two child nodes within the &quot;notification&quot; container are expected,
        representing the event time and the notification payload.  The "eventTime"
        node is defined within the same XML namespace as the &quot;notification&quot;
        element and is compliant with <xref target="RFC3339"/>.</t>

        <t>The name and namespace of the payload element are determined by the
        YANG module containing the notification statement representing the
        notification message.</t>

        <t>The following example shows a &quot;push-update&quot; notification defined
        in the YANG module of YANG-Push <xref target="RFC8641"/> encoded in XML:</t>

        <figure anchor="fig_xml"
              title="XML-encoded notification">
              <sourcecode type="xml"><![CDATA[
<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
  <eventTime>2022-09-02T10:59:55.32Z</eventTime>
  <push-update xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-push">
    <id>1011</id>
    <datastore-contents>
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface>
          <name>eth0</name>
          <oper-status>up</oper-status>
        </interface>
      </interfaces>
    </datastore-contents>
  </push-update>
</notification>
    ]]></sourcecode>
            </figure>
      </section>
      <section title="JSON Structure">
        <t>A YANG notification encoded in JSON is structured as a root
        "notification" container. The namespace of this container is the name of
        the YANG module "ietf-notification" defined in <xref target="yang-model"/>.</t>

        <t>Two child nodes within the "ietf-notification:notification" container are expected,
        representing the event time and the notification payload.  The "eventTime"
        node is defined within the same namespace as the "ietf-notification:notification"
        container and is compliant with <xref target="RFC3339"/>.</t>

        <t>The following example shows a "push-update" notification defined
        in the YANG module of YANG-Push <xref target="RFC8641"/> encoded in JSON:</t>

        <figure anchor="fig_json"
              title="JSON-encoded notification">
              <sourcecode type="json"><![CDATA[
{
    "ietf-notification:notification": {
        "eventTime": "2023-02-10T08:00:11.22Z",
        "ietf-yang-push:push-update": {
            "id": 1011,
            "datastore-contents": {
                "ietf-interfaces:interfaces": [
                    {
                        "interface": {
                            "name": "eth0",
                            "oper-status": "up"
                        }
                    }
                ]
            }
        }
    }
}
    ]]></sourcecode>
        </figure>
        
        <t>When Notifications are implemented within RESTCONF <xref target="RFC8040"/>
        environments, the namespace of a notification stays "ietf-restconf:notification"
        as defined in Section 6.4 of <xref target="RFC8040"/>.</t>

      </section>
      <section title="CBOR Structure">

        <t>YANG data can be represented in CBOR using Names or SIDs in keys. The following 
        sections shows how these messages are encoded in both cases.</t>

        <section title="CBOR encoded messages">
          <t>Notifications encoded using keys is similar to JSON encoding as defined in
          Section 3.3 of <xref target="RFC9254"/>. The key of the element can be the element
          itself or be namespace-qualified. In the latter case, the namespace of the
          notification container uses the YANG module name "ietf-notification" defined
          in <xref target="yang-model"/>.</t>

          <t>Two child nodes within the "ietf-notification:notification" container are expected,
          representing the event time and the notification payload.  The "eventTime"
          node is defined within the same namespace as the "ietf-notification:notification"
          container and is compliant with <xref target="RFC3339"/>.</t>

          <t>The following example shows a "push-update" notification defined
          in the YANG module of YANG-Push <xref target="RFC8641"/> encoded in CBOR
          using names as keys. The example uses the CBOR diagnostic notation as defined
          in section 3.1 of <xref target="RFC9254"/>:</t>

          <figure anchor="fig_cbor"
              title="CBOR-encoded notification using diagnostic notation">
              <sourcecode type="cbor-diag"><![CDATA[
{
    "ietf-notification:notification": {
        "eventTime": "2023-02-10T08:00:11.22Z",
        "ietf-yang-push:push-update": {
            "id": 1011,
            "datastore-contents": {
                "ietf-interfaces:interfaces": [
                    {
                        "interface": {
                            "name": "eth0",
                            "oper-status": "up"
                        }
                    }
                ]
            }
        }
    }
}
    ]]></sourcecode>
          </figure>
        </section>
        <section title="CBOR encoded messages using YANG-SIDs">

          <t>A Notification encoded using YANG-SIDs replaces the names of
          the keys of the CBOR encoded message for a 63 bit unsigned integer.
          This is defined in Section 3.2 of <xref target="RFC9254"/> and
          a process for SID allocation is defined in <xref target="I-D.ietf-core-sid"/>.</t>

          <t>Two child nodes within the root container are expected,
          representing the event time and the notification payload. The root container
          and the "eventTime" node uses a SID and the content of the "eventTime" is
          compliant with <xref target="RFC3339"/>.</t>

          <t>This is an example of YANG-CBOR encoded notification using YANG SIDs 
          <xref target="RFC9254"/>. The <xref target="fig_cbor_sid"/> shows
          the message using the CBOR diagnostic notation as defined in section 3.1 of
          <xref target="RFC9254"/>:</t>

          <figure anchor="fig_cbor_sid"
              title="CBOR-encoded notification using YANG SIDs in CBOR diagnostic notation">
              <sourcecode type="cbor-diag"><![CDATA[
{
    2551: {
        1: "2023-02-10T08:00:11.22Z",
        "ietf-yang-push:push-update": {
            "id": 1011,
            "datastore-contents": {
                "ietf-interfaces:interfaces": [
                    {
                        "interface": {
                            "name": "eth0",
                            "oper-status": "up"
                        }
                    }
                ]
            }
        }
    }
}
    ]]></sourcecode>
          </figure>
        </section>
      </section>
    </section>

    <section anchor="yang-model" title="YANG Module">

      <section anchor="yang-tree" title="YANG Tree Diagram">
        <t>This YANG module adds a structure with one leaf for the datetime as defined in 
        section 2.2.1 of <xref target="RFC5277"/>. The name of the leaf matches the 
        definition of the XSD element name defined in Section 4 of <xref target="RFC5277"/>.
        </t>

          <sourcecode type="yangtree"><![CDATA[
module: ietf-notification

  structure notification:
    +-- eventTime    yang:date-and-time
]]></sourcecode>
      </section>

      <section anchor="yang-module" title="YANG Module">
      <t>The YANG module uses the same namespace from the XML Schema
      defined in Section 4 of <xref target="RFC5277"/> allowing to use this YANG module 
      to also validate already implemented XML encoded NETCONF Event Notifications.</t>

      <sourcecode type="yang" markers="true" name="ietf-notification@2024-06-17.yang"><![CDATA[
module ietf-notification {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:netconf:notification:1.0";
  prefix inotif;
  import ietf-yang-types {
    prefix yang;
    reference
      "RFC 6991: Common YANG Data Types";
  }
  import ietf-yang-structure-ext {
    prefix sx;
    reference
      "RFC 8791: YANG Data Structure Extensions";
  }

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

     Authors:  Alex Huang Feng
               <mailto:alex.huang-feng@insa-lyon.fr>
               Pierre Francois
               <mailto:pierre.francois@insa-lyon.fr>
               Thomas Graf
               <mailto:thomas.graf@swisscom.com>
               Benoit Claise
               <mailto:benoit.claise@huawei.com>";

  description
    "Defines NETCONF Event Notification structure as defined in
    RFC5277 and RFC7950. This YANG module uses the same namespace
    from the XML schema defined in Section 4 of RFC5277 to be able to
    validate already implemented XML encoded messages.
    
    This module can be used to validate XML encoded notifications
    [RFC7950], JSON encoded messages [RFC7951] and CBOR encoded
    messages [RFC9254]. Refer to Section 4 of RFC XXXX for more
    details.

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

  revision 2024-06-17 {
    description
      "First revision";
    reference
      "RFC XXXX: NETCONF Event Notification YANG";
  }

  sx:structure notification {
    leaf eventTime {
      type yang:date-and-time;
      mandatory true;
      description
        "The date and time the event was generated by the event
        source. This parameter is of type dateTime and compliant
        to [RFC3339]. Implementations must support time zones.
        The leaf name in camel case matches the name of the XSD
        element defined in Section 4 of RFC5277.";
    }
  }
}
]]></sourcecode>
      </section>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t>The security considerations for the NETCONF Event notifications
      are described in <xref target="RFC5277"/>. This documents adds
      no additional security considerations.</t>
    </section>

    <section anchor="IANA_Considerations" title="IANA Considerations">

      <t>This document describes the URI used for the IETF XML Registry and
      registers a new YANG module name.</t>

      <section title="URI">
      <t>IANA is requested to add this document as a reference in the following
      URI in the <xref target="RFC3688">IETF XML Registry</xref>.</t>

      <artwork align="left"><![CDATA[
URI: urn:ietf:params:xml:ns:netconf:notification:1.0
Registrant Contact: The IESG.
XML: N/A; the requested URI is an XML namespace.
Reference: RFC5277; RFC-to-be]]></artwork>
      </section>

      <section title="YANG module name">

        <t>This document registers the following YANG module in the <xref
        target="RFC6020">YANG Module Names Registry</xref>, within the
        "YANG Parameters" registry:</t>

        <artwork align="left"><![CDATA[
name: ietf-notification
namespace: urn:ietf:params:xml:ns:netconf:notification:1.0
prefix: inotif
reference: RFC-to-be]]></artwork>
      </section>

      <section title="YANG SID-file" anchor="iana-sid">
        <t>IANA is requested to register a new ".sid" file in the <xref
        target="I-D.ietf-core-sid">"IETF YANG SID Registry"</xref>:</t>

        <artwork align="left"><![CDATA[
SID range entry point: TBD
SID range size: 50
YANG module name: ietf-notification
reference: RFC-to-be]]></artwork>

        <t>A ".sid" file is proposed in <xref target="sid_appendix"/>.</t>
      </section>
    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>The authors would like to thank Per Anderson, Andy Bierman, Carsten Bormann,
      Mohamed Boucadair, Tom Petch, Jason Sterne, Kent Watsen and Rob Wilton for
      their review and valuable comments.</t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.3688.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.5277.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.6020.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.6241.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.6991.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.7950.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.7951.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8174.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8639.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8641.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8791.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.9254.xml"?>

      <reference anchor="W3C.REC-xml-20001006"
                 derivedAnchor="W3C.REC-xml-20001006" quoteTitle="true"
                 target="https://www.w3.org/TR/2000/REC-xml-20001006">
        <front>
          <title>Extensible Markup Language (XML) 1.0 (Second Edition)</title>

          <author fullname="Tim Bray" initials="T." surname="Bray">
            <organization showOnFrontPage="true"/>
          </author>

          <author fullname="Jean Paoli" initials="J." surname="Paoli">
            <organization showOnFrontPage="true"/>
          </author>

          <author fullname="Michael Sperberg-McQueen" initials="M."
                  surname="Sperberg-McQueen">
            <organization showOnFrontPage="true"/>
          </author>

          <author fullname="Eve Maler" initials="E." surname="Maler">
            <organization showOnFrontPage="true"/>
          </author>

          <date month="October" year="2000"/>
        </front>

        <refcontent>W3C</refcontent>
      </reference>
      
      <?rfc include="https://bib.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-core-sid.xml"?>

    </references>

    <references title="Informative References">
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8340.xml"?>
      <?rfc include="https://xml.resource.org/public/rfc/bibxml/reference.RFC.8040.xml"?>
      <?rfc include="https://datatracker.ietf.org/doc/bibxml3/draft-ietf-netconf-notification-messages-08.xml"?>
    </references>

    <section title=".sid file" anchor="sid_appendix">
      <t>Note to the RFC-Editor: Please remove this section before publishing.</t>

      <t>For CBOR encoding using YANG-SIDs identifiers, a ".sid" file is requested
      to IANA in <xref target="iana-sid"/>.</t>

      <figure anchor="fig_sid_file"
            title='.sid file for "ietf-notification" module'>
        <sourcecode type="yang-sid" markers="true" name="ietf-notification@2024-05-27.sid"><![CDATA[
{
  "ietf-sid-file:sid-file": {
    "module-name": "ietf-notification",
    "module-revision": "2024-05-27",
    "description": "NETCONF Event Notification structure",
    "dependency-revision": [
      {
        "module-name": "ietf-yang-types",
        "module-revision": "2013-07-15"
      },
      {
        "module-name": "ietf-yang-structure-ext",
        "module-revision": "2020-06-17"
      }
    ],
    "assignment-range": [
      {
        "entry-point": "2550",
        "size": "50"
      }
    ],
    "item": [
      {
        "namespace": "module",
        "identifier": "ietf-notification",
        "sid": "2550"
      },
      {
        "namespace": "data",
        "identifier": "/ietf-notification:notification",
        "sid": "2551"
      },
      {
        "namespace": "data",
        "identifier": "/ietf-notification:notification/eventTime",
        "sid": "2552"
      }
    ]
  }
}
    ]]></sourcecode>
      </figure>
    </section>
  </back>
</rfc>
