<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd'[
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2578 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2578.xml">
<!ENTITY RFC3410 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3410.xml">
<!ENTITY RFC3416 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3416.xml">
<!ENTITY RFC3418 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3418.xml">
<!ENTITY RFC4293 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4293.xml">
<!ENTITY RFC4648 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4648.xml">
<!ENTITY RFC4944 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4944.xml">
<!ENTITY RFC5277 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5277.xml">
<!ENTITY RFC6020 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6020.xml">
<!ENTITY RFC6241 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6241.xml">
<!ENTITY RFC6243 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6243.xml">
<!ENTITY RFC6347 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6347.xml">
<!ENTITY RFC6643 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6643.xml">
<!ENTITY RFC6650 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6650.xml">
<!ENTITY RFC6775 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6775.xml">
<!ENTITY RFC6690 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6690.xml">
<!ENTITY RFC7049 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7049.xml">
<!ENTITY RFC7159 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7159.xml">
<!ENTITY RFC7252 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7252.xml">
<!ENTITY RFC7277 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7277.xml">
<!ENTITY RFC7641 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7641.xml">
<!ENTITY RFC7950 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7950.xml">
<!ENTITY RFC7959 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7959.xml">
<!ENTITY I-D.ietf-core-interfaces SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-core-interfaces.xml">
<!ENTITY I-D.becker-core-coap-sms-gprs SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.becker-core-coap-sms-gprs.xml">
<!ENTITY I-D.ietf-netconf-restconf SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-netconf-restconf.xml">
<!ENTITY I-D.vanderstok-core-etch SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.vanderstok-core-etch.xml">
<!ENTITY I-D.ietf-netconf-YANG-patch SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-netconf-YANG-patch.xml">
<!ENTITY I-D.somaraju-core-sid SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.somaraju-core-sid.xml">
<!ENTITY I-D.ietf-core-yang-cbor SYSTEM
"http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-core-yang-cbor.xml">
]>

<?rfc toc="yes"?>
<?rfc symrefs="yes" ?>

<rfc category="std" ipr="trust200902" docName="draft-vanderstok-core-comi-10">
  <front>
    <title abbrev="CoMI">CoAP Management Interface</title>
    <author initials="P." surname="van der Stok" fullname="Peter van der Stok">
      <organization abbrev="consultant">consultant</organization>
      <address>
        <phone>+31-492474673 (Netherlands), +33-966015248 (France)</phone>
        <email>consultancy@vanderstok.org</email>
        <uri>www.vanderstok.org</uri>
      </address>
    </author>

   <author initials="A" surname="Bierman" fullname='Andy Bierman' >
      <organization>YumaWorks</organization>
      <address>
        <postal>
          <street>685 Cochran St.</street>
          <street>Suite #160</street>
          <city>Simi Valley</city>
          <region>CA</region>
          <code>93065</code>
          <country>USA</country>
        </postal>
        <email>andy@yumaworks.com</email>
      </address>
    </author>

<author initials="M.V." surname="Veillette" fullname="Michel Veillette">
      <organization>Trilliant Networks Inc.</organization>
      <address>
        <postal>
          <street>610 Rue du Luxembourg</street>
          <city>Granby</city>
          <region>Quebec</region>
          <code>J2J 2V2</code>
          <country>Canada</country>
        </postal>
        <phone>+14503750556</phone>
        <email>michel.veillette@trilliantinc.com</email>
      </address>
    </author>

    <author initials="A.P." surname="Pelov" fullname="Alexander Pelov">
      <organization>Acklio</organization>
      <address>
        <postal>
          <street>2bis rue de la Chataigneraie</street>
          <city>Cesson-Sevigne</city>
          <region>Bretagne</region>
          <code>35510</code>
          <country>France</country>
        </postal>
        <email>a@ackl.io</email>
      </address>
    </author>


    <date />
    <area>Applications</area>
    <workgroup>CoRE</workgroup>
    <abstract>
      <t>
        This document describes a network management interface for constrained devices and networks, called CoAP Management Interface (CoMI).
        The Constrained Application Protocol (CoAP) is used to access data resources specified in YANG,
        or SMIv2 converted to YANG. CoMI uses the YANG to CBOR mapping and converts YANG identifier strings to numeric identifiers for payload size reduction. CoMI extends the set of YANG based protocols NETCONF and RESTCONF with the capability to manage constrained devices and networks. 
      </t>
    </abstract>
    <note title="Note">
      <t>
        Discussion and suggestions for improvement are requested,
        and should be sent to core@ietf.org.
      </t>
    </note>
  </front>
  <middle>

<section anchor="introduction" title="Introduction">
<t>
The Constrained Application Protocol (CoAP) <xref target="RFC7252"/> is designed for 
Machine to Machine (M2M) applications such as smart energy and building control.
Constrained devices need to be managed in an automatic fashion to handle the large quantities of devices that are expected in
future installations. The messages between devices need to be as small and infrequent as possible. The implementation
complexity and runtime resources need to be as small as possible.
</t><t>
This draft describes the CoAP Management Interface which uses CoAP methods to access structured data defined in YANG <xref target="RFC6020"/>. This draft is complementary to
the draft <xref target="I-D.ietf-netconf-restconf"/> which describes a REST-like interface called RESTCONF,
which uses HTTP methods to access structured data defined in YANG. 
</t><t>
The use of standardized data sets, specified in a standardized language such as YANG, promotes interoperability between devices and applications from different manufacturers.
A large amount of  Management Information Base (MIB) <xref target="RFC3418"/> <xref target="mibreg"/> specifications already
exists for monitoring purposes. This data can be accessed in RESTCONF or CoMI if the server converts the
SMIv2 modules to YANG, using the mapping rules defined in <xref target="RFC6643"/>.
</t><t>
CoMI and RESTCONF are intended to work in a stateless client-server fashion. They use a single round-trip to complete a single editing transaction, where NETCONF needs up to 10 round trips.
</t><t>
To promote small packets, CoMI uses a YANG to CBOR mapping <xref target="I-D.ietf-core-yang-cbor"/> and an additional "data-identifier string-to-number conversion" to minimize CBOR payloads and URI length.
</t>

<section anchor="terminology" title="Terminology">
<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 <xref target="RFC2119"/>.
</t>
<t>
Readers of this specification should be familiar with all the terms and concepts discussed in <xref target="RFC3410"/>, <xref target="RFC3416"/>, and <xref target="RFC2578"/>.
</t>
<t>
  The following terms are defined in the NETCONF protocol <xref target="RFC6241"/>: client, configuration data, datastore, and server.
</t>
<t>
  The following terms are defined in the YANG data modelling language <xref target="RFC6020"/>: container, data node, key, key leaf, leaf, leaf-list, and list. 
</t><t>
The following terms are defined in RESTCONF protocol <xref target="I-D.ietf-netconf-restconf"/>: data resource, datastore resource, edit operation, query parameter, and target resource.
</t>
<t>
  The following terms are defined in this document:
  <list style="hanging">
    <t hangText="data node instance:"> An instance of a data node specified in a YANG module present in the server. The instance is stored in the memory of the server.
    </t>
    <t hangText="Notification instance:"> An instance of a schema node of type notification, specified in a YANG module present in the server. The instance is generated in the server at the occurrence of the corresponding event and appended to a stream.
    </t>
       <t hangText="YANG schema item identifier:"> Numeric identifier which replaces the name identifying a YANG item ( see section 6.2 of <xref target="RFC7950"/>) (data node, RPC, Action, Notification, Identity, Module name, Submodule name, Feature).
</t>
<t hangText="list instance identifier:">
Handle used to identify a YANG data node that is an instance of a YANG "list" specified with the values of the key leaves of the list.
</t>
<t hangText="single instance identifier:">
Handle used to identify a specific data node which can be instantiated only once. This includes data nodes defined at the root of a YANG module or submodule and data nodes defined within a container. This excludes data nodes defined within a list or any children of these data nodes. 
</t>
<t hangText="instance identifier:">
List instance identifier or single instance identifier. 
</t>
<t hangText="data node value:">
Value assigned to a data node instance. Data node values are encoded based on the rules defined in section 4 of <xref target="I-D.ietf-core-yang-cbor"/>. 
</t>
<t hangText="set of data node instances:">
Represents the payload of CoAP methods when a collection is sent or returned. There are two possibilities, dependent on Request context :
<list style="numbers">
<t>CBOR array of pair(s) &lt;instance identifier, data node value &gt; </t>
<t>CBOR map of pair(s) &lt;instance identifier, data node value &gt; </t>
</list>
 </t>

  </list>
</t>
<t>
  The following list contains the abbreviations used in this document.
  <list style="hanging">
    <t hangText="SID:">YANG Schema Item iDentifier.</t>
  </list>
</t>

</section>  <!-- Terminology -->

</section>  <!-- Introduction -->


<section anchor="comi-architecture" title="CoMI Architecture">
<t>
This section describes the CoMI architecture to use CoAP for the reading and modifying of instrumentation variables used for the management of the instrumented node.
</t>
<figure anchor="archit" title="Abstract CoMI architecture"><artwork align="left"><![CDATA[

Client
+--------------------------------------------------------------+
| +----------------+    +----------------+                     |
| |    SMIv2       | >  |      YANG      |    >     COAP       |
| |specification(2)|    |specification(1)|       Request(3)    |
| +----------------+    +----------------+[         *          |
+-----------------------------*-----------[---------*----------+
                              *           [         *
                              *           [    +-----------+
                      mapping *   security[    |  Network  |
                              *      (8)  [    | packet(4) |
                              *           [    +-----------+
Server                        *           [         *
+-----------------------------*-----------[---------*----------+
|                             *           [         *          |
|                             *                 Retrieval,     |
|                             *               Modification(5)  |
|                            \*/                    *          |
| +-------------------------------------------------*--------+ |
| |                    +--------------+       +------------+ | |
| |                    |configuration |       |Operational | | |
| |                    |     (6b)     |       |  state(6a) | | |
| |                    +--------------+       +------------+ | |
| |                      datastore (6)              *        | |
| +-------------------------------------------------*--------+ |
|                                                   *          |
|                                                Variable      |
|                                            Instrumentation(7)|
+--------------------------------------------------------------+

]]></artwork></figure>
<t>
<xref target="archit"/> is a high level representation of the main elements of the CoAP management architecture. A client sends requests as payload in packets over the network to a managed constrained node. 
</t>
<t>
The different numbered components of <xref target="archit"/>  are discussed according to component number.
<list style="hanging"> 
<t hangText="(1) YANG specification:"> contains a set of named and versioned modules. 
</t>
<t hangText="(2) SMIv2 specification:"> A named module specifies a set of variables and "conceptual tables". There is an algorithm to translate SMIv2 specifications to YANG specifications.
</t>
<t hangText="(3) CoAP request:"> The CoAP request needs a Universal Resource Identifier (URI). The CoMI client sends request messages and receives response messages.</t> 
<t hangText="(4) Network packet:"> The payload contains CBOR encoded YANG data node instances.
</t>
<t hangText="(5) Retrieval, modification:"> The server needs to parse the CBOR encoded message 
and identify the corresponding instances in the datastore.
</t>
<t hangText="(6) Datastore:"> The store is composed of two parts: Operational state and Configuration datastore. 
</t>
<t hangText="(7) Variable instrumentation:"> This code depends on implementation of drivers and other node specific aspects. 
</t>
<t hangText="(8) Security:"> The server MUST prevent unauthorized users from reading or writing
any data resources. CoMI relies on the security measures specified for CoAP such as DTLS <xref target="RFC6347"/>.
</t>
</list>
</t> 

<section title="Major differences between RESTCONF and CoMI" anchor = "MAJDIF">
<t>
CoMI uses CoAP/UDP as transport protocol and CBOR as payload format <xref target="I-D.ietf-core-yang-cbor"/>. RESTCONF uses HTTP/TCP as transport protocol and JSON <xref target="RFC7159"/> or XML <xref target="XML"/> as payload formats. CoMI encodes YANG identifier strings as numbers, where RESTCONF does not.
</t><t>
CoMI uses the methods FETCH and iPATCH, not used by RESTCONF.  RESTCONF uses the HTTP methods HEAD, and OPTIONS, which are not used by CoMI.
</t><t>
CoAP servers MUST maintain the order of user-ordered data. CoMI does not support insert-mode (first, last, before, after) and insertion-point (before, after) which are supported by RESTCONF. 
Many CoAP servers will not support date and time functions. For that reason CoMI does not support the start, stop options for events.
</t><t>
CoMI servers only implement the efficient "trim" mode for default values
</t><t>
The CoMI servers do not support the following RESTCONF functionality:
<list style="symbols"> 
<t>
The "fields" query parameter to query multiple instances.
</t>
<t>
The 'filter' query that involves XML parsing, 'content', and 'depth', query parameters.
</t>
</list>
</t>
</section> <!-- Major differences  -->

<section anchor="object-id-compression" title="Compression of data node instance identifier">
<t>
In the YANG specification the nodes are identified with a name string. The name string contains the module name, hierarchy of container/list names, and the leaf name.
</t>
<t>
In order to significantly reduce the size of identifiers used in CoMI, numeric
object identifiers are used instead of these strings.
The specific encoding of the object identifiers
is not hard-wired in the protocol.
</t>
<t>
Examples of object identifier encoding formats are described in
 <xref target="I-D.somaraju-core-sid"/>.
</t>

</section> <!-- Compression -->

</section>  <!-- CoMI Architecture  -->

<section title="Example syntax" anchor="EXSYNTAX">
<t>
This section presents the notation used for the examples. The YANG specifications that are used throughout this document are shown in <xref target="EXSPEC"/>. The example specifications are taken over from existing modules and annotated with SIDs. The values of the SIDs are taken over from <xref target="yang-cbor"/>. 
</t><t>
CBOR is used for the payload of the request- and the return-packets. The CBOR syntax of the YANG payloads is specified in <xref target="RFC7049"/>. The payload examples are notated in Diagnostic notation (defined in section 6 of <xref target="RFC7049"/>) that can be automatically converted to CBOR.
</t><t>
A YANG leaf (YANG item identifier, YANG item value) pair is mapped to a CBOR(key, value) pair. The YANG leaf value is encoded as specified in <xref target="I-D.ietf-core-yang-cbor"/>. The YANG leaf identifier can be a SID or a CBOR array with the structure [SID, key1, key2], where SID is a list identifier and the key values specify the list instance. The YANG leaf value can be a simple value, a CBOR array, or a CBOR map.
</t><t> Delta encoding is used for the SIDs. The notation +n is used when the SID has the value PREC+n where PREC is the SID of the parent container, or PREC is the SID of the preceding entity in a CBOR array.
</t><t>
In all examples the resource path in the URI is expressed as a SID, represented as a base64 number. SIDs in the payload are represented as decimal numbers.
</t>
</section> <!-- Example syntax -->

<section anchor="coap-interface" title="CoAP Interface">
<t>

In CoAP a group of links can constitute a Function Set. The format of the links is specified in <xref target="I-D.ietf-core-interfaces"/>.
  This note specifies a Management Function Set. CoMI end-points that implement the CoMI management protocol support
 at least one discoverable management resource of resource type (rt): core.c, with path: /c, where c is short-hand for CoMI. The path root /c is recommended but not compulsory (see <xref target="discovery"/>).
</t>
<t>
The path prefix /c has resources accessible with the following three paths:
<list style="hanging">
<t hangText="/c:">YANG-based data with path "/c" and using CBOR content encoding format.
This path represents a datastore resource which contains YANG data resources as its descendant nodes. The data nodes are identified with their SID with format /c/SID.</t>
<t hangText="/c/mod.uri:">URI identifying the location of the server module information, with path "/c/mod.uri" and CBOR content format. This YANG data is encoded with plain identifier strings, not YANG encoded values. An Entity Tag MUST be maintained
for this resource by the server, which MUST be changed to a new value when the set of YANG modules in use by the server changes.</t>
<t hangText="/c/s:"> String identifying the default stream resource to which YANG notification instances are appended.  Notification support is optional, so this resource will not exist
if the server does not support any notifications.
</t>
</list>
</t><t>
The mapping of YANG data node instances to CoMI resources is as follows:
A YANG module describes a set of data trees composed of YANG data nodes.
Every root of a data tree in a YANG module loaded in the CoMI server represents a resource of the server.
All data root descendants represent sub-resources.
</t><t>
The resource identifiers of the instances of the YANG specifications are encoded YANG identifier strings. When multiple instances of a list node exist, instance selection is possible as described in <xref target="FETCH"/> and <xref target="GetExamples"/>.
</t>
<t>
The profile of the management function set, with IF=core.c, is shown in the table below,
following the guidelines of <xref target="I-D.ietf-core-interfaces"/>:
</t>

<texttable>
  <ttcol align="left">name</ttcol>
  <ttcol align="left">path</ttcol>
  <ttcol align="left">rt</ttcol>
  <ttcol align="left">Data Type</ttcol>

  <c> Management  </c>   <c> /c </c> <c> core.c </c> <c> n/a </c>
  <c> Data  </c>   <c> /c </c> <c> core.c.data </c> <c> application/cbor </c>
  <c> Module Set URI </c>   <c> /c/mod.uri </c> <c> core.c.moduri </c> <c> application/cbor </c>
  <c> Events </c>   <c> /c/s </c> <c> core.c.stream </c> <c> application/cbor </c>
</texttable>

</section>   <!-- CoAP Interface -->

<section anchor="mgFS" title="/c Function Set">
<t>
The /c Function Set provides a CoAP interface to manage YANG servers.
</t>

<t>
The methods used by CoMI are:
</t>
<texttable>
  <ttcol align="left">Operation</ttcol>
  <ttcol align="left">Description</ttcol>
  <c> GET </c>   <c> Retrieve the datastore resource or a data resource </c>
<c> FETCH </c>   <c> Retrieve partial data resources </c>
  <c> POST </c>   <c> Create a data resource, invoke RPC </c>
  <c> PUT </c>   <c> Create or replace a data resource </c>
<c> iPATCH </c>  <c> Idem-potently replace a data resource partially  </c>
  <c> DELETE </c>   <c> Delete a data resource </c>
</texttable>
<t>
There is one query parameters for the GET, PUT, POST, and DELETE methods.
</t>
<texttable>
  <ttcol align="left">Query Parameter</ttcol>
  <ttcol align="left">Description</ttcol>
<c> k </c> <c> Select an instance of a list node </c>
</texttable>
<t>
This parameter is not used for FETCH and iPATCH, because their request payloads support list instance selection.
</t>


<section anchor="query" title="Using the 'k' query parameter">
<t>
The "k" (key) parameter specifies the instance of a list node.
The SID in the URI is followed by the (?k=key1, key2,..). Where SID identifies a list node, and key1, key2 are the values of the key leafs that specify an instance of the list.
</t><t> Key values are encoded using the rules defined in the following table:
</t>
<texttable>
  <ttcol align="left">YANG datatype</ttcol>
  <ttcol align="left">Binary representation</ttcol>
  <ttcol align="left">Text representation</ttcol>
  <c>uint8,uint16,unit32, uint64 </c> <c> CBOR unsigned integer</c> <c> int_to_text(number) </c>
  <c> int8, int16,int32, int64 </c>   <c> CBOR negative integer </c> <c> Base64 (CBOR representation) </c>
 <c>  </c> <c> CBOR unsigned integer </c> <c> </c>
<c> decimal64 </c><c> CBOR decimal fractions </c><c> base64  (CBOR representation</c>
<c> string </c> <c> CBOR text or string </c> <c> text </c>
<c> boolean </c> <c> CBOR false or true </c> <c> "0" or "1" </c>
<c> enumeration </c> <c> CBOR unsigned integer </c> <c> int_to_text (number) </c>
<c> bits </c> <c> CBOR byte string </c> <c> Base64 (CBOR representation) </c>
<c> binary </c> <c> CBOR byte string </c> <c> Base64 (CBOR representation) </c>
<c> identityref </c> <c> CBOR unsigned integer </c> <c> int_to_text (number) </c>
<c> union </c> <c>  </c> <c> Base64 (CBOR representation) </c>
<c> List instance identifier </c> <c> CBOR unsigned integer </c> <c> Base64 (CBOR representation) </c>
<c> List instance identifier </c> <c> CBOR array </c> <c> Base64 (CBOR representation) </c>
</texttable>
</section> <!-- query parameter -->


<section anchor="DataRetrieval" title="Data Retrieval">
<t>
One or more data node instances can be retrieved by the client.
The operation is mapped to the GET method defined in section 5.8.1 of <xref target="RFC7252"/> and to the FETCH method defined in section 2 of <xref target="I-D.vanderstok-core-etch"/>.
</t><t>
It is possible that the size of the payload is too large to fit in a single message.
In the case that management data is bigger than the maximum supported payload size,
the Block mechanism from <xref target="RFC7959"/> is used, as explained in more detail in <xref target="block"/>.
</t>
<t>
CoMI uses the FETCH payload for filtering sub-trees and retrieving only a
    subset that a managing application is interested in.
  </t>
<t>
There is one additional query parameters for the GET and FETCH methods.
</t>
<texttable>
  <ttcol align="left">Query Parameter</ttcol>
  <ttcol align="left">Description</ttcol>
<c> c </c> <c> Request to select configuration and non-configuration nodes (GET and FETCH) </c>
<c> d </c> <c> Control retrieval of default values.</c>                
</texttable>


<section anchor="content" title="Using the 'c' query parameter">
<t>
The 'c' (content) parameter controls how descendant nodes of the
   requested data nodes will be processed in the reply.
</t><t>
   The allowed values are:
</t>
<texttable>
  <ttcol align="left">Value</ttcol>
  <ttcol align="left">Description</ttcol>
  <c> c </c> <c> Return only configuration descendant data nodes</c>
  <c> n </c>   <c> Return only non-configuration descendant data nodes </c>
 <c> a </c> <c> Return all descendant data nodes </c>
</texttable>
<t>
This parameter is only allowed for GET and FETCH methods on datastore and data
   resources.  A 4.00 Bad Request error is returned if used for other
   methods or resource types.
</t><t>
   If this query parameter is not present the default value is "a".
</t>
</section>   <!-- content -->

<section anchor="dquery" title="Using the 'd' query parameter">
<t>
The "d" (with-defaults) parameter controls how the default values of the descendant nodes of the requested data nodes will be processed.
</t><t>
The allowed values are:
</t>
<texttable>
  <ttcol align="left">Value</ttcol>
  <ttcol align="left">Description</ttcol>
  <c> a </c> <c> All data nodes are reported| Defined as 'report-all' in section 3.1 of <xref target="RFC6243"/>.  </c>
  <c> t </c>   <c>Data nodes set to the YANG default are not reported.  Defined as 'trim' in section 3.2 of <xref target="RFC6243"/>. </c>
</texttable>
<t>


If the target of a GET or FETCH method is a data node that represents a leaf
   that has a default value, and the leaf has not been given a value
   yet, the server MUST return the leaf.
</t><t>
   If the target of a GET method is a data node that represents a
   container or list that has any child resources with default values,
   for the child resources that have not been given value yet, the
   server MUST not return the child resource if this query parameter is set to 't' and MUST return the child resource if this query parameter is set to 'a'.
</t><t>
If this query parameter is not present, the default value is 't'.
</t>
</section>  <!-- defaults handling -->


<section anchor="GetOperation" title="GET">
<t>
A request to read the values of instances of a management object  is sent with a confirmable CoAP GET message. A single object is specified in the URI path prefixed with /c. 
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    GET /c/<instance identifier>

    2.05 Content (Content-Format: application/cbor)
    <data node value>
]]></artwork>
    </figure>
<t>
The specified object MUST be a complete object. Accordingly, the returned payload is composed of all the leaves associated with the object.
</t><t>
The instance identifier is a SID or a SID followed by the "k" query parameter.
</t>

<section anchor="GetExamples" title="GET Examples">
<t>
Using for example the current-datetime leaf from <xref target="ietf-system"/>, a request is sent to retrieve the value of system-state/clock/current-datetime specified in container system-state. The ID of system-state/clock/current-datetime is 1719, encoded in base64 this yields a3. The answer to the request returns a &lt;value&gt;, transported as a single CBOR string item.
</t>

 <figure>
    <artwork align="left"><![CDATA[

REQ: GET example.com/c/a3

RES: 2.05 Content (Content-Format: application/cbor)
"2014-10-26T12:16:31Z"
]]></artwork>
    </figure>
<t>
For example, the GET of the clock node (ID = 1717; base64: a1), sent by the client, results in the following returned value sent by the server, transported as a CBOR map containing 2 pairs:
</t>

<figure><artwork align="left">
<![CDATA[
REQ: GET example.com/c/a1

RES: 2.05 Content (Content-Format: application/cbor)
{
      +2 : "2014-10-26T12:16:51Z",   # ID 1719
      +1 : "2014-10-21T03:00:00Z"    # ID 1718
}
]]></artwork></figure>

<t>
A "list" node can have multiple instances. Accordingly, the returned payload of GET is composed of all the instances associated with the selected list node. 
</t><t>
For example, look at the example in <xref target="interfaces"/>. The GET of the /interfaces/interface/ (with identifier 1533, base64: Bf0) results in the following returned payload, transported as a CBOR array with 2 elements.
</t>
<figure><artwork align="left">
<![CDATA[
REQ: GET example.com/c/Bf0

RES: 2.05 Content (Content-Format: application/cbor)
[
 {+4 : "eth0",                # name  (ID 1537)
  +1 : "Ethernet adaptor",    # description (ID 1534)
  +5 : 1179,                  # type, (ID 1538)identity 
                              # ethernetCsmacd (ID 1179)
  +2 : true                   # enabled ( ID 1535)
 },
 {+4 : "eth1",                # name
  +1 : "Ethernet adaptor",    # description
  +5 : 1179,         # type, identity ethernetCsmacd (ID 1179)
  +2 : false                  # enabled
]
]]></artwork></figure>
<t>
It is equally possible to select a leaf of one instance of a list or a complete instance container with GET. The instance identifier is the numeric identifier of the list followed by the specification of the values for the key leafs that uniquely identify the list instance. The instance identifier looks like:
SID?k=key-value. The key of "interface" is the "name" leaf. The example below requests the description leaf of the instance with name="eth0" (ID=1534, base64: Bf4). The value of the description leaf is returned.
</t>
<figure><artwork align="left">
<![CDATA[
REQ: GET example.com/c/Bf4?k="eth0"

RES: 2.05 Content (Content-Format: application/cbor)
"Ethernet adaptor"
]]></artwork></figure>

</section>  <!-- GET examples -->

</section>   <!-- GET -->


<section anchor="FETCH" title="FETCH">
<t>
The FETCH is used to retrieve a list of data node values. The FETCH Request payload contains a CBOR list of instance identifiers.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    FETCH /c/ Content-Format (application/YANG-fetch+cbor)
    <CBOR array of instance identifiers>

    2.05 Content (Content-Format: application/YANG-patch+cbor)
    <CBOR array of data node values>
]]></artwork>
    </figure>
<t>
The instance identifier is a SID or a CBOR array containing the SID followed by key values that identify the list instance (sec 5.13.1 of <xref target="I-D.ietf-core-yang-cbor"/>. In the payload of the returned data node values, delta encoding is used as described in <xref target="I-D.ietf-core-yang-cbor"/>.
</t>

<section title="FETCH examples" anchor="FETCHEX">
<t>
The example uses the current-datetime leaf and the interface list from <xref target="ietf-system"/>.
In the following example the value of current-datetime (ID 1719)and the interface list (ID 1533) instance identified with name="eth0" are queried.
</t>
<figure>
   <artwork align="left"><![CDATA[

FETCH /c Content-Format (application/YANG-fetch+cbor)
[ 1719,              # ID 1719
  [-186, "eth0"]   # ID 1533 with name = "eth0"
]

2.05 Content Content-Format (application/YANG-patch+cbor)
[ 
  "2014-10-26T12:16:31Z",
  {
   +4 : "eth0",                # name (ID 1537)
   +1 : "Ethernet adaptor",    # description (ID 1534)
   +5 : 1179,         # type (ID 1538), identity ethernetCsmacd
   +2 : true                   # enabled (ID 1535)
  }
]]></artwork>
</figure>

</section>  <!-- FETCH examples -->

</section>  <!-- FETCH -->

</section>  <!-- Data Retrieval -->

<section anchor="DataEditing" title="Data Editing">
<t>
CoMI allows datastore contents to be created, modified and deleted using CoAP methods.
</t>

<section anchor="DataOrdering" title="Data Ordering">
<t>
A CoMI server SHOULD preserve the relative order of all user-ordered list and
leaf-list entries that are received in a single edit request.  These YANG
data node types are encoded as arrays so messages will preserve their order.
</t>
</section>

<section anchor="PostOperation" title="POST">
<t>
Data resource instances are created with the POST method.
The CoAP POST operation is used in CoMI
for creation of data resources and the invocation of "ACTION" and "RPC" resources. Refer to <xref target="RPC"/> for details on "ACTION" and "RPC" resources.
</t><t>
A request to create the values of an instance of a container or leaf is sent with a confirmable CoAP POST message. A single SID is specified in the URI path prefixed with /c. 
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    POST /c/<instance identifier> Content-Format(application/cbor)
    <data node value>

    2.01 Created (Content-Format: application/cbor)
]]></artwork>
    </figure>
<t>
If the data resource already exists, then the POST request MUST fail and a "4.09 Conflict" status-line MUST be returned
</t>
<t>
The instance identifier is a SID or a SID followed by the "k" query parameter.
</t>

<section anchor="POSTEX" title="Post example">
<t>The example uses the interface list from <xref target="ietf-system"/>.
Example is creating a new version of the container interface (ID = 1533):
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    POST /c/Bf0 Content-Format(application/cbor)
      {
        +4 : "eth0",             # name (ID 1537)
        +1 : "Ethernet adaptor", # description (ID 1534)
        +5 : 1179,               # type (ID 1538), identity 
                                 # ethernetCsmacd (ID 1179)
        +2 : true                # enabled (ID 1535)
      }
    2.01 Created (Content-Format: application/cbor)
]]></artwork>
    </figure>

</section> <!-- POST example -->

</section>  <!-- POST -->

<section anchor="PutOperation" title="PUT">
<t>
Data resource instances are created or replaced with the PUT method.
The PUT operation is supported in CoMI.
A request to set the value of an instance of data node is sent with a confirmable CoAP PUT message.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    PUT /c/<instance identifier> Content-Format(application/cbor)
    <data node value>

    2.01 Created
]]></artwork>
    </figure>
<t>

The instance identifier is a SID or a SID followed by the "k" query parameter.
</t>

<section anchor="PUTEX" title="PUT example">
<t>The example uses the interface list from <xref target="ietf-system"/>.
Example is renewing an instance of the list interface (ID = 1533) with key name="eth0":
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    PUT /c/Bf0?k="eth0" Content-Format(application/cbor)
      {
        +4 : "eth0",             # name (ID 1537)
        +1 : "Ethernet adaptor", # description (ID 1534)
        +5 : 1179,               # type (ID 1538), identity  
                                 # ethernetCsmacd ( ID 1179)
        +2 : true                # enabled (ID 1535)
      }
    2.04 Changed
]]></artwork>
    </figure>

</section> <!-- PUT example -->


</section>  <!-- PUT  -->


<section anchor="PatchOperation" title="iPATCH">
<t>
One or multiple data resource instances are replaced with the idem-potent iPATCH method <xref target="I-D.vanderstok-core-etch"/>.
A request to set the values of instances of a subset of the values of the resource is sent with a confirmable CoAP iPATCH message.
</t><t>
There are no query parameters for the iPATCH method.
</t><t>
The processing of the iPATCH command is specified by the CBOR payload. The CBOR patch payload describes the changes to be made to target YANG data nodes REF TO BE DEFINED. If the CBOR patch payload contains data node instances that are not present in the target, these instances are added or silently ignored dependent of the payload information. If the target contains the specified instance, the contents of the instances are replaced with the values of the payload. Null values indicate the removal of existing values.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    iPATCH /c Content-Format(application/YANG-patch+cbor)
    <set of data node instances>

    2.04 Changed
]]></artwork>
    </figure>

