Data Link Layer

In this tutorial, you will learn the basic concepts of the data link layer. After reading this tutorial, you will be able to understand why the data link layer is used in computer networks, how it works on the network, and what are the responsibilities of the data link layer.

Contents:

  1. Purpose of Data Link Layer
  2. Responsibilities of Data Link Layer
  3. Framing and Addressing
  4. Flow Control and Error Control
  5. Media Access Control
  6. Sub Layers of Data Link Layer
  7. Data Encapsulation on Data Link Layer
  8. Protocols of Data Link Layer

Purpose of Data Link Layer

The data link layer is one of the layers of the OSI reference model. It is also known as layer-2 of the OSI model. Basically, the main purpose of the data link layer is to provide NIC-to-NIC or hop-to-hop communication. It also describes how access to the network is controlled using access control mechanisms.

  • The data link layer communicates with the network layer and receives packets from it. When the data link layer receives packets from the network layer, it adds an Ethernet header and Ethernet trailer to the packet, which makes the frame. Then the data link layer sends the frame to the physical layer.
  • The switch is the most common device used at the data link layer. Switch transmits frames from sender to receiver. For that, the switch uses the MAC addresses of the sender and receiver.

Responsibilities of Data Link Layer

The main responsibility of the data link layer is to prepare data for the physical layer. For that, it converts the received packets from the network layer into frames and sends them to the physical layer. But the data link layer also has other responsibilities that are necessary for communication.

The responsibilities of the data link layer are described as follows:

advertisement
advertisement
  1. Framing
  2. Addressing
  3. Flow and Error control
  4. Media access control

Framing and Addressing

Framing and Addressing are the important responsibilities of the data link layer. Because frames are sent using addresses and become responsible for communication between the data link layer and the physical layer.

Framing: The data link layer provides services to the network layer and the physical layer. It communicates with the network layer and receives IPv4 or IPv6 packets from the network layer. The data link layer then converts the packet into a frame that reaches the physical layer.

  • The frame consists of the header, payload field (actual data), and trailer. Frames are transmitted using the MAC addresses of the devices.
  • MAC addresses are printed on the device NIC (Network Interface Card).
  • The structure of the frame and the information stored in the header and trailer varies according to the protocol used in the data link layer.

The diagram below describes the framing mechanism in the Data Link layer.

framing mechanism in the Data Link layer

The above diagram shows that the data link layer receives the packets from the network layer. It also shows that after receiving the packet from the network layer, it adds the header and trailer, which makes up the frame, then the frame is sent to the physical layer.

Addressing: The data link layer uses physical addresses to transmit frames from sender to receiver. Generally, physical addresses are also known as MAC (Media Access Control) addresses.

  • MAC is a 48-bit number printed on the network interface card of the device. MAC address is an identifier of the device.
  • MAC address is divided into two parts that are Organization Unique Identifier and Unique Part. These two parts combine to form a MAC address that is unique to a device.
  • Physical addresses are used for data encapsulation and media access control.
  • The data link layer combines the MAC address of the sender and receiver in the frame with the IP address.
  • When the sender and receiver are on the same network, instead of using IP, the MAC addresses of the sender and receiver are used to transmit the frame.
  • Basically, when frames are transmitted from intermediary devices, the intermediary devices de-encapsulate the frames to understand the IP address and find the destination host.

Flow Control and Error Control

Managing the flow of data and detecting errors in frames are also important responsibilities of the data link layer. By controlling the flow and error of data, the data link layer provides reliable communication between devices. In the data link layer, flow control and error control take place between network devices.

  • Flow control: Flow control is a mechanism to control the flow of data when the receiver starts receiving more data than its capacity.
    • For example, the sender is sending the frame at the speed of 100 Mbps, and the receiver is capable of receiving the frame at the speed of 10 Mbps. So the receiver will send an acknowledgment to the sender to reduce the flow of data
    • When the sender receives the acknowledgment from the receiver, the sender will decrease the flow of data and starts transmitting data at the speed of 10 Mbps.
    • The receiving device should be able to send an acknowledgment when an increase in the flow of data.
    • To overcome the problem of flow control, each device has a block of memory known as a buffer. Buffer stores data until they are used for processing.
  • Error control: Error control provides error detection and error correction mechanisms. The frame has a trailer field that contains an error detection method. The trailer is used to determine whether the frame has been successfully delivered to the receiver without error.
    • When an error occurs in a frame and frames are lost in the middle of communication, the receiver sends an acknowledgment to the sender and asks to resend the frame.
    • The Automatic Repeat Request (ARQ) process is used in case of any error during transmission. If an error is detected during transmission, the ARQ process resends the frame.

advertisement

Media Access Control

Multiple devices simultaneously attempt to access a communication channel on a network for communication purposes, but which devices will gain access to the channel is decided by the access control mechanism.

  • There will be no need to use access control if the channel has a dedicated path between devices for communication. But when communication over a communication channel does not have a dedicated path between devices, then access to the channel should be prioritized.
  • The media access control layer of the data link layer is responsible for access control.
  • Media access control ensures that there will be no conflict between communication devices on a channel.
  • Typically, access control is used when devices are connected and use a common link known as a multipoint link.

