<?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 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 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 RFC7223 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7223.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 RFC7317 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7317.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.ietf-netconf-restconf SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-netconf-restconf.xml">
<!ENTITY I-D.ietf-core-etch SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-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.ietf-core-sid SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-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">
<!ENTITY I-D.bormann-appsawg-cbor-merge-patch SYSTEM
"http://xml.resource.org/public/rfc/bibxml3/reference.I-D.bormann-appsawg-cbor-merge-patch.xml">
<!ENTITY I-D.veillette-core-cool SYSTEM
"http://xml.resource.org/public/rfc/bibxml3/reference.I-D.veillette-core-cool.xml">
<!ENTITY I-D.veillette-core-cool-library SYSTEM
"http://xml.resource.org/public/rfc/bibxml3/reference.I-D.veillette-core-cool-library.xml">
]>

<?rfc toc="yes"?>
<?rfc symrefs="yes" ?>

<rfc category="std" ipr="trust200902" docName="draft-vanderstok-core-comi-11">
  <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="RFC7950"/>. 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="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 numeric identifiers  <xref target="I-D.ietf-core-sid"/> 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="RFC7950"/>: anydata, anyxml, 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"/>) (anydata, anyxml, 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><t>
TODO: Reduce to one, if possible
</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 the content of a datastore used for the management of the instrumented node.
</t>
<figure anchor="archit" title="Abstract CoMI architecture"><artwork align="left"><![CDATA[

+--------------------------------------------------------------+
|                    SMIv2  specification (2)                  |
+--------------------------------------------------------------+
                              \/
+--------------------------------------------------------------+
|                    YANG  specification  (1)                  |
+---------*-----------------------------------------*----------+
          | compilation                             | compilation
          |              security (7)               |
client   \|/      [===========================]    \|/    Server
+--------------------+                       +------------------+
|                    |                       |                  |
| Request generation +--> CoAP request(3) -->| Request retrieval|
| answer retrieval   |<-- CoAP response(3)<--| answer generation|
|       (4)          |                       |       (4)        |
+--------------------+                       | +---------------+|
                                             | | datastore (5) ||
                                             | +---------------+|
                                             |                  |
                                             |      Variable    |
                                             |Instrumentation(6)|
                                             +------------------+

]]></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) CoMI messages:"> The CoMI client sends request messages to and receives response messages from the CoMI server.
</t> 
<t hangText="(4) Retrieval, generation:"> The server and client  parse the CoMI request/response and identify the corresponding instances in the datastore based on YANG specification.
</t>
<t hangText="(5) Datastore:"> The store is composed of two parts: Operational state and Configuration datastore. Datastore also supports RPCs and event streams. 
</t>
<t hangText="(6) Variable instrumentation:"> This code depends on implementation of drivers and other node specific aspects. 
</t>
<t hangText="(7) Security:"> The server MUST prevent unauthorized users from reading or writing any data resources. CoMI relies on security protocols such as DTLS <xref target="RFC6347"/> to secure CoAP communication.
</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>
CoMI servers cannot change 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 YANG identifiers">
<t>
In the YANG specification items are identified with a name string. 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.ietf-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 to encode CoMI request- and response- payloads. 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 (item identifier, item value) pair is mapped to a CBOR (key, value) pair. The YANG item value is encoded as specified in <xref target="I-D.ietf-core-yang-cbor"/>. The YANG item identifier can be a SID (single node identifier) or a CBOR array with the structure [SID, key1, key2] (list node identifier), where SID is a list identifier and the key values specify the list instance. The YANG item value can be any CBOR major type.
</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. 
</t><t>
TODO: what will happen to term Function Set ?
</t><t>
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 data node of the YANG modules loaded in the CoMI server
represents a resource of the datastore container (e.g. /c/&lt;sid&gt;
</t><t>
When multiple instances of a list node exist, instance selection is possible as described in <xref target="FETCH"/> and <xref target="GetExamples"/>.
</t><t>
TODO; reference to fetch and patch content formats.
</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 resource(s) </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 create, replace, and delete data resource(s) (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 leaves 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> 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 (binary value) </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.ietf-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 retrieving a
    subset of the datastore.
  </t>
<t>
There are two 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> Control selection of configuration and non-configuration data 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 a data node instance is sent with a confirmable CoAP GET message. A single instance identifier 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 returned payload is composed of all the children associated with the specified data node instance.
</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: X9) 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/X9

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 (ID 1537) /
  +1 : "Ethernet adaptor",    / description (ID 1534) /
  +5 : 1179,                  / type, (ID 1538) 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 leaves 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: X-). The value of the description leaf is returned.
