Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Data Link Layer Chapter 3 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Data Link Layer Design Issues Error.

Similar presentations


Presentation on theme: "The Data Link Layer Chapter 3 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Data Link Layer Design Issues Error."— Presentation transcript:

1 The Data Link Layer Chapter 3 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Data Link Layer Design Issues Error Detection and Correction Elementary Data Link Protocols Sliding Window Protocols Example Data Link Protocols Revised: August 2011

2 The Data Link Layer CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Responsible for delivering frames of information over a single link Handles transmission errors and regulates the flow of data Physical Link Network Transport Application

3 TUNALI Computer Networks 1 3 Assumptions Source and destination are directly connected to each other There can be an error during the transmission The channel has finite data rate There is a nonzero propagation delay Purpose Develop algorithms for reliable and efficient communication between the source and the destination

4 Data Link Layer Design Issues CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Frames » Possible services » Framing methods » Error control » Flow control »

5 TUNALI Computer Networks 1 5 Data Link Layer Functions Providing a well defined service interface to the network layer Dealing with transmission errors Regulating the flow of data slow receivers are not swamped by fast senders

6 Frames CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 Actual data path Virtual data path Network Link Physical

7 TUNALI Computer Networks 1 7 Data Link Functionality Data link layer provides services to the network layer On the source machine, there is a process that hands in bits to the data link layer for transmission to the destination. The job of data link layer is to transmit the bits so that they can be handed over to the destination network layer

8 TUNALI Computer Networks 1 8 Data Link Communication

9 Possible Services CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Unacknowledged connectionless service Frame is sent with no connection / error recovery Ethernet is example Acknowledged connectionless service Frame is sent with retransmissions if needed Example is 802.11 Acknowledged connection-oriented service (rare in data link layer, usually provided at transport layer)) Connection Establishment Data Transmission Connection Release

10 Framing Methods CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Byte count » Flag bytes with byte stuffing » Flag bits with bit stuffing » Physical layer coding violations −Use non-data symbol to indicate frame

11 Framing – Byte count CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Frame begins with a count of the number of bytes in it Simple, but difficult to resynchronize after an error Error case Expected case

12 Framing – Byte stuffing CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Special flag bytes delimit frames; occurrences of flags in the data must be stuffed (escaped) Longer, but easy to resynchronize after error Used in PPP Stuffing examples Frame format Need to escape extra ESCAPE bytes too!

13 Framing – Bit stuffing CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 Used in HDLC and USB Transmitted bits with stuffing Data bits

14 Framing – Physical Layer Coding Violations CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Recall that 4B/5B maps four bit combinations to a five bit pattern. 16 out of 32 combinations are not used Pick one of the unused ones to establish a delimiter Ethernet 802.11 uses uses a 72 bit pattern called preamble

15 Error Control CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 Frame sequence numbers are introduced to identify the acknowledged frame Detecting errors and retransmissions are next topics.

16 Flow Control CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Prevents a fast sender from out-pacing a slow receiver Two approaches −Receiver gives feedback on the data it can accept −Sender is limited by a rate built into the protocol 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 in the Link and Transport layers.

17 Error Detection and Correction CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Error codes add structured redundancy to data so errors can be either detected, or corrected. Error correction codes: Hamming codes » Binary convolutional codes » Reed-Solomon and Low-Density Parity Check codes −Mathematically complex, widely used in real systems Error detection codes: Parity » Checksums » Cyclic redundancy codes »

18 Error Bounds – Hamming distance CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Code turns data of n bits into codewords of n+k bits Hamming distance is the minimum bit flips to turn one valid codeword into any other valid one. Example with 4 codewords of 10 bits (n=2, k=8): −0000000000, 0000011111, 1111100000, and 1111111111 −Hamming distance is 5 Bounds for a code with distance: 2d+1 – can correct d errors (e.g., 2 errors above) d+1 – can detect d errors (e.g., 4 errors above)

19 TUNALI Computer Networks 1 19 Bound on the Number of Check Bits to Correct 1-bit Errors n = total number of bits in a ‘codeword’ m = number of data bits in a codeword r = number of check bits in a codeword n = m +r Each of the 2 m legal messages has n illegal codewords at a distance 1 from it. Considering the codeword itself, there are n+1 codewords associated to a particular codeword. Since n=m+r, we must have (m+r+1) 2 m  2 n or (m+r+1)  2 r

