Sliding Window ARQ: Window Size & Link Efficiency
Interview Question: "Using a link with bandwidth 5 Mbps and propagation delay 20 ms, a sender uses Sliding Window ARQ with 1000-bit frames. Calculate the minimum window size for full utilization using , analyze efficiency with a halved window, compare Go-Back-N vs. Selective Repeat sequence numbering constraints, and explain the sequence number ambiguity trap."
Sliding window protocols bridge physical channel limits with software flow control. Instead of idling while waiting for individual acknowledgments, pipelining allows a transmitter to keep multiple unacknowledged frames in flight.
Staff-level networking interviews frequently probe beyond the formula to evaluate your understanding of sequence number space constraints () and why protocol designs must prevent catastrophic frame misidentification.
1. Derivation of and Minimum Window Size ()
Transmission Time ():
Dimensionless Ratio :
The ratio represents the one-way propagation delay measured in units of frame transmission time: (Physical intuition: The physical medium is long enough to hold 100 individual 1000-bit frames along its length before the first bit reaches the destination).
Round-Trip Cycle Time:
For a sender transmitting frame 0, the acknowledgment for frame 0 arrives after: Assuming negligible processing and ACK transmission times:
Condition for 100% Link Utilization:
To ensure the sender never experiences idle pipeline bubbles, it must continuously transmit frames for the entire duration of until the ACK for the first frame returns:
A sender window of keeps the 5 Mbps pipe 100% saturated.
Time (ms) Sender Action Receiver Action
0.0 Start transmitting Frame 1 ...
0.2 Finish Frame 1, start Frame 2 ...
... Continuously transmitting Frames 3 to 200 ...
20.0 Frame 101 on wire Frame 1 arrives, ACK 1 sent
40.0 Start transmitting Frame 201 ...
40.2 Finish Frame 201; ACK 1 arrives! Window slides forward -> ZERO IDLE TIME!
2. Efficiency with a Halved Window Size ()
When the actual sender window is less than the optimal capacity :
For a halved window size frames:
The Physical Explanation:
- The sender transmits 100 frames continuously: .
- At , the sender has exhausted its 100-frame window. It is legally forced by the protocol to freeze and wait.
- The ACK for Frame 1 does not arrive until .
- The sender sits completely idle from to ( of wasted wire time).
- Because active transmission time equals idle wait time, efficiency drops to .
3. Protocol Comparison: Stop-and-Wait vs GBN vs Selective Repeat
| Feature | Stop-and-Wait | Go-Back-N (GBN) | Selective Repeat (SR) |
|---|---|---|---|
| Sender Window Size () | 1 | (up to ) | (up to ) |
| Receiver Window Size () | 1 | 1 | (up to ) |
| Sequence Space Rule | |||
| Maximum Window for bits | |||
| Acknowledgment Type | Individual ACK | Cumulative ACK | Individual ACK (or SACK) |
| Out-of-Order Buffering | No (Discarded) | No (Discarded) | Yes (Buffered in receiver queue) |
| Retransmission on Loss | 1 frame | All unacknowledged frames | Only the specific lost frame |
4. The Sequence Number Ambiguity Trap
Why can a Go-Back-N protocol with -bit sequence numbers have a maximum window size of only , rather than ?
The Disaster Scenario ( in GBN):
Let sequence numbers be 2 bits wide (), providing 4 available numbers: . Suppose an engineer naively sets :
- Sender transmits frames: 0, 1, 2, 3.
- Receiver receives all 4 frames cleanly, advances its expected sequence pointer to 0 (wrapping around), and transmits cumulative ACK 0, 1, 2, 3.
- The Disaster: A network partition or router failure drops all 4 ACKs.
- The sender's retransmission timer for frame 0 expires.
- The sender retransmits frame 0 (the old data!).
- The receiver is waiting for frame 0 (the new, next-generation data!).
- The receiver accepts the old frame 0 as the brand new frame 0, storing corrupted duplicate data without triggering any warning!
Sender (Ws = 4, k = 2) Receiver (Wr = 1)
|--- Frame 0, 1, 2, 3 ------------------------->| Receives all 4. Expected bit = 0
| |
|<-- [ALL ACKs LOST IN TRANSIT] ----------------|
| |
| (Timeout!) |
|--- Frame 0 (Old Data) ----------------------->| Accepts Frame 0 as NEW data!
*** SILENT DATA CORRUPTION ***
The Mathematical Fix ():
With ():
- Sender sends frames 0, 1, 2.
- If all ACKs are lost, sender retransmits frame 0.
- Receiver had advanced to expect frame 3. Since frame 0 frame 3, the receiver recognizes frame 0 as a duplicate, silently discards the payload, and retransmits ACK 2!
For Selective Repeat, since both sender and receiver slide windows forward independently:
5. Link Efficiency under Packet Loss ()
On clean links, GBN and SR achieve identical maximum throughput (). Over noisy or lossy links with frame drop probability :
- Stop-and-Wait:
- Go-Back-N: When a single frame drops, the receiver discards all subsequent arriving frames. All frames must be retransmitted: (As loss grows, GBN efficiency collapses rapidly).
- Selective Repeat: Only the dropped frame is retransmitted. Throughput degrades gracefully:
Modern TCP Solution (RFC 2018 SACK):
Standard TCP historically behaved like Go-Back-N. RFC 2018 introduced Selective Acknowledgment (SACK) options, allowing TCP receivers to inform the sender of non-contiguous buffered blocks, achieving the optimal efficiency of Selective Repeat while retaining cumulative ACKs.
6. Runnable Python Implementation
This script calculates optimal window sizing, models efficiency degradation under halved windows, and simulates Go-Back-N vs Selective Repeat behavior under packet loss.
"""
Sliding Window ARQ Simulator
Evaluates window sizing N = 1 + 2a, sequence number bounds,
and throughput degradation under packet loss for GBN vs SR.
"""
def calculate_optimal_window(bandwidth_bps: int, prop_delay_sec: float, frame_bits: int) -> tuple[float, float, int]:
"""Calculates transmission delay, ratio a, and minimum window size for 100% utilization."""
t_trans = frame_bits / bandwidth_bps
a = prop_delay_sec / t_trans
n_optimal = int(-(- (1 + 2 * a) // 1)) # Ceiling to integer
return t_trans, a, n_optimal
def window_efficiency(window_size: int, a: float) -> float:
"""Calculates theoretical link efficiency for a given window size and ratio a."""
max_w = 1 + 2 * a
return min(1.0, window_size / max_w)
def arq_loss_efficiency(p_loss: float, a: float) -> dict[str, float]:
"""Calculates theoretical efficiency under frame loss probability p."""
eff_sw = (1 - p_loss) / (1 + 2 * a)
eff_gbn = (1 - p_loss) / (1 + (2 * a * p_loss))
eff_sr = 1 - p_loss
return {"Stop-and-Wait": eff_sw, "Go-Back-N": eff_gbn, "Selective-Repeat": eff_sr}
def validate_sequence_space(k_bits: int, ws: int, wr: int) -> bool:
"""Validates the sequence number space condition: Ws + Wr <= 2^k."""
return (ws + wr) <= (2**k_bits)
if __name__ == "__main__":
bandwidth = 5 * 10**6 # 5 Mbps
prop_delay = 20 * 10**-3 # 20 ms
frame_size = 1000 # 1000 bits
# 1. Optimal Window Derivation
t_tx, a_ratio, n_opt = calculate_optimal_window(bandwidth, prop_delay, frame_size)
print(f"Transmission Time (Tt): {t_tx * 1000:.2f} ms")
print(f"Ratio a (Tp / Tt): {a_ratio:.1f}")
print(f"Optimal Window Size (N): {n_opt} frames")
assert a_ratio == 100.0
assert n_opt == 201
# 2. Halved Window Efficiency
halved_w = 100
eff_halved = window_efficiency(halved_w, a_ratio)
print(f"\nEfficiency with Halved Window (W = {halved_w}): {eff_halved * 100:.2f}%")
assert round(eff_halved * 100, 1) == 49.8
# 3. Sequence Number Ambiguity Validation
k = 3 # 3-bit sequence numbers -> 8 values (0..7)
print("\n--- Sequence Space Validation (k = 3 bits, 2^k = 8) ---")
print(f"GBN with Ws = 7, Wr = 1: Valid? {validate_sequence_space(k, 7, 1)}")
print(f"GBN with Ws = 8, Wr = 1: Valid? {validate_sequence_space(k, 8, 1)} (DISASTER TRAP!)")
print(f"SR with Ws = 4, Wr = 4: Valid? {validate_sequence_space(k, 4, 4)}")
print(f"SR with Ws = 5, Wr = 5: Valid? {validate_sequence_space(k, 5, 5)} (DISASTER TRAP!)")
assert validate_sequence_space(k, 7, 1) is True
assert validate_sequence_space(k, 8, 1) is False
# 4. Efficiency under 5% Packet Loss
loss_rate = 0.05
efficiencies = arq_loss_efficiency(loss_rate, a_ratio)
print(f"\n--- Efficiency Comparison under {loss_rate * 100:.0f}% Packet Loss ---")
for protocol, eff in efficiencies.items():
print(f"{protocol:<18}: {eff * 100:.2f}%")
7. Concise Staff-Level Interview Answer
"To find the window size for 100% link utilization, we first compute transmission delay and the dimensionless ratio .
Full utilization requires the transmitter to send continuously for an entire round-trip time (). Dividing this total cycle by gives . If the window is halved to 100 frames, efficiency drops linearly to because the sender exhausts its window in 20 ms and sits idle for the remaining 20.2 ms waiting for the first ACK.
In protocol design, sequence numbers must satisfy . For Go-Back-N (), the maximum sender window is . If an engineer mistakenly sets and all ACKs are lost, the sender retransmits frame 0 while the receiver, having wrapped around, expects the next frame 0; the receiver silently accepts old duplicate data as new. In Selective Repeat, where both sides buffer out-of-order frames, window sizes must not exceed ."