<section title="iPATCH example" anchor="IPATCHEX">
<t>The example uses the interface list from <xref target="interfaces"/>, and the timezone-utc-offset leaf from <xref target="ietf-system"/>.
In the example one leaf (timezone-utc-offset ) and one container (interface) instance are changed.
</t>
<figure>
    <artwork align="left"><![CDATA[
iPATCH /c Content-Format(application/YANG-patch+cbor)
[
  [1533, "eth0"] ,                # interface (ID = 1533)
    { 
      +4 : "eth0",                # name (ID 1537)
      +1 : "Ethernet adaptor",    # description (ID 1534)
      +5 : 1179,                  # type (ID 1538), 
                                  # identity ethernetCsmacd
      +2 : true                   # enabled (ID 1535)
    }
  +203 , 60          # timezone-utc-offset (delta = 1736 - 1533)
]

2.04 Changed]]></artwork>
    </figure>

</section> <!-- iPatch examples -->

</section>  <!-- iPatch -->

<section anchor="DeleteOperation" title="DELETE">
<t>
Data resource instances are deleted with the DELETE method.
The RESTCONF DELETE operation is supported in CoMI.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    Delete /c/<instance identifier>

    2.02 Deleted
]]></artwork>
    </figure>

<t>
The instance identifier is a SID or a SID followed by the "k" query parameter.
</t>


