0% found this document useful (0 votes)
16 views

5-7 Data Link Layer

This document discusses error detection and correction techniques at the data link layer. It covers the following key points: 1) Redundant bits are added to data to detect and correct errors that may occur during transmission. Error detection techniques include parity checks and checksums while error correction uses techniques like forward error correction. 2) Block coding divides data into blocks and adds redundant bits to each block to form codewords. Properties like minimum Hamming distance determine a code's ability to detect or correct errors. 3) Linear block codes allow codewords to be generated by XORing other codewords. Simple parity codes provide single-bit error detection by making the total number of 1s in a codeword even or
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

5-7 Data Link Layer

This document discusses error detection and correction techniques at the data link layer. It covers the following key points: 1) Redundant bits are added to data to detect and correct errors that may occur during transmission. Error detection techniques include parity checks and checksums while error correction uses techniques like forward error correction. 2) Block coding divides data into blocks and adds redundant bits to each block to form codewords. Properties like minimum Hamming distance determine a code's ability to detect or correct errors. 3) Linear block codes allow codewords to be generated by XORing other codewords. Simple parity codes provide single-bit error detection by making the total number of 1s in a codeword even or
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 99

Data Link Layer

Fundamentals of Data Communications and


Networking
INT205

Data Communications & Networking by Behrouz A Forouzan. Copyright © The McGraw-Hill Companies, Inc.
Data can be corrupted
during transmission.

Some applications require that


errors be detected and corrected.
CODING AND ERROR CONTROL

Let us first discuss some issues related, directly or


indirectly, to error detection and correction.

Topics discussed in this section:


Types of Errors
Redundancy
Detection Versus Correction
Forward Error Correction Versus Retransmission
Coding
Modular Arithmetic
Single-bit error

In a single-bit error, only 1 bit in the data


unit has changed.
Burst error of length 8

A burst error means that 2 or more bits


in the data unit have changed.
To detect or correct errors, we need to
send extra (redundant) bits with data.
The structure of encoder and decoder
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.
Datawords and codewords in block coding
Process of error detection in block coding
XORing of two single bits or two words
Example

Let us assume that k = 2 and n = 3.


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

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

Let us add more redundant bits to the 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. The following table shows the datawords
and codewords.
Example (continued)

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


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 in Table 10.1.
Solution
We first find all Hamming distances.

The dmin in this case is 2.


Example

Find the minimum Hamming distance of the coding


scheme in Table 10.2.

Solution
We first find all the Hamming distances.

Table 10.2
The dmin in this case is 3.
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.
Example

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.
Table 10.1
Example

Our second block code scheme (Table 10.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.
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. 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, . . . ).
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.
Note

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


any two valid codewords creates another valid
codeword.
Example

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

In our first code (Table 10.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 10.2), the numbers of 1s in the


nonzero codewords are 3, 3, and 4. So in this code we have
dmin = 3.
Note

A simple parity-check code is a


single-bit error-detecting
code in which
n = k + 1 with dmin = 2.
Table 10.3 Simple parity-check code C(5, 4)

- 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.
Encoder and decoder for simple parity-check code

The checker at the receiver does the same thing as the


generator in the sender with one exception: The addition
is done over all 5 bits. The result, which is called the
syndrome, is just 1 bit. The syndrome is 0 when the
number of 1s in the received codeword is even;
otherwise, it is 1.
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.
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.
Note

A simple parity-check code can detect an odd


number of errors.
Two-dimensional parity-check code

• A simple parity-check bit,


which is normally added at
the end of the word cannot
detect even numbers of
errors. For example, two or
four errors are not detected.
• A better solution is to
organize the characters in a
table and create row and
column parities. The bit in
the row parity is sent with
the byte, the column parity is
sent an extra byte.
Two-dimensional parity-check code
Two-dimensional parity-check code
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.
Cont.
• In variable-size framing, we need a way to
define the end of the frame and the beginning
of the next.
• Two approaches were used for this purpose:
– A character-oriented approach
– A bit-oriented approach.
A frame in a character-oriented protocol

