<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" []>

<?rfc comments="yes"?>
<?rfc compact="no"?>
<?rfc inline="yes"?>
<?rfc sortrefs="yes"?>
<?rfc subcompact="no"?>
<?rfc symrefs="yes"?>
<?rfc toc="yes"?>
<?rfc tocdepth="5"?>
<?rfc tocindent="yes"?>
<?rfc tocompact="yes"?>


<rfc category="std" docName="draft-ietf-netmod-nmda-diff-00" ipr="trust200902">

<front>
<title abbrev="">Comparison of NMDA datastores</title>

<author fullname="Alexander Clemm" initials="A."
    surname="Clemm">
    <organization>Huawei</organization>
    <address>
        <postal>
            <street>2330 Central Expressway</street>
            <city>Santa Clara,</city>
            <country>USA</country>
            <code>CA 95050</code>
        </postal>
        <phone></phone>
        <email>ludwig@clemm.org</email>
    </address>
</author>

<author fullname="Yingzhen Qu" initials="Y."
    surname="Qu">
    <organization>Huawei</organization>
    <address>
        <postal>
            <street>2330 Central Expressway</street>
            <city>Santa Clara,</city>
            <country>USA</country>
            <code>CA 95050</code>
        </postal>
        <phone></phone>
        <email>yingzhen.qu@huawei.com</email>
    </address>
</author>

<author fullname="Jeff Tantsura" initials="J."
    surname="Tantsura">
    <organization>Nuage Networks</organization>
    <address>
        <email>jefftant.ietf@gmail.com</email>
    </address>
</author>

<author fullname="Andy Bierman" initials="A."
    surname="Bierman">
    <organization>YumaWorks</organization>
    <address>
        <email>andy@yumaworks.com</email>
    </address>
</author>
<date day="21" month="October" year="2018" />

<abstract>
    <t>    
		This document defines an RPC operation to compare management datastores that comply with the NMDA architecture.   
    </t>
</abstract>

</front>


<middle>
	<section anchor="intro" title="Introduction">

		<t>
		    The revised Network Management Datastore Architecture (NMDA) <xref target="RFC8342"/> introduces a set of new datastores that each hold YANG-defined data <xref target="RFC7950"/> and represent a different “viewpoint” on the data that is maintained by a server. New YANG datastores that are introduced include &lt;intended&gt;, which contains validated configuration data that a client application intends to be in effect, and &lt;operational&gt;, which contains at least conceptually operational state data (such as statistics) as well as configuration data that is actually in effect.    
			</t>
			<t>
			NMDA introduces in effect a concept of “lifecycle” for management data, allowing to clearly distinguish between data that is part of a configuration that was supplied by a user, configuration data that has actually been successfully applied and that is part of the operational state, and overall operational state that includes both applied configuration data as well as status and statistics.  
			</t>
			<t>
			As a result, data from the same management model can be reflected in multiple datastores.  Clients need to specify the target datastore to be specific about which viewpoint of the data they want to access.  This way, an application can differentiate whether they are (for example) interested in the configuration that has been applied and is actually in effect, or in the configuration that was supplied by a client and that is supposed to be in effect.  
			</t>
			<t>Due to the fact that data can propagate from one datastore to another, it is possibly for differences between datastores to occur.  Some of this is entirely expected, as there may be a time lag between when a configuration is given to the device and reflected in &lt;intended&gt;, until when it actually takes effect and is reflected in &lt;operational&gt;.  However, there may be cases when a configuration item that was to be applied may not actually take effect at all or needs an unusually long time to do so.  This can be the case due to certain conditions not being met, resource dependencies not being resolved, or even implementation errors in corner conditions.  
			</t>
			<t>When configuration that is in effect is different from configuration that was applied, many issues can result.  It becomes more difficult to operate the network properly due to limited visibility of actual status which makes it more difficult to analyze and understand what is going on in the network.  Services may be negatively affected (for example, breaking a service instance resulting in service is not properly delivered to a customer) and network resources be misallocated.  
			</t>
			<t>
			Applications can potentially analyze any differences between two datastores by retrieving the contents from both datastores and comparing them.  However, in many cases this will be at the same time costly and extremely wasteful. 
			</t>
			<t>
			This document introduces a YANG data model which defines RPCs, intended to be used in conjunction with NETCONF <xref target="RFC6241"/> or RESTCONF <xref target="RFC8040"/>, that allow a client to request a server to compare two NMDA datastores and report any differences.  
			</t>

	</section>


 <section title="Key Words">
   <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 title="Definitions and Acronyms">

<t>
<list style="empty">
    <t>NMDA: Network Management Datastore Architecture</t>
	<t>RPC: Remote Procedure Call</t>
</list>
</t>
</section>

