Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Payload bytes After byte stuffing After byte destuffing

0xAB FLAG 0xCD 0xAB ESC FLAG 0xCD 0xAB FLAG 0xCD
0xAB ESC 0xCD 0xAB ESC ESC 0xCD 0xAB ESC 0xCD
0xAB ESC FLAG 0xCD 0xAB ESC ESC ESC FLAG 0xCD 0xAB ESC FLAG 0xCD

Table 4.1: Illustration of byte stuffing and destuffing

flag byte is not destuffed. However, in most data link layer protocols, the escape byte is inserted
before other control bytes as well. Then the receiver has to check if the escape byte is followed
by any one of the control bytes before destuffing it. This can be a time-consuming operation if
the number of possible control bytes is large. A simpler strategy is to insert another escape byte
before the appearance of every escape byte in the payload at the sending data link layer. At the
receiving data link layer, every pair of escape bytes is destuffed to a single escape byte and an
escape byte followed by a flag byte is destuffed to a flag byte. This is illustrated in Table 4.1
where FLAG denotes the flag byte, ESC denotes the escape byte and the other payload bytes
are given in hexadecimal notation.

Another approach to framing involves bit stuffing instead of byte stuffing. As before the start
and end of a frame is indicated by a flag byte which in this case is chosen to be the byte 01111110.
To deal with the issue of the flag byte appearing in the payload, the sending data link layer
inserts a 0 bit whenever it encounters five consecutive 1s in the payload. This is illustrated in
Figure 4.3.

In reality, many data link layer protocols use the payload length and the flag delimiters together
to achieve framing. This has the advantage of more robustness against channel errors. The
payload length is used to calculate the end of the frame and the presence of a flag at that
position is checked. If the the expected flag is absent either due to channel errors corrupting
the length field or the flag itself, the frame is discarded as erroneous.

4.2 Error Control

The most crucial function of the data link layer is to convert the unreliable bit pipe provided
by the physical layer into a error-free bit pipe. This is achieved using the combination of an
error-detecting code like cyclic redundancy check (CRC) and automatic repeat request (ARQ).
Although CRC is just one type of error-detecting code, it is the most prevalent one in usage
today and hence it has become synonymous with error detection in networking literature. ARQ
uses a combination of timeouts and acknowledgements to ensure frame retransmissions when
frame errors are detected by the CRC.

In the introductory chapter, we mentioned forward error correction (FEC) as another method

Payload bits 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0
After bit stuffing 1 0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0
After destuffing 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0

Figure 4.3: Illustration of bit stuffing where the underlined bits are introduced by the bit stuffing
operation

30

You might also like