<?xml version="1.0"?>
<?rfc toc="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc strict="yes" ?>
<!DOCTYPE rfc SYSTEM "../../rfcAuthoring/new2009/xml2rfc-1.34pre2/rfc2629.dtd">
<rfc ipr="trust200811" category="std">
    <front>
        <title>Partial Lock RPC for NETCONF</title>
        <author  surname="Lengyel" fullname="Balazs Lengyel" initials="B">
            <organization>Ericsson</organization>
            <address><email>balazs.lengyel@ericsson.com</email></address>
        </author>      
        <author  surname="Bjorklund" fullname="Martin Bjorklund" initials="M">
            <organization>Tail-f Systems</organization>
            <address><email>mbj@tail-f.com</email></address>
        </author>      
        <date year="2009" month="February" day="19"/>
        <area>OPS</area>
        <workgroup>NETCONF</workgroup>
        <abstract>
            <t>The NETCONF protocol defines the lock and unlock RPCs, used to
                lock entire configuration datastores. In some situations, a way
                to lock only parts of a configuration 
                datastore is required. This document defines a capability-based extension to 
                the NETCONF protocol for locking portions of a configuration datastore. </t>
        </abstract>        
    </front>
    <middle>
        <section title="Introduction" toc="include"><t>
            The <xref target="NETCONF"/> protocol describes the lock and unlock operations
            that operate on entire configuration datastores. Often,
            multiple management sessions need to be able to modify the 
            configuration of a managed device in parallel. In these cases, locking
            only parts of a configuration 
            datastore is needed. This document defines a capability based extension to the NETCONF protocol to
            support partial locking of NETCONF datastores using a mechanism
            based on the existing XPath filtering mechanisms.</t>
            <section title="Definition of Terms">
                <t>
                    The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;,
                    &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;NOT RECOMMENDED&quot;, &quot;MAY&quot;, and
                    &quot;OPTIONAL&quot; in this document are to be interpreted as described in BCP 14, <xref target="RFC2119"/>.
                </t>
                <t>
                    Additionally the following terms are defined:
                    <list style="symbols">
                        <t>Instance Identifier: an XPath expression identifying a 
                            specific node in the conceptual XML datastore. 
                            It contains an absolute path expression in abbreviated syntax,
                            where predicates are used only to specify values for nodes defined as keys to
                            distinguish multiple instances.</t>
                        <t>Scope of the lock: initially the set of nodes returned by the XPath expressions in a successful
                            partial-lock operation. The set might be modified if some of the nodes are deleted. 
                        </t>      
                        <t>Protected area: the set of nodes that are protected from modification by the lock. 
                            This consist of nodes in the scope of the lock and nodes in subtrees under them.</t>
                    </list>      
                </t>     
                
            </section>
         </section>
        <section title="Partial Locking Capability">
            <section title="Overview">
                <t>
                    The :partial-lock capability indicates that the device supports
                    the locking of its configuration with a more limited scope than a complete 
                    configuration datastore. The scope to be locked is specified by using restricted or full XPath expressions.
                    Partial locking only affects configuration data.
                    <vspace blankLines="1"/>
                    The system MUST ensure that configuration resources
                    covered by the lock are not modified by other
                    NETCONF or non-NETCONF management operations such as
                    SNMP and the CLI.
                    <vspace blankLines="1"/>
                    The duration of the partial lock begins when the partial lock is
                    granted and lasts until (1) either the corresponding &lt;partial-unlock> operation 
                    succeeds or (2) the NETCONF session terminates.
                    <vspace blankLines="1"/>
                    A NETCONF session MAY have multiple parts of one or more datastores (running, candidate, startup) locked 
                    using partial lock operations. 
                    <vspace blankLines="1"/>
                    The &lt;partial-lock> operation returns a 
                    lock-id to identify each successfully acquired lock.
                </t> 
                <section title="Usage Scenarios">
                    <t>
                        In the following we describe a few scenarios for partial locking. While scenarios 
                        using the running datastore are seen as the most important, as an 
                        example a scenario involving the candidate datastore is also presented. 
                        Besides the three described here, there 
                        are many other usage scenarios possible.
                    </t>
                    <section title="Multiple managers handling the writable running datastore">
                        <t>
                            Multiple managers are handling the same NETCONF agent simultaneously. 
                            The agent is handled via the writable running datastore.
                            Each manager has his or her own task, which might involve 
                            the modification of overlapping sections of the datastore. 
                            <vspace blankLines="1"/>
                            After collecting and analyzing input and preparing the 
                            NETCONF operations off-line, 
                            the manager locks the areas that are important for his task
                            using one single &lt;partial-lock> operation.
                            The manager executes a number of &lt;edit-config> operations to modify 
                            the configuration, then releases the partial-lock. 
                            The lock should be held for only a short time 
                            (seconds rather then minutes). 
                            The manager should collect all human input before locking anything.
                            As each manager locks only a part of the data model, usually multiple operators can 
                            execute the &lt;edit-config> operations simultaneously.
                         </t>       
                    </section>
                    <section title="Multiple managers handling the writable running datastore, distinct management areas">
                        <t>
                            Multiple managers are handling the same NETCONF agent simultaneously. 
                            The agent is handled via the writable running datastore.
                            The agent's data model contains a number of well defined separate
                            areas that can be configured without impacting other areas. An
                            example can be a server with multiple applications running on it, or
                            a number of a network elements with a common NETCONF agent for
                            management.                            
                            <vspace blankLines="1"/>
                            Each manager has his or her own task, which does not involve the modification 
                            of overlapping sections of the datastore. 
                            <vspace blankLines="1"/>
                            The manager locks his area with a &lt;partial-lock> operation, 
                            uses a number of &lt;edit-config> commands to modify it, 
                            later releases the lock.
                            As each manager has his functional area assigned to him, 
                            and he locks only that area, multiple managers can edit 
                            the configuration simultaneously.
                            Locks can be held for extended periods (minutes, hours), 
                            as this will not hinder other managers.
                            <vspace blankLines="1"/>
                            This scenario assumes, that the global lock operation 
                            from <xref target="NETCONF"/> is not used. 
                        </t>
                    </section>
                    <section title="Multiple managers handling the candidate datastore in a semi-coordinated work mode">
                        <t>
                            Multiple managers are handling the same NETCONF agent simultaneously. 
                            The agent is handled via the candidate datastore.
                            Each manager has his or her own task which might involve the modification 
                            of overlapping sections of the datastore.
                            <vspace blankLines="1"/>
                            After collecting and analyzing input and preparing the 
                            NETCONF operations off-line, 
                            the manager locks the areas that are important for his task
                            using one single &lt;partial-lock> operation in both the candidate and the running datastore.
                            He executes a number of &lt;edit-config> operations to modify 
                            the configuration, then releases the partial-lock. 
                            The lock should be held for only a short time 
                            (seconds rather then minutes).
                            <vspace blankLines="1"/>
                            Operators coordinate with each other. When all of them finish their tasks 
                            one of them orders commit. If any of the operators are still working, 
                            and holds a lock, the commit will fail, and will need to be repeated after all managers finish.
                        </t>
                    </section>
                </section>
            </section>
            <section title="Dependencies">
                <t>The device MUST support restricted XPath expressions in the select element, 
                    as described in <xref target="partial-lock-operation"/>.
                    Optionally, if the :xpath capability is also supported 
                    (as defined in <xref target="NETCONF"/> chapter 8.9. XPath Capability), 
                    the device MUST also support using any 
                    XPath 1.0 expression in the select element.
                </t>
            </section>
            <section title="Capability Identifier"><t>urn:ietf:params:netconf:capability:partial-lock:1.0</t></section>
            <section title="New Operations">
                <section title="&lt;partial-lock>" anchor="partial-lock-operation"><t>
                    The &lt;partial-lock> operation allows the client to lock a portion of
                    one or more datastores. The portion to lock is specified with XPath 
                    expressions in the "select" elements and the list of datastores in 
                    the "target" elements in the &lt;partial-lock> operation. Each XPath expression 
                    MUST return a node set. 
                    <vspace blankLines="1"/>
                    When a NETCONF session holds a lock on a node, no other session or
                    non-NETCONF mechanism of the system can change that node or any node
                    in the hierarchy of nodes beneath it.
                    <vspace blankLines="1"/>
                    Locking a node protects the node itself and 
                    the complete subtree under the node from modification by others. 
                    The set of locked nodes is called the scope of the lock, while all the 
                    locked nodes and the nodes in the subtrees under them make up the protected area.
                    <vspace blankLines="1"/>
                    In some situations it is desirable that the same set of nodes are
                    locked in more than one datastore.
                    For example, if an interface is configured in the candidate datastore, 
                    it is dangerous for it to be configured by someone else in a possibly conflicting 
                    manner in the running datastore.
                    For this reason &lt;partial-lock> allows the locking of the same sections of 
                    the management data in multiple datastores.                  
                    <vspace blankLines="1"/>
                    The XPath expressions are evaluated only once at lock time. 
                    Thereafter, the scope of the lock is maintained as a set of nodes, 
                    i.e. the returned nodeset, and not by the XPath expression. 
                    If the configuration data is later altered in a way that 
                    would make the original XPath  
                    expressions evaluate to a different set of nodes, this does not affect the scope of the partial lock.  
                    <vspace blankLines="1"/>
                    Let's say the agent's data model includes a list of users. 
                    If the XPath expression in the partial lock operation covers all users at locking, 
                    the scope of the lock will be maintained as the list of "user" nodes at the time 
                    when the lock was granted. If someone later creates a new user, this new
                    user will not be included in the locked-nodes list created previously, the new user will not be locked.
                    <vspace blankLines="1"/>
                    A &lt;partial-lock> operation MUST be handled atomically by the NETCONF 
                    server. The server either locks all requested parts of the datastore(s) or none.  
                    If during the &lt;partial-lock> operation one of the requested parts cannot be locked, the 
                    server MUST unlock all parts that have already been locked during that operation. 
                    <vspace blankLines="1"/>
                    If a node in the scope of the lock is deleted, it is removed from the 
                    scope of the lock, so any other session or non-NETCONF mechanism can recreate it. 
                    If all nodes in the scope of the lock are deleted, the 
                    lock will still be present. However, its scope will become empty (since the lock will not cover any nodes).
                    <vspace blankLines="1"/>
                    A NETCONF server MUST be able to grant multiple simultaneous partial locks to a 
                    single NETCONF session. If the protected area of the individual locks overlaps, nodes in the 
                    common area MUST be protected until all of the locks are released.                    
                    <vspace blankLines="1"/>
                    A partial lock operation MUST fail if:
                   <list style="symbols">
                       <t>Any NETCONF session (including the current session) owns the
                       global lock on any target datastore.</t>
                       <t>Any part of the area to be protected is already locked (or protected by partial locking) by another management
                           session, including other NETCONF sessions using 
                           &lt;partial-lock> or any other non-NETCONF management method.</t>
                       <t>The NETCONF server implements access control, and the locking user does not have sufficient 
                            access rights. The exact handling of access rights is outside the 
                            scope of this document, but it is assumed that there is an access 
                            control system that MAY deny or allow the partial lock operation.</t>
                   </list>
                    The &lt;partial-lock> operation is designed for simplicity, so when a partial lock is executed you get what 
                    you asked for: a set of nodes that are locked for writing. As a consequence users must observe the following: 
                    <list style="symbols">
                        <t>Locking does not affect read operations.</t>
                        <t>If part of a datastore is locked, this has no effect on any unlocked parts of the datastore. 
                            If this is a problem (e.g., changes depend on data values or nodes outside the protected  
                            part of the datastore), these nodes should be included in the protected area of the lock.</t>
                        <t>Configuration data can be edited both inside and outside the protected area of a 
                            lock. It is the responsibility of the NETCONF client application to lock all relevant parts of a datastore that 
                            are crucial for a specific management action.</t>
                    </list>
                    <vspace blankLines="1"/>
                    Note: The &lt;partial-lock> operation does not modify the global &lt;lock> operation defined in the base 
                    NETCONF Protocol  <xref target="NETCONF"></xref>. If part of a 
                    datastore is already locked by &lt;partial-lock>, then a global lock for that datastore MUST fail even 
                    if the global lock is requested by the NETCONF session that owns the partial lock. 
                </t>
                 <section title="Parameters, Result, Examples">  
                     <t>
                        Parameters:
                        <list style="hanging" hangIndent="4">
                            <t hangText="target:">Name of one or more configuration datastores 
                                of which a part shall be locked. 
                                If multiple datastores are specified the same select parameter(s) 
                                are evaluated for each of them.
                            </t>
                            <t hangText="select:">One or more 'select' elements, each  
                                containing an XPath expression.  The XPath expression is
                                evaluated in a context where the context node is the root of the
                                server's conceptual data model,
                                and the set of namespace declarations are those in scope on the
                                select element.
                                <vspace blankLines="1"/>                            
                                Each select expression is evaluated for each targeted datastore.
                                <vspace blankLines="1"/>
                                The nodes returned from the select expressions are reported in
                                the rpc-reply message.
                                <vspace blankLines="1"/>
                                Note that if some of the requested nodes exist
                                only in some of the targeted datastores, the lock is granted on different
                                nodes in different datastores.
                                <vspace blankLines="1"/>                            
                                Each select expression MUST return a node set, and at least one of the 
                                node sets for one of the specified datastores MUST be non-empty. 
                                <vspace blankLines="1"/>
                                If the device supports the :xpath capability, any valid XPath 1.0 expression can 
                                be used. If the device does not support the :xpath capability, the XPath 
                                expression MUST be limited to an Instance Identifier expression.
                                An Instance Identifier is an absolute path expression in abbreviated syntax,
                                where predicates are used only to specify values for nodes defined as keys to
                                distinguish multiple instances.
                            </t>
                        </list>
                        <figure><preamble>Example: Lock virtual router 1 and interface eth1</preamble>
                            <artwork>
                                <![CDATA[
    <nc:rpc
      xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
      xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
      message-id="135">
        <partial-lock>
            <target>
                <running/>
            </target>
            <select xmlns:rte="http://example.com/ns/route">
                /rte:routing/rte:virtualRouter[rte:routerName='router1']
            </select>
            <select xmlns:if="http://example.com/ns/interface">
                /if:interfaces/if:interface[if:id='eth1']
            </select>
         </partial-lock>
    </nc:rpc>             
    
    <nc:rpc-reply
      xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
      xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
      message-id="135">
        <lock-id>127</lock-id>
        <running>
          <locked-node xmlns:rte="http://example.com/ns/route">
              /rte:routing/rte:virtualRouter[rte:routerName='router1']
          </locked-node>
          <locked-node xmlns:if="http://example.com/ns/interface">
              /if:interfaces/if:interface[if:id='eth1']
          </locked-node>            
        </running>
    </nc:rpc-reply>          ]]>
                            </artwork>
                        </figure>
                        <vspace blankLines="1"/>
                        Positive Response:
                        <vspace blankLines="1"/>
                        If the device was able to satisfy the request, an &lt;rpc-reply> is
                        sent with a &lt;lock-id> element (lock identifier) in the &lt;rpc-reply> element.
                        A list of locked nodes per datastore is also returned in Instance Identifier format.
                        <vspace blankLines="1"/>
                        Negative Response:
                        <vspace blankLines="1"/>
                        If a lock is already held by another session on any node within the subtrees to be
                        locked, the &lt;error-tag> element is 'lock-denied' and the
                        &lt;error-info> element includes the &lt;session-id> of the lock
                        owner.  If the lock is held by a non-NETCONF session, a
                        &lt;session-id> of 0 (zero) is included. If needed the returned session-id may 
                        be used to &lt;kill-session> the NETCONF session holding the lock.
                        The same error response is returned if 
                        the requesting session already holds the (global) lock for the same datastore.
                        <vspace blankLines="1"/>
                         If any select expression is an invalid XPath expression, the
                         &lt;error-tag> is 'invalid-value'.
                         <vspace blankLines="1"/>                             
                         If any select expression returns something other than a node set, the
                         &lt;error-tag> is 'invalid-value', and the &lt;error-app-tag> is 'not-a-node-set'.
                        <vspace blankLines="1"/>
                        If all the select expressions return an empty node set, the &lt;error-tag> is 
                        'operation-failed', and the &lt;error-app-tag> is 'no-matches'.
                        <vspace blankLines="1"/>
                        If any of the target datastors does not exist, the &lt;error-tag>
                        is 'invalid-value', the &lt;error-app-tag> is 'invalid-lock-specification'
                        <vspace blankLines="1"/>
                        If the :xpath capability is not supported and the XPath 
                        expression is not an Instance Identifier,
                        the &lt;error-tag> is 'invalid-value', the &lt;error-app-tag> is 'invalid-lock-specification'.
                        <vspace blankLines="1"/>
                        If access control denies the partial lock, the &lt;error-tag>
                        is 'access-denied'.
                        <vspace blankLines="1"/>
                        </t>
                 </section>
                 <section title="Deadlock Avoidance">
                     <t>
                         As with most locking systems, it is possible that two management sessions trying to lock different 
                         parts of the configuration could become dead-locked. To avoid this situation, clients should lock 
                         everything they need in one operation. If locking fails, the client should back-off, 
                         release any previously acquired locks, and retry the procedure after waiting some randomized time interval. 
                         <vspace blankLines="1"/>                         
                     </t>
                 </section>   
                </section>                
                <section title="&lt;partial-unlock>">
                  <t>The operation unlocks the parts of the datastores that were previously 
                      locked using &lt;partial-lock> during the same session. 
                      <vspace blankLines="1"/>
                        Parameters:
                        <list style="hanging" hangIndent="4">
                            <t hangText="lock-id:">Identity of the lock to be unlocked.
                              This lock-id MUST have been received as a response to a lock request
                              by the manager during the current session, and MUST NOT have
                              been sent in a previous unlock request.
                            </t>
                        </list>
                        <figure><preamble>Example: Unlock a previously created lock</preamble>
                        <artwork>
                            <![CDATA[
   <nc:rpc xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
     xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
     message-id="136">
       <partial-unlock>
         <lock-id>127</lock-id>
       </partial-unlock>
   </nc:rpc>    
                    ]]>
                      </artwork>
                      </figure>
                      Positive Response:
                      <vspace blankLines="1"/>
                      If the device was able to satisfy the request, an &lt;rpc-reply> is
                      sent that contains an &lt;ok> element. A positive response MUST 
                      be sent even if all of the locked parts of the datastore(s) have already been deleted.
                      <vspace blankLines="1"/>
                      Negative Response:
                      <vspace blankLines="1"/>
                      If the &lt;lock-id> parameter does not identify a lock which is owned
                      by the session, an 'invalid-value' error is returned.
                  </t>
                </section>
            </section>
            <section title="Modifications to Existing Operations">
                <t>A successful partial lock will cause a subsequent operation to fail if that attempts to modify 
                    nodes in the protected area of the lock  
                    and is executed in a NETCONF session other than the session that has been granted the lock. 
                    The &lt;error-tag>  'in-use' and the &lt;error-app-tag> 'locked' is returned. 
                    All operations that modify the datastore are affected, including: &lt;edit-config>, &lt;copy-config>, 
                    &lt;delete-config>, &lt;commit> and &lt;discard-changes>.
                    If partial lock prevents &lt;edit-config> modifying some data, but the 
                    operation includes the continue-on-error option, modification of other 
                    parts of the datastore, which are not protected by partial locking, might 
                    still succeed.                    
                    <vspace blankLines="1"/>
                    If a datastore contains nodes locked by partial lock, this will cause the (global) &lt;lock> operation to fail. The 
                    &lt;error-tag> element 'lock-denied' and an 
                    &lt;error-info> element including the &lt;session-id> of the lock
                    owner will be returned. If the lock is held by a non-NETCONF session, a
                    &lt;session-id> of 0 (zero) is returned.
                    <vspace blankLines="1"/>                    
                    All of these operations are affected only if they are targeting the same datastore.
                </t>
            </section>
            <section title="Interactions with Other Capabilities">
                <section title="Candidate Configuration Capability">
                    <t>
                        Partial locking of the candidate datastore can only 
                        be done if the :candidate capability is supported by the device. 
                        Partial locking of the candidate datastore does not depend on whether the 
                        datastore was modified or not.
                    </t>
                </section>
                <section title="Confirmed Commit Capability">
                    <t>
                        If:
                   	    <list style="symbols">
                       	  <t>a partial lock is requested for the running datastore, and</t>
                       	  <t>the NETCONF server implements the :confirmed-commit capability, and</t>
                       	  <t>there was a recent confirmed &lt;commit> operation where the confirming  &lt;commit> operation has not been received</t>
                   	    </list>
			            then the lock MUST be denied, because if the confirmation does not arrive, 
			            the running datastore MUST be rolled back to its state before the commit.
                        The NETCONF server might therefore need to modify the configuration.
                        <vspace/>
                        In this case the &lt;error-tag>  'in-use' and the 
                        &lt;error-app-tag> 'outstanding-confirmed-commit' 
                        is returned.
                    </t>
                </section>
                <section title="Distinct Startup Capability"><t>Partial locking of the startup datastore can only 
                    be done if the :startup capability is supported by the device.</t>
                </section>
            </section>
        </section>
        <section title="Security Considerations"><t>
            The same considerations are relevant as for the base NETCONF Protocol  <xref target="NETCONF"></xref>. 
            It is assumed that the &lt;partial-lock> and &lt;partial-unlock> RPCs are only allowed for an authenticated user after passing some access control mechanism.
            <vspace blankLines="1"/>
            A lock (either a partial lock or a global lock) might prevent other users from configuring the system. The following mechanisms are in place to prevent the misuse of this possibility:
            <list>
                <t>Only an authenticated and authorized user can request a partial lock.</t>
                <t>The partial lock is automatically released when a session is terminated regardless of how the session ends.</t>
                <t>The &lt;kill-session> operation makes it possible to terminate other users's sessions.</t>
                <t>The NETCONF server may log partial lock requests in an audit trail.</t>
                <t></t>
            </list>
            A lock that is hung for some reason (e.g., a broken TCP connection that the server has not yet recognised) can be released 
            using another NETCONF session by explicitly killing the session owning that lock using the &lt;kill-session> operation.
            <vspace blankLines="1"/>
            Partial locking is NOT an authorization mechanism; it SHOULD NOT be used to provide security or access control. 
            Partial locking SHOULD only be used as a mechanism for providing consistency 
            when multiple managers are trying to configure the node.
            It is vital that users easily understand the exact scope of a lock. 
            This is why the scope is determined when granting a lock and is not modified thereafter.
        </t></section>
        <section title="IANA Considerations">
            <t>This document registers two URIs for the NETCONF XML namespace in
                the IETF XML registry <xref target="RFC3688"></xref>. Note that the capability URN is compliant to
                <xref target="NETCONF"></xref> section 10.3.</t>
            <texttable>
                <ttcol  align="left" width="20%">Index</ttcol>
                <ttcol align="left">Capability Identifier</ttcol>
                <c>:partial-lock</c>
                <c>urn:ietf:params:netconf:capability:partial-lock:1.0</c>
            </texttable>
            <?rfc compact="no"?>
            <t>URI: urn:ietf:params:xml:ns:netconf:partial-lock:1.0
            <vspace blankLines="1"/>
            Registrant Contact: The IESG.
            <vspace blankLines="1"/>    
             XML: N/A, the requested URI is an XML namespace.
            </t>
            </section>
        <section title="Appendix A  -  XML Schema for Partial Locking (normative)">
            <t>                        
                The following XML Schema defines the &lt;partial-lock> and &lt;partial-unlock> operations:
                <figure>
                    <artwork><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
  xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
  targetNamespace="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
  elementFormDefault="qualified" attributeFormDefault="unqualified">
  
  <xs:annotation>
    <xs:documentation> 
      Schema defining the partial-lock and unlock operations. 
      organization "IETF NETCONF Working Group"
 
      contact
        Netconf Working Group 
        Mailing list: netconf@ietf.org
        Web: http://www.ietf.org/html.charters/netconf-charter.html
    
        Balazs Lengyel
        balazs.lengyel@ericsson.com"
         
      revision 2009-02-19 
        description Initial version, published as RFC yyyy.
