Skip to main content

2.5 Sliding Window Protocol: Selective Repeat (SR) ARQ

πŸ“šModule 02: Data Link Layer: Framing, Flow & Error ControlTopic 2.5⏱️12 min read
🎯High-Yield For:Semester Exams (All Universities) β€’ Placement Technical Rounds β€’ Engineering Foundations

πŸ’‘ Core Intuition: The E-Commerce Package Delivery Analogy​

🍳 The Everyday Analogy: The Hallway Storage Closet​

Imagine ordering a 4-piece home audio system (Amplifier, Left Speaker, Right Speaker, Subwoofer) from an online retailer:

  • The warehouse ships all 4 items simultaneously in separate delivery vans.
  • Van 1 (Amplifier) arrives safely at your door; you accept it.
  • Van 2 (Left Speaker) encounters an accident and is lost in transit.
  • Van 3 (Right Speaker) and Van 4 (Subwoofer) arrive safely at your door.

Under Go-Back-N rules, because you strictly wanted item 2 next and refused to hold out-of-order boxes, you would throw the Right Speaker and Subwoofer into the trash and demand the seller re-ship items 2, 3, and 4 from scratch!

Under Selective Repeat (SR) rules:

  • You have a storage closet in your hallway (Receiver Buffer).
  • You place the Right Speaker and Subwoofer into the closet, notify customer support that the Left Speaker is missing (Negative Acknowledgment / NAK), and wait.
  • The retailer re-ships only the Left Speaker.
  • When the Left Speaker arrives, you retrieve the Right Speaker and Subwoofer from your closet, assemble the complete 4-piece audio set in order, and enjoy your music. Zero undamaged packages are wasted!

πŸ’» Bridging to Computer Science​

Selective Repeat resolves the primary bottleneck of sliding window protocols on noisy channels: by adding memory buffers at the receiver and dedicating individual timers at the transmitter, the protocol isolates errors to only the corrupted frame, achieving maximum throughput with zero redundant retransmissions.



⚑ Why Selective Repeat? Overcoming GBN Inefficiencies​

While Go-Back-N provides full channel pipelining, it suffers from a fatal flaw on noisy transmission links:

  • In GBN, losing a single frame forces the retransmission of an entire window of WSW_S frames, even though the receiver may have already ingested subsequent frames error-free.
  • On high-speed, long-distance links with large Bandwidth-Delay Products (BDPBDP), retransmitting WSW_S frames consumes enormous channel capacity, causing throughput to drop precipitously.

Selective Repeat (SR) ARQ eliminates this retransmission waste:

  1. The receiver is equipped with a memory buffer of size WR>1W_R > 1 to hold out-of-order, undamaged frames.
  2. The sender maintains an independent timer for every outstanding frame.
  3. When an error occurs, the sender retransmits only the specific missing or damaged frame, preserving all other packets in the receiver's buffer.

πŸͺŸ Selective Repeat Architecture & Windows​

In Selective Repeat, both the sender and the receiver maintain active sliding windows over the sequence number space.

Architecture Flow

Selective Repeat Window Symmetry & Buffer Architecture

Symmetric sender and receiver buffer allocation across sequence space 2^k

πŸ“€Transmit Window

Sender Window Ws = 2^(k-1)

Tracks up to 2^(k-1) outstanding frames, each with an independent timer.

β†’
Physical Channel Transit
πŸ’½Receive Buffer

Receiver Window Wr = 2^(k-1)

Buffers out-of-order undamaged frames within range [Rf, Rf + Wr).

β†’
In-Order Batch Release
πŸš€Upper Layer

Network Layer L3 Sink

Packets delivered strictly in sequential order when lowest frame arrives.

The Symmetrical Window Configuration​

In standard implementations, the sender window size and receiver window size are set symmetrically: WS=WR=2kβˆ’1\mathbf{W_S = W_R = 2^{k-1}} Where kk is the number of bits allocated to sequence numbers in the frame header.

  • For k=3k = 3 bits: Sequence space is 23=82^3 = 8 (values 0,1,…,70, 1, \dots, 7).
    • WS=23βˆ’1=4W_S = 2^{3-1} = 4.
    • WR=23βˆ’1=4W_R = 2^{3-1} = 4.

πŸ”’ The Master Mathematical Theorem: WS+WR≀2kW_S + W_R \le 2^k​

The most fundamental theorem governing sliding window protocols dictates that the sum of the sender window size and receiver window size cannot exceed the total sequence number space: WS+WR≀2k\mathbf{W_S + W_R \le 2^k}

