Download as pdf or txt
Download as pdf or txt
You are on page 1of 149

Chapter 3

Transport Layer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Computer Networking: A
Top-Down Approach
8th edition
Jim Kurose, Keith Ross
Pearson, 2020
Transport Layer: 3-1
Transport layer: overview
Our goal:
▪ understand principles ▪ learn about Internet transport
behind transport layer layer protocols:
services: • UDP: connectionless transport
• multiplexing, • TCP: connection-oriented reliable
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

demultiplexing transport
• reliable data transfer • TCP congestion control
• flow control
• congestion control

Transport Layer: 3-2


Transport layer: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer functionality

Transport Layer: 3-3


Transport services and protocols
application
transport

▪ provide logical communication mobile network


network
data link
physical
between application processes national or global ISP

running on different hosts


▪ transport protocols actions in end
systems:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

local or
• sender: breaks application messages regional ISP

into segments, passes to network layer home network content


• receiver: reassembles segments into provider
network datacenter
messages, passes to application layer application
transport
network
network

▪ two transport protocols available to data link


physical

Internet applications enterprise


network
• TCP, UDP
Transport Layer: 3-4
Transport vs. network layer services and protocols
household analogy:
12 kids in Ann’s house sending
letters to 12 kids in Bill’s
house:
▪ hosts = houses
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ processes = kids
▪ app messages = letters in
envelopes
▪ transport protocol = Ann and Bill
who demux to in-house siblings
▪ network-layer protocol = postal
service

Transport Layer: 3-5


Transport vs. network layer services and protocols
household analogy:
▪network layer: logical
communication between 12 kids in Ann’s house sending
letters to 12 kids in Bill’s
hosts house:
▪transport layer: logical ▪ hosts = houses
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

communication between ▪ processes = kids


▪ app messages = letters in
processes envelopes
• relies on, enhances, network ▪ transport protocol = Ann and Bill
layer services who demux to in-house siblings
▪ network-layer protocol = postal
service

Transport Layer: 3-6


Transport Layer Actions

Sender:
application ▪ is passed an application- application
app. msg
layer message
transport ▪ determines segment TThhtransport
app. msg
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

header fields values


network (IP) ▪ creates segment network (IP)

link ▪ passes segment to IP link

physical physical

Transport Layer: 3-7


Transport Layer Actions

Receiver:
application ▪ receives segment from IP application
▪ checks header values
transport
app. msg ▪ extracts application-layer transport
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

message
network (IP) network (IP)
▪ demultiplexes message up
link to application via socket link

physical physical
Th app. msg

Transport Layer: 3-8


Two principal Internet transport protocols
application
transport

▪ TCP: Transmission Control Protocol mobile network


network
data link
physical
• reliable, in-order delivery national or global ISP

• congestion control
• flow control
• connection setup
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

local or
▪ UDP: User Datagram Protocol regional ISP

• unreliable, unordered delivery home network content


• no-frills extension of “best-effort” IP provider
network datacenter
application
network
▪ services not available: transport
network
data link

• delay guarantees physical

• bandwidth guarantees enterprise


network

Transport Layer: 3-9


Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-10
HTTP server
client
application application
HTTP msg
transport
network
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport transport
network link network
link physical link
physical physical

Transport Layer: 3-11


HTTP server
client
application application
HTTP msg
transport
Ht HTTP msg

network
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport transport
network link network
link physical link
physical physical

Transport Layer: 3-12


HTTP server
client
application application
HTTP msg
transport
Ht HTTP msg

Hnnetwork
Ht HTTP msg
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport transport
network link network
link physical link
physical physical

Transport Layer: 3-13


HTTP server
client
application application

transport
network
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport transport
network link network
link physical link
physical physical

Hn Ht HTTP msg

Transport Layer: 3-14


HTTP server
client1 client2
application P-client1 P-client2 application

transport
network
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport transport
network link network
link physical link
physical physical

Transport Layer: 3-15


Multiplexing/demultiplexing
multiplexing at sender: demultiplexing at receiver:
handle data from multiple use header info to deliver
sockets, add transport header received segments to correct
(later used for demultiplexing) socket
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

application

application P1 P2 application socket


P3 transport P4
process
transport network transport
network link network
link physical link
physical physical

Transport Layer: 3-16


How demultiplexing works
▪ host receives IP datagrams 32 bits
• each datagram has source IP source port # dest port #
address, destination IP address
• each datagram carries one other header fields
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport-layer segment
• each segment has source, application
destination port number data
▪ host uses IP addresses & port (payload)
numbers to direct segment to
appropriate socket TCP/UDP segment format

Transport Layer: 3-17


Connectionless demultiplexing
Recall: when receiving, host receives
▪ when creating socket, host UDP segment:
must specify host-local port #: • checks destination port # in
segment
DatagramSocket mySocket1
= new DatagramSocket(12534); • directs UDP segment to
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

socket with that port #


▪ when creating datagram to
send into UDP socket, host
must specify IP/UDP datagrams with same dest.
port #, but different source IP
• destination IP address addresses and/or source port
• destination port # numbers will be directed to same
socket at receiving host
Transport Layer: 3-18
Connectionless demultiplexing: an example
DatagramSocket
serverSocket = new
DatagramSocket
DatagramSocket mySocket2 = DatagramSocket mySocket1 =
new DatagramSocket (6428); new DatagramSocket (5775);
same
(9157); application
socket
application application
P1
P3 P4
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transport
transport transport
network
network link network
link physical link
physical physical

source port: 6428 source port: ?


dest port: 9157 dest port: ?

source port: 9157 source port: ?


dest port: 6428 dest port: ?
Transport Layer: 3-19
Connection-oriented demultiplexing
▪ TCP socket identified by ▪ server may support many
4-tuple: simultaneous TCP sockets:
• source IP address • each socket identified by its
• source port number own 4-tuple
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• dest. IP address • each socket associated with


• dest. port number a different connecting client
▪ demux: receiver uses all
four values (4-tuple) to
direct segment to
appropriate socket
Transport Layer: 3-20
Connection-oriented demultiplexing: example
different
socket
application
application P4 P5 P6 application
P1 P2 P3
transport
transport transport
network
network link network
link physical link
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

physical server: IP physical


address B

host: IP source IP,port: B,80 host: IP


address A dest IP,port: A,9157 source IP,port: C,5775 address C
dest IP,port: B,80
source IP,port: A,9157
dest IP, port: B,80
source IP,port: C,9157
dest IP,port: B,80
Three segments, all destined to IP address: B,
dest. port: 80 are demultiplexed to different sockets
Transport Layer: 3-21
Summary
▪ Multiplexing, demultiplexing: based on segment, datagram
header field values
▪ UDP: demultiplexing using destination port number (only)
▪ TCP: demultiplexing using 4-tuple: source and destination IP
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

addresses, and port numbers


▪ Multiplexing/demultiplexing happen at all layers

Transport Layer: 3-22


Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-23
UDP: User Datagram Protocol
Why is there a UDP?
▪ “no frills,” “bare bones”
Internet transport protocol ▪ no connection
establishment (which can
▪ “best effort” service, UDP add RTT delay)
segments may be: ▪ simple: no connection state
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• lost at sender, receiver


• delivered out-of-order to app ▪ overhead: small header size
▪ connectionless: ▪ no congestion control
• no handshaking between UDP ▪ UDP can blast away as fast as
desired!
sender, receiver
▪ can function in the face of
• each UDP segment handled congestion
independently of others
Transport Layer: 3-24
UDP: User Datagram Protocol
▪ UDP used for:
▪ streaming multimedia apps (loss tolerant, rate sensitive)
▪ DNS
▪ SNMP
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ HTTP/3
▪ if reliable transfer needed over UDP (e.g., HTTP/3):
▪ add needed reliability at application layer
▪ add congestion control at application layer

