You are on page 1of 87

Chapter 3

Transport
Layer
A note on the use of these PowerPoint slides:
We’re making these slides freely available to all (faculty, students,
readers). They’re in PowerPoint form so you see the animations; and
can add, modify, and delete slides (including this one) and slide content
to suit your needs. They obviously represent a lot of work on our part.
In return for use, we only ask the following:
 If you use these slides (e.g., in a class) that you mention their source
(after all, we’d like people to use our book!)
 If you post any slides on a www site, that you note that they are
adapted from (or perhaps identical to) our slides, and note our
copyright of this material.
Computer Networking: A
For a revision history, see the slide note for this page.
Top-Down Approach
Thanks and enjoy! JFK/KWR 8th edition
Jim Kurose, Keith Ross
All material copyright 1996-2020
J.F Kurose and K.W. Ross, All Rights Reserved Pearson, 2020
Transport Layer: 3-1
Transport layer: overview
Our goal:
 understand principles  learn about Internet transport
behind transport layer layer protocols:
services: • UDP: connectionless transport
• multiplexing, • TCP: connection-oriented reliable
demultiplexing transport
• reliable data transfer • TCP congestion control
• flow control
• congestion control

Transport Layer: 3-2


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

 provide logical communication mobile


network
network
data link
physical

between application processes national or global ISP

running on different hosts

log
ica
le
 transport protocols actions in end

nd
-e
systems:

nd
local or

tra
• sender: breaks application messages regional ISP

n sp
into segments, passes to network layer

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

 two transport protocols available to data link


physical

Internet applications enterprise


network
• TCP, UDP
Transport Layer: 3-4
Transport vs. network layer services and protocols
household analogy:
12 kids in Ann’s house sending
letters to 12 kids in Bill’s house:
 hosts = houses
 processes = kids
 app messages = letters in
envelopes
 transport protocol = Ann and Bill
who demux to in-house siblings
 network-layer protocol = postal
service

Transport Layer: 3-5


Transport vs. network layer services and protocols

 network layer: logical household analogy:


communication between 12 kids in Ann’s house sending
hosts letters to 12 kids in Bill’s house:
 hosts = houses
 transport layer: logical  processes = kids
communication between  app messages = letters in
processes envelopes
• relies on, enhances, network  transport protocol = Ann and Bill
layer services who demux to in-house siblings
 network-layer protocol = postal
service

Transport Layer: 3-6


Transport Layer Actions

Sender:
application  is passed an application- app. msg
application
layer message
transport
 determines segment TTh htransport
app. msg
header fields values
network (IP)
 creates segment network (IP)

link
 passes segment to IP link

physical physical

Transport Layer: 3-7


Transport Layer Actions

Receiver:
application  receives segment from IP application
 checks header values
app. msg
transport  extracts application-layer transport
message
network (IP)  demultiplexes message up network (IP)

link to application via socket link

physical physical
Th app. msg

Transport Layer: 3-8


Two principal Internet transport protocols
application
transport

 TCP: Transmission Control Protocol mobile


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

log
• congestion control

ica
le
• flow control

nd
-e
• connection setup

nd
local or

tra
regional ISP
 UDP: User Datagram Protocol

n sp
ort
• unreliable, unordered delivery home network content
provider
• no-frills extension of “best-effort” IP network
application
transport
datacenter
network

 services not available:


network
data link
physical

• delay guarantees enterprise


network
• bandwidth guarantees
Transport Layer: 3-9
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-10
HTTP server
client
application application
HTTP msg
transport

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-11


HTTP server
client
application application
HTTP msg
Ht HTTP msg
transport

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-12


HTTP server
client
application application
HTTP msg
Ht HTTP msg
transport
Hnnetwork
Ht HTTP msg
transport transport
network link network
link physical link
physical physical

Transport Layer: 3-13


HTTP server
client
application application

transport

transport network transport


network link network
link physical link
physical physical

Hn Ht HTTP msg

Transport Layer: 3-14


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

transport

transport network transport


network link network
link physical link
physical physical

Transport Layer: 3-15


Multiplexing/demultiplexing
multiplexing at sender: demultiplexing at receiver:
handle data from multiple use header info to deliver
sockets, add transport header received segments to correct
(later used for demultiplexing) socket

