Introduction to Computer Networks - Lecture Notes (PDF)

Document Details

DecisiveJasmine1286

Uploaded by DecisiveJasmine1286

University of Washington

Ran Dror

Tags

computer networking framing error detection error correction

Summary

These lecture notes provide an introduction to computer networking, covering fundamental concepts like framing, byte stuffing, and bit stuffing. They also detail error detection and correction methods like parity and checksums. The notes are presented in a slide format and include diagrams for visualization.

Full Transcript

Introduction to Computer Networks Ran Dror © Some Slides Adapted from: Computer Networking: A Top Down Approach Jim Kurose, Keith Ross, Addison-Wesley Introduction to Computer Networks Overview of the Link Layer Where we are in the Course Moving on to the Link Layer...

Introduction to Computer Networks Ran Dror © Some Slides Adapted from: Computer Networking: A Top Down Approach Jim Kurose, Keith Ross, Addison-Wesley Introduction to Computer Networks Overview of the Link Layer Where we are in the Course Moving on to the Link Layer! Application Transport Internet Link Physical Physical 3 Scope of the Link Layer Concerns how to transfer messages over one or more connected links – Messages are frames, of limited size – Builds on the physical layer Frame 4 In terms of layers … Network Link Virtual data path Physical Actual data path 5 In terms of layers Internet Link Virtual data path Physical Actual data path 6 Typical Implementation of Layers Transport Internet 7 Socket API API provided by the operating system implementing the transport layer and the layers below. 8 Topics 1. Framing 2. Error Coding Overview 3. Error Detection 4. Error Correction Next time: Retransmissions, Multiple Access and Switching. 9 Introduction to Computer Networks 1. Framing (§3.1.2) Topic The Physical layer gives us a stream of bits. How do we interpret it as a sequence of frames? Framing Methods We’ll look at: – Byte count » – Byte stuffing » – Bit stuffing » 12 Byte Count First try: – Let’s start each frame with a length field! – It’s simple, and hopefully good enough … 13 Byte Count (2) How well do you think it works? 14 Byte Count (3) Difficult to re-synchronize after framing error – Want an easy way to scan for a start of frame 15 Byte Stuffing Better idea: – Have a special flag byte value that means start/end of frame 0x12 0x37 0x48 0xA2 0x4B 0x15 0xAA 0x12 0x37 0x48 0xA2 0x4B 0x15 0xAA – What to do if we have the flag in the data? 0x12 0x37 0x48 0xAA 0x4B 0x15 0xAA 0x12 0x37 0x48 0xBB 0xAA 0x4B 0x15 0xAA – Replace (“stuff”) the flag inside the frame with an escape code escape means the following character is originally in the data Byte Stuffing – What to do if we have the escape code in the data? 0x12 0x37 0x48 0xBB 0x4B 0x15 0xAA 0x12 0x37 0x48 0xBB 0xBB 0x4B 0x15 0xAA 17 Byte Stuffing – Have a special flag byte value that means start/end of frame – Replace (“stuff”) the flag inside the frame with an escape code. escape means the following character is originally in the data – Complication: have to escape the escape code too! 18 Byte Stuffing (2) Rules: – Replace each FLAG in data with ESC FLAG – Replace each ESC in data with ESC ESC Now any unescaped FLAG is the start/end of a frame 19 Bit Stuffing Can stuff at the bit level too – Assume a flag is: 01111110 (0,six consecutive 1s,0) – On transmit, after five 1s in the data, insert a 0 – On receive, a 0 after five 1s is deleted 20 Bit Stuffing (2) Example: Data bits 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 101 1 1 1 101 1 0 0 1 0 0 1 1 1 1 1 1 0 Transmitted bits with stuffing and flags 21 Bit Stuffing (3) So how does it compare with byte stuffing? – Slightly less overhead. – More complicate because we have to deal with data not divided to bytes (octet) Byte stuffing is used in practice 22 Link Example: PPP over SONET (1) SONET - physical layer protocol commonly used over long optical fiber links (provide bit stream) PPP – (Point to Point Protocol) link protocol provides many features including framing. Protocol stacks 23 Link Example: PPP over SONET (2) Framing uses byte stuffing – FLAG is 0x7E and ESC is 0x7D. 01111110 01111101 24 Link Example: PPP over SONET (3) Byte stuffing method: – To stuff (unstuff) a byte: Add (Remove) ESC (0x7D) 0x20 = 0010 0000 XOR byte with 0x20 XOR with 0x20 toggle the 6th bit Example: 0x7E -> 0x7D7E -> 0x7D5E 0x7D -> 0x7D7D -> 0x7D5D – Removes FLAG from the contents of the frame 25 Framing Methods In practice, the physical layer often helps to identify frame boundaries – E.g., Ethernet, 802.11 26 IntroductiontotoComputer Introduction ComputerNetworks Networks 2. Error Coding Overview (§3.2) Problem – Noise may flip received bits 1 1 1 Signal 0 0 0 0 0 Slightly Noisy Very noisy 28 Topic Some bits will be received in error due to noise. What can we do? – Detect errors with codes » – Correct errors with codes » – Retransmit lost frames Later Reliability is a concern that cuts across the layers – we’ll see it again 29 Approach – Add Redundancy Error detection codes – Add check bits to the message bits to let some errors be detected (add redundancy) Error correction codes – Add more check bits to let some errors be corrected Key issue is now to structure the code to detect many errors with few check bits and modest computation 30 Motivating Example A simple code to handle errors: – Send two copies! Error if different. 10010 10010 10010 How good is this code? – How many errors can it correct/detect? – Correct – 0 – Detect – up to 5 errors if errors are in different bit positions – How many errors will make it fail? – 2 errors can fool it 31 Motivating Example (2) We want to handle more errors with less overhead – Will look at better codes; they are applied mathematics – But, they can’t handle all errors – And they focus on accidental errors (and not intentional - security) 32 Using Error Codes We will learn systematic block codes: Codeword consists of D data plus R check bits. Data bits Check bits D R=fn(D) Sender: – Compute R check bits based on the D data bits; send the codeword of D+R bits 33 Using Error Codes (2) Receiver: – Receive D’+R’ bits with unknown errors – Recompute R’’ check bits based on the D’ data bits; error if R’’ doesn’t match R’. Error could be in the check bits. Data bits Check bits D’ R’ ≠ = =? Illegal Legal R’’=fn(D’) Codeword Codeword 34 Intuition for Error Codes Example: Data bits Check bits D 800 bits R 16 bits How many codewords there are? 2816 (Legal and Illegal) How many Legal codewords there are? 2800 All 2D+R=2816 codewords 2D=2800 Legal codewords Intuition for Error Codes All 2D+R=2816 codewords 2D=2800 Legal codewords What are the chances of a codeword to be Legal codeword? 2800/2816=1/2R=1/216=0.001% When sending Legal codeword, and error flipped a bit, What are the chances that 1/2R=1/216=0.001% the new codeword is Legal codeword? Conclusion – method will detect random errors with good probability, with low overhead. R.W. Hamming (1915-1998) Much early work on codes: – “Error Detecting and Error Correcting Codes”, BSTJ, 1950 See also: – Course by Hamming on youtube "Learning to Learn” 1986 R.W. Hamming 37 Hamming Distance Hamming distance of two codewords, is the number of bit flips needed to change D1 to D2 Example: 2 codewords: 000, 111 2 codewords: 101, 111 Hamming distance = 3 Hamming distance = 1 Hamming distance of a code is the minimum distance between any pair of codewords Example: code: 0 → 0000000000, 1 → 0000011111, 2 → 1111100000, 3 → 1111111111 Hamming distance = 5 38 Hamming Distance Example: code: 000 0 → 000 1 → 111 100 010 001 Legal codeword: 000 111 110 101 011 Illegal codeword: 100 010 001 110 101 011 111 Hamming distance = 3 39 Hamming Distance (2) Error detection: 000 – For a code of distance d+1, up to d errors will always be 100 010 001 detected 110 101 011 Example: code: 0 → 000, 1 → 111 111 d+1=HD=3 => d=2 40 Hamming Distance (3) Error correction: – For a code of distance 2d+1, 000 up to d errors can always be corrected by mapping to the 100 010 001 closest codeword 110 101 011 Example: 111 code: 0 → 000, 1 → 111 2d+1=HD=3 => d=1 Hamming Distance (4) Visualization of another code: Legal codeword Hamming distance = 3 Error detection = 2 Error corection = 1 Illegal codeword 42 IntroductiontotoComputer Introduction ComputerNetworks Networks 3. Error Detection (§3.2.2) Topic Some bits may be received in error due to noise. How do we detect this? – Parity » – Checksums » – CRCs » Detection will let us fix the error, for example, by retransmission (later). 44 Simple Error Detection – Parity Bit 1 0 0 1 1 0 0 1 The sender: – Take D data bits, add 1 check bit that is the sum of the D bits. – Sum is modulo 2 (equivalent to XOR of all the bits) The receiver sum the data bits and compare to the parity, or add all the bits and it should get 0. 45 Parity Bit (2) How well does parity work? – What is the distance of the code? We check how many bits we need to flip to get from one legal codeword to another. Legal codeword is word with good checksum. flipping 2 bits will give a good parity sum (another legal codeword). Haming distance = 2 – Up to how many errors will it detect/correct? Detect=1 : 2 = d+1→ d=1 Correct=0 : 2 = 2d+1→ d=0 What about larger errors? Catch all odd number of errors – fail in half of the more then one error 46 Checksums Idea: sum up data in N-bit words – Widely used in, e.g., TCP/IP/UDP 16 bits Stronger protection than parity 47 Reminder: 1’s and 2’s complement Positive number representation: How to represent negative number in bits? – Use one bit as sign -> Bad, need to convert to other representation for calculations – 2’s complement – The left most bit represent -128 – 1’s complement – The left most bit represent -127 Reminder: 1’s and 2’s complement Binary 1’s comp Binary 2’s comp 00000000 +0 00000000 0 1’s comp 2’s comp 00000001 1 00000001 1 ⋮ ⋮ Left bit -127 -128 ⋮ ⋮ 01111101 125 represent 01111110 126 01111110 126 01111111 127 range -127 to +127 -128 to 127 01111111 127 10000000 -128 10000000 -127 Zero 2 representation 1 representation 10000001 -127 10000001 -126 Negation 1’s comp 2’s comp 10000010 -126 10000010 -125 operation flip all bits flip all bits and ⋮ ⋮ 11111110 ⋮ ⋮ add 1 -2 11111101 -2 (Another tricky method) 11111111 -1 11111110 -1 11111111 -0 Reminder: Decimal 1’s comp 2’s comp 1’s and 2’s complement +7 +6 0111 0110 0111 0110 +5 0101 0101 Addition +4 +3 0100 0011 0100 0011 +2 0010 0010 1’s comp 2’s comp +1 0001 0001 +0 0000 0000 -0 1111 -1 1110 1111 -2 1101 1110 -3 1100 1101 -4 1011 1100 -5 1010 1011 (In 2’s comp carry -6 1001 1010 1000 1001 doesn’t tell overflow) -7 -8 N/A 1000 Internet Checksum “The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words” – RFC 791 = the negative of the sum of 16 bit words, in one’s complement Example with 3 bit words: Sum Negation of sum (ones complement) (ones complement) 110 010 110+ 001→110 010 110 010 110 ----- 1 000 000+ 1 checksum ----- 001 0001f203f4f5f6f7???? Internet Checksum (3) 0001 Sending: f203 f4f5 1. Arrange data in 16-bit words f6f7 +(0000) 2. Put zero in checksum position, add ------ 2ddf0 ddf0 3. Add any carryover back to get 16 bits + 2 ------ ddf2 4. Negate (complement) to get checksum 220d 0001f203f4f5f6f7220d 0001f203f4f5f6f7220d Internet Checksum (5) Receiving: 0001 f203 1. Arrange data in 16-bit words f4f5 f6f7 2. Checksum will be non-zero, add + 220d ------ 2fffd fffd 3. Add any carryover back to get 16 bits + 2 ------ ffff 4. Negate the result and check, 0000 it should be 0 53 Internet Checksum (6) How well does the checksum work? – What is the Hamming distance of the code? Legal 110 010 100 010 Legal 110 110 000 010 codeword: 110+ Changing codeword: 110+ 010+ 110+ 100 2 bits 000 ----- give ----- 1 100 another 1 100 100+ legal codeword 100+ 1 1 ----- ----- 101 101 010 010 54 Internet Checksum (7) How well does the checksum work? – What is the distance of the code? Because it is sum, swapping 2 bits as in the last slide will give the same checksum. Haming distance = 2 – Up to how many errors will it detect/correct? Detect=1 : 2 = d+1→ d=1 Correct=0 : 2 = 2d+1→ d=0 What about larger errors? All bursts up to 16 detected. For random error 1/216 chance that the checksum match the data. (to get another legal codeword) 55 Internet Checksum (8) The Internet checksum is efficient and simple Errors are not random as a consequence, undetected errors are much more common than 1/216. but provides weak protection in some cases, because it is a simple sum. for example It does not detect: deletion or addition of zero data, swapping parts of the message, and other errors that are common in communication. 56 Cyclic Redundancy Check (CRC) Even stronger protection Given n data bits, generate k check bits such that: the n+k bits are evenly divisible by a known generator C n Data bits K Check bits % generator C = 0 Motivation example with decimal numbers: – n data bits = 302, k check bits = one digit, generator C = 3 – We look for x that: 302x % 3 = 0 3020 % 3 = 2 → x=1 3021 % 3 = 0 58 CRC The catch: – It’s based on mathematics of finite fields (Galois fields), in which “numbers” represent polynomials and operation are done modulo 2. 10011010 Addition Subtraction is 1x7 + 0x6 + 0x5 +1x4 +1x3 +0x2 +1x1 +0x0 = x7 + x 4 + x3 + x 1 Modulo 2 equal to bitwise XOR CRC Multiplication (we will not need) (x5+x3+x1)‧(x4+x2+1) = x9+x7+x5 + x7+x5+x3 + x5+x3+x1 = x9+x7+x7+x5+ x5+x5+x3 +x3+x1 = x9 + x5 + x1 Division CRC Long division is like binary except that: The minus is modulo 2 Number X is bigger then Y if it has as many bits as Y Identical CRC Known Generator: k+1 bits binary number Send Procedure: 1. Extend the n data bits with k zeros 2. Divide by the generator value C 3. Keep remainder, ignore quotient 4. Adjust k check bits by remainder Receive Procedure: 1. Divide and check for zero remainder 62 CRC Data bits: 100111 1 0 1 0 1 1 1 1 1 0 0 0 0 1101011111 Generator: C = 10011 k=4 63 CRC 64 CRC Protection depend on generator – There are few standard generators, with varying lengths. Standard CRC-32 is 10000010 01100000 10001110 110110111 Properties: – Depend on generator, for standard CRC-32 - HD=4, detects up to triple bit errors. (HD=6 is known) – Also odd number of errors – And bursts of up to k bits in error – Not vulnerable to systematic errors like checksums – Easy to compute CRC in hardware using shift register Error Detection in Practice CRCs are widely used on links – Ethernet, 802.11, ADSL, Cable … Internet Checksum used in Internet – IP, TCP, UDP … but it is weak Parity – Is little used 66 Introduction to Computer Networks 4. Error Correction (§3.2.3) Topic Some bits may be received in error due to noise. How do we fix them? – Hamming code » – Other codes » And why should we use detection when we can use correction? 68 Why Error Correction is Hard If we had reliable check bits we could use them to narrow down the position of the error – Then correction would be easy But error could be in the check bits as well as the data bits! – Data might even be correct 69 Intuition for Error Correcting Code Visualization of code: Single legal Hamming distance = 3 bit error A codeword If we assume errors are from A only 1 bit. We can correct them by mapping to the closest Three bit Illegal legal codeword errors to B codeword get to B 70 Intuition for Error Correcting Code Suppose we construct a code with a Hamming distance of at least 3 – Need ≥3 bit errors to change one legal codeword into another – Single bit errors will be closest to a unique legal codeword If we assume errors are only 1 bit, we can correct them by mapping an error to the closest legal codeword – Works for d errors if HD ≥ 2d + 1 71 Hamming Code 0 1 0 1 0 We will begin from simple parity check: – Take D data bits, add 1 check bit that is the sum of the D bits. – The receiver sum all the bits and it should get 0. – Assuming max 1 bit error we can detect the error. 72 Hamming Code 1 0 1 0 1 0 Adding parity bit Separating to two areas. Now (if there is only one error) we can know if the error is at the beginning middle or at the end. 73 Hamming Code Adding parity bit ①②③④⑤⑥⑦ 0 1 0 0 1 0 1 Separating to three areas. ① Now we can know 0 exactly the location of ⑤ ③ the error. (if there is 1 ⑦ 0 1 only one error) ④ ② 0 ⑥ 1 0 74 Hamming Code Example of error correction: ①②③④⑤⑥⑦ 0 1 1 0 1 0 1 – Check bit 1 circle: 1+1+1+0 = 1 error ① – Check bit 2 circle: 0 1+1+0+1 = 1 error ⑤ ③ – Check bit 4 circle: 1 ⑦ 1 1+1+0+0 = 0 no error 1 – Bit 3 is wrong ④ ② 0 ⑥ 1 correct message is: 0 0100101 75 Hamming Code Example of error correction ①②③④⑤⑥⑦ 0 1 1 0 1 0 1 – To find error position Recompute parity (parity sum including ① the check bit) and 0 arrange the result from ⑤ ③ 1 ⑦ right to left. 1 1 ④ ② ① ④ ② 0 ⑥ 1 0 1 1 = 3 0 76 Hamming Code Gives a method for constructing a code with a distance of 3 Plus an easy way to correct To encode: 1. Uses k check bits for 2k-k-1 data bits 2. Put check bits in positions p that are powers of 2, starting with position 1 3. Check bit in position p is parity of positions with a p term in their values 77 Hamming Code Example: data=0101 1. 3 check bits, 7 bit code 2. check bit positions 1, 2, 4 3. Check 1 covers positions 1, 3, 5, 7 Check 2 covers positions 2, 3, 6, 7 0 _ 1_ 0_ 0_ 1_ 0_ 1_ Check 4 covers positions 4, 5, 6, 7 1 2 3 4 5 6 7 p1(1,3,5,7) = 0+1+1 = 0 001 011 101 111 010 100 110 p2(2,3,6,7) = 0+0+1 = 1 p4(4,5,6,7) = 1+0+1 = 0 78 Hamming Code To decode: – Compute parity (parity sum including the check bit) – Arrange as a binary number from right to left – Value (syndrome) tells error position – Value of zero means no error – Otherwise, flip bit to correct 79 Hamming Code Example, continued p1(1,3,5,7) = 0+0+1+1 = 0 p2(2,3,6,7) = 1+0+0+1 = 0 p4(4,5,6,7) = 0+1+0+1 = 0 0 _ 1_ 0_ 0_ 1_ 0_ 1_ Syndrome = 000, no error 1 2 3 4 5 6 7 Data = 0 1 0 1 001 011 101 111 010 100 110 80 Hamming Code Example, continued p1(1,3,5,7) = 0+0+1+1 = 0 p2(2,3,6,7) = 1+0+1+1 = 1 p4(4,5,6,7) = 0+1+1+1 = 1 Error 0 _ 1_ 0_ 0_ 1_ 1_ 1_ Syndrome = 110 = 6 flip position 6 1 2 3 4 5 6 7 001 011 101 111 Data = 0 1 0 1 (correct after flip!) 010 100 110 81 Using Hamming code for burst errors With high speed transmission, one bit requires nanoseconds. Most interference lasts longer than that. Arrange in matrix, each row is a codeword. Normally would transmit this row-by-row. Trick: Transmit column-by- column. Other Error Correction Codes Codes used in practice are much more complicated than Hamming Convolutional codes (§3.2.3) – Take a stream of data and output a mix of the recent input bits – Decode using Viterbi algorithm - which can use bit confidence values from the physical layer – Flexible block length – Flexible code rate 83 Other Codes (2) – LDPC Low Density Parity Check (§3.2.3) – LDPC based on sparse matrices – Decoded iteratively using a belief propagation algorithm – State of the art today Invented by Robert Gallager in 1963 as part of his PhD thesis – Promptly forgotten until 1996 … Source: IEEE GHN, © 2009, IEEE 84 Error Correction in Practice Heavily used in physical layer – Convolutional codes widely used in practice – LDPC is the future, used for demanding links like 802.11, DVB, WiMAX, LTE, power-line,… – Used extensively in other application like storage (Reed- Solomon CDs, DVDs, Bar codes…) Error detection (w/ retransmission) is used in the link layer and above for residual errors Detection vs. Correction Example : 1000 bit messages, with a bit error rate (BER) of 1 in 10,000. Which is better (has less overhead) Detection or Correction? – It depends! We need to know more about the errors 86 Detection vs. Correction (2) – 1000 bit messages, bit error rate (BER) of 1 in 10,000 Case 1 Case 2 Random errors Max number of bit error in message Erroneous massages rate Correction overhead for message in bits Detection Detection vs. Correction (3) Case 1: Bit errors are random 1 message = 1000 bit bit error 1 in 10,000 bits 10 Message = 10,000 bit 1 Erroneous massage from 10 Conclusions: – Messages have 0 or maybe 1 error – Probability of 1/10 of Erroneous massage Detection vs. Correction (4) Case 1: Bit errors are random – Messages have 0 or maybe 1 error 10 – Probability of 1/10 of Erroneous massage Check bits Error correction: – Need ~10 check bits per message – Overhead: 10 message Error detection: – Need ~1 check bits per message plus 1000 bit retransmission 1/10 of the time – Overhead: 1 + 1/10*1000 = 101 89 Detection vs. Correction (5) Case 2: Errors comes in burst of 100 bit error 1 in 10,000 bits = burst of 100 bits errors in 1,000,000 bits 1 message = 1000 bit 1000 Message = 1,000,000 bit 1 or 2 Erroneous massage from 1000 Conclusions: – Messages have 0 bit errors or burst shorter then 100 – 1 or 2 Erroneous massage from 1000 Detection vs. Correction (6) Case 2: Errors come in bursts of 100 – Messages have 0 bit errors or burst

Use Quizgecko on...
Browser
Browser