Outline Review EEC-682/782 Computer Networks I Data Link Layer Design Issues Error Detection and Correction Data link layer Elementary Data Link Protocols Sliding Window Protocols Lecture 6 Wenbing Zhao w.zhao1@csuohio.edu (Lecture nodes are based on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Spring Semester 2005 Data Link Layer Design Issues How does DL layer form frames? Point-to-point, source-to-destination, “wirelike” Framing Insert time gapes between frames Physical bit stream divided up into frames Too risky, no timing guarantees, not used Error Control Acks and nacks Sender has timer –within timeout get ack, or send again If frame transmitted multiple times, receiver may get several copies Use sequence numbers Character count Flag bytes with byte stuffing Starting and ending flags, with bit stuffing Physical layer coding violations Applies only if encoding on medium contain some redundancy Example: encode 1 bit with 2 bits Flow Control Sender may transmit frames faster than receiver can receive them Throttle sender so sends no faster than receiver can receive them EEC-682: Computer Networks I - Wenbing Zhao 2 Framing Services Provided to the Network Layer Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 1 => 10 0 => 01 Can use 00 or 11 to delimit frames 3 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 4 1 Error-Correcting Codes Error-Correcting Codes N-bit codeword – an n-bit unit containing data and check bits (m bits of data, r bits redundant/check bits) Given any two codewords, it is possible to determine how many corresponding bits differ, using exclusive OR and counting number of 1 bits in the result Hamming distance – number of bit positions in which two codewords differ In general, all 2m possible data messages are legal, but not all 2n possible codewords are used Given the algorithm for computing the check bits, it is possible to Construct a complete list of legal codewords Find two codewords whose Hamming distance is minimum This distance is the Hamming distance of the complete code To detect d errors, need a distance d+1 code No way that d single-bit errors can change a valid codeword into another valid codeword If two codewords are a Hamming distance d apart, it will require d single-bit errors to convert one into the other Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao To correct d errors, need a distance 2d+1 code Legal codewords are so far part that even with d changes, orginal codeword is still closer than any other codeword, so it can be uniquely determined 5 Hamming Code Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 6 Hamming Code - Example The bits of codeword are numbered consecutively, starting with bit 1 at the left end, bit 2 to its immediate right and so on The bits that are powers of 2 (1,2,4,8,16,etc) are check bits Data (character ‘H’): 1001000 Create the data word, leaving spaces for the parity bits: The rest are filled up with the m data bits Each parity bit calculates the parity for some of the bits in the code word. The position of the parity bit determines the sequence of bits that it alternately checks and skips. __1_001_000 Calculate the parity for each parity bit Position 1 checks bits 1,3,5,7,9,11: Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...) Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...) Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc. (4,5,6,7,12,13,14,15,20,21,22,23,...) Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,2431,40-47,...) etc. ? _ 1 _ 0 0 1 _ 0 0 0. Even number of 1’s, set position 1 to 0: 0 _ 1 _ 0 0 1 _ 0 0 0 Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ 0 0 1 _ 0 0 0. Even number of 1’s, set position 2 to 0: 0 0 1 _ 0 0 1 _ 0 0 0 Position 4 checks bits 4,5,6,7: 0 0 1 ? 0 0 1 _ 0 0 0. Odd number of 1’s, set position 4 to 1: 0 0 1 1 0 0 1 _ 0 0 0 Position 8 checks bits 8,9,10,11,12: 0 0 1 1 0 0 1 ? 0 0 0. Even number of 1’s, set position 8 to 0: 0 0 1 1 0 0 1 0 0 0 0 Code word: 00110010000. Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of ones in the positions it checks is even (assuming even parity is used) Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 7 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 8 2 Hamming Code Cyclic Redundant Code Sender and receiver agree on generate polynomial G(x), with high and low bits = 1 To compute checksum for some frame with m bits corresponding to M(x) When a codeword arrives, Receiver initializes a counter to 0, It then examines each check bit, k, to see if it has the right parity. M > deg G(x) = r If not, adds k to the counter. Append checksum to end of frame so polynomial T(x) corresponding to checksummed frame is divisible by G(x) When receiver gets checksummed frame, divides T(x) by G(x) If remainder R(x) != 0, then transmission error If counter is 0 after all check bits, the codeword is accepted as valid. If counter is nonzero, it contains the number of the incorrect bit e.g., if 1, 2, 8 in error, bit in position 11 is inverted Can only correct single-bit error Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 9 Algorithm to Compute CRC Checksum Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 10 Elementary Data Link Protocols Let m = deg M(x), r = deg G(x) Append r 0 bits to lower-order end of frame to obtain corresponding polynomial xrM(x) Divide bit string corresponding to xrM(x) by bit string corresponding to G(x) Subtract remainder R(x) from bit string corresponding to xrM(x) An Unrestricted Simplex Protocol A Simplex Stop-and-Wait Protocol A Simplex Protocol for a Noisy Channel Result is checksummed frame Let T(x) be its polynomial xrM(x) = Q(x)G(x) + R(x) xrM(x) – R(x) = Q(x)G(x) = T(x) Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 11 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 12 3 Elementary Data Link Protocols Protocol Definitions Initial assumptions Physical, data link, network layers are independent processes Sender has infinite amount of data ready to send, supplied by network layer “wire-like” service: reliable, source ordered delivery Packet is treated as pure data When sender accepts packet from NL, it encapsulates in a frame with a header and trailer Receiver waits for arrived of frame, which generates an interrupt When frame arrives at receiver, hardware computes checksum Continued Æ If error then DLL informed event = chksum_err Else DLL informed event = frame_arrival DLL acquires frame from physical layer, checks control info in header If ok then passes packet to NL Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 13 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 14 Unrestricted Simplex Protocol Protocol Definitions Additional assumptions Processing time insignificant Infinite buffer space Communication channel never loses or damages frames Uses no sequence numbers or acks Only event type frame_arrival Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 15 4 Simplex Stop-andWait Protocol Simplex Stop-and-Wait Protocol Drop assumption Receiver processing time insignificant, or, equivalently, infinite input buffer at receiver Main problem To prevent sender from overwhelming the receiver Sender sends frame, stop and wait for ack Alternates between sender and receiver If receiver takes t time units to execute from physical layer to network layer, sender must not transmit more than one frame per time t One solution – too conservative Restrict sender so transmits so slowly that even if frame undergoes max delay no buffer overflows Better solution Half-duplex Receiver provides feedback to sender and gives sender permission to send next frame Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 17 A Simplex Protocol for a Noisy Channel A Simplex Protocol for a Noisy Channel Drop assumption Frames not damaged or lost Further considerations Assumption Timeout must be long enough so sender does not send duplicate when ack is on its way Timeout must allow If frame is damaged, receiver will detect it when it computes the checksum Possible solution Receiver sends ack if receives uncorrupted frame, discards frame if damaged Sender sends frame again if doesn’t receive ack before timeout Frame to get to receiver Receiver to process frame Ack to get to sender Problem Acks need to be matched against frames Receiver receives uncorrupted frame, sends ack Sender times out before receiving ack, sends frame again Receiver receives send copy uncorrupted – has duplicate copies Sender remembers next_frame_to_send Receiver remembers frame_expected Positive acknowledgement with retransmission (PAR), or, Automatic Repeat reQuest (ARQ) Solution Use sequence numbers: 1 bit suffices Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 19 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 20 5 A Simplex Protocol for a Noisy Channel A Simplex Protocol for a Noisy Channel A positive acknowledgement with retransmission protocol. A positive acknowledgement with retransmission protocol. Continued Æ Spring Semester 2005 Sliding Window Protocols EEC-682: Computer Networks I - Wenbing Zhao 22 Sliding Window Protocols Efficiency improvements A One-Bit Sliding Window Protocol A Protocol Using Go Back N A Protocol Using Selective Repeat Use same circuit for data in both direction: full-duplex Interleave data and ack frames Use “kind” field to distinguish them B piggybacks its ack for A’s frame onto B’s next frame Savings of header in separate ack frame If B sends data frames infrequently, use timeout to determine when B should send ack in separate ack frame Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 23 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 24 6 Sliding Window Protocols Sliding Window Protocols Each frame contains sequence number in ranges 0..2n-1 Sending window – list of consecutive sequence numbers of frames that sender is permitted to send Receiving window – list of consecutive sequence numbers of frames that receiver is permitted to accept When frame with (seq num = lower edge of window) arrives Frame is passed to NL Ack is generated Window slid down by 1 (remains same size as was initially) When new packet arrives from NL, it is given next highest sequence number, and upper edge of window is incremented When ack arrives from receiver, lower edge of window is incremented Within sending window, frame sent but not acked Sender must keep those frames for possible retransmission If max window size = w, need w buffers Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 25 Sliding Window Protocols Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 26 One-Bit Sliding Window Protocol Sender transmits frame, waits for ack before sending next frame Next_frame_to_send – which frame sender is trying to send Frame_expected – which frame receiver is expecting Sender initially Gets packet from NL constructs frame sends frame A sliding window of size 1, with a 3-bit sequence number. (a) Initially. (b) After the first frame has been sent. (c) After the first frame has been received. (d) After the first acknowledgement has been received. Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 27 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 28 7 One-Bit Sliding Window Protocol One-Bit Sliding Window Protocol Receiver on arrival of frame Checks if it is duplicate If expected frame Passes frame to NL Slides its window up Sends ack back to sender indicating last uncorrupted frame it received Sender on receipt of ack If ack agrees with seq num of frame it is trying to send Gets next packet frame NL Constructs frame Sends frame Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao One-Bit Sliding Window Protocol Continued Æ 29 One-Bit Sliding Window Protocol No duplicate, no omissions, no deadlock, but inefficient Two scenarios for protocol 4. (a) Normal case. (b) Abnormal case. The notation is (seq, ack, packet number). An asterisk indicates where a network layer accepts a packet. Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 32 8 A Protocol Using Go Back n Sliding Window Protocols Drop assumption Transmission time is negligible from sending til receiving ack Problem: sender blocks till receives acks (does not send another frame) Solution: pipelining Allow sender to send up to w frames before blocking Problem: if frame in middle is lost or damaged, what to do with the frames following it Solution: two strategies Go Back n - all the frames following it are discarded Selective repeat – nack the lost/damaged frame and retransmit that frame Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao Pipelining and error recovery. Effect on an error when (a) Receiver’s window size is 1. (b) Receiver’s window size is large. 33 Go Back n Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 34 Go Back n Drop assumption NL has infinite supply of packets Network_layer_ready event added Max seq frames outstanding at any instant Needs multiple timers, on per outstanding frame Sender Stores all frames in output buffer Must get acks in order in which frames are sent Receiver Discards all frames following lost or damaged frame Works well if transmission errors rare and few retransmissions If lot of traffic in both directions Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 35 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao Continued Æ 36 9 Go Back n Go Back n Continued Æ Spring Semester 2005 Go Back n EEC-682: Computer Networks I - Wenbing Zhao Continued Æ 37 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 38 Simulation of multiple timers in software Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 40 10 Selective Repeat Selective Repeat Problem: non-sequential receive Receiver (rather than sender as in Go Back n) accepts and buffers frames following lost or damaged frame Both sender and receiver maintain windows New range of valid sequence numbers for receiver can overlap old range Overlap can contain duplicates Sender’s window starts at 0, grows to MAX SEQ Receiver’s window fixed at MAX SEQ Receiver has buffer reserved for each seq num in its window When frame arrives, receiver checks if seq num in window If so and if not already received, frame is accepted and stored If all lower numbered frames delivered to NL, frame is delivered to NL Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 41 Problem for Non-Sequential Receive Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 42 Problem for Non-Sequential Receive Scenarios: n = 3bit seq num (8 possible numbers, 0 through 7, back to 0) Sender sends 0,1,2,3,4,5,6 Receiver receives 0,1,2,3,4,5,6 sends ack but ack gets lost Assumes sender gets ack and expects to get 7,0,1,2,3,4,5 Sender times out, retransmits 0,1,2,3,4,5,6 Receiver checks 0 is in new window, thinks new 0 because sent ack for old 6, waits for 7 Sender receives ack for 0-6, sends 7 Receiver receives 7, delivers 7 and old 0 (as new 0 !) Solution: (a) Initial situation with a window size seven. (b) After seven frames sent and received, but not acknowledged. (c) Initial situation with a window size of four. (d) After four frames sent and received, but not acknowledged. make sure no overlap when receiver advances its window Make window size w =1/2 range of seq numbers Note: number buffers at receiver needs = w Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 43 Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 44 11 Selective Repeat Selective Repeat If no reverse traffic before timer goes off, separate ack frame is sent Interrupt due to timer is ack_timedout event Solves problem of traffic in one direction only and blocking of Go Back n Further enhancements When receiver suspects error, sends NAK back to sender (request for retransmission) Two circumstances that trigger NAK Damaged frame arrives Frame other than expected one arrives, suspect expected one is lost Receiver sends only one NAK for frame expected Spring Semester 2005 Continued Æ EEC-682: Computer Networks I - Wenbing Zhao 45 Selective Repeat Selective Repeat Continued Æ Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 47 Continued Æ 12 Selective Repeat Spring Semester 2005 EEC-682: Computer Networks I - Wenbing Zhao 49 13