📡 Data Link Layer Study Guide

OSI Model Layer 2 - Computer Networks for Electrical Engineering

🎯 Overview & Position in OSI Model

Definition: The Data Link Layer (Layer 2) is responsible for node-to-node data transfer and handling errors in the physical layer. It transforms the physical layer's raw bit stream into a reliable link between adjacent nodes.
7. Application Layer
6. Presentation Layer
5. Session Layer
4. Transport Layer
3. Network Layer
2. Data Link Layer ← You are here
1. Physical Layer

🔌 Electrical Engineering Context

The Data Link Layer bridges the gap between electrical signals (Physical Layer) and network routing (Network Layer). It deals with:

  • Signal Encoding: Converting bits to electrical signals (NRZ, Manchester encoding)
  • Timing & Synchronization: Clock recovery and bit synchronization
  • Error Detection: Parity checks, CRC (Cyclic Redundancy Check) - implemented in hardware
  • Medium Access: Controlling access to shared electrical media (buses, coaxial cables)
Key Responsibilities:
  • Framing: Dividing bit stream into manageable frames
  • Physical Addressing: MAC addressing for local delivery
  • Error Control: Detection and correction of bit errors
  • Flow Control: Managing data rate between sender and receiver
  • Access Control: Determining which device controls the link

⚙️ Core Functions

1. Framing

Framing is the process of dividing the stream of bits from the physical layer into data units called frames.

Generic Frame Structure

Header Address & Control
Payload (Data) Network Layer Packet
Trailer Error Detection

Framing Methods:

Fixed-Size Framing

Frames have constant size. No boundaries needed, but internal fragmentation may occur.

Example: ATM cells (53 bytes fixed)

Variable-Size Framing

Frames have variable lengths. Need delimiters to mark start and end.

  • Character Count: First field specifies frame length
  • Flag Bytes with Byte Stuffing: Special flag bytes (01111110) mark boundaries
  • Flag Bits with Bit Stuffing: HDLC uses 01111110 flag; sender inserts 0 after five consecutive 1s

2. Error Control

Ensures reliable delivery by detecting and correcting errors that occur during transmission.

Error Types:
  • Single-bit errors: Only one bit in the data unit is changed
  • Burst errors: Two or more bits in the data unit are changed (more common in electrical interference)

Error Detection Methods:

Method Mechanism Error Detection Capability Overhead
Parity Check Add 1 bit to make total 1s even/odd Single-bit errors only 1 bit
Checksum Sum of all words in data Burst errors up to check digits 16-32 bits
CRC (Cyclic Redundancy Check) Polynomial division Burst errors < degree of polynomial 8-32 bits
Hamming Code Multiple parity bits Single-bit correction, double-bit detection log₂(m)+1 bits

3. Flow Control

Coordinates the rate of data transmission between sender and receiver to prevent buffer overflow.

Flow Control Mechanisms:
  • Stop-and-Wait: Send one frame, wait for ACK before next
  • Sliding Window: Send multiple frames before requiring ACK

📦 Detailed Framing Techniques

Byte Stuffing (Character-Oriented)

Used when data consists of characters (8-bit bytes). Special flag byte (usually 01111110) marks frame boundaries.

Sender: Original Data: A B FLAG C D Stuffed Data: FLAG A B ESC FLAG C D FLAG Rule: If FLAG appears in data, insert ESC (escape) byte before it. If ESC appears in data, insert another ESC before it. Receiver: Unstuffing: Remove ESC bytes and interpret next byte as data.

Bit Stuffing (Bit-Oriented)

More universal approach. Flag pattern: 01111110. Transmitter inserts 0 after five consecutive 1s.

Interactive Bit Stuffing Demo

Original Data: 0111111111111110

Stuffed Data:

Watch for 0s inserted after five consecutive 1s (shown in red)

🛡️ Error Detection & Correction

Cyclic Redundancy Check (CRC)

Most powerful error detection method. Uses polynomial division.

CRC Calculator

Hamming Code

Error-correcting code that can detect and correct single-bit errors.

Hamming Code Formula:
For m data bits, r redundancy bits needed where: 2^r ≥ m + r + 1
Positions of redundancy bits: Powers of 2 (1, 2, 4, 8, 16...)

Hamming Code Position Calculator

🌊 Flow Control Protocols

1. Stop-and-Wait ARQ

Operation:

  1. Sender transmits one frame
  2. Sender waits for ACK (Acknowledgment)
  3. If ACK received within timeout, send next frame
  4. If timeout or NAK (Negative ACK), retransmit
Efficiency: Low for high bandwidth-delay product links
Utilization: U = 1 / (1 + 2a) where a = propagation time / transmission time

2. Sliding Window Protocol

Allows multiple frames to be in transit simultaneously.

Go-Back-N ARQ

  • Window size: N frames
  • Receiver accepts only in-sequence frames
  • If frame lost, receiver discards all subsequent frames
  • Sender retransmits from lost frame onward

Selective Repeat ARQ

  • Receiver accepts out-of-order frames (buffers them)
  • Only lost frame is retransmitted
  • More efficient but requires more buffer space
  • Window size typically ≤ (MAX_SEQ + 1) / 2