Proof by Contradiction: What Happens If WS+WR>2kW_S + W_R > 2^k?​

Let k=2k = 2 bits β€…β€ŠβŸΉβ€…β€Š\implies total sequence numbers available =22=4= 2^2 = 4 (values 0,1,2,30, 1, 2, 3).
Suppose we violate the theorem and set WS=3W_S = 3 and WR=2W_R = 2, so that WS+WR=5>4W_S + W_R = 5 > 4:

  1. Initial Window State:
    • Sender Window WS=3W_S = 3 (Slots: 0, 1, 2).
    • Receiver Window WR=2W_R = 2 (Slots: 0, 1).
  2. Initial Burst:
    • Sender transmits Frames 0, 1, and 2.
  3. Receiver Progress:
    • Receiver ingests Frame 0 and Frame 1 safely into its buffer.
    • Receiver delivers Frames 0 and 1 to the Network Layer and advances its window forward by 2 positions: Receive window slides from [0, 1] to [2, 3]!
    • Receiver transmits ACK0ACK_0 and ACK1ACK_1.
  4. Channel Failure:
    • Both ACK0ACK_0 and ACK1ACK_1 are destroyed in transit by electromagnetic interference.
  5. Timeout & Retransmission:
    • Sender timer for Frame 0 expires.
    • Sender retransmits duplicate Frame 0 of the previous cycle.
  6. The Receiver Overlap Catastrophe:
    • Suppose the receiver window had been sized slightly larger (e.g., WR=3W_R = 3, so WS+WR=6>4W_S + W_R = 6 > 4).
    • Upon sliding forward by 2 positions, the receive window would cover slots [2, 3, 0]!
    • Notice that slot 0 is now an active member of the receiver's current acceptance window!
    • When duplicate Frame 0 arrives, the receiver cannot determine whether it is an old duplicate or brand-new data belonging to the next round. The duplicate is erroneously accepted, permanently corrupting user data!
  • The Conclusion: To guarantee that an old retransmitted frame can never fall inside the current receive window, the window sizes must satisfy: WS+WR≀2k\mathbf{W_S + W_R \le 2^k}
  • For symmetric windows where WS=WRW_S = W_R: 2β‹…WS≀2kβ€…β€ŠβŸΉβ€…β€ŠWS=2kβˆ’1,WR=2kβˆ’12 \cdot W_S \le 2^k \implies \mathbf{W_S = 2^{k-1}}, \quad \mathbf{W_R = 2^{k-1}}

βš™οΈ Operating Mechanics: Buffers, Timers & Negative ACKs​

1. Independent Timers​

Unlike Go-Back-N (which uses a single timer for the oldest frame), Selective Repeat maintains an independent countdown timer for every single unacknowledged frame in the sender window:

  • When Frame ii is transmitted, its dedicated timer TiT_i is started.
  • When an acknowledgment for Frame ii arrives, timer TiT_i is stopped.
  • If timer TiT_i expires, only Frame ii is retransmitted.

2. Receiver Buffering & Window Sliding​

  • If an incoming frame has an undamaged CRC and its sequence number falls within the receive window [Rf,Rf+WRβˆ’1][R_f, R_f + W_R - 1]:
    • The frame is stored in the receiver's local memory buffer.
    • An ACK for that specific frame is returned to the sender.
  • When does the receive window slide?
    • The receive window slides forward only when the lowest in-order frame (at RfR_f) arrives!
    • If Frames 2 and 3 are buffered while Frame 1 is missing, the window remains pinned at Rf=1R_f = 1.
    • As soon as missing Frame 1 arrives, the receiver delivers Frames 1, 2, and 3 to the Network Layer as an in-order batch, and the window slides forward past Frame 3!

3. Negative Acknowledgments (NAK / SACK)​

  • When the receiver detects a missing sequence number (e.g., receives Frame 2 when awaiting Frame 1), it immediately dispatches a Negative Acknowledgment (NAK1NAK_1).
  • The NAK1NAK_1 triggers an immediate selective retransmission of Frame 1 without waiting for the sender's timeout timer to expire, cutting recovery delay down to 1Β RTT1\text{ RTT}.

4. Piggybacking​

On full-duplex links where both stations are transmitting data, acknowledgment bits are embedded directly into the header of outgoing data frames (Piggybacking). This eliminates the bandwidth overhead of sending standalone ACK control packets.


πŸ”„ Interactive Flagship Blueprint: Selective Repeat ARQ Space-Time Protocol Ladder​

