High-Level Data Link Control
High-Level Data Link Control is a bit-oriented code-transparent synchronous data link layer protocol developed by the International Organization for Standardization. The standard for HDLC is ISO/IEC 13239:2002.
HDLC provides both connection-oriented and connectionless service.
HDLC can be used for point-to-multipoint connections via the original master-slave modes Normal Response Mode and Asynchronous Response Mode, but they are now rarely used; it is now used almost exclusively to connect one device to another, using Asynchronous Balanced Mode.
History
HDLC is based on IBM's SDLC protocol, which is the layer 2 protocol for IBM's Systems Network Architecture. It was extended and standardized by the ITU as LAP, while ANSI named their essentially identical version ADCCP.The HDLC specification does not specify the full semantics of the frame fields. This allows other fully compliant standards to be derived from it, and derivatives have since appeared in innumerable standards. It was adopted into the X.25 protocol stack as LAPB, into the V.42 protocol as LAPM, into the Frame Relay protocol stack as LAPF and into the ISDN protocol stack as LAPD.
The original ISO standards for HDLC are the following:
- ISO 3309-1979 – Frame Structure
- ISO 4335-1979 – Elements of Procedure
- ISO 6159-1980 – Unbalanced Classes of Procedure
- ISO 6256-1981 – Balanced Classes of Procedure
HDLC was the inspiration for the IEEE 802.2 LLC protocol, and it is the basis for the framing mechanism used with the PPP on synchronous lines, as used by many servers to connect to a WAN, most commonly the Internet.
A similar version is used as the control channel for E-carrier and SONET multichannel telephone lines. Cisco HDLC uses low-level HDLC framing techniques but adds a protocol field to the standard HDLC header.
Framing
HDLC frames can be transmitted over synchronous or asynchronous serial communication links. Those links have no mechanism to mark the beginning or end of a frame, so the beginning and end of each frame has to be identified. This is done by using a unique sequence of bits as a frame delimiter, or flag, and encoding the data to ensure that the flag sequence is never seen inside a frame. Each frame begins and ends with a frame delimiter. A frame delimiter at the end of a frame may also mark the start of the next frame.On both synchronous and asynchronous links, the flag sequence is binary "01111110", or hexadecimal 0x7E, but the details are quite different.
Synchronous framing
Because a flag sequence consists of six consecutive 1-bits, other data is coded to ensure that it never contains more than five 1-bits in a row. This is done by bit stuffing: any time that five consecutive 1-bits appear in the transmitted data, the data is paused and a 0-bit is transmitted.The receiving device knows that this is being done, and after seeing five 1-bits in a row, a following 0-bit is stripped out of the received data. If instead the sixth bit is 1, this is either a flag, or an error. In the latter case, the frame receive procedure is aborted, to be restarted when a flag is next seen.
This bit-stuffing serves a second purpose, that of ensuring a sufficient number of signal transitions. On synchronous links, the data is NRZI encoded, so that a 0-bit is transmitted as a change in the signal on the line, and a 1-bit is sent as no change. Thus, each 0 bit provides an opportunity for a receiving modem to synchronize its clock via a phase-locked loop. If there are too many 1-bits in a row, the receiver can lose count. Bit-stuffing provides a minimum of one transition per six bit times during transmission of data, and one transition per seven bit times during transmission of a flag.
When no frames are being transmitted on a simplex or full-duplex synchronous link, a frame delimiter is continuously transmitted on the link. This generates one of two continuous waveforms, depending on the initial state:
The HDLC specification allows the 0-bit at the end of a frame delimiter to be shared with the start of the next frame delimiter, i.e. "011111101111110". Some hardware does not support this.
For half-duplex or multi-drop communication, where several transmitters share a line, a receiver on the line will see continuous idling 1-bits in the inter-frame period when no transmitter is active.
HDLC transmits bytes of data with the least significant bit first.
Asynchronous framing
When using asynchronous serial communication such as standard RS-232 serial ports, synchronous-style bit stuffing is inappropriate for several reasons:- Bit stuffing is not needed to ensure an adequate number of transitions, as start and stop bits provide that,
- Because the data is NRZ encoded for transmission, rather than NRZI encoded, the encoded waveform is different,
- RS-232 sends bits in groups of 8, making adding single bits very awkward, and
- For the same reason, it is only necessary to specially code flag bytes; it is not necessary to worry about the bit pattern straddling multiple bytes.
The "abort sequence" 0x7D 0x7E ends a packet with an incomplete byte-stuff sequence, forcing the receiver to detect an error. This can be used to abort packet transmission with no chance the partial packet will be interpreted as valid by the receiver.
Structure
The contents of an HDLC frame are shown in the following table:Flag | Address | Control | Information | FCS | Flag |
8 bits | 8 or more bits | 8 or 16 bits | Variable length, 8×n bits | 16 or 32 bits | 8 bits |
Note that the end flag of one frame may be the beginning flag of the next frame.
Data is usually sent in multiples of 8 bits, but only some variants require this; others theoretically permit data alignments on other than 8-bit boundaries.
The frame check sequence is a 16-bit CRC-CCITT or a 32-bit CRC-32 computed over the Address, Control, and Information fields. It provides a means by which the receiver can detect errors that may have been induced during the transmission of the frame, such as lost bits, flipped bits, and extraneous bits. However, given that the algorithms used to calculate the FCS are such that the probability of certain types of transmission errors going undetected increases with the length of the data being checked for errors, the FCS can implicitly limit the practical size of the frame.
If the receiver's calculation of the FCS does not match that of the sender's, indicating that the frame contains errors, the receiver can either send a negative acknowledge packet to the sender, or send nothing. After either receiving a negative acknowledge packet or timing out waiting for a positive acknowledge packet, the sender can retransmit the failed frame.
The FCS was implemented because many early communication links had a relatively high bit error rate, and the FCS could readily be computed by simple, fast circuitry or software. More effective forward error correction schemes are now widely used by other protocols.
Types of stations (computers) and data transfer modes
was originally designed to connect one computer with multiple peripherals via a multidrop bus. The original "normal response mode" is a master-slave mode where the computer gives each peripheral permission to speak in turn. Because all communication is either to or from the primary terminal, frames include only one address, that of the secondary terminal; the primary terminal is not assigned an address. There is a distinction between commands sent by the primary to a secondary, and responses sent by a secondary to the primary, but this is not reflected in the encoding; commands and responses are indistinguishable except for the difference in the direction in which they are transmitted.Normal response mode allows the secondary-to-primary link to be shared without contention, because it has the primary give the secondaries permission to transmit one at a time. It also allows operation over half-duplex communication links, as long as the primary is aware that it may not transmit when it has given permission to a secondary.
Asynchronous response mode is an HDLC addition for use over full-duplex links. While retaining the primary/secondary distinction, it allows the secondary to transmit at any time. Thus, there must be some other mechanism to ensure that multiple secondaries do not try to transmit at the same time.
Asynchronous balanced mode adds the concept of a combined terminal which can act as both a primary and a secondary. Unfortunately, this mode of operation has some implementation subtleties. While the most common frames sent do not care whether they are in a command or response frame, some essential ones do, and the address field of a received frame must be examined to determine whether it contains a command or a response.
This means that the address field is not optional, even on point-to-point links where it is not needed to disambiguate the peer being talked to. Some HDLC variants extend the address field to include both source and destination addresses, or an explicit command/response bit.
HDLC operations and frame types
Three fundamental types of HDLC frames may be distinguished:- Information frames, or I-frames, transport user data from the network layer. They can also include flow and error control information piggybacked on data.
- Supervisory frames, or S-frames, are used for flow and error control whenever piggybacking is impossible or inappropriate, such as when a station does not have data to send. S-frames do not have information fields.
- Unnumbered frames, or U-frames, are used for various miscellaneous purposes, including link management. Some U-frames contain an information field, depending on the type.
Control field
There are also extended forms of I and S frames. Again, the least significant bit is sent first.
P/F bit
Poll/Final is a single bit with two names. It is called Poll when part of a command, and Final when part of a response. In all other cases, the bit is clear.The bit is used as a token that is passed back and forth between the stations. Only one token should exist at a time. The secondary only sends a Final when it has received a Poll from the primary. The primary only sends a Poll when it has received a Final back from the secondary, or after a timeout indicating that the bit has been lost.
- In NRM, possession of the poll token also grants the addressed secondary permission to transmit. The secondary sets the F-bit in its last response frame to give up permission to transmit.
- In ARM and ABM, the P bit forces a response. In these modes, the secondary need not wait for a poll to transmit, so the final bit may be included in the first response after the poll.
- If no response is received to a P bit in a reasonable period of time, the primary station times out and sends P again.
- The P/F bit is at the heart of the basic checkpoint retransmission scheme that is required to implement HDLC; all other variants are optional and only serve to increase efficiency. Whenever a station receives a P/F bit, it may assume that any frames that it sent before it last transmitted the P/F bit and not yet acknowledged will never arrive, and so should be retransmitted.
N(R), the receive sequence number
Both I and S frames contain a receive sequence number N. N provides a positive acknowledgement for the receipt of I-frames from the other side of the link. Its value is always the first frame not yet received; it acknowledges that all frames with N values up to N−1 have been received and indicates the N of the next frame it expects to receive.N operates the same way whether it is part of a command or response. A combined station only has one sequence number space.
N(S), the sequence number of the sent frame
This is incremented for successive I-frames, modulo 8 or modulo 128. Depending on the number of bits in the sequence number, up to 7 or 127 I-frames may be awaiting acknowledgment at any time.I-Frames (user data)
Information frames, or I-frames, transport user data from the network layer. In addition they also include flow and error control information piggybacked on data. The sub-fields in the control field define these functions.The least significant bit defines the frame type. 0 means an I-frame.
Except for the interpretation of the P/F field, there is no difference between a command I frame and a response I frame; when P/F is 0, the two forms are exactly equivalent.
S-frames (control)
Supervisory Frames, or 'S-frames', are used for flow and error control whenever piggybacking is impossible or inappropriate, such as when a station does not have data to send. S-frames in HDLC do not have information fields, although some HDLC-derived protocols use information fields for "multi-selective reject".The S-frame control field includes a leading "10" indicating that it is an S-frame. This is followed by a 2-bit type, a poll/final bit, and a 3-bit sequence number.
The first 2 bits mean it is an S-frame. All S frames include a P/F bit and a receive sequence number as described above. Except for the interpretation of the P/F field, there is no difference between a command S frame and a response S frame; when P/F is 0, the two forms are exactly equivalent.
Receive Ready (RR)
- Bit value = 00
- Indicate that the sender is ready to receive more data.
- Send this packet if you need to send a packet but have no I frame to send.
- A primary station can send this with the P-bit set to solicit data from a secondary station.
- A secondary terminal can use this with the F-bit set to respond to a poll if it has no data to send.
Receive Not Ready (RNR)
- Bit value = 10
- Acknowledge some packets but request no more be sent until further notice.
- Can be used like RR with P bit set to solicit the status of a secondary station
- Can be used like RR with F bit set to respond to a poll if the station is busy.
Reject (REJ)
- Bit value = 01
- Requests immediate retransmission starting with N.
- Sent in response to an observed sequence number gap; e.g. after seeing I1/I2/I3/I5, send REJ4.
- Optional to generate; a working implementation may use only RR.
Selective Reject (SREJ)
- Bit value = 11
- Requests retransmission of only the frame N.
- Not supported by all HDLC variants.
- Optional to generate; a working implementation may use only RR, or only RR and REJ.
U-Frames
The first 2 bits mean it is a U-frame. The five type bits can create 32 different types of U-frame. In a few cases, the same encoding is used for different things as a command and a response.
Mode setting
The various modes are described in. Briefly, there are two non-operational modes and three operational modes with 3-bit or 7-bit sequence numbers.; Disconnected mode response
; Unnumbered acknowledge response
; Set... mode command
; Set... mode extended command
; Set mode command
; Disconnect command
; Request disconnect response
; Set initialization mode command
; Request initialization mode response
Information transfer
These frames may be used as part of normal information transfer.; Unnumbered information
; UI with header check
; Unnumbered poll command
Error Recovery
; Frame reject response; Reset command
Peer discovery
; Exchange identification; TEST
Defined in other standards
There are several U frames which are not part of HDLC, but defined in other related standards.; Nonreserved
; Ack connectionless
; Configure
; Beacon response
Link configurations
Link configurations can be categorized as being either:- Unbalanced, which consists of one primary terminal, and one or more secondary terminals.
- Balanced, which consists of two peer terminals.
- Normal Response Mode is an unbalanced configuration in which only the primary terminal may initiate data transfer. The secondary terminals transmit data only in response to commands from the primary terminal. The primary terminal polls each secondary terminal to give it an opportunity to transmit any data it has.
- Asynchronous Response Mode is an unbalanced configuration in which secondary terminals may transmit without permission from the primary terminal. However, there is still a distinguished primary terminal which retains responsibility for line initialization, error recovery, and logical disconnect.
- Asynchronous Balanced Mode is a balanced configuration in which either station may initialize, supervise, recover from errors, and send frames at any time. There is no master/slave relationship. The DTE and DCE are treated as equals. The initiator for Asynchronous Balanced Mode sends an SABM.
HDLC Command and response repertoire
The minimal set required for operation are:- Commands: I, RR, RNR, DISC, and one of SNRM, SARM or SABM
- Responses: I, RR, RNR, UA, DM, FRMR
Basic operations
- Initialization can be requested by either side. When the primary sends one of the six mode-set commands, it:
- *Signals the other side that initialization is requested
- *Specifies the mode, NRM, ABM, ARM
- *Specifies whether 3 or 7 bit sequence numbers are in use.
Functional extensions (options)
- For Switched Circuits
- *Commands: ADD – XID
- *Responses: ADD – XID, RD
- For 2-way Simultaneous commands & responses are ADD – REJ
- For Single Frame Retransmission commands & responses: ADD – SREJ
- For Information Commands & Responses: ADD – Ul
- For Initialization
- *Commands: ADD – SIM
- *Responses: ADD – RIM
- For Group Polling
- *Commands: ADD – UP
- Extended Addressing
- Delete Response I Frames
- Delete Command I Frames
- Extended Numbering
- For Mode Reset Commands are: ADD – RSET
- Data Link Test Commands & Responses are: ADD – TEST
- Request Disconnect. Responses are ADD – RD
- 32-bit FCS
HDLC command and response repertoire
Unnumbered frames
Unnumbered frames are identified by the low two bits being 1. With the P/F flag, that leaves 5 bits as a frame type. Even though fewer than 32 values are in use, some types have different meanings depending on the direction they are sent: as a command or as a response. The relationship between the DISC command and the RD response seems clear enough, but the reason for making SARM command numerically equal to the DM response is obscure.The UI, UIH, XID, TEST frames contain a payload, and can be used as both commands and responses. The SM command and FRMR response also contain a payload.
- A UI frame contains user information, but unlike an I frame it is neither acknowledged nor retransmitted if lost.
- A UIH frame is like a UI frame, but additionally applies the frame check sequence only to a specified-length prefix of the frame; transmission errors after this prefix are not detected.
- The XID frame is used to exchange terminal capabilities. Systems Network Architecture defined one format, but the variant defined in ISO 8885 is more commonly used. A primary advertises its capabilities with an XID command, and a secondary returns its own capabilities in an XID response.
- The TEST frame is simply a ping command for debugging purposes. The payload of the TEST command is returned in the TEST response.
- The SM command is a generic "set mode" command which includes an information field specifying parameters. This allows parameter values and parameters like window sizes and maximum frame sizes not expressible by the standard six mode-set commands to be negotiated.
- The FRMR response contains a description of the unacceptable frame, in a standardized format. The first 1 or 2 bytes are a copy of the rejected control field, the next 1 or 2 contain the secondary's current send and receive sequence numbers, and the following 4 or 5 bits are error flags indicating the reason for the rejection.