§6.2Error-Detection and -Correction Techniques

Link layer Kurose & Ross pp. 454–460 · ~14 min read

  • parity bit
  • two-dimensional parity
  • forward error correction
  • cyclic redundancy check
  • generator

Where you are

  • Application layer
  • Transport layer
  • Network layer
  • Link layer you are here
  • Physical layer

Bits flip on real links, so the sender adds extra bits that let the receiver notice — sometimes locate, and occasionally repair — the damage.

Words you will meet

  • Parity bit — one extra bit that makes the number of 1s even, or odd.

  • Two-dimensional parity — parity on every row and every column, which locates a flipped bit.

  • Forward error correction — written FEC (Forward Error Correction) : repairing the error where it lands, without asking for a retransmission.

  • Cyclic redundancy check — written CRC (Cyclic Redundancy Check) : what link-layer adapters actually use.

  • Generator — written G: the agreed bit pattern a CRC divides by.

Why this matters

Section 3.3 built the Internet checksum and section 4.3.1 put one in the IP (Internet Protocol) header. Both are weak, and the book said so at the time without saying what a strong one looks like.

This section says. It also answers a question the book planted two chapters ago. Why does the transport layer use a checksum and the link layer a CRC, when both detect the same kind of damage?

The answer is not about mathematics. It is about where each one runs, which is what section 6.1 established.

What the receiver can actually know

Figure 6.3 — the setting for everything in this section
The sender protects D with EDCstep 1 of 4
sending nodereceiving nodedatagram from the network layerD · d data bitsEDCD also covers the frame header, not just the datagram

D is the data to be protected. It typically includes not only the datagram passed down from the network layer, but also link-level addressing information, sequence numbers and other header fields. EDC is the error-detection and -correction bits.

The book’s wording of the receiver’s decision is deliberate, and step 4 is why.

Read all steps as text
  1. The sender protects D with EDCD is the data to be protected. It typically includes not only the datagram passed down from the network layer, but also link-level addressing information, sequence numbers and other header fields. EDC is the error-detection and -correction bits.
  2. Both cross a link that flips bitsBit errors are introduced by signal attenuation and electromagnetic noise. Nothing in the link promises they will not happen.
  3. The receiver gets D′ and EDC′Both may differ from what was sent. Note that the error-detection bits themselves can be damaged — they cross the same link.
  4. And the question it can answer is narrower than you wantThe receiver must decide whether D′ is the same as D, knowing only D′ and EDC′. The book asks whether an error is DETECTED, not whether an error has OCCURRED — and says the wording is important. These techniques let a receiver sometimes, but not always, notice that bit errors happened.

”Detected”, not “occurred”

The book flags its own wording, and it is worth slowing down for.

The receiver’s question is “is an error detected?” — not “did an error occur?” Error-detection techniques let a receiver sometimes, but not always, detect that bit errors have happened.

So a receiver may be entirely unaware that what it holds is corrupt. It might deliver a damaged datagram upward, or act on a damaged header field, believing both are fine.

The whole design goal is to make that probability small, not zero. And the usual price is overhead: a scheme with a smaller chance of missing an error needs more computation and more bits.

Parity: the smallest possible scheme

In an even parity scheme the sender adds one bit, chosen so the total number of 1s in the d + 1 bits is even. Odd parity chooses the other value.

The receiver simply counts the 1s. An odd count under even parity means at least one bit flipped — more precisely, it means an odd number of bits flipped.

Figure 6.4 — one-bit even parity
01110001101010111
16 data bitsparity bit

The receiver counts the 1s in all 17 bits and finds 10, which is even. No error detected.

Click any data bit to flip it. Then flip a second one.

The book’s own bits. Click one to flip it, then click a second. The second flip is the lesson.

In plain words

Flip one bit and the count changes from even to odd, and the receiver knows.

Flip a second and the count is even again. The receiver sees nothing wrong.

