Data Link Layer Protocol Tutorial With Example

In the previous tutorial, we have studied about the physical layer and the various functions performed at this layer. We will now move ahead to the next layer in ISO/ OSI Stack i.e. the Data Link Layer.

Communication at the data link layer protocol is node-to-node. The data link layer provides services to the network layer. It receives services from the physical layer. The scope of data link layer is node-to-node. When a packet is travelling in the internet, the data link layer of the node is responsible for delivering a datagram to the next node in the path. We encapsulate and decapsulate at each node because IP address information is present in packet, which is encapsulated by frame.

The main responsibilities of Data Link layer are:
  • Flow Control: The layer looks after the flow control during the communication using methods like stop and wait, Go back N and Selective repeat. These methods have been discussed in greater detail in the previous tutorials.
  • Error Control: The errors are corrected and detected at the data link layer during a communication. Methods like CRC, Checksum, parity check, hamming distance are used for error control. These methods have also been discussed in greater detail in the previous tutorials on error control methods.
  • Access Control: The Data link layer is also responsible for access control of the link. Methods like CSMA/CD, token passing etc. used for access control have also been discussed previously.
  • Physical Addressing: The technique of translating the virtual address into physical address is done at the data link layer.
  • Framing: The term frame refers to a small chunk of data used in a specific network. The data link layer groups raw data bits to / from the physical layer into discrete frames with error correction / detection code-bits added.
    Framing Methods
    1. Character count.
    2. Starting and ending characters, with character stuffing.
    3. Starting and ending flags with bit-stuffing.

Let us try to understand framing and it’s methods in more detail.
The Data link layer Protocol translates the physical layer’s raw bit stream into discrete units (messages) called frames. How can frame be transmitted so that the receiver can detect frame boundaries? That is, how can the receiver recognise the start and end of a frame? These can be achieved in multiple ways:

1. Character Count

Make the first field in the frame’s header be the length of the frame. That way the receiver knows how big the current frame is and can determine where the frame ends.

Disadvantage:
Receiver loses synchronization when bit becomes garbled. If the bits in the count become corrupted during transmission, the receiver will think that the frame contains fewer (or more) bits that it actually does. Although checksum will detect the frames are incorrect, the receiver will have difficult re-synchronizing to the start of a new frame. This technique is not used anymore, since better techniques are available.

Tutorialwing Computer Networks Data Link Layer Character Count Example of Data Link Layer

Character Count Example

2. Character Stuffing

Each frame starts with the ASCII character sequence DLE (Data Link Escape) and STX (Start of Text). When binary data is transmitted where (DLE STX or DLE ETX) can occur in data, character stuffing is used (additional DLE is inserted in the data). It is limited to 8-bit character and ASCII.

Network layer Data at the sender:

Tutorialwing Computer Networks - Data Link Layer Character Stuffing - Sender 's Network layer Data

Sender ‘s Network layer Data

Data after character stuffing by the Data Link Layer at the sender:

Tutorialwing Computer Networks - Data After Character Stuffing

Data After Character Stuffing

Network Layer Data at the receiver:

Tutorialwing Computer Networks Network Layer Data At receiver

Network Layer Data At receiver

3. Bit Oriented using Start / End Flags (Bit Stuffing)

  • Each frame begins and ends with 01111110 .
  • After each five consecutive ones in a data, zero is stuffed. Stuffed zero bits are removed by the data link layer at the receiving end.
  • The receiver will re-synchronise quickly with the sender as to where frames begin and end, even when bits in the frame get garbled.
Example

The original Data:

0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0

Data appearing on the line after bit stuffing:

0 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 1 0 

Data received after destuffing:

0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0
Disadvantage

The main disadvantage with bit stuffing is the insertion of additional bits into the data stream which leads to wastage of bandwidth. How much expansion? The precise amount depends on the frequency in which the reserved patterns appear as user data.

Now that we are clear with the concepts, let us practice some question based on Data Link Layer and its responsibilities.

Exercises on Data Link Layer

1. Answer below question –

What is the maximum overhead in the byte stuffing algorithm?

2. Answer below question –

Imagine one of your teachers, has pointed out that it is wasteful to end each frame with a flag byte 
and then begin the next one with a second flag byte. 
One flag byte could do the job as well, and a byte saved is a byte earned. 
Justify if he is correct or not.

3. Answer below question –

The following character encoding is used in a data link protocol: 
   A: 01000111
   B: 11100011
   FLAG: 01111110
   ESC: 11100000

Show the bit sequence transmitted (in binary) for the four-character 
frame A B ESC FLAG when each of the following frame method is used.
   a) Byte count
   b) Flag bytes with byte stuffing
   c) Starting and ending flag bytes with bit stuffing

That’s end of tutorial on Data Link Layer Protocol.

Leave a Reply