Transport Layer: 3-25


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

UDP: User Datagram Protocol [RFC 768]

Transport Layer: 3-26


UDP: Transport Layer Actions

SNMP client SNMP server

application application

transport transport
(UDP)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

(UDP)
network (IP) network (IP)

link link

physical physical

Transport Layer: 3-27


UDP: Transport Layer Actions

SNMP client SNMP server


UDP sender actions:
application ▪ is passed an application- application
SNMP msg
layer message
transport transport
▪ determines UDP segment UDP
UDPhh SNMP msg
(UDP)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

(UDP) header fields values


network (IP) ▪ creates UDP segment network (IP)

link ▪ passes segment to IP link

physical physical

Transport Layer: 3-28


UDP: Transport Layer Actions

SNMP client SNMP server


UDP receiver actions:
application ▪ receives segment from IP application
▪ checks UDP checksum
transport transport
SNMP msg header value
(UDP)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

(UDP) ▪ extracts application-layer


network
UDP h SNMP(IP)
msg message network (IP)
▪ demultiplexes message up
link link
to application via socket
physical physical

Transport Layer: 3-29


UDP segment header
32 bits
source port # dest port #
length checksum
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

application length, in bytes of


data UDP segment,
(payload) including header

data to/from
UDP segment format application layer

Transport Layer: 3-30


UDP checksum
Goal: detect errors (i.e., flipped bits) in transmitted segment
1st number 2nd number sum

Transmitted: 5 6 11
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Received: 4 6 11

receiver-computed sender-computed
checksum
= checksum (as received)

Transport Layer: 3-31


Internet checksum
Goal: detect errors (i.e., flipped bits) in transmitted segment
sender: receiver:
▪ treat contents of UDP ▪ compute checksum of received
segment (including UDP header segment
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

fields and IP addresses) as


sequence of 16-bit integers ▪ check if computed checksum equals
▪ checksum: addition (one’s checksum field value:
complement sum) of segment • not equal - error detected
content • equal - no error detected. But maybe
▪ checksum value put into errors, nonetheless? More later ….
UDP checksum field
Transport Layer: 3-32
Internet checksum: an example
example: add two 16-bit integers
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1

sum 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1

Note: when adding numbers, a carryout from the most significant bit needs to be
added to the result

* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Transport Layer: 3-33
Internet checksum: weak protection!
example: add two 16-bit integers
0 1
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Even though
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
numbers have
sum 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 changed (bit
flips), no change
checksum 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 in checksum!

Transport Layer: 3-34


Summary: UDP
▪ “no frills” protocol:
• segments may be lost, delivered out of order
• best effort service: “send and hope for the best”
▪ UDP has its plusses:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• no setup/handshaking needed (no RTT incurred)


• can function when network service is compromised
• helps with reliability (checksum)
▪ build additional functionality on top of UDP in application layer
(e.g., HTTP/3)
Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-36
Principles of reliable data transfer

sending receiving
process process
application data data
transport
reliable channel
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

reliable service abstraction

Transport Layer: 3-37


Principles of reliable data transfer

sending receiving sending receiving


process process process process
application data data application data data
transport transport
reliable channel
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

sender-side of receiver-side
reliable service abstraction reliable data of reliable data
transfer protocol transfer protocol

transport
network
unreliable channel

reliable service implementation

Transport Layer: 3-38


Principles of reliable data transfer

sending receiving
process process
application data data
transport
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

sender-side of receiver-side
Complexity of reliable data reliable data
transfer protocol
of reliable data
transfer protocol
transfer protocol will depend
(strongly) on characteristics of transport
network
unreliable channel (lose, unreliable channel
corrupt, reorder data?)
reliable service implementation

Transport Layer: 3-39


Principles of reliable data transfer

sending receiving
process process
application data data
transport
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

sender-side of receiver-side
reliable data of reliable data
Sender, receiver do not know transfer protocol transfer protocol
the “state” of each other, e.g.,
was a message received? transport
network
▪ unless communicated via a unreliable channel
message
reliable service implementation

Transport Layer: 3-40


Reliable data transfer protocol (rdt): interfaces
rdt_send(): called from above, deliver_data(): called by rdt
(e.g., by app.). Passed data to to deliver data to upper layer
deliver to receiver upper layer
sending receiving
process process
rdt_send() data data
deliver_data()
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

sender-side data receiver-side


implementation of implementation of
rdt reliable data packet rdt reliable data
transfer protocol transfer protocol
udt_send() Header data Header data rdt_rcv()

unreliable channel
udt_send(): called by rdt rdt_rcv(): called when packet
to transfer packet over Bi-directional communication over arrives on receiver side of
unreliable channel to receiver unreliable channel channel
Transport Layer: 3-41
Reliable data transfer: getting started
We will:
▪ incrementally develop sender, receiver sides of reliable data transfer
protocol (rdt)
▪ consider only unidirectional data transfer
• but control info will flow in both directions!
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ use finite state machines (FSM) to specify sender, receiver


event causing state transition
actions taken on state transition
state: when in this “state”
next state uniquely state state
determined by next 1 event
event 2
actions

Transport Layer: 3-42


rdt1.0: reliable transfer over a reliable channel
▪ underlying channel perfectly reliable
• no bit errors
• no loss of packets

▪ separate FSMs for sender, receiver:


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• sender sends data into underlying channel


• receiver reads data from underlying channel

Wait for rdt_send(data) Wait for rdt_rcv(packet)


sender call from packet = make_pkt(data) receiver call from extract (packet,data)
above udt_send(packet) below deliver_data(data)

Transport Layer: 3-43


rdt2.0: channel with bit errors
▪ underlying channel may flip bits in packet
• checksum (e.g., Internet checksum) to detect bit errors
▪ the question: how to recover from errors?
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

How do humans recover from “errors” during conversation?

Transport Layer: 3-44


rdt2.0: channel with bit errors
▪ underlying channel may flip bits in packet
• checksum to detect bit errors
▪ the question: how to recover from errors?
• acknowledgements (ACKs): receiver explicitly tells sender that pkt
received OK
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• negative acknowledgements (NAKs): receiver explicitly tells sender


that pkt had errors
• sender retransmits pkt on receipt of NAK

stop and wait


sender sends one packet, then waits for receiver response
Transport Layer: 3-45
rdt2.0: FSM specifications
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
sender call from ACK or udt_send(sndpkt) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
above NAK
udt_send(NAK)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L call from receiver
below

rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)


extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)

Transport Layer: 3-46


rdt2.0: FSM specification
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
sender call from ACK or udt_send(sndpkt) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
above NAK
udt_send(NAK)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L call from receiver
below

Note: “state” of receiver (did the receiver get my


message correctly?) isn’t known to sender unless rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
extract(rcvpkt,data)
somehow communicated from receiver to sender deliver_data(data)
▪ that’s why we need a protocol! udt_send(ACK)

Transport Layer: 3-47


rdt2.0: operation with no errors
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
sender call from ACK or udt_send(sndpkt) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
above NAK
udt_send(NAK)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L call from receiver
below

rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)


extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)

Transport Layer: 3-48


rdt2.0: corrupted packet scenario
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
sender call from ACK or udt_send(sndpkt) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
above NAK
udt_send(NAK)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L call from receiver
below

rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)


extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)

Transport Layer: 3-49


rdt2.0 has a fatal flaw!
what happens if ACK/NAK handling duplicates:
corrupted? ▪ sender retransmits current pkt
▪ sender doesn’t know what if ACK/NAK corrupted
happened at receiver! ▪ sender adds sequence number
▪ can’t just retransmit: possible to each pkt
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

duplicate ▪ receiver discards (doesn’t


deliver up) duplicate pkt

stop and wait


sender sends one packet, then
waits for receiver response
Transport Layer: 3-50
rdt2.1: sender, handling garbled ACK/NAKs
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt) rdt_rcv(rcvpkt) &&
(corrupt(rcvpkt) ||
Wait for Wait for isNAK(rcvpkt) )
call 0 from ACK or
NAK 0 udt_send(sndpkt)
above
rdt_rcv(rcvpkt)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt) &&
&& notcorrupt(rcvpkt)
isACK(rcvpkt)
&& isACK(rcvpkt)
L
L
Wait for Wait for
ACK or call 1 from
rdt_rcv(rcvpkt) NAK 1 above
&& (corrupt(rcvpkt) ||
isNAK(rcvpkt) ) rdt_send(data)

udt_send(sndpkt) sndpkt = make_pkt(1, data, checksum)


udt_send(sndpkt)

Transport Layer: 3-51


rdt2.1: receiver, handling garbled ACK/NAKs
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq0(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) && (corrupt(rcvpkt) rdt_rcv(rcvpkt) && (corrupt(rcvpkt)
sndpkt = make_pkt(NAK, chksum) sndpkt = make_pkt(NAK, chksum)
udt_send(sndpkt)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

udt_send(sndpkt)
Wait for Wait for
rdt_rcv(rcvpkt) && 0 from 1 from rdt_rcv(rcvpkt) &&
not corrupt(rcvpkt) && below below not corrupt(rcvpkt) &&
has_seq1(rcvpkt) has_seq0(rcvpkt)
sndpkt = make_pkt(ACK, chksum) sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt) udt_send(sndpkt)
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)

extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)

Transport Layer: 3-52


rdt2.1: discussion
sender: receiver:
▪ seq # added to pkt ▪ must check if received packet
▪ two seq. #s (0,1) will suffice. is duplicate
Why? • state indicates whether 0 or 1 is
expected pkt seq #
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ must check if received ACK/NAK


corrupted ▪ note: receiver can not know if
its last ACK/NAK received OK
▪ twice as many states at sender
• state must “remember” whether
“expected” pkt should have seq #
of 0 or 1

Transport Layer: 3-53


rdt2.2: a NAK-free protocol
▪ same functionality as rdt2.1, using ACKs only
▪ instead of NAK, receiver sends ACK for last pkt received OK
• receiver must explicitly include seq # of pkt being ACKed
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ duplicate ACK at sender results in same action as NAK:


retransmit current pkt

As we will see, TCP uses this approach to be NAK-free

Transport Layer: 3-54


rdt2.2: sender, receiver fragments
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
Wait for Wait for
ACK isACK(rcvpkt,1) )
call 0 from
above 0 udt_send(sndpkt)
sender FSM
fragment
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && && isACK(rcvpkt,0)
(corrupt(rcvpkt) || L
has_seq1(rcvpkt)) Wait for receiver FSM
0 from
udt_send(sndpkt) below fragment
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK1, chksum)
udt_send(sndpkt) Transport Layer: 3-55
rdt3.0: channels with errors and loss
New channel assumption: underlying channel can also lose
packets (data, ACKs)
• checksum, sequence #s, ACKs, retransmissions will be of help …
but not quite enough
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Q: How do humans handle lost sender-to-


receiver words in conversation?

Transport Layer: 3-56


rdt3.0: channels with errors and loss
Approach: sender waits “reasonable” amount of time for ACK
▪ retransmits if no ACK received in this time
▪ if pkt (or ACK) just delayed (not lost):
• retransmission will be duplicate, but seq #s already handle this!
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• receiver must specify seq # of packet being ACKed


▪ use countdown timer to interrupt after “reasonable” amount
of time
timeout

Transport Layer: 3-57


rdt3.0 sender
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
start_timer

Wait for Wait


call 0 from for
above ACK0
rdt_rcv(rcvpkt)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

&& notcorrupt(rcvpkt) rdt_rcv(rcvpkt)


&& isACK(rcvpkt,1) && notcorrupt(rcvpkt)
stop_timer && isACK(rcvpkt,0)
stop_timer
Wait Wait for
for call 1 from
ACK1 above

rdt_send(data)
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
start_timer

Transport Layer: 3-58


rdt3.0 sender
rdt_send(data)
rdt_rcv(rcvpkt) &&
sndpkt = make_pkt(0, data, checksum) ( corrupt(rcvpkt) ||
udt_send(sndpkt) isACK(rcvpkt,1) )
rdt_rcv(rcvpkt) start_timer L
L Wait for Wait
for timeout
call 0 from
ACK0 udt_send(sndpkt)
above
start_timer
rdt_rcv(rcvpkt)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

&& notcorrupt(rcvpkt) rdt_rcv(rcvpkt)


&& isACK(rcvpkt,1) && notcorrupt(rcvpkt)
stop_timer && isACK(rcvpkt,0)
stop_timer
Wait Wait for
timeout for call 1 from
udt_send(sndpkt) ACK1 above
start_timer rdt_rcv(rcvpkt)
rdt_send(data) L
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) || sndpkt = make_pkt(1, data, checksum)
isACK(rcvpkt,0) ) udt_send(sndpkt)
start_timer
L

Transport Layer: 3-59


rdt3.0 in action
sender receiver sender receiver
send pkt0 pkt0 send pkt0 pkt0
rcv pkt0 rcv pkt0
ack0 send ack0 ack0 send ack0
rcv ack0 rcv ack0
send pkt1 pkt1 send pkt1 pkt1
rcv pkt1 X
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

loss
ack1 send ack1
rcv ack1
send pkt0 pkt0
rcv pkt0 timeout
ack0 send ack0 resend pkt1 pkt1
rcv pkt1
ack1 send ack1
rcv ack1
send pkt0 pkt0
(a) no loss rcv pkt0
ack0 send ack0
stop and wait
sender sends one packet, then
waits for receiver response (b) packet loss
Transport Layer: 3-60
rdt3.0 in action
sender receiver
sender receiver send pkt0
pkt0
rcv pkt0
send pkt0 pkt0 send ack0
ack0
rcv pkt0 rcv ack0
ack0 send ack0 send pkt1 pkt1
rcv ack0 rcv pkt1
send pkt1 pkt1 send ack1
rcv pkt1
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

ack1
ack1 send ack1
X timeout
loss resend pkt1
timeout
pkt1 rcv pkt1
resend pkt1 pkt1
rcv pkt1 rcv ack1 (detect duplicate)
send pkt0 pkt0 send ack1
(detect duplicate)
ack1 send ack1 ack1 rcv pkt0
rcv ack1 rcv ack1 send ack0
send pkt0 pkt0 (ignore) ack0
rcv pkt0
ack0 send ack0 pkt1

(c) ACK loss (d) premature timeout/ delayed ACK


Transport Layer: 3-61
Performance of rdt3.0 (stop-and-wait)
▪ U sender: utilization – fraction of time sender busy sending

▪ example: 1 Gbps link, 15 ms prop. delay, 8000-bit packet


• time to transmit packet into channel:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

