CSCS 311 Data Communications and Networking Lecture 19

  • Slides: 57
Download presentation
CSCS 311 Data Communications and Networking Lecture 19 Lecture Focus: Data Link Layer Error

CSCS 311 Data Communications and Networking Lecture 19 Lecture Focus: Data Link Layer Error Control

Error Control

Error Control

Error Control Error Detection and Correction Data can be corrupted during transmission. Many factors

Error Control Error Detection and Correction Data can be corrupted during transmission. Many factors can alter one or more bits of a message. For reliable communication, errors must be detected and corrected. Some applications can tolerate a small level of error. e. g. errors in audio or video transmissions may be tolerable. When we transfer text, we expect a very high level of accuracy.

Error Control Types of Errors Single-Bit Error Burst Error

Error Control Types of Errors Single-Bit Error Burst Error

Error Control Types of Errors Single-Bit Error Only one bit in the given data

Error Control Types of Errors Single-Bit Error Only one bit in the given data unit is changed. A 0 is changed to a 1 OR a 1 to a 0. Transmitter 0 1 1 0 Receiver Medium Data unit = A byte, character, or packet 1 0

Error Control Types of Errors Single-Bit Error Single-bit errors are the least likely type

Error Control Types of Errors Single-Bit Error Single-bit errors are the least likely type of error in serial data transmission.

Types of Errors Burst Error When 2 or more bits in the data unit

Types of Errors Burst Error When 2 or more bits in the data unit are changed. A burst error does not necessarily mean that the errors occur in consecutive bits. Length of the burst is measured from the first corrupted bit to the last corrupted bit. Some bits in between may not have been corrupted. A burst error is more likely to occur than a single-bit error. Data unit = A byte, character, or packet

Error Detection: We look only to see if any error has occurred. Redundancy Parity

Error Detection: We look only to see if any error has occurred. Redundancy Parity Check Cyclic Redundancy Check (CRC) Checksum

Error Detection and Correction Redundancy = Adding extra bits The central concept in detecting

Error Detection and Correction Redundancy = Adding extra bits The central concept in detecting or correcting errors is redundancy. To be able to detect or correct errors, we need to send some extra bits with our data. These redundant bits are added by the sender with the original data. Their presence allows the receiver to detect or correct corrupted bits. The receiver uses these bits to detect the error(s). If the received message is error free, these redundant bits are removed and the remaining data is accepted. If the received message is not error free, the whole message is discarded by the receiver.

Error Detection and Correction Redundancy

Error Detection and Correction Redundancy

Error Detection and Correction Coding Redundancy is achieved through various coding schemes. The sender

Error Detection and Correction Coding Redundancy is achieved through various coding schemes. The sender adds redundant bits through a process that creates a relationship between the redundant bits and the actual data bits. The receiver checks the relationships between the two sets of bits to detect or correct the errors. The ratio of redundant bits to the data bits and the robustness of the process are important factors in any coding scheme. We can divide coding schemes into two broad categories: Block coding Convolution coding (Not to be studied)

Error Detection and Correction Coding Structure of Encoder and Decoder Encoder Decoder Message Accept,

Error Detection and Correction Coding Structure of Encoder and Decoder Encoder Decoder Message Accept, Correct or Discard Generator Message and redundancy Sender Checker Unreliable Transmission Received data Receiver

Error Detection and Correction Coding Block Coding We divide our message into blocks, each

Error Detection and Correction Coding Block Coding We divide our message into blocks, each of k bits, called datawords. We add r redundant bits to each block to make the length n = k + r. The resulting n-bit blocks are called codewords. Dataword k bits + Redundant bits r bits Size = Codeword n bits n=k+r

Error Detection and Correction Coding Block Coding We have a set of datawords, each

Error Detection and Correction Coding Block Coding We have a set of datawords, each of size k, and a set of codewords, each of size of n. With k bits, we can create a combination of 2 k datawords. With n bits, we can create a combination of 2 n codewords. Since n > k, the number of possible codewords is larger than the number of possible datawords. The block coding process is one-to-one; the same dataword is always encoded as the same codeword. This means that we have 2 n - 2 k codewords that are not used. We call these codewords invalid or illegal.

Error Detection and Correction Coding Block Coding k bits . … k bits 2

Error Detection and Correction Coding Block Coding k bits . … k bits 2 k Datawords, each of k bits n bits . … n bits 2 n Codewords, each of n bits (only 2 k of these are valid) n bits

Error Detection and Correction Coding Block Coding Example: 4 B/5 B block coding: In

Error Detection and Correction Coding Block Coding Example: 4 B/5 B block coding: In this coding scheme, k =4 and n =5. We have: 2 k = 24 = 16 datawords 2 n = 25 = 32 codewords 16 out of 32 codewords are used for message transfer. The rest are either used for control purposes or unused.

Error Detection in Block Coding If the following two conditions are met, the receiver

Error Detection in Block Coding If the following two conditions are met, the receiver can detect a change in the original codeword: 1. The receiver has (or can find) a list of valid codewords. 2. The original codeword has changed to an invalid one.

Error Detection in Block Coding Process Encoder k bits Decoder Dataword k bits Extract

Error Detection in Block Coding Process Encoder k bits Decoder Dataword k bits Extract Generator n bits Codeword Sender Checker Unreliable Transmission Codeword Receiver Discard n bits

Error Detection in Block Coding Process The sender creates codewords out of datawords by

Error Detection in Block Coding Process The sender creates codewords out of datawords by using a generator that applies the rules and procedures of encoding. Each codeword sent to the receiver may change during transmission. If the received codeword is the same as one of the valid codewords, the word is accepted; the corresponding dataword is extracted for use. If the received codeword is not valid, it is discarded. If the codeword is corrupted during transmission but the received word still matches a valid codeword, the error remains undetected. This type of coding can detect only single errors. Two or more errors may remain undetected.

Error Detection in Block Coding Process Example: Assume that k =2 and n =3.

Error Detection in Block Coding Process Example: Assume that k =2 and n =3. Table below shows the list of datawords and codewords.

Error Detection in Block Coding Example: Assume the sender encodes the dataword 01 as

Error Detection in Block Coding Example: Assume the sender encodes the dataword 01 as 011 and sends it to the receiver. Consider the following cases: 1. The receiver receives 011. It is a valid codeword. The receiver extracts the dataword 01 from it. 2. The codeword is corrupted during transmission, and 111 is received (the leftmost bit is corrupted). This is not a valid codeword and is discarded. 3. The codeword is corrupted during transmission, and 000 is received (the right two bits are corrupted). This is a valid codeword. The receiver incorrectly extracts the dataword 00. Two corrupted bits have made the error undetectable.

Error Detection Methods

Error Detection Methods

Error Detection Methods Simple Parity-Check Code The most familiar error-detecting code. In this code,

Error Detection Methods Simple Parity-Check Code The most familiar error-detecting code. In this code, a k-bit dataword is changed to an n-bit codeword where n = k + 1. The extra bit, called the parity bit, is selected to make the total number of 1 s in the codeword even. Some implementations specify an odd number of 1 s. The code is a single-bit error-detecting code. It cannot correct any error. In parity check, a parity bit is added to every data unit so that the total number of 1 s is even (or odd for odd-parity).

Error Detection Methods Simple Parity-Check Code Possible structure of an encoder and a decoder

Error Detection Methods Simple Parity-Check Code Possible structure of an encoder and a decoder The encoder uses a generator that takes a copy of a 4 -bit dataword (a 0, a 1, a 2, and a 3) and generates a parity bit r 0. The dataword bits and the parity bit create the 5 -bit codeword. The parity bit that is added makes the number of 1 s in the codeword even. This is normally done by adding the 4 bits of the dataword (modulo-2); the result is the parity bit. If the number of 1 s is even, the result is 0; if the number of 1 s is odd, the result is 1. In both cases, the total number of 1 s in the codeword is even.

Error Detection Methods Simple Parity-Check Code: Encoder and Decoder Sender Receiver Encoder Dataword Decoder