• To separate one frame from the next, an 8-bit (1-byte) flag is added
at the beginning and the end of a frame.
• The flag, composed of protocol-dependent special characters, signals
the start or end of a frame.
Byte stuffing and unstuffing
Byte Stuffing
• Any pattern used for the flag could also be part of the information.
• If this happens, the receiver, when it encounters this pattern in the
middle of the data, thinks it has reached the end of the frame.
• To fix this problem, a byte-stuffing strategy was added to character-
oriented framing.
• In byte stuffing (or character stuffing), a special byte is added to the
data section of the frame when there is a character with the same
pattern as the flag.
• The data section is stuffed with an extra byte. This byte is usually
called the escape character (ESC), which has a predefined bit
pattern.
• Whenever the receiver encounters the ESC character, it removes it
from the data section and treats the next character as data, not a
delimiting flag.
Note

Byte stuffing is the process of adding 1


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

• Uses a special 8-bit pattern flag 01111110 as the


delimiter to define the beginning and the end of
the frame.

• This flag can create the same type of problem we saw in the
byte-oriented protocols.
• If the flag pattern appears in the data, we need to somehow
inform the receiver that this is not the end of the frame.
• We do this by stuffing 1 single bit (instead of 1 byte) to
prevent the pattern from looking like a flag.
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.
Bit stuffing and unstuffing
FLOW AND ERROR CONTROL

The most important responsibilities of the data link


layer are flow control and error control. Collectively,
these functions are known as data link control.
Note

Flow control refers to a set of procedures


used to restrict the amount of data
that the sender can send before
waiting for acknowledgment.
Note

Error control in the data link layer is


based on automatic repeat request,
which is the retransmission of data.
PROTOCOLS

• Now let us see how the data link layer can combine
framing, flow control, and error control to achieve
the delivery of data from one node to another.
• The protocols are normally implemented in software
by using one of the common programming
languages.
Taxonomy of protocols
NOISELESS CHANNELS

Let us first assume we have an ideal channel in which


no frames are lost, duplicated, or corrupted . We
introduce two protocols for this type of channel.
The design of the simplest protocol with no flow or error control
Example 11.1

Figure 11.7 shows an example of communication


using this protocol. It is very simple.
•The sender sends a sequence of frames without
even thinking about the receiver.
•To send three frames, three events occur at the
sender site and three events at the receiver site.
•Note that the data frames are shown by tilted
boxes;
– The height of the box defines the transmission
time difference between the first bit and the last
bit in the frame.
Figure 11.7 Flow diagram for Example 11.1
Design of Stop-and-Wait Protocol
Example 11.2

Figure 11.9 shows an example of communication using


this protocol. It is still very simple.
•The sender sends one frame and waits for feedback from
the receiver.
•When the ACK arrives, the sender sends the next frame.
Figure 11.9 Flow diagram for Example 11.2
NOISY CHANNELS

Although the Stop-and-Wait Protocol gives us an idea


of how to add flow control to its predecessor, noiseless
channels are nonexistent. We discuss three protocols in
this section that use error control.
Stop-and-Wait Automatic Repeat Request

Note

Error correction in Stop-and-Wait ARQ


is done by keeping a copy of the sent
frame and retransmitting of the frame
when the timer expires.

• Adds a simple error control mechanism to the Stop-and-Wait


Protocol.
• Stop-and-Wait Protocol assumes no errors, no duplicates, etc.
Note

In Stop-and-Wait ARQ, we use


sequence numbers to number the
frames.
Note

In Stop-and-Wait ARQ, the


acknowledgment number always
announces the sequence number of the
next frame expected.
Design of the Stop-and-Wait ARQ Protocol
Example 11.3

