- Published on
[Computer Networking] 08. Transport Layer: Multiplexing/Demultiplexing and UDP
- Authors

- Name
- Youngju Kim
- @fjvbn20031
This post is based on the textbook Computer Networking: A Top-Down Approach (6th Edition) by James Kurose and Keith Ross.
- 1. Transport Layer Services
- 2. Multiplexing and Demultiplexing
- 3. UDP (User Datagram Protocol)
- 4. UDP Checksum
- 5. Reliable Transfer Over UDP
- 6. Summary
- 7. Review Questions
1. Transport Layer Services
1.1 Role of the Transport Layer
The transport layer provides logical communication between processes running on different hosts.
Network layer: Host-to-host communication
Transport layer: Process-to-process communication
+--------+ +--------+
| App P1 | | App P3 |
| App P2 | | App P4 |
+--------+ +--------+
| Transport | <-- logical --> | Transport |
+--------+ communication +--------+
| Network | <-- logical --> | Network |
+--------+ communication +--------+
Host A Host B
1.2 Relationship Between Transport and Network Layers
Analogy: House-to-house postal system
House (Host) A House (Host) B
Ann (process) Bob (process)
Bill (process) Carol (process)
Transport layer = The person in the house who sorts the mail
(decides which family member to deliver to)
Network layer = The postal service
(delivers letters from House A to House B)
The transport layer can add services that the network layer does not provide. For example, reliable TCP is built on top of unreliable IP.
1.3 Two Protocols of the Internet Transport Layer
TCP (Transmission Control Protocol):
+-- Connection-oriented (3-way handshake)
+-- Reliable data transfer
+-- Flow control (receiver protection)
+-- Congestion control (network protection)
+-- Order guarantee
UDP (User Datagram Protocol):
+-- Connectionless
+-- Unreliable (best-effort delivery)
+-- No flow/congestion control
+-- No order guarantee
2. Multiplexing and Demultiplexing
2.1 Concept
Multiple processes on a single host use the network simultaneously. The transport layer must manage this.
Multiplexing:
On the sending side, gather data from multiple sockets,
add transport-layer headers, and pass to the network layer
Demultiplexing:
On the receiving side, receive transport-layer segments
and deliver to the correct socket (process)
Demultiplexing operation:
Segment received from network layer
|
v
Transport layer: Check port number in segment header
|
+--> Port 80 -> Web server process
+--> Port 25 -> Mail server process
+--> Port 53 -> DNS server process
2.2 Port Numbers
A 16-bit number used by the transport layer to identify processes.
Port number range: 0 to 65535
0 to 1023: Well-Known Ports
HTTP(80), HTTPS(443), DNS(53), SMTP(25)
1024 to 49151: Registered Ports
49152 to 65535: Dynamic/Ephemeral Ports
Automatically assigned to clients
2.3 Port Number Fields in the Segment Header
Transport layer segment:
+--------------+--------------+
| Source port | Dest port | <- 16 bits each
+--------------+--------------+
| Other header fields |
+------------------------------+
| Application data |
+------------------------------+
2.4 Connectionless Demultiplexing (UDP)
A UDP socket is identified by a 2-tuple of (destination IP, destination port).
Server: IP=10.0.0.1, Port=46428
Client A (IP=10.0.0.2, source port=9157)
-> Destination: 10.0.0.1:46428
Client B (IP=10.0.0.3, source port=9157)
-> Destination: 10.0.0.1:46428
Both datagrams are delivered to the same socket!
(Same destination port, even though source IPs differ)
2.5 Connection-Oriented Demultiplexing (TCP)
A TCP socket is identified by a 4-tuple of (source IP, source port, destination IP, destination port).
Server: IP=10.0.0.1, Port=80
Client A (IP=10.0.0.2, source port=9157)
-> 4-tuple: (10.0.0.2, 9157, 10.0.0.1, 80)
-> Dedicated connection socket 1
Client B (IP=10.0.0.3, source port=9157)
-> 4-tuple: (10.0.0.3, 9157, 10.0.0.1, 80)
-> Dedicated connection socket 2
Same source port but different IPs -> different sockets!
TCP server socket structure:
Welcome socket (port 80)
|
+-- Connection socket 1: (10.0.0.2:9157, 10.0.0.1:80)
+-- Connection socket 2: (10.0.0.3:9157, 10.0.0.1:80)
+-- Connection socket 3: (10.0.0.2:5775, 10.0.0.1:80)
Each connection is distinguished by its unique 4-tuple
3. UDP (User Datagram Protocol)
3.1 Characteristics of UDP
UDP performs the bare minimum that the transport layer can do.
What UDP does:
+ Multiplexing/demultiplexing (port numbers)
+ Simple error detection (checksum)
What UDP does not do:
x Connection setup
x Reliable delivery
x Flow control
x Congestion control
x Order guarantee
3.2 Why Use UDP
Advantages of UDP:
1. No connection setup -> Reduced delay (why DNS uses UDP)
2. No connection state -> Can support more clients
3. Small header overhead -> Efficient (UDP: 8 bytes, TCP: 20 bytes)
4. No rate limitation -> Application can send at desired speed
Applications That Use UDP
| Application | Protocol | Reason |
|---|---|---|
| DNS | UDP | Simple query-response, fast needed |
| SNMP | UDP | Network management, simple requests |
| Streaming media | UDP/TCP | Some loss tolerable, real-time important |
| Internet telephony | UDP | Real-time more important than reliability |
| Online games | UDP | Low latency is essential |
3.3 UDP Segment Structure
+------------------+------------------+
| Source port (16) | Dest port (16) |
+------------------+------------------+
| Length (16) | Checksum (16) |
+------------------+------------------+
| |
| Application data (payload) |
| |
+--------------------------------------+
Header size: 8 bytes (4 fields x 2 bytes)
| Field | Size | Description |
|---|---|---|
| Source port | 16 bits | Port of the sending process |
| Dest port | 16 bits | Port of the receiving process |
| Length | 16 bits | Total length of UDP segment (header + data) |
| Checksum | 16 bits | For error detection |
4. UDP Checksum
4.1 Purpose
To detect whether the segment was altered (bit errors) during transmission.
4.2 Calculation Method
Add all 16-bit words of the segment and take the 1's complement.
Example: Three 16-bit words
0110 0110 0110 0000
0101 0101 0101 0101
1000 1111 0000 1100
Step 1: Add the first two words
0110 0110 0110 0000
+ 0101 0101 0101 0101
---------------------
1011 1011 1011 0101
Step 2: Add the third word to the result
1011 1011 1011 0101
+ 1000 1111 0000 1100
---------------------
0100 1010 1100 0001 (wraparound on carry)
Step 3: Take the 1's complement
0100 1010 1100 0001
-> 1011 0101 0011 1110 <- This is the checksum
4.3 Error Detection Process
Sender:
1. Set checksum field to 0
2. Add all 16-bit words of the segment
3. Take the 1's complement and store in checksum field
Receiver:
1. Add all 16-bit words of the segment (including checksum)
2. If the result is all 1s -> No error (high probability)
3. If any bit is 0 -> Error detected!
Verification example (no error):
Sum of data words + checksum = 1111 1111 1111 1111
-> All bits are 1 -> Normal
Verification example (error present):
Due to bit error, sum becomes 1111 1011 1111 1111
-> Contains a 0 -> Error detected!
4.4 Limitations of Checksum
Checksum limitations:
1. Can detect errors but cannot correct them
2. May miss some errors (e.g., two bits change complementarily)
3. UDP takes no action even when an error is detected
- Discards the damaged segment or delivers it with a warning to the application
Why UDP provides a checksum: Not all link-layer protocols provide error detection, and bit errors can occur in memory. Following the end-to-end principle, the transport layer also performs error detection.
5. Reliable Transfer Over UDP
UDP itself does not provide reliable transfer, but reliability can be implemented at the application layer.
Application-level reliability implementation:
+-- Acknowledgment (ACK) mechanism
+-- Retransmission timer
+-- Sequence numbers
Example: QUIC protocol (used in HTTP/3)
- Implements reliable transfer over UDP
- Faster connection setup than TCP
- Multiplexing support
6. Summary
Transport layer summary:
Multiplexing/Demultiplexing:
+-- UDP: Socket identified by (dest IP, dest port) 2-tuple
+-- TCP: Socket identified by (src IP, src port, dest IP, dest port) 4-tuple
UDP:
+-- Connectionless, unreliable
+-- 8-byte header (source port, dest port, length, checksum)
+-- Error detection via checksum
+-- Suitable for real-time applications
7. Review Questions
Q1. What is the key difference between UDP demultiplexing and TCP demultiplexing?
- UDP: Identifies sockets using only the destination IP and destination port (2-tuple). Therefore, two datagrams from different sources are delivered to the same socket if they share the same destination port.
- TCP: Identifies sockets using source IP, source port, destination IP, and destination port (4-tuple). Segments from different sources are delivered to different sockets.
Q2. What is the principle and limitation of UDP checksum?
Principle: Add all 16-bit words of the segment and take the 1's complement. On the receiving side, when all words (including the checksum) are added together, if the result is all 1s, no error is assumed.
Limitation: If two bits change simultaneously in a complementary way (one bit flips from 0 to 1, another from 1 to 0), the error may go undetected. Also, even when an error is detected, correction is not possible.
Q3. Why does DNS use UDP instead of TCP?
DNS queries are mostly short transactions consisting of a single request and response. The TCP 3-way handshake introduces more overhead than the actual data. By using UDP, queries can be sent and responses received immediately without connection setup, greatly reducing latency. If a response is not received, the application can simply retransmit.