Before understanding the framing in data link layer we need to understand some common terminology.
Datagram:
The unit of transmission in the network layer (such as IP). A datagram may be encapsulated in one or more packets passed to the data link layer.
Frame:
The unit of transmission at the data link layer. A frame may include a header and/or a trailer, along with some number of units of data.
Packet:
The basic unit of encapsulation, which is passed across the interface between the network layer and the data link layer. A packet is usually mapped to a frame; the exceptions are when data link layer fragmentation is being performed, or when multiple packets are incorporated into a single frame.
Peer:
The other end of the point-to-point link
Framing is a technique performed by the Data Link layer. Basically, Framing is a point-to-point connection between two computers or devices consists of a wire in which data is transmitted as a stream of bits. However, these bits must be framed into discernible blocks of information.
Framing provides a way for a sender to transmit a set of bits that are meaningful to the receiver. Ethernet, token ring, frame relay, and other data link layer technologies have their own frame structures. Frames have headers that contain information such as error-checking codes.
Parts of a Frame:
There are following parts of a frame-
- Flag − It marks the beginning and end of the frame (flag value will be 7E in HDLC).
- Frame Header − It contains the source and the destination addresses of the frame.
- Payload field − It contains the message to be delivered.
- Trailer − It contains the error detection and error correction bits.
Types of framing:
We can categorize framing in two-part fixed-size framing and variable size framing.
Fixed-size framing:
In which frame size will be fixed. Because the length is fixed so the length of the frame itself acts as a delimiter.
Drawback: It suffers from internal fragmentation if the data size is less than the frame size.
Solution: We can resolve this problem by using padding.
Variable size framing:
The frame length will be not fixed and the size of each frame to be transmitted may be different. So here we need to use some additional techniques to identify the end of one frame and the beginning of the next frame. We can be done in two ways:
1. Length Field:
Here, a length field is used that determines the size of the frame. It is used in Ethernet (IEEE 802.3). The problem with this is that sometimes the length field might get corrupted.
2.End Delimiter:
Here, a pattern is used as a delimiter to determine the size of the frame. Like in HDLC we use 7E as a delimiter which indicates the beginning and end of a frame. In which, if the pattern occurs in the message, then two approaches are used to avoid the situation,
a.) Byte–Stuffing − A byte is stuffed in the message to differentiate from the delimiter. This is also called character-oriented framing.
b. ) Bit–Stuffing − A pattern of bits of arbitrary length is stuffed in the message to differentiate from the delimiter. This is also called bit-oriented framing. Like in HDLC, if there are five consecutive 1s in the stream then bit stuffing used to avoid confusion with data containing 01111110. The transmitter inserts 0 bit after every sequence of five 1s with the exception of flag fields.
Recommended Post
- SSL vs TLS.
- Difference between HDLC and PPP.
- HDLC protocol.
- Transport Layer Security (TLS)
- SSL programming in C.
- Socket programming in C.
- Parse XML response in C without using the library.
- Create Http Get and Post request in C.
- File handling in C.
- I2C Communication protocol.
- Embedded C Interview Questions.
- Pointers in C.
- CAN Protocol Interview Questions.
- Bit-wise interview Questions in C.