TCP contd…. - courses.cs.washington.edu

Post on 02-Apr-2022

20 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

TCP contd ….

Last class• Connection setup

This class• Connection release

CSE 461 University of Washington 2

Recap: Connection setup

•Three-way handshake:• Client sends SYN(x)• Server replies with SYN(y)ACK(x+1)• Client replies with ACK(y+1)• SYNs are retransmitted if lost

•Sequence and ack numbers carried on further segments

1

2

3

Active party(client)

Passive party(server)

SYN (SEQ=x)

SYN (SEQ=y, ACK=x+1)

(SEQ=x+1, ACK=y+1)Time

CSE 461 University of Washington 3

Three-Way Handshake

•Suppose delayed, duplicate copies of the SYN and ACK arrive at the server!• Improbable, but anyhow …

Active party(client)

Passive party(server)

SYN (SEQ=x)

(SEQ=x+1,ACK=z+1)

CSE 461 University of Washington 4

Three-Way Handshake

•Suppose delayed, duplicate copies of the SYN and ACK arrive at the server!• Improbable, but anyhow …

•Connection will be cleanly rejected on both sides J

Active party(client)

Passive party(server)

SYN (SEQ=x)

SYN (SEQ=y, ACK=x+1)

(SEQ=x+1,ACK=z+1)

XXREJECT

REJECT

Connection Release

•Orderly release by both parties when done• Delivers all pending data and “hangs up”• Cleans up state in sender and receiver

•Key problem is to provide reliability while releasing• TCP uses a “symmetric” close in which both sides

shutdown independently

CSE 461 University of Washington 5

CSE 461 University of Washington 6

TCP Connection Release

•Two steps:• Active sends FIN(x), passive ACKs• Passive sends FIN(y), active ACKs• FINs are retransmitted if lost

•Each FIN/ACK closes one direction of data transfer

Active party Passive party

CSE 461 University of Washington 7

TCP Connection Release (2)

•Two steps:• Active sends FIN(x), passive ACKs• Passive sends FIN(y), active ACKs• FINs are retransmitted if lost

•Each FIN/ACK closes one direction of data transfer

Active party Passive party

1

2

FIN (SEQ=x)

(SEQ=y, ACK=x+1)

(SEQ=x+1, ACK=y+1)

FIN (SEQ=y, ACK=x+1)

TCP Connection State Machine

CSE 461 University of Washington 8

Both parties run instances of this state

machine

TCP Release

•Follow the active party

CSE 461 University of Washington 9

TCP Release (2)

•Follow the passive party

CSE 461 University of Washington 10

TCP Release (3)

•Again, with states …

CSE 461 University of Washington 11

1

2

CLOSED

FIN (SEQ=x)

(SEQ=y, ACK=x+1)

(SEQ=x+1, ACK=y+1)

FIN (SEQ=y, ACK=x+1)

Active party Passive party

FIN_WAIT_1

CLOSE_WAIT

LAST_ACKFIN_WAIT_2

TIME_WAIT

CLOSED

ESTABLISHED

(timeout)

ESTABLISHED

TIME_WAIT State

•Wait a long time after sending all segments and before completing the close• Two times the maximum segment lifetime of 60 seconds

•Why?

CSE 461 University of Washington 12

TIME_WAIT State

•Wait a long time after sending all segments and before completing the close• Two times the maximum segment lifetime of 60 seconds

•Why?• ACK might have been lost, in which case FIN will be resent

for an orderly close• Could otherwise interfere with a subsequent connection

CSE 461 University of Washington 13

Flow Control

Flow control goal

Match transmission speed to reception capacity• Otherwise data will be lost

ARQ: Automatic repeat query

•ARQ with one message at a time is Stop-and-Wait

CSE 461 University of Washington 16

Frame 0

ACK 0Timeout Time

Sender Receiver

Frame 1

ACK 1

Limitation of Stop-and-Wait

• It allows only a single message to be outstanding from the sender:• Fine for LAN (only one frame fits in network anyhow)• Not efficient for network paths with longer delays

CSE 461 University of Washington 17

Limitation of Stop-and-Wait (2)

•Example: B=1 Mbps, D = 50 ms• RTT (Round Trip Time) = 2D = 100 ms• How many packets/sec? • 10

• Usage efficiency if packets are 10kb?• (10,000 x 10) / (1 x 106) = 10%

•What is the efficiency if B=10 Mbps?• 1%

CSE 461 University of Washington 18

Sliding Window

•Generalization of stop-and-wait• Allows W packets to be outstanding• Can send W packets per RTT (=2D)

• Pipelining improves performance • Need W=2BD to fill network path

CSE 461 University of Washington 19

Sliding Window (2)

What W will use the network capacity with 10kb packets?

• Ex: B=1 Mbps, D = 50 ms• 2BD = 2 x 106 x 50/1000 = 100 Kb• W = 100 kb/10 = 10 packets

• Ex: What if B=10 Mbps?• W = 100 packets

CSE 461 University of Washington 20

Sliding Window Protocol

•Many variations, depending on how buffers, acknowledgements, and retransmissions are handled

•Go-Back-N• Simplest version, can be inefficient

•Selective Repeat•More complex, better performance

CSE 461 University of Washington 21

Sender Sliding Window

•Sender buffers up to W segments until they are acknowledged• LFS=LAST FRAME SENT, LAR=LAST ACK REC’D• Sends while LFS – LAR ≤ W

CSE 461 University of Washington 22

.. 5 6 7 .. 2 3 4 5 2 3 ..

LAR LFS

W=5

Acked Unacked 3 ..Unavailable

Available

seq. number

SlidingWindow

Sender Sliding Window (2)

•Transport accepts another segment of data from the Application ...• Transport sends it (LFS–LAR à 5)

CSE 461 University of Washington 23

.. 5 6 7 .. 2 3 4 5 2 3 ..

LAR

W=5

Acked Unacked 3 ..Unavailable

Sent

seq. number

SlidingWindow

LFS

Sender Sliding Window (3)

•Next higher ACK arrives from peer…•Window advances, buffer is freed • LFS–LAR à 4 (can send one more)

CSE 461 University of Washington 24

.. 5 6 7 .. 2 3 4 5 2 3 ..

LAR

W=5

Acked Unacked 3 ..Unavailable

Available

seq. number

SlidingWindow

LFS

Receiver Sliding Window – Go-Back-N

•Receiver keeps only a single packet buffer for the next segment• State variable, LAS = LAST ACK SENT

•On receive:• If seq. number is LAS+1, accept and pass it to app, update

LAS, send ACK• Otherwise discard (as out of order)

CSE 461 University of Washington 25

Receiver Sliding Window – Selective Repeat

• Receiver passes data to app in order, and buffers out-of-order segments to reduce retransmissions

• ACK conveys highest in-order segment, plus hints about out-of-order segments• Ex: I got everything up to 42 (LAS), and got 44, 45

• TCP uses a selective repeat design; we’ll see the details later

CSE 461 University of Washington 26

Receiver Sliding Window – Selective Repeat (2)

•Buffers W segments, keeps state variable LAS = LASTACK SENT

•On receive:• Buffer segments [LAS+1, LAS+W] • Send app in-order segments from LAS+1, and update LAS• Send ACK for LAS regardless

CSE 461 University of Washington 27

5

Sender Sliding Window – Selective Repeat

•Keep normal sliding window• If out-of-order ACK arrives• Send LAR+1 again!

CSE 461 University of Washington 28

.. 5 6 7 .. 2 4 5 3 ..

LAR

W=5

Acked Unacked 3 ..Unavailable

Ack Arrives Out of Order!

seq. number

SlidingWindow

LFS

..

5

Sender Sliding Window – Selective Repeat (2)

•Keep normal sliding window• If in-order ACK arrives•Move window and LAR, send more messages

CSE 461 University of Washington 29

.. 5 6 7 .. 4 5 3 ..

LAR

W=5

Acked Unacked 3 ..

In-order ack arrives…

seq. number

SlidingWindow

LFS

....Now Available

Sliding Window – Retransmissions

•Go-Back-N uses a single timer to detect losses• On timeout, resends buffered packets starting at LAR+1

•Selective Repeat uses a timer per unacked segment to detect losses• On timeout for segment, resend it• Hope to resend fewer segments

CSE 461 University of Washington 30

Sequence Numbers

Need more than 0/1 for Stop-and-Wait … but how many?• For Selective Repeat: 2W seq numbers• W for packets, plus W for earlier acks

• For Go-Back-N: W+1 sequence numbers

Typically implement seq. number with an N-bit counter that wraps around at 2N—1 • E.g., N=8: …, 253, 254, 255, 0, 1, 2, 3, …

CSE 461 University of Washington 31

Sequence Time Plot

CSE 461 University of Washington 32

Time

Seq.

Num

ber

Acks(at Receiver)

Delay (=RTT/2)

Transmissions(at Sender)

Sequence Time Plot (2)

CSE 461 University of Washington 33

Time

Seq.

Num

ber

Go-Back-N scenario

Sequence Time Plot (3)

CSE 461 University of Washington 34

Time

Seq.

Num

ber Loss

Timeout

Retransmissions

top related