Sunteți pe pagina 1din 51

Functions of Data Link Layer

Providing a well-defined service interface to the network layer.


Dealing with transmission errors.
Regulating the flow of data so that slow receivers are not swamped
by fast senders
DLL takes the packets it gets from the network layer and
encapsulates them into frames for transmission
Each frame contains a frame header, a payload field for
holding the packet, and a frame trailer
Data Link Layer
Design Issues
Reliable Delivery
Flow control
Acknowledged delivery
Error detection and correction
Services provided to the Network Layer
Unacknowledged connectionless service
Suitable for applications with low error rate and for real time
traffic such as voice
Acknowledged connectionless service
Suitable for applications that needs assurance of delivery
Acknowledged connection-oriented service



Data Link Layer
Transmission of the data link layer starts with
breaking up the bit stream
into discrete frames
Computation of a checksum for each frame, and
Include the checksum into the frame before it is
transmitted.
Receiver computes its checksum error for a receiving
frame and if it is different from the checksum that is
being transmitted will have to deal with the error.
Framing is more difficult than one could think!

DLC functions
To provide service to the network layer, the data
link layer must use the service provided to it by
the physical layer
Physical layer accept a raw bit stream and
attempt to deliver it to the destination.
Bit stream is not guaranteed to be error free
Number of bits received may be less than, equal
to, or more than the number of bits transmitted,
and they may have different values.
It is up to the data link layer to detect and, if
necessary, correct errors

Framing
1. Byte count
2. Flag bytes with byte stuffing
3. Flag bits with bit stuffing


Framing Methods
It uses a field in the header to specify the number of
bytes in the frame.
Once the header information is being received it will be
used to determine end of the frame.


Byte/Character Count Framing
Method
A byte stream. (a) Without errors
Disadvantages
Trouble with this algorithm is that when the count is
incorrectly received the destination will get out of synch
with transmission.
Destination may be able to detect that the frame is in error but it does
not have a means (in this algorithm) how to correct it

Byte/Character Count Framing
Method
A byte stream (b) With one error.
Flag Bytes with Byte Stuffing
Framing Method
This methods gets around the boundary detection of the
frame by having each appended by the frame start and
frame end special bytes.
If they are the same (beginning and ending byte in the
frame) they are called flag byte.

A frame delimited by flag bytes.
If the actual data contains a byte that is identical
to the FLAG byte (e.g., picture, data stream, etc.)
the convention that can be used is to have
escape character(ESC) inserted just before the
FLAG character

Flag Bytes with Byte Stuffing
Framing Method
It may also appears that escape byte appears in
the data.
To prevent escape byte from being mixed with
the data, each escape byte appearing in data is
stuffed with another escape byte
Flag Bytes with Byte Stuffing
Framing Method
Bit Stuffing Framing Method
This methods achieves the same thing as Byte Stuffing
method by using Bits (1) instead of Bytes (8 Bits).
It was developed for High-level Data Link Control (HDLC)
protocol.
Each frames begins and ends with a special bit pattern:
01111110 or 0x7E <- Flag Byte
Whenever the senders data link layer encounters five
consecutive 1s in the data it automatically stuffs a 0 bit into
the outgoing bit stream.
USB uses bit stuffing.
Bit Stuffing Framing Method
During data transmission, one or more bits of
data being transmitted may get corrupted
Depending on the number of bits in data that
have been corrupted, there exist two types of
error:
1. Single bit error
2. Burst error
Types of Error
Single-bit error means that only 1 bit of a
given data unit (such as a byte, character, or
packet) is changed from 1 to 0 or from 0 to 1
Single bit error
Burst error means that 2 or more bits in the
data unit have changed from 1 to 0 or from 0
to 1
Burst error
During data transmission, errors may occur because
of certain transmission impairments such as
attenuation and electromagnetic noise
To detect or correct errors, we need to send some
extra bits with our data
Error detection uses the concept of redundancy, which
means adding extra bits for detecting errors at the
destination
These extra bits are called Redundant bits
These redundant bits are added by the sender and
removed by the receiver
Their presence allows the receiver to detect or
correct corrupted bits
The central concept in detecting or correcting errors
is redundancy
Redudancy
Error Detection:
In error detection, we are only looking to see if
any error has occurred
The answer is a simple yes or no
We are not even interested in the number of
corrupted bits
A single-bit error is the same for us as a burst
error
Some of the commonly error-detecting codes are:
1. Simple parity check
2. Two dimensional(2D) parity check
3. Checksum
4. Cyclic Redundancy Check(CRC)