If bit errors were rare and independent, two errors in one frame would be very unlikely and one parity bit might do. But measurements show errors are not independent: they cluster in bursts. Under burst conditions the probability that a single parity bit misses the damage can approach 50 per cent.

A coin flip is not error detection.

Two dimensions, and something new

Lay the d bits out in i rows and j columns, and compute a parity value for each row and each column. The i + j + 1 parity bits are the frame’s error-detection bits.

Now flip a single bit. Its row fails and its column fails, and no other row or column does. The receiver can use those two indices to find the corrupted bit and put it back.

Figure 6.5 — two-dimensional even parity
101011
111100
011101
001010
000000

Every row and every column agrees with its parity bit. Click any bit to flip it.

Row parity down the right, column parity along the bottom. Flip exactly one bit and the receiver can repair it. Flip two and it can only complain.

That ability — to detect and correct — is forward error correction . Two-dimensional parity can also detect any combination of two errors, though it cannot correct them.

Everyday picture

A spreadsheet where every row has a total in the right-hand column and every column has a total along the bottom.

Change one number by mistake and exactly one row total and one column total stop matching. You do not need to hunt: the two wrong totals cross at the cell you broke, and you can work out what the value should have been.

Change two numbers and several totals disagree, and they no longer cross at one place. You know something is wrong. You cannot say what.

Where the picture stops. A spreadsheet’s totals are much bigger than one digit, so they carry far more information than a parity bit, which is a single 0 or 1. Parity tells you only whether a count was odd — which is exactly why an even number of errors slips through.

Why forward error correction is worth its bits

FEC (Forward Error Correction) is used in audio storage and playback, and the book names audio compact discs. In networks it is used either alone or alongside link-layer ARQ (Automatic Repeat reQuest) techniques like the ones in section 3.4.

It has two benefits, and the second is the bigger one.

It reduces the number of retransmissions the sender must make.

It corrects the error immediately, at the receiver. No waiting a round-trip for a NAK (negative acknowledgement) to travel back and a retransmission to travel forward. That matters for real-time applications. It matters enormously on links with long propagation delays — the book’s example is a deep-space link, where one round trip is measured in hours.

Checksums, and the question the book has been saving

In a checksumming method the d data bits are treated as a sequence of k-bit integers, which are summed. The Internet checksum does exactly this with 16-bit integers, and section 3.3 took it apart bit by bit.

Why a checksum at the transport layer and a CRC at the link layer
Internet checksumtransport layerCyclic redundancy checklink layer
Runs where
And therefore must be
The arithmetic
Bits of overhead
Protection

Cells marked ⓘ have a reason behind them — click to read it.

The book plants this question and answers it in one sentence. Everything else in the table follows. Click any cell.

In plain words

The answer is one sentence long, and it is not about which scheme is better.

The transport layer is software, so it needs something fast. The link layer is a chip, so it can afford something strong.

That is why the same job is done two different ways at two layers, and why neither choice is a mistake. Section 6.1 is what makes the argument work: without knowing the link layer is a network adapter, this looks arbitrary.

Cyclic redundancy check

CRC (Cyclic Redundancy Check) codes are also known as polynomial codes, because the bit string can be viewed as a polynomial whose coefficients are its 0s and 1s.

The sender and receiver first agree on an r + 1 bit generator , G, whose leftmost bit must be 1. For a piece of data D, the sender then chooses r additional bits R and appends them. It chooses them so that the resulting d + r bit pattern is exactly divisible by the generator, with no remainder, using modulo-2 arithmetic.

Error checking is then trivial: the receiver divides the d + r received bits by the generator. A non-zero remainder means an error; zero means the data is accepted.

R means something different here from anywhere else in this chapter

In this section R is the r CRC check bits — a bit pattern.

From section 6.3 onwards, R is the link rate of a shared channel, in bits per second, and it turns up in expressions like R/N. That is five book pages away.

The tell is the unit. If R is being divided or measured in bits per second, it is a rate. If it is being appended to data, it is the CRC bits.

