Application Protocols

For the Internet of Things

Patrick Barrett / Applications Engineer

But First

Who dat?

IP
Internet Protocol
TCP
Transmittion Control Protocol
UDP
User Datagram Protocol

Uh... The Internet? (Protocol)

  • The Foundation of the Internet
  • Packets
  • IP Addresses Live Here

- -·-· ·--·

  • Connection Establishment
  • Stream Protocol
    • Handles Packetizing Data
    • Data will be Delivered in Order
  • Data Will be Delivered
  • Automatically Retries
  • Every Bit Will be Exactly as it was Sent
  • Flow and Congestion Control
  • Port Numbers

A Friend of the Users

  • Connection Establishment
  • Stream Protocol
    • Handles Packetizing Data
    • Data will be Delivered in Order
  • Data Will be Delivered
  • Automatically Retries
  • Every Bit Will be Exactly as it was Sent
  • Flow and Congestion Control
  • Port Numbers

Bored Yet?

Client-Server :: Request-Response
The Architecture of the Internet
NAT
Network Address Translation
Firewall
A Wall of Fire (Duh)

Gimme! - Okay, here.

  1. Something Happens
  2. Client Asks Server for Resource
  3. Server Processes
  4. Server Sends Resource to Client
  5. GOTO 1

Hold Out Your Hand for a Stamp

  • Firewall ≈ NAT
  • Connections Are Stateful
    • Even for UDP
  • Packets Go Out, But they Don't Come In
    • Unless One of their Friends Just Left

Wait What Was this Talk About?

Better than a Wigwam

  • TCP
  • Client-Server
  • Request-Response
  • Text-Based
    • Easy to Read
  • Extensible

Get it? It rhymes with TiPi


POST /api:v1/stack/alias HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 7

temp=26
					

HTTP/1.1 204 No Content
Date: Thu, 05 Mar 2015 18:00:44 GMT
Content-Length: 0
Server: nginx

 
					

GET Back you Monster


GET /api:v1/stack/alias?temp HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909
Accept: application/x-www-form-urlencoded; charset=utf-8

 
					

HTTP/1.1 200 OK
Date: Tue, 25 Aug 2015 05:43:42 GMT
Server: nginx
Connection: Close
Content-Length: 7

temp=26
					

Don't Call it a Hack


GET /api:v1/stack/alias?temp HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909
Accept: application/x-www-form-urlencoded; charset=utf-8
Request-Timeout: 300000
If-Modified-Since: 1440481217

 
					

HTTP/1.1 200 OK
Date: Tue, 25 Aug 2015 05:43:42 GMT
Server: nginx
Connection: Close
Content-Length: 7
Last-Modified: Tue, 25 Aug 2015 05:43:42 GMT

temp=26
					

Surely OP Will Deliver


GET /api:v1/stack/alias?temp HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909
Accept: application/x-www-form-urlencoded; charset=utf-8
Request-Timeout: 300000
If-Modified-Since: 1440481217

 
					

HTTP/1.1 304 Not Modified
Date: Tue, 25 Aug 2015 05:45:17 GMT
Server: nginx
Connection: Close

 
					

Bla, Bla, Bla


POST /api:v1/stack/alias HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 7

temp=26
					

HTTP/1.1 204 No Content
Date: Thu, 05 Mar 2015 18:00:44 GMT
Content-Length: 0
Server: nginx

 
					

Let Me Make that Look Worse


