1 / 52

The Data Link Layer

The Data Link Layer. Chapter 3. Data Link Layer Design Issues. Services Provided to the Network Layer Framing Error Control Flow Control. Functions of the Data Link Layer. Provide service interface to the network layer Dealing with transmission errors Regulating data flow

Télécharger la présentation

The Data Link Layer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Data Link Layer Chapter 3

  2. Data Link Layer Design Issues • Services Provided to the Network Layer • Framing • Error Control • Flow Control

  3. Functions of the Data Link Layer • Provide service interface to the network layer • Dealing with transmission errors • Regulating data flow • Slow receivers not swamped by fast senders • Services provided: • Unacknowledged connectionless service (e.g. if error rate low, for voice transmission, or for LANs) • Acknowledged connectionless service (e.g. for wireless systems: retransmissions are possible) • Acknowledged connection-oriented service  frames guaranteed to be received in right order and exactly once  3 phases: initialization, transmission, release

  4. Functions of the Data Link Layer (2) Relationship between packets and frames.

  5. Services Provided to Network Layer (a) Virtual communication. (b) Actual communication.

  6. Services Provided to Network Layer (2) Placement of the data link protocol.

  7. Framing A character stream. (a) Without errors. (b) With one error.

  8. Framing (2) (a) A frame delimited by flag bytes. (b) Four examples of byte sequences before and after stuffing.

  9. Framing (3) Bit stuffing (e.g. 01111110 is delimiter) (a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in receiver’s memory after destuffing.

  10. Error Detection and Correction • Types of Errors • Error-Correcting Codes • Error-Detecting Codes

  11. Types of Errors Single-Bit Error: Burst Error: (a) (b)

  12. Redundancy  All error detection/correction methods are based on redundancy

  13. Error Detection • Four basic detection methods: • Vertical Redundancy Check (VRC) • Longitudinal Redundancy Check (LRC) • Cyclic Redundancy Check (CRC) • Checksum • VRC (Parity Bit Method): Single-Bit errors are always detected. Burst errors detected, if number of errors is odd.

  14. LRC Original data 11100111 11011101 00111001 10101001 11100111 11011101 00111001 10101001 10101010 LRC 11100111 11011101 00111001 1010100110101010 Original data plus LRC LRC detects burst errors better than VRC:  Bursts less than number of columns are detected with a high probability Some error patterns remain undetected:  e.g. 2 bits in the same position but in different rows change their values

  15. CRC r bits r+1 bits r bits

  16. CRC • CRC Algorithm: • Let M be the frame to be sent. M is interpreted as a binary number. • Let G (divisor) be a binary number agreed on between sender and receiver. G should have r + 1 bits (G is the so-called generator polynomial of degree r). • Append r zero bits to right-end of the frame M and get f: f = M.2r • Divide the “bit string” f by G (using modulo 2 division): f = p.G + R (R has r or fewer bits and is the CRC) • Get T = f + R (= f – R = p.G,which is divisible by G) • T is now the checksummed frame to be transmitted.

  17. CRC Example: G M Message transmitted: T = 100100001

  18. CRC Why polynomials? Standard polynomials: (IEEE 802)

  19. CRC • CRC Performance: • Assume an error is described as a bit string E: e.g. E = 001010 means 2 error in second and fourth bit (from the right) • Receiver gets: T + E • Since T is divisible by G, E/G will determine whether or not an error can be detected. • Cases: • Single-Bit Error: E = 2i for some i.  Choose G with 2 or more terms (e.g. G = 2p +1). G does not divide 2i • Two-Bit Error: E = 2i + 2j = (2i-j +1)2i (with i > j).  G should include 2p + 1(to avoid the 2i term, see above)  Also, G should not divide 2i-j +1 for any (i-j=) k <= frame length  For example: G = 215 +214 +1 works for frames with length <= 32768 • E has an odd number of 1s:  Choose a G - as a number - that is divisible by 3

  20. CRC • CRC Performance (contd): • Burst Error: E = (2k-1 + … + 1).2i (E of length k). • G should be odd (i.e. it ends with 1) to avoid the factor 2i • Cases: • k-1 < r: burst length less than length of G: • Error always detected, since A mod B != 0 for any A < B and A != 0 • k-1 = r: burst length equal length of G: • Error is not detected iff E = G. However, because G begins/ends with 1, only the middle k-2 (= r-1) bits are decisive in this case. This constellation happens then with probability 1/2r-1 • k-1 > r: burst is arbitrarily long: • The length of the remainder (of E/G) is r. Hence, the probability of the error not being detected is 1/2r (remainder has r zeros)

  21. CRC 1 1 0 1 1 Adder 0 100100000 0 0 • Hardware Implementation: • Shift register of length r initialized to zero. • XOR gates added between cells where there is 1 in G (except for leftmost 1) • In each step, a bit is read from the message, the XOR operations activated, and then the shift operations. • Our example: • RegisterData • 000 100100000 • 001 00100000 • 010 0100000 • 100 100000 • 100 00000 • 101 0000 • 111 000 • 011 00 • 110 0 • 001 remainder

  22. Checksum

  23. Error Correction • Two methods: • Sender-based: First error detection, then ask sender to retransmit data in case of an error. • Automatic or Receiver-based: Here, receiver tries to find out after an error what the correct data might have been.  Error-correcting codes • In theory, it is possible to correct any detected error automatically, however, this is not done in practice, because it requires lots of redundancy (which is overhead). • How many redundant bits are needed to allow for correction? • Example for single-bit errors: • ASCII character = 7 Bits • Situations: No error, Error in 1st bit, Error in 2nd bit, …, Error in 7th bit. • At first glance, we would need 3 redundant bits to perform correction. • However, errors can affect the redundant bits, too.

  24. Error Correction • Number of redundant bits r should be chosen in such a way that all single-bit errors, and these are m+r+1 ones, can be corrected. • Since r bits can have 2r different states, a sufficient condition is: • 2r >= m+r+1 • For example, for ASCII code (m=7) the smallest value of r is 4: • 16 = 24 >= 7+4+1 = 12 • How many redundant bits are needed? (Contd)

  25. Error Correction • We now know how many redundant bits to use. The remaining question is how to use them to identify the bit in error.  Hamming code • Idea: • Place the redundant bits (r-bits) in different positions. • Each r-bit is the parity bit (or VRC bit) for a subset of the entire data. • Receiver checks the parity bits again, and can identify the bit in error (if any). • Placement of the r-bits for ASCII characters:  r-bits are placed in positions which are power of 2.

  26. Error Correction • Details of the r-bit placement: Let bi the binary representation of (position i). Pj the set of bits, which rj is responsible for.  Pj = {i, bi has a 1 at position j and i !=j} • Our example again:

  27. Error Correction • Our example: (contd)

  28. Error Correction • Calculating the values of the r-bits (sender side):

  29. Error Correction • Correcting a single-bit error (receiver side):  Assume bit 7 changed it value: received message = 10010100101

  30. Error Correction • Burst errors: • Hamming code can correct single-bit errors. In principle, same method can • be applied for burst errors, too. However, the number of the r-bits may grow • prohibitively for practical use. • However, there is a trick that makes Hamming code practical enough also for burst errors: • Idea: • 1. Use Hamming method for • k data units. • 2. Send those k codes column • by column. • 3. If |burst| <= k occurs, it would • affect different codes by • changing at most one bit. • 4. Thus, correct data can be • reconstructed, since Hamming • code can correct single-bit errors

  31. Data Link Layer Protocols • Main task of these protocols: • Flow control: Curb (fast) sender so that it does not overwhelm receiver. • Error control: Handle errors • Types of flow control: • Stop-and-wait: Wait for acknowledgement of sent frame prior to sending a new one. •  individual acknowledgement for each frame • Sliding Window: Multiple frames can be sent without acknowledgement •  acknowledgement is not individual for each frame • Error control: • Adds error handling to protocols for flow control. • Types of errors: • Frame is damaged (and no correction is used or possible) • Frame is lost • Acknowledgement is lost • Negative acknowledgement is lost (if used)

  32. Data Link Layer Protocols

  33. Flow Control • Stop-and-Wait: • Sender waits after each sent frame until corresponding acknowledgement arrives • In this way, receiver will not be overwhelmed with frames • + Simple • Inefficient: •  transmission time • doubled •  Bandwidth wasted

  34. Flow Control • Sliding Window: • Multiple frames may be in transit at a time • Window prevents sender from overwhelming the receiver • More precisely: • Both sender and receiver have a window with same size n. • Frames are numbered modulo n+1 • Acknowledgements also carry a number (mod n+1), which identifies the • next frame expected by the receiver • The window can hold n frames at either ends, hence at most n frames can be sent without a need for acknowledgement. • Example: n = 7 • Frames are numbered mod 8 e.g. • 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 … • If receiver sends ACK 5, the sender would understand that all frames up to number 4 have been successfully received.

  35. Flow Control • Sender Sliding Window: • Assume data are fed (by network layer) from the right, then: • Sender window shrinks from the left when frames are sent • Sender window expands to the right when acknowledgements are received • Example: If frame 0, 1, 2, 3, 4 have been sent  W = {5, 6} • If ACK 4 arrives later  W = {5, 6, 7, 0, 1, 2} to physical layer from network layer

  36. Flow Control • Receiver Sliding Window: • Assume data are fed (by physical layer) from the left, then: • Receiver window shrinks from the left when frames are received • Receiver window expands to the right when acknowledgements are sent • Example: If frame 0, 1, 2, 3, 4, 5 have been received  W = {6} • If ACK 2 has been sent  W = {6, 7, 0} • If ACK 5 has been sent  W = {6, 7, 0, 1, 2, 3} • (new win size = old win size + (current ACK# - previous ACK#) mod 8) from physical layer to network layer

  37. Flow Control: Example

  38. Error Control • Idea: • Integrate error handling with flow control. • Error control refers mainly to methods of error detection and retransmission. • Error control is based on ARQ (Automatic Repeat Request). • ARQ policy: On error detection, send NAK and let sender retransmit a frame. • Sender uses in general a timer to detect errors (lost ACK/NAK). • Again, errors are: corrupted frame, lost frame, or lost ACK/NAK • Classification:

  39. Error Control • Stop-and-Wait ARQ: • Simple Stop-and-Wait flow control + retransmission in case of errors • Rules for retransmission: • Sender keeps copy of last transmitted frame until an ACK arrives • Both data frames and ACK are numbered alternatively 0 and 1. For example, ACK1 means that receiver accepted data frame 0 and is expecting data frame 1. • If an error is detected in a frame, a NAK is send by receiver. NAKs are not numbered and tell sender to retransmit last frame. • Sender uses a timer, after a timeout (without ACK) sender retransmits last frame. • Error handling: • Damaged frame • Lost frame • Lost ACK/NAK

  40. Stop-and-Wait ARQ : Damaged Frame Example for a damaged frame 0 1 0 Error in frame 0 Retransmission 0

  41. Stop-and-Wait ARQ: Lost Frame ACK 0

  42. Stop-and-Wait ARQ: Lost ACK/NAK 0 ACK 0 Second copy discarded ACK 0

  43. Sliding Window ARQ • New Features (added to basic sliding window flow control): • Sender keeps copies of frames which are not acknowledged yet. • In addition to ACK receivers uses also NAKs. • Both are numbered: • ACK carries the number of next frame expected. • NAK carries the number of the damaged frame itself (which is the expected one). • Examples: • If last ACK was numbered 4, an ACK 7 means that frames 4, 5, and 6 have been received correctly. • If frame 8 and 9 were damaged, both NAK 8 and NAK 9 are returned, but NAK 8 tells sender that previous frames were intact. • Sender has a timer. Since n (window size) frames can be sent without acknowledgement, sender starts the timer after sending n frames if their ACK is still missing. • On timeout, sender resends one/multiple frames (depending on protocol). Receiver must be able to recognize duplicates. • Two protocols: Go-Back-n ARQ and Selective Reject ARQ

  44. Go-Back-n ARQ • Idea: If frame is lost/damaged all frames since the last ACK are resent. • Damaged frame: Resent Resent Resent

  45. Go-Back-n ARQ • Lost frame: Receiver detects 2 is skipped Resent Resent Resent

  46. Go-Back-n ARQ • Lost ACK: Sender has to send 3 frames only (otherwise window size is decisive) Resent discard Resent discard Resent discard Resent ACK 3

  47. Selective Reject ARQ • Idea: • Resend only the specific lost/damaged frame. • If NAK is returned, sender retransmits only specified frame (out of sequence). • This means that receiver must be able to sort frames and insert a retransmitted frame in its proper place in the sequence. • Requirements: • Receiver should have a sorting logic to enable to reorder frames received out of sequence. • Receiver must be able to store frames after a NAK has been sent until the damaged frame has been replaced. • A buffer in the receiver must keep all frames until all retransmissions have been sorted and any duplicate frames have been identified and discarded. • To aid selectivity, ACK numbers, like NAK numbers should refer to the frame received (or lost) instead of the next frame expected. • Sender must have a searching logic that allow to find and select the frame to be retransmitted. • For efficiency, window size is recommended to be less than or equal 1+n/2 where n is the Go-Back-n window size.

  48. Selective Reject ARQ • Damaged frame: Receiver accepts further frames but must not return an ACK until frame 2 is retransmitted ACK 5

  49. Selective Reject ARQ • Lost frame: If frame 2 was last frame, sender treats this case as a lost ACK Receiver detects 2 is skipped 3 Data NAK 2 Resent Data 2 4 Data 5 Data 2 Data 5 Data

  50. Selective Reject ARQ • Lost ACK/NAK: • Like in Go-Back-n. • When sender reaches capacity of window or the end of its transmission, it sets a timer. • If after timeout no ACK arrives, sender retransmits all frames that are not acknowledged yet. • Receiver should recognize duplicates and discard them. • Go-Back-n vs. Selective Reject: • Communication overhead: • Go-Back-n > Selective Reject • Logic complexity: • Selective Reject > Go-Back-n • However, in practice Go-Back-n is used more often (due to its simplicity). • Remark: • Note that stop-and-wait is a special case of the sliding window protocol with a window size of 1.

More Related