You are on page 1of 51

Framing Methods

The data link layer needs to pack bits into frames, so that each
frame is distinguishable from another.
Methods

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

Byte/Character Count Framing


Method
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.

A byte stream. (a) Without errors

Byte/Character Count Framing


Method
Disadvantages
Trouble with this algorithm is that when the count is
incorrectly received the destination will get out of synch with
transmission.

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.

A frame delimited by flag bytes.

Flag Bytes with Byte Stuffing


Framing Method
If the actual data contains a byte that is
identical to the FLAG byte 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

Byte stuffing and unstuffing

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

Bit stuffing and unstuffing

Error Control

Types of Error
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
Two basic strategies for dealing with errors
1.Error Detection
2.Error Correction

Single bit 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

Burst error
Burst error means that 2 or more bits in the
data unit have changed from 1 to 0 or from 0
to 1

Redudancy
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.

Error detection v/s Correction


Error Detection:
In error detection, we are only looking if any error
has occurred.
The answer is a simple yes or no
We are not even interested in the number of corrupted
bits.
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)

1.Simple Parity check


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:
Even Parity

Odd Parity

Dataword

Dataword

Simple parity-check code C(5, 4)

Simple Parity check


What happens if the character 10010101 is
sent and the first two 0s accidentally become
two 1s?
Thus, the following character
11110101
Will there be a parity error?

is

received:

Problem: Simple parity only detects odd numbers of


bits in error

2.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

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


Both simple parity and 2D parity do not catch
all errors.
Simple parity only catches odd numbers of bit
errors

2D parity is better at catching errors but


requires too many check bits added to a block
of data

Additive Checksum
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.

3.Additive Checksum
Example
Data:10110011;10101011;01011010;11010101
Check sum:01110000
Transmitted Data:
10110011;10101011;01011010;11010101;
01110000

4.Cyclic Redundancy Check (CRC)


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)

Cyclic Redundancy Check (CRC)


A m-bit frame is regarded as the coefficient list for a
polynomial with m terms ranging from xm-1 to x0
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 message 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 xkM(x)
2. Divide the resultant polynomial xkM(x) by the
generator G(x) in modulo-2 arithmetic
3. After division, the remainder bits (i.e r-bits) called
redundant bits 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 x3+1 using the
generator polynomial x3+x+1
M(x) = x3+1 in Binary =1001
G(x) = x3+x+1 in Binary = 1011
x3M(x) = x3 (x3+1) = x6+x3 = 1001000
1
1011

1 0 0 1
1 0 1 1

1
1

0
0

0
1

0
1

Dataword
1

CRC
(Remainder)

0 0 1 1
1 0
Codeword
1 0 0 1 1 1 0

Cyclic Redundancy Check (CRC)


CRC computation at receiver

CRC Code C(7,4)

Cyclic Redundancy Check (CRC)


Generate

the

CRC

code

for

1101011011

using generator
write both in the polynomial form.
Answer: CRC = 1110
Codeword =

11010110111110

the

dataword

10011.

Also

Standard polynomials

10.34

Performance of 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 Correcting codes


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


m is the number of data bits in a frame
r is the number of redundant bits
Number of bits in Codeword: n=m+r
Selection of r
2r>=m+r+1
For example: if m=7, the smallest value of r=4
24>=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 2t bit positions where
t=0,1,2,3,,,,,
20 = 1 at first position
21 = 2 at second position
22 = 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:
2r 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

Hamming Distance
The minimum Hamming distance is the smallest Hamming
distance between all possible pairs in a set of words.

Example
Hamming distance

And Minimum Hamming Distance


The dmin in this case is 3.

Error Correcting codes


Hamming distance
Hamming distance between two codewords of equal length is
the number of positions at which the corresponding bits are
different
Hamming distance between two codewords X and Y is
denoted as d(X, y)
X=
1
0
0
1
0
0
1
0
Example:
Y=
1
1
0
1
1
0
0
1
d(X, Y) = 4

It can be calculated by performing the XOR operation on the


codewords
The number of 1 in the result will give you Hamming distance
X=

Y=

XOR

d(X, Y) = 4

Error Correcting codes


Minimum hamming distance (dmin )
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 dmin,
otherwise errors can not be corrected
Error detection and correction capabilities of any
coding technique largely depend on the dmin

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

Hamming code C(7, 4) - n=7, k = 4

You might also like