1
CS 168, Summer 2025 @ UC Berkeley
Slides credit: Sylvia Ratnasamy, Rob Shakir, Peyrin Kao
Reliability
Lecture 10 (Transport 1)
1
2
3
4
ack(1)
ack(2)
ack(3)
ack(4)
✗
2
Transport Layer Design Goals
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Transport Layer Protocols
Layer 3 (IP) gave us the ability to send packets anywhere in the Internet.
Layer 4 (Transport) builds extra features on top of Layer 3.
Let's check out each of these features.
Transport Layer Feature: De-Multiplexing with Ports
Recall: Protocol field in IP Header (L3) supports de-multiplexing between L4 protocols.
Operating
System
Network Interface Card
IP
TCP
UDP
Firefox
Zoom
Slack
Game
Layers 1–2
Layer 3
Layer 4
Layer 7
IP Header
IP Payload
(TCP? UDP?)
Transport Layer Feature: De-Multiplexing with Ports
Port field in TCP header (L4) supports de-multiplexing between L7 applications.
TCP Header
TCP Payload
(Slack? Email?)
Operating
System
Network Interface Card
IP
TCP
UDP
Firefox
Zoom
Slack
Game
Layers 1–2
Layer 3
Layer 4
Layer 7
Transport Layer Feature: De-Multiplexing with Ports
Protocol (L3) and port (L4) together allow us to de-multiplex arriving packets.
TCP Header
TCP Payload
(Slack? Email?)
Operating
System
Network Interface Card
IP
TCP
UDP
Firefox
Zoom
Slack
Game
Layers 1–2
Layer 3
Layer 4
Layer 7
IP Header
Transport Layer Feature: De-Multiplexing with Ports
Ports identify the attachment point between the application and the OS.
Ports allow data to pass between the application and the OS, without mixing up data between applications.
Operating
System
Network Interface Card
IP
TCP
UDP
Firefox
Zoom
Slack
Game
Layers 1–2
Layer 3
Layer 4
Layer 7
Warning: Naming conflict.
Both are often called "ports."
Transport Layer Feature: De-Multiplexing with Ports
Analogy: Ports are like room numbers in a house/building.
Ports identify applications on a specific machine.
Transport Layer Feature: Reliability
Many application semantics involve reliable delivery.
Implemented by TCP, but not UDP.
Challenge: Building a reliable service (L4) on top of unreliable packet delivery (L3).
Transport Layer Feature: New Abstractions: Bytestream
TCP implementing reliability gives the application a new abstraction.
Arbitrary data...so I tied an onion to my belt, which was the style at the time...
Transport Layer
Recipient
Application
Sender
Application
Transport Layer Feature: New Abstractions: Datagram
UDP does not implement reliability, and it gives users the datagram abstraction.
Recipient
Application
Sender
Application
So I tied an
onion to my
belt, which
was the style
at teh time
Corrupted.
Out of order.
Dropped.
So I tied an
Duplicate.
Transport Layer Protocols
Two choices of protocols at Layer 4:
The programmer can choose which one to use.
TCP
Transport Layer Protocols
UDP
We're about to spend a lot of time here, but don't forget the bigger picture.
Transport Layer is Implemented at End Hosts
Both TCP and UDP are implemented at end hosts, not intermediate routers.
2. Link
3. IP
1. Physical
4. Transport
7. Application
End Host (Sender)
2. Link
3. IP
1. Physical
4. Transport
7. Application
End Host (Recipient)
2. Link
3. IP
1. Physical
Router
2. Link
3. IP
1. Physical
Router
2. Link
3. IP
1. Physical
Router
Implementing Reliability:�Single Packet
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Implementing Reliability
Challenge: Building a reliable service (L4) on top of unreliable packet delivery (L3).
Goals for reliable transfer:
Defining Reliability
3 different definitions of reliability:
Our plan for bridging the abstraction gap:
Defining Reliability
A reliability protocol is allowed to give up, but must announce it to the application.
Reminder: Timing Diagrams
Sender
Recipient
Time increases as we move down the diagram.
One-way delay
Round-trip time (RTT)
Designing Reliability for a Single Packet
Let's start with providing at-least-once delivery for a single packet.
We have to deal with 5 problems from the best-effort service model:
Designing Reliability for a Single Packet
The packet is sent. How does the sender know if it was received successfully?
Solution: The recipient replies with an acknowledgment (ack).
ack
Sender
Recipient
Problem 1/5: Dropped Packets
Solution: Set a timer when we send the packet.
If the timer expires and we don't get the ack, resend the packet.
When we get the ack, cancel the timer.
ack
Sender
Recipient
Start timer
Timeout!
Restart timer
✗
Cancel timer
Problem 1/5: Dropped Packets
What if the ack gets dropped?
The timer expires, and the packet gets resent. Repeat until the ack arrives.
The destination received the packet twice, but that's okay (at-least-once delivery).
ack
Sender
Recipient
Start timer
Timeout!
✗
Cancel timer
ack
Restart timer
Problem 1/5: Dropped Packets
How do we set the timer length?
Ideally: Timer is proportional to RTT (round-trip time).
In practice: Measuring the RTT is non-trivial.
Problem 2/5: Corrupted Packets
Add a checksum to detect corruption. 2 approaches to dealing with a bad checksum:
Solution 1: When you get a corrupt packet, send a negative acknowledgement (nack).
Sender sees the nack and resends.
ack
Sender
Recipient
✗ Bad checksum
nack
Problem 2/5: Corrupted Packets
Solution 2: When you get a corrupt packet, ignore it (don't send the ack).
Sender times out and resends.
Both solutions work. TCP uses this one (no nacks).
ack
Sender
Recipient
✗ Bad checksum
Timeout!
Problem 3/5: Delayed Packets
Minor delay: No problem. The ack still arrives before the timeout.
ack
Sender
Recipient
Problem 3/5: Delayed Packets
Longer delay: Sender times out and resends.
The sender receives two acks. That's fine.
ack
Sender
Recipient
Timeout!
ack
Problem 4/5: Duplicated Packets
The recipient gets the packet twice, and the sender receives two acks. That's fine.
Why would the network even duplicate a packet?
Usually, because of link-level reliability gone wrong (very rare).
ack
Sender
Recipient
ack
Designing Reliability for a Single Packet
Sender:
Recipient:
We solved all 5 problems from the best-effort service model:
Designing Reliability for a Single Packet
What did we learn from this protocol?
At-least-once delivery simplifies our protocol.
Multiple Packets, Windows
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Designing Reliability for Multiple Packets
We can use the single-packet solution repeatedly to support sending multiple packets.
One extra design component: sequence numbers.
Recipient
Application
Sender
Application
1. So I tied an
2. onion to my
3. belt, which
4. was the style
5. at the time
1. So I tied an
Duplicates. Same number.
Out of order. Use numbers to rearrange.
Sequence Numbers
Each packet has a unique, increasing sequence number.
Acks indicate which packet is being acked.
ack (1)
Sender
Recipient
ack (2)
Stop-and-Wait Protocol
Naive approach: Wait for packet i to be acked before sending packet i+1.
Sender
Recipient
1
ack (1)
2
ack (2)
3
ack (3)
4
ack (4)
Total time to send 4 packets.
Window-Based Algorithms
Better approach: Send more packets while waiting for acks.
Idea: Have multiple packets in flight simultaneously.
In flight: Packet has been sent, but has not been acked yet.
Sender
Recipient
1
2
3
4
ack(1)
ack(2)
ack(3)
ack(4)
Total time to send 4 packets.
Window-Based Algorithms
Idea: Have multiple packets in flight simultaneously.
Could we send all the packets at once?
Window-based algorithms: Limit the amount of packets in flight.
To stay inside the window limit:
Window isn't necessary for correctness, but is added for efficiency (performance).
Window-Based Algorithms
Start: Send W = 4 packets. In-flight packets: {1, 2, 3, 4}.
When ack(1) arrives: Send 5. In-flight packets: {2, 3, 4, 5}.
When ack(2) arrives: Send 6. In-flight packets: {3, 4, 5, 6}.
Sender
Recipient
1
2
3
4
ack(1)
ack(2)
5
6
W = 4
Setting Window Size
How big should the window be?
Pick window size W to balance three goals:
Setting Window Size (1/3): Filling the Pipe
First goal: Take advantage of network capacity ("fill the pipe").
How to compute this W?
More generally: W = RTT × bandwidth.
Setting Window Size (1/3): Filling the Pipe
After sending the maximum W = 4 packets, the sender sits idle, waiting for ack(1).
This window size is too small to fill the pipe.
Sender
Recipient
ack(1)
5
W = 4
The first RTT
1
2
3
4
Setting Window Size (1/3): Filling the Pipe
The sender is busy the entire RTT sending W = 6 packets.
ack(1) arrives just as the last of the 6 packets leaves.
Sender
Recipient
1
2
3
4
5
6
7
ack(1)
W = 6
The first RTT
Setting Window Size (1/3): Filling the Pipe
To fill the pipe: W = RTT × bandwidth.
What exactly is the bandwidth?
We could rewrite this in terms of bytes, not packets.
This gives us an upper bound on the desired size of W.
Setting Window Size (1/3): Filling the Pipe (W = 6)
7
7
7
7
6
5
4
3
2
1
Sender
Recipient
t = 0
6
5
4
3
2
1
Sender
Recipient
t = 1
6
5
4
3
1
Sender
Recipient
t = 2
6
5
4
1
3
Sender
Recipient
t = 3
2
2
In flight: 0
In flight: 1
In flight: 2
In flight: 3
Setting Window Size (1/3): Filling the Pipe (W = 6)
7
7
7
6
5
Sender
Recipient
t = 4
6
Sender
Recipient
t = 5
5
Sender
Recipient
t = 6
5
7
Sender
Recipient
t = 7
6
6
3
5
4
4
3
4
2
ack(1)
ack(2)
ack(1)
ack(3)
ack(2)
ack(1)
ack(4)
ack(3)
ack(2)
1
1
1
1
2
2
3
2
3
4
ack(1)
In flight: 4
In flight: 5
In flight: 6
In flight: 6
Setting Window Size (1/3): Filling the Pipe (W = 3)
7
7
7
6
5
Sender
Recipient
t = 4
6
Sender
Recipient
t = 5
Sender
Recipient
t = 6
4
Sender
Recipient
t = 7
3
3
2
ack(1)
ack(2)
ack(1)
ack(3)
ack(2)
ack(1)
ack(4)
ack(3)
ack(2)
ack(1)
1
1
1
1
2
2
3
2
3
4
5
4
6
5
4
7
6
5
In flight: 3
In flight: 3
In flight: 3
In flight: 3
Avoiding Overload: Flow Control and Congestion Control
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Setting Window Size
How big should the window be?
Pick window size W to balance three goals:
Setting Window Size (2/3): Don't Overload Recipient (Flow Control)
Consider the recipient:
We have to make sure the recipient doesn't run out of buffer space.
The application expects 3 next, but the sender gave me 4 and 5.
I'll hold on to 4 and 5 while waiting for 3 to arrive.
Recipient OS�(running TCP)
Recipient Application
1. So I tied an
2. onion to my
4. was the style
5. at the time
Setting Window Size (2/3): Don't Overload Recipient (Flow Control)
Flow control ensures the recipient has enough buffer space for out-of-order packets.
Recipient tells the sender how much space it has left.
Sender adjusts its window accordingly.
Recipient OS�(running TCP)
Recipient Application
1. So I tied an
2. onion to my
4. was the style
5. at the time
ack(5).
By the way, I only have enough space for 2 more packets.
To: Sender
Setting Window Size (3/3): Don't Overload Network (Congestion Control)
Previously, we set W to fully consume the bottleneck link bandwidth.
In practice, the bottleneck is shared with other flows.
A
S
B
D
10 Gbps
1 Gbps
5 Gbps
Recall: W = RTT × bandwidth.
So W and bandwidth are proportional (roughly speaking).
0.5 Gbps
0.5 Gbps
Setting Window Size (3/3): Don't Overload Network (Congestion Control)
The sender's TCP code implements a congestion control algorithm that dynamically computes the sender's share of bandwidth.
More about the algorithms later.
Recall: W = RTT × bandwidth.
So W and bandwidth are proportional (roughly speaking).
I have magically decided that W = 7 avoids overloading the network.
A
S
B
D
10 Gbps
1 Gbps
5 Gbps
0.5 Gbps
0.5 Gbps
Setting Window Size
How big should the window be?
Pick window size W to balance three goals:
Ideally: W is set to the minimum of the 3 values.
In practice: W is the minimum of advertised window (2) and congestion window (3).
Smarter Acknowledgments
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Ack Strategy (1/3): Individual Packet Acks
Our design so far: Individual packet acks.
When you receive packet i, send ack(i).
Sender
Recipient
1
2
3
4
ack(1)
ack(2)
ack(3)
ack(4)
✗
2
Unnecessary and avoidable retransmission!
Ack Strategy (2/3): Full Information Acks
Smarter idea: Full information acks.
When you receive a packet, send an ack listing every packet received.
Sender
Recipient
1
2
3
4
Received 1.
Received 1, 2.
Received 1, 2, 3.
Received 1, 2, 3, 4.
✗
Sender learns that 2 was received.
Ack Strategy (2/3): Full Information Acks
Full information ack format: "All packets 1~n, plus [list out all other packets]."
Example: "I received all packets up to 12, plus 14, 15, 16."
Problem: The list can get long.
Sender
Recipient
1
2
3
4
5
6
7
Received all up to 1.
Received all up to 1, plus [3].
Received all up to 1, plus [3, 5].
Received all up to 1, plus [3, 5, 7].
✗
If every even-numbered packet is dropped:
"Received all up to 1, plus [3, 5, 7, ..., 999]."
Long.
✗
✗
Ack Strategy (3/3): Cumulative Acks
What TCP actually uses: Cumulative acks.
Example: "I received all packets up to 12, plus 14, 15, 16." (Full info, minus the list.)
Ack the highest sequence number for which all previous packets have been received.
Sender
Recipient
1
2
3
4
5
6
7
Received all up to 1.
Received all up to 1, plus [3].
Received all up to 1, plus [3, 5].
Received all up to 1, plus [3, 5, 7].
✗
If every even-numbered packet is dropped:
"Received all up to 1, plus [3, 5, 7, ..., 999]."
Shorter, but more ambiguous.
✗
✗
Ack Strategies
Individual packet acks: Each ack corresponds to one packet.
Full information acks: Each ack lists all packets received.
Cumulative acks: Each ack says, "all packets up to n received."
TCP uses cumulative acks.
Detecting Loss Early
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Smarter Loss Detection
So far, we detect loss by waiting for a timeout.
Another approach: Detect loss when acks for subsequent packets arrive.
Implementing ack-based loss detection depends on the type of ack we're using.
1 millisecond = 1,000,000 nanoseconds.
Ack-Based Loss Detection: Individual Acks
Individual acks: Declare a packet lost if k subsequent packets are acked.
Sender OS�(running TCP)
ack(1)
ack(2)
ack(3)
ack(4)
ack(6)
ack(7)
ack(8)
I received ack(6), ack(7), and ack(8).
I'll assume 5 is lost and resend it.
Ack-Based Loss Detection: Full-Information Acks
Full-information acks: Declare a packet lost if k subsequent packets are acked.
We can see the gap in packets: "up to 4, plus 6, 7, 8" → 5 is missing.
Sender OS�(running TCP)
up to 1
up to 2
up to 3
up to 4
up to 4,
plus 6
up to 4,
plus 6, 7
up to 4, plus 6, 7, 8
I received acks for 6, 7, 8.
I'll assume 5 is lost and resend it.
Ack-Based Loss Detection: Cumulative Acks
Cumulative acks: Declare loss if k duplicate acks are received.
Duplicate acks: Later packets (6, 7, 8) received, but there's a gap, so the "up to 4" cumulative ack cannot increase.
Sender OS�(running TCP)
up to 1
up to 2
up to 3
up to 4
up to 4
up to 4
up to 4
I received 3 copies of "up to 4" (plus the original).
That means 3 extra packets were received (and none of them are 5).
I'll assume 5 is lost and resend it.
ack for 6�dup #1
ack for 7�dup #2
ack for 8�dup #3
Responding to Loss
Timeouts:
Subsequent acks: (This strategy is sometimes called "fast retransmit.")
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8
Assumptions:
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8 9
Assumptions:
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10
Assumptions:
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11
Assumptions:
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11 12
Assumptions:
Responding to Loss: Individual Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11 12 13
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8
# duplicate acks = 0
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9
# duplicate acks = 1
Assumptions:
Note: It might look like there's 7 packets in flight.
But the duplicate ACK 3 tells us one of them was received.
We just don't know which one, so we can't mark it.
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10
# duplicate acks = 2
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11
# duplicate acks = 3
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11 12
# duplicate acks = 4
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11 12 13
# duplicate acks = 5
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# duplicate acks = 6
Assumptions:
Responding to Loss: Cumulative Acks, Multiple Losses
Problem: Cumulative acks don't tell the sender exactly which packets were received.
Unfortunately, TCP uses cumulative acks, so we have to deal with this ambiguity.
Alternate Designs
Lecture 10, CS 168, Summer 2025
Transport Layer Design Goals
Implementing Reliability
Alternate Designs to Implementing Reliability
We implemented reliability by re-sending lost packets.
Another possible approach: Sender encodes the data to be resilient to loss.
Example:
Vast literature exists on coding schemes.
Historically, not used very much, but that could change... (e.g. video streaming).
Summary: Design Choices
We've covered all the basic building blocks of TCP.
Along the way, we sometimes had to pick one design out of several alternatives.
Other Design Choices
TCP made specific design choices (e.g. we chose cumulative acks).
If you make different choices, you'll get different reliability protocols.
Understanding how to design and evaluate a reliability protocol is more important than memorizing the details of any specific implementation!