Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 University of Calgary CS 441 Part 3 The Data Link Layer 3.1 Framing & Error Control 3.2 Error & Flow Control.

Similar presentations


Presentation on theme: "1 University of Calgary CS 441 Part 3 The Data Link Layer 3.1 Framing & Error Control 3.2 Error & Flow Control."— Presentation transcript:

1 1 University of Calgary CS 441 Part 3 The Data Link Layer 3.1 Framing & Error Control 3.2 Error & Flow Control

2 2 University of Calgary CS 441 3.1 Framing & Error Control Asynchronous Character Transmission Synchronous Frame Transmission Error Detection Hamming Distance Cyclic Redundancy Checks CRC Implementation Forward Error Control Backward Error Control

3 3 University of Calgary CS 441 Network, Data Link, Physical Layers physical channel Network Layer Data Link Layer Physical Layer Data Link Layer Network Layer virtual paths packets frames bits

4 4 University of Calgary CS 441 Data Link Layer Requirements Accept Packets from Network Layer on Host A and transfer to Network Layer on Host B Transfer (Packets only) without errors Deliver Packets in the order received Deliver one and only one copy of each Packet If errors are rare this may not be efficient, i.e., the overhead associated with reliable transfer Higher Layers can deal with end to end errors

5 5 University of Calgary CS 441 Medium Access Control (MAC) Layer Data Link layer Physical layer Data Link Control Medium Access Control (MAC) Physical layer

6 6 University of Calgary CS 441 Point to Point Establishment - ENQ (enquiry), ACK, NAC, ERP (error procedure) Data Transfer Termination - EOT ENQ ACK frame ACK A B

7 7 University of Calgary CS 441 Asynchronous Character Transmission data transmission one character at a time otherwise idle sending binary 1, NRZ-L -volts start bit is transition to 0 then 7 bit ASCII followed by parity bit final is a stop bit, a binary 1, for 1, 1.5, or 2 times the normal bit duration receiver can be easily synchronized overhead of 2-3 bits per character, ~2/9 = 22%

8 8 University of Calgary CS 441 Synchronous Frame Transmission block or frame transmission ~1000 bits character/byte oriented frame is >= 1 synch characters; control characters; data characters; control characters bit oriented frame is 8 bit flag, control field, data, control field, 8 bit flag bit stuffing needed for the latter in HDLC have 48 bits of control & flags which for 1000 bit message gives 4.6% overhead

9 9 University of Calgary CS 441 Framing Physical Layer transfers bits unreliably Framing enables efficient error control and synchronization on a bunch of bits Could insert number of characters in header Errors again make it very hard to re- synchronize, where is start of next frame if an error? Can deal with by using DLE STX and DLE ETX frame start and stop characters Disadvantage with this method is that its closely tied to 8 bit characters and to ASCII.

10 10 University of Calgary CS 441 Framing - Character Stuffing frame starts with ASCII characters DLE STX frame ends with ASCII characters DLE ETX +DLE: Data Link Escape +STX: Start of Text +ETX: End of Text problem: ok for ASCII text, but binary data may have sequences matching these codes solution: character stuffing +matches in data to DLE are "escaped" +sender inserts DLE before accidental one +receiver detects two DLE's, removes one

11 11 University of Calgary CS 441 Framing - bit stuffing Start and end a Frame with a flag byte : 01111110 Whenever the sender sees five 1s occur in a row in the data it inserts a 0 Whenever the receiver sees five 1s followed by a 0, it deletes the 0 Bit stuffing is completely transparent to the Network Layer Frames can be unambiguously recognized When nothing to send can send flags

12 12 University of Calgary CS 441 Errors in Physical Layer - Review caused by +impulse noise +thermal noise +crosstalk +attenuation +frequency-dependent nature of -amplitude -propagation speed -phase +microwave interference, etc

13 13 University of Calgary CS 441 Errors are Bursty advantage: destroys occasional frames, rather than many frames +eg independent errors, with error rate of 0.001 bits/sec, frame size = 1000bits -average of one error per frame! +eg same error rate, but errors come in bursts of 100 -average error rate of 1-2 frames/100 disadvantage: harder to detect and correct, difficult to model mathematically

14 14 University of Calgary CS 441 Coding Theory: Dealing with Errors error detection +redundant (additional) information sent in a frame to allow receiver to detect errors error correction +even more redundancy to allow errors to be detected and then corrected codeword: +a frame with m (message) data bits and r (redundant) check bits and n = m + r total bits

15 15 University of Calgary CS 441 Hamming Distance the bit difference d between two code words, -algorithm: Exclusive OR two code words, count the 1 bits in the result -1 0 0 1 1 0 1 code word 1 -1 1 0 0 1 0 1 code word 2 -0 1 0 1 0 0 0 X-OR'd result, -Hamming distance = 2

16 16 University of Calgary CS 441 Hamming Distance Hamming distance of complete code: +all 2**m possible data messages are legal +not all 2**n codewords are legal +h.d. of complete code: -find the minimum Hamming Distance between any two code words this minimum Hamming Distance is the Hamming Distance of that complete code

17 17 University of Calgary CS 441 Significance of Hamming Distance d single-bit errors are required to convert one codeword to into another +if two legal code words differ by 2 bits, then there have to be at least 2 bits in error to accidentaly convert one to the other to detect d errors requires a distance d+1 code +if the Hamming Distance of complete code is 3, all legal words differ by “at least” 3 bits +any legal codeword with only 2 bits in error cannot produce another (different) legal codeword

18 18 University of Calgary CS 441 Significance of Hamming Distance, Cont’d to correct d errors requires distance 2d+1 code +consider code with 5 bit Hamming Distance, ie all legal codes differ by “at least” 5 bits +if 2 bit errors occur within a codeword -h.d. illegal codeword to original = 2 -h.d. illegal codeword to any other legal codeword >= 3 therefore can recognize original code word

19 19 University of Calgary CS 441 Example 1: error detection via parity bits add single "parity" bit to data so that +# "1" bits in codeword is even (even parity), or +# "1" bits in codeword is odd (odd parity) -eg 2 bits data, 1 bit odd parity: 100 001 010 111 Hamming Distance = 2, therefore can detect all 1 bit errors

20 20 University of Calgary CS 441 Example 2: error correction code 4 valid codewords, Hamming Distance = 5 +0000000000 +0000011111 +1111100000 +1111111111 +can guarantee to correct 2 errors -2 bit error corrected: +0000000000->0011000000, closest to 0000000000 -eg 3 bit error detected but not corrected: +0000000000->0011100000, closest to 1111100000

21 21 University of Calgary CS 441 Forward Error Correction corrects by detecting +single bit error in a code word +the error's position in the code word uses theoretical minimum number of check bits required to correct single errors can also be used to detect burst errors forward error correction is much less efficient than detection and retransmission forward error correction is used where retransmission is impractical, eg broadcast, satellite situations, deep space probes

22 22 University of Calgary CS 441 Minimum check bits to correct single errors m message bits, r check bits, n=m+r 2 legal messages have n illegal words at distance 1 (invert each bit in legal word) thus dedicate n+1 code words to each legal message total number of code words is 2 >=(n+1)2 Hamming’s forward code achieved this limit +number the bits starting with 1 from left +bits that are powers of 2 are check bits +rest (3, 5, 6, 7, 9,...) are message bits +each message bit = sum of powers of 2 +each check bit makes the sum of its appearances in message sums + self = even (or odd) m nm

23 23 University of Calgary CS 441 Example 3: Hamming forward error correction msg = 1001000 (3rd=2+1, 7th=4+2+1) 1st = 1+1+self=1+1+0=0 (for even parity) 2nd = 1+1+self=0 4th = 1+self=1 8th = self = 0 code = 0 0 1 1 0 0 1 0 0 0 0 receiver tests each check bit k (=1,2,4,...) if wrong adds k to counter if counter 0 then word correct else it contains the number of the incorrect bit eg, if 2 & 4 bits wrong, counter = 6, then 6th wrong

24 24 University of Calgary CS 441 Hamming Forward Burst Error Correction k codewords define k rows in a k by n matrix instead of sending rows, send columns collect the k columns at receiving end and reform the k by n matrix if a burst error of length,=k occurs it will cause at most one error per word, => correctable kr check bits for data blocks of size km enables correcting burst errors of up to k bits

25 25 University of Calgary CS 441 Cyclic Redundancy Checks (CRC) given m bit message M add R, an r bit frame checksum = frame of m+r = n bits = T R, the r bit checksum, is the remainder of dividing M by G, a constant r+1 bit number thus : +T = 2 r M + R +where R = remainder R of 2 r M/ G +then +T/ G = 2 r M/ G + R / G = Q + R/ G + R / G = Q ie, if no remainder (T/G=Q) then correct m must be greater than r

26 26 University of Calgary CS 441 Review Modulo 2 Arithmetic examples 1111 + 1010 = 0101 1111 - 1010 = 0101 1010 + 0101 = 1111 1010 - 0101 = 1111 11 * 11001 = 110010 + 11001 = 101011 101/ 11 = 11 remainder 0 11 * 11 = 11 + 110 = 101

27 27 University of Calgary CS 441 Example - M = 11011 & generator G = 1011 compute R = remainder of (2 r M + 000)/G 11011000 / 1011 = 11111 + 001/ 1011 thus T = 11011001 11011001/ 1011 = 11111

28 28 University of Calgary CS 441 Polynomial Arithmetic 1011 = x 3 + x + 1 = M(x) Generator G(x) = x 5 + x 3 + 1 = 101001 still use modulo 2 arithmetic G always of the form 1... 1 CRC-16 = X 16 + X 15 + X 2 + 1 T(x) = x r M(x) + R(x) TR(x) = T(x) + E(x) where E = error pattern

29 29 University of Calgary CS 441 CRC Error Detection An error is undetectable IFF E divisible by G TR(x) = T(x) + E(x) TR(x)/G = T(x)/G(x) + E(x)/G(x) = Q + E(X)/G(x) CRC-16=G(x)= X 16 + X 15 + X 2 + 1 = 11000000000000101 all single & double bit errors any odd number of errors if G(x) contains x+1 any burst error of length <= r = 16 99.997% of 17 bit bursts 99.998% of 18 bit and longer bursts

30 30 University of Calgary CS 441 Shift Register Implementation of CRC (0) 0 0 0 0 0 <= 1010001101 00000 = 2 n M + 00000 (1) 0 0 0 0 1 <= 010001101 00000 - left shift 1 bit (5) 1 0 1 0 0 <= 01101 00000 (6) 1 1 1 0 1 <= 1101 00000 (7) 0 1 1 1 0 <= 101 00000 (15) 0 1 1 1 0 <= after all 15 shifts have R C4 + C3 C2 C1 C0 + +

31 31 University of Calgary CS 441 Receiver Implementation of CRC have duplicate logic received bits for M shifted into register this should leave R in shift register as the received R bits are shifted in they will zero out the register if the register isn’t all zeros then an error has occured in TR /= T = 2 n M + R and E(X) /= 0

32 32 University of Calgary CS 441 Coding Theory view legal code words as points in multidimensional space want to develop complete codes with maximum Hamming Distance, ie, idealy all are further apart than some minimum Hamming distance can detect d errors if minimum Hamming Distance is d+1 can correct d errors if minimum distance is 2d+1 forward error correction imposes this 2d+1 overhead on every message backward error correction incurs overhead to retransmit which should be rare


Download ppt "1 University of Calgary CS 441 Part 3 The Data Link Layer 3.1 Framing & Error Control 3.2 Error & Flow Control."

Similar presentations


Ads by Google