Sanjay K. Bose
Lecture Set III
Data Link Layer (DLC)
2
Error Control
All real channels will have noise causing occasional
bit errors (i.e. 1 0 or 0 1 due to noise)
Error Control involves Error Detection and possibly
Error Correction
In network communications, error detection
followed by repetition of the frame/packet in error
is the typical approach followed (see ARQ
discussion later). Error correction is less commonly
used.
3
Types of Error
An error occurs when a bit is altered between its
transmission and reception send 0/receive 1 or send
1/receive 0
Single bit errors (random bit error channel model)
Randomly selected bits are altered;
Bit errors are independent events, i.e. error in a bit does
not affect the probability of any other bit being in error
Mostly caused by White Noise
Burst errors (random error vector channel model)
Length B
Contiguous sequence of B bits in which the first bit, the
last bit and any number of intermediate bits are in error
Caused by Impulse Noise and/or Fading in wireless
channels
Effect greater at higher data rates
4
Error Detection Process
5
Additional bit added by transmitter for error detection
Information bits + parity bit = codeword
k (bits) 1 k+1 (bits)
Value of parity bit is such that character has even (even
parity) or odd (odd parity) number of ones (choose one
even/odd)
E.g. 1100110 0 0 makes sure the codeword
contains even number of 1s
if at the receiver the codeword is 1101110 0, odd number
of 1s will be detected as an error in the codeword
Even number of bit errors goes undetected, e.g. 2 error bits
in the above codeword becomes 1101010 0 (even parity)
Single Parity Check
Even Parity Bit
E
v
e
n
P
a
r
i
t
y
6
(Even) Parity Check using Modulo 2 Addition
Append an overall parity check to k information bits
Info Bits: b
1
, b
2
, b
3
, , b
k
Check Bit: b
k+1
=b
1
+ b
2
+ b
3
+ + b
k
modulo 2
Codeword: (b
1
, b
2
, b
3
, , b
k,
, b
k+1
)
All codewords have even # of 1s
Receiver checks to see if # of 1s is even
All error patterns that change an odd # of bits are
detectable
All evennumbered patterns are undetectable
Parity bit was commonly used in ASCII code
7
How good is the single parity check code?
Redundancy: Single parity check code adds 1
redundant bit per k information bits
overhead = 1/(k + 1)
Coverage: all error patterns with odd # of errors can
be detected
An error pattern (vector) is a binary (k + 1)tuple
with 1s where errors occur and 0s elsewhere
Of 2
k+1
binary (k + 1)tuples, are odd, so 50% of
error patterns can be detected
For random error vector channel model, all 2
k +1
possible error vectors are equally likely to occur
and probability of error detection failure is 1/2
Is it possible to detect more errors if we add more
check bits?
Yes, but one has to choose the right codes
2+1 tuple
even
parity
codes
00 0
01 1
10 1
11 0
2+1 tuple
error
vectors
00 1
01 0
01 1
10 0
10 1
11 0
11 1
8
Probability of Bit Error Patterns
Many transmission channels introduce (single) bit errors at
random, independently of each other, and with probability p
Some error patterns are more probable than others:
In any worthwhile channel p < 0.5, and so (p/(1 p)) < 1
For such a channel, it follows that patterns with 1 error are more
likely than patterns with 2 errors and so forth
Important Question: What is the probability that an undetectable
error pattern occurs?
P[10000000] =p(1 p)
7
=(1 p)
8
and
P[11000000] =p
2
(1 p)
6
=(1 p)
8
p
1 p
p
2
1 p
Note that the error
pattern has a 1 where
a bit error occurs
9
Random Bit Error Channel Model
(Single Parity Check Code)
Undetectable error pattern if even # of bit errors:
Example: Evaluate above for n = 32, p = 10
3
For this example, roughly 1 in 2000 error patterns is undetectable
For p<<1, p
i
(1p)
j
p
i
(1p
j
) p
i
and mostly the first term of P [..]
is significant
P[error detection failure] =P[undetectable error pattern]
=P[error patterns with even number of 1s]
= p
2
(1 p)
n2
+ p
4
(1 p)
n4
+
n
2
n
4
P[undetectable error] (10
3
)
2
(1 10
3
)
30
+ (10
3
)
4
(1 10
3
)
28
496 (10
6
) +35960 (10
12
) 4.96 (10
4
)
32
2
32
4
10
x = codewords
o =noncodewords
x
x
x
x
x
x
x
o
o
o
o
o
o
o
o
o
o
o
o
o
x
x
x
x
x
x
x
o
o
o
o
o
o
o
o
o
o
o
Poor
distance
properties
What is a good code?
Many channels have preference
for error patterns that have
fewer # of errors
These error patterns map
transmitted codeword to
nearby ntuple
If codewords close to each
other then detection failures
will occur
Good codes should maximize
separation between codewords
Good
distance
properties
11
TwoDimensional Parity Check
1 0 0 1 0 0
0 1 0 0 0 1
1 0 0 1 0 0
1 1 0 1 1 0
1 0 0 1 1 1
Bottom row consists of
check bit for each column
Last column consists
of check bits for each
row
More parity bits to improve coverage
Arrange information as columns
Add single parity bit to each column
Add a final parity column
Used in early error control systems
12
1 0 0 1 0 0
0 0 0 1 0 1
1 0 0 1 0 0
1 0 0 0 1 0
1 0 0 1 1 1
1 0 0 1 0 0
0 0 0 0 0 1
1 0 0 1 0 0
1 0 0 1 1 0
1 0 0 1 1 1
1 0 0 1 0 0
0 0 0 1 0 1
1 0 0 1 0 0
1 0 0 1 1 0
1 0 0 1 1 1
1 0 0 1 0 0
0 0 0 0 0 1
1 0 0 1 0 0
1 1 0 1 1 0
1 0 0 1 1 1
Arrows indicate failed check bits
Two errors
One error
Three
errors
Four errors
(undetectable)
Errordetecting capability
1, 2, or 3 errors can
always be detected.
Not all patterns of 4
errors or more can be
detected
13
Other Error Detection Codes
Many applications require very low error rate
Need codes that detect the vast majority of
errors
Single parity check codes do not detect enough
errors
Twodimensional codes require too many check
bits
The following error detecting codes used in
practice:
Internet Check Sums
CRC Polynomial Codes
14
Internet Checksum
Several Internet protocols (e.g. IP, TCP, UDP) use
check bits to detect errors in the IP header (or in
the header and data for TCP/UDP)
A checksum is calculated for header contents and
included in a special field.
Checksum recalculated at every router, so
algorithm selected for ease of implementation in
software
Let header consist of L, 16bit words,
b
0
, b
1
, b
2
, ..., b
L1
The algorithm appends a 16bit checksum b
L
15
The checksum b
L
is calculated as follows:
Treating each 16bit word as an integer, find
x = b
0
+ b
1
+ b
2
+ ...+ b
L1
modulo 2
16
1
The checksum is then given by:
b
L
=  x modulo 2
16
1
Thus, the headers must satisfy the following pattern:
0 = b
0
+ b
1
+ b
2
+ ...+ b
L1
+ b
L
modulo 2
16
1
The checksum calculation is carried out in software
using ones complement arithmetic
Internet Checksum Calculation
1
2
3
4
5
6
7
0
2
10
10 mod 7 =3
2 mod 7 =5
16
Internet Checksum Example
(A simple one, using 4bit words and mod 2
4
1 arithmetic)
Using mod 15 arithmetic
b
0
=1100 = 12
b
1
=1010 = 10
b
0
+b
1
=(12+10) mod 15 = 7
b
2
= 7 mod15 = 8
Therefore, b
2
=1000
Using Binary Arithmetic
Note that 16 mod15 = 1
So: 10000 mod15 = 0001
(i.e. leading bit wraps around)
b
0
+b
1
=1100+1010
=10110
=10000+0110
=0001+0110
=0111
=7
Take 1s complement to find
b
2
= 0111 =1000
x mod y residue of
x/y
x mod y y x
1100 12
1010 10
10110 22
1 15
 0111 07
