Framing in Data Link Layer

In this tutorial, you will learn the basics of framing. This tutorial will explain the different types, methods, and the purpose of framing in communication over a channel. You will also learn about the working, advantages, and disadvantages of different frame methods.

Contents:

  1. What is Framing?
  2. Fields of Frame
  3. Transmission of Frames
  4. Types of Framing
  5. Methods for Dividing Frames
  6. Byte Count Method
  7. Flag Bytes with Byte Stuffing & Bit Stuffing
  8. Physical Layer Coding Violations

What is Framing?

Framing is one of the responsibilities of the data link layer, which provides reliable communication between sender and receiver.

  • The frame contains the addresses of the sender and receiver. According to the destination address, the frame will be sent to the destination. When the destination receives the frame, it opens the frame and checks the sender’s address, and acknowledges to the sender that it has received the frame.
  • Basically, the data link layer receives packets from the network layer and converts the packets into frames.
  • The data link layer splits large frames into smaller frames to maintain the flow of data and reduce the chance of error between devices.

Fields of Frame

The frame consists of three parts, the header, data, and trailer. The frame structure and size vary according to the protocol being used.

Header: The header contains the frame start, addressing, type, and control fields.

advertisement
advertisement
  • Frame start: We can identify the start of the frame by looking at the Frame Start field.
  • Addressing: It stores the address of the sender and receiver. According to the addressing field, the data link layer sends the frame from the sender to the receiver.
  • Type: The Type field is used to identify the network layer protocol that is used for header information.
  • Control: It provides a flow control mechanism. By using control fields, the network prioritizes packets that are important for communication.

Data: This is an IP packet received from the network layer. Packets are also known as payload or data at the data link layer. All protocols in the data link layer will be added to the frame’s data field.

Trailer: Error Detection and Frame Stop are the fields of the trailer. The data link layer information will be added to the trailer of the frame.

  • Error Detection: The trailer field of the frame contains an error detection method that is used to identify errors during communication.
  • Frame Stop: It is used to identify the end of the field.

The diagram below describes the fields of the frame.

fields of the frame

As you can see in the diagram above, frame start, addressing, type, and control are the fields of the header. Error detection and frame stop are the fields of the trailer.

Transmission of Frames

The data link layer receives IP packets from the network layer. It then converts the packets into frames and adds the data link layer information, which is determined by the protocol.

  • The data link layer is also responsible for providing addressing for transmitting frames from sender to receiver. Typically, physical addresses at the data link layer are used to transmit frames.
  • In the header field of the frame, the physical addresses of the sender and receiver are stored.
  • According to the physical addresses, the data link layer will send frames hop-by-hop.
  • Basically, physical addresses do not indicate which network the device is located on, like IP addresses. Therefore, physical addresses are used to connect devices that are on the same media and network.
  • If the sender and receiver are on the same LAN connected to the switch and share media, instead of using the IP address, the sender can send frames to the receiver, using only the physical address.

The diagram below shows how frames are transmitted over a network.

Transmission of frames
  • The above diagram shows that PC-1 wants to send frames to PC-2 through the router. So, in the header field of the frame, layer-3 and layer-2 addresses will be stored.
  • According to the address of the receiver which is stored in the header field, the sender will initiate the transmission process, and the physical addresses will be changed at each hop during the transmission process, as shown in the figure.

Types of Framing

As we know that on the sender side, the frames are converted into bits at the physical layer. But when a stream of bits is received at the physical layer of the receiver, the physical layer sends the stream of bits to the data link layer. So, according to the size of the bits, the data link layer divides the bits into frames, which can be fixed-size frames or variable-sized frames.

advertisement

Fixed-Size Framing: In fixed-size framing, all the bits received from the physical layer are in one frame, or you can say that there is no limit in fixed-size framing because fixed-size framing itself defines the beginning and end of the frame. Asynchronous Transfer Mode Wide Area Network (ATM WAN) is an example of the fixed-size framing.

Variable-Size Framing: In variable-size framing, the entire message is divided into smaller-sized frames. So for each frame, we have to define the start and end of the frame.

The below diagram describes the types of framing.

types of framing
  • The above diagram shows that fixed-size framing and variable-size framing are two types of framing.
  • As you can see in the above diagram that in fixed-size framing, a frame consists of 1024 bits, so if an error occurs, the receiver device has to check all 1024 bits, which is time-consuming for the receiver.
  • In variable-size framing, 1024 bits are divided into 4 frames of 256 bits each. Also, if there is an error in one of the frames, instead of checking all 1024 bits, the receiver will only check 256 bits of the frame that contains the error.

Methods for Dividing Frames

Dividing a stream of bits into frames is not as easy as it sounds. Frames must be divided in such a way that the receiver can receive frames using the low bandwidth of the channel and can detect the start and end of the frame. So, there are four methods of framing as follows:

advertisement
  1. Byte Count
  2. Flag Bytes with Byte Stuffing
  3. Flag Bits with Bit Stuffing
  4. Physical Layer Coding Violations.

