EEC-484/584 Computer Networks Lecture 6 wenbing@ieee.org (Lecture nodes are based on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Outline Review Data Link Layer Design Issues Error Detection and Correction Data link layer Elementary Data Link Protocols Sliding Window Protocols 2 Data Link Layer Design Issues 3 Framing 4 Services Provided to the Network Layer Point-to-point, source-to-destination, wirelike How does DL layer form frames? Framing: Physical bit stream divided up into frames Error Control Acks and nacks Flow Control Sender may transmit frames faster than receiver can receive them Throttle sender so sends no faster than receiver can receive them Insert time gaps between frames Character count Flag bytes with byte stuffing Starting and ending flags, with bit stuffing Physical layer coding violations 1
Error-Correcting Codes 5 Error-Correcting Codes 6 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 2 m possible data messages are legal, but not all 2 n 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 To correct d errors, need a distance 2d+1 code Hamming Code 7 Cyclic Redundant Code 8 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 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 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) Sender and receiver agree on generate polynomial G(x), with high and low order bits = 1 To compute checksum for some frame with m bits corresponding to M(x) m > deg G(x) = r 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 2
Elementary Data Link Protocols 9 Elementary Data Link Protocols 10 An Unrestricted Simplex Protocol A Simplex Stop-and-Wait Protocol A Simplex Protocol for a Noisy Channel 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 Elementary Data Link Protocols 11 Protocol Definitions 12 Receiver waits for arrived of frame, which generates an interrupt When frame arrives at receiver, hardware computes checksum 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 Continued 3
Protocol Definitions 13 Protocol Definitions 14 Unrestricted Simplex Protocol 15 Unrestricted Simplex Protocol 16 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 4
Unrestricted Simplex Protocol 17 Unrestricted Simplex Protocol 18 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 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 19 Simplex Stop-and-Wait Protocol One solution too conservative Restrict sender so transmits so slowly that even if frame undergoes max delay no buffer overflows Better solution Receiver provides feedback to sender and gives sender permission to send next frame 20 5
Simplex Stop-and-Wait Protocol 21 Simplex Stop-and-Wait Protocol 22 Sender sends frame, stop and wait for ack Alternates between sender and receiver Half-duplex Simplex Stop-and-Wait Protocol 23 Simplex Protocol for Noisy Channel 24 Drop assumption Frames not damaged or lost Assumption 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 6
Simplex Protocol for Noisy Channel Problem Receiver receives uncorrupted frame, sends ack Sender times out before receiving ack, sends frame again Receiver receives second copy uncorrupted has duplicate copies Solution Use sequence numbers: 1 bit suffices 25 Simplex Protocol for Noisy Channel Further considerations Timeout must be long enough so sender does not send duplicate when ack is on its way Timeout must allow Frame to get to receiver Receiver to process frame Ack to get to sender 26 Simplex Protocol for Noisy Channel 27 Simplex Protocol for Noisy Channel 28 Acks need to be matched against frames Sender remembers next_frame_to_send Receiver remembers frame_expected Protocols in which the sender waits for a positive acknowledgement before advancing to the next data item are often called Positive acknowledgement with retransmission (PAR), or, Automatic Repeat request (ARQ) 7
Simplex Protocol for Noisy Channel 29 A Simplex Protocol for a Noisy Channel 30 31 32 Sliding Window Protocols Sliding Window Protocols A One-Bit Sliding Window Protocol A Protocol Using Go Back n A Protocol Using Selective Repeat Efficiency improvements 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 8
Sliding Window Protocols 33 Sliding Window Protocols 34 Each frame contains sequence number in ranges 0..2 n -1 Sending window list of consecutive sequence numbers of frames that sender is permitted to send 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 Sliding Window Protocols 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) 35 Sliding Window Protocols A sliding window of size 1, with a 3-bit sequence number (a) Initially (b) After first frame sent (c) After first frame received (d) After first ack received 36 9
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 37 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 38 One-Bit Sliding Window Protocol 39 One-Bit Sliding Window Protocol 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 Continued 10
One-Bit Sliding Window Protocol One-Bit Sliding Window Protocol No duplicate, no omissions, no deadlock, but inefficient 42 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 Sliding Window Protocols Drop assumption Transmission time is negligible from sending till 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 43 Sliding Window Protocols 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 44 11
Pipelining and Error Recovery 45 Go Back n 46 Go back n: Effect of an error when receiver s window size is 1 Drop assumption NL has infinite supply of packets network_layer_ready event added MAX SEQ frames outstanding at any instant Needs multiple timers, one per outstanding frame Sender Stores all frames in output buffer Must get acks in order in which frames are sent Selective repeat: Effect of an error when receiver s win. size is large Go Back n 47 Go Back n 48 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 a b c c a b 0 MAX_SEQ b c a 12
Go Back n 49 Go Back n Continued Go Back n 51 Go Back n 52 Continued Continued 13
Go Back n 53 Simulation of Multiple Timers in Software 54 14