application

application P1 P2 application socket


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

Transport Layer: 3-16


How demultiplexing works
 host receives IP datagrams 32 bits
• each datagram has source IP source port # dest port #
address, destination IP address
• each datagram carries one other header fields
transport-layer segment
• each segment has source,
application
destination port number data
 host uses IP addresses & port (payload)
numbers to direct segment to
appropriate socket TCP/UDP segment format

Transport Layer: 3-17


Connectionless demultiplexing
Recall: when receiving host receives
 when creating socket, must UDP segment:
• checks destination port # in
specify host-local port #:
segment
DatagramSocket mySocket1 = new
DatagramSocket(12534); • directs UDP segment to socket
with that port #
 when creating datagram to
send into UDP socket, must
IP/UDP datagrams with same dest.
specify port #, but different source IP
• destination IP address addresses and/or source port
• destination port # numbers will be directed to same
socket at receiving host
Transport Layer: 3-18
Connectionless demultiplexing: an example
DatagramSocket
serverSocket = new
DatagramSocket
DatagramSocket mySocket2 = DatagramSocket mySocket1 =
new DatagramSocket (6428); new DatagramSocket (5775);
(9157); application
application P1 application
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: ?


dest port: 6428 dest port: ?
Transport Layer: 3-19
Connection-oriented demultiplexing
 TCP socket identified by  server may support many
4-tuple: simultaneous TCP sockets:
• source IP address • each socket identified by its
• source port number own 4-tuple
• dest IP address • each socket associated with
• dest port number a different connecting client
 demux: receiver uses all
four values (4-tuple) to
direct segment to
appropriate socket
Transport Layer: 3-20
Connection-oriented demultiplexing: example
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

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


address A dest IP,port: A,9157 source IP,port: C,5775 address C
dest IP,port: B,80
source IP,port: A,9157
dest IP, port: B,80
source IP,port: C,9157
dest IP,port: B,80
Three segments, all destined to IP address: B,
dest port: 80 are demultiplexed to different sockets
Transport Layer: 3-21
Summary
 Multiplexing, demultiplexing: based on segment, datagram
header field values
 UDP: demultiplexing using destination port number and Dest IP
address
 TCP: demultiplexing using 4-tuple: source and destination IP
addresses, and port numbers
 Multiplexing/demultiplexing happen at all layers

Transport Layer: 3-22


Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
 Principles of congestion control
 TCP congestion control
 Evolution of transport-layer
functionality
Transport Layer: 3-23
UDP: User Datagram Protocol
 “no frills,” “bare bones”
Why is there a UDP?
Internet transport protocol  no connection
establishment (which can
 “best effort” service, UDP add RTT delay)
segments may be:  simple: no connection state
• lost at sender, receiver
• delivered out-of-order to app  small header size
 connectionless:  no congestion control
 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-24
UDP: User Datagram Protocol
 UDP use:
 streaming multimedia apps (loss tolerant, rate sensitive)
 DNS
 SNMP
 if reliable transfer needed over UDP (e.g., HTTP/3):
 add needed reliability at application layer
 add congestion control at application layer

Transport Layer: 3-25


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


UDP: Transport Layer Actions

SNMP client SNMP server


UDP sender actions:
application  is passed an application- SNMP msg
application
layer message
transport  determines UDP segment UDPhtransport
UDP h 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-27


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)  extracts application-layer (UDP)

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

physical physical

Transport Layer: 3-28


UDP segment header
32 bits
source port # dest port #
length checksum

application length, in bytes of


data UDP segment,
(payload) including header

data to/from
UDP segment format application layer

Transport Layer: 3-29


Motivation behind Calculating Checksum
 When you send and receive data over the wire, there are possibilities
where the data can get corrupted, altered, or modified(it can be
accidental, purposely done with evil intention). Whatever may be the
case, there needs to be a method where the receiver can verify and
figure out easily if the data is altered or corrupted.
 Generally what happens is this. The sender calculates a short checksum
value(very small in size) which represents the message/data that is
being sent. The value calculated is either sent along with the message,
or through other methods. Once the data is received, the receiver also
calculates the checksum. If both the values(of the sender and the
receiver) tallies, then the data is uncorrupted/unaltered.

