The role of the Data Link Layer
The transmits raw bits and defines the properties of the transmission medium. The uses logical addresses and selects a route for a packet from source to destination across networks such as the Internet.
The Data Link Layer (Layer 2) takes packets from the Network Layer and prepares them for transmission over a specific local physical link. Its operation is hop-by-hop, so a frame is created and checked on each link between neighboring nodes. It delivers data between directly connected devices, for example between a computer and a Wi-Fi router, and defines the frame format and medium-access rules. Each link can use a different frame format, so a router replaces the frame when a packet moves to the next link.
Core responsibilities of the Data Link Layer
For local delivery, the Data Link Layer performs three basic functions:
- Framing: It takes packets from the Network Layer and encapsulates them into structures called frames. A frame adds a header and a trailer containing information needed to transmit the packet over a local link.
- Physical addressing: It manages hardware addresses used by devices on a local network, known as . IEEE 802 networks commonly use a 48-bit EUI-48 address to identify an interface within a segment.
- Error detection and medium access control: It detects whether a frame was corrupted during transmission. It also defines how devices share a channel, for example in Wi-Fi or classic shared Ethernet.
Two sublayers: LLC and MAC
The IEEE 802 architecture divides the Data Link Layer into an LLC sublayer shared by different access methods and a MAC sublayer specific to the technology. IEEE 802.2 defines LLC, while technology standards describe their MAC sublayers.
1. Logical Link Control (LLC)
LLC is the upper sublayer. It provides an interface to the Network Layer and handles logical aspects of the link. Depending on the technology, protocol identification can also be carried by an EtherType or an LLC and SNAP field. Its tasks include:
- Identifying the Network Layer protocol, such as IPv4 or IPv6, contained within the frame's payload by using the mechanism defined for the technology.
- Optionally providing services like flow control and error control for the logical link.
- It is defined by the IEEE 802.2 standard, making it independent of the underlying physical medium.
2. Media Access Control (MAC)
MAC is the lower sublayer. It interacts directly with the Physical Layer and handles placing data in the medium and sharing that medium. Its behavior includes frame boundaries, source and destination addresses, and rules for transmitting on the link. Its responsibilities include:
- Encapsulating packets into frames, including source and destination MAC addresses and control fields required by the standard.
- Defining the method of (e.g., CSMA/CD for classic Ethernet or CSMA/CA in Wi-Fi).
- This sublayer is specific to the physical technology being used (e.g., Ethernet MAC is different from Wi-Fi MAC).
Error detection
The Physical Layer transmits bits as signals that can be affected by noise and interference. A bit can change from 0 to 1 or from 1 to 0. The Data Link Layer introduces a mechanism for checking such corruption.
The primary method for this is the Frame Check Sequence (FCS), a small value placed in the frame's trailer.
Cyclic Redundancy Check (CRC)
In Ethernet, the FCS contains a 32-bit CRC calculated from the destination address through the data and padding fields, excluding the preamble and start-of-frame delimiter. A Cyclic Redundancy Check (CRC) is an error-detecting code based on polynomial arithmetic over a finite field. The receiver validates the result against the value carried in the frame trailer.
- At the sender: The sender treats the relevant frame fields as a bit string and divides it by a defined Generator Polynomial. The remainder becomes the CRC value appended to the frame as the FCS.
- At the receiver: The receiver checks the received data with the same Generator Polynomial and verifies the result against the FCS value in the frame trailer. The check covers the fields selected by the link protocol, rather than the preamble and start delimiter.
- Verdict: A matching result allows the frame to be passed to the Network Layer. A mismatch indicates corruption, so the receiver discards the frame. In typical Ethernet, a higher-layer protocol such as TCP handles retransmission of lost data.
CRC detects many single-bit, multi-bit, and burst errors, meaning errors affecting several consecutive bits. The detected error patterns depend on the polynomial and frame length. In Ethernet, a corrupted frame is discarded at the receiver. CRC does not reconstruct missing bits or repair the payload.
Data Link Layer protocols
The next articles describe protocols that implement these functions, including the classic link-control protocol HDLC and solutions for different link types. They also compare framing, error handling, and access rules across technologies. Another topic is flow control, which limits the sending rate when a receiver processes data more slowly and prevents receiver buffers from overflowing.