Unit-4 1. 2 Types of errors Compile-time errors Run-time errors.
05 directnets errors
Transcript of 05 directnets errors
1
Direct Link Networks:Error Detection
Sections 2.4
2
Outline
• Error Detection– Cyclic Redundancy Check (2.4.3)– Internet Checksum Algorithm (2.4.2)
• Reliable Transmission– Stop-and Wait (2.5.1)– Sliding Window Algorithm (2.5.2)– (will not cover implementation pp. (109-115)
3
Error Detection
• Errors are unavoidable– Electrical interference, thermal noise, etc.
• Techniques for detecting errors– Cyclic Redundancy Check (CRC)– Checksum– Parity checking ( Section 2.4.1: will not cover in class)
4
Cyclic Redundancy Check (CRC)
• Generation of CRC and using it to detect errors makes use of Polynomial Arithmetic Modulo 2
5
Polynomial Arithmetic
A polynomial is an expression of the form
anxn + an-1x
n-1 + ...... + a1x + a0x0
where the coefficients a0, a1, ...., an are drawn
from some designated set S. S is called the coefficient set.
When an an ≠ 0, we have a polynomial of degree
n. Polynomial arithmetic deals with the addition,
subtraction, multiplication, and division of polynomials.
6
Polynomial Arithmetic Modulo 2: Overview
• A special class of polynomial arithmetic• Coefficient set ={1, 0}• Operations on coefficients performed using
modulo 2 arithmetic• Key properties (accept on faith)
1. Any polynomial B(x) can be divided by a divisor polynomial C(x) if B(x) is of higher degree than C(x)
2. Any polynomial B(x) can be divided once by a divisor polynomial C(x) if B(x) is of the same degree as C(x)
7
Polynomial Arithmetic Modulo 2,Properties (cont.)
3. The remainder obtained when B(x) is divided by C(x) is obtained by subtracting C(x) from B(x)
4. To subtract C(x) from B(x) perform XOR on each pair of matching coefficients
8
Polynomial Arithmetic Modulo 2,Example
B(x) = x3 + 1 can be divided by
C(x) = x3 + x2 + 1
because they are both of degree 3 remainder:
subtract C(x) from B(x) {XOR each pair of matching coefficients}
0 × x3 + 1 × x2 + 0 × x1 + 0 × x0 = x2
Phrased differently: 1001 can be divided by 1101 and leaves a remainder of 0100
9
Cyclic Redundancy Check
• Add k redundant bits to an n-bit message– want k << n– e.g. on an Ethernet a CRC-32 code is used
• k = 32 and n = 12,000 (1500 bytes); ( .27% overhead )
• Represent n-bit message as n-1 degree polynomial– e.g., 8-bit message, MSG=1001 1010 as M(x) = x7 +
x4 + x3 + x1
• Using polynomial arithmetic modulo 2, let k be the degree of some divisor polynomial– e.g., C(x) = x3 + x2 + 1; i.e. 1101
10
CRC (cont)
• Transmit polynomial P(x) that is evenly divisible by C(x) – Shift left message k bits, i.e., T(x) = M(x)xk {T(x) is called the zero
extended message}– Divide T(x) by C(x) and find remainder– Subtract remainder from T(x) P(x)
• P(x) is divisible exactly by C(x)• P(x) is M(x) followed by remainder
• Think of the received polynomial as P(x) + E(x)– E(x) = 0 implies no errors– Divide (received polynomial, P(x) + E(x)) by C(x);
remainder zero if:• E(x) was zero (no error), or• E(x) is exactly divisible by C(x)
• Pick C(x) so that this is very unlikely for common types of errors
??
11
Figure 2.20 CRC calculation using polynomial long division
• MSG= 1001 1010 ; M(x) = x7 + x4 + x3 + x1• C(x) = x3 + x2 + 1; 1101• k = the degree of the divisor , C(X) = 3• T(x) = 1001 1010 000
• CRC = Remainder = 101
• Transmit P(x) = 1001 1010 101
Zero ExtendedGenerator 1101
1111100110011010000 Message1101
10011101
10001101
10111101
11001101
10001101101 Remainder
12
CRC – Example Decoding – No Errors
1001
1101
1000
1101
1011
1101
1100
1101
1101
1101
1101
k + 1 bit check sequence c,
equivalent to a degree-k
polynomial
0
1101Remainder
m mod c
10011010101 Received message, no
errors
Result:
CRC test is passed
MSG = 1001 1010C(x) = x3 x2 1 = 1101 Generator P(x) = x10 x7 x6 x4 x2 1 = 10011010101 Received Message
13
CRC – Example Decoding – with Errors
1000
1101
1011
1101
1101
1101
1101
k + 1 bit check sequence c,
equivalent to a degree-k
polynomial
0101
1101
Remainder
m mod c
10010110101 Received message
Result:
CRC test failed
Two bit errors
MSG = 1001 1010C(x) = x3 x2 1 = 1101 Generator P(x) = x10 x7 x5 x4 x2 1 = 10010110101 Received Message
14
Selecting C(x)
Sender and receiver agree on a divisor polynomial, C(x)• In practice, look C(x) up in a book
• Choice of C(x) has a significant impact on what types of errors can be detected
• A handful of divisor polynomials are very good choices for various environments
• Exact choice: part of the protocol design
• Ethernet standard uses a well-known polynomial of degree 32
15
Common Polynomials for C(x)
CRC C(x)
CRC-8 x8 x2 x1 1
CRC-10 x10 x9 x5 x4 x1 1
CRC-12 x12 x11 x3 x2 x1 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 x1 1
16
Selecting C(x) (cont.)
• The following types of errors can be detected by a C(x) with the stated properties:– All single-bit errors, as long as the xk and x0 terms have
non-zero coefficients {proof p. 99).– All double-bit errors, as long as C(x) contains a factor with
at least three terms– Any odd number of errors, as long as C(x) contains the
factor (x + 1)– Any ‘burst’ error (i.e., sequence of consecutive error bits)
for which the length of the burst is less than k bits.– Most burst errors of larger than k bits can also be
detected
17
Figure 2.21 CRC algorithm implemented in hardware using a 3-bit shift register and XOR gates (This figure is for for the generator x3 + x2 + x0 )
x0 x1XOR gate x2
MessageZero Extended
•# bits = k = 3
•bits in register labeled 0 through k-1, left to right
•XOR in front of bit n if there is a term xn in the generator polynomial
•zero extended message shifted in from the left, beginning with most significant bit
•register will contain the CRC ( most significant bit on the right)
18
Internet Checksum Algorithm(used in IP, UDP and TCP)
• View message as a sequence of 16-bit integers (words)
• Compute a sum of all the 16-bit words, with no carries, produce the sum
• Transmit the data & the sum (checksum)• Receiver performs calculation on received data• Compares result with received checksum• If transmitted data (or transmitted checksum) is
corrupted– result of receiver calculation will not match received
checksum • error
19
Internet Checksum Example
• Internet Checksum– Use 1’s complement addition on 16bit codewords– Example
• Codewords: -5 -3• 1’s complement binary: 1010 1100• 1’s complement sum 1000
• Comments– Small number of redundant bits– Easy to implement– Not very robust
20
Internet Checksum Algorithm
• produce the sum using 16-bit ones-complement arithmetic; take ones-complement of the result to get the checksum.
u_shortcksum(u_short *buf, int count){ register u_long sum = 0; while (count--) { sum += *buf++; if (sum & 0xFFFF0000) { /* carry occurred, so wrap around */ sum &= 0xFFFF; sum++; } } return ~(sum & 0xFFFF);}
•routine assumes buf already padded with 0s to a 16-bit boundary
•count = the length of buf ( in 16-bit units )
21
Error Correction
• Some error codes can be used to detect and correct most errors– Overhead is too high
• Some errors can not be corrected
22
Error Detection vs. Error Correction• Detection
– Pro: Overhead (i.e. retransmission) only on messages with errors
– Con: Cost in bandwidth and latency for retransmissions
• Correction– Pro: Quick recovery– Con: Overhead on all messages
• What should we use?– Correction if retransmission is too expensive– Correction if probability of errors is high