20 TUNALI Computer Networks 1 20 Error Correction – Hamming code 1 Position the bits as 1,2,3,… starting from left Mark the positions of 2 i, i = 0,1,2,… as control bits (1,2,4,8,16,..) The rest, 3,5,6,7,9,10,11,12,13,14,15,17,.. are filled with data Write each data bit position as the sum of control bits E.g. 11=8+2+1=2 3 +2 1 +2 0 To fill a control bit, consider all the data bits whose position contains the particular control bit and use parity to fill the control bit

21 TUNALI Computer Networks 1 21 Error Correction – Hamming code 2 When the codeword arrives, the receiver checks each control bit and adds it to a sum if parity does not check At the end, the sum contains the incorrect bit if it is not zero Hamming Code can correct single bit errors To correct burst errors, matrix arrangement can be used to allow only one bit error.

22 Error Correction – Hamming code 3 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 Recomputing the parity sums (syndrome) gives the position of the error to flip, or 0 if there is no error (11, 7) Hamming code adds 4 check bits and can correct 1 error

23 TUNALI Computer Networks 1 23 Hamming Code and Burst Errors

24 Error Correction – Convolutional codes CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 Popular NASA binary convolutional code (rate = ½) used in 802.11 … 1 1 1 0 1 1 1 0 1 …

25 Error Correction – Reed – Solomon codes CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Operates on m – bit symbols Codewords are 2 m -1 symbols long m is usually chosen as 8 Works on the following principle −Any n - degree polynomial is uniquly identified by n+1 points −Use extra points on the polynomial −When error occurs fit the best polynomial Used in DSL and DVD s etc

26 Error Correction – Low Density Parity Check (LDPC) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Developed by Gallager Each output bit is formed from a fraction of input bits leading to a matrix representation Matrix is sparse

27 Error Detection – Parity (1) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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 ½

28 Error Detection – Parity (2) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 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

29 Error Detection – Checksums CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Checksum treats data as N-bit words and adds N check bits that are the modulo 2 N sum of the words Ex: Internet 16-bit 1s complement checksum Properties: Improved error detection over parity bits Detects bursts up to N errors Detects random errors with probability 1-2 N Vulnerable to systematic errors, e.g., added zeros

30 TUNALI Computer Networks 1 30 Error Detection - CRC (1) Bit strings as representation of polynomials E.g. 110001  x 5 + x 4 + x 0 Modulo 2 Arithmetic  Polynomial Arithmetic Addition and subtraction −No carries for addition and no borrows for subtraction − 1001101111110000 +11001010 -10100110 ----------------------------- 01010001 01010110  Division  Same as binary except that the binary is done in modulo 2

31 TUNALI Computer Networks 1 31 Error Detection - CRC (2) The sender and receiver agree on a generator polynomial G(x) of order r whose high and low order bits 1 The sender appends r zero bits to low-order end of the m- bit message M(x) to transform it to x r M(x) Modulo 2 divide x r M(x) by G(x) Modulo 2 Subtract remainder from x r M(x) to form the transmitted frame T(x)

32 Error Detection – CRC (3) Adds bits so that transmitted frame viewed as a polynomial is evenly divisible by a generator polynomial CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Start by adding 0s to frame and try dividing Offset by any reminder to make it evenly divisible

33 TUNALI Computer Networks 1 33 Error Detection – CRC (4) The receiver modulo 2 divides the received frame by G(x) If the remainder is zero, then it concludes that the frame received is correct Else, it discards the frame

34 Error Detection – CRC (5) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Based on standard polynomials: Ex: Ethernet 32-bit CRC is defined by: Computed with simple shift/XOR circuits Stronger detection than checksums: E.g., can detect all double bit errors Not vulnerable to systematic errors

35 TUNALI Computer Networks 1 35 CRC Performance 1 If an error occurs then the received polynomial is T(x) + E (x) where E(x) represents the error Each 1 in E(x) represents a bit inverted At the receiver, remainder[(T(x)+E(x))/G(x)]=remainder[E(x)/G(x)] For single bit errors, E(x)=x i, G(x) contains two or more terms and it will never divide E(x) hence all single bit errors will be detected For 2-bit errors, E(x)=x i +x j =x j (x i-j +1), assume x is not divisible by G(x), then all 2-bit errors are detected if G(x) does not divide x k +1 for any k up to a maximum of i-j (i.e. up to the maximum frame length)

36 TUNALI Computer Networks 1 36 CRC Performance 2 Fact: There is no polynomial with odd number of terms that has (x+1) as factor, so include x+1 in G(x) to catch all odd numbered errors G(x) will detect all burst errors of length  r Some popular polynomials CRC-12= x 12 +x 11 +x 3 +x 2 +x 1 +1 CRC-16= x 16 +x 15 +x 2 +1 CRC-CCITT= x 16 +x 12 +x 5 +1

37 Elementary Data Link Protocols CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Link layer environment » Utopian Simplex Protocol » Stop-and-Wait Protocol for Error-free channel » Stop-and-Wait Protocol for Noisy channel »

38 Link layer environment (1) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Commonly implemented as NICs and OS drivers; network layer (IP) is often OS software

39 TUNALI Computer Networks 1 39 General Assumptions Physical, data link and network layers are independent processes that communicate by passing messages back and forth Machine A has infinite data to send to machine B There are library procedures to_physical_layer and from_physical_layer to send and receive a frame respectively. The physical layer handles the CRC check Receiver waits something to happen by a procedure call wait_for _event E.g. event=cksum_err, event=frame_arrival

40 TUNALI Computer Networks 1 40 Protocol Definitions Continued  Some definitions needed in the protocols to follow. These are located in the file protocol.h.

41 Link layer environment (2) Link layer protocol implementations use library functions See code ( protocol.h ) for more details CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 GroupLibrary FunctionDescription Network layer from_network_layer(&packet) to_network_layer(&packet) enable_network_layer() disable_network_layer() Take a packet from network layer to send Deliver a received packet to network layer Let network cause “ready” events Prevent network “ready” events Physical layer from_physical_layer(&frame) to_physical_layer(&frame) Get an incoming frame from physical layer Pass an outgoing frame to physical layer Events & timers wait_for_event(&event) start_timer(seq_nr) stop_timer(seq_nr) start_ack_timer() stop_ack_timer() Wait for a packet / frame / timer event Start a countdown timer running Stop a countdown timer from running Start the ACK countdown timer Stop the ACK countdown timer

42 Utopian Simplex Protocol CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 An optimistic protocol (p1) to get us started Assumes no errors, and receiver as fast as sender Considers one-way data transfer Receiver has infinite buffer space That’s it, no error or flow control … Sender loops blasting framesReceiver loops eating frames }

43 TUNALI Computer Networks 1 43 A simplex Stop-and-Wait Protocol Assumptions Drop two of the assumptions The receiver has finite buffer space The receiver does not have infinite processing speed

44 Stop-and-Wait – Error-free channel CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Protocol (p2) ensures sender can’t outpace receiver: Receiver returns a dummy frame (ack) when ready Only one frame out at a time – called stop-and-wait We added flow control! Sender waits to for ack after passing frame to physical layer Receiver sends ack after passing frame to network layer

45 TUNALI Computer Networks 1 45 A Simplex Protocol for a Noisy Channel: Assumptions Drop the assumption The communication channel can make errors Frames may be damaged or lost completely If the frame is damaged in transit, the receiver hardware is assumed to compute the checksum In case the frame is damaged and the checksum is correct, then the protocol may fail

46 TUNALI Computer Networks 1 46 A Simplex Protocol for a Noisy Channel: Extra Mechanisms Since acks may also get lost, sequence numbers are needed to prevent duplicates at the receiver A 1-bit sequence number (0 or 1) is sufficient Sending frame m+2 depends on receiving ack for frame m+1 Sending ack for frame m+1 implies that frame is correctly received Protocols in which the sender waits for a positive ack before advancing to next frame are called PAR (Positive Acknowledgement with retransmission) or ARQ (Automatic Repeat reQuest)

47 Stop-and-Wait – Noisy channel (1) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 ARQ (Automatic Repeat reQuest) adds error control Receiver acks frames that are correctly delivered Sender sets timer and resends frame if no ack) For correctness, frames and acks must be numbered Else receiver can’t tell retransmission (due to lost ack or early timer) from new frame For stop-and-wait, 2 numbers (1 bit) are sufficient

48 TUNALI Computer Networks 1 48 Protocol 3: New Variables Sender next_frame_to_send A timer starts running when a frame is sent Receiver frame_expected

49 Stop-and-Wait – Noisy channel (2) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Sender loop (p3): Send frame (or retransmission) Set timer for retransmission Wait for ack or timeout If a good ack then set up for the next frame to send (else the old frame will be retransmitted) {

50 Stop-and-Wait – Noisy channel (3) CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Receiver loop (p3): Wait for a frame If it’s new then take it and advance expected frame Ack current frame

51 TUNALI Computer Networks 1 51 Required Reading Tanenbaum Sections 3.1 3.2 3.3

52 Homework CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 2 (3) 6 (8) 14 (16) 19 (21)


Download ppt "The Data Link Layer Chapter 3 CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011 Data Link Layer Design Issues Error."

Similar presentations


Ads by Google