Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Data Link Layer

Download as pdf or txt
Download as pdf or txt
You are on page 1of 87

UNIT 2

DATA LINK LAYER


Data link layer(DLL)
• The data link layer in the OSI (Open System Interconnections) Model,
is in between the physical layer and the network layer.
• This layer converts the raw transmission facility provided by the
physical layer to a reliable and error-free link.
Data link layer(DLL)
Data link layer(DLL)
• The data link layer receives the information in the form of packets
from the Network layer, it divides packets into frames and sends
those frames bit-by-bit to the underlying physical layer.
SERVICES OF DATA LINK LAYER
1.Framing
• The packet received from the Network layer is known as a frame in
the Data link layer.
• At the sender’s side, DLL receives packets from the Network layer and
divides them into small frames, then, sends each frame bit-by-bit to
the physical layer.
• It also attaches some special bits (for error control and addressing) at
the header and end of the frame.
• At the receiver’s end, DLL takes bits from the Physical layer organizes
them into the frame, and sends them to the Network layer.
SERVICES OF DATA LINK LAYER
• It provides a way for a sender to transmit a set of bits that are
meaningful to the receiver.
• Ethernet, token ring, frame relay, and other data link layer
technologies have their own frame structures.
• Frames have headers that contain information such as error-
checking codes
SERVICES OF DATA LINK LAYER
• At the data link layer, it extracts the message from the sender and
provides it to the receiver by providing the sender’s and receiver’s
addresses.
• The advantage of using frames is that data is broken up into
recoverable chunks that can easily be checked for corruption.
• The process of dividing the data into frames and reassembling it is
transparent to the user and is handled by the data link layer.
• Framing is an important aspect of data link layer protocol design
because it allows the transmission of data to be organized and
controlled, ensuring that the data is delivered accurately and
efficiently
SERVICES OF DATA LINK LAYER
Problems in Framing
• Detecting start of the frame: When a frame is transmitted, every
station must be able to detect it. Station detects frames by looking
out for a special sequence of bits that marks the beginning of the
frame i.e. SFD (Starting Frame Delimiter).
• How does the station detect a frame: Every station listens to link for
SFD pattern through a sequential circuit. If SFD is detected,
sequential circuit alerts station. Station checks destination address to
accept or reject frame.
• Detecting end of frame: When to stop reading the frame.
SERVICES OF DATA LINK LAYER
Frame structure:
• Frame Header − It contains the source and the destination addresses of
the frame.
• Payload field − It contains the message to be delivered. In bit stuffing it is
a variable sequence of bits, while in byte stuffing it is a variable sequence
of data bytes.
• Trailer − It contains the error detection and error correction bits.
• Flags − Flags are the frame delimiters signalling the start and end of the
frame. In bit stuffing, flag comprises of a bit pattern that defines the
beginning and end bits. It is generally of 8-bitsand if flag is of 1- byte
denoting a protocol - dependent special character.
SERVICES OF DATA LINK LAYER
SERVICES OF DATA LINK LAYER
Types of framing – There are two types of framing:
1. Fixed size
• The frame is of fixed size and there is no need to provide boundaries
to the frame, the length of the frame itself acts as a delimiter.
• Drawback: It suffers from internal fragmentation if the data size is
less than the frame size
• Solution: Padding
SERVICES OF DATA LINK LAYER
Variable – Sized Framing
• Here, the size of each frame to be transmitted may be different. So
additional mechanisms are kept to mark the end of one frame and
the beginning of the next frame.
• It is used in local area networks.
SERVICES OF DATA LINK LAYER
2. Addressing
• The data link layer encapsulates the source and destination’s MAC
address/ physical address in the header of each frame to ensure
node-to-node delivery. MAC address is the unique hardware address
that is assigned to the device while manufacturing.
SERVICES OF DATA LINK LAYER
SERVICES OF DATA LINK LAYER
Related Questions
Q.1:What is the purpose of framing in the Data Link Layer?
• Framing involves encapsulating data into frames with headers and trailers,
allowing the receiver to identify the start and end of each frame and to
distinguish between different frames.
Q.2:What is MAC address in the Data Link Layer?
• MAC (Media Access Control) address is a unique hardware address
assigned to network interfaces at the Data Link Layer. It is used to identify
devices on a network.
Q.3:What is the difference between a MAC address and an IP address?
• A MAC address is a hardware address associated with a network interface
card, while an IP address is a logical address used for routing data packets
in a network. MAC addresses are used at the Data Link Layer, and IP
addresses are used at the Network Layer.
SERVICES OF DATA LINK LAYER
Error control
• An Error is a situation when the message received at the receiver end
is not identical to the message transmitted
• Data can get corrupted due to various reasons like noise. So, it is the
responsibility of the data link layer, to detect the error in the
transmitted data and correct it using error detection and correction
techniques respectively.
• DLL adds error detection bits into the frame’s header, so that receiver
can check received data is correct or not. It adds reliability to physical
layer by adding mechanisms to detect and retransmit damaged or
lost frames
SERVICES OF DATA LINK LAYER
SERVICES OF DATA LINK LAYER
Single-Bit Error
• The only one bit of a given data unit is changed from 1 to 0 or from 0
to 1.
• Single-Bit Error mainly occurs in Parallel Data Transmission. For
example, if eight wires are used to send the eight bits of a byte, if one
of the wire is noisy, then single-bit is corrupted per byte.
SERVICES OF DATA LINK LAYER
• In the figure, the message which is sent is corrupted as single-bit, i.e.,
0 bit is changed to 1.
SERVICES OF DATA LINK LAYER
Burst Error
• The two or more bits are changed from 0 to 1 or from 1 to 0 is known
as Burst Error.
• The Burst Error is determined from the first corrupted bit to the last
corrupted bit.
Error detection and Correction
• When data is transmitted from one device to another device, the
system does not guarantee whether the data received by the device
is identical to the data transmitted by another device.
• An Error is a situation when the message received at the receiver end
is not identical to the message transmitted.
Error detection and Correction
Error detection and Correction
• Error Detection : It means detection or identification of errors. These
errors may occur due to noise or any other impairments during
transmission from transmitter to the receiver, in communication
system. It is a class of techniques for detecting garbled i.e. unclear
and distorted data or messages.
• Error Correction : Error correction, as the name suggests, simply
means correction or solving or fixing of errors. It simply means
reconstruction and rehabilitation of original data that is error-free.
But error correction method is very costly and very hard.
Error Detecting Techniques
The most popular Error Detecting Techniques are:

• Single parity check


• Two-dimensional parity check
• Checksum
• Cyclic redundancy check
Single parity check

• Single Parity checking is the simple mechanism and


inexpensive to detect the errors.
• In this technique, a redundant bit is also known as a parity bit
which is appended at the end of the data unit so that the
number of 1s becomes even. Therefore, the total number of
transmitted bits would be 9 bits.
• If the number of 1s bits is odd, then parity bit 1 is appended and
if the number of 1s bits is even, then parity bit 0 is appended at
the end of the data unit.
• At the receiving end, the parity bit is calculated from the
received data bits and compared with the received parity bit.
• This technique generates the total number of 1s even, so it is
known as even-parity checking.
Single parity check
Single parity check

• It can only detect single-bit errors which are very rare.


• If two bits are interchanged, then it cannot detect the errors.
Two-Dimensional Parity Check

• Performance can be improved by using Two-Dimensional Parity


Check which organizes the data in the form of a table.
• Parity check bits are computed for each row, which is equivalent to
the single-parity check.
• In Two-Dimensional Parity check, a block of bits is divided into rows,
and the redundant row of bits is added to the whole block.
• At the receiving end, the parity bits are compared with the parity bits
computed from the received data.
Two-Dimensional Parity Check
Two-Dimensional Parity Check

Drawbacks Of 2D Parity Check


• This technique cannot be used to detect the 4-bit errors
or more in some cases.
• If two bits in one data unit are corrupted and two bits
exactly the same position in another data unit are also
corrupted, then 2D Parity checker will not be able to
detect the error.
Checksum

• In checksum error detection scheme, the data is divided into k


segments each of m bits.
• In the sender’s end the segments are added using 1’s complement
arithmetic to get the sum. The sum is complemented to get the
checksum.
• The checksum segment is sent along with the data segments.
• At the receiver’s end, all received segments are added using 1’s
complement arithmetic to get the sum. The sum is complemented.
• If the result is zero, the received data is accepted; otherwise
discarded.
Checksum
Checksum -Assignment

11001100, 10101010, 11110000 and 11000011


Cyclic redundancy check

• CRC or Cyclic Redundancy Check is a method of detecting accidental


changes/errors in the communication channel.
• CRC uses Generator Polynomial which is available on both sender
and receiver side.
• An example generator polynomial is of the form like x3 + x + 1. This
generator polynomial represents key 1011. Another example is x2 + 1
that represents key 101.
• n : Number of bits in data to be sent from sender side.
• k : Number of bits in the key obtained from generator polynomial
Cyclic redundancy check

• CRC can detect all single-bit errors


• CRC can detect all double-bit errors provided the divisor contains at
least three logic 1’s.
• CRC can detect any odd number of errors provided the divisor is a
factor of x+1.
• CRC can detect all burst error of length less than the degree of the
polynomial.
• CRC can detect most of the larger burst errors with a high probability.
Error Correction
• Error correction techniques find out the exact number of bits that
have been corrupted and as well as their locations.
Error Correction can be handled in two ways:
• Backward error correction: Once the error is discovered, the receiver
requests the sender to retransmit the entire data unit.
• Forward error correction: In this case, the receiver uses the error-
correcting code which automatically corrects the errors.
Error Correction-Hamming Code
• A single additional bit can detect the error, but cannot correct it.
• For correcting the errors, one has to know the exact position of the error.
For example, If we want to calculate a single-bit error, the error correction
code will determine which one of seven bits is in error. To achieve this, we
have to add some additional redundant bits.
• Suppose r is the number of redundant bits and d is the total number of
the data bits. The number of redundant bits r can be calculated by using
the formula:
• 2r>=d+r+1
• To determine the position of the bit which is in error, a technique
developed by R.W Hamming is Hamming code which can be applied to any
length of the data unit and uses the relationship between data units and
redundant units.
Error Correction-Hamming Code
Algorithm of Hamming code:
• An information of 'd' bits are added to the redundant bits 'r' to form
d+r.
• The location of each of the (d+r) digits is assigned a decimal value.
• The 'r' bits are placed in the positions 1,2,.....2k-1.
• At the receiving end, the parity bits are recalculated. The decimal
value of the parity bits determines the position of an error.
Hamming code through an example
• Suppose the original data is 1010 which is to be sent.
• Total number of data bits 'd' = 4
• Number of redundant bits r : 2r >= d+r+1
• 2r>= 4+r+1
• Therefore, the value of r is 3 that satisfies the above relation.
• Total number of bits = d+r = 4+3 = 7;
Hamming code through an example
• the number of redundant bits is 3. The three bits are
represented by r1, r2, r4. The position of the redundant
bits is calculated with corresponds to the raised power of
2. Therefore, their corresponding positions are 1, 21, 22.
• The position of r1 = 1
• The position of r2 = 2
• The position of r4 = 4
• Representation of Data on the addition of parity bits:
Hamming code through an example
• Determining the r1 bit
• The r1 bit is calculated by performing a parity check on the bit positions
whose binary representation includes 1 in the first position.

• We observe from the above figure that the bit positions that includes 1 in
the first position are 1, 3, 5, 7. Now, we perform the even-parity check at
these bit positions. The total number of 1 at these bit positions
corresponding to r1 is even, therefore, the value of the r1 bit is 0.
Hamming code through an example
• Determining r2 bit
• The r2 bit is calculated by performing a parity check on the bit
positions whose binary representation includes 1 in the second
position.

• We observe from the above figure that the bit positions that
includes 1 in the second position are 2, 3, 6, 7. Now, we
perform the even-parity check at these bit positions. The total
number of 1 at these bit positions corresponding to r2 is odd,
therefore, the value of the r2 bit is 1.
Hamming code through an example
• The r4 bit is calculated by performing a parity check on the bit positions
whose binary representation includes 1 in the third position.

• We observe from the above figure that the bit positions that includes 1 in
the third position are 4, 5, 6, 7. Now, we perform the even-parity check at
these bit positions. The total number of 1 at these bit positions
corresponding to r4 is even, therefore, the value of the r4 bit is 0.
Hamming code through an example
• Data transferred is given below:
Hamming code through an example
• Suppose the 4th bit is changed from 0 to 1 at the receiving end, then parity
bits are recalculated.

• We observe from the above figure that the binary representation of r1 is


1100. Now, we perform the even-parity check, the total number of 1s
appearing in the r1 bit is an even number. Therefore, the value of r1 is 0.
Hamming code through an example
• R2 bit
• The bit positions of r2 bit are 2,3,6,7

• We observe from the above figure that the binary representation of


r2 is 1001. Now, we perform the even-parity check, the total number
of 1s appearing in the r2 bit is an even number. Therefore, the value
of r2 is 0.
Hamming code through an example
• R4 bit
• The bit positions of r4 bit are 4,5,6,7.

• We observe from the above figure that the binary representation of


r4 is 1011. Now, we perform the even-parity check, the total number
of 1s appearing in the r4 bit is an odd number. Therefore, the value of
r4 is 1.
Relationship b/w Error position & binary
number.
Data-link Control & Protocols
• Data-link layer is responsible for implementation of point-to-point
flow and error control mechanism.
Flow Control
• When a data frame (Layer-2 data) is sent from one host to another
over a single medium, it is required that the sender and receiver
should work at the same speed. That is, sender sends at a speed on
which the receiver can process and accept the data.
Flow Control
• It is a technique in which proper flow of data from sender to receiver.
• It is possible for sender to transmit data or information at very fast
rate and hence receiver can receive this information and process it.
• It is restricts and coordinates number of frames or amount of data
sender can send just before it waits for an acknowledgement from
receiver.
Flow control
• Flow control can also be understand as a speed matching mechanism
for two stations.
Flow Control
Feedback – based Flow Control
• In this control technique, sender simply transmits data or information
or frame to receiver, then receiver transmits data back to sender and
also allows sender to transmit more amount of data or tell sender
about how receiver is processing or doing.
• It is mean that sender transmits data or frames after it has received
acknowledgements from user.
Flow Control
Rate – based Flow Control
• In this control technique, usually when sender sends or transfer data
at faster speed to receiver and receiver is not being able to receive
data at the speed, then mechanism known as built-in mechanism in
protocol will just limit or restricts overall rate at which data or
information is being transferred or transmitted by sender without
any feedback or acknowledgement from receiver.
Techniques of Flow Control in Data Link
Layer
Techniques of Flow Control in Data Link
Layer
1. Stop and Wait Protocol
• Stop and wait means, whatever the data that sender
wants to send, he sends the data to the receiver.
• After sending the data, he stops and waits until he
receives the acknowledgment from the receiver.
• The stop and wait protocol is a flow control protocol
where flow control is one of the services of the data link
layer.
Techniques of Flow Control in Data Link
Layer
• It is a data-link layer protocol which is used for transmitting the data
over the noiseless channels(An idealistic channel in which no frames
are lost, corrupted or duplicated)
• It provides unidirectional data transmission which means that either
sending or receiving of data will take place at a time. It provides flow-
control mechanism but does not provide any error control
mechanism.
• The idea behind the usage of this frame is that when the sender
sends the frame then he waits for the acknowledgment before
sending the next frame.
Techniques of Flow Control in Data Link
Layer
Sender side
• Rule 1: Sender sends one data packet at a time.
• Rule 2: Sender sends the next packet only when it receives the
acknowledgment of the previous packet.

• Therefore, the idea of stop and wait protocol in the sender's side is
very simple, i.e., send one packet at a time, and do not send another
packet before receiving the acknowledgment.
Techniques of Flow Control in Data Link
Layer
Receiver side
• Rule 1: Receive and then consume the data packet.
• Rule 2: When the data packet is consumed, receiver sends the
acknowledgment to the sender.
• Therefore, the idea of stop and wait protocol in the receiver's side is
also very simple, i.e., consume the packet, and once the packet is
consumed, the acknowledgment is sent. This is known as a flow
control mechanism.
Techniques of Flow Control in Data Link
Layer
Working of Stop and Wait protocol
Disadvantages of Stop and Wait
protocol
Problems occur due to lost data
• Suppose the sender sends the data and the data is lost. The receiver
is waiting for the data for a long time. Since the data is not received
by the receiver, so it does not send any acknowledgment. Since the
sender does not receive any acknowledgment so it will not send the
next packet. This problem occurs due to the lost data.
Disadvantages of Stop and Wait
protocol
In this case, two problems occur:
• Sender waits for an infinite amount of time for an acknowledgment.
• Receiver waits for an infinite amount of time for a data.
Disadvantages of Stop and Wait
protocol
Problems occur due to lost acknowledgment
• Suppose the sender sends the data and it has also been received by
the receiver. On receiving the packet, the receiver sends the
acknowledgment. In this case, the acknowledgment is lost in a
network, so there is no chance for the sender to receive the
acknowledgment.
• There is also no chance for the sender to send the next packet as in
stop and wait protocol, the next packet cannot be sent until the
acknowledgment of the previous packet is received.
Disadvantages of Stop and Wait
protocol
In this case, one problem occurs:
• Sender waits for an infinite amount of time for an
acknowledgment.
Disadvantages of Stop and Wait
protocol
Problem due to the delayed data or acknowledgment
Suppose the sender sends the data and it has also been received by the
receiver. The receiver then sends the acknowledgment but the
acknowledgment is received after the timeout period on the sender's
side. As the acknowledgment is received late, so acknowledgment can
be wrongly considered as the acknowledgment of some other data
packet.
Techniques of Flow Control in Data Link
Layer
2. Sliding Window Protocol
• The sliding window is a technique for sending multiple frames at a
time.
• It controls the data packets between the two devices where reliable
and gradual delivery of data frames is needed. It is also used in TCP
• In this technique, each frame has sent from the sequence number.
The sequence numbers are used to find the missing data in the
receiver end.
• The purpose of the sliding window technique is to avoid duplicate
data, so it uses the sequence number.
Sliding Window Protocol
• The sliding window protocol is the flow control protocol for noisy
channels that allows the sender to send multiple frames even before
acknowledgments are received
• It is called a Sliding window because the sender slides its window
upon receiving the acknowledgments for the sent frames.
Sliding Window Protocol
• The sliding window protocol is a communication protocol used to
manage the flow control and reliability of data transmission over a
network.
• It allows the sender to transmit a specified number of packets, known
as the window size, without waiting for an acknowledgment from the
receiver for each packet. This approach enhances efficiency by
minimizing the communication overhead.
Sliding Window Protocol
The protocol employs two primary components:
• The sender's sliding window and the receiver's sliding window.
• The sender's window keeps track of the packets that have been sent
but not yet acknowledged, while the receiver's window tracks the
expected sequence of packets to receive.
• As acknowledgments are received, both windows slide forward,
allowing for the continuous flow of data
Sliding Window Protocol
Working
• The sender and receiver have a “window” of frames. A window is a
space that consists of multiple bytes. The size of the window on the
receiver side is always 1.
• Each frame is sequentially numbered from 0 to n - 1, where n is the
window size at the sender side.
• The sender sends as many frames as would fit in a window.
• After receiving the desired number of frames, the receiver sends an
acknowledgment. The acknowledgment (ACK) includes the number
of the next expected frame.
Sliding Window Protocol
Sliding Window Protocol
Techniques of Flow Control in Data Link
Layer
Sliding window protocol has two types

• Go-Back-N ARQ
• Selective Repeat ARQ
Go-Back-N ARQ
Go-Back-N ARQ
• Go-Back-N ARQ protocol is also known as Go-Back-N Automatic
Repeat Request.
• Go – Back – N ARQ provides for sending multiple frames before
receiving the acknowledgment for the first frame.
• It uses the concept of sliding window, and so is also called sliding
window protocol.
• The frames are sequentially numbered and a finite number of frames
are sent.
Go-Back-N ARQ

• If the acknowledgment of a frame is not received within the time


period, all frames starting from that frame are retransmitted
• In this, if any frame is corrupted or lost, all subsequent frames have
to be sent again.
• The size of the sender window is N in this protocol.
For example, Go-Back-8, the size of the sender window, will be 8. The
receiver window size is always 1.
• If the receiver receives a corrupted frame, it cancels it. The receiver
does not accept a corrupted frame. When the timer expires, the
sender sends the correct frame again.
Go-Back-N ARQ
Selective Repeat ARQ

Selective Repeat ARQ


• This protocol also provides for sending multiple frames before
receiving the acknowledgment for the first frame.
• Selective Repeat ARQ is also known as the Selective Repeat
Automatic Repeat Request.
• The Go-back-N ARQ protocol works well if it has fewer errors. But if
there is a lot of error in the frame, lots of bandwidth loss in sending
the frames again. So, we use the Selective Repeat ARQ protocol.
• In this protocol, the size of the sender window is always equal to the
size of the receiver window. The size of the sliding window is always
greater than 1.
Selective Repeat ARQ

• If the receiver receives a corrupt frame, it does not directly discard it.
It sends a negative acknowledgment to the sender.
• The sender sends that frame again as soon as on the receiving
negative acknowledgment.
• There is no waiting for any time-out to send that frame. The design
of the Selective Repeat ARQ protocol is shown below.
Selective Repeat ARQ
Selective Repeat ARQ
DLL
DLL is divided into two sublayers
• LLC sublayer
• MAC sublayer
DLL
• The main functionality of the LLC layer is that it multiplexes the
protocols over the MAC layer while sending and de-multiplex the
protocols while receiving. This layer controls the flow control.
DLL
• Data link layer is responsible for Framing, which is the division of a
stream of bits from the network layer into manageable units (called
frames).

• Each frame consists of the sender’s address and a destination


address. The destination address defines where the packet is to go
and the sender’s address helps the recipient acknowledge the
receipt.
Frames could be fixed size or variable size.
• In fixed-size framing, there is no need for defining the boundaries of
the frames as the size itself can be used to define the end of the
frame and the beginning of the next frame.
• In variable-size framing, we need a way to define the end of the
frame and the beginning of the next frame.
• To separate one frame from the next, an 8-bit (or 1-byte) flag is
added at the beginning and the end of a frame. But the problem
with that is, any pattern used for the flag could also be part of the
information. So, there are two ways to overcome this problem:

• Using Byte stuffing (or character stuffing)


• Using Bit stuffing

You might also like