</t>
<figure><artwork align="left">
<![CDATA[
REQ: GET example.com/c/X-?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[

REQ:  FETCH /c Content-Format (application/YANG-fetch+cbor)
      [ 1719,            / ID 1719 /
      [-186, "eth0"]   / ID 1533 with name = "eth0" /
      ]

RES:  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 (ID 1179) /
   +2 : true                   / enabled (ID 1535) /
  }
]
]]></artwork>
</figure>
<t>
TODO: align with future FETCH content format.
</t>

</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 resources 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[
REQ: POST /c/X9 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) /
      }

RES: 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 a data node instance 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[

REQ:  PUT /c/X9?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) /
      }
RES:  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.ietf-core-etch"/>.
A request 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 <xref target="I-D.bormann-appsawg-cbor-merge-patch"/>. 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[
REQ: 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 (ID 1179) /
      +2 : true                   / enabled (ID 1535) /
    },
  +203 , 60          / timezone-utc-offset (delta = 1736-1533) /
]

RES: 2.04 Changed
]]></artwork>
    </figure>
<t>
TODO: Align with future cbor-merge-patch content format.
</t>

</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[
REQ:   DELETE /c/X9?k="eth0"
      
RES:   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
   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[

RQ:  GET /c 
RES: 2.05 Content Content-Format (application/YANG-patch+cbor)
[ 
  {1717: 
     { +2: "2016-10-26T12:16:31Z", / current-datetime (ID 1719) /
       +1: "2014-10-05T09:00:00Z"  / boot-datetime (ID 1718) /
     },
  -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>


<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[

REQ:  GET /c/s Observe(0) Token(0x93)

RES:  2.05 Content Content-Format(application/YANG-patch+cbor)
                        Observe(12) Token(0x93)
{
   60010 :                  / example-port-fault (ID 60010) /
    {
      +1 : "0/4/21",       / port-name (ID 60011) /
      +2 : "Open pin 2"    / port-fault (ID 60012) /
    },
   60010 :                  / example-port-fault (ID 60010) /
    {
      +1 : "1/4/21",       / port-name (ID 60011) /
      +2 : "Open pin 5"    / port-fault (ID 60012) /
    } 
}

]]></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>
</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 an "Action" or "RPC" resource instance. 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.
</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 an action 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" (ID 60002, base64: Opq), that is part of a "server instance" with key value "myserver", is invoked.
</t>
<figure>
    <artwork align="left"><![CDATA[
REQ:  POST /c/Opq?k="myserver" 
              Content-Format(application/YANG-patch+cbor)
{
  +1 : "2016-02-08T14:10:08Z09:00" / reset-at (ID 60003) /
}

RES:  2.05 Content Content-Format(application/YANG-patch+cbor)
{
  +2 : "2016-02-08T14:10:08Z09:18" / reset-finished-at (ID 60004)/
}
]]></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 module mapped from the SMI specification "IP-MIB" <xref target="RFC4293"/>.
The following example shows the "ipNetToPhysicalEntry" list with 2 instances, using diagnostic notation without delta encoding.
</t>
<figure><artwork align="left">
<![CDATA[
{
   60021 :                     / list ipNetToPhysicalEntry /
   [
     {
       60022 : 1,              / ipNetToPhysicalIfIndex /
       60023 : 1,              / ipNetToPhysicalNetAddressType: ipv4 /
       60024 : h'0A000033',    / ipNetToPhysicalNetAddress /
       60025 : h'00000A01172D',/ ipNetToPhysicalPhysAddress /
       60026 : 2333943,        / ipNetToPhysicalLastUpdated /
       60027 : 4,              / ipNetToPhysicalType: static /
       60028 : 1,              / ipNetToPhysicalState: reachable /
       60029 : 1               / ipNetToPhysicalRowStatus: active /
     },
     {
       60022 : 1,              / ipNetToPhysicalIfIndex /
       60023 : 1,              / ipNetToPhysicalNetAddressType: ipv4 /
       60024 : h'09020304',    / ipNetToPhysicalNetAddress  /
       60025 : h'00000A36200A',/ ipNetToPhysicalPhysAddress /
       60026 : 2329836,        / ipNetToPhysicalLastUpdated /
       60027 : 3,              / ipNetToPhysicalType: dynamic /
       60028 : 6,              / ipNetToPhysicalState: unknown /
       60029 : 1               / ipNetToPhysicalRowStatus: active /
     }
   ]
}
]]></artwork></figure> 
<t> 
The IPv4 addresses A.0.0.33 and 9.2.3.4 are encoded in CBOR as h'0A000033' and h'09020304' respectively.      
In the following example exactly one instance is requested from
the ipNetToPhysicalEntry (ID 60021, base64: Oz1). The h'09020304' value is encoded in base64 as AJAgME. 
</t><t>
     In this example one instance of /ip/ipNetToPhysicalEntry that matches the keys 
ipNetToPhysicalIfIndex = 1, 
ipNetToPhysicalNetAddressType = ipv4 and ipNetToPhysicalNetAddress = 9.2.3.4 (h'09020304', base64: AJAgME).
</t>

 <figure>
    <artwork align="left"><![CDATA[
REQ: GET example.com/c/Oz1?k="1,1,AJAgME"

RES: 2.05 Content (Content-Format: application/YANG-patch+cbor)
{
   +1 : 1,                  / ( SID 60022 ) /
   +2 : 1,                  / ( SID 60023 ) /
   +3 : h'09020304',        / ( SID 60024 ) /
   +4 : h'00000A36200A',    / ( SID 60025 ) /
   +5 : 2329836,            / ( SID 60026 ) /
   +6 : 3,                  / ( SID 60027 ) /
   +7 : 6,                  / ( SID 60028 ) /
   +8 : 1                   / ( SID 60029 ) /
}
]]></artwork>
    </figure>

   

</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 transport 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 for example the "ietf-comi-yang-library" module <xref target="I-D.veillette-core-cool-library"/>.
The resource "/c/mod.uri" is used to retrieve the location of the YANG module library.
</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="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 a text string,
    using the following structure:
  </t>

<figure><artwork align="left">
<![CDATA[
CoMI error: xxxx "error text"

]]></artwork></figure>
  <t>
    The characters xxxx represent one of the values from the table below,
    and the OPTIONAL "error text" field contains a human readable explanation of the error.
  </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.xx</c>
      <c>General error</c>

      <c>1</c>
      <c>4.13</c>
      <c>Request too big</c>
      
      <c>2</c>
      <c>4.00</c>
      <c>Response too big</c>
      
      <c>3</c>
      <c>4.00</c>
      <c>Unknown identifier</c>
      
      <c>4</c>
      <c>4.00</c>
      <c>Invalid value</c>

      <c>5</c>
      <c>4.05</c>
      <c>Attempt to write read-only variable</c>

  	<c>6</c>
      <c>5.01</c>
      <c>No access</c>

	<c>7</c>
	<c>4.00</c>
	<c>Wrong type </c>

      <c>8</c>
      <c>4.15</c>
      <c>Unknown encoding</c>

      <c>9</c>
      <c>4.0</c>
      <c>Wrong value</c>

      <c>10</c>
      <c>4.0</c>
      <c>Not created</c>

      <c>11</c>
      <c>4.04</c>
      <c>Resource unavailable</c>

      <c>12</c>
      <c>4.01</c>
      <c>Authorization error</c>

      <c>13</c>
      <c>4.0</c>
      <c>Bad attribute</c>

      <c>14</c>
      <c>4.0</c>
      <c>Unknown attribute</c>

      <c>15</c>
      <c>4.0</c>
      <c>Missing attribute</c>


    </texttable>

<t>
The CoMI error codes are motivated by the error-status values defined in <xref target="RFC3416"/>, and the error tags defined in <xref target="I-D.ietf-netconf-restconf"/>.
</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 references </t>
</list>
Changes from version 10 to version 11
<list style="symbols">
<t> Introduction streamlined</t>
<t> Error codes streamlined</t>
<t> Examples updated to latest SID values </t>
<t> Update of the YANG specifications in the appendix </t>
</list>


</t>

</section>

</middle>
  <back>
    <references title="Normative References">
      &RFC2119;
	 &RFC5277;
      &RFC6243;
      &RFC7049;
      &RFC7252;
      &RFC7950;
      &RFC7959;
      &RFC7641;
      &I-D.ietf-netconf-restconf;
	&I-D.ietf-core-etch;
      &I-D.bormann-appsawg-cbor-merge-patch;
      &I-D.ietf-core-yang-cbor;



    </references>
    <references title="Informative References">
      &RFC2578;
      &RFC3410;
      &RFC3416;
      &RFC4293;
      &RFC6241;
      &RFC6347;
      &RFC6643;
      &RFC6690; 
      &RFC7159;
      &RFC7223;
      &RFC7317;                      
      &I-D.ietf-core-interfaces;
      &I-D.ietf-core-sid;
      &I-D.veillette-core-cool;
      &I-D.veillette-core-cool-library; 

       
  <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 "//" comment sign, taken from <xref target="yang-cbor"/>.
</t>

<section title ="ietf-system" anchor="ietf-system">
<t>
Excerpt of the YANG module ietf-system <xref target="RFC7317"/>.
</t>

<figure><artwork align="left"><![CDATA[
module ietf-system {
  container system {                   // SID 1715
    container clock {                  // SID 1734
      choice timezone {
        case timezone-name {
          leaf timezone-name {         // SID 1735
            type timezone-name;
          }
        }
        case timezone-utc-offset {
          leaf timezone-utc-offset {   // SID 1736
            type int16 {
            }
          }
        }
      }
    }
    container ntp {                    // SID 1750
      leaf enabled {                   // SID 1751
        type boolean;
        default true;
      }
      list server {                    // SID 1752
        key name;
        leaf name {                    // SID 1755
          type string;
        }
        choice transport {
          case udp {
            container udp {            // SID 1757
              leaf address {           // SID 1758
                type inet:host;
              }
              leaf port {              // SID 1759
                type inet:port-number;
              }
            }
          }
        }
        leaf association-type {        // SID 1753
          type enumeration {
            enum server {
            }
            enum peer {
            }
            enum pool {
            }
          }
        }
        leaf iburst {                  // SID 1754
          type boolean;
        }
        leaf prefer {                  // SID 1756
          type boolean;
          default false;
        }
      }
    }
  container system-state {             // SID 1716
    container clock {                  // SID 1717
      leaf current-datetime {          // SID 1719
        type yang:date-and-time;
      }
      leaf boot-datetime {             // SID 1718
        type yang:date-and-time;
      }
    }
  }
}

]]></artwork>
    </figure>

</section> <!--ietf-system -->

<section title="server list" anchor="server">
<t>
Taken over from <xref target="RFC7950"/> section 7.15.3.

</t>
<figure><artwork align="left"><![CDATA[
module example-server-farm {
  yang-version 1.1;
  namespace "urn:example:server-farm";
  prefix "sfarm";

  import ietf-yang-types {
    prefix "yang";
  }

  list server {                        // SID 60000
    key name;
    leaf name {                        // SID 60001
      type string;
    }
    action reset {                     // SID 60002
      input {
        leaf reset-at {                // SID 60003
          type yang:date-and-time;
          mandatory true;
         }
       }
       output {
         leaf reset-finished-at {      // SID 60004
           type yang:date-and-time;
           mandatory true;
         }
       }
     }
   }
}
  
]]></artwork>
    </figure>

</section> <!-- server -->

<section title="interfaces" anchor="interfaces">
<t>
Excerpt of the YANG module ietf-interfaces <xref target="RFC7223"/>.

</t>
<figure><artwork align="left"><![CDATA[
module ietf-interfaces {
  container interfaces {               // SID 1505
    list interface {                   // SID 1533
      key "name";
      leaf name {                      // SID 1537
        type string;
      }
      leaf description {               // SID 1534
        type string;
      }
      leaf type {                      // SID 1538
        type identityref {
          base interface-type;
        }
        mandatory true;
      }

      leaf enabled {                   // SID 1535
        type boolean;
        default "true";
      }

      leaf link-up-down-trap-enable {  // SID 1536
        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>
Notification example defined within this document.
</t>
<figure><artwork align="left"><![CDATA[
module example-port {
        ...
        notification example-port-fault {   // SID 60010
          description
            "Event generated if a hardware fault on a
             line card port is detected";
          leaf port-name {                  // SID 60011
            type string;
            description "Port name";
          }
          leaf port-fault {                 // SID 60012
            type string;
            description "Error condition detected";
          }
        }
      }
]]></artwork>
    </figure>


</section> <!-- example-port -->

<section title="IP-MIB" anchor="SMI">
<t>
The YANG translation of the SMI specifying the IP-MIB <xref target="RFC4293"/>, extended with example SID numbers, yields:
</t>
<figure><artwork align="left">
<![CDATA[
module IP-MIB {
  import IF-MIB {
    prefix if-mib;
  }
  import INET-ADDRESS-MIB {
    prefix inet-address;
  }
  import SNMPv2-TC {
    prefix smiv2;
  }
  import ietf-inet-types {
    prefix inet;
  }
  import yang-smi {
    prefix smi;
  }
  import ietf-yang-types {
    prefix yang;
  }

  container ip {                            // SID 60020
    list ipNetToPhysicalEntry {             // SID 60021
      key "ipNetToPhysicalIfIndex ipNetToPhysicalNetAddressType ipNetToPhysicalNetAddress";
      leaf ipNetToPhysicalIfIndex {         // SID 60022
        type if-mib:InterfaceIndex;
      }
      leaf ipNetToPhysicalNetAddressType {  // SID 60023
        type inet-address:InetAddressType;
      }
      leaf ipNetToPhysicalNetAddress {      // SID 60024
        type inet-address:InetAddress;
      }
      leaf ipNetToPhysicalPhysAddress {     // SID 60025
        type yang:phys-address {
          length "0..65535";
        }
      }
      leaf ipNetToPhysicalLastUpdated {     // SID 60026
        type yang:timestamp;
      }
      leaf ipNetToPhysicalType {            // SID 60027
        type enumeration {
          enum "other" {
            value 1;
          }
          enum "invalid" {
            value 2;
          }
          enum "dynamic" {
            value 3;
          }
          enum "static" {
            value 4;
          }
          enum "local" {
            value 5;
          }
        }
      }
      leaf ipNetToPhysicalState {           // SID 60028
        type enumeration {
          enum "reachable" {
            value 1;
          }
          enum "stale" {
            value 2;
          }
          enum "delay" {
            value 3;
          }
          enum "probe" {
            value 4;
          }
          enum "invalid" {
            value 5;
          }
          enum "unknown" {
            value 6;
          }
          enum "incomplete" {
            value 7;
          }
        }
      }
      leaf ipNetToPhysicalRowStatus {       // SID 60029
        type smiv2:RowStatus;
    }  // list ipNetToPhysicalEntry
  }  // container ip
}  // module IP-MIB

]]></artwork></figure>

</section> <!-- IP-MIB -->

</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.veillette-core-cool"/> 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>