All the above methods are used as per the requirement. By using the appropriate method for the network, one can make the communication over the channel reliable.

Byte Count Method

In the byte count method, a frame has a header field (byte count) that is used to identify the number of bytes in the frame. So when the frame reaches the receiver, the receiver checks the byte count, and based on that, it detemines the number of bytes in the frame and the start and end of the frame.

The figure below explains the byte count method.

byte count method
  • As you can see in Figure-4.a, a 16-byte message is divided into three frames. The size of frame-1, frame-2, and frame-3 are 4, 4, and 8 bytes, respectively.
  • In frame-1, the value of byte count is 4, indicating that frame-1 contains 4 bytes. Similarly, frame-2 and frame-3 have byte count values 4 and 8, respectively, which describe the size of the frame.
  • But the problem here is that the bytes of the message can get flipped during transmission, which can cause an error. In Figure-4.b, the byte count of 4 becomes 6 due to one-bit reversal, so the receiver will be unable to detect the correct start of the frame.
  • Furthermore, sending an acknowledgment to the sender will also not work, as the receiver will not know how many bytes to skip to initiate retransmission. Therefore the byte count method is rarely used.

Flag Bytes with Byte Stuffing & Bit Stuffing

Flag bytes with byte stuffing and flag bytes with bit stuffing are also important methods of framing, which add a flag byte to the frame.

Flag Bytes with Byte Stuffing: This method uses a flag byte to indicate the start and end of the frame.

The figure below explains the flag bytes with byte stuffing.

flag bytes with byte stuffing
  • As you can see in Figure-5.a, two flags are used in the frame. The start flag describes the start of the frame, and the end flag describes the end of the current frame and the start of the next frame.
  • If the receiver loses synchronization between communications, it can know the current frame by looking at the two flags.
  • But there is still a problem with this method. If the flag bytes are 8 bytes (111111111) and the flag bytes are also in the data, an interrupt will occur in the frame. So, to solve this problem, we can add an escape byte (ESC) before the flag bytes, as shown in Figure-5.b.
  • When the data link layer receives the frame, it removes the ESC bytes from the frame and sends them to the network layer, this is known as byte stuffing.
  • Also, if the data contains ESC, we will add another ESC byte to prevent interference, as you can see some examples of byte stuffing in Figure-5.b above.

Flag Bytes with Bit Stuffing: In this method, framing is done with bits instead of bytes. The flag byte starts and ends with a special sequence of bits which is 01111110 in a frame. A well-known example of this method is USB (Universal Serial Bus). The physical layer maintains the synchronization of bits using this method.

The figure below explains the flag bytes with bit stuffing.

flag bytes with bit stuffing
  • In this method, when there are five consecutive 1’s in the data of the sender’s data link layer, then the data link layer automatically appends the bit ‘0’ after five consecutive 1’s, as shown in the figure.
  • As you can see in the above figure the sender is sending a stream of bits to the receiver. In the middle of the communication, the data link layer will add a bit ‘0’ after five consecutive 1’s to the message.
  • When the receiver will receive the stream of bits, it sees the 0 bit followed by five consecutive 1’s, so it will remove the bit ‘0’ automatically.
  • A receiver can clearly identify the start and end of the frame using the bit stuffing method.

Physical Layer Coding Violations

In this method, the message is encoded by the encoding method in such a way that both the sender and receiver can recognize it.

  • This method provides some reserved signals that indicate the start and end of the frame. We are using “coding violation” to delimit the frame of the data link layer.
  • We apply a reserved signal to the original data sent by the sender so that there is no problem on the receiver side to identify the data.
  • High-High (11) and Low-Low (00) are error codes used as escapes to differentiate data link layer frames.

Key Points to Remember

Here is the list of key points we need to remember about “Framing in Data Link Layer”.

  • The data link layer communicates with the network layer and receives IP packets from it. After receiving the packets, the data link layer converts them into frames and sends them to the physical layer.
  • The frame consists of three parts, the header, data, and trailer. The frame structure and size vary according to the protocol being used.
  • Frame start, addressing, type, and control are the fields of the header. Error detection and frame stop are the fields of the trailer.
  • There are two types of frames as follows:
    1. Fixed-Size Framing
    2. Variable-Size Framing
  • Four methods are used for dividing the frames. They are as follows:
    1. Byte Count
    2. Flag Bytes with Byte Stuffing
    3. Flag Bits with Bit Stuffing
    4. Physical Layer Coding Violations.
  • In the byte count method, when the frame reaches the receiver, the receiver checks the byte count and based on that, it knows the number of bytes in the frame and the start and end of the frame.
  • In flag bytes with byte stuffing, the start flag describes the start of the frame, and the end flag describes the end of the current frame and the start of the next frame.
  • In flag bytes with bit stuffing, framing is done with bits instead of bytes. The flag byte starts and ends with a special sequence of bits which is 01111110 in a frame.
  • In physical layer coding violations, High-High (11) and Low-Low (00) are error codes used as escapes to differentiate data link layer frames.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.