Link Layer
The Link Layer is identified as the second layer in the OSI Reference Model and is often called the Network Access Layer in the TCP/IP Reference Model. It sits directly above the physical layer and below the network layer.
Core Responsibility:
Data Transfer Across Individual Links: The primary role of the link layer is to transfer data across individual links between two directly connected nodes. This means it handles the communication for a single "hop" in the journey of data through the network.
A node is defined as any device that implements link-layer protocols. Examples include hosts (like computer or smartphone), routers, switches, and WiFi access points.
A link refers to the physical medium connecting two adjacent nodes.
- Links can be either point-to-point (connecting a single sender and receiver) or broadcast (shared among multiple sending and receiving nodes).
- Links can be made of various physical media, such as twisted-pair copper wire, coaxial cable, optical fiber, or radio spectrum for wireless connections.
Data Units: Frames
Data at the link layer is transmitted in units called frames. Before transmission, network-layer datagrams are encapsulated within these frames. This encapsulation involves adding a link-layer header and sometimes a trailer to the datagram.
Upon receipt, the reverse process, de-encapsulation, occurs where headers are stripped off to deliver the original message to the application.
End-to-End Transmission (Hop-by-Hop):
For a datagram to travel from a source host to a destination host, it typically passes across multiple links, one hop at a time. At each intermediate node (like a router or switch), the datagram is taken out of its current frame, processed, and then encapsulated into a new link-layer frame appropriate for the next link, before being forwarded.
This process continues until the datagram reaches its final destination. This layered approach ensures that the network layer doesn't need to worry about the specifics of each physical link, as that's the link layer's job.
Example of Link Traversal
This example illustrates the hop-by-hop nature of datagram transmission and the role of the link layer at each step:
WiFi link: Wireless host to WiFi access point: A datagram from a wireless host is encapsulated into an 802.11 wireless frame and sent over the wireless medium to the WiFi access point (AP). The link-layer protocol here is specifically designed for wireless communication, addressing challenges like signal attenuation and interference.
Ethernet link: Access point to switch: The WiFi access point, after receiving the wireless frame and extracting the datagram, encapsulates it into an Ethernet frame and sends it over a wired Ethernet link to a link-layer switch.
Ethernet link: Switch to router: The switch forwards the Ethernet frame to an output port connected to a router. A switch operates only up through layer 2, forwarding frames based on MAC addresses.
Link: Between two routers: The router extracts the datagram from the Ethernet frame. Based on network-layer routing decisions, it then encapsulates the datagram into a new frame, potentially of a different link-layer protocol (e.g., another Ethernet frame, or an MPLS frame if MPLS-capable) and transmits it to the next router.
Ethernet link: Router to switch: The second router extracts the datagram, determines the next hop, encapsulates it into an Ethernet frame, and forwards it to another link-layer switch.
Ethernet link: Switch to server: Finally, the switch forwards the Ethernet frame, containing the original datagram, to the destination server's network interface, which extracts the datagram and passes it up its protocol stack.
At each of these links, the datagram is encapsulated into a new link-layer frame. This highlights how the link layer provides local, direct communication between adjacent nodes, relying on its specific protocols and physical media for that particular segment of the data's journey. The transport and network layers are typically unaware of the specific link-layer technologies used on the individual links.
Services Provided by the Link Layer
The primary responsibility of the link layer is to move a datagram from one node to its directly connected neighbor over a single communication link. The specific services provided by different link-layer protocols can vary based on the physical medium and usage scenario.
1 Framing
Encapsulation: Link-layer protocols take network-layer datagrams and encapsulate them into frames. A network-layer datagram, which is itself a segment from the transport layer, is wrapped within a link-layer frame.
- Frame Structure: Each frame is composed of a data field, which holds the encapsulated datagram, and header fields used for purposes like addressing and error checking.
Protocol-Specific Definition: The precise structure and fields of the frame are defined by the specific link-layer protocol being used (e.g., Ethernet, WiFi).
2 Link Access
This service defines when and how a node can place a frame onto the link.
MAC Protocols: Medium Access Control (MAC) protocols are responsible for managing link access.
Point-to-Point Links: For links connecting only two devices (one sender, one receiver), the MAC protocol is typically simple: the sender transmits when the link is idle.
Broadcast Links: For shared channels where multiple devices can send and receive (e.g., Ethernet, Wi-Fi), MAC protocols are critical to coordinate access and avoid collisions that would result in data loss. These include techniques like channel partitioning, random access (e.g., ALOHA, CSMA/CD), and taking-turns protocols.
3 Reliable Delivery
Error-Free Link Transmission: This service ensures that each datagram is delivered across the single link without errors.
It is typically achieved using acknowledgments (ACKs) from the receiver and retransmissions by the sender if an ACK is not received. (Similar to the reliable data transfer mechanisms in the transport layer TCP).
Reliable delivery at the link layer is most often used on unreliable links, such as wireless connections, which are prone to higher bit error rates. The goal is to correct errors locally on the link where they occur, rather than relying solely on end-to-end retransmission by higher-layer protocols.
Overhead: For links with very low error rates (e.g., fiber-optic or Ethernet cables), providing link-layer reliable delivery can be considered unnecessary overhead, and many wired link-layer protocols omit this service.
4 Error Detection and Correction
Handling Bit Errors: This service addresses bit errors that can occur during transmission due to factors like noise, signal attenuation, or interference.
Methods: The link layer incorporates error detection bits (e.g., Cyclic Redundancy Check (CRC)) in the frame and utilizes hardware-based error checking at the receiver. CRC is a robust error-detection technique widely used in networks.
Response to Errors: If an error is detected, the frame may either be discarded (often with a request for retransmission by a higher layer or the link layer itself) or, if supported by the protocol, corrected by the receiver using forward error correction (FEC) techniques.
Level of Sophistication: Error detection and correction at the link layer are typically more sophisticated and implemented in hardware (e.g., in network adapters) compared to the simpler checksums used at the transport or network layers, which are often software-based.