Chapter 03 Data Link Layer
Chapter 03 Data Link Layer
Chapter 3
1. Introduction
The Data Link Layer is the second layer in the OSI model, above the Physical Layer, which
ensures that the error free data is transferred between the adjacent nodes in the network. It
breaks the datagram passed down by above layers and converts them into frames ready for
transfer.
This layer is responsible for achieving reliable, efficient communication between two adjacent
machines which are directly connected by a communication channel.
Hence, it is a very important layer and takes the responsibility of transmitting data from one
node in the network to the next.
1/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
If the rate at which the data are absorbed by the receiver is less than the rate at which data
are produced in the sender, the data link layer imposes a flow control mechanism to avoid
overwhelming the receiver.
The data link layer also adds reliability to the physical layer by adding mechanisms to detect
and retransmit damaged, duplicate, or lost frames.
When two or more devices are connected to the same link, data link layer protocols are
necessary to determine which device has control over the link at any given time.
3. Framing
One of the important functions performed by the data link layer is framing. The sending data
link layer takes a packet from the network layer and puts it into frames for transmission. The
frame contains a frame header, a payload field for storing the packet and a frame trailer.
In order to identify the start and end of a frame, it must have delimiters. Four commonly use
methods for framing are:
Character Count
Flag bytes with byte stuffing
Starting and Ending flags with bit stuffing
Physical Layer Coding Violations
One problem with this method is that a transmission error can modify the count value. If this
happens, there is no way of telling where the next frame starts or ends.
Even if the receiver detects a transmission error, the receiver cannot ask for retransmission
of a specific frame since it does not know which frame had the error. Thus, the entire data
need to be retransmitted.
For example, if the count in the second frame gets modified from 8 to 7, the length of the
next frame will be interpreted as 1.
Flag bytes
However, a problem occurs when the flag byte's binary code occurs as a part of the data
itself. The receiver will mistakenly interpret it as a frame delimiter, this problem can be
solved using byte stuffing or character stuffing.
Here, a special byte called Escape byte is inserted or stuffed before each accidental flag
byte in the data. The receiving data link layer removes the escape byte from the frame. In
case an escape byte occurs in the data, it is also preceded by an inserted escape byte.
3/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
The problem with this method is that it allows only 8 bit characters and cannot be used for
arbitrary sized characters.
Character stuffing
4. Error Control
Because of Attenuation, distortion, noise and interferences, errors during transmission are
inevitable, leading to corruption transmitted bits.
The data link layer has to ensure that the frames are sent and received properly at the
receiving end. It has to take into consideration transmission errors.
One way to deal with errors is to include enough redundant information along with the data
so that receiver can deduce what the transmitted data must have been (Error correcting
codes).
The other strategy is to include only enough redundant information so that the receiver can
deduce that an error has occurred but not which error, and request a retransmission (Error-
detecting codes).
5/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Example:
6/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Performance:
- If two bits in one data unit are damaged and two bits in exactly same position in another
data unit are also damaged, The 2-D Parity check checker will not detect an error.
- For example, if two data units: 11001100 and 10101100. If first and second from last
bits in each of them is changed, making the data units as 01001110 and 00101110, the
error cannot be detected by 2-D Parity check.
4.1.3. Checksum
In checksum error detection scheme, the data is divided into k segments each of m bits.
In the sender’s end the segments are added using 1’s complement arithmetic to get the sum.
The sum is complemented to get the checksum. The checksum segment is sent along with
the data segments.
7/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
8/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
where C1, C2, and C3 are check bits and D1 to D4 are data bits.
The check bits are calculated such that the check bit along with some data bits has even
(or odd) parity.
- C1 is calculated from bit position 1, 3, 5, 7, 9, i.e., position numbers having bit l in their
LSB (Least Significant Bit).
- C2 is calculated from 2, 3, 6, 7, 10, i.e., having bit 1 in the second place from LSB.
- C3 is calculated from 4, 5, 6, 7, ... , i.e., having bit l in the third place from LSB.
Example: Calculate the Hamming bits for data message 1001.
- Here, m= 4. Thus, r = 3, since (m + r + 1) <= 2r i.e. 4 + 3+1 <=23.
9/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
- When the codeword arrives at the receiver, it calculates each check bit.
- If the parity is correct, it accepts the codeword.
- If it is incorrect, it adds the positions of the wrong checkbits to give the position
of the erroneous bit.
- For example, if the message arrives as 0011011:
10/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
6. The transmitting hardware computes the checksum and adds it to the data. The data link
layer need not worry about it.
7. Initially the receiver has nothing to do. It is just waiting for something to happen. Events
could be Frame Arrival, Error or Time-Out.
8. When a frame arrives, the hardware computes the checksum. If there is no error, the data
link layer is informed. It then takes the frame, inspects the header and if it is correct, passes
only the packet portion to the network layer but not the header.
These protocols are classified as follows:
For noiseless channel:
1. Simplex
2. Stop-and-wait
For noisy channel:
1. Stop-and-wait ARQ
2. Go back n ARQ
3. Selective repeat ARQ
5.1. Simplex Protocol
This is the simplest protocol, thoroughly unrealistic, here the assumptions made are:
1. Data transmission is simplex, i.e., in one direction only.
2. Both the transmitting and receiving network layers are always ready.
3. Processing time can be ignored.
4. Infinite buffer space is available.
5. The communication channel is ideal, i.e., it never loses or damages frames.
In this protocol, there are two distinct procedures:
1. A sender, which runs in the data link layer of the source machine.
2. A receiver which runs in the data link layer of the destination machine.
The following diagram shows the communication between the sender and receiver.
[Link]-and-Wait Protocol
In this protocol, we drop the unrealistic assumption that the receiving network layer can
process incoming data infinitely fast.
In such a case, the receiver must have some buffer space to store the frames. However, this
space is limited. If more frames are sent, they will be discarded.
The sender should be prevented from transmitting the next frame before the receiver sends
an acknowledgement for the received frame.
The sender transmits the next frame only after it has received an acknowledgement. Hence it
is called Stop and Wait protocol.
In this case, the communication channel has to be capable of bi-directional information
transfer. But since the data frame and acknowledgement frame do not have to travel
simultaneously, a half-duplex physical channel would be sufficient. The operation of this
protocol is shown below:
13/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
The sizes and limits of the windows need not be the same in the sender and receiver.
All protocols belonging to this category have common features listed below:
- Each outbound frame contains a sequence number ranging from 0 to some maximum
(usually 2n-1, so n bit field can be used).
- At any instant of time, the sender and receiver maintain a sending and receiving
window respectively.
- The communication channel must deliver frames in the order that they were sent.
- The sender's window represents frames sent but not acknowledged. A new frame is
given the next highest sequence number and the upper edge of the window is
advanced by one. When an acknowledgement arrives, the lower edge is advanced by
one.
- Since the sent frames may be lost or damaged, the sender has to store them in
buffers. If the maximum window size is 'n', 'n' buffers are required.
- The receiver's window corresponds to the frames it may accept. Any frame falling
outside the window is discarded. When a frame whose number is equal to the low
edge arrives, an acknowledgement is generated and the window is rotated by one. If
the window size is one, the receiver only accepts frames in order. For larger size
window, this is not true but the network layer is always given data packets in order.
Mechanism:
- The sender initializes sequence-number to 0. The sender builds a frame with
sequence number 0 and sends it. The receiver expects frame 0.
- When the receiver receives a frame, it checks to see if it is a duplicate one. If it is the
expected frame, it is accepted, an acknowledgement is sent and the receiver window
is slide up, i.e., it expects frame 1.
15/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
- The acknowledgement field contains the number of the last frame received without
error. If the sender receives an acknowledgement with correct sequence number, it
slides up its sequence number to 1 and sends a new frame.
- If they do not match, it has to resend the same frame.
- The notation is (Sequence, acknowledgement, packet).
This protocol ensures that no duplicate frames will be delivered to the network layer if
one transmits before the other.
Peculiar Situation:
- If both, A and B send simultaneously, a peculiar situation arises. There will be a
synchronization problem if both A and B transmit simultaneously.
- This causes duplicate frames to be delivered even though there is no transmission
error.
- Figure (b) shows that duplicate frames will be delivered since A and B sends at the
same time.
- The * indicates where a frame is accepted.
16/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Receiver Sliding Window: The receiver only accepts frames in order. Hence, the receiver
window size is 1. It stores the expected frame number in Rn. When the expected frame
arrives, Rn is incremented.
Method:
- The sender sends multiple frames and maintains a timer for each sent frame.
- The receiver sends a separate acknowledgement for each correctly received frame. If it
receives a frame with error, the receiver discards the damaged frame and all subsequent
frames.
- When the sender does not receive an acknowledgement for a frame, the timer times out.
The sender then retransmits all the outstanding frames.
- The Go-back-N strategy is illustrated in the next figure. Here, frame 2 is arrived with an
error, hence it is discarded. The receiver also discards all subsequent frames 3-8. The
sender retransmits frames 2-8.
Go back n strategy
18/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
19/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
[Link] Standards
In 1985, the Computer Society of the IEEE started a project, called Project 802, to set standards
to enable intercommunication among equipment from a variety of manufacturers. Project 802 is
a way of specifying functions of the physical layer and the data link layer of major LAN
protocols.
The relationship of the 802 Standard to the traditional OSI model is shown in the figure bellow.
The IEEE has subdivided the data link layer into two sublayers: logical link control (LLC) and
media access control (MAC). IEEE has also created several physical layer standards for
different LAN protocols.
20/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Data Link Layer: As we mentioned before, the data link layer in the IEEE standard is
divided into two sublayers: LLC and MAC.
Logical Link Control (LLC): In IEEE Project 802, flow control, error control, and part
of the framing duties are collected into one sublayer called the logical link control.
Framing is handled in both the LLC sublayer and the MAC sublayer.
The LLC provides one single data link control protocol for all IEEE LANs. In this way,
the LLC is different from the media access control sublayer MAC, which provides
different protocols for different LANs.
The purpose of the LLC is to provide flow and error control for the upper-layer
protocols that actually demand these services.
Media Access Control (MAC): IEEE Project 802 has created a sublayer called media
access control that defines the specific access method for each LAN. For example, it
defines CSMA/CD as the media access method for Ethernet LANs and the token
passing method for Token Ring and Token Bus LANs. Part of the framing function is
also handled by the MAC layer.
In contrast to the LLC sublayer, the MAC sublayer contains a number of distinct
modules; each defines the access method and the framing format specific to the
corresponding LAN protocol.
Physical Layer: The physical layer is dependent on the implementation and type of
physical media used. IEEE defines detailed specifications for each LAN implementation.
For example, although there is only one MAC sublayer for Standard Ethernet, there is a
different physical layer specifications for each Ethernet implementations.
[Link] ETHERNET
The original Ethernet was created in 1976 at Xerox’s Palo Alto Research Center (PARC). Since
then, it has gone through four generations. We briefly discuss the Standard (or traditional)
Ethernet in this section.
21/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Preamble. The first field of the 802.3 frame contains 7 bytes (56 bits) of alternating
0s and 1s that alerts the receiving system to the coming frame and enables it to
synchronize its input timing. The 56-bit pattern allows the stations to miss some bits
at the beginning of the frame. The preamble is actually added at the physical layer
and is not (formally) part of the frame.
Start frame delimiter (SFD). The second field (l byte: 10101011) signals the
beginning of the frame. The SFD warns the station or stations that this is the last
chance for synchronization. The last 2 bits is 11 and alerts the receiver that the next
field is the destination address.
Destination address (DA). The DA field is 6 bytes and contains the physical
address of the destination station or stations to receive the packet.
Source address (SA). The SA field is also 6 bytes and contains the physical address
of the sender of the packet.
Length or type. This field is defined as a type field or length field. The original
Ethernet used this field as the type field to define the upper-layer protocol using the
22/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
MAC frame. The IEEE standard used it as the length field to define the number of
bytes in the data field. Both uses are common today.
Data. This field carries data encapsulated from the upper-layer protocols. It is a
minimum of 46 and a maximum of 1500 bytes.
CRC. The last field contains error detection information, in this case a CRC-32.
Minimum and maximum lengths : An Ethernet frame needs to have a minimum
length of 512 bits or 64 bytes. Part of this length is the header and the trailer. If we
count 18 bytes of header and trailer (6 bytes of source address, 6 bytes of destination
address, 2 bytes of length or type, and 4 bytes of CRC), then the minimum length of
data from the upper layer is 64 – 18 = 46 bytes. If the upper-layer packet is less than 46
bytes, padding is added to make up the difference.
The standard defines the maximum length of a frame (without preamble and SFD field)
as 1518 bytes. If we subtract the 18 bytes of header and trailer, the maximum length of
the payload is 1500 bytes.
Minimum Frame length:: 64 bytes (512 bits)
Maximum Frame length:: 1518 bytes (12,144 bits)
6.2.2. Addressing
Each station on an Ethernet network (such as a PC, workstation, or printer) has its own
network interface card (NIC). The NIC fits inside the station and provides the station with a
6-byte physical address (MAC address). Primarily specified as a unique identifier during
device manufacturing, the MAC address is often found on a device's NIC. The Ethernet
address (MAC address) is 6 bytes (48 bits), nonnally written in hexadecimal notation, with a
colon between the bytes.
23/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Switched Ethernet
26/28
Module : Computer Networks 2nd year Computer Science Abdelhafid Boussouf University Center, Mila Year : 2024/2025
Carrier sense multiple access with collision detection (CSMA/CD) is a Media Access
Control method in which:
- A carrier sensing scheme is used.
- A transmitting data station that detects another signal while transmitting a frame, stops
transmitting that frame, transmits a jam signal, and then waits for a random time
interval before trying to resend the frame.
- CSMA/CD is a modification of pure carrier sense multiple access (CSMA). CSMA/CD
is used to improve CSMA performance by terminating transmission as soon as a
collision is detected, thus shortening the time required before a retry can be attempted.
- The jam signal is a signal that carries a 32-bit binary pattern sent by a data station to
inform the other stations that they must not transmit.
CSMA/CD process
28/28