Computer Networks The Data Link Layer 1 Data Link Layer Application Transport Network DLL PHY 2
What does it do? What functions it performs? Typically: Handling transmission errors, a.k.a., error control. Flow control. Framing. 3 Framing 4
DLL and the Stack (a) Virtual communication (b) Actual communication 5 DLL Between Routers 6
The DLL and PHY The PHY delivers raw sequence of bits. Unreliable service. The DLL must detect and, in some cases, correct errors. 7 DLL s Error Control Break bit stream into frames. Check if frames arrived correctly. If not: Discards frame. In some cases also request retransmisssion. 8
Not trivial. Different methods. Framing 9 Framing: Using Counters (a) Without errors. (b) With one error. 10
Main problem? Character Counter 11 Framing: Flag Byte Each frame starts and ends with special bytes: flag bytes. Two consecutive flag bytes indicate end of frame and beginning on new frame. Problem? What if flab bit pattern occurs in data? 12
Byte Stuffing (a) A frame delimited by flag bytes. (b) Four examples of byte sequences before and after stuffing. 13 Byte Stuffing (Cont d) Single ESC: part of the escape sequence. Doubled ESC: single ESC is part of data. De-stuffing. Problem: What if character encoding does not use 8-bit characters? 14
Bit Stuffing Allows character codes with arbitrary bits per character. Each frames begins and ends with special pattern. Example: 01111110. When sender s DLL finds 5 consecutive 1 s in data stream, stuffs 0. When receiver sees 5 1 s followed by 0, destuffs. 15 Bit Stuffing: Example (a) Original data. (b) Data as they appear on the line. (c) Data after de-stuffing. 16
Error Control 17 Error Control Reliable delivery. Hop-by-hop! Detecting errors. Detecting and correcting errors. 18
Acknowledgments Special control info (in the case of the DLL, control frame) acknowledging receipt of data. Positive and negative ACKs. ACKs. NACKs. Are ACKs sufficient? 19 Timers. Retransmission. Duplicate detection. Reliable Delivery 20
Flow Control Handles mismatch between sender s and receiver s speed. Receiver s buffer limitation. Feedback-based flow control. Explicit permission from receiver. Rate-based flow control. Implicit mechanism for limiting sending rate. DLL typically uses feedback-based flow control. 21 Error Detection and Correction Add control information to the original data being transmitted. Error detection: enough info to detect error. Need retransmissions. Error correction: enough info to detect and correct error. A.k.a., forward error correction (FEC). 22
Why? Error detection versus error correction. Cost-efficiency? Environment. Application. 23 What s an error? Frame = m data bits + r bits for error control. n = m + r. Given the original frame f and the received frame f, how many corresponding bits differ? Hamming distance (Hamming, 1950). 24
Hamming Distance: Examples 25 Hamming Distance If f and f are Hamming distance of d apart, there needs to be d single-bit errors to convert f to f. Error detecting/correcting properties of a code depend on the code s Hamming distance. To detect d errors, need code with Hamming distance d+1. Need d+1 single-bit errors to change a valid f to a valid f. If receiver sees invalid f, it knows an error occurred. 26
Parity Bit Simple error detecting code. Even- or odd parity. Example: Transmit 1011010. Add parity bit 1011010 0 (even parity) or 1011010 1 (odd parity). Code with single parity bit has Hamming distance of 2! Any single bit error produces frame with wrong parity. 27 Error Correcting Codes To correct d errors, need 2d+1distance code. Code words are 2d+1 apart. With d changes, original frame is closer than any other valid frame. 28
Error Correction: Example Suppose code with 4 valid words: 0000000000, 0000011111, 1111100000, 1111111111. Hamming distance is 5. Possible to correct double errors. Example: If 0000000111 arrives at receiver, receiver assumes original must have been 0000011111. But if triple error changes 0000000000 into 0000000111, not able to correct it properly. 29 Hamming Code Check bits in power-of-two positions. Each check bit verifies a set of data bits. A data bit is checked by multiple check bits. 30
Hamming Code Bits in positions that are power of 2 are check bits. The rest are data bits. Each check bit used in parity (even or odd) computation of collection of bits. Example: check bit in position 11, checks for bits in positions, 11 = 1+2+8. Similarly, bit 11 is checked by bits 1, 2, and 8. 31 Hamming Code (Cont d) Parity computations: 11: 1, 2, 8-6: 2, 4 10: 2, 8-5: 1, 4 9: 1, 8-3: 1, 2 7: 1, 2, 4 32
Hamming Code: Example 1 Data: 1001101 using even parity (counting from right to left). 1 0 0 1 1 0 1 11 10 9 8 7 6 5 4 3 2 1 1 1: 1, 3, 5, 7, 9, 11 1 0 0 1 1 1 0 0 1 0 1 11 10 9 8 7 6 5 4 3 2 1 2: 3, 6, 7, 10, 11 33 Hamming Code: Example 2 What if instead of 1 0 0 1 1 1 0 0 10 1, receiver gets 1 0 0 1 0 1 0 0 1 0 1? 11 10 9 8 7 6 5 4 3 2 1. Receiver takes frame received and re-computes check bits. 1: 3, 5, 7, 9, 11: 1, 1, 0, 1, 0, 1 => 1 2: 3, 6, 7, 10, 11: 0, 1, 1, 0, 0, 1 => 1 4: 5, 6, 7 : 0, 0, 1, 0 => 1 8: 9, 10, 11: 1, 0, 0, 1 => 0 0 1 1 1 Result: Bit in position 0 1 1 1 is wrong! 34
How much code redundancy? How many check bits needed, i.e., given m data bits, how many more bits (r) are needed to allow all single-bit errors to be corrected? Resulting frame is m + r. (m+r+1) <= 2 r. Given m, then find r. Example: If m = 7 (ASCII 7 code), minimum r is 4. 35 Hamming Code: Example 7-bit. Hamming codes can only correct single errors.. But, to correct bursts of errors, send column by column. 36
Error Detecting Codes Typically used in reliable media. Examples: parity bit, polynomial codes (a.k.a., CRC, or Cyclic redundancy Check). 37 Polynomial Codes Treat bit strings as representations of polynomials with coefficients 1 s and 0 s. K-bit frame is coefficient list of polynomial with k terms (and degree k-1), from x k-1 to x 0. Highest-order bit is coefficient of x k-1, etc. Example: 110001 represents x 5 + x 4 +x 0. Generator polynomial G(x). Agreed upon by sender and receiver. 38
CRC Checksum appended to frame being transmitted. Resulting polynomial divisible by G(x). When receiver gets checksummed frame, it divides it by G(x). If remainder, then error! 39 Cyclic Redunancy Check At Transmitter, with M = 1 1 1 0 1 1, compute 2 r M= 1 1 1 0 1 1 0 0 0 with G = 1 1 0 1 T = 2 r M + R [note G starts and ends with 1 ] R = 1 1 1 Transmit T= 1 1 1 0 1 1 1 1 1 40
Cyclic Redundancy Check At the Receiver, compute: Note remainder = 0 no errors detected 41 CRC Performance Errors go through undetected only if divisible by G(x) With suitably chosen G(x) CRC code detects all single-bit errors. And more 42
Flow + Error Control 43 Flow + Error Control How do Layer 2 protocols implement them? What s a frame? F H Payload T F. What s F?. What s in T?. What s in H? 44
Flow + Error Control Frame revisited. Layer 2 encapsulation/decapsulation. Flags. Trailer: checksum. Header: type, sequence number, ack. 45 Header and Trailer Trailer typically has checksum. How is it used/processed? Header has: type, sequence number, and ack. 46
Stop-and-Wait Simplest form of flow control. How does it work? (assume error-free channel) (1) Send 1 frame; (2) Wait for ACK. (3) Go to 1. 47 Stop-and-Wait: Pros and Cons Very simple! But, poor link utilization. High data rates. Long propagation delay. 48
Noisy Channels From Stallings: Data and Computer Communications 49 Stop-and-Wait in Noisy Channels Need timers, retransmissions, and duplicate detection. Use sequence numbers. Why? Distinguish frames. How large (e.g., in number of bits) are sequence numbers? 50
ARQ Protocols Automatic Repeat Request. Protocols that wait for ACK before sending more data. ACKs now are used for flow AND error control. What can happen? At receiver: frame arrives correctly, frame arrives damaged, or frame does not arrive. At sender: ACK arrives correctly, ACK arrives damaged, or ACK does not arrive. 51 ARQ Protocols Sender: Send frame 0. Start timer. If ACK 0, arrives, send frame 1. If timeout, re-send frame 0. Receiver: **Waits for frame. If frame arrives, check if correct sequence number. Then send ACK for that frame. Go to (**) 52
Simplex: Simplex versus Duplex Transmission Send data in one channel and control in another channel. Duplex: Send data and control on the same chanel. 53 Can we do better? Can we do better? Piggybacking. Bi-directional transmission. Wait for data packet and use that to piggyback the ACK. Use ACK field: only a few additional bits in the header. But, how long should Layer 2 wait to send an ACK? ACK timers! 54
Can we do even better? In Stop and Wait, only 1 frame outstanding at any given point in time. What s the problem with that? Loooong pipes. S R Fat pipes. S R 55 Sliding Window Protocols Window: number of outstanding frames at any given point in time. So what s the window size of Stop and Wait? Every ACK received, window slides. 56
Sliding Window: Example 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. 57 Sliding Window: Basics Allows multiple frames to be in transit at the same time. Receiver allocates buffer space for n frames. Transmitter is allowed to send n (window size) frames without receiving ACK. Frame sequence number: labels frames. 58
Sliding Window: Receiver Receiver ack s frame by including sequence number of next expected frame. Cumulative ACK: ack s multiple frames. Example: if receiver receives frames 2,3, and 4, it sends an ACK with sequence number 5, which ack s receipt of 2, 3, and 4. 59 More Sliding Window Sender maintains sequence numbers it s allowed to send; receiver maintains sequence number it can receive. Sequence numbers are bounded; if frame reserves k-bit field for sequence numbers, then they can range from 0 2 k -1 k. Transmission window shrinks each time frame is sent, and grows each time an ACK is received. 60
Example: 3-bit sequence number and window size 7 A (Sender) B (Receiver) 0 1 2 3 4 5 6 7 0 1 2 3 4 0 1 2 3 4 5 6 7 0 1 2 3 4 0 0 1 2 3 4 5 6 7 0 1 2 3 4 1 2 0 1 2 3 4 5 6 7 0 1 2 3 4 ACK 3 0 1 2 3 4 5 6 7 0 1 2 3 4 0 1 2 3 4 5 6 7 0 1 2 3 4 3 4 0 1 2 3 4 5 6 7 0 1 2 3 4 0 1 2 3 4 5 6 7 0 1 2 3 4 5 ACK 4 6 0 1 2 3 4 5 6 7 0 1 2 3 4 0 1 2 3 4 5 6 7 0 1 2 3 4 61 One-Bit Sliding Window Protocol Two scenarios: (a) Normal case. (b) Abnormal case. Notation is (seq, ack, packet number). An * indicates where a network layer accepts packet. ACK indicates last sequence number received. 62
Bandwidth-Delay Product How large should the sender s window be? Function of how fat is the pipe? S BW R RTT W = BW*RTT/data size 63 Pipelining Receiver s window size is 1: discard frames after error with no ACK. Go Back N Receiver s window size is large: buffers all frames until error Selective Repeat recovered. Pipelining and error recovery. Effect on error when (a) Receiver s window size is 1. (b) Receiver s window size is large. 64
Example DLL Protocols High-Level Data Link Control (HDLC). Point-to-Point Protocol (PPP). 65 HDLC ISO standard. Flag Identifies host. ACK, seq. # CRC 66
Internet s DLL. Router-to-router. Home user-to-isp. RFC 1661, etc. PPP PPP is a multi-protocol framing mechanism that can be used over multiple PHYs (dial-up, dedicated point-to-point connections). 67 The Data Link Layer in the Internet 68
PPP Frame Type of protocol in the payload Default value; no need for addresses. Default value: unumbered frame; No rexmissions. 69