L 8000 bits
Dtrans = R = 9 = 8 microsecs
10 bits/sec

Transport Layer: 3-62


rdt3.0: stop-and-wait operation
sender receiver
first packet bit transmitted, t = 0

first packet bit arrives


RTT last packet bit arrives, send ACK
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

ACK arrives, send next


packet, t = RTT + L / R

Transport Layer: 3-63


rdt3.0: stop-and-wait operation
sender receiver

L/R L/R
Usender=
RTT + L / R
.008 RTT
=
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

30.008
= 0.00027

▪ rdt 3.0 protocol performance stinks!


▪ Protocol limits performance of underlying infrastructure (channel)

Transport Layer: 3-64


rdt3.0: pipelined protocols operation
pipelining: sender allows multiple, “in-flight”, yet-to-be-acknowledged
packets
• range of sequence numbers must be increased
• buffering at sender and/or receiver
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Transport Layer: 3-65


Pipelining: increased utilization
sender receiver
first packet bit transmitted, t = 0
last bit transmitted, t = L / R

first packet bit arrives


RTT last packet bit arrives, send ACK
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

last bit of 2nd packet arrives, send ACK


last bit of 3rd packet arrives, send ACK
ACK arrives, send next
packet, t = RTT + L / R
3-packet pipelining increases
utilization by a factor of 3!

U 3L / R .0024
sender = = = 0.00081
RTT + L / R 30.008

Transport Layer: 3-66


Go-Back-N: sender
▪ sender: “window” of up to N, consecutive transmitted but unACKed pkts
• k-bit seq # in pkt header
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ cumulative ACK: ACK(n): ACKs all packets up to, including seq # n


• on receiving ACK(n): move window forward to begin at n+1
▪ timer for oldest in-flight packet
▪ timeout(n): retransmit packet n and all higher seq # packets in window
Transport Layer: 3-67
Go-Back-N: receiver
▪ ACK-only: always send ACK for correctly-received packet so far, with
highest in-order seq #
• may generate duplicate ACKs
• need only remember rcv_base
▪ on receipt of out-of-order packet:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• can discard (don’t buffer) or buffer: an implementation decision


• re-ACK pkt with highest in-order seq #

Receiver view of sequence number space:


received and ACKed

… … Out-of-order: received but not ACKed

rcv_base
Not received
Transport Layer: 3-68
Go-Back-N in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, discard,
rcv ack0, send pkt4 (re)send ack1
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

012345678
012345678 rcv ack1, send pkt5 receive pkt4, discard,
(re)send ack1
ignore duplicate ACK receive pkt5, discard,
(re)send ack1
pkt 2 timeout
012345678 send pkt2
012345678 send pkt3
012345678 send pkt4 rcv pkt2, deliver, send ack2
012345678 send pkt5 rcv pkt3, deliver, send ack3
rcv pkt4, deliver, send ack4
rcv pkt5, deliver, send ack5

Transport Layer: 3-69


Selective repeat
▪receiver individually acknowledges all correctly received packets
• buffers packets, as needed, for eventual in-order delivery to upper
layer
▪sender times-out/retransmits individually for unACKed packets
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• sender maintains timer for each unACKed pkt


▪sender window
• N consecutive seq #s
• limits seq #s of sent, unACKed packets

Transport Layer: 3-70


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Selective repeat: sender, receiver windows

Transport Layer: 3-71


Selective repeat: sender and receiver
sender receiver
data from above: packet n in [rcvbase, rcvbase+N-1]
▪ if next available seq # in ▪ send ACK(n)
window, send packet ▪ out-of-order: buffer
timeout(n): ▪ in-order: deliver (also deliver
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

buffered, in-order packets),


▪ resend packet n, restart timer advance window to next not-yet-
ACK(n) in [sendbase,sendbase+N]: received packet
▪ mark packet n as received packet n in [rcvbase-N,rcvbase-1]
▪ if n smallest unACKed packet, ▪ ACK(n)
advance window base to next otherwise:
unACKed seq # ▪ ignore

Transport Layer: 3-72


Selective Repeat in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, buffer,
rcv ack0, send pkt4 send ack3
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

012345678
012345678 rcv ack1, send pkt5
receive pkt4, buffer,
record ack3 arrived send ack4
receive pkt5, buffer,
pkt 2 timeout send ack5
012345678 send pkt2
012345678 (but not 3,4,5)
012345678 rcv pkt2; deliver pkt2,
012345678 pkt3, pkt4, pkt5; send ack2

Q: what happens when ack2 arrives?

Transport Layer: 3-73


sender window receiver window
Selective repeat: (after receipt)

pkt0
(after receipt)

a dilemma!
0123012
0123012 pkt1 0123012
0123012 pkt2 0123012
0123012
example: 0123012 pkt3
X
▪ seq #s: 0, 1, 2, 3 (base 4 counting)
0123012
pkt0 will accept packet
with seq number 0
▪ window size=3 (a) no problem
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

0123012 pkt0
0123012 pkt1 0123012
0123012 pkt2 X 0123012
X 0123012
X
timeout
retransmit pkt0
0123012 pkt0
will accept packet
with seq number 0
(b) oops!
Transport Layer: 3-74
sender window receiver window
Selective repeat: (after receipt)

pkt0
(after receipt)

a dilemma!
0123012
0123012 pkt1 0123012
0123012 pkt2 0123012
0123012
example: 0123012 pkt3
X
▪ seq #s: 0, 1, 2, 3 (base 4 counting) ▪ receiver can’t
0123012
pkt0 will accept packet
see sender side with seq number 0
▪ window size=3 (a) no problem
▪ receiver
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

behavior
identical in both
cases!
▪0something’s
123012 pkt0
Q: what relationship is needed 0(very)
1 2 3 0 1wrong!
2 pkt1 0123012
pkt2 X
between sequence # size and 0123012
X
0123012
0123012
window size to avoid problem X
timeout
in scenario (b)? retransmit pkt0
0123012 pkt0
will accept packet
with seq number 0
(b) oops!
Transport Layer: 3-75
Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


• segment structure
• reliable data transfer
• flow control
• connection management
▪ Principles of congestion control
▪ TCP congestion control
Transport Layer: 3-76
TCP: overview RFCs: 793,1122, 2018, 5681, 7323
▪ point-to-point: ▪ cumulative ACKs
• one sender, one receiver ▪ pipelining:
▪ reliable, in-order byte • TCP congestion and flow control
stream: set window size
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• no “message boundaries" ▪ connection-oriented:


▪ full duplex data: • handshaking (exchange of control
• bi-directional data flow in messages) initializes sender,
same connection receiver state before data exchange
• MSS: maximum segment size ▪ flow controlled:
• sender will not overwhelm receiver

Transport Layer: 3-77


TCP segment structure
32 bits

source port # dest port # segment seq #: counting


ACK: seq # of next expected sequence number bytes of data into bytestream
byte; A bit: this is an ACK (not segments!)
acknowledgement number
head not
length (of TCP header) len used C EUAP R SF receive window flow control: # bytes
Internet checksum receiver willing to accept
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

checksum Urg data pointer

options (variable length)


C, E: congestion notification
TCP options
application data sent by
RST, SYN, FIN: connection data application into
management (variable length) TCP socket

Transport Layer: 3-78


TCP sequence numbers, ACKs
outgoing segment from sender
Sequence numbers: source port # dest port #
sequence number
• byte stream “number” of acknowledgement number
rwnd
first byte in segment’s data checksum urg pointer

window size
Acknowledgements: N
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• seq # of next byte expected


from other side sender sequence number space

• cumulative ACK sent sent, not- usable not


ACKed yet ACKed but not usable
(“in-flight”) yet sent
Q: how receiver handles out-of-
order segments outgoing segment from receiver

• A: TCP spec doesn’t say, - up


source port # dest port #
sequence number

to implementor acknowledgement number


A rwnd
checksum urg pointer
Transport Layer: 3-79
TCP sequence numbers, ACKs
Host A Host B

User types‘C’
Seq=42, ACK=79, data = ‘C’
host ACKs receipt
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

of‘C’, echoes back ‘C’


Seq=79, ACK=43, data = ‘C’
host ACKs receipt
of echoed ‘C’
Seq=43, ACK=80

simple telnet scenario


Transport Layer: 3-80
TCP round trip time, timeout
Q: how to set TCP timeout Q: how to estimate RTT?
value? ▪ SampleRTT:measured time
▪ longer than RTT, but RTT varies! from segment transmission until
ACK receipt
▪ too short: premature timeout,
• ignore retransmissions
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

unnecessary retransmissions
▪ SampleRTT will vary, want
▪ too long: slow reaction to estimated RTT “smoother”
segment loss • average several recent
measurements, not just current
SampleRTT

Transport Layer: 3-81


TCP round trip time, timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
▪ exponential weighted moving average (EWMA)
▪ influence of past sample decreases exponentially fast
▪ typical value:  = 0.125
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

RTT: gaia.cs.umass.edu to fantasia.eurecom.fr


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

RTT (milliseconds)
300

250

RTT (milliseconds)
200

sampleRTT
150

EstimatedRTT

100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
time (seconds)
SampleRTT Estimated RTT Transport Layer: 3-82
TCP round trip time, timeout
▪ timeout interval: EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT: want a larger safety margin
TimeOutInterval = EstimatedRTT + 4*DevRTT
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

estimated RTT “safety margin”

▪ DevRTT: EWMA of SampleRTT deviation from EstimatedRTT:


DevRTT = (1-)*DevRTT + *|SampleRTT-EstimatedRTT|
(typically,  = 0.25)

* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Transport Layer: 3-83
TCP Sender (simplified)
event: data received from event: timeout
application ▪ retransmit segment that
caused timeout
▪ create segment with seq #
▪ restart timer
▪ seq # is byte-stream number of
first data byte in segment
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

event: ACK received


▪ start timer if not already
running ▪ if ACK acknowledges
• think of timer as for oldest previously unACKed segments
unACKed segment • update what is known to be
• expiration interval: ACKed
TimeOutInterval • start timer if there are still
unACKed segments
Transport Layer: 3-84
TCP Receiver: ACK generation [RFC 5681]
Event at receiver TCP receiver action
arrival of in-order segment with delayed ACK. Wait up to 500ms
expected seq #. All data up to for next segment. If no next segment,
expected seq # already ACKed send ACK
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

arrival of in-order segment with immediately send single cumulative


expected seq #. One other ACK, ACKing both in-order segments
segment has ACK pending

arrival of out-of-order segment immediately send duplicate ACK,


higher-than-expect seq. # . indicating seq. # of next expected byte
Gap detected

arrival of segment that immediate send ACK, provided that


partially or completely fills gap segment starts at lower end of gap

Transport Layer: 3-85


TCP: retransmission scenarios
Host A Host B Host A Host B

SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


timeout

timeout
ACK=100
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

X
ACK=100
ACK=120

Seq=92, 8 bytes of data Seq=92, 8


SendBase=100 bytes of data send cumulative
SendBase=120 ACK for 120
ACK=100
ACK=120

SendBase=120

lost ACK scenario premature timeout

Transport Layer: 3-86


TCP: retransmission scenarios
Host A Host B

Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

ACK=100
X
ACK=120

Seq=120, 15 bytes of data

cumulative ACK covers


for earlier lost ACK
Transport Layer: 3-87
TCP fast retransmit
Host A Host B
TCP fast retransmit
if sender receives 3 additional
ACKs for same data (“triple
duplicate ACKs”), resend unACKed
segment with smallest seq # X
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ likely that unACKed segment lost,


so don’t wait for timeout

timeout
Receipt of three duplicate ACKs
indicates 3 segments received Seq=100, 20 bytes of data

after a missing segment – lost


segment is likely. So, retransmit!

Transport Layer: 3-88


Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


• segment structure
• reliable data transfer
• flow control
• connection management
▪ Principles of congestion control
▪ TCP congestion control
Transport Layer: 3-89
TCP flow control
application
Q: What happens if network Application removing
process
layer delivers data faster data from TCP socket
buffers
than application layer TCP socket
removes data from socket receiver buffers
buffers?
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

TCP
code
Network layer
delivering IP datagram
payload into TCP
IP
socket buffers
code

from sender

receiver protocol stack

Transport Layer: 3-90


TCP flow control
application
Q: What happens if network Application removing
process
layer delivers data faster than data from TCP socket
buffers
application layer removes TCP socket
data from socket buffers? receiver buffers
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

TCP
code
Network layer
delivering IP datagram
payload into TCP
IP
socket buffers
code

from sender

receiver protocol stack

Transport Layer: 3-91


TCP flow control
application
Q: What happens if network Application removing
process
layer delivers data faster than data from TCP socket
buffers
application layer removes TCP socket
data from socket buffers? receiver buffers
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

TCP
code

receive window
flow control: # bytes
receiver willing to accept IP
code

from sender

receiver protocol stack

Transport Layer: 3-92


TCP flow control
application
Q: What happens if network Application removing
process
layer delivers data faster than data from TCP socket
buffers
application layer removes TCP socket
data from socket buffers? receiver buffers
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

TCP
code
flow control
receiver controls sender, so
sender won’t overflow IP
code
receiver’s buffer by
transmitting too much, too fast
from sender

receiver protocol stack

Transport Layer: 3-93


TCP flow control
▪ TCP receiver “advertises” free buffer
space in rwnd field in TCP header to application process
• RcvBuffer size set via socket
options (typical default is 4096 bytes) RcvBuffer buffered data
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• many operating systems auto-adjust


RcvBuffer
rwnd free buffer space

▪ sender limits amount of unACKed


(“in-flight”) data to received rwnd TCP segment payloads

▪ guarantees receive buffer will not TCP receiver-side buffering


overflow

Transport Layer: 3-94


TCP flow control
flow control: # bytes receiver willing to accept

▪ TCP receiver “advertises” free buffer


space in rwnd field in TCP header
• RcvBuffer size set via socket
receive window
options (typical default is 4096 bytes)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• many operating systems autoadjust


RcvBuffer
▪ sender limits amount of unACKed
(“in-flight”) data to received rwnd
▪ guarantees receive buffer will not
overflow
TCP segment format

Transport Layer: 3-95


TCP connection management
before exchanging data, sender/receiver “handshake”:
▪ agree to establish connection (each knowing the other willing to establish connection)
▪ agree on connection parameters (e.g., starting seq #s)

application application
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

connection state: ESTAB connection state: ESTAB


connection variables: connection Variables:
seq # client-to-server seq # client-to-server
server-to-client server-to-client
rcvBuffer size rcvBuffer size
at server,client at server,client

network network

Socket clientSocket = Socket connectionSocket =


newSocket("hostname","port number"); welcomeSocket.accept();
Transport Layer: 3-96
Agreeing to establish a connection
2-way handshake:

Q: will 2-way handshake always


Let’s talk work in network?
ESTAB
▪ variable delays
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

OK
ESTAB
▪ retransmitted messages (e.g.,
req_conn(x)) due to message
loss
choose x
req_conn(x) ▪ message reordering
acc_conn(x)
ESTAB ▪ can’t “see” other side
ESTAB

Transport Layer: 3-97


2-way handshake scenarios

choose x
req_conn(x)
ESTAB
acc_conn(x)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

ESTAB
data(x+1) accept
data(x+1)
ACK(x+1)
connection
x completes

No problem!

Transport Layer: 3-98


2-way handshake scenarios

choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

ESTAB
req_conn(x)

connection
client x completes server
terminates forgets x

ESTAB
acc_conn(x)
Problem: half open
connection! (no client)
Transport Layer: 3-99
2-way handshake scenarios
choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)

ESTAB
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

data(x+1) accept
data(x+1)
retransmit
data(x+1)
connection
x completes server
client
terminates forgets x
req_conn(x)
ESTAB
data(x+1) accept
data(x+1)
Problem: dup data
accepted!
TCP 3-way handshake
Server state
serverSocket = socket(AF_INET,SOCK_STREAM)
Client state serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
clientSocket = socket(AF_INET, SOCK_STREAM) connectionSocket, addr = serverSocket.accept()
LISTEN
clientSocket.connect((serverName,serverPort)) LISTEN
choose init seq num, x
send TCP SYN msg
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

SYNSENT SYNbit=1, Seq=x


choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB

Transport Layer: 3-101


A human 3-way handshake protocol

1. On belay?
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

2. Belay on.
3. Climbing.

Transport Layer: 3-102


Closing a TCP connection
▪ client, server each closes their side of connection
• send TCP segment with FIN bit = 1
▪ respond to received FIN with ACK
• on receiving FIN, ACK can be combined with own FIN
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ simultaneous FIN exchanges can be handled

Transport Layer: 3-103


Closing a TCP connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

FIN_WAIT_2 wait for server send data


close

LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime

CLOSED

Transport Layer: 3-104


Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-105
Principles of congestion control
Congestion:
▪ informally: “too many sources sending too much data too fast for
network to handle”
▪ manifestations:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• long delays (queueing in router buffers)


• packet loss (buffer overflow at routers)
▪ different from flow control! congestion control:
▪ a top-10 problem! too many senders,
sending too fast

flow control: one sender


too fast for one receiver
Transport Layer: 3-106
Causes/costs of congestion: scenario 1
original data: lin throughput: lout
Simplest scenario:
Host A
▪ one router, infinite buffers
▪ no retransmissions needed infinite shared
output link buffers

▪ input, output link capacity: R


R R
▪ two flows: fairly, R/2
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Host B

R/2
Q: What happens as
arrival rate lin lout

delay
throughput:

approaches R/2?
lin R/2 lin R/2
maximum per-connection large delays as arrival rate
throughput: R/2 lin approaches capacity
Transport Layer: 3-107
Causes/costs of congestion: scenario 2
▪ one router, finite buffers
▪ sender retransmits lost, timed-out packet
• application-layer input = application-layer output: lin = lout
• transport-layer input includes retransmissions : l’in lin
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Host A lin : original data


lout
l'in: original data, plus
retransmitted data

R R

Host B finite shared output


link buffers
Transport Layer: 3-108
Causes/costs of congestion: scenario 2
Idealization: perfect knowledge R/2

▪ sender sends only when router buffers available

throughput: lout
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Host A lin : original data lin


lout R/2
copy l'in: original data, plus
retransmitted data

free buffer space!

R R

Host B finite shared output


link buffers
Transport Layer: 3-109
Causes/costs of congestion: scenario 2
Idealization: some perfect knowledge
▪ packets can be lost (dropped at router) due to
full buffers
▪ sender knows when packet has been dropped:
only resends if packet known to be lost
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Host A lin : original data


copy l'in: original data, plus
retransmitted data

no buffer space!

R R

Host B finite shared output


link buffers
Transport Layer: 3-110
Causes/costs of congestion: scenario 2
Idealization: some perfect knowledge R/2
“wasted” capacity due
▪ packets can be lost (dropped at router) due to to retransmissions

throughput: lout
full buffers
when sending at
▪ sender knows when packet has been dropped: R/2, some packets
only resends if packet known to be lost are needed
retransmissions
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Host A lin : original data lin R/2


l'in: original data, plus
retransmitted data

free buffer space!

R R

Host B finite shared output


link buffers
Transport Layer: 3-111
Causes/costs of congestion: scenario 2
Realistic scenario: un-needed duplicates R/2
▪ packets can be lost, dropped at router due to “wasted” capacity due

throughput: lout
to un-needed
full buffers – requiring retransmissions retransmissions
▪ but sender timer can time out prematurely,
sending two copies, both of which are delivered when sending at
R/2, some packets
are retransmissions,
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

including needed
Host A lin : original data lin
and un-needed
duplicates, that are
R/2
timeout
copy l'in: original data, plus delivered!
retransmitted data

free buffer space!

R R

Host B finite shared output


link buffers
Transport Layer: 3-112
Causes/costs of congestion: scenario 2
Realistic scenario: un-needed duplicates R/2
▪ packets can be lost, dropped at router due to “wasted” capacity due

throughput: lout
to un-needed
full buffers – requiring retransmissions retransmissions
▪ but sender timer can time out prematurely,
sending two copies, both of which are delivered when sending at
R/2, some packets
are retransmissions,
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

including needed
and un-needed
lin R/2 duplicates, that are
delivered!
“costs” of congestion:
▪ more work (retransmission) for given receiver throughput
▪ unneeded retransmissions: link carries multiple copies of a packet
• decreasing maximum achievable throughput

Transport Layer: 3-113


Causes/costs of congestion: scenario 3
▪ four senders Q: what happens as lin and lin’ increase ?
▪ multi-hop paths A: as red lin’ increases, all arriving blue pkts at upper
▪ timeout/retransmit queue are dropped, blue throughput g 0
Host A lin : original data
Host B
l'in: original data, plus
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

retransmitted data
finite shared
output link buffers

Host D
lout
Host C

Transport Layer: 3-114


Causes/costs of congestion: scenario 3
R/2
lout
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

lin’ R/2

another “cost” of congestion:


▪ when packet dropped, any upstream transmission capacity and
buffering used for that packet was wasted!

Transport Layer: 3-115


Causes/costs of congestion: insights
R/2

▪ throughput can never exceed capacity

throughput: lout
lin R/2

▪ delay increases as capacity approached

delay
R/2
lin R/2

lout
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ loss/retransmission decreases effective

throughput:
throughput
lin R/2 R/2

▪ un-needed duplicates further decreases

throughput: lout
effective throughput
R/2
lin

▪ upstream transmission capacity/buffering


R/2

lout
wasted for packets lost downstream
lin’ R/2

Transport Layer: 3-116


Approaches towards congestion control
End-end congestion control:
▪ no explicit feedback from
network
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ congestion inferred from data data


ACKs
observed loss, delay ACKs

▪ approach taken by TCP

Transport Layer: 3-117


Approaches towards congestion control
Network-assisted congestion
control: explicit congestion info
▪ routers provide direct feedback
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

to sending/receiving hosts with data data


ACKs
flows passing through congested ACKs

router
▪ may indicate congestion level or
explicitly set sending rate
• e.g., TCP ECN, ATM, DECbit protocols

Transport Layer: 3-118


Chapter 3: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-119
TCP congestion control: AIMD
▪ approach: senders can increase sending rate until packet loss
(congestion) occurs, then decrease sending rate on loss event
Additive Increase Multiplicative Decrease
increase sending rate by 1 cut sending rate in half at
maximum segment size (MSS) each loss event
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

every RTT until loss detected


TCP sender Sending rate

AIMD sawtooth
behavior: probing
for bandwidth

time Transport Layer: 3-120


TCP AIMD: more
Multiplicative decrease detail: 2 events, sending rate is
▪ Cut in half on loss detected by triple duplicate ACK (TCP Reno)
▪ Cut to 1 MSS (maximum segment size) when loss detected by
timeout (TCP Tahoe)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Why AIMD?
▪ AIMD – a distributed, asynchronous algorithm – has been
shown to:
• optimize congested flow rates network wide!
• have desirable stability properties

Transport Layer: 3-121


TCP congestion control: details
sender sequence number space
cwnd TCP sending behavior:
▪ roughly: send cwnd bytes,
wait RTT for ACKs, then
send more bytes
last byte
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

available but ~
cwnd
ACKed sent, but not- TCP rate ~ bytes/sec
yet ACKed not used RTT
(“in-flight”) last byte sent

▪ TCP sender limits transmission: LastByteSent - LastByteAcked < cwnd


▪ cwnd is dynamically adjusted in response to observed
network congestion (implementing TCP congestion control)
Transport Layer: 3-122
TCP slow start
Host A Host B
▪ when connection begins,
increase rate exponentially
until first loss event:

RTT
• initially cwnd = 1 MSS
• double cwnd every RTT
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• done by incrementing cwnd


for every ACK received
▪ summary: initial rate is
slow, but ramps up
exponentially fast time

Transport Layer: 3-123


TCP: from slow start to congestion avoidance
Q: when should the exponential
increase switch to linear?
X
A: when cwnd gets to 1/2 of its
value before timeout.
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Implementation:
▪ variable ssthresh
▪ on loss event, ssthresh is set to
1/2 of cwnd just before loss event

* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Transport Layer: 3-124
Summary: TCP congestion control
New
New ACK!
ACK! new ACK
duplicate ACK
dupACKcount++ new ACK .
cwnd = cwnd + MSS (MSS/cwnd)
dupACKcount = 0
cwnd = cwnd+MSS transmit new segment(s), as allowed
dupACKcount = 0
L transmit new segment(s), as allowed
cwnd = 1 MSS
ssthresh = 64 KB cwnd > ssthresh
dupACKcount = 0
slow L congestion
start timeout avoidance
ssthresh = cwnd/2
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

cwnd = 1 MSS duplicate ACK


timeout dupACKcount = 0 dupACKcount++
ssthresh = cwnd/2 retransmit missing segment
cwnd = 1 MSS
dupACKcount = 0
retransmit missing segment New
timeout
ACK!
ssthresh = cwnd/2
cwnd = 1 New ACK
dupACKcount = 0
cwnd = ssthresh dupACKcount == 3
dupACKcount == 3 retransmit missing segment dupACKcount = 0
ssthresh= cwnd/2 ssthresh= cwnd/2
cwnd = ssthresh + 3 cwnd = ssthresh + 3
retransmit missing segment retransmit missing segment
fast
recovery
duplicate ACK
cwnd = cwnd + MSS
transmit new segment(s), as allowed

Transport Layer: 3-125


TCP CUBIC
▪ Is there a better way than AIMD to “probe” for usable bandwidth?
▪ Insight/intuition:
• Wmax: sending rate at which congestion loss was detected
• congestion state of bottleneck link probably (?) hasn’t changed much
• after cutting rate/window in half on loss, initially ramp to to Wmax faster, but then
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

approach Wmax more slowly

Wmax classic TCP

TCP CUBIC - higher


Wmax/2 throughput in this
example

Transport Layer: 3-126


TCP CUBIC
▪ K: point in time when TCP window size will reach Wmax
• K itself is tunable
▪ increase W as a function of the cube of the distance between current
time and K
• larger increases when further away from K
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• smaller increases (cautious) when nearer K


▪ TCP CUBIC default Wmax
in Linux, most
TCP Reno
popular TCP for TCP CUBIC
popular Web TCP
sending
servers rate

time
t0 t1 t2 t3 t4
Transport Layer: 3-127
TCP and the congested “bottleneck link”
▪ TCP (classic, CUBIC) increase TCP’s sending rate until packet loss occurs
at some router’s output: the bottleneck link
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

source destination
application application
TCP TCP
network network
link link
physical physical
packet queue almost
never empty, sometimes
overflows packet (loss)

bottleneck link (almost always busy)


Transport Layer: 3-128
TCP and the congested “bottleneck link”
▪ TCP (classic, CUBIC) increase TCP’s sending rate until packet loss occurs
at some router’s output: the bottleneck link
▪ understanding congestion: useful to focus on congested bottleneck link
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

insight: increasing TCP sending rate will


source not increase end-end throughout destination
with congested bottleneck
application application
TCP TCP
network network
link link
physical physical

insight: increasing TCP


sending rate will
increase measured RTT
Goal: “keep the end-end pipe just full, but not fuller”
RTT
Transport Layer: 3-129
Delay-based TCP congestion control
Keeping sender-to-receiver pipe “just full enough, but no fuller”: keep
bottleneck link busy transmitting, but avoid high delays/buffering
# bytes sent in
measured last RTT interval
RTTmeasured throughput =
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

RTTmeasured
Delay-based approach:
▪ RTTmin - minimum observed RTT (uncongested path)
▪ uncongested throughput with congestion window cwnd is cwnd/RTTmin
if measured throughput “very close” to uncongested throughput
increase cwnd linearly /* since path not congested */
else if measured throughput “far below” uncongested throughout
decrease cwnd linearly /* since path is congested */
Transport Layer: 3-130
Delay-based TCP congestion control
▪ congestion control without inducing/forcing loss
▪ maximizing throughput (“keeping the just pipe full… ”) while keeping
delay low (“…but not fuller”)
▪ a number of deployed TCPs take a delay-based approach
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ e.g., Bottleneck Bandwidth and Round-trip propagation time (BBR) deployed on


Google’s (internal) backbone network

Transport Layer: 3-131


Explicit congestion notification (ECN)
TCP deployments often implement network-assisted congestion control:
▪ two bits in IP header (ToS field) marked by network router to indicate congestion
• policy to determine marking chosen by network operator
▪ congestion indication carried to destination
▪ destination sets ECE bit on ACK segment to notify sender of congestion
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ involves both IP (IP header ECN bit marking) and TCP (TCP header C,E bit marking)
source TCP ACK segment
destination
application application
TCP ECE=1
TCP
network network
link link
physical physical

ECN=10 ECN=11

IP datagram
Transport Layer: 3-132
TCP fairness
Fairness goal: if K TCP sessions share same bottleneck link of
bandwidth R, each should have average rate of R/K
TCP connection 1
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

bottleneck
TCP connection 2 router
capacity R

Transport Layer: 3-133


Q: is TCP Fair?
Example: two competing TCP sessions:
▪ additive increase gives slope of 1, as throughout increases
▪ multiplicative decrease decreases throughput proportionally

R equal bandwidth share


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Is TCP fair?
A: Yes, under idealized
loss: decrease window by factor of 2 assumptions:
congestion avoidance: additive increase ▪ same RTT
loss: decrease window by factor of 2
congestion avoidance: additive increase ▪ fixed number of sessions
only in congestion
avoidance

Connection 1 throughput R
Transport Layer: 3-134
Fairness: must all network apps be “fair”?
Fairness and UDP Fairness, parallel TCP
▪ multimedia apps often do not connections
use TCP ▪ application can open multiple
• do not want rate throttled by
congestion control parallel connections between two
hosts
▪ instead use UDP:
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• send audio/video at constant rate, ▪ web browsers do this, e.g., link of


tolerate packet loss rate R with 9 existing connections:
▪ there is no “Internet police” • new app asks for 1 TCP, gets rate R/10
policing use of congestion • new app asks for 11 TCPs, gets R/20
control

Transport Layer: 3-135


Transport layer: roadmap
▪ Transport-layer services
▪ Multiplexing and demultiplexing
▪ Connectionless transport: UDP
▪ Principles of reliable data transfer
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

▪ Connection-oriented transport: TCP


▪ Principles of congestion control
▪ TCP congestion control
▪ Evolution of transport-layer
functionality
Transport Layer: 3-136
Evolving transport-layer functionality
▪ TCP, UDP: principal transport protocols for 40 years
▪ different “flavors” of TCP developed, for specific scenarios:
Scenario Challenges
Long, fat pipes (large data Many packets “in flight”; loss shuts down
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

transfers) pipeline
Wireless networks Loss due to noisy wireless links, mobility;
TCP treat this as congestion loss
Long-delay links Extremely long RTTs
Data center networks Latency sensitive
Background traffic flows Low priority, “background” TCP flows

▪ moving transport–layer functions to application layer, on top of UDP


• HTTP/3, QUIC
Transport Layer: 3-137
QUIC: Quick UDP Internet Connections
▪ application-layer protocol, on top of UDP
• increase performance of HTTP
• deployed on many Google servers, apps (Chrome, mobile YouTube app)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

HTTP/2 HTTP/2 (slimmed)


Application HTTP/3
TLS QUIC

Transport TCP UDP

Network IP IP

HTTP/2 over TCP HTTP/2 over QUIC over UDP

Transport Layer: 3-138


QUIC: Quick UDP Internet Connections
adopts approaches we’ve studied in this chapter for
connection establishment, error control, congestion control
• error and congestion control: “Readers familiar with TCP’s loss
detection and congestion control will find algorithms here that parallel
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

well-known TCP ones.” [from QUIC specification]


• connection establishment: reliability, congestion control,
authentication, encryption, state established in one RTT

▪ multiple application-level “streams” multiplexed over single QUIC


connection
• separate reliable data transfer, security
• common congestion control
Transport Layer: 3-139
QUIC: Connection establishment

TCP handshake
(transport layer) QUIC handshake
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

data
TLS handshake
(security)
data

TCP (reliability, congestion control state) QUIC: reliability, congestion control,


+ TLS (authentication, crypto state) authentication, crypto state
▪ 2 serial handshakes ▪ 1 handshake

Transport Layer: 3-140


QUIC: streams: parallelism, no HOL blocking
HTTP HTTP
GET GET HTTP
GET
HTTP HTTP
application

GET GET
HTTP
GET QUIC QUIC QUIC QUIC QUIC QUIC
encrypt encrypt encrypt encrypt encrypt encrypt
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

QUIC QUIC QUIC QUIC QUIC QUIC


TLS encryption TLS encryption RDT RDT RDT RDT
error!
RDT RDT

QUIC Cong. Cont. QUIC Cong. Cont.


TCP RDT TCP
error! RDT
transport

TCP Cong. Contr. TCP Cong. Contr. UDP UDP

(a) HTTP 1.1 (b) HTTP/2 with QUIC: no HOL blocking


Transport Layer: 3-141
Chapter 3: summary
▪ principles behind transport Up next:
layer services: ▪ leaving the network
• multiplexing, demultiplexing “edge” (application,
• reliable data transfer transport layers)
• flow control ▪ into the network “core”
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

• congestion control
▪ two network-layer
▪ instantiation, implementation chapters:
on the Internet • data plane
• UDP • control plane
• TCP

Transport Layer: 3-142


Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

Additional Chapter 3 slides

Transport Layer: 3-143


Go-Back-N: sender extended FSM
rdt_send(data)
if (nextseqnum < base+N) {
sndpkt[nextseqnum] = make_pkt(nextseqnum,data,chksum)
udt_send(sndpkt[nextseqnum])
if (base == nextseqnum)
start_timer
nextseqnum++
}
L else
refuse_data(data)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

base=1
nextseqnum=1
timeout
start_timer
Wait udt_send(sndpkt[base])
rdt_rcv(rcvpkt) udt_send(sndpkt[base+1])
&& corrupt(rcvpkt) …
udt_send(sndpkt[nextseqnum-1])
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
base = getacknum(rcvpkt)+1
If (base == nextseqnum)
stop_timer
else
start_timer
Transport Layer: 3-144
Go-Back-N: receiver extended FSM
any other event
udt_send(sndpkt) rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
L && hasseqnum(rcvpkt,expectedseqnum)
expectedseqnum=1 Wait extract(rcvpkt,data)
sndpkt = deliver_data(data)
make_pkt(expectedseqnum,ACK,chksum) sndpkt = make_pkt(expectedseqnum,ACK,chksum)
udt_send(sndpkt)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

expectedseqnum++

ACK-only: always send ACK for correctly-received packet with highest


in-order seq #
• may generate duplicate ACKs
• need only remember expectedseqnum
▪ out-of-order packet:
• discard (don’t buffer): no receiver buffering!
• re-ACK pkt with highest in-order seq #
Transport Layer: 3-145
TCP sender (simplified)
data received from application above
create segment, seq. #: NextSeqNum
pass segment to IP (i.e., “send”)
NextSeqNum = NextSeqNum + length(data)
if (timer currently not running)
L start timer
NextSeqNum = InitialSeqNum wait
SendBase = InitialSeqNum for
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

event timeout
retransmit not-yet-acked segment
with smallest seq. #
start timer
ACK received, with ACK field value y
if (y > SendBase) {
SendBase = y
/* SendBase–1: last cumulatively ACKed byte */
if (there are currently not-yet-acked segments)
start timer
else stop timer
}
Transport Layer: 3-146
TCP 3-way handshake FSM
closed
Socket connectionSocket =
welcomeSocket.accept();
L Socket clientSocket =
newSocket("hostname","port number");
SYN(x)
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

SYNACK(seq=y,ACKnum=x+1) SYN(seq=x)
create new socket for communication
back to client
listen

SYN
SYN sent
rcvd
SYNACK(seq=y,ACKnum=x+1)
ESTAB
ACK(ACKnum=y+1) ACK(ACKnum=y+1)
L

Transport Layer: 3-147


TCP throughput
▪ avg. TCP throughput as function of window size, RTT?
• ignore slow start, assume there is always data to send
▪ W: window size (measured in bytes) where loss occurs
• avg. window size (# in-flight bytes) is ¾ W
• avg. throughput is 3/4W per RTT
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

3 W
avg TCP throughput = bytes/sec
4 RTT
W

W/2
TCP over “long, fat pipes”
▪ example: 1500-byte segments, 100ms RTT, want 10 Gbps throughput
▪ requires W = 83,333 in-flight segments
▪ throughput in terms of segment loss probability, L [Mathis 1997]:

1.22 . MSS
Copyright® 1996-2020, J.F Kurose and K.W. Ross, All Rights Reserved

TCP throughput =
RTT L
➜ to achieve 10 Gbps throughput, need a loss rate of L = 2·10-10 – a
very small loss rate!
▪ versions of TCP for long, high-speed scenarios

Transport Layer: 3-149

You might also like