RFC 8790

FETCH and PATCH with Sensor Measurement Lists (SenML)

πŸ“… published June 2020, from ietf

Title Block: RFC 8790 πŸŽ€βœ¨

Okay so bestie, this is the RFC that teaches FETCH and PATCH to speak SenML πŸ§šπŸ’– It's from June 2020, written by A. KerΓ€nen (Ericsson) and M. Mohajer 🫢 It's a Standards Track document, which means it's a real Internet standard, not just vibes πŸ‘‘ It doesn't obsolete or update any other RFC, so it's a clean, fresh start 🌸 The IETF, the ISSN 2070-1721, and the whole "consensus" thing all check out πŸ’…


Abstract ✨

Okay so the Sensor Measurement Lists (SenML) media type and data model can be used to send collections of resources, like batches of sensor data or configuration parameters πŸ¦‹ The Constrained Application Protocol (CoAP) FETCH, PATCH, and iPATCH methods let you access and update parts of a resource, or multiple resources, with one single request πŸ”₯ This document defines new media types for CoAP FETCH, PATCH, and iPATCH for resources represented with the SenML data model, and it's giving main character energy πŸ‘‘πŸ’…

Status of This Memo ✨

This is an Internet Standards Track document πŸ’–

This document is a product of the Internet Engineering Task Force (IETF) 🌈 It represents the consensus of the IETF community, received public review, and was approved for publication by the Internet Engineering Steering Group (IESG) πŸŽ€ More info on Internet Standards is in Section 2 of RFC 7841 🫢

Info about the current status of this document, any errata, and how to give feedback is at https://www.rfc-editor.org/info/rfc8790 πŸ¦‹

Copyright (c) 2020 IETF Trust and the persons identified as the document authors. All rights reserved. πŸ’œ

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document 🌸 Please review these carefully, because they describe your rights and restrictions. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they're provided without warranty as described in the Simplified BSD License πŸ™ˆ

Table of Contents ✨

1.  Introduction
2.  Terminology
3.  Using FETCH and (i)PATCH with SenML
  3.1.  SenML FETCH
  3.2.  SenML (i)PATCH
4.  Fragment Identification
5.  Extensibility
6.  Security Considerations
7.  IANA Considerations
  7.1.  CoAP Content-Format Registration
  7.2.  senml-etch+json Media Type
  7.3.  senml-etch+cbor Media Type
8.  References
  8.1.  Normative References
  8.2.  Informative References
Acknowledgements
Authors' Addresses

1. Introduction πŸŽ€

The Sensor Measurement Lists (SenML) media type [RFC8428] and data model can be used to transmit collections of resources, like batches of sensor data or configuration parameters 🧚

An example of a SenML collection looks like this πŸ“

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "vb":true},
 {"n":"5851", "v":42},
 {"n":"5750", "vs":"Ceiling light"}
]

Here, three resources, "3311/0/5850", "3311/0/5851", and "3311/0/5750", of a dimmable light smart object [IPSO] are represented using a single SenML Pack with three SenML Records πŸ’‘ All of them share the same base name "2001:db8::2/3311/0/", so the full names are "2001:db8::2/3311/0/5850", etc. πŸ¦‹

The CoAP [RFC7252] FETCH, PATCH, and iPATCH methods [RFC8132] let you access and update parts of a resource, or multiple resources, with one request ✨

This document defines two new media types. One uses the JavaScript Object Notation (JSON) [RFC8259] and the other uses the Concise Binary Object Representation (CBOR) [RFC7049]. They can be used with the CoAP FETCH, PATCH, and iPATCH methods for resources represented using the SenML data model, meaning both SenML and Sensor Streaming Measurement Lists (SenSML) data 🌈 The rest of the document says "(i)PATCH" when it's talking about both methods, because the semantics of the new media types are the same for CoAP PATCH and iPATCH πŸ’…

2. Terminology 🌸

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here πŸ”₯

Readers should also be familiar with the terms and concepts in [RFC8132] and [RFC8428] 🧚 The following extra terms are used in this document:

  • Fetch Record: One set of parameters that is used to match SenML Record(s) πŸŽ€
  • Fetch Pack: One or more Fetch Records in an array structure πŸ¦‹
  • Patch Record: One set of parameters similar to a Fetch Record, but also containing instructions on how to change existing SenML Pack(s) πŸ’–
  • Patch Pack: One or more Patch Records in an array structure 🌈
  • Target Record: A Record in a SenML Pack that matches the selection criteria of a Fetch or Patch Record, and hence is a target for a Fetch or Patch operation 🎯
  • Target Pack: A SenML Pack that is a target for a Fetch or Patch operation 🫢
  • (i)PATCH: A term that refers to both CoAP "PATCH" and "iPATCH" methods when there is no difference in this specification as to which one is used πŸ’œ

