Sei sulla pagina 1di 88

Data Link Layer

BY:
MITUL PATEL

Figure 3-5

Data Link Layer

WCB/McGraw-Hill

The McGraw-Hill Companies, Inc., 1998

Figure 3-6

Data Link Layer Example

WCB/McGraw-Hill

The McGraw-Hill Companies, Inc., 1998

Packets and Frames


Relationship between packets and frames.

Specific responsibilities of the data link layer include


Framing: divides the stream of bits received from the
network layer into manageable data units called frames.
Addressing: The data link layer adds a header to the
frame to define the addresses of the sender and
receiver of the frame.
Flow control: If the rate at which the data are
absorbed by the receiver is less than the rate at which
data are produced in the sender, the data link layer
imposes a flow control mechanism to avoid
overwhelming the receiver.
Error control: The data link layer also adds reliability
to the physical layer by adding mechanisms to detect
and retransmit damaged, duplicate, or lost frames.
Media access control: When two or more devices are
connected to the same link, data link layer protocols are
necessary to determine which device has control over
the link at any given time.

Error Control

Types of Errors

Single-bit error

Single bit errors are the least likely


type of errors in serial data transmission
because the noise must have a very short
duration which is very rare. However this
kind of errors can happen in parallel
transmission.
Example:

If data is sent at 1Mbps then each bit


lasts only 1/1,000,000 sec. or 1 s.

For a single-bit error to occur, the noise


must have a duration of only 1 s, which
is very rare.

Burst error

The term burst error means that two or


more bits in the data unit have changed
from 1 to 0 or from 0 to 1.
Burst errors does not necessarily
mean that the errors occur in
consecutive bits, the 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.

Burst error is most likely to happen in


serial transmission since the duration of
noise is normally longer than the duration of a
bit.
The number of bits affected depends on the
data rate and duration of noise.
Example:
If data is sent at rate = 1Kbps then a noise
of 1/100 sec can affect 10 bits.(1/100*1000)

If same data is sent at rate = 1Mbps then a


noise of 1/100 sec can affect 10,000 bits.
(1/100*106)

Error detection
Error detection means to decide whether the
received data is correct or not without having
a copy of the original message.
Error detection uses the concept of
redundancy, which means adding extra bits
for detecting errors at the destination.

Redundancy

Error Correction
Need to know exact number of bits that are
corrupted and their location in the message
The number of the errors and the size of the
message are important factors
Correct one single error in an 8-bit data
unit, how many possibilities??
Two errors in 8-bit data unit?
10 errors in 1000 bits??

Forward error correction Vs.


Retransmission
Forward error correction receiver tries to
guess the message by using redundant bits.
Retransmission the receiver detects the
occurrence of an error and asks the sender
to resend the message

BLOCK CODING
Divide the message into blocks each of kbits called datawords.
Add r redundant bits to each block to make
length n=k+r. The resulting n-bit blocks are
called codewords.

K bits

N bits

K bits

N bits

K bits

N bits

A code for error detection

k=2

n=3
Datawords

Codewords

00

000

01

011

10

101

11

110

Assume the sender encodes the dataword 01 as


011 and sends it to the receiver
1. The receiver receives 011
2. The receiver receives 111
3. The receiver receives 000

A code for error correction

k=2

n=5
Dataword

Codeword

00

00000

01

01011

10

10101

11

11110

Assume the dataword is 01.The sender


creates the codeword 01011.The codeword
is corrupted during transmission and 01001
is received.

Hamming Distance
The Hamming distance between two words
is the number of differences between
corresponding bits.
Hamming distance of two words x and y is
d(x,y)
Can be found by applying XOR operation on
the two words and count the number of 1s
in the result.

Hamming distance between two pairs of


words.
The Hamming distance d(000, 011) is 2
because

000 + 011 is 011 (two 1s)

The Hamming distance d(10101, 11110) is


3 because
10101 + 11110 is 01011 (three 1s)

Minimum Hamming
Distance

The minimum Hamming distance is the smallest Hamming


distance between all possible pairs in a set of words.
Find the minimum Hamming distance of the coding
scheme in Table:
DataWords

Codewords

00

000

01

011

10

101

11

110

d(000,011)=2
d(000,101)=2
d(000,110)=2
d(011,101)=2 d(011,110)= 2
d(101,110)=2
The dmin in this case is 2.

The minimum Hamming distance for our first


