Data Link Layer Design Issues • Error Detection and Correction • Elementary Data Link Protocols • Sliding Window Protocols • Example Data Link Protocols
Total Page:16
File Type:pdf, Size:1020Kb
The Data Link Layer Chapter 3 • Data Link Layer Design Issues • Error Detection and Correction • Elementary Data Link Protocols • Sliding Window Protocols • Example Data Link Protocols Revised: August 2011 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 The Data Link Layer Application Responsible for delivering frames of information over a single link Transport Network • Handles transmission errors and Link regulates the flow of data Physical CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Data Link Layer Design Issues • Frames » • Possible services » • Framing methods » • Error control » • Flow control » CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Frames Link layer accepts packets from the network layer, and encapsulates them into frames that it sends using the physical layer; reception is the opposite process Network Link Virtual data path Physical Actual data path CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Possible Services Unacknowledged connectionless service • Frame is sent with no connection / error recovery • Ethernet is example Acknowledged connectionless service • Frame is sent with retransmissions if needed • Very unreliable channels; Example is 802.11 • NOTE: DL acknowledgement is an optimization to improve performance for unreliable channels, ACKs can also be done at higher layers Acknowledged connection-oriented service • Connection is set up; rare • Long unreliable channels such as satellites and long-distance telephone CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Framing Methods 1. Byte count » 2. Flag bytes with byte stuffing » 3. Flag bits with bit stuffing » 4. Physical layer coding violations − Use non-data symbol to indicate frame (e.g., for systems using 4B/5B line codes at the physical layer) Many DL protocols use a combination of the above framing methods for additional safety CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 1 Framing – Byte count Frame begins with a count of the number of bytes in it • Simple, but difficult to resynchronize after an error Expected case Error case CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 2 Framing – Byte stuffing Special flag bytes delimit frames; occurrences of flags in the data must be stuffed (escaped) • Longer, but easy to resynchronize after error Frame format Need to escape extra ESCAPE bytes too! Stuffing examples Example here is a simplification of PPP (point-to-point protocol) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 3 Framing – Bit stuffing Stuffing done at the bit level: • Frame flag has six consecutive 1s (not shown) • On transmit, after five 1s in the data, a 0 is added • On receive, a 0 after five 1s is deleted Data bits Transmitted bits with stuffing CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Error Control Error control repairs frames that are received in error • Requires errors to be detected at the receiver • Typically retransmit the unacknowledged frames • Timer protects against lost acknowledgements Detecting errors and retransmissions are next topics. CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Flow Control Prevents a fast sender from out-pacing a slow receiver • Receiver gives feedback on the data it can accept • Rare in the Link layer as NICs run at “wire speed” − Receiver can take data as fast as it can be sent Flow control is a topic addressed in the Data Link and higher layers. • DL uses feedback-based flow control • Transport uses both feedback-based flow control and rate-based flow control • Different behavior at the network layer (i.e., congestion control) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Error Detection and Correction Error codes add structured redundancy to data so errors can be either detected, or corrected. Error correction codes (used on wireless links = high error environments): • Hamming codes » • Binary convolutional codes » • Reed-Solomon and Low-Density Parity Check codes − Mathematically complex, widely used in real systems Error detection codes (used on fiber and high quality wire): • Parity » • Checksums » • Cyclic redundancy codes » CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Definitions • Error detection or correction codes add extra redundant bits to the message so that the message could be accurately reconstructed (or detected) at the remote peer node • m data (message) bits + r check bits • Let n = m + r; n = codeword; code rate is the fraction of the codeword that contains information that is not redundant = m/n 1. Block Code • r check bits are computed solely as a function of the m data bits with which they are associated; operates on a predetermined message size and encoding boundary 2. Systematic Code • m data bits sent directly along with the check bits rather than being encoded themselves before they are sent 3. Linear Code • r check bits are computed as a linear function of the m data bits (e.g., XOR or modulo 2 addition). This means that encoding can be done with operations such as matrix multiplication or simple logic circuits. Hamming Codes, Reed-Solomon Code, Low Density Parity Check, Parity, Checksum, and CRC are all linear, systematic block codes CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Error Bounds – Hamming distance Example of bit errors: Transmitted 10001001 Received 10110001 #bit errors 3 = XOR difference and count the 1s in the result Hamming distance is the number of bit positions by which two codewords differ. − If codewords are a Hamming distance of d apart, it will require d single-bit errors to convert one to the other • Example of a universe comprising 4 valid codewords of 10 bits (m=2, r=8): − 0000000000, 0000011111, 1111100000, and 1111111111 − Hamming distance of this example is 5 • Error-detecting and error-correcting properties of a block code depend upon its Hamming Distance (d = bit error difference between two codes) Correction/Detection Bounds for a code with errors: • Correction: 2d + 1 – can correct d errors where 2d + 1 <= Hamming Distance − 2 errors in the example above; i.e., solve for 2d+1 <=5) • Detection: d + 1 – can detect d errors where d + 1 <= Hamming Distance − 4 errors in example above; i.e., solve for d + 1 <= 5 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 1 Error Correction – Hamming code Hamming code gives a simple way to add check bits and correct up to a single bit error: • Check bits are parity over subsets of the codeword − Bit positions that are powers of 2 are check bits (1, 2, 4, 8, 16,…) − Rest of bit positions are message bits − Msg bits checked by adding together parity bits for its position; e.g., 3 = 1 + 2, 5 = 1 + 4, 6 = 2 + 4, 7 = 1 + 2 + 4, 9 = 1 + 8, 10 = 2 + 8, 11 = 1 + 2 + 8, … • Recomputing the parity sums (error syndrome) gives the position of the error to flip, or 0 if there is no error Bug – should be a 0 (11, 7) Hamming code adds 4 check bits w a Hamming Distance of 3; it can correct 1 error CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 There is a Bug in example 2 Error Correction – Convolutional codes Operates on a stream of bits, keeping internal state • Output stream is a function of all preceding input bits • Bits are decoded with the Viterbi algorithm (not covered) … 0 1 1 … 1 1 1 1 0 1 XOR sums Popular NASA binary convolutional code (rate = ½; i.e., 1 input produces 2 outputs) used in 802.11 and NASA Convolutional codes also used for GSM and SatCom CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 1 Error Detection – Parity (1) Parity bit is added as the modulo 2 sum of data bits • Equivalent to XOR; this is even parity • Ex: 1110000 11100001 • Detection checks if the sum is wrong (an error) Simple way to detect an odd number of errors • Ex: 1 error, 11100101; detected, sum is wrong • Ex: 3 errors, 11011001; detected sum is wrong • Ex: 2 errors, 11101101; not detected, sum is right! • Error can also be in the parity bit itself • Random errors are detected with probability ½ CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Error Detection – Parity (2) Interleaving of N parity bits detects burst errors up to N • Each parity sum is made over non-adjacent bits • An even burst of up to N errors will not cause it to fail CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 2 Error Detection – Checksums Checksum treats data as N-bit words and adds N check bits that are the modulo 2N sum of the words • Ex: Internet 16-bit 1s complement checksum • (Restated: Sum of the msg bits divided into 16 bit words) Properties: • Checksum often placed at end of the message (IP uses a 16-bit header checksum) • Improved error detection over parity bits • Detects bursts up to N errors • Vulnerable to systematic errors, e.g., added zeros • Can be combined with parity to better detect errors – parity operates on bits, checksums on words CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 3 Error Detection – CRCs (1) More powerful than parity or checksum to find errors at the DL Layer Divides the message (frame) by a generator polynomial. Adds bits so that transmitted frame is evenly divisible by that generator polynomial. Start by adding 0s to frame and try dividing Sender & Receiver agree on generator polynomial value in + and - for advance. In this example they modulo 2 arithmetic have agreed upon x4 + x + 1 is identical to XOR Offset by any reminder to make it evenly divisible CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D.