Error detection v/s Correction
Error Correction:
Emphasis is on not only to detect the errors but
also to correct them
For this, it is important to know the exact
number of bits that are corrupted and, more
importantly, their location in the message
The correction of errors is more difficult than
the detection
The most commonly used error correcting
code is Hamming code

Error detection v/s Correction
An extra bit known as parity bit is added to each
data word that is being transmitted
A k-bit data word is changed to n-bit codeword
i.e. n = k+1
Value of parity bit (i.e. 0 or 1) is such that
character has even (even parity) or odd (odd
parity) number of ones
Generally, the MSB is parity bit
Example:
Simple Parity check
Even Parity
P Dataword
0 1 0 1 0 0 1 1
1 1 1 1 0 1 1 0
Odd Parity
P Dataword
1 1 0 1 0 0 1 1
0 1 1 1 0 1 1 0
Simple parity-check code C(5, 4)
10.21
10.22
Encoder and decoder for simple parity-check code
What happens if the character 10010101 is
sent and the first two 0s accidentally become
two 1s?
Thus, the following character is received:
11110101
Will there be a parity error?
Problem: Simple parity only detects odd numbers of
bits in error
Simple Parity check
There are two types of 2D parity check
Longitudinal Redundancy Check (LRC)
Vertical Redundancy Check (VRC)
Longitudinal Redundancy Check (LRC)
Longitudinal parity adds a parity bit to each character
then adds a row of parity bits after a block of characters.
The row of parity bits is actually a parity bit for each
column of characters
Two dimensional parity check

LRC and VRC
LRC and VRC are calculated using simple parity
check method
The binary words being transmitted or received
organized in the form of rows and columns
VRC Parity bits are computed for each column
LRC Parity bits are computed for each row
Parity bits along with the data are sent to the
receiver
Two dimensional parity check
If the data to be transmitted are 1100001, 1111001,
1011001, 0000101, 0010101, 0010101, 1010001. find the
VRC, LRC and bytes to be transmitted








Coded Bytes: 11000011, 11110011, 10110010, 00001010, 00101011,
00101011, 10100011, 00101011
Two dimensional parity check
Bytes
LRC
Bits
B

I

t

s



VRC Bits
1 1 1 0 0 0 1
1 1 0 0 0 0 0
0 1 1 0 1 1 1
0 1 1 0 0 0 0
0 0 0 1 1 1 0
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0
0
1
0
1
0
1
1 1 0 0 1 1 1 1
Both simple parity and 2D parity do not catch
all errors.
Simple parity only catches odd numbers of bit
errors (50% of all errors)
2D parity is better at catching errors but
requires too many check bits added to a block
of data.
As such, these methods are not that often
used. However, a parity bit exists in 1 byte of
data.
Two dimensional parity check
It can be applied to a message of any length
It can be used to detect multiple errors
At the source, message is divided into m-bit units
At the sender, Generator creates an extra m-bit unit
called checksum by adding the bits of data to be
transmitted, which is sent with the message
At the receiver, checksum is again computed by
adding the bits of received bytes
If the newly computed checksum is same as one
transmitted, then it implies no error
It is calculated by adding all the bytes bit-by-bit by
neglecting the final carry (i.e out of MSB)
It can detect all odd numbers of errors and most of
the even number of errors.
Additive Checksum
Find the checksum byte for the fallowing
datawords: 10110011, 10101011, 01011010,
11010101






Check sum byte: 10001101
Additive Checksum
1 0 1 1 0 0 1 1
1 0 1 0 1 0 1 1
0 1 0 1 1 0 1 0
Neglect Final
Carry
1 1 0 1 0 1 0 1
1 1 0 0 0 1 1 0 1
Most widely and powerful error-detecting
techniques developed by IBM
Also referred to as Polynomial code, as it treats
the bit stream to be transmitted as a polynomial
The coefficients are the 0 and 1 values in the bit
string
The transmitter takes the Message polynomial
M(x)
Using polynomial arithmetic, divides it by a
given Generator polynomial G(x)
MSB and LSB of the Generator polynomial
should be always 1



Cyclic Redundancy Check (CRC)
A m-bit frame is regarded as the coefficient list for a
polynomial with m terms ranging from x
m-1
to x
0


The degree of the polynomial is m-1





