Upload
robbbminson
View
7.953
Download
14
Tags:
Embed Size (px)
DESCRIPTION
Lecture slides from the 3rd-year module on Computer Networks at the University of Birmingham, UK.This presentation covers the Data-Link layer of the networks stack, primarily Error Control, Flow Control and Framing.
Citation preview
Computer Networks(06-05933)
The Data-Link LayerRob Minson, rm. [email protected]
Computer Networks 2 of 52
Data Link Layer Overview
Computer Networks 3 of 52
Data Link Layer Overview
• Error Control– Correction and Detection Schemes– Framing– Flow Control
• Medium Access
Computer Networks 4 of 52
Errors in the Physical Layer
• Noise
Computer Networks 5 of 52
Errors in the Physical Layer
• Noise– Near End Cross-Talk (NEXT)
=
Computer Networks 6 of 52
Errors in the Physical Layer
• Attenuation– Can we distinguish between power levels
with enough accuracy?
Computer Networks 7 of 52
Errors in the Physical Layer
• Attenuation
Computer Networks 8 of 52
Errors in the Physical Layer
• Distortion
Computer Networks 9 of 52
Error ControlCorrection and Detection
Schemes
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
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
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
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
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
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
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.
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…?
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
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?
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
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)
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
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
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’)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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?
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
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…
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
Computer Networks 50 of 52
Error Detection with CRC• Division of two polynomials = binary
division (with XOR subtraction)
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
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
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?
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
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?
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
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’)
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
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?
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
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
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
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
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)
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?
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
Computer Networks 67 of 52
Framing
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?
Computer Networks 69 of 52
Character Count Framing
• Each frame contains a header with the number of characters in the frame
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
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?
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: \\”
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
Computer Networks 74 of 52
Putting it all together…
DATA
a chunk of network-layer binary data
Computer Networks 75 of 52
Putting it all together…
ESC DATA
ESC bytes or 0 bits stuffed
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)
Computer Networks 77 of 52
Putting it all together…
CRCESC DATA
CRC checksum or other error-control information
CTRL
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)
Computer Networks 79 of 52
Flow Control
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
Computer Networks 81 of 52
Unrestricted
• Sender sends• Receiver waits to receive
Computer Networks 82 of 52
Unrestricted
• Problem: receiver’s buffers may fill up
Computer Networks 83 of 52
Stop-and-Wait
• Sender sends, waits for ACK• Receiver receives, sends ACK
Computer Networks 84 of 52
Stop-and-Wait
• Problem: lost frame = wait forever
Computer Networks 85 of 52
Stop-and-Wait
• What, exactly, is a lost frame?
Computer Networks 86 of 52
Stop-and-Wait with Timeouts
• Sender sends, waits for ack– Stops waiting after t seconds and re-
sends
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
Computer Networks 88 of 52
Stop-and-Wait with Timeouts
• Lost ack = duplicate frame
• When else will a duplicate be received?
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
Computer Networks 90 of 52
ARQ: Automatic Repeat Request
• Always ACK the latest frame number we received
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
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
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
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)
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
Computer Networks 96 of 52
Sliding Window: Go-Back-N• Normal Operation…
Computer Networks 97 of 52
Sliding Window: Go-Back-N• Lost Frame…
Computer Networks 98 of 52
Sliding Window: Go-Back-N• Lost ACK…
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
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?
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
Computer Networks 102 of 52
Sliding Window: Go-Back-N
• Problem: retransmission overhead is large
Computer Networks 103 of 52
Sliding Window: Selective Repeat
• Receiver keeps an array of frame buffers
• Now accepts any frame in the window
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
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:
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?
Computer Networks 107 of 52
Real DLL protocols: HDLC
• Bit-Oriented (FLAG + bit-stuffing)• 3-bit selective-repeat [0-7] +
piggybacking
(if piggybacked)
(otherwise)
Computer Networks 108 of 52
Real DLL protocols: LLC (802.2)
• Identical to HDLC (bit-oriented, 3-bit SR)
• No Addressing• No Error Control
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.
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
Computer Networks 111 of 52
Medium Access Control
Computer Networks 112 of 52
Multiple Access Channels
Computer Networks 113 of 52
Multiple Access Channels
Computer Networks 114 of 52
MAC Overview
• The MAC (sub-)layer• ALOHA Protocols• Carrier-Sense Protocols• Wireless protocols
Computer Networks 115 of 52
The MAC sub-layer
Data-Link Layer provides packet
send/receive service to Network Layer
Computer Networks 116 of 52
The MAC sub-layer
Physical Layer provides binary
send/receive to Data-Link Layer
Computer Networks 117 of 52
The MAC sub-layer
But, different media have different
constraints about multiple nodes accessing the
medium
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)
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
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
Computer Networks 121 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Time-Division fails with heterogeneous traffic
Computer Networks 122 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Time-Division fails with heterogeneous traffic
Computer Networks 123 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Frequency-Division fails with bursty traffic
Computer Networks 124 of 52
Channel Allocation Problem
• Multiplexing works with constant traffic
• Frequency-Division fails with bursty traffic
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
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)
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)
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
Computer Networks 129 of 52
Pure ALOHA
• On Collision…– Wait random amount of time and resend– Randomisation is vital
Computer Networks 130 of 52
Pure ALOHA
• On Collision…– Wait random amount of time and resend– Randomisation is vital
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
Computer Networks 132 of 52
Slotted ALOHA
• Time divided in to slots of size F– Frames delayed until beginning of the
next slot
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
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)
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
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…
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
Computer Networks 138 of 52
CSMA Performance
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
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
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
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…
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…
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
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
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
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…
Computer Networks 148 of 52
CSMA/CD in Ethernet
• Broadcast Topologies– Linear
• single shared coaxial cable• direct connection (vampire taps or
transceivers)
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
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
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
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
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)
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
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
Computer Networks 156 of 52
CSMA/CA in WiFi
Computer Networks 157 of 52
CSMA with Adaptive Backoff
• What is a good value for p?
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
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
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)
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
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!
Computer Networks 163 of 52
802 inter-connections
• Bridges
Computer Networks 164 of 52
802 inter-connections
• Switches
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
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