Application Protocols – For the Internet of Things – FIN ☃



Application Protocols – For the Internet of Things – FIN ☃

0 0


CoAPTalkSlides


On Github Azdle / CoAPTalkSlides

Application Protocols

For the Internet of Things

Patrick Barrett / Applications Engineer

Hello, Me, Questions Audience: What do you want out of this? Engineer, "Lord Business", Hobbyist, C Lang, TCP/UDP

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
TCP is the most commonly used protocol. Positive Acknowledgment

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.

Something Happens Client Asks Server for Resource Server Processes Server Sends Resource to Client GOTO 1 because

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
because

Wait What Was this Talk About?

Oh, right. CoAP. We're actually still not there yet. Lets talk about HTTP first. Who here knows what HTTP is? knows what it looks like? For those that don't it's the protocol that runs the internet these days. (Hey that's the third time I've said that!) If you have a smartphone (and I assume that all of you do) then it has probably made dozens of HTTP calls to some server since I switched to this slide. It looks like this... ->

Better than a Wigwam

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

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

 
					
That may look short and sweet, but there's really a lot going on there just to say that the temperature is 26º. This just happens to be an API call to Exosite's (where I work) simple HTTP data API. Note that I said simple. We stripped out everything that we could to make the data use overhead as small as we could without breaking protocol. Lets look at it in a slightly different way just so we can see every byte that is there. ->

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..
					
That's a lot of bytes when all we're trying to say is "temp=26". So, how do we make this shorter? Well, we could remove some of the headers or make our own aliases for them. Maybe take this Content-Type header and say that our Content-Type is "urlenc". It's a lot shorter, but it's also not going to be understood by any software that wasn't written specfically for our APIs. Not good. So, what's a presenter to do with this obviously leading question? Why show you something much shorter and completely incomprehensible, of course.

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
					
Looking over at the little preview window, it's really not quite as clear what's going on just from looking. We can see somethings in there. Here there's "temp", there there's a "26". Oh, right we were trying to tell the server that temp=26 in the last slide, maybe that's what we're still doing. Yup. This packet contains all the same information and is doing the same thing that the last one did. But this one is using CoAP instead of HTTP. Not bad, we went from a total of NNN bytes for HTTP to just MM bytes for CoAP. So, that's cool. We just did some thing that we were already able to do, but with fewer bytes. Is that all? Just what is this CoAP thing anyway? Well, I'm glad that I'm assuming you're asking that.

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

"web transfer protocol ... low-power .. 8-bit ... low-power again ... M2M"

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
					
Looking over at the little preview window, it's really not quite as clear what's going on just from looking. We can see somethings in there. Here there's "temp", there there's a "26". Oh, right we were trying to tell the server that temp=26 in the last slide, maybe that's what we're still doing. Yup. This packet contains all the same information and is doing the same thing that the last one did. But this one is using CoAP instead of HTTP. Not bad, we went from a total of NNN bytes for HTTP to just MM bytes for CoAP. So, that's cool. We just did some thing that we were already able to do, but with fewer bytes. Is that all? Just what is this CoAP thing anyway? Well, I'm glad that I'm assuming you're asking that.

Goodnight Moon

{ "version": 1, "type": "CON", "code": "POST", "mid": 55, "token": {}, "opts": { "UriPath": [ "1a", "temp" ], "UriQuery": [ "f6b2d8b26aa4a42f54eca858d509663e02a7b909" ] }, "payload": "26" }{ "version": 1, "type": "ACK", "code": "Changed", "mid": 55, "token": {}, "opts": {} }

Do a Flip

{ "version": 1, "type": "CON", "code": "GET", "mid": 55, "token": {}, "opts": { "UriPath": [ "1a", "msg" ], "UriQuery": [ "f6b2d8b26aa4a42f54eca858d509663e02a7b909" ] } }

Meep Meep

{ "version": 1, "type": "CON", "code": "GET", "mid": 55, "token": [22,45], "opts": { "UriPath": [ "1a", "count" ], "UriQuery": [ "f6b2d8b26aa4a42f54eca858d509663e02a7b909" ], "Observe": 0 } }

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.