<section anchor="DELETEX" title="DELETE example">
<t>The example uses the interface list from <xref target="interfaces"/>.
Example is deleting an instance of the container interface (ID = 1533):
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    DELETE /c/Bf0?k="eth0"
      
    2.02 Deleted
]]></artwork>
    </figure>

</section> <!-- DELETE example -->

</section>


</section>   <!-- Edit Operations -->

<section title="Full Data Store access" anchor="DATASTORE">
<t>
The methods GET, PUT, POST, and DELETE can be used to return, replace, create, and delete the whole data store respectively.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
    GET /c
    2.05 Content (Content-Format: application/cbor)
    <array of data node instances>

   PUT /c
   (Content-Format: application/cbor)
    <array of data node instances>
   2.04 Changed

   POST /c
   (Content-Format: application/cbor)
    <array of data node instances>
   2.01 Created

   DELETE /c
   (Content-Format: application/cbor)
    <array of data node instances>
    2.02 Deleted

]]></artwork>
    </figure>
<t>
The array of data node instances represents an array of all root nodes in the data store after the PUT, POST and GET method invocations.
</t>

<section title="Full Data Store examples" anchor="FULLDATEX">
<t>The example uses the interface list and the clock container from <xref target="interfaces"/>.
Assume that the data store contains two root objects: the list interface (ID 1533) with one instance and the container Clock (ID 1717). After invocation of GET an array with these two objects is returned:
</t>
<figure>
   <artwork align="left"><![CDATA[

GET /c 
2.05 Content Content-Format (application/YANG-patch+cbor)
[ 
  1717: 
     { +1: "2016-10-26T12:16:31Z", # current-datetime (ID 501)
       +2: "2014-10-05T09:00:00Z"  # boot-datetime (ID 502)
     }
  -186:                            # clock (ID 1533)
     {
       +4 : "eth0",                # name (ID 1537)
       +1 : "Ethernet adaptor",    # description (ID 1534)
       +5 : 1179,                  # type (ID 1538), identity:    
                                   # ethernetCsmacd (ID 1179)
       +2 : true                   # enabled (ID 1535)
     }
]
]]></artwork>
</figure>

