Network and Data CommunicationsUnit 38 min read
Data Link Layer: Framing, Error Detection & MAC Addressing
Unit 3 of Network and Data Communications explores how data is structured into frames, protected from errors using checksums/CRC, and delivered reliably via MAC addressing—core concepts behind every wired/wireless network from eSewa transactions to Pathao rides.
Core Concepts
What is the Data Link Layer?
The Data Link Layer (Layer 2) is the second layer of the OSI model, sitting between the Physical Layer (raw bits) and the Network Layer (logical addressing). Its job:
- Framing: Breaking data into manageable chunks (frames) and adding headers/trailers.
- Error detection/correction: Ensuring frames arrive intact.
- MAC addressing: Identifying devices on the same network segment.
The 7-layer OSI stack with Data Link Layer highlighted (Image: SVG edition: Gorivero, CC BY-SA 3.0, via Wikimedia Commons)
1. Framing: Structuring Data into Frames
Frames are the basic units of data transmission in the Data Link Layer. They include:
- Header: Source/destination MAC addresses, control flags.
- Payload: The actual data (e.g., HTTP request, file chunk).
- Trailer: Error-checking bits (e.g., CRC).
Why Framing?
- Multiplexing: Multiple devices share the same medium (e.g., Wi-Fi router).
- Error isolation: A corrupted frame doesn’t ruin the entire transmission.
- Flow control: Devices can pause/speed up transmission (e.g., Pathao’s ride updates).
Frame Formats
| Field | Purpose |
|---|---|
| Preamble | Synchronizes sender/receiver clocks (e.g., Ethernet’s 7-byte sync). |
| Start Flag | Marks the beginning of a frame (e.g., 01111110 in HDLC). |
| MAC Addresses | Source (16 bytes) + Destination (16 bytes) for local delivery. |
| Type/Length | Identifies protocol (e.g., IPv4 = 0x0800) or payload size. |
| Payload | Data (max 1500 bytes in Ethernet). |
| FCS (CRC) | Error-checking code (e.g., 4-byte CRC-32). |
| End Flag | Marks frame termination (e.g., 01111110). |
2. Error Detection: CRC and Checksums
Errors occur due to noise (random interference) or attenuation (signal weakening over distance). The Data Link Layer uses:
- Checksum: Simple sum of bytes (used in IP headers).
- Cyclic Redundancy Check (CRC): More robust, used in Ethernet/Wi-Fi.
How CRC Works (Example)
- Divide: Treat the message as a binary polynomial (e.g.,
M(X) = x⁷ + x⁶ + x⁴ + 1for110101001). - Append zeros: Add
nzeros (wheren= degree ofG(X)). ForG(X) = x⁴ + x + 1, append 4 zeros:1101010010000. - Divide by
G(X): Use binary division (like long division). - Remainder: The remainder becomes the CRC bits.
Worked Example:
Message: 1101011011 (from past exams), G(X) = x⁴ + x + 1.
- Append 4 zeros:
11010110110000. - Divide by
10011(binary forx⁴ + x + 1):11010110110000 ÷ 10011 = 1101011011 with remainder 1101. - Transmitted frame: Original message + CRC =
11010110111101.
3. MAC Addressing: Unique Device Identifiers
Every network interface (NIC) has a 48-bit MAC address (e.g., 00:1A:2B:3C:4D:5E):
- First 24 bits (OUI): Vendor ID (e.g.,
00:1A:2B= Cisco). - Last 24 bits: Unique device ID.
How MAC Addresses Work
- Unicast: One-to-one (e.g., your laptop to the router).
- Broadcast: All devices (e.g., ARP requests).
- Multicast: Specific group (e.g., IPTV channels).
Real-World Example: When you order from Daraz, your device’s MAC address helps the router forward packets to the correct switch in the data center. If two devices have the same MAC (rare but possible), collisions occur.
sequenceDiagram
participant A as Device A (MAC: 00:1A:2B)
participant Switch as Ethernet Switch
participant B as Device B (MAC: 00:1A:2C)
A->>Switch: Frame (Dest: 00:1A:2C)
Switch->>B: Frame (via MAC table lookup)
Note over Switch: Switch learns A's MAC on port 14. Medium Access Control (MAC) Protocols
How devices share a medium (e.g., Wi-Fi channel, Ethernet cable):
| Protocol | Description | Pros | Cons |
|---|---|---|---|
| CSMA/CD | Listen before transmitting (Ethernet). If collision, back off. | Simple, no central control. | Inefficient in high traffic. |
| CSMA/CA | Used in Wi-Fi: "listen before talk" + acknowledgments. | Works in wireless (hidden node problem). | Overhead from ACKs. |
| Token Passing | Devices take turns (e.g., old Token Ring networks). | Fair, no collisions. | Slow, complex. |
| ALOHA | Pure/Slotted: Devices transmit anytime (Hawaiian radio roots). | No coordination needed. | High collisions. |
Throughput in ALOHA (Exam Focus)
Pure ALOHA throughput (S) is given by: where .
Worked Example (Past Exam):
- Bandwidth = 200 kbps, frame size = 200 bits → Transmission time (T) = 1 ms.
- 1000 frames/sec offered → .
- Throughput or 13.5%.
5. Real-World Applications
eSewa Payments
- Framing: Your payment request is split into frames (e.g., "User ID: 12345", "Amount: 500").
- CRC: Ensures the bank’s server receives the correct amount (no "500" → "5000" errors).
- MAC Addressing: Your phone’s MAC helps the bank’s router forward the request to the payment gateway.
Pathao Ride Booking
- CSMA/CA: Your phone and the driver’s phone negotiate turns to transmit updates (e.g., "Driver arrived at your location").
- Error Detection: If the driver’s app crashes, CRC detects corrupted frames and retries.
NTC’s Fiber-Optic Backbone
- Token Passing: Old NTC networks used token rings to avoid collisions in high-traffic exchanges.
- MAC Addresses: Routers use MAC tables to forward packets between Kathmandu and Pokhara without flooding the entire network.
Exam Tip
- CRC Calculations: Always show binary division steps. Use the remainder as the CRC.
- ALOHA Throughput: Memorize the formula and units (frames/sec vs. bandwidth).
- MAC vs. IP:
- MAC = Local delivery (same network).
- IP = Global routing (across networks).
- Frame Fields: Know Ethernet’s preamble, FCS, and type/length fields for diagrams.
- Collision Handling: CSMA/CD uses exponential backoff; CSMA/CA uses ACKs.
Summary Table
| Concept | Key Idea | Example |
|---|---|---|
| Framing | Breaking data into frames with headers/trailers. | Ethernet’s 1500-byte max payload. |
| CRC | Error detection using polynomial division. | Wi-Fi’s 32-bit CRC. |
| MAC Address | Unique 48-bit identifier for devices. | 00:1A:2B:3C:4D:5E. |
| CSMA/CD | "Listen before talk" + collision handling. | Old Ethernet networks. |
| ALOHA | Simple but collision-prone sharing. | Early wireless networks. |
Based on the TU BIT syllabus for Network and Data Communications (BIT254), unit 3.
Discussion
Loading…