Back to Course Home
Overview Multiplexing UDP Reliable Data Transfer TCP Flow Control Connection Mgmt Congestion Control TCP CC QUIC & Evolution Homework

Chapter 3: Transport Layer

Kurose & Ross, Computer Networking: A Top-Down Approach, 9th edition (2025) – Full lecture coverage

1. Transport-Layer Services and Protocols

The transport layer provides logical communication between application processes running on different hosts. It breaks messages into segments, passes them to the network layer, and reassembles them at the receiver. Two main protocols: TCP and UDP.

🏠 Household Analogy

12 kids in Ann’s house sending letters to 12 kids in Bill’s house:

  • Hosts = houses
  • Processes = kids
  • App messages = letters in envelopes
  • Transport protocol = Ann & Bill demultiplexing to siblings
  • Network-layer protocol = postal service

📦 Transport vs. Network Layer

  • Network layer: communication between hosts
  • Transport layer: communication between processes
  • Relies on and enhances network layer services
  • TCP: reliable, in-order delivery, congestion control, flow control, connection setup
  • UDP: unreliable, unordered, no-frills best-effort service
Transport layer actions:
Sender: receives app message → determines segment header → creates segment → passes to IP.
Receiver: receives segment from IP → checks header → extracts app message → demultiplexes to correct socket.

Quick Comparison: TCP vs UDP

Feature TCP UDP
Connection Connection-oriented (handshake) Connectionless
Reliability Reliable (retransmissions, ACKs) Unreliable (best-effort)
Ordering In-order delivery No ordering guarantees
Congestion Control Yes (AIMD, slow start, etc.) None (applications can add their own)
Flow Control Yes (receive window rwnd) No
Header Size 20–60 bytes 8 bytes
Typical Applications Web, email, file transfer Streaming, DNS, VoIP, HTTP/3

Having seen the big picture, let’s dive into how transport-layer protocols multiplex and demultiplex data streams.

2. Multiplexing and Demultiplexing

