<?xml version="1.0" encoding="US-ASCII"?>

<?xml-stylesheet type="text/xsl" href="rfc2629.xslt"?>

<!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>
<?rfc toc="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc iprnotified="no"?>
<?rfc strict="yes"?>

<rfc ipr="trust200902" category="bcp" submissionType="IETF" consensus="yes"
    number="8340" seriesNo="215">

    <front>
    <title abbrev="YANG Tree Diagrams">YANG Tree Diagrams</title>

    <author initials="M" surname="Bjorklund" fullname='Martin Bjorklund' >
      <organization>Tail-f Systems</organization>
      <address>
        <email>mbj@tail-f.com</email>
      </address>
    </author>

    <author initials="L" surname="Berger" fullname='Lou Berger' role="editor">
      <organization>LabN Consulting, L.L.C.</organization>
      <address>
        <email>lberger@labn.net</email>
      </address>
    </author>

    <date month="March" year="2018"/>

    <abstract>
        <t>
This document captures the current syntax used in YANG module
tree diagrams.  The purpose of this document is to provide a single
location for this definition.  This syntax may be updated from time to time
based on the evolution of the YANG language.
        </t>
</abstract>
</front>

<middle>
<section title="Introduction" anchor="introduction">
    <t>
YANG tree diagrams were first published in RFC 6536. Such diagrams
are used to provide a simplified graphical representation of
a data model and can be automatically generated via tools such as
&quot;pyang&quot; <xref target="PYANG" />.  This document describes
the syntax used in YANG tree diagrams.  It is expected that this
document will be updated or replaced as changes to the YANG language
<xref target="RFC7950"/> necessitate.
    </t>
    <t>
Today&apos;s common practice is to include the definition of the syntax
used to represent a YANG module in every document that provides a tree
diagram.  This practice has several disadvantages; therefore, the purpose
of this document is to provide a single location for this definition.  It
is not the intent of this document to restrict future changes, but
rather to ensure that such changes are easily identified and suitably
agreed upon.
    </t>
    <t>
An example tree diagram can be found in
Section&nbsp;3 of <xref target="RFC8343"/>; the following is a
portion of it:
    </t>
        <figure>
            <artwork><![CDATA[
  +--rw interfaces
     +--rw interface* [name]
        +--rw name                        string
        +--rw description?                string
        +--rw type                        identityref
        +--rw enabled?                    boolean
        +--rw link-up-down-trap-enable?   enumeration {if-mib}? ]]></artwork>
   </figure>

</section>

<section title="Tree Diagram Syntax" anchor="tree-diagram-syntax">
    <t>
This section describes the meaning of the symbols used in YANG
tree diagrams.
    </t>
    <t>
A full tree diagram of a module represents all elements.  It includes
the name of the module and sections for top&nbhy;level module statements
(typically containers), augmentations, rpcs, and notifications all
identified under a module statement.  Module trees may be included in a
document as a whole, by one or more sections, or even by subsets of nodes.
    </t>
    <t>
A module is identified by &quot;module:&quot; followed by the module-name.
This is followed by one or more sections, in order:
    </t>
<t>
 <list style="numbers">
 <t>
The top-level data nodes defined in the module, offset by two&nbsp;spaces.
 </t>
 <t>
Augmentations, offset by two spaces and identified by the keyword
&quot;augment&quot; followed by the augment target node and a colon
(&quot;:&quot;) character.
 </t>
 <t>
RPCs, offset by two spaces and identified by &quot;rpcs:&quot;.
 </t>
 <t>
Notifications, offset by two spaces and identified by
&quot;notifications:&quot;.
 </t>
 <t>
Groupings, offset by two spaces and identified by the keyword
&quot;grouping&quot; followed by the name of the grouping and a colon
(&quot;:&quot;) character.
 </t>
 <t>