Protocol Efficiency Calculator

📋 Data Link Protocols

HDLC (High-Level Data Link Control)

Bit-oriented protocol developed by ISO. Basis for many other protocols including PPP.

HDLC Frame Format

Flag
8 bits
Address
8 bits
Control
8/16 bits
Information
Variable
FCS
16/32 bits
Flag
8 bits

Control Field Types:

PPP (Point-to-Point Protocol)

Used for direct communication between two nodes. Common in dial-up and DSL connections.

PPP Components:

  • HDLC-like Framing: Defines frame structure
  • LCP (Link Control Protocol): Establishes, configures, and tests connection
  • NCP (Network Control Protocol): Configures different network layer protocols

Ethernet (IEEE 802.3)

Dominant wired LAN technology. Uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection).

🔌 Electrical Characteristics

  • Encoding: Manchester encoding (10 Mbps), 4B/5B or 8B/10B (higher speeds)
  • Voltage Levels: +0.85V to -0.85V differential signaling
  • Impedance: 50Ω (thicknet), 100Ω (UTP)
  • Signaling: Baseband (digital signals) vs Broadband (analog carriers)

🎛️ MAC Sublayer (Medium Access Control)

The MAC sublayer controls how devices gain access to the physical medium and permission to transmit.

Channel Allocation Methods

Method Description Examples Best For
FDMA Frequency Division Multiple Access Traditional radio, analog systems Continuous traffic, voice
TDMA Time Division Multiple Access GSM, T1 circuits Digital voice, bursty data
CDMA Code Division Multiple Access IS-95, WCDMA, GPS High capacity, soft handoff
CSMA/CD Carrier Sense Multiple Access/Collision Detection Ethernet (legacy) Wired LANs
CSMA/CA Carrier Sense Multiple Access/Collision Avoidance Wi-Fi (802.11) Wireless networks
Token Passing Token controls transmission right Token Ring, FDDI Deterministic access

CSMA/CD Operation

  1. Carrier Sense: Listen before transmitting
  2. Multiple Access: Multiple stations on shared medium
  3. Collision Detection: Detect simultaneous transmissions
  4. Jam Signal: Send jamming signal to ensure all stations detect collision
  5. Backoff: Wait random time using binary exponential backoff
Minimum Frame Size: In Ethernet, minimum frame size is 64 bytes (512 bits) to ensure collision detection works even at maximum cable length.
Slot Time: Round-trip propagation time of the network (51.2 μs for 10 Mbps Ethernet)

🔗 LLC Sublayer (Logical Link Control)

The LLC sublayer provides the interface between the MAC sublayer and the network layer. Defined in IEEE 802.2.

LLC Functions:
  • Multiplexing multiple network layer protocols over single MAC layer
  • Flow control (optional)
  • Error control (optional)

LLC Service Types

Type 1 - Unacknowledged Connectionless

No ACK, no connection setup. Best effort delivery. Most common for Ethernet/IP.

Type 2 - Connection-Oriented

Reliable service with connection establishment, ACKs, flow control. Similar to HDLC.

Type 3 - Acknowledged Connectionless

Individual frames acknowledged but no connection setup. Used in automation.

IEEE 802.x Architecture

Network Layer
LLC (802.2)
MAC
(802.3/11/etc)
Physical
Layer

🧮 Interactive Calculators

Frame Transmission Time Calculator

Maximum Network Distance (CSMA/CD)

Knowledge Check Quiz

1. What is the primary responsibility of the Data Link Layer?

End-to-end delivery
Node-to-node delivery
Process-to-process delivery
Bit synchronization only

2. In bit stuffing, what bit is inserted after five consecutive 1s?

1
0
Flag byte
Parity bit

3. Which error detection method can correct single-bit errors?

Parity check
CRC
Hamming code
Checksum

4. What is the efficiency formula for Stop-and-Wait ARQ?

1/(1+2a)
W/(1+2a)
1/(1+a)
W/(2+2a)

5. Which sublayer of Data Link Layer is responsible for MAC addressing?

LLC
MAC
Physical
Network

6. In CSMA/CD, what is the minimum frame size designed to prevent?

Buffer overflow
Late collision detection
Bit errors
Frame duplication

📚 Summary

Key Functions

  • Framing
  • Physical Addressing (MAC)
  • Error Detection/Correction
  • Flow Control
  • Medium Access Control

Important Protocols

  • HDLC
  • PPP
  • Ethernet (IEEE 802.3)
  • Wi-Fi (IEEE 802.11)
  • Token Ring

Error Control

  • Parity Check
  • Checksum
  • CRC (Polynomial)
  • Hamming Code
  • ARQ Protocols

Flow Control

  • Stop-and-Wait
  • Sliding Window
  • Go-Back-N
  • Selective Repeat

Study Tips for Electrical Engineering Students

  • Understand the relationship between electrical signals (Physical Layer) and logical framing
  • Practice CRC calculations - they appear frequently in exams
  • Know the timing constraints in CSMA/CD and why minimum frame size matters
  • Understand the trade-offs between error detection and correction methods
  • Be able to calculate channel utilization for different protocols
  • Review the electrical characteristics of different media (impedance, encoding, voltage levels)