csc 335 data communications and networking lecture 5: error detection, error correction, and data...

59
CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Upload: derek-spencer

Post on 12-Jan-2016

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

CSC 335 Data Communications

and Networking

Lecture 5: Error Detection, Error Correction, and Data Security

Dr. Cheer-Sun Yang

Page 2: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Motivation

• Error can occur during transmission.• Signal can be distorted and cause sampling errors.• Sender sends a 1101, receiver can receive 1001.• How can a receiver be aware of that an error has

occurred? • Can the position of a single bit error be identified?• The techniques are called error detection and

single bit error correction.

Page 3: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Transmission Errors

• External electromagnetic signals - noise

• Transmission errors - attenuation

• Lost data – timing

But, before we talk about errors, we have to understand how messages are actually organized and sent.

Page 4: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Protocol Data Unit

• Messages are transmitted in a unit called protocol data unit (PDU).

• The data unit at data link layer is called a frame which is a block of data bits enclosing in a beginning and ending character. The beginning character is called the start of header (SOH) and the ending character is called the end of transmission (EOT) in our textbook.

Page 5: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Data Frame

In fact, the header contains a FLAG, the address, and some control information. There are also several kinds of frames: information, supervisory, and others. Each information frame is also identified by a sequence number.

Page 6: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Data FrameAdvantages: If error occurs at the sender side, the receiver will never receive the ending character. When the sender sends the header again, the receiver can synchronize easily.Disadvantages:

• overhead• what if the data portion includes a character identical to either the header or the ending character?

Page 7: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Bit Stuffing and Byte Stuffing

• Ideally, the frame header or the ending character won’t occur in the data block.

• But, it could happen.

• Bit-oriented protocol uses bit stuffing to solve the problem.

Page 8: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Bit Stuffing

• Header = 01111110

• In any data character, if there are 6 continuous 1 bits, the transmitter inserts an extra 1 bit after the fifth 1 bit; the receiver will reverse the procedure.

Page 9: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Byte Stuffing

• If any data block contains a SOH, EOT, or ESC (escape), the transmitter also does the following:– SOH in data becomes ESC + X.– EOT in data becomes ESC + Y.– ESC in data becomes ESC + Z.

Page 10: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 11: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Error Detection

• The ability to detect when a transmission error has occurred is called error detection.

• Additional bits should be added by the transmitter for detecting errors at the receiving side.

• Parity Bit– Value of parity bit is such that character has

even (even parity) or odd (odd parity) number of ones

– Disadvantage: Even number of bit errors goes undetected

Page 12: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Parity Checking Analysis

• Single bit error can be detected by a single parity bit.

• For example, the original data bits include 11010100, the parity (even) bit is then 0.

• The data bits and the parity bit will be sent together as a unit to the receiver.

• If there is an error at the second bit, the receiver receives 100101000. The total number of 1’s is not an even number. The receiver can claim that the message is incorrect.

Page 13: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Parity Checking (cont’d)

• Single bit error can be detected by a single parity bit.

• However, if two bits are transmitted incorrectly, the parity checking may not detect them.

• For example, data=1101, parity bit = 1;

• If incorrect data= 1011, parity bit = 1; the receiver cannot tell that this message is incorrect.

Page 14: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 15: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Any Problem?

• Parity checking will detect any single-bit error.

• Is there any glitch?

• Yes.

• What?

Page 16: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Single-Bit Error• Suppose an error occurred because of a

brief power surge or static electricity whose duration is a hundredth of a second. If the data rate is 64 Kbps, approximately 640 bits will be affected.

• When many bits are damaged, we call this a burst error.

• Single-bit parity checking is very likely to fail!!

Page 17: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Single-Bit Error (cont’d)• In general, if an odd number of bits change, parity

checking will detect the error.• If an even number of bits change, parity checking

will not detect the error.• The error detection rate is 50% which is not

acceptable for a communications network.• Does this mean that parity checking is useless? –

