0% found this document useful (0 votes)
75 views20 pages

Eec 2502 Lec 4

Uploaded by

IAMMARKS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views20 pages

Eec 2502 Lec 4

Uploaded by

IAMMARKS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

DATA-LINK LAYER

Data Link Layer is second layer of OSI Layered Model. This layer is one of the most
complicated layers and has complex functionalities and liabilities. Data link layer hides the
details of underlying hardware and represents itself to upper layer as the medium to
communicate.
Data link layer works between two hosts which are directly connected in some sense. This direct
connection could be point to point or broadcast. Systems on broadcast network are said to be on
same link. The work of data link layer tends to get more complex when it is dealing with
multiple hosts on single collision domain.
Data link layer is responsible for converting data stream to signals bit by bit and to send that over
the underlying hardware. At the receiving end, Data link layer picks up data from hardware
which are in the form of electrical signals, assembles them in a recognizable frame format, and
hands over to upper layer.
Data link layer has two sub-layers:
 Logical Link Control: It deals with protocols, flow-control, and error control
 Media Access Control: It deals with actual control of media
Functionality of Data-link Layer
Data link layer does many tasks on behalf of upper layer. These are:
 Framing
Data-link layer takes packets from Network Layer and encapsulates them into Frames. Then, it
sends each frame bit-by-bit on the hardware. At receiver’ end, data link layer picks up signals
from hardware and assembles them into frames.
 Flow Control
Stations on same link may have different speed or capacity. Data-link layer ensures flow control
that enables both machine to exchange data on same speed.
 Error Control
Sometimes signals may have encountered problem in transition and the bits are flipped.These
errors are detected and attempted to recover actual data bits. It also provides error reporting
mechanism to the sender.
 Addressing
Data-link layer provides layer-2 hardware addressing mechanism. Hardware address is assumed
to be unique on the link. It is encoded into hardware at the time of manufacturing.
 Media access control
When host on the shared link tries to transfer the data, it has a high probability of collision. Data-
link layer provides mechanism such as CSMA/CD to equip capability of accessing a shared
media among multiple Systems.
 Synchronization
When data frames are sent on the link, both machines must be synchronized in order for transfer
to take place.

1. FRAMING
• To provide service to the network layer, the data link layer must use the service provided to it
by the physical layer
• I t breaks up physical layer data stream into small blocks, a process called segmentation and
adds header and frame flag to each block to form a frame, a process called encapsulation
• The usual approach is for the data link layer to break up the bit stream into discrete frames
called framing. Four methods of framing are:
i. Byte count.
ii. Flag bytes with byte stuffing.
iii. Flag bits with bit stuffing.
iv. Physical layer coding violations.

i .Framing –Byte Count


 The first framing method uses a field in the header to specify the number of bytes in the
frame
• The trouble with this algorithm is that the count can be garbled by a transmission error
A byte stream. (a)Without errors. (b)With one error.

ii. Framing –Flag bytes with byte stuffing


 Each frame start and end with special bytes called Flag byte.
• It is used as both the starting and ending delimiter.
• It may happen that the flag byte occurs in the data.
• To solve this problem the sender’s data link layer insert a special escape byte (ESC) just before
each ‘‘accidental’’ flag byte in the data.
• This technique is called byte stuffing
iii. Framing –Flag bits with bit stuffing
Uses Flag bits 11111 instead of Flag byte. Sender adds a 0 bit whenever it encounters five
consecutive 1 bits in data, and receiver deletes the 0 bit that follows five consecutive 1 bits in the
received data.

iv. Framing –Physical layer coding violations


 Uses some reserved signals to indicate the start and end of frames
• In effect, we are using ‘‘coding violations’’ to delimit frames
• Because they are reserved signals, it is easy to find the start and end of frames and there is no
need to stuff the data

2. DATA LINK CONTROL


•The most important functions of Data Link layer to satisfy the above requirements are error
control and flow control
•Flow Control is a technique so that transmitter and receiver with different speed characteristics
can communicate with each other
•Error Control involves both error detection and error correction It is necessary because errors
are inevitable in data communication, in spite of the use of better equipment and reliable
transmission media based on the current technology