yang-data, offset by two spaces and identified by the keyword
&quot;yang&#8209;data&quot; followed by the name of the yang-data structure
and a colon (&quot;:&quot;) character.
 </t>
 </list>
</t>
    <t>
The relative organization of each section is provided using a text&nbhy;based
format that is typical of a file system directory tree display command.
Each node in the tree is prefaced with &quot;+&#8209;&#8209;&quot;.  Schema
nodes that are children of another node are offset from the parent by
three&nbsp;spaces. Sibling schema nodes are listed with the same space offset
and, when separated by lines, are linked via a vertical bar (&quot;|&quot;)
character.
    </t>
    <t>
The full format, including spacing conventions, is:
    </t>

        <figure>
            <artwork><![CDATA[
  module: <module-name>
    +--<node>
    |  +--<node>
    |     +--<node>
    +--<node>
       +--<node>
          +--<node>

    augment <target-node>:
      +--<node>
         +--<node>
         +--<node>
            +--<node>
    augment <target-node>:
      +--<node>

    rpcs:
      +--<rpc-node>
      +--<rpc-node>
         +--<node>
         |  +--<node>
         +--<node>

    notifications:
      +--<notification-node>
      +--<notification-node>
         +--<node>
         |  +--<node>
         +--<node>

    grouping <grouping-name>:
      +--<node>
         +--<node>
         |  +--<node>
         +--<node>
    grouping <grouping-name>:
      +--<node>

    yang-data <yang-data-name>:
      +--<node>
         +--<node>
         |  +--<node>
         +--<node>
    yang-data <yang-data-name>:
      +--<node>
            ]]></artwork>
        </figure>

<section title="Submodules" anchor="submodules">
    <t>
Submodules are represented in the same fashion as modules but are
identified by &quot;submodule:&quot; followed by the (sub)module-name.
For example:

    </t>
        <figure>
            <artwork><![CDATA[
  submodule: <module-name>
    +--<node>
    |  +--<node>
    |     +--<node>
            ]]></artwork>
        </figure>
</section>
<section title="Groupings" anchor="groupings">
    <t>
Nodes within a used grouping are normally expanded as if the nodes
were defined at the location of the &quot;uses&quot; statement.  However,
it is also possible to not expand the &quot;uses&quot; statement but to
instead print the name of the grouping.
    </t>
    <t>
For example, the following diagram shows the &quot;tls&#8209;transport&quot;
grouping from <xref target="RFC7407"/> unexpanded:
    </t>
        <figure>
            <artwork><![CDATA[
    +--rw tls
       +---u tls-transport
            ]]></artwork>
        </figure>
    <t>
If the grouping is expanded, it could be printed as:
    </t>
        <figure>
            <artwork><![CDATA[
    +--rw tls
       +--rw port?                 inet:port-number
       +--rw client-fingerprint?   x509c2n:tls-fingerprint
       +--rw server-fingerprint?   x509c2n:tls-fingerprint
       +--rw server-identity?      snmp:admin-string
            ]]></artwork>
        </figure>
    <t>
Groupings may optionally be present in the &quot;groupings&quot; section.
    </t>
</section>

<section title="yang-data" anchor="yang-data">
    <t>
If the module defines a &quot;yang&#8209;data&quot; structure <xref
target="RFC8040"/>, these structures may optionally be present in the
&quot;yang&#8209;data&quot; section.
    </t>
</section>

<section title="Collapsed Node Representation" anchor="collapsed-node-representation">
    <t>
At times when the composition of the nodes within a module schema is not
important in the context of the presented tree, sibling nodes and their
children can be collapsed using the notation &quot;...&quot; in place of the
text lines used to represent the summarized nodes.  For example:
    </t>
        <figure>
            <artwork><![CDATA[
    +--<node>
    |  ...
    +--<node>
       +--<node>
          +--<node>
            ]]></artwork>
        </figure>
</section>

<section title="Comments" anchor="comments">
    <t>
