0% found this document useful (0 votes)
20 views178 pages

Chapter 3 v8.0 AAST

Uploaded by

Seif.A. Sayed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views178 pages

Chapter 3 v8.0 AAST

Uploaded by

Seif.A. Sayed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 178

Chapter 3

Transport Layer

Transport Layer: 3-1


Transport layer: roadmap
• Transport-layer services
• Multiplexing and demultiplexing
• Connectionless transport: UDP
• Principles of reliable data transfer
• Connection-oriented transport: TCP
• Principles of congestion control
• TCP congestion control
• Evolution of transport-layer functionality

Transport Layer: 3-2


Transport layer: roadmap
• Transport-layer services
• Multiplexing and demultiplexing
• Connectionless transport: UDP
• Principles of reliable data transfer
• Connection-oriented transport: TCP
• Principles of congestion control
• TCP congestion control
• Evolution of transport-layer functionality

Transport Layer: 3-3


3.1 Introduction and Transport-Layer Services
Transport services and protocols application
transport
network
mobile network
 provide logical communication data link
physical
national or global ISP
between application processes
running on different hosts
 transport protocols actions in end
systems: 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
3.1 Introduction and Transport-Layer Services
Transport services and protocols

Example:
application messages = letters in envelopes
processes = cousins
hosts (end systems) = houses
transport-layer protocol = Ann and Bill
network-layer protocol = postal service (including mail carriers)

5  Prof. Yahya Z. Mohasseb


3.1 Introduction and Transport-Layer Services
Transport Layer Actions
Sender:
application  is passed an application- application
app. msg
layer message
transport  determines segment TThhtransport
app. msg
header fields values
network (IP)  creates segment network (IP)

link  passes segment to IP link

physical physical

Transport Layer: 3-6


3.1 Introduction and Transport-Layer Services
Transport Layer Actions
Receiver:
application  receives segment from IP application
 checks header values
transport
app. msg  extracts application-layer transport
message
network (IP) network (IP)
 demultiplexes message up
link to application via socket link

physical physical
Th app. msg

Transport Layer: 3-7


3.1 Introduction and Transport-Layer Services
Two principal Internet transport protocols
application
transport

 UDP: User Datagram Protocol mobile network


network
data link
physical
national or global ISP
• unreliable, unordered delivery
• Basic extension of “best-effort” IP
 TCP: Transmission Control Protocol
• reliable, in-order delivery local or
regional ISP
• congestion control
• flow control home network content
provider
• connection setup network datacenter
application
network

 services not available:


transport
network
data link

• delay guarantees
physical

• bandwidth guarantees enterprise


network
Transport Layer: 3-8
Transport layer: roadmap
• Transport-layer services
• Multiplexing and demultiplexing
• Connectionless transport: UDP
• Principles of reliable data transfer
• Connection-oriented transport: TCP
• Principles of congestion control
• TCP congestion control
• Evolution of transport-layer functionality

Transport Layer: 3-9


3.2 Multiplexing and Demultiplexing
HTTP server
client
application application
HTTP msg
transport

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-10


3.2 Multiplexing and Demultiplexing
HTTP server
client
application application
HTTP msg
transport
Ht HTTP msg

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-11


3.2 Multiplexing and Demultiplexing
HTTP server
client
application application
HTTP msg
transport
Ht HTTP msg

Hnnetwork
Ht HTTP msg transport
transport
network link network
link physical link
physical physical

Transport Layer: 3-12


3.2 Multiplexing and Demultiplexing
HTTP server
client
application application

transport

transport network transport


network link network
link physical link
physical physical

Hn Ht HTTP msg

Transport Layer: 3-13


3.2 Multiplexing and Demultiplexing
HTTP server
client1 client2
application P-client1 P-client2 application

transport

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-14


3.2 Multiplexing and 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 (de-capsulate and deliver)

application

application P1 P2 application socket


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

Transport Layer: 3-15


3.2 Multiplexing and Demultiplexing
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
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-16


3.2 Multiplexing and Demultiplexing
Connectionless demultiplexing
Recall: when receiving host receives
 when creating socket, must UDP segment:
• checks destination port # in
specify host-local port #: segment
DatagramSocket mySocket1 • directs UDP segment to
= new DatagramSocket(12534);
socket with that port #
 when creating datagram to
send into UDP socket, 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-17
3.2 Multiplexing and Demultiplexing
Connectionless demultiplexing: an example
DatagramSocket
serverSocket = new
DatagramSocket
DatagramSocket mySocket2 = DatagramSocket mySocket1 =
new DatagramSocket (6428); new DatagramSocket (5775);
(9157); application
application application
P1
P3 P4
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: ?


Transport Layer: 3-18 dest port: 6428 dest port: ?
3.2 Multiplexing and Demultiplexing
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
• 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 Exception?
appropriate socket
Transport Layer: 3-19
3.2 Multiplexing and Demultiplexing
Connection-oriented demultiplexing: example
application
application P4 P5 P6 application
P1 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: physical
IP
address
B
host: IP source IP,port: B,80 host: IP
address dest IP,port: A,9157 source IP,port: C,5775 address
dest IP,port: B,80 C
A
source IP,port: A,9157
dest IP, port: B,80
source IP,port: C,9157
Three segments, all destined dest IP,port: B,80
to same IP address: B and same dest port: 80
Transport Layer: 3-20
are demultiplexed to different sockets
3.2 Multiplexing and Demultiplexing
Connection-oriented demultiplexing: example

Transport Layer: 3-21


3.2 Multiplexing and Demultiplexing
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
addresses, and port numbers
 Multiplexing/demultiplexing happen at all layers

Transport Layer: 3-22


Transport layer: roadmap
• Transport-layer services
• Multiplexing and demultiplexing
• Connectionless transport: UDP
• Principles of reliable data transfer
• Connection-oriented transport: TCP
• Principles of congestion control
• TCP congestion control
• Evolution of transport-layer functionality

Transport Layer: 3-25


3.3 Connectionless Transport: UDP
UDP: User Datagram Protocol
 “Basic,” “simple” Internet Why is there a UDP?
transport protocol  no connection establishment
 “best effort” service, UDP (which can add RTT delay)
segments may be:  simple: no connection state at
• lost sender, receiver
• delivered out-of-order to app  small header size
 no congestion control
 connectionless:  UDP can blast away as fast as