<section title="Data Model Overview" anchor="Overview">
	<t>
	At the core of the solution is a new management operation, &lt;compare&gt;, that allows to compare two datastores for the same data.  The operation checks whether there are any differences in values or in data nodes that are contained in either datastore, and returns any differences as output.  The output is returned in  the format specified in YANG-Patch <xref target="RFC8072"/>.  
	</t>
	<t> 
	The YANG data model defines the &lt;compare&gt; operation as a new RPC.  The operation takes the following input parameters:
      <list style="symbols">
		<t>source: The source identifies the datastore that will serve as reference for the comparison, for example &lt;intended&gt;.</t>
		<t>target: The target identifies the datastore to compare against the source.</t>
		<t>filter-spec: This is a choice between different filter constructs to identify the portions of the datastore to be retrieved.  It acts as a node selector that specifies which data nodes are within the scope of the comparison and which nodes are outside the scope.  This allows a comparison operation to be applied only to a specific portion of the datastore that is of interest, such as a particular subtree.  (The filter dow not contain expressions that would match values data nodes, as this is not required by most use cases and would complicate the scheme, from implementation to dealing with race conditions.)</t>
		<t>all:  When set, this parameter indicates that all differences should be included, including differences pertaining to schema nodes that exist in only one of the datastores.  When this parameter is not included, a prefiltering step is automatically applied to exclude data from the comparison that does not pertain to both datastores: if the same schema node is not present in both datastores, then all instances of that schema node and all its descendants are excluded from the comparison. This allows client applications to focus on the differences that constitute true mismatches of instance data without needing to specify more complex filter constructs.</t>
	  </list>	
	</t>
	<t>
	The operation provides the following output parameter:
	<list style="symbols">
	  <t>differences: This parameter contains the list of differences, encoded per RFC8072, i.e. specifying which patches would need to be applied to the source to produce the target.  When the target datastore is &lt;operational&gt;, "origin" metadata is included as part of the patch. Including origin metadata can help explain the cause of a difference, for example when a data node is part of &lt;intended&gt; but the origin of the same data node in &lt;operational&gt; is reported as "system".</t>
	</list>
	</t>

    <t>The data model is defined in the ietf-nmda-compare YANG
        module. Its structure is shown in the following figure. The notation syntax 
        follows <xref target="RFC8340"/>.</t>
        <t>
        <figure align="center"
                title="Structure of ietf-nmda-compare">
          <artwork align="left">
module: ietf-nmda-compare

  rpcs:
    +---x compare
       +---w input
       |  +---w source            identityref
       |  +---w target            identityref
       |  +---w all?              empty
       |  +---w (filter-spec)?
       |     +--:(subtree-filter)
       |     |  +---w subtree-filter?   &lt;anydata&gt;
       |     +--:(xpath-filter)
       |        +---w xpath-filter?     yang:xpath1.0 {nc:xpath}?
       +--ro output
          +--ro (compare-response)?
             +--:(no-matches)
             |  +--ro no-matches?    empty
             +--:(differences)
                +--ro differences
                   +--ro yang-patch
                      +--ro patch-id    string
                      +--ro comment?    string
                      +--ro edit* [edit-id]
                         +--ro edit-id      string
                         +--ro operation    enumeration
                         +--ro target       target-resource-offset
                         +--ro point?       target-resource-offset
                         +--ro where?       enumeration
                         +--ro value?       &lt;anydata&gt;

          
          </artwork>
        </figure></t>
</section>

