0% found this document useful (0 votes)
39 views94 pages

Unit II BCN

The document discusses error detection and correction in data link control, emphasizing the importance of framing, reliable delivery, flow control, and error detection. It covers types of errors, redundancy, block coding, Hamming distance, and various error detection methods such as parity-check codes, cyclic codes, and checksums. Additionally, it explains framing techniques, including fixed-size and variable-size framing, and the concept of flow control in data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views94 pages

Unit II BCN

The document discusses error detection and correction in data link control, emphasizing the importance of framing, reliable delivery, flow control, and error detection. It covers types of errors, redundancy, block coding, Hamming distance, and various error detection methods such as parity-check codes, cyclic codes, and checksums. Additionally, it explains framing techniques, including fixed-size and variable-size framing, and the concept of flow control in data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Unit - II

Error
Detection,Correction
and
Data Link Control
Data Link Layer Services

Framing & Link access


Reliable delivery


Flow control


Error detection
Note

Data can be corrupted

during transmission.

Some applications require that

errors be detected and corrected.


ERROR DETECTION & CORRECTION

INTRODUCTION:

Let us first discuss some issues related, directly or indirectly, to error detection and correction.

Topics :

Types of Errors

Redundancy

Detection Versus Correction

Forward Error Correction Versus Retransmission

Coding
Note

In a single-bit error, only 1 bit in the data unit has changed.


Single-bit error
Note

A burst error means that 2 or more bits in the data unit have changed.
Burst error of length 8
Note

To detect or correct errors, we need to send extra (redundant) bits with data.
The structure of encoder and decoder
Note

Here, we concentrate on block codes; we leave convolution codes

to advanced texts.
Note

In modulo-N arithmetic, we use only the integers in the range 0 to N −1, inclusive.
XORing of two single bits or two words
BLOCK CODING

In block coding, we divide our message into blocks, each of k bits, called datawords. We add r

redundant bits to each block to make the length n = k + r. The resulting n-bit blocks are called

codewords.

Topics :

Error Detection

Error Correction

Hamming Distance

Minimum Hamming Distance


Datawords and codewords in block coding
Example

The 4B/5B block coding is a good example of this type of coding.

k n
In this coding scheme, k = 4 and n = 5. As we saw, we have 2 = 16 datawords and 2 = 32

codewords.

We saw that 16 out of 32 codewords are used for message transfer and the rest are either used for

other purposes or unused.


Error Detection
 Enough redundancy is added to detect an
error.
 The receiver knows an error occurred but
does not know which bit(s) is(are) in error.
 Has less overhead than error correction.
Process of error detection in block coding
Example
Let us assume that k = 2 and n = 3. Below table shows the list of datawords and codewords. Later, we will see how to derive a codeword

from a dataword.

Assume the sender encodes the dataword 01 as 011 and sends it to the receiver. Consider the following cases:

1. The receiver receives 011. It is a valid codeword. The receiver extracts the dataword 01 from it.

2. The codeword is corrupted during transmission, and 111 is received. This is not a valid codeword and is

discarded.

3.A The
code for error detection (Above Example )
codeword is corrupted during transmission, and 000 is received. This is a valid codeword. The receiver

incorrectly extracts the dataword 00. Two corrupted bits have made the error undetectable.
Note

An error-detecting code can detect

only the types of errors for which it is designed; other types of errors may remain

undetected.
Structure of encoder and decoder in error correction
Hamming distance

Note

The Hamming distance between two words is the number of


differences between corresponding bits.
Example

Let us find the Hamming distance between two pairs of words.

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

2. The Hamming distance d(10101, 11110) is 3 because


Note

The minimum Hamming distance is the smallest Hamming distance


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

Solution
We first find all Hamming distances.

The dmin in this case is 2.


Example

Find the minimum Hamming distance of the coding scheme .

Solution
We first find all the Hamming distances.

The dmin in this case is 3.


Example :

Find the minimum Hamming distance of the coding scheme .

d(010101,111000)

d(011101,101000)

d(010111,001000)

d(110100,111010)

d(010100,111011)

d(010001,110010)
Note

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

To guarantee correction of up to t errors in all cases, the minimum


Hamming distance in a block code
must be dmin = 2t + 1.
Example

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.
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) of two valid codewords creates

another valid codeword.

Topics :
Minimum Distance for Linear Block Codes
Some Linear Block Codes
Note

In a linear block code, the exclusive OR (XOR) of any two valid


codewords creates another valid codeword.
Note

A simple parity-check code is a single-bit error-detecting


code in which n = k + 1 with dmin = 2.

Even parity (ensures that a codeword has an even number of 1’s) and
odd parity (ensures that there are an odd number of 1’s in the
codeword)
Simple parity-check code C(5, 4)
Encoder and decoder for simple parity-check code
Note

