Framing In Data Link Layer

Framing in the Data Link Layer is the process of dividing a data stream into manageable units called frames before transmission over a network. Each frame contains not just the raw data (payload), but also control information like addressing, error detection, and synchronization, which ensures reliable communication between devices.

OSI Model: At Sender side data link layer receive packets from network layer and converts it into frames by adding multiple things as, MAC addresses, error-checking (CRC), and other control info.

  • Frame: A frame is the unit of data at the Data Link Layer (Layer 2) of the OSI model. It’s concerned with local delivery (within the same network or physical link). It includes MAC addresses, error-checking (CRC), and other control info.

  • Packet: A packet is the unit of data at the Network Layer (Layer 3). It includes IP addresses (source and destination) and is used for end-to-end delivery across networks. A packet is what gets routed across the internet.

When a message is travel to its destination from sender side, it holds all information added by OSI 7 layers.

Frame Structure

There are 3 major components of  frame at data link layer

Frame Structure - Data Link Layer

i. Header (Control Information Before the Data)

The header contains information needed to control and manage the frame as it travels across the network.

Field Name Description
Preamble (Ethernet) Pattern for synchronization between sender and receiver
Start Frame Delimiter (SFD) Marks the start of the actual frame data
Destination Address MAC address of the receiving device
Source Address MAC address of the sending device
Length/Type Indicates the size or type of the payload (e.g., IPv4, ARP)
Control Field Used in some protocols for flow control, sequencing, or acknowledgments (e.g., HDLC, PPP)

 ii. Payload (Data)

  • This contains the actual data passed from the Network Layer (like an IP packet).
  • Varies in size depending on the protocol (e.g., Ethernet allows 46–1500 bytes).

 iii. Trailer (Control Information After the Data)

Field Name Description
Frame Check Sequence (FCS) Contains a CRC value for error detection
Frame End Delimiter (optional) Some protocols mark the end of a frame explicitly (e.g., HDLC)

Why Framing is Important

  • Data Separation: Splits continuous stream of bits into frames.
  • Error Detection: Each frame can include a checksum or CRC to detect errors.
  • Addressing: Helps identify the sender and receiver.
  • Flow Control & Acknowledgments: Ensures proper delivery and handling.

Types of Framing Techniques

Most common framing techniques are given below

i. Character Count

  • How it works: The first byte (or field) of the frame indicates the total number of bytes in the frame.

    Example:

    [05][A][B][C][D]
    • Here, 05 means the frame has 5 bytes (including the count field).

  • Problem:
    If the character count gets corrupted (e.g., read as 20 instead of 5), the receiver will misinterpret the frame boundary and lose synchronization for the rest of the transmission.

ii. Flag-based (Bit Stuffing)

  • How it works: A unique bit pattern (often 01111110) is used as a flag to indicate the start and end of a frame.
  • Bit Stuffing Rule:
    If the same flag pattern appears in the actual data, the sender inserts an extra 0 after five consecutive 1s to prevent confusion.

Example: Data: 01111110 → Stuffed as: 011111010
Frame: 01111110 [Stuffed Data] 01111110

  • Receiver: Looks for the flag and then removes stuffed 0‘s during processing.

iii. Byte-oriented (Character Stuffing)

Character stuffing is a technique used in communication protocols to differentiate between regular data and special characters that are used to signal the beginning and end of data frames.

Special characters (like DLE STX for start and DLE ETX for end) are used to mark the boundaries of the frame. If these special characters appear in the data itself, we need a way to indicate that they are part of the data, not frame delimiters. This is where “escaping” comes into play, where we add a special prefix (like DLE) to the special characters in the data.

  • Start of Frame = DLE STX (a special character to indicate the start of the frame)
  • End of Frame = DLE ETX (a special character to indicate the end of the frame)

Step-by-Step Example

  • Original Data: "A DLE B"
  • Frame with Start/End Markers: [DLE][STX] A DLE B [DLE][ETX]
  • Applying Stuffing: When “DLE” is encountered in the data, it’s escaped by adding an extra DLE.
    • A DLE B → becomes → A DLE DLE B
  • Final Frame with Stuffing: [DLE][STX] A DLE DLE B [DLE][ETX]
  • Receiver Receives the Frame: It sees the frame and recognizes that DLE DLE means DLE, so it strips out the extra DLE.
  • Decoded Data: "A DLE B" is the final decoded data.

Character stuffing ensures that special characters used to denote the start and end of a frame (like DLE STX and DLE ETX) don’t appear within the actual data. If they do, they are escaped (i.e., prefixed with DLE) so that the receiver can distinguish between control characters and data.

iv. Clock-based Framing (Physical Layer Coding)

How it works: This method relies on synchronization between the sender and receiver using the physical layer’s timing signals. If one device’s clock is slightly faster or slower than the other’s, the receiver might miss data or even think data has been corrupted.

  • Used in: High-speed synchronous communication (like optical fiber or SONET).
  • Frame boundaries are marked by specific timing patterns or predefined electrical signals, not by inserted flags or characters.
  • Advantage: No need to add framing overhead in the data stream.
  • Disadvantage: Requires precise clock synchronization between devices.