Chapter 10
Error Detection
and Correction
• Types of Errors
• Detection
• Correction
Basic concepts
Networks must be able to transfer data from
one device to another with complete accuracy.
Data can be corrupted during transmission.
For reliable communication, errors 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.
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.
Error detection/correction
• Error detection
– Check if any error has occurred
– Don’t care the number of errors
– Don’t care the positions of errors
• Error correction
– Need to know the number of errors
– Need to know the positions of errors
– More difficult
10.11
Figure 10.3 The structure of encoder and decoder
To detect or correct errors, we need to send extra (redundant) bits with data.
10.12
Modular Arithmetic
• Modulus N: the upper limit
• In modulo-N arithmetic, we use only the
integers in the range 0 to N −1, inclusive.
• If N is 2, we use only 0 and 1
• No carry in the calculation (sum and
subtraction)
10.13
Figure 10.4 XORing of two single bits or two words
10.14
BLOCK CODING
• Message is divided into blocks each of k bits
called datawords.
• Adding r redundant bits to each block to make
the length
• n=k+r ; n=codeword
• Combination of datawords = 2^k
• Combination of codewords =2^n where n>k
• Block coding is one to one process
• 2^n -2^k codewords are not used.
Figure 10.5 Datawords and codewords in block coding
10.16
Figure 10.6 Process of error detection in block coding
10.17
A code for error detection
10.18
Structure of encoder and decoder in error correction
10.19
Table 10.2 A code for error correction (Example 10.3)
10.20
Hamming Distance
• The Hamming distance between two words is
the number of differences between
corresponding bits.
• The minimum Hamming distance is the
smallest Hamming distance between
all possible pairs in a set of words.
10.21
We can count the number of 1s in the Xoring of two words
1. The Hamming distance d(000, 011) is 2 because
2. The Hamming distance d(10101, 11110) is 3 because
10.22
Find the minimum Hamming distance of the coding scheme
Solution
We first find all Hamming distances.
The
10.23 dmin in this case is 2.
Find the minimum Hamming distance of the coding scheme
Solution
We first find all the Hamming distances.
The
10.24 dmin in this case is 3.
Minimum Distance for
Error Detection
• To guarantee the detection of upto s errors in
all cases, the minimum hamming distance in a
block code must be dmin = s + 1.
10.25
Example 10.7
•The minimum Hamming distance for our first code
scheme (Table 10.1) 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.
10.26
Example 10.8
•Table 10.2 has dmin = 3. This code can detect up to two
errors. When any of the valid codewords is sent, two errors
create a codeword which is not in the table of valid
codewords.
10.27
Figure 10.8 Geometric concept for finding dmin in error detection
10.28
Figure 10.9 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.
10.29
Example 10.9
A code scheme has a Hamming distance dmin = 4. What is
the error detection and correction capability of this
scheme?
Solution
This code guarantees the detection of up to three errors
(s = 3), but it can correct up to one error. In other words,
if this code is used for error correction, part of its capability
is wasted. Error correction codes need to have an odd
minimum distance (3, 5, 7, . . . ).
10.30
10-3 LINEAR BLOCK CODES
•Almost all block codes used today belong to a
subset called linear block codes.
•A linear block code is a code in which the
exclusive OR (addition modulo-2 / XOR) of two
valid codewords creates another valid
codeword.
10.31
Example 10.10
Let us see if the two codes we defined in Table 10.1 and
Table 10.2 belong to the class of linear block codes.
1. The scheme in Table 10.1 is a linear block code
because the result of XORing any codeword with any
other codeword is a valid codeword. For example, the
XORing of the second and third codewords creates the
fourth one.
2. The scheme in Table 10.2 is also a linear block code.
We can create all four codewords by XORing two
other codewords.
10.32
Minimum Distance for
Linear Block Codes
• The minimum hamming distance is the number of 1s in the nonzero
valid codeword with the smallest number of 1s
10.33
Linear Block Codes
• Simple parity-check code
• Hamming codes
10.34
Table 10.3 Simple parity-check code C(5, 4)
•A simple parity-check code is a single-bit
error-detecting code in which n = k + 1 with dmin = 2.
•The extra bit (parity bit) is to make the total number
of 1s in the codeword even
•A simple parity-check code can detect an odd
10.35
number of errors.
Figure 10.10 Encoder and decoder for simple parity-check code
10.36
➢Encoder uses a generator that takes 4-bit dataword(a0 a1 a2 a3)
and generates a parity bit r0.
➢So, a 5-bit code is generated.
➢Parity bit is added to make the number of 1s in the codeword
even.
➢r0=a3+a2+a1+a0 (modulo-2)
➢At the receiver, addition is done all over 5 bits.
➢The result is called syndrome.
➢It is one bit.
➢Syndrome is 0→ number of 1s is even
➢Syndrome is 1→ number of 1s is odd
➢S0=b3+b2+b1+b0+q0 (modulo-2)
Example 10.12
Let us look at some transmission scenarios. Assume the
sender sends the dataword 1011. The codeword created
from this dataword is 10111, which is sent to the receiver.
We examine five cases:
1. No error occurs; the received codeword is 10111. The
syndrome is 0. The dataword 1011 is created.
2. One single-bit error changes a1 . The received
codeword is 10011. The syndrome is 1. No dataword
is created.
3. One single-bit error changes r0 . The received codeword
is 10110. The syndrome is 1. No dataword is created.
10.38
Example 10.12 (continued)
4. An error changes r0 and a second error changes a3 .
The received codeword is 00110. The syndrome is 0.
The dataword 0011 is created at the receiver. Note that
here the dataword is wrongly created due to the
syndrome value.
5. Three bits—a3, a2, and a1—are changed by errors.
The received codeword is 01011. The syndrome is 1.
The dataword is not created. This shows that the simple
parity check, guaranteed to detect one single error, can
also find any odd number of errors.
A parity-check code can detect an odd number
of10.39errors.
Figure 10.11 Two-dimensional parity-check code
Two-D parity check can detect upto 3 errors.
10.40
Figure 10.11 Two-dimensional parity-check code
10.41
HAMMING CODES
10-4 CYCLIC CODES
Cyclic codes are special linear block codes with one
extra property. In a cyclic code, if a codeword is
cyclically shifted (rotated), the result is another
codeword.
For eg- if 1011000 is a codeword and if it is left shifted then
0110001 is also a codeword.
10.43
Table 10.6 A CRC code with C(7, 4)
10.44
Figure 10.14 CRC encoder and decoder
10.45
➢In the encoder, the dataword has k bits.
➢Codeword has n bits.
➢Size of dataword is augmented by adding n-k 0s to the right-
hand side of the word.
➢Size of divisor is n-k+1; predefined and agreed upon.
➢Generator divides the augmented dataword by the
divisor(modulo-2 division).
➢Quotient is discarded and the remainder(r2r1r0) is appended
to the dataword to create the codeword.
➢Decoder receives the codeword and a copy of all n bits is fed
to the checker which is a replica of the generator.
➢The remainder produced by the checker is a syndrome of n-k
bits which is fed to decision logic analyzer.
➢Syndrome bits → all 0s (no error) else discarded.
POLYNOMIALS
➢A pattern of 0 and 1 can be represented as a polynomial
with coefficients of 0 and 1.
➢The power of each term shows position of the bit.
➢Coefficient shows the value of the bit.
➢Degree of polynomial is highest power in it.
➢NOTE-Degree is one less than the number of bits in the
pattern.
Figure 10.21 A polynomial to represent a binary word
10.48
Chapter 11
11.1 DLC SERVICES
11.1.1 Framing
11.1.2 Flow and Error Control
11.1.3 Connectionless and Connection-Oriented
11.2 DATA-LINK LAYER PROTOCOLS
11.2.1 Simple Protocol
11.2.2 Stop-and-Wait Protocol
11.2.3 Piggybacking
11.3 HDLC
11.3.1 Configurations and Transfer Modes
11.3.2 Framing
49
11.1 DLC SERVICES
• The data-link layer is divided into two sub-layers
• Logical Link Control (LLC)/DLC
• Media Access Control (MAC)
• The LLC sub-layer handles error control, flow control,
framing, and MAC sub-layer addressing.
• The MAC sub-layer is the lower of the two sub-layers of
the Data Link Layer.
• MAC handles access to shared media, such as Token
passing or Ethernet.
50
11.1.1 Framing
• It is process of wrapping data with certain info before
sending out.
• Frame size can be variable or fixed.
• In fixed-size framing, there is no need of delimiter.
• In variable-size framing, there is need of delimiter.
• This can be done using two approaches
– Character-Oriented Approach
– Bit-Oriented Approach 51
11.1.1 Framing contd..
• Character-Oriented Framing(or Byte-Oriented):
– In COF framing, data carried 8-bit characters from a coding system
such as ASCII.
• A frame typically consists of
– Data from the upper layer
– Flag: indication for start and end of a frame, composed of special
characters (8-bit)
– Header: source/destination addresses, as well as other control
information
– Trailer: error detection/correction code
52
Byte Stuffing
• Process of adding extra byte whenever there is an escape
or a flag character in the data
53
Bit-Oriented Framing
– In bit-oriented framing, data is transmitted as a sequence
of bits that can be interpreted in the upper layers.
– Need a delimiter to separate one frame from the other.
• Each frame begins and ends with special bit pattern called flag
byte (01111110).
54
Bit Stuffing
• Process of adding extra bit to ensure flag sequence does not appear in the data.
• When sender’s DLL finds 5 consecutive 1’s in data stream, stuffs 0.
• When receiver sees 5 1’s followed by 0, de-stuffs.
01111110
55
Flow Control and Error Control
• Flow control
– It is the process of managing the rate of data transmission
– It prevent a fast sender from overwhelming a slow receiver.
• Error control
– It is the process of detecting and correcting data frames that
have been corrupted or lost during transmission.
– Retransmission of frames whenever error is detected or frame is
lost.
– Allows receiver to inform sender of lost or duplicate frames
56
FLOW CONTROL AT THE DATA LINK
LAYER
• One of the solutions is normally to use two buffers; one at the sending
data-link layer and the other at the receiving data-link layer.
• When the buffer of the receiving data-link layer is full, it informs the
sending data-link layer to stop pushing frames.
57
11.1.3 Connectionless and Connection-Oriented
• A DLC protocol can be either connectionless or
connection-oriented.
• Connectionless Protocol
• No connection is established between two nodes.
• Each frame is independent.
• There is no connection between frames.
• Frames are not numbered
• Connection-Oriented Protocol
• A logical connection must be established between the two nodes( setup, data
transfer and teardown)
• The frames are numbered and sent in order
58
11.2 DATA-LINK LAYER PROTOCOLS
• Data link layer have four protocols
• Simple,
• Stop-and-Wait,
• Go-Back-N, and
• Selective-Repeat - that deal with flow and error control
• First two protocols still are used at the data-link layer
59
11.2.1 Simple Protocol
• A simple protocol with neither flow nor error control.
• We assume that the receiver can immediately handle any frame it
receives.
• The receiver can never be overwhelmed with incoming frames.
• The DLL sender gets a packet from its network layer, makes a frame out of it, and
sends the frame.
• The DLL at the receiver receives a frame from the link, extracts the packet from the
frame, and delivers the packet to its network layer.
• The data-link layers of the sender and receiver provide transmission services for their
network layers.
60
FINITE STATE MACHINE FOR THE
SIMPLE PROTOCOL
61
Simple Protocol
The sender sends frames one after another without even thinking
about the receiver.
• It is very simple.
• The sender sends frames one after another without even
thinking about the receiver.
62
11.2.2 Stop-and-Wait Protocol
• It uses both flow and error control.
• The sender will send one frame at a time.
• The sender will stop and wait for the acknowledgment (ACK) from
the receiver.
• After receiving ACK sender send the next packet to receiver.
• Receiver responds with an ACK when it successfully receives a frame
• Both Data and ACK frames must be numbered
• When sender does not receive an ACK within certain time, it assumes
frame is lost, then retransmits the same frame.
63
11.2.2 Stop-and-Wait Protocol
64
11.2.3 Piggybacking
• The two protocols discussed are designed for
unidirectional communication, in which data is flowing
only in one direction although the acknowledgment may
travel in the other direction.
• However, to make the communication more efficient, the
data in one direction is piggybacked with the
acknowledgment in the other direction.
• In other words, when node A is sending data to node B,
Node A also acknowledges the data received from node
B.
• Data and acknowledgement are sent in a single frame is
called Piggybacking.
• Piggybacking saves bandwidth.
65
11.2.3 Piggybacking
66
11.3 HDLC
• High-level Data Link Control
• HDLC is a bit-oriented protocol for communication
over point-to-point and multipoint links.
It implements the Stop-and-Wait protocol.
• HDLC provides two common transfer modes
– Normal Response Mode (NRM)
– Asynchronous Balanced Mode (ABM)
67
Normal Response Mode (NRM)
• In NRM, the configuration is unbalanced.
• Have one primary station and multiple secondary stations.
• A primary station can send commands; a secondary station can only
respond.
• Used in both point-to-point and multi-point link
68
Asynchronous Balance Mode (ABM)
• In ABM, the configuration is balanced
• Supports only point-to-point links
• Each station is both primary and secondary
69
11.3.2 HDLC Frames
• HDLC defines three types of frames:
– Information frames (I-frames)
– Supervisory frames (S-frames)
– Unnumbered frames (U-frames)
• Each type of frame serves as an envelope for the transmission
of a different type of message.
• I-frames are used to data-link user data and control information
relating to user data (piggybacking).
• S-frames are used only to transport control information.
• U-frames are reserved for system management. Information
carried by U-frames is intended for managing the link itself.
70
11.3.2 HDLC Frames
• HDLC frame may contain up to six fields
• A beginning flag field, an address field, a control field, an information field, a
frame check sequence (FCS) field, and an ending flag field. In multiple-
frame transmissions, the ending flag of one frame
can serve as the beginning flag of the next frame.
Information frame (I-frame)
Supervisory frame (S-frame)
Unnumbered frame (U-frame)
Frame Check Sequence
(error detection code)
71
11.3.2 HDLC Frames
Flag field.
– This field contains synchronization pattern 01111110, which identifies both the beginning and
the end of a frame.
Address field.
– This field contains the address of the secondary station.
– If a primary station created the frame, it contains a TO ADDRESS.
– If a secondary station creates the frame, it contains a from address.
– The address field can be one byte or several bytes long, depending on the needs of the network.
Control field.
– The control field is one or two bytes used for flow and error control.
Information field.
– The information field contains the user’s data from the network layer or management
information.
– Its length can vary from one network to another.
FCS field.
– The frame check sequence (FCS) is the HDLC error detection field.
– It can contain either a 2- or 4-byte CRC.
72
Control field format for the different
frame types
• The control field determines the type of frame and
defines its functionality.
• The format is specific for the type of frame, as shown
below.
73
Control Field for I-Frames
• I-frames carry user data from the network layer
• Can carry flow- and error-control information (piggybacking)
• 0, 1 bit, means the frame is an I-frame
• N(S), 3 bits, define the sequence number (0 to 7) of the frame
• N(R), 3 bits, acknowledgment number when piggybacking is used
• P/F field is a single bit with a dual purpose
• when it is set (bit = 1) and can mean poll or final
• poll when the frame is sent by a primary station to a secondary
• final when the frame is sent by a secondary to a primary
74
Control Field for S-Frames
• Receive ready (RR).
– 00 is code
– This kind of frame acknowledges the receipt of a safe and sound frame or group of
frames.
– N(R) field defines the acknowledgment number.
• Receive not ready (RNR).
– 10 is code, It gives acknowledgment of frames
– It also announces that the receiver is busy and cannot receive more frames ask
sender to slow down.
• Reject (REJ).
– 01 is code, this is a NAK frame which can be used in Go-Back-N-ARQ
• Selective reject (SREJ).
– 11 is code, This Nak is used in Selective Repeat ARQ
75
Control Field for U-Frames
• Unnumbered frames are used to exchange session management
and control information
• Do not contain N(S) or N(R) in control field.
• U-frame contains two code fields, one two bit and other three bit.
• These five bits can create upto 32 different U-frames.
• Purpose of P/F bit is same
76
U-Frame Codes
77