<section title="YANG Data Model">
<t>
<figure>
            <artwork><![CDATA[
<CODE BEGINS> file "ietf-nmda-compare@2018-10-21.yang"
module ietf-nmda-compare {

  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-nmda-compare";

  prefix cp;

  import ietf-yang-types {
    prefix yang;
  }
  import ietf-datastores {
    prefix ds;
  }
  import ietf-yang-patch {
    prefix ypatch;
  }
  import ietf-netconf {
    prefix nc;
  }

  organization "IETF";
  contact
    "WG Web:   <http://tools.ietf.org/wg/netconf/>
     WG List:  <mailto:netconf@ietf.org>

     Author: Alexander Clemm
             <mailto:ludwig@clemm.org>

     Author: Yingzhen Qu
             <mailto:yingzhen.qu@huawei.com>

     Author: Jeff Tantsura
             <mailto:jefftant.ietf@gmail.com>

     Author: Andy Bierman
             <mailto:andy@yumaworks.com>";

  description
    "The YANG data model defines a new operation, <compare>, that
     can be used to compare NMDA datastores.";

  revision 2018-10-21 {
    description
      "Initial revision";
    reference
      "RFC XXXX: Comparison of NMDA datastores";
  }

  /* RPC */
  rpc compare {
    description
      "NMDA compare operation.";
    input {
      leaf source {
        type identityref {
          base ds:datastore;
        }
        mandatory true;
        description
          "The source datastore to be compared.";
      }
      leaf target {
        type identityref {
          base ds:datastore;
        }
        mandatory true;
        description
          "The target datastore to be compared.";
      }
      leaf all {
            type empty;
        description
          "When this leaf is provided, all data nodes are compared, 
		   whether their schema node pertains to both datastores or    
           not. When this leaf is omitted, a prefiltering step is
           automatically applied that excludes data nodes from the
           comparison that can occur in only one datastore but not
           the other.  Specifically, if one of the datastores
           (source or target) contains only configuration data and
           the other datastore is <operational>, data nodes for
           which config is false are excluded from the comparison.";
      }
      choice filter-spec {
        description
          "Identifies the portions of the datastores to be
               compared.";
        anydata subtree-filter {
          description
            "This parameter identifies the portions of the
             target datastore to retrieve.";
          reference "RFC 6241, Section 6.";
        }
        leaf xpath-filter {
          if-feature nc:xpath;
          type yang:xpath1.0;
          description
            "This parameter contains an XPath expression
             identifying the portions of the target
             datastore to retrieve.";
        }
      }
    }
    output {
      choice compare-response {
        leaf no-matches {
          type empty;
          description
            "This leaf indicates that the filter did not match anything
             and nothing was compared.";
        }
        container differences {
          uses ypatch:yang-patch;
          description
            "The list of differences, encoded per RFC8072.";
        }
        description
          "Comparision results.";
      }
    }
  }
}
<CODE ENDS>
]]></artwork></figure>
</t>

</section>

<section title="Example">
<t>
The following example compares the difference between &lt;operational&gt; and &lt;intended&gt; for object "explicit-router-id", 
as defined in data module <xref target="I-D.ietf-ospf-yang"/>.
</t>
<t>
RPC request:
</t>
<t><figure>
          <artwork align="left"><![CDATA[ 
    <rpc message-id="101"
        xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <compare xmlns="urn:ietf:params:xml:ns:yang:ietf-nmda-compare"
          xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">
        <source>ds:operational</source>
        <target>ds:intended</target>
        <xpath-filter
          xmlns:rt="urn:ietf:params:xml:ns:yang:ietf-routing"
          xmlns:ospf="urn:ietf:params:xml:ns:yang:ietf-ospf">\
            /rt:routing/rt:control-plane-protocols\
            /rt:control-plane-protocol/ospf:ospf\
        </xpath-filter>
      </compare>
    </rpc>

          ]]></artwork>
</figure></t>
<t>
RPC reply, when a difference is detected:
</t>
<t><figure>
          <artwork align="left"><![CDATA[ 
  <rpc-reply
       xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
       message-id="101">
    <differences
       xmlns="urn:ietf:params:xml:ns:yang:ietf-nmda-compare"
       xmlns:or="urn:ietf:params:xml:ns:yang:ietf-origin">
      <yang-patch>
        <patch-id>ospf router-id</patch-id>
        <comment>diff between operational and intended</comment>
        <edit>
          <edit-id>1</edit-id>
          <operation>replace</operation>
          <target>/ietf-ospf:explicit-router-id</target>
          <value>
            <ospf:explicit-router-id
              or:origin="or:system">1.1.1.1<explicit-router-id>
          </value>
        </edit>
      </yang-patch>
    </differences>
  </rpc-reply>
          ]]></artwork>
 </figure></t>
<t>
RPC reply when no difference is detected:
</t>
<t><figure>
          <artwork align="left"><![CDATA[ 
    <rpc-reply
      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
      message-id="101">
      <differences
        xmlns="urn:ietf:params:xml:ns:yang:ietf-nmda-compare"/>
    </rpc-reply>            
          ]]></artwork>
</figure></t>
<t>The same request in RESTCONF (using JSON format): </t>
<t><figure>
    <artwork align="left"><![CDATA[ 
   POST /restconf/operations/ietf-nmda-compare:compare HTTP/1.1
   Host: example.com
   Content-Type: application/yang-data+json
   Accept: application/yang-data+json

   { "ietf-nmda-compare:input" {
      "source" : "ietf-datastores:operational",
      "target" : "ietf-datastores:intended".
      "xpath-filter" : \
          "/ietf-routing:routing/control-plane-protocols\
          /control-plane-protocol/ietf-ospf:ospf"
      }
    }
    ]]></artwork>