Sub Layers of Data Link Layer

There are two types of sub-layers in the data link layer as follows:

  1. Logical Link Control (LLC)
  2. Media Access Control (MAC)
  • Logical Link Control (LLC): The LLC of the data link layer communicates with the upper layer and the lower layer. On the upper layer, it communicates with the networking software, whereas in the lower layer, it communicates with the hardware of the device.
    • LLC receives packets from the network layer and stores the information in a frame using a protocol. The LLC also identifies which network layer protocol is used for the frame.
    • When the LLC receives packets from the network layer, it adds layer-2 (data link layer) control information to send packets from the sender to the receiver.
  • Media Access Control (MAC): Basically, MAC is responsible for data encapsulation and access control.
    • The MAC sub-layer of the data link layer manages the NIC information, which is responsible for sending and receiving frames over guided or unguided media.
    • The MAC sub-layer provides delimiters that identify fields of the frame. It ensures whether the frame sent by the sender is correctly received by the receiver.
    • When MAC receives the packet, it starts the data encapsulation process. It adds the header and trailer to the packet and makes the frame. The trailer is used to detect transmission errors. After that, it provides the sender and receiver address to transmit the frame from sender to receiver.
    • The MAC layer allows multiple devices to communicate over a shared channel that operates on half-duplex, as full-duplex mode communication does not require an access control mechanism.

The diagram below describes the two sub-layers of the data link layer.

sub-layers of the data link layer

The above diagram shows two sub-layers of the data link layer that are Logical Link Control and Media Access Control. Both provide standards for communication over a communication channel.

advertisement

Data Encapsulation on Data Link Layer

Now we know that the data link layer receives packets from the network layer and converts them into frames. But how does it encapsulate the data and transmit data to the network? Let’s understand it.

The diagram below explains the data encapsulation process on a network using data link layer services.

data encapsulation process on a network using data link layer services
  • As you can see in the above diagram that the data link layer communicates with the network layer and receives packets. The data link layer adds the Ethernet LAN header and LAN trailer to the packet, adding the header and trailer to the data is known as the encapsulation process.
  • Typically, the header and trailer associated with the packet are the LAN header and LAN trailer. Now PC-1 will send the frame to the router-1, as shown in the diagram.
  • When Router-1 receives the frame, it de-encapsulates the frame. Because the frame consists of the LAN header and trailer, and the router is connected to the WAN network. So, Router-1 will de-encapsulate the frame and re-encapsulate the frame by adding the WAN header and the WAN trailer.
  • Router-1 will send the newly created frame to the appropriate device for further processing. The encapsulation and de-encapsulation process will be repeated until the frame is received by the receiver.

Protocols of Data Link Layer

Generally, a protocol is a set of rules that govern the communication between devices on a network. Protocols are essential for successful communication because before communication occurs, the sender and receiver agree on rules.

  • Network devices operating at the data link layer act as a node when implementing the data link layer protocol.
  • Protocols at the data link layer are dependent on the logical topology and physical media.
  • Ethernet, 802.11 Wireless, High-Level Data Link Control (HDLC), Frame Relay, Point-to-Point Protocol, and X.25 are the protocols of the data link layer.
  • Different data link layer protocols are used for LAN and WAN. According to the protocol used at the data link layer, the bandwidth of the network varies.
  • The protocol used depends on the technology that is used to implement the network topology.

The diagram below describes the use of different protocols on different links in the network.

different protocols on different links in the network
  • As you can see in the diagram above that PC-1 is using Ethernet protocol to send a frame to Router-1 via Switch-1. Then Router-1 uses the 802.11 wireless frame protocol to send the frame to Wireless-Router-2.
  • As soon as wireless router-2 receives the frame, it will send the frame to router-3 using a point-to-point protocol. Router-3 is communicating with Router-4 using HDLC protocol, so it will send a frame to Router-4 using HDLC protocol.
  • Finally, PC-2 will receive the frame from Router-4 via Switch-2 using the Ethernet protocol.

Key Points to Remember

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

  • The main purpose of the data link layer is to provide NIC-to-NIC or hop-to-hop communication. It describes how access to the network is controlled using access control mechanisms.
  • The responsibilities of the data link layer are described as follows:
    1. Framing
    2. Addressing
    3. Flow and Error control
    4. Media access control
  • Data Link Layer communicates with the network layer and receives IPv4 or IPv6 packets from the network layer. The data link layer then converts the packet into a frame that reaches the physical layer.
  • The data link layer uses physical (MAC) addresses to transmit frames from sender to receiver. The MAC address is divided into two parts that are “organization unique identifier” and the “unique part”.
  • Multiple devices simultaneously attempt to access a communication channel on a network for communication purposes, but which devices will gain access to the channel is decided by the access control mechanism.
  • In the data link layer, flow control and error control take place between network devices.
  • There are two types of sub-layers in the data link layer and they are:
    1. Logical Link Control (LLC)
    2. Media Access Control (MAC)
  • Ethernet, 802.11 Wireless, High-Level Data Link Control (HDLC), Frame Relay, Point-to-Point Protocol, and X.25 are the protocols of the data link layer.

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.