A simple parity-check code can detect an odd number of errors.


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.


A CRC code with C(7, 4)
CRC encoder and decoder
Division in CRC encoder
Division in the CRC decoder for two cases
 Generate the CRC code for message
1101010101.Given generator Polynomial
g(x) = x4 + x2 + 1.
Using Polynomials
 We can use a polynomial to represent a binary
word.
 Each bit from right to left is mapped onto a power
term.
 The rightmost bit represents the “0” power term.
The bit next to it the “1” power term, etc.
 If the bit is of value zero, the power term is
deleted from the expression.
A polynomial to represent a binary word
CRC division using polynomials
Note

The divisor in a cyclic code is normally called the generator polynomial


or simply the generator.
Note

In a cyclic code,

If s(x) ≠ 0, one or more bits is corrupted.


If s(x) = 0, either

a. No bit is corrupted. or
b. Some bits are corrupted, but the
decoder failed to detect them.
Table 10.7 Standard polynomials

10.
10-5 CHECKSUM

The last error detection method we discuss here is called the checksum. The checksum is used

in the Internet by several protocols although not at the data link layer. However, we briefly

discuss it here to complete our discussion on error checking

Topics discussed in this section:


Idea
One’s Complement
Internet Checksum

10.
Example 10.18

Suppose our data is a list of five 4-bit numbers that we want to send to a
destination. In addition to sending these numbers, we send the sum of the
numbers. For example, if the set of numbers is (7, 11, 12, 0, 6), we send (7, 11,
12, 0, 6, 36), where 36 is the sum of the original numbers. The receiver adds
the five numbers and compares the result with the sum. If the two are the
same, the receiver assumes no error, accepts the five numbers, and discards
the sum. Otherwise, there is an error somewhere and the data are not
accepted.

10.
Example 10.19

We can make the job of the receiver easier if we send the negative (complement) of the sum, called
the checksum. In this case, we send (7, 11, 12, 0, 6, −36). The receiver can add all the numbers
received (including the checksum). If the result is 0, it assumes no error; otherwise, there is an error.

10.
Example 10.20

How can we represent the number 21 in one’s complement arithmetic using only four bits?

Solution
The number 21 in binary is 10101 (it needs five bits). We can wrap the leftmost bit and add it to the
four rightmost bits. We have (0101 + 1) = 0110 or 6.

10.
Example 10.21

How can we represent the number −6 in one’s complement arithmetic using only four bits?

Solution
In one’s complement arithmetic, the negative or complement of a number is found by inverting all
bits. Positive 6 is 0110; negative 6 is 1001. If we consider only unsigned numbers, this is 9. In other
words, the complement of 6 is 9. Another way to find the complement of a number in one’s
n
complement arithmetic is to subtract the number from 2 − 1 (16 − 1 in this case).

10.
Example 10.22

Let us redo Exercise 10.19 using one’s complement arithmetic. Figure 10.24 shows the process at
the sender and at the receiver. The sender initializes the checksum to 0 and adds all data items and
the checksum (the checksum is considered as one data item and is shown in color). The result is
36. However, 36 cannot be expressed in 4 bits. The extra two bits are wrapped and added with the
sum to create the wrapped sum value 6. In the figure, we have shown the details in binary. The
sum is then complemented, resulting in the checksum value 9 (15 − 6 = 9). The sender now sends
six data items to the receiver including the checksum 9.

10.
Example 10.22 (continued)

The receiver follows the same procedure as the sender. It adds all data items (including the
checksum); the result is 45. The sum is wrapped and becomes 15. The wrapped sum is
complemented and becomes 0. Since the value of the checksum is 0, this means that the data is not
corrupted. The receiver drops the checksum and keeps the other data items. If the checksum is not
zero, the entire packet is dropped.

10.
Figure 10.24 Example 10.22

10.
Note

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.

10.
Note

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.

10.
Example 10.23

Let us calculate the checksum for a text of 8 characters (“Forouzan”).


The text needs to be divided into 2-byte (16-bit) words. We use ASCII
(see Appendix A) to change each byte to a 2-digit hexadecimal
number. For example, F is represented as 0x46 and o is represented as
0x6F. Figure 10.25 shows how the checksum is calculated at the
sender and receiver sites. In part a of the figure, the value of partial
sum for the first column is 0x36. We keep the rightmost digit (6) and
insert the leftmost digit (3) as the carry in the second column. The
process is repeated for each column. Note that if there is any
corruption, the checksum recalculated by the receiver is not all 0s. We
leave this an exercise.

10.
Figure 10.25 Example 10.23

10.
11-1 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
Framing is the process of breaking the bit stream up into

discrete frames.

DLL prepares a frame for transport across the local media by

encapsulating it with a header and trailer.

The data link layer frame includes:

Data: The packet from the network layer.

