To provide service to the network layer, the data link layer must use the service provided to it by the physical layer.
As seen in the image above, the data link layer uses the services of the physical layer.
In following steps data link layer received bits from the physical layer.
- Physical layer accept raw bit stream and transfer to the destination.
- Channel may be noisy whether it is Wireless or wired medium.
- Physical layer will add some redundancy to its signals to reduce the bit error rate to a tolerable level.
- When data link layer received bit stream, it is not guaranteed to be error free.
- It is up to the data link layer to detect error and, if necessary, correct errors.
Now its necessary to know about frame in data link layer.
A frame contains (see the image below),
- A frame header contains control information
- A payload field for holding the packet
- A frame trailer
Data transmitted on a physical link are packed in units of frames.
Control information in frame header means the destination address, the upper-layer protocol in use, the error detection code, etc.
How data link layer know there is error in bit stream received?
- Data link layer to break up the bit stream into discrete frames, and for each frame computes a short token called a checksum.
- When frame is transmitted checksum is included in it.
- When a frame arrives at the destination, the checksum is recomputed.
- If the newly computed checksum is different from the one contained in the frame, the data link layer knows that an error has occurred and takes steps to deal with it
This was an usual approach which we discuss above.
Since data are transmitted as raw bit streams in the physical layer, the link layer must identify the beginning and the end of each frame when receiving a bit stream. On the other hand, it must also turn frames into a raw bit stream for physical transmission. This function is called framing.
For this there are some framing methods too.
- Byte count.
- Flag bytes with byte stuffing.
- Flag bits with bit stuffing.
- Physical layer coding violations.
1. Byte count framing method:
The byte count framing method uses a field in the header to specify the number of bytes in the frame.
- Data link layer at sender sends the byte count.
- Data link layer at receiver counts the byte count. send by sender.
- If there is difference between bytes counts of sender and receiver. There is error in data received.
- Else received data is correct.
- Above points are shown in diagram below.
2. Flag bytes with byte stuffing framing method:
- In this method a flag byte, is used as both the starting and ending of a frame. See in the figure below.
- Two consecutive flag bytes indicate the end of one frame and the start of the next frame.
- If the receiver ever loses synchronization it can just search for two flag bytes to find the end of the current frame and the start of the next frame.
What if accidental unwanted flag bytes occur in the data?
To prevent from wrong flag bytes, escape byte (ESC) is inserted just before each ‘‘accidental’’ flag byte in the data. As shown in the figure below.
The data link layer on the receiving end removes the ESC before giving the data to the network layer.
This technique is called byte stuffing.
What if accidental unwanted ESC occur in the data?
This unwanted ESC is also stuffed with an escape byte (ESC). As shown in the figure below.
3. Flag bits with bit stuffing framing method:
- In this method bit stuffing is used.
- When sender’s data link layer encounters five consecutive 1s in the data, it automatically stuffs a 0 bit.
- At receiver end this stuffed 0 bit automatically deleted. As shown in the figure below.
4. Physical layer coding violations framing method:
- In this method some reserved signals are used to indicate the start and end of frames.
- As they are reserved signals, it is easy to find the start and end of frames.
- Here we are using ‘‘coding violations’’ by putting reserved signals in original data.
Error Control in Data Link Layer:
With positive and negative acknowledgement about a frame.
- If the sender receives a positive acknowledgement about a frame, the frame has received safely.
- A negative acknowledgement means that something has gone wrong and the frame must be transmitted again.
What if frame not received by receiver?
- Here timer concept is used.
- When the sender transmits a frame, it also starts a timer.
- Before expiry of this timer acknowledgement from receiver must reach to the sender.
- In absent of acknowledgement sender will again transmit the frame.
What is acknowledgement sent by receiver not reached to sender?
- In this case may possible sender sent multiple frames.
- To prevent from receiving same frames by receiver sender assign a sequence number to the frame.
- By seeing sequence number receiver identifies that its duplicate frame.
Flow Control in data link layer:
A situation arise when sender wants to transmit frames faster than the receiver can accept them.For example when a slow speed smart phone requests a Web page from very powerful server.Even if the transmission is error free, the receiver phone may be unable to handle the frames as fast as they arrive and will lose some.In such situations two approaches are commonly used:
- Feedback-based flow control
- Rate-based flow control
1. Feedback-based flow control: In this the receiver sends back information to the sender giving it permission to send more data.
2. Rate-based flow control: In this a built-in mechanism is used that limits the rate at which senders may transmit data, without using feedback from the receiver.