</section> <!-- Full Data Store examples -->

</section> <!-- Full Data Store access -->


<section anchor="Notify" title="Notify functions">
<t>
Notification by the server to a selection of clients when an event occurs in the server is an essential function for the management of servers. CoMI allows events specified in YANG <xref target="RFC5277"/> to be notified to a selection of requesting clients. The server appends  newly generated events to a stream. There is one, so-called "default", stream in a CoMI server. The /c/s resource identifies the default stream. The server MAY create additional stream resources. When a CoMI server generates an internal event, it is appended to the chosen stream, and the content of a notification instance is ready to be sent to all CoMI clients which observe the chosen stream resource.
</t><t>
Reception of generated notification instances is enabled with the CoAP Observe <xref target="RFC7641"/> function.
 The client subscribes to the notifications by sending a GET request with an "Observe" option, specifying the /c/s resource when the default stream is selected.
</t><t>
Every time an event is generated, the chosen stream is cleared, and the generated notification instance is appended to the chosen stream(s). After appending the instance, the contents of the instance is sent to all clients observing the modified stream. 
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
  Get /<stream-resource> 
      Content-Format(application/YANG-patch+cbor) Observe(0)

2.05 Content Content-Format(application/YANG-patch+cbor)
<set of data node instances>

]]></artwork>
    </figure>
<t>
TODO: addition of generic information
</t>

<section anchor="NotifyEX" title="Notify Examples">
<t>
Suppose the server generates the event specified in <xref target="notify-ex"/>. By executing a GET on the /c/s resource the client receives the following response:
</t>

 <figure>
    <artwork align="left"><![CDATA[

GET /c/s Observe(0) Token(0x93)

2.05 Content Content-Format(application/YANG-patch+cbor)
                        Observe(12) Token(0x93)
{
   2600 :                    # example-port-fault (ID 2600)
    {
      +1 : "0/4/21",       # port-name (ID 2601)
      +2 : "Open pin 2",   # port-fault (ID 2602)
    },
   2600 :                    # example-port-fault (ID 2600)
    {
      +1 : "1/4/21",       # port-name (ID 2601)
      +2 : "Open pin 5",   # port-fault (ID 2602)
    } 

}]]></artwork>
    </figure>

<t>
In the example, the request returns a success response with the contents of the last two generated events. Consecutively the server will regularly notify the client when a new event is generated. 
</t><t>
To check that the client is still alive,
the server MUST send confirmable notifications once in a while. When the client does
not confirm the notification from the server, the server will remove
the client from the list of observers <xref target="RFC7641"/>.
</t><t>
  In the registration request,
  the client MAY include a "Response-To-Uri-Host" and optionally "Response-To-Uri-Port" option as defined in
  <xref target="I-D.becker-core-coap-sms-gprs"/>.
  In this case,
  the observations SHOULD be sent to the address and port indicated in these options.
  This can be useful when the client wants the managed device to send the trap information to a multicast address.
</t>
</section>  <!-- Notify example -->

</section>  <!-- Notify -->

<section anchor="RPC" title="RPC statements">
<t>
   The YANG "action" and "RPC" statements specify the execution of a Remote procedure Call (RPC) in the server.  It is invoked using a POST method to the "Action" or "RPC" identifier. The Request payload contains the values assigned to the input container when specified with the action station. The Response payload contains the values of the output container when specified with the action statement.
</t><t>
The returned success response code is 2.05 Content.
</t>
<figure>
    <artwork align="left"><![CDATA[
FORMAT:
 POST /c/<instance identifier> 
           Content-Format(application/YANG-patch+cbor)
<input node value>

2.05 Content Content-Format (application/YANG-patch+cbor)
<output node value> 

]]></artwork>
    </figure>
<t>
There "k" query parameter is allowed for the POST method when used for RPC invocation.
</t>


<section title="RPC Example" anchor="RPCEX">
<t>
The example is based on the YANG action specification of <xref target="server"/>. A server list is specified and the action "reset", that is part of a "server instance" with key value "myserver", is invoked.
</t>
<figure>
    <artwork align="left"><![CDATA[
POST /c/B24?k="myserver" 
              Content-Format(application/YANG-patch+cbor)
{
  +1 : "2016-02-08T14:10:08Z09:00"  # reset-at (ID 1903)
}

2.05 Content Content-Format(application/YANG-patch+cbor)
{
  +2 : "2016-02-08T14:10:08Z09:18"  # reset-finished-at (ID 1904)
}
]]></artwork>
    </figure>

</section> <!-- RPC example  -->

</section> <!-- RPC statement  -->

</section>  <!-- /c Function Set -->

<section anchor="MIB" title="Access to MIB Data">
<t>
<xref target="SMI"/> shows a YANG specification mapped from the SMI specification "ipNetToPhysicalTable".
The following example shows the YANG "ipNetToPhysicalTable" with 2 instances, using diagnostic notation encoding and annotating the leaf names with SID numbers.
</t>
<figure><artwork align="left">
<![CDATA[
{ 
  "IP-MIB/ipNetToPhysicalTable/ipNetToPhysicalEntry" :  # ID 302
  [
   {
     "ipNetToPhysicalIfIndex" : 1,                       # ID 303      
     "ipNetToPhysicalNetAddressType" : "ipv4",           # ID 304
     "ipNetToPhysicalNetAddress" : "10.0.0.51",          # ID 305
     "ipNetToPhysicalPhysAddress" : "00:00:10:01:23:45", # ID 306
     "ipNetToPhysicalLastUpdated" : "2333943",           # ID 307
     "ipNetToPhysicalType" : "static",                   # ID 308
     "ipNetToPhysicalState" : "reachable",               # ID 309
     "ipNetToPhysicalRowStatus" : "active"               # ID 310
    },
    {
      "ipNetToPhysicalIfIndex" : 1,                      # ID 303
      "ipNetToPhysicalNetAddressType" : "ipv4",          # ID 304
      "ipNetToPhysicalNetAddress" : "9.2.3.4",           # ID 305
      "ipNetToPhysicalPhysAddress" : "00:00:10:54:32:10",# ID 306
      "ipNetToPhysicalLastUpdated" : "2329836",          # ID 307
      "ipNetToPhysicalType" : "dynamic",                 # ID 308
      "ipNetToPhysicalState" : "unknown",                # ID 309
      "ipNetToPhysicalRowStatus" : "active"              # ID 310
     }
   ]
}
]]></artwork></figure> 
<t>       
In the following example exactly one instance is requested from
the ipNetToPhysicalEntry. The CBOR payload, here represented with diagnostic JSON, permits to transport the selected instance and nothing more.
</t>

 <figure>
    <artwork align="left"><![CDATA[
REQ: FETCH example.com/c/
(Content-Format: application/YANG-fetch+cbor)
[
302,1,"ipv4",9.2.3.4
]

RES: 2.05 Content (Content-Format: application/YANG-patch+cbor)
{
   +1 : 1,                     ( ID 303)
   +2 : "ipv4",                ( ID 304)
   +3 : "9.2.3.4",             ( ID 305)
   +4 : "00:00:10:54:32:10",   ( ID 306)
   +5 : "2329836",             ( ID 307)
   +6 : "dynamic",             ( ID 308)
   +7 : "unknown",             ( ID 309)
   +8 : "active"               ( ID 310)
}
]]></artwork>
    </figure>

   <t>
     In this example one instance of ipNetToPhysicalTable/ipNetToPhysicalEntry that matches the key values (1,"ipv4",9.2.3.4) is returned.
   </t>