code scheme is 2.
This code guarantees detection of only a
single error.
For example, if the third codeword (101) is
sent and one error occurs, the received
codeword does not match any valid
codeword.
If two errors occur, however, the received
codeword may match a valid codeword and
the errors are not detected.

Geometric concept for finding dmin in error detection

To guarantee the detection of up to s errors in


all cases, the minimum Hamming distance in a
block
code must be dmin = s + 1.

Minimum Hamming
Distance

Find the minimum Hamming distance of the


coding scheme in Table:
Datawords

Codewords

00

00000

01

01011

10

10101

11

11110

The dmin in this case is 3.

Our

second block code scheme has dmin = 3.


This code can detect up to two errors. Again,
we see that when any of the valid codeword is
sent, two errors create a codeword which is
not in the table of valid codeword.
However, some combinations of three errors
change a valid codeword to another valid
codeword. The receiver accepts the received
codeword and the errors are undetected.

Three parameters for coding scheme C(n,k)


n codeword size
k datawordsize
dminminimum hamming distance

Example
C(3,2) with dmin = 2

Geometric concept for finding dmin in error correction

To guarantee correction of up to t errors in all


cases, the minimum Hamming distance in a
block code
must be dmin = 2t + 1.

A code scheme has a Hamming


distance dmin = 4. What is the error
detection and correction capability of
this scheme?
Solution
Thiscodeguaranteesthedetectionofuptothreeerrors
(s=3),butitcancorrectuptooneerror.Inother
words,ifthiscodeisusedforerrorcorrection,partof
itscapabilityiswasted.Errorcorrectioncodesneedto
haveanoddminimumdistance(3,5,7,...).

Linear Block Codes

In a linear block code, the exclusive


OR(XOR) of any two valid codewords creates
another valid codeword.
Datawords

Codewords

Datawords

Codewords

00

000

00

00000

01

011

01

01011

10

101

10

10101

11

110

11

11110

Minimum Distance for Linear


Block Codes

Number of 1s in the non-zero valid


codeword with the smallest number of 1s.

our types of redundancy checks are used


in data communications

Parity Check

most familiar error-detecting code is the


simple parity-check code.
a k-bit data word is changed to an n-bit
codeword where n = k + 1. The extra bit,
called the parity bit.
parity bit: selected to make the total
number of 1s in the codeword even
For odd parity number of 1s in the
codeword should be odd

Simple parity-check code


C(5,4)
Datawords

Codewords

Datawords

Codewords

0000

00000

1000

10001

0001

00011

1001

10010

0010

00101

1010

10100

0011

00110

1011

10111

0100

01001

1100

11000

0101

01010

1101

11011

0110

01100

1110

11101

0111

01111

1111

11110

Encoder and decoder for simple


parity-check code

Vertical Redundancy Check


VRC

Example
Assume the sender sends the dataword
1011.The codeword was created from this
dataword is 10111,which is sent to the receiver.
1. No error occurs
2. One single-bit error changes a1.
3. One single-bit error changes r0.
4. An error changes r0 and a second error
changes a3.
5. Three bits-a3,a2 and a1- are changed by
errors.

Performance
It

can detect single bit error


It can detect burst errors only if the total
number of errors is odd.

Longitudinal Redundancy Check


LRC

Performance
LRC increases the likelihood of
detecting burst errors.
If two bits in one data units are
damaged and two bits in exactly
the same positions in another data
unit are also damaged, the LRC
checker will not detect an error.

A better approach is the two-dimensional


parity check.
In this method, the data- word is organized
in a table (rows and columns).

2D Parity Check:
Performance

46

2D Parity Check:
Performance

47

Hamming Codes
dmin=3
Hamming code C(7,4)

Dataword
s

Codeword
s

Dataword
s

Codeword
s

0000

0000000

1000

1000110

0001

0001101

1001

1001011

0010

0010111

1010

1010001

0011

0011010

1011

1011100

0100

0100011

1100

1100101

0101

0101110

1101

1101000

0110

0110100

1110

1110010

0111

0111001

1111

1111111

A copy of a 4-bit dataword is fed into the


generator that creates three parity checks ro,r1
and r2 as shown below:
r0=a2+a1+a0 modulo-2
r1=a3+a2+a1 modulo-2
r2=a1+a0+a3 modulo-2

The checker in the decoder creates a 3-bit


