Building the Internet of Things with Thingsquare and Contiki - day 2 part 2

7,675 views

Published on

The second slide set from the second day of the Thingsquare Building the IoT with Contiki course. http://thingsquare.com/training/

Published in: Technology

Building the Internet of Things with Thingsquare and Contiki - day 2 part 2

  1. 1. Diving into the IoT/IP stack
  2. 2. The IoT/IP stack HTTP, WebSockets, CoAP Application TCP, UDP Transport IPv6, IPv4, RPL Network, routing 6lowpan Adaptation CSMA/CA MAC ContikiMAC, CSL Duty cycling 802.15.4 Radio
  3. 3. The application layer • Do something useful with the data • Today, applications typically run above the application layer – E.g. the Web runs on top of HTTP Application Transport Network, routing Adaptation MAC Duty cycling Radio
  4. 4. The transport layer • Allow program A to send data to program B – Even though the network may drop packets – Get packets in order, despite them being reordered on the way Application Transport Network, routing Adaptation MAC Duty cycling Radio
  5. 5. The network layer • Figure out how to send a packet from A to C, through node B Application Transport Network, routing C A Adaptation MAC Duty cycling B Radio
  6. 6. The adaptation layer • Send network layer packets over the radio • Compress headers, fragment packets Application Transport Network, routing Adaptation MAC Duty cycling Radio
  7. 7. The MAC layer • Make sure to not send when others are sending • Back off exponentially when there is too much traffic Application Transport Network, routing Adaptation MAC Duty cycling Radio
  8. 8. The radio duty cycling layer • Turn off the radio when not needed, to save power – The radio consumes more power than other components • Make sure nodes are awake to hear messages from others Application Transport Network, routing Adaptation MAC Duty cycling Radio
  9. 9. The radio link layer • Frequency bands – 2.4 GHz and sub-GHz • Modulations and encodings • Bit rates and bit errors • Standards and nonstandards Application Transport Network, routing Adaptation MAC Duty cycling Radio
  10. 10. The packet path Application Application Application Transport Transport Transport Network, routing Network, routing Network, routing Adaptation Adaptation Adaptation MAC MAC MAC Duty cycling Duty cycling Duty cycling Radio Radio Radio
  11. 11. Application Transport The IoT/IP Protocols Network, routing Adaptation The application layer MAC Duty cycling Radio
  12. 12. The application layer • The layer where applications supposedly run • But many applications actually run on top of an application layer protocol • Application layer protocols for the IoT – HTTP (TCP) – WebSockets (TCP) – CoAP (UDP)
  13. 13. HTTP • HyperText Transfer Protocol • The same HTTP which is used on the web • HTTP is often used for automated mechanisms • Useful for mesh-to-Internet communication
  14. 14. REST • Representational State Transfer • A conceptualization of the way HTTP works – Resource: an URL – Resources are manipulated with methods • GET http://device-25.local/sensor/light • POST http://device-28.local/configuration sensor=123&batt=3300 • DELETE, UPDATE, HEAD, ... • There is a lot of confusion around what REST is and is not
  15. 15. WebSockets • A recently defined standard – RFC6455 • Provides a TCP-like service on top of HTTP with very little overhead • Goes through firewalls, proxies (TCP port 80) • Compatible with HTTP – A WebSocket connection starts with a handshake over HTTP • Useful for mesh-to-Internet communication
  16. 16. Websocket exchange GET /path HTTP/1.1 Host: api.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: example Sec-WebSocket-Version: 12 Origin: http://example.com HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: example
  17. 17. Websocket message header
  18. 18. CoAP • Message protocol over UDP • Started as a bit-optimized REST mechanism • Has grown into a fully fledged transport/application solution – – – – – – Retransmissions Confirmable/non-confirmable transmission modes Support for caching Support for sleeping nodes Subscription support Resource discovery • Useful for in-mesh communication – May have problems with firewalls
  19. 19. Application Transport The IoT/IP Protocols Network, routing Adaptation The transport layer MAC Duty cycling Radio
  20. 20. The problem • Getting data from application A to application B • UDP – Best-effort delivery, no ordering • TCP – Reliable stream delivery: in order, reliably • We’ll know whether it was received or not
  21. 21. UDP • • • • • User Datagram Protocol Provides 16-bit port numbers Payload checksum Length field No protocol logic
  22. 22. The UDP Header
  23. 23. TCP • Transport Control Protocol • Significantly more complex than UDP • Reliable, in-order stream delivery – Byte sequence – End-to-end acknowledgements – Flow control • Avoid overloading the receiver – Congestion control • Avoid overloading the network
  24. 24. The TCP header
  25. 25. The TCP byte stream
  26. 26. TCP 3-way handshake, opening • SYN – Includes maximum segment size option • SYN + ACK – Also includes maximum segment size option • ACK
  27. 27. TCP retransmissions
  28. 28. TCP 3-way handshake, closing • FIN • FIN+ ACK • ACK
  29. 29. TCP problems for wireless • TCP reacts strongly to packet loss – Reduces sending rate significantly • TCP does not like reordering – May reduce sending rate • But TCP can be made efficient for lowpower wireless – E.g. Duquennoy, Österlind, Dunkels, SenSys 2011
  30. 30. TCP for IoT applications • May be overkill for some applications – Not all applications need a reliable data stream • Does not support multicast/broadcast operation – TCP is strictly point-to-point • But TCP works well with the Internet
  31. 31. In Contiki • Full support for UDP and TCP • TCP implementation is simple – Uses stop-and-wait, resulting in low throughput – TCP-segment splitting can improve throughput • UDP and TCP callback-based sockets (Contiki 3.x) – Register a socket with a callback function that gets called when something happens
  32. 32. Takeaway transport layer • UDP and TCP – UDP: simple, datagram delivery – TCP: reliable byte stream
  33. 33. More http://thingsquare.com

×