a. FLOW CONTROL
•Flow Control is a technique for speed matching of transmitter and receiver
•Flow control ensures that a transmitting station does not overflow a receiving station with data
•We will discuss two protocols for flow control
1. Stop and Wait
2. Sliding Window
For the time being, we assume that we have a perfect channel no errors)
1. Stop and wait Flow Control
•Simplest form of flow control
•In Stop and Wait flow control, the receiver indicates its readiness to receive data for each frame
•Operations
i. Sender Transmit a single frame
ii. Receiver Transmit acknowledgment
iii. Go to 1
 The sender must wait until it receives the ACK frame before sending the next data frame
•Major drawback of Stop and Wait Flow Control is that only one frame can be in transmission at
a time
2. Sliding Window Flow Control
Major drawback of stop-and-wait flow control is only one frame can be transmitted at a time;
this leads to inefficiency if propagation delay is much longer than transmission delay. Sliding
window flow control allows the transmission of multiple frame. It assigns each frame a k-bit
sequence number and the range of sequence no. is [0..2k -1 ].
Let us examine how this might work for two stations, A and B, connected via a full-duplex link.
Station B allocates buffer space for n frames. Thus, B can accept n frames, and A is allowed to
send n frames without waiting for any acknowledgments. To keep track of which frames have
been acknowledged, each is labeled with a sequence number. B acknowledges a frame by
sending an acknowledgment that includes the sequence number of the next frame expected. This
acknowledgment also implicitly announces that B is prepared to receive the next n frames,
beginning with the number specified. This scheme can also be used to acknowledge multiple
frames.
How Flow control is achieved?
• Receiver can control the size of the sending window.
• By limiting the size of the sending window data flow from sender to receiver can be
limited .

The example assumes a 3-bit sequence number field and a maximum window size of seven
frames. Initially, A and B have windows indicating that A may transmit seven frames, beginning
with frame 0 (F0). After transmitting three frames (F0, F1, F2) without acknowledgment, A has
shrunk its window to four frames. The window indicates that A may transmit four frames,
beginning with frame number 3. B then transmits an RR (receive-ready) 3, which means: "I have
received all frames up through frame number 2 and am ready to receive frame number 3; in fact,
I am prepared to receive seven frames, beginning with frame number 3." With this
acknowledgment, A is back up to permission to transmit seven frames, still beginning with frame
3. A proceeds to transmit frames 3, 4, 5 , and 6. B returns an RR 4, which allows A to send up to
and including frame F2.
Fig. Example of Sliding window Protocol

b. ERROR CONTROL
There are many reasons such as noise, cross-talk, distortion, attenuation etc., which may make
data to get corrupted during transmission. If errors do occur, then some of the bits will either
change from 0 to 1 or from 1 to 0. The upper layers work on some generalized view of network
architecture and are not aware of actual hardware data processing. Hence, the upper layers expect
error-free transmission between the systems. Most of the applications would not function
expectedly if they receive erroneous data. Applications such as voice and video may not be that
affected and with some errors they may still function well.
Data-link layer uses some error control mechanism to ensure that frames (data bit streams) are
transmitted with certain level of accuracy. But to understand how errors is controlled, it is
essential to know what types of errors may occur.
Types of Errors
There may be three types of errors:
 Single bit error
In a frame, there is only one bit, anywhere though, which is corrupt.

 Multiple bits error

Frame is received with more than one bits in corrupted state.


 Burst error

Frame contains more than1 consecutive bits corrupted.

Error control mechanism may involve two possible ways:


1. Error detection
2. Error correction

1. Error Detection
Errors in the received frames are detected by means of Parity Check and Cyclic Redundancy
Check (CRC). In both cases, few extra bits are sent along with actual data to confirm that bits
received at other end are same as they were sent. If the counter-check at receiver’ end fails, the
bits are considered corrupted.
i. Parity Check
One Dimensional Parity Check
One extra bit is sent along with the original bits to make number of 1s either even in case of even
parity, or odd in case of odd parity.
The sender while creating a frame counts the number of 1s in it. For example, if even parity is
used and number of 1s is even then one bit with value 0 is added. This way number of 1s remains
even. If the number of 1s is odd, to make it even a bit with value 1 is added.
The receiver simply counts the number of 1s in a frame. If the count of 1s is even and even parity
is used, the frame is considered to be not-corrupted and is accepted. If the count of 1s is odd and
odd parity is used, the frame is still not corrupted.
If a single bit flips in transit, the receiver can detect it by counting the number of 1s. But when
more than one bits are erroneous, then it is very hard for the receiver to detect the error.
Two-Dimensional Parity Check
A better approach is the two dimensional parity checks. In this method, a block of bits is
organized in a table (rows and columns). First we calculate the parity bit for each data unit. Then
we organize them into a table. We then calculate the parity bit for each column and create a new
row of 8 bits. Consider the following example; we have four data units to send. They are
organized in the tabular form as shown below.

