🚀 Tutorial 5: Pipelined Protocols – Go‑Back‑N and Selective Repeat (Advanced)
University‑level treatment – COMP347 (TrustOpen University)
🎯 Learning Objectives
After completing this tutorial, you should be able to:
- Explain the need for pipelining in reliable data transfer and its benefits over stop‑and‑wait.
- Describe the operation of Go‑Back‑N (GBN), including sender and receiver finite‑state machines, cumulative acknowledgments, and timeout handling.
- Describe the operation of Selective Repeat (SR), including sender and receiver windows, individual ACKs, buffering, and selective retransmission.
- Analyze the constraints on window size imposed by sequence number space for both GBN and SR.
- Compare GBN and SR in terms of efficiency, complexity, memory usage, and performance under different loss patterns.
- Evaluate the impact of window size, loss rate, and RTT on throughput for both protocols.
- Relate these protocols to TCP’s reliability mechanisms (cumulative ACKs, fast retransmit).
🔍 Overview
Stop‑and‑wait, while correct, suffers from poor link utilization due to the idle waiting period between transmissions. Pipelined protocols allow multiple packets to be in flight simultaneously, significantly improving throughput. This tutorial covers two classic pipelined error‑recovery protocols: Go‑Back‑N (GBN) and Selective Repeat (SR). Both are foundational to understanding how TCP achieves high performance. We will examine their sender and receiver behaviours, window management, sequence number requirements, and performance characteristics, and we will discuss their influence on modern transport protocols.
📘 1. Motivation for Pipelining
As we saw in Tutorial 4, stop‑and‑wait utilization is U = t_trans / (t_trans + 2*t_prop). For high‑bandwidth, long‑delay links, this ratio is extremely small. The solution is to allow multiple packets to be transmitted before waiting for acknowledgments. This is achieved by pipelining: the sender can send up to N packets without waiting for an ACK, where N is the window size.
Pipelining increases throughput by filling the network pipe. However, it introduces complexity in error recovery:
- How does the receiver handle out‑of‑order packets?
- How does the sender know which packets to retransmit when losses occur?
- How do we avoid ambiguity with sequence numbers?
Two main approaches emerged: Go‑Back‑N (simple receiver) and Selective Repeat (efficient retransmissions).
📘 2. General Pipelined Protocol Architecture
In a pipelined protocol, both sender and receiver maintain a window of sequence numbers. The sender window defines the range of packets that can be sent without waiting for ACKs. The receiver window defines which packets are acceptable to receive (and buffer).
- Sender window: typically bounded by N. Packets with sequence numbers in the window are either sent but unacknowledged, or ready to send. As ACKs arrive, the window slides forward.
- Receiver window: defines the sequence numbers that the receiver will accept. In GBN, the receiver window size is 1 (only expects the next in‑order packet). In SR, the receiver window size can be larger to buffer out‑of‑order packets.
Pipelining relies on sequence numbers of sufficient bits to uniquely identify packets in flight and avoid confusion after wraparound.
📘 3. Go‑Back‑N (GBN) – Detailed Analysis
3.1 Sender Operation
- Maintains a base (oldest unacknowledged packet) and a nextseqnum (next packet to send).
- Window size = N. Packets with seq numbers in [base, base+N-1] can be sent.
- When data arrives from application, if nextseqnum < base+N, send packet with seq = nextseqnum, increment nextseqnum; else block.
- On receipt of a cumulative ACK with acknowledgment number acknum: slide base to acknum (i.e., base = acknum). This acknowledges all packets up to acknum-1.
- On timeout: restart timer and retransmit all packets from base to nextseqnum-1 (i.e., the entire window).
- Typically uses a single timer for the oldest outstanding packet.
3.2 Receiver Operation
- Expects only the next in‑order packet (expectedseqnum).
- On arrival of packet with seq = expectedseqnum: deliver to application, send cumulative ACK (ack = expectedseqnum+1), increment expectedseqnum.
- On arrival of out‑of‑order packet (seq != expectedseqnum): discard the packet (no buffering) and resend ACK for the last in‑order packet (i.e., a duplicate ACK for expectedseqnum).
- Thus, the receiver window size is effectively 1.
3.3 Advantages and Disadvantages
- Advantages: Simple receiver (no buffering), simple sender (single timer).
- Disadvantages: Wastes bandwidth on retransmissions when a single packet is lost (must retransmit entire window).
📘 4. Selective Repeat (SR) – Detailed Analysis
4.1 Sender Operation
- Maintains a window of size N.
- Packets in the window can be sent; each packet has its own timer (or a single timer can be used with a list of outstanding).
- On timeout for a specific packet: retransmit only that packet.
- On receipt of an individual ACK for a packet: mark that packet as acknowledged. If the ACK acknowledges the lowest unacknowledged packet (base), slide the window forward over all consecutively acknowledged packets.
- Thus, the sender can retransmit selectively.
4.2 Receiver Operation
- Maintains a receiver window of size N (or at least as large as sender window).
- Accepts packets with sequence numbers within the receiver window, even if out of order.
- Buffers out‑of‑order packets until missing ones arrive.
- Sends individual ACK for every correctly received packet (including duplicates).
- When a packet is received with seq = expected (the lowest missing), deliver all consecutive buffered packets, and slide the window forward.
4.3 Advantages and Disadvantages
- Advantages: More efficient use of bandwidth; only lost packets are retransmitted.
- Disadvantages: More complex; receiver needs to buffer out‑of‑order packets; multiple timers needed (or more complex timer management).
📘 5. Sequence Number Space and Window Size Constraints
With finite‑bit sequence numbers, the window size cannot be arbitrarily large; otherwise, ambiguous situations arise when sequence numbers wrap around. The constraints differ for GBN and SR.
5.1 GBN Constraint
For GBN, the receiver discards out‑of‑order packets and sends duplicate ACKs. The sender may receive duplicate ACKs, but it only slides the window on a new cumulative ACK. To avoid ambiguity when a packet is retransmitted, we need Window size ≤ (Sequence number space) – 1.
With k‑bit sequence numbers, max window size = 2k – 1. For example, with 3 bits (0–7), max window = 7.
Why? If window size equals 2k, the sender could have all sequence numbers outstanding, and a delayed ACK for the first packet could be mistaken for an ACK for the retransmitted packet with the same sequence number.
5.2 SR Constraint
For SR, the receiver buffers out‑of‑order packets and uses individual ACKs. To avoid ambiguity between new packets and retransmissions, the window size must be ≤ half the sequence number space.
With k‑bit sequence numbers, max window size = 2k‑1. For example, with 3 bits, max window = 4.
Why? If window size > 2k‑1, after a wraparound, a packet could be mistaken for a new packet when ACKs are lost. The half‑space ensures that the sender and receiver windows do not overlap in a way that causes ambiguity.
5.3 Practical Implications
In TCP, sequence numbers are 32 bits, so the window size is limited by the 16‑bit window field in the TCP header (up to 65535), but with window scaling (RFC 1323), the effective window can be larger. TCP uses a variant of Selective Repeat (with SACK) but historically used cumulative ACKs.
📘 6. Performance Comparison: GBN vs. SR
6.1 Throughput Models
Assume a loss probability p for each packet (independent), window size N, and RTT.
- GBN: When a packet is lost, all packets from that point in the window are retransmitted. The expected number of transmissions per successfully delivered packet is approximately
1 / (1 - p) but with additional overhead due to the "go‑back" effect. A common approximation for throughput (with large N) is Throughput ≈ (1 - p) * N * MSS / RTT when N is small enough to avoid timeouts, but more exact models account for the probability of multiple losses.
- SR: Only the lost packet is retransmitted. The expected number of transmissions per packet is
1 / (1 - p). Throughput is roughly Throughput ≈ N * MSS / (RTT * (1 + overhead)), but each packet's retransmission is independent.
For a given loss rate, SR yields higher throughput because it retransmits less. However, GBN is simpler to implement.
6.2 Impact of Window Size
Larger windows improve utilization but increase the cost of a loss in GBN (more retransmissions). In SR, larger windows improve throughput but require more buffering and timers.
6.3 Impact of Loss Pattern
If losses are bursty, GBN may suffer greatly because many packets need retransmission. SR performs better because only the lost packets are retransmitted, but it relies on accurate ACKs.
6.4 Complexity Comparison
| Aspect | GBN | SR |
| Receiver buffering | None | Yes (up to N) |
| Sender timers | Single (oldest) | Multiple (one per outstanding packet) |
| ACK type | Cumulative | Individual |
| Retransmission | Entire window | Specific packets |
| Memory at receiver | Minimal | Potentially high |
📘 7. Advanced Topics: Dynamic Windows, SACK, and TCP Influences
7.1 Dynamic Window Sizing
In practice, the window size is often dynamic to adapt to network conditions (congestion control). TCP uses a congestion window (cwnd) that grows and shrinks based on loss signals. The concepts of GBN and SR are reflected in TCP's mechanisms: cumulative ACKs (GBN style) and fast retransmit (similar to SR's selective retransmission, especially with SACK).
7.2 Selective Acknowledgment (SACK)
TCP SACK (RFC 2018) allows the receiver to acknowledge non‑contiguous blocks of data, effectively enabling selective retransmission without the complexity of full SR at the transport layer. This bridges the gap between GBN and SR.
7.3 Impact of Out‑of‑Order Buffering
SR's receiver buffering requires memory and careful management to avoid head‑of‑line blocking. This is a key design consideration in high‑performance systems.
7.4 Relationship to TCP
TCP uses a sliding window with cumulative ACKs (like GBN) but also implements fast retransmit (which is SR‑like) when it receives 3 duplicate ACKs. This hybrid approach combines the simplicity of cumulative ACKs with the efficiency of selective retransmission for some losses.
📝 Quiz
Test your understanding with these 30 questions. Answers are hidden below each.
- What is the main advantage of pipelining over stop‑and‑wait?
Answer
It allows multiple packets to be in flight, increasing link utilization and throughput.
- In Go‑Back‑N, what does the sender do when a timeout occurs?
Answer
It retransmits all packets from the base to the current nextseqnum (the entire window).
- What type of ACK does Go‑Back‑N use?
Answer
Cumulative ACK.
- In Selective Repeat, what does the sender do when a timeout occurs for a specific packet?
Answer
It retransmits only that specific packet.
- What type of ACK does Selective Repeat use?
Answer
Individual ACKs for each packet.
- Does the receiver in Go‑Back‑N buffer out‑of‑order packets?
Answer
No, it discards them.
- Does the receiver in Selective Repeat buffer out‑of‑order packets?
Answer
Yes, it buffers them until the missing ones arrive.
- With 4‑bit sequence numbers, what is the maximum window size for Go‑Back‑N?
Answer
24 – 1 = 15.
- With 4‑bit sequence numbers, what is the maximum window size for Selective Repeat?
Answer
24‑1 = 8.
- Why does Selective Repeat require a window size ≤ half the sequence number space?
Answer
To avoid ambiguity between new packets and retransmissions when sequence numbers wrap around.
- In Go‑Back‑N, why is the window size limited to 2k – 1?
Answer
To avoid confusion when a delayed ACK for a packet with the same sequence number is mistaken for a new ACK.
- Which protocol is more efficient when the packet loss rate is high?
Answer
Selective Repeat, because it retransmits only lost packets.
- Which protocol is simpler to implement?
Answer
Go‑Back‑N, because the receiver has no buffering and the sender uses a single timer.
- In Go‑Back‑N, how does the receiver handle a corrupted packet?
Answer
It discards it and does not send an ACK; the sender will timeout and retransmit.
- In Selective Repeat, how does the receiver handle a corrupted packet?
Answer
It discards it; the sender will timeout for that packet and retransmit it.
- What is a cumulative ACK?
Answer
An ACK that acknowledges all packets up to a given sequence number.
- What is an individual ACK?
Answer
An ACK that acknowledges a specific packet by its sequence number.
- In Go‑Back‑N, what happens when the receiver receives an out‑of‑order packet?
Answer
It discards the packet and sends a duplicate ACK for the last in‑order packet.
- In Selective Repeat, what happens when the receiver receives an out‑of‑order packet?
Answer
It buffers the packet and sends an individual ACK for it.
- How does the sender in Selective Repeat know which packets have been acknowledged?
Answer
It maintains a record of ACKs received for each packet in the window.
- How does the sender in Go‑Back‑N know which packets have been acknowledged?
Answer
It uses the base pointer; all packets before base are acknowledged.
- In Go‑Back‑N, what does the sender do when it receives a duplicate ACK?
Answer
It ignores it (unless it triggers a fast retransmit in some variants, but that is not part of basic GBN).
- In Selective Repeat, what does the sender do when it receives a duplicate ACK?
Answer
It ignores it (since it already has the ACK for that packet).
- Which protocol requires more memory at the receiver?
Answer
Selective Repeat, because it buffers out‑of‑order packets.
- Which protocol is more prone to wasting bandwidth when losses occur?
Answer
Go‑Back‑N, because it retransmits the entire window.
- What is the role of the timer in Go‑Back‑N?
Answer
To detect lost packets; a single timer for the oldest outstanding packet.
- What is the role of timers in Selective Repeat?
Answer
Each outstanding packet may have its own timer to detect loss of that specific packet.
- Can Go‑Back‑N be used with a window size larger than 2k – 1?
Answer
No, it would cause ambiguity.
- Can Selective Repeat be used with a window size larger than 2k‑1?
Answer
No, it would cause ambiguity.
- Which protocol does TCP primarily resemble?
Answer
TCP uses cumulative ACKs (like GBN) but also incorporates selective retransmission via fast retransmit and SACK, making it a hybrid.
🛠️ Exercises
Apply your knowledge with these 15 exercises. Solutions are provided below each.
- Exercise 1: GBN Retransmission
Suppose GBN with window size N=4. Sender sends packets 0,1,2,3. Packet 1 is lost. Describe the sender and receiver actions.
Solution
Receiver gets packet 0 (ACK 0), packet 2 and 3 are out of order, so they are discarded and duplicate ACKs (ACK 0) are sent. Sender times out, retransmits packets 1,2,3.
- Exercise 2: SR Retransmission
Using SR with window size N=4, packets 0,1,2,3 sent. Packet 2 lost. Describe the actions.
Solution
Receiver gets 0,1,3; sends ACK 0,1,3; buffers 3. Sender gets ACKs, slides window to 4,5,6,7, but packet 2 still unacknowledged. Timer for 2 expires; retransmit only 2. Receiver gets 2, delivers in order.
- Exercise 3: Window Size Calculation
With 5‑bit sequence numbers, what are the maximum sender window sizes for GBN and SR?
Solution
5 bits → 32 seq numbers. GBN max = 31, SR max = 16.
- Exercise 4: GBN Duplicate ACK
In GBN, why does the receiver send duplicate ACKs for out‑of‑order packets?
Solution
To inform the sender that it is still expecting the next in‑order packet and to help detect losses (used later for fast retransmit in TCP).
- Exercise 5: SR Window Slide
In SR, sender window base = 2, nextseqnum = 6, N=4. Which sequence numbers are in the window?
Solution
Window: [2, 3, 4, 5].
- Exercise 6: GBN Timer
In GBN, how many timers does the sender maintain? Why?
Solution
One timer for the oldest unacknowledged packet. Since all outstanding packets are retransmitted together, a single timer suffices.
- Exercise 7: SR Timer Management
In SR, the sender has 5 outstanding packets. How many timers might be active?
Solution
Up to 5 (one per packet), though a single timer per packet is common.
- Exercise 8: GBN and ACK Loss
In GBN, if an ACK for packet 0 is lost, but ACK for packet 1 arrives, what happens?
Solution
The cumulative ACK for packet 1 acknowledges both 0 and 1, so the sender slides base to 2. The lost ACK is harmless.
- Exercise 9: SR and ACK Loss
In SR, if ACK for packet 0 is lost, but ACK for packet 1 arrives, what happens to packet 0?
Solution
Sender still has packet 0 marked as unacknowledged; it will timeout and retransmit packet 0. The ACK for packet 1 does not acknowledge packet 0.
- Exercise 10: Throughput Comparison
For a loss rate of 1%, which protocol (GBN or SR) would have higher throughput? Briefly explain.
Solution
SR would have higher throughput because it only retransmits the lost packet, while GBN retransmits the entire window, wasting bandwidth.
- Exercise 11: GBN with Large Window
If GBN window size is 8 and sequence numbers are 3 bits, what problem occurs?
Solution
Window size equals 23 = 8, which is not allowed (max is 7). Ambiguity can arise when sequence numbers wrap.
- Exercise 12: SR with Large Window
If SR window size is 5 and sequence numbers are 3 bits, is this valid?
Solution
No, max for SR with 3 bits is 4 (22). Window size 5 violates the half‑space constraint.
- Exercise 13: GBN Receiver State
In GBN, if the receiver receives a packet with sequence number 5 but expected sequence number is 4, what does it do?
Solution
It discards packet 5 and sends a duplicate ACK for sequence 4.
- Exercise 14: SR Receiver Buffering
In SR, if receiver window size is 4 and expected seq is 2, which sequence numbers are in the window?
Solution
[2, 3, 4, 5].
- Exercise 15: Hybrid Approach
How does TCP combine GBN and SR features?
Solution
TCP uses cumulative ACKs (like GBN) for most acknowledgments, but implements fast retransmit (when 3 duplicate ACKs are received) which selectively retransmits the lost packet (like SR). With SACK, TCP can explicitly acknowledge non‑contiguous blocks, enabling full selective retransmission.
📚 Homework
These advanced problems require synthesis, quantitative analysis, and research. Sample answers are provided below.
- Problem 1: Derive GBN Throughput with Loss
Derive an expression for the throughput of GBN as a function of packet loss probability p, window size N, and RTT. Assume that losses are independent and timeouts are rare. Hint: consider the expected number of transmissions per packet.
Sample Answer
Let p be loss probability. In GBN, when a packet is lost, N packets are retransmitted. The expected number of transmissions per successfully delivered packet is approximately 1/(1-p) * (1 + N*p*(1-p)?). A simplified model: throughput ≈ (1-p) * N * MSS / RTT, but with a penalty of (1 + (N-1)*p) due to retransmission overhead. More precise models can be found in networking literature.
- Problem 2: SR Throughput with Loss
For SR, derive the expected number of transmissions per packet and the throughput. Assume independent losses.
Sample Answer
Expected transmissions per packet = 1/(1-p). Throughput ≈ N * MSS / (RTT * (1 + overhead)) but since each packet is independent, the link can be fully utilised if N is large enough to fill the pipe. However, the need for individual ACKs adds overhead.
- Problem 3: Sequence Number Space Design
Suppose you are designing a new reliable protocol with pipelining that uses selective retransmission. You need to support a window size of 16. What is the minimum number of sequence bits required?
Sample Answer
For SR, window ≤ 2k‑1. To get ≥16, we need 2k‑1 ≥ 16 → k‑1 ≥ 4 → k ≥ 5. So 5 bits.
- Problem 4: GBN vs SR Memory Requirements
Compare the memory requirements of the receiver for GBN and SR when the window size is N and each packet is L bytes. Which is more memory‑intensive?
Sample Answer
GBN receiver requires no buffering (0 bytes). SR receiver may buffer up to N packets, requiring N*L bytes. Thus SR is much more memory‑intensive.
- Problem 5: Impact of Bursty Loss
If losses occur in bursts (e.g., a router drops 3 consecutive packets), how does GBN vs SR perform?
Sample Answer
GBN will retransmit the entire window after the first loss, which may include many packets, some of which may already be lost again. SR will retransmit each lost packet individually, which can be more efficient if losses are infrequent. For burst losses, GBN's retransmission of the whole window might actually help by sending all packets again, but it wastes bandwidth for packets that were not lost.
- Problem 6: Timer Granularity in GBN
If the timer in GBN is coarse (e.g., can only be set in multiples of 100 ms), how does this affect performance?
Sample Answer
A coarse timer may cause the sender to wait longer than necessary before retransmitting, reducing throughput. It may also lead to unnecessary retransmissions if the timer is too short, causing spurious retransmissions.
- Problem 7: Selective Repeat with Cumulative ACKs
Could Selective Repeat use cumulative ACKs? What would be the implications?
Sample Answer
SR could use cumulative ACKs, but then the sender would not know which specific packets were lost unless it also uses NAKs or timeouts. Cumulative ACKs would reduce the granularity of feedback, potentially causing more retransmissions. The protocol would become closer to GBN.
- Problem 8: GBN with Piggybacked ACKs
If data flows in both directions, ACKs can be piggybacked on data packets. How does this affect GBN?
Sample Answer
Piggybacking reduces the number of separate ACK packets, saving bandwidth. However, the sender still relies on the cumulative ACK to slide the window, so the same loss recovery rules apply.
- Problem 9: Window Size and Delay
How does the window size affect the end‑to‑end delay (latency) for a large file transfer?
Sample Answer
A larger window allows more data to be in flight, which can reduce the time to send the file (higher throughput), but it may increase the time to recover from losses because more data may need to be retransmitted (especially in GBN).
- Problem 10: Adaptive Window Sizing
Propose a heuristic to dynamically adjust the window size in GBN or SR based on observed loss rate.
Sample Answer
If loss rate is low, increase window size to improve throughput. If loss rate exceeds a threshold, decrease window size to reduce the cost of retransmissions. This is analogous to TCP's congestion control.
- Problem 11: Receiver Window in SR
In SR, the receiver window size can be the same as the sender's, or larger. What happens if the receiver window is smaller?
Sample Answer
If receiver window < sender window, the receiver may not accept certain in‑flight packets, causing unnecessary discards. The receiver window must be at least as large as the sender window to accept all packets in the sender's window.
- Problem 12: GBN with Fast Retransmit
How would you add fast retransmit to GBN to improve performance?
Sample Answer
Instead of waiting for a timeout, if the sender receives N duplicate ACKs (typically 3), it could immediately retransmit the oldest unacknowledged packet. This would reduce recovery time for single packet losses, similar to TCP.
- Problem 13: SR and Duplicate ACKs
In SR, why might a receiver send a duplicate ACK for a packet it already acknowledged?
Sample Answer
If the sender retransmits a packet that the receiver already has (e.g., because the original ACK was lost), the receiver will send a duplicate ACK to confirm its receipt. This helps the sender know that the packet is acknowledged.
- Problem 14: Performance under High RTT
For a satellite link with high RTT (500 ms) and low loss, which protocol would you choose? Justify.
Sample Answer
Both protocols would benefit from pipelining, but SR would be preferred because any loss would cause GBN to waste a lot of bandwidth retransmitting many packets. With low loss, SR's overhead is acceptable.
- Problem 15: Formal Specification
Write a formal specification of the SR receiver FSM, including states, events, and actions.
Sample Answer
States: Wait for packet (expected = e). On arrival with seq = e: deliver, send ACK for e, e++ until all buffered consecutive packets delivered. On arrival with seq within window and seq != e: buffer, send ACK for seq. On arrival out of window: discard.
📌 Summary
- Pipelining improves link utilization by allowing multiple outstanding packets.
- Go‑Back‑N uses cumulative ACKs, a single timer, and retransmits the entire window on loss. Simple but wasteful.
- Selective Repeat uses individual ACKs, per‑packet timers, and retransmits only lost packets. More efficient but more complex.
- Window size constraints depend on sequence number space: for GBN, ≤ 2k – 1; for SR, ≤ 2k‑1.
- SR provides better performance under loss, but requires buffering and timer management.
- TCP combines elements of both: cumulative ACKs with fast retransmit and SACK for selective recovery.
In the next tutorial, we will examine TCP Fundamentals and Segment Structure, applying the principles of pipelining to the real‑world transport protocol.