Chapter 3 v8.2
Chapter 3 v8.2
Transport Layer
Computer Networking: A
Top-Down Approach
8th edition
Jim Kurose, Keith Ross
Pearson, 2020
All material copyright 1996-2023
J.F Kurose and K.W. Ross, All Rights Reserved
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
demultiplexing transport
• reliable data transfer • TCP congestion control
• flow control
• congestion control
lo g
i ca
l en
§ transport protocols actions in end
d- e
systems:
nd
local or
tra
• sender: breaks application messages regional ISP
n sp
into segments, passes to network layer
o rt
home network content
• receiver: reassembles segments into provider
network
messages, passes to application layer application
transport
datacenter
network
network
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)
physical physical
Receiver:
application § receives segment from IP application
§ checks header values
app. msg
transport § extracts application-layer transport
message
network (IP) network (IP)
§ demultiplexes message up
link to application via socket link
physical physical
Th app. msg
congestion control
lo g
•
i ca
• flow control
l en
d- e
• connection setup
nd
local or
§ UDP: User Datagram Protocol
tra
regional ISP
n sp
• unreliable, unordered delivery
o rt
home network content
provider
• no-frills extension of “best-effort” IP network
application
datacenter
network
§ services not available: transport
network
data link
application
Hnnetwork
Ht HTTP msg transport
transport
Hn Hnetwork
t HTTP msg
link network
link physical link
physical physical
Hn Ht HTTP msg
client
application application
HTTP msg
HTTP msg transport
Ht HTTP msg
de-multiplexing
application
? transport
de-multiplexing
Demultiplexing
multiplexing
application
transport
multiplexing
Multiplexing
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
B D
source port: 6428 source port: ?
dest port: 9157 dest port: ?
A C
source port: 9157 source port: ?
dest port: 6428 dest port: ?
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
appropriate socket
Transport Layer: 3-23
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: IP physical
address B
application application
transport transport
(UDP) (UDP)
link link
physical physical
physical physical
data to/from
UDP segment format application layer
Transmitted: 5 6 11
Received: 4 6 11
receiver-computed
checksum
= sender-computed
checksum (as received)
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-36
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!
sending receiving
process process
application data data
transport
reliable channel
transport
network
unreliable channel
sending receiving
process process
application data data
transport
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
sending receiving
process process
application data data
transport
sender-side of receiver-side
Sender, receiver do not know reliable data
transfer protocol
of reliable data
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
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-44
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
2
event actions
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt_send(data)
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
start_timer
L/R L/R
Usender=
RTT + L / R
.008 RTT
=
30.008
= 0.00027
!
Transport Layer: 3-69
Go-Back-N: sender
§ sender: “window” of up to N, consecutive transmitted but unACKed pkts
• k-bit seq # in pkt header
rcv_base
Not received
Transport Layer: 3-71
Go-Back-N in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
send pkt2 receive pkt0, send ack0
012345678
send pkt3 Xloss receive pkt1, send ack1
012345678
(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
lãng phí cho những gói
tin phải gửi lại từ pkt2->
hết Transport Layer: 3-72
Selective repeat: the approach
§pipelining: multiple packets in flight
§receiver individually ACKs all correctly received packets
• buffers packets, as needed, for in-order delivery to upper layer
§sender:
• maintains (conceptually) a timer for each unACKed pkt
• timeout: retransmits single unACKed packet associated with timeout
• maintains (conceptually) “window” over N consecutive seq #s
• limits pipelined, “in flight” packets to be within this window
a dilemma!
0123012 pkt0
0123012 pkt1 0123012
0123012 pkt2 0123012
example:
0123012
0123012 pkt3
X
0123012
§ seq #s: 0, 1, 2, 3 (base 4 counting) pkt0 will accept packet
with seq number 0
§ window size=3 (a) no problem
a dilemma!
0123012 pkt0
0123012 pkt1 0123012
0123012 pkt2 0123012
example:
0123012
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 (very) wrong!
0123012 pkt1 0123012
options (variable length) option khiến head thay đổi -> cần head len
C, E: congestion notification not used có thể dùng cho thế hệ sau
TCP options
application data sent by
RST, SYN, FIN: connection data application into
management (variable length) TCP socket
• cumulative ACK
ack sẽ là stt của gói tin
sent sent, not- usable not tiếp theo, là ack tích
ACKed yet ACKed but not usable luyx
Q: how receiver handles out-of- (“in-flight”) yet sent
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
RTT (milliseconds)
%""
RTT uowc lg
$""
sampleRTT
!#"
EstimatedRTT
!""
! & !# $$ $' %E )% #" #* E) *! *& &# '$ '' !"E
time (seconds)
time (seconnds)
+,-./0122 34RS-,R0T8122
Transport Layer: 3-85
TCP round trip time, timeout
§ timeout interval: EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT: want a larger safety margin
TimeoutInterval = EstimatedRTT + 4*DevRTT
DevRTT = uowcs lÿợng
estimated RTT “safety margin” RTT
* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Transport Layer: 3-86
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
event: ACK received
§ start timer if not already
running § if ACK acknowledges
previously unACKed segments
• think of timer as for oldest
unACKed segment • update what is known to be
ACKed
• expiration interval:
TimeOutInterval • start timer if there are still
unACKed segments
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout
ACK=100
X
ACK=100
ACK=120
SendBase=120
=100
timeout
ACK
=100
ACK
=100
Receipt of three duplicate ACKs ACK
from sender
TCP
code
Network layer
delivering IP datagram
payload into TCP
socket buffers IP
code
from sender
TCP
code
receive window
flow control: # bytes
receiver willing to accept IP
code
from sender
TCP
flow control code
application application
network network
choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB
data(x+1) accept
ACK(x+1) data(x+1)
connection
x completes
No problem!
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
ESTAB
acc_conn(x)
Problem: half open
connection! (no client)
Transport Layer: 3-102
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
accepted!
TCP 3-way handshake
Server state
Client state
serverSocket = socket(AF_INET,SOCK_STREAM)
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
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
1. On belay?
2. Belay on.
3. Climbing.
§ two flows
R R
§ no retransmissions needed
Host B
R/2
Q: What happens as
lout
delay
throughput:
approaches R/2?
lin R/2 lin R/2
maximum per-connection large delays as arrival rate
throughput: R/2 line approaches capacity
Transport Layer: 3-109
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
R R
throughput: lout
Host A lin : original data lin
copy lout R/2
l'in: original data, plus
retransmitted data
R R
no buffer space!
R R
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
R R
throughput: lout
full buffers – requiring retransmissions to un-needed
retransmissions
§ but sender times can time out prematurely,
sending two copies, both of which are delivered when sending at
R/2, some packets
are retransmissions,
including needed
and un-needed
Host A lin : original data lin duplicates, that are
timeout
copy R/2
l'in: original data, plus delivered!
retransmitted data
R R
throughput: lout
full buffers – requiring retransmissions to un-needed
retransmissions
§ but sender times can time out prematurely,
sending two copies, both of which are delivered when sending at
R/2, some packets
are retransmissions,
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
Host D
lout
Host C
lin’ R/2
throughput: lout
lin R/2
delay
R/2
lin R/2
loutthroughput:
throughput
lin R/2 R/2
throughput: lout
effective throughput
R/2
lin
§ upstream transmission capacity / buffering
R/2
lout
wasted for packets lost downstream
lin’ R/2
router
§ may indicate congestion level or
explicitly set sending rate
§ TCP ECN, ATM, DECbit protocols
Transport Layer: 3-120
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-121
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
Why AIMD?
§ AIMD – a distributed, asynchronous algorithm – has been
shown to:
• optimize congested flow rates network wide!
• have desirable stability properties
RTT
• initially cwnd = 1 MSS two segm
ents
• double cwnd every RTT
• done by incrementing cwnd
for every ACK received four segm
ents
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-126
Summary: TCP congestion control
New
New ACK!
ACK!
.
new ACK
duplicate ACK
cwnd = cwnd + MSS (MSS/cwnd)
dupACKcount++ new ACK 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
fast retransmit missing segment
recovery
duplicate ACK
cwnd = cwnd + MSS
transmit new segment(s), as allowed
bottleneck
TCP connection 2 router
capacity R
Connection 1 throughput R
Transport Layer: 3-136
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