We then calculate the parity bit for each column and create a new row of 8 bits; they are the
parity bits for the whole block. Note that the first parity bit in the fifth row is calculated based on
all first bits: the second parity bit is calculated based on all second bits: and so on. We then
attach the 8 parity bits to the original data and send them to the receiver. Two-dimensional parity
check increases the likelihood of detecting burst errors. A burst error of more than ‘n‘ bits is also
detected by this method with a very high probability.
ii. Repetition Code
The repetition code makes use of repetitive transmission of each data bit in the bit stream. In the
case of threefold repetition, ‘1’ and ‘0’ would be transmitted as ‘111’ and ‘000’ respectively. If,
in the received data bit stream, bits are examined in groups of three bits, the occurrence of an
error can be detected. In the case of single-bit errors, ‘1’ would be received as 011 or 101 or 110
instead of 111, and a ‘0’ would be received as 100 or 010 or 001 instead of 000. In both cases,
the code becomes self-correcting if the bit in the majority is taken as the correct bit. There are
various forms in which the data are sent using the repetition code. Usually, the data bit stream is
broken into blocks of bits, and then each block of data is sent some predetermined number of
times. For example, if we want to send eight-bit data given by 11011001, it may be broken into
two blocks of four bits each. In the case of threefold repetition, the transmitted data bit stream
would be 110111011101100110011001.
However, such a repetition code where the bit or block of bits is repeated 3 times is not capable
of correcting two-bit errors, although it can detect the occurrence of error. For this, we have to
increase the number of times each bit in the bit stream needs to be repeated. For example, by
repeating each data bit 5 times, we can detect and correct all two-bit errors. The repetition code
is highly inefficient and the information throughput drops rapidly as we increase the number of
times each data bit needs to be repeated to build error detection and correction capability.

iii. Cyclic Redundancy Check (CRC)


CRC is a different approach to detect if the received frame contains valid data. This technique
involves binary division of the data bits being sent. The divisor is generated using polynomials.
The sender performs a division operation on the bits being sent and calculates the remainder.
Before sending the actual bits, the sender adds the remainder at the end of the actual bits. Actual
data bits plus the remainder is called a codeword. The sender transmits data bits as codewords.
At the other end, the receiver performs division operation on codewords using the same CRC
divisor. If the remainder contains all zeros the data bits are accepted, otherwise it is considered as
there some data corruption occurred in transit.
2. Error Correction
In the digital world, error correction can be done in two ways:
i. Forward error correction (FEC) is accomplished by adding redundancy to the
transmitted information using a predetermined algorithm. Each redundant bit is
invariably a complex function of many original information bits. The original
information may or may not appear in the encoded output; codes that include the
unmodified input in the output are systematic, while those that do not are
nonsystematic.) Example of Forward error correction mechanism is the Hamming
Code.
ii. Backward Error correction also known as Automatic repeat request (ARQ) in which
the receiver detects transmission errors in a message and automatically requests a
retransmission from the transmitter. Usually, when the transmitter receives the ARQ,
the transmitter retransmits the message until it is either correctly received or the error
persists beyond a predetermined number of retransmissions. A few types of ARQ
protocols are Stop-and-wait ARQ, Go-Back-N ARQ and Selective Repeat ARQ.
NB: Error control in the data link layer is based on automatic repeat request, which is
the retransmission of data.
i.Forward error correction (FEC)
Hamming Code
We have seen, in the case of the error detection and correction codes described above, how an
increase in the number of redundant bits added to message bits can enhance the capability of the
code to detect and correct errors. If we have a sufficient number of redundant bits, and if these
bits can be arranged such that different error bits produce different error results, then it should be
possible not only to detect the error bit but also to identify its location. In fact, the addition of
redundant bits alters the ‘distance’ code parameter, which has come to be known as the
Hamming distance. The Hamming distance is nothing but the number of bit disagreements
between two code words. For example, the addition of single-bit parity results in a code with a
Hamming distance of at least 2. The smallest Hamming distance in the case of a threefold
repetition code would be 3. Hamming noticed that an increase in distance enhanced the code’s
ability to detect and correct errors. Hamming’s code was therefore an attempt at increasing the
Hamming distance and at the same time having as high an information throughput rate as
possible.
The algorithm for writing the generalized Hamming code is as follows:
1. The generalized form of code is P1P2D1P3D2D3D4P4D5D6D7D8D9D10D11P5………., where P
and D respectively represent parity and data bits.
2. We can see from the generalized form of the code that all bit positions that are powers of 2
(positions
1, 2, 4, 8, 16,…….) are used as parity bits.
3. All other bit positions (positions 3, 5, 6, 7, 9, 10, 11,……) are used to encode data.
4. Each parity bit is allotted a group of bits from the data bits in the code word, and the value of
the parity bit (0 or 1) is used to give it certain parity.
5. Groups are formed by first checking N− 1 bits and then alternately skipping and checking N
bits following the parity bit. Here, N is the position of the parity bit; 1 for P1, 2 for P2, 4 for P3, 8
for P4 and so on. For example, for the generalized form of code given above, various groups of
bits formed with different parity bits would be P1D1D2D4D5……. , P2D1D3D4D6D7……..,
P3D2D3D4D8D9…… , P4D5D6D7D8D9D10D11…….and so on. To illustrate the formation of
groups further, let us examine the group corresponding to parity bit P3. Now, the position of P3 is
at number 4. In order to form the group, we check the first three bits (N− 1=3) and then follow it
up by alternately skipping and checking four bits (N =4).
The Hamming code is capable of correcting single-bit errors on messages of any length.
Although the Hamming code can detect two-bit errors, it cannot give the error locations. The
number of parity bits required to be transmitted along with the message, however, depends upon
the message length, as shown above. The number of parity bits n required to encode m message
bits is the smallest integer that satisfies the condition (2n – n) > m.

