idnits 2.17.1 draft-bormann-coap-misc-03.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). -- The document date (July 01, 2010) is 5047 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Informational ---------------------------------------------------------------------------- == Outdated reference: A later version (-02) exists of draft-hartke-coap-observe-00 == Outdated reference: A later version (-18) exists of draft-ietf-core-coap-00 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p1-messaging-09 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p4-conditional-09 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p6-cache-09 ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) Summary: 1 error (**), 0 flaws (~~), 7 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 CoRE Working Group C. Bormann 3 Internet-Draft K. Hartke 4 Intended status: Informational Universitaet Bremen TZI 5 Expires: January 2, 2011 July 01, 2010 7 Miscellaneous additions to CoAP 8 draft-bormann-coap-misc-03 10 Abstract 12 This short I-D makes a number of partially interrelated proposals how 13 to solve certain problems in the CoRE WG's main protocol, CoAP. 15 Status of this Memo 17 This Internet-Draft is submitted in full conformance with the 18 provisions of BCP 78 and BCP 79. 20 Internet-Drafts are working documents of the Internet Engineering 21 Task Force (IETF). Note that other groups may also distribute 22 working documents as Internet-Drafts. The list of current Internet- 23 Drafts is at http://datatracker.ietf.org/drafts/current/. 25 Internet-Drafts are draft documents valid for a maximum of six months 26 and may be updated, replaced, or obsoleted by other documents at any 27 time. It is inappropriate to use Internet-Drafts as reference 28 material or to cite them other than as "work in progress." 30 This Internet-Draft will expire on January 2, 2011. 32 Copyright Notice 34 Copyright (c) 2010 IETF Trust and the persons identified as the 35 document authors. All rights reserved. 37 This document is subject to BCP 78 and the IETF Trust's Legal 38 Provisions Relating to IETF Documents 39 (http://trustee.ietf.org/license-info) in effect on the date of 40 publication of this document. Please review these documents 41 carefully, as they describe your rights and restrictions with respect 42 to this document. Code Components extracted from this document must 43 include Simplified BSD License text as described in Section 4.e of 44 the Trust Legal Provisions and are provided without warranty as 45 described in the Simplified BSD License. 47 Table of Contents 49 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 50 2. A Compact Accept Option . . . . . . . . . . . . . . . . . . . 4 51 3. Representing Durations . . . . . . . . . . . . . . . . . . . . 6 52 3.1. Pseudo-Floating Point . . . . . . . . . . . . . . . . . . 6 53 3.2. A Duration Type for CoAP . . . . . . . . . . . . . . . . . 8 54 4. URI encoding . . . . . . . . . . . . . . . . . . . . . . . . . 9 55 4.1. An efficient stateless URI encoding . . . . . . . . . . . 9 56 4.2. Stateful URI compression . . . . . . . . . . . . . . . . . 11 57 5. Block-wise transfers . . . . . . . . . . . . . . . . . . . . . 13 58 5.1. The Block Option . . . . . . . . . . . . . . . . . . . . . 13 59 6. Option Encoding . . . . . . . . . . . . . . . . . . . . . . . 17 60 6.1. A More Efficient Option Encoding . . . . . . . . . . . . . 17 61 6.2. Critical Options . . . . . . . . . . . . . . . . . . . . . 18 62 6.3. Payload-Length Option . . . . . . . . . . . . . . . . . . 18 63 6.4. Problems with specific options . . . . . . . . . . . . . . 19 64 7. Experimental Options . . . . . . . . . . . . . . . . . . . . . 20 65 7.1. Options indicating absolute time . . . . . . . . . . . . . 20 66 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 22 67 9. Security Considerations . . . . . . . . . . . . . . . . . . . 24 68 9.1. Amplification Attacks . . . . . . . . . . . . . . . . . . 24 69 10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 25 70 10.1. Normative References . . . . . . . . . . . . . . . . . . . 25 71 10.2. Informative References . . . . . . . . . . . . . . . . . . 26 72 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 27 74 1. Introduction 76 The CoRE WG is tasked with standardizing an Application Protocol for 77 Constrained Networks/Nodes, CoAP. This protocol is intended to 78 provide RESTful [REST] services not unlike HTTP [RFC2616], while 79 reducing the complexity of implementation as well as the size of 80 packets exchanged in order to make these services useful in a highly 81 constrained network of themselves highly constrained nodes. 83 This objective requires restraint in a number of sometimes 84 conflicting ways: 86 o reducing implementation complexity in order to minimize code size, 88 o reducing message sizes in order to minimize the number of 89 fragments needed for each message (in turn to maximize the 90 probability of delivery of the message), the amount of 91 transmission power needed and the loading of the limited-bandwidth 92 channel, 94 o reducing requirements on the environment such as stable storage, 95 good sources of randomness or user interaction capabilities. 97 This draft attempts to address a number of problems not yet 98 adequately solved in [I-D.ietf-core-coap]. The solutions proposed to 99 these problems are somewhat interrelated and are therefore presented 100 in one draft. 102 In this document, the key words "MUST", "MUST NOT", "REQUIRED", 103 "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", 104 and "OPTIONAL" are to be interpreted as described in BCP 14 [RFC2119] 105 and indicate requirement levels for compliant CoAP implementations. 107 2. A Compact Accept Option 109 A resource may be available in a number of representations. Without 110 some information from the client, a server has no easy way to decide 111 which of these would be best served. HTTP has an Accept: request 112 header that a client can use to indicate the media types supported, 113 allowing the server to decide. This header is somewhat unpopular as, 114 for a web browser, there are too many media types to choose from, so 115 -- even with wildcards -- there is no meaningful information to put 116 there. (This has changed a bit for AJAX calls, which may indeed have 117 a specific media type preference.) It is unlikely that machine-to- 118 machine communication would have the same problem. 120 A similar function to the HTTP Accept: header could be added to CoAP 121 as an option in a much simpler way. The CoAP Accept option would 122 simple carry a value that is a sequence of octets, each of which is 123 an acceptable media type for the client, in the order of preference 124 (see Figure 1). If no Accept option is given, the client does not 125 express a preference. 127 0 128 0 1 2 3 4 5 6 7 129 +-+-+-+-+-+-+-+-+ 130 | mediatype | 131 +-+-+-+-+-+-+-+-+ 133 0 1 134 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 135 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 136 | mediatype1 | mediatype2 | etc. 137 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 139 Figure 1: Accept option value: A sequence of media types 141 Accept also has to be given an option type code, e.g. 7, in Table 2 142 of [I-D.ietf-core-coap]. 144 The other addition that would be required is an error code that 145 mirrors HTTP's "415 Unsupported Media Type". This is indeed already 146 listed as CoAP Code 35 in Table 3 of [I-D.ietf-core-coap]. 148 Proposal: Add an Accept Option. 150 Benefits: A Server does not need to specify one URI each for every 151 possible media type that it wants to serve a resource under. 153 Open Issues: For coap-00, this would have needed a way to handle 154 two-byte media types (easiest if these can be made self- 155 describing, at the cost of about 3 bits in the sub-type field; 156 Figure 2). 158 An self-describing representation for long mediatypes could look like 159 this: 161 0 162 0 1 2 3 4 5 6 7 163 +-+-+-+-+-+-+-+-+ 164 | top | sub | (1-byte: unchanged) 165 +-+-+-+-+-+-+-+-+ 167 0 1 168 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 169 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 170 | 000 | top | sub | (2-byte) 171 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 173 Figure 2: A self-describing media type representation 175 3. Representing Durations 177 Various message types used in CoAP need the representation of 178 *durations*, i.e. of the length of a timespan. In SI units, these 179 are measured in seconds. Where CPU power and memory is abundant, a 180 duration can almost always be adequately represented by a non- 181 negative floating-point number representing that number of seconds. 182 Historically, many APIs have also used an integer representation, 183 which limits both the resolution (e.g., if the integer represents the 184 duration in seconds) and often the range (integer machine types have 185 range limits that may become relevant). UNIX's "time_t" (which is 186 used for both absolute time and durations) originally was a signed 187 32-bit value of seconds, but was later complemented by an additional 188 integer to add microsecond ("struct timeval") and then later 189 nanosecond ("struct timespec") resolution. 191 Three decisions need to be made for each application of the concept 192 of duration: 194 o the *resolution*. What rounding error is acceptable? 196 o the *range*. What is the maximum duration that needs to be 197 represented? 199 o the *number of bits* that can be expended. 201 Obviously, these decisions are interrelated. Typically, a large 202 range needs a large number of bits, unless resolution is traded. For 203 most applications, the actual requirement for resolution are limited 204 for longer durations, but can be more acute for shorter durations. 206 3.1. Pseudo-Floating Point 208 Constrained systems typically avoid the use of floating-point (FP) 209 values, as 211 o simple CPUs often don't have support for floating-point datatypes 213 o software floating-point libraries are expensive in code size and 214 slow. 216 In addition, floating-point datatypes used to be a significant 217 element of market differentiation in CPU design; it has taken the 218 industry a long time to agree on a standard floating point 219 representation. 221 These issues have led to protocols that try to constrain themselves 222 to integer representation even where the ability of a floating point 223 representation to trade range for resolution would be beneficial. 225 The idea of introducing _pseudo-FP_ is to obtain the increased range 226 provided by embedding an exponent, without necessarily getting stuck 227 with hardware datatypes or inefficient software floating-point 228 libraries. 230 For the purposes of this draft, we define an (n,e)-pseudo-FP as a 231 fixed-length value of n bits, e of which may be used for an exponent. 232 Figure 3 illustrates an (8,4)-pseudo-FP value. 234 0 1 2 3 4 5 6 7 235 +---+---+---+---+---+---+---+---+ 236 | 0... value | 237 +---+---+---+---+---+---+---+---+ 239 +---+---+---+---+---+---+---+---+ 240 | 1... mantissa | exponent | 241 +---+---+---+---+---+---+---+---+ 243 Figure 3: An (8,4) pseudo-FP representation 245 If the high bit is clear, the entire n-bit value (including the high 246 bit) is the decoded value. If the high bit is set, the mantissa 247 (including the high bit, but with the exponent field cleared out) is 248 shifted left by the exponent to yield the decoded value. 250 The (n,e)-pseudo-FP format can be decoded with a single line of code 251 (plus a couple of constant definition), as demonstrated in Figure 4. 253 #define N 8 254 #define E 4 255 #define HIBIT (1 << (N - 1)) 256 #define EMASK ((1 << E) - 1) 257 #define MMASK ((1 << N) - 1 - EMASK) 259 #define DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK)) 261 Figure 4: Decoding an (8,4) pseudo-FP value 263 Only non-negative numbers can be represented by this format. It is 264 designed to provide full integer resolution for values from 0 to 265 2^(n-1)-1, i.e., 0 to 127 in the (8,4) case, and a mantissa of n-e 266 bits from 2^(n-1) to (2^n-2^e)*2^(2^e-1), i.e., 128 to 7864320 in the 267 (8,4) case. By choosing e carefully, resolution can be traded 268 against range. 270 Note that a pseudo-FP encoder needs to consider rounding; different 271 applications of durations may favor rounding up or rounding down the 272 value encoded in the message. This requires a little more than a 273 single line of code (which is left as an exercise to the reader, as 274 the most efficient expression depends on hardware details). 276 3.2. A Duration Type for CoAP 278 CoAP needs durations in a number of places. In [I-D.ietf-core-coap], 279 durations occur in the option "Subscription-lifetime" as well as in 280 the option "Max-age". (Note that the option "Date" is not a 281 duration, but a point in time.) Other durations of this kind may be 282 added later. 284 Most durations relevant to CoAP are best expressed with a minimum 285 resolution of one second. More detailed resolutions are unlikely to 286 provide much benefit. 288 The range of lifetimes and caching ages are probably best kept below 289 the order of magnitude of months. An (8,4)-pseudo-FP has the maximum 290 value of 7864320, which is about 91 days; this appears to be adequate 291 for a subscription lifetime and probably even for a maximum cache 292 age. (If a larger range for the latter is indeed desired, an (8,5)- 293 pseudo-FP could be used; this would last 15 milleniums, at the cost 294 of having only 3 bits of accuracy for values larger than 127 295 seconds.) 297 Proposal: A single duration type is used throughout CoAP, based on 298 an (8,4)-pseudo-FP giving a duration in seconds. 300 Benefits: Implementations can use a single piece of code for 301 managing all CoAP-related durations. 303 In addition, length information never needs to be managed for 304 durations that are embedded in other data structures: All 305 durations are expressed by a single byte. 307 Open Issues: It might be worthwhile to reserve one duration value, 308 e.g. 0xFF, for an indefinite duration. 310 4. URI encoding 312 In HTTP-based systems, URIs can reach significant lengths. While 313 CoAP-based systems may be able to sidestep the most egregious 314 excesses (mostly by simply applying REST principles), a URI such as 316 /.well-known/resources 318 can use up one third of the available payload in a CoAP message 319 transported in a single 6LoWPAN packet. Is there a way to encode 320 these URIs in a more efficient way? 322 Several proposals have been made on the CoRE mailing list, e.g. 323 applying the principle of base64-encoding [RFC4648] in reverse and 324 using only 6 bits per character. However, due to rounding errors and 325 occasional characters that are not in the 64-character subset chosen 326 to be efficiently encodable, the actual gains are limited. 327 Similarly, using 7 bits per character (assuming URIs contain only 328 ASCII characters) only gives a best-case gain of 12.5 %, and that 329 only in the case the URI is a multiple of 8 characters long. On the 330 other hand, the complexity (and danger of subtle interoperability 331 problems) is not entirely trivial. 333 We will proceed by first proposing an URI encoding that is slightly 334 more efficient than the abovementioned ones, then rejecting even that 335 for its unconvincing cost-benefit ratio, and finally taking up 336 Henning Schulzrinne's proposal to add state. 338 4.1. An efficient stateless URI encoding 340 There is very little redundancy by repetition in a typical URI, 341 rendering popular compression methods such as LZ77 (as implemented in 342 in the widely used DEFLATE algorithm [RFC1951]) rather ineffective. 344 For the short, non-repetitive data structures that URIs tend to be, 345 efficient stateless compression is pretty much confined to Huffman 346 (or, for even more complexity, arithmetic) coding. The complexity 347 can be reduced significantly by moving to n-ary Huffman coding, i.e., 348 optimizing not to the bit level, but to a larger level of 349 granularity. Informal experiments by the author show that a 16ary 350 Huffman coding is close to optimal for reasonable URI lengths. In 351 other words, basing the encoding on nibbles (4-bit half-bytes) is 352 both nearly optimal and relatively inexpensive to implement. 354 The actual letter frequencies that will occur in CoAP URIs are hard 355 to predict. As a stopgap, the author has analyzed an HTTP-based URI 356 corpus and found the following characters to occur with high 357 frequency: 359 %.aeinorst 361 In the encoding proposed, each of these ten highly-compressed 362 characters is represented by a single 4-bit nibble. As the % 363 character is used for hexadecimal encoding in URIs, two additional 364 nibbles are used to provide the numeric value of the two hexadecimal 365 numbers following the % character (the original URI will only be 366 properly reconstituted if these are upper-case as they should be 367 according to section 2.1 of the URI specification [RFC3986]; the 368 encoder can choose to send all three characters in dual-nibble format 369 if that matters). An encoder could also map non-ASCII characters to 370 this three-nibble form, even though they are not allowed in URIs. 371 This gives compatibility with the %-encoding required by [RFC3986]. 373 All other characters are represented by both of their nibbles. The 374 resulting sequence of nibbles is reconstituted into a sequence of 375 bytes in most-significant-nibble-first order. Any unused nibble in 376 the last byte of an encoding is set to 0. (Upon decoding, this 377 padding can be readily distinguished from another % combination as 378 this would require another byte after the last byte.) The encoding 379 is summarized in Figure 5. 381 0 1 382 0 1 2 3 4 5 6 7 8 9 0 1 383 +---+---+---+---+ 384 | 1, 8-F | .aeinorst 385 +---+---+---+---+ 189ABCDEF 387 +---+---+---+---+---+---+---+---+ 388 | 2-7 | 0-F | other ASCII 389 +---+---+---+---+---+---+---+---+ 391 +---+---+---+---+---+---+---+---+---+---+---+---+ 392 | 0 | 0-F | 0-F | %HH 393 +---+---+---+---+---+---+---+---+---+---+---+---+ 395 Figure 5: A nibble-based URI encoding 397 An example encoding for "/.well-known/resources" (where the initial 398 slash is left out, as proposed for abs-path URIs) is given in 399 Figure 6. While the more than 28 % savings in this example may seem 400 just an accident, the HTTP-based corpus indeed shows an average 401 savings of about 21.8 %, i.e. the sum of the lengths of the encoded 402 version of all URIs in the corpus is about 78.2 % of the sum of the 403 length of all URIs. (The savings should be noticeably higher with a 404 more RESTful selection of URIs than was available for this 405 experiment.) 406 0 1 2 407 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 408 / . w e l l - k n o w n / r e s o u r c e s 410 2e 77 65 6c 6c 2d 6b 6e 6f 77 6e 2f 72 65 73 6f 75 72 63 65 73 411 -> 412 1 77 9 6c 6c 2d 6b b c 77 b 2f d 9 e c 75 d 63 9 e 413 = 17 79 6c 6c 2d 6b bc 77 b2 fd 9e c7 5d 63 9e 415 Figure 6: Nibble-based URI encoding: 21 -> 15 bytes 417 4.2. Stateful URI compression 419 Is the approximately 25 % average saving achievable with Huffman- 420 based URI compression schemes worth the complexity? Probably not, 421 because much higher average savings can be achieved by introducing 422 state. 424 Henning Schulzrinne has proposed for a server to be able to supply a 425 shortened URI once a resource has been requested using the full- 426 length URI. Let's call such a shortened referent a _Temporary 427 Resource Identifier_, _TeRI_ for short. This could be expressed by a 428 response option as shown in Figure 7. 430 0 431 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 432 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 433 | duration | TeRI... 434 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 436 Figure 7: Option for offering a TeRI in a response 438 The TeRI offer option indicates that the server promises to offer 439 this resources under the TeRI given for at least the time given as 440 the duration. Another TeRI offer can be made later to extend the 441 duration. 443 Once a TeRI for a URI is known (and still within its lifetime), the 444 client can supply a TeRI instead of a URI in its requests. The same 445 option format as an offer could be used to allow the client to 446 indicate how long it believes the TeRI will still be valid (so that 447 the server can decide when to update the lifetime duration). TeRIs 448 in requests could be distinguished from URIs e.g. by using a 449 different option number. 451 Proposal: Add a TeRI option (e.g., number 2) that can be used in 452 CoAP requests and responses. 454 Add a way to indicate a TeRI and its duration in a link-value. 456 Do not add any form of stateless URI encoding. 458 Benefits: Much higher reduction of message size than any stateless 459 URI encoding could achieve. 461 As the use of TeRIs is entirely optional, minimal complexity nodes 462 can get by without implementing them. 464 5. Block-wise transfers 466 Not all resource representations will fit into a single link layer 467 packet of a constrained network. Using fragmentation (either at the 468 adaptation layer or at the IP layer) to enable the transport of 469 larger representations is possible up to the maximum size of a UDP 470 datagram, but the fragmentation/reassembly process loads the lower 471 layers with conversation state that is better managed in the 472 application layer. 474 This section proposes options to enable _block-wise_ access to 475 resource representations. The overriding objective is to avoid 476 creating conversation state at the server for block-wise GET 477 requests. (It is impossible to fully avoid creating conversation 478 state for POST/PUT, if the creation/replacement of resources is to be 479 atomic; where that property is not needed, there is no need to create 480 server conversation state in this case, either.) Also, 481 implementation of these options is intended to be optional. (The 482 details of which parts of the behavior need to be mandatory to enable 483 that optionality still are TBD, see below.) 485 The size of the blocks should not be fixed by the protocol. On the 486 other hand, implementation should be as simple as possible. We 487 therefore propose a small range of power-of-two block sizes, from 2^4 488 (16) to 2^11 (2048) bytes. One of these eight values can be encoded 489 in three bits (0 for 2^4 to 7 for 2^11 bytes), the "szx" (size 490 exponent); the actual block size is then "1 << (szx + 4)". 492 5.1. The Block Option 494 When a representation is larger than can be comfortably transferred 495 in a single UDP datagram, the Block option can be used to indicate a 496 block-wise transfer. Block is a 1-, 2- or 3-byte integer, the four 497 least significant bits of which indicate the size and whether the 498 current block-wise transfer is the last block being transferred (M or 499 "more" bit). The value divided by sixteen is the number of the block 500 currently being transferred, starting from zero, i.e., the current 501 transfer is about the "size" bytes starting at "blocknr << (szx + 502 4)". The default value of the Block option is zero, indicating that 503 the current block is the first (block number 0) and only (M bit not 504 set) block of the transfer; however, there is no explicit size 505 implied by this default value. 507 0 508 0 1 2 3 4 5 6 7 509 +-+-+-+-+-+-+-+-+ 510 |blocknr|M| szx | 511 +-+-+-+-+-+-+-+-+ 513 0 1 514 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 515 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 516 | block nr |M| szx | 517 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 519 0 1 2 520 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 521 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 522 | block nr |M| szx | 523 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 525 Figure 8: Block option 527 (Note that the option with the last 4 bits masked out, shifted to the 528 left by the value of szx, gives the byte position of the block. The 529 author is not too sure whether that particularly is a feature.) 531 The block option is used in one of three roles: 533 o In the request for a GET, it gives the block number requested and 534 suggests a block size (block number 0) or echoes the block size of 535 previous blocks received (block numbers other than 0). 537 o In the response for a GET or in the request for a PUT or POST, it 538 describes what block number is contained in the payload, and 539 whether further blocks are part of that body (M bit). If the M 540 bit is set, the size of the payload body in bytes MUST indeed be 541 the power of two given by the block size. All blocks for a 542 transaction MUST use the same block size, except for the last 543 block (M bit not set). 545 o In the response for a PUT or POST, it indicates what block number 546 is being acknowledged. In this case, the M bit is set to indicate 547 that this response does not carry the final response to the 548 request; this can occur when the M bit was set in the request and 549 the server implements PUT/POST atomically (only with the receptin 550 of the last block). 552 In all cases, the block number logically extends the transaction ID, 553 i.e. the same transaction ID can be used for all exchanges for a 554 block-wise transfer. (For GET, and for PUT/POST where atomic 555 semantics are not needed, the requester is free to use different 556 transactions IDs for each block if desired.) 558 When a GET is answered with a response carrying a Block option with 559 the M bit set, the requestor may retrieve additional blocks by 560 sending requests with a Block option giving the block number desired. 561 In such a Block option, the M bit MUST be sent as zero and ignored on 562 reception. 564 To influence the block size used in response to a GET request, the 565 requestor uses the Block option, giving the desired size, a block 566 number of zero and an M bit of zero. A server SHOULD use the block 567 size indicated or a smaller size. Any further block-wise requests 568 for blocks beyond the first one MUST indicate the block size used in 569 the response for the first one. 571 If the Block option is used by the requestor, all GET requests in a 572 single transaction MUST use the same size. The server SHOULD use the 573 block size indicated in the request option, but the requestor MUST 574 take note of the actual block size used in the response; the server 575 MUST ensure that it uses the same block size for all responses in a 576 transaction (except for the last one with the M bit not set). [TBD: 577 decide whether the Block option can only be used in a response if a 578 Block option was in the request. Such a minimal block option could 579 be of length zero, i.e., would occupy just one byte for the type/ 580 length information, but is a bit redundant, so it would be nice to 581 leave this requirement out, but then every GET requestor has the 582 burden of having to cope with receiving Block options.] 584 Block-wise transfers SHOULD be used in conjunction with the Etag 585 option, unless the representation being exchanged is entirely static 586 (not changing over time at all, such as in a schema describing a 587 device). When reassembling the representation from the blocks being 588 exchanged, the reassembler MUST compare Etag options. If the Etag 589 options do not match in a GET transfer, the requestor has the option 590 of attempting to retrieve fresh values for the blocks it retrieved 591 first. To minimize the resulting inefficiency, the server MAY cache 592 the current value of a representation for an ongoing transaction, but 593 there is no requirement for the server to establish any state. The 594 server may offer a TeRI with the initial block to reduce the size of 595 further block-wise GET requests; this TeRI MAY be short-lived and 596 specific to the version of the representation being retrieved (which 597 would in effect freeze the representation of the resource 598 specifically for the purposes of this block-wise transfer). 600 In a PUT or POST transfer, the block option refers to the body in the 601 request, i.e., there is no way to perform a block-wise retrieval of 602 the body of the response. Servers that do need to supply large 603 bodies in response to PUT/POST SHOULD therefore be employing 604 redirects, possibly offering a TeRI. 606 In a PUT or POST transfer that is intended to be implemented in an 607 atomic fashion at the server, the actual creation/replacement takes 608 place at the time a block with the M bit unset is received. If not 609 all previous blocks are available at the server at this time, the 610 transfer fails and error code 4__ (TBD) MUST be returned. The error 611 code 4__ can also be returned at any time by a server that does not 612 currently have the resources to store blocks for a block-wise PUT or 613 POST transfer that it would intend to implement in an atomic fashion. 614 [TBD: a way for a server to derive the equivalent of an Etag for the 615 request body, so that when these do not match in a PUT or POST 616 transfer, the reassembler MUST discard older blocks. For now, the 617 transaction ID will have to suffice.] 619 Proposal: Add a Block option (e.g., number 8) that can be used for 620 block-wise transfers. 622 Benefits: Transfers larger than can be accommodated in constrained- 623 network link-layer packets can be performed in smaller blocks. 625 No hard-to-manage conversation state is created at the adaptation 626 layer or IP layer for fragmentation. 628 The transfer of each block is acknowledged, enabling 629 retransmission if required. 631 Both sides have a say in the block size that actually will be 632 used. 634 6. Option Encoding 636 The option encoding in [I-D.ietf-core-coap] is neither particularly 637 flexible nor particularly efficient. One important, easily 638 overlooked disadvantage of the encoding is the large number of ways 639 in which the same information can be encoded. This unneeded 640 variability causes problems in interoperability and increases both 641 coding and testing efforts required. 643 6.1. A More Efficient Option Encoding 645 The basic idea of the proposed encoding is to reduce the number of 646 ways the same information can be encoded as far as possible (but not 647 further). This both simplifies decoding (e.g., an implementation 648 that only ever uses short URIs never has to implement long options, 649 because these can only be used with long lengths) and 650 interoperability testing (there is only one way to say a specific 651 thing, so there aren't multiple ways that need testing). 653 One of the undesired variations in packets is the ordering of the 654 options. In this draft, we therefore mandate a total ordering of 655 options, ordered by the option number. 657 As an interesting consequence, the option numbers can now be 658 expressed in delta coding, in turn requiring fewer bits to encode the 659 option number. This frees a number of bits for the length, making 660 the likelihood of actually needing the two-byte form of the option 661 header much smaller. 663 To further reduce variation, the length of the value (as always, not 664 including the option header) is now encoded in such a way that there 665 is only one way to express a given length: The short form (one-byte 666 option tag) can express length values from 0 to 14, and the long form 667 is used for values of 15 to 15+255=270, inclusively (Figure 9). 669 0 1 2 3 4 5 6 7 670 +---+---+---+---+---+---+---+---+ 671 | option delta | length | for 0..14 672 +---+---+---+---+---+---+---+---+ 673 for 15..270: 674 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 675 | option delta | 1 1 1 1 | length - 15 | 676 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 678 Figure 9: Option delta/length representation with small range 680 The small option delta of 0..15 in this encoding limits the 681 difference in option value between two adjacent options (or the value 682 of the option number of the first option). While realistic sequences 683 of options rarely will have a problem here, option numbers 14, 28, 684 ... are reserved for no-op options with no body (implementations will 685 automatically ignore these with zero additional code; see Section 6.2 686 why the reserved values are not 15, 30, ...). Note that the 687 resulting delta that reaches the interim nop option may have any 688 number, e.g., for including option 2 and 27 in one message, the 689 sequence would be: 691 o delta = 2 (option 2, body) 693 o delta = 12 (option 14 = no-op, no body) 695 o delta = 13 (option 27, body) 697 In the unlikely case that only option 40 is needed, the sequence 698 would be: 700 o delta = 14 (option 14 = no-op, no body) 702 o delta = 14 (option 28 = no-op, bo body) 704 o delta = 12 (option 40, body) 706 6.2. Critical Options 708 CoAP is designed to enable the definition of additional options by 709 later extensions. Typically, new options are designed in such a way 710 that they can simply be ignored if not understood, i.e. new options 711 are _elective_. However, some new options may be _critical_, i.e., 712 there is no good way to process the message if the option is not 713 understood. (Actually, half of the options currently on the table 714 are critical in nature.) 716 In the option encoding proposed, odd-numbered options indicate a 717 critical option; even-numbered options indicate elective options. 718 (Note that, again, the even/odd distinction is on the option number 719 resulting from the decoding, not the delta value actually embedded in 720 the packet.) 722 Implementing this proposal requires some renumbering of options from 723 [I-D.ietf-core-coap]. 725 6.3. Payload-Length Option 727 Not all transport mappings may provide an unambiguous length of the 728 CoAP message. For UDP, it may also be desirable to pack more than 729 one CoAP message into one UDP payload (aggregation); in that case, 730 for all but the last message there needs to be a way to delimit the 731 payload of that message. 733 We propose a new option, the Payload-Length option. If this option 734 is present, the value of this option is an unsigned integer giving 735 the length of the payload of the message (note that this integer can 736 be zero for a zero-length payload, which can in turn be represented 737 by a zero-length option value). (In the UDP aggregation case, what 738 would have been in the payload of this message after "payload-length" 739 bytes is then actually one or more additional messages.) 741 6.4. Problems with specific options 743 Problem: The Uri option currently does not provide a way to 744 distinguish an "absolute-URI" from an "absolute-path" [RFC3986], 745 as the leading slash is omitted from the latter. (Ticket #12.) 747 Proposal: Split the option into two variants: "Uri-Full" and 748 "Uri-Path". None (= "Uri-Path" with option value ''), one of 749 these, but never both can be present. 751 7. Experimental Options 753 7.1. Options indicating absolute time 755 HTTP has a number of headers that may indicate absolute time: 757 o "Date", defined in Section 14.18 in [RFC2616] (Section 9.3 in 758 [I-D.ietf-httpbis-p1-messaging]), giving the absolute time a 759 response was generated; 761 o "Last-Modified", defined in Section 14.29 in [RFC2616], (Section 762 6.6 in [I-D.ietf-httpbis-p4-conditional], giving the absolute time 763 of when the origin server believes the resource representation was 764 last modified; 766 o "If-Modified-Since", defined in Section 14.25 in [RFC2616], 767 "If-Unmodified-Since", defined in Section 14.28 in [RFC2616], and 768 "If-Range", defined in Section 14.27 in [RFC2616] can be used to 769 supply absolute time to gate a conditional request; 771 o "Expires", defined in Section 14.21 in [RFC2616] (Section 3.3 in 772 [I-D.ietf-httpbis-p6-cache]), giving the absolute time after which 773 a response is considered stale. 775 o The more obscure headers "Retry-After", defined in Section 14.37 776 in [RFC2616], and "Warning", defined in section 14.46 in 777 [RFC2616], also may employ absolute time. 779 [I-D.ietf-core-coap] defines a single "Date" option, which however 780 "indicates the creation time and date of a given resource 781 representation", i.e., is closer to a "Last-Modified" HTTP header. 782 HTTP's caching rules [I-D.ietf-httpbis-p6-cache] make use of both 783 "Date" and "Last-Modified", combined with "Expires". The specific 784 semantics required for CoAP needs further consideration. 786 In addition to the definition of the semantics, an encoding for 787 absolute times needs to be specified. 789 In UNIX-related systems, it is customary to indicate absolute time as 790 an integer number of seconds, after midnight UTC, January 1, 1970. 791 Unless negative numbers are employed, this time format cannot 792 represent time values prior to January 1, 1970, which probably is not 793 required for the uses ob absolute time in CoAP. 795 If a 32-bit integer is used and allowance is made for a sign-bit in a 796 local implementation, the latest UTC time value that can be 797 represented by the resulting 31 bit integer value is 03:14:07 on 798 January 19, 2038. If the 32-bit integer is used as an unsigned 799 value, the last date is 2106-02-07, 06:28:15. 801 The reach can be extended by: - moving the epoch forward, e.g. by 40 802 years (= 1262304000 seconds) to 2010-01-01. This makes it impossible 803 to represent Last-Modified times in that past (such as could be 804 gatewayed in from HTTP). - extending the number of bits, e.g. by one 805 more byte, either always or as one of two formats, keeping the 32-bit 806 variant as well. 808 Also, the resolution can be extended by expressing time in 809 milliseconds etc., requiring even more bits (e.g., a 48-bit unsigned 810 integer of milliseconds would last well after year 9999.) 812 For experiments, an experimental "Date" option is defined with the 813 semantics of HTTP's "Last-Modified". It can carry an unsigned 814 integer of 32, 40, or 48 bits; 32- and 40-bit integers indicate the 815 absolute time in seconds since 1970-01-01 00:00 UTC, while 48-bit 816 integers indicate the absolute time in milliseconds since 1970-01-01 817 00:00 UTC. 819 8. IANA Considerations 821 This draft adds the following option numbers to Table 2 of 822 [I-D.ietf-core-coap]: 824 +------+-----+--------+----------------------------+--------+-------+ 825 | Type | C/E | Name | Data type | Length | Rules | 826 +------+-----+--------+----------------------------+--------+-------+ 827 | 2 | E | TeRI | Duration + Sequence of | 2-n B | | 828 | | | | Bytes | | | 829 | | | | | | | 830 | 7 | E | Accept | Sequence of bytes | 1-n B | | 831 | | | | | | | 832 | 8 | C | Block | Unsigned Integer | 1-3 B | | 833 +------+-----+--------+----------------------------+--------+-------+ 835 With the new option encoding and the proposal for essential options, 836 the total list becomes: 838 +------+-----+----------------+------------------+--------+---------+ 839 | Type | C/E | Name | Data type | Length | Rules | 840 +------+-----+----------------+------------------+--------+---------+ 841 | 0 | E | TeRI | Duration + | 2-n B | | 842 | | | | Sequence of | | | 843 | | | | Bytes | | | 844 | | | | | | | 845 | 1 | C | Uri-Path | String | 1-n B | | 846 | | | | | | | 847 | 2 | E | Accept | Sequence of | 1-n B | | 848 | | | | Bytes | | | 849 | | | | | | | 850 | 3 | C | Uri-Full | String | 1-n B | | 851 | | | | | | | 852 | 4 | E | Max-age | Duration | 1 B | | 853 | | | | | | | 854 | 5 | C | Content-type | Unsigned Integer | 1-2 B | | 855 | | | | | | | 856 | 6 | E | Etag | Sequence of | 1-4 B | | 857 | | | | Bytes | | | 858 | | | | | | | 859 | 8 | E | Date | Unsigned Integer | 4-6 B | (with | 860 | | | | (?) | | body) | 861 | | | | | | | 862 | 13 | C | Block | Unsigned Integer | 1-3 B | | 863 | | | | | | | 864 | 14.. | E | Nop | None | 0 B | | 865 | | | | | | | 866 | 15 | C | Payload-length | Unsigned Integer | 0-2 B | | 867 +------+-----+----------------+------------------+--------+---------+ 869 (The upper limit of "n" indicates that the size is limited only by 870 the options encoding.) Odd option numbers indicate critical options, 871 even option numbers indicate elective options. Option numbers 14, 872 28, 42, ... (any number divisible by 14) are reserved (they are 873 elective and therefore ignored by all implementations). 875 (Subscription-related options are discussed in 876 [I-D.hartke-coap-observe], so the following option from 877 [I-D.ietf-core-coap] is not further discussed here: 879 +-----+-----+-----------------------+----------+--------+-----------+ 880 | Typ | C/E | Name | Data | Length | Rules | 881 | e | | | type | | | 882 +-----+-----+-----------------------+----------+--------+-----------+ 883 | 6 | E | Subscription-lifetime | Duration | 1 B | With | 884 | | | | | | SUBSCRIBE | 885 | | | | | | or its | 886 | | | | | | response | 887 +-----+-----+-----------------------+----------+--------+-----------+ 889 9. Security Considerations 891 TBD. (Weigh the security implications of application layer block- 892 wise transfer against those of adaptation-layer or IP-layer 893 fragmentation. Discuss the implications of TeRIs. Also: Discuss 894 nodes without clocks.) 896 9.1. Amplification Attacks 898 TBD. (This section discusses how CoAP nodes could become implicated 899 in DoS attacks by using the amplifying properties of the protocol, as 900 well as mitigations for this threat.) 902 10. References 904 10.1. Normative References 906 [I-D.hartke-coap-observe] 907 Hartke, K. and C. Bormann, "Observing Resources in CoAP", 908 draft-hartke-coap-observe-00 (work in progress), 909 June 2010. 911 [I-D.ietf-core-coap] 912 Shelby, Z., Frank, B., and D. Sturek, "Constrained 913 Application Protocol (CoAP)", draft-ietf-core-coap-00 914 (work in progress), June 2010. 916 [I-D.ietf-httpbis-p1-messaging] 917 Fielding, R., Gettys, J., Mogul, J., Nielsen, H., 918 Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke, 919 "HTTP/1.1, part 1: URIs, Connections, and Message 920 Parsing", draft-ietf-httpbis-p1-messaging-09 (work in 921 progress), March 2010. 923 [I-D.ietf-httpbis-p4-conditional] 924 Fielding, R., Gettys, J., Mogul, J., Nielsen, H., 925 Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke, 926 "HTTP/1.1, part 4: Conditional Requests", 927 draft-ietf-httpbis-p4-conditional-09 (work in progress), 928 March 2010. 930 [I-D.ietf-httpbis-p6-cache] 931 Fielding, R., Gettys, J., Mogul, J., Nielsen, H., 932 Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke, 933 "HTTP/1.1, part 6: Caching", 934 draft-ietf-httpbis-p6-cache-09 (work in progress), 935 March 2010. 937 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 938 Requirement Levels", BCP 14, RFC 2119, March 1997. 940 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 941 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 942 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 944 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 945 Resource Identifier (URI): Generic Syntax", STD 66, 946 RFC 3986, January 2005. 948 10.2. Informative References 950 [REST] Fielding, R., "Architectural Styles and the Design of 951 Network-based Software Architectures", 2000. 953 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format Specification 954 version 1.3", RFC 1951, May 1996. 956 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 957 Encodings", RFC 4648, October 2006. 959 Authors' Addresses 961 Carsten Bormann 962 Universitaet Bremen TZI 963 Postfach 330440 964 Bremen D-28359 965 Germany 967 Phone: +49-421-218-63921 968 Fax: +49-421-218-7000 969 Email: cabo@tzi.org 971 Klaus Hartke 972 Universitaet Bremen TZI 973 Postfach 330440 974 Bremen D-28359 975 Germany 977 Phone: +49-421-218-63908 978 Fax: +49-421-218-7000 979 Email: hartke@tzi.org