transport layer (tcp/udp) - courses.cs.washington.edu · port protocol use 20, 21ftp file transfer...

160
Transport Layer (TCP/UDP)

Upload: dangngoc

Post on 10-Apr-2019

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Transport Layer (TCP/UDP)

Page 2: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Recall the protocol stack

Computer Networks 2

Application – Programs that use network service

Transport – Provides end-to-end data delivery

Network – Send packets over multiple networks

Link – Send frames over one or more links

Physical – Send bits using signals

Page 3: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Transport layer

Provides end-to-end connectivity to applications

CSE 461 University of Washington 3

Host Host

TransportNetwork

Client

TransportNetwork

Server

Page 4: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Transport layer protocols

•Provide different kinds of data delivery across the network to applications

CSE 461 University of Washington 4

Unreliable ReliableMessages Datagrams (UDP)Bytestream Streams (TCP)

Page 5: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Comparison of Internet transports

•TCP is full-featured, UDP is a glorified packet

CSE 461 University of Washington 5

TCP (Streams) UDP (Datagrams)Connections Datagrams

Bytes are delivered once, reliably, and in order

Messages may be lost, reordered, duplicated

Arbitrary length content Limited message sizeFlow control matches

sender to receiverCan send regardless

of receiver stateCongestion control matches

sender to networkCan send regardless

of network state

Page 6: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Socket API

•Simple abstraction to use the network• The “network” API (really Transport service) used to write

all Internet apps• Part of all major OSes and languages; originally Berkeley

(Unix) ~1983•Supports both Internet transport services (Streams

and Datagrams)

CSE 461 University of Washington 6

Page 7: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Socket API (2)

• Sockets let apps attach to the local network at different ports

CSE 461 University of Washington 7

Socket,Port #1

Socket,Port #2

Page 8: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Socket API (3)•Same API used for Streams and Datagrams

CSE 461 University of Washington 8

Primitive MeaningSOCKET Create a new communication endpointBIND Associate a local address (port) with a socketLISTEN Announce willingness to accept connectionsACCEPT Passively establish an incoming connectionCONNECT Actively attempt to establish a connectionSEND(TO) Send some data over the socketRECEIVE(FROM) Receive some data over the socketCLOSE Release the socket

Only needed for Streams

To/From for Datagrams

Page 9: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Ports

•Application process is identified by the tuple IP address, transport protocol, and port• Ports are 16-bit integers representing local “mailboxes”

that a process leases•Servers often bind to “well-known ports”• <1024, require administrative privileges

•Clients often assigned “ephemeral” ports• Chosen by OS, used temporarily

CSE 461 University of Washington 9

Page 10: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Some Well-Known Ports

CSE 461 University of Washington 10

Port Protocol Use20, 21 FTP File transfer

22 SSH Remote login, replacement for Telnet25 SMTP Email80 HTTP World Wide Web

110 POP-3 Remote email access143 IMAP Remote email access443 HTTPS Secure Web (HTTP over SSL/TLS)543 RTSP Media player control631 IPP Printer sharing

Page 11: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Topics

• Service models• Socket API and ports• Datagrams, Streams

• User Datagram Protocol (UDP)• Connections (TCP)• Sliding Window (TCP)• Flow control (TCP)• Retransmission timers (TCP)• Congestion control (TCP)

CSE 461 University of Washington 11

Page 12: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

UDP

Page 13: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

User Datagram Protocol (UDP)

•Used by apps that don’t want reliability or bytestreams• Like what?

CSE 461 University of Washington 13

Page 14: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

User Datagram Protocol (UDP)

•Used by apps that don’t want reliability or bytestreams• Voice-over-IP • DNS• DHCP

(If application wants reliability and messages then it has work to do!)

CSE 461 University of Washington 14

Page 15: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Datagram Sockets

CSE 461 University of Washington 15

Client (host 1) Server (host 2)Time

request

reply

Page 16: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Datagram Sockets (2)

CSE 461 University of Washington 16

Client (host 1) Server (host 2)Time

1: socket 2: bind1: socket

6: sendto

3: recvfrom*4: sendto

5: recvfrom*

7: close 7: close

*= call blocks

request

reply

Page 17: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

UDP Buffering

CSE 461 University of Washington 17

App

Port Mux/Demux

App AppApplication

Transport(UDP)

Network (IP) packet

Message queues

