Data Link Layer
Data Link Layer
Physical addressing.
• If frames are to be distributed to different systems on
the network, the data link layer adds a header to the
frame to define the sender and/or receiver of the frame.
• If the frame is intended for a system outside the
sender‘s network, the receiver address is the address of
the device that connects the network to the next one.
Framing
• The data link layer divides the stream of bits
received from the network layer into manageable
data units called frames.
Synchronization
• When data frames are sent on the link, both machines
Flow control.
• 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.
Error control
• The data link layer adds reliability to the physical layer
by adding mechanisms to detect and retransmit
damaged or lost frames.
o It also uses a mechanism to recognize duplicate
frames.
o Error control is normally achieved through a trailer
added to the end of the frame.
Sunday, June 8, 2025 9
Contd.
Access control
• 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.
The data link layer, needs to pack bits into frames, so that
each frame is distinguishable from another.
Framing separates a message from one source to a
destination, by adding a sender address and a destination
address.
The destination address defines where the packet is to go;
the sender address helps the recipient acknowledge the
receipt.
NB: Addressing here is about the next node in the LAN
Sunday, June 8, 2025 12
Contd.
1. Flag field:
an 8-bit sequence
identifies both the beginning and the end of a frame
serves as a synchronization pattern for the receiver.
2. Data filed:
contains the user's data from the net-work layer.
Its length can vary from one network to another.
Sunday, June 8, 2025 Page 14
Layer 2 frame structure
Header Trailer
Start
Address Type/ FCS Stop Frame
Frame Data
Length (Flag)
(Flag)
3. FCS field:
The frame check sequence (FCS) is the error detection field.
It can contain either a 2- or 4-byte ITU-T CRC.
3. Address field:
contains the address of the secondary station.
If a primary station created the frame, it contains a to
address.
If a secondary creates the frame, it contains a from address.
An address field can be 1 byte or several bytes long,
depending on the needs of the network
Sunday, June 8, 2025 Page 15
Error Detection and Correction
• Error Detection
• Error Correction
1 0 1 1 0 0 1 1 => 1 0 1 0 0 1 1 1
Burst error
1 0 1 1 0 0 1 1 => 1 1 0 0 0 1 1 1
Dealing With Errors
uncorrupted.
• Error detection
• Error correction
Error Detecting Techniques
The most popular Error Detecting Techniques are:
• Checksum
The parity bit is calculated for each column and sent along
with the data
Step 1:the 1st data block in the 1st row ,2nd data block 2nd row ….
D1 1 1 1 0 0 1 1 1
D2 1 1 0 1 1 1 0 1
D3 0 0 1 1 1 0 0 1
D4 1 0 1 0 1 0 0 1
LRC :Example
Step 2: Find LRC
In the receiver side, calculate LRC and compare it with senders LRC
Hamming Distance
The Hamming distance between two bit patterns is the
number of dissimilar bits.
It measures the minimum number of substitutions
required to change one string into the other, or the
number of errors that transformed one string into the
other.
Tip: XOR bits and count number of 1s
It would take two errors in the wrong place to turn an ‘A’ into a
‘B’.
10000100
00100100
11100010
10011001
_____________
1000100011
Checksum: Example
Sender
Step 3: sum the carry Step 4 : 1’s Complement
10000100 00100101
_____________
00100100 11011010
11100010 Step 5 : append the checksum
and send
10011001
11011010
_____________
00100011 10011001
10 11100010
_____________ 00100100
00100101 10000100
Checksum: Example
Receiver
Step 1: collect all data blocks Step 2: sum all the data blocks and
checksum
11011010
11011010
10011001 10011001
11100010 11100010
00100100
00100100 10000100
10000100 _______
1011111101
sum the carry
=11111101
10
Step 3 : accept if the result is all _______
1’s else reject 11111111
Cyclic Redundancy Code (CRC)
A far more effective way of detecting errors in a block of data is
to use a Cyclic Redundancy Code.
In CRC, a number is mathematically calculated for a packet by
its source computer, and then recalculated by the destination
computer.
If the original and recalculated versions at the destination
computer differ, the packet is corrupt and needs to be resent or
ignored.
Sunday, June 8, 2025 40
CRC
Sender
Find the length of the divisor ‘L’
Append ‘L-1’ bits to the original message
Perform binary division operation
Remainder of the division=CRC
A B A XOR B
Note: 1 1 0
1 0 1
o The CRC must be of L-1 bits 0 1 1
0 0 0
CRC
Flow Control
tells the sender how much data it can transmit before it must
wait for an acknowledgment from the receiver.
If the buffer begins to fill up, the receiver must be able to tell the
sender to halt transmission until it is once again able to receive.
Stop-and-wait
Sliding Window
Stop-and-Wait
This flow control mechanism forces the sender after
transmitting a data frame to stop and wait until the
acknowledgement of the data-frame sent is received.
Stop-and-Wait
Advantage:
• its simplicity
Disadvantage:
• Poor performance
Stop-and-Wait : Problems
1. Problems due to lost data
o Sender waits ack for infinite amount of time
Number of frames to be
sent is based on
window size
• Go-Back-N ARQ
The set of rules that defines how the computer puts data
onto the network cable and takes data from the cable is
called an access method.
Once data is moving on the network, access methods help
to regulate the flow of network traffic.
Controlled-access Channelization
Random access protocols
protocols Protocols
Token
CSMA/CD CDMA
passing
CSMA/CA
Pure ALOHA
wait if busy and transmit only when the media becomes idle
again (not transmission after a triggered timer expire)
other stations.
Each mini slot belongs to a station. When a station needs to send a data
frame, it makes a reservation in its own minislot.
The stations that have made reservations can send their data frames after
the reservation frame.
Sunday, June 8, 2025 72
Contd.
The following figure shows a situation with five stations and a
five-minislot reservation frame.
But how is the right to access the channel passed from one station to
another?
a special packet called a token circulates through the ring.
The possession of the token gives the station the right to access the
channel and send its data.
When a station has some data to send, it waits until it receives the
token from its predecessor. It then holds the token and sends its data.
When the station has no more data to send, it releases the token,
passing it to the next logical station in the ring.
The station cannot send data until it receives the token again in the next
round.
Sunday, June 8, 2025 77
Access methods summary
Demand
Feature/function CSMA/CD CSMA/CA Token passing
priority
Type of Broadcast
Broadcast based Token based Hub based
communication based
Contention
Type of access Non-
(collisions may Contention Contention
method contention
occur)
Token Ring
Type of Network Ethernet LocalTalk 100VG-AnyLAN
ARCnet