• no handshaking between UDP desired!
sender, receiver  can function in the face of
• each UDP segment handled congestion
independently of others
Transport Layer: 3-26
3.3 Connectionless Transport: UDP
UDP: User Datagram Protocol
 UDP use:
 streaming multimedia apps (loss tolerant, rate sensitive)
 DNS
 SNMP
 HTTP/3
 if reliable transfer needed over UDP (e.g., HTTP/3):
 add needed reliability at application layer
 add congestion control at application layer
 E.g., QUIC protocol (Quick UDP Internet Connection, [IETF QUIC 2020]),
used in Google’s Chrome browser.
Transport Layer: 3-27
3.3 Connectionless Transport: UDP
UDP: User Datagram Protocol

[RFC 768]

Transport Layer: 3-28


3.3 Connectionless Transport: UDP
UDP: User Datagram Protocol
• Each port number is a 16-bit number, ranging from 0 to 65535.
• The port numbers ranging from 0 to 1023 are called well-known port numbers
and are restricted (reserved) for use by well-known application protocols.

Transport Layer: 3-29


3.3 Connectionless Transport: UDP
UDP: Transport Layer Actions
SNMP client SNMP server

application application

transport transport
(UDP) (UDP)

network (IP) network (IP)

link link

physical physical

Transport Layer: 3-30


3.3 Connectionless Transport: UDP
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) header fields values (UDP)

network (IP)  creates UDP segment network (IP)

link  passes segment to IP link

physical physical

Transport Layer: 3-31


3.3 Connectionless Transport: UDP
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) (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-32


3.3 Connectionless Transport: UDP
3.3.1 UDP segment header
32 bits
source port # dest port #
length checksum

application length in bytes


data (header+data)
(payload)

data to/from
UDP segment format application layer

Transport Layer: 3-33


3.3 Connectionless Transport: UDP
3.3.2 UDP Checksum
 Goal: detect errors (i.e., flipped bits) in transmitted segment
1st number 2nd number sum

Transmitted: 5 6 11
Error detection is required
for ARQ to work, we present
here the basic principle of error
detection, showing the simple
operation used in UDP as an
example
Received: 4 6 = 11

receiver-computed sender-computed
checksum checksum (as received)
Adapted from © 1996-2021 J.F. Kurose,
Prof. Yahya Z. Mohasseb K.W. Ross All Rights Reserved.-34
3.3 Connectionless Transport: UDP
3.3.2 UDP Checksum
 Goal: detect errors (i.e., flipped bits) in transmitted segment
sender: receiver:
 treat contents of UDP segment  compute checksum of received
(including UDP header fields and IP
addresses) as sequence of 16-bit segment
integers  check if computed checksum
 checksum: addition (one’s equals checksum field value:
complement sum) of segment content • Not equal - error detected
 checksum value put into UDP • Equal - no error detected. But maybe
checksum field errors nonetheless? More later ….

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-35
3.3 Connectionless Transport: UDP
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
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 Even though
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!

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose,


K.W. Ross All Rights Reserved.-36
Summary: UDP
 “Basic” protocol:
• segments may be lost, delivered out of order
• best effort service: “send and hope for the best”
• Segmentation/process-to-process delivery/multiplexing-demultiplexing
 UDP has advantages:
• 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)
Transport layer: roadmap
• Transport-layer services
• Multiplexing and demultiplexing
• Connectionless transport: UDP
• Principles of reliable data transfer
• Connection-oriented transport: TCP
• Principles of congestion control
• TCP congestion control
• Evolution of transport-layer functionality

Transport Layer: 3-38


3.4 Principles of reliable data transfer

sending receiving
process process
application data data
transport
reliable channel

reliable service abstraction

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-39
3.4 Principles of reliable data transfer

sending receiving sending receiving


process process process process
application data data application data data
transport transport
reliable channel
sender-side of receiver-side
reliable service abstraction reliable data of reliable data
transfer protocol transfer protocol

Provided service transport


network
unreliable channel

reliable service implementation


Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All
Prof. Yahya Z. Mohasseb Rights Reserved.-40
3.4 Principles of reliable data transfer

sending receiving
process process
application data data
transport

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

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-42
3.4 Principles of reliable data transfer
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()

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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights
3.4 Principles of reliable data transfer
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!
 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-44


3.4 Principles of reliable data transfer
rdt1.0: reliable transfer over a reliable channel
 underlying channel perfectly reliable
• no bit errors
• no loss of packets
 separate FSMs for sender, receiver:
• sender sends data into underlying channel Wait for rdt_send(data)
• receiver reads data from underlying channel sender call from packet = make_pkt(data)
above udt_send(packet)
This transfer protocol does not
take channel errors into account
nor flow control is assumed. Wait for rdt_rcv(packet)
receiver call from extract (packet,data)
below deliver_data(data)

dashed indicates arrow initial state


Prof. Yahya Z. Mohasseb
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights Reserved.
3.4 Principles of reliable data transfer
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
• 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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose, K.W.
Ross All Rights Reserved.-46
3.4 Principles of reliable data transfer
rdt2.0: FSM specifications

rdt_send(data)
sndpkt = make_pkt(data, checksum) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
udt_send(sndpkt) udt_send(NAK)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
sender call from ACK or Wait for
receiver
udt_send(sndpkt)
above NAK call from
below

rdt_rcv(rcvpkt) && isACK(rcvpkt)


L rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights
Reserved.-47
3.4 Principles of reliable data transfer
rdt2.0: FSM specifications
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt) (“OK”) rdt_rcv(rcvpkt) && corrupt(rcvpkt)
sender call from ACK or udt_send(sndpkt) udt_send(NAK)
above NAK

rdt_rcv(rcvpkt) && isACK(rcvpkt) (“Please repeat that.”) Wait for


call from receiver
L below
ARQ (Automatic Repeat reQuest) protocols

Note: “state” of receiver (did the receiver get my rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
message correctly?) isn’t known to sender unless extract(rcvpkt,data)
deliver_data(data)
somehow communicated from receiver to sender udt_send(ACK)
 that’s why we need a protocol! Adapted from © 1996-2021 J.F. Kurose, K.W.
Prof. Yahya Z. Mohasseb Ross All Rights Reserved.-48
3.4 Principles of reliable data transfer
rdt2.0: operation with no errors
rdt_send(data)
sndpkt = 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)

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)
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-49
3.4 Principles of reliable data transfer
rdt2.0: operation with no errors
rdt_send(data)
sndpkt = 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)

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L
sender receiver
call from receiver
below
APP layer Transport Net layer Transport
State (Actions) State (Actions)
(event) (event)
Wait make_pkt(d) Wait Chksum: OK rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
for call
rdt_send() udt_send() for call
rdt_rcv() extract()
deliver_data()----to APP extract(rcvpkt,data)
Wait udt_send() --------to Sender deliver_data(data)
for ACK L udt_send(ACK)
Change State
Wait Adapted from © 1996-2021 J.F.
for call Prof. Yahya Z. Mohasseb Kurose, K.W. Ross All Rights
Reserved.-50
3.4 Principles of reliable data transfer
rdt2.0: corrupted packet scenario
rdt_send(data)
sndpkt = 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)

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L call from receiver
below

rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)


extract(rcvpkt,data)
deliver_data(data)
Adapted from © 1996-2021 J.F. Kurose,
udt_send(ACK)
Prof. Yahya Z. Mohasseb
K.W. Ross All Rights Reserved.-51
3.4 Principles of reliable data transfer
rdt2.0: corrupted packet scenario
rdt_send(data)
sndpkt = 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)

rdt_rcv(rcvpkt) && isACK(rcvpkt)


Wait for
L
State
APP layer Transport
State
Net layer Transport call from receiver
(event) (Actions) (event) (Actions) below
Wait make_pkt(d) Wait Chksum: BAD
for call
rdt_send() udt_send() for call
rdt_rcv() udt_send(NAK) --------to Sender
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
extract(rcvpkt,data)
udt_send()
deliver_data(data)
Adapted from © Change
1996-2021
State J.F. Kurose, Prof. Yahya Z. Mohasseb
K.W. Ross All Rights Reserved.-52 udt_send(ACK)
Wait
for ACK
3.4 Principles of reliable data transfer
rdt2.0 has a fatal flaw!
what happens if ACK/NAK handling duplicates:
corrupted?
 sender retransmits current pkt if
 sender doesn’t know what ACK/NAK corrupted
happened at receiver!
 sender adds sequence number to
 can’t just retransmit: possible
duplicate each pkt
 receiver discards (doesn’t deliver
up) duplicate pkt
stop and wait
sender sends one packet, then
waits for receiver response
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All
Prof. Yahya Z. Mohasseb
Rights Reserved.-53
3.4 Principles of reliable data transfer
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)
rdt_rcv(rcvpkt) above
&& notcorrupt(rcvpkt) && rdt_rcv(rcvpkt)
isACK(rcvpkt) && notcorrupt(rcvpkt)
L && isACK(rcvpkt)
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)
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb
All Rights Reserved.-54
3.4 Principles of reliable data transfer
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) 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)
Adapted from © 1996-2021 J.F.
Prof. Yahya Z. Mohasseb Kurose, K.W. Ross All Rights
Reserved.-55
3.4 Principles of reliable data transfer
rdt2.1: discussion
sender: receiver:
 seq # added to pkt  must check if received packet is
 two seq. #s (0,1) will suffice. Why? duplicate
• state indicates whether 0 or 1 is
 must check if received ACK/NAK expected pkt seq #
corrupted
 note: receiver can not know if its
 twice as many states last ACK/NAK received OK at
• state must “remember” whether sender
“expected” pkt should have seq # of 0
or 1

Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights


Prof. Yahya Z. Mohasseb
Reserved.-56
RDT 2.1 Rdt 2.1
sender receiver
pkt0
• Scenario:
rcv pkt0: OK
• 1st Packet: Received OK
ack0

ack0
• 1st ACK: Corrupted corrupt pkt0
Repeated, discard
• Retransmit: OK ack0 send ack0
rcv ack0
• ACK: Ok pkt1
send pkt1
• Second Packet: Corrupt NAK1
Pkt1: Corrupt
send NAK1
• NAK: OK
pkt1
• 2nd Retransmit: OK ack1 rcv pkt1
send ack1
• ACK: OK rcv ack1

send pkt0 pkt0


3-57 Transport Layer
3.4 Principles of reliable data transfer
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
 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-58


3.4 Principles of reliable data transfer
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 rdt_rcv(rcvpkt)
rdt_rcv(rcvpkt) && && notcorrupt(rcvpkt)
(corrupt(rcvpkt) || && isACK(rcvpkt,0)
has_seq1(rcvpkt)) Wait for receiver FSM L
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)
Transport Layer: 3-59 udt_send(sndpkt)
Rdt 2.2
RDT 2.2
sender receiver
• Same Scenario: pkt0
rcv pkt0: OK
• 1st Packet: Received OK ack0

• 1st ACK: Corrupted ack0


corrupt pkt0
• Retransmit: OK
• ACK: Ok rcv ack0
ack0

• Second Packet: Corrupt pkt1


• Repeated ack0: OK send pkt1
Pkt1: Corrupt
• 2nd Retransmit: OK ack0 Repeat ack0
• ACK: OK pkt1
ack1 rcv pkt1
send ack1
rcv ack1
pkt0
3-60 Transport Layer
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
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): timeout
• retransmission will be duplicate, but seq #s already handles this!
• receiver must specify seq # of packet being ACKed
• use countdown timer to interrupt after “reasonable” amount of time
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb All Rights Reserved.-61
3.4 Principles of reliable data transfer
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)
&& 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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-62
3.4 Principles of reliable data transfer
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)
&& 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 Adapted from © 1996-2021 J.F.
Prof. Yahya Z. Mohasseb Kurose, K.W. Ross All Rights
Reserved.-63
3.4 Principles of reliable data transfer
rdt3.0 receiver
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
&& has_seq0(rcvpkt)
Extract(rcvpkt,data)
deliver_data(data) rdt_rcv(rcvpkt)
rdt_rcv(rcvpkt) udt_send(ACK[0]) && corrupt(rcvpkt)
&& corrupt(rcvpkt)
udt_send(ACK[1]) udt_send(ACK[0])

Wait for 0 Wait for 1


rdt_rcv(rcvpkt) rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt) && has_seq0(rcvpkt)
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt) udt_send(ACK[0])
udt_send(ACK[1])
&& has_seq1(rcvpkt)
Extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK[1])

#64 Reliable Data Transfer


3.4 Principles of reliable data transfer
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
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

Transport Layer: 3-65


(b) packet loss
3.4 Principles of reliable data transfer
rdt3.0 in action
sender receiver sender receiver
send pkt0 pkt0 send pkt0
pkt0
rcv pkt0 rcv pkt0
ack0 send ack0 send ack0
ack0
rcv ack0 rcv ack0
send pkt1 pkt1 send pkt1 pkt1
rcv pkt1 rcv pkt1
ack1 send ack1 send ack1
X
loss ack1
timeout timeout
resend pkt1 pkt1 resend pkt1
rcv pkt1 pkt1 rcv pkt1
(detect duplicate) rcv ack1 (detect duplicate)
ack1 send ack1 send ack1
rcv ack1 send pkt0 pkt0
send pkt0 pkt0 ack1 rcv pkt0
rcv pkt0 rcv ack1 send ack0
ack0 send ack0 (ignore) ack0

pkt1
(c) ACK loss
Transport Layer: 3-66 (d) premature timeout/ delayed ACK
3.4 Principles of reliable data transfer
rdt3.0 in action sender Rdt 3.0
pkt0
receiver

• Same Scenario: ack0: lost


rcv pkt0: OK

• Packet 0: Received OK
• ACK0: LOST timeout
• Retransmit: after timeout
resend pkt0 pkt0
duplicate pkt0,
• ACK: Ok ack0 discarded
• Packet 1: LOST rcv ack0 pkt1: lost
• Retransmit: OK send pkt1
• ACK1: OK

timeout
resend pkt1 pkt1

rcv ack1 rcv pkt1


ack1 send ack1
3-67
Key elements of a reliable transfer protocol:
• Checksums
• Sequence numbers
• Timers
• Acknowledgments
• Send/Receive buffers (window)

68  Prof. Yahya Z. Mohasseb


3.4 Principles of reliable data transfer
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:
L 8000 bits
Dtrans = R = 9 = 8 microsecs
10 bits/sec

Transport Layer: 3-69


3.4 Principles of reliable data transfer
Performance of rdt3.0 (stop-and-wait)
• rdt3.0 works, but performance is very bad!
• Example: 1 Gbps link, 15 ms prop. delay, 8000 bit packet:
1KB = 8000 bit
L 8000bits
d trans   9
 8 microseconds
R 10 bps
 U sender: utilization – fraction of time sender busy sending

U L/R .008
sender
= = = 0.00027
RTT + L / R 30.008 microsec
onds
 if RTT=30 msec, 1KB pkt every 30 msec -> 33kB/sec thruput over 1 Gbps link
 network protocol limits use of physical resources!

3-70 Transport Layer


3.4 Principles of reliable data transfer
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

ACK arrives, send next


packet, t = RTT + L / R

Transport Layer: 3-71


3.4 Principles of reliable data transfer
rdt3.0: stop-and-wait operation
sender receiver
L/R
Usender= L/R
RTT + L / R
.008
= RTT
30.008
= 0.00027

 rdt 3.0 protocol performance is very bad!


 Protocol limits performance of underlying infrastructure (channel)

Transport Layer: 3-72


3.4 Principles of reliable data transfer
rdt3.0: pipelined protocols operation
pipelining: sender allows multiple, “in-flight” (if available), yet-to-be-
acknowledged packets later
• range of sequence numbers must be increased
• buffering at sender and/or receiver

Transport Layer: 3-73


3.4 Principles of reliable data transfer
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
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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-74
3.4 Principles of reliable data transfer
Go-Back-N (GBN): sender
 sender: “window” of up to N, consecutive transmitted but unACKed pkts
• k-bit seq # in pkt header

 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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose, K.W.
Ross All Rights Reserved.-75
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:
• 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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-77
GBN: receiver extended FSM

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


in-order seq #
• may generate duplicate ACKs
• need only remember expectedseqnum
• out-of-order pkt:
• discard (don’t buffer) -> no receiver buffering!
• Re-ACK pkt with highest in-order seq #
default
udt_send(sndpkt) rdt_rcv(rcvpkt)
&& notcurrupt(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)
expectedseqnum++
3-78 Transport Layer
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,
012345678 rcv ack0, send pkt4 (re)send ack1
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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-79
Selective repeat (SR)
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
• sender maintains timer for each unACKed pkt
sender window
• N consecutive seq #s
• limits seq #s of sent, unACKed packets

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-80
Selective repeat: sender, receiver windows

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-81
3.4.4 Selective Repeat: Sender &
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
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
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-82
3.4.4 Selective Repeat (SR): Sender
sender
data from above:
 if next available seq # in
window, send packet
timeout(n):
 resend packet n, restart timer
ACK(n) in [sendbase,sendbase+N]:
 mark packet n as received
 if n smallest unACKed packet,
advance window base to next
unACKed seq #
83 Prof. Yahya Z. Mohasseb
3.4.4 Selective Repeat (SR): Sender
receiver
packet n in [rcvbase, rcvbase+N-1]
 send ACK(n)
 out-of-order: buffer
 in-order: deliver (also deliver
buffered, in-order packets),
advance window to next not-yet-
received packet
packet n in [rcvbase-N, rcvbase-1]
 ACK(n) (reacknowledgment)
otherwise:
 ignore
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-84
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,
012345678 rcv ack0, send pkt4 send ack3
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

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose,


Q: what happens when ack2 arrives? K.W. Ross All Rights Reserved.-85
Selective repeat:
a dilemma! Receiver can’t “see” sender’s actions; only the
sequence of messages received from the channel.
example: seq #s: 0, 1, 2, 3 The 2 scenarios are identical for the receiver!
A window = Max message sequence -1 not working.
(base 4 counting) & window size=3 Window must be less ≤ ½ Max message sequence
sender window receiver window number.
(after receipt) (after receipt)
0123012 pkt0
0123012 pkt0 0123012 pkt1 0123012
0123012 pkt1 0123012 0123012 pkt2 X 0123012
0123012 pkt2 0123012 X 0123012
0123012 X
0123012 pkt3 timeout
X retransmit pkt0
0123012 0123012 pkt0
pkt0 will accept packet will accept packet
(a) Scenario (a) with seq number 0 (b) Scenario (b) with seq number 0

ACKs for the first 3 packets delivered correctly. ACKs for the first 3 packets are lost and the
The sender moves forward & sends the 4th , 5th sender retransmits these packets. The receiver
and 6th packets, # 3, 0, and 1, respectively. thus next receives a packet with sequence number
Packet 3 is lost, but Packet number 0 arrives—a 0—a copy of the first packet sent.
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
packet containing new data. Kurose, K.W. Ross All Rights
Reserved.-86
Selective repeat: sender window
(after receipt)
receiver window
(after receipt)

a dilemma! 0123012
0123012
pkt0
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
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!
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-87
Transport Layer 3-96
Transport Layer 3-97
Transport Layer 3-98
Transport Layer 3-99
Transport Layer 3-100
Transport Layer 3-103
ignore

Transport Layer 3-104


Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
• segment structure
• reliable data transfer
• flow control
• connection management
 Principles of congestion control
 TCP congestion control
Transport Layer: 3-105
3.5 Connection-Oriented Transport: TCP
TCP: overview RFCs: 793,1122, 2018, 5681, 7323
 point-to-point: (no multicasting)  cumulative ACKs
• one sender, one receiver  pipelining:
 reliable, in-order byte stream: • TCP congestion and flow control
• no “message boundaries" set window size
 full duplex data:  connection-oriented:
• bi-directional data flow in same • handshaking (exchange of control
connection messages) initializes sender,
• MSS: maximum segment size receiver state before data exchange
1460=1500 (Ethernet/PPP)- 40(TCP/IP  flow controlled:
header) • sender will not overwhelm receiver
Adapted from © 1996-2021 J.F. Kurose, K.W.
Prof. Yahya Z. Mohasseb Ross All Rights Reserved.-106
3.5 Connection-Oriented Transport: TCP
TCP: overview RFCs: 793,1122, 2018, 5681, 7323

Adapted from © 1996-2021 J.F. Kurose, K.W.


Prof. Yahya Z. Mohasseb Ross All Rights Reserved.-107
3.5 Connection-Oriented Transport: TCP
3.5.2 TCP Segment Structure
32 bits

source port # dest port # number of the first byte


ACK: seq # of next expected sequence number in the segment
byte; A bit: this is an ACK (byte-stream not segments!)
acknowledgement number
head not
4-bit length (of TCP header) len used C EUAP R SF receive window flow control: # bytes
Internet checksum checksum Urg data pointer receiver willing to accept

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
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
All Rights Reserved.-108
3.5 Connection-Oriented Transport: TCP
3.5.2 TCP Segment Structure outgoing segment from sender
source port # dest port #

TCP sequence numbers, ACKs sequence number


acknowledgement number
rwnd
Sequence numbers: checksum urg pointer
window size
• byte stream “number” of N

first byte in segment’s data


Acknowledgements: sender sequence number space

• seq # of next byte expected sent sent, not- usable not


from other side ACKed yet ACKed but not usable
(“in-flight”) yet sent
• cumulative ACK
outgoing segment from receiver
Q: how receiver handles out-of-order segments source port # dest port #

• A: TCP spec doesn’t say, - up to implementor sequence number


acknowledgement number
A rwnd
checksum urg pointer
Prof. Yahya Z. Mohasseb
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights Reserved.-109
3.5 Connection-Oriented Transport: TCP
3.5.2 TCP Segment Structure
TCP sequence numbers, ACKs (TELNET Example, 1-Byte Data)
Host A Host B

User types‘C’
Seq=42, ACK=79, data = ‘C’
host ACKs receipt
of‘C’, echoes back ‘C’
Seq=79, ACK=43, data = ‘C’
host ACKs receipt
of echoed ‘C’
Seq=43, ACK=80 Piggybacking!

simple telnet scenario Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-110
3.5 Connection-Oriented Transport: TCP
3.5.3 Round-Trip Time Estimation and Timeout

Q: how to estimate RTT? Q: how to set TCP timeout


 SampleRTT:measured time from value?
segment transmission until ACK
receipt  longer than RTT, but RTT varies!
• ignore retransmissions  too short: premature timeout,
 SampleRTT will vary, want unnecessary retransmissions
estimated RTT “smoother”  too long: slow reaction to segment
• average several recent measurements, loss
not just current SampleRTT
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb All Rights Reserved.-111
3.5 Connection-Oriented Transport: TCP
3.5.3 Round-Trip Time Estimation and Timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

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

RTT (milliseconds)
300

250

RTT (milliseconds)
 exponential weighted moving 200

average (EWMA) sampleRTT


 influence of past sample decreases
150

EstimatedRTT
exponentially fast
 typical value:  = 0.125
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
time (seconds)
SampleRTT Estimated RTT
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb
All Rights Reserved.-112
3.5 Connection-Oriented Transport: TCP
3.5.3 Round-Trip Time Estimation and Timeout
 timeout interval: EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT: want a larger safety margin
TimeoutInterval = EstimatedRTT + 4*DevRTT

estimated RTT “safety margin”

 DevRTT: EWMA of SampleRTT deviation from EstimatedRTT:


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

Prof. Yahya
* Check out the online interactive exercises for more examples: Z. Mohasseb
http://gaia.cs.umass.edu/kurose_ross/interactive/ Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-113
3.5 Connection-Oriented Transport: TCP
3.5.3 Round-Trip Time Estimation and Timeout
event: data received from application event: timeout
 create segment with seq #  retransmit segment that caused
 seq # is byte-stream number of first timeout
data byte in segment  restart timer
 start timer if not already running event: ACK received
• think of timer as for oldest unACKed  if ACK acknowledges
segment previously unACKed segments
• expiration interval: • update what is known to be
TimeOutInterval ACKed
• start timer if there are still
unACKed segments
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-114
3.5 Connection-Oriented Transport: TCP
3.5.4 Reliable Data Transfer
TCP: retransmission scenarios Host A Host B
premature timeout
Host A Host B
SendBase=92
Seq=92, 8 bytes of data
lost ACK scenario
Seq=100, 20 bytes of data

timeout
Seq=92, 8 bytes of data
ACK=100
timeout

ACK=100 ACK=120
X
Seq=92, 8
SendBase=100 bytes of data send cumulative
SendBase=120 ACK for 120
Seq=92, 8 bytes of data
ACK=120

SendBase=120
ACK=100
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-115
3.5 Connection-Oriented Transport: TCP
3.5.4 Reliable Data Transferm
TCP: retransmission scenarios
Host A Host B

cumulative ACK
covers for earlier lost
ACK
Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


ACK=100
X
ACK=120

Seq=120, 15 bytes of data

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-116
3.5 Connection-Oriented Transport: TCP
3.5.4 Reliable Data Transferm (implicit NAK mechanism)
Host B
TCP fast retransmit Host A

if sender receives 3 additional


ACKs for same data (“triple
duplicate ACKs”), resend unACKed X
segment with smallest seq #
(oldest unAcked)
 likely that unACKed segment lost,

timeout
so don’t wait for 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!
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb
All Rights Reserved.-117
Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
• segment structure
• reliable data transfer
• flow control
• connection management
 Principles of congestion control
 TCP congestion control
Transport Layer: 3-118
3.5 Connection-Oriented Transport: TCP
3.5.5 TCP Flow Control application

• Q: What happens if network layer Application removing


process
data from TCP socket
delivers data faster than application buffers
layer removes data from socket TCP socket
receiver buffers
buffers?
TCP
code
Network layer
delivering IP datagram
receive window
flow control: # bytes payload into TCP
IP
receiver willing to accept socket buffers
code

from sender

receiver protocol stack


Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-119
3.5 Connection-Oriented Transport: TCP
3.5.5 TCP Flow Control application

• Q: What happens if network layer Application removing


process
data from TCP socket
delivers data faster than application buffers
layer removes data from socket TCP socket
receiver buffers
buffers?
TCP
code
flow control Network layer
receiver controls sender, so delivering IP datagram
payload into TCP
sender won’t overflow socket buffers IP
code
receiver’s buffer by
transmitting too much, too fast
from sender

receiver protocol stack


Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-120
3.5 Connection-Oriented Transport: TCP
3.5.5 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

• many operating systems autoadjust rwnd free buffer space


RcvBuffer
 sender limits amount of unACKed
TCP segment payloads
(“in-flight”) data to received rwnd
 guarantees receive buffer will not TCP receiver-side buffering
overflow
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb All Rights Reserved.-121
3.5 Connection-Oriented Transport: TCP
3.5.5 TCP Flow Control
 TCP receiver “advertises” free buffer flow control: # bytes receiver willing to accept

space in rwnd field in TCP header


• RcvBuffer size set via socket
options (typical default is 4096 bytes)
receive window
• many operating systems autoadjust
RcvBuffer
 sender limits amount of unACKed
(“in-flight”) data to received rwnd
 guarantees receive buffer will not
overflow
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All
Rights Reserved.-122
Prof. Yahya Z. Mohasseb
TCP segment format
3.5 Connection-Oriented Transport: TCP
3.5.6 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

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();
Prof. Yahya Z. Mohasseb
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management
Agreeing to establish a connection

Q: will 2-way handshake always


2-way handshake: work in network?
 variable delays
 retransmitted messages (e.g.
choose x
req_conn(x) req_conn(x)) due to message loss
acc_conn(x)
ESTAB  message reordering
ESTAB
 can’t “see” other side

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-124
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management
2-way handshake scenarios

choose x
req_conn(x)
ESTAB
acc_conn(x)

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

No problem!
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-125
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management
2-way handshake scenarios
choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)

ESTAB
req_conn(x)

connection
client x completes server
terminates forgets x

Problem: half open ESTAB


connection! (no client) acc_conn(x)
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All
Rights Reserved.-126
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management
2-way handshake scenarios choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)

ESTAB
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
127 Prof. Yahya Z. Mohasseb
accepted!
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-128
3.5 Connection-Oriented Transport: TCP
3.5.6 TCP Connection Management
Closing a TCP connection

 client, server each close 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
 simultaneous FIN exchanges can be handled

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-129
24.3.4 A TCP Connection (full-duplex)
1- Connection Establishment: TCP transmits data in mode.

Do not carry data


consumes one sequence number
(i.e., imaginary byte)

if carrying no data,
consumes no sequence number
Figure 24.10 Three-way handshaking 23.130
24.3.4 A TCP Connection (full-duplex)
1- Connection Establishment: TCP transmits data in mode.
SYN Flooding Attack (A denial of service attack)

 Attackers send a large number of SYN segments from a different clients (faking the source
IP addresses).
 The server runs out of resources and becomes unable to accept connection requests

To alleviate the effect of the attack,


 Impose a limit of connection requests during a specified period of time.
 Filter out datagrams from unwanted source addresses.
 SCTP postpones resource allocation until the server can verify the connection request is
coming from a valid IP address, by using a cookie.

23.131
24.3.4 A TCP Connection (full-duplex)
2- Data Transfer

Pushing Data
(from receiving TCP)

Urgent Data
(at receiving application)
Figure 24.11 Data transfer 23.132
24.3.4 A TCP Connection (full-duplex)
3-Connection Termination: A-Three-way handshaking

One sequence number


if it does not carry data

No sequence number
Does not carry data

Figure 24.12 Three-way handshaking


23.133
Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
 Principles of congestion control
 TCP congestion control
 Evolution of transport-layer
functionality
Transport Layer: 3-134
3.6 Principles of Congestion Control
Congestion:
 informally: “too many sources sending too much data too fast for network to
handle”
 Manifestations:
• long delays (queueing in router buffers)
• packet loss (buffer overflow at routers)
 different from flow control!
flow control: one sender too fast for one receiver
congestion control: too many senders, sending too fast
Adapted from © 1996-2021 J.F. Kurose, K.W. Ross Prof. Yahya Z. Mohasseb
All Rights Reserved.-135
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion:
scenario 1
Simplest scenario: original data: lin throughput: lout
 one router, infinite buffers Host A
 input, output link capacity: R infinite shared
 two flows output link buffers

 no retransmissions needed R R

Host B
R/2
Q: What happens as
lout

arrival rate lin

delay
throughput:

approaches R/2?
lin R/2 lin R/2
maximum per-connection large delays as arrival rate lin
Transport Layer: 3-136 throughput: R/2 approaches capacity
3.6 Principles of Congestion Control
3.6.1 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

lin : original data


lout
Host A l'in: original data, plus
retransmitted data

R R

Host B finite shared output Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
link buffers All Rights Reserved.-137
Prof. Yahya Z. Mohasseb
3.6 Principles of Congestion Control
3.6.1 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

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 Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
Prof. Yahya Z. Mohasseb All Rights Reserved.-138
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion: scenario 2

Idealization: perfect knowledge


R/2
 sender sends only when router buffers available

throughput: lout
Host A lin : original data
lout
copy l'in: original data, plus
retransmitted data
lin R/2
free buffer space!

R R

Host B finite shared output


link buffers Adapted from © 1996-2021 J.F.
Prof. Yahya Z. Mohasseb
Kurose, K.W. Ross All Rights
Reserved.-139
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion: scenario 2
Idealization: some perfect knowledge
R/2 “wasted” capacity
 packets can be lost (dropped at router) due to due to

throughput: lout
full buffers retransmissions

 sender knows when packet has been dropped: when sending at


only resends if packet known to be lost R/2, some packets
are needed
Host A lin : original data retransmissions
l'in: original data, plus
retransmitted data lin R/2

free buffer space!

R R

Host B finite shared output


link buffers Adapted from © 1996-2021 J.F. Kurose,
Prof. Yahya Z. Mohasseb
K.W. Ross All Rights Reserved.-140
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion: scenario 2
Realistic scenario: un-needed duplicates R/2

 packets can be lost, dropped at router due to full “wasted” capacity


buffers – requiring retransmissions

throughput: lout
due to un-needed
retransmissions
 but sender can time out prematurely, sending two
copies, both of which are delivered when sending at
R/2, some packets
are
Host A lin : original data retransmissions,
timeout
copy l'in: original data, plus (needed & un-
retransmitted data needed duplicates).
lin
R/2

free buffer space!

R R “costs” of congestion?

Host B finite shared output


link buffers
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion: scenario 2
Realistic scenario: un-needed duplicates R/2

 packets can be lost, dropped at router due to full “wasted” capacity


buffers – requiring retransmissions

throughput: lout
due to un-needed
retransmissions
 but sender can time out prematurely, sending two
copies, both of which are delivered when sending at
R/2, some packets
are
“costs”
Host A
of congestion:
lin : original data retransmissions,
 moretimeout
work
copy (retransmission)
l'in: originalfor given
data, plus receiver (needed & un-
needed duplicates).
throughput retransmitted data
lin
R/2
 unneeded retransmissions: link carries multiple
copies of a packet free buffer space!
• decreasing maximum achievable throughput
R R

Host B finite shared output


link buffers
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion:
scenario 3
Q: what happens as lin and lin’ increase ?
 four senders
 multi-hop paths A: as red lin’ increases, all arriving blue pkts at upper
queue are dropped, blue throughput g 0
 timeout/retransmit
Host A lin : original data
Host B
l'in: original data, plus
retransmitted data
finite shared
output link buffers

Host D
lout
Host C

Prof. Yahya Z. Mohasseb


Adapted from © 1996-2021 J.F. Kurose,
K.W. Ross All Rights Reserved.-143
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion:
scenario 3
R/2
lout

lin’ R/2

Another “cost” of congestion:


 When packet dropped, any upstream transmission capacity
and buffering used for that packet was wasted!

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-144
3.6 Principles of Congestion Control
3.6.1 Causes/costs of congestion: Summary R/2

throughput: lout
throughput can never exceed capacity
delay

delay increases as capacity approached lin R/2


R/2
lin R/2

lout
loss/retransmission decreases effective throughput

throughput:
R/2
throughput: lout

un-needed duplicates further R/2 lin


decreases effective throughput R/2

upstream transmission capacity/buffering

lout
wasted for packets lost downstream
lin R/2
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F. Kurose, K.W. Ross
All Rights Reserved.-145 lin’ R/2
3.6 Principles of Congestion Control
3.6.2 Approaches to Congestion Control
1. End-end congestion control:
• no explicit feedback from network
• congestion inferred from observed
loss, delay

approach taken by TCP ACKs


data data
ACKs

Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-146
3.6 Principles of Congestion Control
3.6.2 Approaches to Congestion Control
2. Network-assisted congestion
control:
 routers provide direct feedback to explicit congestion info

sending/receiving hosts with flows


passing through congested router data data
ACKs
ACKs
 may indicate congestion level or
explicitly set sending rate

Approach in TCP ECN, ATM, DECbit protocols

Adapted from © 1996-2021 J.F. Kurose, K.W. Ross All Rights


Reserved.-147
Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
 Principles of congestion control
 TCP congestion control
 Evolution of transport-layer
functionality
Transport Layer: 3-148
3.7 TCP Congestion Control
3.7.1 Classic 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 every each loss event
RTT until loss detected
TCP sender Sending rate

AIMD sawtooth
behavior: probing
for bandwidth
Adapted from © 1996-2021 J.F. Kurose, K.W.
time Ross All Rights Reserved.-149
3.7 TCP Congestion Control
3.7.1 Classic TCP Congestion Control: AIMD
Multiplicative decrease detail: 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)
Why AIMD?
 AIMD – a distributed, asynchronous algorithm – has been
shown to:
• optimize congested flow rates network wide!
• have desirable stability properties

Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.


Kurose, K.W. Ross All Rights
Reserved.-150
3.7 TCP Congestion Control
3.7.1 Classic 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
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)
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-151
3.7 TCP Congestion Control
3.7.1 Classic TCP Congestion Control: Slow
Start
 when connection begins, Host A Host B

increase rate exponentially


until first loss event:

RTT
• initially cwnd = 1 MSS
• double cwnd every RTT
• done by incrementing cwnd for
every ACK received
 summary: initial rate is
slow, but ramps up
exponentially fast time
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-152
3.7 TCP Congestion Control
3.7.1 Classic TCP Congestion Control:
Slow Start/congestion avoidance
Q: when should the exponential
increase switch to linear? X
A: when cwnd gets to 1/2 of its value
before timeout.

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/
Prof. Yahya Z. Mohasseb Adapted from © 1996-2021 J.F.
Kurose, K.W. Ross All Rights
Reserved.-153
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
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
Prof. Yahya Z. Mohasseb cwnd = cwnd + MSS Adapted from © 1996-2021 J.F.
transmit new segment(s), as allowed Kurose, K.W. Ross All Rights
Reserved.-154
24.3.9 TCP Congestion Control
1-Congestion Window

Actual send window size = minimum (rwnd, cwnd)

cwnd is related to the congestion in the middle (network).


rwnd is related to the congestion at the end (for flow control).

23.155
24.3.9 TCP Congestion Control
2-Congestion Detection

 Time-out: A sign of a severe congestion


 Three duplicate ACKs (four ACKs with the same acknowledgment number):
The network is either slightly congested or has recovered from the congestion.
o Duplicate ACK is a sign that a segment has been delayed.
o Three duplicate ACKs means one segment is missing, but three segments
have been received.

23.156
24.3.9 TCP Congestion Control
3-Congestion Policies: based on three algorithms
A. Slow Start (SS): Exponential Increase until it reaches a threshold (ssthresh)

If an ACK arrives,
cwnd = cwnd + 1

Figure 24.29 Slow start 23.157


24.3.9 TCP Congestion Control
3-Congestion Policies: based on three algorithms
A. Slow Start: Exponential Increase until it reaches a threshold (ssthresh)

The growth rate


- Exponential in terms of each round trip time (a very aggressive approach):

If an ACK arrives,
cwnd = cwnd + 1

- Slower in the case of delayed acknowledgments.

23.158
24.3.9 TCP Congestion Control
3-Congestion Policies: based on three algorithms
B. Congestion Avoidance: (CA)
slow down to a linear increase (Additive) until congestion is detected.

If an ACK arrives,
cwnd = cwnd + (1/cwnd)

Figure 24.30 Congestion avoidance, additive increase 23.159


24.3.9 TCP Congestion Control
3-Congestion Policies: based on three algorithms
C. Fast Recovery (optional)
Starts when three duplicate ACKs arrive.

when a duplicate ACK arrives,


cwnd = cwnd + (1/cwnd)

23.160
24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
A. Taho TCP

Figure 24.31 FSM for Taho TCP


23.161
24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
A. Taho TCP

Figure 24.32 Example 23.162


24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
B. Reno TCP (most common today)
- uses fast-recovery
- treats the two signals of congestion differently

Figure 24.33 FSM for Reno TCP 23.163


24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
B. Reno TCP (most common today)

Figure 24.34 Example 23.164


24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
B. Reno TCP (most common today)
Additive Increase, Multiplicative Decrease (AIMD)
 Most of the time the congestion is detected by observing the three
duplicate ACKs.
 If we ignore the slow-start states and short exponential growth
during fast recovery.
o when an ACK arrives: cwnd = cwnd + (1 / cwnd) (additive
increase)
o when 3 dupACKs: cwnd = cwnd / 2 (multiplicative decrease)

Figure 24.35 Saw tooth pattern (AIMD) 23.165


24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
B. Reno TCP (most common today)
TCP Throughput: If each tooth were exactly the same: Throughput = [(maximum + minimum)/2]/RTT

However, the maximum is twice the value of the minimum (cwnd is set to half of its previous value)
Throughput=(0.75) Wmax /RTT
in which Wmax is the average of window sizes when the congestion occurs.

Figure 24.35 Saw tooth pattern (AIMD) 23.166


24.3.9 TCP Congestion Control
4-Policy Transition: three versions of TCP: Taho TCP, Reno TCP, and Ne
B. Reno TCP (most common today)
TCP Throughput: If each tooth were exactly the same: Throughput = [(maximum + minimum)/2]/RTT

However, the maximum is twice the value of the minimum (cwnd is set to half of its previous value)
Throughput=(0.75) Wmax /RTT
in which Wmax is the average of window sizes when the congestion occurs.

Example 24.11
If MSS = 10 KB (kilobytes) and RTT = 100 ms in Figure 24.35, we can calculate the throughput as:

Wmax = (10 + 12 + 10 + 8 + 8) / 5 = 9.6 MSS

Throughput = (0.75 Wmax / RTT) = 0.75 × 960 kbps / 100 ms = 7.2 Mbps

23.167
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
approach Wmax more slowly

Wmax classic TCP

TCP CUBIC - higher


Wmax/2 throughput in this
example

Transport Layer: 3-168


TCP CUBIC
 K: point in time when TCP window size will reach Wmax
• K itself is tuneable
 increase W as a function of the cube of the distance between current
time and K
• larger increases when further away from K
• smaller increases (cautious) when nearer K

 TCP CUBIC default Wmax

in Linux, most TCP Reno


TCP CUBIC
popular TCP for TCP
sending
popular Web rate

servers time
t0 t1 t2 t3 t4
Transport Layer: 3-169
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

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-170
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

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-171
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 =
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-172
Delay-based TCP congestion control
 congestion control without inducing/forcing loss
 maximizing throughout (“keeping the just pipe full… ”) while keeping
delay low (“…but not fuller”)
 a number of deployed TCPs take a delay-based approach
 BBR deployed on Google’s (internal) backbone network

Transport Layer: 3-173


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
 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-174
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

bottleneck
TCP connection 2 router
capacity R

Transport Layer: 3-175


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


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-176
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:
• 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/2
control

Transport Layer: 3-177


Transport layer: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
 Principles of congestion control
 TCP congestion control
 Evolution of transport-layer
functionality
Transport Layer: 3-178
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
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-179
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)

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-180


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
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-181
QUIC: Connection establishment

TCP handshake
(transport layer) QUIC handshake

data
TLS handshake
(security)
data

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


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

Transport Layer: 3-182


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
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-183
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”
• congestion control
 two network-layer
 instantiation, implementation chapters:
in the Internet • data plane
• UDP • control plane
• TCP

Transport Layer: 3-184


Additional Chapter 3 slides

Transport Layer: 3-185


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)
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-186
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)
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-187
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
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-188
TCP 3-way handshake FSM
closed
Socket connectionSocket =
welcomeSocket.accept();
L Socket clientSocket =
newSocket("hostname","port number");
SYN(x)
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-189


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
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-190


TCP throughput
 avg. TCP thruput 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. thruput is 3/4W per RTT
3 W
avg TCP thruput = 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
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-192

You might also like