Ports

Page 18: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

UDP Header

•Uses ports to identify sending and receiving application processes•Datagram length up to 64K•Checksum (16 bits) for reliability

CSE 461 University of Washington 18

Page 19: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

UDP Header (2)

•Optional checksum covers UDP segment and IP pseudoheader• Checks key IP fields (addresses)• Value of zero means “no checksum”

CSE 461 University of Washington 19

Page 20: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP

Page 21: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP

•TCP Consists of 3 primary phases:• Connection Establishment (Setup)• Sliding Windows/Flow Control• Connection Release (Teardown)

Page 22: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Connection Establishment

•Both sender and receiver must be ready before we start the transfer of data• Need to agree on a set of parameters• e.g., the Maximum Segment Size (MSS)

•This is signaling• It sets up state at the endpoints• Like “dialing” for a telephone call

CSE 461 University of Washington 22

Page 23: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 23

Three-Way Handshake• Used in TCP; opens connection for

data in both directions• Each side probes the other with a

fresh Initial Sequence Number (ISN)• Sends on a SYNchronize segment• Echo on an ACKnowledge segment

• Chosen to be robust even against delayed duplicates

Active party(client)

Passive party(server)

Page 24: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 24

Three-Way Handshake (2)

•Three steps:

• 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

Page 25: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 25

Three-Way Handshake (3)

•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)

Page 26: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 26

Three-Way Handshake (4)

•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

Page 27: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connection State Machine

•Captures the states ([]) and transitions (->)• A/B means event A triggers the transition, with action B

Both parties run instances of this state

machine

Page 28: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connections (2)

• Follow the path of the client:

Page 29: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connections (3)

• And the path of the server:

Page 30: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connections (4)

• Again, with states …

CSE 461 University of Washington 30

LISTEN

SYN_RCVD

SYN_SENT

ESTABLISHED

ESTABLISHED

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

CLOSEDCLOSED

Page 31: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connections (5)

•Finite state machines are a useful tool to specify and check the handling of all cases that may occur

•TCP allows for simultaneous open• i.e., both sides open instead of the client-server pattern• Try at home to confirm it works J

CSE 461 University of Washington 31

Page 32: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 32

Page 33: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 33

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

Page 34: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 34

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)

Page 35: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Connection State Machine

CSE 461 University of Washington 35

Both parties run instances of this state

machine

Page 36: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Release

•Follow the active party

CSE 461 University of Washington 36

Page 37: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Release (2)

•Follow the passive party

CSE 461 University of Washington 37

Page 38: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Release (3)

•Again, with states …

CSE 461 University of Washington 38

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

Page 39: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 39

Page 40: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 40

Page 41: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Flow Control

Page 42: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Flow control goal

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

Page 43: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

ARQ: Automatic repeat query

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

CSE 461 University of Washington 43

Frame 0

ACK 0Timeout Time

Sender Receiver

Frame 1

ACK 1

Page 44: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 44

Page 45: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Limitation of Stop-and-Wait (2)

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

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

•What is the efficient B=10 Mbps?• 1%

CSE 461 University of Washington 45

Page 46: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 46

Page 47: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 47

Page 48: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 48

Page 49: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 49

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

LAR LFS

W=5

Acked Unacked 3 ..Unavailable

Available

seq. number

Sliding

Window

Page 50: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Sender Sliding Window (2)

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

CSE 461 University of Washington 50

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

LAR

W=5

Acked Unacked 3 ..Unavailable

Sent

seq. number

SlidingWindow

LFS

Page 51: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 51

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

LAR

W=5

Acked Unacked 3 ..Unavailable

Available

seq. number

SlidingWindow

LFS

Page 52: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 52

Page 53: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 53

Page 54: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 54

Page 55: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

5

Sender Sliding Window – Selective Repeat

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

CSE 461 University of Washington 55

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

LAR again

W=5

Acked Unacked 3 ..Unavailable

Ack Arrives Out of Order!

seq. number

SlidingWindow

LFS

..

Page 56: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 56

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

LAR

W=5

Acked Unacked 3 ..

In-order ack arrives…

seq. number

SlidingWindow

LFS

....

Now Available

Page 57: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 57

Page 58: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

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 58

Page 59: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Sequence Time Plot

CSE 461 University of Washington 59

Time

Seq.

Num

ber

Acks(at Receiver)

Delay (=RTT/2)

Transmissions(at Sender)

Page 60: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Sequence Time Plot (2)

CSE 461 University of Washington 60

Time

Seq.

Num

ber

Go-Back-N scenario

Page 61: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Sequence Time Plot (3)

CSE 461 University of Washington 61

Time

Seq.

Num

ber Loss

Timeout

Retransmissions

Page 62: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

ACK Clocking

Page 63: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Sliding Window ACK Clock

•Typically, the sender does not know B or D•Each in-order ACK advances the sliding window and

lets a new segment enter the network• ACKs “clock” data segments

CSE 461 University of Washington 63

Ack 1 2 3 4 5 6 7 8 9 10

20 19 18 17 16 15 14 13 12 11 Data

Page 64: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Benefit of ACK Clocking

•Consider what happens when sender injects a burst of segments into the network

CSE 461 University of Washington 64

Fast link Fast linkSlow (bottleneck) link

Queue

Page 65: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Benefit of ACK Clocking (2)

•Segments are buffered and spread out on slow link

CSE 461 University of Washington 65

Fast link Fast linkSlow (bottleneck) link

Segments “spread out”

Page 66: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Benefit of ACK Clocking (3)

•ACKs maintain the spread back to the original sender

CSE 461 University of Washington 66

Slow linkAcks maintain spread

Page 67: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Benefit of ACK Clocking (4)

•Sender clocks new segments with the spread• Now sending at the bottleneck link without queuing!

CSE 461 University of Washington 67

Slow link

Segments spread Queue no longer builds

Page 68: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Benefit of ACK Clocking (4)

•Helps run with low levels of loss and delay!•The network smooths out the burst of data segments•ACK clock transfers this smooth timing back to sender•Subsequent data segments are not sent in bursts so do

not queue up in the network

CSE 461 University of Washington 68

Page 69: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Uses ACK Clocking

•TCP uses a sliding window because of the value of ACK clocking•Sliding window controls how many segments are

inside the network•TCP only sends small bursts of segments to let the

network keep the traffic smooth

CSE 461 University of Washington 69

Page 70: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Problem

•Sliding window has pipelining to keep network busy•What if the receiver is overloaded?

CSE 461 University of Washington 70

Streaming videoBig Iron Wee Mobile

Arg …

Page 71: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Receiver Sliding Window

•Consider receiver with W buffers• LAS=LAST ACK SENT• app pulls in-order data from buffer with recv() call

CSE 461 University of Washington 71

SlidingWindow

.. 5 6 7 5 2 3 ..

LAS

W=5

Finished 3 ..Too high

seq. number

555 5Acceptable

Page 72: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Receiver Sliding Window (2)

•Suppose the next two segments arrive but app does not call recv()

CSE 461 University of Washington 72

.. 5 6 7 5 2 3 ..

LAS

W=5

Finished 3 ..Too high

seq. number

555 5Acceptable

Page 73: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Receiver Sliding Window (3)

•Suppose the next two segments arrive but app does not call recv()• LAS rises, but we can’t slide window!

CSE 461 University of Washington 73

.. 5 6 7 5 2 3 ..

LAS

W=5

Finished 3 ..Too high

seq. number

555 5Acked

Page 74: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Receiver Sliding Window (4)

•Further segments arrive (in order) we fill buffer •Must drop segments until app recvs!

CSE 461 University of Washington 74

NothingAcceptable!

.. 5 6 7 5 2 3 ..

W=5

Finished 3 ..Too high

seq. number

555 5Acked

LAS

Page 75: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Receiver Sliding Window (5)

•App recv() takes two segments•Window slides (phew)

CSE 461 University of Washington 75

Acceptable

.. 5 6 7 5 2 3 ..

W=5

Finished 3 ..

seq. number

555 5Acked

LAS

Page 76: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Flow Control

•Avoid loss at receiver by telling sender the available

buffer space

•WIN=#Acceptable, not W (from LAS)

CSE 461 University of Washington 76

Acceptable

.. 5 6 7 5 2 3 ..

W=5

Finished 3 ..

seq. number

555 5Acked

LAS

Page 77: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Flow Control (2)

•Sender uses lower of the sliding window and flow control window (WIN) as the effective window size

CSE 461 University of Washington 77

Acceptable

.. 5 6 7 5 2 3 ..

LAS

W=3

Finished 3 ..Too high

seq. number

555 5Acked

Page 78: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

CSE 461 University of Washington 78

Flow Control (3)

•TCP-style example• SEQ/ACK sliding window• Flow control with WIN• SEQ + length < ACK+WIN• 4KB buffer at receiver• Circular buffer of bytes

Page 79: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Topic

•How to set the timeout for sending a retransmission• Adapting to the network path

CSE 461 University of Washington 79

Lost?

Network

Page 80: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Retransmissions

•With sliding window, detecting loss with timeout• Set timer when a segment is sent• Cancel timer when ack is received• If timer fires, retransmit data as lost

CSE 461 University of Washington 80

Retransmit!

Page 81: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Timeout Problem

•Timeout should be “just right”• Too long à inefficient network capacity use• Too short à spurious resends waste network capacity

•But what is “just right”?• Easy to set on a LAN (Link)• Short, fixed, predictable RTT

• Hard on the Internet (Transport)• Wide range, variable RTT

CSE 461 University of Washington 81

Page 82: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Example of RTTs

CSE 461 University of Washington 82

0

100

200

300

400

500

600

700

800

900

1000

0 20 40 60 80 100 120 140 160 180 200

Roun

d Tr

ip T

ime

(ms)

BCNàSEAàBCN

Seconds

Page 83: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Example of RTTs (2)

CSE 461 University of Washington 83

0

100

200

300

400

500

600

700

800

900

1000

0 20 40 60 80 100 120 140 160 180 200

Ro

un

d T

rip

Tim

e (

ms) Variation due to queuing at routers,

changes in network paths, etc.

BCNàSEAàBCN

Propagation (+transmission) delay ≈ 2D

Seconds

Page 84: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Example of RTTs (3)

CSE 461 University of Washington 84

0

100

200

300

400

500

600

700

800

900

1000

0 20 40 60 80 100 120 140 160 180 200

Roun

d Tr

ip T

ime

(ms)

Timer too high!

Timer too low!

Need to adapt to the network conditions

Seconds

Page 85: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Adaptive Timeout

• Smoothed estimates of the RTT (1) and variance in RTT (2)• Update estimates with a moving average1. SRTTN+1 = 0.9*SRTTN + 0.1*RTTN+12. SvarN+1 = 0.9*SvarN + 0.1*|RTTN+1– SRTTN+1|

• Set timeout to a multiple of estimates• To estimate the upper RTT in practice• TCP TimeoutN = SRTTN + 4*SvarN

CSE 461 University of Washington 85

Page 86: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Example of Adaptive Timeout

CSE 461 University of Washington 86

0

100

200

300

400

500

600

700

800

900

1000

0 20 40 60 80 100 120 140 160 180 200

RTT

(ms)

SRTT

Svar

Seconds

Page 87: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Example of Adaptive Timeout (2)

CSE 461 University of Washington 87

0

100

200

300

400

500

600

700

800

900

1000

0 20 40 60 80 100 120 140 160 180 200

RTT

(ms)

Timeout (SRTT + 4*Svar)Early

timeout

Seconds

Page 88: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Adaptive Timeout (2)

•Simple to compute, does a good job of tracking actual RTT• Little “headroom” to lower• Yet very few early timeouts

•Turns out to be important for good performance and robustness

CSE 461 University of Washington 88

Page 89: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Congestion

Page 90: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP to date:

•We can set up and tear connections • Connection establishment and release handshakes

•Keep the sending and receiving buffers from overflowing (flow control)

What’s missing?

Page 91: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Network Congestion

•A “traffic jam” in the network• Later we will learn how to control it

CSE 461 University of Washington 91

What’s the hold up?

Network

Page 92: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Congestion Collapse in the 1980s

•Early TCP used fixed size window (e.g., 8 packets)• Initially fine for reliability

•But something happened as the network grew• Links stayed busy but transfer rates fell by orders of

magnitude!

CSE 461 University of Washington 92

Page 93: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Nature of Congestion

•Routers/switches have internal buffering

CSE 461 University of Washington 93

. . .

. . .. . . . . .

Input Buffer Output BufferFabric

Input Output

Page 94: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Nature of Congestion (2)

•Simplified view of per port output queues• Typically FIFO (First In First Out), discard when full

CSE 461 University of Washington 94

Router

=

(FIFO) QueueQueuedPackets

Router

Page 95: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Nature of Congestion (3)

•Queues help by absorbing bursts when input > output rate•But if input > output rate persistently, queue will

overflow• This is congestion

•Congestion is a function of the traffic patterns – can occur even if every link has the same capacity

CSE 461 University of Washington 95

Page 96: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Effects of Congestion

•What happens to performance as we increase load?

Page 97: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Effects of Congestion (2)

•What happens to performance as we increase load?

Page 98: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Effects of Congestion (3)

•As offered load rises, congestion occurs as queues begin to fill:• Delay and loss rise sharply with load• Throughput < load (due to loss)• Goodput << throughput (due to spurious retransmissions)

•None of the above is good!•Want network performance just before congestion

CSE 461 University of Washington 98

Page 99: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Tahoe/Reno

•TCP extensions and features we will study:• AIMD• Fair Queuing• Slow-start• Fast Retransmission• Fast Recovery

CSE 461 University of Washington 100

Page 100: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Timeline

CSE 461 University of Washington 101

1988

19901970 19801975 1985

Origins of “TCP”(Cerf & Kahn, ’74)

3-way handshake(Tomlinson, ‘75)

TCP Reno(Jacobson, ‘90)

Congestion collapse Observed, ‘86

TCP/IP “flag day”(BSD Unix 4.2, ‘83)

TCP Tahoe(Jacobson, ’88)

Pre-history Congestion control

. . .

TCP and IP(RFC 791/793, ‘81)

Page 101: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Timeline (2)

CSE 461 University of Washington 102

201020001995 2005

ECN(Floyd, ‘94)

TCP Reno(Jacobson, ‘90) TCP New Reno

(Hoe, ‘95) TCP BIC(Linux, ‘04

TCP with SACK(Floyd, ‘96)

DiversificationClassic congestion control. . .

1990

TCP LEDBAT(IETF ’08)

TCP Vegas(Brakmo, ‘93)

TCP CUBIC(Linux, ’06)

. . .

BackgroundRouter support

Delaybased

FAST TCP(Low et al., ’04)

Compound TCP(Windows, ’07)

Page 102: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Bandwidth Allocation

• Important task for network is to allocate its capacity to senders• Good allocation is both efficient and fair

•Efficient: most capacity is used but there is no congestion•Fair: every sender gets a reasonable share of the

network

CSE 461 University of Washington 103

Page 103: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Efficiency vs. Fairness

•Cannot always have both!• Example network with traffic:• AàB, BàC and AàC

• How much traffic can we carry?

CSE 461 University of Washington 104

A B C1 1

Page 104: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Efficiency vs. Fairness (2)

• If we care about fairness:• Give equal bandwidth to each flow• AàB: ½ unit, BàC: ½, and AàC, ½ • Total traffic carried is 1 ½ units

CSE 461 University of Washington 105

A B C1 1

Page 105: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Efficiency vs. Fairness (3)

• If we care about efficiency:•Maximize total traffic in network• AàB: 1 unit, BàC: 1, and AàC, 0 • Total traffic rises to 2 units!

CSE 461 University of Washington 106

A B C1 1

Page 106: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fairness

• What’s a “fair” bandwidth allocation?• The max-min fair allocation

CSE 461 University of Washington 107

Page 107: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

The Slippery Notion of Fairness

•Why is “equal per flow” fair anyway?• AàC uses more network resources than AàB or BàC• Host A sends two flows, B sends one

•Not productive to seek exact fairness•More important to avoid starvation• A node that cannot use any bandwidth

• “Equal per flow” is good enough

CSE 461 University of Washington 108

Page 108: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Generalizing “Equal per Flow”

•Bottleneck for a flow of traffic is the link that limits its bandwidth•Where congestion occurs for the flow• For AàC, link A–B is the bottleneck

CSE 461 University of Washington 109

A B C1 10

Bottleneck

Page 109: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Generalizing “Equal per Flow” (2)

•Flows may have different bottlenecks• For AàC, link A–B is the bottleneck• For BàC, link B–C is the bottleneck• Can no longer divide links equally …

CSE 461 University of Washington 110

A B C1 10

Page 110: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Fairness

• Intuitively, flows bottlenecked on a link get an equal share of that link•Max-min fair allocation is one that:• Increasing the rate of one flow will decrease the rate of a

smaller flow• This “maximizes the minimum” flow

CSE 461 University of Washington 111

Page 111: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Fairness (2)

•To find it given a network, imagine “pouring water into the network”

1. Start with all flows at rate 02. Increase the flows until there is a new bottleneck in

the network3. Hold fixed the rate of the flows that are bottlenecked4. Go to step 2 for any remaining flows

CSE 461 University of Washington 112

Page 112: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Example

•Example: network with 4 flows, link bandwidth = 1•What is the max-min fair allocation?

CSE 461 University of Washington 113

Page 113: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Example (2)

•When rate=1/3, flows B, C, and D bottleneck R4—R5 • Fix B, C, and D, continue to increase A

CSE 461 University of Washington 114

BottleneckBottleneck

Page 114: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Example (3)

•When rate=2/3, flow A bottlenecks R2—R3. Done.

CSE 461 University of Washington 115

Bottleneck

Bottleneck

Page 115: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Max-Min Example (4)

•End with A=2/3, B, C, D=1/3, and R2—R3, R4—R5 full • Other links have extra capacity that can’t be used

• , linksxample: network with 4 flows, links equal bandwidth•What is the max-min fair allocation?

CSE 461 University of Washington 116

Page 116: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Adapting over Time

•Allocation changes as flows start and stop

CSE 461 University of Washington 117

Time

Page 117: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Adapting over Time (2)

CSE 461 University of Washington 118

Flow 1 slows when Flow 2 starts

Flow 1 speeds up when Flow 2 stops

Time

Flow 3 limit is elsewhere

Page 118: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Recall the goals of bandwidth allocation

•Want to allocate capacity to senders• Network layer provides feedback• Transport layer adjusts offered load• A good allocation is efficient and fair

CSE 461 University of Washington 119

Page 119: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Why is Bandwidth Allocation hard?

•Number of senders and their offered load changes• Senders may be limited in other ways• Other parts of network or by applications

•Network is distributed; no single party has an overall picture of its state

CSE 461 University of Washington 120

Page 120: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Bandwidth Allocation Models

•Open loop versus closed loop• Open: reserve bandwidth before use• Closed: use feedback to adjust rates

•Host versus Network support•Who is sets/enforces allocations?

•Window versus Rate based• How is allocation expressed?

CSE 461 University of Washington 123TCP is a closed loop, host-driven, and window-based

Page 121: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Bandwidth Allocation Models (2)

•We’ll study closed-loop, host-driven, and window-based too•Network layer returns feedback on current

allocation to senders • At least tells if there is congestion

•Transport layer adjusts sender’s behavior via window in response• How senders adapt is a control law

CSE 461 University of Washington 124

Page 122: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Additive Increase Multiplicative Decrease

•AIMD is a control law hosts can use to reach a good allocation• Hosts additively increase rate while network not congested• Hosts multiplicatively decrease rate when congested• Used by TCP

• Let’s explore the AIMD game …

CSE 461 University of Washington 125

Page 123: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Game

•Hosts 1 and 2 share a bottleneck• But do not talk to each other directly

•Router provides binary feedback• Tells hosts if network is congested

CSE 461 University of Washington 126

Rest ofNetwork

Bottleneck

Router

Host 1

Host 2

1

11

Page 124: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Game (2)

•Each point is a possible allocation

CSE 461 University of Washington 127

Host 1

Host 20 1

1

Fair

Efficient

OptimalAllocation

Congested

Page 125: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Game (3)

•AI and MD move the allocation

CSE 461 University of Washington 128

Host 1

Host 20 1

1

Fair, y=x

Efficient, x+y=1

OptimalAllocation

Congested

MultiplicativeDecrease

AdditiveIncrease

Page 126: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Game (4)

•Play the game!

CSE 461 University of Washington 129

Host 1

Host 20 1

1

Fair

Efficient

Congested

A starting point

Page 127: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Game (5)

•Always converge to good allocation!

CSE 461 University of Washington 130

Host 1

Host 20 1

1

Fair

Efficient

Congested

A starting point

Page 128: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Sawtooth

•Produces a “sawtooth” pattern over time for rate of each host• This is the TCP sawtooth (later)

CSE 461 University of Washington 131

MultiplicativeDecrease

AdditiveIncrease

Time

Host 1 or 2’s Rate

Page 129: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

AIMD Properties

•Converges to an allocation that is efficient and fair when hosts run it• Holds for more general topologies

•Other increase/decrease control laws do not! (Try MIAD, MIMD, MIAD)•Requires only binary feedback from the network

CSE 461 University of Washington 132

Page 130: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Feedback Signals

• Several possible signals, with different pros/cons• We’ll look at classic TCP that uses packet loss as a signal

CSE 461 University of Washington 133

Signal Example Protocol Pros / ConsPacket loss TCP NewReno

Cubic TCP (Linux)Hard to get wrong

Hear about congestion lateOther events can cause loss

Packet delay Compound TCP (Windows)

Hear about congestion earlyNeed to infer congestion

Router indication

TCPs with Explicit Congestion Notification

Hear about congestion earlyRequire router support

Page 131: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Slow Start (TCP Additive Increase)

Page 132: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

What we know about TCP so far

• Connection establishment• 3-way handshake

• Connection release• FIN/ACK for each direction

• Flow control• Sliding windows

• Congestion control basics• Max-min fairness, AIMD

This lecture: TCP congestion control in practice

Page 133: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP congestion control overview

•Follows AIMD control law for a good allocation•Sender uses a congestion window or cwnd to set its

rate (≈cwnd/RTT)•Sender uses loss as network congestion signal•Designed to work across a very large range of rates

and RTTs

CSE 461 University of Washington 136

Page 134: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP “Slow Start” Problem

•We want to quickly near the right rate, cwndIDEAL, but it varies greatly• Fixed sliding window doesn’t adapt and is rough on the

network (loss!) • Additive Increase with small bursts adapts cwnd gently,

but might take a long time to become efficient

CSE 461 University of Washington 137

Page 135: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Slow-Start Solution

•Start by doubling cwnd every RTT• Exponential growth (1, 2, 4, 8, 16, …)• Start slow, quickly reach large values

138

AI

Fixed

TimeWin

dow

(cw

nd)

Slow-start

Page 136: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Slow-Start Solution (2)

•Eventually packet loss will occur when the network is congested• Loss timeout tells us cwnd is too large• Next time, switch to AI beforehand• Slowly adapt cwnd near right value

• In terms of cwnd:• Expect loss for cwndC ≈ 2BD+queue• Use ssthresh = cwndC/2 to switch to AI

CSE 461 University of Washington 139

Page 137: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Slow-Start Solution (3)

•Combined behavior, after first time•Most time spent near right value

140

AI

Fixed

Time

Window

ssthresh

cwndC

cwndIDEALAI phase

Slow-start

Page 138: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Slow-Start (Doubling) Timeline

CSE 461 University of Washington 141

Increment cwndby 1 packet for each ACK

Page 139: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Additive Increase Timeline

CSE 461 University of Washington 142

Increment cwnd by 1 packet every cwndACKs (or 1 RTT)

Page 140: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Tahoe (Implementation)

• Initial slow-start (doubling) phase• Start with cwnd = 1 (or small value)• cwnd += 1 packet per ACK

• Later Additive Increase phase• cwnd += 1/cwnd packets per ACK• Roughly adds 1 packet per RTT

• Switching threshold (initially infinity)• Switch to AI when cwnd > ssthresh• Set ssthresh = cwnd/2 after loss• Begin with slow-start after timeout

CSE 461 University of Washington 143

Page 141: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Timeout Misfortunes

•Why do a slow-start after timeout?• Instead of MD cwnd (for AIMD)

•Timeouts are sufficiently long that the ACK clock will have run down• Slow-start ramps up the ACK clock

•We need to detect loss before a timeout to get to full AIMD

CSE 461 University of Washington 144

Page 142: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Recovery (TCP Multiplicative Decrease)

Page 143: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Inferring Loss from ACKs

•TCP uses a cumulative ACK• Carries highest in-order seq. number• Normally a steady advance

•Duplicate ACKs give us hints about what data hasn’t arrived• Tell us some new data did arrive, but it was not next

segment• Thus the next segment may be lost

CSE 461 University of Washington 146

Page 144: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Retransmit

•Treat three duplicate ACKs as a loss • Retransmit next expected segment• Some repetition allows for reordering, but still detects loss

quickly

CSE 461 University of Washington 147

Ack 1 2 3 4 5 5 5 5 5 5

Page 145: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Retransmit (2)

CSE 461 University of Washington 148

Ack 10Ack 11Ack 12Ack 13

. . .

Ack 13

Ack 13Ack 13

Data 14. . . Ack 13

Ack 20. . . . . .

Data 20Third duplicate ACK, so send 14 Retransmission fills

in the hole at 14ACK jumps after loss is repaired

. . . . . .

Data 14 was lost earlier, but got

15 to 20

Page 146: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Retransmit (3)

• It can repair single segment loss quickly, typically before a timeout•However, we have quiet time at the sender/receiver

while waiting for the ACK to jump•And we still need to MD cwnd …

CSE 461 University of Washington 149

Page 147: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Inferring Non-Loss from ACKs

•Duplicate ACKs also give us hints about what data has arrived• Each new duplicate ACK means that some new segment

has arrived• It will be the segments after the loss• Thus advancing the sliding window will not increase the

number of segments stored in the network

CSE 461 University of Washington 150

Page 148: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Recovery

•First fast retransmit, and MD cwnd

•Then pretend further duplicate ACKs are the expected ACKs• Lets new segments be sent for ACKs • Reconcile views when the ACK jumps

CSE 461 University of Washington 151

Ack 1 2 3 4 5 5 5 5 5 5

Page 149: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Recovery (2)

CSE 461 University of Washington 152

Ack 12Ack 13Ack 13

Ack 13Ack 13

Data 14Ack 13

Ack 20. . . . . .

Data 20Third duplicate ACK, so send 14

Data 14 was lost earlier, but got

15 to 20

Retransmission fills in the hole at 14

Set ssthresh, cwnd = cwnd/2

Data 21Data 22

More ACKs advance window; may send

segments before jump

Ack 13

Exit Fast Recovery

Page 150: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Fast Recovery (3)

•With fast retransmit, it repairs a single segment loss quickly and keeps the ACK clock running•This allows us to realize AIMD• No timeouts or slow-start after loss, just continue with a

smaller cwnd•TCP Reno combines slow-start, fast retransmit and

fast recovery•Multiplicative Decrease is ½

CSE 461 University of Washington 153

Page 151: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Reno

CSE 461 University of Washington 154

MD of ½ , no slow-start

ACK clock running

TCP sawtooth

Page 152: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

TCP Reno, NewReno, and SACK

•Reno can repair one loss per RTT•Multiple losses cause a timeout

•NewReno further refines ACK heuristics• Repairs multiple losses without timeout

•Selective ACK (SACK) is a better idea• Receiver sends ACK ranges so sender can retransmit

without guesswork

CSE 461 University of Washington 155

Page 153: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Network-Assisted Congestion Control

Page 154: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Congestion Avoidance vs. Control

•Classic TCP drives the network into congestion and then recovers• Needs to see loss to slow down

•Would be better to use the network but avoid congestion altogether!• Reduces loss and delay

•But how can we do this?

CSE 461 University of Washington 157

Page 155: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Feedback Signals

• Delay and router signals can let us avoid congestion

CSE 461 University of Washington 158

Signal Example Protocol Pros / ConsPacket loss Classic TCP

Cubic TCP (Linux)Hard to get wrong

Hear about congestion lateOther events can cause loss

Packet delay Compound TCP (Windows)

Hear about congestion earlyNeed to infer congestion

Router indication

TCPs with Explicit Congestion Notification

Hear about congestion earlyRequire router support

Page 156: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

ECN (Explicit Congestion Notification)

•Router detects the onset of congestion via its queue•When congested, it marks affected packets (IP header)

CSE 461 University of Washington 159

Page 157: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

ECN (2)

•Marked packets arrive at receiver• TCP receiver informs TCP sender of the congestion

CSE 461 University of Washington 160

Page 158: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

ECN (3)

•Advantages:• Routers deliver clear signal to hosts• Congestion is detected early, no loss• No extra packets need to be sent

•Disadvantages:• Routers and hosts must be upgraded

CSE 461 University of Washington 161

Page 159: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Recent transport layer developments (1)

QUIC

https://blog.chromium.org/2015/04/a-quic-update-on-googles-experimental.html

Page 160: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Port Protocol Use 20, 21FTP File transfer 22SSH Remote login, replacement for Telnet 25SMTP Email ... •Service models •Socket

Recent transport layer developments (2)

Multipath TCP (MPTCP)

By Aclarembeau - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=49727919