Data Link Layer
1)Introduction
2)Error Detection and
Correction
1
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
OSI
Application
Presentation
Session
Transport
Network
Datalink
Physical
Responsibility of Data Link Layer:
PROVIDE SERVICE TO NETWORK LAYER
OSI
Application
LOGICAL LINK
Presentation
Session sublayer
Transport Framing
Network
Error control
Data Link
Flow control
Physical
Transmission/reception of MEDIA ACCESS
frames sublayer
Data Link Layer (DLL)
OSI
Application
Presentation Framing
Session
Group the physical layer bit
Transport
stream into units called frames.
Network
Data Link Note that frames are nothing
Physical more than ``packets'' or
``messages''. By convention,
we'll use the term ``frames''
when discussing DLL packets.
Data Link Layer (DLL)
OSI
Application
Presentation Flow Control
Session Prevent a fast sender from
Transport overwhelming a slower
Network receiver.
Datalink For example, a
Physical supercomputer can easily
generate data faster than a
PC can consume it.
Data Link Layer (DLL)
OSI
Application
Presentation Error Detection
Session
Sender checksums the
Transport
frame and sends checksum
Network together with data.
Data Link
The checksum allows the
Physical receiver to determine when
a frame has been damaged
in transit.
Data Link Layer (DLL)
OSI
Application
Presentation Error Control
Session Receiver recomputes the
Transport checksum and compares it
Network with the received value.
Data link If they differ, an error has
Physical
occurred and the frame is
discarded.
DLL Type of service
– Unacknowledged connectionless
• No attempt to recover lost frame
• Suited for low error rate networks or for fault tolerant
applications such as voice
– Acknowledged connectionless
• Each frame is acknowledged by the receiver
• Suited for unreliable channels
– Acknowledged connection-oriented
• Ensures that
– All frames are received
– Each is received exactly once
The service is accomplished using SIMPLEX, HALF
DUPLEX OR FULL DUPLEX channels.
Types of Services
Error Detection and Correction
Note
Data can be corrupted
during transmission.
Some applications require that
errors be detected and corrected.
Some applications can tolerate a small level of error.
For example, random errors in audio or video
transmissions may be tolerable, but when we transfer
text, we expect a very high level of accuracy.
Single Bit Errors
Note
In a single-bit error, only 1 bit in the data
unit has changed.
Single-bit errors are the least likely type
of error in serial data transmission.
10.12
Figure 1 Single-bit error
Let data sent at 1 Mbps.
This means that each bit lasts only 1/1,000,000 s,or 1 µs(
or a single-bit error to occur, the noise must have a
duration of only 1µs), which is very rare;
Noise normally lasts much longer than this.
Burst Errors
Note
A burst error means that 2 or more bits
in the data unit have changed.
A burst error 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.
10.14
Figure 2 Burst error of length 8
A burst error is more likely to occur than a single-bit
error.
The duration of noise is normally longer than the
duration of 1 bit, which means that when noise affects
data, it affects a set of bits.
The number of bits affected depends on the data rate and
duration of noise.
For example, if we are sending data at 1kbps, a noise of
11100 s can affect 10 bits; if we are sending data at 1Mbps,
the same noise can affect 10,000 bits.
Redundancy
Note
To detect or correct errors, we need to
send extra (redundant) bits with data.
Redundancy is achieved through various coding
schemes. The sender adds redundant bits through a
process that creates a relationship between the redundant
bits and the
actual data bits.
The receiver checks the relationships between the two
sets of bits to detect or correct the errors.
The ratio of redundant bits to the data bits and the
robustness of the process are important factors in any
coding scheme.
Figure 3 The structure of encoder and decoder
Note
We can divide coding schemes into two
broad categories: block coding and
convolution coding.
Here, we will concentrate on block
coding
Modulo-N arithmetic
Note
In modulo-N arithmetic, we use only the
integers in the range 0 to N −1,
inclusive.
Addition and subtraction in modulo arithmetic are
simple.
There is no carry when you add two digits in a column.
There is no carry when you subtract one digit from
another in a column.
Figure 4 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.
10.24
With k bits, we can create a combination of 2k
datawords; with n bits, we can create a combination of 2n
codewords.
Since n > k, the number of possible codewords is larger
than the number of possible datawords.
The block coding process is one-to-one; the same
dataword is always encoded as the same codeword.
This means that we have 2n - 2k codewords that are not
used.
We call these codewords invalid or illegal.
Figure 5 Datawords and codewords in block coding
Error Detection
How can errors be detected by using block coding?
If the following two conditions are met, the receiver
can detect a change in the original codeword.
1. The receiver has (or can find) a list of valid
codewords.
2. The original codeword has changed to an invalid
one.
Figure 6 Process of error detection in block coding
10.28
The sender creates codewords out of datawords by using
a generator that applies the rules and procedures of
encoding.
Each codeword sent to the receiver may change during
transmission.
If the received codeword is the same as one of the valid
codewords, the word is accepted; the corresponding
dataword is extracted for use.
If the received codeword is not valid, it is discarded.
However, if the codeword is corrupted during transmission
but the received word still matches a valid codeword, the
error remains undetected.
This type of coding can detect only single errors. Two or
more errors may remain undetected.
Example
Let us assume that k = 2 and n = 3. Table 1 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.
Example (continued)
2. The codeword is corrupted during transmission, and
111 is received. This is not a valid codeword and is
discarded.
3. The 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.
Table 1 A code for error detection
Note
An error-detecting code can detect
only the types of errors for which it is
designed; other types of errors may
remain undetected.
Error Correction
Error correction is much more difficult
than error detection.
In error detection, the receiver needs to
know only that the received codeword is
invalid; in error correction the receiver
needs to find (or guess) the original
codeword sent.
We can say that we need more
redundant bits for error correction than
for error detection.
Figure 7 Structure of encoder and decoder in error correction
Example
Let us add more redundant bits to previous Example to
see if the receiver can correct an error without knowing
what was actually sent. We add 3 redundant bits to the 2-
bit dataword to make 5-bit codewords. Table 2 shows the
datawords and codewords. Assume the dataword is 01.
The sender creates the codeword 01011. The codeword is
corrupted during transmission, and 01001 is received.
First, the receiver finds that the received codeword is not
in the table. This means an error has occurred. The
receiver, assuming that there is only 1 bit corrupted, uses
the following strategy to guess the correct dataword.
10.36
Example (continued)
1. Comparing the received codeword with the first
codeword in the table (01001 versus 00000), the
receiver decides that the first codeword is not the one
that was sent because there are two different bits.
2. By the same reasoning, the original codeword cannot
be the third or fourth one in the table.
3. The original codeword must be the second one in the
table because this is the only one that differs from the
received codeword by 1 bit. The receiver replaces
01001 with 01011 and consults the table to find the
dataword 01.
10.37
Table 2 A code for error correction (Example 3)
Hamming Code
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Note
The Hamming distance between two
words is the number of differences
between corresponding bits.
10.
The Hamming distance between two words (of the
same size) is the number of differences between the
corresponding bits.
We show the Hamming distance between two words
x and y as d(x, y).
The Hamming distance can easily be found if wc
apply the XOR operation on the two words and count
the number of Is in the result.
Note that the Hamming distance is a value greater
than zero.
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
10.
Note
The minimum Hamming distance is the
smallest Hamming distance between
all possible pairs in a set of words.
10.
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.
10.
Example 7
The minimum Hamming distance for our first code
scheme (Table 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.
Example 8
Our second block code scheme (Table 2) has dmin
= 3. This code can detect up to two errors. Again,
we see that when any of the valid codewords is
sent, two errors create a codeword which is not in
the table of valid codewords. The receiver cannot
be fooled.
However, some combinations of three errors
change a valid codeword to another valid
codeword. The receiver accepts the received
codeword and the errors are undetected.
10.
Figure 8 Geometric concept for finding dmin in error detection
10.
M inim um Distance for Error Detection
Let us assume that the sent codeword x is at the
center of a circle with radius s.
All other received codewords that are created by 1
to s errors are points inside the circle or on the
perimeter of the circle.
All other valid codewords must be outside the circle.
M inim um Distance for Error Correction
We assume that each valid codeword has a circular
territory with a radius of ‘ t ’ and that the valid
codeword is at the center.
For example, suppose a codeword ‘x’ is corrupted by
‘ t ’ bits or less. Then this corrupted codeword is
located either inside or on the perimeter of this
circle.
If the receiver receives a codeword that belongs to
this territory, it decides that the original codeword is
the one at the center.
Note that we assume that only up to ‘ t ’ errors have
occurred; otherwise, the decision is wrong.
Figure 9 Geometric concept for finding dmin in error correction
10.
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.
10.
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. 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.
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.
10.
Example
Let us see if the two codes we defined in Table 1 and Table
2 belong to the class of linear block codes.
1. The scheme in Table 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 2 is also a linear block code.
We can create all four codewords by XORing two
other codewords.
10.
Example
In our first code (Table 1), the numbers of 1s in the
nonzero codewords are 2, 2, and 2. So the
minimum Hamming distance is dmin = 2. In our
second code (Table 2), the numbers of 1s in the
nonzero codewords are 3, 3, and 4. So in this code
we have dmin = 3.
10.
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)
10.
In this code, a k-bit dataword is changed to an n-bit
codeword where n = k + 1.
The extra bit,called the parity bit, is selected to make
the total number of 1s in the codeword even.
The minimum Hamming distance for this category is
dmin =2, which means that the code is a single-bit
error-detecting code; it cannot correct any error.
Table 3 Simple parity-check code C(5, 4)
10.
Figure 10 Encoder and decoder for simple parity-check code
10.
Example
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.
Example (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.
10.
Note
A simple parity-check code can detect an
odd number of errors.
10.
A better approach is the two-dimensional parity
check.
In this method, the dataword is organized in a table
(rows and columns). In Figure, the data to be sent,
five 7-bit bytes, are put in separate rows.
For each row and each column, 1 parity-check bit is
calculated.
The whole table is then sent to the receiver, which
finds the syndrome for each row and each column.
As Figure shows, the two-dimensional parity check
can detect up to three errors that occur anywhere in
the table (arrows point to the locations of the created
nonzero syndromes).
However, errors affecting 4 bits may not be detected.
Hamming Code
These codes were originally designed with dmin = 3,
which means that they can detect up to two errors or
correct one single error.
Although there are some Hamming codes that can
correct more than one error, our discussion focuses
on the single-bit error-correcting code.
First let us find the relationship between ‘n’ and ‘k’ in
a Hamming code.
We need to choose an integer m >= 3. The values of
‘n’ and ‘k’ are then calculated from ‘m’ as n = 2m - 1
and k=n - m. The number of check bits r =m.
For example, if m =3, then n = 7 and k= 4. This is a
Hamming code C(7, 4) with dmin =3. Table 4 shows the
datawords and codewords for this code.
Figure 9-18
Hamming Code
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Figure 9-19
Hamming Code
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Figure 9-19-continued
Hamming Code
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Figure 9-20
Example of Hamming Code
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Figure 9-21
Single-bit error
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Figure 9-22
Error
Detection
WCB/McGraw-Hill The McGraw-Hill Companies, Inc., 1998
Calculating the parity bits at the
transmitter
Modulo 2 arithmetic:
:
r0 = a2 + a1 + a0
r1 = a3 + a2 + a1
r2 = a1 + a0 + a3
Calculating the syndrome at the
receiver:
s0 = b2 + b1 + b0 +q0
s1 = b3 + b2 + b1 +q1
s2 = b1 + b0 + b3 +q2
10.
Figure 12 The structure of the encoder and decoder for a Hamming code
10.
Table 5 Logical decision made by the correction logic analyzer
10.
Example 13
Let us trace the path of three datawords from the sender to
the destination:
1. The dataword 0100 becomes the codeword 0100011.
The codeword 0100011 is received. The syndrome is
000, the final dataword is 0100.
2. The dataword 0111 becomes the codeword 0111001.
The received codeword is: 0011001. The syndrome is
011. After flipping b2 (changing the 1 to 0), the final
dataword is 0111.
3. The dataword 1101 becomes the codeword 1101000.
The syndrome is 101. After flipping b0, we get 0000,
the wrong dataword. This shows that our code cannot
correct two errors.
10.