Data link layer is responsible for something called Framing, which is the division of stream of bits from the network layer into manageable units (called frames). Each frame consists of the sender’s address and a destination address. The destination address defines where the packet is to go and the sender’s address helps the recipient acknowledge the receipt.
Frames could be of fixed size or variable size. In fixed-size framing, there is no need for defining the boundaries of the frames as the size itself can be used to define the end of the frame and the beginning of the next frame. But, in variable-size framing, we need a way to define the end of the frame and the beginning of the next frame.
To separate one frame from the next, an 8-bit (or 1-byte) flag is added at the beginning and the end of a frame. But the problem with that is, any pattern used for the flag could also be part of the information. So, there are two ways to overcome this problem:
- Using Byte stuffing (or character stuffing)
- Using Bit stuffing
Byte stuffing –
A byte (usually escape character(ESC)), which has a predefined bit pattern is added to the data section of the frame when there is a character with the same pattern as the flag. Whenever the receiver encounters the ESC character, it removes from the data section and treats the next character as data, not a flag.
But the problem arises when the text contains one or more escape characters followed by a flag. To solve this problem, the escape characters that are part of the text are marked by another escape character i.e., if the escape character is part of the text, an extra one is added to show that the second one is part of the text.
Note – Point-to-Point Protocol (PPP) is a byte-oriented protocol.
Bit stuffing –
Mostly flag is a special 8-bit pattern “01111110” used to define the beginning and the end of the frame.
Problem with the flag is the same as that was in case of byte stuffing. So, in this protocol what we do is, if we encounter 0 and five consecutive 1 bits, an extra 0 is added after these bits. This extra stuffed bit is removed from the data by the receiver.
The extra bit is added after one 0 followed by five 1 bits regardless of the value of the next bit. Also, as the sender side always knows which sequence is data and which is flag it will only add this extra bit in the data sequence, not in the flag sequence.
Note – High-Level Data Link Control(HDLC) is a bit-oriented protocol.
Data Communications and Networking By Behrouz A. Forouzan (Book).
- Implementing Byte Stuffing using Java
- Bit Stuffing in Computer Network
- Bit Stuffing error detection technique using Java
- Difference between Byte Addressable Memory and Word Addressable Memory
- Difference between LAN and WAN
- Difference between MAN and WAN
- Difference between H.323 and SIP
- Difference between 4G and 5G
- Difference between C and C#
- Difference between CPU and GPU
- Difference between 1G and 2G
- Difference between LED and LCD
- Difference between TDM and FDM
- Difference between CRT and LCD
- Difference between OOP and POP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ayushgangwar