HDLC Protocol

High-Level Data Link Control frame structure, commands, and operation modes.

What is HDLC? The Postman of the Network

High-Level Data Link Control (HDLC) is a classic and highly influential protocol that operates at the Data Link Layer (Layer 2) of the OSI model. Think of it as a highly disciplined and reliable postal service for a single, direct link between two network devices (like a connection between two routers over a leased line).

Its main purpose is to take raw packets from the Network Layer (the "letter") and place them into a standardized envelope called a frame. This frame not only contains the data but also adds addressing, control information, and error-checking mechanisms to ensure the data arrives safely and in order at the next device on its journey. HDLC was a foundational protocol for point-to-point and multipoint links and its concepts have influenced countless subsequent protocols, including PPP, Frame Relay, and ISDN.

Core Concepts: Stations and Operational Modes

Before diving into the frame structure, it's essential to understand the roles that devices (called "stations") can play and the modes in which an HDLC link can operate.

Station Types

  • Primary Station (Master): This station controls the operation of the data link. It issues commands and is responsible for managing the link, initiating data transfers, and handling error recovery.
  • Secondary Station (Slave): This station operates under the control of a primary station. It only speaks when spoken to, sending responses to the primary station's commands.
  • Combined Station (Peer): A more advanced type of station that combines the features of both a primary and a secondary station. It can send and receive both commands and responses, acting as a peer in the communication.

Operational Modes

  • Normal Response Mode (NRM): An unbalanced configuration used in point-to-multipoint links. It features one primary station and one or more secondary stations. The secondary stations cannot transmit until they are polled (explicitly given permission) by the primary station.
  • Asynchronous Response Mode (ARM): Another unbalanced mode. It allows a secondary station to initiate transmission without waiting to be explicitly polled by the primary. However, the primary station still retains ultimate control over link setup and error recovery.
  • Asynchronous Balanced Mode (ABM): This is the most widely used mode, especially for point-to-point links. It uses two combined stations acting as peers. Either station can initiate transmissions without permission from the other, providing a more efficient, full-duplex communication channel.

The Anatomy of an HDLC Frame

HDLC encapsulates all data and control messages into a well-defined structure called a frame. Each part of the frame has a specific purpose.

  • Flag (8 bits): The frame begins and ends with a special 8-bit sequence: 01111110. This unique pattern acts as a delimiter, allowing the receiver to detect the exact start and end of a frame within a continuous stream of bits. A single flag can be used to simultaneously mark the end of one frame and the beginning of the next.
  • Address (8 or 16 bits): This field identifies the destination secondary station. In point-to-point links, this field might have a standard value as the destination is unambiguous. In multipoint configurations (like NRM), it's crucial for specifying which of several secondary stations the frame is intended for. An address of all 1s is typically used as a broadcast address.
  • Control (8 bits): This is the "brain" of the frame. It defines the frame's purpose and contains sequence numbers for flow and error control. There are three types of frames, distinguished by the first bits of this field: Information (I-frames), Supervisory (S-frames), and Unnumbered (U-frames).
  • Information (Variable Length): This is the payload. It contains the actual data from the higher layer, typically a Network Layer packet (like an IP packet). This field is only present in Information frames and some Unnumbered frames. Its length can vary up to a negotiated maximum.
  • Frame Check Sequence (FCS) (16 or 32 bits): This is an error-detection field. The sender calculates a value using a algorithm over the Address, Control, and Information fields. The receiver performs the same calculation. If the results don't match, the frame is assumed to be corrupted and is discarded.

A Crucial Detail: Bit Stuffing

A critical problem arises: what if the flag sequence 01111110 appears naturally within the user's data? The receiver would mistakenly interpret it as the end of the frame, leading to a synchronization error. HDLC solves this with an elegant technique called bit stuffing (also known as zero-bit insertion).

  • Sender's Action: The sender's HDLC hardware continuously scans the data stream (between the flags). Whenever it detects a sequence of five consecutive '1's, it automatically inserts, or "stuffs," an extra '0' bit into the stream before transmitting.
  • Receiver's Action: The receiver scans the incoming stream. If it sees five consecutive '1's followed by a '0', it knows this '0' was stuffed by the sender and automatically removes it, perfectly restoring the original data. If it sees five '1's followed by a '1', it checks the next bit. If that bit is a '0', it knows it has found a true flag (01111110).

This simple and clever mechanism ensures that the flag sequence is unique and can only ever appear at the true beginning and end of a frame, guaranteeing data transparency.

Understanding the Control Field and Frame Types

The 8-bit Control field is the most complex part of the HDLC frame. Its structure determines the frame's function.

Information Frames (I-frames)

I-frames are the workhorses of HDLC. Their job is to carry the user's data from the Network Layer. The control field starts with a 0.

  • N(S) - Send Sequence Number: A 3-bit sequence number for the outgoing frame. It allows for up to 8 frames (232^3) to be in transit before an acknowledgment is needed.
  • N(R) - Receive Sequence Number: A 3-bit sequence number that acknowledges received frames. It indicates the number of the next frame the station expects to receive, implicitly acknowledging all frames up to N(R)-1. This is a key part of HDLC's sliding window mechanism.
  • P/F - Poll/Final bit: A versatile bit with different meanings. A primary station sets it to 1 to "poll" a secondary station for a response. A secondary station sets it to 1 in its final frame of a response to indicate "final".
Supervisory Frames (S-frames)

S-frames are used for flow and error control. They do not carry user data. The control field starts with 10.

  • Type (2 bits): Defines the function of the S-frame:
    • Receive Ready (RR): Acknowledges received frames up to N(R)-1 and indicates readiness to receive more.
    • Receive Not Ready (RNR): Acknowledges received frames but tells the sender to temporarily stop transmitting (flow control).
    • Reject (REJ): A negative acknowledgment requesting the retransmission of a single frame starting from N(R).
  • N(R) - Receive Sequence Number: Same function as in I-frames, used for acknowledging data.
Unnumbered Frames (U-frames)

U-frames are used for link management purposes, such as establishing and terminating connections. They do not have sequence numbers. The control field starts with 11.

Common U-frames include:

  • SABME (Set Asynchronous Balanced Mode Extended): A command to establish an HDLC link in ABM mode with extended (7-bit) sequence numbers.
  • DISC (Disconnect): A command to terminate the logical link.
  • UA (Unnumbered Acknowledgment): A response used to confirm the acceptance of a U-frame command like SABME or DISC.
    HDLC Protocol | Teleinf Edu