371-1-0291: An Introduction to Computer Networks Homepage http://help.cse.bgu.ac.il/cse/Courses/list.asp Handout #13: Error Detection and Correction Additional Reading Text book: Chap. 2.4 Lect-11-1: Error Control Computer Networks
Outline Basic ideas: BER, PER and Hamming Distance Parity Error Detection: Cyclic Redundancy Codes Error Correction Error Detection versus Correction Lect-11-1: Error Control Computer Networks
Errors A bit error occurs when a source sends a bit, b, and the destination receives NOT b. The error can take place on the link (e.g. interference, or signal loss), in a (malfunctioning) switch or router along the path, or in the source or destination (e.g. failed hardware, or bit errors in memories). The bit error rate (BER) tells us the probability of any given bit being in error. Typical values are BER = 10-9 for an electrical link, and 10-12 for an optical link. Lect-11-1: Error Control Computer Networks
Error Detection D H H ACK An example: Assume BER and independent errors, Packet Error Rate = PER = 1 – (1 – BER)N PER ~= N (BER) if N (BER) << 1 e.g. N = 104, BER = 10-7 = PER = 10-3 Lect-11-1: Error Control Computer Networks
Error Detection In practice, bit errors occur in BURSTS: Perhaps caused by mechanical switches. Time constants. Therefore, PER is lower for a given BER Lect-11-1: Error Control Computer Networks
Encoding to detect errors We use codes to help us detect errors. The set of possible messages is mapped by a function onto the set of codes. We pick the mapping function so that it is easy to detect errors among the resulting codes. Example: Consider the function that duplicates each bit in the message. E.g. the message 1011001 would be mapped to the code 11001111000011, and then transmitted by the sender. The receiver knows that bits always come in pairs. If the two bits in a pair are different, it declares that there was a bit error. Of course, this code is quite inefficient (doubles #bits, un-detects if both bits are corrupted) Lect-11-1: Error Control Computer Networks
Hamming Distance Number of bits that differ between two codes e.g. 1 0 0 1 0 1 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 1 0 0 In our example code (replicated bits), all codes have at least two bits different from every other code. Therefore, it has a Hamming distance of at least2. HD=3 Lect-11-1: Error Control Computer Networks
Hamming Distance Set of codes - To reliably detect errors in d bits: HD > d - To reliably correct errors of d bits : HD > 2d 4 3 Example Suppose we encode “0” by “0” and “1” by “1” A corrupted single bit leads to a decoding error If we encode “0” –> “00” ; “1” –> “11”, then a single corrupted bit is detected, but from receiving “01” we don’t know if “1” or “0” has been transmitted If we encode “0” –> “000” ; “1” –> “111” and one bit is corrupted, we reliably detect the xmitted by the majority rule d 23 1 2 HD = min (dij ) ij Lect-11-1: Error Control Computer Networks
Parity: A simple error detection code We look for to add redundancy efficiently Parity: A simple error detection code 0 1 1 1 0 1 0 1 1 Parity added to make # 1s even/odd If parity is wrong ERROR If parity is right NO ERROR (or an even number of errors has occurred) Q: What is the minimum Hamming distance for this code? Lect-11-1: Error Control Computer Networks
Error Detection Cyclic Redundancy Code (CRC) Goal: Maximize the error detection prob using only a small # of redundant bits Technique comes from Finite Fields Algebra A (n+1) bit message is represented by a polynomial with degree n MSB e.g., For CRC, the XMT and RCV agree on a divisor polynomial , of degree k, e.g., for k=3 Lect-11-1: Error Control Computer Networks
T(X) is divisible by C(X) if deg[T(X)] >= deg[C(X)] The selection of C(X) has a crucial impact on what errors can be detected. E.g., for Ethernet the C(X) is a 32 degree polynomial Given M(X) and C(X), the transmitted message is (n+1)+k bits long and corresponds to a polynomial T(X) that is exactly divisible by C(X) (using binary polynomial arithmetic): T(X) is divisible by C(X) if deg[T(X)] >= deg[C(X)] If deg[T(X)] = deg[C(X)], T(X) is divisible once by C(X), and if deg[T(X)] < deg[C(X)] it is not The remainder of T(X)/C(X) is [T(X) XOR C(X)] Lect-11-1: Error Control Computer Networks
A division example will be given later A remainder computational example Example C(X) ~ 1 1 0 1 T(X) ~ 1 0 0 1 XOR 0 1 0 0 Lect-11-1: Error Control Computer Networks
T(X)= M(X) (adds k zeros at the message end) To create T(X) do: T(X)= M(X) (adds k zeros at the message end) Divide T(X) by C(X) and find the remainder R(X) T(X)=T(X) – R(X) The resulting T(X) is exactly divisible by C(X) and contains M(X) followed by R(X) (recall that by binary subtraction 0 -b = b) Lect-11-1: Error Control Computer Networks
Example: M= 110101 C = 1001 M(X) T = 1 1 0 1 0 1 0 1 1 Xmitted message 1 1 0 0 1 1 M(X) 1 0 0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 0 0 1 1 T = 1 1 0 1 0 1 0 1 1 Xmitted message R Lect-11-1: Error Control Computer Networks
To detect an error upon receiving T(X) do: Divide T(X) by C(X) If the remainder R(X) is zero, no-error is concluded If the remainder R(X) is not zero, an error has ocured Lect-11-1: Error Control Computer Networks
Cyclic Redundancy Code (CRC) single bit error detection A single-bit error can be represented as: T(X)+E(X), where E(X) = Xi (bit i corruption) If C(X) = Xk + Xj , i.e. C(X) has any 2 terms we can detect a single bit error. Indeed, Since C(X) divides T(X) (so generated) but can’t divide E(X), all single bit errors can be detected. [ Check what happens when you divide (10000) by (101) ] Lect-11-1: Error Control Computer Networks
Cyclic Redundancy Code (CRC) Double bit error detection (ii) Two isolated errors can be represented as: E(x) = xi + xj = xj (xi-j + 1) If (xk + 1) is not a factor of C(x) for any k then: all two-bit errors are detected, or if C(x) has a 3-term factor. (In this cases, C(x) cannot divide E(x) ) (iii) Detecting an odd number of errors Theorem: If (x + 1) is a factor of C(x) then: all odd errors are detected. Proof by contradiction: Assume E has odd # of 1’s and (x + 1) is a factor: E(x) = (x +1)E’ (x) for some E’ (x) Lect-11-1: Error Control Computer Networks
Cyclic Redundancy Code (CRC) (iii) Proof (cont.) E(1) = (1 + 1) E’(1) = 0 E’(1) = 0 Evaluated at x=1 But E(x) has odd # of 1’s so : E (1) = 1 Therefore, if E has an odd # of 1’s, it is not divisible by (x + 1) Lect-11-1: Error Control Computer Networks
Cyclic Redundancy Code (CRC) (iv) Burst error of length < k (degree of C(x)) can be detected Burst of length k-1 is represented : E(x)=xi (x k-1-i + …+1), 0 <= i < k Thus, C(x) doesn't divide any factor of E(x) (v) Longer bursts can not necessarily be guaranteed to be detected. Lect-11-1: Error Control Computer Networks
Cyclic Redundancy Code (CRC) Examples of common CRC generators: CRC-8: x8 + x2 + x1 + 1 CRC-10: x10 + x9 + x5 + x4 + x1 + 1 CRC-12: x12 + x11 + x3 +x2 +1 CRC-16: x16 + x15 + x2 +1 CRC-CCITT: x16 + x12 + x5 + 1 CRC-32: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 +x + 1 Lect-11-1: Error Control Computer Networks
Error Correction Common code used: Bose-Chaudhuri-Hocquenghem (BCH) R BCH (R + M, M, t) e.g. BCH (1023, 923, 10) Can detect all “t” bit errors If t=1 then the code is called Reed-Solomon and is used in CD players Lect-11-1: Error Control Computer Networks
Most data networks today use error detection, Detect or Correct? Advantages of Error Detection Requires smaller number of bits/overhead. Requires less/simpler processing. Advantages of Error Correction Reduces number of retransmissions. Most data networks today use error detection, not error correction. Lect-11-1: Error Control Computer Networks
Detect or Correct? An example Assume: 1. Packets are of lengths 923 bits 2. PER = 10-5 Overhead of Error Correction: Assume we use: BCH (1023, 923, 10) Therefore, we send 923 data bits as 1023 bits. Overhead of Error Detection: Assume we use: 32-bit CRC; one retransmission per error. Therefore, we send 923 data bits as 955 bits. 100 923 Transmission Overhead = ~= 10% Transmission Overhead = ~= 3% (923 + 32) 10-5 + 32 923 Lect-11-1: Error Control Computer Networks