draft-ietf-core-block-10.txt   draft-ietf-core-block-11.txt 
CoRE Working Group C. Bormann CoRE Working Group C. Bormann
Internet-Draft Universitaet Bremen TZI Internet-Draft Universitaet Bremen TZI
Intended status: Standards Track Z. Shelby, Ed. Intended status: Standards Track Z. Shelby, Ed.
Expires: April 24, 2013 Sensinode Expires: October 01, 2013 Sensinode
October 21, 2012 March 30, 2013
Blockwise transfers in CoAP Blockwise transfers in CoAP
draft-ietf-core-block-10 draft-ietf-core-block-11
Abstract Abstract
CoAP is a RESTful transfer protocol for constrained nodes and CoAP is a RESTful transfer protocol for constrained nodes and
networks. Basic CoAP messages work well for the small payloads we networks. Basic CoAP messages work well for the small payloads we
expect from temperature sensors, light switches, and similar expect from temperature sensors, light switches, and similar
building-automation devices. Occasionally, however, applications building-automation devices. Occasionally, however, applications
will need to transfer larger payloads -- for instance, for firmware will need to transfer larger payloads -\u002D for instance, for
updates. With HTTP, TCP does the grunt work of slicing large firmware updates. With HTTP, TCP does the grunt work of slicing
payloads up into multiple packets and ensuring that they all arrive large payloads up into multiple packets and ensuring that they all
and are handled in the right order. arrive and are handled in the right order.
CoAP is based on datagram transports such as UDP or DTLS, which CoAP is based on datagram transports such as UDP or DTLS, which
limits the maximum size of resource representations that can be limits the maximum size of resource representations that can be
transferred without too much fragmentation. Although UDP supports transferred without too much fragmentation. Although UDP supports
larger payloads through IP fragmentation, it is limited to 64 KiB larger payloads through IP fragmentation, it is limited to 64 KiB
and, more importantly, doesn't really work well for constrained and, more importantly, doesn't really work well for constrained
applications and networks. applications and networks.
Instead of relying on IP fragmentation, this specification extends Instead of relying on IP fragmentation, this specification extends
basic CoAP with a pair of "Block" options, for transferring multiple basic CoAP with a pair of "Block" options, for transferring multiple
blocks of information from a resource representation in multiple blocks of information from a resource representation in multiple
request-response pairs. In many important cases, the Block options request-response pairs. In many important cases, the Block options
enable a server to be truly stateless: the server can handle each enable a server to be truly stateless: the server can handle each
block transfer separately, with no need for a connection setup or block transfer separately, with no need for a connection setup or
other server-side memory of previous block transfers. other server-side memory of previous block transfers.
In summary, the Block options provide a minimal way to transfer In summary, the Block options provide a minimal way to transfer
larger representations in a block-wise fashion. larger representations in a block-wise fashion.
Status of this Memo The present revision -11 fixes one example and adds the text and
examples about the Block/Observe interaction, taken from -observe.
It also adds a couple of formatting bugs from the new xml2rfc. The
"grand rewrite" is next.
Status of This Memo
This Internet-Draft is submitted in full conformance with the This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79. provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/. Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on April 24, 2013. This Internet-Draft will expire on October 01, 2013.
Copyright Notice Copyright Notice
Copyright (c) 2012 IETF Trust and the persons identified as the Copyright (c) 2013 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Block-wise transfers . . . . . . . . . . . . . . . . . . . . . 6 2. Block-wise transfers . . . . . . . . . . . . . . . . . . . . 5
2.1. The Block Options . . . . . . . . . . . . . . . . . . . . 6 2.1. The Block Options . . . . . . . . . . . . . . . . . . . . 5
2.2. Structure of a Block Option . . . . . . . . . . . . . . . 7 2.2. Structure of a Block Option . . . . . . . . . . . . . . . 6
2.3. Block Options in Requests and Responses . . . . . . . . . 9 2.3. Block Options in Requests and Responses . . . . . . . . . 8
2.4. Using the Block Options . . . . . . . . . . . . . . . . . 11 2.4. Using the Block2 Option . . . . . . . . . . . . . . . . . 10
3. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.5. Using the Block1 Option . . . . . . . . . . . . . . . . . 11
4. The Size Option . . . . . . . . . . . . . . . . . . . . . . . 20 2.6. Combining Blockwise Transfers with the Observe Option . . 12
5. HTTP Mapping Considerations . . . . . . . . . . . . . . . . . 22 2.7. Block2 and Initiative . . . . . . . . . . . . . . . . . . 13
6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 24 3. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 13
7. Security Considerations . . . . . . . . . . . . . . . . . . . 25 3.1. Block2 Examples . . . . . . . . . . . . . . . . . . . . . 13
7.1. Mitigating Resource Exhaustion Attacks . . . . . . . . . . 25 3.2. Block1 Examples . . . . . . . . . . . . . . . . . . . . . 16
7.2. Mitigating Amplification Attacks . . . . . . . . . . . . . 26 3.3. Combining Block1 and Block2 . . . . . . . . . . . . . . . 18
8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 27 3.4. Combining Observe and Block2 . . . . . . . . . . . . . . 20
9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4. The Size Option . . . . . . . . . . . . . . . . . . . . . . . 23
9.1. Normative References . . . . . . . . . . . . . . . . . . . 28 5. HTTP Mapping Considerations . . . . . . . . . . . . . . . . . 24
9.2. Informative References . . . . . . . . . . . . . . . . . . 28 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 25
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 29 7. Security Considerations . . . . . . . . . . . . . . . . . . . 26
7.1. Mitigating Resource Exhaustion Attacks . . . . . . . . . 26
7.2. Mitigating Amplification Attacks . . . . . . . . . . . . 27
8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 27
9. References . . . . . . . . . . . . . . . . . . . . . . . . . 28
9.1. Normative References . . . . . . . . . . . . . . . . . . 28
9.2. Informative References . . . . . . . . . . . . . . . . . 28
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 29
1. Introduction 1. Introduction
The CoRE WG is tasked with standardizing an Application Protocol for The CoRE WG is tasked with standardizing an Application Protocol for
Constrained Networks/Nodes, CoAP. This protocol is intended to Constrained Networks/Nodes, CoAP. This protocol is intended to
provide RESTful [REST] services not unlike HTTP [RFC2616], while provide RESTful [REST] services not unlike HTTP [RFC2616], while
reducing the complexity of implementation as well as the size of reducing the complexity of implementation as well as the size of
packets exchanged in order to make these services useful in a highly packets exchanged in order to make these services useful in a highly
constrained network of themselves highly constrained nodes. constrained network of themselves highly constrained nodes.
skipping to change at page 6, line 24 skipping to change at page 5, line 24
o by the desire to avoid adaptation layer fragmentation (60-80 bytes o by the desire to avoid adaptation layer fragmentation (60-80 bytes
for 6LoWPAN [RFC4919]) for 6LoWPAN [RFC4919])
When a resource representation is larger than can be comfortably When a resource representation is larger than can be comfortably
transferred in the payload of a single CoAP datagram, a Block option transferred in the payload of a single CoAP datagram, a Block option
can be used to indicate a block-wise transfer. As payloads can be can be used to indicate a block-wise transfer. As payloads can be
sent both with requests and with responses, this specification sent both with requests and with responses, this specification
provides two separate options for each direction of payload transfer. provides two separate options for each direction of payload transfer.
In the following, the term "payload" will be used for the actual In the following, the term "payload" will be used for the actual
content of a single CoAP message, i.e. a single block being content of a single CoAP message, i.e. a single block being
transferred, while the term "body" will be used for the entire transferred, while the term "body" will be used for the entire
resource representation that is being transferred in a block-wise resource representation that is being transferred in a block-wise
fashion. fashion. The Content-Format option applies to the body, not to the
payload, in particular the boundaries between the blocks may in
places that are not whole units in terms of the structure, encoding,
or content-coding used by the Content-Format.
In most cases, all blocks being transferred for a body will be of the In most cases, all blocks being transferred for a body will be of the
same size. The block size is not fixed by the protocol. To keep the same size. The block size is not fixed by the protocol. To keep the
implementation as simple as possible, the Block options support only implementation as simple as possible, the Block options support only
a small range of power-of-two block sizes, from 2**4 (16) to 2**10 a small range of power-of-two block sizes, from 2**4 (16) to 2**10
(1024) bytes. As bodies often will not evenly divide into the power- (1024) bytes. As bodies often will not evenly divide into the power-
of-two block size chosen, the size need not be reached in the final of-two block size chosen, the size need not be reached in the final
block (but even for the final block, the chosen power-of-two size block (but even for the final block, the chosen power-of-two size
will still be indicated in the block size field of the Block option). will still be indicated in the block size field of the Block option).
skipping to change at page 7, line 9 skipping to change at page 6, line 13
Table 1: Block Option Numbers Table 1: Block Option Numbers
Both Block1 and Block2 options can be present both in request and Both Block1 and Block2 options can be present both in request and
response messages. In either case, the Block1 Option pertains to the response messages. In either case, the Block1 Option pertains to the
request payload, and the Block2 Option pertains to the response request payload, and the Block2 Option pertains to the response
payload. payload.
Hence, for the methods defined in [I-D.ietf-core-coap], Block1 is Hence, for the methods defined in [I-D.ietf-core-coap], Block1 is
useful with the payload-bearing POST and PUT requests and their useful with the payload-bearing POST and PUT requests and their
responses. Block2 is useful with GET, POST, and PUT requests and responses. Block2 is useful with GET, POST, and PUT requests and
their payload-bearing responses (2.01, 2.02, 2.04, 2.05 -- see their payload-bearing responses (2.01, 2.02, 2.04, 2.05 -\u002D see
section "Payload" of [I-D.ietf-core-coap]). section "Payload" of [I-D.ietf-core-coap]).
(As a memory aid: Block_1_ pertains to the payload of the _1st_ part (As a memory aid: Block_1_ pertains to the payload of the _1st_ part
of the request-response exchange, i.e. the request, and Block_2_ of the request-response exchange, i.e. the request, and Block_2_
pertains to the payload of the _2nd_ part of the request-response pertains to the payload of the _2nd_ part of the request-response
exchange, i.e. the response.) exchange, i.e. the response.)
Where Block1 is present in a request or Block2 in a response (i.e., Where Block1 is present in a request or Block2 in a response (i.e.,
in that message to the payload of which it pertains) it indicates a in that message to the payload of which it pertains) it indicates a
block-wise transfer and describes how this block-wise payload forms block-wise transfer and describes how this block-wise payload forms
part of the entire body being transferred ("descriptive usage"). part of the entire body being transferred ("descriptive usage").
Where it is present in the opposite direction, it provides additional Where it is present in the opposite direction, it provides additional
control on how that payload will be formed or was processed ("control control on how that payload will be formed or was processed ("control
usage"). usage").
Implementation of either Block option is intended to be optional. Implementation of either Block option is intended to be optional.
However, when it is present in a CoAP message, it MUST be processed However, when it is present in a CoAP message, it MUST be processed
(or the message rejected); therefore it is identified as a critical (or the message rejected); therefore it is identified as a critical
option. It MUST NOT occur more than once. option. It MUST NOT occur more than once.
2.2. Structure of a Block Option 2.2. Structure of a Block Option
Three items of information may need to be transferred in a Block Three items of information may need to be transferred in a Block
option: (Block1 or Block2) option:
o The size of the block (SZX); o The size of the block (SZX);
o whether more blocks are following (M); o whether more blocks are following (M);
o the relative number of the block (NUM) within a sequence of blocks o the relative number of the block (NUM) within a sequence of blocks
with the given size. with the given size.
The value of the option is a 1-, 2- or 3-byte integer which encodes The value of the Block Option is a variable-size (0 to 3 byte)
these three fields, see Figure 1. unsigned integer (uint, see Appendix A of [I-D.ietf-core-coap]).
This integer value encodes these three fields, see Figure 1. (Due to
the CoAP uint encoding rules, when all of NUM, M, and SZX happen to
be zero, a zero-byte integer will be sent.)
0 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
| NUM |M| SZX | | NUM |M| SZX |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
0 1 0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NUM |M| SZX | | NUM |M| SZX |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0 1 2 0 1 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NUM |M| SZX | | NUM |M| SZX |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 1: Block option value Figure 1: Block option value
The block size is encoded as a three-bit unsigned integer (0 for 2**4 The block size is encoded using a three-bit unsigned integer (0 for
to 6 for 2**10 bytes), which we call the "SZX" (size exponent); the 2**4 to 6 for 2**10 bytes), which we call the "SZX" ("size
actual block size is then "2**(SZX + 4)". SZX is transferred in the exponent"); the actual block size is then "2**(SZX + 4)". SZX is
three least significant bits of the option value (i.e., "val & 7" transferred in the three least significant bits of the option value
where "val" is the value of the option). (i.e., "val & 7" where "val" is the value of the option).
The fourth least significant bit, the M or "more" bit ("val & 8"), The fourth least significant bit, the M or "more" bit ("val & 8"),
indicates whether more blocks are following or the current block-wise indicates whether more blocks are following or the current block-wise
transfer is the last block being transferred. transfer is the last block being transferred.
The option value divided by sixteen (the NUM field) is the sequence The option value divided by sixteen (the NUM field) is the sequence
number of the block currently being transferred, starting from zero. number of the block currently being transferred, starting from zero.
The current transfer is therefore about the "size" bytes starting at The current transfer is therefore about the "size" bytes starting at
byte "NUM << (SZX + 4)". byte "NUM << (SZX + 4)".
Implementation note: As an implementation convenience, "(val & ~0xF) Implementation note: As an implementation convenience, "(val & ~0xF)
<< (val & 7)", i.e. the option value with the last 4 bits masked << (val & 7)", i.e., the option value with the last 4 bits masked
out, shifted to the left by the value of SZX, gives the byte out, shifted to the left by the value of SZX, gives the byte
position of the block being transferred. position of the block being transferred.
More specifically, within the option value of a Block1 or Block2 More specifically, within the option value of a Block1 or Block2
Option, the meaning of the option fields is defined as follows: Option, the meaning of the option fields is defined as follows:
NUM: Block Number. The block number is a variable-size (4, 12, or NUM: Block Number, indicating the block number being requested or
20 bit) unsigned integer (uint, see Appendix A of provided. Block number 0 indicates the first block of a body
[I-D.ietf-core-coap]) indicating the block number being requested (i.e., starting with the first byte of the body).
or provided. Block number 0 indicates the first block of a body.
M: More Flag (not last block). For descriptive usage, this flag, if M: More Flag (not last block). For descriptive usage, this flag, if
unset, indicates that the payload in this message is the last unset, indicates that the payload in this message is the last
block in the body; when set it indicates that there are one or block in the body; when set it indicates that there are one or
more additional blocks available. When a Block2 Option is used in more additional blocks available. When a Block2 Option is used in
a request to retrieve a specific block number ("control usage"), a request to retrieve a specific block number ("control usage"),
the M bit MUST be sent as zero and ignored on reception. (In a the M bit MUST be sent as zero and ignored on reception. (In a
Block1 Option in a response, the M flag is used to indicate Block1 Option in a response, the M flag is used to indicate
atomicity, see below.) atomicity, see below.)
SZX: Block Size. The block size is a three-bit unsigned integer SZX: Block Size. The block size is represented as three-bit
indicating the size of a block to the power of two. Thus block unsigned integer indicating the size of a block to the power of
size = 2**(SZX + 4). The allowed values of SZX are 0 to 6, i.e., two. Thus block size = 2**(SZX + 4). The allowed values of SZX
the minimum block size is 2**(0+4) = 16 and the maximum is are 0 to 6, i.e., the minimum block size is 2**(0+4) = 16 and the
2**(6+4) = 1024. The value 7 for SZX (which would indicate a maximum is 2**(6+4) = 1024. The value 7 for SZX (which would
block size of 2048) is reserved, i.e. MUST NOT be sent and MUST indicate a block size of 2048) is reserved, i.e. MUST NOT be sent
lead to a 4.00 Bad Request response code upon reception in a and MUST lead to a 4.00 Bad Request response code upon reception
request. in a request.
There is no default value for the Block1 and Block2 Options. Absence There is no default value for the Block1 and Block2 Options. Absence
of one of these options is equivalent to an option value of 0 with of one of these options is equivalent to an option value of 0 with
respect to the value of NUM and M that could be given in the option, respect to the value of NUM and M that could be given in the option,
i.e. it indicates that the current block is the first and only block i.e. it indicates that the current block is the first and only block
of the transfer (block number 0, M bit not set). However, in of the transfer (block number 0, M bit not set). However, in
contrast to the explicit value 0, which would indicate an SZX of 0 contrast to the explicit value 0, which would indicate an SZX of 0
and thus a size value of 16 bytes, there is no specific explicit size and thus a size value of 16 bytes, there is no specific explicit size
implied by the absence of the option -- the size is left unspecified. implied by the absence of the option -\u002D the size is left
(Note that, as for any uint, the value 0 is efficiently indicated by unspecified. (As for any uint, the explicit value 0 is efficiently
a zero-length option; this, therefore, is different in semantics from indicated by a zero-length option; this, therefore, is different in
the absence of the option.) semantics from the absence of the option.)
2.3. Block Options in Requests and Responses 2.3. Block Options in Requests and Responses
The Block options are used in one of three roles: The Block options are used in one of three roles:
o In descriptive usage, i.e. a Block2 Option in a response (e.g., a o In descriptive usage, i.e., a Block2 Option in a response (such as
2.05 response for GET), or a Block1 Option in a request (e.g., PUT a 2.05 response for GET), or a Block1 Option in a request (a PUT
or POST): or POST):
* The NUM field in the option value describes what block number * The NUM field in the option value describes what block number
is contained in the payload of this message. is contained in the payload of this message.
* The M bit indicates whether further blocks are required to * The M bit indicates whether further blocks need to be
complete the transfer of that body. transferred to complete the transfer of that body.
* The block size given by SZX MUST match the size of the payload * The block size given by SZX MUST match the size of the payload
in bytes, if the M bit is set. (SZX does not govern the in bytes, if the M bit is set. (SZX does not govern the
payload size if M is unset). For Block2, if the request payload size if M is unset). For Block2, if the request
suggested a larger value of SZX, the next request MUST move SZX suggested a larger value of SZX, the next request MUST move SZX
down to the size given here. (The effect is that, if the down to the size given in the response. (The effect is that,
server uses the smaller of its preferred block size and the one if the server uses the smaller of (1) its preferred block size
requested, all blocks for a body use the same block size.) and (2) the block size requested, all blocks for a body use the
same block size.)
o A Block2 Option in control usage in a request (e.g., GET): o A Block2 Option in control usage in a request (e.g., GET):
* The NUM field in the Block2 Option gives the block number of * The NUM field in the Block2 Option gives the block number of
the payload that is being requested to be returned in the the payload that is being requested to be returned in the
response. response.
* In this case, the M bit has no function and MUST be set to * In this case, the M bit has no function and MUST be set to
zero. zero.
* The block size given (SZX) suggests a block size (in the case * The block size given (SZX) suggests a block size (in the case
of block number 0) or repeats the block size of previous blocks of block number 0) or repeats the block size of previous blocks
received (in the case of block numbers other than 0). received (in the case of a non-zero block number).
o A Block1 Option in control usage in a response (e.g., a 2.xx o A Block1 Option in control usage in a response (e.g., a 2.xx
response for a PUT or POST request): response for a PUT or POST request):
* The NUM field of the Block1 Option indicates what block number * The NUM field of the Block1 Option indicates what block number
is being acknowledged. is being acknowledged.
* If the M bit was set in the request, the server can choose * If the M bit was set in the request, the server can choose
whether to act on each block separately, with no memory, or whether to act on each block separately, with no memory, or
whether to handle the request for the entire body atomically, whether to handle the request for the entire body atomically,
or any mix of the two. If the M bit is also set in the or any mix of the two.
response, it indicates that this response does not carry the
final response code to the request, i.e. the server collects + If the M bit is also set in the response, it indicates that
further blocks and plans to implement the request atomically this response does not carry the final response code to the
(e.g., acts only upon reception of the last block of payload). request, i.e. the server collects further blocks from the
Conversely, if the M bit is unset even though it was set in the same endpoint and plans to implement the request atomically
request, it indicates the block-wise request was enacted now (e.g., acts only upon reception of the last block of
specifically for this block, and the response carries the final payload). In this case, the response MUST NOT carry a
response to this request (and to any previous ones with the M Block2 option.
bit set in the response's Block1 Option in this sequence of
block-wise transfers); the client is still expected to continue + Conversely, if the M bit is unset even though it was set in
sending further blocks, the request method for which may or may the request, it indicates the block-wise request was enacted
not also be enacted per-block. now specifically for this block, and the response carries
the final response to this request (and to any previous ones
with the M bit set in the response's Block1 Option in this
sequence of block-wise transfers); the client is still
expected to continue sending further blocks, the request
method for which may or may not also be enacted per-block.
* Finally, the SZX block size given in a control Block1 Option * Finally, the SZX block size given in a control Block1 Option
indicates the largest block size preferred by the server for indicates the largest block size preferred by the server for
transfers toward the resource that is the same or smaller than transfers toward the resource that is the same or smaller than
the one used in the initial exchange; the client SHOULD use the one used in the initial exchange; the client SHOULD use
this block size or a smaller one in all further requests in the this block size or a smaller one in all further requests in the
transfer sequence, even if that means changing the block size transfer sequence, even if that means changing the block size
(and possibly scaling the block number accordingly) from now (and possibly scaling the block number accordingly) from now
on. on.
2.4. Using the Block Options
Using one or both Block options, a single REST operation can be split Using one or both Block options, a single REST operation can be split
into multiple CoAP message exchanges. As specified in into multiple CoAP message exchanges. As specified in
[I-D.ietf-core-coap], each of these message exchanges uses their own [I-D.ietf-core-coap], each of these message exchanges uses their own
CoAP Message ID. CoAP Message ID.
2.4. Using the Block2 Option
When a request is answered with a response carrying a Block2 Option When a request is answered with a response carrying a Block2 Option
with the M bit set, the requester may retrieve additional blocks of with the M bit set, the requester may retrieve additional blocks of
the resource representation by sending further requests with the same the resource representation by sending further requests with the same
options and a Block2 Option giving the block number and block size options and a Block2 Option giving the block number and block size
desired. In a request, the client MUST set the M bit of a Block2 desired. In a request, the client MUST set the M bit of a Block2
Option to zero and the server MUST ignore it on reception. Option to zero and the server MUST ignore it on reception.
To influence the block size used in a response, the requester also To influence the block size used in a response, the requester also
uses the Block2 Option, giving the desired size, a block number of uses the Block2 Option, giving the desired size, a block number of
zero and an M bit of zero. A server MUST use the block size zero and an M bit of zero. A server MUST use the block size
skipping to change at page 11, line 33 skipping to change at page 10, line 39
blocks beyond the first one MUST indicate the same block size that blocks beyond the first one MUST indicate the same block size that
was used by the server in the response for the first request that was used by the server in the response for the first request that
gave a desired size using a Block2 Option. gave a desired size using a Block2 Option.
Once the Block2 Option is used by the requester and a first response Once the Block2 Option is used by the requester and a first response
has been received with a possibly adjusted block size, all further has been received with a possibly adjusted block size, all further
requests in a single block-wise transfer SHOULD ultimately use the requests in a single block-wise transfer SHOULD ultimately use the
same size, except that there may not be enough content to fill the same size, except that there may not be enough content to fill the
last block (the one returned with the M bit not set). (Note that the last block (the one returned with the M bit not set). (Note that the
client may start using the Block2 Option in a second request after a client may start using the Block2 Option in a second request after a
first request without a Block2 Option resulted in a Block option in first request without a Block2 Option resulted in a Block2 option in
the response.) The server SHOULD use the block size indicated in the the response.) The server SHOULD use the block size indicated in the
request option or a smaller size, but the requester MUST take note of request option or a smaller size, but the requester MUST take note of
the actual block size used in the response it receives to its initial the actual block size used in the response it receives to its initial
request and proceed to use it in subsequent requests. The server request and proceed to use it in subsequent requests. The server
behavior MUST ensure that this client behavior results in the same behavior MUST ensure that this client behavior results in the same
block size for all responses in a sequence (except for the last one block size for all responses in a sequence (except for the last one
with the M bit not set, and possibly the first one if the initial with the M bit not set, and possibly the first one if the initial
request did not contain a Block2 Option). request did not contain a Block2 Option).
Block-wise transfers can be used to GET resources the representations Block-wise transfers can be used to GET resources the representations
skipping to change at page 12, line 15 skipping to change at page 11, line 22
the blocks it retrieved first. To minimize the resulting the blocks it retrieved first. To minimize the resulting
inefficiency, the server MAY cache the current value of a inefficiency, the server MAY cache the current value of a
representation for an ongoing sequence of requests. (The server may representation for an ongoing sequence of requests. (The server may
identify the sequence by the combination of the requesting end-point identify the sequence by the combination of the requesting end-point
and the URI being the same in each block-wise request.) Note well and the URI being the same in each block-wise request.) Note well
that this specification makes no requirement for the server to that this specification makes no requirement for the server to
establish any state; however, servers that offer quickly changing establish any state; however, servers that offer quickly changing
resources may thereby make it impossible for a client to ever resources may thereby make it impossible for a client to ever
retrieve a consistent set of blocks. retrieve a consistent set of blocks.
2.5. Using the Block1 Option
In a request with a request payload (e.g., PUT or POST), the Block1 In a request with a request payload (e.g., PUT or POST), the Block1
Option refers to the payload in the request (descriptive usage). Option refers to the payload in the request (descriptive usage).
In response to a request with a payload (e.g., a PUT or POST In response to a request with a payload (e.g., a PUT or POST
transfer), the block size given in the Block1 Option indicates the transfer), the block size given in the Block1 Option indicates the
block size preference of the server for this resource (control block size preference of the server for this resource (control
usage). Obviously, at this point the first block has already been usage). Obviously, at this point the first block has already been
transferred by the client without benefit of this knowledge. Still, transferred by the client without benefit of this knowledge. Still,
the client SHOULD heed the preference and, for all further blocks, the client SHOULD heed the preference and, for all further blocks,
use the block size preferred by the server or a smaller one. Note use the block size preferred by the server or a smaller one. Note
skipping to change at page 12, line 42 skipping to change at page 11, line 51
has been reached, and try restating the request as a block-wise has been reached, and try restating the request as a block-wise
transfer with a smaller payload. Note that this new attempt is then transfer with a smaller payload. Note that this new attempt is then
a new message-layer transaction and requires a new Message ID. a new message-layer transaction and requires a new Message ID.
(Because of the uncertainty whether the request or the (Because of the uncertainty whether the request or the
acknowledgement was lost, this strategy is useful mostly for acknowledgement was lost, this strategy is useful mostly for
idempotent requests.) idempotent requests.)
In a blockwise transfer of a request payload (e.g., a PUT or POST) In a blockwise transfer of a request payload (e.g., a PUT or POST)
that is intended to be implemented in an atomic fashion at the that is intended to be implemented in an atomic fashion at the
server, the actual creation/replacement takes place at the time the server, the actual creation/replacement takes place at the time the
final block, i.e. a block with the M bit unset in the Block1 Option, final block, i.e. a block with the M bit unset in the Block1 Option,
is received. If not all previous blocks are available at the server is received. If not all previous blocks are available at the server
at this time, the transfer fails and error code 4.08 (Request Entity at this time, the transfer fails and error code 4.08 (Request Entity
Incomplete) MUST be returned. The error code 4.13 (Request Entity Incomplete) MUST be returned. The error code 4.13 (Request Entity
Too Large) can be returned at any time by a server that does not Too Large) can be returned at any time by a server that does not
currently have the resources to store blocks for a block-wise request currently have the resources to store blocks for a block-wise request
payload transfer that it would intend to implement in an atomic payload transfer that it would intend to implement in an atomic
fashion. (Note that a 4.13 response to a request that does not fashion. (Note that a 4.13 response to a request that does not
employ Block1 is a hint for the client to try sending Block1, and a employ Block1 is a hint for the client to try sending Block1, and a
4.13 response with a smaller SZX in the Block1 than requested is a 4.13 response with a smaller SZX in its Block1 option than requested
hint to try a smaller SZX.) is a hint to try a smaller SZX.)
Note that there is no way to perform multiple concurrently proceeding The Block1 option provides no way for a single endpoint to perform
block-wise request payload transfer (e.g., PUT or POST) operations to multiple concurrently proceeding block-wise request payload transfer
the same URI. Starting a new block-wise sequence of requests to the (e.g., PUT or POST) operations to the same resource. Starting a new
same URI (before an old sequence from the same endpoint was finished) block-wise sequence of requests to the same resource (before an old
simply overwrites the context the server may still be keeping. (This sequence from the same endpoint was finished) simply overwrites the
is probably exactly what one wants in this case - the client may context the server may still be keeping. (This is probably exactly
simply have restarted and lost its knowledge of the previous what one wants in this case - the client may simply have restarted
sequence.) and lost its knowledge of the previous sequence.)
2.6. Combining Blockwise Transfers with the Observe Option
The Observe Option provides a way for a client to be notified about
changes over time of a resource [I-D.ietf-core-observe]. Resources
observed by clients may be larger than can be comfortably processed
or transferred in one CoAP message. The following rules apply to the
combination of blockwise transfers with notifications.
As with basic GET transfers, the client can indicate its desired
block size in a Block2 Option in the GET request. If the server
supports blockwise transfers, it SHOULD take note of the block size
and apply it as a maximum size to all notifications/responses
resulting from the GET request (until the client is removed from the
list of observers or the server receives a new GET request for the
resource from the client).
When sending a 2.05 (Content) notification, the server always sends
all blocks of the representation, suitably sequenced by its
congestion control mechanism, even if only some of the blocks have
changed with respect to a previous notification. The server performs
the blockwise transfer by making use of the Block2 Option in each
block. When reassembling representations that are transmitted in
multiple blocks, the client MUST NOT combine blocks carrying
different Observe Option values.
Blockwise transfers of notifications MUST use Confirmable messages
and MUST NOT use Non-confirmable messages.
See Section 3.4 for examples.
2.7. Block2 and Initiative
In a basic block-wise GET request, it is the job of the client to
initiate each further block transfer. We say that the "initiative"
is with the client. If no buffering of a snapshot of the resource is
required, the server can stay entirely stateless. This is
particularly useful for very simple servers for which all resources
that are big enough to merit block-wise transfer are static (such as
the links in "/.well-known/core").
However, when Block2 is combined with Observe or Block1, this simple
approach no longer works very well. Therefore, the presence of an
Observe or Block1 option in combination with a Block2 option is said
to reverse the initiative: From then on, it is the job of the server
to provide additional responses that complete the blockwise transfer
of the notification (Observe) or response to a block-wise PUT or POST
transfer (Block1). As all these additional responses are in response
to the single request that caused them, they all carry the token of
this request: The GET with an Observe option, or the PUT/POST with a
Block1 option.
(For the request side of block-wise transfers that use the Block1
option, it is of course always the initiative of the client to send
the next block - which is quite natural, as the client has to
generate them and therefore knows when it is time to send the next
block.)
3. Examples 3. Examples
This section gives a number of short examples with message flows for This section gives a number of short examples with message flows for
a block-wise GET, and for a PUT or POST. These examples demonstrate a block-wise GET, and for a PUT or POST. These examples demonstrate
the basic operation, the operation in the presence of the basic operation, the operation in the presence of
retransmissions, and examples for the operation of the block size retransmissions, and examples for the operation of the block size
negotiation. negotiation.
In all these examples, a Block option is shown in a decomposed way In all these examples, a Block option is shown in a decomposed way
separating the kind of Block option (1 or 2), block number (NUM), indicating the kind of Block option (1 or 2) followed by a colon, and
more bit (M), and block size exponent (2**(SZX+4)) by slashes. E.g., then the block number (NUM), more bit (M), and block size exponent
a Block2 Option value of 33 would be shown as 2/2/0/32), or a Block1 (2**(SZX+4)) separated by slashes. E.g., a Block2 Option value of 33
Option value of 59 would be shown as 1/3/1/128. would be shown as 2:2/0/32), or a Block1 Option value of 59 would be
shown as 1:3/1/128.
3.1. Block2 Examples
The first example (Figure 2) shows a GET request that is split into The first example (Figure 2) shows a GET request that is split into
three blocks. The server proposes a block size of 128, and the three blocks. The server proposes a block size of 128, and the
client agrees. The first two ACKs contain 128 bytes of payload each, client agrees. The first two ACKs contain 128 bytes of payload each,
and third ACK contains between 1 and 128 bytes. and third ACK contains between 1 and 128 bytes.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], GET, /status ------> | | CON [MID=1234], GET, /status ------> |
| | | |
| <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | | <------ ACK [MID=1234], 2.05 Content, 2:0/1/128 |
| | | |
| CON [MID=1235], GET, /status, 2/1/0/128 ------> | | CON [MID=1235], GET, /status, 2:1/0/128 ------> |
| | | |
| <------ ACK [MID=1235], 2.05 Content, 2/1/1/128 | | <------ ACK [MID=1235], 2.05 Content, 2:1/1/128 |
| | | |
| CON [MID=1236], GET, /status, 2/2/0/128 ------> | | CON [MID=1236], GET, /status, 2:2/0/128 ------> |
| | | |
| <------ ACK [MID=1236], 2.05 Content, 2/2/0/128 | | <------ ACK [MID=1236], 2.05 Content, 2:2/0/128 |
Figure 2: Simple blockwise GET Figure 2: Simple blockwise GET
In the second example (Figure 3), the client anticipates the In the second example (Figure 3), the client anticipates the
blockwise transfer (e.g., because of a size indication in the link- blockwise transfer (e.g., because of a size indication in the link-
format description [RFC6690]) and sends a size proposal. All ACK format description [RFC6690]) and sends a size proposal. All ACK
messages except for the last carry 64 bytes of payload; the last one messages except for the last carry 64 bytes of payload; the last one
carries between 1 and 64 bytes. carries between 1 and 64 bytes.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], GET, /status, 2/0/0/64 ------> | | CON [MID=1234], GET, /status, 2:0/0/64 ------> |
| | | |
| <------ ACK [MID=1234], 2.05 Content, 2/0/1/64 | | <------ ACK [MID=1234], 2.05 Content, 2:0/1/64 |
| | | |
| CON [MID=1235], GET, /status, 2/1/0/64 ------> | | CON [MID=1235], GET, /status, 2:1/0/64 ------> |
| | | |
| <------ ACK [MID=1235], 2.05 Content, 2/1/1/64 | | <------ ACK [MID=1235], 2.05 Content, 2:1/1/64 |
: : : :
: ... : : ... :
: : : :
| CON [MID=1238], GET, /status, 2/4/0/64 ------> | | CON [MID=1238], GET, /status, 2:4/0/64 ------> |
| | | |
| <------ ACK [MID=1238], 2.05 Content, 2/4/1/64 | | <------ ACK [MID=1238], 2.05 Content, 2:4/1/64 |
| | | |
| CON [MID=1239], GET, /status, 2/5/0/64 ------> | | CON [MID=1239], GET, /status, 2:5/0/64 ------> |
| | | |
| <------ ACK [MID=1239], 2.05 Content, 2/5/0/64 | | <------ ACK [MID=1239], 2.05 Content, 2:5/0/64 |
Figure 3: Blockwise GET with early negotiation Figure 3: Blockwise GET with early negotiation
In the third example (Figure 4), the client is surprised by the need In the third example (Figure 4), the client is surprised by the need
for a blockwise transfer, and unhappy with the size chosen for a blockwise transfer, and unhappy with the size chosen
unilaterally by the server. As it did not send a size proposal unilaterally by the server. As it did not send a size proposal
initially, the negotiation only influences the size from the second initially, the negotiation only influences the size from the second
message exchange onward. Since the client already obtained both the message exchange onward. Since the client already obtained both the
first and second 64-byte block in the first 128-byte exchange, it first and second 64-byte block in the first 128-byte exchange, it
goes on requesting the third 64-byte block ("2/0/64"). None of this goes on requesting the third 64-byte block ("2/0/64"). None of this
is (or needs to be) understood by the server, which simply responds is (or needs to be) understood by the server, which simply responds
to the requests as it best can. to the requests as it best can.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], GET, /status ------> | | CON [MID=1234], GET, /status ------> |
| | | |
| <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | | <------ ACK [MID=1234], 2.05 Content, 2:0/1/128 |
| | | |
| CON [MID=1235], GET, /status, 2/2/0/64 ------> | | CON [MID=1235], GET, /status, 2:2/0/64 ------> |
| | | |
| <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | | <------ ACK [MID=1235], 2.05 Content, 2:2/1/64 |
| | | |
| CON [MID=1236], GET, /status, 2/3/0/64 ------> | | CON [MID=1236], GET, /status, 2:3/0/64 ------> |
| | | |
| <------ ACK [MID=1236], 2.05 Content, 2/3/1/64 | | <------ ACK [MID=1236], 2.05 Content, 2:3/1/64 |
| | | |
| CON [MID=1237], GET, /status, 2/4/0/64 ------> | | CON [MID=1237], GET, /status, 2:4/0/64 ------> |
| | | |
| <------ ACK [MID=1237], 2.05 Content, 2/4/1/64 | | <------ ACK [MID=1237], 2.05 Content, 2:4/1/64 |
| | | |
| CON [MID=1238], GET, /status, 2/5/0/64 ------> | | CON [MID=1238], GET, /status, 2:5/0/64 ------> |
| | | |
| <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | | <------ ACK [MID=1238], 2.05 Content, 2:5/0/64 |
Figure 4: Blockwise GET with late negotiation Figure 4: Blockwise GET with late negotiation
In all these (and the following) cases, retransmissions are handled In all these (and the following) cases, retransmissions are handled
by the CoAP message exchange layer, so they don't influence the block by the CoAP message exchange layer, so they don't influence the block
operations (Figure 5, Figure 6). operations (Figure 5, Figure 6).
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], GET, /status ------> | | CON [MID=1234], GET, /status ------> |
| | | |
| <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | | <------ ACK [MID=1234], 2.05 Content, 2:0/1/128 |
| | | |
| CON [MID=1235], GE///////////////////////// | | CON [MID=1235], GE///////////////////////// |
| | | |
| (timeout) | | (timeout) |
| | | |
| CON [MID=1235], GET, /status, 2/2/0/64 ------> | | CON [MID=1235], GET, /status, 2:2/0/64 ------> |
| | | |
| <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | | <------ ACK [MID=1235], 2.05 Content, 2:2/1/64 |
: : : :
: ... : : ... :
: : : :
| CON [MID=1238], GET, /status, 2/5/0/64 ------> | | CON [MID=1238], GET, /status, 2:5/0/64 ------> |
| | | |
| <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | | <------ ACK [MID=1238], 2.05 Content, 2:5/0/64 |
Figure 5: Blockwise GET with late negotiation and lost CON Figure 5: Blockwise GET with late negotiation and lost CON
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], GET, /status ------> | | CON [MID=1234], GET, /status ------> |
| | | |
| <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | | <------ ACK [MID=1234], 2.05 Content, 2:0/1/128 |
| | | |
| CON [MID=1235], GET, /status, 2/2/0/64 ------> | | CON [MID=1235], GET, /status, 2:2/0/64 ------> |
| | | |
| //////////////////////////////////tent, 2/2/1/64 | | //////////////////////////////////tent, 2:2/1/64 |
| | | |
| (timeout) | | (timeout) |
| | | |
| CON [MID=1235], GET, /status, 2/2/0/64 ------> | | CON [MID=1235], GET, /status, 2:2/0/64 ------> |
| | | |
| <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | | <------ ACK [MID=1235], 2.05 Content, 2:2/1/64 |
: : : :
: ... : : ... :
: : : :
| CON [MID=1238], GET, /status, 2/5/0/64 ------> | | CON [MID=1238], GET, /status, 2:5/0/64 ------> |
| | | |
| <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | | <------ ACK [MID=1238], 2.05 Content, 2:5/0/64 |
Figure 6: Blockwise GET with late negotiation and lost ACK Figure 6: Blockwise GET with late negotiation and lost ACK
3.2. Block1 Examples
The following examples demonstrate a PUT exchange; a POST exchange The following examples demonstrate a PUT exchange; a POST exchange
looks the same, with different requirements on atomicity/idempotence. looks the same, with different requirements on atomicity/idempotence.
Note that, similar to GET, the responses to the requests that have a Note that, similar to GET, the responses to the requests that have a
more bit in the request Block1 Option are provisional; only the final more bit in the request Block1 Option are provisional; only the final
response tells the client that the PUT succeeded. response tells the client that the PUT succeeded.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], PUT, /options, 1/0/1/128 ------> | | CON [MID=1234], PUT, /options, 1:0/1/128 ------> |
| | | |
| <------ ACK [MID=1234], 2.04 Changed, 1/0/1/128 | | <------ ACK [MID=1234], 2.04 Changed, 1:0/1/128 |
| | | |
| CON [MID=1235], PUT, /options, 1/1/1/128 ------> | | CON [MID=1235], PUT, /options, 1:1/1/128 ------> |
| | | |
| <------ ACK [MID=1235], 2.04 Changed, 1/1/1/128 | | <------ ACK [MID=1235], 2.04 Changed, 1:1/1/128 |
| | | |
| CON [MID=1236], PUT, /options, 1/2/0/128 ------> | | CON [MID=1236], PUT, /options, 1:2/0/128 ------> |
| | | |
| <------ ACK [MID=1236], 2.04 Changed, 1/2/0/128 | | <------ ACK [MID=1236], 2.04 Changed, 1:2/0/128 |
Figure 7: Simple atomic blockwise PUT Figure 7: Simple atomic blockwise PUT
A stateless server that simply builds/updates the resource in place A stateless server that simply builds/updates the resource in place
(statelessly) may indicate this by not setting the more bit in the (statelessly) may indicate this by not setting the more bit in the
response (Figure 8); in this case, the response codes are valid response (Figure 8); in this case, the response codes are valid
separately for each block being updated. This is of course only an separately for each block being updated. This is of course only an
acceptable behavior of the server if the potential inconsistency acceptable behavior of the server if the potential inconsistency
present during the run of the message exchange sequence does not lead present during the run of the message exchange sequence does not lead
to problems, e.g. because the resource being created or changed is to problems, e.g. because the resource being created or changed is
not yet or not currently in use. not yet or not currently in use.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], PUT, /options, 1/0/1/128 ------> | | CON [MID=1234], PUT, /options, 1:0/1/128 ------> |
| | | |
| <------ ACK [MID=1234], 2.04 Changed, 1/0/0/128 | | <------ ACK [MID=1234], 2.04 Changed, 1:0/0/128 |
| | | |
| CON [MID=1235], PUT, /options, 1/1/1/128 ------> | | CON [MID=1235], PUT, /options, 1:1/1/128 ------> |
| | | |
| <------ ACK [MID=1235], 2.04 Changed, 1/1/0/128 | | <------ ACK [MID=1235], 2.04 Changed, 1:1/0/128 |
| | | |
| CON [MID=1236], PUT, /options, 1/2/0/128 ------> | | CON [MID=1236], PUT, /options, 1:2/0/128 ------> |
| | | |
| <------ ACK [MID=1236], 2.04 Changed, 1/2/0/128 | | <------ ACK [MID=1236], 2.04 Changed, 1:2/0/128 |
Figure 8: Simple stateless blockwise PUT Figure 8: Simple stateless blockwise PUT
Finally, a server receiving a blockwise PUT or POST may want to Finally, a server receiving a blockwise PUT or POST may want to
indicate a smaller block size preference (Figure 9). In this case, indicate a smaller block size preference (Figure 9). In this case,
the client SHOULD continue with a smaller block size; if it does, it the client SHOULD continue with a smaller block size; if it does, it
MUST adjust the block number to properly count in that smaller size. MUST adjust the block number to properly count in that smaller size.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], PUT, /options, 1/0/1/128 ------> | | CON [MID=1234], PUT, /options, 1:0/1/128 ------> |
| | | |
| <------ ACK [MID=1234], 2.04 Changed, 1/0/1/32 | | <------ ACK [MID=1234], 2.04 Changed, 1:0/1/32 |
| | | |
| CON [MID=1235], PUT, /options, 1/4/1/32 ------> | | CON [MID=1235], PUT, /options, 1:4/1/32 ------> |
| | | |
| <------ ACK [MID=1235], 2.04 Changed, 1/4/1/32 | | <------ ACK [MID=1235], 2.04 Changed, 1:4/1/32 |
| | | |
| CON [MID=1236], PUT, /options, 1/5/1/32 ------> | | CON [MID=1236], PUT, /options, 1:5/1/32 ------> |
| | | |
| <------ ACK [MID=1235], 2.04 Changed, 1/5/1/32 | | <------ ACK [MID=1235], 2.04 Changed, 1:5/1/32 |
| | | |
| CON [MID=1237], PUT, /options, 1/6/0/32 ------> | | CON [MID=1237], PUT, /options, 1:6/0/32 ------> |
| | | |
| <------ ACK [MID=1236], 2.04 Changed, 1/6/0/32 | | <------ ACK [MID=1236], 2.04 Changed, 1:6/0/32 |
Figure 9: Simple atomic blockwise PUT with negotiation Figure 9: Simple atomic blockwise PUT with negotiation
3.3. Combining Block1 and Block2
Block options may be used in both directions of a single exchange. Block options may be used in both directions of a single exchange.
The following example demonstrates a blockwise POST request, The following example demonstrates a blockwise POST request,
resulting in a separate blockwise response. resulting in a separate blockwise response.
CLIENT SERVER CLIENT SERVER
| | | |
| CON [MID=1234], POST, /soap, 1/0/1/128 ------> | | CON [MID=1234], POST, /soap, 1:0/1/128 ------> |
| | | |
| <------ ACK [MID=1234], 2.01 Created, 1/0/1/128 | | <------ ACK [MID=1234], 2.01 Created, 1:0/1/128 |
| | | |
| CON [MID=1235], POST, /soap, 1/1/1/128 ------> | | CON [MID=1235], POST, /soap, 1:1/1/128 ------> |
| | | |
| <------ ACK [MID=1235], 2.01 Created, 1/1/1/128 | | <------ ACK [MID=1235], 2.01 Created, 1:1/1/128 |
| | | |
| CON [MID=1236], POST, /soap, 1/2/0/128 ------> | | CON [MID=1236], POST, /soap, 1:2/0/128 ------> |
| | | |
| <------ ACK [MID=1236], 0, 1/2/0/128 | | <------ ACK [MID=1236], 2.01 Created, 2:0/1/128, 1:2/0/128 |
| | | |
| <------ CON [MID=4712], 2.01 Created, 2/0/1/128 | | (initiative changes to server) |
| | | |
| ACK [MID=4712], 0, 2/0/1/128 ------> | | <------ CON [MID=4713], 2.01 Created, 2:1/1/128 |
| | | |
| <------ CON [MID=4713], 2.01 Created, 2/1/1/128 | | ACK [MID=4713], 0 ------> |
| | | |
| ACK [MID=4713], 0, 2/1/1/128 ------> | | <------ CON [MID=4714], 2.01 Created, 2:2/1/128 |
| | | |
| <------ CON [MID=4714], 2.01 Created, 2/2/1/128 | | ACK [MID=4714], 0 ------> |
| | | |
| ACK [MID=4714], 0, 2/2/1/128 ------> | | <------ CON [MID=4715], 2.01 Created, 2:3/0/128 |
| | | |
| <------ CON [MID=4715], 2.01 Created, 2/3/0/128 | | ACK [MID=4715], 0 ------> |
| |
| ACK [MID=4715], 0, 2/3/0/128 ------> |
Figure 10: Atomic blockwise POST with separate blockwise response Figure 10: Atomic blockwise POST with separate blockwise response
This model does provide for early negotiation input to the Block2
blockwise transfer, as shown below. (However, there is no way to
provide late negotiation with server initiative.)
CLIENT SERVER
| |
| CON [MID=1234], POST, /soap, 1:0/1/128 ------> |
| |
| <------ ACK [MID=1234], 2.01 Created, 1:0/1/128 |
| |
| CON [MID=1235], POST, /soap, 1:1/1/128 ------> |
| |
| <------ ACK [MID=1235], 2.01 Created, 1:1/1/128 |
| |
| CON [MID=1236], POST, /soap, 1:2/0/128, 2:0/0/64 ------> |
| |
| <------ ACK [MID=1236], 2.01 Created, 1:2/0/128, 2:0/1/64 |
| |
| (initiative changes to server) |
| |
| <------ CON [MID=4713], 2.01 Created, 2:1/1/64 |
| |
| ACK [MID=4713], 0 ------> |
| |
| <------ CON [MID=4714], 2.01 Created, 2:2/1/64 |
| |
| ACK [MID=4714], 0 ------> |
| |
| <------ CON [MID=4715], 2.01 Created, 2:3/0/64 |
| |
| ACK [MID=4715], 0 ------> |
Figure 11: Atomic blockwise POST with separate blockwise response,
early negotiation
3.4. Combining Observe and Block2
In the following example, the server sends two notifications of two
blocks each. The first notification is a direct response to the GET
request; the first block therefore can be sent piggy-backed in the
ACK. The Observe Option indicates that the initiative has switched
to the server.
CLIENT SERVER
| |
+----->| Header: GET 0x41011636
| GET | Token: 0xfb
| | Uri-Path: status-icon
| | Observe: (empty)
| |
|<-----+ Header: 2.05 0x61451636
| 2.05 | Token: 0xfb
| | Block2: 0/1/128
| | Observe: 62354
| | Max-Age: 60
| | Payload: [128 bytes]
| |
| | (initiative changes to server)
| |
|<-----+ Header: 2.05 0x4145af9c
| 2.05 | Token: 0xfb
| | Block2: 1/0/128
| | Observe: 62354
| | Max-Age: 60
| | Payload: [27 bytes]
| |
+- - ->| Header: 0x6000af9c
| |
|<-----+ Header: 2.05 0x4145af9d
| 2.05 | Token: 0xfb
| | Block2: 0/1/128
| | Observe: 62444
| | Max-Age: 60
| | Payload: [128 bytes]
| |
+- - ->| Header: 0x6000af9d
| |
|<-----+ Header: 2.05 0x4145af9e
| 2.05 | Token: 0xfb
| | Block2: 1/0/128
| | Observe: 62444
| | Max-Age: 60
| | Payload: [27 bytes]
| |
+- - ->| Header: 0x6000af9e
| |
Figure 12: Observe sequence with blockwise response
In the following example, the client also uses early negotiation to
limit the block size to 64 bytes.
CLIENT SERVER
| |
+----->| Header: GET 0x41011636
| GET | Token: 0xfb
| | Uri-Path: status-icon
| | Observe: (empty)
| | Block2: 0/0/64
| |
|<-----+ Header: 2.05 0x61451636
| 2.05 | Token: 0xfb
| | Block2: 0/1/64
| | Observe: 62354
| | Max-Age: 60
| | Payload: [64 bytes]
| |
| | (initiative changes to server)
| |
|<-----+ Header: 2.05 0x4145af9c
| 2.05 | Token: 0xfb
| | Block2: 1/1/64
| | Observe: 62354
| | Max-Age: 60
| | Payload: [64 bytes]
| |
+- - ->| Header: 0x6000af9c
| |
|<-----+ Header: 2.05 0x4145af9d
| 2.05 | Token: 0xfb
| | Block2: 2/0/64
| | Observe: 62354
| | Max-Age: 60
| | Payload: [27 bytes]
| |
+- - ->| Header: 0x6000af9d
| |
|<-----+ Header: 2.05 0x4145af9e
| 2.05 | Token: 0xfb
| | Block2: 0/1/64
| | Observe: 62444
| | Max-Age: 60
| | Payload: [128 bytes]
| |
+- - ->| Header: 0x6000af9e
| |
|<-----+ Header: 2.05 0x4145af9f
| 2.05 | Token: 0xfb
| | Block2: 1/1/64
| | Observe: 62444
| | Max-Age: 60
| | Payload: [128 bytes]
| |
+- - ->| Header: 0x6000af9f
| |
|<-----+ Header: 2.05 0x4145afa0
| 2.05 | Token: 0xfb
| | Block2: 2/0/64
| | Observe: 62444
| | Max-Age: 60
| | Payload: [27 bytes]
| |
+- - ->| Header: 0x6000afa0
| |
Figure 13: Observe sequence with early negotiation
4. The Size Option 4. The Size Option
In many cases when transferring a large resource representation block In many cases when transferring a large resource representation block
by block, it is advantageous to know the total size early in the by block, it is advantageous to know the total size early in the
process. Some indication may be available from the maximum size process. Some indication may be available from the maximum size
estimate attribute "sz" provided in a resource description [RFC6690]. estimate attribute "sz" provided in a resource description [RFC6690].
However, the size may vary dynamically, so a more up-to-date However, the size may vary dynamically, so a more up-to-date
indication may be useful. indication may be useful.
The Size Option may be used for three purposes: The Size Option may be used for three purposes:
skipping to change at page 25, line 43 skipping to change at page 27, line 4
A stateless server might be susceptible to an attack where the A stateless server might be susceptible to an attack where the
adversary sends a Block1 (e.g., PUT) block with a high block number: adversary sends a Block1 (e.g., PUT) block with a high block number:
A naive implementation might exhaust its resources by creating a huge A naive implementation might exhaust its resources by creating a huge
resource representation. resource representation.
Misleading size indications may be used by an attacker to induce Misleading size indications may be used by an attacker to induce
buffer overflows in poor implementations, for which the usual buffer overflows in poor implementations, for which the usual
considerations apply. considerations apply.
7.1. Mitigating Resource Exhaustion Attacks 7.1. Mitigating Resource Exhaustion Attacks
Certain blockwise requests may induce the server to create state, Certain blockwise requests may induce the server to create state,
e.g. to create a snapshot for the blockwise GET of a fast-changing e.g. to create a snapshot for the blockwise GET of a fast-changing
resource to enable consistent access to the same version of a resource to enable consistent access to the same version of a
resource for all blocks, or to create temporary resource resource for all blocks, or to create temporary resource
representations that are collected until pressed into service by a representations that are collected until pressed into service by a
final PUT or POST with the more bit unset. All mechanisms that final PUT or POST with the more bit unset. All mechanisms that
induce a server to create state that cannot simply be cleaned up induce a server to create state that cannot simply be cleaned up
create opportunities for denial-of-service attacks. Servers SHOULD create opportunities for denial-of-service attacks. Servers SHOULD
avoid being subject to resource exhaustion based on state created by avoid being subject to resource exhaustion based on state created by
untrusted sources. But even if this is done, the mitigation may untrusted sources. But even if this is done, the mitigation may
cause a denial-of-service to a legitimate request when it is drowned cause a denial-of-service to a legitimate request when it is drowned
out by other state-creating requests. Wherever possible, servers out by other state-creating requests. Wherever possible, servers
should therefore minimize the opportunities to create state for should therefore minimize the opportunities to create state for
untrusted sources, e.g. by using stateless approaches. untrusted sources, e.g. by using stateless approaches.
Performing segmentation at the application layer is almost always Performing segmentation at the application layer is almost always
better in this respect than at the transport layer or lower (IP better in this respect than at the transport layer or lower (IP
fragmentation, adaptation layer fragmentation), e.g. because there is fragmentation, adaptation layer fragmentation), e.g. because there
application layer semantics that can be used for mitigation or is application layer semantics that can be used for mitigation or
because lower layers provide security associations that can prevent because lower layers provide security associations that can prevent
attacks. However, it is less common to apply timeouts and keepalive attacks. However, it is less common to apply timeouts and keepalive
mechanisms at the application layer than at lower layers. Servers mechanisms at the application layer than at lower layers. Servers
MAY want to clean up accumulated state by timing it out (cf. response MAY want to clean up accumulated state by timing it out (cf.
code 4.08), and clients SHOULD be prepared to run blockwise transfers response code 4.08), and clients SHOULD be prepared to run blockwise
in an expedient way to minimize the likelihood of running into such a transfers in an expedient way to minimize the likelihood of running
timeout. into such a timeout.
7.2. Mitigating Amplification Attacks 7.2. Mitigating Amplification Attacks
[I-D.ietf-core-coap] discusses the susceptibility of CoAP end-points [I-D.ietf-core-coap] discusses the susceptibility of CoAP end-points
for use in amplification attacks. for use in amplification attacks.
A CoAP server can reduce the amount of amplification it provides to A CoAP server can reduce the amount of amplification it provides to
an attacker by offering large resource representations only in an attacker by offering large resource representations only in
relatively small blocks. With this, e.g., for a 1000 byte resource, relatively small blocks. With this, e.g., for a 1000 byte resource,
a 10-byte request might result in an 80-byte response (with a 64-byte a 10-byte request might result in an 80-byte response (with a 64-byte
skipping to change at page 27, line 18 skipping to change at page 28, line 8
the [I-D.ietf-core-coap] authors, and via many CoRE WG discussions. the [I-D.ietf-core-coap] authors, and via many CoRE WG discussions.
Charles Palmer provided extensive editorial comments to a previous Charles Palmer provided extensive editorial comments to a previous
version of this draft, some of which the authors hope to have covered version of this draft, some of which the authors hope to have covered
in this version. Esko Dijk reviewed a more recent version, leading in this version. Esko Dijk reviewed a more recent version, leading
to a number of further editorial improvements as well as a solution to a number of further editorial improvements as well as a solution
to the 4.13 ambiguity problem. Markus Becker proposed getting rid of to the 4.13 ambiguity problem. Markus Becker proposed getting rid of
an ill-conceived default value for the Block2 and Block1 options. an ill-conceived default value for the Block2 and Block1 options.
Kepeng Li, Linyi Tian, and Barry Leiba wrote up an early version of Kepeng Li, Linyi Tian, and Barry Leiba wrote up an early version of
the Size Option, which has informed this draft. the Size Option, which has informed this draft. Klaus Hartke wrote
some of the text describing the interaction of Block2 with Observe.
9. References 9. References
9.1. Normative References 9.1. Normative References
[I-D.ietf-core-coap] [I-D.ietf-core-coap]
Shelby, Z., Hartke, K., Bormann, C., and B. Frank, Shelby, Z., Hartke, K., and C. Bormann, "Constrained
"Constrained Application Protocol (CoAP)", Application Protocol (CoAP)", draft-ietf-core-coap-14
draft-ietf-core-coap-12 (work in progress), October 2012. (work in progress), March 2013.
[I-D.ietf-core-observe]
Hartke, K., "Observing Resources in CoAP", draft-ietf-
core-observe-08 (work in progress), February 2013.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997. Requirement Levels", BCP 14, RFC 2119, March 1997.
[RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
9.2. Informative References 9.2. Informative References
[REST] Fielding, R., "Architectural Styles and the Design of [REST] Fielding, R., "Architectural Styles and the Design of
Network-based Software Architectures", Ph.D. Dissertation, Network-based Software Architectures", Ph.D. Dissertation,
University of California, Irvine, 2000, <http:// University of California, Irvine, 2000, <http://
www.ics.uci.edu/~fielding/pubs/dissertation/ www.ics.uci.edu/~fielding/pubs/dissertation/
fielding_dissertation.pdf>. fielding_dissertation.pdf>.
[RFC4919] Kushalnagar, N., Montenegro, G., and C. Schumacher, "IPv6 [RFC4919] Kushalnagar, N., Montenegro, G., and C. Schumacher, "IPv6
over Low-Power Wireless Personal Area Networks (6LoWPANs): over Low-Power Wireless Personal Area Networks (6LoWPANs):
Overview, Assumptions, Problem Statement, and Goals", Overview, Assumptions, Problem Statement, and Goals", RFC
RFC 4919, August 2007. 4919, August 2007.
[RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link
Format", RFC 6690, August 2012. Format", RFC 6690, August 2012.
Authors' Addresses Authors' Addresses
Carsten Bormann Carsten Bormann
Universitaet Bremen TZI Universitaet Bremen TZI
Postfach 330440 Postfach 330440
Bremen D-28359 Bremen D-28359
 End of changes. 100 change blocks. 
197 lines changed or deleted 446 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/