Error Detection Methods Simple Parity-Check Code: Encoder and Decoder Sender Receiver Encoder Dataword Decoder Dataword a 3 a 2 a 1 a 0 Discard Accept Decision Logic Generator s 0 Syndrome Checker Parity bit a 3 a 2 a 1 a 0 r 0 Codeword Unreliable Transmission b 3 b 2 b 1 b 0 q 0 Codeword

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder The sender sends the

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder The sender sends the codeword which may be corrupted during transmission. The receiver receives a 5 -bit word. The checker at the receiver does the same thing as the generator in the sender with one exception: The addition is done over all 5 bits. The result, which is called the syndrome, is just 1 bit. The syndrome is 0 when the number of 1 s in the received codeword is even; otherwise, it is 1. The syndrome is passed to the decision logic analyzer. If the syndrome is 0, there is no error in the received codeword; the data portion of the received codeword is accepted as the dataword; if the syndrome is 1, the data portion of the received codeword is discarded. The dataword is not created.

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Suppose the

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Suppose the sender wants to send the word world. In ASCII the five characters are coded as w o r l 11101111 1110010 d 1101100100 11011000 11001001 The following shows the actual bits sent 1110 110111100100

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Example: Now

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Example: Now suppose the word world is received by the receiver without being corrupted in transmission. 1110 110111100100 11011000 11001001 The receiver counts the 1 s in each character and comes up with even numbers (6, 6, 4, 4, 4). The data are accepted.

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Example: Now

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Example: Now suppose the word world in Example 1 is corrupted during transmission. 11111110 110111101100 11011000 11001001 The receiver counts the 1 s in each character and comes up with even and odd numbers (7, 6, 5, 4, 4). The receiver knows that the data are corrupted, discards them, and asks for retransmission.

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept Simple parity

Error Detection Methods Simple Parity-Check Code: Encoder and a decoder Even-parity concept 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.

Error Detection Methods Two-Dimensional Parity-Check: In this method, the dataword is organized in a

Error Detection Methods Two-Dimensional Parity-Check: In this method, the dataword is organized in a table (rows and columns). For each row and each column, 1 parity-check bit is calculated. The whole table is then sent to the receiver, which finds the syndrome for each row and each column. The two-dimensional parity check can detect up to three errors that occur anywhere in the table. However, errors affecting 4 bits may not be detected. In two-dimensional parity check, a block of bits is divided into rows and redundant bits are added to the whole block.

Error Detection Methods Two-Dimensional Parity-Check:

Error Detection Methods Two-Dimensional Parity-Check:

Error Detection Methods Cyclic Redundancy Check (CRC): In the encoder, the dataword has k

Error Detection Methods Cyclic Redundancy Check (CRC): In the encoder, the dataword has k bits; the codeword has n bits. The size of the dataword is augmented by adding n – k (generally) 0 s to the right-hand side of the word. The n-bit result is fed into the generator. The generator uses a divisor of size n - k + I (generally ), predefined and agreed upon. The generator divides the augmented dataword by the divisor (modulo-2 division). The quotient of the division is discarded; the remainder (r 2 r 1 r 0) is appended to the dataword to create the codeword.

Error Detection Methods Cyclic Redundancy Check: The decoder receives the possibly corrupted codeword. A

Error Detection Methods Cyclic Redundancy Check: The decoder receives the possibly corrupted codeword. A copy of all n bits is fed to the checker which is a replica of the generator. The remainder produced by the checker is a syndrome of n - k bits, which is fed to the decision logic analyzer. The analyzer has a simple function. If the syndrome bits are all 0 s, the 4 leftmost bits of the codeword are accepted as the dataword (interpreted as no error); otherwise, the 4 bits are discarded (error).

Error Detection Methods Cyclic Redundancy Check: Sender Receiver Encoder Dataword Decoder Dataword a 3

Error Detection Methods Cyclic Redundancy Check: Sender Receiver Encoder Dataword Decoder Dataword a 3 a 2 a 1 a 0 Generator Remainder a 3 a 2 a 1 a 0 r 2 r 1 r 0 Codeword Syndrome Accept Discard 000 Decision Logic Transmission s 1 Checker Divisor d 3 d 2 d 1 d 0 Unreliable s 2 b 3 b 2 b 1 b 0 q 2 q 1 q 0 Codeword s 0

Error Detection Methods Cyclic Redundancy Check: CRC generator and checker

Error Detection Methods Cyclic Redundancy Check: CRC generator and checker

Error Detection Methods Cyclic Redundancy Check: CRC generator

Error Detection Methods Cyclic Redundancy Check: CRC generator

Error Detection Methods Cyclic Redundancy Check: CRC checker

Error Detection Methods Cyclic Redundancy Check: CRC checker

Error Detection Methods Polynomial: A better way to understand cyclic codes and how they

Error Detection Methods Polynomial: A better way to understand cyclic codes and how they can be analyzed is to represent them as polynomials. A pattern of 0 s and 1 s can be represented as a polynomial with coefficients of 0 and 1. The power of each term shows the position of the bit; the coefficient shows the value of the bit. Figure below shows a binary pattern and its polynomial representation. Figure also shows how the polynomial can be shortened by removing all terms with zero coefficients and replacing x 1 by x and x 0 by 1.

Error Detection Methods Polynomial: 1 0 0 1 1 1 x 6 0 x

Error Detection Methods Polynomial: 1 0 0 1 1 1 x 6 0 x 5 0 x 4 0 x 3 0 x 2 1 x 1 1 x 0 1 1 x 6 0 0 1 1 1 x 0 = x 6 + x + 1

Error Detection Methods Polynomial: 1 1 x 6 0 0 1 1 1 x

Error Detection Methods Polynomial: 1 1 x 6 0 0 1 1 1 x 0 = x 6 + x + 1 Figure shows one immediate benefit; a 7 -bit pattern can be replaced by three terms. The benefit is even more conspicuous when we have a polynomial such as x 23 + X 3 + 1. Here the bit pattern is 24 bits in length (three Is and twenty-one 0 s) while the polynomial is just three terms.

Error Detection Methods Polynomial: Degree of a Polynomial: The degree of a polynomial is

Error Detection Methods Polynomial: Degree of a Polynomial: The degree of a polynomial is the highest power in the polynomial. For example, the degree of the polynomial x 6 + x + 1 is 6. Note that the degree of a polynomial is 1 less that the number of bits in the pattern. The bit pattern in this case has 7 bits.

Error Detection Methods Polynomials Shifting: Shifting to the left means adding extra 0 s

Error Detection Methods Polynomials Shifting: Shifting to the left means adding extra 0 s as rightmost bits; shifting to the right means deleting some rightmost bits. Shifting to the left is accomplished by multiplying each term of the polynomial by xn, where n is the number of shifted bits; Shifting to the right is accomplished by dividing each term of the polynomial by xn. We do not have negative powers in the polynomial representation. Shifting left 3 bits: 10011 becomes 10011000 x 4 + x + 1 becomes x 7 + x 4 + x 3 Shifting right 3 bits: 10011 becomes 10 x 4 + x + 1 becomes x When we augment the dataword in the encoder, we actually shift the bits to the left.

Error Detection Methods Cyclic Code Encoder Using Polynomials Creation of a codeword from a

Error Detection Methods Cyclic Code Encoder Using Polynomials Creation of a codeword from a dataword: The dataword 1001 is represented as x 3 + 1. The divisor 1011 is represented as x 3 + x + 1. To find the augmented dataword, we left-shift the dataword 3 bits (multiplying by x 3). The result is x 6 + x 3 The divisor in a cyclic code is normally called the generator polynomial or simply the generator.

Error Detection Methods Cyclic Code Encoder and Decoder Using Polynomials Cyclic Code Analysis We

Error Detection Methods Cyclic Code Encoder and Decoder Using Polynomials Cyclic Code Analysis We can analyze a cyclic code to find its capabilities by using polynomials. We define the following, where f(x) is a polynomial with binary coefficients. Dataword: d(x) Codeword: c(x) Generator: g(x) Syndrome: s(x) Error: e(x) If s(x) is not zero, then one or more bits is corrupted. If s(x) is zero, either no bit is corrupted or the decoder failed to detect any errors. Algorithm: In a cyclic code, 1. If s(x) 0, one or more bits is corrupted. 2. If s(x) =0, either a. No bit is corrupted. or b. Some bits are corrupted, but the decoder failed to detect them.

Error Detection Methods Cyclic Code Using Polynomials

Error Detection Methods Cyclic Code Using Polynomials

Error Detection Methods Checksum The checksum is used in the Internet by several protocols.

Error Detection Methods Checksum The checksum is used in the Internet by several protocols. Like block and cyclic codes, the checksum is based on the concept of redundancy. 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.

Error Detection Methods Checksum We can make the job of the receiver easier if

