Sei sulla pagina 1di 48

Chapter 3

Data Link Layer &


Error Control Coding

DATA LINK CONTROL (DLC)


PACKET

DLC

FRAME

OBJECTIVE: PROVIDE AN
ERROR FREE BIT PIPE

PACKET

HEADER
SEQUENCE
NUMBERS
ECE/CSC 570, NC State University

TRAILER
CRC

DATA LINK CONTROL (2)


RELIABLE
BIT PIPE

DLC

DLC
UNRELIABLE
BIT PIPE

MAC

MAC

PHYSICAL

PHYSICAL
ECE/CSC 570, NC State University

Functions of the Data Link Layer


(DLL)
n

Provide service interface to the network


layer
Dealing with transmission errors
error-control coding & retransmission

Regulating data flow


slow receivers not swamped by fast senders
done by ARQ..

ECE/CSC 570, NC State University

Data Link Layer Design Issues


n

Service provided to the Network Layer

Framing

Error Control

Flow Control

ECE/CSC 570, NC State University

Packets vs. Frames


Relationship between packets and frames.

ECE/CSC 570, NC State University

Services Provided to Network Layer

(a) Virtual communication.


(b) Actual communication.
ECE/CSC 570, NC State University

Service types
n

Unacknowledged connectionless service

Acknowledged connectionless service

Acknowledged connection-oriented service

ECE/CSC 570, NC State University

Services
Regular bulk postal mail

Unacknowledged connectionless service

Source machine sends independent frames without having the


destination machine acknowledge them
No logical connection is established
If a frame is lost due to noise on the link, no detection or
recovery
Appropriate for reliable links and leave the recovery to higher
layers. (LANs)

Acknowledged connectionless service

certified postal mail


No logical connection is established
Each frame sent is individually acknowledged
Retransmit if time out
Useful for unreliable channels (wireless systems!)
Delay of a packet is long if many frames are retransmitted

ECE/CSC 570, NC State University

Services (2)
n

Acknowledged connection-oriented service


Connection is established before any data are transferred
Each frame is numbered and guaranteed to be received
Each frame is received only once and all frames are
received in the right order.
Provides the network layer processes with the equivalent of
a reliable bit stream

Reliable pipe !

ECE/CSC 570, NC State University

Framing
n

How to decide the successive frames start


and stop ?
Inserting time gaps between frames will not
work. Why?
Three types of framing used in practice
Character-based count
Flag bytes with byte stuffing
Starting and ending flags, with bit stuffing
ECE/CSC 570, NC State University

Framing: Character-based count


A header to specify the no. of characters in the frame

A character stream. (a) Without errors. (b) With one error.


Even the destination knows that the frame is bad, it still has no way of
telling where the next frame starts. Resending a frame back to the source
asking for retransmission does not help either. Rarely use any more
ECE/CSC 570, NC State University

Framing: Flag bytes with byte stuffing


Use flag bytes to
separate the frames
What if the data has the same
byte pattern as flag bytes?
Insert ESC as byte stuffing,
but limited to 8-bit characters.

(a) A frame delimited by flag bytes.


(b) Four examples of byte sequences before and after stuffing.
ECE/CSC 570, NC State University

Framing: Starting/ending flags with bit stuffing


a flag byte = 01111110

Delete 0 at the receiver

Bit stuffing
(a) The original data.
(b) The data as they appear on the line.

(c) The data as they are stored in receivers memory after de-stuffing.

Many DLL protocols use combined method!


ECE/CSC 570, NC State University

Error Control Coding

Error Detection and Correction


n

The primary function of the DLC (Data Link Control)


is to convert the unreliable bit pipe into a reliable
bit pipe.

This can be done by using FEC (Forward Error


Correction) or ARQ (Automatic Repeat reQuest)
for retransmission.

The FEC relies upon some form of Error Control


Coding and the ARQ relies on Error Control Coding
but also on the introduction of Sequence
Number(SN) and Request Numbers (RN).

ECE/CSC 570, NC State University

Error Detection and Correction


n

Error-Correcting Codes
Hamming Code

Error-Detecting Codes
Parity Check
Cyclic Redundancy Check (CRC)

ECE/CSC 570, NC State University

Properties
n

Errors on a link tend to be dependent and occur in


bursts

For any reasonable code, the frequency of


undetectable errors is very small and thus difficult
to measure and difficult to model analytically.

The minimum distance of the code

The burst detecting capability

The probability that a completely random string will


be accepted as error free

