2. Data Link Layer (DLL): Flow & Error Control
This chapter covers Lectures 3 (flow control) and 4 (error control). Both look at one link between two nodes: a sender and a receiver. They answer two questions:
- Flow control: how does the sender avoid sending faster than the receiver can store the frames?
- Error control: what does the sender do when a frame is lost or damaged?
These topics carry most of the calculations in Part I: link utilisation, window size, and how fast a middle node must send so that its buffer does not overflow. Section 6 shows how to use the formulas for each of these.
1. Where This Fits
The data link layer (DLL) moves frames across one link. Its jobs are framing, link access, flow control and reliable delivery. IEEE splits the DLL into two sub-layers: LLC (Logical Link Control, which faces the network layer) and MAC (Medium Access Control, which faces the medium).
Not examinable (slide labels): the list of DLL roles, framing (byte-oriented and bit-oriented), asynchronous start/stop bits, and link configuration (topology and duplex). Everything about flow control and ARQ is examinable.
2. The Four Times You Need
Every calculation in this chapter uses these quantities. Get the units right first.
| Symbol | Name | Formula | What it depends on |
|---|---|---|---|
| Frame length | given, in bits | Convert bytes to bits: . | |
| Data rate | given, in bit/s | ||
| Transmission time | The time to push all bits of one frame onto the link. | ||
| Propagation time | The time for one bit to travel the distance at speed (often m/s). Some questions give a delay per km instead. | ||
| Normalised propagation delay | How long the link is, measured in frame times. |
Think of like this: if , the first bit of a frame arrives at the receiver only after the sender has sent 3 frames’ worth of time.
3. Flow Control
3.1 The problem
The receiver keeps each arriving frame in a buffer (a small memory) until it can process the frame. If the sender sends too fast, the buffer fills and new frames are lost. Flow control makes the sender wait for permission from the receiver.
In this section we assume that no frame has errors. Section 4 adds errors.
3.2 Stop-and-wait
The simplest method:
- The source sends one frame.
- The destination receives the frame.
- The destination sends back an acknowledgement (ACK) when it is ready for the next frame.
- The source waits until the ACK arrives.
- The source sends the next frame.
The receiver can stop the flow at any time. It simply does not send the ACK.
Sequence numbers. Stop-and-wait only needs a 1-bit number: frames alternate 0, 1, 0, 1, …. The ACK carries the number of the frame that the receiver expects next. So “ACK1” means “I have frame 0, now send frame 1”.
3.3 Link utilisation of stop-and-wait
Link utilisation is the fraction of time the link carries useful data:
One cycle has these parts:
The ACK is very short and processing is fast, so we ignore and :
Worked example (lecture). Mbit/s, km, m/s, bytes.
- s
- s
3.4 What is wrong with stop-and-wait
- Lost frame or lost ACK. The source waits for ever. We need a timeout: if no ACK arrives in time, the source sends the frame again. (Section 4 covers this.)
- Long links. When is large, the sender is idle for most of the cycle. For example, gives . The bottom of the fraction, , is set by physics. We cannot make it smaller. But we can make the top bigger by sending more than one frame per cycle. That is the sliding window.
3.5 Sliding window
The idea. The receiver has buffers for frames. So the sender may send up to frames before it gets an ACK.
Rules:
- Each frame carries a sequence number with bits. The numbers go , then start again at 0 (we count modulo ).
- An ACK carries the number of the next frame the receiver expects. “ACK 3” means “I have everything up to frame 2. Send frame 3 next.” One ACK can acknowledge many frames at once.
- Sender window: the list of frames that the sender may send now. It shrinks from the left (trailing edge) each time the sender sends a frame. It grows at the right (leading edge) each time an ACK arrives.
- Receiver window: the list of frames the receiver can accept. It shrinks as frames arrive and grows as the receiver sends ACKs.
Two extra controls:
- RNR (Receive Not Ready): “I have your frames up to , but stop sending.” To restart the flow, the receiver later sends a normal ACK (RR).
- Piggybacking: when both sides send data, a node puts its ACK number inside its own data frame. This saves sending a separate ACK frame.
Window size limit for pure flow control. With bits there are different numbers, so the window can hold at most frames:
The ARQ methods in Section 4 need a smaller limit. Use the ARQ limit when the question includes errors.
3.6 Link utilisation of sliding window
Time starts when the sender sends the first bit of frame 0. The ACK for frame 0 comes back at time . In that time the sender can send frames. There are two cases:
- Case 1: . The ACK for frame 0 arrives before the window is used up. The sender never stops. .
- Case 2: . The sender sends frames in , then waits for the ACK. Each cycle lasts .
Stop-and-wait is the special case .
Smallest window for a target throughput. A 100 kbit/s link carries 1000-bit frames. ms. No errors. What is the smallest window that gives at least 50 kbit/s?
- ms, so and .
- We need .
- . So . If the division gives a fraction, round up, because a window is a whole number of frames.
- Check the sequence number: with bits, , so 2 bits are enough.
4. Error Control (ARQ)
4.1 Two kinds of frame error
- Lost frame: the frame does not arrive, or its header is so damaged that the receiver cannot recognise it.
- Damaged frame: the frame arrives, but some bits are wrong. The receiver’s error check finds this.
4.2 Two ways to deal with errors
- Forward Error Correction (FEC): the sender adds extra bits so that the receiver can repair errors itself (for example, Hamming codes and Reed–Solomon codes).
- Automatic Repeat reQuest (ARQ): the receiver finds
the error, and the sender sends the frame again. This happens in two
ways:
- retransmission after a timeout (no ACK arrives in time), and
- retransmission on request (the receiver sends a NAK, a negative acknowledgement).
ARQ turns an unreliable link into a reliable one. Each flow-control method has an ARQ version:
| Flow control | ARQ version |
|---|---|
| Stop-and-wait | Stop-and-wait ARQ |
| Sliding window | Go-back-N ARQ, or Selective-reject ARQ |
Not examinable (slide labels): parity check, the “seven prisoners” puzzle, and CRC.
4.3 Stop-and-wait ARQ
The source keeps a copy of the frame and starts a timer when it sends.
| Event | What happens |
|---|---|
| Frame is lost | No ACK comes. The timer runs out. The source sends the frame again. |
| Frame is damaged | The destination discards it. It may also send a NAK. The source sends the frame again (after the NAK, or after the timeout). |
| ACK is lost | The timer runs out. The source sends the frame again. The destination now has two copies. The sequence number (0 or 1) shows that the second one is a duplicate. The destination discards it and sends the ACK again. |
| ACK is damaged | The source ignores it. The timer runs out, and the case is the same as a lost ACK. |
Utilisation. Let be the probability that a frame is in error. On average a frame needs attempts. So:
Lecture example: with and , .
4.4 Go-back-N ARQ (the “cautious” method)
The receiver accepts frames only in order.
- Frame types: RR = ACK (receive ready), RNR = receive not ready (flow control), REJ = NAK (reject).
- At the destination: when frame has an error, the destination sends REJ . It then discards frame and every frame after it until a good copy of frame arrives.
- At the source: after a REJ or a timeout, the source goes back and sends frame and every frame after it again.
Maximum window for Go-back-N:
Why not ? Take , so the numbers are 0 to 7.
- With : the source sends frames 0 to 7. All arrive, and the receiver now expects a new frame 0. Its ACK is lost. The source times out and sends the old frame 0 again. The receiver cannot tell old from new. It accepts the old frame 0 as new data. Error.
- With : the source sends frames 0 to 6. The receiver now expects frame 7. The old frame 0 arrives. It is not frame 7, so the receiver discards it. Correct.
Utilisation. The exact Go-back-N formula is not required. The lecture says: use the selective-reject formula for Go-back-N too.
4.5 Selective-reject ARQ (the “efficient” method)
Also called selective repeat. The receiver accepts frames out of order if they fall inside its window.
- At the destination: when frame has an error, the destination sends SREJ (selective reject). It keeps and buffers the frames that arrive after .
- At the source: the source sends again only frame (and any frame whose timer ran out).
- When the good copy of frame arrives, the destination puts the frames back in order and passes them up.
Maximum window for selective-reject:
Why half? Take .
- With : the source sends frames 0 to 4. All arrive. The receiver window moves to {5, 6, 7, 0, 1}. The ACKs are lost. The source times out and sends the old frame 0. Frame 0 is inside the new window, so the receiver accepts it as new. Error.
- With : the window moves to {4, 5, 6, 7}. The old frame 0 is outside the window, so the receiver discards it and sends ACK 4 again. Correct.
The rule: the old window and the new window must not share any number. Two windows of size must fit inside numbers, so .
Utilisation:
4.6 Go-back-N versus selective-reject
| Go-back-N | Selective-reject | |
|---|---|---|
| What is resent | The bad frame and all frames after it | Only the bad frame |
| Receiver buffer | One frame (accepts in order only) | A full window (stores out-of-order frames) |
| Receiver logic | Simple | Complex: must buffer and reorder |
| Bandwidth wasted on errors | More (good frames are sent again) | Less |
| Maximum window | ||
| Best for | Low error rates, simple hardware | High error rates, long links (large ) |
5. Formula Summary
| Method | Max window | when | when |
|---|---|---|---|
| Stop-and-wait (no error) | 1 | — | |
| Sliding window (no error) | |||
| Stop-and-wait ARQ | 1 | — | |
| Go-back-N ARQ | use SR | use SR | |
| Selective-reject ARQ |
Throughput (in bit/s) .
If the question gives a bit error probability instead of a frame error probability, the frame is good only if every bit is good:
6. Using the Formulas
Every calculation in this chapter starts the same way. Write these four lines first, in one unit of time:
- (or distance × delay per km)
Then compare the window with to choose the case. The rest of this section shows the kinds of question this leads to.
6.1 Utilisation, the best window, and the sequence bits
Setup. Mbit/s, bytes, km at 5 µs/km, frame error probability , selective-reject.
- bits, so ms.
- ms.
- , so .
Utilisation for a given window, . , so the window runs out before the first ACK returns:
The throughput is kbit/s.
The smallest window that gives the maximum utilisation. The sender never stops when . The window must be a whole number, so . Then . A larger window cannot do better, because errors still cost 10%.
The fewest sequence bits for that window. Each method has its own limit, so the answer depends on the method:
| Method | Limit | Smallest for |
|---|---|---|
| Sliding window, no errors | ||
| Go-back-N | ||
| Selective-reject |
Header overhead. The sequence number sits in the frame header, so it carries no user data. If the question says that the frame length includes the sequence bits, only of each frame is useful. Multiply the utilisation by this fraction to get the useful utilisation.
6.2 Frame errors from bit errors
Sometimes the question gives a bit error probability , not a frame error probability . A frame is good only if every one of its bits is good:
For bits and : . Longer frames have a higher .
6.3 A middle node must not overflow its buffer
The problem. Frames go A → B → C. B stores each frame from A in its buffer, then sends it on to C. If frames arrive at B faster than B can send them on, the buffer fills and frames are lost. So B’s outgoing throughput must be at least its incoming throughput. The question usually asks for the slowest data rate on link B–C that achieves this.
Method:
- Find the incoming throughput at B: , with the correct formula for link A–B.
- Write the outgoing throughput of link B–C in terms of the unknown rate . For stop-and-wait, B sends one frame per cycle: , with .
- Set outgoing incoming. Solve for , then .
Example. All frames are 2000 bits, with no errors.
- A–B: kbit/s, ms, sliding window .
- B–C: ms, stop-and-wait.
Step 1. On A–B, ms and , so . Since , . The incoming throughput is kbit/s. In time: A sends 2 frames every 40 ms.
Step 2. On B–C, one cycle takes ms.
Step 3. Solve:
The same chain with ARQ on A–B. Now let link A–B have and a 2-bit sequence number, and let A use the largest window that its method allows. Link B–C stays the same.
| Go-back-N on A–B | Selective-reject on A–B | |
|---|---|---|
| Largest window | ||
| Compare with | ||
| (SR formula) | ||
| Incoming at B | 135 kbit/s | 90 kbit/s |
| on B–C | ms | ms |
| Smallest | 416 kbit/s | 164 kbit/s |
Go-back-N allows a larger window for the same , so A sends faster, and B–C must be faster too.
Sanity check. Stop-and-wait can never carry more than , even with an infinite data rate, because every cycle includes the round trip. Here that is kbit/s. If the incoming throughput is larger than this, no rate on B–C works. Say so in your answer.
7. HDLC Time-Sequence Diagrams
HDLC (High-level Data Link Control) is a standard data link protocol that uses sliding windows. A time-sequence diagram shows the frames that two stations, A and B, send to each other over time. You must be able to label every frame in such a diagram.
7.1 The three frame types
| Frame | Meaning |
|---|---|
| I(, ) | An information (data) frame. = the sequence number of this frame. = a piggybacked ACK: “I have your frames up to ; I expect your frame next.” |
| RR() | Receive Ready (an ACK with no data): “I have your frames up to ; send next.” |
| SREJ() | Selective Reject (a NAK): “Send your frame again.” |
All numbers are modulo . With 3 bits, the number after 7 is 0.
7.2 Method
- Treat the two directions separately. Each side has its own sequence counter.
- For each sender, number its I-frames one after another: (mod 8).
- For the second number in an I-frame, look at the frames that this side has received so far from the other side. = (last in-order frame received) + 1.
- A lost frame does not move the receiver’s counter. When a later frame arrives, the receiver sees the gap and sends SREJ for the missing number.
- After the missing frame arrives, the next RR or value jumps to one past the highest frame received.
7.3 Example trace
. A’s next frame number is 6. B’s next frame number is 0. Neither side has received anything yet.
| Step | Frame | Why |
|---|---|---|
| 1 | A → B: I(6, 0) | A’s frame 6. A has nothing from B, so it expects B’s frame 0. |
| 2 | A → B: I(7, 0) | A’s next number. |
| 3 | B → A: I(0, 0) | B’s frame 0. B has A’s 6 and 7, so it expects . |
| 4 | A → B: I(0, 1) | A’s numbers wrap to 0. A now has B’s frame 0, so it expects 1. |
| 5 | A → B: I(1, 1), lost | B never sees it. B still expects A’s frame 1. |
| 6 | A → B: I(2, 1) | B receives frame 2, but frame 1 is missing. |
| 7 | B → A: SREJ(1) | B asks for frame 1 only. It keeps frame 2 in its buffer. |
| 8 | A → B: I(1, 1) | A resends frame 1. B has sent no new data, so stays 1. |
| 9 | B → A: RR(3) | B now holds 0, 1 and 2 in order, so it expects 3. |
In step 3, the two zeros mean different things. The first 0 is B’s own frame number. The second 0 is the next frame B expects from A.
8. Common Traps
- Convert bytes to bits. Convert all times to the same unit before you divide.
- Write , , and first. Most of the work is in these four lines.
- Compare with before you choose the formula. never goes above 1 (or with errors).
- Window limits differ by method: flow control ; Go-back-N ; selective-reject . Use the ARQ limit whenever the link has errors.
- The smallest window for the maximum is . Round up. Then find from the correct limit.
- Go-back-N has no separate formula in this course. Use the selective-reject formula for it.
- ACK (or RR ) means “the next frame I expect is ”, not “I received frame ”.
- In I(, ), counts the sender’s own frames, and counts the other side’s frames.
- A frame error probability is not a bit error probability. Convert with .
- For a buffer question, find the incoming throughput first, then solve for the outgoing rate. Stop-and-wait has a ceiling of that no data rate can beat.
- FEC repairs errors at the receiver. ARQ resends. Parity, CRC and the “seven prisoners” puzzle are not examined.