CN-UNIT-2 - Data Link Layer
CN-UNIT-2 - Data Link Layer
CN-UNIT-2 - Data Link Layer
bottom.
● The data link layer is responsible for maintaining the data link between two hosts or nodes.
● The main functions and the design issues of this layer are
■ Framing
■ Addressing
■ Error Control
■ Flow Control
Providing Services to The Network Layer
● In the OSI Model, each layer uses the services of the layer below it and provides services
● The data link layer uses the services offered by the physical layer.
● The primary function of this layer is to provide a well defined service interface to network
● What the physical layer does is accept a raw bit stream and attempt to deliver it to the
destination.
● Physical layers only just accept and transfer stream of bits without any regard to meaning or
structure. Therefore it is up to data link layer to simply develop and recognize frame
boundaries.
● Framing purpose is to divide the stream of data from the network layer into manageable
● The data link layer encapsulates Network Layer Packets into Frames by adding header and
trailer information.
1. Frame Header: It contains the source and the destination addresses of the frame and
the control bytes.
1. Byte count
2. Flag bytes with byte stuffing
3. Flag bits with bit stuffing
1. Byte count
● This method is rarely used and is generally required to count total number of Bytes that are
● Byte count method ensures data link layer at the receiver about total number of Bytes that
: Without errors:
1. Byte count: : With errors:
● There is disadvantage also of using this method i.e., if anyhow Byte count is disturbed or
distorted by an error occurring during transmission, then destination or receiver might lose
synchronization.
● The destination or receiver might also be not able to locate or identify beginning of next
frame.
2. Flag bytes with byte stuffing
● The second framing method gets around the problem of resynchronization after an error by
● Often the same byte, called a flag byte, is used as both the starting and ending delimiter.
● Two consecutive flag bytes indicate the end of one frame and the start of the next. Thus, if
the receiver ever loses synchronization it can just search for two flag bytes to find the end
have the sender’s data link layer insert a special escape byte (ESC) just before each
● Thus, a framing flag byte can be distinguished from one in the data by the absence or
● The data link layer on the receiving end removes the escape bytes before giving the data to
● It was developed for the once very popular HDLC (Highlevel Data Link Control) protocol.
● Each frame begins and ends with a special bit pattern, 01111110
0111111 0111111
0 0
A Frame delimited by a flag byte 01111110
● Whenever the sender’s data link layer encounters five consecutive 1s in the data, it
Switch
1. MAC Address (Media Access Control Address)
● MAC addresses are unique identifiers assigned to Network Interface Cards (NICs) at
the factory.
● They consist of 6 bytes (48 bits) and are usually represented in 12-digit hexadecimal
● MAC addresses are globally unique, allowing each network device to have a unique
identifier.
● The source and destination MAC addresses are included in the frame header of data
● The data link layer ensures error free link for data transmission. The issues it caters to with
● The data link layer regulates flow control so that a fast sender does not drown a slow
receiver.
● When the sender sends frames at very high speeds, a slow receiver may not be able to
handle it. There will be frame losses even if the transmission is error-free.
● A single-bit error refers to a type of data transmission error that occurs when one bit (i.e.,
a single binary digit) of a transmitted data unit is altered during transmission, resulting in
● For each column, parity check bits are computed and transmitted together with the data.
● These are compared with the parity bits calculated on the received data at the receiving end.
2. Checksum:
Checksum is a error detection which detects the error by dividing the data into the segments of equal
size and then use 1's complement to find the sum of the segments and then sum is transmitted with
the data to the receiver and same process is done by the receiver and at the receiver side, all zeros in
the sum indicates the correctness of the data.
➔ First of all data is divided into k segments in a checksum error detection scheme and each
segment has m bits.
➔ For finding out the sum at the sender’s side, all segments are added through 1's complement
arithmetic. And for determining the checksum we complement the sum.
➔ Along with data segments, the checksum segments are also transferred.
➔ All the segments that are received on the receiver's side are added through 1’s complement
arithmetic to determine the sum. Then complement the sum also.
➔ The received data is accepted only on the condition that the result is found to be 0. And if the
result is not 0 then it will be discarded.
11011010
Check Sum
Eg: 10110011 10101011 01011010 11010101, K=4 & m=8
Sum = ? Sum = ?
CheckSum = ? CheckSum = ?
3. Cyclic Redundancy Checks (CRCs) or polynomial code:
● Unlike the checksum scheme, which is based on addition, CRC is based on binary division.
● In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are appended to the
end of the data unit so that the resulting data unit becomes exactly divisible by a second,
predetermined binary number.
● The sender divides the bits that are being transferred and calculates the remainder.
● The sender inserts the remainder at the end of the original bits before sending the actual
bits.
● A codeword is made up of the actual data bits plus the remainder. The transmitter sends data
bits in the form of codewords.
● The receiver, on the other hand, divides the codewords using the same CRC divisor.
● If the remainder consists entirely of zeros, the data bits are validated; otherwise, it is assumed
that some data corruption happened during transmission.
Cyclic Redundancy Checks
Eg:
A bit stream 1010000 is transmitted using the standard CRC
method. The generator polynomial is x^3+1. What is the actual bit
string transmitted? Conclude whether the receiver receive original
message or error message.
Examples:
1. A bit stream 1101011011 is transmitted using the standard CRC method. The
generator polynomial is x4+x+1. What is the actual bit string transmitted?
Solution:
★ Hamming codes
★ Binary convolutional codes
★ Reed-Solomon codes
★ Low-Density Parity Check codes
★ Error Correction codes are used to detect and correct errors that occur during data
transmission from the transmitter to the receiver.
★ There are two approaches to error correction:
1. Backward Error Correction:
When a backward mistake is detected, the receiver requests that the sender retransmit the
complete data unit.
2. Forward Error Correction:
In this scenario, the error-correcting code is used by the receiver, which automatically corrects
the mistakes.
★ A single extra bit can identify but not correct the errors.
★ To correct the mistakes, the specific location of the error must be known.
★ If we wish to compute a single-bit mistake, for example, the error correcting algorithm will
identify which one of seven bits is incorrect. We will need to add some more redundant bits to
do this.
★ The number of redundant bits is calculated using the following formula:
★ The above formula is used to compute the value of r. For example, if the value of d is 4, the
least possible number that fulfils the above relation is 3.
Hamming codes
★ It is a block code that is capable of detecting up to two simultaneous bit errors and
correcting single-bit errors.
★ Parity bits: A bit that is added to the original binary data to make sure the total number of
1s is even or odd (in case of even or odd parity respectively).
○ Even parity: To check for even parity, if the total number of 1s is even, the parity bit
value is 0. If the total number of occurrences of 1s is odd, the parity bit value is 1.
○ Odd Parity: To test for odd parity, if the total number of 1s is even, the parity bit
value is 1. If the total number of 1s is odd, the parity bit value is 0.
Hamming codes
Algorithm of Hamming code:
1. An information of 'd' bits are added to the redundant bits 'r' to form d+r.
2. The location of each of the (d+r) digits is assigned a decimal value.
3. The 'r' bits are placed in the positions 1,2,.....2k-1.
4. At the receiving end, the parity bits are recalculated. The decimal value of the parity bits
determines the position of an error.
● 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.
Determining the Parity bits
● Determining the 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.
Determining the r4 bit
○ 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.
* Data transferred is given below:
Example: If the data to be transmitted is 1011001
Flow Control
Elementary data link protocols
Flow control
★ Flow control is a Speed Matching Mechanism.
★ Flow control in the data link layer is a mechanism used to manage the rate of data
transmission between the sender and the receiver.
★ It ensures that the sender does not overwhelm the receiver with more data than it can
handle, preventing data loss or buffer overflow.
★ Flow control is set of procedures that tells the sender how much data it can transmit before it
must wait for an acknowledgement from the receiver.
★ Receiver must inform the sender before the limits are reached and request that the sender to
send fewer frames or stop temporarily.
★ There are different protocols involved in Flow Control.
What is Protocol?
★ In computer networks, a protocol refers to a set of rules and procedures that govern the
communication and interaction between devices or systems.
★ It defines how data is transmitted, formatted, addressed, routed, and processed in a network.
★ Protocols ensure that devices can understand and interpret the information exchanged,
allowing for reliable and standardized communication.
Sliding
Window
Protocol
Stop and wait Protocol
★ It is a basic protocol used for reliable data transmission between a sender and a receiver when
there is no noise or errors in the channel.
Sender: Receiver:
● The sender sends a single frame to the ● The receiver receives a frame from the
receiver. sender.
● After sending the frame, it waits for an ● If the frame is error-free, the receiver
acknowledgment (ACK) from the sends an ACK back to the sender
receiver. indicating successful reception.
● If the sender receives the ACK, it assumes ● If the frame contains errors, the receiver
that the frame was successfully received discards the frame and does not send an
by the receiver and proceeds to send the ACK.
next frame. ● The receiver waits for the sender to
● If the sender does not receive the ACK retransmit the frame if it does not
within a specified time, it assumes that the receive a valid frame.
frame was lost and retransmits the same
frame.
Flow diagram for Stop & Wait Protocol
Problems of Stop and Wait Protocol
[1] The Ack is received before the timer [2] The Ack is lost
Expires
All possible scenarios of this protocol are explain under
★ Go-Back-N ARQ
★ Selective Repeat ARQ
Sliding Window Protocol
★ The Sliding Window Protocol is a flow control protocol used in data communication to allow efficient
and reliable transmission of data between a sender and a receiver.
★ It is an extension of the Stop-and-Wait protocol and overcomes its limitations by allowing multiple
frames to be in transit without waiting for individual acknowledgments.
★ The number of frames to be sent based on the Window Size.
★ Sender:
○ The sender maintains a "window" that represents the range of acceptable sequence numbers for
the frames it can send.
○ The sender can transmit multiple frames within the window without waiting for
acknowledgments.
○ As frames are sent, the sender slides the window forward.
○ The sender starts a timer for the first frame in the window.
Sliding Window Protocol
★ Receiver:
○ The receiver maintains a corresponding "window" that represents the range of acceptable
sequence numbers for the frames it expects to receive.
○ The receiver acknowledges the frames it successfully receives, indicating the next expected
sequence number.
○ If a frame is received out of order or contains errors, the receiver discards the frame and does not
send an acknowledgment.
○ The receiver can accept frames within its window and slides the window forward as it receives
valid frames.
Working of Sliding Window Protocol
Example :
For example, suppose there are 11 frames required transmitting and sender window size is 4
then the sequence number will be 0,1,2,3, 0,1,2,3, 0, 1 and 2.
Step 1: 11 frames (0-10), window size, sender and receiver are shown below
Working of Sliding Window Protocol
Step 2:After sending all frames equal to window size, Sender wait for ACK from receiver of
first frame (i.e. 0).
Working of Sliding Window Protocol
Step 3:After receiving the ACK the Sliding window moves one position next and transmit
frame 4 and frame No.4 is transmitted.
Working of Sliding Window Protocol
Step 4:After transmission of frame No.4, Sender waits for ACK from receiver of Second
frame (i.e. 1).
Working of Sliding Window Protocol
Step 5:After receiving ACK for Frame No.1 Sender transmit the Next frame No.5 by moving
the sliding window one position next and so on.
Working of Sliding Window Protocol
Variations of Sliding Window Protocol
Sender's
Window
Size
★ Go-Back-N ARQ
★ Selective Repeat ARQ
Go-Back-N ARQ
● In Go-Back-N ARQ, N is the sender's window size. Suppose we say that Go-Back-3,
which means that the three frames can be sent at a time before expecting the
acknowledgment from the receiver.
● It uses the principle of protocol pipelining in which the multiple frames can be sent before
receiving the acknowledgment of the first frame. If we have five frames and the concept is
Go-Back-3, which means that the three frames can be sent, i.e., frame no 1, frame no 2,
frame no 3 can be sent before expecting the acknowledgment of frame no 1.
● In Go-Back-N ARQ, the frames are numbered sequentially as Go-Back-N ARQ sends the
multiple frames at a time that requires the numbering approach to distinguish the frame
from another frame, and these numbers are known as the sequential numbers.
● The number of frames that can be sent at a time totally depends on the size of the sender's
window.
● So, we can say that 'N' is the number of frames that can be sent at a time before receiving
● If the acknowledgment of a frame is not received within an agreed-upon time period, then
○ Suppose we have sent the frame no 5, but we didn't receive the acknowledgment of
frame no 5, and the current window is holding three frames, then these three frames
will be retransmitted.
Working of Go-Back-N ARQ
Example : For example, suppose there are 11 frames required transmitting and sender
window size is 4
Step 1: Step 1: Firstly, the sender will send the first four frames to the receiver, i.e., 0,1,2,3,
and now the sender is expected to receive the acknowledgment of the 0th frame.
Working of Go-Back-N ARQ
Step 2: Let's assume that the receiver has sent the acknowledgment for the 0 frame, and the
receiver has successfully received it.
Working of Go-Back-N ARQ
Step 3: The sender will then send the next frame, i.e., 4, and the window slides containing
four frames (1,2,3,4).
Working of Go-Back-N ARQ
Step 4: The receiver will then send the acknowledgment for the frame no 1. After receiving
the acknowledgment, the sender will send the next frame, i.e., frame no 5, and the window
will slide having four frames (2,3,4,5).
Step 5: Now, let's assume that the receiver is not acknowledging the frame no 2, either the
frame is lost, or the acknowledgment is lost. Instead of sending the frame no 6, the sender
Go-Back to 2, which is the first frame of the current window, retransmits all the frames in the
current window, i.e., 2,3,4,5.
Selective Repeat ARQ
● In selective repeat, both the sender and receiver maintain a window. The sender can
transmit multiple packets within the window, and the receiver acknowledges each correctly
received packet.
● If the sender does not receive an acknowledgment for a specific packet within a
timeout period, it retransmits only that packet, instead of retransmitting the entire
window.
If a frame is corrupted or lost in it,all subsequent In this, only the frame is sent again, which is corrupted or lost.
If it has a high error rate,it wastes a lot of There is a loss of low bandwidth.
bandwidth.
It does not require sorting. In this, sorting is done to get the frames in the correct order.
● Importance of HDLC.
CRC
Frame Format of HDLC
● Flag: The frame starts and ends with a flag delimiter, which is an 8-bit sequence. The most
commonly used flag sequence is 01111110.
● Address: The address field is used to specify the source and destination devices. It can be 1 to
8 bits long, depending on the configuration of the HDLC variant.
● Control: The control field is used to indicate the frame type and control information. It is
typically 8 bits long and contains various control bits for different purposes, such as indicating
supervisory frames, information frames, or commands.
● Information: The information field carries the actual data being transmitted. Its length can vary
depending on the needs of the application.
● Cyclic Redundancy Check (CRC): a CRC (Cyclic Redundancy Check) value, which is
calculated based on the frame's data and control fields. The receiver uses the CRC value to
check for errors in the received frame.
● Flag: The frame ends with another flag delimiter, which is the same 8-bit sequence used at the
beginning of the frame.
Types of HDLC Frames
Control Field –
● HDLC generally uses this field to determine how to control process of communication.
● The control field is different for different types of frames in HDLC protocol.
● The types of frames can be
○ Information frame (I-frame)
○ Supervisory frame (S-frame)
○ Un-numbered frame (U-frame).
S-Frame In the control field if the first bit is 10 Used for Error Control and Flow Control
U-Frame In the control field if the first bit is 11 Used for Link Management
The data link layer in the internet
I. In the Internet, the data link layer is responsible for the reliable transmission of data over a
physical network link.
II. It sits above the physical layer and below the network layer in the networking protocol stack.
While the Internet Protocol (IP) primarily operates at the network layer, the data link layer is
essential for the proper functioning of IP-based communication.
III. The data link layer in the Internet encompasses various protocols and technologies, including:
A. Ethernet: Ethernet is the most commonly used technology at the data link layer in local
area networks (LANs). It defines the standards for wired communication, specifying the
physical and data link layer protocols for transmitting data between devices connected to
the same LAN.
B. Wi-Fi (Wireless LAN): Wi-Fi is a wireless data link layer technology that enables
devices to connect to a network wirelessly. It uses protocols such as IEEE 802.11 to
establish wireless connections and handle data transmission over the air.
C. Point-to-Point Protocol (PPP): PPP is a data link layer protocol used for establishing direct
point-to-point connections over various physical links, including dial-up connections and dedicated
serial links. It provides authentication, error detection, and framing capabilities.
D. Asynchronous Transfer Mode (ATM): Although less commonly used in modern networks,
ATM was a data link layer technology that provided high-speed transmission of fixed-size cells. It
was used in wide area networks (WANs) and for certain specialized applications.
E. MPLS (Multi-Protocol Label Switching): MPLS is a protocol that operates at both the network
and data link layers. It adds a label to IP packets at the data link layer, allowing routers to make
forwarding decisions based on the label rather than examining the entire IP header.
Syllabus
● The Media Access Sub Layer
.
Static Channel Allocation in LANs and MANs:
● It is the classical or traditional approach of allocating a single channel among multiple
competing users using Frequency Division Multiplexing (FDM).
● If there are N users, the frequency channel is divided into N equal sized portions (bandwidth),
each user being assigned one portion. since each user has a private frequency band, there is no
interference between users.
● It is not efficient to divide into fixed number of chunks.
➔ Throughput = G exp{-2*G}
➔ Maximum throughput = 0.184 for G=0.5
SLOTTED ALOHA
● Slotted ALOHA is an improvement over ALOHA and Pure ALOHA, introducing a
● Devices are allowed to transmit only at the beginning of each time slot.
● If a collision occurs, the devices involved wait for the next time slot to retransmit.
● If a station misses out the allowed time, it must wait for the next slot, This reduces the
probability of collision.
Slotted Aloha
Vulnerable Time
➔ CSMA/CD was widely used in early Ethernet networks based on coaxial or twisted-pair
cables.
➔ However, with the advent of faster Ethernet technologies and the prevalence of switched
networks, CSMA/CD has become less common.
Carrier Sense Multiple Access with Collision Avoidance
(CSMA/CA)
➔ CSMA/CA stands for Carrier Sense Multiple Access with Collision Avoidance.
➔ It is a protocol used in wireless networks, particularly Wi-Fi networks, to manage access to
the shared wireless medium and prevent collisions.
➔ Unlike CSMA/CD, which is used in wired Ethernet networks, CSMA/CA is designed for
wireless networks where collisions cannot be reliably detected due to the "hidden node"
problem.
➔ The hidden node problem occurs when two devices are out of range of each other but within
range of the access point, making it difficult for them to sense each other's transmissions.