Header: contains control information (addressing) and located at the beginning of

frame.
Fixed-size Framing:

ӿ In fixed size framing, there is no need for defining the

boundaries of the frames.

ӿ The size of frame itself can be used as a delimiter.

Variable-size Framing:

ӿ In variable-size framing, we need a way to define the end of


Figure 11.1 A frame in a character-oriented protocol

A character-oriented approach:

Here, data are 8-bit characters from a coding system such as ASCII.

The header and trailer are also multiples of 8-bits.

To separate one frame from next, an 8-bit flag is added at the end and beginning of the frame.

The flag, is composed of protocol-dependent special characters, which signals the start and end

of a frame.

A byte-stuffing strategy is used in character-oriented framing.


Byte-Stuffing(Character-Stuffing)

In this method, Frame starts & end with a special character that mark the beginning &

end of frame.

Each character begins with the ASCII character sequence DLE STX(data link escape start

of text ) and end with ASCII character sequence DLE ETX (data link escape end of text).

A B C D Data From Network Layer


Figure 11.2 Byte stuffing and unstuffing
Note

Byte stuffing is the process of adding 1


extra byte whenever there is a flag or
escape character in the text.
A bit-oriented approach:

In this method, each frame begins & ends with a special bit pattern

01111110 called flags.

There for each frame starts with 01111110 & also ends with

01111110.
Bit-Stuffing:

01010011111101 Data from network layer

01111110 01010011111 0 101 01111110

Starting flag Shifted Bit Ending Flag Bit

Stuffing Performed By Data Link layer


Figure 11.3 A frame in a bit-oriented protocol
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.
Figure 11.4 Bit stuffing and unstuffing
Flow Control
 Flow control coordinates the amount of data that can be
sent before receiving acknowledgement
 It is one of the most important functions of data link
layer.
 Flow control is a set of procedures that tells the sender
how much data it can transmit before it must wait for an
acknowledgement from the receiver.
 Receiver has a limited speed at which it can process
incoming data and a limited amount of memory in which
to store incoming data.
 Receiver must inform the sender before the limits are
reached and request that the transmitter to send fewer
frames or stop temporarily.
 Since the rate of processing is often slower than the rate
of transmission, receiver has a block of memory (buffer)
for storing incoming data until they are processed.
Error Control
 Error control includes both error detection
and error correction.
 It allows the receiver to inform the sender
if a frame is lost or damaged during
transmission and coordinates the
retransmission of those frames by the
sender.
 Error control in the data link layer is based
on automatic repeat request (ARQ).
Whenever an error is detected, specified
frames are retransmitted.
Error and Flow Control
Mechanisms
 Stop-and-Wait
 Go-Back-N ARQ
 Selective-Repeat ARQ
 Sender keeps a copy of the last frame until
Stop-and-Wait it receives an acknowledgement.
 For identification, both data frames and
acknowledgements (ACK) frames are
numbered alternatively 0 and 1.
 Sender has a control variable (S) that holds
the number of the recently sent frame. (0
or 1)
 Receiver has a control variable ® that
holds the number of the next frame
expected (0 or 1).
 Sender starts a timer when it sends a
frame. If an ACK is not received within a
allocated time period, the sender assumes
that the frame was lost or damaged and
resends it
 Receiver send only positive ACK if the
frame is intact.
 ACK number always defines the number
of the next expected frame
Stop-and-Wait ARQ, lost ACK
frame
 When a receiver
receives a damaged
frame, it discards it and
keeps its value of R.
 After the timer at the
sender expires, another
copy of frame 1 is sent.
Stop-and-Wait, lost ACK
frame
 If the sender receives
a damaged ACK, it
discards it.
 When the timer of the
sender expires, the
sender retransmits
frame 1.
 Receiver has already
received frame 1 and
expecting to receive
frame 0 (R=0).
Therefore it discards
the second copy of
frame 1.
Stop-and-Wait, delayed ACK
frame The ACK can be

delayed at the receiver


or due to some
problem
 It is received after the
timer for frame 0 has
expired.
 Sender retransmitted a
copy of frame 0.
However, R =1 means
receiver expects to see
frame 1. Receiver
discards the duplicate
frame 0.
 Sender receives 2
ACKs, it discards the
second ACK.
Piggybacking
 A method to combine
a data frame with
ACK.
 Station A and B both
have data to send.
 Instead of sending
separately, station A
sends a data frame
that includes an ACK.
 Station B does the
same thing.
 Piggybacking saves
bandwidth.
Disadvantage of Stop-and-Wait
 In stop-and-wait, at any point in time, there is
only one frame that is sent and waiting to be
acknowledged.
 This is not a good use of transmission medium.
 To improve efficiency, multiple frames should
be in transition while waiting for ACK.
 Two protocol use the above concept,

Go-Back-N ARQ