Transport Layer: 3-30


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

Transmitted: 5 6 11

Received: 4 6 11

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

Transport Layer: 3-31


UDP checksum
Goal: detect errors (i.e., flipped bits) in transmitted segment
sender: receiver:
 treat contents of UDP  compute checksum of received
segment (including UDP header segment
fields and IP addresses) as
sequence of 16-bit integers  check if computed checksum equals
 checksum: addition (one’s checksum field value:
complement sum) of segment • Not equal - error detected
content • Equal - no error detected. But maybe
 checksum value put into errors nonetheless? More later ….
UDP checksum field
Transport Layer: 3-32
Internet checksum: an example
example: add two 16-bit integers
1110011001100110
1101010101010101
wraparound 11011101110111011

sum 1011101110111100
checksum 0100010001000011

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: h ttp://gaia.cs.umass.edu/kurose_ross/interactive/
Transport Layer: 3-33
Internet checksum: weak protection!
example: add two 16-bit integers
01
1110011001100110 10
1101010101010101
wraparound 11011101110111011 Even though
numbers have
sum 1011101110111100 changed (bit
flips), no change
checksum 0100010001000011 in checksum!

Transport Layer: 3-34


Continue, At the sender side
 As an example, suppose that we have the bit stream
0110011001100110        0110011001100110          0000111100001111:

 This bit stream is divided into segments of 16-bits integers.


 So, it looks like this:
 0110011001100110 (16-bit integer segment)
 0101010101010101
 0000111100001111

Transport Layer: 3-35


Continue
 0110011001100110
 0101010101010101
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 1011101110111011
 Adding the third word to the above sum gives
1011101110111011
0000111100001111
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1100101011001010 (sum of all segments)

Transport Layer: 3-36


Continue
 1100101011001010
 Now to calculate checksum 1's complement of sum is taken. As I
mentioned earlier, 1's complement is achieved by converting all 1s
into 0s and all 0s into 1s. So, the checksum at sender side is:
 0011010100110101

Transport Layer: 3-37


At the receiver side
 Now at the receiver side, again all segments are added .and sum is added with
sender's checksum.
 1100101011001010 The sum at the sender side
 0011010100110101 The Checksum at the sender side
 If no error than check of receiver would be: 1111111111111111.
 If any 0 bit is presented in the header than there is an error in checksum. So,
the packet is discarded.
 Although UDP provides error checking, it does not do anything to recover from
an error. Some implementations of UDP simply discard the damaged segment;
others pass the damaged segment to the application with a warning.

Transport Layer: 3-38


Summary: UDP
 “no frills” protocol:
• segments may be lost, delivered out of order
• best effort service: “send and hope for the best”
 UDP has its plusses:
• no setup/handshaking needed (no RTT incurred)
• can function when network service is compromised
• helps with reliability (checksum)
 build additional functionality on top of UDP in application layer
(e.g., HTTP/3)
Chapter 3: roadmap
 Transport-layer services
 Multiplexing and demultiplexing
 Connectionless transport: UDP
 Principles of reliable data transfer
 Connection-oriented transport: TCP
 Principles of congestion control
 TCP congestion control
 Evolution of transport-layer
functionality
Transport Layer: 3-40
Principles of reliable data transfer

sending receiving
process process
application data data
transport
reliable channel

reliable service abstraction

Transport Layer: 3-41


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

transport
network
unreliable channel

reliable service implementation

Transport Layer: 3-42


Principles of reliable data transfer

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

Transport Layer: 3-43


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

Transport Layer: 3-44


Reliable data transfer protocol (rdt): interfaces
rdt_send(): called from above, deliver_data(): called by rdt to
(e.g., by app.). Passed data 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
Transport Layer: 3-45
The End of Session

Transport Layer: 3-46


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
Transport Layer: 3-47
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 each pkt
duplicate
 receiver discards (doesn’t deliver
up) duplicate pkt

stop and wait


sender sends one packet, then
waits for receiver response
Transport Layer: 3-48
rdt3.0: channels with errors and loss
Approach: sender waits “reasonable” amount of time for ACK
 retransmits if no ACK received in this time
 if pkt (or ACK) just delayed (not lost):