00000000: 50 4F 53 54 20 2F 61 70  69 3A 76 31 2F 73 74 61  POST /api:v1/sta
00000010: 63 6B 2F 61 6C 69 61 73  20 48 54 54 50 2F 31 2E  ck/alias HTTP/1.
00000020: 31 0A 48 6F 73 74 3A 20  6D 32 2E 65 78 6F 73 69  1.Host: m2.exosi
00000030: 74 65 2E 63 6F 6D 0A 58  2D 45 78 6F 73 69 74 65  te.com.X-Exosite
00000040: 2D 43 49 4B 3A 20 61 33  32 63 38 35 62 61 39 64  -CIK: a32c85ba9d
00000050: 64 61 34 35 38 32 33 62  65 34 31 36 32 34 36 63  da45823be416246c
00000060: 66 38 62 34 33 33 62 61  61 30 36 38 64 37 0A 43  f8b433baa068d7.C
00000070: 6F 6E 74 65 6E 74 2D 54  79 70 65 3A 20 61 70 70  ontent-Type: app
00000080: 6C 69 63 61 74 69 6F 6E  2F 78 2D 77 77 77 2D 66  lication/x-www-f
00000090: 6F 72 6D 2D 75 72 6C 65  6E 63 6F 64 65 64 3B 20  orm-urlencoded;
000000A0: 63 68 61 72 73 65 74 3D  75 74 66 2D 38 0A 43 6F  charset=utf-8.Co
000000B0: 6E 74 65 6E 74 2D 4C 65  6E 67 74 68 3A 20 37 0A  ntent-Length: 7.
000000C0: 0A 74 65 6D 70 3D 32 36                           .temp=26
					

00000000: 48 54 54 50 2f 31 2e 31 20 32 30 34 20 4e 6f 20  HTTP.....2.4.No.
00000010: 43 6f 6e 74 65 6e 74 44 61 74 65 3a 20 54 68 75  ContentDate:.Thu
00000020: 2c 20 30 35 20 4d 61 72 20 32 30 31 35 20 31 38  ...5.Mar.2..5..8
00000030: 3a 30 30 3a 34 34 20 47 4d 54 43 6f 6e 74 65 6e  :..:44.GMTConten
00000040: 74 2d 4c 65 6e 67 74 68 3a 20 30 53 65 72 76 65  t.Length:..Serve
00000050: 72 3a 20 6e 67 69 6e 78 20 20                    r:.nginx..
					

Yo!


00000000: 40 01 00 37 B2 31 61 04  74 65 6D 70 4D 07 A3 2C  @..7.1a.tempM..,
00000010: 85 BA 9D DA 45 82 3B E4  16 24 6C F8 B4 33 BA A0  ....E.;..$l..3..
00000020: 68 D7                                             h.
					

00000000: 60 44 00 37                                       `D.7
					

The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained (e.g., low-power, lossy) networks. The nodes often have 8-bit microcontrollers with small amounts of ROM and RAM, while constrained networks such as IPv6 over Low-Power Wireless Personal Area Networks (6LoWPANs) often have high packet error rates and a typical throughput of 10s of kbit/s. The protocol is designed for machine- to-machine (M2M) applications such as smart energy and building automation.

CoAP provides a request/response interaction model between application endpoints, supports built-in discovery of services and resources, and includes key concepts of the Web such as URIs and Internet media types. CoAP is designed to easily interface with HTTP for integration with the Web while meeting specialized requirements such as multicast support, very low overhead, and simplicity for constrained environments.

RFC7252

Wait, what‽

Like HTTP, but...

  • UDP
  • Client-Server
    • And More
  • Request-Response
    • And More
  • Binary (ie. Small)
    • Really Easy to Parse
  • Well-Defined *
  • Extensible

It's Full of Bits


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 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Ver| T |  TKL  |      Code     |          Message ID           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
					

B2? You Sunk my Battleship


00000000: 40 01 00 37 B2 31 61 04  74 65 6D 70 4D 07 A3 2C  @..7.1a.tempM..,
00000010: 85 BA 9D DA 45 82 3B E4  16 24 6C F8 B4 33 BA A0  ....E.;..$l..3..
00000020: 68 D7                                             h.
					

00000000: 60 44 00 37                                       `D.7
					

Goodnight Moon

Do a Flip

Meep Meep

Don't Drink the Kool-Aid

  • It's New
  • It's Still Evolving
  • DTLS
  • More Complicated
  • Needs More Tooling

Fight!

  • MQTT
  • XMPP

FIN

Other Cool Things About CoAP That I Don't Know Much About and Aren't Really Relevant

  • Multicast & Group Communication
  • Resource Discovery
  • 6LoWPAN, Thread, BLE, etc.