SEN2008 · Week 3 · Data Link Layer Concepts (I) : error detection and correction, elementary protocols, sliding window protocols

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.

ARQ (automatic repeat request)stop-and-waitalternating bit protocolACK / NAKtimeoutsequence numbersliding windowGo-Back-NSelective Repeatcumulative ACKpipeliningutilizationwindow sizepiggybacking

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:

  1. U=N⋅(L/R)/(RTT+L/R)U = N \cdot (L/R) / (RTT + L/R), and it cannot exceed 1. In stop-and-wait N=1N = 1.
  2. The GBN receiver discards out-of-order frames, the SR receiver buffers them.
  3. In GBN the window is ≤2k−1\le 2^k - 1, in SR it is ≤2k−1\le 2^{k-1}.
  4. 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.

ProtocolAssumptionMechanism added
Utopia (simplex, perfect)Error-free channel, infinitely fast receiverNone, just send
Stop-and-wait, error-free channelThe receiver may be slowThe receiver says “I’m ready” (flow control)
Stop-and-wait, noisy channel (PAR)A frame may be lost or corruptedACK + timeout + retransmission
+ sequence number (alternating bit)The ACK may also be lost1-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 t=0t = 0, the last bit at L/RL/R, and the ACK returns at RTT+L/RRTT + L/R. The fraction of time the sender is really putting bits on the link is:

Usender=L/RRTT+L/RU_{sender} = \frac{L/R}{RTT + L/R}

Worked example

R=100R = 100 Mbps, L=10,000L = 10{,}000 bits, RTT=20RTT = 20 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 aa

Some books define a=dprop/dtransa = d_{prop}/d_{trans}. If the ACK size and the processing time are neglected, RTT=2dpropRTT = 2 d_{prop}:

USW=11+2aU_{SW} = \frac{1}{1 + 2a}

In the example dprop=10d_{prop} = 10 ms, dtrans=0.1d_{trans} = 0.1 ms, a=100a = 100, U=1/201U = 1/201. The same number.

Pipelining and the sliding window

The solution: send several frames without waiting for ACKs. The sender can keep at most NN unacknowledged frames “in flight”. This NN is the window size. When an ACK arrives, the window slides forward.

U=min⁡(1, N⋅L/RRTT+L/R)U = \min\left(1,\ \frac{N \cdot L/R}{RTT + L/R}\right)

In the same example with N=50N = 50: U=50×0.1/20.1=0.2488U = 50 \times 0.1 / 20.1 = 0.2488. For full utilization:

N≥RTT+L/RL/R=20.10.1=201N \ge \frac{RTT + L/R}{L/R} = \frac{20.1}{0.1} = 201

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 kk bits, the values cycle through 0,1,…,2k−10, 1, \ldots, 2^k - 1.

ProtocolMaximum windowk=3k = 3k=5k = 5
Go-Back-N2k−12^k - 1731
Selective Repeat2k−12^{k-1}416

Why not 2k2^k in GBN? If the window were 2k2^k, 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)

R=1R = 1 Mbps, L=1000L = 1000 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 pp, the expected number of transmissions per frame is:

E[transmissions]=11−pE[\text{transmissions}] = \frac{1}{1-p}

For p=0.2p = 0.2 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 ideaCorrect
U=(L/R)/RTTU = (L/R)/RTTThe denominator is RTT+L/RRTT + L/R.
RTT = one-way propagationRTT=2dpropRTT = 2 d_{prop} (if there is no extra delay).
UU grows without limit with the windowmin⁡(1,…)\min(1, \ldots); it stops growing once the pipe is full.
The GBN receiver buffers out-of-order framesIt discards them. SR is the one that buffers.
On timeout GBN resends only the lost frameEverything in the window from the lost one on.
Cumulative ACK in SRA separate ACK for each frame.
GBN window 2k2^k2k−12^k - 1. In SR it is 2k−12^{k-1}.
A duplicate frame doesn’t need an ACKIt does, otherwise the sender gets stuck.

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

In the stop-and-wait protocol, why does each frame need a sequence number (even a 1-bit one)?

  1. To encrypt the frame
  2. So that the receiver can detect a duplicate frame when an ACK is lost and the sender retransmits
  3. To measure the round-trip time
  4. To allow the sender to send several frames at once
Show answer
B) So that the receiver can detect a duplicate frame when an ACK is lost and the sender retransmits

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.

Question 2medium

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
≈ 0.00185