Error Detection Methods Checksum We can make the job of the receiver easier if we send the negative (complement) of the sum, called the checksum. In this case, we send (7, 11, 12, 0, 6, -36). 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 The previous example has one major drawback. All of our data can be written as a 4 -bit word (they are less than 15) except for the checksum. One solution is to use one's complement arithmetic. In this arithmetic, we can represent unsigned numbers between 0 and 2 n - 1 using only n bits. If the number has more than n bits, the extra leftmost bits need to be added to the n rightmost bits (wrapping). In one's complement arithmetic, a negative number can be represented by inverting all bits (changing a 0 to a 1 and a 1 to a 0). This is the same as subtracting the number from 2 n - 1.

Error Detection Methods Checksum Example: How can we represent the number 21 in one's

Error Detection Methods Checksum Example: How can we represent the number 21 in one's complement arithmetic using only four bits? Solution: The number 21 in binary is 10101 (it needs five bits). We can wrap the leftmost bit and add it to the four rightmost bits. We have (0101 + 1) = 0110 or 6. Example: How can we represent the number -6 in one's complement arithmetic using only four bits? Solution: In one's complement arithmetic, the negative or complement of a number is found by inverting all bits. Positive 6 is 0110; negative 6 is 100 I. If we consider only unsigned numbers, this is 9. In other words, the complement of 6 is 9. Another way to find the complement of a number in one's complement arithmetic is to subtract the number from 2 n - I (16 - 1 in this case).

Error Detection Methods Checksum Example: Let us redo previous exercise (7, 11, 12, 0,

Error Detection Methods Checksum Example: Let us redo previous exercise (7, 11, 12, 0, 6) using one's complement arithmetic. Figure below shows the process at the sender and at the receiver. The sender initializes the checksum to 0 and adds all data items and the checksum (the checksum is considered as one data item). The result is 36. However, 36 can’t be expressed in 4 bits. The extra two bits are wrapped and added with the sum to create the wrapped sum value 6. The sum is then complemented, resulting in the checksum value 9 (15 6 = 9). The sender now sends six data items to the receiver including the checksum 9. (Continued)

Error Detection Methods Checksum Example: The receiver follows the same procedure as the sender.

Error Detection Methods Checksum Example: The receiver follows the same procedure as the sender. It adds all data items (including the checksum); the result is 45. The sum is wrapped and becomes 15. The wrapped sum is complemented and becomes 0. Since the value of the checksum is 0, this means that the data is not corrupted. The receiver drops the checksum and keeps the other data items. If the checksum is not zero, the entire packet is dropped.

Error Detection Checksum Error Detection Methods

Error Detection Checksum Error Detection Methods

Error Detection Methods Checksum The sender follows these steps: The unit is divided into

Error Detection Methods Checksum The sender follows these steps: The unit is divided into k sections, each of n bits. All sections are added using one’s complement to get the sum. The sum is complemented and becomes the checksum. The checksum is sent with the data. The receiver follows these steps: The unit is divided into k sections, each of n bits. All sections are added using one’s complement to get the sum. The sum is complemented. If the result is zero, the data are accepted: otherwise, rejected.

Error Detection Methods Checksum Suppose the following block of 16 bits is to be

Error Detection Methods Checksum Suppose the following block of 16 bits is to be sent using a checksum of 8 bits. 10101001 00111001 The numbers are added using one’s complement 10101001 00111001 --------Sum = 11100010 Checksum = 00011101 The pattern sent is 10101001 00111001 00011101

Error Detection Methods Checksum Now suppose the receiver receives the pattern sent and there

Error Detection Methods Checksum Now suppose the receiver receives the pattern sent and there is no error. 10101001 00111001 00011101 When the receiver adds the three sections, it will get all 1 s, which, after complementing, is all 0 s and shows that there is no error. 10101001 00111001 00011101 --------Sum = 1111 Complement = 0000 It means that the pattern is OK.

Error Detection Methods Checksum 10101001 00111001 00011101 Now suppose there is a burst error

Error Detection Methods Checksum 10101001 00111001 00011101 Now suppose there is a burst error of length 5 that affects 4 bits. 101011111001 00011101 When the receiver adds the three sections, it gets 101011111001 00011101 Partial Sum Carry Sum Complement 1 11000101 1 11000110 00111001 It means the pattern is corrupted.