</section>  <!-- Access to MIB data -->

<section anchor="block" title="Use of Block">
<t>
The CoAP protocol provides reliability by acknowledging the UDP datagrams. However, when large pieces of text need to be transported the datagrams get fragmented, thus creating constraints on the resources in the client, server and intermediate routers. The block option <xref target="RFC7959"/> allows the transport of the total payload in individual blocks of which the size can be adapted to the underlying fragment sizes such as: (UDP datagram size ~64KiB, IPv6 MTU of 1280, IEEE 802.15.4 payload of 60-80 bytes). Each block is individually acknowledged to guarantee reliability.
</t><t>
Notice that the Block mechanism splits the data at fixed positions,
such that individual data fields may become fragmented.
Therefore,  assembly of multiple blocks may be required to process the complete data field.
</t><t>
Beware of race conditions. Blocks are filled one at a time and care should be taken that the whole data representation is sent in multiple blocks sequentially without interruption. In the server, values are changed, lists are re-ordered, extended or reduced. When these actions happen during the serialization of the contents of the variables, the transported results do not correspond with a state having occurred in the server; or worse the returned values are inconsistent. For example: array length does not correspond with actual number of items. It may be advisable to use CBOR maps or CBOR arrays of undefined length which are foreseen for data streaming purposes.
</t>
</section>


<section anchor="discovery" title="Resource Discovery">
<t>
The presence and location of (path to) the management data are discovered by sending a GET request to "/.well-known/core" including a resource type (RT) parameter with the value "core.c" <xref target="RFC6690"/>. Upon success, the return payload will contain the root resource of the management data. It is up to the implementation to choose its root resource, but it is recommended that the value "/c" is used, where possible. The example below shows the discovery of the presence and location of management data.
</t>
<figure><artwork align="left"><![CDATA[

  REQ: GET /.well-known/core?rt=core.c

  RES: 2.05 Content </c>; rt="core.c"
  
]]></artwork>
    </figure>

<t>
Management objects MAY be discovered with the standard CoAP resource discovery. The implementation can add the encoded values of the object identifiers to /.well-known/core with rt="core.c.data". The available objects identified by the encoded values can be discovered by sending a GET request to "/.well-known/core" including a resource type (RT) parameter with the value "core.c.data". Upon success, the return payload will contain the registered encoded values and their location. 
The example below shows the discovery of the presence and location of management data.
</t>
<figure><artwork align="left"><![CDATA[

  REQ: GET /.well-known/core?rt=core.c.data

  RES: 2.05 Content </c/BaAiN>; rt="core.c.data",
  </c/CF_fA>; rt="core.c.data"

]]></artwork>
    </figure>

<t>
Lists of encoded values may become prohibitively long. It is discouraged to provide long lists of objects on discovery. Therefore, it is recommended that details about management objects are discovered by reading the YANG module information stored in the "ietf-YANG-library" module <xref target="I-D.ietf-netconf-restconf"/>.
The resource "/c/mod.uri" is used to retrieve the location of the YANG module library.
</t><t>
TODO: additional references using SIDs
</t>
<t>
The module list can be stored locally on each server, or remotely on a different server. The latter is advised when the deployment of many servers are identical.
</t>

<figure><artwork align="left"><![CDATA[

  Local in example.com server:

  REQ: GET example.com/c/mod.uri

  RES: 2.05 Content (Content-Format: application/cbor)
  {
    "mod.uri" : "example.com/c/modules"
  }


  Remote in example-remote-server:

  REQ: GET example.com/c/mod.uri

  RES: 2.05 Content (Content-Format: application/cbor)
  {
    "moduri" : "example-remote-server.com/c/group17/modules"
  }

]]></artwork>
    </figure>

<t>
Within the YANG module library all information about the module is stored such as: module identifier, identifier hierarchy, grouping, features and revision numbers.
</t>

</section>


<section anchor="error" title="Error Return Codes">
<t>
The RESTCONF return status codes defined in section 7 of <xref target="I-D.ietf-netconf-restconf"/> are used
in CoMI error responses, except they are converted to CoAP error codes.
</t>


<texttable>
  <ttcol align="left">RESTCONF Status Line</ttcol>
  <ttcol align="left">CoAP Status Code</ttcol>
  <c> 100 Continue </c>   <c> none? </c>
  <c> 200 OK </c>   <c> 2.05 </c>
  <c> 201 Created </c>   <c> 2.01 </c>
  <c> 202 Accepted </c>   <c> none? </c>
  <c> 204 No Content </c>   <c> 2.04 Changed</c>
  <c> 304 Not Modified </c>   <c> 2.03 </c>
  <c> 400 Bad Request </c>   <c> 4.00 </c>
  <c> 403 Forbidden </c>   <c> 4.03 </c>
  <c> 404 Not Found </c>   <c> 4.04 </c>
  <c> 405 Method Not Allowed </c>   <c> 4.05 </c>
  <c> 409 Conflict </c>   <c> none? </c>
  <c> 412 Precondition Failed </c>   <c> 4.12 </c>
  <c> 413 Request Entity Too Large </c>   <c> 4.13 </c>
  <c> 414 Request-URI Too Large </c>   <c> 4.00 </c>
  <c> 415 Unsupported Media Type </c>   <c> 4.15 </c>
  <c> 500 Internal Server Error </c>   <c> 5.00 </c>
  <c> 501 Not Implemented </c>   <c> 5.01 </c>
  <c> 503 Service Unavailable </c>   <c> 5.03 </c>
</texttable>
</section> <!-- error return codes -->

<section anchor="ERRORS" title="Error Handling">
  <t>
    In case a request is received which cannot be processed properly,
    the CoMI server MUST return an error message.
    This error message MUST contain a CoAP 4.xx or 5.xx response code,
    and SHOULD include additional information in the payload.
  </t>
  <t>
    Such an error message payload is encoded in CBOR,
    using the following structure:
  </t>

<figure><artwork align="left">
<![CDATA[
errorMsg     : ErrorMsg;

*ErrorMsg {
  errorCode  : uint;
  ?errorText : tstr;
}
]]></artwork></figure>
  <t>
    The variable "errorCode" has one of the values from the table below,
    and the OPTIONAL "errorText" field contains a human readable explanation of the error.
</t><t>
TODO: Alternatives?
  </t>
  
    <texttable>
      <ttcol align="left">CoMI Error Code</ttcol>
      <ttcol align="left">CoAP Error Code</ttcol>
      <ttcol align="left">Description</ttcol>
      
      <c>0</c>
      <c>4.00</c>
      <c>General error</c>

      <c>1</c>
      <c>4.00</c>
      <c>Malformed CBOR data</c>
      
      <c>2</c>
      <c>4.00</c>
      <c>Incorrect CBOR datatype</c>
      
      <c>3</c>
      <c>4.00</c>
      <c>Unknown MIB variable</c>
      
      <c>4</c>
      <c>4.00</c>
      <c>Unknown conversion table</c>

      <c>5</c>
      <c>4.05</c>
      <c>Attempt to write read-only variable</c>

  	<c>0..2</c>
      <c>5.01</c>
      <c>Access exceptions</c>

	<c>0..18</c>
	<c>5.00</c>
	<c> SMI error status </c>
    </texttable>

<t>
The CoAP error code 5.01 is associated with the exceptions defined in <xref target="RFC3416"/> and CoAP error code 5.00 is associated with the error-status defined in <xref target="RFC3416"/>.
</t>
  
</section>

<section title="Security Considerations">
  <t>
    For secure network management,
    it is important to restrict access to configuration variables only to authorized parties.
    This requires integrity protection of both requests and responses,
    and depending on the application encryption.
  </t>
  <t>
    CoMI re-uses the security mechanisms already available to CoAP as much as possible.
    This includes DTLS <xref target="RFC6347"/> for protected access to resources,
    as well suitable authentication and authorization mechanisms.
  </t>
  <t>
    Among the security decisions that need to be made are
    selecting security modes and encryption mechanisms (see <xref target="RFC7252"/>).
    This requires a trade-off,
    as the NoKey mode gives no protection at all,
    but is easy to implement,
    whereas the X.509 mode is quite secure, 
    but may be too complex for constrained devices.
  </t>
  <t>
    In addition,
    mechanisms for authentication and authorization may need to be selected.
  </t>
  <t>
    CoMI avoids defining new security mechanisms as much as possible.
    However some adaptations may still be required,
    to cater for CoMI's specific requirements.
  </t>
</section>

<section  title="IANA Considerations">  
  <t>
    'rt="core.c"' needs registration with IANA.
  </t>
  <t>
    'rt="core.c.data"' needs registration with IANA.
  </t>

  <t>
    'rt="core.c.moduri"' needs registration with IANA.
  </t>
  <t>
    'rt="core.c.stream"' needs registration with IANA.
  </t>
  <t>
    Content types to be registered:
    <list style="symbols">
      <t>application/YANG-patch+cbor</t>
      <t>application/YANG-fetch+cbor</t>
    </list>
  </t>