The interactive space-time protocol ladder below traces Selective Repeat in action (WS=4,WR=4W_S = 4, W_R = 4): sender bursts Frames 0, 1, 2, 3; Frame 1 is lost in transit; the receiver buffers out-of-order Frames 2 and 3 in local RAM; negative ACK (NAK1NAK_1) triggers retransmission of ONLY Frame 1; and finally all frames are reassembled in-order and delivered to the upper layers.

Space-Time Protocol Ladder
Step 1 of 9

Selective Repeat ARQ: Out-of-Order Buffering & Selective Retransmission Ladder

Space-time protocol ladder showing burst send, Frame 1 channel drop, receiver RAM buffering of F2/F3, NAK 1 dispatch, selective retransmit, and in-order release

πŸ’‘Click or hover any packet flight arrow, timer event, or step button to inspect protocol mechanics in real time
πŸͺŸSelective Repeat Window Buffers (k = 3 bits, Ws = 4, Wr = 4)
Sender Window (4 Timers)WS = 4
Frame 0
ACKed
Frame 1
Lost
Frame 2
Buffered
Frame 3
Buffered
Frame 4
Usable
Frame 5
usable
Frame 6
blocked
Frame 7
blocked
Receiver Window Buffer (RAM)WR = 4
Slot 1
Rf = 1
Slot 2
Buffered
Slot 3
Buffered
Slot 4
Usable
TIME (t)+∞Tp delayACK PropagatesOut-of-Order ArrivalFast NAK FlightOut-of-Order ArrivalTargeted RetransmitCumulative Resync ACK
πŸ“‘Transmitter (Ws = 4)
Sender (Host A)
Lifeline Rail (t ↓)
πŸ“₯Receiver (Wr = 4)
Receiver (Host B)
Lifeline Rail (t ↓)
1Frame 0(seq=0 (Burst #1))
2ACK 0(Frame 0 Accepted)
3Frame 1Lost(seq=1 (Burst #2))
4Frame 2(seq=2 (Burst #3))
5NAK 1(Missing Frame 1 Alert)
6Frame 3(seq=3 (Burst #4))
7Frame 1 (Selective Retransmit)(seq=1 ONLY)
⚑In-Order Delivery & Window Slide(Deliver [F1, F2, F3] to L3)
9ACK 4(Expects Frame 4)
Step 1 of 9sender βž” receiverβœ… Delivered SuccessfullyFrame 0

Sender transmits Frame 0 and starts its dedicated retransmission timer. Frame 0 arrives at receiver with zero bit errors.

Protocol Mechanics:Receiver checks CRC, accepts Frame 0, delivers it immediately to Layer 3, and advances receiver window.

πŸ“Š Master Flow Control Comparison Matrix​

The table below contrasts the operational parameters, hardware requirements, and mathematical boundaries of the three fundamental Data Link Layer flow control protocols:

Feature / MetricStop-and-Wait ARQGo-Back-N (GBN) ARQSelective Repeat (SR) ARQ
Sender Window Size (WSW_S)112kβˆ’12^k - 12kβˆ’12^{k-1}
Receiver Window Size (WRW_R)11112kβˆ’12^{k-1}
Window Size RelationWS+WR=2W_S + W_R = 2WS+WR=2kW_S + W_R = 2^kWS+WR≀2kW_S + W_R \le 2^k
Sequence Number Bits (kk)1Β bit1\text{ bit} (00 and 11)⌈log⁑2(WS+1)βŒ‰\lceil \log_2(W_S + 1) \rceil⌈log⁑2(2β‹…WS)βŒ‰=⌈log⁑2(WS)βŒ‰+1\lceil \log_2(2 \cdot W_S) \rceil = \lceil \log_2(W_S) \rceil + 1
Active Timers at Sender1111 (for oldest frame SfS_f)WSW_S independent timers
Receiver Buffer Memory00 (No buffer needed)00 (Discards out-of-order)WRW_R frame buffers
Out-of-Order FramesDiscardedDiscardedBuffered in local RAM
Acknowledgment TypeIndividual / AlternatingCumulative (ACKmACK_m)Selective / Individual (ACKmACK_m, NAKmNAK_m)
Retransmission PolicySingle frameGo-Back-NN (All outstanding)Selective (Only lost frame)
Efficiency (Ξ·\eta)11+2a\frac{1}{1 + 2a}WS1+2a≀1\frac{W_S}{1 + 2a} \le 1WS1+2a≀1\frac{W_S}{1 + 2a} \le 1
Performance on Noisy LinksPoorExtremely Poor (Retransmission storm)Excellent (Zero redundant retransmission)
Implementation ComplexityMinimalModerateHigh (Buffer sorting + multiple timers)

🏭 Real-World Production Context​

In modern internet transport and cellular infrastructure:

  • TCP Selective Acknowledgment (TCP SACK, RFC 2018): When packets drop across high-latency transoceanic fiber links, standard TCP would collapse into Go-Back-N retransmissions. SACK allows the receiver to report non-contiguous received byte blocks (e.g., received bytes 5000–6000 and 7000–8000), allowing the sender to selectively retransmit only the missing byte span 6001–6999.
  • 5G New Radio (NR) RLC Layer: Operates in Acknowledged Mode (AM) using Selective Repeat with specialized status reports (STATUS PDU) to prevent retransmission of massive 100MB blocks over volatile millimeter-wave radio links.

πŸ“ Numerical Applications & Worked Examples​

Problem Statement:
Consider two communication hosts X and Y connected by a direct point-to-point link of rate 106Β bits/sec10^6\text{ bits/sec} (1Β Mbps1\text{ Mbps}). The physical distance between the hosts is 10,000Β km10,000\text{ km} and signal propagation speed through the medium is 2Γ—108Β m/s2 \times 10^8\text{ m/s}. Host X transmits data frames of size 1000Β bytes1000\text{ bytes} each to host Y using Selective Repeat sliding window protocol. Calculate the minimum number of bits required for the sequence number field in the frame header to achieve 100%100\% link efficiency.

Step-by-Step Solution:​

  1. Given Parameters:
    • Bandwidth B=106Β bpsB = 10^6\text{ bps}.
    • Distance d=10,000Β km=107Β metersd = 10,000\text{ km} = 10^7\text{ meters}.
    • Velocity v=2Γ—108Β m/sv = 2 \times 10^8\text{ m/s}.
    • Frame size L=1000Β bytes=8000Β bitsL = 1000\text{ bytes} = 8000\text{ bits}.
  2. Calculate Propagation Delay (TpT_p) and Transmission Delay (TtT_t): Tp=dv=107Β m2Γ—108Β m/s=0.05Β s=50Β msT_p = \frac{d}{v} = \frac{10^7\text{ m}}{2 \times 10^8\text{ m/s}} = 0.05\text{ s} = 50\text{ ms} Tt=LB=8000Β bits106Β bps=0.008Β s=8Β msT_t = \frac{L}{B} = \frac{8000\text{ bits}}{10^6\text{ bps}} = 0.008\text{ s} = 8\text{ ms}
  3. Calculate Parameter aa and Optimal Window Size (WSW_S): a=TpTt=50Β ms8Β ms=6.25a = \frac{T_p}{T_t} = \frac{50\text{ ms}}{8\text{ ms}} = 6.25 WSβ‰₯1+2a=1+2(6.25)=1+12.5=13.5β€…β€ŠβŸΉβ€…β€ŠWS=⌈13.5βŒ‰=14W_S \ge 1 + 2a = 1 + 2(6.25) = 1 + 12.5 = 13.5 \implies W_S = \lceil 13.5 \rceil = \mathbf{14}
  4. Compute Minimum Sequence Number Bits (kk):
    • In symmetric Selective Repeat: WS≀2kβˆ’1W_S \le 2^{k-1}. 14≀2kβˆ’1β€…β€ŠβŸΉβ€…β€Š2kβˆ’1β‰₯1414 \le 2^{k-1} \implies 2^{k-1} \ge 14
    • For k=4k = 4: 24βˆ’1=23=8<142^{4-1} = 2^3 = 8 < 14 (Insufficient).
    • For k=5k = 5: 25βˆ’1=24=16β‰₯142^{5-1} = 2^4 = 16 \ge 14 (Satisfied!). k=5Β bits\mathbf{k = 5\text{ bits}}
  5. Final Result: At least 5Β bits5\text{ bits} are required in the sequence number field.

Example 2: Mathematical Proof of Maximum Window Size with n-Bit Identifiers​

Problem Statement:
Prove analytically why the maximum allowable sender window size for data transmission using the Selective Repeat protocol with nn-bit frame sequence numbers is 2nβˆ’12^{n-1}.

Step-by-Step Solution:​

  1. General Sliding Window Condition: To avoid overlap between the current receive window and old retransmitted duplicate frames, the window sizes must satisfy: WS+WR≀2nW_S + W_R \le 2^n
  2. Symmetric Window Allocation: In Selective Repeat, to handle bidirectional symmetric communication and ensure identical buffer memory allocations at both endpoints, the receive window is chosen equal to the send window: WS=WRW_S = W_R
  3. Substitute into Inequality: WS+WS≀2nβ€…β€ŠβŸΉβ€…β€Š2β‹…WS≀2nβ€…β€ŠβŸΉβ€…β€ŠWS≀2n2=2nβˆ’1W_S + W_S \le 2^n \implies 2 \cdot W_S \le 2^n \implies W_S \le \frac{2^n}{2} = \mathbf{2^{n-1}}
  4. Final Result: The maximum possible sender window size is strictly 2nβˆ’12^{n-1}.

Example 3: Feasibility Analysis of Full Sequence Space Allocation (2i2^i Window)​

Problem Statement:
Suppose an engineer attempts to configure a sliding window protocol with a sender window size of 2i2^i, where ii is the total number of bits in the sequence number field. Analyze whether this protocol can operate correctly under Selective Repeat without data corruption.

Step-by-Step Solution:​

  1. Evaluate Against the Master Theorem:
    • The fundamental condition is WS+WR≀2iW_S + W_R \le 2^i.
    • Even under the most restrictive receiver configuration possible (WR=1W_R = 1): WS+1≀2iβ€…β€ŠβŸΉβ€…β€ŠWS≀2iβˆ’1W_S + 1 \le 2^i \implies W_S \le 2^i - 1
  2. Analyze Failure Mode for WS=2iW_S = 2^i:
    • If WS=2iW_S = 2^i, the sender window consumes the entire sequence space.
    • If all acknowledgments for an entire window are lost, the sender times out and retransmits duplicate frames.
    • Because the sequence numbers have wrapped around by an entire cycle (2i≑0(mod2i)2^i \equiv 0 \pmod{2^i}), the receiver will misidentify duplicate frames as brand-new frames from the next cycle.
  3. Final Result: A sender window size of 2i2^i will inevitably lead to protocol failure. The maximum allowable window size is 2iβˆ’12^{i-1} for symmetric Selective Repeat.

🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions

Question 1: "Why is Selective Repeat much harder to implement in hardware than Go-Back-N?"
Key Focus Points:

  • Memory Buffer Management: SR requires active RAM buffers at both the transmitter and the receiver to store, reorder, and track out-of-order packets.
  • Multiple Concurrent Timers: The transmitter must maintain and update an independent hardware countdown timer for every unacknowledged frame in the window, creating significant interrupt-handling overhead.
  • In-Order Assembly Logic: The receiver must implement sorting and gap-detection logic to deliver frames to the Network Layer in strict order.

Question 2: "What happens in Selective Repeat if an ACK for Frame 0 is lost, but the sender receives an ACK for Frame 1?"
Key Focus Points:

  • In Selective Repeat, acknowledgments are selective and independent, not cumulative.
  • Receiving ACK1ACK_1 confirms only Frame 1. It tells the sender nothing about Frame 0.
  • Frame 0 remains unacknowledged in the sender's window until its dedicated timer T0T_0 expires or a NAK0NAK_0 arrives, at which point only Frame 0 is retransmitted.

Question 3: "Under what channel conditions is Go-Back-N preferred over Selective Repeat?"
Key Focus Points:

  • On ultra-reliable, low-error channels (such as local Ethernet fiber), packet loss is nearly zero (Pβ‰ˆ0P \approx 0).
  • Under zero-loss conditions, the retransmission storm of GBN never triggers, and GBN achieves identical 100%100\% efficiency to Selective Repeat while saving significant buffer memory and timer complexity.
Common Interview Traps

Trap 1: "Does Selective Repeat use cumulative ACKs like Go-Back-N?"
Answer: Standard Selective Repeat uses individual/selective ACKs. An ACKmACK_m in pure Selective Repeat acknowledges only frame mm. However, modern advanced transport protocols like TCP SACK (Selective Acknowledgment) combine both: the standard TCP header carries a cumulative ACK, while TCP options carry SACK blocks describing out-of-order received chunks!

Trap 2: "Can the receiver window (WRW_R) in Selective Repeat be larger than the sender window (WSW_S)?"
Answer: Technically yes mathematically (WS+WR≀2kW_S + W_R \le 2^k), but practically never. If WR>WSW_R > W_S, the extra receive slots sit completely empty because the sender can never transmit more than WSW_S frames at any time! Symmetrical sizing (WS=WR=2kβˆ’1W_S = W_R = 2^{k-1}) maximizes bandwidth utilization in both directions.


πŸ’¬

Discussion & Doubts