How UDP Handles Multiplexing and Demultiplexing
User Datagram Protocol (UDP) facilitates the transmission of multiple data streams across a single network interface by utilizing multiplexing and demultiplexing. Through the use of 16-bit port numbers combined with IP addresses, UDP gathers data from various application processes, packages it into datagrams for transmission, and subsequently directs incoming packets from the network layer to the precise target application on the receiving host.
Understanding Transport Layer Multiplexing and Demultiplexing
On any active host, multiple network-enabled applications run concurrently (such as DNS clients, video streaming applications, and online gaming services). Multiplexing and demultiplexing are the mechanisms that allow these distinct applications to share a single physical network connection without cross-talk or data collisions.
- Multiplexing (Sender Side): The process of collecting data from multiple application processes via their respective sockets, appending transport-layer headers to create UDP datagrams, and passing these datagrams to the underlying network layer (IP).
- Demultiplexing (Receiver Side): The process of inspecting the transport-layer header of an incoming datagram from the network layer, identifying the intended recipient process, and delivering the payload directly to the correct application socket.
The Role of UDP Headers in Traffic Routing
UDP relies on a minimal 8-byte header to perform its transport duties. Two specific fields within this header make multiplexing and demultiplexing possible:
- Source Port Number (16 bits): Identifies the sending application process on the source host. This allows the receiving host to know where to send a reply if necessary.
- Destination Port Number (16 bits): Identifies the target application process on the destination host.
Port numbers range from 0 to 65535. Ports
0 to 1023 are well-known ports reserved for
standard services (e.g., DNS on port 53), while ports 1024
to 65535 are used for dynamic or private application
assignments.
The UDP Multiplexing Process (Sending Data)
When an application wants to transmit data using UDP:
- Socket Creation: The operating system assigns a local port number to the application’s UDP socket.
- Datagram Encapsulation: The UDP layer accepts the raw data payload from the application layer.
- Header Generation: UDP adds the assigned source port and the specified destination port, along with the length and checksum fields.
- Handoff to Network Layer: The encapsulated datagram is passed down to the IP layer, which wraps it in an IP packet containing the source and destination IP addresses before transmitting it over the physical network.
The UDP Demultiplexing Process (Receiving Data)
UDP performs connectionless demultiplexing. Unlike TCP, which uses a 4-tuple to identify a socket, UDP demultiplexes traffic using a 2-tuple:
\[\text{UDP Identifier} = (\text{Destination IP Address}, \text{Destination Port Number})\]
When an incoming IP packet arrives at the receiving host:
- Packet Extraction: The network layer strips the IP header and passes the encapsulated UDP datagram up to the transport layer.
- Port Inspection: The transport layer examines the datagram’s Destination Port Number.
- Socket Matching: The host matches the destination IP address and destination port to the local socket bound to that port.
- Data Delivery: The UDP payload is placed into the specific socket’s receive buffer, where the corresponding application reads it.
Because UDP is connectionless, two incoming datagrams with different source IP addresses or source port numbers—but directed to the same destination IP and destination port—will be delivered to the exact same application socket on the receiving host. The application itself can read the source IP and source port from the packet metadata if it needs to differentiate between individual senders.