Speed up machine-to-machine networking with UDP
In today's world of connected devices, smartphones upload photos to servers in the cloud, car rental agencies check-in your rental upon your return, you can purchase in-flight meals using your credit card, and doctors access vital signs of patients across town—or around the world.
While such machine-to-machine (M2M) communication is performed over the Internet and generally uses the popular transmission control protocol (TCP), what you may not realize is that many other M2M communications utilize ‘user datagram protocol’ (UDP) and communicate at rates that would be unachievable using TCP.
In fact, UDP can be advantageous for many embedded M2M system requirements, and might be worth consideration for your next “Internet of Things” design. Following are highlights and some of my thoughts on the use of UDP in M2M communications.
TCP/IP is a layered protocol, which means more complex protocols are built on top of simpler underlying protocols (Table 1). In TCP/IP, the lowest layer protocol is at the link level and is handled by the network driver. This level is typically targeted for Ethernet, but it could also be fiber, serial, or virtually any physical media.
On top of the link layer is the network layer. In TCP/ IP, this is the IP, which is responsible for sending and receiving simple packets, in a best effort manner, across the network. Management type protocols like ICMP and IGMP also are typically categorized as network layers, even though they rely on IP for sending and receiving.
The transport layer rests on top of the network layer. This layer is responsible for managing the flow of data between hosts on the network. UDP operates within the transport layer, along with TCP, DCCP, SCTP, RSVP, and others, since, as the name implies, these protocols are used to move data from sender to receiver. In particular, two general transport services are commonly used by M2M applications: UDP and TCP. UDP services provide best-effort sending and receiving of data between two hosts in a connectionless manner; TCP provides connection management between two host entities with a reliable data path between them.
The UDP protocol is the "poor sister" of the Internet, not getting much media love, while TCP soaks up all the attention. But UDP operates with far less overhead, and can run rings around TCP.
While TCP is more widely known and used, many Internet applications use UDP, including the Domain Name System (DNS), simple network management protocol (SNMP), routing information protocol (RIP), and dynamic host configuration protocol (DHCP).
Most voice and video traffic is transmitted using UDP. To understand why, and to determine whether it is a good fit for your M2M system, we will introduce some fundamental characteristics of each protocol and show how those characteristics make one protocol better than the other for a given application.
Transmission control protocol (TCP)
TCP is a widely used protocol for Internet traffic. It enables applications to send data from one system to another, across arbitrary distances, through an arbitrary number of intervening machines. Indeed, the sender does not need to know where the receiver is, or how to get to it. Those critical functions are taken care of by other aspects of the Internet protocol.
TCP provides reliable data transfer between two network members. All data transfers sent from one network member are verified and acknowledged by the receiving member. In addition, the sender and receiver must have established a connection prior to any data transfer. All this results in reliable data transfer, but it does introduce substantial overhead. Additional overhead is introduced in the TCP header.
TCP places a somewhat complex packet header in front of the application’s data when sending data and removes the header from the packet before delivering a received TCP packet to the application. Table 2 shows the format of the TCP header. TCP uses the IP protocol to send and receive packets, which means there is an additional IP header in front of the TCP header when the packet is on the network.
The data section follows the header. The length of the data section is not specified in the TCP segment header. It can be calculated, though, by subtracting the combined length of the TCP header and the encapsulating IP header from the total IP datagram length (specified in the IP header).
TCP protocol operations may be divided into three phases: connection establishment, reliable data transfer, and connection termination. To establish a connection, TCP uses a three-way handshake. For data transfer, the protocol uses a sequence number to identify each byte of data. If the sender infers that data has been lost in the network, it retransmits the data. Sequence numbers and acknowledgments cover discarding duplicate packets, retransmission of lost packets, and ordered-data transfer. To assure correctness, a checksum field is included.
TCP uses an end-to-end flow control protocol to avoid having the sender send data too fast for the TCP receiver to receive and process reliably. The protocol also includes a number of mechanisms to improve performance and prevent congestion collapse, an event that can cause network performance to fall by several orders of magnitude. These mechanisms control the rate of data entering the network, keeping the data flow below a rate that would trigger collapse. They also yield an approximately max-min fair allocation between flows. Once transfers are complete, the connection is terminated to free system resources for re-use elsewhere.
While the TCP protocol is a rich one, with many features related to data integrity, the TCP header is quite large. One can imagine the overhead that those characteristics introduce. For certain applications, UDP may be a more efficient solution.
Currently no items