ECE/CSC 570, NC State University

Definitions
n

Codeword : n-bit unit (n = m + r ) containing m data and


r redundant, or check bits, is referred to as an n-bit
codeword

The minimum distance of the code : the smallest


number of errors that can convert one codeword into
another

The length of a burst of errors : the number of bits from


the first error to the last error (inclusive). The burst error
detecting capability of a code is defined as the largest
integer B such that a code can detect all bursts of
length B or less.
ECE/CSC 570, NC State University

Definitions (2)
n

Hamming Distance d: the number of bit positions


in which two codewords differ
Given any two codewords, exclusive OR (XOR)
10001001
10110001
00111000

0 for same values


1 for different values

It requires d single-bit errors to convert one


codeword to another.

ECE/CSC 570, NC State University

Binary Symmetric Channel

1 p e

pe
pe
1

1 p e
n

The probability that all k bits in a


message are received correctly is
equal to

(1 p e )

ECE/CSC 570, NC State University

Bit Error Rate


n

A simple error correction coding method is to send every


packet three times.

Three values are then received for each bit and the receiver
uses a majority vote on each bit.

Evaluate the effectiveness of this method assuming that all


the bits errors are independent.
The probability that a given bit is incorrectly received two or three
times is equal to

e = 3 Pe2 (1-Pe) + Pe3


Therefore, the probability that at least one of the N bits of the packet is
received incorrectly two or three times is equal to

PER (packet error rate) = 1 (1 e)N Ne 3N Pe2


ECE/CSC 570, NC State University

Packet Error Rate (Contd)


n

Compare the PER


For N = 105 and BER =Pe= 10-7, the PER of one time
transmission is 1- (1-BER)N N BER = 10-2.
The PER of three times transmission is
PER Ne 3N Pe2 = 3 10-9

Price?
The useful transmission rate has been reduce by a factor
of 3.

ECE/CSC 570, NC State University

Single Parity Coder


s1 s2
where
n

sk

CODER

s1 s2

sk c

c = s1 s 2 L s k , the modulo-2 sum

Parity check append a single bit to the data. If the number


of 1 bits in the codeword is even (or odd), a bit 0 (1) is
appended.
E.g., 1011010, a bit 0 will be added to the end and it makes
10110100
It can be used to detect single errors.
Minimum distance of the code ?
ECE/CSC 570, NC State University

Horizontal and Vertical Parity Checks


l

A two-dimensional array with one parity check


for each row and one for each column.
c1
s11 s12 s13 L s1k

s21 s 22
s
s 31
31

M
M

s n1 s n2
r1 r2

s 23 L s2k
s 33 L s3k
M
sn3

M
M
L snk

r3

rk

c2
c3

cn
c n +1

ci = si1 si 2 si 3 L sik
rj = s1 j s2 j s3 j L snj
ECE/CSC 570, NC State University

Horizontal and Vertical Parity Checks (2)


1001010
0111010
1110001
1000111
0011001
1011111

1
0
0
0
1
0

1001010
0111010
1110001
1000111
0011001
1011111

1
0
0
0
1
0

Horizontal checks

ci = s i1 s i 2 s i 3 L s ik
Vertical checks

rj = s1j s 2 j s3 j Lsnj
If the bit in each
circle is changed,
all parity checks
are still satisfied

Detects all single,


double and triple
errors and most
quadruple but not all!

ECE/CSC 570, NC State University

Observations
n

To detect d errors, we need a distance d+1 code so


that d single-bit errors cannot change a codeword to
another.

To correct d errors, we need a distance 2d+1 code so


that even d-bit errors, the original codeword is still
closer than any other codewords.
E.g., there are 4 valid codewords: 0000000000, 0000011111,
1111100000, 1111111111. This code has distance of 5 (2d +1= 5).
If a codeword 0000000111 arrives, the closest valid codeword is
0000011111 (2-bit error, d = 2). Then the receiver can determine the
original codeword. If there are 3-bit errors, this code is unable to
correct.

ECE/CSC 570, NC State University

Hamming Code (Error Correcting Code)


n

The bits of the codeword are numbered consecutively,


starting from bit 1 at the left end.

Original code
n

The bits that are powers of 2 (1,2,4,8) are check bits, so


the codeword becomes

Codeword
n
n

1234567
1001000

1 2 3 4 5 6 7 8 9 10 11
xx1x001x 0 0 0

