Unit 2 - Data Link Layer
Unit 2 - Data Link Layer
Dr.R.U.Anitha
1
Unit - 2
2
Major Topics
3
Data Link Layer
• The data link layer transforms the physical layer, a raw
transmission facility, to a link responsible for node-to-node
(hop-to-hop) communication.
• Specific responsibilities of the data link layer include
framing, addressing, flow control, error control, and media
access control.
4
DATA LINK LAYER FUNCTIONS (SERVICES)
Appropriate for low error rate and real-time traffic. Ex: Ethernet
Guarantee frames are received exactly once and in the right order.
Appropriate over long, unreliable links such as a satellite channel or a long distance
telephone circuit
2. Framing:
Frames are the streams of bits received from the network layer into manageable
data units. This division of stream of bits is done by Data Link Layer.
3. Physical Addressing:
The Data Link layer adds a header to the frame in order to define physical address
5
4. Flow Control:
A receiving node can receive the frames at a faster rate than it can process the frame.
Without flow control, the receiver's buffer can overflow, and frames can get lost. To
overcome this problem, the data link layer uses the flow control to prevent the
sending node on one side of the link from overwhelming the receiving node on
another side of the link. This prevents traffic jam at the receiver side.
5. Error Control:
Error control is achieved by adding a trailer at the end of the frame. Duplication of
frames are also prevented by using this mechanism. Data Link Layers adds
Error detection:
Errors can be introduced by signal attenuation and noise. Data Link Layer protocol
provides a mechanism to detect one or more errors. This is achieved by adding error
detection bits in the frame and then receiving node can perform an error check.
Error correction:
Error correction is similar to the Error detection, except that receiving node not only
6
6. Access Control:
Protocols of this layer determine which of the devices has control over the
link at any given time, when two or more devices are connected to the same
link.
7. Reliable delivery:
Data Link Layer provides a reliable delivery service, i.e., transmits the
mainly provides the reliable delivery service over the links as they have
higher error rates and they can be corrected locally, link at which an error
In a Full-Duplex mode, both the nodes can transmit the data at the same
time. In a Half-Duplex mode, only one node can transmit the data at the
7
DATA LINK LAYER DESIGN ISSUES
Providing a well-defined service interface to the network
layer.
Dealing with transmission errors.
Regulating the flow of data so that slow receivers are not
swamped by fast senders
For this, the data link layer takes the packets it gets from the
network layer and encapsulates them into frames for
transmission. Each frame contains a frame header, a payload
field for holding the packet, and a frame trailer
8
SERVICES PROVIDED TO THE NETWORK LAYER
The function of the data link layer is to provide services to
the network layer.
The principal service is transferring data from the network
layer on the source machine to the network layer on the
destination machine.
The data link layer can be designed to offer various services.
The actual services offered can vary from system to system.
Three reasonable possibilities that are commonly provided
are
1) Unacknowledged Connectionless service
2) Acknowledged Connectionless service 9
1. Byte count.
13
FRAMING – Byte count
The first framing method uses a field in the header to specify the
number of characters in the frame.
When the data link layer at the destination sees the character
count, it knows how many characters follow and hence where the
end of the frame is.
11
The troublewith this algorithm is thatthe count can be
garbled by a 14
FRAMING – Flag bytes with byte stuffing.
Use reserved characters to indicate the start and end of a frame. For instance,
use the two-character sequence DLE STX (Data-Link Escape, Start of TeXt) to
signal the beginning of a frame, and the sequence DLE ETX (End of TeXt) to
flag the frame's end.
The second framing method, Starting and ending character stuffing, gets
around the problem of resynchronization after an error by having each frame
start with the ASCII character sequence DLE STX and end with the sequence
DLE ETX.
Problem: What happens if the two-character sequence DLE ETX
transmitted over the channel would be ``DLE STX A B DLE DLE D E DLE DLE
15
DLE ETX''.
16
FRAMING – Flag bits with bit stuffing
This technique allows data frames to contain an arbitrary number of bits
and allows character codes with an arbitrary number of bits per character.
It works like this.
Each frame begins and ends with a special bit pattern, 01111110 (in fact,
a flag byte).
Whenever the sender's data link layer encounters five consecutive 1s in the
data, it automatically stuffs a 0 bit into the outgoing bit stream.
This bit stuffing is analogous to byte stuffing, in which an escape byte is
stuffed into the outgoing character stream before a flag byte in the data.
When the receiver sees five consecutive incoming 1 bits, followed by a 0
bit, it automatically destuffs (i.e., deletes) the 0 bit
17
BIT STUFFING EXAMPLE
18
PHYSICAL LAYER CODING VIOLATIONS
This Framing Method is used only in those networks in which Encoding on
the Physical Medium contains some redundancy.
Some LANs encode each bit of data by using two Physical Bits
i.e. Manchester coding is Used. Here, Bit 1 is encoded into high-
low(10) pair and Bit 0 is encoded into low-high(01) pair.
The scheme means that every data bit has a transition in the middle,
making it easy for the receiver to locate the bit boundaries. The
combinations high-high and low-low are not used for data but are used for
delimiting frames in some protocols.
19
ERROR CONTROL
Sequence Numbers:
1. Single bit error : It means only one bit of data unit is changed from 1
to 0 or from 0 to 1.
2. Burst error : It means two or more bits in data unit are changed from
1 to 0 from 0 to 1. In burst error, it is not necessary that only
consecutive bits are changed. The length of burst error is measured
from first changed bit to last changed bit
24
ERROR DETECTION VS ERROR CORRECTION
25
Error Correcting Codes
Error Correction codes are used to detect and correct the errors
when data is transmitted from the sender to the receiver.
Error Correction can be handled in two ways:
30
Determining the Parity bits
position.
• We observe from the above figure that the bit position that
includes 1 in the
first position are 1, 3, 5, 7.
• Now, we perform the even-parity check at these bit positions.
• The total number of 1 at these bit positions corresponding to r1
is even, therefore, the value of the r1 bit is 0.
31
Determining the Parity bits
Determining r2 bit:
position
We observe from the above figure that the bit positions that
includes 1 in the
second position are 2, 3, 6, 7. Now, we perform the even-parity
Determining r4 bit:
The r4 bit is calculated by performing a parity check on the
position
• We observe from the above figure that the bit positions that includes 1 in
the
third position are 4, 5, 6, 7.
• Now, we perform the even-parity check at these bit positions.
• The total number of 1 at these bit positions corresponding to r4 is even,
therefore, the value of the r4 bit is 0. 33
Data transferred is given below:
Suppose the 4th bit is changed from 0 to 1 at the receiving end, then parity bits
are recalculated.
R1 bit
The bit positions of the r1 bit are 1,3,5,7
34
• We observe from the above figure that the binary representation of r2
is 1001.
• Now, we perform the even-parity check, the total number of 1s
appearing in the
r2 bit is an even number. Therefore, the value of r2 is 0.
R4 bit
The bit positions of r4 bit are 4,5,6,7.
Error
A condition when the receiver’s information does not matches with the sender’s
information.
During transmission, digital signals suffer from noise that can introduce errors
in the binary bits travelling from sender to receiver. That means a 0 bit may
change to 1 or a 1 bit may change to 0.
Error Detecting Codes
Whenever a message is transmitted, it may get scrambled by noise or data may
get corrupted.
To avoid this, we use error-detecting codes which are additional data added to a
given digital message to help us detect if any error has occurred during
transmission of the message.
Basic approach used for error detection is the use of redundancy bits, where
37
Two-dimensional Parity check
Parity check bits are calculated for each row, which is equivalent
sent along with the data. At the receiving end these are compared
with the parity bits calculated on the received data.
38
Checksum
39
Cyclic redundancy check (CRC)
Unlike checksum scheme, which is based on addition,
43
44
ELEMENTARY DATA LINK
PROTOCOLS
• The protocols are normally implemented in software by
using one of the common programming languages.
1.An Unrestricted Simplex Protocol
2.A Simplex Stop-and-Wait Protocol
3.A Simplex Protocol for a Noisy Channel
45
SIMPLEX PROTOCOL
It is very simple. The sender sends a sequence of frames without
even thinking about the receiver.
Data are transmitted in one direction only.
Both sender & receiver always ready. Processing time can be
ignored.
Infinite buffer space is available. And best of all, the communication
channel between the data link layers never damages or loses
frames.
This thoroughly unrealistic protocol, which we will nickname
‘‘Utopia,’’.
The utopia protocol is unrealistic because it does not handle either
flow control or error correction
46
Stop-and-wait Protocol
• The sender sends one frame and waits for feedback from the
receiver.
• When the ACK arrives, the sender sends the next frame.
• It is Stop-and-Wait Protocol because the sender sends one frame,
stops until it receives confirmation from the receiver (okay to go
ahead), and then sends the next frame.
• It have unidirectional communication for data frames, but auxiliary
ACK frames (simple tokens of acknowledgment) travel from the other
direction.
• It add flow control to our previous protocol.
47
Sliding Window Protocols
1 . Stop-and-Wait Automatic Repeat Request
To detect and correct corrupted frames, we need to add redundancy bits to our
data frame. When the frame arrives at the receiver site, it is checked and if it
receiver.
In the previous protocols, there was no way to identify a frame. The received
The solution is to number the frames. When the receiver receives a data frame
that is out of order, this means that frames were either lost or duplicated
48
Sliding Window Protocols
The lost frames need to be resent in this protocol. If the receiver does not
respond when there is an error, how can the sender know which frame to
resend?
To remedy this problem, the sender keeps a copy of the sent frame.
At the same time, it starts a timer. If the timer expires and there is no ACK
for the sent frame, the frame is resent, the copy is held, and the timer is
restarted.
Since the protocol uses the stop-and-wait mechanism, there is only one
product?
If the system data frames are
50
2. Go-Back-N Automatic Repeat Request
To improve the efficiency of transmission (filling the pipe), multiple
acknowledgment.
acknowledgments arrive.
outstanding frame.
The send window can slide one or more slots when a valid
acknowledgment arrives.
54
Receiver window: variable Rn (receive window, next frame
expected) .
The sequence numbers to the left of the window belong to the
is discarded.
Only a frame with a sequence number matching the value of Rn
a correct
frame is received (and a frame is received only one at a time), the
window
55
Timers
• Although there can be a timer for each frame that is sent, in our
protocol we use only one. The reason is that the timer for the first
outstanding frame always expires first; we send all outstanding
frames when this timer expires.
56
Acknowledgment
The receiver sends a positive acknowledgment if a frame has arrived safe and
If a frame is damaged or is received out of order, the receiver is silent and will
The silence of the receiver causes the timer of the unacknowledged frame at the
sender side to expire. This, in turn, causes the sender to go back and resend all
The receiver does not have to acknowledge each frame received. It can send one
Resending a Frame
When the timer expires, the sender resends all outstanding frames. For example,
suppose the sender has already sent frame 6, but the timer for frame 3 expires.
This means that frame 3 has not been acknowledged; the sender goes back and sends
frames 3,4,5, and 6 again. That is why the protocol is called Go-Back-N ARQ.
57
Below figure is an example(if ack lost ) of a case where the
lost.
The example also shows how cumulative acknowledgments can
58
Below figure is an example(if frame lost)
Stop-and-Wait ARQ is a special case of Go-Back-N ARQ in
59
3 Selective Repeat Automatic Repeat Request
sliding.)
The only difference in sender window between Go-back N and
61
Receiver window
The receiver window in Selective Repeat is totally different from the one
in Go Back-N. First, the size of the receive window is the same as the
The Selective Repeat Protocol allows as many frames as the size of the
receiver window to arrive out of order and be kept until there is a set of
of the send window and receive window are the same, all the frames in
the send frame can arrive out of order and be stored until they can be
delivered.
However the receiver never delivers packets out of order to the network
layer.
Above Figure shows the receive window. Those slots inside the window
that are colored define frames that have arrived out of order and are
62
waiting for their neighbors to arrive before delivery to the network
Delivery of Data in Selective Repeat ARQ
Flow Diagram
63
Differences between Go-Back N & Selective Repeat
Piggybacking
• A technique called piggybacking is used to improve the
efficiency of the bidirectional protocols. When a frame is
carrying data from A to B, it can also carry control information
about arrived (or lost) frames from B; when a frame is carrying
data from B to A, it can also carry control information about the
arrived (or lost) frames from A. 64
MAC sub layer
The medium access sub layer, which is part of the data link layer, it deals how to
determine that who may use the network next when the network consists of a single
shared channel, as in most networks. This layer is also known as the Medium Access
Control Sub-layer.
Networks can be divided into two categories: those using point-to-point connections
In any broadcast network, the key issue is how to determine who gets to use the
To make this point clearer, consider a conference call in which six people, on six
different telephones, are all connected so that each one can hear and talk to all the
others. It is very likely that when one of them stops speaking, two or more will start
talking at once, leading to chaos. When only a single channel is available, determining
The protocols used to determine who goes next on a multi-access channel belong to a
sub-layer of the data link layer called the MAC (Medium Access Control) sub-layer.
65
The Channel Allocation Problem
each user being assigned one portion. Since each user has a private
frequency band, there is no interference between users. When there are
only a small and constant number of users, each of which has a heavy load
of traffic, FDM is a simple and efficient allocation mechanism.
When the number of senders is large and continuously varying or the
66
If the spectrum is cut up into N regions and fewer than N users are
bandwidth is simply lost. They are not using it, and no one else is
allowed to use it either.
The poor performance of static FDM can easily be seen from a
10,000 bits, and the frame arrival rate, F, is 5000 frames/sec, then
T = 200 μsec.
Note that if we ignored the queuing delay and just asked how long
That result only holds when there is no contention for the channel.68
Now let us divide the single channel into N independent sub-channels, each
with capacity C/N bps. The mean input rate on each of the sub-channels
(ii)
The mean delay using FDM is N times worse than if all the frames were
Precisely the same arguments that apply to FDM also apply to time division
multiplexing (TDM). Each user is statically allocated every Nth time slot.
If a user does not use the allocated slot, it just lies fallow. The same holds if
each and statically allocate each user to one of them, the mean delay would
1. Independent Traffic.
The model consists of N independent stations (e.g., computers,
2. Single Channel.
A single channel is available for all communication.
All stations can transmit on it and all can receive from it.
resulting signal is garbled. This event is called a collision. All stations can
detect that a collision has occurred. A collided frame must be transmitted
again later. No errors other than those generated by collisions occur.
4. Continuous or Slotted Time.
Time may be assumed continuous, in which case frame transmission can
before trying to use it. No station will attempt to use the channel while it is
sensed as busy. If there is no carrier sense, stations cannot sense the
channel before trying to use it. They just go ahead and transmit. Only later
71
Multiple Access Protocol
The upper sub layer is responsible for data link control, and the lower sub
called the logical link control (LLC) layer; the lower sub layer that is
mostly responsible for multiple access resolution is called the media
access control (MAC) layer.
When nodes or stations are connected and use a common link, called a
72
Taxonomy of multiple-access protocols
1. RANDOM ACCESS
Two features give this method its name. First, there is no scheduled
compete with one another to access the medium. That is why these
73
methods are also called contention methods.
ALOHA
1 Pure ALOHA
The original ALOHA protocol is called pure ALOHA. This is a
simple, but elegant protocol. The idea is that each station sends a
frame whenever it has a frame to send. However, since there is
only one channel to share, there is the possibility of collision
between frames from different stations. Below Figure shows an
example of frame collisions in pure ALOHA
74
In pure ALOHA, the stations transmit frames whenever they have data to send.
When two or more stations transmit simultaneously, there is collision and the
If the frame is destroyed because of collision the station waits for a random
amount of time and sends it again. This waiting time must be random otherwise
again.
Therefore pure ALOHA dictates that when time-out period passes, each station
must wait for a random amount of time before resending its frame. This
75
Vulnerable time
76
Station A sends a frame at time t.
and t.
station B. The end of B's frame collides with the beginning of A's
C. The beginning of C's frame collides with the end of A's frame
transmission time.
This is so because there is no rule that defines when the station can
send. A station may send soon after another station has started or
soon before another station has finished.
Slotted ALOHA was invented to improve the efficiency of pure
ALOHA.
In slotted ALOHA we divide the time into slots of Tfr s and force the
station to send only at the beginning of the time slot. Figure 3 shows
an example of frame collisions in slotted ALOHA
78
Because a station is allowed to send only at the beginning of the synchronized
time slot, if a station misses this moment, it must wait until the beginning of
the next time slot.
This means that the station which started at the beginning of this slot has
already finished sending its frame. Of course, there is still the possibility of
collision if two stations try to send at the beginning of the same time slot.
However, the vulnerable time is now reduced to one-half, equal to Tfr
Below fig shows that the vulnerable time for slotted ALOHA is one-half that of
pure ALOHA.
Slotted ALOHA vulnerable time = Tfr
80
Carrier Sense Multiple Access (CSMA)
To minimize the chance of collision and, therefore, increase the
can be reduced if a station senses the medium before trying to use it.
Carrier sense multiple access (CSMA) requires that each station first
listen to the medium (or check the state of the medium) before sending.
CSMA can reduce the possibility of collision, but it cannot eliminate it.
81
Stations are connected to a shared channel (usually a
dedicated medium).
delay; station may sense the medium and find it idle, only
because the first bit sent by another station has not yet been
received.
sends a frame.
idle because, at this time, the first bits from station B have
This is the time needed for a signal to propagate from one end of the
When a station sends a frame, and any other station tries to send a
frame during this time, a collision will result. But if the first bit of the
frame reaches the end of the medium, every station will already have
83
Persistence
Methods
What should a station do
1. The 1-persistent
method
2. The non-persistent
Method
3. p-persistent method
84
1. 1-Persistent: In this method, after the station finds the line idle, it sends
its frame immediately (with probability 1). This method has the highest
chance of collision because two or more stations may find the line idle and
2. Non-persistent: a station that has a frame to send senses the line. If the
line is idle, it sends immediately. If the line is not idle, it waits a random
amount of time and then senses the line again. This approach reduces the
chance of collision because it is unlikely that two or more stations will wait
the same amount of time and retry to send simultaneously. However, this
method reduces the efficiency of the network because the medium remains
3. p-Persistent: This is used if the channel has time slots with a slot
2.With probability q = 1 - p,
step 1.
backoff procedure.
86
Carrier Sense Multiple Access with Collision Detection (CSMA/CD)
collision.
detects the collision, we show what happens as the first bits collide.
87
In below Figure, stations A and C are involved in the
collision.
88
Collision of the first bit in CSMA/CD
At time t2, station C has not yet sensed the first bit sent by A. Station C
executes its persistence procedure and starts sending the bits in its
Station A detects collision at time t4 when it receives the first bit of C's
Looking at the figure, we see that A transmits for the duration t4 - tl; C
sending the last bit of the frame, the sending station must detect a
This is so because the station, once the entire frame is sent, does not keep
a copy of the frame and does not monitor the line for collision detection.
Therefore, the frame transmission time T fr must be at least two times the
If the two stations involved in a collision are the maximum distance apart,
the signal from the first takes time Tp to reach the second, and the Effect
So the requirement is that the first station must still be transmitting after
2Tp
90
91
DIFFERENCES BETWEEN ALOHA & CSMA/CD
The first difference is the addition of the persistence
93
Inter frame Space (IFS)
found idle.
When an idle channel is found, the station does not send immediately.
It waits for a period of time called the inter frame space or IFS.
Even though the channel may appear idle when it is sensed, a distant station
may have already started transmitting. The distant station's signal has not yet
reached this station. The IFS time allows the front of the transmitted signal by
If after the IFS time the channel is still idle, the station can send, but it still
The IFS variable can also be used to prioritize stations or frame types. For
In CSMA/CA, the IFS can also be used to define the priority of a station or a
frame.
94
Contention Window
The contention window is an amount of time divided into slots. A station that is
The number of slots in the window changes according to the binary exponential
back-off strategy.
This means that it is set to one slot the first time and then doubles each time the
This is very similar to the p-persistent method except that a random outcome
One interesting point about the contention window is that the station needs to
However, if the station finds the channel busy, it does not restart the process; it
just stops the timer and restarts it when the channel is sensed as idle.
This gives priority to the station with the longest waiting time.In CSMA/CA, if the
station finds the channel busy, it does not restart the timer of the contention
window; it stops the timer and restarts it when the channel becomes idle. 95
Acknowledgment
With all these
precautions, there still
may be a collision
resulting in destroyed
data. In addition, the
data may be corrupted
during the
transmission.
The positive
acknowledgment and
the time-out timer can
help guarantee that
the receiver has
received the frame. 96
This is the CSMA protocol with collision avoidance.
The station ready to transmit, senses the line by using one of the
persistent strategies.
As soon as it finds the line to be idle, the station waits for an IFS
If then waits for some random time and sends the frame.
After sending the frame, it sets a timer and waits for the
off parameter, waits for the back off time and re senses the line.
97
Controlled Access Protocols
In controlled access, the stations seek information from one another
to find which station has the right to send. It allows only one node to
send at a time, to avoid collision of messages on shared medium.
The three controlled-access methods are:
1 Reservation
2 Polling
3 Token Passing
Reservation
In the reservation method, a station needs to make a reservation
Suppose if station 1 has a frame to send, it transmits 1 bit during the slot
After all N slots have been checked, each station knows which stations
wish to transmit.
The stations which have reserved their slots transfer their frames in that
order.
Since everyone agrees on who goes next, there will never be any
collisions.
99
The following figure shows a situation with five stations
reservations.
In the second interval, only station 1 has made a
reservation.
100
Polling
Polling process is similar to the roll-call performed in class. Just like the
controller.
The message sent by the controller contains the address of the node
Although all nodes receive the message but the addressed one responds
station in the ring whereas incase of Token bus, each station uses
the bus to send the token to the next station in some predefined
order.
send that frame before it passes the token to the next station. If it
(including itself) to send the token to their neighbors and the other N
104