OverviewUDP  usage

UDP widely known as User Datagram Protocol, an alternative to the Transmission Control Protocol (TCP) and, together with IP, is also referred to as UDP/IP. Like the Transmission Control Protocol, UDP uses the Internet Protocol to get a data unit (datagram) from one computer to another. But before jumping into the nuances of this simple protocol lets take a peek into the history of its development.

Earlier during the development of the protocol suite, TCP protocol was used to handle functions now performed by IP and TCP.TCP was responsible for providing network-layer connectivity, connection establishment, flow control and reliability. But soon it was realized that the reliability functions introduced an overhead, as some applications needed the reliability functions, while some did not. Hence this overhead caused a loss of performance in many applications which did not depend on reliability functions offered by TCP.

The solution came in the mode of UDP User Datagram Protocol. The Original protocol was separated into IP, TCP and UDP internetworking was handled IP, and the reliability features by TCP.

UDP as discussed earlier is a simple protocol that resides in Transport Layer of the OSI model. UDP was defined in RFC 768, User Datagram Protocol, in 1980.

OSI model diagram

UDP is a Simple and lighter protocol specifically because it doesn’t have all the complexities of a TCP. That is UDP does not support reliability or acknowledgements and hence uses a best effort delivery model. In short the only real objective of the protocol is to serve as an interface between networking application processes running at the higher layers, and the internetworking capabilities of IP.This Process identification in UDP is done by port number. All it does is take application layer data passed to it, package it in a simplified message format, and send it to IP for transmission.

UDP Datagram

As UDP provides no guarantees to the upper layer protocol for message delivery hence it is also referred to as Unreliable Datagram Protocol. Any reliability issues for the information must be implemented and handled in upper layers.

UDP fields diagram

As shown in Fig. The UDP header consists of only 4 fields.

  • Source port

This field identifies the sending port when meaningful and should be assumed to be the port to reply to if needed. This field is optional, when not used it should be zero.

  • Destination port

This field identifies the destination port and is mandatory.

  • Length

A 16-bit field that specifies the length in bytes of the entire datagram: header and data in total. The minimum length is 8 bytes since that is the length of the header.

  • Checksum

The 16-bit checksum field is used for error-checking of the header and data. This field is optional.

Checksum is the 16-bit one’s complement of the one’s complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.

  • Data

This field contains the actual data.

PSEUDO Header mystery:

UDP uses Pseudo header concept to define the checksum. The pseudo header contains.

  • The IP Source Address field.
  • The IP Destination Address field.
  • The IP Protocol field.
  • The UDP Length field.

The total length of this “pseudo header” is 11 bytes. It is padded to 12 bytes with a byte of zeroes and then prepended to the real UDP message. The checksum is then calculated over the combination of both pseudo header and the real UDP message, and the value is placed into the Checksum field.

Note: The pseudo header is used only for this computation and is discarded; it is not actually transmitted. The UDP software in the destination device creates the same pseudo header when calculating its checksum to compare to the one transmitted in the UDP header.

UDP length diagram

UDP Basic Operation, Ports, Functions and Implementations

The basic operations involved for transmission using UDP can be defined in 3 simple steps:

1.Higher-Layer Data Transfer: An application sends a message to the UDP software.

2.UDP Message Encapsulation: The higher-layer message is encapsulated into the Data field of a UDP message. The headers of the UDP message are filled in, including the Source Port of the application that sent the data to UDP, and the Destination Port of the intended recipient. The checksum value is also calculated.

3.Transfer Message to IP: The UDP message is passed to IP for transmission.

At the destination device this short procedure is reversed on reception.

UDP functions can be underlined as follows:

  • UDP does not provide guarantees that its messages will arrive and no acknowledgments to show that data was received.
  • UDP does not establish connections before sending data. It just packages it.
  • UDP does not ensure that data is received in the same order that they were sent.
  • UDP does not detect lost messages and retransmit them as in TCP.
  • UDP does not provide any mechanism to manage the flow of data between devices, and congestion handling.
  • UDP provides optional checksum capability, which can allow detection of an error in transmission or the situation where a UDP message is delivered to the wrong destination.
  • UDP is widely used and recommended for:
  • Data Where Performance, Speed Is More Important that is when an application values timely delivery over reliable delivery
  • Places where data exchanges are short and the order of reception of datagram does not matter
    Acknowledgement of delivery is not needed
  • Applications that require multicast or broadcast transmissions, since these are not supported by TCP.

UDP Ports Defined

As you know every computer or device on the Internet must have a unique number assigned to it called the IP address. This IP address is used to recognize your particular computer on the Internet. When information is sent over the Internet to that computer it accepts that information by using TCP or UDP ports.

TCP and UDP protocol port numbers are designed to distinguish multiple applications running on a device from one another. Since many network applications may be running on the same machine, computers need something to make sure the correct application on the destination computer gets the data packets from the source machine, and vice versa. This is accomplished through the use of the TCP or UDP port numbers. In the TCP and UDP header, there are Source Port and Destination Port fields which are used to indicate the message sending process ID and receiving process ID.

Let’s take an example to study it further, When a program on your computer sends or receives data over the Internet it sends that data to an ip address and a specific port on the remote computer, and receives the data on a usually random port on its own computer. If it uses the TCP protocol to send and receive the data then it will connect and bind itself to a TCP port. If it uses the UDP protocol to send and receive data, it will use a UDP port. Note that once an application binds itself to a particular port, that port can not be used by any other application.

Some popular examples where UDP is used are:

  • Multimedia applications like streaming video , VOIP
  • In multicast environment
  • If an application needs to multicast or broadcast data, it must use UDP, because TCP is only supported for unicast communication between two devices.
  • Domain Name System (DNS)
  • Simple network management protocol (SNMP)
  • Dynamic Host Configuration Protocol (DHCP)
  • Routing Information Protocol (RIP)

In short though functionally UDP is less complex, simpler and unreliable than TCP its advantage lies in its Speed and Simplicity. Despite its age, UDP continues to be used in mainstream application like video conferencing, streaming video, multicast applications and still remains a prominent protocol in use.