Single line comments, starting with &quot;//&quot; (possibly indented) and
ending at the end of the line, may be used in the tree notation.
    </t>
</section>

<section title="Node Representation" anchor="node-representation">
    <t>
Each node in a YANG module is printed as:
    </t>

        <figure>
            <artwork><![CDATA[
  <status>--<flags> <name><opts> <type> <if-features>

    <status> is one of:
      +  for current
      x  for deprecated
      o  for obsolete

    <flags> is one of:
      rw  for configuration data nodes and choice nodes
      ro  for non-configuration data nodes and choice nodes,
          output parameters to rpcs and actions, and
          notification parameters
      -w  for input parameters to rpcs and actions
      -u  for uses of a grouping
      -x  for rpcs and actions
      -n  for notifications
      mp  for nodes containing a "mount-point" extension statement

      Case nodes do not have any <flags>.

    <name> is the name of the node
      (<name>) means that the node is a choice node
     :(<name>) means that the node is a case node

      If the node is augmented into the tree from another module,
      its name is printed as <prefix>:<name>, where <prefix> is the
      prefix defined in the module where the node is defined.

      If the node is a case node, there is no space before the
      <name>.

    <opts> is one of:
      ?  for an optional leaf, choice, anydata, or anyxml
      !  for a presence container
      *  for a leaf-list or list
      [<keys>] for a list's keys
      /  for a top-level data node in a mounted module
      @  for a top-level data node of a module identified in a
         mount point parent reference

    <type> is the name of the type for leafs and leaf-lists

      If the type is a leafref, the type is printed as either
      (1) "-> TARGET", where TARGET is the leafref path,
      with prefixes removed if possible or (2) "leafref".

    <if-features> is the list of features this node depends on,
      printed within curly brackets and a question mark "{...}?"
            ]]></artwork>
        </figure>

    <t>
Arbitrary whitespace is allowed between any of the whitespace-separated
fields (e.g., &lt;opts&gt; and &lt;type&gt;). Additional whitespace may,
for example, be used to "column align" fields (e.g., within a list or
container) to improve readability.
    </t>
</section>
</section>

<section title="Usage Guidelines for RFCs" anchor="usage-guidelines-for-rfcs">
    <t>
This section provides general guidelines related to the use of
tree diagrams in RFCs.
    </t>

<section title="Wrapping Long Lines" anchor="wrapping-long-lines">
    <t>
Internet-Drafts and RFCs limit the number of characters that may appear
in a line of text to 72&nbsp;characters.  When the tree representation of a
node results in a line being longer than this limit, the line should be broken
between &lt;opts&gt; and &lt;type&gt; or between &lt;type&gt; and
&lt;if&#8209;feature&gt;.  The new line should be indented so that it starts
below &lt;name&gt; with a whitespace offset of at least two characters. For
example:
    </t>

        <figure>
            <artwork><![CDATA[
  notifications:
    +---n yang-library-change
       +--ro module-set-id
               -> /modules-state/module-set-id
            ]]></artwork>
        </figure>

    <t>
Long paths (e.g., leafref paths or augment targets) can be split and
printed on more than one line.  For example:
    </t>

        <figure>
            <artwork><![CDATA[
  augment /nat:nat/nat:instances/nat:instance/nat:mapping-table
            /nat:mapping-entry:
            ]]></artwork>
        </figure>

    <t>
The previously mentioned &quot;pyang&quot; command can be helpful in producing
such output; for example, the notification diagram above was produced using:
    </t>

        <figure>
            <artwork><![CDATA[
  pyang -f tree --tree-line-length 50 ietf-yang-library.yang
            ]]></artwork>
        </figure>

    <t>
When a tree diagram is included as a figure in an Internet&nbhy;Draft or
RFC, &quot;--tree-line-length 69&quot; works well.
    </t>
</section>

<section title="Groupings" anchor="groupings-2">
    <t>
If the YANG module is comprised of groupings only, then the tree
diagram should contain the groupings.  The &quot;pyang&quot; compiler
can be used to produce a tree diagram with groupings using the
<vspace/>
&quot;-f tree --tree-print-groupings&quot; command-line parameters.
    </t>
</section>

<section title="Long Diagrams" anchor="long-diagrams">
    <t>
Tree diagrams can be split into sections to correspond to
document structure. As tree diagrams are intended to provide a simplified
view of a module, diagrams longer than a page should generally be avoided.
If the complete tree diagram for a module becomes too long, the diagram
can be split into several smaller diagrams.  For example, it might be possible
to have one diagram with the data node and another with all notifications.  If
the data nodes tree is too long, it is also possible to split the diagram
into smaller diagrams for different subtrees. When long diagrams are included
in a document, authors should consider whether to include the long diagram in
the main body of the document or in an appendix.
    </t>
    <t>
An example of such a split can be found in <xref target="RFC7407"/>, where
Section&nbsp;2.4 of that document shows the diagram for &quot;engine
configuration&quot;:
    </t>

        <figure>
            <artwork><![CDATA[
    +--rw snmp
       +--rw engine
          // more parameters from the "engine" subtree here
            ]]></artwork>
        </figure>

    <t>
Further, Section 2.5 of <xref target="RFC7407"/> shows the diagram for
&quot;target configuration&quot;:
    </t>

        <figure>
            <artwork><![CDATA[
    +--rw snmp
       +--rw target* [name]
          // more parameters from the "target" subtree here
            ]]></artwork>
        </figure>

    <t>
The previously mentioned &quot;pyang&quot; command can be helpful in producing
such output; for example, the above example was produced using:
    </t>

        <figure>
            <artwork><![CDATA[
  pyang -f tree --tree-path /snmp/target ietf-snmp.yang
            ]]></artwork>
        </figure>

</section>
</section>

<section title="YANG Schema Mount Tree Diagrams" anchor="yang-schema-mount-tree-diagrams">
    <t>
"YANG schema mount" is defined in <xref target="SCHEMA-MOUNT"/>
and warrants some specific discussion. Schema mount is a generic mechanism
that allows for the mounting of one or more YANG  modules at a specified
location of another (parent) schema. The specific location is referred
to as a &quot;mount point&quot;, and any container or list node in a schema
may serve as a mount point.  Mount points are identified via the inclusion
of the &quot;mount&#8209;point&quot; extension statement as a substatement
under a container or list node. Mount point nodes are thus directly identified
in a module schema definition and can be identified in a tree diagram
as indicated above using the &quot;mp&quot; flag.
    </t>
    <t>
In the following example taken from <xref target="YANG-NIs"/>,
&quot;vrf&#8209;root&quot; is a container that includes the
&quot;mount&#8209;point&quot; extension statement as part of its definition:
    </t>
        <figure>
            <artwork><![CDATA[
  module: ietf-network-instance
    +--rw network-instances
       +--rw network-instance* [name]
          +--rw name           string
          +--rw enabled?       boolean
          +--rw description?   string
          +--rw (ni-type)?
          +--rw (root-type)
             +--:(vrf-root)
             |  +--mp vrf-root
            ]]></artwork>
        </figure>

<section title="Representation of Mounted Schema Trees" anchor="representation-of-mounted-schema-trees">
    <t>
The actual modules made available under a mount point are controlled by a
server and are provided to clients.  This information is typically
provided via the schema mount module ("ietf&nbhy;yang&nbhy;schema&nbhy;mount")
defined in <xref target="SCHEMA-MOUNT"/>.  The schema mount module supports
the exposure of both mounted schema and &quot;parent&#8209;references&quot;.
Parent references are used for XML Path Language (XPath) evaluation within
mounted modules and do not represent client-accessible paths; the referenced
information is available to clients via the parent schema.  Schema mount also
defines an &quot;inline&quot; type of mount point, where mounted modules are
exposed via the YANG library module.
    </t>
    <t>
