<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="rfc7991bis.rnc"?>  <!-- Required for schema validation and schema-aware editing -->

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc
  xmlns:xi="http://www.w3.org/2001/XInclude"
  category="std"
  docName="draft-wills-netmod-yang-templates-00"
  ipr="trust200902"
  obsoletes=""
  updates=""
  submissionType="IETF"
  xml:lang="en"
  version="3"
  consensus="true">


  <front>
    <title abbrev="Yang Templates">Yang Templates</title>
    <seriesInfo name="Internet-Draft" value="draft-wills-netmod-yang-templates-00"/>
    <author fullname="Robert Wills" initials="R" surname="Wills">
      <organization>Cisco Systems</organization>
      <address>
        <email>rowills@cisco.com</email>
      </address>
    </author>
  
    <date day="2" month="3" year="2025"/>

    <area>General</area>
    <workgroup>Internet Engineering Task Force</workgroup>

    <keyword>NETCONF</keyword>

    <abstract>
      <t>Yang Templates is a way to more easily manage a network device's
      configuration when parts of that configuration are repetitive.  This
      document provides a high-level description of Yang Templates, and is
      expected to evolve into a full solution in later versions.</t>
    </abstract>
  </front>

  <middle>
    
    <section>
      <name>Introduction</name>
      <t>This document describes a mechanism whereby nodes of configuration
      data can be placed into templates, and templates can be applied to
      subtrees in a configuration datastore.  When a template is applied to a
      subtree, the configuration in the template takes effect for that subtree
      (unless other configuration takes precedence, as described later in this
      document).</t>

      <t>The contents of this document are based on discussions in two Interim
      Meetings of the Netmod working group.  It was written <em>after</em>
      those meetings and is intended to summarise the outcomes as a set of
      high-level requirements.  It is not an exhaustive set of minutes.</t>

      <t>It's expected that later versions of this document will contain a
      fuller description of Yang Templates.</t>

      <section>
        <name>Requirements Language</name>
        <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>
      </section>

    </section>

    <section>
      <name>Overview</name>
      <t>The configuration of network devices is modeled using the
      <xref target="RFC7950">Yang</xref> language, and the configuration of a
      specific device is determined by the contents of one or more
      configuration datastores on the device.</t>

      <t>A configuration datastore often contains multiple subtrees with
      similar or identical nodes within them.  For example, a device may be
      configured to have multiple BGP neighbors.  Each neighbor could have an
      identical set of properties (achieved using identical configuration on
      each neighbor), and neighbor-specific properties such as the address
      (achieved using configuration that varies between neighbors).</t>

      <t>In this situation, a client must ensure that each set of identical
      nodes exists in all the relevant subtrees of the datastore and that each
      occurrence of a node has the same value in order to achieve the correct
      intended configuration.  This creates problems in keeping occurrences of
      these nodes in sync and understanding the contents of a large
      configuration datastore.</t>

      <t>Yang Templates defines fragments of configuration called "templates".
      When an implementation supports Yang Templates, the client is able to use
      existing network management protocols such as
      <xref target="RFC6241">NETCONF</xref> to:</t>
      <ul>
        <li>Manage the configuration inside each template.</li>
        <li>Apply templates to subtrees of the datastore.</li>
      </ul>

      <t>The configuration from templates and the configuration not in
      templates is combined together to produce an intended datastore that
      describes the configuration of the device.</t>
    </section>

    <section>
      <name>Requirements</name>
      <t>This section describes the requirements that the Yang Templates
      solution must satisfy.  These requirements were all discussed in the
      Interim Meetings, and a rough consensus was reached on each of them by
      the participants in the meetings.</t>

      <t>A general theme of the Yang Templates work is to come up with a
      "Minimal Viable Product" that is useful but not over-complicated.  More
      advanced features could be considered as extensions in later drafts.</t>

      <section>
        <name>Defining and managing templates</name>
        <t>Templates can be used with any Yang module.  They contain nodes of
        configuration data, and are stored persistently in the running
        datastore of the device.</t>

        <t>A client can view and manipulate a template, including the
        configuration inside it, by manipulating it in the &lt;running&gt;
        datastore.  In this sense, a template and its contents behaves like any
        other subtree of configuration.</t>
      </section>

      <section>
        <name>Applying templates</name>
        <t>A template can be applied to zero or more nodes in the
        &lt;running&gt; datastore.  Each node can have zero or more templates
        applied to it, and the order they are applied is specified by the
        client.  The order is important when determining the final intended
        configuration -- see the next section.</t>

        <t>Templates can be applied at multiple points in the hierachy.  The
        next section states the requirements when a node applies a template and
        it has an ancestor that also applies a template.</t>

        <t>When viewing the &lt;running&gt; datastore, there is a mechanism to
        see which templates have been applied to each node, and in which
        order.</t>
      </section>

      <section>
        <name>Producing the &lt;intended&gt; datastore</name>
        <t>The device's &lt;intended&gt; datastore is the result of combining
        all the applications of templates together with non-template config.
        This is called "expanding out" the templates.</t>

        <t>The intended configuration inside a subtree is the result of
        taking the relevant contents of every template applied to the subtree's
        root node and its ancestors, and combining it with the (non-template)
        data nodes inside the subtree.</t>

        <t>A node inside a subtree may be present in multiple templates that
        have been applied, and/or it may be present as non-template config
        inside the subtree.  The requirements for combining the templates and
        the non-template config together are as follows:</t>
        <ul>
          <li>The value of a node in the &lt;intended&gt; configuration is
          determined by using precedence to decide where to take the value
          from.</li>
          <li>Non-template config always has the highest precedence.</li>
          <li>When templates are applied to multiple ancestors, the innermost
          ancestor takes precedence.</li>
          <li>When multiple templates are applied to a particular node, the
          order of application (as indicated by the client when applying the
          templates) determines the precedence within that node.</li>
        </ul>

        <t>Whenever the contents of a template is updated in &lt;running&gt;,
        the result of expanding out the template appears in
        &lt;intended&gt; and takes effect on the device.</t>
      </section>

      <section>
        <name>Pattern matching in templates</name>
        <t>The configuration inside a template definition can contain values
        for list keys that are simple regular expressions, using a limited
        subset of regular expression syntax.  This controls which list entries
        that subtree of the template takes effect for when it is applied.</t>

        <t>An example of this would be to have a template that is applied to
        a top-level &lt;interfaces&gt; container, but the template only takes
        effect for certain interface names that match the regular
        expression.</t>
      </section>

      <section>
        <name>Off-box template expansion</name>
        <t>If the client knows the contents of the &lt;running&gt; datastore
        (non-template config, template definitions and template applications),
        it must be possible for the client to calculate the result of
        template expansion.</t>

        <t>In other words, the outcome of template expansion depends solely on
        the &lt;running&gt; datastore and not the state of the device.</t>
      </section>
    </section>

    <section anchor="IANA">
      <name>IANA Considerations</name>
      <t>This memo includes no request to IANA.</t>
    </section>
    
    <section anchor="Security">
      <name>Security Considerations</name>
      <t>This document should not affect the security of the Internet.</t>
    </section>
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6241.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.7950.xml"/>
        <!-- The recommended and simplest way to include a well known reference -->
        
      </references>
 
      <references>
        <name>Informative References</name>
      </references>
    </references>
    
    <section anchor="Acknowledgements" numbered="false">
      <name>Acknowledgements</name>
      <t>The author would like to thank Shiya Ashraf, Lou Berger, Quifang Ma,
      Robert Peschi, Deepak Rajaram, Jason Sterne, Kent Watsen and
      Robert Wilton for comments and contributions made during interim
      meetings.</t>

      <t>The author would like to acknowledge the following drafts and
      presenters for kick-starting discussions on Yang Templates:</t>
      <ul>
        <li>draft-ma-netmod-yang-config-template-00</li>
        <li>draft-rajaram-netmod-yang-cfg-template-framework-00</li>
        <li>Jan Lindblad</li>
      </ul>
    </section>

 </back>
</rfc>