The rest (3,5,6,7) are filled up with the m (=7) data bits
Any k that is not a power of 2 can be written as a sum of
powers of 2.
Data bit in k will contribute to some of the check bits.
E.g., k = 11 = 1+2+8, which means it contributes to the check bits 1, 2, 8.

ECE/CSC 570, NC State University

Hamming Code: Example


n

Consider a (7,4) code: 4 bits message+3 parity bits 7 bits


codeword
3 = 1+2 : 5 = 1+4 : 6 = 2+4 : 7 = 1+2+4

1 2 3 4 5 6 7
P P D P D D D 7-bit codeword

Check bit
contributed

P - D - D - D

(Even Parity)

- P D -

- D D

(Even Parity)

- P D D D

(Even Parity)

ECE/CSC 570, NC State University

Hamming Code: Example (contd)


n

Rule: Each circle must have EVEN parity.

Message 1011 would be sent as 0110011, since

1 2 3 4 5 6 7
7-bit codeword

Check bit
contributed

- 1

(Even Parity)

- 1 1

(Even Parity)

- 0 0 1 1

(Even Parity)

0 1 1 0 0 1 1
0 - 1 - 0
- 1 1 -

ECE/CSC 570, NC State University

Hamming Code: Example (contd)


n

Single bit error (bit) occurs: 0110011 0110111


1 2 3 4 5 6 7
0 1 1 0 1 1 1

7-bit codeword

Parity
computed

(Even Parity)

(NOT!) 1

1 1

1 1

(Even Parity)

(OK!) 0

0 1 1 1

(Even Parity)

(NOT!) 1

The bad parity bits labeled 101 point directly to the bad bit
(101 = 5 !)

ECE/CSC 570, NC State University

Hamming Code: Example (contd)


n
n

Correction of single bit errors


Detection of 2 bit errors (assuming no
correction is attempted)

Cost of 3 bits added to a 4-bit message.

In general, Hamming distance = 3


The minimum distance between any two valid
codewords is 3 allows error correction of one
bit and detection of 2 bits.

ECE/CSC 570, NC State University

Hamming Code (contd)


When a codeword arrives,
the receiver initializes a
counter to zero.
It then examines each
check bit, k, to see if it has
the correct parity.
If k = 0 after the whole
examination, the codeword
is accepted. Otherwise, it
contains the number of the
incorrect bit, (1+2+8 = 11)
Hamming codes can only
correct single errors.
To correct burst errors,
transmit one column at a
time.
Use of a Hamming code to correct burst errors.
ECE/CSC 570, NC State University

Cyclic Redundancy Check (CRC)


n

The basic idea is to start with a bit string and to generate


parity checks on various subsets of the bits.

The most common code is the polynomial code


Bit string is represented by a polynomial with coefficients of 0 and 1
only.
A k-bit frame is regarded as a polynomial with k terms, ranging from
xk-1 to x0 . It is called a polynomial of degree (k-1)
If the data bits are denoted as mK-1, mK-2, , m1,m0, the polynomial
M(x) representation of the string with coefficients is

M(x) = mK-1xK-1 + mK-2xk-2 + , +m1x + m0

ECE/CSC 570, NC State University

CRC (Contd)
n

Both the sender and receiver agree upon a generator


polynomial, G(x) of degree r.

G(x) = xr+gr-1xr-1++g1x+1
G(x) has at least two nonzero terms (i.e., xr and 1)

Rule of the game: r(x) = Remainder[M(x)xr /G(x)]


This is a ordinary long division of one polynomial by another, except
that the coefficients are restricted to be binary, and the arithmetic on
coefficients is performed modulo 2.

What is modulo 2 arithmetic?

The CRC polynomial T(x) = M(x)xr r(x) = M(x)xr+r(x)


The remainder is of degree at most r-1.

If there is no error, T(x) must be divisible (modulo) by


G(x)
ECE/CSC 570, NC State University

Example of Polynomial
x2+ x
x3 + x2 + 1 x5 + x3
5
4
x + x

x
Example: r=3 and k=3

G(x) = 1 + x + x
2

M(x) = 1 + x 2
( m2m1m0=101)

+ x

+ x + x
3

x + x + x
2
x + x
4

Code-polynomial
T(x) = x5 + x3 +x2 + x
ECE/CSC 570, NC State University

Remainder

Error-Detecting Codes
Calculation of
the polynomial
code checksum.
1.
2.
3.

Add (r=4) zero bits at the end of


frame polynomial
Divide by G(x)
Subtract (or add) the remainder
from the bit string
corresponding to xrM(x)