• retransmission will be duplicate, but seq #s already handles this!
• receiver must specify seq # of packet being ACKed
 use countdown timer to interrupt after “reasonable” amount of
time
timeout

Transport Layer: 3-49


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

(b) packet loss


Transport Layer: 3-50
rdt3.0 in action
sender receiver
sender receiver send pkt0
pkt0
rcv pkt0
send pkt0 pkt0 send ack0
ack0
rcv pkt0 rcv ack0
ack0 send ack0 send pkt1 pkt1
rcv ack0 rcv pkt1
send pkt1 pkt1 send ack1
rcv pkt1 ack1
ack1 send ack1
X timeout
loss resend pkt1
pkt1 rcv pkt1
timeout
resend pkt1 pkt1
rcv pkt1 rcv ack1 (detect duplicate)
send pkt0 pkt0 send ack1
(detect duplicate)
ack1 send ack1 ack1 rcv pkt0
rcv ack1 rcv ack1 send ack0
send pkt0 pkt0 (ignore) ack0
rcv pkt0
ack0 send ack0 pkt1

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


Transport Layer: 3-51
rdt3.0: pipelined protocols operation
pipelining: sender allows multiple, “in-flight”, yet-to-be-acknowledged
packets
• range of sequence numbers must be increased
• buffering at sender and/or receiver

Transport Layer: 3-52


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

Transport Layer: 3-53


Selective repeat
 receiver individually acknowledges all correctly received packets
• buffers packets, as needed, for eventual in-order delivery to upper
layer
 sender times-out/retransmits individually for unACKed packets
• sender maintains timer for each unACKed pkt
 sender window
• N consecutive seq #s
• limits seq #s of sent, unACKed packets

Transport Layer: 3-54


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

Transport Layer: 3-55


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-56
TCP: overview RFCs: 793,1122, 2018, 5681, 7323
 point-to-point:  cumulative ACKs
• one sender, one receiver  pipelining:
 reliable, in-order byte • TCP congestion and flow control
steam: set window size
• no “message boundaries"  connection-oriented:
 full duplex data: • handshaking (exchange of control
• bi-directional data flow in messages) initializes sender,
same connection receiver state before data exchange
• MSS: maximum segment size  flow controlled:
• sender will not overwhelm receiver

Transport Layer: 3-57


TCP segment structure
32 bits

source port # dest port # segment seq #: counting


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

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

Transport Layer: 3-58


TCP sequence numbers, ACKs
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

simple telnet scenario


Transport Layer: 3-59
TCP round trip time, timeout
Q: how to set TCP timeout Q: how to estimate RTT?
value?  SampleRTT:measured time
 longer than RTT, but RTT varies! from segment transmission until
ACK receipt
 too short: premature timeout,
• ignore retransmissions
unnecessary retransmissions
 SampleRTT will vary, want
 too long: slow reaction to estimated RTT “smoother”
segment loss • average several recent
measurements, not just current
SampleRTT

Transport Layer: 3-60


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
• think of timer as for oldest
previously unACKed segments
unACKed segment • update what is known to be
ACKed
• expiration interval:
TimeOutInterval • start timer if there are still
unACKed segments
Transport Layer: 3-61
TCP: retransmission scenarios
Host A Host B Host A Host B

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

Seq=100, 20 bytes of data


timeout

timeout
ACK=100
X
ACK=100
ACK=120

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


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

SendBase=120

lost ACK scenario premature timeout

Transport Layer: 3-62


TCP: retransmission scenarios
Host A Host B

Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


ACK=100
X
ACK=120

Seq=120, 15 bytes of data

cumulative ACK covers


for earlier lost ACK

Transport Layer: 3-63


TCP fast retransmit
Host A Host B
TCP fast retransmit
if sender receives 3 additional
Seq=92
ACKs for same data (“triple Seq=1
, 8 bytes
of data
duplicate ACKs”), resend unACKed 0 0, 20 b
ytes o
f data
segment with smallest seq # X
 likely that unACKed segment lost,
=100
so don’t wait for timeout ACK

=100

timeout
ACK
CK =100
A
=100
Receipt of three duplicate ACKs ACK

indicates 3 segments received Seq=100, 20 bytes of data

