Data Link Layer(OSI Layer 2)
The Data Link Layer is responsible for reliable node-to-node data transfer. It takes raw bits from the Physical Layer (Layer 1) and organizes them into frames, ensuring that data is transferred error-free and in the correct order over a physical link between two directly connected nodes.
Key Responsibilities
Framing
- Breaks up data from the Network Layer (Layer 3) into manageable units called frames.
- Adds headers and trailers for synchronization and control.
Physical Addressing
- Uses MAC (Media Access Control) addresses to identify devices on a local network.
- These are hardware addresses burned into network interface cards (NICs).
Error Detection and Handling
- Implements error detection methods like CRC (Cyclic Redundancy Check), often using CRC32.
- Can detect errors, but usually doesn't correct them (except in some cases like in PPP with FEC).
Flow Control
- Ensures that the sender doesn't overwhelm the receiver with too much data.
- Simple forms can be implemented in this layer (more complex flow control is typically at Layer 4).
Access Control
- Determines how devices share the communication medium (e.g., Ethernet's CSMA/CD, Wi-Fi’s CSMA/CA).
- Helps prevent collisions in shared medium networks.
Medium Access Control (MAC) and Logical Link Control (LLC)
The layer is divided into two sublayers:
- MAC Sublayer: Deals with physical addressing and access to the physical medium.
- LLC Sublayer: Manages communication between the Data Link Layer and Network Layer.
Frame Structure (Example: Ethernet Frame)
+-------------+-----------+----------+-------------+--------------+
| Preamble | MAC Addr. | Type | Payload | CRC (FCS) |
| (7 bytes) | (Source & | (2 bytes)| (Data) | (4 bytes) |
| | Dest) | | | |
+-------------+-----------+----------+-------------+--------------+
Devices Operating at Layer 2
- Switches (learn and forward based on MAC addresses)
- Bridges
- Network Interface Cards (NICs)
Note: Switches operate at Layer 2, but they can sometimes perform Layer 3 functions (like routing) in advanced models.
Protocols at Layer 2
- Ethernet (IEEE 802.3)
- Wi-Fi (IEEE 802.11)
- PPP (Point-to-Point Protocol)
- HDLC (High-Level Data Link Control)
- Frame Relay
- Token Ring (obsolete)
Important Concepts
- Unicast, Broadcast, Multicast: Delivery types based on MAC addressing.
- MAC Address Table (Switching Table): Used by switches to forward frames to the correct port.
- VLANs (Virtual LANs): Layer 2 feature that allows logical separation of networks on the same physical switch.
Comparison with Other Layers
OSI Layer | Role |
---|---|
Layer 1: Physical | Transmits raw bits over a physical medium. |
Layer 2: Data Link | Packages bits into frames and ensures error-free delivery. |
Layer 3: Network | Determines best path for data (routing). |
Real-World Example
When your computer sends a packet over Ethernet:
- Layer 3 adds an IP header.
- Layer 2 wraps it in a frame, adds MAC addresses, and a CRC.
- The switch reads the frame’s destination MAC address and forwards it to the correct port.