Data Link Layer
Data Link Layer
➢ The Data Link Layer is the second layer in the OSI (Open Systems Interconnection) model,
lying just above the Physical Layer.
➢ Its main job is to provide reliable communication between directly connected nodes over
a physical medium.
5) Physical Addressing
o Adds MAC (Media Access Control) addresses to the frames so that devices on the same network
can identify each other.
o MAC address is unique for every network interface card (NIC).
2
Data link layer …
3
IEEE 802 standards
▪ The IEEE 802 is a set of networking standards created by the Institute of Electrical and Electronics
Engineers (IEEE) for local area networks (LANs) and metropolitan area networks (MANs).
▪ It defines how data is transmitted over a network at Layer 1 (Physical Layer) and Layer 2 (Data Link
Layer) of the OSI model.
4
DLL Sub-layer
5
DLL Sub-layer
IEEE 802 Layers (in Data Link Layer)
The Data Link Layer is split into two sublayers:
[Link] (Logical Link Control) – IEEE 802.2
Handles error checking and control.
[Link] (Media Access Control) – Defined by standards like:
a) 802.3 for Ethernet
b) 802.11 for Wi-Fi
Handles addressing (MAC address) and access to the medium.
6
DLL Sub-layer
1) LLC Sublayer (Logical Link Control)
What it does:
▪ Works above MAC.
▪ Provides error checking and flow control.
▪ Allows multiple network protocols (like IP, IPX) to work over the same MAC.
Key Tasks:
▪ Identifies protocol type (like IP or ARP)
▪ Adds control info in the header
▪ Ensures data integrity
7
DLL Sub-layer
2) MAC Sublayer (Media Access Control)
What it does:
▪ Adds MAC address (physical address) to frames.
▪ Controls when and how devices use the network.
▪ Detects collisions on the medium.
▪ Used in both wired (Ethernet) and wireless (Wi-Fi) networks.
Key Tasks:
▪ Frame formatting
▪ Access control (who can send data)
▪ Error detection (e.g., CRC)
Example: In Ethernet (IEEE 802.3), MAC decides when a device can send data using CSMA/CD.
8
Data link layer Frame
o Framing is the process of dividing a stream of bits received from the network layer into
manageable units called frames.
o It also involves adding headers and sometimes trailers to define the beginning and end of
each frame.
1. FLAG
▪ Marks the start and end of a frame.
▪ Used in Bit stuffing and Byte stuffing
▪ A unique pattern is used as a flag (e.g., 01111110 in HDLC).
▪ Two flags are used: one at the beginning and one at the end of the frame.
9
Data link layer Frame …
2. HEADER
o It Carries control information needed to deliver the frame.
o Contains
▪ Source and Destination MAC Address
▪ Frame type / Protocol info
▪ Sequence numbers (in reliable protocols)
▪ Control bits (ACK, NAK, etc.)
3. TRAILER
o Used for error detection and sometimes padding.
o Contains:
▪ CRC (Cyclic Redundancy Check)
▪ Checksum
10
Data link layer Frame …
There are two main categories of framing methods:
Framing
Techniques
Character
Byte Stuffing Bit Stuffing
Count
11
Data link layer Frame …
1) Fixed Size Framing
o All frames are of same size.
o No need for start or end delimiters.
o Receiver divides the bit stream into frames based on size.
Advantages:
o Simple and fast.
Disadvantages:
o Wastes space if data doesn’t exactly fit the frame size.
o No flexibility for variable-size data.
13
Data link layer Frame …
b) Byte Stuffing
Byte stuffing is the process of adding 1 extra byte whenever there is a flag or escape
character in the text
14
Data link layer Frame …
c) Bit Stuffing
Bit stuffing is the process of adding one extra 0 whenever five consecutive 1’s follow a 0 in the
data, so that the receiver does not mistake the pattern 0111110 for a flag
15
Error Control
Error control in the Data Link Layer (DLL) ensures reliable transmission of data by detecting and
possibly correcting errors that occur during transmission .
Types of Errors:
1) Single-bit Error:
Only one bit in the frame is
altered.
2) Burst Error:
Two or more bits in the frame are
altered (common in real networks). 16
Error Control …
Error Detection Techniques :
These methods detect whether an error occurred in the transmitted frame.
a) Hamming Code
o Adds redundant bits that can locate and correct single-bit errors.
o Used in memory and real-time systems.
18
Error Control …
Retransmission Techniques :
o Any time an error is detected in an exchange, specified frames are retransmitted. This
process is called automatic repeat request (ARQ)
o i.e. If an error is detected, ARQ protocols ask for retransmission.
19
Flow Control
o Flow Control is a technique used in the Data Link
Layer to prevent the sender from overwhelming
the receiver with too much data too quickly.
o It ensures that data is sent at a rate that the
receiver can process and store without loss.
20
Flow Control …
1) Noiseless Channel
a) Simplest
o The Simplest Protocol is a basic data
transmission protocol used for theoretical
understanding of data link layer operations
Disadvantages:
o Not practical in real-world networks
o Cannot handle:
▪ Frame loss
▪ Errors
▪ Buffer overflow at receiver
o No way to confirm if data was received
22
Flow Control …
b) Stop and Wait
o Sender sends a data packet to the receiver.
o Sender stops and waits for the acknowledgement for the sent
packet from the receiver.
o Receiver receives and processes the data packet.
o Receiver sends an acknowledgement to the sender.
o After receiving the acknowledgement, sender sends the next
data packet to the receiver.
Advantages:
o Simple to implement.
Disadvantages:
o Low efficiency, especially on long-delay (high-latency) links.
23
Flow Control …
2) Noisy Channel
Sliding Window Protocol
o Allows sender to send multiple frames before waiting for ACK.
o Uses a window to define the number of unacknowledged frames allowed.
Components:
o Sender Window Size (N): Maximum frames sender can send without ACK.
o Receiver Window Size: Number of frames the receiver can buffer.
Advantages:
o High efficiency.
o Keeps pipeline full and better use of bandwidth.
Disadvantages:
o More complex.
o Needs sequence numbers and buffering.
24
Flow Control …
a) Stop and Wait ARQ
o The communication channel is noisy.
o Errors may get introduced in the data during the transmission.
o Stop and wait ARQ works similar to stop and wait protocol.
o It provides a solution to all the limitations of stop and wait protocol.
o Stop and wait ARQ includes the following three extra elements.
25
Flow Control …
Stop and wait ARQ is a one bit sliding window protocol where-
•Sender window size = 1
•Receiver window size = 1
Thus,
Minimum number of sequence numbers required in Stop and Wait ARQ = 2.
The two sequence numbers used are 0 and 1.
26
Flow Control …
Problem of Lost Data Packet-
27
Flow Control …
Problem of Lost Acknowledgement-
28
Flow Control …
29
Flow Control …
Difference between Stop-and-wait & stop-and-wait ARQ
30
Flow Control …
b) GO Back N ARQ
Working:
o Sender transmits multiple frames up to a certain window size.
o Receiver checks each frame:
▪ If correct: it sends an ACK (acknowledgment).
▪ If incorrect: it discards the bad frame and sends a NACK (negative acknowledgment) or does
not send an ACK.
o Sender: Retransmits only those frames for which NACKs were received or ACKs were missing after
timeout.
o Receiver buffers the out-of-order correct frames until the missing frame is received.
32
Flow Control …
Difference between Stop-and-Wait , Go-Back-N & Selective ARQ
33
Link Layer Addressing
Link Layer Addressing is how devices on the same local network identify and communicate
with each other.
34
ARP Protocol
ARP (Address Resolution Protocol)
o ARP (Address Resolution Protocol) is a network protocol used to find the MAC address of a device
from its IP address in a local network.
o It works at the Data Link Layer (Layer 2) but uses information from the Network Layer (Layer 3).
35
Random Access
➢ Random Access Control is a media access control (MAC) method used when multiple devices share a
communication channel (like in Ethernet or Wi-Fi).
➢ It allows any device to transmit at any time, without permission, making it simple but sometimes
prone to collisions.
Random
Access
Protocol
Pure Slotted
ALOHA ALOHA
36
ALOHA
o ALOHA is a random access protocol used to control how multiple devices share a single
communication channel, like in wireless networks or satellites.
o It was one of the earliest MAC protocols, developed at the University of Hawaii.
o Devices send whenever they want.
o If collision → wait random time and retransmit.
37
ALOHA …
➢ This figure illustrates how collisions occur in a
Pure ALOHA system.
➢ It shows four stations (devices) trying to send
frames at random times over a shared channel.
38
ALOHA …
This figure shows how Slotted ALOHA works
and how collisions happen when multiple
stations transmit in the same time slot.
1) Slot 1
▪ Only Station 1 transmits.
▪ No collision.
▪ Successful transmission.
2) Slot 2 4) Slot 4
▪ Stations 2, 3, and 4 transmit at the same ▪ Only Station 4 transmits.
time. ▪ Successful transmission.
▪ Collision occurs.
▪ None of the data is received correctly. 5) Slot 5
▪ Only Station 3 transmits.
3) Slot 3 ▪ Successful.
▪ Stations 1, 2, and 3 transmit again.
▪ Another collision. 6) Slot 6
▪ Data is lost again. ▪ No transmission (idle slot). 39
CSMA
CSMA (Carrier Sense Multiple Access)
CSMA is a random access protocol used in
networks to avoid collisions before sending data.
▪ It shows two computers (B and C) trying to send data at almost the same time in a network.
▪ Computer B starts sending at time t₁.
▪ Computer C doesn’t know B is sending (because B's signal hasn't reached C yet).
▪ So, C also starts sending at time t₂.
▪ The signals from B and C crash into each other — this is a collision.
▪ The area where the signals overlap (gray part) is where data is lost.
40
CSMA/CD
CSMA/CD – Carrier Sense Multiple Access with Collision Detection
CSMA/CD is a method used in wired networks (like Ethernet) to avoid data collisions when multiple
devices try to send data at the same time.
How it works:
a) Sense the channel:
Is the line free? If yes, then send data.
Send data.
b) Keep listening:
While sending, check for collision by detecting noise.
c) If collision happens:
Stop sending immediately.
Send a jamming signal (to inform others about the collision).
Wait a random time (backoff).
Try again.
41
CSMA/CD …
This diagram explains collision and abortion in
CSMA/CD (Carrier Sense Multiple Access with
Collision Detection) in a simple timeline format.
42
CSMA/CA
CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance)
43
CSMA/CA …
The diagram Figure 12.17 CSMA/CA and NAV shows
how CSMA/CA (Carrier Sense Multiple Access with
Collision Avoidance) works using RTS/CTS signals
and NAV (Network Allocation Vector) to prevent
collisions in wireless communication (like Wi-Fi).
44
CSMA/CA …
1) A waits for DIFS (Distributed Inter-Frame 4) C and D set NAV (Network Allocation Vector)
Space) ▪ C and D hear CTS, so they set their NAV
▪ A checks the channel. If idle, waits for — this is a timer that tells them to stay
DIFS time (a small gap). silent for the given duration.
▪ This is collision avoidance: other stations
2) A sends RTS (Request To Send) won’t try to transmit during that time.
▪ A sends a small control message: “Can I
send data?” 5) A sends the actual Data
▪ This includes duration information ▪ Now that the channel is clear, A sends
(how long data + ACK will take). the full data frame.
3) B replies with CTS (Clear To Send) 6) B sends ACK (Acknowledgement)
▪ B replies with CTS, saying “Yes, go ▪ After receiving data, B waits a SIFS (Short
ahead”. Inter-Frame Space) and sends ACK.
▪ It also includes the same duration info. ▪ This tells A the data was received
successfully.
45
HDLC
➢ High-Level Data Link Control.
➢ It is a bit-oriented protocol developed by ISO for reliable communication.
Features of HDLC:
o Bit-oriented protocol → Uses bit patterns for framing (not characters).
o Works at Data Link Layer (Layer 2 of OSI model).
o Error detection → Uses CRC (Cyclic Redundancy Check).
o Reliable communication → Supports flow and error control.
46
HDLC …
Types of Stations in HDLC:
[Link] Station
o Controls the operation of the link.
o Responsible for initiating communication.
o Sends commands to secondary stations.
o Maintains error and flow control.
[Link] Station
o Works under the control of the primary station.
o Cannot start communication on its own.
o Sends responses back to the primary.
[Link] Station
o Has features of both primary and secondary.
o Can send commands and responses.
o Used in peer-to-peer communication.
47
HDLC …
Modes of Communication (based on stations):
48
HDLC …
HDLC Frame:
o Flag → 01111110 (marks start & end of a frame).
o Address → Identifies the secondary station.
o Control → Defines type of frame (I, S, or U).
o Information → Actual data (only in I-frames).
o FCS (Frame Check Sequence) → Error detection (CRC).
49
HDLC …
Types of HDLC Frames:
1) I – frame
➢ Information Frame
➢ Used to carry user data & some control information.
50
HDLC …
2) S – Frame
➢ Supervisory Frame
➢ Used for flow control and error control, not for user data.
51
HDLC …
3) U – Frame
➢ Unnumbered Frame
➢ Used for control, link management, and special purposes
Management Information:
o The Information field of a U-frame can be used for
management/control data.
o This is not user payload, but rather link management
details exchanged between stations.
o Example: parameters for establishing a session,
configuration data, or error reporting details.
Management information used for:
o Link setup
Control field format (8 bits): o Error diagnostics
o 11 → indicates this is an U - frame. o Configuration
o M → 5-bit modifier bits (define the exact type of U- o Control signaling
frame).
o P/F → Poll/Final bit.
52
HDLC …
modifier bits (5-bit) in U – Frame:
53
VLAN
o Virtual Local Area Network
o It is a logical (virtual) network created inside a physical LAN.
o Devices in the same VLAN can communicate as if they are on the same LAN, even if they are connected
to different physical switches.
o VLAN divides one physical network into multiple smaller logical networks.
o VLAN is created by a Switch, NOT by a Hub.