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).
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Implementing Byte Stuffing using Java
- Bit Stuffing in Computer Network
- Bit Stuffing error detection technique using Java
- Difference between byte and sbyte in C#
- Difference between Byte Addressable Memory and Word Addressable Memory
- Difference between DVD-R and DVD-RW
- Difference between Blu-ray and DVD
- Difference between GSM and LTE
- Difference between Blu-ray and HD DVD
- Difference between LAN and MAN
- Difference between SSH and SSL
- Difference between Tor and VPN
- Difference between USB 2.0 and USB 3.0
- Difference between T-SQL and PL-SQL
- Difference between 4G and 5G
- Difference between H.323 and SIP
- Difference between DFD and ERD
- Difference between IoE and IoT
- Difference between DAS and NAS
- Difference between RAM and ROM
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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