Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Communication Networks
P. Demeester
Chapter 3
Transport Layer
Computer networking A top-down approach featuring the internet
4th Edition, 2008
Addison Wesley
James F. Kurose, Keith W. Ross
ISBN 0-321-49770-8
3-11
Part of slides provided by J.F Kurose and K.W. Ross, All Rights Reserved
Chapter 3: Transport Layer
Our goals:
understand principles
behind transport layer
services:
multiplexing/demultiplexing
reliable data transfer
flow control
congestion control
learn about transport
layer protocols in the
Internet:
UDP: connectionless
transport
TCP: connection-oriented
transport
Transport Layer
3-2
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer
3-3
Transport services and protocols
provide logical communication
between app processes
running on different hosts
transport protocols run in
end systems
send side: breaks app
messages into segments,
passes to network layer
rcv side: reassembles
segments into messages,
passes to app layer
more than one transport
protocol available to apps
Internet: TCP and UDP
application
transport
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical
Transport Layer
3-4
Transport vs. network layer
network layer: logical
communication
between hosts (IP
address)
transport layer: logical
communication
between processes
(port)
relies on, enhances,
network layer services
Household analogy:
12 kids sending letters to
12 kids
processes = kids
app messages = letters
in envelopes
hosts = houses
transport protocol =
Ann and Bill
network-layer protocol
= postal service
Transport Layer
3-5
Internet transport-layer protocols
reliable, in-order
delivery (TCP)
congestion control
flow control
connection setup
unreliable, unordered
delivery: UDP
no-frills extension of
“best-effort” IP
services not available:
delay guarantees
bandwidth guarantees
application
transport
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical
Transport Layer
3-6
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer
3-7
Multiplexing/demultiplexing
Multiplexing at send side:
gathering data from multiple
sockets, enveloping data with
header (later used for
demultiplexing)
Demultiplexing at rcv side:
delivering received segments
to correct socket
P1
application
application
transport
Proc
2345
network
link
transport
DNS
53
SNMP
network
= socket
server
= process
application
transport
link
physical
host 1
Proc
4235
network
link
physical
161
physical
host 2
Transport Layer
3-8
How demultiplexing works
host receives IP datagrams
each datagram has source
IP address, destination IP
address
each datagram carries 1
transport-layer segment
each segment has source,
destination port number
(recall: well-known port
numbers for specific
applications)
host uses IP addresses & port
numbers to direct segment to
appropriate socket
32 bits
source port #
dest port #
other header fields
application
data
(message)
TCP/UDP segment format
Transport Layer
3-9
Connectionless (de)multiplexing
Create sockets with port
numbers:
DatagramSocket serverSocket1 =
new DatagramSocket(53);
DatagramSocket serverSocket2 =
new DatagramSocket(161);
UDP socket identified by
two-tuple:
(dest IP address, dest port number)
When host receives UDP
segment:
checks destination port
number in segment
directs UDP segment to
socket with that port
number
IP datagrams with
different source IP
addresses and/or source
port numbers directed
to same socket
Transport Layer 3-10
Connectionless (de)multiplexing
DatagramSocket serverSocket = new DatagramSocket(53);
Proc
2345
SP: 2345
SP: 4235
DP: 53
DP: 53
SP: 53
client
IP: A
P1
Proc
4235
DNS
53
DP: 2345
SP: 53
server
IP: C
Source Port (SP) provides “return address”
DP: 4235
Client
IP: B
Transport Layer
3-11
Connection-oriented (de)mux
TCP socket identified
by 4-tuple:
source IP address
source port number
dest IP address
dest port number
recv host uses all four
values to direct
segment to appropriate
socket
Server host may support
many simultaneous TCP
sockets:
each socket identified by
its own 4-tuple
Web servers have
different sockets for
each connecting client
non-persistent HTTP will
have different socket for
each request
Transport Layer 3-12
Connection-oriented (de)mux
P1
IP : A, C
Port : 80, 9157
IP : B, C
Port : 80, 5775
SP: 80
SP: 80
DP: 9157
DP: 5775
SP: 9157
client
IP: A
DP: 80
SP: 5775
http
server
IP: C
DP: 80
Client
IP:B
Transport Layer 3-13
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-14
UDP: User Datagram Protocol
“no frills,” “bare bones”
Internet transport
protocol
“best effort” service, UDP
segments may be:
lost
delivered out of order
to app
connectionless:
no handshaking between
UDP sender, receiver
each UDP segment
handled independently
of others
Why is there a UDP?
no connection
establishment (which can
add delay)
simple: no connection state
at sender, receiver
small segment header
no congestion control: UDP
can blast away as fast as
desired
Transport Layer 3-15
UDP
often used for streaming
multimedia apps
loss tolerant
rate sensitive
Length, in
bytes of UDP
segment,
including
header
other UDP uses
DNS
SNMP
reliable transfer over UDP:
add reliability at
application layer
application-specific
error recovery!
32 bits
source port #
dest port #
length
checksum
Application
data
(message)
UDP segment format
Transport Layer 3-16
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
Sender:
Receiver:
treat segment contents
compute checksum of
as sequence of 16-bit
integers
checksum: addition (1’s
complement sum) of
segment contents
sender puts checksum
value into UDP checksum
field
received segment
check if computed checksum
equals checksum field value:
NO - error detected
YES - no error detected.
But maybe errors
nonetheless?
Transport Layer 3-17
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-18
TCP: overview
End-to-end, point-to-point, full-duplex byte-stream
service
over IP’s end-to-end packet delivery service
A connection-oriented protocol (handshake for initialization)
over the connectionless IP protocol
Reliability (acknowledgment, retransmission, in sequence
delivery, error control)
over the unreliable IP protocol
Flow control
end-to-end, without help from the network
Congestion control
without help from the network
No guarantee on delay, delay variation, bandwidth
like IP
Transport Layer 3-19
TCP: overview
Send/Receive
Process
full-duplex, pt-pt, end-end
Receive/Send
Process
Byte stream
TCP
TCP
(+TCP receive/
send buffer)
(+TCP send/
receive buffer)
Segments
IP
IP
Packets
Transport Layer 3-20
Use of TCP
Port
7
9
13
20
21
23
25
53
80
109
110
111
119
143
161-162
179
194
220
515
666
6000-6063
Protocol
Echo
Discard
Daytime
FTP data
FTP control
Telnet
SMTP
DNS
HTTP
POPv2
POPv3
SUN RPC
NNTP
IMAP
SNMP
BGP
IRC
IMAPv3
Print Spooler
Doom
X11
Description
Sends back what is received
Discards what is received
Sends back the time of day
Data channel for FTP
Control channel for FTP (get, put, …)
Default port for telnet application
Used for sending email to a mailserver
Domain Name System over TCP
Used in the World Wide Web
Used for reading email on a mailserver
Used for reading email on a mailserver
Sun’s Remote Procedure Call over TCP
Network News Transfer Protocol (newsgroups)
Used for reading email on a mailserver
Simple Network Management Protocol
Border Gateway Protocol
Internet Relay Chat, a chat service
Used for reading email on a mailserver
Used in print servers
The popular 3D game by Id Software
The X Window System
Transport Layer 3-21
TCP segment structure
each byte from sender to receiver
has a 32 bit sequence number
One more than the
(this number indicates the first byte)
sequence number of the last byte
being acknowledged
20, 21 : FTP
23 : Telnet
25 SMTP
80 : HTTP
0-1023 : reserved
>1023 : ephemeral
(short lived) port
16-bit source port number
16-bit destination port number
32-bit sequence number
32-bit acknowledgement number
4-bit
unused U A P R S F
16-bit window size
header (6 bits) R C S S Y I
length
G K H T N N
16-bit TCP checksum
16-bit urgent pointer
length of TCP header
in 32-bit words
different flags
Options (if any)
maximum number of bytes
that sender of this segment
still can receive
mandatory
:
Data
e.g.: maximum segment size
covers header and data field
(MSS) that sender can receive
relative position of the
urgent
data inLayer
the segment
Transport
3-22
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-23
3-way handshake
TCP Connection OPEN
Client side
SP : Source Port number
DP : Destination Port number
SEQ : SEQuence number
(…) : length data field
ACK : ACKnowledgment number
SYN : SYN flag set to 1
ACK : ACK flag set to 1
MSS : Maximum Segment Size
OPEN TCP
connection
(negotiate initial settings)
Server side
Note : most important fields in TCP header are indicated
Transport Layer 3-24
Note : last segment may contain data
TCP Connection CLOSE
CLOSE TCP
connection
Server side
passive close
active close
Client side
Transport Layer 3-25
TCP State Transition Diagram
STARTING POINT
LISTEN
appl: passive open
send: -
recv: SYN
send: ACK, SYN
SYN_RCVD
CLOSED
DATA
TRANSFER
STATE
recv: ACK
send: -
recv: ACK
send: -
ACTIVE
CLOSE
FIN_WAIT_2
recv: ACK, FIN
send: ACK
recv: FIN
send: ACK
SYN_SENT
recv: ACK, SYN
send: ACK
ESTABLISHED
appl: close
send: FIN
FIN_WAIT_1
appl: active open
send: SYN
recv: FIN
send: ACK
CLOSE_WAIT
appl: close
send: FIN
PASSIVE
CLOSE
LAST_ACK
TIME_WAIT
wait 2 MSL
recv : ACK
send : -
Transport Layer 3-26
Maximum segment lifetime
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
connection management
reliable data transfer
flow control
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-27
Acknowledgment and retransmission
use of acknowledgements
Sender side
Receiver side
timeout
retransmit
Transport Layer 3-28
Ack/retrans/duplicate reception
use of acknowledgements
Sender side
timeout
retransmit
Receiver side
duplicate
reception
=> discard
Transport Layer 3-29
Piggybacking and delayed ACKs
Sender side A
Receiver side B
Delayed ACK
<200 msec
piggybacked
Transport Layer 3-30
ACK
Delayed accumulated ack
Sender side A
Receiver side B
delayed
ACK
accumulated ACK
after 2 segments
accumulated
ACK
- ACK number indicates that all bytes before the ACK number have been received correctly
Transport
Layer 3-31
- in practice : if a second segment is received, the accumulated ACK is send
immediately
Avoid retransmission
Sender side A
Receiver side B
out of order
immediate ACK
timeout
retransmit
start
timer
and double
RTO
Les
5 segments
6
not all
have to be retransmitted !
missing segment arrived
accumulated ACK
Transport Layer 3-32
Fast retransmission
Sender side A
Receiver side B
out of order
immediate ACK
3
duplicated
ACK’s
=> fast
retransmit
Note : 3 dupl ack :
make distinction with out of order
e.g. 1,3,4,2,5,6,...
timeout
NOT USED
retransmission much faster then timeout
missing segment arrived
accumulated ACK
Transport Layer 3-33
TCP ACK generation
Event at Receiver
TCP Receiver action
Arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
Delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
Arrival of in-order segment with
expected seq #. One other
segment has ACK pending
Immediately send single cumulative
ACK, ACKing both in-order segments
Arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
Immediately send duplicate ACK,
indicating seq. # of next expected byte
Arrival of segment that
partially or completely fills gap
Immediate send ACK, provided that
segment starts at lower end of gap
Transport Layer 3-34
Retransmission timeout
Problem : large variation in round trip time !!!
(LAN <> worldwide Internet)
==> dynamic update of retransmission timeout (RTO)
[TimeoutInterval]
new value
old value
measured value
RTT = a RTT + (1-a) M
(in general a = 7/8)
RTT (Round Trip Time) = exponential weighted moving
average (EWMA) [EstimatedRTT]
M = last measured time for an acknowledgment [SampleRTT]
Retransmission Timeout : RTO = RTT + 4 D
D = b D + (1-b) |RTT-M| (mean deviation) [DevRTT]
(b = 3/4 … 7/8)
initial values :
RTO = 3”
D = 1.5”
RTT = 0”
Exponential back-off : every retransmission of the same segment will double the RTO
(with an upper limit and latching of 64”)
(connection timeout after preconfigured number of retransmissions)
Transport Layer
3-35
(note : the RTT will not be updated based on the measurement of a retransmitted
segment)
Measured round trip time (M)
measured
round trip time
M #1
M #2
Transport Layer 3-36
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
reliable data transfer
flow control
connection management
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-37
Flow control
Flow Control :
receiver limits sender speed
based on own buffer filling
• slow receiver may not be able to cope with segment
stream from fast sender
• receiver will measure buffer filling
• receiver will advertise to sender its free buffer space
(advertise receive window : RcvWindow)
• sender will limit outgoing traffic
• ONLY terminals participate in flow control (layer 4!)
Transport Layer 3-38
Flow control : receiver side
application layer
segments delivered
to application layer
receiver buffer (4 x MSS)
receive
windowwindow
= 2 = 4
receive
transport layer : TCP
receiver
segments received
from sender
Transport Layer 3-39
Flow control : sender side
application layer
information from application
ready to send
1
2
3
4
5
6
7
8
9
send
window
window
sendsend
window
=
4= 2 = 3
transport layer : TCP
sender
send window = amount of data still allowed to send
ACK=3, W=3
sent, not yet acknowledged
sent and acknowledged
Transport Layer 3-40
Flow control : example
sender
data to be sent (expressed in MSS)
1
2
3
4
5
6
7
8
receiver
receiver buffer (4 x MSS)
9
send window
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
receive
window
sent, not yet ack.
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
sent and
acknowledged
2 MSS to
application
received
not transferred
to application
zero window <ACK=5, W=0> will stop communication (no more window updates)
regular probing from sender (use persistencyTransport
timer) Layer 3-41
Flow control : sliding window
<ACK=4, W=3>
1
2
3
4
5
6
7
8
9 10 11 12 13 14 15 16 17 18
<ACK=3, W=2>
SEND WINDOW =
receive window (RcvWindow)
MINUS
number of sent but not yet acknowledged bytes
(LastByteSent – LastByteAcked)
LastByteAcked
LastByteSent
allowed to send if :
Layer 3-42
LastByteSent – LastByteAcked < RcvWindow or Transport
SndWindow
> 0
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
reliable data transfer
flow control
connection management
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-43
Congestion <> Flow control
Transport layer : TCP
flow control : L4 buffers in hosts
congestion control : L3 buffers in routers
receiver
receiver1
sender
sender1
buffer
sender 2
receiver 2
!! Discarded !!
ROUTER
!! Discarded !!
Network layer : IP
Transport Layer 3-44
Impact of congestion
Network congestion (layer 3):
Effective throughput
- limited capacity of routers (L3)
- traffic load high
Maximum capacity
of the network
retransmissions: packet loss
due to buffer overflow
linear increase
congestion
starts
Traffic offered
to the network
Solution : Congestion Control (in terminals)
layer 4 (TCP) will reduce load offered to L3 (IP)
Transport Layer 3-45
Approaches towards congestion control
Two broad approaches towards congestion control:
Network-assisted
End-end congestion
congestion control:
control (TCP approach):
no explicit feedback from
network
congestion inferred from
end-system observed loss,
delay
approach taken by TCP
routers provide feedback
to end systems
single bit indicating
congestion
explicit rate sender
should send at
Transport Layer 3-46
Chapter 3 outline
3.1 Transport-layer
services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless
transport: UDP
3.4 Principles of
reliable data transfer
3.5 Connection-oriented
transport: TCP
segment structure
reliable data transfer
flow control
connection management
3.6 Principles of
congestion control
3.7 TCP congestion
control
Transport Layer 3-47
Congestion window : limit send rate
SEND WINDOW :
MINIMUM {receive window, congestion window}
MINUS
number of sent but not yet acknowledged bytes
allowed to send if :
LastByteSent – LastByteAcked < min {CongWindow, RcvWindow}
or SndWindow > 0
Flow control : detection by receiver and control by sender
- receive window (set at receiver side)
Congestion control : detection and control by sender
- congestion window (set at sender side)
Transport Layer 3-48
Congestion window
congestion window < receive window
congestion window > receive window
sent and ack.
receive window
- focus on the congestion window
- suppose congestion window < receive window
- congestion window multiple of MSS
- expressed in bytes
congestion window
sent, not yet ack.
Transport
Layer
send
window
3-49
Congestion detection (by sender !)
Timeout :
• A segment or ACK was dropped due to congestion.
• A segment or ACK is experiencing a large delay due to congestion.
• A segment or ACK was dropped due to a transmission error
(has nothing to do with congestion and is assumed to be not important).
TCP solution : slow start + congestion avoidance
Duplicate acknowledgments (3 or more) :
• One segment was dropped due to congestion.
• Next segments still get through the network
(generating duplicate acknowledgments)
TCP solution :
fast retransmission
(see reliability)
+ fast recovery
Transport Layer 3-50
Slow start
cwnd (# MSS)
cwnd = 1
18
16
cwnd = 2
14
12
10
cwnd = 4
8
6
4
2
cwnd = 8
cwnd = 16
...
...
values expressed in MSS
00
1
2
3
4
5
# RTT
!!! value of
measured RTT
is varying !!!
Transport Layer 3-51
Slow start threshold / Congestion avoidance
cwnd = 1
cwnd = 2
cwnd = 4
cwnd (# MSS)
18
16
14
12
10
cwnd = 8
8
Slow
Start
Threshold
(ssthresh)
6
4
2
cwnd = 9
00
1
2
3
slow
start
cwnd = 10
4
5
# RTT
congestion
avoidance
Transport Layer 3-52
Avoiding congestion (Timeout)
!!! TIMEOUT !!!
cwdn
size
ssthresh = cwnd/2
cwnd = 1 x MSS
!!! TIMEOUT !!!
ssthresh = cwnd/2
cwnd = 1 x MSS
congestion
avoidance
slow
start
slow
start
# RTT
Intial values :
ssthresh = 64 kbyte
cwnd = 1xMSS
Note : when cwnd > receive window
==> normal flow control takes over
3-53
(based on Transport
receive Layer
window)
Avoiding congestion : dupl ack
normal
ACK=5
dupl
ACK=5
dupl
ACK=5
dupl
ACK=5
18
fast retransmit :
first non-ack
segment=5
dupl
ACK=5
16
cwnd (# MSS)
14
12
10
8
dupl
ACK=5
Congestion
avoidance
ACK=19
cwnd =
sstresh
+ 3 MSS
6
4
acknowledge
retransmitted
segment=5
ACK=11
(accumulated)
Ssthresh = 1/2 cwnd
cwnd =
sstresh
2
0
see notes
time
Transport Layer 3-54
TCP AIMD :
Additive Increase Multiplicative Decrease
Multiplicative Decrease:
cut cwnd in half after
loss event
congestion
window
Additive Increase:
increase cwnd by 1
MSS every RTT in the
absence of loss
events: probing
24 Kbytes
16 Kbytes
8 Kbytes
time
Long-lived TCP connection
Transport Layer 3-55
Summary: TCP Congestion control
When CongWin is below Threshold, sender in
slow-start phase, window grows exponentially.
When CongWin is above Threshold, sender is in
congestion-avoidance phase, window grows linearly.
When a triple duplicate ACK occurs, Threshold
set to CongWin/2 and CongWin set to
Threshold.
When timeout occurs, Threshold set to
CongWin/2 and CongWin is set to 1 MSS.
Transport Layer 3-56
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
TCP
connection 2
bottleneck
router
capacity R
Transport Layer 3-57
Why is TCP fair?
rate =
CongWin
Bytes/sec
RTT
R = bottleneck rate
RTT = constant
rate ~ CongWin
only 3 dup ack
3 dup ack
rate
3 dup ack
R/2
time
Layer 3-58
every time a “3 dup ack” occurs, difference in bitrate is halved resultingTransport
in fair distribution
Fairness : UDP, TCP
Fairness and UDP
Multimedia apps often
do not use TCP
do not want rate
throttled by congestion
control
Instead use UDP:
pump audio/video at
constant rate, tolerate
packet loss
Not fair
Fairness and parallel TCP
connections
nothing prevents app from
opening parallel
connections between 2
hosts.
Web browsers do this
Example: link of rate R
supporting 9 cnctions;
new app asks for 1 TCP, gets
rate R/10
new app asks for 11 TCPs,
gets R/2 !
Transport Layer 3-59
Chapter 3 Summary
principles behind transport
layer services:
multiplexing,
demultiplexing
reliable data transfer
flow control
congestion control
instantiation and
implementation in the
Internet
UDP
TCP
Next:
leaving the network
“edge” (application,
transport layers)
into the network
“core”
Transport Layer 3-60
Table of contents
3.1 Transport-layer services
3.2 Multiplexing and demultiplexing
3.3 Connectionless transport: UDP
3.5 Connection-oriented transport: TCP
3.6 Principles of congestion control
3.7 TCP congestion control
Summary
Table of contents
3
7
14
18
43
47
60
61
Transport Layer 3-61