Well, No!• It is the basis of more complex techniques. It is

also useful when single-bit error could happen.

Page 18: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Double-Bit Error Detection

• How about using two parity bits – one checks for the bits in odd positions and another checks for bits in even positions?

• It is better but still not good enough – Why?

• A:_____________________________. (Exercise)

Page 19: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 20: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Burst Error Detection

• Perhaps we should take a look at how data bits are actually transmitted.

• A block of data bits are transmitted in a unit called frame. We will talk about the concept of data frame more in next lecture.

• Let’s assume that a frame looks like this for now.

Page 21: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Data Frame with Parity Bits

Page 22: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

• Rather than sending all bits from one frame together, we send them separately. Transmitting just one bit of information is not very efficient, however.

• If there are more frames to be sent together, we can send one bit from each frame together with the parity bit of the new data frames. Fig 4.3 illustrates this principle.

Page 23: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 24: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

• Instead of sending 10 5-bit frames with a parity bit, we send each column (6 10-bit frames).

• Now, suppose a burst error occurs and interferes with one transmission. At most, one bit from each original data frame is actually changed, and the parity check will detect them.

• How successful is this approach?

Page 25: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

• The only way a burst error affecting two columns can go undetected is when either two bits or no bits are actually changed in each (old) frame.

• What is the probability that this error can occur and will not be detected?

• Suppose column i and j were affected. Suppose that the bits from column i are affected randomly. Now consider any bit from column j, it is either correct or it is incorrect. Therefore there is a ½ chance that an error occurs to two bits in the same row.

Page 26: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

• If there are n bits in a column, there is a probability of (1/2)n that either two or no bits are changed in each row and the error goes undetected. If n=20, the probability that the error will not be detected = 1/1048576.

Page 27: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Cyclic Redundancy Check

• A major disadvantage of previous method is the cost of assembling and reassembling of the frames. Also, the error can only be detected after all frames are received. Then resending all frames is very costly.

• Is there a way to send a frame and determine immediately whether there was an error?

• Yes. CRC is more efficient although more difficult to understand.

Page 28: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Bit String Representation

.1235710 xxxxxx The bit string 10010101110 is interpreted as

Page 29: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 30: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

CRC Method

We assume all computations are done using modulo 2.

1. Given a bit string, append several 0s to the end of it (we will specify how many and why later) and call it B. Let B(x) be the polynomial corresponding to B.

2. Divide B(x) by some agreed-on polynomial G(x) (generator polynomial) and determine the remainder R(x).

Page 31: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

CRC Method (cont’d)3. Define T(x) = B(x) – R(x). Later we will show that

T(x)/G(x) generates a 0 remainder and that the subtraction can be done by replacing the previously appended 0 bits with the bit string corresponding to R(x).

4. Transmit T, the bit string corresponding to T(x).5. Let T’ represent the bit stream that receiver receives

and T’(x) the associated polynomial. The receiver divides T’(x) by G(x). If there is a 0 remainder the receiver concludes T=T’ and no error occurred. Otherwise, the receiver concludes an error occurred.

Page 32: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Modulo 2 Addition

• 0 + 0 = 0

• 0 + 1 = 1

• 1 + 0 = 1

• 1 + 1 = 0 (with no carry)

• “Modulo 2” means “to take the remainder after dividing by 2.”

• 2 mod 2 = 0

Page 33: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Modulo 2 Subtraction

• 0 – 0 = 0

• 0 – 1 = 1 (with no carry) (why?)

• 1 – 0 = 1

• 1 – 1 = 0

Page 34: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Exclusive OR andModulo 2 Addition and Subtraction

Page 35: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 36: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 37: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

How CRC works?

Suppose that we need to send the bit string 1101011, and the generator polynomial is G(x) = x4+x3 +1.

Step 1: Append 0’s to the end of the string. The number of 0’s is the same as the degree of the the generator polynomial. Thus the string is (B=) 11010110000.

