Data Communication · Lecture 12
Flow and error control: Stop-and-Wait, Go-Back-N and Selective Repeat ARQ, piggybacking, HDLC and PPP
Md Mahbub E Noor · Assistant Professor, Department of CSE, University of Barishal
Course: Data Communication · 2nd Year, 2nd Semester
Lecture 11 gave us
frames, and codes that tell the receiver when a frame is damaged.
Today
make delivery reliable: acknowledge, time out, resend, and never overwhelm the receiver.
Reading: Forouzan (5th ed.) Sections 11.1–11.4 and 23.2 (Go-Back-N, Selective Repeat)
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
2 / 38
How much may the sender send before it must wait for an acknowledgement? Protects the receiver's buffer.
Detect lost or damaged frames and resend them: automatic repeat request (ARQ).
| Tool | Job |
|---|---|
| ACK (acknowledgement) | “received correctly; I expect frame n next” |
| NAK (negative ACK) | “frame n is missing or damaged” |
| Timer | no ACK in time → resend |
| Sequence numbers | tell new frames from duplicates |
| Window | how many frames may be unacknowledged |
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
3 / 38
| Protocol | Channel | Flow control | Error control | Windows (send / receive) |
|---|---|---|---|---|
| Simplest | noiseless | none | none | – |
| Stop-and-Wait | noiseless | wait for ACK | none | 1 / 1 |
| Stop-and-Wait ARQ | noisy | wait for ACK | timer, resend 1 frame | 1 / 1 |
| Go-Back-N ARQ | noisy | window | resend from the lost frame on | 2m − 1 / 1 |
| Selective Repeat ARQ | noisy | window | resend only the lost frame | 2m−1 / 2m−1 |
A noiseless channel is an ideal one: no frame is lost, duplicated or corrupted. Real links are noisy, so real protocols use ARQ. m = number of bits in the sequence-number field.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
4 / 38
Sender
Receiver
F
F
F
F
F
Sender
Receiver
F
ACK
F
ACK
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
5 / 38
| What can go wrong | Fix in Stop-and-Wait ARQ |
|---|---|
| frame lost or damaged (receiver silent) | sender keeps a copy and a timer; on time-out it resends |
| ACK lost: the frame arrives twice | sequence number on each frame; the receiver discards the duplicate |
| ACK delayed: which frame is it for? | ACK number = number of the next frame expected |
Sequence numbers
modulo 2 (m = 1)
0, 1, 0, 1 …
Receiver gets frame 0 correctly
it now expects frame 1
sends ACK 1
A damaged frame is discarded silently: the receiver sends nothing, and the timer does the rest.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
6 / 38
Sender
Receiver
Frame 0
ACK 1
Frame 1
Frame 1
ACK 0
Frame 0
ACK 1
Frame 0
ACK 1
time-out
time-out
duplicate: discard, re-ACK
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
7 / 38
Checkpoint 1 · 3 minutes
Stop-and-Wait ARQ: the receiver has just accepted frame 1. Which ACK does it send, and why?
Frame 0's ACK is lost. What does the sender do, and how does the receiver recognise the duplicate?
A 2 Mbps link carries 4,000-bit frames; one-way propagation is 4 ms. What fraction of the time is Stop-and-Wait sending?
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
8 / 38
One round trip could carry 20 frames of 1,000 bits; Stop-and-Wait sends one
Bandwidth-delay product
1 Mbps × 20 ms
20,000 bits
Stop-and-Wait
1,000 / 20,000
5%
Up to 15 frames in flight
15,000 / 20,000
75%
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
9 / 38
a = Tp / Tt
U = W / (1 + 2a), at most 1
Full use: W ≥ 1 + 2a
Worked: a GEO satellite link · R = 1 Mbps, L = 8,000 bits, Tp = 270 ms
Tt and a
8,000 / 10⁶ = 8 ms; 270 / 8
a = 33.75
Stop-and-Wait
1 / 68.5
1.46%
Window for 100%
1 + 2a = 68.5
W = 69
Sequence bits
GBN: 2⁷ − 1 = 127 · SR: 2⁷ = 128
m = 7 · m = 8
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
10 / 38
Interactive
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
11 / 38
m = 3: sequence numbers repeat modulo 8
0
1
2
3
4
5
6
7
0
1
2
3
4
5
Sf = 2 (first outstanding)
· Sn = 5 (next to send)
· Ssize = 5
acknowledged
sent, no ACK yet
may send
ACK 4 arrives → frames 2 and 3 confirmed → the window slides two places
0
1
2
3
4
5
6
7
0
1
2
3
4
5
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
12 / 38
0
1
2
3
4
5
6
7
0
1
2
3
one timer, for the oldest outstanding frame (Sf)
0
1
2
3
4
5
6
7
0
1
2
3
receive window of size 1: accepts only Rn; anything else is discarded
Cumulative ACK
ACK 5 confirms
every frame before 5
Time-out
resend
Sf … Sn − 1
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
13 / 38
ACK 2 lost
Sender
Receiver
F0
F1
F2
F3
ACK 1
ACK 2
ACK 3
ACK 4
Frame 1 lost
Sender
Receiver
F0
F1
F2
F3
ACK 1
F1
F2
F3
ACK 2
ACK 4
time-out
Grey = arrived but discarded (out of order) · dashed = resent
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
14 / 38
sender: sent, all ACKs lost, then resends 0
0
1
2
3
0
receiver now expects
0
1
2
3
Resent 0 ≠ expected 3: recognised as a duplicate ✓
sender: sent, all ACKs lost, then resends 0
0
1
2
3
0
0
receiver now expects
0
1
2
3
0
Resent old 0 = expected new 0: accepted by mistake ✗
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
15 / 38
Interactive
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
16 / 38
Checkpoint 2 · 3 minutes
m = 4. What is the largest send window for Go-Back-N? For Selective Repeat?
Go-Back-N, window 5: frames 0–4 are sent and frame 2 is lost; the rest arrive. Which frames does the sender resend after the time-out?
A link has a = 12. What window gives full utilisation, and how many sequence bits does Go-Back-N need?
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
17 / 38
0
1
2
3
4
5
6
7
0
1
2
3
a timer for each outstanding frame
0
1
2
3
4
5
6
7
0
1
2
3
window of size 2m−1: frame 3 is stored while 2 is missing
delivered / acknowledged
sent / stored
window
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
18 / 38
Sender
Receiver
F0
F1
F2
F3
ACK 1
NAK 1
F1
ACK 4
F2 stored
F3 stored
deliver 1, 2, 3
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
19 / 38
sender: sent, all ACKs lost, then resends 0
0
1
2
0
receiver now expects
0
1
2
3
Receiver window {2, 3} does not contain 0: duplicate ✓
sender: sent, all ACKs lost, then resends 0
0
1
2
3
0
receiver now expects
0
1
2
3
0
1
Receiver window {3, 0, 1} contains 0: old frame accepted ✗
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
20 / 38
Interactive
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
21 / 38
| Stop-and-Wait ARQ | Go-Back-N | Selective Repeat | |
|---|---|---|---|
| Frames in flight | 1 | up to 2m − 1 | up to 2m−1 |
| Receiver window | 1 | 1 | 2m−1 (buffers) |
| After a loss, resend | that frame | it and all after it | only that frame |
| Timers | 1 | 1 | one per frame |
| Lab run: 10 frames, frame 3 lost, m = 3 | 11 sent · 80 time units | W = 7: 17 sent · 36 | W = 4: 11 sent · 30 |
| Best for | short links | few errors | long or noisy links |
Lab run: propagation = 3 frame times, link otherwise idle. Go-Back-N's bigger window loses to Selective Repeat once a frame is lost: 7 frames go twice.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
22 / 38
Top: 3 frames · Bottom: piggybacking, 2 frames
A
B
A
B
data →
← ACK
← data
data →
← data
+ ACK
| Advantage | Disadvantage |
|---|---|
| fewer frames, better use of the channel | more complex sender and receiver |
| less header overhead | an ACK held back too long triggers a time-out |
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
23 / 38
NRM: normal response mode
Primary
Secondary
Secondary
Secondary
ABM: asynchronous balanced mode
Combined
Combined
Primary sends commands; secondaries only respond. A combined station does both.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
24 / 38
Flag
Address
Control
Information
FCS
Flag
| Frame | Carries | Control starts with |
|---|---|---|
| I-frame | user data + flow/error control (piggybacked ACK) | 0 |
| S-frame | flow and error control only (ACK, NAK); no data | 10 |
| U-frame | link management: connect, disconnect … | 11 |
Back-to-back frames may share a flag: one frame's ending flag is the next frame's starting flag.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
25 / 38
I-frame
0
N(S) ·3
P/F
N(R) ·3
S-frame
1 0
code ·2
P/F
N(R) ·3
U-frame
1 1
code ·2
P/F
code ·3
·n = number of bits
| S code | Name | Meaning |
|---|---|---|
00 | RR | receive ready: ACK up to N(R) − 1 |
10 | RNR | ACK, but stop: receiver busy |
01 | REJ | NAK for Go-Back-N: resend from N(R) |
11 | SREJ | NAK for Selective Repeat: resend N(R) only |
Decode 0 011 0 101
I-frame · N(S) = 3 · P/F = 0 · N(R) = 5
“my frame 3; I expect your 5”
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
26 / 38
Interactive
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
27 / 38
No error: piggybacking
Node A
Node B
I 0,0
I 1,0
I 0,2
I 1,2
I 2,2
RR 3
Frame 1 lost: REJ
Node B
Node A
I 0
I 1
I 2
REJ 1
I 1
I 2
RR 3
Labels: I N(S),N(R) · grey = discarded · dashed = resent
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
28 / 38
Flag
7E
Addr
FF
Ctrl
03
Protocol
1–2 B
Payload
≤ 1500 B
FCS
2–4 B
Flag
7E
| PPP provides | PPP does not provide |
|---|---|
| frame format and byte stuffing | flow control |
| link set-up and option negotiation (LCP) | error recovery: a bad frame is silently dropped |
| authentication (PAP, CHAP) | sequence numbers |
| many network protocols; address assignment (NCP) |
Old-slide fix: control = 00000011 = 03 (5th ed.). The old slide's 11000000 is the same byte written in transmission order (LSB first).
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
29 / 38
Payload bytes (hex)
45
7E
00
7D
21
Forouzan's rule: insert escape 7D (01111101) before 7E or 7D
45
7D
7E
00
7D
7D
21
Real PPP (RFC 1662): 7D, then the byte XOR 20
45
7D
5E
00
7D
5D
21
7E ⊕ 20
0111 1110 ⊕ 0010 0000
5E
7D ⊕ 20
0111 1101 ⊕ 0010 0000
5D
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
30 / 38
Interactive
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
31 / 38
Dead
Establish
Authenticate
Network
Open
Terminate
carrier
LCP OK
auth OK
NCP done
close
carrier lost
auth failed
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
32 / 38
| Protocol field | Payload carries |
|---|---|
C021 | LCP: link set-up, options, termination |
C023 | PAP: user name and password |
C223 | CHAP: challenge and response |
8021 | IPCP (an NCP): configure IP |
0021 | an IP datagram: user data |
2 steps: send ID + password; accept or reject. Password crosses the link in clear.
3 steps: challenge → result of f(challenge, password) → accept or reject. Password never sent.
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
33 / 38
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
34 / 38
Click the video to play or pause · Press → for full screen
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
35 / 38
Checkpoint 3 · 3 minutes
Decode the HDLC control field 10 01 0 011 (as on the slides). What is the receiver asking for?
Byte-stuff the PPP payload 7E 41 7D: (a) by Forouzan's rule, (b) by RFC 1662.
Selective Repeat, m = 3: frames 0–3 are sent and frame 2 is lost. What does the receiver deliver, store and send?
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
37 / 38
Next lecture
Sharing one medium: random access (ALOHA, CSMA, CSMA/CD, CSMA/CA), controlled access and channelization.
Reading: Forouzan, Chapter 12 · Practise in the ARQ Lab
Md Mahbub E Noor
Lecture 12: Data Link Layer II
University of Barishal
38 / 38