130 likes | 297 Views
COM342 Networks and Data Communications. Lecture 4D: Further examples of Data encoding for error detection : CRC and Checksums. Ian McCrum Room 5B18 Web site: http://www.eej.ulst.ac.uk Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk. Cyclic Redundancy Codes (CRC).
E N D
COM342Networks and Data Communications Lecture 4D: Further examples of Data encoding for error detection : CRC and Checksums Ian McCrum Room 5B18 Web site: http://www.eej.ulst.ac.uk Tel: 90 366364 voice mail on 6th ring Email: IJ.McCrum@Ulster.ac.uk http://www.eej.ulst.ac.uk/~ian/modules/COM342
Cyclic Redundancy Codes (CRC) • The CRC technique is used to protect blocks of data called Frames. Using this technique, the transmitter appends an extra n- bit sequence to every frame called Frame Check Sequence (FCS). The FCS holds redundant information about the frame that helps the transmitter detect errors in the frame. The CRC is one of the most used techniques for error detection in data communications. The technique gained its popularity because it combines three advantages: • Extreme error detection capabilities. • Little overhead. • Ease of implementation. http://www.eej.ulst.ac.uk/~ian/modules/COM342
Basics • The basic idea of CRC algorithms is simply to treat the message as an enormous binary number, to divide it by another fixed binary number, and to make the remainder from this division the checksum. • Upon receipt of the message, the receiver can perform the same division and compare the remainder with the "checksum" (transmitted remainder). • There are a few additional points to bear in mind. The fixed binary number is defined in advance, although several versions exist. • The “division” is done in a simplified way, no carries are generated during the subtraction. • widely used in practice (ATM, HDLC) • ATM 5-byte header uses 8-bit CRC • IEEE GCRC-32 , 32-bit CRC for Ethernet, etc. • Although simple checksums are also used ,they are less efficient at detecting errors http://www.eej.ulst.ac.uk/~ian/modules/COM342
CRC in Practice • International standards (CCITT) are defined for CRC-8, CRC-12, CRC-16, and CRC-32 • CRC-8: ATM header error control • CRC-10: ATM AAL error detection (recommended) • CRC-12: IBM Bisync error control • CCITT-16: HDLC, XMODEM, V.41 • CCITT-32: IEEE 802, V.42, ATM AAL5 • Each standard CRC can detect: • ALL burst errors of < r+1 bits, and ALL odd number of bit errors • Bursts of > r+1 bits detected with P = 1 – 0.5r http://www.eej.ulst.ac.uk/~ian/modules/COM342
Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents sender puts checksum value into UDP checksum field Receiver: compute checksum of received segment check if computed checksum added to checksum field value gives zero NO - error detected YES - no error detected. But maybe errors nonetheless? Internet checksum (RFC1071) Goal: detect “errors” (e.g., flipped bits) in transmitted segment (note: in actual practice, used at transport layer only) http://www.eej.ulst.ac.uk/~ian/modules/COM342
Cyclic Redundancy Code (CRC) • CRCs treat a bit string as a polynomial code with coefficients of 0 and 1. A k-bit frame is regarded as the coefficient list for a polynomial of order k, ranging from xk-1 to x0, said to be of degree k-1. The leftmost bit is xk-1 the next is xk-2 • I.e 110001 has 6 bits and is said to be x5+x4+x0 or x5+x4+1 • This is only important because the divisor is specified in this way, in practice you convert it to a binary number and do calculation using binary… • Binary arithmetic is needed but the division process is simplified. Subtraction is done without carries or borrows and so is actually an XOR operation or just a matter of letting a bit through or inverting it…and when you do the subtraction itself is slightly different http://www.eej.ulst.ac.uk/~ian/modules/COM342
The polynomial code (optional) • The transmitter and receiver must agree the polynomial code of the generator, normally called G(x). • It will be a binary number that must begin and end with a ‘1’. It will have less bits than the data being protected • Basic idea is to add extra bits after the data so that the complete new frame is divisible exactly by G(x). The receiver does the division and if the remainder is zero then all is ok • We begin with data of m bits represented by M(x). Add r bits to this, initially zero in value, r is the degree of G(x) • Since the early bits are zero we have changed M(x) to xr M(x) • We divide xr M(x) by G(x) using module-2 division and http://www.eej.ulst.ac.uk/~ian/modules/COM342
This example from http://www.relisoft.com/Science/CrcNaive.html The CRC algorithm requires the division of the message polynomial by the key polynomial. The straightforward implementation follows the idea of long division, except that it's much simpler. The coefficients of our polynomials are ones and zeros. We start with the leftmost coefficient (leftmost bit of the message). If it's zero, we move to the next coefficient. If it's one, we subtract the divisor. Except that subtraction modulo 2 is equivalent to exclusive or, so it's very simple. Let's do a simple example, dividing a message 100110 by the key 101 also expressed as x2 + 1. Since the degree of the key is 2, we start by appending two zeros to our message. 1 0 1 ) 1 0 0 1 1 0 0 0 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 Remainder is 0 1 so transmit 1 0 0 1 1 0 0 1 http://www.eej.ulst.ac.uk/~ian/modules/COM342
Book Example fig 3-7/p189 1 1 0 0 0 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 1 Replace these 4 zeros with the remainder 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 G(x)=x4+x+1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 0 Remainder is 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 0 Transmit 11010110111110 1 1 1 0 http://www.eej.ulst.ac.uk/~ian/modules/COM342
G PDU r 0's 1 0 1 / 1 1 0 1 0 0 \ 1 1 1 0 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 0 R = 1 0 Cyclic Redundancy Code - Example Q T = 110110 http://www.eej.ulst.ac.uk/~ian/modules/COM342
Cyclic Redundancy Code - Generators • CRC Generators are subject of design and standardization. The goal here is to let them have strong properties like: • Detect all single and double errors • Detect all burst of 16 bits and less • Example generators are: • CRC-8: 100000111 • CRC-10: 11000110011 • CRC-12: 1100000000101 • CRC-16: 11000000000000101 • CRC-CCITT (ITU-T): 10001000000100001 • CRC-32: 100000100110000010001110110110111 We see why writing e.g CRC-CCITT as x16+x15+x2+1 is less error prone! http://www.eej.ulst.ac.uk/~ian/modules/COM342
Cyclic Redundancy Code - Advantages • The capabilities of e.g. CRC-16: • All single errors are detected • All double errors are detected • All burst errors of 16 errors in a row are detected • All errors with an odd number of bits • There are more… • Highly Efficient Codes • overhead of e.g. CRC-16 Code for a PDU of size 12000 (1500 bytes) as in Ethernet: 0.14 % http://www.eej.ulst.ac.uk/~ian/modules/COM342
Tutorials for Lecture 4D (CRC) [1] Write the bit pattern 10100001 and 1001 as polynomials [2] What is the result of dividing (modulo-2) the polynomial x7+x5+1 by the generator polynomial x3+1? [3] Using the CRC generator 1001 generate the data to be transmitted if a data block is 1111000. ( answer 1111000110) [4] What data is sent if a CRC of x4+x1+1 is used to protect a data block of 110101101? Answer (1101011011111) http://www.eej.ulst.ac.uk/~ian/modules/COM342