The most commonly used Hamming code is the one that has a code word length of seven bits
with four message bits and three parity bits. It is also referred to as the Hamming (7, 4) code. The
code word sequence for this code is written as P1P2D1P3D2D3D4, with P1, P2 and P3 being the
parity bits and D1,
D2, D3 and D4 being the data bits. We will illustrate step by step the process of writing the
Hamming code for a certain group of message bits and then the process of detection and
identification of error bits with the help of an example. We will write the Hamming code for the
four-bit message 0110 representing numeral ‘6’. The process of writing the code is illustrated in
Table 2.9, with even parity. Thus, the Hamming code for 0110 is 1100110. Let us assume that
the data bit D1 gets corrupted in the transmission channel. The received code in that case is
1110110. In order to detect the error, the parity is checked for the three parity relations
mentioned above. During the parity check operation at the receiving end, three additional bits X,
Y and Z are generated by checking the parity status of P1D1D2D4, P2D1D3D4 and P3D2D3D4
respectively. These bits are a ‘0’ if the parity status is okay, and a ‘1’ if it is disturbed. In that
case, ZYX gives the position of the bit that needs correction. The process can be best explained
with the help of an example.
Examination of the first parity relation gives X =1 as the even parity is disturbed. The second
parity relation yields Y = 1 as the even parity is disturbed here too. Examination of the third
relation gives Z = 0 as the even parity is maintained. Thus, the bit that is in error is positioned at
011 which is the binary equivalent of ‘3’. This implies that the third bit from the MSB needs to
be corrected. After correcting the third bit, the received message becomes 1100110 which is the
correct code.
Example 2.6
By writing the parity code (even) and threefold repetition code for all possible four-bit straight
binary
numbers, prove that the Hamming distance in the two cases is at least 2 in the case of the parity
code
and 3 in the case of the repetition code.
Solution
The generation of codes is shown in Table 2.10. An examination of the parity code numbers
reveals that the number of bit disagreements between any pair of code words is not less than 2. It
is either 2 or 4. It is 4, for example, between 00000 and 10111, 00000 and 11011, 00000 and
11101, 00000 and 11110 and 00000 and 01111. In the case of the threefold repetition code, it is
either 3, 6, 9 or 12 and therefore not less than 3 under any circumstances.
Example 2.7
It is required to transmit letter ‘A’ expressed in the seven-bit ASCII code with the help of the
Hamming
(11, 7) code. Given that the seven-bit ASCII notation for ‘A’ is 1000001 and that the data word
gets corrupted to 1010001 in the transmission channel, show how the Hamming code can be
used to identify
the error. Use even parity.
Solution
• The generalized form of the Hamming code in this case is P1P2D1P3D2D3D4P4D5D6D7
= P1P21P3000P4001.
• The four groups of bits using different parity bits are P1D1D2D4D5D7, P2D1D3D4D6D7,
P3D2D3D4
and P4D5D6D7.
• This gives P1 =0, P2 =0, P3 =0 and P4=1.
• Therefore, the transmitted Hamming code for ‘A’ is 00100001001.
• The received Hamming code is 00100101001.
• Checking the parity for the P1 group gives ‘0’ as it passes the test.
• Checking the parity for the P2 group gives ‘1’ as it fails the test.
• Checking the parity for the P3 group gives ‘1’ as it fails the test.
• Checking the parity for the P4 group gives ‘0’ as it passes the test.
• The bits resulting from the parity check, written in reverse order, constitute 0110, which is the
binary equivalent of ‘6’. This shows that the bit in error is the sixth from the MSB.
• Therefore, the corrected Hamming code is 00100001001, which is the same as the transmitted
code.
• The received data word is 1000001.

