Skip to content
BoKSA

09 – The Transport Layer: UDP, TCP (and QUIC)

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
 0               16              31
 ┌───────────────┬───────────────┐
 │  source port  │   dest port   │
 ├───────────────┼───────────────┤
 │    length     │   checksum    │
 ├───────────────┴───────────────┤
 │      application data …       │
 └───────────────────────────────┘
  • 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
 0                   16                  31
 ┌───────────────────┬───────────────────┐
 │    source port    │     dest port     │
 ├───────────────────┴───────────────────┤
 │           sequence number             │  ← number of the first byte in this segment
 ├───────────────────────────────────────┤
 │        acknowledgement number         │  ← next byte expected from the other side
 ├──────┬──────┬─────────┬───────────────┤
 │ hdr  │      │ flags   │ receive window│  ← flags: SYN, ACK, FIN, RST, PSH, URG, ECE, CWR
 │ len  │      │         │               │
 ├──────┴──────┴─────────┼───────────────┤
 │      checksum         │  urgent ptr   │
 ├───────────────────────┴───────────────┤
 │       options (MSS, SACK, window scale, timestamps)   │
 ├───────────────────────────────────────┤
 │                data                   │
 └───────────────────────────────────────┘

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
 client                                  server (listening on port 443)
   │ ── SYN, seq=x ──────────────────────► │
   │ ◄─ SYN+ACK, seq=y, ack=x+1 ────────── │
   │ ── ACK, ack=y+1 (may already carry data) ─► │
   │ ════════════ data ═══════════════════ │

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
 cwnd │                 loss (3 dup ACKs)
      │            /|      /|      /|
      │          /  |    /  |    /  |          ← AIMD "saw-tooth"
      │        /    |  /    |  /    |
      │      /      |/      |/      |
      │    /  ← congestion avoidance: +1 MSS per RTT (additive increase)
      │  /
      │ / ← slow start: doubles every RTT
      └────────────────────────────────── time
  • 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

  1. 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.
  2. Find the SYN, SYN-ACK, ACK segments. What are the (relative and raw) sequence numbers?
  3. Which TCP options are in the SYN (MSS, SACK permitted, window scale)?
  4. Use Statistics → TCP Stream Graphs → Stevens: can you see slow start?
  5. Wireshark UDP: filter udp or dns. Look at the 8-byte header. What is the length field?
  6. QUIC: filter quic while visiting https://www.google.com in Chrome. Which UDP port is used? How much of the packet is readable?
  7. 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

  1. What is the difference between network-layer and transport-layer communication?
  2. Name three reasons to use UDP.
  3. Why does reliable data transfer need sequence numbers?
  4. What happens in the 3-way handshake?
  5. What is the difference between flow control and congestion control?
  6. Describe slow start and AIMD in your own words.
  7. Name three advantages of QUIC.

References

Book

Videos

Standards and articles


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