Figure 11.11 shows an example of Stop-and-Wait ARQ.


•Frame 0 is sent and acknowledged.
•Frame 1 is lost and resent after the time-out. The resent
frame 1 is acknowledged and the timer stops.
•Frame 0 is sent and acknowledged, but the
acknowledgment is lost. The sender has no idea if the
frame or the acknowledgment is lost, so after the time-
out, it resends frame 0, which is acknowledged.
Figure 11.11 Flow diagram for Example 11.3
Go-Back-N ARQ
• To improve the efficiency of transmission
(filling the pipe), multiple frames must be in
transition while waiting for acknowledgment.
• we need to let more than one frame be
outstanding to keep the channel busy while
the sender is waiting for acknowledgment.
• In this protocol we keep a copy of the sent
frames until the acknowledgements arrive.
Sequence Numbers
• Frames from a sending station are numbered
sequentially.
• If the header of the frame allows m bits for the
sequence number, the sequence numbers range
from 0 to 2m - 1.
• For example, if m is 4, the only sequence numbers
are 0 through 15 inclusive. However, we can
repeat the sequence.
– So the sequence numbers are 0, 1,2,3,4,5,6, 7,8,9, 10,
11, 12, 13, 14, 15,0, 1,2,3,4,5,6,7,8,9,10, 11, ...
Sliding Window
• The send window is an imaginary box
covering the sequence numbers of the data
frames which can be in transit.
• In each window position, some of these
sequence numbers define the frames that
have been sent; others define those that can
be sent.
• The maximum size of the window is 2m - 1
Cont.
• Three variables define its size and location at any
time. We call these variables:
– Sf(send window, the first outstanding frame).
• The variable Sf defines the sequence number of the first
(oldest) outstanding frame. It defines the frames that have
been sent, but not acknowledged yet.
– Sn (send window, the next frame to be sent).
• The variable Sn holds the sequence number that will be
assigned to the next frame to be sent. It defines those that
can be sent, but not yet received from the network layer.
– Ssize (send window, size).
• The variable Ssize defines the size of the window, which is
fixed in our protocol.
Send window for Go-Back-N ARQ
Flow diagram of Go-Back-N ARQ
Resending a Frame
• The size of the receive window is always 1.
• The receiver is always looking for the arrival of a
specific frame.
• Any frame arriving out of order is discarded and
needs to be resent.
• If a frame is damaged or is received out of
order, the receiver is silent and will discard all
subsequent frames until it receives the one it is
expecting.
Resending a Frame
• The receiver causes the timer of the unacknowledged
frame at the sender site to expire.
• This, in turn, causes the sender to go back and resend
all frames, beginning with the one with the expired
timer.
• For example, suppose the sender has already sent
frame 6, but the timer for frame 3 expires. This means
that frame 3 has not been acknowledged; the sender
goes back and sends frames 3, 4,5, and 6 again. That
is why the protocol is called Go-Back-N ARQ.
Note

The send window can slide one


or more slots when a valid
acknowledgment arrives.
Note

The receive window is an abstract


concept defining an imaginary box
of size 1. The window slides
when a correct frame has arrived;
sliding occurs one slot at a time.
Design of Go-Back-N ARQ
Note

In Go-Back-N ARQ, the size of the send