</figure></t>
<t>The same response in RESTCONF (using JSON format): </t>
<t><figure>
    <artwork align="left"><![CDATA[ 
   HTTP/1.1 200 OK
   Date: Thu, 26 Jan 2017 20:56:30 GMT
   Server: example-server
   Content-Type: application/yang-data+json

   { "ietf-nmda-compare:output" : {
       "differences" : {
         "ietf-yang-patch:yang-patch" : {
           "patch-id" : "ospf router-id",
           "comment" : "diff between operational and intended",
           "edit" : [
             {
               "edit-id" : "1",
               "operation" : "replace",
               "target" : "/ietf-ospf:explicit-router-id",
               "value" : {
                  "ietf-ospf:explicit-router-id" : "1.1.1.1"
                  "@ietf-ospf:explicit-router-id" : {
                  "ietf-origin:origin" : "ietf-origin:system"
                  }
               }
             }
           ]
         }
       }
     }
   }
    ]]></artwork>
</figure></t>
</section>

<section title="Open Issues">
  <t>Currently, origin metadata is included in RPC output per default in comparisons that involve &lt;operational&gt;.  It is conceivable to introduce an input parameter that controls whether origin metadata should in fact be included.</t>   
  <t>Currently the comparison filter is defined using subtree and XPath as in NETCONF<xref target="RFC6241"/>.  It is not clear whether there is a requirement to allow for the definition of filters that relate instead to target resources per RESTCONF <xref target="RFC7950"/>. </t>

</section>

<section title="Possible Future Extensions">

    <t>It is conceivable to extend the compare operation with a number of possible additional features in the future.  </t>
    <t>
    Specifically, it is possible to define an extension with an optional feature for dampening.   This will allow clients to specify a minimum time period for which a difference must persist for it to be reported.  This will enable clients to distinguish between differences that are only fleeting from ones that are not and that may represent a real operational issue and inconsistency within the device.  
    </t>
    <t>For this purpose, an additional input parameter can be added to specify the dampening period.  Only differences that pertain 
		   for at least the dampening time are reported.   
           A value of 0 or omission of the parameter indicates no 
           dampening. 
           Reporting of differences MAY correspondingly be delayed by the dampening period from the time the request is received.
    </t>
    <t> 
    To implement this feature, a server implementation might run a comparison when the RPC is first invoked and temporarily store the result.  Subsequently, it could wait until after the end of the dampening period to check whether the same differences are still observed.  The differences that still persist are then returned. 
    </t>
    
</section>

<section title="IANA Considerations">
<section title="Updates to the IETF XML Registry">
<t>This document registers one URI in the IETF XML registry <xref target="RFC3688"/>.  Following the format in <xref target="RFC3688"/>, the following registration is requested:
<list>
      <t>URI: urn:ietf:params:xml:ns:yang:ietf-nmda-compare</t>
      <t>Registrant Contact: The IESG.</t>
      <t>XML: N/A, the requested URI is an XML namespace.</t>
</list>
</t>
</section>
<section title="Updates to the YANG Module Names Registry">
<t>
   This document registers a YANG module in the YANG Module Names
   registry <xref target="RFC7950"/>.  Following the format in <xref target="RFC7950"/>, the
   following registration is requested:
<list>
      <t>name:         ietf-nmda-compare</t>
      <t>namespace:    urn:ietf:params:xml:ns:yang:ietf-nmda-compare</t>
      <t>prefix:       cp</t>
      <t>reference:    RFC XXXX</t>
</list>
</t>
</section>

</section>
	

<section title="Security Considerations">
 
<t>
  Comparing discrepancies between datastores requires a certain amount of processing resources at the server.  An attacker could attempt to attack a server by making a high volume of comparison requests. Server implementations can guard against such scenarios in several ways.  For one, they can implement NACM in order to require proper authorization for requests to be made.  Second, server implementations can limit the number of requests that they serve in any one time interval, potentially rejecting requests made at a higher frequency than the implementation can reasonably sustain.  
</t>
</section>

<section title="Acknowledgments">
<t>We thank Rob Wilton, Martin Bjorklund, Mahesh Jethanandani, Lou Berger, Kent Watsen, Phil Shafer, Ladislav Lhotka for valuable feedback and suggestions on an earlier revision of this document. 
</t>
</section>

</middle>

<back>

	<references title="Normative References">
		<?rfc include="reference.RFC.2119"?>
		<?rfc include="reference.RFC.3688"?>
		<?rfc include="reference.RFC.6241"?>
		<?rfc include="reference.RFC.7950"?>
		<?rfc include="reference.RFC.8040"?>
	    <?rfc include="reference.RFC.8072"?>
		<?rfc include="reference.RFC.8174"?>
        <?rfc include="reference.RFC.8340"?>
		<?rfc include="reference.RFC.8342"?>		
       
</references>

<references title="Informative References">
  <?rfc include="reference.I-D.ietf-ospf-yang"?>
</references>
</back>
	
</rfc>