L/R=1000/106=1L/R = 1000/10^6 = 1 ms. RTT =2×270=540= 2 \times 270 = 540 ms.U=L/RRTT+L/R=1541≈0.00185U = \frac{L/R}{RTT + L/R} = \frac{1}{541} \approx 0.00185.
The link is used less than 0.2% of the time.

Question 3medium

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
≈ 0.0129

With a 3-bit sequence number, the GBN window is at most 23−1=72^3 - 1 = 7.U=7×1541≈0.0129U = \frac{7 \times 1}{541} \approx 0.0129.

Question 4hard

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
541 frames; 10 bits

For full utilization, the window must equal the number of frames that can be sent in one RTT + L/R: N=(540+1)/1=541N = (540 + 1)/1 = 541.
In GBN N≤2k−1N \le 2^k - 1: 29−1=511<5412^9 - 1 = 511 < 541, 210−1=1023≥5412^{10} - 1 = 1023 \ge 541. So k=10k = 10.

Question 5medium

With a kk-bit sequence number, what are the maximum window sizes for Go-Back-N and Selective Repeat?

  1. GBN: 2k2^k, SR: 2k2^k
  2. GBN: 2k−12^k - 1, SR: 2k−12^{k-1}
  3. GBN: 2k−12^{k-1}, SR: 2k−12^k - 1
  4. GBN: kk, SR: k/2k/2
Show answer
B) GBN: 2k−12^k - 1, SR: 2k−12^{k-1}

Since the GBN receiver's window is 1, the sender can go up to 2k−12^k - 1.
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: W≤2k−1W \le 2^{k-1}, which is half of the sequence space.

Question 6medium

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
ACK0, ACK1, ACK1, ACK1, ACK1; 4 frames

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.

Question 7easy

Same situation (window 6, frames 0 to 5, frame 2 lost) but with Selective Repeat. Which frames are retransmitted?

  1. Frames 2, 3, 4, 5
  2. Only frame 2
  3. All frames 0 to 5
  4. Frames 3, 4, 5
Show answer
B) Only frame 2

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.

Question 8medium

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
≈ 0.941

L/R=12000/(2×106)=6L/R = 12000/(2\times10^6) = 6 ms. RTT+L/R=51RTT + L/R = 51 ms.U=min⁡(1,8×651)=4851≈0.941U = \min\left(1, \frac{8 \times 6}{51}\right) = \frac{48}{51} \approx 0.941.
With a window of 9 or more, 9×6=54>519 \times 6 = 54 > 51, so U = 1.

Question 9medium

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
1.25

Geometric distribution: the success probability is 1−p=0.81 - p = 0.8, so the expected number of attempts is 1/(1−p)=1/0.8=1.251/(1-p) = 1/0.8 = 1.25.
The efficiency drops by the same factor: the error-free UU is divided by 1.25.

Question 10hard

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?

  1. Nothing, the receiver discards it correctly
  2. The receiver's window is now {3, 0, 1}, so it accepts the old frame 0 as new data
  3. The sender deadlocks
  4. The receiver sends a NAK and the problem is resolved
Show answer
B) The receiver's window is now {3, 0, 1}, so it accepts the old frame 0 as new data

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 (2k−1=22^{k-1} = 2) the receiver would expect {2, 3} and the old 0 would fall outside.

Question 11hard

Express stop-and-wait utilization in terms of a=dprop/dtransa = d_{prop}/d_{trans} (ignore processing and ACK size). If a=100a = 100, what is UU?

Show answer
U = 1/(1 + 2a) ≈ 0.004975

U=dtransdtrans+2dprop=11+2aU = \frac{d_{trans}}{d_{trans} + 2 d_{prop}} = \frac{1}{1 + 2a}.
For a=100a = 100: U=1/201≈0.004975U = 1/201 \approx 0.004975. When aa 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).

Review card

ARQ = error detection + ACK + timeout + retransmit Sequence number is required: to recognize a repeated frame after a lost ACK (SW: 1 bit) U = min(1, N (L/R) / (RTT + L/R)) SW: N = 1 a = dprop/dtrans -> U_SW = 1 / (1 + 2a) For full utilization N >= (RTT + L/R) / (L/R) = 1 + 2a throughput = U x R GBN: receiver window 1, DISCARD out-of-order, cumulative ACK, one timer, timeout -> resend EVERYTHING from that frame SR : receiver buffers, separate ACK and timer per frame, resend only the lost one k-bit sequence number: GBN W <= 2^k - 1 SR W <= 2^(k-1) error probability p: expected transmissions = 1/(1-p) Piggybacking: put the ACK on a data frame going the other way Pitfall: RTT = 2 x one way; if L is in bytes, multiply by 8