-- RFC Ed.: replace yyyy with actual RFC number and remove this note.
    </xs:documentation>
  </xs:annotation>
  
  <xs:import namespace="urn:ietf:params:xml:ns:netconf:base:1.0"
    schemaLocation="urn:ietf:params:xml:ns:netconf:base:1.0"/>
  
  <xs:simpleType name="lock-id-type">
    <xs:annotation>
      <xs:documentation>
        A number identifying a specific 
        partial-lock granted to a session.
        It is allocated by the system, and SHOULD 
        be used in the unlock operation.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:unsignedInt"/>
  </xs:simpleType>
  
  <xs:complexType name="configNameType"/>
  <xs:element name="config-name"
      type="configNameType" abstract="true"/>
  <xs:element name="startup" type="configNameType"
      substitutionGroup="config-name"/>
  <xs:element name="candidate" type="configNameType"
      substitutionGroup="config-name"/>
  <xs:element name="running" type="configNameType"
      substitutionGroup="config-name"/>
    
  <xs:complexType name="partialLockType">
    <xs:annotation>
      <xs:documentation>
        A NETCONF operation that locks part of one or more datastores.
      </xs:documentation>
    </xs:annotation>     
    <xs:complexContent>
      <xs:extension base="nc:rpcOperationType">
        <xs:sequence>
          <xs:element name="target" maxOccurs="unbounded">
            <xs:annotation>
              <xs:documentation>
                A list of one or more datastore names for NETCONF. 
                Each target element MUST contain a different 
                datastore name.
              </xs:documentation>
            </xs:annotation>                       
            <xs:complexType>
              <xs:sequence>
                  <xs:element ref="config-name"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="select" type="xs:string" 
            maxOccurs="unbounded">
            <xs:annotation>
              <xs:documentation>
                XPath expression that specifies the scope of the lock.
                An Instance Identifier expression must be used unless 
                the :xpath capability is supported in which case any 
                XPath 1.0 expression is allowed.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="partialUnLockType">
    <xs:annotation>
      <xs:documentation>
        A NETCONF operation that releases a previously acquired 
        partial-lock.
      </xs:documentation>
    </xs:annotation>     
    <xs:complexContent>
      <xs:extension base="nc:rpcOperationType">
        <xs:sequence>
          <xs:element name="lock-id" type="lock-id-type">
            <xs:annotation>
              <xs:documentation>
                Identifies the lock to be released. MUST be the value
                received in the response to the partial-lock operation.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- <partial-lock> operation -->
  <xs:element name="partial-lock" type="partialLockType" 
    substitutionGroup="nc:rpcOperation"/>
  
  <!-- <partial-unlock> operation -->
  <xs:element name="partial-unlock" type="partialUnLockType" 
    substitutionGroup="nc:rpcOperation"/>
  
  <!-- reply to <partial-lock> -->
  
  <xs:complexType name="contentPartInPartialLockReplyType">
    <xs:annotation>
      <xs:documentation>
        The content of the reply to a successful 
        partial-lock request MUST conform to this complex type.
      </xs:documentation>
    </xs:annotation> 
    <xs:sequence>
      <xs:element name="lock-id" type="lock-id-type">
        <xs:annotation>
          <xs:documentation>
            Identifies the lock to be released. Must be the value
            received in the response to the partial-lock operation.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="running" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            List of locked nodes in the running datastore.
          </xs:documentation>
        </xs:annotation>     
        <xs:complexType>
          <xs:sequence>
            <xs:element name="locked-node" type="xs:string" 
              maxOccurs="unbounded">
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>              
      <xs:element name="candidate" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            List of locked nodes in the candidate datastore.
          </xs:documentation>
        </xs:annotation>     
        <xs:complexType>
          <xs:sequence>
            <xs:element name="locked-node" type="xs:string" 
              maxOccurs="unbounded">
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>              
      <xs:element name="startup" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            List of locked nodes in the startup datastore.
          </xs:documentation>
        </xs:annotation>     
        <xs:complexType>
          <xs:sequence>
            <xs:element name="locked-node" type="xs:string" 
              maxOccurs="unbounded">
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>              
    </xs:sequence>
  </xs:complexType>    
  
