Framing
COMPUTER NETWORK AND SECURITY NOTES, IOE, TU , BCA, BSCCSIT
Framing
Framing in the Data Link Layer involves the encapsulation of network layer packets into frames. Frames are the basic units of data at the Data Link Layer, and they serve several important purposes in data communication. The framing process is crucial for the transmission of data over a physical medium, such as a cable or wireless channel.
Frame Structure
A frame typically consists of several fields, each serving a specific purpose. Common fields in a frame include:
Preamble: A sequence of bits that helps synchronize the receiver's clock with the incoming bitstream.
Start Frame Delimiter (SFD): Marks the beginning of the frame and helps the receiver identify the start of the frame.
Addressing Information: Contains the source and destination MAC (Media Access Control) addresses, allowing devices on the same network to recognize the intended recipients.
Frame Control: Includes control information, such as frame type, sequence number, and error-checking information.
Payload: Carries the actual data from the higher-layer protocols (e.g., IP packets).
Frame Check Sequence (FCS): Contains error-checking information (e.g., CRC) to detect transmission errors.
Framing Techniques
Framing techniques in the context of networking refer to the methods used to encapsulate data into frames at the Data Link Layer. The framing process is essential for transmitting data over a physical medium, such as cables or wireless channels.
- Character Count
The Character Count method is a framing technique used in the Data Link Layer to define the boundaries of a data frame by specifying the number of characters (bytes) in the frame. This method is mainly used in character-oriented protocols like BISYNC (Binary Synchronous Communication).
How Character Count Works
- Each frame starts with a special byte that indicates the number of characters (including the count byte itself) in the frame.
- The receiver reads this count value and extracts the exact number of characters to reconstruct the frame.
- The next frame starts after the counted number of characters, and the process repeats.
The first byte in each frame represents the character count of that frame.
The receiver extracts data based on this count.
2. Byte Stuffing
Byte stuffing is a technique used to prevent the flag byte from being interpreted as the end of the frame within the data. When the sender encounters a predefined pattern (e.g., 01111110), it inserts an extra byte to differentiate it from the flag. The receiver removes the extra byte during frame processing. It is primarily used in character-oriented communication protocols, such as PPP (Point-to-Point Protocol) and BISYNC (Binary Synchronous Communication).
Why is Byte Stuffing Needed?
Some protocols use special characters (like FLAG or ESC) to mark the start and end of a frame.
If these special characters appear inside the actual data, the receiver might mistake them for frame boundaries, leading to errors.
Byte stuffing solves this by inserting an escape character (ESC) before special characters in the data.
How Byte Stuffing Works
- The sender checks for special control characters (FLAG, ESC, etc.) inside the data.
- When such a character is found, it inserts an escape character (ESC) before it.
- The receiver, upon detecting an escape character (ESC), knows that the next byte is a data byte and not a control character.
Example of Byte Stuffing
Assume the following protocol uses:
- Frame delimiter (FLAG): F
- Escape character (ESC): E
Original Data (Before Stuffing):
A B F C E D
After Byte Stuffing (Sent Data):
A B E F C E E D
Here:
- F (frame delimiter) is preceded by E (ESC), so it is not mistaken as a delimiter.
- E (escape character) itself is escaped by another E, so the receiver knows it is part of the data.
Receiver Side (Byte Destuffing):
- The receiver removes the extra escape character before F and E, reconstructing the original data.
3. Bit Stuffing
Bit stuffing is similar to byte stuffing but operates at the bit level. It involves inserting extra bits into the data stream to avoid long sequences of identical bits that might be confused with flag sequences. The receiver removes the stuffed bits during frame processing. It is commonly used in synchronous communication protocols such as HDLC (High-Level Data Link Control).
Why is Bit Stuffing Needed?
- In some protocols, a specific bit pattern is used to indicate the start and end of a frame (e.g., 01111110 in HDLC).
- If the same pattern appears within the actual data, it could be mistaken for a frame delimiter, causing errors in transmission.
- Bit stuffing helps to avoid this confusion by adding extra bits when needed.
How Bit Stuffing Works
- The sender scans the data stream for a sequence of five consecutive 1s.
- After detecting five 1s in a row, the sender inserts a 0.
- The receiver, upon detecting five 1s followed by a 0, removes the extra 0 to reconstruct the original data.
Example of Bit Stuffing
Original Data (before stuffing):
01111101111110
After Bit Stuffing (Sent Data):
0111110 0111110 0
- A 0 is inserted after every five consecutive 1s.
Receiver Side (Bit Destuffing):
- The receiver removes the inserted 0s when it detects five consecutive 1s.