Communication Networks
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 erroris 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 1’s – if at the receiver the codeword is 1101110 0, odd number
of 1’s 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
Even
Par
ity
6
(Even) Parity Check using Modulo 2 Addition
• Append an overall parity check to k information bits
Info Bits: b1, b2, b3, …, bk
Check Bit: bk+1= b1+ b2+ b3+ …+ bk modulo 2
Codeword: (b1, b2, b3, …, bk,, bk+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 even-numbered 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 0’s elsewhere– Of 2k+1 binary (k + 1)-tuples, ½ are odd, so 50% of
error patterns can be detected – For random error vector channel model, all 2k +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 codes00 001 110 111 0
2+1 tuple error
vectors00 101 001 110 010 111 011 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] = p2(1 – p)6 = (1 – p)8
p1 – p
p 21 – 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(1-p) j≈ p i(1-p 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]
= p2(1 – p)n-2 + p4(1 – p)n-4 + …n2
n4
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)
322
324
10
x = codewordso = non-codewords
x
x x
x
x
x
x
oo
ooo
ooo
ooo
o
ox
x xx
xxx
o ooo
oooooo
o Poordistance
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 n-tuple
• If codewords close to each other then detection failures will occur
• Good codes should maximize separation between codewords
Gooddistance
properties
11
Two-Dimensional 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 errorsOne error
Three errors
Four errors (undetectable)
Error-detecting capability
1, 2, or 3 errors canalways be detected.Not all patterns of 4errors or more can bedetected
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• Two-dimensional 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, 16-bit words, b0, b1, b2, ..., bL-1
• The algorithm appends a 16-bit checksum bL
15
The checksum bL is calculated as follows:• Treating each 16-bit word as an integer, find
x = b0 + b1 + b2+ ...+ bL-1 modulo 216-1• The checksum is then given by:
bL = - x modulo 216-1Thus, the headers must satisfy the following pattern:
0 = b0 + b1 + b2+ ...+ bL-1 + bL modulo 216-1 • The checksum calculation is carried out in software
using one’s complement arithmetic
Internet Checksum Calculation
123
4
56 7
0-2
10
10 mod 7 = 3-2 mod 7 = 5
16
Internet Checksum Example(A simple one, using 4-bit words and mod 24-1 arithmetic)
Using mod 15 arithmetic• b0=1100 = 12• b1=1010 = 10• b0+b1=(12+10) mod 15 = 7• b2 = -7 mod15 = 8 • Therefore, b2=1000
Using Binary Arithmetic• Note that 16 mod15 = 1• So: 10000 mod15 = 0001
(i.e. leading bit wraps around)b0 + b1 = 1100+1010
=10110=10000+0110=0001+0110=0111=7
Take 1s complement to findb2 = - 0111 =1000
x mod y residue of x/y
-x mod y y – x
1100 121010 10
10110 221 -15
- 0111 071000 08
Binary Mod
11001010
101101
- 01111000
If b0=1100, b1=1010, what is their Internet Checksum b2?
Don’t take this example too seriously as it uses only 4-bit words for simplicity! Real Internet checksum calculations (shown next) uses 16-bit words.
17
Internet Checksum Example(A more complex one, using 16-bit words and mod 216-1 arithmetic)
Using mod 216-1=65535 arithmetic• b0=1000 0001 1011 1100 = 81BCH = 33212 • b1=0100 1000 0101 1010 = 485AH = 18522• b0+b1=(33212+18522) mod 65535 = 51734• b2 = - 51734 mod 65535 = 65535-51734 = 13801 = 35E9H
• Therefore, b2 = 0011 0101 1110 1001
If b0=1000 0001 1011 1100
& b1=0100 1000 0101 1010
What will be their Internet Checksum b2?
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
error-correction methods
19
Addition of Polynomials:
Multiplication of Polynomials:
Binary Polynomial Arithmetic
Mapping Binary Vectors to Polynomials:
(ik-1 , ik-2 ,…, i2 , i1 , i0) ik-1xk-1 + ik-2xk-2 + … + i2x2 + i1x + i0
(x7 + x6 + 1) + (x6 + x5) = x7 + x6 + x6 + x5 + 1
= x7 +(1+1)x6 + x5 + 1
= x7 +x5 + 1
(x + 1) (x2 + x + 1) = x(x2 + x + 1) + 1(x2 + x + 1)
= (x3 + x2 + x) + (x2 + x + 1)
= x3 + 1
Modulo 2 is bin XOR0 + 0 = 0 1 + 1 = 01 + 0 = 1 0 + 1 = 1
(1 0 1 1 0 1 0 1) x7 + x5 + x4 + x2 + 1
20
Binary Polynomial Division
Recall how you do Division with Decimal Numbers
32
35 ) 12223
105172
4
140divisor
quotient
remainder
dividend1222 = 34 x 35 + 32
dividend = quotient x divisor +remainder
Polynomial Divisionx3 + x + 1 ) x6 + x5
x6 + x4 + x3
x5 + x4 + x3
x5 + x3 + x2
x4 + x2
x4 + x2 + xx
q(x) quotient
r(x) remainder
divisordividend
+ x+ x2x3
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 framecheck sequence (FCS). These n-k bits are generated in such away that the binary polynomial T(x) corresponding to the n bitsequence 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 - kk
22
CRC FormulationDefine,
T = n-bit frame to be transmittedD = k-bit data block, the first k bits of TF = (n-k)-bit FCS, the last (n-k) bits of TP = pattern of (n-k+1) bits; predetermined divisor; high- and low-order bits must be 1
For T/P to have no remainder, T is generated in the following formT = 2n-kD + F ; D is left shifted by n-k bits, and F suitably chosen
Now suppose,2n-kD/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 PT = 2n-kD + 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 error-freeElse, T’ is declared to have one or more bits in error
Binary exclusive-OR (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 25, 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) = x9 x7+x3+x2+1 degree ≤ k-1– P = 110101 P(x) or g(x) = x5+x4+x2+1 degree= n-k
• D multiplied by 25 is equivalent to x5D(x) – x5D(x) = x14 +x12+x8+x7+x5
CRC formulation expressedin polynomials P(x)
R(x)Q(x)P(x)
D(x)X k-n
R(x)D(x)xT(x) kn degree ≤ n-1
= x14+x12+x8+x7+x5+x3+x2+x 101000110101110
degree ≤ n-1
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 xi is 1 if ith bit is in errorReceived 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)=xi) 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 anodd 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)=xi+xj+xk can never exactly divide E(x)=xk
(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 xm+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)= xi+xj = (xi-j+1)xj
where (i-j)<n since there are only n bits in the codeword
•A CRC code with (n-k) check bits will detect all error bursts of length (n-k) or less.
These burst error patterns will be polynomials of degree (n-k-1) or less and cannot be divided exactly by g(x), since g(x) is a polynomial of higher degree, i.e. (n-k)
• Most longer bursts are also detected by the CRC code
Example: x15+ x14+1 will not divide any xk+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)Pn(x)
• The factor (1+x) ensures that all odd errors will be detected
• The factor Pn(x) is chosen such that it does not exactly divide any (1+xm) for m<n. This ensures that all double errors in an n-bit codeword will always be detected
A good choice for Pn(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 xn + 1 is n = 2m − 1
31
Choosing a Good Generator Polynomial g(x)
Example:
Consider the CRC-5 (ITU) generating function g(x)=x5+x4+x2+1
g(x) = x5+x4+x2+1 = (1+x)(1+x+x4)
Note that (1+x+x4) is a primitive polynomial which will not exactly divide (1+x), (1+x2), (1+x3)………(1+x14) but will exactly divide (1+x15)
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
CRC-8 x8+x2+x+1 ATM header error check
CRC-10 x10+x9+x5+x4+x+1 ATM AAL CRC
CRC-12 x12+x11+x3+x2+x+1 Bisync
CRC-16 x16+x15+x2+1 Bisync
CCITT-16 x16+x12+x5+1 DHLC, XMODEM, V.41 IEEE 802, DoD, V.42, AAL5
CRC-32 x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+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, wire-like• Losses & errors, but no out-of-
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 LinkLayer
Physicallayer
Physicallayer
Data LinkLayer
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
0110110111
Framing
receivedframes
0111
1101
01transmitted
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 frameFCS is the Frame Check Sequence to report if frame has errors
Flag FlagAddress Control Information FCS
HDLC frame
variable number of bits
011111010011111010x
38
Error Detection
Additional bits added by transmitter for error detection, such as
1. Even/Odd ParityValue 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 error-free 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
Stop-and-Wait
• Without error
ACK
ACK
ACK
ACK
42
Stop-and-Wait ARQ with Frame Loss
• With frame loss
Frame lost
43
Stop-and-Wait ARQ with ACK Loss [1]
• Without frame and ACK sequence number
frame receivedAcknowledgement frame damaged
Duplicate frame undetected
44
Stop-and-Wait 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
Stop-and-Wait Link Utilization [1]Let,
L = length of the frame in bitsR = data rate of the link, bpsd = length or distance of the link in metersV = 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 efficiencyLBa
VdRB
LB
dV
R
where d/V is propagation time
46
Stop-and-Wait Link Utilization [2](Transmission time = 1; propagation time = a)
underutilized
underutilizedunderutilized
Time intervals normalized to the frame length
47
Stop-and-Wait Link Efficiency [1]The time to send 1 frame and receive an acknowledgement
TF = tframe + tprop+ tproc + tack + tprop + tproc
Assume tproc and tack are negligible, the time to send a message containing n frames is
T =n(2 tprop + tframe)
Only n tframe is actually spent transmitting data. Hence, maximum possible utilization (or efficiency) of the link is
Define , then ; smaller a higher link efficiency
frameprop
frame
frameprop
frame
ttt
ttntn
u
2)2(
au
211
frame
prop
tta
1
1+2a
48
Propagation Time, tprop= d/V d: distance of link in metersV : signal speed, 2.0 108 m/s for fiber and copper media
Transmission Time, tframe= L/RL: 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
Stop-and-Wait Link Efficiency [2]
VLRd
RLVd
ttaframe
prop
//
au
211
LB
dV
R
Effective data transmission rate across nodes = u x R
49
Link Efficiency in Presence of Transmission Errors (Stop-and-Wait)
Let Pf = probability that a frame arrives with errorsthen, 1 – Pf = probability a frame arrives w/o errors
If Nr is the number of expectedtransmission per frame, then
If we assume that ACKs are never in error, then the probability thatit will take k attempts to transmit a frame successfully is Pf
k-1(1-Pf).In that case, we will have (k-1) unsuccessful attempts followed byone successful attempt. The expected number of transmission isthen -
)2( framepropr
frame
ttNt
u
fif
if
irr
PPPi
onstransmissiiPionstransmissiEN
11))1((
))((][
1
1
1
50
Link Efficiency in Presence of Transmission Errors (Stop-and-Wait)
Therefore, for a Stop-&-Wait system a
Pu f
211
For a channel with bit error probability p, the probability that a L bit frame is error-free will be (1-p)L.
Hence, Pf = 1 - (1-p)L
a
puL
211
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 ratesof a transmitted frame are p = 10-4 and 10-5, compare the linkefficiency 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 – Pf) = (1–10-4)8000 = 0.45 u = 0.075
For p = 10-5 , (1 – Pf) = (1–10-5)8000 = 0.92 u = 0.153
When L=5000 bytes = 40000 bits, we get a = 0.5
For p = 10-4 , (1 – Pf) = (1–10-4)40000 = 0.018 u = 0.009For p = 10-5 , (1 – Pf) = (1–10-5)40000 = 0.67 u = 0.335
52
Why is Stop-and-Wait inefficient when the propagation delay is long compared to the frame
length?
This is primarily because the Stop-and-Waitapproaches forces the system to allow only oneframe to be in transit at any given time.
Only after the frame in transit is acknowledged asbeing received correctly, is the sender allowed totransmit the next frame
Sliding Window Protocols (Go-Back-N 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 2k
• Acknowledgment frame RR i indicatesthat the i-1th frame (and earlier frames) received and receiver is expecting the ith frame next.
1
1+2a
2W●●●
au
211
Compare with Stop-and-Wait Link Efficiency!
3-bit seq. no. implies frames and ACKs are
numbered as 0,1,2,3,4,5,6,7Cumulative
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
3-7=(3+7)-7=3
4-3=1
4-3=1
Buffer saves next (current ack # – last Ack #) frames
3-7=(3+7)-7=3
4-3=1 4-3=1
Window expands by (current ack # – last Ack #) frames
3-7=(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 tframe=1, tprop=a
112)12(
aau
Sliding Window Link Efficiency
57
Sliding Window Link Utilization [2]
Case 2: W<2a+1; where tframe=1, tprop=a
all windowed frames exhausted
112
aWu
Sliding Window Link Efficiency
58
Sliding Window Link Efficiency
• Link utilization efficiency depends on the window size W and the value of a
• Sliding Window link efficiency is W times more than Stop-and-Wait (=1/(2a+1))
1212
121
aWaW
aWu
VLRd
RLVd
tt
aframe
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=W out 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 ReceiverTransmitterReceiver
SArecent RA
next
SBrecent RB
next
60
Go-Back-N 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 (out-of-sequence)
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
Go-Back-N 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 frame-i but gets something else)– Receiver sends rejection-i , i.e. REJ-i– Transmitter gets rejection-i– 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
Go-Back-N 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 Go-Back-N ARQ [1]
Maximum sending window size for Go-Back-N ARQ with k-bit sequence number field should be 1 less than the maximum window size
WGo-back-N (max) = 2k-1
To see why, consider an example with W =2k as in the following -• 3-bit sequence number, window size is 8 (23)• 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
t0
Unacknowledged frames
RR1 RR1t1Frame 1,2,3,4,5,6,7,0 sent
Frames sent
Ack received
Ambiguous RR1’s
65
Window Size of Go-Back-N 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 t0)– All eight frames are received successfully, RR1 is
accumulated ACK (sent at t1)– Confusion as RR1 may indicate either of the above
• To avoid the confusion limit the window size to 2k-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 2k-1=7 frames lost Case 2: all 2k-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
RR0RR1RR1
66
Selective-Repeat 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
Selective-Repeat 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 Selective-Repeat ARQ [1]
Window size is more restrictive than Go-Back-N 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 Selective-Repeat ARQ is
WSelective-Repeat(max) =2k-1
Important: Notice that maximum window size is less than that with Go-Back-N ARQ (see example in next slide)
69
Window Size for Selective-Repeat ARQ [2]
Consider the following scenario:– 3-bit sequence field, window size 7 (e.g. like Go-Back-N)– 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,…,6RR7
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 Selective-Repeat 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,3RR4
0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3 4 5 6 7 0 1 2
RR4 X
0X 4 to 7
4 to 7
Solution: Limit window size to no more than half the range of sequence numbers, i.e. 2k-1 (e.g. max. window size = 4 for k=3)
71
High-level 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 bi-directional 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 point-to-point 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
011111010x
Xmitter
R’cvr
X’mitter 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 framesFirst 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 set-mode command
– Signals that initialization is requested
– Specifies which of the three modes (NRM, ABM, ARM) is requested
– Specifies whether 3- or 7-bit 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 I-frames 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
23
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 I-frames
transmission from B can now resume
Frame 4 is the next frame
90
HDLC Operation – Reject Recovery
I-frame 5 is out of order
I-frame 4 is lost
REJ initiates Go-back-N ARQRetransmitting 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 lostNow A can proceed