IoT Application Layer Protocols -19!2!25
IoT Application Layer Protocols -19!2!25
Figure 2.19: Example of a High-Level IoT Protocol Stack for CoAP and MQTT
In Figure 2.19, CoAP and MQTT are naturally at the top of this sample IoT stack,
based on an IEEE 802.15.4 mesh network. While there are a few exceptions, you
will almost always find CoAP deployed over UDP and MQTT running over TCP. The
following sections take a deeper look at CoAP and MQTT.
CoAP
Constrained Application Protocol (CoAP) resulted from the IETF Constrained
RESTful Environments (CoRE) working group’s efforts to develop a generic
framework for resource-oriented applications targeting constrained nodes and
networks. The CoAP framework defines simple and flexible ways to manipulate
sensors and actuators for data or device management.
The CoAP messaging model is primarily designed to facilitate the exchange of
messages over UDP between endpoints, including the secure transport protocol
Datagram Transport Layer Security (DTLS).
From a formatting perspective, a CoAP message is composed of a short fixed-
length Header field (4 bytes), a variable-length but mandatory Token field (0–8
bytes), Options fields if necessary, and the Payload field. Figure 2.20 details the
CoAP message format, which delivers low overhead while decreasing parsing
complexity.
Figure 2.20: CoAP Message Format
The CoAP message format is relatively simple and flexible. It allows CoAP to
deliver low overhead, which is critical for constrained networks, while also being
easy to parse and process for constrained devices.
Table 2.4 CoAP Message Fields
CoAP can run over IPv4 or IPv6. However, it is recommended that the message fit
within a single IP packet and UDP payload to avoid fragmentation. For IPv6, with
the default MTU size being 1280 bytes and allowing for no fragmentation across
nodes, the maximum CoAP message size could be up to 1152 bytes, including
1024 bytes for the payload. In the
case of IPv4, as IP fragmentation may exist across the network, implementations
should limit themselves to more conservative values and set the IPv4 Don’t
Fragment (DF) bit.
CoAP communications across an IoT infrastructure can take various paths.
Connections can be between devices located on the same or different
constrained networks or between devices and generic Internet or cloud servers,
all operating over IP. Proxy mechanisms are also defined, and RFC 7252 details a
basic HTTP mapping for CoAP. As both HTTP and CoAP are IP-based protocols, the
proxy function can be located practically anywhere in the network, not
necessarily at the border between constrained and non-constrained networks.