Selective Repeat ARQ
Go-Back-N ARQ
 We can send up to W frames before
worrying about ACKs.
 We keep a copy of these frames until the
ACKs arrive.
 This procedure requires additional features
to be added to Stop-and-Wait ARQ.
Sequence Numbers
 Frames from a sender are numbered sequentially.
 We need to set a limit since we need to include the
sequence number of each frame in the header.
 If the header of the frame allows m bits for
sequence number, the sequence numbers range from
0 to 2 m – 1. for m = 3, sequence numbers are: 1, 2,
3, 4, 5, 6, 7.
 We can repeat the sequence number.
 Sequence numbers are:
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, …
Sender Sliding Window
• At the sending site, to hold the
outstanding frames until they are
acknowledged, we use the concept of a
window.

• m
The size of the window is at most 2 -1
where m is the number of bits for the
sequence number.
• Size of the window can be variable, e.g.
TCP.
• The window slides to include new unsent
frames when the correct ACKs are received
Receiver Sliding Window
• Size of the window at the receiving site
is always 1 in this protocol.
• Receiver is always looking for a specific
frame to arrive in a specific order.
• Any frame arriving out of order is
discarded and needs to be resent.
• Receiver window slides as shown in fig.
Receiver is waiting for frame 0 in part a.
Control Variables
• Sender has 3 variables: S, SF, and SL
• S holds the sequence number of recently sent frame
• SF holds the sequence number of the first frame
• SL holds the sequence number of the last frame
• Receiver only has the one variable, R, that holds the sequence number of the frame it expects to receive. If the
seq. no. is the same as the value of R, the frame is accepted, otherwise rejected.
Acknowledgement
 Receiver sends positive ACK if a frame arrived safe and in order.
 If the frames are damaged/out of order, receiver is silent and
discard all subsequent frames until it receives the one it is
expecting.
 The silence of the receiver causes the timer of the unacknowledged
frame to expire.
 Then the sender resends all frames, beginning with the one with
the expired timer.
 For example, suppose the sender has sent frame 6, but the timer for
frame 3 expires (i.e. frame 3 has not been acknowledged), then the
sender goes back and sends frames 3, 4, 5, 6 again. Thus it is
called Go-Back-N-ARQ
 The receiver does not have to acknowledge each frame received, it
can send one cumulative ACK for several frames.
Go-Back-N ARQ, normal operation
• The sender keeps track of the outstanding frames and updates the variables and windows as the
ACKs arrive.
Go-Back-N ARQ, lost frame
• Frame 2 is lost
• When the receiver receives
frame 3, it discards frame 3
as it is expecting frame 2
(according to window).
• After the timer for frame 2
expires at the sender site,
the sender sends frame 2
and 3. (go back to 2)
Go-Back-N ARQ, damaged/lost/delayed
ACK
• If an ACK is damaged/lost, we can have two situations:
• If the next ACK arrives before the expiration of any timer, there is no need for retransmission of
frames because ACKs are cumulative in this protocol.
• If ACK1, ACK2, and ACk3 are lost, ACK4 covers them if it arrives before the timer expires.
• If ACK4 arrives after time-out, the last frame and all the frames after that are resent.
• Receiver never resends an ACK.
• A delayed ACK also triggers the resending of frames
Go-Back-N ARQ, sender window size
• m m
Size of the sender window must be less than 2 . Size of the receiver is always 1. If m = 2, window size = 2 – 1 = 3.
• Fig compares a window size of 3 and 4.

st
Accepts as the 1
frame in
the next
cycle-an
error
Selective Repeat ARQ, sender and receiver windows
• Go-Back-N ARQ simplifies the process at the receiver site. Receiver only keeps track of only one variable, and there is no need to
buffer out-of-order frames, they are simply discarded.
• However, Go-Back-N ARQ protocol is inefficient for noisy link. It bandwidth inefficient and slows down the transmission.
• In Selective Repeat ARQ, only the damaged frame is resent. More bandwidth efficient but more complex processing at receiver.
• It defines a negative ACK (NAK) to report the sequence number of a damaged frame before the timer expires.
Selective Repeat ARQ, lost frame • Frames 0 and 1 are
accepted when received
because they are in the
range specified by the
receiver window. Same for
frame 3.
• Receiver sends a NAK2 to
show that frame 2 has not
been received and then
sender resends only frame
2 and it is accepted as it is
in the range of the
window.
Selective Repeat ARQ, sender window size
• m m
Size of the sender and receiver windows must be at most one-half of 2 . If m = 2, window size should be 2 /2 = 2. Fig compares a
window size of 2 with a window size of 3. Window size is 3 and all ACKs are lost, sender sends duplicate of frame 0, window of the
st
receiver expect to receive frame 0 (part of the window), so accepts frame 0, as the 1 frame of the next cycle – an error.

You might also like