380 likes | 441 Views
Part III. Data Link Layer. Chapter 10. Error Detection. COMP 3270 Computer Networks Computing Science Thompson Rivers University. Learning Objectives. Describe the general idea of error detection, using redundancy Determine parity bit with a given data word.
E N D
Part III. Data Link Layer Chapter 10. Error Detection COMP 3270 Computer Networks Computing Science Thompson Rivers University
Learning Objectives • Describe the general idea of error detection, using redundancy • Determine parity bit with a given data word. • Determine CRC redundancy with a given data word and divisor. • Determine checksum with a given data word.
Position of the data-link layer ☺ Main responsibility/role: ? [Reliable] node-to-node delivery of packets called frames
Data link layer duties Framing Physical address or MAC address Slow receiver Shared medium Error detection and retransmission • Error control is used in the network layer and the transport layer as well. • Flow control is used in the transport layer as well.
LLC and MAC sublayers Hardware independent Not standardized in the Internet society Then where? Hardware dependent
IEEE standards for LANs Connectionless service: - No flow and error control, or - Just acknowledgement Connection-oriented service: - ARQ for flow and error controls Ethernet 802.11: 2.4GHz; 2Mbps 802.11a: 5GHz; 54 Mbps 802.11b: 2.4GHz; 11Mbps; Wi-Fi 802.11g: 2.4GHz; 54Mbps
Data can be corrupted during transmission due to attenuation, distortion and noise. Some applications require that errors be detected and retransmitted.
Chapter Outline • Introduction • Parity check • Cyclic codes • Checksum
1. INTRODUCTION Let us first discuss some issues related, directly or indirectly, to error detection. Topics discussed in this section: • Redundancy • Detection
Redundancy To detect or correct errors, we need to send extra (redundant) bits with data. ☺ What does this mean? ☺ What is the basic idea to detect errors?
Basic Idea of Error Detection Algorithm Same algorithm
Error Detection Methods Internet protocols software Serial line Ethernet, hardware
Parity Check To make the number of bit 1s even
In parity check, a parity bit is added to every data unit so that the total number of 1s is even (or odd for odd-parity).
Example: Suppose the sender wants to send the word world. In ASCII the five characters are coded as 1110111 1101111 1110010 1101100 1100100 When even parity check is used, the actual bits sent: 1110111? 1101111? 11100100 1101100? 1100100? When odd parity check is used, the actual bits sent: 1110111? 1101111? 11100101 1101100? 1100100?
Example: Assuming even parity check, now suppose the word world in the previous Example is received by the receiver without being corrupted in transmission. 11101110 11011110 11100100 11011000 11001001 The receiver counts the 1s in each character and comes up with even numbers (6, 6, 4, 4, 4). The data are accepted.
Example: Assuming even parity check, now suppose the word world in the previous Example is corrupted during transmission. 11111110 11011110 11101100 11011000 11001001 The receiver counts the 1s in each character and comes up with even and odd numbers (7, 6, 5, 4, 4). The receiver knows that the data are corrupted. How to correct? Then, the receiver discards them, and asks for retransmission somehow.
Simple parity check can detect all single-bit errors. It can detect burst errors only if the total number of errors in each data unit is odd. Simple, but not powerful algorithm
Cyclic Redundancy Check CRC encoder and decoder With a leading bit 1
Division in CRC encoder XOR X xor 1...1 ??? X xor 0...0 ??? X or 1...1 ??? X or 0...0 ??? X and 1...1 ??? X and 0...0 ???
Example: Suppose the following dataword is sent: 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 1 Find the CRC redundancy when the divisor 1 0 1 1 is used. 1011 | 1010100100111001000 1011 1100
Standard polynomials Divisors 1 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1
5. CHECKSUM The last error detection method we discuss here is called the checksum. The checksum is used in the Internet by several protocols (IP, UDP, TCP) although not at the data link layer. However, we briefly discuss it here to complete our discussion on error checking. Topics discussed in this section: • Idea • One’s Complement • Internet Checksum
Idea • Suppose our data is a list of five 4-bit numbers that we want to send to a destination. • In addition to sending these numbers, we send the sum of the numbers. • For example, if the set of numbers is (7, 11, 12, 0, 6), we send (7, 11, 12, 0, 6, 36), where 36 is the sum of the original numbers. • The receiver adds the five numbers and compares the result with the sum. • If the two are the same, the receiver assumes no error, accepts the five numbers, and discards the sum. Otherwise, there is an error somewhere and the data are not accepted.
We can make the job of the receiver a bit easier if we send the negative (complement) of the sum, called the checksum. • In this case, we send (7, 11, 12, 0, 6, −36). • The receiver can add all the numbers received (including the checksum). • If the result is 0, it assumes no error; otherwise, there is an error.
One’s Complement 1 1 0 1
Internet Checksum Sender site: The message is divided into 16-bit words. The value of the checksum word is set to 0. All words including the checksum are added using one’s complement addition. The sum becomes the checksum. The checksum is sent with the data.
Receiver site: The message (including checksum) is divided into 16-bit words. All words are added using one’s complement addition. The sum is complemented and becomes the new checksum. If the value of checksum is 0, the message is accepted; otherwise, it is rejected.
Example: Suppose the following block of 16 bits is to be sent using a checksum of 8 bits. 10101001 10111001 The codeword is:
Example: Now suppose the receiver receives the pattern sent in the previous example and there is no error. 10101001 10111001 10011100 When the receiver adds the three sections, it will get all 1s, which, after complementing, is all 0s and shows that there is no error. 10101001 10111001 10011100 Sum 11111111 Complement 00000000means that the pattern is OK.
Example: Now suppose there is a burst error of length 5 that affects 3 bits. 10101001 10111001 10011100 10101111 11111001 10011100 When the receiver adds the three sections, it gets 10101111 11111001 10011100 Sum 01000100 Complement 10111011the pattern is corrupted.
Example:some very useful bit operations • How to check if the 18th bit from the right is 1 or 0? • How to make a 16 bit integer from two bytes? • How to store a 16 bit integer into two bytes? • How to reset the right 14 bits from a 32 bit integer? • How to obtain the 24th, 23rd, 22nd, and 21st bits?
C code – 16 bit checksum: Can you complete it? (Play the slide to see the code!) int checksum = 0; unsigned char data[MAX]; // even number of bytes unsigned short delta; // 16 bits int i; ... // checksum for (i = 0; i < MAX/2; i++) { delta = (data[2*i] << 8) + data[2*i + 1]; checksum += delta; if (checksum & 0x10000) { // if there is a carry checksum &= 0xffff; // reset the carry checksum++; // add 1 } } checksum = ~checksum; // 1’s complement ... // store the checksum into a packet packet[i] = (unsigned char)((checksum >> 8) & 0xff); packet[i+1] = (unsigned char)(checksum & 0xff); ...