Position of the data-link layer
Kyung Hee
University
1
Error Detection and Correction
UNIT-2
Kyung Hee
University
2
Error Detection and Correction
Types of Errors
Error Detection
Error Correction
Kyung Hee
University
3
Error Detection and Correction
Data can be corrupted during transmission. For reliable
communication, error must be detected and corrected
Error Detection and Correction are implemented either
at the data link layer or the transport layer of the OSI
model
Kyung Hee
University
4
10.1 Type of Errors
Kyung Hee
University
5
Type of Errors(cont’d)
Single-Bit Error
It is when only one bit in the data unit has changed from
0 to 1,1 to 0
Kyung Hee
University
6
Type of Errors(cont’d)
Multiple-Bit Error
when two or more nonconsecutive bits in the data unit
have changed 1 to 0 and 0 to 1
Kyung Hee
University
7
Type of Errors(cont’d)
Burst Error
means that 2 or more consecutive bits in the data unit
have changed from 1 to 0 and 0 to 1
Kyung Hee
University
8
It is actually to detect errors, we use the mechanism called Redundancy
It is the main technique to detect errors
Error Detection
Group of bits adding to end of data unit
It is actually to detect errors, we use the mechanism called
Redundancy
It is the main technique to detect errors
Group of bits adding to end of data unit
1.Redundancy
Generating
function
Kyung Hee
University
9
Now reciever will check the message with the help of checking
function ,validating the sender message ,
If checking function is valid the data will accept
If the checking function is not valid the data rejectd
Kyung Hee
University
10
Detection(cont’d)
Detection methods
Kyung Hee
University
11
Detection(cont’d)
Parity Check:
It is simplest technique for error detection,we are using most
significant bit(MSB),List significant bit(LSB)
A parity bit is added to every data unit so that the total number of
1s(including the parity bit) becomes even for even-parity check
or odd for odd-parity check
Simple parity check P-PARITY BITD
p D6 D5 D4 D3 D2 D1 DO
D6---D0-- Even number of 1’s----parity bit=0
D6---D0-- Odd number of 1’s----parity bit=1
Kyung Hee
University
12
DRAW BACKS
1.it does not support all types of errors
2.it support even ,odd number of bits
3.it is not suitable for multiple errors
4.it is suitable for single bit error
Kyung Hee
University
13
Kyung Hee
University
14
Check sum
Check sum:
8 8 8 8
In the check sum error detection scheme
The data is divided into k segments each of m bits
In the sender end ,the segments are added using 1’s complement arithmetic to
get the sum, the sum is complemented to get the check sum
Now check sum segment is sent along with the data segment
At receiver end,all received segments are added 1’scomplement arithmetic to
get the sum,the sum is to be complemented
If the complemented result is ---------0----data accepted other wise rejected
Kyung Hee
University
15
For error detection by checksums, data is divided into
fixed sized frames or segments.
Sender’s End − The sender adds the segments using
1’s complement arithmetic to get the sum. It then
complements the sum to get the checksum and sends it
along with the data frames.
Receiver’s End − The receiver adds the incoming
segments along with the checksum using 1’s complement
arithmetic to get the sum and then complements it.
Kyung Hee
University
16
Suppose that the sender wants to send 4 frames each of 8 bits,
where the frames are 11001100, 10101010, 11110000 and
11000011.
The sender adds the bits using 1s complement arithmetic. While
adding two numbers using 1s complement arithmetic, if there is a
carry over, it is added to the sum.
After adding all the 4 frames, the sender complements the sum to get
the checksum, 11010011, and sends it along with the data frames.
The receiver performs 1s complement arithmetic sum of all the frames
including the checksum. The result is complemented and found to be 0.
Hence, the receiver assumes that no error has occurred .
Kyung Hee
University
17
If the result is zero, the received frames are accepted;
Kyung Hee
otherwise
Universitythey are discarded.
18
CRC(Cyclic Redundancy Check)
It is an error detection method base on binary division
In CRC,a segment of redundant bits called cyclic redundancy
check bits are appended to the end o the data.
So that the resulting data unit become exactly divisible by second
pre determined binary number
At the destination, the incommimg data is divided by the same
number
If the remainder is 0 -data is accepted otherwise rejected.
Kyung Hee
University
19
CRC(Cyclic Redundancy Check)
CRC(Cyclic Redundancy Check)
it is based on binary division.
Kyung Hee
University
20
Detection(cont’d)
CRC generator
uses modular-2 division.
po
Binary Division
in a
CRC Generator
Kyung Hee
University
21
Detection(cont’d)
Binary Division
in a
CRC Checker
Kyung Hee
University
22
Detection(cont’d)
Polynomials
CRC generator(divisor) is most often represented not as a
string of 1s and 0s, but as an algebraic polynomial.
Kyung Hee
University
23
Detection(cont’d)
A polynomial representing a divisor
Kyung Hee
University
24
Error Correction
Error Correction
>>Error Correction codes are used to detect and correct the
errors when data is transmitted from the sender to the
receiver.
Error Correction can be handled in two ways:
Backward error correction: Once the error is discovered, the
receiver requests the sender to retransmit the entire data unit.
Forward error correction: In this case, the receiver uses the
error-correcting code which automatically corrects the errors
Kyung Hee
University
25
>>A single additional bit can detect the error, but
cannot correct it.
For correcting the errors, one has to know the exact position of
the error. For example, if we want to calculate a single-bit
error, the error correction code will determine which one of
seven bits is in error. To achieve this, we have to add some
additional redundant bits.
>>Suppose r is the number of redundant bits and d is the total
number of the data bits. The number of redundant bits r can be
calculated by using the formula: 2r >=d+r+1
Kyung Hee
University
26
>>The value of r is calculated by using the above
formula. For example, if the value of d is 4, then the
possible smallest value that satisfies the above relation
would be 3.
>>To determine the position of the bit which is in error,
a technique developed by R.W Hamming is Hamming
code which can be applied to any length of the data
unit and uses the relationship between data units and
redundant units.
Kyung Hee
University
27
Hamming Code
It can be applied to data units of any length.
It is used to detect and correct single bit errors.
Proposed by e.w.hamming.
It is usually represented as 7 bits.
Hamming Code Structures:--
All bit positions that are power of 2 are marked as
parity bits.(1,2,4,6,8...) and the remaining bits are
data bits.
Kyung Hee
University
28
Determine the value of Parity bits:--
Rule: The value of parity bit is determined by the sequence of
bits that is alternatively checks and skips.
Sender is sending a data 1010 to receive
D7 D6 D5 P4 D3 P2 P1
1 0 1 ? 0 ? ?
Here P—parity Bit, D– data unit
Determine the value of parity bit
Kyung Hee
University
29
for P1:-- check 1bit,skip 1bit, check 1bit skip 1bit...)
: 1,3,5,7,....
for P2:-- check 2bits, skip 2bits,check 2bits, skip
2bits...)
: 2,3,6,7,10,11.....
for P4:-- check 4bits,skip 4bits, check 4 bits, skip
4bits...)
:4,5,6,7,12,13,14,15,20,21,22,23..
Kyung Hee
University
30
D7 D6 D5 P4 D3 P2 P1
1 0 1 ? 0 ? ?
P1 d3 d5 d7 | P2 d3 d6 d7 | P4 d5 d6 d7
P1 0 1 1 P2 0 0 1 P4 1 0 1
P1=0 P2=1 P4=0
D7 D6 D5 P4 D3 P2 P1
1 0 1 0 0 1 0
Kyung Hee
University
31
The sender send the exact data of parity data,the
recievier will receive message or not
Detecting errors in the Hamming code structure
D7 D6 D5 P4 D3 P2 P1
At reviever end bit (1,3,5,7,) (2,3,6,7) (4,5,6,7) are
checked for even parity P1=0, P2=0, P4=0
Kyung Hee
University
32
Correecting of Errors
An error i s located by forming a 3 bit error number of out of 3
bit parity checker
P4 P2 P1
We need to check parity of (P1, D3,D5,,D7)
If it is odd error exists P1=1
It is even error P1=0
Similarly P2 & p4
After we have found the Error word .we find decimal value
Then we invert the incorrect bit to obtain the correct word
Kyung Hee
University
33
Problem
A 7 bit Hamming code received as 1011011.Assume even parity state wheather the recieved code is
correct or wrong,if it is wrong locate the bit in error(which position was error)
Sol: Recieved Hamming code
D7 D6 D5 P4 D3 P2 P1
1 0 1 1 0 1 1
9
Kyung Hee
University
34
Detecting Errors:
Step-1: analyzing bits (1,3,5,7)
We have P1 D3 D5 D7-1 0 1 1
We have to put P1=1 {odd parity error exist}
Step-2: analyzing bits (1,3,5,7)
We have P2 D3 D6 D7-1 0 0 1
We have to put P2=0 {even parity error exist}
Kyung Hee
University
35
Step-3: analyzing bits (4,5,6,7)
We have P4 D5 D6 D7-1 1 0 1
We have to put P4=1 {odd parity error exist}
P4 & P1 are not equal to zero ,so recieved code is wrong
Correcting Errors:
Error Word E= 1 0 1
Find the decimal value E=5 (which Shows 5th Bit Is In Error)
S we write the correct word by simply inverting the 5 bit
Kyung Hee Correcting word:-1001011
University
36
Elementary Data link protocols
The basic function of the layer is to transmit frames over a
physical communication link. Transmission may be half duplex
or full duplex. To ensure that frames are delivered free of errors
to the destination station (IMP) a number of requirements are
placed on a data link protocol. The protocol (control mechanism)
should be capable of performing:
The identification of a frame (i.e. recognise the first and last bits
of a frame).
The transmission of frames of any length up to a given maximum.
Any bit pattern is permitted in a frame.
The detection of transmission errors.
Kyung Hee
University
37
The retransmission of frames which were damaged by errors.
The assurance that no frames were lost.
The detection of failure or abnormal situations
for control and monitoring purposes.
Kyung Hee
University
38
ELEMENTARY DATA LINK PROTOCOLS :
An Unrestricted Simplex Protocol •
A Simplex Stop-and-Wait Protocol •
A Simplex Protocol for a Noisy Channel
Kyung Hee
University
39
AN UNRESTRICTED SIMPLEX PROTOCOL
In order to appreciate the step by step development of efficient
and complex protocols we will begin with a simple but unrealistic
protocol. In this protocol:
Data are transmitted in one direction only
The transmitting (Tx) and receiving (Rx) hosts are always ready
Processing time can be ignored
Infinite buffer space is available
No errors occur; i.e. no damaged frames and no lost frames
(perfect channel)
Kyung Hee
University
40
Kyung Hee
University
41
A SIMPLEX STOP-AND-WAIT PROTOCOL
Here stop and wait means, whatever the data that sender wants to send,
he sends the data to the receiver. After sending the data, he stops and
waits until he receives the acknowledgment from the receiver. The stop
and wait protocol is a flow control protocol where flow control is one
of the services of the data link layer.
It is a data-link layer protocol which is used for transmitting the data
over the noiseless channels. It provides unidirectional data
transmission which means that either sending or receiving of data will
take place at a time. It provides flow-control mechanism but does not
provide any error control mechanism.
The idea behind the usage of this frame is that when the sender sends the frame then
he waits for the acknowledgment before sending the next frame.
Kyung Hee
University
42
Primitives of Stop and Wait Protocol
The primitives of stop and wait protocol are:
Sender side
Rule 1: Sender sends one data packet at a time.
Rule 2: Sender sends the next packet only when it receives the
acknowledgment of the previous packet.
Therefore, the idea of stop and wait protocol in the sender's side is very
simple, i.e., send one packet at a time, and do not send another packet
before receiving the acknowledgment.
Kyung Hee
University
43
Receiver side:
Rule 1: Receive and then consume the data packet.
Rule 2: When the data packet is consumed, receiver sends the
acknowledgment to the sender.
Therefore, the idea of stop and wait protocol in the receiver's side
is also very simple, i.e., consume the packet, and once the packet
is consumed, the acknowledgment is sent. This is known as a flow
control mechanism.
Kyung Hee
University
44
The above figure shows the working of the stop and wait protocol. If there
is a sender and receiver, then sender sends the packet and that packet is
known as a data packet. The sender will not send the second packet
without receiving the acknowledgment of the first packet. The receiver
sends the acknowledgment for the data packet that it has received. Once
the acknowledgment is received, the sender sends the next packet.
Kyung Hee
University
45
Disadvantages of Stop and Wait protocol
1. Problems occur due to lost
data
Suppose the sender sends the data and the data is lost. The receiver is
waiting for the data for a long time. Since the data is not received by the
receiver, so it does not send any acknowledgment. Since the sender does
not receive any acknowledgment so it will not send the next packet. This
problem occurs due to the lost data.
In this case, two problems occur:
Sender waits for an infinite amount of time for an acknowledgment.
Receiver waits for an infinite amount of time for a data.
Kyung Hee
University
46
2. Problems occur due to lost acknowledgment
Suppose the sender sends the data and it has also been received by the
receiver. On receiving the packet, the receiver sends the acknowledgment.
In this case, the acknowledgment is lost in a network, so there is no chance
for the sender to receive the acknowledgment. There is also no chance for
the sender to send the next packet as in stop and wait protocol, the next
packet cannot be sent until the acknowledgment of the previous packet is
received.
Kyung Hee
University
47
3.Problem due to the delayed data or acknowledgment
Suppose the sender sends the data and it has also been received by the
receiver. The receiver then sends the acknowledgment but the
acknowledgment is received after the timeout period on the sender's side.
As the acknowledgment is received late, so acknowledgment can be
wrongly considered as the acknowledgment of some other data packet.
Kyung Hee
University
48
Sender is sending data before reaching receiver, what sender will do
The sender has to wait particular time whenever time is out ,the sender will send again same data to the reciever
Stop and Wait ARQ (Automatic Repeat Request
Above 3 problems are resolved by Stop and Wait ARQ (Automatic Repeat
Request) that does both error control and
1 .Time Out:
Kyung Hee
University
49
before reaching the sender The Acknowledgement will be lost,particular time is out the sender will do again send data to the receiver,after
2. Sequence Number (Data)
The receiver sending Acknowledgement before reaching the sender The
Acknowledgement will be lost,particular time is out the sender will do again
send data to the receiver,after the sender receive the acknowledgement
Kyung Hee
University
50
Kyung Hee
University
51
Working of Stop and Wait ARQ:
Working of Stop & Wait ARQ is almost like Stop & Wait
protocol, the only difference is that it includes some additional
components, which are:
Time out timer
Sequence numbers for data packets
Sequence numbers for feedbacks
Kyung Hee
University
52
1) Sender A sends a data frame or packet with sequence number 0
2) Receiver B, after receiving data frame, sends and
acknowledgement with sequence number 1 (sequence number of
next expected data frame or packet)
There is only one bit sequence number that implies that both
sender and receiver have buffer for one frame or packet only.
[available sequence numbers >= sender window size + receiver
window size]
Stop & Wait ARQ is a 1-bit sliding window protocol where the
size ofHee
Kyung the sender window as well as the receiver window is 1
University
53
[minimum number of sequence numbers required = sender
window size + receiver window size]
Thus, the minimum number of sequence numbers required
in Stop & Wait ARQ is 2, which are 0 and 1.
Kyung Hee
University
54
What is Go-Back-N ARQ?
In Go-Back-N ARQ, N is the sender's window size. Suppose we say that Go-
Back-3, which means that the three frames can be sent at a time before
expecting the acknowledgment from the receiver.
If we have five frames and the concept is Go-Back-3, which means that the
three frames can be sent, i.e., frame no 1, frame no 2, frame no 3 can be sent
before expecting the acknowledgment of frame no 1.
In Go-Back-N ARQ, the frames are numbered sequentially as Go-Back-N ARQ
sends the multiple frames at a time these numbers are known as the sequential
numbers.
The number of frames that can be sent at a time totally depends on the size of the sender's
window. So, we can say that 'N' is the number of frames that can be sent at a time before
receiving the acknowledgment from the receiver .
Kyung Hee
University
55
If the acknowledgment of a frame is not received within time period,
then all the frames available in the current window will be retransmitted.
Suppose we have sent the frame no 5, but we didn't receive the
acknowledgment of frame no 5, and the current window is holding three
frames, then these three frames will be retransmitted.
N is the sender's window size.
If the size of the sender's window is 4 then the sequence number
will be 0,1,2,3,0,1,2,3,0,1,2, 3 and so on.
Kyung Hee
University
56
Suppose there are a sender and a receiver, and let's assume that there
are 11 frames to be sent. These frames are represented as
0,1,2,3,4,5,6,7,8,9,10, and these are the sequence numbers of the
frames. Mainly, the sequence number is decided by the sender's
window size. But, for the better understanding, we took the running
sequence numbers, i.e., 0,1,2,3,4,5,6,7,8,9,10. Let's consider the
window size as 4, which means that the four frames can be sent at a
time before expecting the acknowledgment of the first frame.
Kyung Hee
University
57
Step 1: Firstly, the sender will send the first four frames to
the receiver, i.e., 0,1,2,3, and now the sender is expected to
receive the acknowledgment of the 0th frame.
Kyung Hee
University
58
Kyung Hee
University
59
After damage of data2 frame the reciever will not be accepted
data3,data4
The receiver will send NACK of data2,sender understood the data
is not recieved, what sender will do again send
data2,data3,data4,data5.
Problems-3: 1.Damage frame:
The Reciever recieve the damage or error frame then send NACK
Send NACK along with frame number
After NACK reciever discard of all frames
Kyung Hee
University
60
Lost frame:
Reciever checks the number of each frame
Just checks the sequence
Lost ACK:
If sender does not recieve ACK With in a time,it resend all the
frame
Kyung Hee
University
61
Selective repeat protocol
Selective repeat protocol, also called Selective Repeat ARQ (Automatic
Repeat reQuest), is a data link layer protocol that uses sliding window
method for reliable delivery of data frames. Here, only the erroneous or
lost frames are retransmitted, while the good frames are received and
buffered.
It uses two windows of equal size: a sending window that stores the
frames to be sent and a receiving window that stores the frames receive by
the receiver
Selective Repeat protocol provides for sending multiple frames depending upon
the availability of frames in the sending window, even if it does not receive
acknowledgement for any frame in the interim. The maximum number of frames
that can be sent depends upon the size of the sending window .
Kyung Hee
University
62
Selective Repeat protocol retransmitted only damage or lost of
frames, it retransmitted only that frames which is damage or lost
The reciever is capable of sorting the frame proper sequence
The sender must be capable of searching the frame for which
NACK has been recieved
Kyung Hee
University
63
Only selected has to be repeated to retransmit again you have to be
continue asuseually
Kyung Hee
University
64
The problem here is how to prevent the sender from flooding the
receiver.
A general solution to this problem is to have the receiver
provide some sort of feedback to the sender. The process
could be as follows: The receiver send an acknowledge
frame back to the sender telling the sender that the last
received frame has been processed and passed to the host;
permission to send the next frame is granted. The sender,
after having sent a frame, must wait for the acknowledge
frame from the receiver before sending another frame
Only selected has to be repeated to retransmit again you
have to be continue asusually
Kyung Hee
University
65
STOP & WAIT PROTOCOL
The sender sends one frame and waits for feedback from the
receiver. When the ACK arrives, the sender sends the next
frame
Kyung Hee
University
66
A SIMPLEX PROTOCOL FOR A NOISY CHANNEL
Inthis protocol the unreal "error free" assumption in protocol
2 is dropped. Frames may be either damaged or lost
completely. We assume that transmission errors in the frame
are detected by the hardware checksum. One suggestion is
that the sender would send a frame, the receiver would send
an ACK frame only if the frame is received correctly. If the
frame is in error the receiver simply ignores it; the
transmitter would time out and would retransmit it.
One fatal flaw with the above scheme is that if the ACK
frame is lost or damaged, duplicate frames are accepted at
the receiver without the receiver knowing it
Kyung Hee
University
67
Kyung Hee
University
68
Sliding Window Protocol
The sliding window is a technique for sending multiple frames at a
time. It controls the data packets between the two devices where
reliable and gradual delivery of data frames is needed. It is also used
in TCP (Transmission Control Protocol).
In this technique, each frame has sent from the sequence number. The
sequence numbers are used to find the missing data in the receiver
end. The purpose of the sliding window technique is to avoid duplicate
data, so it uses the sequence number.
The term sliding window refers to the imaginary boxes to hold frames.
Sliding window method is also known as windowing.
Kyung Hee
University
69
Working Principle
In these protocols, the sender has a buffer called the sending
window and the receiver has buffer called the receiving window.
The size of the sending window determines the sequence number
of the outbound frames. If the sequence number of the frames is
an n-bit field, then the range of sequence numbers that can be
assigned is 0 to 2𝑛−1. Consequently, the size of the sending
window is 2𝑛−1. Thus in order to accommodate a sending window
size of 2𝑛−1, a n-bit sequence number is chosen
if the sending window size is 4, then the sequence numbers will
be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on
Kyung Hee
University
70
Example
Suppose that we have sender window and receiver window each of
size 4. So the sequence numbering of both the windows will be
0,1,2,3,0,1,2 and so on. The following diagram shows the
positions of the windows after sending the frames and receiving
acknowledgments
Kyung Hee
University
71
Kyung Hee
University
72
Go – Back – N ARQ
Go – Back – N ARQ provides for sending multiple frames before
receiving the acknowledgment for the first frame. It uses the
concept of sliding window, and so is also called sliding window
protocol. The frames are sequentially numbered and a finite
number of frames are sent. If the acknowledgment of a frame is
not received within the time period, all frames starting from that
frame are retransmitted.
Selective Repeat ARQ:This protocol also provides for sending
multiple frames before receiving the acknowledgment for the first
frame. However, here only the erroneous or lost frames are
retransmitted, while the good frames are received and buffered.
Kyung Hee
University
73
Kyung Hee
University
74