DataLink Layer


📦 1. What is the Data Link Layer?

The Data Link Layer is responsible for node-to-node data transfer — meaning it ensures that frames are transferred between two directly connected devices over a physical medium (like Ethernet, Wi-Fi, etc.).

Think of it as a “postal worker” who takes a letter from your house and hands it to the next post office — but not across the country.


🧠 2. Core Responsibilities of the Data Link Layer

Responsibility

Description

Framing

Converts raw bits from the Physical Layer into structured frames (a frame = header + payload + trailer).

MAC Addressing

Uses MAC addresses (e.g., AA:BB:CC:DD:EE:FF) for source and destination.

Error Detection

Adds checks like CRC (Cyclic Redundancy Check) to detect corruption.

Flow Control

Prevents sender from overwhelming receiver (not as common today, more at higher layers).

Access Control (MAC)

Controls who can send data at a time in a shared medium (via CSMA/CD, CSMA/CA).

Acknowledgment & Retransmit

In some cases (like HDLC or PPP), the layer can acknowledge and retransmit frames.


🧱 3. Key Concepts

✅ Framing

  • A frame is the unit of communication.

Structure:

[Preamble][Start][MAC Header][Payload][CRC]


  • Adds start/end indicators, payload size, etc.

🆔 MAC Addressing

  • Every NIC (Network Interface Card) has a unique MAC address.

  • Data is delivered based on these hardware-level addresses, not IPs.

🧪 Error Detection

  • CRC is calculated at sender and verified at receiver.

  • If mismatch: the frame is discarded.

  • If used with acknowledgment-based protocols, it can trigger a retransmit.

⚡ Media Access Control

  • In shared mediums, there must be a protocol to avoid collision:

    • CSMA/CD (Ethernet): Listen before you talk; if collision → back off.

    • CSMA/CA (Wi-Fi): Avoid collision through acknowledgments and waiting.


🧩 4. Sublayers of Data Link Layer

The layer is often divided into two sublayers:

Sublayer

Responsibilities

LLC (Logical Link Control)

Talks to the Network Layer above, provides multiplexing (e.g., IPv4, ARP on same wire)

MAC (Media Access Control)

Talks to the Physical Layer below, handles addressing, collision handling, frame delimiting, etc.


🕸️ 5. Protocols at Data Link Layer

Protocol

Medium

Notes

Ethernet (IEEE 802.3)

Wired

Dominant LAN protocol

Wi-Fi (IEEE 802.11)

Wireless

Uses CSMA/CA

PPP (Point-to-Point Protocol)

Serial

Used in WAN links

HDLC (High-Level Data Link Control)

Serial

Framing + reliability

Frame Relay / ATM

Legacy

Used in telecom networks


🔍 6. FAANG-Level Debugging/Interview Concepts

⚙️ Debug Scenario: Frame Drop

  • Symptoms: Device not receiving data.

  • Tools: Wireshark, tcpdump

  • Check:

    • CRC errors? → Bad cable/NIC.

    • Duplex mismatch? → Collisions or errors.

    • Interface stats (ethtool, ifconfig): Check for RX errors, dropped.

❓ FAANG Questions

  1. What happens if two devices transmit simultaneously on Ethernet?

    • Collision → CSMA/CD → Both back off and retry.

  2. How is reliability handled in Ethernet?

    • It's best effort at Layer 2; reliability handled at TCP (Layer 4).

  3. How does the Data Link Layer differ from the Network Layer?

    • L2: Node-to-node, MAC, no routing.
      L3: End-to-end, IP, routing, path selection.

  4. Explain difference: Switch vs Hub at Data Link Layer.

    • Switch: Uses MAC table, forwards frames intelligently (unicast).

    • Hub: Broadcasts to all, no MAC logic.


🖼️ Visual Summary

App | Presentation | Session
    ⬇
Transport Layer (TCP/UDP)
    ⬇
Network Layer (IP) -- Logical routing
    ⬇
Data Link Layer (MAC) -- Local delivery (frame)
    ⬇
Physical Layer (bits on wire)


🧠 Focus: Deliver one frame from one MAC address to another MAC address reliably within a local network.


🧪 Real-World Example

📦 A device wants to send a file over the LAN:

  • IP layer: Identifies destination IP.

  • ARP: Resolves IP to MAC.

  • Data Link Layer: Builds frame with MACs, adds CRC.

  • Physical Layer: Converts to bits and transmits.

  • Switch forwards the frame based on MAC table.


🚀 Advanced: VLANs and QoS (Tagging in Layer 2)

  • VLANs (802.1Q) add tags in frames to segregate traffic.

  • QoS (802.1p) allows priority marking within the frame.


💡 Tricks to Remember

  • "Frame = Data + MAC header + Error check"

  • "MAC talks to MAC — IP talks to IP"

  • Ethernet = Local, IP = Global



Distributed by Gooyaabi Templates | Designed by OddThemes