370 likes | 381 Views
Data Communication and Networks. Lecture 3 Data Link Control (Part 1) September 18, 2003 Joseph Conron Computer Science Department New York University jconron@cs.nyu.edu. Data Link Layer. Source node. Destination node. Application. Application. Presentation. Presentation. Session.
E N D
Data Communication and Networks Lecture 3 Data Link Control (Part 1) September 18, 2003 Joseph Conron Computer Science Department New York University jconron@cs.nyu.edu
Data Link Layer Source node Destination node Application Application Presentation Presentation Session Session Intermediate node transport transport Packets Network Network Network Frames Data link Data link Data link Bits Physical Physical Physical Signals
OSI Layer 2 - Data Link Layer • Primary function is to make Layer 1 into what appears to be a channel free of undetected errors • Deals with data in chunks (typically 100s-1000s of bytes) generally called Frames • This layer must create/recognize frame boundaries • Physical layer does not care about frames, only bits • Requires special bit patterns to signal boundaries • May have to deal with possibility of pattern appearing in data • Implements data link control protocols, such High Level Data Link Control (HDLC)
Encoding Information Frames Typical Fields in a Frame Start Frame Delimiter Destination Address Source Address Frame Control Check sum Data
DLL Operation Sender Receiver NL correct and ordered CRC Retransmit if timeout ACK if correct DLL Frame ACK PL CRC
Data Link Layer Services • Flow Control: • pacing between senders and receivers • Error Detection: • errors are caused by signal attenuation and noise. • Receiver detects presence of errors: • it signals the sender for retransmission or just drops the corrupted frame • Error Correction: • mechanism for the receiver to locate and correct the error without resorting to retransmission
Flow Control • Ensuring the sending entity does not overwhelm the receiving entity • Preventing buffer overflow • Transmission time • Time taken to emit all bits into medium • Propagation time • Time for a bit to traverse the link
Stop and Wait • Source transmits frame • Destination receives frame and replies with acknowledgement • Source waits for ACK before sending next frame • Destination can stop flow by not send ACK • Works well for a few large frames
Fragmentation • Large block of data may be split into small frames • Limited buffer size • Errors detected sooner (when whole frame received) • On error, retransmission of smaller frames is needed • Prevents one station occupying medium for long periods • Stop and wait becomes inadequate when data is fragmented into several small frames.
Sliding Windows Flow Control • Allow multiple frames to be in transit • Receiver has buffer W long • Transmitter can send up to W frames without ACK • Each frame is numbered • ACK includes number of next frame expected • Sequence number bounded by size of field (k) • Frames are numbered modulo 2k
Sliding Window Example An example of sliding window in action …..
Sliding Window Enhancements • Receiver can acknowledge frames without permitting further transmission (Receive Not Ready) • Must send a normal acknowledge to resume • If duplex, use piggybacking • If no data to send, use acknowledgement frame • If data but no acknowledgement to send, send last acknowledgement number again, or have ACK valid flag (TCP)
Error Detection • Additional bits added by transmitter for error detection code • Parity • Value of parity bit is such that character has even (even parity) or odd (odd parity) number of ones • Even number of bit errors goes undetected • Checksum can be a simple XOR operation of bits to be checked • DL protocols use more sophisticated methods, like Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check • For a block of k bits transmitter generates n bit sequence (FCS) • Transmit k+n bits which is exactly divisible by some number • Receive divides frame by that number • If no remainder, assume no error • For math, see Stallings chapter 6
Cyclic Redundancy Check • Example: 16-Bit CRC for HDLC • Performed on Address, Control, Data Fields • Detects a Variety of Error Conditions • Data Message is Represented as a Polynomial, Mi(x) = polynomial of order i = a0 + a1 x + a2 x2 + a3 x3 + . . . + ai xi where ai = 0, 1 • Data Message = ai ai-1 … a3 a2 a1 a0 Start Frame Delimiter Destination Address Source Address Frame Control CRC Data
CRC Generation • Given a Specific Polynomial G(x) called the generator, and a Data Message M(x), Calculate a Frame Check Sequence (FCS), or Checksum • Append the FCS (Checksum) to the Data Message for Transmission • At the Receiver, Recalculate the Checksum, and Check with the Transmitted Value
CRC Algorithm • Multiply xr M(x), where r = degree of G(x) • Add r Zeros to M(x), or Shift M(x) Left • Divide xr M(x)/G(x) = R(x) • R(x) = Reminder of Divide Operation • Transmit xr M(x) + R(x) = T(x) • XOR the Shifted Message and R(x) • At the Receiver, Recalculate the R(x) and Check Equal to the Transmitted FCS • Errors Occurred in Transmission if Not equal
CRC Error Detection • All Single Bit Errors • All Double Bit Errors • Any Odd Number of Errors • Any Burst Error for Which the Length of the Burst Error is Less Than the Length of the Divisor Polynomial, G(x) • Most Larger Burst Errors • Several G(x) Polynomials Have Been Used
Example of G(x) Polynomials • CRC-12 • X12 + X11 + X3 + X2 + X + 1 • CRC-16 • X16 + X15 + X2 + 1 • CRC-CCITT • X16 + X15 + X5 + 1 • CRC-32 • X32 + X26 + X23 + X22 + X16 + X12 + X11 + X10 + X8 + X7 + X5 + X4 + X2 + X + 1 • CRC’s Are Implemented in Shift registers
Error Control • Detection and correction of errors • Lost frames • Damaged frames • Automatic repeat request • Error detection • Positive acknowledgment • Retransmission after timeout • Negative acknowledgement and retransmission
Automatic Repeat Request (ARQ) • Stop and wait • Go back N • Selective reject (selective retransmission)
Stop and Wait • Source transmits single frame • Wait for ACK • If received frame damaged, discard it • Transmitter has timeout • If no ACK within timeout, retransmit • If ACK damaged,transmitter will not recognize it • Transmitter will retransmit • Receive gets two copies of frame • Use ACK0 and ACK1
Stop and Wait - Pros and Cons • Simple • Inefficient
Go Back N (1) • Based on sliding window • If no error, ACK as usual with next frame expected • Use window to control number of outstanding frames • If error, reply with rejection • Discard that frame and all future frames until error frame received correctly • Transmitter must go back and retransmit that frame and all subsequent frames
Go Back N - Damaged Frame • Receiver detects error in frame i • Receiver sends rejection-i • Transmitter gets rejection-i • Transmitter retransmits frame i and all subsequent
Go Back N - Lost Frame (1) • Frame i lost • Transmitter sends i+1 • Receiver gets frame i+1 out of sequence • Receiver send reject i • Transmitter goes back to frame i and retransmits
Go Back N - Lost Frame (2) • Frame i lost and no additional frame sent • Receiver gets nothing and returns neither acknowledgement nor rejection • Transmitter times out and sends acknowledgement frame with P bit set to 1 • Receiver interprets this as command which it acknowledges with the number of the next frame it expects (frame i ) • Transmitter then retransmits frame i
Go Back N - Damaged Acknowledgement • Receiver gets frame i and send acknowledgement (i+1) which is lost • Acknowledgements are cumulative, so next acknowledgement (i+n) may arrive before transmitter times out on frame i • If transmitter times out, it sends acknowledgement with P bit set as before • This can be repeated a number of times before a reset procedure is initiated
Go Back N - Damaged Rejection • As for lost frame (2)
Selective Reject • Also called selective retransmission • Only rejected frames are retransmitted • Subsequent frames are accepted by the receiver and buffered • Minimizes retransmission • Receiver must maintain large enough buffer • More complex logic in transmitter