window must be less than 2m;
the size of the receiver window
is always 1.
Send Window Size
Why the size of the send window must be
less than 2m?.
•As an example, we choose m =2, which means the size
of the window can be 2m - 1, or 3.
•Figure 11.15 compares a window size of 3 against a
window size of 4.
•If the size of the window is 3 (less than 22) and all
three acknowledgments are lost, the frame timer
expires and all three frames are resent. The receiver is
now expecting frame 3, not frame 0, so the duplicate
frame is correctly discarded.
Cont.
• On the other hand, if the size of the window is
4 (equal to 22) and all acknowledgments are
lost, the sender will send a duplicate of frame
0.
• However, this time the window of the receiver
expects to receive frame 0, so it accepts frame
0, not as a duplicate, but as the first frame in
the next cycle. This is an error.
Window size for Go-Back-N ARQ
Selective Repeat ARQ
• Go-Back-N ARQ simplifies the process at the receiver site.
• The receiver keeps track of only one variable.
• There is no need to buffer out-of-order frames; they are
simply discarded.
• In a noisy link, a frame has a higher probability of damage,
which means the resending of multiple frames. This
resending uses up the bandwidth and slows down the
transmission.
• For noisy links, no need to resend N frames when just one
frame is damaged; only the damaged frame is resent.
• This mechanism is called Selective Repeat ARQ.
Windows
• It uses two windows, a send window and a receive
window.
• The Maximum size of the send window is 2m-1 .
• The receive window is the same size as the send window.
• For example, if m = 4, the sequence numbers go from 0
to 15, but the size of the window is just 8 (it is 15 in the
Go-Back-N Protocol).
• The smaller window size means less efficiency in filling
the pipe, but the fact that there are fewer duplicate
frames can compensate for this.
• The protocol uses the same variables as we discussed for
Go-Back-N.
Cont.
• The Selective Repeat Protocol allows as many
frames as the size of the receive window to
arrive out of order.
• Because the sizes of the send window and
receive window are the same, all the frames
in the send frame can arrive out of order and
be stored until they can be delivered.
• The receiver never delivers packets out of
order to the network layer.
Cont.
• An ACK or a NAK (No Acknowledgement) frame
may arrive.
• If a valid NAK frame arrives, we just resend the
corresponding frame.
• If a valid ACK arrives, move the left wall of the
window.
• The time-out event is simpler here; only the
frame which times out is resent.
• In the next example, NAK1 to inform the
sender to resend frame 1 again.
Flow diagram of Selective Repeat ARQ
Design of Selective Repeat ARQ
IEEE STANDARDS

In 1985, the Computer Society of the IEEE started a


project, called Project 802, to set standards to enable
intercommunication among equipment from a variety of
manufacturers. Project 802 is a way of specifying
functions of the physical layer and the data link layer
of major LAN protocols.
IEEE standard for LANs
Note
Frame length:
Minimum: 64 bytes (512 bits)
Maximum: 1518 bytes (12,144 bits)
Example of an Ethernet address in hexadecimal notation
Note

The least significant bit of the first byte


defines the type of address.
If the bit is 0, the address is unicast;
otherwise, it is multicast.
Note

The broadcast destination address is a


special case of the multicast address in
which all bits are 1s.
Example 13.1

Define the type of the following destination addresses:


a. 4A:30:10:21:10:1A b. 47:20:1B:2E:08:EE
c. FF:FF:FF:FF:FF:FF
Solution
To find the type of the address, we need to look at the
second hexadecimal digit from the left. If it is even, the
address is unicast. If it is odd, the address is multicast. If
all digits are F’s, the address is broadcast. Therefore, we
have the following:
a. This is a unicast address because A in binary is 1010.
b. This is a multicast address because 7 in binary is 0111.
c. This is a broadcast address because all digits are F’s.
Example 13.2

Show how the address 47:20:1B:2E:08:EE is sent out on


line.

Solution
The address is sent left-to-right, byte by byte; for each
byte, it is sent right-to-left, bit by bit, as shown below:
Ethernet frame structure

• Addresses: 6 byte source, destination MAC addresses


• if adapter receives frame with matching destination address, or with
broadcast address (e.g. ARP packet), it passes data in frame to network
layer protocol. Otherwise, adapter discards frame
• type: indicates higher layer protocol (mostly IP but others possible, e.g.,
Novell IPX, AppleTalk)
• CRC: cyclic redundancy check at receiver error detected: frame is dropped

type

dest. source data (payload)


preamble address address CRC

14.99

You might also like