Chapter 5
Data Link Layer
Data Link Layer Functions
Automatic Repeat Request (ARQ)
Flow Control
Framing
1
OSI Reference Models
Machine A
Machine B
Application
Application
Presentation
Presentation
Session
Session
Transport
Communication Network
Transport
Network
Network
Network
Network
Data Link
Data Link
Data Link
Data Link
Physical
Physical
Physical
Physical
Electrical and/or Optical Signals
2
DLL Functions and Protocols (1)
⚫ Responsible for Reliable Transfer of Frames
from one node to the other.
⚫ No Loss
⚫ No Corruption
⚫ No Duplication
⚫ No Insertion
⚫ In the sequence of transmission.
3
DLL Functions and Protocols (2)
DLC Protocols:
⚫ Framing
⚫ Error Control (Detection/Correction)
⚫ Automatic Repeat Request (ARQ)
⚫ Flow Control
⚫ Medium access control (MAC sublayer)
⚫ Controls the access of many hosts to a shared
channel
⚫ MAC Protocols:
⚫ Random: ALOHA, CSMA, ….
⚫ Scheduled: Reservation, Polling, Token-Ring
⚫
4
Data Link Control Protocols
⚫
For efficient and reliable transmission of
data between two stations:
⚫ Frame Synchronization
⚫ Flow Control
⚫ Error Control
⚫ Addressing
⚫ Control and Data on Same Link
⚫ Link Management
5
Error Detection and Control
Practical communication is never error free.
⚫ Quality is measured in BER.
⚫ Communication over copper wire 10-3
⚫ Communication over fiber optics 10-9
⚫ Wireless communication 10-2
⚫ Quality can be improved by deploying error control codes.
⚫ Error control is achieved by adding structured redundancy
to a segment of data, for
⚫ Error detection and/or
⚫ Error correction
⚫ Two types of erroneous frames:
⚫ Lost frames and Damaged frames
6
⚫
Error Detection
Additional bits (parity bits) are added by transmitter as
error detection code
⚫ Receiver checks this code
⚫ Parity bits are added to the transmitted data such that
errors may be detected and possibly corrected at the
receiver
⚫ Examples:
⚫
Single Bit Parity Check Codes
⚫ Two Dimensional Parity Check Codes
⚫ Cyclic Redundancy Check (CRC) Codes
⚫ Internet Check Sum
⚫
7
Error Control
⚫
Automatic repeat request (ARQ) techniques are based
on:
⚫ Error detection
⚫ Positive acknowledgment
⚫ Retransmission after timeout
⚫ Negative acknowledgment and retransmission
⚫
ARQ standardized versions:
⚫ Stop-and-wait ARQ
⚫ Go-back-N ARQ
⚫ Selective-repeat ARQ
8
ARQ Protocols
ARQ could be applied at
⚫ Transport Layer (end-to-end)
⚫ Data Link Layer (hop-by-hop)
⚫ To deliver:
⚫ Error-free frames
⚫ No Duplication or Loss
⚫ In order
⚫ Forward Channel:
⚫ Information Frame: Data + CRC
⚫ Enquiry Frame: ENQ + CRC
⚫ Feedback Channel:
⚫ Acknowledgment Frame: ACK/NAK + CRC
⚫
9
Error Control Schemes
FEC
ARQ
Error control
Correction
Detection
After decoding
Deliver to user
Accept or retransmit
Feedback
channel
Not required
Required
Throughput
Fixed
Variable
Delay
Constant
Variable
Packet length
Short
Long
Reliability
Limited
Almost unlimited
Application
Voice Networks
Data Networks
10
Stop-and-Wait ARQ
A
B
After transmitting a frame, A stops and waits for ACK
or time out.
⚫ B transmits ACK if received frame is correct;
otherwise no action is taken.
⚫ A transmits a new frame upon the receipt of ACK, or
retransmits the old frame if timeout expires.
⚫
11
Performance Metrics and Delays
⚫
Transmission time (delay)
⚫ Time taken to emit all bits into medium
⚫
Propagation time (delay)
⚫ Time for a bit to traverse the link
⚫
Processing time (delay)
⚫ Time spent at the recipient for processing
⚫
Queuing time (delay)
⚫ Waiting time at the queue to be sent out
12
Stop-and-Wait ARQ Example
PDU transmission
time
Propagation time
Time
Propagation time
Station B
ACK transmission
time
PDU transmission
time
Station A
Station B
ACK transmission
time
Station A
Timeout interval
Timeout interval
Frame 0 lost;
A retransmits
X
Frame damaged/lost
X
ACK damaged/lost
ACK0 lost;
A retransmits
B discards
duplicate frame
13
Stop-and-Wait ARQ
⚫
⚫
⚫
⚫
⚫
⚫
⚫
Transmit single frame
Wait for ACK
If received frame damaged, discard it
⚫ Transmitter has timeout
⚫ If no ACK within timeout, retransmit
If ACK damaged, transmitter will not recognize it
⚫ Transmitter will retransmit
⚫ Two copies of the same frame are received (discard one)
Use ACK0 (for frame labeled 1) and ACK1 (for frame labeled
0)
Pros: simple
Cons: inefficient
14
Stop and Wait Link Utilization
a>1
a<1
transmission time = 1; propagation time = a
15
Scenario (a): Frame Lost or
Corrupted
A
timeout
B
⚫
Timeout period is set to be
greater than the round-trip
delay
D= 2Tprop+Tf+Ta.
Tf
Tprop
Ta
Tprop
16
Scenario (b): ACK Lost
A
timeout
B
⚫ Problem: frame duplication.
17
Scenario (c): Delayed ACK
A
timeout
B
⚫ Problem: Missing frames
18
Sequence Numbers (SN) for ACK
One toggling bit (SL / RN ) suffices to remove the
ambiguity.
⚫ SL indicates the label of the Last frame transmitted and
not yet acknowledged.
⚫ RN indicates the label for the next frame expected.
⚫ SL is sent within I-frame, while RN is sent within ACK
frame.
⚫ The transmitter toggles SL upon receiving ACK.
⚫ The receiver toggles RN after accepting a frame.
⚫ The receiver accepts the frame only if SL and RN match
⚫ The transmitter transmits a new frame only if SL and RN
are different; otherwise it retransmits the old frame.
19
⚫
1
A SL =0
B
0
RN =0
1
0
1
0
RN =0
1
0
0 1
A SL=0
B
1
1
A SL =0
B
1
0
0
1
RN =0
1
1
0
20
Stop-and-Wait Efficiency
First frame bit
enters channel
Last frame bit
enters channel
ACK
arrives
Channel idle while transmitter
waits for ACK
t
A
B
First frame bit
arrives at
receiver
t
Last frame bit
arrives at
receiver
Receiver
processes frame
and
prepares ACK
10000-bit frame @ 1 Mbps takes 10 ms to transmit
⚫ If wait for ACK = 1 ms, then efficiency = 10/11= 91%
⚫ If wait for ACK = 20 ms, then efficiency =10/30 = 33%
⚫
21
Stop-and-Wait Model
t0 = total time to transmit 1 frame
A
tproc
B
tprop
frame
tf time
tproc
tprop
tack
t0 = 2t prop + 2t proc + t f + t ack
nf
bits/info frame
na
= 2t prop + 2t proc +
+
R
R
bits/ACK frame
channel transmission rate
22
S&W Efficiency on Error-free
channel
Effective transmission rate:
0
eff
R
bits for header & CRC
number of informatio n bits delivered to destination n f − no
=
=
,
total time required to deliver the informatio n bits
t0
Transmission efficiency:
n f − no
Reff
t0
0 =
=
=
R
R
Delay-bandwidth
product is the amount of
bits that can exist in the
channel at a given time
Effect of
no
frame overhead
1−
nf
.
na 2(t prop + t proc ) R
1+
+
nf
nf
Effect of
ACK frame
Effect of
23
Delay-Bandwidth Product
Example: Impact of DelayBandwidth Product
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
2xDelayxBW
Efficiency
1 Mbps
1 Gbps
1 ms
200 km
103
88%
106
1%
10 ms
100 ms
1 sec
2000 km 20000 km 200000 km
104
105
106
49%
9%
1%
107
108
109
0.1%
0.01%
0.001%
Stop-and-Wait does not work well for very high speeds
or long propagation delays
24
S&W Performance with
Transmission Errors
i – 1 unsuccessful transmissions
1 successful transmission
E[ttotal ] = t0 + (i − 1)tout P[nt = i ]
i =1
= t0 + (i − 1)tout (1 − Pf ) Pf
i −1
Recall that
i =1
= t0 +
tout Pf
1 − Pf
= t0
1
.
1 − Pf
Efficiency:
n f − no
E[ttotal ]
SW =
= (1 − Pf )
R
1−
no
nf
na 2(t prop + t proc ) R
1+
+
nf
nf
= (1 − Pf ) 0 .
25
Example: Impact of Bit Error Rate
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
Find efficiency for random bit errors with p=0, 10-6, 10-5, 10-4
1 − Pf = (1 − p) f e
n
1 – Pf
−n f p
for large n f and small p
p=0
p=10-6
p=10-5
p=10-4
1
88%
0.99
86.6%
0.905
79.2%
0.368
32.2%
Efficiency
1 Mbps
& 1 ms
Bit errors impact performance as nfp approach 1
26
Basic Go-Back-N ARQ
A
B
Out-of-sequence
frames (no ACK)
A sends Ws frames without waiting for ACK.
⚫ After that, A sends a new frame upon the receipt of
ACK, or goes back WS frames and retransmits them.
⚫ For the same reasons explained for SW, a
mechanism for sequence numbers is needed.
⚫ Since WS frames are outstanding, we need to
implement a SN mechanism that distinguishes them.
⚫
27
Go-Back-N Transmitter & Receiver
Receiver
Transmitter
Send Window
...
Frames
transmitted S
last
and ACKed
Srecent
Receive Window
Slast+Ws-1
Buffers
Timer
Slast
Timer
Slast+1
oldest unACKed frame
...
Timer
Srecent
most recent
transmission
...
Slast+Ws-1
max Seq #
allowed
Frames
received
Rnext
Receiver will only accept
a frame that is error-free and
that has sequence number Rnext
When such a frame arrives, Rnext
is incremented by one, and then
the receive window slides
forward by one
28
Sliding Window Operation
Transmitter
Send Window
...
Frames
transmitted S
last
and ACKed
Srecent
Slast+Ws-1
Transmitter waits for error-free
ACK frame with sequence
number Slast
When such ACK frame arrives,
Slast is incremented by one, and
the send window slides forward
by one
m-bit Sequence Numbering
2m – 1
0
1
2
Slast
send
i
window
i+1
i + Ws – 1
29
Maximum Allowable Window Size is Ws = 2m-1
M = 22 = 4, Go-Back - 4:
A
fr
0
B
Rnext
fr
2
fr
1
0
fr
3
Transmitter goes back 4
fr
0
A
C
K
1
A
C
K
2
A
C
K
3
A
C
K
0
1
2
3
0
fr
1
fr
2
fr
3
Time
Receiver has Rnext= 0, but it does not
know whether its ACK for frame 0 was
received, so it does not know whether this
is the old frame 0 or a new frame 4 (4=0)
Maximum Allowable Window Size is Ws = 2m-1
M = 22 = 4, Go-Back - 4:
A
fr
0
B
Rnext
fr
2
fr
1
0
fr
3
A
B
Rnext
0
fr
0
A
C
K
1
A
C
K
2
A
C
K
3
A
C
K
0
1
2
3
0
M = 22 = 4, Go-Back-3:
fr
0
Transmitter goes back 4
fr
2
fr
3
Time
Receiver has Rnext= 0, but it does not
know whether its ACK for frame 0 was
received, so it does not know whether this
is the old frame 0 or a new frame 4 (4=0)
Transmitter goes back 3
fr
0
fr
2
fr
1
fr
1
A
C
K
1
A
C
K
2
A
C
K
3
1
2
3
fr
1
fr
2
Receiver has Rnext= 3 , so it
rejects the old frame 0
Time
31
Sliding Window
⚫
Send Window:
⚫ Lower limit: SL
⚫ Upper limit: SL+ WS - 1
⚫ Most recently transmitted frame: Srecent
⚫ When a new ACK arrives both lower and upper
limits are incremented by one or more frames
(window slides forward).
⚫ Transmitting new frames continues as long as Srecent
upper limit.
⚫ If Srecent reaches the upper limit, transmitter stops
transmitting new frames until the window slides
forward.
32
Sliding Window (cont’d)
⚫
⚫
⚫
⚫
⚫
Receive Window:
⚫ Size is 1.
⚫ Contains the number of the next expected frame RN
When RN is received at transmitter, it implicitly acknowledges all
prior frames.
Upon receiving ACK with value RN, the transmitter updates the
value of SL to RN
It is important to emphasize that retransmission takes place only
if upper limit is received, and not when ACK is absent.
This eliminates (reduces) the need to retransmit a frame
because ACK is lost or not transmitted, and hence enhances the
scheme efficiency.
33
Use of Negative Acknowledgment
(NAK)
The efficiency of GBN-ARQ can be further enhanced by
incorporating NAK.
⚫ GBN does not respond to absent ACK, which is
beneficial if the frame was received but its ACK was
lost.
⚫ However, ACK could be absent because the frame was
lost or corrupted.
⚫ In this case, it is a waste of resources for the transmitter
to keep transmitting new frames as they will definitely
be retransmitted.
⚫
34
Use of NAK (cont’d)
Solution: Let receiver send NAK for lost/corrupted frames.
When the transmitter receives NAK, it stops transmitting new frames
and goes back to the NAKed frame and retransmits from there on. (It
may go back less than WS)
NAK will be cleared only after RN is received.
Receiver is allowed to send only one NAK until it is cleared.
Example of GBN: High-Level Data Link Control (HDLC)
⚫
⚫
⚫
⚫
⚫
A
B
Out-of-sequence
frames
35
Efficiency of Go-Back-N
⚫
⚫
GBN is very efficient when Ws is large enough to keep channel
busy, and if channel is error-free
Using Pf frame loss probability, the time to deliver a frame is:
⚫
⚫
tf
tf + Wstf /(1-Pf)
if first frame transmission succeeds (1 – Pf )
if the first transmission does not succeed (Pf)
tGBN = t f (1 − Pf ) + Pf {t f +
Ws t f
1 − Pf
} = t f + Pf
Ws t f
1 − Pf
and
n f − no
n
1− o
nf
tGBN
GBN =
=
(1 − Pf )
R
1 + (Ws − 1) Pf
36
Delay-bandwidth product determines Ws
Selective Repeat ARQ
Go-Back-N ARQ inefficient because multiple frames
are resent when errors or losses occur
⚫ Selective Repeat retransmits only an individual frame
⚫
⚫
⚫
⚫
Timeout causes individual corresponding frame to be resent
NAK causes retransmission of oldest un-acked frame
Receiver maintains a receive window of sequence
numbers that can be accepted
⚫
⚫
Error-free, but out-of-sequence frames with sequence
numbers within the receive window are buffered
Arrival of frame with Rnext causes window to slide forward by
1 or more
37
SR Demonstration
release F0
release F1
Clear NAK
release F2-F6
release F7, F8
A
B
Stored, window
pointer incremented
Increment lower limit
Deliver F2- F6
Advance lower limit to 7
38
Transmission Mechanism
⚫
⚫
⚫
⚫
⚫
⚫
When an out-of-sequence frame is received:
⚫ It is stored
⚫ Window pointer is incremented
⚫ NAK with RN is sent
If window is full, the frame is rejected
The transmitter retransmits the specific frame that is NAKed
only.
Once accepted, the receiver releases this frame and the
consecutive frames stored and increments the lower limit
accordingly.
It can be shown that for m-bit SN the maximum allowable
window sizes WS= WR= 2m-1
Example: TCP
39
Selective Repeat ARQ
Receiver
Transmitter
Send Window
...
Frames
transmitted S
last
and ACKed
Timer
Timer
Srecent
Slast+ Ws-1
Receive Window
Frames
received Rnext
Buffers
Slast
Buffers
Rnext+ 1
Slast+ 1
Rnext+ 2
Rnext + Wr-1
...
Timer
Srecent
...
Slast+ Ws - 1
...
Rnext+ Wr- 1
max Seq #
accepted
40
What Ws and Wr are allowed?
⚫
Example: M=22=4, Ws=3, Wr=3
Frame 0 resent
Send
Window
{0,1,2} {1,2}
{2}
{.}
fr0
fr1
fr2
A
B
Receive
Window
ACK1
{0,1,2} {1,2,3}
fr0
ACK2
Time
ACK3
{2,3,0}
{3,0,1}
Old frame 0 accepted as a
new frame because it falls
in the receive window
41
Ws + Wr = 2m is maximum allowed
⚫
Example: M=22=4, Ws=2, Wr=2
Frame 0 resent
Send
Window
{0,1}
A
{.}
{1}
fr0
B
Receive
Window
fr0
fr1
ACK1
{0,1}
{1,2}
Time
ACK2
{2,3}
Old frame 0 rejected because it
falls outside the receive window
42
Efficiency of Selective Repeat
⚫
Assume Pf frame loss probability, then number of
transmissions required to deliver a frame is:
⚫
tf /(1-Pf)
SR =
n f − no
t f /(1 − Pf )
R
no
= (1 − )(1 − Pf )
nf
43
Summary of ARQ Efficiencies
Assume na and no are negligible relative to nf, and
L = 2(tprop+tproc)R/nf =(Ws-1), then
Selective-Repeat:
no
SR = (1 − Pf )(1 − ) (1 − Pf )
nf
Go-Back-N:
GBN =
1 − Pf
1 + (WS − 1) Pf
=
1 − Pf
1 + LPf
Stop-and-Wait:
(1 − Pf )
1 − Pf
SW =
2
(
t
+
t
)
R
n
1+ L
1 + a + prop proc
nf
nf
44
Comparison of Schemes
Stop&Wait
45
Flow Control
⚫ Ensuring the sending entity does not
overwhelm the receiving entity
⚫ Recipient needs some time to process
incoming packets
⚫ If sender sends faster than recipient
processes, then buffer overflow occurs
⚫ Flow control prevents buffer overflow
46
Flow Control Schemes
⚫ Stop-and-Wait
⚫ Sliding-Window
47
Stop-and-Wait
Source transmits frame
⚫ Destination receives frame and replies with
acknowledgement
⚫ Source waits for ACK before sending next frame
⚫ Destination can stop flow by not sending ACK
⚫ Works well for a few large frames
⚫
48
Sliding-Window Flow Control
⚫
Multiple frames to be in transit
⚫
Receiver has W-size buffer
⚫
Transmitter can send up to W frames without ACK
⚫
Each frame is numbered
⚫
ACK indicates the number of next expected frame
⚫
Sequence number bounded by field size (m)
⚫ Frames are numbered modulo 2m (0 … 2m-1)
⚫ The maximum window size is 2m-1
49
Sliding Window Depiction
3-bit sequence number field
W=8
Window size = 5 < W
Buffered frames
but not yet
acknowledged
Window of possible
transmitted frames
Frames already transmitted
Sender’s
perspective
…
0
1
2
3
4
5
6
7
0
1
2
3
Last frame
acknowledged
2
3
4
5
4
5
6
7
0
…
0
…
Window expands
from leading edge as
ACKs are received
Window of possible
transmitted frames
Frames already received
…
1
Window shrinks
from trailing edge
as frames are sent
Last frame
acknowledged
Receiver’s
perspective
0
6
7
0
1
2
Window shrinks
from trailing edge as
frames are received
3
4
5
6
7
Window expands
from leading edge as
ACKs are sent
50
Framing
transmitted
frames
received
frames
0110110111
0111110101
Framing
Mapping stream of
physical layer bits into
frames
⚫ Mapping frames into
bit stream
⚫ Frame boundaries can
be determined using:
⚫
⚫
⚫
⚫
Character Counts
Control Characters
Flags
51
Framing & Bit Stuffing
Flag Address Control
Information
FCS
Flag
Data bits from higher layer
Frame boundary defined by flag bits (e.g., 01111110)
⚫ Example: HDLC uses bit stuffing to prevent
occurrence of flag 01111110 inside the frame
⚫ Transmitter inserts extra 0 after each consecutive five
1s inside the frame
⚫ Receiver checks for five consecutive 1s
⚫
⚫
⚫
⚫
if next bit = 0, it is removed
if next two bits are 10, then flag is detected
If next two bits are 11, then frame has errors
52
Example: Bit stuffing & de-stuffing
(a)
Data to be sent
0110111111111100
After stuffing and framing
0111111001101111101111100001111110
(b)
Data received
01111110000111011111011111011001111110
After destuffing and deframing
*000111011111-11111-110*
53
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )