09 – The Transport Layer: UDP, TCP (and QUIC)
Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 3 (3.1–3.3 transport services and UDP; 3.4 principles of reliable data transfer; 3.5 TCP; 3.6–3.7 congestion control; QUIC)
Learning goals
After this article you can:
- explain the services of the transport layer and how it differs from the network layer;
- describe UDP and its header, and explain when UDP is a good choice;
- explain the building blocks of reliable data transfer: checksums, ACKs, sequence numbers, timers, pipelining;
- describe the TCP segment, the 3-way handshake and connection teardown;
- explain flow control and congestion control (slow start, AIMD) and name modern algorithms (CUBIC, BBR);
- explain why QUIC was created;
- analyse UDP and TCP traffic in Wireshark.
1. Transport layer services
| Layer | Communication between | "Analogy" |
|---|---|---|
| Network layer | hosts (IP address → IP address) | the post delivers letters to a house |
| Transport layer | processes (port → port) | someone in the house hands each letter to the right person |
The transport layer runs only in end systems, not in routers. The Internet's network layer (IP) is best effort: packets may be lost, duplicated, delayed or arrive out of order. The transport layer decides how to deal with that:
- UDP: "no frills". It does multiplexing and simple error detection, nothing more.
- TCP: reliable, in-order byte stream with flow and congestion control.
Neither offers guaranteed delay or bandwidth.
2. UDP – User Datagram Protocol (RFC 768)
2.1 The UDP header (8 bytes)
1 2 3 4 5 6 7 8 | |
- Checksum: the sender adds up the segment as 16-bit words (1's complement sum) and puts the inverted result in the header. The receiver repeats the calculation. If the result is wrong, an error has been detected, and the segment is dropped.
2.2 Why would anyone use UDP?
- No connection setup → no extra RTT delay (DNS: one question, one answer).
- No connection state → a server can handle many more clients.
- Small header (8 bytes vs. 20+ for TCP).
- No congestion control → the application decides how fast to send (real-time audio/video, games). Downside: it can overload the network if the app isn't careful.
Used by: DNS, DHCP, NTP, SNMP, VoIP/RTP, online games, video calls (WebRTC), QUIC/HTTP/3, WireGuard VPN.
If an application over UDP needs reliability, it has to build it itself, and that is exactly what QUIC does.
3. Principles of reliable data transfer
How do you get reliable delivery over an unreliable channel? Step by step (Kurose & Ross "rdt" protocols):
| Problem | Solution |
|---|---|
| bits can be corrupted | checksum to detect errors |
| receiver must tell sender what arrived | acknowledgements (ACKs) (and in theory NAKs) |
| an ACK can be corrupted or lost → sender re-sends → duplicates | sequence numbers |
| packets can be lost completely | timer / timeout + retransmission |
| waiting for every ACK (stop-and-wait) is very slow | pipelining: several packets "in flight" at once |
Why pipelining? Example: 1 Gbit/s link, RTT 30 ms, packets of 1,000 bytes (8,000 bits). Stop-and-wait sends 8,000 bits every 30.008 ms → utilisation ≈ 0.027%. With a window of N packets, utilisation increases about N times.
Two pipelining approaches: - Go-Back-N: cumulative ACKs; on a timeout the sender re-sends all unacknowledged packets. - Selective Repeat: the receiver ACKs each packet individually and buffers out-of-order packets; only missing packets are re-sent.
TCP uses a mix of these ideas.
4. TCP – Transmission Control Protocol (RFC 9293)
4.1 Properties
- Point-to-point: one sender, one receiver.
- Connection-oriented: handshake before data is sent.
- Reliable, in-order byte stream: no "messages", just a stream of bytes.
- Full duplex: data in both directions on one connection.
- Flow control and congestion control.
4.2 The TCP segment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Sequence numbers count bytes, not segments. If A sends 100 bytes starting with seq = 42, B answers with ACK = 142 ("I have everything up to byte 141; send 142 next").
4.3 The 3-way handshake
1 2 3 4 5 | |
The initial sequence numbers (x, y) are random, for security reasons (see Cyber Security).
Closing: each side sends FIN and receives an ACK (4 segments, often combined). RST aborts a connection immediately (e.g. when no process listens on that port).
4.4 Timeouts and fast retransmit
- TCP measures the RTT continuously (SampleRTT → EstimatedRTT, DevRTT) and sets the timeout a little above the expected RTT.
- Fast retransmit: after 3 duplicate ACKs the sender re-sends the missing segment without waiting for the timeout.
- SACK (selective acknowledgement, a TCP option used by almost every modern OS) tells the sender exactly which blocks arrived.
4.5 Flow control – don't overwhelm the receiver
The receiver advertises how much free buffer space it has in the receive window (rwnd) field. The sender never has more than rwnd unacknowledged bytes in flight.
4.6 Congestion control – don't overwhelm the network
Symptoms of congestion: long delays (full queues) and packet loss. TCP adjusts its congestion window (cwnd):
1 2 3 4 5 6 7 8 9 | |
- Slow start: cwnd starts small and doubles every RTT until a threshold (ssthresh) or loss.
- Congestion avoidance (AIMD): Additive Increase (+1 MSS per RTT), Multiplicative Decrease (halve cwnd on loss).
- Sending rate ≈ min(cwnd, rwnd) / RTT.
Modern algorithms (updated):
| Algorithm | Idea | Where |
|---|---|---|
| Reno / NewReno | classic loss-based AIMD (the textbook version) | historical basis, still in some stacks |
| CUBIC | grows cwnd as a cubic function of time since the last loss; better on fast, long-distance links | default in Linux, Windows, macOS |
| BBR (v1–v3) | estimates bottleneck bandwidth and RTT instead of waiting for loss | Google (YouTube, Google Cloud), many CDNs |
| ECN / L4S | routers mark packets instead of dropping them, so senders slow down before loss | growing support (Apple, Comcast, Linux) |
5. QUIC: transport in user space
QUIC (RFC 9000, 2021) was developed by Google and standardised by the IETF. It runs on top of UDP and provides:
- reliable, congestion-controlled delivery (like TCP);
- multiple independent streams: one lost packet only blocks its own stream (no head-of-line blocking across streams);
- built-in TLS 1.3: everything except a few header fields is encrypted;
- fast handshake: 1 RTT for transport + encryption together; 0-RTT when resuming;
- connection migration: the connection survives a change of IP address (Wi-Fi → 5G).
Why on top of UDP? Because many firewalls and middleboxes only let TCP and UDP through, so a new transport protocol directly on IP would not work on most networks. Also, implementing it in user space means apps can be updated quickly without waiting for OS kernels.
Still in use? TCP is absolutely still the workhorse of the Internet (SSH, e-mail, databases, HTTP/1.1, HTTP/2, most APIs). QUIC carries a large and growing share of web traffic via HTTP/3.
6. Try it yourself
- Wireshark TCP: start a capture, then upload a file with your browser (Kurose & Ross Wireshark TCP exercise: https://gaia.cs.umass.edu/kurose_ross/wireshark.php). Use the filter
tcp. - Find the SYN, SYN-ACK, ACK segments. What are the (relative and raw) sequence numbers?
- Which TCP options are in the SYN (MSS, SACK permitted, window scale)?
- Use Statistics → TCP Stream Graphs → Stevens: can you see slow start?
- Wireshark UDP: filter
udpordns. Look at the 8-byte header. What is the length field? - QUIC: filter
quicwhile visitinghttps://www.google.comin Chrome. Which UDP port is used? How much of the packet is readable? - Netcat:
1 2 3
nc -l 5000 # TCP server nc -u -l 5000 # UDP server nc localhost 5000 # TCP client nc -u localhost 5000 # UDP client ss -tn # show the TCP connection and its state (ESTAB)
Check your understanding
- What is the difference between network-layer and transport-layer communication?
- Name three reasons to use UDP.
- Why does reliable data transfer need sequence numbers?
- What happens in the 3-way handshake?
- What is the difference between flow control and congestion control?
- Describe slow start and AIMD in your own words.
- Name three advantages of QUIC.
References
Book
- Kurose & Ross, 9th ed., chapter 3
- Kurose & Ross interactive animations (GBN, SR, TCP congestion control) – https://gaia.cs.umass.edu/kurose_ross/interactive/
Videos
- PowerCert – TCP vs UDP Comparison https://www.youtube.com/watch?v=uwoD5YsGACg
- Code.org – The Internet: Packets, Routing & Reliability https://www.youtube.com/watch?v=AYdF7b3nMto
- Chris Greer – Learn Wireshark! Tutorial for Beginners https://www.youtube.com/watch?v=OU-A2EmVrKQ
- Jim Kurose's video lectures, chapter 3 – https://gaia.cs.umass.edu/kurose_ross/lectures.php
Standards and articles
- RFC 768 – UDP – https://www.rfc-editor.org/rfc/rfc768
- RFC 9293 – TCP (2022, replaces RFC 793) – https://www.rfc-editor.org/rfc/rfc9293
- RFC 9000 – QUIC – https://www.rfc-editor.org/rfc/rfc9000
- The Illustrated QUIC Connection – https://quic.xargs.org/
Cyber Security
Why is this important for cyber security?
| Attack | How it works |
|---|---|
| Port scanning | attackers send SYNs to many ports; a SYN-ACK means "open", a RST means "closed". This is usually the first step of an attack (reconnaissance) |
| SYN flood (DoS) | the attacker sends huge numbers of SYNs (often with spoofed IPs) and never completes the handshake; the server's table of half-open connections fills up |
| UDP amplification / reflection DDoS | UDP has no handshake, so the source IP is easy to spoof. Small requests to DNS, NTP, Memcached or CLDAP servers produce large replies that hit the victim (amplification factors of 50× to 50,000×) |
| TCP session hijacking / RST injection | an attacker who can guess sequence numbers can inject data or reset connections. That's why initial sequence numbers are random |
| Unencrypted payloads | TCP and UDP don't encrypt anything: everything above the header can be read with Wireshark |
What can you do to make it safe?
- SYN cookies (enabled by default in Linux): the server stores no state until the handshake completes, so a SYN flood can't fill the table.
- Firewalls that only allow the necessary ports and track connection state (stateful inspection).
- Rate limiting and DDoS protection at your ISP or a scrubbing/CDN service.
- Don't run open UDP services on the Internet (open DNS resolvers, NTP monlist, Memcached). Network operators should apply BCP 38 (ingress filtering) so spoofed source addresses can't leave their network.
- Encrypt at a higher layer: TLS over TCP, QUIC (always encrypted), DTLS over UDP, or a VPN.
- Monitor for scans and unusual numbers of half-open connections with an IDS (see article 18).
- Only scan systems you are allowed to scan. In the Netherlands, unauthorised scanning and hacking can be a criminal offence (computervredebreuk, art. 138ab Sr).
Extra references
- Cloudflare blog – SYN packet handling in the wild – https://blog.cloudflare.com/syn-packet-handling-in-the-wild/
- BCP 38 / RFC 2827 – Network ingress filtering – https://www.rfc-editor.org/rfc/rfc2827
- Nmap – port scanning basics (for authorised use) – https://nmap.org/book/man-port-scanning-basics.html
- Nationale Anti-DDoS Coalitie – https://www.nomoreddos.org/