The arithmetic is exclusive-or

All CRC calculations are done in modulo-2 arithmetic, without carries in addition or borrows in subtraction. So addition and subtraction are identical, and both are the bitwise exclusive-or:

10110101=111010011101=01001011 \oplus 0101 = 1110 \qquad 1001 \oplus 1101 = 0100

and equally 1011 − 0101 = 1110. Multiplication by 2^k left-shifts a pattern by k places, exactly as in ordinary binary.

Where R comes from

The sender wants R such that D · 2^r ⊕ R = nG for some n. Exclusive-or R onto both sides and that becomes

D2r=nGRD \cdot 2^r = nG \oplus R

which says: divide D · 2^r by G, and the remainder is exactly R.

R=remainder ⁣(D2rG)R = \text{remainder}\!\left(\frac{D \cdot 2^r}{G}\right)
Figure 6.7 — a sample CRC calculation, one step at a time
division step 6 of 6
quotient101011
G1001
D · 2r101110000
working000000011

Step 6: the working bit at position 6 is 1, so G is XORed in there and the quotient gets a 1. Modulo-2 subtraction is exclusive-or, with no borrows.

The last 3 bits of the working value are 011 — that is R, the CRC bits. What goes on the wire is D followed by R:

101110011click a bit to damage it in flight

The receiver divides by G and gets remainder 000 zero, so the data is accepted.

The book’s own D = 101110 and G = 1001, so d = 6 and r = 3. Step to the end and the nine transmitted bits are 101 110 011, exactly as the book prints them. Then click a bit to damage the frame in flight.

Check the book’s own numbers

The widget above runs the book’s Figure 6.7: D = 101110, so d = 6, and G = 1001, so r = 3.

Step to the end and you should have quotient 101011 and remainder 011 — both printed in the book’s figure. The nine transmitted bits are then 101 110 011, which is exactly what page 460 says.

Then click any transmitted bit. The receiver’s division stops coming out at zero, and it does so for every single-bit flip. tools/check-bitstream-ch06.mjs tries all nine positions and all 49 possible bursts of up to 3 bits, and the check catches every one.

What a CRC actually guarantees

International standards define 8-, 12-, 16- and 32-bit generators. CRC-32, adopted in a number of IEEE (Institute of Electrical and Electronics Engineers) link-level protocols, uses

G_CRC-32 = 100000100110000010001110110110111

Thirty-three bits, so r = 32. Each CRC standard gives three guarantees.

  • Every burst error of fewer than r + 1 bits is detected. All consecutive bit errors of r bits or fewer are caught, with certainty.
  • A longer burst is detected with probability 1 − 0.5^r. For CRC-32 that is a chance of about one in four billion of missing one.
  • Any odd number of bit errors is detected, however far apart they are.

Check yourself

Check yourself

0 of 7 answered
  1. 1.The book asks whether an error is "detected", not whether an error has "occurred", and says the wording is important. Why?

  2. 2.predictA frame is protected by a single even parity bit. Two of its bits flip in transit. What does the receiver conclude?

  3. 3.With two-dimensional parity, one bit flips. What can the receiver do?

  4. 4.Why does the transport layer use a checksum while the link layer uses a CRC, when both detect the same kind of damage?

  5. 5.In CRC, how does the sender choose the r bits R?

  6. 6.In CRC arithmetic, what is 1011 − 0101?

  7. 7.CRC-32 uses a 33-bit generator, so r = 32. What does that guarantee?

What to remember

  • The receiver asks whether an error is detected, not whether one occurred. These schemes can always be fooled; the goal is to make that rare.
  • Two-dimensional parity locates a single error — its row and its column both fail — so it can correct it. That is forward error correction, and its real value is repairing the error immediately rather than waiting a round trip.
  • A checksum sums integers; a CRC divides. The transport layer uses the first because it is software; the link layer uses the second because it is a chip.