ii. Backward Error correction (Automatic repeat request (ARQ) )


Error Control protocols
When data-frame is transmitted, there is a probability that data-frame may be lost in the transit or
it is received corrupted. In both cases, the receiver does not receive the correct data-frame and
sender does not know anything about any loss. In such case, both sender and receiver are
equipped with some protocols which helps them to detect transit errors such as loss of data-
frame. Hence, either the sender retransmits the data-frame or the receiver may request to resend
the previous data-frame.
Requirements for error control mechanism:
 Error detection - The sender and receiver, either both or any, must ascertain that there
is some error in the transit.
 Positive ACK - When the receiver receives a correct frame, it should acknowledge it.
 Negative ACK - When the receiver receives a damaged frame or a duplicate frame, it
sends a NACK back to the sender and the sender must retransmit the correct frame.
 Retransmission: The sender maintains a clock and sets a timeout period. If an
acknowledgement of a data-frame previously transmitted does not arrive before the
timeout the sender retransmits the frame, thinking that the frame or it’s acknowledgement
is lost in transit.
There are three types of techniques available which Data-link layer may deploy to control the
errors by Automatic Repeat Requests (ARQ):
 Stop-and-wait ARQ
 Go-Back-N ARQ
 Selective Repeat ARQ
i. Stop-and-wait ARQ
The following transition may occur in Stop-and-Wait ARQ:
o The sender maintains a timeout counter.
o When a frame is sent, the sender starts the timeout counter.
o If acknowledgement of frame comes in time, the sender transmits the next frame
in queue.
o If acknowledgement does not come in time, the sender assumes that either the
frame or its acknowledgement is lost in transit. Sender retransmits the frame and
starts the timeout counter.
o If a negative acknowledgement is received, the sender retransmits the frame.
ii. Go-Back-N ARQ
Stop and wait ARQ mechanism does not utilize the resources at their best.When the
acknowledgement is received, the sender sits idle and does nothing. In Go-Back-N ARQ method,
both sender and receiver maintain a window.
The sending-window size enables the sender to send multiple frames without receiving the
acknowledgement of the previous ones. The receiving-window enables the receiver to receive
multiple frames and acknowledge them. The receiver keeps track of incoming frame’s sequence
number.
When the sender sends all the frames in window, it checks up to what sequence number it has
received positive acknowledgement. If all frames are positively acknowledged, the sender sends
next set of frames. If sender finds that it has received NACK or has not receive any ACK for a
particular frame, it retransmits all the frames after which it does not receive any positive ACK.
iii. Selective Repeat ARQ
In Go-back-N ARQ, it is assumed that the receiver does not have any buffer space for its window
size and has to process each frame as it comes. This enforces the sender to retransmit all the
frames which are not acknowledged.
In Selective-Repeat ARQ, the receiver while keeping track of sequence numbers, buffers the
frames in memory and sends NACK for only frame which is missing or damaged.
The sender in this case, sends only packet for which NACK is received.

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
4. ADDRESSING
Computer network entities need some way to distinguish devices on the network. This is done
through addressing. The Data Link Layer is only concerned with physical devices addresses.
Physical device addressee are, unique hardware addresses typically assigned by hardware
venders. The hardware vendors use addresses that are allocated to them by a standards
organization, the format of the
address depends upon the media access method being used. With Ethernet and Token Ring, the
addresses are very similar. Each uses Media Access Control (MAC) addresses.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy