Elementary and sliding window protocols: stop-and-wait, Go-Back-N, Selective Repeat
Reliable delivery over an unreliable channel: ACK, timeout, sequence numbers, why stop-and-wait is slow, the window rules of Go-Back-N and Selective Repeat, and the utilization formula.
On the previous page you saw how the link layer notices errors. Noticing is not enough: a corrupted frame is discarded, and the data still has to reach the other side. The way to do this is ARQ (automatic repeat request): the receiver sends an acknowledgment (ACK), and the sender retransmits if no ACK arrives. The same ideas come back in week 7 with TCP, so learn them well here.
Exam questions come in three patterns: utilization calculation, “which frames are retransmitted?” traces, and the number of sequence-number bits. Golden rules:
- , and it cannot exceed 1. In stop-and-wait .
- The GBN receiver discards out-of-order frames, the SR receiver buffers them.
- In GBN the window is , in SR it is .
- RTT is two-way. If the one-way propagation is given, multiply by two.
Elementary protocols, step by step
Textbooks build reliable delivery as a series of protocols going from simple to complex. Each one removes a convenience that the previous one assumed.
| Protocol | Assumption | Mechanism added |
|---|---|---|
| Utopia (simplex, perfect) | Error-free channel, infinitely fast receiver | None, just send |
| Stop-and-wait, error-free channel | The receiver may be slow | The receiver says “I’m ready” (flow control) |
| Stop-and-wait, noisy channel (PAR) | A frame may be lost or corrupted | ACK + timeout + retransmission |
| + sequence number (alternating bit) | The ACK may also be lost | 1-bit sequence number, recognizing duplicates |
Why a sequence number? Scenario: the sender sends frame 0, the receiver gets it and sends an ACK, and the ACK is lost. At the timeout the sender sends 0 again. Without a sequence number the receiver would think it is new data and deliver it to the upper layer twice. One bit is enough: the receiver says “I was expecting 1 now, this 0 is a duplicate”, discards it, but still sends an ACK.
PITFALL · ACK the duplicate frame too. The receiver discards the duplicate frame but must still send the ACK. If it doesn’t, the sender resends the same frame forever, because the first ACK was already lost.
Why is stop-and-wait slow?
The sender sends one frame and waits until the ACK arrives. The first bit of the frame leaves at , the last bit at , and the ACK returns at . The fraction of time the sender is really putting bits on the link is:
Worked example
Mbps, bits, ms.
L/R = 10,000 / 10^8 = 0.1 ms
U = 0.1 / (20 + 0.1) = 0.004975 (about 0.5%)
throughput = U x R = 497.5 kbps
Not even half a megabit gets through a 100 Mbps link. The problem is not the link, it is the protocol.
The parameter
Some books define . If the ACK size and the processing time are neglected, :
In the example ms, ms, , . The same number.
Pipelining and the sliding window
The solution: send several frames without waiting for ACKs. The sender can keep at most unacknowledged frames “in flight”. This is the window size. When an ACK arrives, the window slides forward.
In the same example with : . For full utilization:
This is the bandwidth-delay product idea from week 1, expressed in frames: the pipe must be full.
The sender’s sequence-number space looks like this:
[ acknowledged ][ sent, waiting for ACK ][ can be sent ][ not yet usable ]
^ base ^ nextseqnum
|<-------------- window N -------------->|
Pipelining recovers from errors in two different ways: Go-Back-N and Selective Repeat.
Go-Back-N (GBN)
- Receiver window is 1. The receiver accepts only the frame it expects next in order. It discards everything that arrives out of order.
- Cumulative ACK. “ACK n” means everything up to and including n was received. When an out-of-order frame arrives, the receiver resends the ACK of the last in-order frame it received.
- A single timer, for the oldest unacknowledged frame. At the timeout the sender resends all frames in the window, starting from that frame. Hence the name: go back N.
Trace: window 6, frame 2 lost
Sender : 0 1 2 3 4 5
Channel : ok ok X ok ok ok
Receiver: acc acc - drop drop drop (expected is always 2)
ACK : 0 1 1 1 1 (repeated ACK1)
Timeout(2): resend 2 3 4 5 -> 4 frames
Advantage: the receiver is simple, with no buffer. Disadvantage: a single loss also throws away the correctly received frames behind it. With a high error rate and a large window on the link, it wastes a lot.
Selective Repeat (SR)
- The receiver also keeps a window and buffers frames that are out of order but inside the window.
- Each frame is ACKed individually (not cumulative).
- Each frame has its own timer. Only the frame whose timer expires is resent.
- When the missing frame arrives, the receiver hands the in-order block in the buffer to the upper layer together.
The same trace, with SR
Sender : 0 1 2 3 4 5
Channel : ok ok X ok ok ok
Receiver: acc acc - buffer buffer buffer
ACK : 0 1 3 4 5
Timeout(2): only 2 -> 1 frame
When 2 arrives: 2,3,4,5 delivered in order
How many bits should the sequence number have?
If the sequence number is bits, the values cycle through .
| Protocol | Maximum window | ||
|---|---|---|---|
| Go-Back-N | 7 | 31 | |
| Selective Repeat | 4 | 16 |
Why not in GBN? If the window were , the sender would send 0..7 and either all the ACKs are lost or all arrive; in both cases the next frame the receiver expects is 0. The sender cannot tell whether an “ACK 7” it receives refers to the new window or the old one.
Why half in SR? The receiver’s window also slides forward. The sender’s and receiver’s windows must not overlap in the sequence space.
k = 2 (0..3), W = 3:
receiver got 0,1,2, the ACKs were lost
receiver window is now {3, 0, 1}
sender resends the old 0 -> receiver thinks it is a NEW 0, wrong delivery
k = 2, W = 2:
receiver window {2, 3}, the old 0 is outside -> correctly discarded (and ACKed)
Worked example: a satellite link
Mbps, bits, one-way propagation 270 ms.
L/R = 1 ms, RTT = 540 ms
SW : U = 1 / 541 = 0.00185
GBN, k=3 (N=7) : U = 7 / 541 = 0.0129
For full use : N = 541
GBN bit count : 2^10 - 1 = 1023 >= 541 -> k = 10
SR bit count : 2^10 = 1024 >= 541 -> k = 11
Stop-and-wait with error probability
If each frame is corrupted independently with probability , the expected number of transmissions per frame is:
For it is 1.25. The efficiency drops by the same factor. On a noisy link, GBN repeats many frames after a single error, so SR’s advantage grows.
TIP · piggybacking. When data flows in both directions, instead of sending a separate ACK frame, the receiver puts the ACK in the header of its own data frame going the other way. This saves bandwidth. TCP works this way too.
Security note
None of these protocols verifies who the other party is. If the sequence number becomes predictable, someone in the middle can inject a forged frame with the right sequence number. This is one reason TCP chooses its initial sequence number at random (week 7).
Common mistakes
| Wrong idea | Correct |
|---|---|
| The denominator is . | |
| RTT = one-way propagation | (if there is no extra delay). |
| grows without limit with the window | ; it stops growing once the pipe is full. |
| The GBN receiver buffers out-of-order frames | It discards them. SR is the one that buffers. |
| On timeout GBN resends only the lost frame | Everything in the window from the lost one on. |
| Cumulative ACK in SR | A separate ACK for each frame. |
| GBN window | . In SR it is . |
| A duplicate frame doesn’t need an ACK | It does, otherwise the sender gets stuck. |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
In the stop-and-wait protocol, why does each frame need a sequence number (even a 1-bit one)?
- To encrypt the frame
- So that the receiver can detect a duplicate frame when an ACK is lost and the sender retransmits
- To measure the round-trip time
- To allow the sender to send several frames at once
Show answer
If the ACK is lost, the sender resends the same frame after the timeout. Without a sequence number the receiver can't tell whether this is a new frame or a duplicate, and it would deliver the data twice.
In stop-and-wait a single bit is enough (0, 1, 0, 1...): the alternating bit protocol.
A link has rate 1 Mbps, frames are 1000 bits, and the one-way propagation delay is 270 ms (satellite). What is the sender utilization with stop-and-wait (ignore ACK transmission time)?
Show answer
ms. RTT ms..
The link is used less than 0.2% of the time.
For the same satellite link, the sender uses Go-Back-N with a 3-bit sequence number and the maximum allowed window. What is the utilization?
Show answer
With a 3-bit sequence number, the GBN window is at most ..
For the satellite link above, what window size is needed for 100% utilization, and how many sequence-number bits does Go-Back-N need for that window?
Show answer
For full utilization, the window must equal the number of frames that can be sent in one RTT + L/R: .
In GBN : , . So .
With a -bit sequence number, what are the maximum window sizes for Go-Back-N and Selective Repeat?
- GBN: , SR:
- GBN: , SR:
- GBN: , SR:
- GBN: , SR:
Show answer
Since the GBN receiver's window is 1, the sender can go up to .
In SR the receiver has a window too; so that old and new frames are not confused, the two windows together must not exceed the sequence space: , which is half of the sequence space.
A Go-Back-N sender with window 6 sends frames 0 to 5. Frame 2 is lost; all others arrive. Using cumulative ACKs where 'ACK n' means all frames up to n were received, which ACKs does the receiver send, and how many frames are retransmitted after the timeout?
Show answer
The GBN receiver accepts only the next expected frame. Frames 0 and 1 arrive: ACK0, ACK1.
Frame 2 is lost. Since 3, 4 and 5 arrive out of order, they are discarded, and for each one the ACK of the last correct in-order frame (ACK1) is sent again.
At the timeout the sender resends everything from 2 on: 2, 3, 4, 5, so 4 frames.
Same situation (window 6, frames 0 to 5, frame 2 lost) but with Selective Repeat. Which frames are retransmitted?
- Frames 2, 3, 4, 5
- Only frame 2
- All frames 0 to 5
- Frames 3, 4, 5
Show answer
The SR receiver buffers out-of-order frames and ACKs each one individually: ACK0, ACK1, ACK3, ACK4, ACK5.
Each frame has its own timer; only the timer of frame 2 expires, so only frame 2 is resent. When 2 arrives, the receiver delivers 2, 3, 4, 5 to the upper layer in order.
A 2 Mbps link carries 12,000-bit frames with RTT = 45 ms. What is the utilization with a window of 8 frames?
Show answer
ms. ms..
With a window of 9 or more, , so U = 1.
Each frame on a stop-and-wait link is corrupted independently with probability 0.2 and must then be resent. What is the expected number of transmissions per frame?
Show answer
Geometric distribution: the success probability is , so the expected number of attempts is .
The efficiency drops by the same factor: the error-free is divided by 1.25.
Selective Repeat uses 2-bit sequence numbers (0 to 3) with window size 3. The receiver gets frames 0, 1, 2 and sends ACKs, but all three ACKs are lost. What goes wrong when the sender retransmits frame 0?
- Nothing, the receiver discards it correctly
- The receiver's window is now {3, 0, 1}, so it accepts the old frame 0 as new data
- The sender deadlocks
- The receiver sends a NAK and the problem is resolved
Show answer
After receiving 0, 1, 2, the receiver's window moves forward and expects 3, 0, 1 (the sequence numbers wrap around).
Since the sender received no ACK, it resends the old 0. The receiver thinks it is the new 0 in its window: duplicate data is delivered as if it were new.
With a window of 2 () the receiver would expect {2, 3} and the old 0 would fall outside.
Express stop-and-wait utilization in terms of (ignore processing and ACK size). If , what is ?
Show answer
.
For : . When is large (a long, fast link), stop-and-wait collapses.
Verification: Utilization, required window and sequence-number bit counts were computed with node (verify/SEN2008/03b.mjs: U = min(1, N·(L/R)/(RTT + L/R)), the 2^k - 1 and 2^(k-1) limits, GBN/SR receiver ACK simulation, SR window ambiguity demonstration).