Local Delivery
The Data Link Layer is responsible for delivering data between two nodes on the same local network. While the Physical Layer just sends bits, the Data Link Layer organizes those bits into frames, adds error detection, and uses MAC addresses to identify who the data is for.
Think of the Physical Layer as the road, and the Data Link Layer as the postal carrier who knows which house on the street gets which letter.
What Does the Data Link Layer Do?
- Framing — Wraps the raw bit stream into structured frames with headers and trailers. A frame has a beginning and end, so the receiver knows where one frame ends and the next begins.
- Physical Addressing — Adds the source and destination MAC addresses to each frame. This ensures the frame reaches the correct device on the local network.
- Error Detection — Adds a checksum (like a CRC — Cyclic Redundancy Check) to each frame. The receiver recalculates the checksum and compares it. If they don't match, the frame was corrupted in transit and is discarded.
- Flow Control — Manages the rate of data transmission to prevent a fast sender from overwhelming a slow receiver.
- Media Access Control — Determines when each device can transmit on shared media. Without this, two devices transmitting simultaneously would cause collisions.
Frame Structure
Every frame has a similar structure:
┌──────────┬──────────┬──────────┬──────────┬──────────┐
│ Preamble │ Dest MAC │ Src MAC │ Data │ CRC │
│ (8 bytes)│ (6 bytes)│ (6 bytes)│(variable)│ (4 bytes)│
└──────────┴──────────┴──────────┴──────────┴──────────┘
- Preamble — Synchronizes the receiver's clock with the sender's.
- Destination MAC — The MAC address of the device the frame is intended for.
- Source MAC — The MAC address of the device that sent the frame.
- Data — The actual payload (usually an IP packet, 46-1500 bytes).
- CRC (Frame Check Sequence) — Error detection code. If the data is corrupted, the CRC won't match and the frame is discarded.
Two Sub-Layers
The Data Link Layer is divided into two sub-layers:
- LLC (Logical Link Control) — Interfaces with the Network Layer above. Identifies which network protocol is being used (IP, IPv6, ARP, etc.).
- MAC (Media Access Control) — Interfaces with the Physical Layer below. Controls how devices access the shared medium and handles physical addressing.
This separation allows the same MAC layer (like Ethernet) to support different network protocols through different LLC implementations.
CSMA/CD: Managing Shared Access
On shared networks (like old Ethernet hubs), multiple devices share the same wire. If two devices transmit at the same time, their signals collide and both are corrupted. CSMA/CD (Carrier Sense Multiple Access with Collision Detection) manages this:
- Carrier Sense — Before transmitting, listen to see if the wire is idle.
- Multiple Access — Multiple devices share the same wire.
- Collision Detection — While transmitting, listen for collisions. If detected, stop immediately and send a jam signal to notify others.
- Backoff — Wait a random amount of time before trying again. The random wait reduces the chance of another collision.
CSMA/CD is mostly obsolete now because modern switched Ethernet is full-duplex — there's no shared medium, so collisions don't happen.