</xs:schema>
                        ]]></artwork>
                </figure>                
            </t>
        </section>
        <section title="Appendix B  - YANG Module for Partial Locking (non-normative)">
            <t>The following YANG module defines the &lt;partial-lock> and &lt;partial-unlock> operations. 
                The YANG language is defined in <xref target="I-D.ietf-netmod-yang"/>.
                <figure>
                    <artwork><![CDATA[
module ietf-netconf-partial-lock {

  namespace urn:ietf:params:xml:ns:netconf:partial-lock:1.0;
  prefix pl;

  organization "IETF Network Configuration (netconf) Working Group";

  contact
   "Netconf Working Group
    Mailing list: netconf@ietf.org
    Web: http://www.ietf.org/html.charters/netconf-charter.html

    Balazs Lengyel
    Ericsson
    balazs.lengyel@ericsson.com";

  description
   "This YANG module defines the <partial-lock> and
    <partial-unlock> operations.";

  revision 2009-02-19 {
    description
     "Initial version, published as RFC yyyy.";
     // RFC Ed.: replace yyyy with actual RFC number & remove this note.
  }

  typedef lock-id-type {
    type uint32;
    description
     "A number identifying a specific partial-lock granted to a session.
      It is allocated by the system, and SHOULD be used in the
      partial-unlock operation.";
  }

  rpc partial-lock {
    description
     "A NETCONF operation that locks part of one or more datastores.";
    input {
      list target {
        min-elements 1;
        description
         "A list of one or more datastore names.
          Each list entry must contain a different datastore name.";
        choice datastore {
          leaf running   { type empty; }
          leaf candidate { type empty; }
          leaf startup   { type empty; }
        }
      }
      leaf-list select {
        type string;
        min-elements 1;
        description
         "XPath expression that specifies the scope of the lock.
          An Instance Identifier expression MUST be used unless the
          :xpath capability is supported, in which case any XPath 1.0
          expression is allowed.";
      }
    }
    output {
      leaf lock-id {
        type lock-id-type;
        description
         "Identifies the lock, if granted. The lock-id SHOULD be
          used in the partial-unlock rpc.";
      }
      container running {
        leaf-list locked-node {
          type instance-identifier;
          min-elements 1;
          description
           "List of locked nodes in the running datastore";
        }
      }
      container candidate {
        leaf-list locked-node {
          type instance-identifier;
          min-elements 1;
          description
           "List of locked nodes in the candidate datastore";
        }
      }
      container startup {
        leaf-list locked-node {
          type instance-identifier;
          min-elements 1;
          description
           "List of locked nodes in the startup datastore";
        }
      }
    }
  }

  rpc partial-unlock {
    description
     "A NETCONF operation that releases a previously acquired
      partial-lock.";
    input {
      leaf lock-id {
        type lock-id-type;
        description
         "Identifies the lock to be released. MUST be the value
          received in the response to the partial-lock operation.";
      }
    }
  }
}

                    ]]></artwork>
                </figure>
            </t>
        </section>
        <section title="Appendix C - Usage Example - Reserving nodes for future editing (non-normative)">
            <t>
                Partial lock cannot be used to lock non-existent nodes, which would effectively attempt to reserve them for future use. 
                To guarantee that a node cannot be created by some other session, the
                parent node should be locked, the top level node of the new subtree created, and then locked 
                with another &lt;partial-lock> operation. After this, the lock on the parent node should be removed.
            </t>
            <t>In this chapter an example illustrating the above is given.
                <vspace blankLines="1"/>
                We want to create &lt;user> Joe under &lt;users>, and start editing it. 
                Editing might take a number of minutes.
                We want to immediately lock Joe so no one will touch it before we are finished with the editing. 
                <vspace blankLines="1"/>
                We also want to minimize locking other parts of the datastore as multiple managers might 
                be adding users near simultaneously.
                <vspace blankLines="1"/>
                First we check what users are already defined. 
                <figure><preamble>Step 1 - Read existing users</preamble>
                    <artwork>
                        <![CDATA[
<rpc message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <get-config>
    <source>
      <running/>
    </source>
    <filter type="subtree">
      <top xmlns="http://example.com/users">
        <users/>
      </top>
    </filter>
  </get-config>
</rpc>
]]>
                    </artwork>
                </figure>
                <vspace blankLines="1"/>
                The NETCONF server sends the following reply.                
                <figure><preamble>Step 2 - Receiving existing data</preamble>
                    <artwork>
                        <![CDATA[
<rpc-reply message-id="101"
     xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <data>
    <top xmlns="http://example.com/users">
      <users>
        <user>
          <name>fred</name>
          <phone>8327</phone>
        </user>
      </users>
    </top>
  </data>
</rpc-reply>
]]>
                    </artwork>
                </figure>
                <vspace blankLines="1"/>
                We want to add the new user "Joe" and immediately lock him 
                using partial locking. The way to do this, is to first lock all &lt;user> nodes by locking the &lt;users> node.               
                <figure><preamble>Step 3 - Lock users</preamble>
                    <artwork><![CDATA[
<nc:rpc
  xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
  xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
      message-id="102">
  <partial-lock>
    <target>
      <running/>
    </target>
    <select xmlns:usr="http://example.com/users">
      /usr:top/usr:users
    </select>
  </partial-lock>
</nc:rpc>             
                        ]]></artwork>
                </figure>
                <vspace blankLines="1"/>
                The NETCONF server grants the partial lock. The scope 
                of the lock includes only the &lt;users> node. The lock 
                protects the &lt;users> node and all &lt;user> nodes below it from 
                modification (by other sessions).               
                <figure><preamble>Step 4 - Receive lock</preamble>
                    <artwork><![CDATA[
<nc:rpc-reply
  xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
  xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
  message-id="102">
    <lock-id>1</lock-id>
    <running>
      <locked-node xmlns:usr="http://example.com/users">
          /usr:top/usr:users
      </locked-node>
    </running>
</nc:rpc-reply>             
                        ]]></artwork>
                </figure>
                <vspace blankLines="1"/>
                Next we create user Joe. Joe is protected by the lock 
                received above, as it is under the sub-tree rooted at the &lt;users> node.
                <figure><preamble>Step 5 - Create user Joe</preamble>
                    <artwork><![CDATA[
<rpc message-id="103"
     xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <edit-config>
    <target>
      <running/>
    </target>
    <config>
      <top xmlns:usr="http://example.com/users">
        <users>
          <user>
            <name>Joe</name>
          </user>
        </users>
      </top>
    </config>
  </edit-config>
</rpc>
                        ]]></artwork>
                </figure>
                <vspace blankLines="1"/>
                We receive a positive reply to the &lt;edit-config> (not shown).
                Next we request a lock, that locks only &lt;user> Joe, and release the lock on the &lt;users> node. 
                This will allow other managers to create additional new users.                
                <figure><preamble>Step 6 - Lock user Joe</preamble>
                    <artwork><![CDATA[
<nc:rpc
  xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
  xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
      message-id="104">
  <partial-lock>
    <target>
      <running/>
    </target>
    <select xmlns:usr="http://example.com/users">
      /usr:top/usr:users/user[usr:name="Joe"]"
    </select>
  </partial-lock>
</nc:rpc>             
                        ]]></artwork>
                </figure>
                <vspace blankLines="1"/>
                The NETCONF server grants the partial lock. The scope 
                of this second lock includes only the &lt;user> node with name Joe. The lock 
                protects all data below this particular &lt;user> node.               
                <figure><preamble>Step 7 - Receive lock</preamble>
                    <artwork><![CDATA[
<nc:rpc-reply
  xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
  xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
  message-id="104">
    <lock-id>2</lock-id>
    <running>
      <locked-node xmlns:usr="http://example.com/users">
          /usr:top/usr:users/user[usr:name="Joe"]"
      </locked-node>
    </running>
</nc:rpc-reply>             
                        ]]></artwork>
                </figure>
                <vspace blankLines="1"/>
                The scope of the second lock is the &lt;user> node Joe. It protects this &lt;user> 
                node and any data below it (e.g. phone number).
                At this point of time these nodes are protected both by the first and second lock.
                Next we unlock the other &lt;user>s and the &lt;users> node, to allow other managers 
                to work on them. We still keep the second lock, so the &lt;user> node Joe and the sub-tree below is still protected.                
                <figure><preamble>Step 8 - Release lock on &lt;users></preamble>
                    <artwork><![CDATA[
<nc:rpc xmlns="urn:ietf:params:xml:ns:netconf:partial-lock:1.0"
    xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
    message-id="105">
  <partial-unlock>
    <lock-id>1</lock-id>
  </partial-unlock>
</nc:rpc>    
                        ]]></artwork>
                </figure>
            </t>
        </section>
        <section title="Appendix D  -  Change Log"> 
          <section title="06-07">
            <t>Changed XSD and YANG to allow additional proprietary datastores to be locked.</t>
          </section>
          <section title="05-06">
            <t>Added usage example</t>
            <t>Clarified error messages</t>
            <t>Clarified interaction with edit-config continue-on-error</t>
            <t>Improved YANG: indentation, canonical order, contact info</t>
            <t>Added usage example in appendix C</t>
            <t>Synchronized YANG and XSD</t>
          </section>
          <section title="04-05">
                <t>Language and editorial updates</t>
                <t>all app-tags are with dashes without spaces</t>
                <t>Added usage scenarios</t>
                <t>Changed encoding</t>
                <t>Clarified definitions, separated scope of lock and protected area</t>
            </section>
            <section title="03-04">
                <t>Minor clarifications</t>
                <t>Added list of locked-nodes to the output of partial-lock.</t>
                <t>Added &lt;target> wrapper around datastore names.</t>
                <t>Allowed atomic/one operation locking of datastore parts in multiple datastores.</t>
                <t>Improved English (hopefully)</t>
                <t>Removed the &lt;data> element from rpc-reply following the text of rfc4741.</t>
            </section>   
            <section title="02-03">
                <t>Minor clarifications</t>
                <t>Same descriptions in XSD and YANG.</t>
            </section>   
            <section title="01-02">
                <t>Made XSD normative</t>
                <t>Clarified that no specific access control is assumed.</t>
                <t>Clarified that non-existing nodes are NOT covered by the lock, even if they where existing and covered by the lock when it was originally granted.</t>
                <t>Some rewording</t>
                <t>Added app-tags for two of the error cases.</t>
                <t>Made YANG an informative reference</t>
                <t>Enhanced security considerations.</t>
            </section>
            <section title="00-01">
                <t>Added YANG module.</t>
            </section>
            <section title="-00">
                <t>Created from draft-lengyel-ngo-partial-lock-01.txt</t>
            </section>
        </section>
        <section title="Acknowledgements">
            <t>Thanks to Andy Bierman, Sharon Chisholm, Phil Shafer , David Harrington, Mehmet Ersue, 
                Wes Hardaker, Juergen Schoenwaelder and 
                many other members of the NETCONF WG for providing important input to this document.</t>
        </section>
    </middle>
    <back>
        <references title="Normative References">
            <reference anchor='NETCONF'>
                <front>
                    <title>NETCONF Configuration Protocol</title>
                    <author initials='R.' surname='Enns' fullname='R. Enns'>
                        <organization /></author>
                    <date year='2006' month='December' />
                    <abstract>
                        <t>The Network Configuration Protocol (NETCONF) defined 
                            in this document provides mechanisms to install, manipulate, 
                            and delete the configuration of network devices.  It uses an 
                            Extensible Markup Language (XML)-based data encoding for the configuration 
                            data as well as the protocol messages.  The NETCONF protocol operations 
                            are realized on top of a simple Remote Procedure Call (RPC) 
                            layer. [STANDARDS TRACK]
                        </t>
                    </abstract>
                </front>                
                <seriesInfo name='RFC' value='4741' />
                <format type='TXT' octets='173914' target='ftp://ftp.isi.edu/in-notes/rfc4741.txt' />
            </reference>
            <reference anchor='RFC2119'>
                <front>
                    <title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
                    <author initials='S.' surname='Bradner' fullname='Scott Bradner'>
                        <organization>Harvard University</organization>
                        <address>
                            <postal>
                                <street>1350 Mass. Ave.</street>
                                <street>Cambridge</street>
                                <street>MA 02138</street></postal>
                            <phone>- +1 617 495 3864</phone>
                            <email>sob@harvard.edu</email></address></author>
                    <date year='1997' month='March' />
                    <area>General</area>
                    <keyword>keyword</keyword>
                    <abstract>
                        <t>
                            In many standards track documents several words are used to signify
                            the requirements in the specification.  These words are often
                            capitalized.  This document defines these words as they should be
                            interpreted in IETF documents.  Authors who follow these guidelines
                            should incorporate this phrase near the beginning of their document:
                            
                            <list>
                                <t>
                                    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
                                    NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED",  "MAY", and
                                    "OPTIONAL" in this document are to be interpreted as described in
                                    RFC 2119.
                                </t></list></t>
                        <t>
                            Note that the force of these words is modified by the requirement
                            level of the document in which they are used.
                        </t></abstract></front>
                
                <seriesInfo name='BCP' value='14' />
                <seriesInfo name='RFC' value='2119' />
                <format type='TXT' octets='4723' target='ftp://ftp.isi.edu/in-notes/rfc2119.txt' />
                <format type='HTML' octets='17491' target='http://xml.resource.org/public/rfc/html/rfc2119.html' />
                <format type='XML' octets='5777' target='http://xml.resource.org/public/rfc/xml/rfc2119.xml' />
            </reference>
            <reference anchor='RFC3688'>                
                <front>
                    <title>The IETF XML Registry</title>
                    <author initials='M.' surname='Mealling' fullname='M. Mealling'>
                        <organization /></author>
                    <date year='2004' month='January' />
                    <abstract>
                        <t>This document describes an IANA maintained registry for IETF standards which use Extensible 
                          Markup Language (XML) related items such as Namespaces, Document Type Declarations (DTDs), 
                          Schemas, and Resource Description Framework (RDF) Schemas.</t></abstract></front>
                <seriesInfo name='BCP' value='81' />
                <seriesInfo name='RFC' value='3688' />
                <format type='TXT' octets='17325' target='ftp://ftp.isi.edu/in-notes/rfc3688.txt' />
            </reference>            
        </references>
        <references title="Informative References">
          <reference anchor='I-D.ietf-netmod-yang'>
            <front>
              <title>YANG - A data modeling language for NETCONF</title>
              <author initials='M' surname='Bjorklund' fullname='Martin Bjorklund'>
                <organization />
              </author>
              <date month='January' day='12' year='2009' />
              <abstract><t>YANG is a data modeling language used to model configuration and state data manipulated 
                by the NETCONF protocol, NETCONF remote procedure calls, and NETCONF notifications.</t></abstract>
            </front>
            <seriesInfo name='Internet-Draft' value='draft-ietf-netmod-yang-03' />
            <format type='TXT'
              target='http://www.ietf.org/internet-drafts/draft-ietf-netmod-yang-03.txt' />
          </reference>
        </references>
    </back>
    
</rfc>
 
