Data Link Layer, Part 2 Error Detection and Correction
Data Link Layer, Part 2 Error Detection and Correction
Transmission Errors
Causes: noises, attenuation, distortion,
crosstalk, losing synchronization
Error detection
– Parity checks, cyclic redundancy codes, …
Error correction
– send redundant information with data
– when receiving data incorrectly, the
receiver makes “educated guess” about the
original data
– Ex. Hamming code
CS 656 2
1
Parity Checks
Add an extra bit to a string of bits in order to make
the total number of 1’s even (even parity) or odd
(odd parity)
Example (even parity): 0 1 1 0 1 1 0 1 1
Advantages
– detects any single bit error
– in fact, detects any error involving odd number
of bits
Disadvantages
– only 50% chance of detecting burst errors
– an n-bit burst error is a string of bits inverted
during transmission
CS 656 3
1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0
+ 1 1 0 0 1 0 1 0 - 1 0 1 0 0 1 1 0
CS 656 4
2
Method
Sender:
– divide string (frame) by a generator
polynomial G(x)
– tag the remainder (called a checksum)
onto the frame when it is transmitted
Receiver:
– divide the entire frame by G(x)
– a non-zero remainder indicates errors
Example:
– data: 1010001101, G(x): 110101
CS 656 5
1 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 0 0 0 0
1 1 0 1 0 1
1 1 1 0 1 1
1 1 0 1 0 1
1 1 1 0 1 0
1 1 0 1 0 1
1 1 1 1 1 0
1 1 0 1 0 1
1 0 1 1 0 0
1 1 0 1 0 1
1 1 0 0 1 0
1 1 0 1 0 1
0 1 1 1 0
Transmitted data:
101000110101110 6-bit generator
produces 5-bit
remainder
CS 656 6
3
How CRC Works ?
D(x): data
D’(x): data with appended 0s
– Let D’(x) = P(x)G(x) + R(x)
T(x): transmitted bits; must be a multiple of G(x)
1 0 1 0 0 0 1 1 0 1 0 0 0 0 0 D’(x)
- 0 1 1 1 0 R(x)
1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 T(x)=D’(x)-R(x)
Transmitted: 11010101010001111
+ Errors: 00001000111000100
Received: 11011101101001011
CS 656 8
4
Example of a CRC Failure
From the earlier example:
– G(x) = x5 + x4 + x2 + 1 (110101)
– D(x): 1 0 1 0 0 0 1 1 0 1
– T(x): 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0
– E(x): 1 1 1 1
– R(x): 1 0 1 0 0 0 1 0 1 0 0 1 1 1 1
– Please check that E(x)=G(x)*(x2+1)
– You can check for yourself that R(x) will be
(incorrectly) accepted by the receiver.
CS 656 9
CS 656 10
5
detects all double errors if
– x does not divide G(x), and
– G(x) does not divide xk + 1 for any k < K
where K is the frame length
Why?
CS 656 11
CS 656 12
6
Other CRC Properties
If G(x) satisfies all the above properties,
then
– all burst errors of length r or less are
detected, where r is the degree of G(x),
– burst errors of length r + 1 are missed
with probability 1 2r −1
– burst errors of length r + 2 or more are
missed with probability 1 2r
CS 656 13
Common Generators
CRC-8: x8 + x2 + x + 1 (used with ATM)
CRC-CCITT: x16 + x12 + x5 + 1 (used with
HDLC)
– catch all single, double, and odd errors
– catch all burst errors of length of 16 or less
– catch 99.997% of burst errors of length 17
– catch 99.998% of length 18 or more
CRC –32: x32 + x26 + x23 + x22 + x16 + x12 +
x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 (used
with Ethernet)
CS 656 14
7
Error Correcting Codes
Frame consists of m data bits and r check bits.
The resulting n = m +r bit unit is called a
codeword.
The number of bits by which two codewords
differ is called the Hamming Distance.
To detect d-bit errors, we need distance of d +
1 between any pair of codewords.
– codewords with single parity bit have a
minimum distance of 2
To correct d-bit errors, we need distance of 2d
+ 1.
CS 656 15
An Example
Consider a (inefficient) coding scheme where each
bit is simply repeated three times.
000 000 000 000
001 000 000 111
010 000 111 000
011 000 111 111
100 111 000 000
101 111 000 111
110 111 111 000
111 111 111 111
The minimum Hamming distance among the
above codewords is 3.
This scheme can detect any 2-bit errors.
CS 656 16
8
A Naïve Error Correction Method
The above scheme can also be used to
correct 1-bit errors.
When receiving an invalid codeword, we
assume that the original data is the closest,
valid codeword.
100 000 000
100 000 111
010 000 000 000 000 001 000 000 110 010 000 111
001 000 000 000 000 000 000 000 010 000 000 101 000 000 111 001 000 111
000 100 000 000 000 100 000 000 011 000 100 111
000 010 000 000 001 000 000 001 111 000 010 111
CS 656 17
9
Hamming Codes
Achieves the theoretical lower bound of check bits.
number bits 1 to n
power-of-2 positions are check bits
the value of each check bit 2k depends on the
parity of the bits whose label contains that 2k when
written as the sum of powers of 2.
to find out the incorrect bit, determine if check bits
are correct
add 2k to a counter c if the check bit is one of the
wrong parity.
in the end, if c = 0, then it gives the position of the
incorrect bit.
CS 656 19
Example
original data: 1 0 1 0 1 1 0
codeword: 0 1 1 1 0 1 0 0 1 1 0
bit numbers: 1 2 3 4 5 6 7 8 9 10 11
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 10
1011 11
CS 656 20
10
Error Correction in Action
Error
received: 0 1 1 1 1 1 0 0 1 1 0
bit numbers: 1 2 3 4 5 6 7 8 9 10 11
Parity checks:
20 = 1, fail Denote pass by 0 and fail by 1.
21 = 2, pass We have: 0 1 0 1 = 5
22 = 4, fail 23 22 21 20
23 = 8, pass
CS 656 21
Discussion
In a nutshell, error correction technologies
are educated guests on the part of the
receiver.
Error corrections are typically used by
applications that
– can tolerate occasional errors
– but cannot tolerate the delays of data
retransmissions
Example: multimedia playback
CS 656 22
11