350 likes | 754 Views
Data Link Layer What does it do?. What functions it performs? Typically: Handling transmission errors. Error control. Flow control. Framing. Framing. The DDL and PHY. The Physical Layer delivers raw sequence of bits. Unreliable service.
E N D
Data Link LayerWhat does it do? What functions it performs? Typically: Handling transmission errors. Error control. Flow control. Framing.
The DDL and PHY • The Physical Layer delivers raw sequence of bits. • Unreliable service. • The Data Link Layer must detect and, in some cases, correct errors.
DLL’s Error Control • Break bit stream into frames. • Check if frames arrived correctly. • If not: • Discards frame. • In some cases also request retransmission.
Framing: Using Counters (a) Without errors. (b) With one error.
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. • What if flag bit pattern occurs in data?
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?
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, de-stuffs.
Bit Stuffing: Example • (a) Original data. • (b) Data as they appear on the line. • (c) Data after de-stuffing.
Error Control • Reliable delivery. • Hop-by-hop! • Detecting errors. • Detecting and correcting errors.
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?
Reliable Delivery • Timers. • Retransmission. • Duplicate detection
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.
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. • forward error correction (FEC).
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).
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.
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.
Error Detecting Codes • Typically used in reliable media. • Examples: parity bit, polynomial codes (CRC, or Cyclic redundancy Check).
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!
Cyclic Redunancy Check T = 2rM + R [note G starts and ends with “1” ] At Transmitter, with M = 1 1 1 0 1 1, compute 2rM= 1 1 1 0 1 1 0 0 0 with G = 1 1 0 1 R = 1 1 1 Transmit T= 1 1 1 0 1 1 1 1 1
Cyclic Redundancy Check At the Receiver, compute Note remainder = 0 no errors detected
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?
Header and Trailer • Trailer typically has checksum. • How is it used/processed? • Header has: type, sequence number, and ack.
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. • Poor link utilization. • High data rates. • Long propagation delay.
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, frame does not arrive. • At sender: ACK arrives correctly, ACK arrives damaged, ACK does not arrive.
ARQ Protocols • Receiver: • **Waits for frame. • If frame arrives, check if correct sequence number. • Then send ACK for that frame. • Go to (**) • Sender: • Send frame 0. • Start timer. • If ACK 0, arrives, send frame 1. • If timeout, re-send frame 0.
Simplex versus Duplex Transmission • Simplex: • Send data in one channel and control in another channel. • Duplex: • Send data and control on the same chanel.
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!
Sliding Window Protocols • Window: number of “outstanding” frames at any given point in time. • Every ACK received, window slides…
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.
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.
Pipelining Go Back N Selective Repeat