after a missing segment – lost


segment is likely. So retransmit!

Transport Layer: 3-64


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-65
TCP flow control
application
Q: What happens if network Application removing
process

layer delivers data faster than data from TCP socket


buffers
application layer removes TCP socket
data from socket buffers? receiver buffers

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

from sender

receiver protocol stack

Transport Layer: 3-66


TCP flow control
application
Q: What happens if network Application removing
process

layer delivers data faster than data from TCP socket


buffers
application layer removes TCP socket
data from socket buffers? receiver buffers

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

from sender

receiver protocol stack

Transport Layer: 3-67


TCP flow control
application
Q: What happens if network Application removing
process

layer delivers data faster than data from TCP socket


buffers
application layer removes TCP socket
data from socket buffers? receiver buffers

TCP
code

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

from sender

receiver protocol stack

Transport Layer: 3-68


TCP flow control
application
Q: What happens if network Application removing
process

layer delivers data faster than data from TCP socket


buffers
application layer removes TCP socket
data from socket buffers? receiver buffers

TCP
flow control code

receiver controls sender, so


sender won’t overflow IP
code
receiver’s buffer by
transmitting too much, too fast
from sender

receiver protocol stack

Transport Layer: 3-69


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
(“in-flight”) data to received rwnd TCP segment payloads

 guarantees receive buffer will not TCP receiver-side buffering


overflow

Transport Layer: 3-70


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

 TCP receiver “advertises” free buffer


space in rwnd field in TCP header
• RcvBuffer size set via socket
receive window
options (typical default is 4096 bytes)
• many operating systems autoadjust
RcvBuffer
 sender limits amount of unACKed
(“in-flight”) data to received rwnd
 guarantees receive buffer will not
overflow
TCP segment format

Transport Layer: 3-71


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();
Transport Layer: 3-72
Agreeing to establish a connection
2-way handshake:

Q: will 2-way handshake always


Let’s talk work in network?
ESTAB
OK  variable delays
ESTAB
 retransmitted messages (e.g.
req_conn(x)) due to message loss
 message reordering
choose x
req_conn(x)  can’t “see” other side
ESTAB
acc_conn(x)
ESTAB

Transport Layer: 3-73


TCP 3-way handshake
Server state
serverSocket = socket(AF_INET,SOCK_STREAM)
Client state serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
clientSocket = socket(AF_INET, SOCK_STREAM) connectionSocket, addr = serverSocket.accept()
LISTEN
clientSocket.connect((serverName,serverPort)) LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB

Transport Layer: 3-74


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

Transport Layer: 3-75


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-76
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! congestion control:
 a top-10 problem! too many senders,
sending too fast

flow control: one sender


too fast for one receiver
Transport Layer: 3-77
Causes/costs of congestion: insights
 throughput can never exceed capacity

 delay increases as capacity approached

 loss/retransmission decreases effective


throughput

 un-needed duplicates further decreases


effective throughput
 upstream transmission capacity / buffering
wasted for packets lost downstream
Transport Layer: 3-78
Approaches towards congestion control

End-end congestion control:


 no explicit feedback from
network
 congestion inferred from ACKs
data data
ACKs
observed loss, delay
 approach taken by TCP

Transport Layer: 3-79


Approaches towards congestion control
Network-assisted congestion
control: explicit congestion info
 routers provide direct feedback
to sending/receiving hosts with data data
ACKs
flows passing through congested ACKs

router
 may indicate congestion level or
explicitly set sending rate
 TCP ECN, ATM, DECbit protocols
Transport Layer: 3-80
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-81
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

time Transport Layer: 3-82


TCP AIMD: more
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

Transport Layer: 3-83


TCP slow start
Host A Host B
 when connection begins,
increase rate exponentially
one segm
until first loss event: ent

RTT
• initially cwnd = 1 MSS two segm
ents
• double cwnd every RTT
• done by incrementing cwnd
for every ACK received four segm
ents

 summary: initial rate is


slow, but ramps up
exponentially fast time

Transport Layer: 3-84


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
ECE=1
TCP TCP
network network
link link
physical physical

ECN=10 ECN=11

IP datagram
Transport Layer: 3-85
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-86
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-87

You might also like