Although the modules made available under a mount point are not specified
in YANG modules that include mount points, the document defining the
module will describe the intended use of the module and may identify
both modules that will be mounted and parent modules that can be
referenced by mounted modules.  An example of such a description can be
found in <xref target="YANG-NIs"/>.  A specific implementation of a
module containing mount points will also support a specific list of
mounted and referenced modules.  In describing both intended use and
actual implementations, it is helpful to show how mounted modules
would be instantiated and referenced under a mount point using tree
diagrams.
    </t>
    <t>
In such diagrams, the mount point should be treated much like a
container that uses a grouping.  The flags should also be set based on
the &quot;config&quot; leaf mentioned above, and the mount-related options
indicated above should be shown for the top&nbhy;level nodes in a mounted or
referenced module.  The following example, taken from
<xref target="YANG-NIs"/>, represents the prior example with the
YANG modules &quot;ietf&nbhy;routing&quot; <xref target="YANG-Routing"/>
and &quot;ietf&nbhy;ospf&quot; <xref target="OSPF-YANG"/> mounted, nodes
from the YANG module &quot;ietf&nbhy;interfaces&quot;
<xref target="RFC8343"/> accessible via a parent&nbhy;reference,
and &quot;config&quot; indicating &quot;true&quot;:
    </t>

        <figure>
            <artwork><![CDATA[
  module: ietf-network-instance
    +--rw network-instances
       +--rw network-instance* [name]
          +--rw name           string
          +--rw enabled?       boolean
          +--rw description?   string
          +--rw (ni-type)?
          +--rw (root-type)
             +--:(vrf-root)
                +--mp vrf-root
                   +--ro rt:routing-state/
                   |  +--ro router-id?
                   |  +--ro control-plane-protocols
                   |     +--ro control-plane-protocol* [type name]
                   |        +--ro ospf:ospf
                   |           +--ro instance* [af]
                   |           ...
                   +--rw rt:routing/
                   |  +--rw router-id?
                   |  +--rw control-plane-protocols
                   |     +--rw control-plane-protocol* [type name]
                   |     +--rw ospf:ospf
                   |        +--rw instance* [af]
                   |           ...
                   +--ro if:interfaces@
                   |  ...
                   +--ro if:interfaces-state@
                   |  ...
            ]]></artwork>
        </figure>
    <t>
It is worth highlighting that the &quot;ietf-ospf&quot; module augments the
&quot;ietf&nbhy;routing&quot; module, and although it is listed in the
schema mount module (or inline YANG library), there is no special
mount-related notation in the tree diagram.
    </t>
    <t>
A mount point definition alone is not sufficient to identify whether
the mounted modules are used for configuration data or for
non&nbhy;configuration data. This is determined by the
&quot;ietf&#8209;yang&#8209;schema&#8209;mount&quot; module&apos;s 
&quot;config&quot; leaf associated with the specific mount point and is
indicated on the top&nbhy;level mounted nodes. For example, in the above tree,
when the &quot;config&quot; leaf for the &quot;ietf&nbhy;routing&quot; module
indicates &quot;false&quot;, the nodes in the &quot;rt:routing&quot; subtree
would have different flags:
    </t>

        <figure>
            <artwork><![CDATA[
                   +--ro rt:routing/
                   |  +--ro router-id?
                   |  +--ro control-plane-protocols
                      ...
            ]]></artwork>
        </figure>
</section>
</section>

<section title="IANA Considerations" anchor="iana-considerations">
    <t>
This document has no IANA actions.
    </t>
</section>

<section title="Security Considerations" anchor="security-considerations">
    <t>
There is no security impact related to the tree diagrams defined in this
document.
    </t>
</section>
</middle>