11010110110000
1110
11010110111110

ECE/CSC 570, NC State University

Error Detection with CRC


n

T(x) is divisible by G(x), so the remainder should be zero for correct


transmission.

10011

1100001010
11010110111110
10011
10011
10011
00001
00000
00010
00000
00101
00000
01011
00000
10111
10011
01001
00000
10011

Assume there is an error


occurs, so the received bit
string is T(x) + E(x) (in
module 2!!)

Each 1 bit in E(x)


corresponds to a bit that has
been inverted. If there are k
1 bits in E(x), k single-bit
errors have occurred.

ECE/CSC 570, NC State University

Error Detection with CRC (2)


T(x)

Channel

Y(x)=T(x)+E(x)

Y ( x)
T ( x) E ( x)
+
Re maider[
] = Re mainder[
]
G ( x)
G ( x ) G ( x)
E ( x)
= Re mainder[
]
G ( x)
n

If no errors occur, then E(x) = 0 remainder =0

E(x) 0 is undetectable if and only if


E(x) = G(x) z(x), where z(x) is nonzero
polynomial.
ECE/CSC 570, NC State University

Single Error
n

If there is a single error, then E(x)=xj for some j .


Since G(x) has at least two non- zero terms xr and 1,
it follows that G(x) z(x) must also have two non-zero
terms for any non-zero z(x) . Consequently G(x)z(x)
cannot equal E(x) .
This means that all single errors can be
detected.

ECE/CSC 570, NC State University

Double Errors
E ( x ) = x i + x j = x j ( x i j + 1)
n

where i > j

We know that xj is not divisible by G(x). So only if xi-j +1 is


divisible by G(x) will we fail to detect double errors. G(x) is
carefully chosen such that it does not divide xk+1 for any k
up to the maximum value of (i-j) (the max. frame length)
a primitive polynomial
Double errors can be detected.

E.g., x15+x14+1 will not divide xk+1 for any value of k below
32,768!
ECE/CSC 570, NC State University

CRC Properties
n

In most CRC implementations the G(x) used is of the form


G(x)=(x+1) { primitive polynomial of degree r-1 }.

A polynomial E(x) is divisible by x+1 if and only if E(x)


contains an even number of non-zero coefficients. If E(x) has
an odd number of terms, substituting 1 for x everywhere will
always yield 1 as the result. Thus, no polynomial with an odd
number of terms is divisible by x+1.

This nice property ensures that all odd number of errors


can be detected.

ECE/CSC 570, NC State University

CRC Properties (Contd)


n

The degrees of the highest and lowest order terms of


G(x) differ by r.

For G(x)z(x), it must be that the difference between


the highest and lowest degree is at least r. Thus if
E(x) is a error polynomial, then the burst length of
errors must be at least r+1. This means that all
bursts of length r can be detected because the
burst stream has 1 at the first and last bits.

ECE/CSC 570, NC State University

Standards
n

Standard CRC polynomials:


G(x) = x16+x15+x2+1
CRC-16
G(x) = x16+x12+x5+1
CRC-ITU-T
G(x)
=x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x1
+1
IEEE 802

ECE/CSC 570, NC State University

Block Codes
n

The previous discussion is about how to transform


a message of k bits into a codeword of n (n=k+r)
bits with n > k. Accordingly, there are 2k codewords
in a set of 2n binary words.

A good code is one where the codewords are as far


from each other as possible.

Easy to use: coding and decoding. These codes are


called block codes because they group the source
bits into blocks of k bits that they encode and
decode independently of one anotherone word at
a time.

Probability of failing to detect errors in random


string = 2-r
ECE/CSC 570, NC State University

Practical Implementations of CRC


r

M(x) x
R(x) = Rem{
}
G(x)

g1
In p u t

g2
+

Feedback Shift Register

g m -1
+

...

How the long division (by modulo 2) is done?


ECE/CSC 570, NC State University

Example: r = 3 and k = 3
G(x) = 1 + x + x
2

M(x) = 1 + x

Input

Initial values
Input 101000

First bit into the circuit

Remainder
ECE/CSC 570, NC State University

+
0
1
0
1
1
1
0

0
0
1
0
1
1
1

0
0
0
1
1
0
1

r(x) = x2+x

Other Error-Detecting Codes


n

Convolutional Codes

Decoding:
Maximum likelihood detection
Trellis decoding

Usually involves number theory!

ECE/CSC 570, NC State University

Potrebbero piacerti anche