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

Data Link Layer

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Data Link Layer

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Data Link Layer

2nd Layer
Data Link layer
► The Data-link layer is the second layer from the bottom in the
TCP/IP model.
► Responsible for the node-to-node delivery of data
► Major role is to ensure error-free transmission of information
► Responsible to encode, decode and organize the outgoing and
incoming data
► most complex layer of the OSI model as it hides all the
underlying complexities of the hardware from the other above
layers
Sub Layers of Data Link Layers
Logical Link Control (LLC) Media Access Control (MAC)
This sublayer of the data link layer deals MAC sublayer manages the device’s
with multiplexing, the flow of data interaction, responsible for addressing
among applications and other services, frames, and also controls physical media
and LLC is responsible for providing error
access.
messages and acknowledgments as well.
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.
Functions of the Data-link Layer:
► 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.
► 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.
Functions of Data Link Layer
► Error Control
► Data can get corrupted due to various reasons like noise, attenuation, etc. 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.
► Flow Control
► If the receiver’s receiving speed is lower than the sender’s sending speed,
then this can lead to an overflow in the receiver’s buffer and some frames may
get lost. So, it’s the responsibility of DLL to synchronize the sender’s and
receiver’s speeds and establish flow control between them.
► Access Control
► When multiple devices share the same communication channel there is a
high probability of collision, so it’s the responsibility of DLL to check which
device has control over the channel and CSMA/CD and CSMA/CA can be used
to avoid collisions and loss of frames in the channel.
Services Provided By DLL
Services Provided By DLL

► Framing & Link access: ► Reliable delivery:


► Data Link Layer protocols ► Data Link Layer provides a
reliable delivery service, i.e.,
encapsulate each network transmits the network layer
frame within a Link layer frame datagram without any error.
before the transmission across ► A reliable delivery service is
the link. accomplished with
transmissions and
► A frame consists of a data field acknowledgements.
in which network layer ► A data link layer mainly
datagram is inserted and a provides the reliable delivery
number of data fields. It service over the links as they
have higher error rates and they
specifies the structure of the can be corrected locally, link at
frame as well as a channel which an error occurs rather
access protocol by which frame than forcing to retransmit the
is to be transmitted over the data.
link.
Services Provided By DLL
► Flow control: ► Error control:
► A receiving node can receive ► Errors can be introduced by
the frames at a faster rate than signal attenuation and noise.
it can process the frame. Data Link Layer protocol
Without flow control, the provides a mechanism to detect
receiver's buffer can overflow, one or more errors.
and frames can get lost. ► This is achieved by adding error
► To overcome this problem, the detection bits in the frame and
data link layer uses the flow then receiving node can
control to prevent the sending perform an error check.
node on one side of the link
from overwhelming the
receiving node on another side
of the link.
Services Provided By DLL
► Error correction: ► Half-Duplex & Full-Duplex:
► Error correction is similar to the ► In a Full-Duplex mode, both the
Error detection, except that nodes can transmit the data at
receiving node not only detect the same time. In a Half-Duplex
the errors but also determine mode, only one node can
where the errors have occurred transmit the data at the same
in the frame. time.
“ A frame can be defined as the
digital data transmission unit
in telecommunication and
computer networking. ”
Frame: A message is usually broken into small pieces, which are called as Frames

A frame is a straight-forward network packet in the packet-switched


systems.
Framing
► Framing in the DLL separates a message from one source to destination or from other
message to other destination.
► The Physical layer provides continuous bit stream of row data without any error
checking to DLL.
► DLL breaks row stream of a data into frame and compute the checksum for every frame.
► When a frame arrives checksum is re computed generates error report and send
acknowledgment.
Frame design consideration
► 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.
► Handling errors: Framing errors may occur due to noise or other transmission
errors, which can cause a station to misinterpret the frame. Therefore, error
detection and correction mechanisms, such as cyclic redundancy check (CRC), are
used to ensure the integrity of the frame.
► Framing overhead: Every frame has a header and a trailer that contains control
information such as source and destination address, error detection code, and
other protocol-related information. This overhead reduces the available bandwidth
for data transmission, especially for small-sized frames.
Frame design consideration
► Framing incompatibility: Different networking devices and protocols may use
different framing methods, which can lead to framing incompatibility issues. For
example, if a device using one framing method sends data to a device using a
different framing method, the receiving device may not be able to correctly
interpret the frame.
► Framing synchronization: Stations must be synchronized with each other to avoid
collisions and ensure reliable communication. Synchronization requires that all
stations agree on the frame boundaries and timing, which can be challenging in
complex networks with many devices and varying traffic loads.
► Framing efficiency: Framing should be designed to minimize the amount of data
overhead while maximizing the available bandwidth for data transmission.
Inefficient framing methods can lead to lower network performance and higher
latency.
Types of Framing
► There are 2 types of framing:
► Fixed Size
► Variable Size
Fixed Length Frames
The first type of frames is of fixed size. There is no requirement to give
boundaries to any frame because frame length behaves as a delemiter itself.
► Drawback: It goes through internal fragmentation when the size of data is
less than as compared to the size of the frame.
► Quick Fix: Padding
Variable length Frame

There is no requirement to describe frame end as well as starting of the


upcoming frame to characterize this type of framing. It could be implemented
in two different forms:
► Length field: In a frame, we can define the length field to show the length of a frame. It is
applied in the Ethernet (802.3). The issue with it is that the length field may get corrupted
sometimes.
► ED (End Delimeter): In a frame, we can address an end delimeter to show the completion of a
frame. It is applied in the Token Ring. The issue with it is that the end delimeter can appear in
the data.
► Bit Stuffing: An arrangement of bits of random length can be stuffed in a message for
differentiating through the delimeter. Also, it is known as bit-oriented framing.
► Byte Stuffing: The bytes are stuffed in a message for differentiating through the delimeter. Also,
it is known as character-oriented framing.
Framing Technique
Character Count

► It is a method of including the length of a frame in header so that we can be aware of the frame
length and end of frame where the count is over.

Header Payload Trailer


(Data)

► If header is Hello. length = 5. for checksum


► If the count is change during transmission it can make the receiver. go out of synchronization.
► Even if the checksum is incorrect and know that the frame is bad it can not find new frame
starting point
► Ask for re-transmission does not work either since destination does not know how many
character to skip over to get start of retransmission.
► Problem with Character Count:
► Asking for re-transmission doesn’t work.
► If character count is changed all frame get garbage.
► Checksum method not work for getting the start point of next frame.
Framing Technique
Character Stuffing
► Character stuffing is also known as byte stuffing or character-oriented framing and
is same as that of bit stuffing but byte stuffing actually operates on bytes whereas
bit stuffing operates on bits.
► In byte stuffing, special byte that is basically known as ESC (Escape Character) that
has predefined pattern is generally added to data section of the data stream or
frame when there is message or character that has same pattern as that of flag
byte.
► But receiver removes this ESC and keeps data part that causes some problems or
issues. In simple words, we can say that character stuffing is addition of 1
additional byte if there is presence of ESC or flag in text.

Flag Header Payload Field Trailer Flag

Original Text After Stuffing

A Flag B A ESC Flag B

A ECS B A ESC ESC B


Framing Technique
Bit Stuffing
► Bit stuffing is also known as bit-oriented framing or bit-oriented approach.
► In bit stuffing, extra bits are being added by network protocol designers to data
streams.
► It is generally insertion or addition of extra bits into transmission unit or message
to be transmitted as simple way to provide and give signaling information and
data to receiver and to avoid or ignore appearance of unintended or unnecessary
control sequences.
► It is type of protocol management simply performed to break up bit pattern that
results in transmission to go out of synchronization.

► Bit stuffing is very essential part of transmission process in network and


communication protocol. It is also required in USB.
Framing Technique
Physical Layer Coding Violations
► Encoding violation is method that is used only for network in which encoding on
physical medium includes some sort of redundancy i.e., use of more than one
graphical or visual structure to simply encode or represent one variable of data.
Error Types Types of Errors

► Single Bit Error

Single Bit Error Burst Errors

does not appear more likely in Serial Data Transmission.


For example, Sender sends the data at 10 Mbps, this means that the bit lasts only for 1 ?s
and for a single-bit error to occurred, a noise must be more than 1 ?s.
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.
Error Types
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.

► The duration of noise in Burst Error is more than the duration of noise in Single-Bit.
► Burst Errors are most likely to occurr in Serial Data Transmission.
► The number of affected bits depends on the duration of the noise and data rate.
Error Detecting Techniques
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.

DRAWBACKS OF 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.
Error Detecting Techniques
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.
DRAWBACK OF TWO - DIMENSIONAL PARITY CHECK
► 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.
► This technique cannot be used to detect the 4-bit errors or more in some cases.
Error Detecting Techniques
CHECKSUM
► A Checksum is generated at the sending side.
► Checksum generator subdivides the data into equal segments of n bits each, and all these
segments are added together by using one's complement arithmetic.
► The sum is complemented and appended to the original data, known as checksum field.
► The extended data is transmitted across the network.
The Sender follows the given steps:
► The block unit is divided into k sections, and each of n bits.
► All the k sections are added together by using one's complement to get the sum.
► The sum is complemented and it becomes the checksum field.
► The original data and checksum field are sent across the network.

► The Sender follows the given steps:


► The block unit is divided into k sections, and each of n bits.
► All the k sections are added together by using one's complement to get the sum.
► The sum is complemented and it becomes the checksum field.
► The original data and checksum field are sent across the network.
The Receiver follows the given steps:
► The block unit is divided into k sections and each of n bits.
► All the k sections are added together by using one's complement algorithm to get the sum.
► The sum is complemented.
► If the result of the sum is zero, then the data is accepted otherwise the data is discarded.
Error Detecting Techniques
CRC
► In CRC technique, a string of n 0s is appended to the data unit, and this n number is less
than the number of bits in a predetermined number, known as division which is n+1 bits.
► Secondly, the newly extended data is divided by a divisor using a process is known as
binary division. The remainder generated from this division is known as CRC remainder.
► Thirdly, the CRC remainder replaces the appended 0s at the end of the original data. This
newly generated unit is sent to the receiver.
► The receiver receives the data followed by the CRC remainder. The receiver will treat this
whole unit as a single unit, and it is divided by the same divisor that was used to find the
CRC remainder.
CRC Generator
► A CRC generator uses a modulo-2 division. Firstly, three zeroes are appended at the end of
the data as the length of the divisor is 4 and we know that the length of the string 0s to be
appended is always one less than the length of the divisor.
► Now, the string becomes 11100000, and the resultant string is divided by the divisor 1001.
► The remainder generated from the binary division is known as CRC remainder. The
generated value of the CRC remainder is 111.
► CRC remainder replaces the appended string of 0s at the end of the data unit, and the final
string would be 11100111 which is sent across the network.
Error Detecting Techniques
CRC Checker
► The functionality of the CRC checker is similar to the CRC generator.
► When the string 11100111 is received at the receiving end, then CRC checker performs the
modulo-2 division.
► A string is divided by the same divisor, i.e., 1001.
► In this case, CRC checker generates the remainder of zero. Therefore, the data is accepted.
Error Correction Protocol
Hamming Code
► Hamming code is a set of error-correction codes that can be used to detect and correct the
errors that can occur when the data is moved or stored from the sender to the receiver.
► It is a technique developed by R.W. Hamming for error correction.
► Redundant bits – Redundant bits are extra binary bits that are generated and added to
the information-carrying bits of data transfer to ensure that no bits were lost during the
data transfer.
► The number of redundant bits can be calculated using the following formula:
2r ≥ d + r + 1
where, r = redundant bit, d = data bit
For Example :
Data: 11001101 then d=8 , thus r would be 4 as 24 ≥ 8+4+1 . here we are calculating power like if
20,21,22 or 23 can not be satisfied and 24 is satisfying the formula. Depending on the data bits r
will be changing respectively.
There are 2 Types of hamming code: Even Parity bit or Odd Parity bit
Types Of Hamming Code Parity Bits
Even Parity Bit Odd Parity Bit

In the case of even parity, for a given set In the case of odd parity, for a given set of
of bits, the number of 1’s are counted. If bits, the number of 1’s are counted. If that
that count is odd, the parity bit value is count is even, the parity bit value is set to 1,
set to 1, making the total count of making the total count of occurrences of 1’s
occurrences of 1’s an even number. If the an odd number. If the total number of 1’s in a
total number of 1’s in a given set of bits is given set of bits is already odd, the parity bit’s
already even, the parity bit’s value is 0. value is 0.

For Example: For Example:


110011001 - 1 110011001 - 0
110011101 - 0 110011101 - 1
00001010 - 0 00001010 - 1
Hamming Code Algorithms

► Step 1 - The position of the data bits and the number of redundant bits in
the original data. The number of redundant bits is deduced from the
expression [2r >= d+r+1].
► Step 2 - Fill in the data bits and redundant bit, and find the parity bit value
using the expression [2p, where, p - {0,1,2, …… n}].
► Step 3 - Fill the parity bit obtained in the original data and transmit the
data to the receiver side.
► Step 4 - Check the received data using the parity bit and detect any error
in the data, and in case damage is present, use the parity bit value to
correct the error.
Features of Hamming Code
Error Detection and Correction: Hamming code is designed to detect and correct single-bit errors
that may occur during the transmission of data. This ensures that the recipient receives the same
data that was transmitted by the sender.

Redundancy: Hamming code uses redundant bits to add additional information to the data being
transmitted. This redundancy allows the recipient to detect and correct errors that may have
occurred during transmission.

Efficiency: Hamming code is a relatively simple and efficient error-correction technique that does
not require a lot of computational resources. This makes it ideal for use in low-power and
low-bandwidth communication networks.

Widely Used: Hamming code is a widely used error-correction technique and is used in a variety of
applications, including telecommunications, computer networks, and data storage systems.

Single Error Correction: Hamming code is capable of correcting a single-bit error, which makes it
ideal for use in applications where errors are likely to occur due to external factors such as
electromagnetic interference.

Limited Multiple Error Correction: Hamming code can only correct a limited number of multiple
errors. In applications where multiple errors are likely to occur, more advanced error-correction
techniques may be required.
Error Control in Stop and Wait Mechanism
► Before understanding the stop and Wait protocol, we first know about the error control
mechanism.
► The error control mechanism is used so that the received data should be exactly same
whatever sender has sent the data.
► The error control mechanism is divided into two categories, i.e., Stop and Wait ARQ and
sliding window.
► The sliding window is further divided into two categories, i.e., Go Back N, and Selective
Repeat.
► Based on the usage, the people select the error control mechanism whether it is stop and
wait or sliding window.
Error Control in Stop and Wait Mechanism

Sender Receiver Sender side


► Rule 1: Sender sends one data packet at a time.
► Rule 2: Sender sends the next packet only when
Data
Pack it receives the acknowledgment of the previous
e t 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
ement before receiving the acknowledgment.
k no wledg
A c Receiver side
► Rule 1: Receive and then consume the data
packet.
Data ► Rule 2: When the data packet is consumed,
Pack
e
receiver sends the acknowledgment to the
t sender.
► Therefore, the idea of stop and wait protocol in
the receiver's side is also very simple, i.e.,
ent consume the packet, and once the packet is
dgem consumed, the acknowledgment is sent. This is
Ack nowle
known as a flow control mechanism.
Disadvantages of Stop and Wait Mechanism
► 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.
► Sender waits for an infinite amount of time for an acknowledgment.
► Receiver waits for an infinite amount of time for a data.

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

► 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.
Error Control in Sliding Window
Mechanism
► 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 (Transmission Control
Protocol).
► 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.

► 2 Types : Go-Back-N ARQ & Selective Repeat ARQ


Go-Back-N ARQ
► Go-Back-N ARQ protocol is also known as Go-Back-N Automatic Repeat Request.
► It is a data link layer protocol that uses a sliding window method.
► 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.

► The design of the Go-Back-N ARQ protocol is shown below.


Selective Repeat ARQ

► Selective Repeat ARQ is also known as the Selective Repeat Automatic Repeat
Request.
► It is a data link layer protocol that uses a sliding window method.
► 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.
► 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.
Go-Back-N ARQ V/S Selective Repeat ARQ
Go-Back-N ARQ Selective Repeat ARQ

If a frame is corrupted or lost in it,all In this, only the frame is sent again, which is
subsequent frames have to be sent again. corrupted or lost.

If it has a high error rate,it wastes a lot of There is a loss of low bandwidth.
bandwidth.

It is less complex. It is more complex because it has to do sorting


and searching as well. And it also requires
more storage.

It does not require sorting. In this, sorting is done to get the frames in the
correct order.

It does not require searching. The search operation is performed in it.

It is used more. It is used less because it is more complex.


Sequence numbering
► The 32-bit sequence number field specifies the number allocated to the segment's first
byte of data.
► TCP is a protocol for transporting data in streams. Each byte to be transmitted is
numbered to assure connectivity.
► Each party generates an initial sequence number (ISN) during connection establishment
using a random number generator, which is usually different in each direction.
► We know that a TCP sequence number is 32 bit.
► So it has finite (from 0 to (232-1) = 4 Giga sequence numbers) and it means we will be able
to send only 4GB of data with a unique sequence number not more than that.
► It helps with the allocation of a sequence number that does not conflict with other data
bytes transmitted over a TCP connection.
► An ISN is unique to each connection and separated by each device.
Sequence Numbering
TCP FIN,ACK ► Frame from a sender are numbered
Seq# = 2941 sequentially.
ACK=4982 ► We need to set a Limit. since we need to
TCP ACK include the sequence number for each
Seq# = 4982
frame in the header.
ACK=2941
► If the header of the frame allow m bits for
TCP FIN,ACK sequence number, the sequence number
Seq# = 2942 range from 0 to 2m-1
ACK=4983
TCP FIN,ACK
► We can repeat the sequence number in the
Seq# = 4982 header for
ACK=2942
m = 3, sequence number are
0 to2m-1
0to23-1
0 to 7
0,1,2,3,4,5,6,7
Piggybacking Acknowledgement
► Communications are mostly full – duplex in nature, i.e. data transmission occurs in both
directions.
► A method to achieve full – duplex communication is to consider both the communication as
a pair of simplex communication.
► Each link comprises a forward channel for sending data and a reverse channel for sending
acknowledgments.
► However, in the above arrangement, traffic load doubles for each data unit that is
transmitted.
► Half of all data transmission comprise of transmission of acknowledgments.
► So, a solution that provides better utilization of bandwidth is piggybacking.
► Here, sending of acknowledgment is delayed until the next data frame is available for
transmission.
► The acknowledgment is then hooked onto the outgoing data frame.
► The data frame consists of an ack field.
► The size of the ack field is only a few bits, while an acknowledgment frame comprises of
several bytes.
► Thus, a substantial gain is obtained in reducing bandwidth requirement.
Principle and Example
► If station X has both data and
acknowledgment to send, it sends a data
frame with the ack field containing the
sequence number of the frame to be
acknowledged.
► If station X has only an acknowledgment
to send, it waits for a finite period of time to
see whether a data frame is available to be
sent. If a data frame becomes available,
then it piggybacks the acknowledgment
with it. Otherwise, it sends an ACK frame.
► If station X has only a data frame to send, it
adds the last acknowledgment with it. The
station Y discards all duplicate
acknowledgments. Alternatively, station X
may send the data frame with the ack field
containing a bit combination denoting no
acknowledgment.

You might also like