In this blog we are going to deep dive into DataLink layer(DLL). Let's start our discussion with the Textbook definition "The Data Link Layer is the second layer of the OSI model.It is responsible for receiving and getting data bits usually from Physical Layer and then converting these bits into groups, known as data link frames so that it can be transmitted further". In short, its main job is to ensure reliable data transfer between two directly connected nodes.
Key Responsibilities:
- Framing: It takes raw bits from the physical layer and organizes them into frames (like envelopes for sending messages).
- Error Detection and correction: It checks for errors in transmitted data using methods like parity checks, CRC (Cyclic Redundancy Check), and checksum. For correction, methods like Automatic Repeat Request (ARQ) are used.
- Flow Control: Prevents a fast sender from overwhelming a slow receiver, like a traffic signal controlling the flow of cars. It include method like stop-and-wait & Sliding window.
- Media Access Control (MAC): MAC Address is a hardware address associated to a network interface card (NIC) or network device. Determines who can send data and when especially in shared networks like Wi-Fi or Ethernet.
Divisions of the Data Link Layer
It has two sublayers:
- Logical Link Control (LLC): It handles error detection & flow control. Ensures communication between devices works smoothly.
- Media Access Control (MAC): Manages physical addressing (MAC addresses).Controls how devices access and share the network medium (wired or wireless).
Media Access Control
when nodes or stations are connected and use a common link, we need a multiple-access protocol to coordinate access to the link.
In multiple-access protocol we are only going to discuss about Random access protocol, since rest of the protocol is Advance and not much related to CS/IT. Let's start.
Random Access
Random Access Protocols are used in networks where multiple devices share a common communication channel. These protocols allow devices to transmit data whenever they have data to send, but they also have mechanisms to handle collisions (when two devices transmit at the same time).It is called a Random Access Protocol because there is no fixed order or schedule for devices to send data. Instead, devices transmit whenever they have data, leading to random chances of collisions.
Think of it like a group of people talking in a room without a moderator—sometimes, two people talk at the same time, leading to confusion (collision), and they have to pause and retry.
Important Note:
All the protocols in the Random access approach will answer the following questions:
- When can the station access the medium?
- What can the station do if the medium is busy?
- How can the station determine the success or failure of transmission?
- What can the station do if there is an access conflict?
1.ALOHA
ALOHA was one of the earliest random access protocols, developed in the 1970s for wireless communication.The main idea of ALOHA is how it handles collisions, which happen when two devices try to send data at the same time, causing interference.
There are two version of ALOHA protocol:
- Pure ALOHA
Pure ALOHA refers to the original ALOHA protocol. It is a Random Access Protocol where devices send data whenever they want, without checking if the channel is free. If two devices transmit at the same time, a collision occurs, and they need to retransmit after a random time.
Since multiple devices can transmit at the same time, collisions are common.If the receiver does not send the acknowledgment, the sender will assume that it has not been received and sender resends the message.
Since collisions are frequent, much of the network capacity is wasted.maximum efficiency of Pure ALOHA is only 18.4%, meaning most transmissions fail.Pure ALOHA is mainly used in wireless communication (satellites, RFID systems) where devices cannot easily detect other transmissions.
With this diagram you can clearly see that last bit of frame A is colliding with first bit of frame B. vulnerable time in which there is a possibility of collision, we can see that the time during which the collision may occur in pure ALOHA. Vulnerable time = 2*Transmission delay
(we will discuss Transmission delay later).
2.Slotted ALOHA
Slotted ALOHA is an improved version of Pure ALOHA that reduces collisions by dividing time into fixed slots. Devices can only send data at the beginning of a time slot, which synchronizes transmissions and improves efficiency with max efficiency of 36.8%.
- The channel is divided into equal-sized time slots, and devices can only send data at the start of a slot.
- This ensures that collisions can only happen if two devices pick the same slot, unlike Pure ALOHA where collisions happen anytime.
- If a collision happens, devices wait for a random number of time slots before trying again.This helps reduce repeated collisions in the next slot.
- Slotted ALOHA is used in wireless systems where devices can be synchronized, like satellite uplinks and RFID (contactless card systems).
2.Carrier Sense Multiple Access (CSMA)
CSMA reduces collisions by first listening to the channel before transmitting which means In this protocol, each device first sense the channel before sending the data. If the channel is busy, the device waits until it is free. This helps reduce collisions. There are two ways to check if the channel is busy or idle:
- Persistent CSMA: Keeps checking and sends immediately if the channel is free. (Higher chance of collision).
- Non-Persistent CSMA: Waits a random time before checking again. (Reduces collision chances).
3.CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
CSMA/CD is used in wired networks (Ethernet) to detect and handle collisions when multiple devices transmit at the same time. If a collision occurs, devices stop transmission, send a jam signal, and retry after a random delay to avoid repeated collisions.
How CSMA/CD Works?
- Carrier Sense (Listen Before Sending):
- The device listens to the channel before sending data.
- If the channel is free, it sends the data.
- If the channel is busy, it waits for a random time before trying again.
- Collision Detection (Detecting a Crash):
- If two devices send data at the same time, a collision happens, and data gets corrupted.
- Devices can detect this because they hear a jumbled signal (like overlapping voices in a room).
- Jam Signal (Alert Everyone):
- When a collision is detected, a "jam signal" is sent to notify all devices.
- Random Backoff (Wait and Retry):
- The devices that collided wait for a random time before retransmitting
- This helps reduce repeated collisions.
Imagine a two-way road where cars can only pass if the road is clear:
- A driver (device) checks if the road is empty (carrier sensing).
- If clear, the driver moves.
- If two cars move at the same time (collision), they both stop (detect collision).
- They wait for a random time before trying again to avoid another crash.
4.CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance)
CSMA/CA is used in wireless networks (Wi-Fi) to prevent collisions before they happen. Devices first send an RTS (Request to Send) signal, wait for a CTS (Clear to Send) response, and then transmit data to ensure smooth communication.
Why CSMA/CA is Needed for Wireless?
- In Wi-Fi, devices cannot "hear" each other's transmissions properly (hidden node problem).
- Unlike Ethernet, wireless signals can’t detect collisions, so CSMA/CA prevents collisions instead of detecting them.
How CSMA/CA Works?
-
Carrier Sense (Listen Before Sending):
- The device checks if the channel is idle.
- If busy, it waits before trying again.
-
Request to Send (RTS) & Clear to Send (CTS):
- Instead of just sending data, the device first sends an RTS (Request to Send) signal to the access point (Wi-Fi router).
- If the channel is free, the router replies with a CTS (Clear to Send) signal.
-
Data Transmission (Safe to Send) :
- After receiving CTS, the device transmits data.
- Other devices stay silent to avoid interference.
-
Acknowledgment (ACK):
- The receiver sends an ACK (Acknowledgment) message confirming successful reception.
- If no ACK is received, the sender assumes a collision happened and retries after a random time.
Imagine a classroom where students ask for permission to speak:
- A student (device) raises their hand (RTS - Request to Speak).
- The teacher (Wi-Fi router) grants permission (CTS - Clear to Speak).
- The student speaks (data transmission).
- The teacher nods (ACK) to confirm the message was heard.
MAC Address
A MAC address is a 48-bit (6-byte) unique hardware address assigned to a network interface card (NIC) by the manufacturer. It is used to identify devices in a Local Area Network (LAN).
Format :
A MAC address is usually written in hexadecimal format, separated by colons or hyphens.
- Example: 00:A0:C9:14:C8:29 or 00-A0-C9-14-C8-29
Structure (6 Bytes = 48 Bits)
First 3 Bytes (24 bits) | Last 3 Bytes (24 bits) |
---|---|
**Organizationally Unique Identifier(OUI)** - Assigned to manufacturer | **Device Identifier(NIC Specific)** - Unique to each device |
Example: 00:A0:C9 → Manufacturer | Example: 14:C8:29 → Unique Device ID |
Here are some OUI of well-known manufacturers:
CC:46:D6 - Cisco
3C:5A:B4 - Google, Inc.
3C:D9:2B - Hewlett Packard
00:9A:CD - HUAWEI TECHNOLOGIES CO.,LTD
Why is a MAC Address Needed?
- Uniquely identifies devices in a network (like a fingerprint for your computer).
- Used in the Data Link Layer for local communication within a LAN.
- Helps switches forward data to the correct device in a network.
Types of MAC Addresses
MAC addresses can be categorized based on their purpose:
Type | Description |
---|---|
Unicast MAC Address | Used to send data to a single specific device in a network. |
Multicast MAC Address | Used to send data to a group of devices (e.g., video streaming). |
Broadcast MAC Address | Used to send data to all devices in a network (FF:FF:FF:FF:FF:FF). |
Example:
- If a switch wants to send data to one computer, it uses a unicast MAC address.
- If a router wants to send data to all devices in a network, it uses the broadcast MAC address (FF:FF:FF:FF:FF:FF).
How MAC Addresses Work in a Network?
When a device wants to communicate, it follows these steps:
- Step 1: The sender checks the MAC address of the destination using the ARP (Address Resolution Protocol).
- Step 2: The sender adds the MAC address to the data frame and sends it.
- Step 3: A network switch reads the MAC address and forwards the data to the correct device.
Example:
If your laptop sends a request to a printer in a LAN, the request contains the printer's MAC address, so the switch knows where to send the data.
MAC Address vs. IP Address – What's the Difference?
Feature | MAC Address | IP Address |
---|---|---|
Definition | Unique hardware address of a device | Logical address assigned to a device |
Layer | Data Link Layer (Layer 2) | Network Layer (Layer 3) |
Type | Physical (cannot change) | Logical (can change) |
Used By | Switches | Routers |
Example | 00:A0:C9:14:C8:29 | 192.168.1.1 |
Analogy:
- A MAC address is like a house address (permanent).
- An IP address is like a temporary hotel room number (can change).
To find your MAC address just open your command prompt type ipconfig /all
and press Enter. Look for "Physical Address" under your network adapter.
Framing in Data Link Layer
What is Framing?
Framing is the process of dividing a stream of data into small manageable units called frames for transmission over a network. Each frame contains both data and necessary control information (such as addresses and error detection codes) to ensure reliable communication.
Why is Framing Needed?
- The physical layer (Layer 1) only transmits raw bits (0s and 1s) without meaning.
- The data link layer (Layer 2) groups these bits into meaningful frames for error detection, synchronization, and addressing.
- It allows the receiver to correctly identify the start and end of each data unit.
Example Analogy:
- Imagine a long letter written without spaces or punctuation—it would be hard to read!
- Framing adds spaces, punctuation, and envelopes so that the receiver can properly understand each message.
Components of a Frame
Each frame consists of three main parts:
Part | Purpose |
---|---|
Header | Contains control information like source & destination MAC addresses |
Data | The actual payload (message) being transmitted |
Trailer | Contains error detection codes to ensure correct data transmission |
Error Detection in Framing
The trailer of a frame includes an error detection code to ensure data integrity.
Common Error Detection Techniques:
- Parity Bit: Adds an extra bit to make the number of 1s either even or odd.
- Checksum: A sum of all data bits is added and verified at the receiver’s end.
- Cyclic Redundancy Check (CRC): A mathematical formula generates a check code, which is compared on both ends.
Conclusion
In this blog, we explored the Data Link Layer, the backbone of network communication. We delved into key concepts like framing, MAC addressing, and random access protocols such as ALOHA, CSMA, CSMA/CA, and CSMA/CD. These mechanisms ensure efficient data transmission and collision avoidance, keeping networks connected and functional.
In the next blog, we’ll dive into the Logical Link Control (LLC) sublayer, covering error detection, correction, and flow control. Let’s keep the conversation going! Connect with me on: Linkedin & X(formally twitter).
Top comments (0)