CoAP Protocol
Background of COAP
• GOAL: to enable web based services in constrained
wireless networks
• Limited memory
• low‐power networks
• Problem: WEB based solutions are hard to implement in
the constrained network
• solution : re‐design web‐based services for constrained
networks using COAP
CoAP/overview
• Very small footprint, RAM, ROM
• URI (Uniform Resource Identifier)
• User-agent/plugin for Firefox Copper (Cu), ETH
• ETSI test (2012)
• RESTful client-server. Compare http:
• Resource Discovery
• UDP
• Proxy and Caching is simple
Introduction
• CoAP (Constrained Application Protocol) is designed for
simplicity, low overhead and multicast support in
resource-constrained environments.
• CoAP is a web protocol that runs over the UDP for IoT
• A variant of HTTP
• Designed to be used with constrained nodes and lossy
networks
• Built-in resource discovery and observation (“push
notification”)
• Block-wise transfer
CoAP/message types
• Comfirmable message
• Non-comfirmable message
• Ack message
• Reset message
• Piggy-backed
• Seprate
CoAP/transport
• Default UDP but required
• DTLS (Datagram TLS)
• TCP SCTP is discussed
• UDP Port 5683 (mandatory)
• UDP Ports 61616-61631 compressed 6lowPAN
CoAP: Message Format
CoAP/protocol header
The fields in the header are defined as follows:
Version (Ver): 2-bit unsigned integer. Indicates the CoAP version number.
Implementations of this specification MUST set this field to 1. Other values are
reserved for future versions.
Type (T): 2-bit unsigned integer. Indicates if this message is of type Confirmable (0),
Non-Confirmable (1), Acknowledgement (2) or Reset (3). See Section 4 for the
semantics of these message types.
Option Count (TKL): 4-bit unsigned integer. Indicates the number of options after the
header (0-14). If set to 0, there are no options and the payload (if any) immediately
follows the header. If set to 15, then an end-of-options marker is used to indicate the
end of options and the start of the payload. The format of options is defined below.
CoAP/pkt-size
• Message size
• Must fit in a single IP datagram
• Default MTU 1280 bytes
• 6LOWPAN 127 bytes
• WSN based on IEEE 802.15.4 127 bytes
COAP Messaging Basics
• Transport:
• (mainly) UDP binding
• Message Exchange between Endpoints
• Messages with 4 bytes header (shared by request and
responses) containing a message ID (16 bits)
• Reliable exchange through Confirmable Messages which
must be acknowledged (through ACK or Reset Messages).
• Simple Stop-and-Wait retransmission with exponential
backoff.
• Unreliable exchange through Non-Confirmable Message
• Duplicate detection for both confirmable and non-
confirmable messages (through message ID)
CoAP: Messaging Model
• Short fixed-length binary header (4bytes)
• Messages must fit in a single IP datagram
• Default IP: 1280bytes,
• 6LoWPAN and IEEE802.15.4 127bytes
• Messages can be confirmable (CON) or non confirmable (NON).
• Naturally runs over UDP and supports :
• multicast IP destination addresses
• DTLS security
• Piggy-backed REST request/response
• The response to a CON message is carried in the ACK
• Request methods: GET, PUT, POST, and DELETE almost as in
HTTP.
COAP Messaging
Request/Response model
CoAP: Sub-layers
CoAP/RESTful
• CoAP Request/Response semantics
• GET, POST, PUT, DELETE
• Easy to map to HTTP
• Cache and Proxy possible
CoAP/URI
coap URI:
coap://example.se:5683/~sensors./temp1.xml
coaps URI:
coaps://myPAN.se/bike/lock
CoAP/Secure
• DTLS (Datagram TLS) RFC4347
• IPSEC alternative
• Key sharing problems
• Resource problems
• Cerificate problems
• Area for work...
CoAP/implementations
• Contiki-2.6 / Erbium
• ETH Zurich
• 8.5 kB ROM
• 1.5 kB RAM
• Linux → libcoap
• TinyOs (libcoap)
• Firefox CoAP Copper Cu plugin – install an test.
• Wikipedia has an upated list. Check it!
CoAP/additional standards
• Blockwise transfers in CoAP (16-1024 bytes)
• draft-ietf-core-block-10
• CoRE Link Format (GET /.well known/core)
• draft-shelby-core-link-format-14
• Observing Resources in CoAP (Observe option)
• draft-ietf-core-observe-07
CoAP/progamming
• Write plain C-code. Socket programming
• libcoap
• Both ways needs some knowledge about CoAP Protocol
• Within MCU OS'es like Contiki or TinyOs etc..
The CoAP Architecture
CoAP Design Requirements
CoAP Features
• Embedded web transfer protocol (coap://)
• Asynchronous transaction model
• UDP binding with reliability and multicast support
• GET, POST, PUT, DELETE methods
• URI support
• Small, simple 4 byte header
• DTLS based PSK, RPK and Certificate security
• Subset of MIME types and HTTP response codes
• Built-in discovery
• Optional observation and block transfer
What CoAP is (and is not)
• Sure, CoAP is
• A very efficient RESTful protocol
• Ideal for constrained devices and networks
• Specialized for M2M applications
• Easy to proxy to/from HTTP
• But, CoAP is not
• A general replacement for HTTP
• HTTP compression
• Restricted to isolated “automation” networks
CoAP: Advantages and Limitations
Advantages:
• Designed for M2M, IoT
• Easily mapped to HTTP, compatible with Proxy infrastructures.
• Easy to map legacy protocols to CoAP
• Extensions: push notifications, discovery and Multicast.
Limitations and work in progress:
• End to end secure connection required for CoAP.
• Securing multicast communications.
• Semantics should be standardized.
• Caching of requests should also be allowed