3. Using FETCH and (i)PATCH with SenML πŸ’…

The FETCH/(i)PATCH media types for SenML are modeled as extensions to the SenML media type, so you can reuse existing SenML parsers and generators, especially on constrained devices 🧚 Unless mentioned otherwise, FETCH and PATCH Packs are built with the same rules and constraints as SenML Packs ✨

The key differences from the SenML media type are that a "null" value can be used for removing Records with the (i)PATCH method, and Fetch Records don't have value fields πŸ™ˆ Also, Fetch and Patch Records don't get a default time or base version when those fields are omitted πŸ’€

3.1. SenML FETCH πŸ¦‹

The FETCH method can be used to select and return a subset of Records, in sequence, from one or more SenML Packs 🌸 SenML Records get selected by giving a set of names that, once resolved, match resolved names in a Target SenML Pack πŸ’– The names for a Fetch Pack are given with the SenML "name" and/or "base name" fields, and they get resolved by concatenating the base name with the name field, as defined in [RFC8428] πŸŽ€

A Fetch Pack MUST contain at least one Fetch Record πŸ”₯ A Fetch Record MUST contain a name and/or base name field πŸ’…

For example, to select the resources "5850" and "5851" from the example in Section 1, you can use this Fetch Pack 🧚

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850"},
 {"n":"5851"}
]

The result of a FETCH request with the example above would be πŸ“

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "vb":true},
 {"n":"5851", "v":42},
]

The SenML time and unit fields can be used in a Fetch Record to narrow the selection of matched SenML Records even further πŸ’« When no time or unit is given in a Fetch Record, all SenML Records with the given name are matched. Unlike with SenML Records, the lack of a time field in a Fetch Record does not imply a time value of zero, so be careful with that one πŸ™ˆ When time is given in the Fetch Record, a Target Record is matched only when its resolved time value and name are equal to those of the Fetch Record πŸ¦‹ Similarly, when unit is given, a Target Record is matched only when its resolved unit and name are equal to those of the Fetch Record 🌈 If both the time and unit are given in the Fetch Record, a Target Record is matched only when both are equal to those of the Fetch Record πŸ‘‘ Each Target Record MUST be included in the response at most once, even if multiple Fetch Records match the same Target Record πŸ’…

For example, if the resource "5850" had multiple sensor readings (SenML Records) with different time values, this Fetch Pack can be used to retrieve the Record with time "1.276020091e+09" πŸŽ€

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "t":1.276020091e+09}
]

The resolved form of Records (Section 4.6 of [RFC8428]) is used when comparing the names, times, and units of the Target and Fetch Records, so that differences in how base values are used don't cause trouble 🧚 In the resolved form, the SenML name in the example above becomes "2001:db8::2/3311/0/5850" πŸ¦‹ Since there is no base time in the Pack, the time in resolved form is equal to the time in the example ✨

If no SenML Records match, an empty SenML Pack (an array with no elements) is returned as the response 🌸

Fetch Records MUST NOT contain other fields than name, base name, time, base time, unit, and base unit πŸš«πŸ’… Implementations MUST reject and generate an error for a Fetch Pack with other fields πŸ”₯ [RFC8132], Section 2.2 gives guidance for FETCH request error handling, for example using the 4.22 (Unprocessable Entity) CoAP error response code πŸ’€

3.2. SenML (i)PATCH πŸ’–

The (i)PATCH method can be used to change the fields of SenML Records, add new Records, and remove existing Records 🌈 The names, times, and units of Patch Records are given and matched the same way as for Fetch Records, except that each Patch Record MUST match at most one Target Record 🎯 A Patch Record matching more than one Target Record is considered invalid, because patching multiple Target Records with one Patch Record would result in multiple copies of the same Record πŸ™ˆ Patch Packs can also include new values and other SenML fields for the Records 🧚 Application of Patch Packs is idempotent, so the PATCH and iPATCH methods for SenML Packs are equivalent 🫢

When the name in a Patch Record matches the name in an existing Record, the resolved time values and units (if any) are compared πŸ¦‹ If the time values and units either don't exist in both Records or are equal, the Target Record is replaced with the contents of the Patch Record ✨ All Patch Records MUST contain at least a SenML Value or Sum field πŸ”₯

If a Patch Record contains a name, or the combination of a time value, unit, and name, that doesn't exist in any existing Record in the Pack, the given Record, with all the fields it contains, is added to the Pack πŸŽ€