Multiplexing at sender: handle data from multiple sockets, add transport header (source/destination port #). Demultiplexing at receiver: use header info (IPs + ports) to deliver segments to the correct socket.

Connectionless Demultiplexing (UDP)

  • UDP socket identified by destination IP + destination port only.
  • Datagrams with same dest port # but different source IP/port go to the same socket.
  • Example: host binds UDP socket to port 9157; all UDP datagrams arriving with dest port 9157 are delivered to that socket.

Connection-Oriented Demultiplexing (TCP)

  • TCP socket identified by 4-tuple: source IP, source port, dest IP, dest port.
  • Server can support many simultaneous TCP sockets, each tied to a different client.
  • Demux uses all four values to direct segment to the correct socket.
Example TCP demultiplexing:
  Segment 1: src A:9157 → dst B:80 → socket 1
  Segment 2: src C:5775 → dst B:80 → socket 2
  Segment 3: src C:9157 → dst B:80 → socket 3
        

Now that we understand how segments are directed to the right application, we can examine the simpler of the two transport protocols: UDP.

3. Connectionless Transport: UDP

UDP is a “no frills” protocol: no handshake, each segment handled independently. It is used for streaming multimedia, DNS, SNMP, and now HTTP/3 (QUIC). Reliability and congestion control can be added at the application layer.

UDP Segment Header

 0      16      31
+--------+--------+
| source port | dest port |
+--------+--------+
| length | checksum |
+--------+--------+
| application data (payload)
        

UDP Checksum

Goal: detect bit errors. Sender computes the 1’s complement sum of all 16‑bit words (including pseudo‑header fields) and stores the result in the checksum field. Receiver recomputes the sum and verifies it. It is simple and fast, though not extremely robust (some bit‑flips may cancel out).

Why UDP?
• No connection establishment delay (no RTT).
• Simple: no connection state at sender/receiver.
• Small header size.
• No congestion control: can blast away as fast as desired (but may cause congestion collapse!).

UDP is useful when speed and simplicity matter more than reliability. For scenarios that require guaranteed delivery, we need reliable data transfer protocols – our next topic.

4. Principles of Reliable Data Transfer

We incrementally develop a reliable data transfer protocol (rdt) over an unreliable channel. Finite state machines (FSMs) specify sender and receiver behaviour.

Protocol Channel Assumptions Key Mechanisms
rdt1.0 Perfectly reliable (no errors, no loss) No special mechanism needed
rdt2.0 / 2.1 / 2.2 Bit errors possible, no loss Checksum, ACKs/NAKs, sequence numbers (to handle duplicates)
rdt3.0 Bit errors and packet loss All above + timeout & retransmission (stop‑and‑wait)

rdt1.0 – Perfectly Reliable Channel

No bit errors, no loss. Sender sends packet, receiver extracts data. Trivial.

rdt2.0 – Channel with Bit Errors

rdt2.1 / 2.2 – Sequence Numbers, NAK‑free

rdt3.0 – Channel with Errors and Loss

Pipelined Protocols

To increase utilization, allow multiple in‑flight packets. Two generic approaches:

Go‑Back‑N (GBN)

  • Sender window of up to N unACKed packets.
  • Cumulative ACK: ACK(n) acknowledges all up to n.
  • On timeout, retransmit packet n and all higher seq # in window.
  • Receiver sends ACK for highest in‑order seq #; out‑of‑order packets discarded (no buffering).

Selective Repeat (SR)

  • Receiver individually ACKs all correctly received packets.
  • Buffers out‑of‑order packets for in‑order delivery.
  • Sender maintains timer for each unACKed packet, retransmits only lost packets.
  • Window size must be ≤ half of sequence number space to avoid overlap (dilemma with seq # wrap).

These reliable transfer principles underpin the design of TCP, which we explore next.

5. Connection-Oriented Transport: TCP

TCP: point‑to‑point, reliable, in‑order byte stream, full duplex, flow controlled, connection‑oriented. Uses cumulative ACKs, pipelining, and a dynamic window size.

TCP Segment Structure

 0                   16                   31
+--------+--------+--------+--------+
| source port        | dest port          |
+--------+--------+--------+--------+
| sequence number                        |
+--------+--------+--------+--------+
| acknowledgement number                 |
+--------+--------+--------+--------+
| hdr len | not used | U A P R S F       |
|         |          | R C S S Y I       |
|         |          | G K H T N N       |
+--------+--------+--------+--------+
| checksum           | receive window (rwnd) |
+--------+--------+--------+--------+
| options (if any)                       |
+--------+--------+--------+--------+
| application data (variable length)     |
+--------+--------+--------+--------+
        
Q: How to set TCP timeout value?

TCP uses an exponentially weighted moving average (EWMA) to estimate the round‑trip time (RTT) and to measure its variation. The actual timeout is the estimated RTT plus a safety margin (typically 4 times the mean deviation). This dynamic calculation prevents premature timeouts while still reacting quickly to packet loss.

TCP Reliable Data Transfer

Simplified sender: on data from app, create segment, start timer if not running. On ACK, update ACKed base, restart timer if still unACKed data. On timeout, retransmit oldest unACKed segment.

Fast retransmit: if sender receives 3 duplicate ACKs (triple duplicate ACK), resend missing segment immediately, without waiting for timeout.

Receiver ACK Generation (RFC 5681)

Event at Receiver TCP Receiver Action
In‑order segment with expected seq #, all data up to expected seq # already ACKed Delayed ACK – wait up to 500 ms for next segment; if no next segment, send ACK
In‑order segment with expected seq #, one other segment has ACK pending Immediately send single cumulative ACK, ACKing both in‑order segments
Out‑of‑order segment (higher‑than‑expected seq #) – gap detected Immediately send duplicate ACK, indicating seq # of next expected byte
Segment that partially or completely fills gap Immediate send ACK, provided that segment starts at lower end of gap

Reliable delivery alone is not enough – TCP also prevents a fast sender from overwhelming a slow receiver through flow control.

6. TCP Flow Control

Flow control prevents a fast sender from overwhelming a slow receiver. The receiver advertises rwnd (receive window) in the TCP header, telling the sender how much free buffer space it has.

How it works: sender limits unACKed data (in‑flight) to ≤ rwnd. This guarantees the receive buffer never overflows. RcvBuffer size set via socket options (default 4096 bytes, often auto‑adjusted).

Before any data can flow, TCP must first establish a connection – let’s see how the 3‑way handshake accomplishes that.

7. TCP Connection Management

TCP uses a 3‑way handshake to establish a connection:

  1. SYN (seq=x): Client sends SYN, enters SYN_SENT.
  2. SYN-ACK (seq=y, ACKnum=x+1): Server responds with SYN+ACK, enters SYN_RCVD.
  3. ACK (ACKnum=y+1): Client sends ACK; both sides now ESTABLISHED. Data may be piggybacked.

Connection closing involves FIN flags and a 2‑way or 3‑way exchange. The state transitions can be visualised as:

Active close (client): ESTAB → FIN_WAIT_1 → FIN_WAIT_2 → TIME_WAIT → CLOSED

Passive close (server): ESTAB → CLOSE_WAIT → LAST_ACK → CLOSED

A TIME_WAIT state (2×MSL) ensures any delayed packets are discarded before the socket is fully closed.

Why a 3‑way handshake? It prevents problems from duplicate connection requests (half‑open connections) and ensures both sides agree to establish the connection.
Security note – SYN Flood & SYN Cookies: An attacker can exhaust a server’s memory by sending many SYN segments without completing the handshake (half‑open connections). To counter this, modern operating systems use SYN cookies: the server does not allocate resources after the initial SYN. Instead, it encodes the connection state in the SYN-ACK sequence number. Only when the final ACK arrives and validates the cookie does the server create the connection state.

With a connection in place, TCP must share network capacity fairly; this leads us to congestion control.

8. Principles of Congestion Control

Congestion: too many sources sending too much data too fast for the network to handle. Manifested as long delays and packet loss. Distinct from flow control.

Costs of congestion: wasted capacity from retransmissions, long delays, and upstream resources wasted on eventually dropped packets.

Approaches to Congestion Control

We now focus on TCP’s end‑end congestion control, the dominant mechanism on the Internet.

9. TCP Congestion Control

TCP uses AIMD (Additive Increase, Multiplicative Decrease): increase sending rate by 1 MSS per RTT until loss detected, then halve the rate. This sawtooth behaviour probes for available bandwidth.

The principles of TCP congestion control have been evolving for decades; the latest major evolution is QUIC.

10. Evolution of Transport-Layer Functionality: QUIC

QUIC (Quick UDP Internet Connections) is an application‑layer protocol on top of UDP, designed to improve HTTP performance. It integrates reliability, congestion control, and encryption in one protocol, reducing handshake latency (1‑RTT, even 0‑RTT). QUIC supports multiple streams within a single connection, eliminating head‑of‑line blocking that occurs with TCP.

QUIC supports multiple streams, connection migration, and integrated TLS 1.3. It forms the basis of HTTP/3.

Key advantage: Connection migration (no need to re‑establish connection when IP address changes). Built‑in TLS 1.3 encryption.

Homework Assignment (Theoretical, Graded)

Instructions: Answer all questions in a separate document (PDF or Word). Submit via the learning platform. This assignment counts towards your final grade (5%).

Part I: Short Essays (40 points)

  1. Explain the difference between multiplexing and demultiplexing. How does TCP demultiplexing differ from UDP demultiplexing?
  2. Why does UDP exist? Give three applications that benefit from UDP and justify each.
  3. Describe the rdt3.0 protocol. Why is its performance poor on high‑speed links? Use the stop‑and‑wait concept in your explanation.
  4. Compare Go‑Back‑N and Selective Repeat. Discuss their handling of out‑of‑order packets and buffer requirements.
  5. What is the purpose of the TCP 3‑way handshake? Describe a scenario where a 2‑way handshake could cause problems.

Part II: True/False + Correction (30 points)

  1. UDP uses a 4-tuple to demultiplex segments. (True / False)
  2. In Go‑Back‑N, the receiver buffers out‑of‑order packets. (True / False)
  3. TCP fast retransmit occurs when the sender receives 3 duplicate ACKs. (True / False)
  4. TCP flow control is implemented using the congestion window (cwnd). (True / False)
  5. QUIC is built on top of TCP. (True / False)

For each false statement, write the correct version.

Part III: Theoretical Analysis & Scenarios (30 points)

  1. Stop‑and‑Wait vs Pipelining: If we have a very fast link, why does Stop‑and‑Wait fail to utilise the available bandwidth? What solution do Pipelining protocols offer, and how does it improve performance?
  2. Duplicate ACKs & Fast Retransmit: Explain why TCP immediately sends a duplicate ACK when an out‑of‑order segment arrives, and how the sender leverages these duplicate ACKs to trigger Fast Retransmit.

Grading criteria: correctness, completeness, proper use of terminology, and clarity of explanation.

Deadline: Two weeks from the lecture date.

Chapter 3 Summary

Self‑review questions (exam preparation):
• How does a TCP receiver generate ACKs?
• Why is the TCP checksum computed over a pseudo‑header that includes IP addresses?
• Why does TCP need a TIME_WAIT state after closing?