The Data Link Layer
-
Upload
robbbminson -
Category
Education
-
view
7.951 -
download
14
description
Transcript of The Data Link Layer
![Page 2: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/2.jpg)
Computer Networks 2 of 52
Data Link Layer Overview
![Page 3: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/3.jpg)
Computer Networks 3 of 52
Data Link Layer Overview
• Error Control– Correction and Detection Schemes– Framing– Flow Control
• Medium Access
![Page 4: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/4.jpg)
Computer Networks 4 of 52
Errors in the Physical Layer
• Noise
![Page 5: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/5.jpg)
Computer Networks 5 of 52
Errors in the Physical Layer
• Noise– Near End Cross-Talk (NEXT)
=
![Page 6: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/6.jpg)
Computer Networks 6 of 52
Errors in the Physical Layer
• Attenuation– Can we distinguish between power levels
with enough accuracy?
![Page 7: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/7.jpg)
Computer Networks 7 of 52
Errors in the Physical Layer
• Attenuation
![Page 8: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/8.jpg)
Computer Networks 8 of 52
Errors in the Physical Layer
• Distortion
![Page 9: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/9.jpg)
Computer Networks 9 of 52
Error ControlCorrection and Detection
Schemes
![Page 10: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/10.jpg)
Computer Networks 10 of 52
Error Control
• Split binary data stream in to words– Each word is m bits long– Add r extra bits in special, known
positions– The r bits can be examined by the
receiver to• Detect if bits have been incorrectly flipped• Locate and correct the flipped bits
– The r bits are then removed and the m-bit data word is delivered
![Page 11: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/11.jpg)
Computer Networks 11 of 52
Error Detection with Parity Bits
• A Parity Bit makes the number of 1’s in a word even, e.g. if m = 3 and r = 1
000001010011100101
111
000000110101011010011010
1111110 1100
![Page 12: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/12.jpg)
Computer Networks 12 of 52
Error Detection with Parity Bits
• A Parity Bit makes the number of 1’s in a word even, e.g. if m = 3 and r = 1
0011
parity check OK
000001010011100101
111
000000110101011010011010
1111110 1100
![Page 13: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/13.jpg)
Computer Networks 13 of 52
Error Detection with Parity Bits
• A Parity Bit makes the number of 1’s in a word even, e.g. if m = 3 and r = 1
0111
error detected!parity check not OK
000001010011100101
111
000000110101011010011010
1111110 1100
![Page 14: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/14.jpg)
Computer Networks 14 of 52
Error Detection with Parity Bits
• A Parity Bit makes the number of 1’s in a word even, e.g. if m = 3 and r = 1
1111
error missed!!!parity check OK
000001010011100101
111
000000110101011010011010
1111110 1100
![Page 15: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/15.jpg)
Computer Networks 15 of 52
Error Detection with Parity Bits
• Parity Bits detect single-bit errors in a given data word– m can be arbitrarily large– But if 2 bits are flipped instead of one
the parity check will pass and an error will be missed
– Larger m increases likelihood of this
![Page 16: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/16.jpg)
Computer Networks 16 of 52
Hamming Theory
• For any values of m and r we can say some things about a given hypothetical code– A scheme produces 2m+r receivable words– 2m will be valid words– 2m+r – 2m will be invalid words
• An error detection scheme can tell the difference between a valid and an invalid word
• An error correction scheme can work out which of the 2m valid words an invalid word must have been upon transmission.
![Page 17: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/17.jpg)
Computer Networks 17 of 52
Hamming Theory
• Some number of bit-flips = d will change a valid word in to another valid word– d is the hamming distance of the code– e.g. Our 4-bit parity scheme required just two
flips to go from one valid word to another, d = 2
– An error detection scheme to detect ≤ d errors must have a hamming distance = d+1
– Why…?
![Page 18: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/18.jpg)
Computer Networks 18 of 52
Hamming Theory
• An error detection scheme to detect ≤ d errors must have a hamming distance = d+1
with distance2, if 1 error
occurs we willalways receivean invalid word
000000110101011010011010
11111100
000100100100011110001011
11101101
![Page 19: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/19.jpg)
Computer Networks 19 of 52
Hamming Theory
• To correct single errors, an m-bit scheme must have r bits such that:
(m + r + 1)2m ≤ 2m+r
• Why?
![Page 20: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/20.jpg)
Computer Networks 20 of 52
Hamming Theory
• Explanation 1 (Reserve Invalid Words):– We have 2m valid words (see our 4-bit parity
code)– For each one, take each bit in turn and flip it– This generates m+r invalid words
0000
1000
0100
0010
0001
![Page 21: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/21.jpg)
Computer Networks 21 of 52
Hamming Theory
• Explanation 1 (Reserve Invalid Words):– In total there are 2m+r
- 2m invalid words
– Each has distance = 1 from a valid original– The receiver will always be able to correct to
the valid original if it receives one of these words, because no other valid word is within distance = 1
– (This is the fundamental principle of error correcting codes)
![Page 22: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/22.jpg)
Computer Networks 22 of 52
Hamming Theory
• Explanation 1 (Reserve Invalid Words):– Because we need to keep this property, each
valid word ‘reserves’ m+r invalid words– The total number of possible words is 2m+r
– Therefore:2m + (m+r)2m ≤ 2m+r
the words invalid words reserved by them
all valid words +total words
available≤
2m + (m+r)2m = (m+r+1)2m
![Page 23: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/23.jpg)
Computer Networks 23 of 52
Hamming Theory
• Explanation 2 (Encode Enough Positions)– Start by rearranging the equation a bit:
(m+r+1)2m ≤ 2m+r
(m+r+1) ≤ 2r (divide both sides by 2m)
– 2r is the number of distinct words we can make out of the r parity bits.
– In order to correct errors, the parity word must tell us both• if an error has occurred• if one has, which bit position is wrong
![Page 24: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/24.jpg)
Computer Networks 24 of 52
Hamming Theory
• Explanation 2 (Encode Enough Positions)– To do this, we need to have ‘parity words’ for
• No error,• Error in position 1• Error in position 2• …• Error in position m+r
– Therefore 2r must be able to express this many positions, and so
(m+r) + 1 ≤ 2r
(That is, we must have enough parity ‘words’ to express ‘error’ in each bit position + 1 word for ‘no errors’)
![Page 25: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/25.jpg)
Computer Networks 25 of 52
Hamming Codes
• Optimal error correction for single-bit errors– Use multiple parity bits (r > 1)– Each parity bit checks a subset of the data
bits– Cross check which parities are wrong to
determine which data bit has been flipped
• Central idea:– The set of parity bits describe the position of
the incorrect bit
![Page 26: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/26.jpg)
Computer Networks 26 of 52
Hamming Codes
• A Simple Code– m = 4– r = 3
• r1 checks m1, m2, m3• r2 checks m2, m3, m4• r3 checks m1, m2, m4
0 0 0 0 0 0 0r1 m1 m2 r2 m3 m4 r3
![Page 27: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/27.jpg)
Computer Networks 27 of 52
Hamming Codes
• An Example:– For the given data bits ‘0011’– What should our 3 parity bits be?
? 0 0 ? 1 1 ?r1 m1 m2 r2 m3 m4 r3
r1 m1 m2 m3
r3 m1 m2 m4
r2 m2 m3 m4
![Page 28: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/28.jpg)
Computer Networks 28 of 52
Hamming Codes
• Another Example:– For the given data bits ‘1010’– What should our 3 parity bits be?
? 1 0 ? 1 0 ?r1 m1 m2 r2 m3 m4 r3
r1 m1 m2 m3
r3 m1 m2 m4
r2 m2 m3 m4
![Page 29: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/29.jpg)
Computer Networks 29 of 52
Hamming Codes
• An Example:– Flip any one data bit and at least two
parity bits will be incorrect– Each data bit is checked by a different
set of parity bits, so we always know which one was flipped
0 1 0 1 1 0 1r1 m1 m2 r2 m3 m4 r3
r1 m1 m2 m3
r3 m1 m2 m4
r2 m2 m3 m4
![Page 30: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/30.jpg)
Computer Networks 30 of 52
Hamming Codes
• An Example:– The pattern of correct/incorrect in the
parity bits form parity words– Each unique parity word describes the
position of the error in the data word
r1 m1 m2 m3
r3 m1 m2 m4
r2 m2 m3 m4
r1 r2 r3 error bitm1
m2
m3
m4
![Page 31: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/31.jpg)
Computer Networks 31 of 52
Hamming Codes
• But isn’t there a problem here…?– r1 checks m1, m2, m3
– r2 checks m2, m3, m4
– r3 checks m1, m2, m4
0 0 0 0 0 0 0r1 m1 m2 r2 m3 m4 r3
![Page 32: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/32.jpg)
Computer Networks 32 of 52
Hamming Codes
• But isn’t there a problem here…?– r1 checks m1, m2, m3
– r2 checks m2, m3, m4
– r3 checks m1, m2, m4…– …so who checks r1,2,3?
0 0 0 0 0 0 0r1 m1 m2 r2 m3 m4 r3
![Page 33: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/33.jpg)
Computer Networks 33 of 52
Hamming Codes w/ Logarithmic Parity
• In a real Hamming code, the r bits are in positions 20, 21, 22,…,2i
• They check the data bits, but they also check each other…
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8 m9 m10 m11 r5 m12
![Page 34: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/34.jpg)
Computer Networks 34 of 52
Hamming Codes w/ Logarithmic Parity
• Each bit has its position expressed as a sum of powers of 2– e.g. m4 in position 7 = 4 + 2 + 1 = 22 +
21 + 20
– A position is checked by the parity bits in the positions used to calculate its sum
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8 m9 m10 m11 r5 m12
![Page 35: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/35.jpg)
Computer Networks 35 of 52
Hamming Codes w/ Logarithmic Parity
0 0 0 0 0 0 0 0 0 0 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 2 3 4 5 6 7 8 9 10 11 12
![Page 36: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/36.jpg)
Computer Networks 36 of 52
Hamming Codes w/ Logarithmic Parity
? ? 0 ? 0 1 0 ? 1 1 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 2 3 4 5 6 7 8 9 10 11 12
![Page 37: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/37.jpg)
Computer Networks 37 of 52
Hamming Codes w/ Logarithmic Parity
1 0 0 1 0 1 0 0 1 1 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 2 3 4 5 6 7 8 9 10 11 12
![Page 38: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/38.jpg)
Computer Networks 38 of 52
Hamming Codes w/ Logarithmic Parity
1 0 0 1 1 1 0 0 1 1 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 2 3 4 5 6 7 8 9 10 11 12
• error in m2…
• …parity incorrect for r1 and r3
![Page 39: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/39.jpg)
Computer Networks 39 of 52
Hamming Codes w/ Logarithmic Parity
1 0 0 1 0 1 0 0 1 0 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 2 3 4 5 6 7 8 9 10 11 12
• error in m6…
• …parity incorrect for r2 and r4
![Page 40: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/40.jpg)
Computer Networks 40 of 52
Hamming Codes w/ Logarithmic Parity
1 2 3 4 5 6 7 8 9 10 11 12
r1 (1)
r2 (2)
r3 (4)
r4 (8)
1 0 0 1 0 1 0 1 1 1 0 0 r1 r2 m1 r3 m2 m3 m4 r4 m5 m6 m7 m8
1 2 3 4 5 6 7 8 9 10 11 12
• error in r4…
• …parity incorrect for r4
![Page 41: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/41.jpg)
Computer Networks 41 of 52
Hamming codes w/ Logarithmic Parity
• General case…– Iterate over each parity bit…– If the bit is not in correct parity, add the
value of its position to a counter…– At the end…
• …if the counter == 0 there are no errors• …else, the counter’s value indicates the
incorrect position• Why?
– Because it is a sum of the incorrect parity positions– NOTE! Each position is described by a unique sum
![Page 42: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/42.jpg)
Computer Networks 42 of 52
Hamming codes w/ Logarithmic Parity
• Example:
0 1 0 1 0 1 0 r1 r2 m1 r3 m2 m3 m4
1 2 3 4 5 6 7
• Iterate over each parity bit…• If the bit is not in correct parity, add the value of
its position to a counter…• At the end…
– …if the counter == 0 there are no errors– …else, the counter’s value indicates the
incorrect position
1 = 12 = 23 = 1 + 24 = 4
5 = 4 + 16 = 4 + 27 = 4 + 2 +
1
![Page 43: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/43.jpg)
Computer Networks 43 of 52
Hamming codes w/ Logarithmic Parity
• Example:
0 0 0 1 0 0 1 r1 r2 m1 r3 m2 m3 m4
1 2 3 4 5 6 7
• Iterate over each parity bit…• If the bit is not in correct parity, add the value of
its position to a counter…• At the end…
– …if the counter == 0 there are no errors– …else, the counter’s value indicates the
incorrect position
1 = 12 = 23 = 1 + 24 = 4
5 = 4 + 16 = 4 + 27 = 4 + 2 +
1
![Page 44: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/44.jpg)
Computer Networks 44 of 52
Hamming Code Summary
• Hamming codes correct single bit errors in a given data word– Embed r parity bits at positions 20, 21, 22, …– Each parity bit checks a unique subset of
the other bit positions (and itself)– If a single bit error occurs a unique
combination of the parity bits will be incorrect
– This unique combination is used to locate and correct the flipped bit
![Page 45: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/45.jpg)
Computer Networks 45 of 52
Cyclic Redundancy for Error Detection
• Based on factorisation of numbers– M/G = P + R/G
• A division produces a result P and a remainder R
– M÷G = R• The modulo operation gives just R• e.g. 26÷8 = 2
– (M-R)/G = P + 0/B• The difference between a dividend and a
remainder can always be factorised by the divisor
• e.g. (26-(26÷8))/8 = (26-2)/8 = 24/8 = 3 + 0/8
• Therefore, (M-R)÷G = 0
![Page 46: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/46.jpg)
Computer Networks 46 of 52
Cyclic Redundancy for Error Detection
• Based on modulo operation– Choose any other value for R in the
formula (M-R)/G• What is the probability of the result having a
0 remainder?– (26-3)/8 = 23/8 = 2 + 7/8– (26-1)/8 = 25/8 = 3 + 1/8– (26-10)/8 = 16/8 = 2 + 0/8
• i.e. How far do we have to change M to get to another number that can be factorised by G?
![Page 47: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/47.jpg)
Computer Networks 47 of 52
Cyclic Redundancy for Error Detection
• How does CRC use this idea?– Agree a value of G beforehand– For a given data frame M
• Calculate R = M÷G
• Send M – R
– If the received frame has a non-zero remainder when divided by G, errors have occurred
![Page 48: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/48.jpg)
Computer Networks 48 of 52
Error Detection with CRC
• Cyclic Redundancy Checking (CRC)– Uses polynomial division instead of binary– Binary string represents a polynomial– arithmetic is performed modulo 2
0 1 1 0 0x3 + 1x2 – 1x1 + 0x0=
1 0 1 0 0 1 1x5 + 0x4 - 1x3 + 0x2 + 0x1 - 1x0=
– NOTE! the arithmetic is modulo 2 so 0 = 0, 1 = 1, 2 = 1, 3 = 0….but also -1 = 1, -2 = 0, etc…
![Page 49: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/49.jpg)
Computer Networks 49 of 52
Error Detection with CRC
• Subtraction of two polynomials == binary XOR operation:
0 1 1 0
- 0 1 1 1
= 0 0 0 1
0x3 + 1x2 - 1x1 + 0x0
- 0x3 + 1x2 - 1x1 + 1x0
= 0x3 + 0x2 + 0x1 - 1x0=
1 0 1 0 0 1
- 0 0 1 1 0 0
= 1 0 0 1 0 1
1x5 + 0x4 - 1x3 + 0x2 + 0x1 - 1x0
- 0x5 + 0x4 + 1x3 + 1x2 + 0x1 + 0x0
= 1x5 + 0x4 - 2x3 - 1x2 + 0x1 - 1x0
=
NOTE! because arithmetic is modulo 2, the -2x4 above becomes a 0 in the binary representation…everything is
simple xOR
![Page 50: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/50.jpg)
Computer Networks 50 of 52
Error Detection with CRC• Division of two polynomials = binary
division (with XOR subtraction)
![Page 51: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/51.jpg)
Computer Networks 51 of 52
Error Detection with CRC• Division of two polynomials
– Complicated process (which you do not need to learn)
• Two important points:– Produces a Result and a Remainder (just like
decimal)– Remainder is always same length as Divisorremainder
result divisor
dividend
![Page 52: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/52.jpg)
Computer Networks 52 of 52
Error Detection with CRC• CRC Algorithm: the sending end
– Agree a generator divisor G of length r
– Append r zeroes to the M data bits producing xrM
– Calculate xrM ÷ G = R
– Calculate xrM – R = T• Equivalent to just appending R to M
1 1 1 0 0 0
1 0 1
1 1 1 0 0 0
÷ 1 0 1
= 0 1 1
1 1 1 0 0 0
– 0 1 1
= 1 1 1 0 1 1
![Page 53: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/53.jpg)
Computer Networks 53 of 52
Error Detection with CRC
1 1 1 0 1 1
T ((xrM – R)/G which is divisible by G with 0 remainder)
M (original data) M (original data) R (remainder of xrM / G)
• What is sent?
![Page 54: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/54.jpg)
Computer Networks 54 of 52
Error Detection with CRC• CRC Algorithm: the receiving
end
– Divide the received bits by G
– If the remainder = 0, remove first r bits and continue
– If the remainder is ≠ 0 an error has occurred
M = 1 1 1
1 1 1 0 1 1
/ 0 1 1
= 0 0 0 0
![Page 55: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/55.jpg)
Computer Networks 55 of 52
Error Detection with CRC
• Why Polynomial Division?– Very fast in hardware– The remainder is always same number of
bits as the divisor– Produces very good hamming distance
• why?
![Page 56: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/56.jpg)
Computer Networks 56 of 52
Error Detection with CRC
• Analysis of CRC– If T/G ≠ 0 then T was actually T` = T+E– For example:
T = 1 1 1 0 1 1
T` = T + E = 1 1 0 0 1 1
E = 0 0 1 0 0 0
transmission error
![Page 57: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/57.jpg)
Computer Networks 57 of 52
Error Detection with CRC
• Analysis of CRC– If T/G != 0 then T was actually T` = T+E
– We only miss errors if E/G = 0
– When will this DEFINITELY NOT happen?• If G has exactly two 1’s in it…
– and only a single bit is flipped
• If G has a 1 in the right-most bit…– and any odd number of flips occurs
• If G is of length r…– and a string of bits of length ≤ r is flipped (a ‘burst’)
![Page 58: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/58.jpg)
Computer Networks 58 of 52
Error Detection with CRC
• Analysis of CRC– A real value of G
=100000100110000010001110110110111
– 802 standard CRC32 (Ethernet)– Detects all bursts < 32 bits– Detects all odd numbers of bit flips
![Page 59: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/59.jpg)
Computer Networks 59 of 52
Error Detection with CRC
• Analysis of CRC– The valid words of a parity-bit scheme
are any words with an even number of 1’s
– What are the valid words of a CRC scheme with a generator = G?
![Page 60: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/60.jpg)
Computer Networks 60 of 52
Error Detection with CRC
• Analysis of CRC– For further analysis see:
• Tannenbaum (pages 198 + 199)– theoretical limits of detection
• Forouzan (pages 284-291)– hardware implementation techniques
![Page 61: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/61.jpg)
Computer Networks 61 of 52
Bursty Error Control
• Isolated Errors– Parity bits, hamming codes and CRC are
very good at detecting/correcting single bit errors
![Page 62: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/62.jpg)
Computer Networks 62 of 52
Bursty Error Control
• Burst Errors– In the real world, noise and attenuation
result in isolated long sequences of errors known as bursts
![Page 63: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/63.jpg)
Computer Networks 63 of 52
Bursty Error Control
• Block Sending– Don’t send one frame at a time, send a
small portion of several frames each frame
– Receiver pieces the frames back together
![Page 64: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/64.jpg)
Computer Networks 64 of 52
Bursty Error Control
• Block Sending– If a burst error of length n wipes out a frame
this will be felt as a single bit error in n consecutive frames (each easy to detect/correct)
![Page 65: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/65.jpg)
Computer Networks 65 of 52
Error Control Design Choices
• Detection vs. Correction– We can detect errors using far fewer control
bits (e.g. parity bit vs. hamming code)– When should we use one or the other?
• Block vs. Linear Sending– We can guard against burst errors by
sending frames in blocks and reconstructing them
– For what applications is this inappropriate?
![Page 66: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/66.jpg)
Computer Networks 66 of 52
Error Control Summary
• The physical layer is error-prone– Noise, attenuation, distortion
• Data Link Layer must deal with this– Split outgoing binary stream in to frames– Each frame contains m data bits and r check
bits
• Error Detection can detect a corrupted frame– Parity bit, CRC
• Error Correction can correct the flipped bits– Hamming codes
![Page 67: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/67.jpg)
Computer Networks 67 of 52
Framing
![Page 68: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/68.jpg)
Computer Networks 68 of 52
Framing
• Error control relies on the ability to break the binary stream in to chunks– How do we now where a chunk begins
and ends?– How can we keep track of the chunks
themselves in an error-rich environment?
![Page 69: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/69.jpg)
Computer Networks 69 of 52
Character Count Framing
• Each frame contains a header with the number of characters in the frame
![Page 70: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/70.jpg)
Computer Networks 70 of 52
Character Count Framing
• Problem:– if the header is corrupted the count will be
wrong and the next header will be missed
![Page 71: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/71.jpg)
Computer Networks 71 of 52
Flag-Byte Framing
• General problem: how do we denote the end of one frame and start of another?– FLAG bytes: 01111110
usually a sequence number
usually error control
• What happens if the payload contains a FLAG?
![Page 72: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/72.jpg)
Computer Networks 72 of 52
FLAG-bytes with Byte Stuffing
• Escape all FLAG bytes in the payload
• Analogous to the Java expression– String s = ”An \”escaped\” String”
• Also need to escape all ESC bytes in the payload
• Analogous to the Java expression– String s = ”An escape character: \\”
![Page 73: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/73.jpg)
Computer Networks 73 of 52
FLAG-bytes with Bit Stuffing
• Escaping a byte with an entire byte is wasteful– Instead just escape the character in the binary
stream directly
• Whenever 5 1’s are seen, insert a 0 in to the output stream (FLAG = 6 1’s)
• Identical to technique used in RLL coding
![Page 74: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/74.jpg)
Computer Networks 74 of 52
Putting it all together…
DATA
a chunk of network-layer binary data
![Page 75: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/75.jpg)
Computer Networks 75 of 52
Putting it all together…
ESC DATA
ESC bytes or 0 bits stuffed
![Page 76: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/76.jpg)
Computer Networks 76 of 52
Putting it all together…
CTRL ESC DATA
Control information such as sender/receiver/seq. number/etc...
(see Flow Control and MAC sub-layer)
Control information such as sender/receiver/seq. number/etc...
(see Flow Control and MAC sub-layer)
![Page 77: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/77.jpg)
Computer Networks 77 of 52
Putting it all together…
CRCESC DATA
CRC checksum or other error-control information
CTRL
![Page 78: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/78.jpg)
Computer Networks 78 of 52
Putting it all together…
FLAG FLAGCTRL CRCESC DATA
FLAG bytes mark start and end of frame(note, these are not CRC-protected)
• A complete data-link frame
FLAG bytes mark start and end of frame(note, these are not CRC-protected)
![Page 79: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/79.jpg)
Computer Networks 79 of 52
Flow Control
![Page 80: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/80.jpg)
Computer Networks 80 of 52
Flow Control Overview
• Flow Control Protocols deal with how to send sequences of DLL frames
• They have two jobs:– Recover from lost frames– Prevent buffer overflows
• Network Layer must receive same set of frames in the same order they were sent
![Page 81: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/81.jpg)
Computer Networks 81 of 52
Unrestricted
• Sender sends• Receiver waits to receive
![Page 82: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/82.jpg)
Computer Networks 82 of 52
Unrestricted
• Problem: receiver’s buffers may fill up
![Page 83: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/83.jpg)
Computer Networks 83 of 52
Stop-and-Wait
• Sender sends, waits for ACK• Receiver receives, sends ACK
![Page 84: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/84.jpg)
Computer Networks 84 of 52
Stop-and-Wait
• Problem: lost frame = wait forever
![Page 85: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/85.jpg)
Computer Networks 85 of 52
Stop-and-Wait
• What, exactly, is a lost frame?
![Page 86: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/86.jpg)
Computer Networks 86 of 52
Stop-and-Wait with Timeouts
• Sender sends, waits for ack– Stops waiting after t seconds and re-
sends
![Page 87: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/87.jpg)
Computer Networks 87 of 52
Stop-and-Wait with Timeouts
• Problem: we are assuming errors only occur in one direction…
sender receiver
errors
no errors
![Page 88: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/88.jpg)
Computer Networks 88 of 52
Stop-and-Wait with Timeouts
• Lost ack = duplicate frame
• When else will a duplicate be received?
![Page 89: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/89.jpg)
Computer Networks 89 of 52
ARQ: Automatic Repeat Request
• Use sequence numbers to identify frames
• Sender sends SEQ n– Start timer– If ack received, n = n+1, if timeout, resend
n• Receiver receives n
– If expecting n, send ack for n– If expecting n+1 then ack for n was lost
• re-send ack for n• await delivery of n+1
![Page 90: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/90.jpg)
Computer Networks 90 of 52
ARQ: Automatic Repeat Request
• Always ACK the latest frame number we received
![Page 91: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/91.jpg)
Computer Networks 91 of 52
ARQ: Automatic Repeat Request
• Only acknowledge latest sequence number we expected to receive and did
• Sender will never send a frame without the ACK for the previous one
• Receiver will never accept a frame it has already seen
![Page 92: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/92.jpg)
Computer Networks 92 of 52
ARQ: Automatic Repeat Request
• Functionally ARQ is a complete protocol– Frame losses are detected– Duplicate frames are detected– Protocol will never deadlock
• This does not mean it is foolproof:– The checksum, data and SEQ fields could
all change pathologically– In general the more changes needed to
break a protocol the lower the chance of it happening
![Page 93: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/93.jpg)
Computer Networks 93 of 52
Sliding Window: Go-Back-N
• ARQ performance is bad because the sender spends most of the time waiting for a timeout or an ACK
• Relationship to channel volume:– Latency = L, Data Rate = R, Frame Size
= F– L * R = Volume– L * 2 = Round Trip Time– F / R = Time to Send 1 Frame– L * 2 – (F/R) ≈ Idle Time per-Frame
![Page 94: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/94.jpg)
Computer Networks 94 of 52
Sliding Window: Go-Back-N
• How can we improve the channel utilisation of an ARQ protocol?
• Answer: Pipelining– assume operation i is successful– perform operations i+1,2,3… up to a max n– be prepared to go back up to n operations
if one or more were incorrect• Also found in…
– Microprocessing architectures– Higher-level network protocols (e.g. http
1.1)
![Page 95: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/95.jpg)
Computer Networks 95 of 52
Sliding Window: Go-Back-N
• Based on valid window of SEQs at sender
• Any frame in window can be sent
• Receiver uses same logic as ARQ– ACK latest SEQ we saw and expected to see– Discard all others
![Page 96: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/96.jpg)
Computer Networks 96 of 52
Sliding Window: Go-Back-N• Normal Operation…
![Page 97: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/97.jpg)
Computer Networks 97 of 52
Sliding Window: Go-Back-N• Lost Frame…
![Page 98: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/98.jpg)
Computer Networks 98 of 52
Sliding Window: Go-Back-N• Lost ACK…
![Page 99: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/99.jpg)
Computer Networks 99 of 52
Sliding Window: Go-Back-N
• Frame and ACK errors solved with timeout (defined in frames, not real time)
• e.g. window size of 7
![Page 100: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/100.jpg)
Computer Networks 100 of 52
Sliding Window: Go-Back-N
• For a k-bit SEQ field, 2k sequence numbers are used, window must be 2k-1 in size…why?
![Page 101: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/101.jpg)
Computer Networks 101 of 52
Sliding Window: Go-Back-N
• Two adjacent windows must be unique to prevent ambiguity in ACKs
• For any window, the ACK tells the sender how many were successfully received:– [0,6] 6 = all, 7 = ack corrupted, 0 = one, 1 = two…– [7,5] 5 = all, 6 = ack corrupted, 7 = one, 0 = two…– [6,4] 4 = all, 5 = ack corrupted, 6 = one, 7 = two…– etc…
• i.e. must always have at least 1 un-used SEQ
![Page 102: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/102.jpg)
Computer Networks 102 of 52
Sliding Window: Go-Back-N
• Problem: retransmission overhead is large
![Page 103: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/103.jpg)
Computer Networks 103 of 52
Sliding Window: Selective Repeat
• Receiver keeps an array of frame buffers
• Now accepts any frame in the window
![Page 104: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/104.jpg)
Computer Networks 104 of 52
Sliding Window: Selective Repeat
• Send Negative ACK (NAK) if a frame is skipped over
• ACK for frame n implicitly acknowledges all frames ≤ n
![Page 105: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/105.jpg)
Computer Networks 105 of 52
Sliding Window: Selective Repeat
• For a k-bit SEQ field window cannot be > 2k-1
– e.g. if SEQ field = 3 bits and window is size 5:
![Page 106: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/106.jpg)
Computer Networks 106 of 52
Duplex Sliding Window
• Method to optimise sliding window protocols– Assume both sides have data frames to
send and both want to receive– Since ACK/NAK is a small amount of
data, include it as an optional field in all frames (piggybacking)
• Utilisation and throughput are now functions of what?
![Page 107: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/107.jpg)
Computer Networks 107 of 52
Real DLL protocols: HDLC
• Bit-Oriented (FLAG + bit-stuffing)• 3-bit selective-repeat [0-7] +
piggybacking
(if piggybacked)
(otherwise)
![Page 108: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/108.jpg)
Computer Networks 108 of 52
Real DLL protocols: LLC (802.2)
• Identical to HDLC (bit-oriented, 3-bit SR)
• No Addressing• No Error Control
![Page 109: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/109.jpg)
Computer Networks 109 of 52
Further Reading…
• Tannenbaum’s code examples are great if you’re familiar (enough) with c
• The java applets on the web page (under ‘additional material -> Data Link Layer -> Simulations’) should help you visualise these algorithms (but they are hideous).
• You WILL be asked what-if questions about these algorithms in the exam.
![Page 110: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/110.jpg)
Computer Networks 110 of 52
Flow Control Summary
• Serves two functional purposes– Prevent buffer overruns– Recover from lost frames
• Simple schemes achieve this– e.g. ARQ (ACKs with timeout + SEQ number)
• Non-functional properties also important– Sliding window improves performance by
pipelining. Achieves several send/ACK exchanges in parallel
– Piggybacking for duplex versions of same protocols
![Page 111: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/111.jpg)
Computer Networks 111 of 52
Medium Access Control
![Page 112: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/112.jpg)
Computer Networks 112 of 52
Multiple Access Channels
![Page 113: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/113.jpg)
Computer Networks 113 of 52
Multiple Access Channels
![Page 114: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/114.jpg)
Computer Networks 114 of 52
MAC Overview
• The MAC (sub-)layer• ALOHA Protocols• Carrier-Sense Protocols• Wireless protocols
![Page 115: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/115.jpg)
Computer Networks 115 of 52
The MAC sub-layer
Data-Link Layer provides packet
send/receive service to Network Layer
![Page 116: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/116.jpg)
Computer Networks 116 of 52
The MAC sub-layer
Physical Layer provides binary
send/receive to Data-Link Layer
![Page 117: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/117.jpg)
Computer Networks 117 of 52
The MAC sub-layer
But, different media have different
constraints about multiple nodes accessing the
medium
![Page 118: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/118.jpg)
Computer Networks 118 of 52
The MAC sub-layer
• We could hide this all in the physical layer:– send(bit b) returns once the medium is
reserved and the bit has been sent
• Very inefficient• We want to reserve the medium for a
longer space of time (i.e. at least the length of a single frame)
![Page 119: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/119.jpg)
Computer Networks 119 of 52
The MAC sub-layer
MAC layer provides medium-access
service to the Data-Link layer
A separate protocol is needed to
implement the service for each
different transmission medium
![Page 120: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/120.jpg)
Computer Networks 120 of 52
Channel Allocation Problem
• Channel cannot carry two signals in the same frequency range at the same time
• Two obvious multiplexing-based solutions:– Frequency multiplexing– Time multiplexing
![Page 121: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/121.jpg)
Computer Networks 121 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Time-Division fails with heterogeneous traffic
![Page 122: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/122.jpg)
Computer Networks 122 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Time-Division fails with heterogeneous traffic
![Page 123: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/123.jpg)
Computer Networks 123 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Frequency-Division fails with bursty traffic
![Page 124: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/124.jpg)
Computer Networks 124 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Frequency-Division fails with bursty traffic
![Page 125: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/125.jpg)
Computer Networks 125 of 52
Channel Allocation Problem
• With bursty, heterogeneous traffic we must find a dynamic way to allocate a node access to the channel– When a node has no traffic to send it
does not waste bandwidth– When a node has traffic to send it can
obtain all capacity of the channel, not just a slice
![Page 126: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/126.jpg)
Computer Networks 126 of 52
ALOHA Protocols
• Classical shared-medium problem– Radio towers all in range of central
antenna– Two concurrent senders = collision (both
frames are lost entirely)
![Page 127: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/127.jpg)
Computer Networks 127 of 52
ALOHA Protocols
• Two General Problems:– How to know when a collision has happened?– How to share the medium in general when
collisions cannot be predicted?
• Two General Solutions:– Resend when a collision happens and hope
for the best (Pure ALOHA)– Synchronise sending to a timer to reduce –
but not eradicate - collisions (Slotted ALOHA)
![Page 128: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/128.jpg)
Computer Networks 128 of 52
ALOHA – Collision Detection
• Central station bounces ACK back to sender• ACKs sent on separate frequency so never
collide• If ACK not received then sender assumes
collision
![Page 129: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/129.jpg)
Computer Networks 129 of 52
Pure ALOHA
• On Collision…– Wait random amount of time and resend– Randomisation is vital
![Page 130: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/130.jpg)
Computer Networks 130 of 52
Pure ALOHA
• On Collision…– Wait random amount of time and resend– Randomisation is vital
![Page 131: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/131.jpg)
Computer Networks 131 of 52
Pure ALOHA
• Weakness: potential for collision is large– For a frame-period of length F, the frame
is vulnerable for a period of 2F
![Page 132: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/132.jpg)
Computer Networks 132 of 52
Slotted ALOHA
• Time divided in to slots of size F– Frames delayed until beginning of the
next slot
![Page 133: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/133.jpg)
Computer Networks 133 of 52
Slotted vs. Pure ALOHA
• Both use randomisation after collision• Slotted reduces probability of
collision– If frame is ready in middle of period:
• In Pure ALOHA I will begin sending and destroy any currently sending frames
• In Slotted ALOHA I will wait and only destroy other waiting frames
![Page 134: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/134.jpg)
Computer Networks 134 of 52
MAC throughput performance
• Reducing collisions increases throughput– Throughput S = Number of frames
successfully received for a given unit time
– Generally:• G = offered load (total frames generated)• P(s) = probability of success for a single
frame• S = G × P(s)
![Page 135: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/135.jpg)
Computer Networks 135 of 52
MAC throughput performance
• We can also increase S by increasing G
• But P(s) is a function of G– For Pure ALOHA: P(s) = e-2G, S = Ge-2G
– For Slotted ALOHA: P(s) = e-G, S = Ge-G
![Page 136: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/136.jpg)
Computer Networks 136 of 52
MAC throughput performance• P(sk) = Probability a frame requires k attempts
• Total frames sent per data frame (average case)
• Same results are significant for error control schemes…
![Page 137: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/137.jpg)
Computer Networks 137 of 52
Carrier Sense Protocols (CSMA)
• Medium can be sensed for traffic– 1-persistent
• channel free: send immediately• channel busy: send once it is free
– non-persistent• channel free: send immediately• channel busy: send after random amount of
time
– (slotted) p-persistent CSMA• channel free: transmit with prob p• channel busy: repeat algorithm next slot
![Page 138: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/138.jpg)
Computer Networks 138 of 52
CSMA Performance
![Page 139: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/139.jpg)
Computer Networks 139 of 52
Carrier Sense Protocols (CSMA)
• CSMA also comes in two flavours– Collision Detection (/CD)
• Can ascertain if two data frames have collided
• Used in Ethernet 802.3 protocol family
– Collision Avoidance (/CA)• Channel is reserved using special frames• Data frames will never collide• Reservation frames still can• Used in Wireless LAN 802.11 protocol family
![Page 140: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/140.jpg)
Computer Networks 140 of 52
CSMA/CD in Ethernet
• Copper Wire: Full Broadcast Medium– Voltage Levels – collision destroys all
data– Key Point: each node can hear all
transmissions– This enables us to:
1. Determine whether the medium is free2. Determine whether our transmission
collided with someone else’s
![Page 141: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/141.jpg)
Computer Networks 141 of 52
CSMA/CD in Ethernet
• Propagation delay means collision are not detected immediately.
• Can be thought of as a frame ‘bouncing’ off another frame and back to the sender
![Page 142: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/142.jpg)
Computer Networks 142 of 52
CSMA/CD in Ethernet
• Collision Detection can greatly reduce the impact of collisions– Medium is only
jammed for as long as it takes colliding nodes to realise they are colliding…
![Page 143: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/143.jpg)
Computer Networks 143 of 52
CSMA/CD in Ethernet
• Collision Detection can greatly reduce the impact of collisions– Medium is only
jammed for as long as it takes colliding nodes to realise they are colliding…
![Page 144: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/144.jpg)
Computer Networks 144 of 52
CSMA/CD in Ethernet
• Delay makes carrier-sensing imperfect– If A sends before
vulnerable period, B will sense it in time
– If A becomes ready to send after vulnerable period it will sense B’s transmission
• Vulnerable period is twice longest latency
![Page 145: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/145.jpg)
Computer Networks 145 of 52
CSMA/CD in Ethernet
• Also relates to frame-size– If B cannot hear
collision before frame has finished sending it will not be detected
• Fsize/bps > RTT– i.e. the sender must
still be sending when the collision arrives back
![Page 146: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/146.jpg)
Computer Networks 146 of 52
CSMA/CD in Ethernet
• Physical Limits– Latency = Distance / Propagation Speed– Send Time = Frame Size / Data Rate
• Variables– Each 802.3 flavour has specific
Propagation Speed and Data Rate– Distance and Frame Size are therefore a
direct tradeoff
![Page 147: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/147.jpg)
Computer Networks 147 of 52
CSMA/CD in Ethernet
• 100baseT (100 Mbps over UTP)– Max Distance = 200m– Min Frame Length = 512 bits
• 1000baseT (1 Gbps over 4 x UTP)– Max Distance = 200m– Min Frame Length = 4096 bits
• etc…
![Page 148: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/148.jpg)
Computer Networks 148 of 52
CSMA/CD in Ethernet
• Broadcast Topologies– Linear
• single shared coaxial cable• direct connection (vampire taps or
transceivers)
![Page 149: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/149.jpg)
Computer Networks 149 of 52
CSMA/CD in Ethernet
• Broadcast Topologies– Star
• Multiple Cat5 cables plug in to a hub• Hub echoes each frame on all ports
![Page 150: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/150.jpg)
Computer Networks 150 of 52
CSMA/CA in WiFi
• Wireless LANs– 2.4Ghz Radio
Frequencies– FDM + QAM encoding
• Hidden station problem– In Ethernet, all stations
receive same signal eventually
– In WLANs each station hears a subset of the broadcasts
![Page 151: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/151.jpg)
Computer Networks 151 of 52
CSMA/CA in WiFi
• Hidden station problem– Increase power
• Needs more power (!)• Collision domain grows
– ALOHA approach (Echo complete frame)• Wasteful – cannot detect collision until 2 x
frame send time + RTT
![Page 152: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/152.jpg)
Computer Networks 152 of 52
CSMA/CA in WiFi
• We cannot detect collisions reliably• Instead we avoid them:
– Dynamic Channel reservation– RTS = Request to send
• Sent by sender, reserves channel• id of requesting station (a MAC address)• length of frame (duration of reservation)
– CTS = Clear to send• Send by access point – confirms reservation
![Page 153: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/153.jpg)
Computer Networks 153 of 52
CSMA/CA in WiFi
• SenderSend RTS(id,len)wait for frame…if (CTS)if CTS.id == id
send data frameelse
wait(CTS.len)CSMA algorithm
if (RTS)wait(RTS.len)CSMA algorithm
• Receiverwait for RTS…send CTS(id,len)wait(RTS.len)
![Page 154: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/154.jpg)
Computer Networks 154 of 52
CSMA/CA in WiFi
• Only prevents data frames colliding– RTS can still collide
• Each node creates a virtual jam on the channel– If a virtual jam is sensed when RTS is
ready the carrier-sense algorithm will see this as a broadcast in progress
– Some CSMA algorithm is then applied
![Page 155: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/155.jpg)
Computer Networks 155 of 52
CSMA/CA in WiFi
• Virtual Jamming– Each node only
needs to hear the CTS from the Access Point to do this
– Can use RTS to increase efficiency
– e.g. C will hear RTS from A but D will only hear CTS from B
![Page 156: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/156.jpg)
Computer Networks 156 of 52
CSMA/CA in WiFi
![Page 157: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/157.jpg)
Computer Networks 157 of 52
CSMA with Adaptive Backoff
• What is a good value for p?
![Page 158: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/158.jpg)
Computer Networks 158 of 52
CSMA with Adaptive Backoff
• What is a good value for p?– Too high:
• Nodes too eager to send, many collisions
– Too Low:• Nodes wait too long, poor utilisation
– (note, this is true in /CD and /CA protocols)
• Answer: make p adaptive– When collisions are high, make p low– When collisions are low, make p high
![Page 159: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/159.jpg)
Computer Networks 159 of 52
CSMA – Adaptive Backoff
• CSMA with Exponential Backoff– Random range = [0,2c-1] (where c = #collisions)– Slotted time (in Ethernet 1 slot length = RTT)
• t=0s: A and B collideA and B choose randomly from 21 slots:
[0,1]A chooses 1, B chooses 1
• t=2s: A and B collideA and B choose randomly from 22 slots:
[0,3]A chooses 2, B chooses 0
• t=3s: B transmits successfully• t=5s: A transmits successfully
![Page 160: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/160.jpg)
Computer Networks 160 of 52
802 error rates
• Error rates are measured in 2 ways– Packet Error Rate (PER) packets rejected– Bit Error Rate (BER) bits flipped
• 802.3– Between 1 in 108 and 1 in 1012
– Error Detection with 32-bit CRC (PER ∞ BER)
• 802.11– Between 1 in 103 and 1 in 106
– Error Correction (various)
![Page 161: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/161.jpg)
Computer Networks 161 of 52
802 addressing
• MAC addresses– 48-bits as twelve hexadecimal digits
• (e.g. 00-00-0c-12-34-56)
– First 24-bits are assigned to device vendors
– Second 24-bits are assigned by vendor to an individual device
![Page 162: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/162.jpg)
Computer Networks 162 of 52
802 inter-connections
• Bridges– Multiple nodes connect to one port– Each port is one collision domain– Frames forwarded if for different domain
• Switches– One node per port– Each frame sent to single destination
port– No Medium-Access Control needed!
![Page 163: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/163.jpg)
Computer Networks 163 of 52
802 inter-connections
• Bridges
![Page 164: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/164.jpg)
Computer Networks 164 of 52
802 inter-connections
• Switches
![Page 165: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/165.jpg)
Computer Networks 165 of 52
MAC Layer Summary
• Data Link Layer split in to two layers:– LLC: addressing and flow control (802.2)– MAC: error and medium-access control
(802.3/11/16)• ALOHA protocols
– Randomisation of re-send time (slotted/pure)• CSMA protocols (with persistence level)
– Collision Detection (Ethernet)– Collision Avoidance (WLAN)– Both use Exponential Back-off
• MAC collision domains– Can be separated by Bridges– Can be eradicated by Switches
![Page 166: The Data Link Layer](https://reader038.fdocuments.in/reader038/viewer/2022102704/54636293af795939028b7ae9/html5/thumbnails/166.jpg)
Computer Networks 166 of 52
Data Link Layer Summary
• Error Control– Detection/Correction– Framing
• Flow Control– Correctness (deadlock, duplication)– Efficiency (channel utilisation, sliding
windows)
• Medium Access– Carrier Sense/Non-Sensed– Collision Detection/Avoidance