38
CSE 123: Computer Networks Lecture 4: Reliable Transmission HW 1 out Friday

Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

CSE 123: Computer Networks

Lecture 4:Reliable Transmission

HW 1 out Friday

Page 2: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Lecture 4 Overview

! Finishing Error Detectionu Checksumsu Cyclic Remainder Check (CRC)

! Handling errorsu Automatic Repeat Request (ARQ)u Acknowledgements (ACKs) and timeouts

u Stop-and-Wait

2CSE 123 – Lecture 4: Reliable Transmission

Page 3: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Per-Frame Detection Codes

! Want to add an error detection code per frameu Frame is unit of transmission; all or nothing.u Computed over the entire frame—including header! Why?

! Receiver checks EDC to make sure frame is validu If frame fails check, throw it away

! We could use error-correcting codesu But they are less efficient, and we expect errors to be rareu Counter example: wireless communication

3

PayloadHeader EDC

CSE 123 – Lecture 4: Error Handling

Page 4: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Two-Dimensional Parity

! Start with normal parityu n data bits, 1 one parity bit

! Do the same across rowsu m data bytes, 1 parity byte

! Can detect up to 3 bit errorsu Even most 4-bit errors

! Can correct any 1 bit erroru Why?

4

1

0

1

1

1

0

1111011 0

Parity Bits

Parity Byte

0101001

1101001

1011110

0001110

0110100

1011111

Data

CSE 123 – Lecture 4: Error Handling

Page 5: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksums! Simply sum up all of the data in the frame

u Transmit that sum as the EDC

! Extremely lightweightu Easy to compute fast in hardwareu Fragile: Hamming Distance of 2

So can only detect how many bit errors (poll)?

! Also easy to modify if frame is modified in flightu Happens a lot to packets on the Internet

! IP packets include a 1’s compliment checksum

5CSE 123 – Lecture 4: Error Handling

Page 6: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

IP 16bit Checksum Example

6

u_short cksum(u_short *buf, int count) {register u_long sum = 0;while (count--) {

sum += *buf++;if (sum & 0xFFFF0000) {/* carry occurred, so wrap around */

sum &= 0xFFFF;sum++;

}}

return ~(sum & 0xFFFF);}

! 1’s compliment of sum of words (not bytes)u Final 1’s compliment means all-zero frame is not valid

CSE 123 – Lecture 4: Error Handling

Page 7: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum in Hardware

! Compute checksum in Modulo-2 Arithmeticu Addition/subtraction is simply XOR operationu Equivalent to vertical parity computation

! Need only a word-length shift register and XOR gateu Assuming data arrives seriallyu All registers are initially 0

7

+

CSE 123 – Lecture 4: Error Handling

Page 8: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

8

11110110Parity Byte

01010011

11010010

10111101

00011101

01101001

10111110

Data

01010011110100101011110100011101011010011011111011110110

CSE 123 – Lecture 4: Error Handling

Page 9: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

9

0 0 0 0 0 0 0 0 +

Parity Byte

Data

0101…

01010011110100101011110100011101011010011011111011110110

CSE 123 – Lecture 4: Error Handling

Page 10: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

10

0 0 0 0 0 0 0 0 +

0Data

1010…

01010011110100101011110100011101011010011011111011110110

CSE 123 – Lecture 4: Error Handling

Page 11: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

11

0 0 0 0 0 0 0 1 +

01

0100…

01010011110100101011110100011101011010011011111011110110

Data

CSE 123 – Lecture 4: Error Handling

Page 12: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

12

0 0 0 0 0 0 1 0 +

010

1001…

01010011110100101011110100011101011010011011111011110110

Data

CSE 123 – Lecture 4: Error Handling

Page 13: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

13

0 0 0 0 0 1 0 1 +

0101

0011…

01010011110100101011110100011101011010011011111011110110

Data

CSE 123 – Lecture 4: Error Handling

Page 14: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

14

0 1 0 1 0 0 1 1 +

01010011

1101…

01010011110100101011110100011101011010011011111011110110

Data

CSE 123 – Lecture 4: Error Handling

Page 15: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

15

1 0 1 0 0 1 1 1 +

1

01010011

1

1010…

01010011110100101011110100011101011010011011111011110110

Data

Parity Byte

CSE 123 – Lecture 4: Error Handling

Page 16: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

16

0 1 0 0 1 1 1 0 +

10

01010011

11

0100…

01010011110100101011110100011101011010011011111011110110

Data

Parity Byte

CSE 123 – Lecture 4: Error Handling

Page 17: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

17

1 0 0 0 0 0 0 1 +

10000001Parity Byte

01010011

11010010

1011…

01010011110100101011110100011101011010011011111011110110

Data

CSE 123 – Lecture 4: Error Handling

Page 18: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

18

0 0 0 0 0 0 1 0 +

0Parity Byte

01010011

11010010

0111…

01010011110100101011110100011101011010011011111011110110

Data

1

CSE 123 – Lecture 4: Error Handling

Prior parity result

Page 19: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Checksum Example

19

1 1 1 1 0 1 1 0 +

11110110Parity Byte

01010011

11010010

10111101

00011101

01101001

10111110

Data

01010011110100101011110100011101011010011011111011110110

CSE 123 – Lecture 4: Error Handling

Page 20: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

From Sums to Remainders! Checksums are easy to compute, but very fragile

u In particular, burst errors are frequently undetectedu We’d rather have a scheme that “smears” parity

! Need to remain easy to implement in hardwareu So far just shift registers and an XOR gate

! We’ll stick to Modulo-2 arithmeticu Multiplication and division are XOR-based as wellu Let’s do some examples…

20CSE 123 – Lecture 4: Error Handling

Page 21: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Modulo-2 Arithmetic! Multiplication

1101110

000011010

110100101110

! Division

1101110 101110

110111110011000110

21CSE 120 – Lecture 1: Course Introduction

Page 22: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Cyclic Remainder Check

22

! Idea is to divide the incoming data, D, rather than addu The divisor is called the generator, g

! We can make a CRC resilient to k-bit burst errorsu Need a generator of k+1 bits

! Divide 2kD by g to get remainder, ru Remainder is called frame check sequence

! Send 2kD – r (i.e., 2kD XOR r)u Note 2kD is just D shifted left k bitsu Remainder must be at most k bits

! Receiver checks that (2kD-r)/g = 0

CSE 123 – Lecture 4: Error Handling

Page 23: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Error Detection – CRC! View data bits, D, as a binary number! Choose r+1 bit pattern (generator), G! Goal: choose r CRC bits, R, such that

u <D,R> exactly divisible by G (modulo 2) u Receiver knows G, divides <D,R> by G. If non-zero remainder: error

detected!u Can detect all burst errors less than r+1 bits

! Widely used in practice (Ethernet, FDDI, ATM)

23CSE 123 – Lecture 4: Reliable Transmission

Page 24: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

CRC: Rooted in Polynomials! We’re actually doing polynomial arithmetic

u Each bit is actually a coefficient of corresponding term in a kth-degree polynomial

1101 is (1 * X3) + (1 * X2) + (0 * X1) + (1 * X0)

! Why do we care?u Can use the properties of finite fields to analyze effectivenessu Says any generator with two terms catches single bit errors

24CSE 123 – Lecture 4: Reliable Transmission

Page 25: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

CRC Example Encoding

25

10011101

10001101

10111101

11001101

10001101

1101

k + 1 bit check sequence g, equivalent to a degree-kpolynomial

1011101Remainder

D mod g

10011010000 Message plus kzeros (*2k)

Result:

Transmit message followed by remainder:

10011010101

x3 + x2 + 1 = 1101 Generatorx7 + x4 + x3 + x = 10011010 Message

CSE 123 – Lecture 4: Reliable Transmission

Page 26: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

CRC Example Decoding

26

10011101

10001101

10111101

11001101

11011101

1101

k + 1 bit check sequence g, equivalent to a degree-kpolynomial

01101Remainder

D mod g

10011010101 Received message, no errors

Result:

CRC test is passed

x3 + x2 + 1 = 1101 Generatorx10 + x7 + x6 + x4 + x2 + 1 = 10011010101 Received Message

CSE 123 – Lecture 4: Reliable Transmission

Page 27: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

CRC Example Failure

27

10001101

10111101

11011101

1101

k + 1 bit check sequence g, equivalent to a degree-kpolynomial

01011101

RemainderD mod g

10010110101 Received message

Result:

CRC test failed

Two bit errors

x3 + x2 + 1 = 1101 Generatorx10 + x7 + x5 + x4 + x2 + 1 = 10010110101 Received Message

CSE 123 – Lecture 4: Reliable Transmission

Page 28: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Common Generators

28

CRC-8 x8 + x2 + x1 + 1

CRC-10 x10 + x9 + x5 + x4 + x1 + 1

CRC-12 x12 + x11 + x3 + x2 + x1 + 1

CRC-16 x16 + x15 + x2 + 1

CRC-CCITT x16 + x12 + x5 + 1

CRC-32 x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x1 + 1

CSE 123 – Lecture 4: Reliable Transmission

Page 29: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Error Handling Summary! Add redundant bits to detect if frame has errors

u A few bits can detect errorsu Need more to correct errors

! Strength of code depends on Hamming Distanceu Number of bitflips between codewords

! Checksums and CRCs are typical methodsu Both cheap and easy to implement in hardwareu CRC much more robust against burst errors

30CSE 123 – Lecture 4: Reliable Transmission

Page 30: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Picking up the Pieces! Link layer is lossy

u We deliberately throw away corrupt frames!u Infrequent bit errors still lead to occasional frame errors

» 10,000+ bits in each frame

! Things get even harrier if we consider multiple linksu In a few lectures, we’ll start sending frames on long tripsu Each intermediate stop might lose, corrupt, reorder, etc.u Regardless of cause, we’ll call loss events drops

! We want to provide reliable, in-order deliveryu Can—and will—do this at multiple layers

31CSE 123 – Lecture 4: Reliable Transmission

Page 31: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Moving up the Stack

32

HTTP

TCP

IP

Ethernetinterface

HTTP

TCP

IP

Ethernetinterface

IP

IP

Ethernetinterface

Ethernetinterface

SONETinterface

SONETinterface

host host

router router

Application Layer

Transport Layer

Network Layer

Link Layer

CSE 123 – Lecture 4: Reliable Transmission

Page 32: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Reliable Transmission! The packet-based version of the same problem

u How do we reliably send a message when packets (not just bits) can be lost/corrupted in the network?

! Two optionsu Detect a loss/corruption and retransmit

u Send data redundantly to tolerate loss/corruption

33CSE 123 – Lecture 4: Reliable Transmission

Page 33: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Simple Idea: ARQ

! Receiver sends acknowledgments (ACKs)u Sender “times out” and retransmits if it doesn’t receive them

! Basic approach is generically referred to as Automatic Repeat Request (ARQ)

Sender Receiver

Data

ACKTim

e

Tim

eout

Data

ACKTim

eout

T

Data

Sender Receiver

imeo

ut

34CSE 123 – Lecture 4: Reliable Transmission

Page 34: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Not So Fast…

! Loss can occur on ACK channel as wellu Sender cannot distinguish data loss from ACK lossu Sender will retransmit the data frame

! ACK loss—or early timeout—results in duplicationu The receiver thinks the retransmission is new data

Sender Receiver

Data

ACKTim

eout

Data

ACKTim

eout

35

Sender Receiver

Data

ACKTim

eout

Data

ACKTim

eout

Duplicate!

CSE 123 – Lecture 4: Reliable Transmission

Page 35: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Sequence Numbers

! Sequence numbers solve this problemu Receiver can simply ignore duplicate datau But must still send an ACK! (Why?)

! Simplest ARQ: Stop-and-waitu Only one outstanding frame at a time

36

Sender Receiver

Data 0

ACK 0Tim

eout

Data 1

ACK 1Tim

eout

Sender Receiver

Data 0

ACK 0Tim

eout

Data 0

ACK 0Tim

eout Data 1

ACK 1

Ignored!

CSE 123 – Lecture 4: Reliable Transmission

Page 36: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Stop-and-Wait Performance

! Lousy performance if xmit 1 pkt << prop. delayu How bad?

! Want to utilize all available bandwidthu Need to keep more data “in flight”u How much? Called the bandwidth-delay product

! Also limited by quality of timeout (how long?)

37CSE 123 – Lecture 4: Reliable Transmission

Page 37: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

Pipelined Transmission

! Keep multiple packets “in flight”u Allows sender to make efficient use of the linku Sequence numbers ensure receiver can distinguish frames

! Sender buffers outstanding un-acked packetsu Receiver ACKs the highest consecutive frame received

» ACKs are cumulative (covers current frame and all previous)

38

Sender Receiver

Data 0

ACK 0

Data 1 Data 2Data 3 ACK 1

ACK 2

ACK 3

Sender Receiver

Data 0

ACK 0

Data 1 Data 2Data 3 ACK 1

ACK 1 Ignored!

CSE 123 – Lecture 4: Reliable Transmission

Page 38: Lecture 4: Reliable Transmission › classes › sp20 › cse123-a › lectures › 123-sp20-l4.pdfCSE 123 –Lecture 4: Reliable Transmission 24. CRC Example Encoding 25 1001 1101

For Next Time

! Homework 1 is out Friday due in one week

39CSE 123 – Lecture 4: Reliable Transmission