Page 38: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

How CRC works? (cont’d)Step 2: Divide B(x) by G(x). Find the corresponding bit representation of the remainder polynomial R(x). In our case 1010.Step 3: Find T(x) = B(x) – R(x). (Remember using modulo 2 subtraction). Transmit the string T.

11010110000 = B – 1010 = R-------------------------------- 11010111010 = T (FACT)

Page 39: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

How CRC works? (cont’d)Step 4: At the receiving side, receiver divides the string (received) by G(x). If the remainder is not 0, the string is incorrect.

Page 40: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 41: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 42: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 43: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Summary of Cyclic Redundancy Check

• For a block of k bits transmitter generates n bit sequence

• Transmit k+n bits which is exactly divisible by some number

• Receive divides frame by that number– If no remainder, assume no error– For math, see Section 4.3

Page 44: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Hamming Code

Retransmission takes time and is costly if retransmission also fails.

• Due to R. W. Hamming

• Single-bit error correction : identifies the position of the error bit

• Multiple-bit error detection : only detects that multiple-bit error has occurred

Page 45: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

General Concept

• Insert some parity checking bit at in the bit string instead of at the end.

• The parity bits check the parity in some specific location

• If there is a single-bit error, the location can be identified by the combination of these parity bits.

Page 46: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

A Guessing Game• You can think of one number from 1 to 15 (Don’t

tell me what it is.)• Is the number in one of the following? 1, 3, 5, 7, 9, 11, 13, 15• Is the number in one of the following? 2, 3, 6, 7, 10, 11, 14, 15• Is the number in one of the following? 4, 5, 6, 7, 12, 13, 14, 15• Is the number in one of the following? 8, 9, 10, 11, 12, 13, 14,15

Page 47: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

An Example

Data to send : m1 m2 m3 m4 m5 m6 m7 m8

Hamming Code

p1 p2 m1 p3 m2 m3 m4 p4 m5 m6 m7 m8

P1 : even parity for positions 1,3,5,7,9,11P2 : even parity for positions 2,3,6,7,10,11P3 : even parity for positions 4,5,6,7,12P4 : even parity for positions 8,9,10,11,12

Page 48: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Position of Extra Bits

• 20 = 1 the 1st position

• 21 = 2 the 2nd position

• 22 = 4 the 4th position

• 23 = 8 the 8th position

• 24 =16 the 16th position

Page 49: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 50: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 51: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang
Page 52: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Error Detection vs. Error Correction

• Which one is better?

• A: Neither.

• Error correction requires more overhead – time and extra bits

• Error detection requires retransmission.

Page 53: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Error Control (next lecture)

• Detection and correction of errors• Lost frames• Damaged frames• Automatic repeat request

– Error detection– Positive acknowledgment– Retransmission after timeout– Negative acknowledgement and retransmission

Page 54: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Data Security

• Encryption and Decryption

• Key Distribution and Protection

• Public Key Encryption

• Viruses, Worms, and Hackers

Page 55: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Encryption and Decryption

The idea is to disguise information so that even if it does fall into the wrong hands, it cannot be understood.

• Caesar Cipher• Poly-alphabetic Cipher• Transposition Cipher• Bit-Level Ciphering• Data Encryption Standard• Clipper Chip

Page 56: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Key Distribution and Protection

• Merkler’s Puzzles

• Shamir’s Method

Page 57: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Public Key Encryption

• RSA Algorithm

• Digital Signatures

• Authentication Using Hash-Bashed Schemes

Page 58: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Viruses, Worms, and Hackers

• Infecting Files

• Memory-Resident Viruses

• Virus Evolution

• Virus Sources

• The Internet Worm

• Computer Hackers

Page 59: CSC 335 Data Communications and Networking Lecture 5: Error Detection, Error Correction, and Data Security Dr. Cheer-Sun Yang

Assignments

• Read Section 4.1 - Section 4.4.

• Homework: