MFormations
Modern Network Engineering

Chapitre 7

Chapter 07: Transport - TCP, UDP et QUIC

Chapter 07: Transport - TCP, UDP et QUIC

Chapter 07: Transport - TCP, UDP et QUIC

1. Transport Layer Overview

The transport layer provides end-to-end communication services between applications. Two main protocols:

  • TCP: Reliable, connection-oriented, ordered delivery
  • UDP: Unreliable, connectionless, low overhead
Diagramme en cours de génération...

2. TCP (Transmission Control Protocol)

2.1 TCP Header

Diagramme en cours de génération...

TCP Flags:

FlagBitMeaning
NS0ECN-nonce concealment
CWR1Congestion Window Reduced
ECE2ECN Echo
URG3Urgent pointer
ACK4Acknowledgment
PSH5Push data
RST6Reset connection
SYN7Synchronize (connection establishment)
FIN8Finish (connection termination)

2.2 TCP 3-Way Handshake

Diagramme en cours de génération...

Sequence numbers:

  • Initial Sequence Number (ISN) is random
  • SYN consumes one sequence number
  • Each byte of data consumes a sequence number
  • ACK = next expected sequence number

2.3 TCP Connection Termination

Diagramme en cours de génération...

2.4 TCP State Machine

Diagramme en cours de génération...

2.5 TCP Sliding Window

Diagramme en cours de génération...

Window Scaling (RFC 7323):

  • Window field is 16 bits (max 65535 bytes)
  • Scaling factor shifts the window value
  • Scaling factor negotiated during handshake

2.6 TCP Congestion Control

Diagramme en cours de génération...

TCP Reno Phases:

  1. Slow Start: Exponential growth (cwnd doubles per RTT)
  2. Congestion Avoidance: Linear growth (cwnd += 1 MSS per RTT)
  3. Fast Retransmit: 3 duplicate ACKs → retransmit, cwnd = cwnd/2
  4. Fast Recovery: cwnd halved, then linear growth
Diagramme en cours de génération...

BBR (Bottleneck Bandwidth and Round-trip propagation time):

  • Model-based (not loss-based)
  • Probes for available bandwidth
  • Much higher throughput than Cubic
  • Google's algorithm, used in YouTube, QUIC

CUBIC:

  • Default Linux TCP congestion control
  • Cube function for window growth
  • More aggressive than Reno after window reduction
  • Better for high-BDP links

2.7 TCP Options

OptionKindDescription
EOL0End of options
NOP1No operation (padding)
MSS2Maximum Segment Size
WS3Window Scale
SACK Permitted4Selective ACK allowed
SACK5Selective ACK
TS8Timestamp
Fast Open34TCP Fast Open (TFO)

TCP Fast Open (TFO):

  • Send data in SYN packet (0-RTT handshake)
  • Requires TFO cookie
  • Reduces latency for repeat connections

Selective ACK (SACK):

  • Acknowledge non-contiguous data
  • More efficient than cumulative ACK
  • Especially important for high-BDP links

2.8 TCP Timers

TimerPurposeValue
Retransmission (RTO)Timeout for unacked dataBased on RTT (usually 200ms-1s)
PersistAvoid deadlock (zero window)Increasing, up to 60s
KeepaliveCheck if peer is alive2 hours + 9 probes × 75s
TIME_WAIT2MSL wait60s (typical)
Delayed ACKWait for data piggyback40-200ms

3. UDP (User Datagram Protocol)

3.1 UDP Header

Diagramme en cours de génération...

Header size: 8 bytes (versus 20-60 for TCP)

3.2 UDP Characteristics

FeatureUDPTCP
ConnectionConnectionlessConnection-oriented
ReliabilityNone (best effort)Reliable (retransmission)
OrderingNo orderingOrdered delivery
Flow controlNoneSliding window
Congestion controlNoneReno, Cubic, BBR
Header size8 bytes20-60 bytes
OverheadLowHigh
Use casesDNS, VoIP, streamingHTTP, email, file transfer

3.3 UDP Use Cases

ApplicationPortWhy UDP
DNS53Single query/response, fast
DHCP67/68Broadcast, no connection
NTP123Time sync, precise timing
VoIP (RTP)16384-32767Real-time, tolerate loss
StreamingDynamicReal-time, loss tolerant
SNMP161/162Simple query/response
QUIC443 (via UDP)Multiplexed, reliable over UDP
Syslog514Logging, loss tolerant

4. QUIC (Quick UDP Internet Connections)

4.1 QUIC Overview

QUIC (RFC 9000) is a transport protocol developed by Google, used by HTTP/3.

Diagramme en cours de génération...

4.2 QUIC Features

FeatureDescription
0-RTTSend data immediately (repeat connections)
MultiplexingMultiple streams, no HOL blocking
Connection migrationSurvive IP address changes
Built-in encryptionTLS 1.3 mandatory
MonolithicCombines transport + security
User-spaceImplemented in applications, not kernel

4.3 QUIC vs TCP

Diagramme en cours de génération...

4.4 Connection Migration

Diagramme en cours de génération...

5. SCTP (Stream Control Transmission Protocol)

Key features:

  • Multi-homing (multiple IPs per connection)
  • Multi-streaming (multiple streams in one connection)
  • Ordered and unordered delivery
  • Built-in heartbeat

Used primarily in telecom (SS7 over IP) and WebRTC (data channels).

6. Socket Programming

6.1 TCP Socket Flow

Diagramme en cours de génération...

6.2 Python TCP Example

Server:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 8888))
s.listen(5)
while True:
    conn, addr = s.accept()
    data = conn.recv(1024)
    conn.send(data)  # echo
    conn.close()

Client:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8888))
s.send(b'Hello')
data = s.recv(1024)
s.close()

7. Summary

FeatureTCPUDPQUIC
TransportTCPUDPQUIC over UDP
ReliabilityYesNoYes
EncryptionOptional (TLS)No (DTLS)Mandatory (TLS 1.3)
MultiplexingNo (HTTP/2 fixes)NoYes
0-RTTNo (TFO partial)N/AYes
Connection migrationNoN/AYes
Head-of-line blockingYes (TCP)NoNo
KernelYesYesUser-space

8. Exercises

Exercise 1: TCP Handshake

Given a TCP connection with ISN=1000 (client) and ISN=5000 (server), write the sequence/ack numbers for each step of the 3-way handshake.

Exercise 2: Window Calculation

A TCP connection has Bandwidth=10 Gbps, RTT=50 ms. What is the minimum window size needed to fill the pipe? What window scale factor is needed?

Exercise 3: QUIC vs TCP

List 3 advantages of QUIC over TCP.

Exercise 4: UDP Analysis

An application sends 100-byte messages every 10ms. Compare the overhead (header proportion) between TCP and UDP.

Exercise 5: Congestion Control

Describe how TCP Reno responds to a single packet loss in congestion avoidance.