CSC 335 Data Communications and Networking I

advertisement
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.
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.
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.
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.
Data Frame
Advantages: 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?
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.
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.
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.
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
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.
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.
Any Problem?
• Parity checking will detect any single-bit
error.
• Is there any glitch?
• Yes.
• What?
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!!
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.
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)
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.
Data Frame with Parity Bits
• 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.
• 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?
• 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.
• 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.
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.
Bit String Representation
The bit string 10010101110 is interpreted as
x x x x x x .
10
7
5
3
2
1
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).
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.
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
Modulo 2 Subtraction
•
•
•
•
0–0=0
0 – 1 = 1 (with no carry) (why?)
1–0=1
1–1=0
Exclusive OR
and
Modulo 2 Addition and Subtraction
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.
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)
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.
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
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
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.
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
An Example
Data to send : m1 m2 m3 m4 m5 m6 m7 m8
Hamming Code
p 1 p 2 m1 p 3 m2 m3 m4 p 4 m5 m6 m 7 m8
P1 : even parity for positions 1,3,5,7,9,11
P2 : even parity for positions 2,3,6,7,10,11
P3 : even parity for positions 4,5,6,7,12
P4 : even parity for positions 8,9,10,11,12
Position of Extra Bits
•
•
•
•
•
20 = 1
21 = 2
22 = 4
23 = 8
24 =16
the 1st position
the 2nd position
the 4th position
the 8th position
the 16th position
Error Detection vs. Error Correction
• Which one is better?
• A: Neither.
• Error correction requires more overhead –
time and extra bits
• Error detection requires retransmission.
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
Data Security
•
•
•
•
Encryption and Decryption
Key Distribution and Protection
Public Key Encryption
Viruses, Worms, and Hackers
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
Key Distribution and Protection
• Merkler’s Puzzles
• Shamir’s Method
Public Key Encryption
• RSA Algorithm
• Digital Signatures
• Authentication Using Hash-Bashed
Schemes
Viruses, Worms, and Hackers
•
•
•
•
•
•
Infecting Files
Memory-Resident Viruses
Virus Evolution
Virus Sources
The Internet Worm
Computer Hackers
Assignments
• Read Section 4.1 - Section 4.4.
• Homework:
Download