<back>
<references title="Informative References">

    <?rfc include="reference.RFC.7407"?>
    <?rfc include="reference.RFC.7950"?>
    <?rfc include="reference.RFC.8040"?>

<!-- draft-ietf-netmod-rfc7223bis (RFC 8343 - AUTH48) -->
<reference anchor="RFC8343" target="https://www.rfc-editor.org/info/rfc8343">
  <front>
    <title>A YANG Data Model for Interface Management</title>
    <author initials="M" surname="Bjorklund" fullname="Martin Bjorklund">
      <organization/>
    </author>
  <date month="March" year="2018"/>
  </front>
<seriesInfo name="RFC" value="8343"/>
<seriesInfo name="DOI" value="10.17487/RFC8343"/>
</reference>

<!-- draft-ietf-netmod-schema-mount (I-D Exists) -->
<reference anchor="SCHEMA-MOUNT">
  <front>
    <title>YANG Schema Mount</title>
    <author initials="M" surname="Bjorklund" fullname="Martin Bjorklund">
      <organization/>
    </author>
    <author initials="L" surname="Lhotka" fullname="Ladislav Lhotka">
      <organization/>
    </author>
    <date month="October" year="2017"/>
  </front>
  <seriesInfo name="Work in Progress," value="draft-ietf-netmod-schema-mount-08"/>
</reference>

<!-- draft-ietf-rtgwg-ni-model (MISSREF) -->
<reference anchor="YANG-NIs">
  <front>
    <title>YANG Model for Network Instances</title>
    <author initials="L" surname="Berger" fullname="Lou Berger">
      <organization/>
    </author>
    <author initials="C" surname="Hopps" fullname="Christian Hopps">
      <organization/>
    </author>
    <author initials="A" surname="Lindem" fullname="Acee Lindem">
      <organization/>
    </author>
    <author initials="D" surname="Bogdanovic" fullname="Dean Bogdanovic">
      <organization/>
    </author>
    <author initials="X" surname="Liu" fullname="Xufeng Liu">
      <organization/>
    </author>
    <date month="March" year="2018"/>
  </front>
  <seriesInfo name="Work in Progress," value="draft-ietf-rtgwg-ni-model-11"/>
</reference>

<!-- draft-ietf-netmod-rfc8022bis (RFC-EDITOR) -->
<reference anchor='YANG-Routing'>
<front>
<title>A YANG Data Model for Routing Management (NMDA Version)</title>
<author initials='L' surname='Lhotka' fullname='Ladislav Lhotka'>
    <organization />
</author>
<author initials='A' surname='Lindem' fullname='Acee Lindem'>
    <organization />
</author>
<author initials='Y' surname='Qu' fullname='Yingzhen Qu'>
    <organization />
</author>
<date month='January' year='2018' />
</front>
<seriesInfo name='Work in Progress,' value='draft-ietf-netmod-rfc8022bis-11'/>
</reference>

<!-- draft-ietf-ospf-yang (I-D Exists) -->
<reference anchor='OSPF-YANG'>
<front>
<title>Yang Data Model for OSPF Protocol</title>
<author initials='D' surname='Yeung' fullname='Derek Yeung'>
    <organization />
</author>
<author initials='Y' surname='Qu' fullname='Yingzhen Qu'>
    <organization />
</author>
<author initials='J' surname='Zhang' fullname='Zhaohui Zhang'>
    <organization />
</author>
<author initials='I' surname='Chen' fullname='Ing-Wher Chen'>
    <organization />
</author>
<author initials='A' surname='Lindem' fullname='Acee Lindem'>
    <organization />
</author>
<date month='March' year='2018' />
</front>
<seriesInfo name='Work in Progress,' value='draft-ietf-ospf-yang-10' />
</reference>

<reference anchor="PYANG" target="https://github.com/mbj4668/pyang"> 
<front>
<title>pyang</title>
<author />
<date month="February" year="2018" />
</front>
</reference>

</references>

</back>
</rfc>