</section>

<section title="Acknowledgements">
<t>
We are very grateful to Bert Greevenbosch who was one of the original authors of the CoMI specification and specified CBOR encoding and use of hashes.
</t><t>
Mehmet Ersue and Bert Wijnen explained the encoding aspects of PDUs transported under SNMP. Carsten Bormann has given feedback on the use of CBOR.
</t><t>
Timothy Carey has provided the text for <xref target="LWM2M"/>.
</t><t>
The draft has benefited from comments (alphabetical order) by Rodney Cummings, Dee Denteneer, Esko Dijk, Michael van Hartskamp, Juergen Schoenwaelder, Anuj Sehgal, Zach Shelby, Hannes Tschofenig, Michael Verschoor, and Thomas Watteyne.
</t>
</section>

<section title="Changelog">
<t>
Changes from version 00 to version 01
<list style="symbols">
<t> Focus on MIB only</t>
<t> Introduced CBOR, JSON, removed BER </t>
<t> defined mappings from SMI to xx </t>
<t> Introduced the concept of addressable table rows </t>
</list>
</t>
<t>
Changes from version 01 to version 02
<list style="symbols">
<t> Focus on CBOR, used JSON for examples, removed XML and EXI</t>
<t> added uri-query attributes mod and con to specify modules and contexts </t>
<t> Definition of CBOR string conversion tables for data reduction </t>
<t> use of Block for multiple fragments </t>
<t> Error returns generalized </t>
<t> SMI - YANG - CBOR conversion </t>
</list>
</t>
<t>
Changes from version 02 to version 03
<list style="symbols">
<t> Added security considerations</t>
</list>
</t>
<t>
Changes from version 03 to version 04
<list style="symbols">
<t> Added design considerations section</t>
<t> Extended comparison of management protocols in introduction </t>
<t> Added automatic generation of CBOR tables </t>
<t> Moved lowpan table to Appendix </t>
</list>
Changes from version 04 to version 05
<list style="symbols">
<t> Merged SNMP access with RESTCONF access to management objects in small devices </t>
<t> Added CoMI architecture section</t>
<t> Added RESTCONf NETMOD description </t>
<t> Rewrote section 5 with YANG examples </t>
<t> Added server and payload size appendix</t>
<t> Removed Appendix C for now. It will be replaced with a YANG example. </t>
</list>
Changes from version 04 to version 05
<list style="symbols">
<t> Extended examples with hash representation </t>
<t> Added keys query parameter text</t>
<t> Added select query parameter text </t>
<t> Better separation between specification and instance </t>
<t> Section on discovery updated</t>
<t> Text on rehashing introduced </t>
<t> Elaborated SMI MIB example </t>
<t> YANG library use described </t>
<t> use of BigEndian/LittleEndian in Hash generation specified </t>
</list>
Changes from version 05 to version 06
<list style="symbols">
<t> Hash values in payload as hexadecimal and in URL in base64 numbers </t>
<t> Streamlined CoMI architecture text</t>
<t> Added select query parameter text </t>
<t> Data editing optional </t>
<t> Text on Notify added</t>
<t> Text on rehashing improved with example </t>
</list>
Changes from version 06 to version 07
<list style="symbols">
<t> reduced payload size by removing JSON hierarchy </t>
<t> changed rehash handling to support small clients </t>
<t> added LWM2M comparison </t>
<t> Notification handling as specified in YANG </t>
<t> Added Patch function </t>
<t> Rehashing completely reviewed </t>
<t> Discover type of YANG name encoding </t>
<t> Added new resource types </t>
<t> Read-only servers introduced </t>
<t> Multiple updates explained </t>
</list>
Changes from version 07 to version 08
<list style="symbols">
<t> Changed YANG Hash algorithm to use module name instead of prefix </t>
<t> Added rehash bit to allow return values to identify rehashed nodes
in the response </t>
<t> Removed /c/mod.set resource since this is not needed </t>
<t> Clarified that YANG Hash is done even for unimplemented objects </t>
<t> YANG lists transported as CBOR maps of maps </t>
<t> Adapted examples with more CBOR explanation </t>
<t> Added CBOR code examples in new appendix </t>
<t> Possibility to use other than default stream </t>
<t> Added text and examples for Patch payload </t>
<t> Repaired some examples </t>
<t> Added appendices on hash clash probability and hash clash storage overhead </t>
</list>
Changes from version 08 to version 09
<list style="symbols">
<t> Removed hash and YANG to CBOR sections </t>
<t> removed hashes from examples. </t>
<t> Added RPC </t>
<t> Added content query parameter. </t>
<t> Added default handling. </t>
<t> Listed differences with RESTCONF </t>
</list>
Changes from version 09 to version 10.
This is the merge of cool-01 with comi-09.
<list style="symbols">
<t> Merged with CoOL SIDs </t>
<t> Introduced iPATCH, PATCH and FETCH </t>
<t> Update of LWM2M comparison </t>
<t> Added appendix with module examples </t>
<t> Removed introductory text </t>
<t> Removed refernces </t>
</list>


</t>

</section>

</middle>
  <back>
    <references title="Normative References">
      &RFC2119;
	&RFC5277;
      &RFC6020;
      &RFC7049;
      &RFC7159;
      &RFC7252;
      &RFC7950;
      &I-D.becker-core-coap-sms-gprs;
      &RFC7959;
      &RFC7641;
      &I-D.ietf-netconf-restconf;
	 &I-D.vanderstok-core-etch;
	 &I-D.somaraju-core-sid;
      &I-D.ietf-core-yang-cbor;


    </references>
    <references title="Informative References">
      &RFC2578;
      &RFC3410;
      &RFC3416;
      &RFC3418;
      &RFC4293;
      &RFC6241;
      &RFC6243;
      &RFC6347;
      &RFC6643;
      &RFC6690;                       
      &I-D.ietf-core-interfaces;

       
  <reference anchor="XML">
        <front>
          <title>Extensible Markup Language (XML)</title>
        <author />
        <date />
          </front>
          <seriesInfo name="Web" value="http://www.w3.org/xml"/>
        </reference>

  <reference anchor="OMA">
        <front>
          <title>OMA-TS-LightweightM2M-V1_0-20131210-C</title>
	  <author fullname="Open Mobile Alliance (OMA)"/>
        <date />
          </front>
          <seriesInfo name="Web" value="http://technical.openmobilealliance.org/Technical/current_releases.aspx"/>
        </reference>

<reference anchor="OMNA">
        <front>
          <title>Open Mobile Naming Authority (OMNA)</title>
	  <author fullname="Open Mobile Alliance (OMA)"/>
        <date />
          </front>
          <seriesInfo name="Web" value="http://http://technical.openmobilealliance.org/Technical/technical-information/omna"/>
        </reference>

<reference anchor="netconfcentral">
        <front>
          <title>NETCONF Central: library of YANG modules
</title>
        <author fullname="YUMAworks"/>
        <date />
          </front>
          <seriesInfo name="Web" value="http://www.netconfcentral.org/modulelist"
/>
        </reference>

<reference anchor="mibreg">
        <front>
          <title>Structure of Management Information (SMI) Numbers (MIB Module Registrations)
</title>
        <author fullname="IANA"/>
        <date />
          </front>
          <seriesInfo name="Web" value="http://www.iana.org/assignments/smi-numbers/smi-numbers.xhtml/" />
        </reference>

<reference anchor="yang-cbor">
        <front>
          <title>yang-cbor Registry
</title>
        <author fullname="Michel Veillette"/>
        <date />
          </front>
          <seriesInfo name="Web" value="https://github.com/core-wg/yang-cbor/tree/master/registry/" />
        </reference>


    </references>

<section title="YANG example specifications" anchor="EXSPEC">
<t>
This appendix shows 5 YANG example specifications taken over from as many existing YANG modules. The YANG modules are available from <xref target="netconfcentral"/>. Each YANG item identifier is accompanied by its SID shown after the "#" character, taken from <xref target="yang-cbor"/>.
</t>

<section title ="ietf-system" anchor="ietf-system">
<t>
Taken over from the module ietf-system.
</t>

<figure><artwork align="left"><![CDATA[
module ietf-system {
  container system-state{          # ID 1716
       container clock  {          # ID 1717
           leaf current-datetime{  # ID 1719    
               type YANG:date-and-time
           }
           leaf boot-datetime{     # ID 1718
               type YANG:date-and-time
           }
   ...
   container system {     
       leaf timezone-name 
       leaf timezone-utc-offset{   # ID 1736  
           type int16
       }
    ...
    container ntp {       # ID 1750
      leaf enabled {     # ID 1751
         type boolean;
      }
      list server {     # ID 1752
        key name;
        leaf name {     # ID 1755
          type string;
        }
        choice transport {
          case udp {
            container udp {     # ID 1757
              leaf address {     # ID 1758
                type inet:host;
              }
              leaf port {     # ID 1759
                type inet:port-number;
              }
            }
          }
        }
        leaf association-type {     # ID 1753
          type enumeration {
            enum server {}
            enum peer {}
            enum pool {}
          }
        }
        leaf iburst {     # ID 1754
          type boolean;
        }
        leaf prefer {     # ID 1756
          type boolean;
        }
      }
    }
  ...
  }
}
]]></artwork>
    </figure>

</section> <!--ietf-system -->

<section title="server list" anchor="server">
<t>
Taken over from module 
</t>
<figure><artwork align="left"><![CDATA[
  list server  # ID = 1901
   {
     key name;
     leaf name {
       type string;
     }
     action reset {     # ID = 1902
       input {
         leaf reset-at {     # ID = 1903
           type YANG:date-and-time;
           mandatory true;
         }
       }
      output {
         leaf reset-finished-at {     # ID = 1904
          type YANG:date-and-time;
          mandatory true;
        }
      }
    }
  }
]]></artwork>
    </figure>

</section> <!-- server -->

<section title="interfaces" anchor="interfaces">
<t>
Taken over from module ietf-interfaces.
</t>
<figure><artwork align="left"><![CDATA[
container interfaces {
       list interface { # ID = 1533
         key "name";
        leaf name {  # ID = 1537
           type string;
         }
         leaf description { # ID = 1534
           type string;
         }

         leaf type {  # ID = 1538
           type identityref {
             base interface-type;
           }
           mandatory true;
         }
         leaf enabled {  # ID = 1535
           type boolean;
           default "true";
         }

         leaf link-up-down-trap-enable {
           if-feature if-mib;
           type enumeration {
             enum enabled {
               value 1;
             }
             enum disabled {
               value 2;
             }
           }
   } } } }
]]></artwork>
    </figure>

</section> <!-- interfaces -->

<section anchor="notify-ex" title="Example-port">
<t>
Taken over from module example-port.
</t>
<figure><artwork align="left"><![CDATA[
   module example-port {
     ...
     prefix ep;
     ...
     notification example-port-fault {  # ID 2600
       description
         "Event generated if a hardware fault on a
          line card port is detected";
       leaf port-name {  # ID 2601
         type string;
         description "Port name";
       }
       leaf port-fault {  # ID 2601
         type string;
         description "Error condition detected";
       }
     }
   }
]]></artwork>
    </figure>


</section> <!-- example-port -->

<section title="ipNetToMediaTable" anchor="SMI">
<t>
The YANG translation of the SMI specifying the ipNetToMediaTable <xref target="RFC4293"/>, extended with example SID numbers, yields:
</t>
<figure><artwork align="left">
<![CDATA[
container IP-MIB {
  container ipNetToPhysicalTable {  # ID 301
    list ipNetToPhysicalEntry {     # ID 302
       key "ipNetToPhysicalIfIndex
            ipNetToPhysicalNetAddressType
            ipNetToPhysicalNetAddress";
       leaf ipNetToMediaIfIndex {   # ID 303
          type: int32;
       }
       leaf ipNetToPhysicalIfIndex {  # ID 304
         type if-mib:InterfaceIndex;
       }
       leaf ipNetToPhysicalNetAddressType { # ID 305
         type inet-address:InetAddressType;
       }
       leaf ipNetToPhysicalPhysAddress {  # ID 306
         type YANG:phys-address {
            length "0..65535";
         }
       }
       leaf ipNetToPhysicalLastUpdated {  # ID 307
         type YANG:timestamp;
       }
       leaf ipNetToPhysicalType {         # ID 308
         type enumeration { ... }
       }
       leaf ipNetToPhysicalState {        # ID 309
         type enumeration { ... }
       }
       leaf ipNetToPhysicalRowStatus {    # ID 310
         type snmpv2-tc:RowStatus;
       }
    }
 }
]]></artwork></figure>

</section> <!-- ipNetToMediaTable -->

</section> <!-- YANG example specifications -->


<section anchor="LWM2M" title="Comparison with LWM2M">
<section title="Introduction">
<t>
CoMI and LWM2M <xref target="OMA"/>, both, provide RESTful device management services over CoAP. Differences between the designs are highlighted in this section.
</t><t>
The intent of the LWM2M protocol is to provide a single protocol to control and manage IoT devices. This means the IoT device implements and uses the same LWM2M agent function for the actuation and sensing features of the IoT device as well as for the management of the IoT device. The intent of CoMI Interface as described in the Abstract section of this document is to provide management of constrained devices and devices in constrained networks using RESTCONF and YANG. This implies that the device, although reusing the CoAP protocol, would need a separate CoAP based agent in the future to control the actuation and sensing features of the device and another CoMI agent that performs the management functions.
</t><t>
It should be noted that the mapping of a LWM2M server to YANG is specified in [YANGlwm2m]. The converted server can be invoked with CoMI as specified in this document.
</t><t>
For the purposes of managing IoT devices the following points related to the protocols compare how management resources are defined, identified, encoded and updated.
</t>

</section> <!-- Introduction -->

<section title="Defining Management Resources">
<t>
Management resources in LWM2M (LWM2M objects) are defined using a standardized number. When a new management resource is defined, either by a standards organization or a private enterprise, the management resource is registered with the Open Mobile Naming Authority <xref target="OMNA"/> in order to ensure different resource definitions do not use the same identifier. CoMI, by virtue of using YANG as its data modeling language, allows enterprises and standards organizations to define new management resources (YANG nodes) within YANG modules without having to register each individual management resource. Instead YANG modules are scoped within a registered name space. As such, the CoMI approach provides additional flexibility in defining management resources. Likewise, since CoMI utilizes YANG, existing YANG modules can be reused. The flexibility and reuse capabilities afforded to CoMI can be useful in management of devices like routers and switches in constrained networks. However for management of IoT devices, the usefulness of this flexibility and applicability of reuse of existing YANG modules may not be warranted. The reason is that IoT devices typically do not require complex sets of configuration or monitoring operations required by devices like a router or a switch. To date, OMA has defined approximately 15 management resources for constrained and non-constrained mobile or fixed IoT devices while other 3rd Party SDOs have defined another 10 management resources for their use in non-constrained IoT devices. Likewise, the Constrained Object Language <xref target="I-D.somaraju-core-sid"/> which is used by CoMI when managing constrained IoT devices uses YANG schema item identifiers, which are registered with IANA, in order to define management resources that are encoded using CBOR when targeting constrained IoT Devices.
</t>

</section> <!-- Defining management resources-->

<section title="Identifying Management Resources">
<t>
As LWM2M and CoMI can similarly be used to manage IoT devices, comparison of the CoAP URIs used to identify resources is relevant as the size of the resource URI becomes applicable for IoT devices in constrained networks. LWM2M uses a flat identifier structure to identify management resources and are identified using the LWM2M object's identifier, instance identifier and optionally resource identifier (for access to and object's attributes). For example, identifier of a device object (object id = 3) would be "/3/0" and identification of the device object's manufacturer attribute would be "/3/0/0". Effectively LWM2M identifiers for management resources are between 4 and 10 bytes in length.
</t><t>
CoMI is expected to be used to manage constrained IoT devices. CoMI utilizes the YANG schema item identifier[SID] that identify the resources. CoMI recommends that IoT device expose resources to identify the data stores and event streams of the CoMI agent. Individual resources (e.g., device object) are not directly identified but are encoded within the payload. As such the identifier of the CoMI resource is smaller (4 to 7 bytes) but the overall payload size isn't smaller as resource identifiers are encoded on the payload.
</t>

</section> <!-- Identifying Management Resources -->

<section title="Encoding of Management Resources">
<t>
LWM2M provides a separation of the definition of the management resources from how the payloads are encoded. As of the writing of this document LWM2M encodes LWM2M encodes payload data in Type-length-value (TLV), JSON or plain text formats. JSON encoding is the most common encoding scheme with TLV encoding used on the simplest IoT devices. CoMI's use of CBOR provides a more efficient transfer mechanism <xref target="RFC7049"/> than the current LWM2M encoding formats.
</t><t>
In situations where resources need to be modified, CoMI uses the CoAP PATCH operation resources only require a partial update. LWM2M does not currently use the CoAP PATCH operation but instead uses the CoAP PUT and POST operations which are less efficient.
</t>

</section> <!-- Encoding of Management Resources  -->

  
</section> <!-- Comparison with LWM2M -->


</back>

</rfc>