1000 08
Binary Mod
1100
1010
10110
1
 0111
1000
If b
0
=1100, b
1
=1010, what is their Internet Checksum b
2
?
Dont take this example too seriously as it uses only 4 bit words for simplicity! Real
Internet checksum calculations (shown next) uses 1 6 bit words.
17
Internet Checksum Example
(A more complex one, using 16bit words and mod 2
16
1 arithmetic)
Using mod 2
16
1=65535 arithmetic
b
0
=1000 0001 1011 1100 = 81BC
H
= 33212
b
1
=0100 1000 0101 1010 = 485A
H
= 18522
b
0
+b
1
=(33212+18522) mod 65535 = 51734
b
2
=  51734 mod 65535 = 6553551734 = 13801 = 35E9
H
Therefore, b
2
= 0011 0101 1110 1001
If b
0
=1000 0001 1011 1100
& b
1
=0100 1000 0101 1010
What will be their Internet Checksum b
2
?
18
Polynomial Codes
Polynomials instead of vectors for codewords
Polynomial arithmetic instead of check sums
Also called Cyclic Redundancy Check (CRC) codes
Most data communications standards use
polynomial codes for error detection
Polynomial codes also form the basis for powerful
errorcorrection methods
19
Addition of Polynomials:
Multiplication of Polynomials:
Binary Polynomial Arithmetic
Mapping Binary Vectors to Polynomials:
(i
k1
, i
k2
,, i
2
, i
1
, i
0
) i
k1
x
k1
+i
k2
x
k2
+ +i
2
x
2
+i
1
x +i
0
(x
7
+x
6
+1) +(x
6
+ x
5
) =x
7
+x
6
+ x
6
+x
5
+1
=x
7
+(1+1)x
6
+x
5
+1
=x
7
+x
5
+1
(x +1) (x
2
+ x + 1) =x(x
2
+x + 1) + 1(x
2
+x +1)
=(x
3
+x
2
+ x) +(x
2
+x +1)
=x
3
+1
Modulo 2 is bin XOR
0 +0 =0 1 +1 =0
1 +0 =1 0 +1 =1
(1 0 1 1 0 1 0 1) x
7
+x
5
+x
4
+x
2
+1
20
Binary Polynomial Division
Recall how you do Division with Decimal Numbers
32
35 ) 1222
3
105
172
4
140
divisor
quotient
remainder
dividend
1222 =34 x 35 +32
dividend =quotient x divisor +remainder
Polynomial Division
x
3
+x +1 ) x
6
+x
5
x
6
+ x
4
+x
3
x
5
+x
4
+x
3
x
5
+ x
3
+x
2
x
4
+ x
2
x
4
+ x
2
+x
x
q(x) quotient
r(x) remainder
divisor
dividend
+x
+x
2
x
3
Note: Degree of r(x) is less than
degree of divisor
21
Cyclic Redundancy Check (CRC) Code
For a block of k data bits, one generates an n bit sequence
(called frame or packet) for transmission
Additional n k bits appended to the data block as a frame
check sequence (FCS). These nk bits are generated in such a
way that the binary polynomial T(x) corresponding to the n bit
sequence is exactly divisible by a specially chosen polynomial g
(x)
Receiver divides the binary polynomial for the incoming
frame (i.e. the received frame) by the same g(x)
If there is no remainder then it assumes No Error in
Received Frame
Otherwise there would be one or more errors
somewhere in the frame
Data FCS
n
n  k k
22
CRC Formulation
Define,
T = nbit frame to be transmitted
D = kbit data block, the first k bits of T
F = (nk)bit FCS, the last (nk) bits of T
P = pattern of (nk+1) bits; predetermined divisor; high and loworder bits must
be 1
For T/P to have no remainder, T is generated in the following form
T = 2
nk
D + F ; D is left shifted by nk bits, and F suitably chosen
Now suppose,
2
nk
D/P = Q + R/P ; Q is the quotient, and R is the remainder
R is transmitted as the FCS, and is at least one bit less than P
T = 2
nk
D + R (choose F to be R)
T is received and T/P is evaluated,
If Rem (T/P) = 0, i.e. T is exactly divisible by P,
then T is declared to be errorfree
Else, T is declared to have one or more bits in error
Binary exclusiveOR (XOR):
1010 1100 0000 0110
0110 0110 0110 0110
1100 1010 0110 0000
Systematic
Code
23
CRC  Operation
Message or data block, D: 1010001101 (10bits)
Predetermined divisor, P: 110101 (6bits)
Frame Check Sequence, R: to be calculated (5 bits)
Operation:
The message is multiplied by 2
5
, 101000110100000
This product is divided by P, yielding remainder 01110
The remainder, R is appended on the right of the message as the
FCS forming the Transmitted word, T: 101000110101110
At the receiver, the received frame, T* is divided by P. If T* is
received intact, 101000110101110/110101 will yield zero remainder
If there is no remainder, it is assumed that there are no errors in
the received frame; the received message data is then extracted
as the leading bits of the frame (the leading 10 bits in this case)
24
CRC  Example
CRC FCS Generation
CRC Error Detection
Subtraction same
as addition in
binary (mod 2)
addition
25
CRC: Polynomial Codes
k information bits may be expressed as a polynomial series
with binary coefficients
D = 1010001101 D(x) = x
9
x
7
+x
3
+x
2
+1 degree k1
P = 110101 P(x) or g(x) = x
5
+x
4
+x
2
+1 degree= nk
D multiplied by 2
5
is equivalent to x
5
D(x)
x
5
D(x) = x
14
+x
12
+x
8
+x
7
+x
5
CRC formulation expressed
in polynomials
P(x)
R(x)
Q(x)
P(x)
D(x) X
k  n
+ =
R(x) D(x) x T(x)
k n
+ =
degree n1
= x
14
+x
12
+x
8
+x
7
+x
5
+x
3
+x
2
+x 101000110101110
degree n1
Note that P(x) or g(x) is the Generator
Polynomial
26
Polynomial Codes  Example
Subtraction same
as addition in
binary (mod 2)
addition
P(X)
27
CRC Codes (Summary)
Data: D(x)
Generator Polynomial: g(x) sometimes also written as P(x)
Transmitted Codeword: T(x) T(x) exactly divisible by g(x)
Error Polynomial: E(x) coefficient of x
i
is 1 if i
th
bit is in error
Received Codeword: T*(x)=T(x)+E(x)
Errors are detected if T*(x) is not exactly divisible by g(x)
Error patterns which are such that E(x) is exactly divisible by g(x)
will not be detected.
Properties of the CRC code are determined by the choice of the
generator polynomial. Choose g(x) such that as many error
patterns E(x) as possible may be detected.
28
Properties of CRC Codes
If g(x) has more than one term, all single errors (i.e. E(x)=x
i
) will
be detected
A g(x) with more than one term cannot exactly divide an
E(x) which has only one term. Therefore such an E(x) will
be always detectable.
If g(x) has (1+x) as a factor, all error patterns with an odd number
of bits in error will always be detected
An error pattern with an odd number of errors will have an
odd number of terms in its E(x). Such an E(x) will never be
divisible by (1+x) and will always be detectable.
Example: g(x)=x
i
+x
j
+x
k
can never exactly
divide E(x)=x
k
(1+x) will divide a polynomial E(x) exactly only if E(x) has an even number of
terms. Verify for yourself that this will indeed always be true.
29
Properties of CRC Codes
Choose g(x) such that it (or one of its factors) does not divide x
m
+1
for any m<n where n is the number of bits in the codeword
This code will then detect all double errors as all double
error patterns will be of the form E(x)= x
i
+x
j
= (x
ij
+1)x
j
where (ij)<n since there are only n bits in the codeword
A CRC code with (nk) check bits will detect all error bursts of length
(nk) or less.
These burst error patterns will be polynomials of degree (nk1)
or less and cannot be divided exactly by g(x), since g(x) is a
polynomial of higher degree, i.e. (nk)
Most longer bursts are also detected by the CRC code
Example: x
15
+ x
14
+1 will not divide any x
k
+1 for a value of k less than 32,768
30
Choosing a Good Generator Polynomial g(x)
Typically choose g(x) of the form g(x)=(1+x)P
n
(x)
The factor (1+x) ensures that all odd errors will be
detected
The factor P
n
(x) is chosen such that it does not exactly
divide any (1+x
m
) for m<n. This ensures that all double
errors in an nbit codeword will always be detected
A good choice for P
n
(x) is something called a Primitive Polynomial which is
available from tables.
A primitive polynomial F(x) of degree m is such that the smallest positive
integer n such that F(x) exactly divides x
n
+ 1 is n = 2
m
1
31
Choosing a Good Generator Polynomial g(x)
Example:
Consider the CRC5 (ITU) generating function g(x)=x
5
+x
4
+x
2
+1
g(x) = x
5
+x
4
+x
2
+1 = (1+x)(1+x+x
4
)
Note that (1+x+x
4
) is a primitive polynomial which will not exactly divide (1+x),
(1+x
2
), (1+x
3
)(1+x
14
) but will exactly divide (1+x
15
)
Therefore using this g(x) ensures that
(a) All odd errors in the codeword will be detected
(b) All double errors will be detected if the codeword has less than 16 bits
(10 bits of data and 5 check bits)
(a) All burst errors with burst length 5 or less will always be detected
32
Standard Polynomial Codes
Name Generator Polynomial, P(x) or g(x) Used in
CRC8 x
8
+x
2
+x+1 ATM header error check
CRC10 x
10
+x
9
+x
5
+x
4
+x+1 ATM AAL CRC
CRC12 x
12
+x
11
+x
3
+x
2
+x+1 Bisync
CRC16 x
16
+x
15
+x
2
+1 Bisync
CCITT16 x
16
+x
12
+x
5
+1
DHLC, XMODEM, V.41 IEEE
802, DoD, V.42, AAL5
CRC32
x
32
+x
26
+x
23
+x
22
+x
16
+x
12
+x
11
+x
10
+x
8
+x
7
+
x
5
+x
4
+x
2
+x+1
33
Data Link Layer in the Layered Architecture
Application
Transport
Network
Data Link
Physical
Network
Data Link
Physical
Network
Data Link
Physical
Source Node
Destination Node
Intermediate
Node(s)
Signals
Packets
Bits
Frames
Application
Transport
Packets
Bits
Frames
Signals
34
Functions of the Data Link Layer
Key functions:
Framing:
Deals with data in chunks generally called Frames
(will typically have few hundreds/thousands of bytes)
Create/recognize frame boundaries
Requires special bit patterns to signal boundaries
(physical layer does not care about frames, only bits)
Error handling
Make Layer 1 into what appears to be a channel free of
undetected errors
Implements data link control protocols, such as High Level
Data Link Control (HDLC)
35
Data Link Protocols
Directly connected, wirelike
Losses & errors, but no outof
sequence frames
Applications: Direct Links;
LANs; Connections across WANs
Data Link Layer Services
Framing
Error control
Flow control
Multiplexing
Link Maintenance
Security:
Examples
PPP
HDLC
Ethernet LAN
IEEE 802.11 (Wi Fi) LAN
Data Link
Layer
Physical
layer
Physical
layer
Data Link
Layer
A
B
Packets
Packets
Frames
Sometimes the DLC is considered subdivided in an LLC Layer (Logical Link Control) and
a MAC Layer (Media Access Control) below it. We will consider these later.
considered
later
considered
later
36
Framing
Mapping stream of
physical layer bits into
frames (at transmitter)
Mapping frames into bit
stream (at receiver)
Frame boundaries can be
determined using:
Character Counts
Control Characters
Flags
0
1
1
0
1
1
0
1
1
1
Framing
received
frames
0
1
1
1
1
1
0
1
0
1
transmitted
frames
37
Framing & Bit Stuffing
Frame delineated by Flag character
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 removes stuffing bit
Control field has frame sequence numbers for error & flow control
Address to identify destination (and possibly source) of frame
FCS is the Frame Check Sequence to report if frame has errors
Flag
Flag
Address Control Information FCS
HDLC frame
variable number of bits
011111010
011111010 x
38
Error Detection
Additional bits added by transmitter for error
detection, such as
1. Even/Odd Parity
Value of parity bit is such that character has even
(even parity) or odd (odd parity) number of ones. Even
number of bit errors goes undetected
2. Checksum
Checksum can be a simple XOR operation of bits to be
checked
3. More sophisticated methods, Cyclic Redundancy Check (CRC)
Error Correction is usually not attempted in DLC Layer
39
Error Control
Detection and correction of errors
Lost frames
Damaged frames
Automatic Repeat Request (ARQ) features
Error detection (Parity check, CRC)
Positive acknowledgment (On errorfree frames)
Retransmission after timeout (Retransmit a frame after
predetermined time)
Negative acknowledgement and retransmission
(Retransmit a frame when an
error detected)
40
Stop and Wait
Source transmits single frame
Start transmitter timeout timer
Wait for ACK from receiver
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
Receive gets two copies of frame
Use ACK0 and ACK1 to detect duplicate copy
Simple but inefficient
Only 1 frame at a time
Timeout
timer starts
Frame
damaged/ lost
Ack
damaged
Transmit next frame only after ACK is received for the earlier frame
41
StopandWait
Without error
ACK
ACK
ACK
ACK
42
StopandWait ARQ with Frame Loss
With frame loss
Frame lost
43
StopandWait ARQ with ACK Loss [1]
Without frame and ACK sequence number
frame received
Acknowledgement
frame damaged
Duplicate frame
undetected
44
StopandWait ARQ with ACK Loss [2]
ACK1
ACK0
ACK0
Frame 0
Alternate frame sequence labeled with 0 or 1
ACK indicates the next frame the receiver is ready for
Frame 1 received
Duplicate frame 1 discarded
but still send ACK
45
StopandWait Link Utilization [1]
Let,
L = length of the frame in bits
R = data rate of the link, bps
d = length or distance of the link in meters
V = velocity of propagation, m/s
The bit length of the link defined as the number of bits present on the link
when a stream of bits fully occupies the link,
Serious link inefficiencies when bit length B is greater than the frame length L,
Define link utilization factor, ; smaller a higher efficiency
L
B
a =
V
d
R B =
L
B
d
V
R
where d/V is propagation time
46
StopandWait Link Utilization [2]
(Transmission time = 1; propagation time = a)
underutilized
underutilized
underutilized
Time intervals
normalized to the
frame length
47
StopandWait Link Efficiency [1]
The time to send 1 frame and receive an acknowledgement
T
F
= t
frame
+ t
prop
+ t
proc
+ t
ack
+ t
prop
+ t
proc
Assume t
proc
and t
ack
are negligible, the time to send a message
containing n frames is
T =n(2 t
prop
+ t
frame
)
Only n t
frame
is actually spent transmitting data. Hence, maximum
possible utilization (or efficiency) of the link is
Define , then ; smaller a higher link efficiency
frame prop
frame
frame prop
frame
t t
t
t t n
t n
u
+
=
+
=
2 ) 2 (
a
u
2 1
1
+
=
frame
prop
t
t
a =
1
1+2a
48
Propagation Time, t
prop
= d/V d: distance of link in meters
V : signal speed, 2.0 10
8
m/s for fiber and copper media
Transmission Time, t
frame
= L/R
L: frame Length in bits
R: data rate, bps
Now, as defined before (called link utilization factor)
It may also be visualized as a measure of lost opportunity in terms of the
number of frames that can be potentially transmitted on the link and will be
inversely proportional to the Link Efficiency
StopandWait Link Efficiency [2]
VL
Rd
R L
V d
t
t
a
frame
prop
= = =
/
/
a
u
2 1
1
+
=
L
B
d
V
R
Effective data transmission
rate across nodes = u x R
49
Link Efficiency in Presence of
Transmission Errors (StopandWait)
Let P
f
= probability that a frame arrives with errors
then, 1 P
f
= probability a frame arrives w/o errors
If N
r
is the number of expected
transmission per frame, then
If we assume that ACKs are never in error, then the probability that
it will take k attempts to transmit a frame successfully is P
f
k1
(1P
f
).
In that case, we will have (k1) unsuccessful attempts followed by
one successful attempt. The expected number of transmission is
then 
) 2 (
frame prop r
frame
t t N
t
u
+
=
f
i
f
i
f
i
r r
P
P P i
ons transmissi i P i ons transmissi E N
= =
= =
=
1
1
)) 1 ( (
)) ( ( ] [
1
1
1
50
Link Efficiency in Presence of Transmission Errors
(StopandWait)
Therefore, for a Stop&Wait
system
a
P
u
f
2 1
1
+
=
For a channel with bit error probability p, the probability
that a L bit frame is errorfree will be (1p)
L
.
Hence, P
f
= 1  (1p)
L
( )
a
p
u
L
2 1
1
+
=
Example considered next to illustrate
Noisy channel p u
Long Frame L but a
(need to consider actual numbers)
 +

+
51
Example 4
For the same system as in Example 3, if the bit error rates
of a transmitted frame are p = 10
4
and 10
5
, compare the link
efficiency for a frame size of 1000 bytes and 5000 bytes.
When L=1000 bytes = 8000 bits, we get a = 2.5
For p = 10
4
, (1 P
f
) = (110
4
)
8000
= 0.45 u = 0.075
For p = 10
5
, (1 P
f
) = (110
5
)
8000
= 0.92 u = 0.153
When L=5000 bytes = 40000 bits, we get a = 0.5
For p = 10
4
, (1 P
f
) = (110
4
)
40000
= 0.018 u = 0.009
For p = 10
5
, (1 P
f
) = (110
5
)
40000
= 0.67 u = 0.335
52
Why is StopandWait inefficient when the
propagation delay is long compared to the frame
length?
This is primarily because the StopandWait
approaches forces the system to allow only one
frame to be in transit at any given time.
Only after the frame in transit is acknowledged as
being received correctly, is the sender allowed to
transmit the next frame
Sliding Window Protocols (GoBackN ARQ and Selective
Repeat ARQ) are used for more efficient operation
53
Sliding Window
Allow multiple frames to be in transit
Receiver has buffer space for W
frames
Transmitter can send up to W frames
without ACK
Each frame is numbered
ACK includes the number of next frame
expected
Sequence number bounded by size of
field (k bits)
Frames are numbered modulo 2
k
Acknowledgment frame RR i indicates
that the i1
th
frame (and earlier
frames) received and receiver is
expecting the i
th
frame next.
1
1+2a
2 W
a
u
2 1
1
+
=
Compare with Stopand
Wait Link Efficiency!
3bit seq. no. implies
frames and ACKs are
numbered as
0,1,2,3,4,5,6,7
Cumulative
Acknowledgement
54
Sliding Window Diagram
W=7, up to 7 consecutive frames can be
sent without getting ACK
55
Example Sliding Window Protocol
Window expands by (current
ack # last Ack #) frames
Window shrinks as
frames are received
Window shrinks as
frames are sent
Buffer discards next (current
ack # last Ack #) frames
37=(3+7)7=3
43=1
43=1
Buffer saves next (current
ack # last Ack #) frames
37=(3+7)7=3
43=1
43=1
Window expands by (current
ack # last Ack #) frames
37=(3+7)7=3
Next 4 frames sent
Next 1 frame received
Next 3 frames received
56
Sliding Window Link Utilization [1]
Case 1: W2a+1; where t
frame
=1, t
prop
=a
>
1
1 2
) 1 2 (
=
+
+
=
a
a
u
Sliding Window
Link Efficiency
57
Sliding Window Link Utilization [2]
Case 2: W<2a+1; where t
frame
=1, t
prop
=a
all windowed frames exhausted
1
1 2
<
+
=
a
W
u
Sliding Window
Link Efficiency
58
Sliding Window Link Efficiency
Link utilization efficiency depends on the window size Wand
the value of a
Sliding Window link efficiency is W times more than Stop
andWait (=1/(2a+1))
+ <
+
+ >
=
1 2
1 2
1 2 1
a W
a
W
a W
u
VL
Rd
R L
V d
t
t
a
frame
prop
= = =
/
/
d:distance of link V: signal speed
L:frame Length in bits R: data rate
frame 1 ack reaches A before window exhausted
window exhausted at t=Wout of 2a+1 period
59
Sliding Window Enhancements
Receiver can acknowledge frames without permitting further
transmission (Receive Not Ready)
Flow control function
Must send a normal acknowledge (Receive Ready) to resume
If duplex, use piggybacking
Data frame includes a sequence number field used for
acknowledgement
If no data to send, use acknowledgement frame
If data but no acknowledgement to send, send last
acknowledgement number again
Acknowledgement number is required in data frame
Duplicate acknowledge is simply ignored
Transmitter
Receiver
Transmitter
Receiver
S
A
recent
R
A
next
S
B
recent
R
B
next
60
GoBackN ARQ
Keep channel busy by continuing to send frames based on
sliding window (Sending Window > 1)
If no error, ACK as usual with next frame expected
Use window to control number of outstanding frames
After transmit window is exhausted, retransmit from last
acknowledged frame (i.e. the frame after that)
When an out of sequence frame received, reject the frame
and
Discard that frame and all future (outofsequence)
frames, may send negative acknowledgment indicating the
expected frame.
Transmitter must go back and retransmit the expected
frame and all subsequent frames
Receiving Window = 1
61
GoBackN ARQ
Example: Frame 3 in error. After A exhaust its transmit
window, retransmit frame 3,4,5,6.
Rejected
Sending Window=4
62
Go Back N
Modified protocol (Optional). Send negative
acknowledgment (REJ):
Receiver detects an out of sequence frame (it
is expecting framei but gets something else)
Receiver sends rejectioni , i.e. REJi
Transmitter gets rejectioni
Transmitter retransmits frame i and all
subsequent frames which it may have in its
sending window (these are frames which have
not yet been acknowledged)
63
Frame 5, 6
GoBackN ARQ
Frame 4 lost
Transmitter sends 5 and 6
Receiver gets frame 5 out of
sequence
Receiver sends reject 4
Transmitter goes back to frame 4
and retransmits
Frame 4 lost
Frame 4, 5, 6
received
Receiver
ready for
frame 4
Reject 4
negative ack
64
Window Size of GoBackN ARQ [1]
Maximum sending window size for GoBackN ARQ with kbit
sequence number field should be 1 less than the maximum
window size
W
GobackN
(max) = 2
k
1
To see why, consider an example with W =2
k
as in the following 
3bit sequence number, window size is 8 (2
3
)
A station sends frame 0 and gets back an RR1
The station then sends frames 1,2,3,4,5,6,7,0 and gets an RR1
0 1 2 3 4 5 6 7 0 1 2
0 1 2 3 4 5 6 7 0 1 2
Sliding window at the sender
RR1
t
0
Unacknowledged frames
RR1
RR1
t
1
Frame 1,2,3,4,5,6,7,0 sent
Frames sent
Ack received
Ambiguous RR1s
65
Window Size of GoBackN ARQ [2]
What does the RR1 mean to the sender?
All frames are lost or damaged, the receiver is repeating
the previous RR1 (sent at t
0
)
All eight frames are received successfully, RR1 is
accumulated ACK (sent at t
1
)
Confusion as RR1 may indicate either of the above
To avoid the confusion limit the window size to 2
k
1
0 1 2 3 4 5 6 7 0 1 2
Unacknowledged frames
0 1 2 3 4 5 6 7 0 1 2
Sliding window at the sender
RR1
Case 1: all 2
k
1=7 frames lost Case 2: all 2
k
1=7 frames received
0 1 2 3 4 5 6 7 0 1 2
Unacknowledged frames
0 1 2 3 4 5 6 7 0 1 2
Sliding window at the sender
RR0
RR1
RR1
66
SelectiveRepeat ARQ
Also called Selective Reject
Only rejected frames are retransmitted
Subsequent frames are accepted by the receiver and
buffered
Minimizes retransmission
Receiver must maintain large enough buffer
More complex logic in transmitter and receiver
67
SelectiveRepeat ARQ
Retransmit only the frame in error.
Store out of sequence frames in receiver buffer.
After the error frame is received correctly pass
everything to receiver.
68
Window Size for SelectiveRepeat ARQ [1]
Window size is more restrictive than GoBackN ARQ
Overlap between sending and receiving windows
Window size should be no more than half the range of
sequence numbers
k: the number of bits in the sequence number field
Maximum window size for SelectiveRepeat ARQ is
W
SelectiveRepeat
(max) =2
k1
Important: Notice that maximum window size is less than that
with GoBackN ARQ (see example in next slide)
69
Window Size for SelectiveRepeat ARQ [2]
Consider the following scenario:
3bit sequence field, window size 7 (e.g. like GoBackN)
A sends frames 0 through 6 to B
B receives all the 7 frames and acks with RR7, but RR7 is
lost
A times out and resends frame 0
B thinks frame 7 is lost and frame 0 is the new frame,
and accepts it
Confusion: caused due to overlap between the sending
and receiving windows
3 4 5 6 7
Sending window at A Receiving window at B
0,,6
RR7
0
RR7
X
0 1 2 3 4 5 6 7 0 1 2 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
70
Window Size for SelectiveRepeat ARQ [3]
Example:
A can send a maximum of 4 frames, say 0 through 3
B receives all the 4 frames and advances receiving window for next
4 frames from frame 4 (i.e. frames 4, 5, 6, 7)
B sends RR4
if RR4 is lost, A resends frame 0 after time out
Frame 0 is outside the receiver window and therefore is discarded
If RR4 is received, A send the next sequence of frames from frame 4
No overlap of sending and receiving windows
Sending window at A Receiving window at B
0,1,2,3
RR4
0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 0 1 2
RR4
X
0 X
4 to 7
4 to 7
Solution: Limit window size to no more than half the range of
sequence numbers, i.e. 2
k1
(e.g. max. window size = 4 for k=3)
71
Highlevel Data Link Control
HDLC High Level Data Link Control (ISO 3009
& ISO 4335)
Provides unified data link control protocols
Format structure, mechanisms
Three types of stations
Two link configurations
Three data transfer modes of operation
72
HDLC Station Types
Primary station
Controls operation of link
Frames issued are called commands
Maintains separate logical link to each secondary station
Secondary station
Under control of primary station
Frames issued called responses
Combined station
May issue commands and responses
73
HDLC Link Configurations
Unbalanced
One primary and one or more secondary
stations
Supports full duplex and half duplex
Balanced
Two combined stations
Supports full duplex and half duplex
Full Duplex: Separate links in both directions, both sides can transmit
simultaneously
Half Duplex: One bidirectional link, can be used in either direction but not
simultaneously
74
HDLC Transfer Modes [1]
Normal Response Mode (NRM)
Unbalanced configuration
Primary initiates transfer to secondary
Secondary may only transmit data in response to
command from primary
Used on multidrop lines
Host computer as primary
Terminals as secondary
Host polls each terminal
Sometimes used in pointtopoint link (with one station
identified as primary, the other as secondary)
command
Response on demand
75
HDLC Transfer Modes [2]
Asynchronous Balanced Mode (ABM)
Balanced configuration
Either station may initiate transmission without receiving
permission
Most widely used
No polling overhead
Command and response
76
HDLC Transfer Modes [3]
Asynchronous Response Mode (ARM)
Unbalanced configuration
Secondary may initiate transmission without permission
form primary
Primary responsible for line initialization, error recovery,
disconnection
rarely used
command
Respond unilaterally
77
HDLC Frame Structure
Synchronous transmission
All transmissions in frames
Single frame format for all data and control exchanges
78
Flag Fields
Delimits frame at both ends
01111110 (Flag)
May close one frame and open another
Receiver hunts for flag sequence to synchronize
Bit stuffing used to avoid confusion with data containing
01111110; referred as data transparency
0 inserted after every sequence of five 1s
If receiver detects five 1s, it checks next bit (sixth bit)
If 0, it is deleted
If 1 and seventh bit is 0, accept as FLAG
If sixth and seventh bits 1, sender is indicating ABORT
01111111
01111110
011111010
011111010 x
Xmitter
Rcvr
Xmitter send ABORT 0111111 when it wants to abort its transmission
79
Bit Stuffing and Pitfalls
Flag pattern in data bits
Data with bit stuffing
data
data
80
Address Field
Identifies secondary station that send or will receive frame
Usually 8 bits long
May be extended to multiples of 7 bits
LSB of each octet indicates that it is the last octet (1)
or not (0)
All ones (11111111) is broadcast address
81
Control Field
Control field defines three types of frames
Information (I)  data to be transmitted to user (next
layer up); ARQ control data are piggybacked
Supervisory (S) provides ARQ when piggyback is not
used, ACK I Frames. Flow Control, Request Retransmit
Unnumbered (U)  supplementary link control, transfer
unnumbered frames
First one or two bits of control field identify frame type
82
Control Field Diagram
 extended mode
83
Poll/Final Bit
Use depends on context
Command frame (from Primary)
P/F = 1 to solicit (poll) response from secondary
Response frame (from Secondary)
Secondary responds to poll from Primary by
sending one or more frames to it
P/F = 1 to indicate the response to these frames
84
Information Field
Only in information and some unnumbered frames
Must contain integral number of octets
Variable length
Frame Check Sequence Field
FCS
Error detection
16 bit CRC
Optional 32 bit CRC
85
HDLC Operation
Exchange of information, supervisory and
unnumbered frames
Three phases
Initialization
Data transfer
Disconnect
86
HDLC Operation  Initialization
Initialization may be requested by either side
by issuing a setmode command
Signals that initialization is requested
Specifies which of the three modes (NRM,
ABM, ARM) is requested
Specifies whether 3 or 7bit sequence
numbers are to be used
The other side sends an unnumbered ack (UA)
frame back to accept the request
If the request is rejected, then a
disconnected mode (DM) frame is sent back
(instead of a UA)
SABME:set ABM/extended mode
87
HDLC Operation Disconnect
One side issues a DISC command,
the other responds with an UA
(unnumbered acknowledgement)
response
When it times out, the originator
repeats the SABME, until a UA or DM
is received or after a given number of
tries, the originator gives up and
reports failure to management.
88
HDLC Operation Data Transfer
N(S): sequence number of the frame
N(R): ack for Iframes received, indicating the expected I
frame
When there is no
incoming data, the
N(R) is repeated
ACK is piggybacked on
I frame
Cumulative ACK
When there is no
outgoing data,
supervisory frame
is sent to convey
the cumulative ACK
0
1
2
3
0
1
2
3
89
HDLC Operation Busy Condition
A is busy, asking B
to halt transmission
of I frames
RNR: Receive not
ready
B polls A periodically,
requiring A to reply
with RNR or RR
When busy condition
clears, A replies with
RR
Iframes
transmission from B
can now resume
Frame 4 is the
next frame
90
HDLC Operation Reject Recovery
Iframe 5 is out of
order
Iframe 4 is lost
REJ initiates GobackN
ARQ
Retransmitting all I
frames, beginning with
frame 4
91
HDLC Operation Timeout Recovery
Frame 3 is the last I
frame from A
B detects error in the
frame, discard it
B does not send any ack
to A
When A times out, it
polls B by sending the RR
frame with P bit set
B replies with the N(R)
number
Here 3 indicates frame
3 is lost Now A can proceed