syndrome(s2s1s0) in which each bit is the parity
check for 4 out of the 7 bits in the received
codeword:
S0=b2+b1+b0+q0
S1=b3+b2+b1+q1
S2=b1+b0+b3+q2

Logical decisions made by the correction


logic analyzer of the decoder

Syndrome

000

001

010 011

100

101

110

111

Error

None

q0

q1

q2

b0

b3

b1

b2

CYCLIC CODES
Cyclic codes are special linear block codes
with one extra property.
If a codeword is cyclically shifted, the result
is another codeword.
1011000
0110001

A CRC code with C(7,4)


Dataword

Codeword

Dataword

Codeword

0000

0000000

1000

1000101

0001

0001011

1001

1001110

0010

0010110

1010

1010011

0011

0011101

1011

1011000

0100

0100111

1100

1100010

0101

0101100

1101

1101001

0110

0110001

1110

1110100

0111

0111010

1111

1111111

Cyclic Redundancy Check


CRC

Cyclic Redundancy Check


Size of dataword=k bits; size of
codeword=n bits
The size of the dataword is augmented
by adding n-k 0s to the right-hand side of
the word
The generator uses a divisor of nk+1,predefined and agreed upon.
The generator divides the augmented
dataword by the divisor.
The quotient of the divison is discarded;
the remainder is appended to the
dataword to create the codeword.

Binary Division

Divisor 1011
Data sequence 1010011110

Polynomial

Polynomial and Divisor

Standard Polynomials

Cyclic Code Analysis


d(x) : Dataword
c(x) : Codeword
g(x) : Generator
e(x) : Error
s(x) : Syndrome

Received codeword = c(x)+e(x)


Received codeword/g(x)= c(x)/g(x) + e(x)/g(x)
In a Cyclic code, those e(x) errors that
are divisible by g(x) are not caught.

Single-bit error
What should be the structure of g(x) to
guarantee the detection of a single-bit error?
A single-bit error is e(x) =x i where i is the
position of the bit. If a single-bit error is caught,
then xi is not divisible by g(x).
If g(x) has at least two terms and the
coefficient of x0is not zero, then e(x) cannot be
divided by g(x).
If the generator has more than one term and
the coefficient of x0 is 1,all single errors can be
caught.

Which of the following g(x) values guarantees


that a single-bit error is caught? For each
case,
what is the error that cannot be caught?
a. x + 1
b. x3
c. 1

Two Isolated Single-Bit


Errors
We can show this type of error as

e(x) =: xj+ xi.


The values of i and j define the positions of the
errors, and the difference j - i defines the distance
between the two errors
We can write e(x) = xi(xj-i+ 1)
So if g(x) is to divide e(x), it must divide x j-i+ 1. In
other words, g(x) must not divide xt + 1, where t is
between 0 and n - 1.
However, t=0 is meaningless and t = I is needed as
we will see later. This means t should be between 2
and n-1.
If a generator cannot divide x t + 1 (t between 0 and
n - 1),then all isolated double errors can be detected.

Find the status of the following generators


related to two isolated, single-bit errors.
a. x+ 1
b. x4 + I
c. x7 + x6+ 1

Odd Numbers of Errors


A generator with a factor of x + 1 can catch
all odd numbers of errors
For example, x4 + x2 + x + 1 can catch all
odd-numbered errors since it can be written
as a product of the two polynomials x + 1
and x3 + x2 + 1.

Burst error
A burst error is of the form e(x) =(xj+ ... + xi)
We can factor out xi and write the error as
xi(xj-i + ... + 1).
If our generator can detect a single error
(minimum condition for a generator), then it
cannot divide xi.
In other words, the remainder of (xj-i + ... +
1)/(xr + ... + 1) must not be zero.
Note that the denominator is the generator
polynomial. We can have three cases:

1.

If j - i < r, the remainder can never be zero. We can write j - i =L


- 1, where L is the length of the error. So L - 1 < r or L < r + 1 or
L <=r. This means all burst errors with length smaller than or
equal to the number of check bits r will be detected.

2.

In some rare cases, if j - i = r, or L = r + 1, the syndrome is 0 and


the error is undetected. It can be proved that in these cases, the
probability of undetected burst error of length r + 1 is (1/2)r-1. For
example, if our generator is x14 + x3+ 1, in which r =14, a burst
error of length L =15 can slip by undetected with the probability
of (1/2)14-1 or almost 1 in 10,000.

3.

In some rare cases, if j - i > r, or L > r + 1, the syndrome is 0 and


the error is undetected. It can be proved that in these cases, the
probability of undetected burst error of length greater than r + 1
is (1/2)r For example, if our generator is x14 + x3 + 1, in which r
=14, a burst error of length greater than 15 can slip by
undetected with the probability of (1/2)14 or almost 1 in 16,000
cases.

length of error L
r degree of generator
L <= r the remainder can never be zero.

All burst error with length smaller than or equal to


the number of check bits r will be detected

L = r+1 the probability of detection of error


is 1-(1/2) r-1
L > r+1 the probability of detection of error
is 1-(1/2) r

The criteria for a good


polynomial generator:
Should not be multiple of x
It should have at least two terms
The coefficient of the term x0 should be 1
It should not divide xt+1for t between 2 and
n-1
It should have factor x+1

Checksum

The checksum is used in the Internet by


several protocols
although not frequently at the data link layer

It is based upon the concept of redundancy


Example

We want to send list of 4-bit numbers (7, 11, 12,


0, 6)
We send (7, 11, 12, 0, 6, 36), where 36 is the sum
of original no.
If we send (7, 11, 12, 0, 6, -36), called the
checksum

Using Ones Complement for


Checksum

A sender needs to send the four data items


Ox3456, OxABCC, Ox02BC, and OxEEEE.
Find the checksum at the sender site.

Internet Checksum
Traditionally, the Internet has been using a
16-bit checksum.
The sender calculates the checksum by
following these steps.
Sender site:

1. The message is divided into 16-bit words.


2. The value of the checksum word is set to 0.
3. All words including the checksum are added
using one's complement addition.
4. The sum is complemented and becomes the
checksum.
5. The checksum is sent with the data.

The receiver uses the following steps for


error detection.
Receiver site:

1. The message (including checksum) is divided


into 16-bit words.
2. All words are added using one's complement
addition.
3. The sum is complemented and becomes the
new checksum.
4. If the value of checksum is 0, the message is
accepted; otherwise, it is rejected.

calculate the checksum for a text of 8


characters ("Forouzan").
Divided into 2-byte (l6-bit) words.
use ASCII to change each byte to a 2-digit
hexadecimal number.
F -> Ox46 and O -> Ox6F
calculate the sum using 32 bits
add the carries (if present) to the 16 - bit
sum
take the complement.

Calculate the checksum for following


packet header : 01 00 F2 03 F4 F5 F6 F7

At sender side
The first step is to form 16-bit words.
0100 F203 F4F5 F6F7
The second step is to calculate the sum using
32-bits.
0100 + F203 + F4F5 + F6F7 = 0002 DEEF
The third step is to add the carries (0002) to
the 16-bit sum.
DEEF + 002 = DEF1
The fourth step is to take the complement.
~DEF1 = 210E checksum is 21 0E
The packet header is sent as :
01 00 F2 03 F4 F5 F6 F7 21 0E

Receiver Side
The first step is to form 16-bit words.
0100 F203 F4F5 F6F7 210E
The second step is to calculate the sum
using 32-bits.
0100 + F203 + F4F5 + F6F7 + 210E=
0002 FFFD
The third step is to add the carries (0002)
to the 16-bit sum.
FFFD+ 0002 = FFFF which means that no
error was detected.(In 1s complement,
zero is 0000 or FFFF.)

FRAMING

FRAMING
The data link layer needs to pack bits into frames, so
that each frame is distinguishable from another. Our
postal system practices a type of framing. The simple
act of inserting a letter into an envelope separates one
piece of information from another; the envelope serves
as the delimiter.
Topics discussed in this section:
Fixed-Size Framing
Variable-Size Framing
11.82

Figure 11.1 A frame in a character-oriented protocol

11.83

Figure 11.2 Byte stuffing and unstuffing

11.84

Note

Byte stuffing is the process of


adding 1 extra byte whenever
there is a flag or escape character
in the text.

11.85

Figure 11.3 A frame in a bit-oriented protocol

11.86

Note
Bit stuffing is the process of adding
one extra 0 whenever five consecutive
1s follow a 0 in the data, so that the
receiver does not mistake
the pattern 0111110 for a flag.

11.87

Figure 11.4 Bit stuffing and unstuffing

11.88

Potrebbero piacerti anche