Polynomial arithmetic is done in modulo-2
In modulo-2, there are no carries for addition or borrows
for subtraction
Both addition and subtraction are identical to exclusive
OR operation
Sender and receiver must agree upon a generator
polynomial, G(x), in advance
Degree of M(x) must be greater than degree of G(x)
Cyclic Redundancy Check (CRC)
m is the number of bits in the frame i.e.in M(x)
k is the degree of G(x)
Algorithm for computing the checksum at the
sender
1. Append k bits to the LSB side of the data frame, so
it now contains m+k bits i.e x
k
M(x)
2. Divide the resultant polynomial x
k
M(x) by the
generator G(x) in modulo-2 arithmetic
3. After division, the remainder bits (i.e r-bits) called
redundant bits or CRC are added to the dividend to
form the code word (m+r bits)
4. Finally, this code word is transmitted
Cyclic Redundancy Check (CRC)
At the receivers end, the received codeword
of m+r bits is again divided by the same
generator as used by the sender
If the remainder is non-zero, the receiver
know that the error has occurred and reject
the data word
If the remainder is zero, the receiver knows
that there is no error and accept the data
word

Cyclic Redundancy Check (CRC)
Generate the CRC code for the message x
3
+1 using the
generator polynomial x
3
+x+1
M(x) = x
3
+1 in Binary =1001
G(x) = x
3
+x+1 in Binary = 1011
x
3
M(x) = x
3
(x
3
+1) = x
6
+x
3
= 1001000

Cyclic Redundancy Check (CRC)

1 0 1 1
1 0 0 1
1 0 1 1
0 1 0 0
0 0 0 0
1 0 0 0
1 0 1 1
0 1 1 0
0 0 0 0
1 1 0
1 0 1 0
Dataword
CRC
(Remainder)
1 0 0 1 1 1 0
Codeword
1 0 0 1 1 1 0
CRC computation at receiver
Cyclic Redundancy Check (CRC)
Generate the CRC code for the dataword
1101011011 using generator 10011. Also write
both in the polynomial form.
Answer: CRC = 1110 codeword = 11010110111110

Cyclic Redundancy Check (CRC)
Standard polynomials
10.38
Performance of CRC
Once an error is detected, what is the receiver
going to do?
Do nothing (simply toss the frame or packet)
Return an error message for retransmission
Fix the error with no further help from the
transmitter

Error Correcting codes
Correct the errors
For a receiver to correct the error with no
further help from the transmitter requires a
large amount of redundant information to
accompany the original data
This redundant information allows the receiver to
determine the error and make corrections
This type of error control is often called
forward error correction(FEC) and involves
codes called Hamming codes
Error Correcting codes
Hamming distance
Hamming distance between two codewords of equal length is
the number of positions at which the corresponding
codewords are different
Hamming distance between two codewords X and Y is
denoted as d(X, y)
Example:

It can be calculated by performing the XOR operation on the
codewords
The number of 1 in the result will give you Hamming distance




Error Correcting codes
X= 1 0 0 1 0 0 1 0
Y= 1 1 0 1 1 0 0 1
d(X, Y) = 4
X= 1 0 0 1 0 0 1 0
Y= 1 1 0 1 1 0 0 1
XOR
0 1 0 0 1 0 1 1
d(X, Y) = 4
Minimum hamming distance (d
min
)
It is the smallest of the hamming distances
calculated between each possible pair of codes
Possible to detect errors if the total number of
errors in the received codeword is less than d
min,

otherwise errors can not be corrected
Error detection and correction capabilities of any
coding technique largely depend on the d
min

Error Correcting codes
m is the number of data bits in a frame
r is the number of redudant bits
Number of bits in Codeword: n=m+r
In most data communication, all 2
m
possible data
messages are legal, but not all 2
n
code words are
used
Selection of r
2
r
>=m+r+1
For example: if m=7, the smallest value of r=4
2
4
>=7+4+1
Error Correcting codes
Hamming code
The basic idea is to insert parity bits in between the data bits
to be transmitted
Parity bits are placed at each 2
t
bit positions where
t=0,1,2,3,,,,,
2
0
= 1 at first position
2
1
= 2 at second position
2
2
= 4 at fourth position and so on



Error Correcting codes
Number of redundancy bits needed
Let data bits = m
Redundancy bits = r
Total message sent = m+r
The value of r must satisfy the following relation:
2
r
m+r+1
Example: if m=4, 3 parity bits are required to
satisfy the condition

Error Correcting codes
Value of r bits set to 1 or 0 to make an even parity







r1= 1, 3, 5, 7, 9, 11, , , , , ,
r2=2,3, 6, 7, 10, 11, , , , ,
r4 = 4, 5, 6, 7, 12, 13, 14, 15, , , , ,
r8 = 8,9,10,11,12,13,14,15, , , , ,
and so on
Ex-OR the bits to get redundancy bits/ parity bits
Error Correcting codes
Error Correcting codes
Single bit errors
Error Correcting codes
Error Detection
The code being received is 10010100101. find the error bit
Error Correcting codes
Note :Error correcting capability
To detect d errors in the codeword
dmin d+1

To correct d errors in the code word
dmin 2d+1

S-ar putea să vă placă și