If a Patch Record has a value ("v") field with a null value, it MUST NOT be added, but the matched Record (if any) is removed from the Target Pack πŸ’€

The Patch Records MUST be applied in the same sequence as they are in the Patch Pack πŸ’… If multiple Patch Packs are being processed at the same time, the result MUST be equivalent to applying them in one sequence πŸ‘‘

Implementations MUST reject and generate an error for Patch Packs with invalid Records πŸ™ˆ If a Patch Pack is rejected, the state of the Target Pack is not changed, i.e., either all or none of the Patch Records are applied πŸ’– [RFC8132], Section 3.4 gives guidance for error handling with PATCH and iPATCH requests, for example using the 4.22 (Unprocessable Entity) and 4.09 (Conflict) CoAP error response codes 🌸

For example, this document could be given as an (i)PATCH payload to change/set the values of two SenML Records for the example in Section 1 ✨

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "vb":false},
 {"n":"5851", "v":10}
]

If the request is successful, the resulting representation of the example SenML Pack would be πŸ¦‹

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "vb":false},
 {"n":"5851", "v":10},
 {"n":"5750", "vs":"Ceiling light"}
]

As another example, this document could be given as an (i)PATCH payload to remove the two SenML Records πŸ’…

[
 {"bn":"2001:db8::2/3311/0/", "n":"5850", "v":null},
 {"n":"5851", "v":null}
]

4. Fragment Identification ✨

okay so fragment identification for Records of Fetch and Patch Packs works the same way as SenML JSON/CBOR fragment identification 🧚 (see Section 9 of [RFC8428]). you use the rec scheme, then a comma-separated list of Record positions or ranges of Records. for example, to grab the 3rd and 5th Record of a Fetch or Patch Pack, you can put rec=3,5 in the URI of the Fetch or Patch Pack resource πŸŽ€

5. Extensibility πŸ¦‹

the SenML mandatory-to-understand field extensibility mechanism (see Section 4.4 of [RFC8428]) does NOT apply to Patch Packs πŸ™ˆ so unknown fields MUST NOT generate an error. instead they get treated like any other field (e.g., added to Patch target Records where applicable). no drama, just vibes πŸ’…

this spec only allows a small subset of SenML fields in Fetch Records, but future specs might enable new fields for Fetch Records and maybe new fields for picking targets for Patch Records too πŸ‘€βœ¨

6. Security Considerations πŸ’€

okay this section is SERIOUS, bestie, so read it carefully 🫢

the security and privacy considerations of SenML also apply to the FETCH and (i)PATCH methods. CoAP's security mechanisms are used to provide security for FETCH and (i)PATCH too πŸ”

in FETCH and (i)PATCH requests, the client can pass arbitrary names to the target resource for manipulation. so the resource implementer has to be really careful to only allow access to names that are actually part of (or accessible through) the target resource 😭 the receiver especially needs to make sure that any input does not lead to uncontrolled special interpretation by the system. that's a whole red flag 🚩

If the client is not allowed to do a GET or PUT on the full target resource (and thus all the names accessible through it), access control rules must be evaluated for each Record in the Pack. no skipping this, periodt πŸ’œ

7. IANA Considerations 🌸

this document registers two new media types and CoAP Content-Format IDs for both media types πŸ“

7.1. CoAP Content-Format Registration

IANA has assigned CoAP Content-Format IDs for the SenML PATCH and FETCH media types in the "CoAP Content-Formats" subregistry, within the "Constrained RESTful Environments (CoRE) Parameters" registry [RFC7252]. the assigned IDs are shown in Table 1 below πŸ’–

           +=============================+==========+=====+
           | Media Type                  | Encoding | ID  |
           +=============================+==========+=====+
           | application/senml-etch+json | -        | 320 |
           +-----------------------------+----------+-----+
           | application/senml-etch+cbor | -        | 322 |
           +-----------------------------+----------+-----+

                   Table 1: CoAP Content-Format IDs

7.2. senml-etch+json Media Type

the registration template for this one looks like this 🧁

   Type name:  application

   Subtype name:  senml-etch+json

   Required parameters:  N/A

   Optional parameters:  N/A

   Encoding considerations:  binary

   Security considerations:  See Section 6 of RFC 8790.

   Interoperability considerations:  N/A

   Published specification:  RFC 8790

   Applications that use this media type:  Applications that use the
      SenML media type for resource representation.

   Fragment identifier considerations:  Fragment identification for
      application/senml-etch+json is supported by using fragment
      identifiers as specified by Section 4 of RFC 8790.

   Additional information:

      Deprecated alias names for this type:  N/A

      Magic number(s):  N/A

      File extension(s):  senml-etchj

      Windows Clipboard Name:  "SenML FETCH/PATCH format"

      Macintosh file type code(s):  N/A

      Macintosh Universal Type Identifier code:
         org.ietf.senml-etch-json conforms to public.text

   Person & email address to contact for further information:
      Ari KerΓ€nen <ari.keranen@ericsson.com>

   Intended usage:  COMMON

   Restrictions on usage:  N/A

   Author:  Ari KerΓ€nen <ari.keranen@ericsson.com>

   Change controller:  IESG

7.3. senml-etch+cbor Media Type

and the CBOR sibling, same energy, different vibe 🌈

   Type name:  application

   Subtype name:  senml-etch+cbor

   Required parameters:  N/A

   Optional parameters:  N/A

   Encoding considerations:  binary

   Security considerations:  See Section 6 of RFC 8790.

   Interoperability considerations:  N/A

   Published specification:  RFC 8790

   Applications that use this media type:  Applications that use the
      SenML media type for resource representation.

   Fragment identifier considerations:  Fragment identification for
      application/senml-etch+cbor is supported by using fragment
      identifiers as specified by Section 4 of RFC 8790.

   Additional information:

      Deprecated alias names for this type:  N/A

      Magic number(s):  N/A

      File extension(s):  senml-etchc

      Macintosh file type code(s):  N/A

      Macintosh Universal Type Identifier code:
         org.ietf.senml-etch-cbor conforms to public.data

   Person & email address to contact for further information:
      Ari KerΓ€nen <ari.keranen@ericsson.com>

   Intended usage:  COMMON

   Restrictions on usage:  N/A

   Author:  Ari KerΓ€nen <ari.keranen@ericsson.com>

   Change controller:  IESG

8. References πŸ“š

8.1. Normative References

these are the must-reads πŸ€“

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119,
              DOI 10.17487/RFC2119, March 1997,
              <https://www.rfc-editor.org/info/rfc2119>.

   [RFC7049]  Bormann, C. and P. Hoffman, "Concise Binary Object
              Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049,
              October 2013, <https://www.rfc-editor.org/info/rfc7049>.

   [RFC7252]  Shelby, Z., Hartke, K., and C. Bormann, "The Constrained
              Application Protocol (CoAP)", RFC 7252,
              DOI 10.17487/RFC7252, June 2014,
              <https://www.rfc-editor.org/info/rfc7252>.

   [RFC8132]  van der Stok, P., Bormann, C., and A. Sehgal, "PATCH and
              FETCH Methods for the Constrained Application Protocol
              (CoAP)", RFC 8132, DOI 10.17487/RFC8132, April 2017,
              <https://www.rfc-editor.org/info/rfc8132>.

   [RFC8174]  Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
              2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
              May 2017, <https://www.rfc-editor.org/info/rfc8174>.

   [RFC8259]  Bray, T., Ed., "The JavaScript Object Notation (JSON) Data
              Interchange Format", STD 90, RFC 8259,
              DOI 10.17487/RFC8259, December 2017,
              <https://www.rfc-editor.org/info/rfc8259>.

   [RFC8428]  Jennings, C., Shelby, Z., Arkko, J., Keranen, A., and C.
              Bormann, "Sensor Measurement Lists (SenML)", RFC 8428,
              DOI 10.17487/RFC8428, August 2018,
              <https://www.rfc-editor.org/info/rfc8428>.

8.2. Informative References

and this one's just for extra context 🌷

   [IPSO]     IPSO, "IPSO Light Control Smart Object", 2019,
              <http://www.openmobilealliance.org/tech/profiles/
              lwm2m/3311.xml>.

Acknowledgements 🫢

the FETCH and (i)PATCH methods with SenML were first introduced by the OMA SpecWorks Lightweight Machine to Machine (LwM2M) v1.1 specification 🌟 this document generalizes the use to any SenML representation. the authors want to thank Carsten Bormann, Christian AmsΓΌss, Jaime JimΓ©nez, Klaus Hartke, Michael Richardson, and other participants from the IETF CoRE and OMA SpecWorks DMSE working groups who contributed ideas and reviews. so much love to them πŸ’œ

Authors' Addresses 🧚

   Ari KerΓ€nen
   Ericsson
   FI-02420 Jorvas
   Finland

   Email: ari.keranen@ericsson.com


   Mojan Mohajer

   Email: mojanm@hotmail.com
πŸ“¦ where this page comes from