# Class 17: Error Detection

Back to Some Programming Style Issues. On to Miscellaneous Data-Link Issues.

Held Wednesday, March 1, 2000

Overview

Today we continue our consideration of the data-link layer by investigating codes used for detecting and correcting errors at the data-link layer.

Notes

• There are likely to be some slots for second-year students on the summer research team. You have until Friday to submit applications.
• I have not finished grading the homework. I apologize.
• I will not give an exam before break.
• Next week, you'll have a data-link programming simulation to work on. I'll assign teams.

Contents

Summary

• Error-detecting codes
• Checksums
• CRC
• Error-correcting codes

## Error-Detecting Codes

• How does the recipient know that the frame it received is correct?
• What kinds of errors can we get?
• Bits can flip
• Can bits be lost?
• Is it usally single bits or sequences of bits?
• The sender could send two copies. If they didn't match, the recipient could assume they were incorrect.
• Of course, if the same bit is flipped in both copies, there's no way to detect the error.
• There is also a lot of overhead, since we're sending two bits for every bit of real information.
• A simple solution is to use a parity bit. Every n bits, you count up the number of 1's and add a 1 or a 0 depending on whether the count is even or odd.
• A single parity bit catches only one odd numbers of one-bit errors.
• In particular, it misses two one-bit errors.
• It may be helpful to use two-dimensional parity, in which you arrange your data in a grid and compute parity for each row and each column.
• This technique always catches three or few one-bit errors. (Proof?)
• It is also likely to catch more errors.
• A better technique is to use a cyclic redundancy check. We treat the data as an n-degree polynomial.
• For example, 1001 is x3 + 1
• Similarly, 100100 is x5 + x2
• We choose a special k-degree polynomial for this technique.
• (The technique requires k check bits.)
• Smart mathematicians come up with those polynomials.
• The algorithm:
• Add k 0's to the end of the data.
• Divide by the special polynomial. The remainder will have degree k-1 or less.
• Subtract the remainder from the extended data.
• The result is then divisible by the special polynomial.
• The recipient can divide what it receives by the special polynomial. If the result is non-0, the data were corrupted.
• Since the remainder has k or fewer bits, the subtraction does not affect the original n bits.
• This catches:
• Single-bit errors, provided the polynomial contains both a degree-k term and degree -0 term.
• Any two one-bit errors, provided the polynomial contains at least three terms.
• Any odd number of one-bit errors, as long as x+1 divides the polynomial.
• Burst errors of less than k bits
• Can you explain why?
• Here are the most common CRC polynomials
• CRC-8: x8 + x2 + x1 + 1
• CRC-10: x10 + x9 + x5 + x4 + 1
• CRC-12: x12 + x11 + x3 + x2 + 1
• CRC-16: x16 + x15 + x2 + 1
• CRC-CCITT: x16 + x12 + x5 + 1

### CRC in Hardware

• Note: all CRC remainder calculations are done with XOR, bit shifts, and similarly simple operations. This means that we can (and should) implement it all in hardware!
• We have a shift register with k bits, corresponding to all but the highest-order term in the polynomial.
• Some XORs are also inserted into the circuit. There's an XOR before xi if that terms appears in the CRC polynomial. The XOR is with the previous bit in the shift register and the output bit.
• Pump the input data in from higher-order-bit to lower-order-bit, starting with the x part of the register. (Add k extra 0's on the lower-order end of the input.)
• At each stage, you shift each bit and take one more bit from the input data.
• Here's a picture for the start of the division of (x6 + x2 + 1) divided by (x3 + x2 + 1)
```        2              1              0
x              x              x
+---+          +---+          +---+
+- | 0 | <- [+] - | 0 | <------- | 0 | <- [+] - 1 0 0 0 1 0 1 0 0 0
|  +---+     ^    +---+          +---+     ^
|            |                             |
+------------+-----------------------------+
```
• Let's do the steps. I'll list the output bit, the values in the boxes, and the remaining input
• 0 / 0 0 0 / 1 0 0 0 1 0 1 0 0 0
• 0 / 0 0 1 / 0 0 0 1 0 1 0 0 0
• 0 / 0 1 0 / 0 0 1 0 1 0 0 0
• 0 / 1 0 0 / 0 1 0 1 0 0 0
• 1 / 1 0 1 / 1 0 1 0 0 0
• 1 / 1 1 0 / 0 1 0 0 0
• 1 / 0 0 1 / 1 0 0 0
• 0 / 0 1 1 / 0 0 0
• 0 / 1 1 0 / 0 0
• 1 / 0 0 1 / 0
• 0 / 0 1 0 /
• Hence, the remainder of the division is x. You can check it.
• This technique works because it is essentially automating what we do when we subtract polynomials.
• The bit shift is ("move one column to the right")
• The xor is "subtract one copy" (which we only do when the polynomial has the highest-order term)

### Correcting Errors

• What do we do once we've detected an error?
• Inform the sender to get another copy
• Hope that there's enough information to resolve the error.
• Peterson and Davie tell us that it's not worth the overhead for error-correcting codes. However, it's worth spending a little time on them.
• The most common error-correcting codes rely on what is called the Hamming distance.
• The Hamming distance of two bit equal-length bit strings is the number of bits you have to flip to convert one string to the other.
• We'll draw a graph and a chart for three-bit strings.
• To correct one bit errors, we choose a set of strings such that no two strings have a Hamming distance less than three
• Each represents some sequence of bits. If there are four codes, we can represent pairs of bits.
• Convert from the sequence to the code.
• Send the code.
• Decode. If you don't have the original string, use the closest one.

### Recovering from Frame Errors

• Once we've detected an error, we must recover from that error.
• Hence, there must be some communication between sender and received.
• Two basic techniques:
• The receiver can say ``Hey, I got that!''
• The receiver can say ``Hey, I missed something!''
• More tomorrow.

### History

Thursday, 20 January 2000

• Created as a blank outline.

Wednesday, 1 February 2000

• Filled in the details, taken from previous outline.