The Data Link Layer transforms raw physical-layer bitstreams into structured, reliable node-to-node communication links. This module explores framing mechanics, flow control, automatic repeat request (ARQ) strategies, and core standard implementations like HDLC and PPP.
To coordinate transmission, the data link layer must package raw bits into distinct, manageable data units called frames. This process, known as framing, enables the receiver to distinguish one packet of information from another, acting much like an envelope separating letters in a postal system.
Physical Layer: ...011111101010010101111110... (Raw Bit Stream)
| |
Data Link Layer: [ FLAG ][ Header ][ Payload ][ Trailer ][ FLAG ] (Discrete Frame)There are two primary approaches to framing:
In character-oriented framing, data to be sent is treated as a sequence of characters (typically 8-bit bytes). The frame begins with a special 1-byte flag and ends with the same flag.
If the payload itself contains a byte with the exact binary pattern of the flag (e.g., 0x7E), the receiver will mistakenly assume the frame has ended. To prevent this, byte stuffing (or character stuffing) is performed:
01111101 or 0x7D) is inserted immediately before any flag or escape character present in the user payload.Original Payload: [ DATA ] [ FLAG ] [ DATA ] [ ESC ] [ DATA ]
| |
Stuffed Payload: [ DATA ] [ ESC ][ FLAG ] [ DATA ] [ ESC ][ ESC ] [ DATA ]
| |
Receiver Unstuffs: [ DATA ] [ FLAG ] [ DATA ] [ ESC ] [ DATA ]In bit-oriented framing, the frame payload is treated as a continuous stream of individual bits, independent of character boundaries. A unique bit sequence—typically the 8-bit flag 01111110 (hex 0x7E)—is used as the start and end delimiter.
To ensure this pattern does not naturally occur inside the payload, bit stuffing is used:
0, it automatically inserts (stuffs) a 0 immediately after the fifth 1.0. If it sees five consecutive 1s followed by a 1 and then a 0, it recognizes it as the frame flag sequence 01111110.Input Bits: 0 1 1 1 1 1 1 0 0 1 0 1
^ (Five consecutive 1s detected)
Stuffed Bits: 0 1 1 1 1 1 0 1 0 0 1 0 1 (Stuffed '0' inserted)
^
Unstuffed Bits: 0 1 1 1 1 1 1 0 0 1 0 1 (Restored to original)The core algorithmic tasks of the data link layer are collectively known as Data Link Control (DLC).
To understand the necessity of advanced DLC protocols, we must analyze the theoretical performance of the physical link. Let:
The round-trip capacity of the link is equivalent to the Bandwidth-Delay Product (BDP). The maximum utilization percentage () of a link represents the fraction of time the link is actively carrying data frames:
Consider a point-to-point satellite link where the round-trip propagation time () is . If the frame size is , let us calculate the link utilization under a basic Stop-and-Wait model.
During the time it takes for a single frame to travel to the destination and its acknowledgment to return, the sender could have transmitted (). Sending only wastes over of the link's capacity.
To solve this inefficiency, sliding window protocols are employed to pipeline multiple frames, keeping the communication channel filled.
To analyze flow control algorithms in their purest form, we first assume an ideal, noiseless channel where no frames are lost, duplicated, or corrupted.
The Simplest Protocol has no flow or error control. The sender site continuously retrieves packets from its network layer, encapsulates them, and pushes them onto the physical line. The receiver site is assumed to have infinite buffer space and processing speed, instantly consuming incoming frames.
Sender Site Receiver Site
----------- -------------
Get packet from network layer Receive frame from physical layer
Encapsulate into frame Extract packet
Send frame Deliver packet to network layerIf the receiver's buffer space is finite, the sender must slow down. The Stop-and-Wait Protocol introduces basic flow control: the sender transmits one frame, stops, and waits for an explicit acknowledgment (ACK) from the receiver before sending the next frame.
Sender Site Receiver Site
----------- -------------
[Send Frame 0] -------------------> [Receive Frame 0]
[Wait for ACK] [Process & Buffer Frame 0]
<------------------- [Send ACK]
[Receive ACK]
[Send Frame 1] -------------------> [Receive Frame 1]Real-world physical channels suffer from noise, attenuation, and interference. We now introduce three classic Automatic Repeat Request (ARQ) protocols to handle noisy links.
In Stop-and-Wait ARQ, the sender keeps a copy of the transmitted frame in memory and starts a retransmission timer.
Scenario A: Frame is Lost
Sender (Seq 0) --------X (Lost in transit)
[Timer Expires]
Sender (Seq 0) --------------------------> Receiver (Expects 0)
Receiver Sends ACK 1
<-------------------------- (Expects Seq 1 next)
Scenario B: ACK is Lost
Sender (Seq 0) --------------------------> Receiver (Expects 0)
Receiver Sends ACK 1
X<------------------------- (ACK Lost)
[Timer Expires]
Sender (Seq 0) --------------------------> Receiver (Expects 1, gets duplicate 0)
Receiver discards duplicate, resends ACK 1To improve link utilization, Go-Back-N ARQ allows the sender to transmit multiple frames before waiting for an ACK. This is achieved via a sliding window.
|<----------- Send Window (Size = Ws) ----------->|
+-------------+-------------------------------------------------+-------------+
| Sent & ACKed| Sf (Sent, Outstanding) | Sn (Ready to Send) | Not Allowed |
+-------------+-------------------------------------------------+-------------+
^ ^ ^
First Outstanding Frame Next Frame to Send End of WindowConsider a -bit sequence space (), giving sequence numbers: .
Suppose we set (violating the rule ):
ACK 0 (acknowledging all frames and expecting next).ACK 0 is lost in transit.By restricting , at least one sequence number remains vacant, eliminating sequence overlap ambiguity.
While Go-Back-N uses bandwidth efficiently under low-error conditions, a single packet loss causes the retransmission of the entire window ("going back N"). Selective Repeat ARQ optimizes this by retransmitting only the specific lost or corrupted frame.
Sender Window (Ws): Receiver Window (Wr):
+---+---+---+---+ +---+---+---+---+
| 0 | 1 | 2 | 3 | (Ws = 4) | 0 | 1 | 2 | 3 | (Wr = 4)
+---+---+---+---+ +---+---+---+---+
^ ^
Lost Frame Buffer Out-of-OrderNAK frame when it detects a gap in the received sequence numbers. This triggers the sender to immediately retransmit the missing frame without waiting for its timer to expire.High-Level Data Link Control (HDLC) is a highly structured, bit-oriented protocol standardized by the ISO. It operates over both point-to-point and multipoint communication configurations.
HDLC supports two primary link configurations:
Normal Response Mode (NRM) Asynchronous Balanced Mode (ABM)
+------------+ +------------+ +------------+
| Primary | | Combined | | Combined |
+------------+ | Station A |<====>| Station B |
| ^ +------------+ +------------+
v |
+------------+
| Secondary |
+------------+HDLC frames are bit-oriented and framed using the standard flag 01111110.
+----------+-----------+-----------+-------------+----------+----------+
| Flag | Address | Control | Information | FCS | Flag |
| 8 bits | 8/16 bits | 8/16 bits | Variable | 16/32 bit| 8 bits |
+----------+-----------+-----------+-------------+----------+----------+01111110 delimits frame boundaries.HDLC classifies frames into three distinct types based on the structure of their control fields:
Control Field Bit Formats
+---+---+---+---+---+---+---+---+
I-Frame (Info) | 0 | N(S) |P/F| N(R) |
+---+---+---+---+---+---+---+---+
S-Frame (Super) | 1 | 0 | Type |P/F| N(R) |
+---+---+---+---+---+---+---+---+
U-Frame (Unnum) | 1 | 1 | Type |P/F| Type |
+---+---+---+---+---+---+---+---+N(S): Sequence number of the current frame.N(R): Piggybacked acknowledgment number, declaring the sequence number of the next frame expected.P/F: Poll/Final bit. When set to 1 by a primary, it polls the secondary; when set to 1 by a secondary, it indicates the final frame in response.00. Acknowledges frames up to and indicates readiness to receive.10. Acknowledges frames but halts further transmission from the sender due to temporary buffer congestion.01. Negative acknowledgment used in Go-Back-N to request immediate retransmission starting from .While HDLC is a powerful bit-oriented protocol, the Point-to-Point Protocol (PPP) is the standard, byte-oriented protocol used to encapsulate IP datagrams over physical point-to-point links (such as dial-up connections, DSL, and fiber links).
The PPP frame is modeled closely on HDLC, but operates on character-aligned byte boundaries and incorporates byte stuffing using the escape byte 01111101 (0x7D).
+--------+--------+--------+----------+----------+---------+--------+
| Flag |Address |Control | Protocol | Payload | FCS | Flag |
| 0x7E | 0xFF | 0x03 | 1-2 bytes| Variable | 2-4 byte| 0x7E |
+--------+--------+--------+----------+----------+---------+--------+11111111 (0xFF), as point-to-point links do not require individual node addressing.00000011 (0x03), indicating unnumbered information.0x0021 for Internet Protocol version 4, or 0xC021 for Link Control Protocol).PPP provides a highly flexible multi-protocol architecture using sub-protocols to manage link parameters:
+--------------------------------------+
| IP / IPv6 / IPX | (Network Layer)
+--------------------------------------+
| IPCP / IPV6CP / IPXCP (NCPs) | (Network Control)
+-------------------+------------------+
| PAP / CHAP | LCP Packets | (Auth & Link Control)
+-------------------+------------------+
| PPP Frame | (Data Link Layer)
+--------------------------------------+A PPP link transitions through distinct phases from physical initialization to complete closure:
+--------+ Link +-----------+
| DEAD |--------------->| ESTABLISH | (LCP Negotiation)
+--------+ +-----------+
^ |
| v
| Auth Fail +-----------+
+---------------------| AUTHENTY | (PAP / CHAP)
| +-----------+
| | Auth Success
| v
| NCP Fail +-----------+
+---------------------| NETWORK | (NCP IPCP Setup)
| +-----------+
| | Net Success
| v
| +-----------+
| | OPEN | (Data Transfer)
| +-----------+
| |
| Terminate |
+---------------------------+To make ARQ systems work, errors must first be detected. In this section, we cover the underlying mathematics of block coding, parity checks, and cyclic redundancy checks.
In block coding, we divide our message into blocks of bits, called datawords. We add redundant bits to each block to make the length . The resulting -bit blocks are called codewords.
+-------------------------+
Dataword (k bits) | Encoder Block |
+------------+------------+
|
v
Codeword (n bits) | Data (k) | Redundancy (r) |The Hamming distance between two binary words of equal length is the number of differences between their corresponding bits. It can be found by performing an Exclusive-OR (XOR) operation on the two words and counting the number of s in the result.
The minimum Hamming distance () of a coding scheme is the smallest Hamming distance between all possible pairs of valid codewords in the codebook.
A coding scheme has a minimum Hamming distance . Let us find its error detection and correction capabilities.
Cyclic codes are special linear block codes where cyclically shifting (rotating) any valid codeword results in another valid codeword. The most widely used cyclic code is the Cyclic Redundancy Check (CRC).
A CRC system represents binary words as polynomials with coefficients in . For example, the binary word is written as:
The divisor in a cyclic code is called the generator polynomial, denoted as .
CRC computation is implemented in hardware using linear feedback shift registers (LFSR) and XOR gates. This allows the incoming bitstream to be processed bit-by-bit in real-time, requiring minimal silicon area.
Incoming Bits ------> (XOR) ------> [Reg 2] ------> [Reg 1] ------> [Reg 0]
^ ^
|_____________________________| (Feedback taps based on g(x))A CRC code is highly robust and catches a wide variety of transmission errors:
Standard generator polynomials like CRC-16 () and CRC-32 () are universally used in Ethernet, Wi-Fi, and HDLC due to these robust mathematical guarantees.
0 after five consecutive 1s).The process of bundling stream bits from the physical layer into recognizable, discrete boundaries called frames using character or bit stuffing.
Mechanisms to synchronize sender and receiver speeds while implementing Automatic Repeat Request (ARQ) strategies to detect and correct transmission errors.
A sliding window protocol allowing up to $2^m - 1$ outstanding frames, where a packet loss forces the retransmission of all frames sent after the lost frame.
An optimized sliding window protocol with symmetric window sizes ($2^{m-1}$) that only retransmits the specific frames identified as lost or corrupted.
Standard data link layer protocols where HDLC provides a bit-oriented framework for point-to-point and multipoint links, and PPP acts as a byte-oriented protocol for point-to-point IP encapsulation.
Test your understanding with 5 questions
In a bit-oriented data link protocol, if the sender wishes to transmit the user payload bit pattern '01111110' (which matches the flag pattern), what will be the actual transmitted bit sequence after bit stuffing?
A Stop-and-Wait ARQ system operates over a 1 Mbps link with a round-trip propagation time of 20 ms. If the frame size is 1000 bits, what is the maximum utilization of this link?
What is the maximum size of the send window ($W_s$) in a Go-Back-N ARQ protocol that uses $m$ bits for sequence numbers?
In Selective Repeat ARQ, if the sequence number field is 3 bits wide, what is the maximum send ($W_s$) and receive ($W_r$) window size to guarantee correct operation?
Which of the following HDLC frame types contains a control field that begins with the bits '10' and is used to transmit flow control and error control commands?
11. Used in Selective Repeat to request the retransmission of a single frame numbered .SABM (Set Asynchronous Balanced Mode)DISC (Disconnect)UA (Unnumbered Acknowledgment)6 Modules
6 Modules