We’re making these slides freely available to all (faculty, students, readers). They’re in PowerPoint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs.

1
Chapter 3
Transport Layer
Transport Layer 3-1
Computer Networking:
A Top Down Approach
4th edition.
Jim Kurose, Keith Ross
Addison-Wesley, July
2007.
A note on the use of these ppt slides:
We’re making these slides freely available to all (faculty, students, readers).
They’re in PowerPoint form so you 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) in substantially unaltered form,
that you mention their source (after all, we’d like people to use our book!)
‰ If you post any slides in substantially unaltered form 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.
Thanks and enjoy! JFK/KWR
All material copyright 1996-2007
J.F Kurose and K.W. Ross, All Rights Reserved
Chapter 3: Transport Layer
Our goals:
ˆ understand principles
behind transport
layer services:
 multiplexing/demultipl
xin
ˆ learn about transport
layer protocols in the
Internet:
 UDP: connectionless
transport
Transport Layer 3-2
exing
 reliable data transfer
 flow control
 congestion control
transport
 TCP: connection-oriented
transport
 TCP congestion control
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-3
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Transport services and protocols
ˆ provide logical communication
between app processes
running on different hosts
ˆ transport protocols run in
end systems
 send side: breaks app
application
transport
network
data link
physical
Transport Layer 3-4
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
Transport vs. network layer
ˆ network layer: logical
communication
between hosts
ˆ transport layer: logical
communication
Household analogy:
12 kids sending letters to
12 kids
ˆ processes = kids
ˆ app messages = letters
Transport Layer 3-5
communication
between processes
 relies on, enhances,
network layer services
ˆ app messages = letters
in envelopes
ˆ hosts = houses
ˆ transport protocol =
Ann and Bill
ˆ network-layer protocol
= postal service
Internet transport-layer protocols
ˆ reliable, in-order
delivery (TCP)
 congestion control
 flow control
 connection setup
li bl d d
application
transport
network
data link
physical network
data link
physical
nt k
network
data link
physical
Transport Layer 3-6
ˆ unreliable, unordered
delivery: UDP
 no-frills extension of
“best-effort” IP
ˆ services not available:
 delay guarantees
 bandwidth guarantees
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical2
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-7
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Multiplexing/demultiplexing
= socket = process
delivering received segments
to correct socket
Demultiplexing at rcv host:
gathering data from multiple
sockets, enveloping data with
header (later used for
demultiplexing)
Multiplexing at send host:
Transport Layer 3-8
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P3 P2 P4 P1
host 1 host 2 host 3
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
source port # dest port #
32 bits
other header fields
Transport Layer 3-9
 each segment has source,
destination port number
ˆ host uses IP addresses & port
numbers to direct segment to
appropriate socket
application
data
(message)
TCP/UDP segment format
Connectionless demultiplexing
ˆ Create sockets with port
numbers:
DatagramSocket mySocket1 = new
DatagramSocket(12534);
DatagramSocket mySocket2 = new
DatagramSocket(12535);
ˆ When host receives UDP
segment:
 checks destination port
number in segment
 directs UDP segment to
socket with that port
Transport Layer 3-10
DatagramSocket(12535);
ˆ UDP socket identified by
two-tuple:
(dest IP address, dest port number)
socket with that port
number
ˆ IP datagrams with
different source IP
addresses and/or source
port numbers directed
to same socket
Connectionless demux (cont)
DatagramSocket serverSocket = new DatagramSocket(6428);
P2 P1P1 P3
Transport Layer 3-11
Client
IP:B
client
IP: A server
IP: C
SP: 6428
DP: 9157
SP: 9157
DP: 6428
SP: 6428
DP: 5775
SP: 5775
DP: 6428
SP provides “return address”
Connection-oriented demux
ˆ TCP socket identified
by 4-tuple:
 source IP address
 source port number
 dest IP address
ˆ Server host may support
many simultaneous TCP
sockets:
 each socket identified by
its own 4-tuple
Transport Layer 3-12
 dest port number
ˆ recv host uses all four
values to direct
segment to appropriate
socket
ˆ Web servers have
different sockets for
each connecting client
 non-persistent HTTP will
have different socket for
each request3
Connection-oriented demux
(cont)
P1 P4 P5 P6 P2 P1P3
SP: 5775
DP: 80
Transport Layer 3-13
Client
IP:B
client
IP: A server
IP: C
SP: 9157
DP: 80
SP: 9157
DP: 80
D-IP:C
S-IP: A
D-IP:C
S-IP: B
D 80
D-IP:C
S-IP: B
Connection-oriented demux:
Threaded Web Server
P1 P4 P2 P1P3
SP: 5775
DP: 80
Transport Layer 3-14
Client
IP:B
client
IP: A server
IP: C
SP: 9157
DP: 80
SP: 9157
DP: 80
D-IP:C
S-IP: A
D-IP:C
S-IP: B
D 80
D-IP:C
S-IP: B
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-15
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
UDP: User Datagram Protocol [RFC 768]
ˆ “no frills,” “bare bones”
Internet transport
protocol
ˆ “best effort” service, UDP
segments may be:
 lost
Why is there a UDP?
ˆ no connection
establishment (which can
add delay)
ˆ simple: no connection state
Transport Layer 3-16
 delivered out of order
to app
ˆ connectionless:
 no handshaking between
UDP sender, receiver
 each UDP segment
handled independently
of others
ˆ simple: no connection state
at sender, receiver
ˆ small segment header
ˆ no congestion control: UDP
can blast away as fast as
desired
UDP: more
ˆ often used for streaming
multimedia apps
 loss tolerant
 rate sensitive
ˆ other UDP uses
DNS
source port # dest port #
32 bits
length checksum
Length, in
bytes of UDP
segment,
including
h d
Transport Layer 3-17
 DNS
 SNMP
ˆ reliable transfer over UDP:
add reliability at
application layer
 application-specific
error recovery!
Application
data
(message)
UDP segment format
header
UDP checksum
Sender:
ˆ treat segment contents
f 16 bit
Receiver:
ˆ compute checksum of
i d s t
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
Transport Layer 3-18
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? More later
….4
Internet Checksum Example
ˆ Note
 When adding numbers, a carryout from the
most significant bit needs to be added to the
result
ˆ Example: add two 16-bit integers
Transport Layer 3-19
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
wraparound
sum
checksum
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-20
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-21
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-22
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-23
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Reliable data transfer: getting started
send receive
rdt_send(): called from above,
(e.g., by app.). Passed data to
deliver to receiver upper layer
deliver_data(): called by
rdt to deliver data to upper
Transport Layer 3-24
send
side
receive
side
udt_send(): called by rdt,
to transfer packet over
unreliable channel to receiver
rdt_rcv(): called when packet
arrives on rcv-side of channel5
Reliable data transfer: getting started
We’ll:
ˆ incrementally develop sender, receiver sides of
reliable data transfer protocol (rdt)
ˆ consider only unidirectional data transfer
 but control info will flow on both directions!
Transport Layer 3-25
ˆ use finite state machines (FSM) to specify
sender, receiver
state
1
state
2
event causing state transition
actions taken on state transition
state: when in this
“state” next state
uniquely determined
by next event
event
actions
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
i d d t f d l i h l
Transport Layer 3-26
 receiver read data from underlying channel
Wait for
call from
above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)
extract (packet,data)
deliver_data(data)
Wait for
call from
below
rdt_rcv(packet)
sender receiver
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
Transport Layer 3-27
tells sender that pkt had errors
 sender retransmits pkt on receipt of NAK
ˆ new mechanisms in rdt2.0 (beyond rdt1.0):
 error detection
 receiver feedback: control msgs (ACK,NAK) rcvr->sender
rdt2.0: FSM specification
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
receiver
rdt_send(data)
Transport Layer 3-28
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below sender
Λ
rdt2.0: operation with no errors
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
rdt_send(data)
Transport Layer 3-29
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below
Λ
rdt2.0: error scenario
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
rdt_send(data)
Transport Layer 3-30
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below
Λ6
rdt2.0 has a fatal flaw!
What happens if
ACK/NAK corrupted?
ˆ sender doesn’t know what
happened at receiver!
ˆ can’t just retransmit:
Handling duplicates:
ˆ sender retransmits current
pkt if ACK/NAK garbled
ˆ sender adds sequence
number to each pkt
Transport Layer 3-31
possible duplicate ˆ receiver discards (doesn’t
deliver up) duplicate pkt
Sender sends one packet,
then waits for receiver
response
stop and wait
rdt2.1: sender, handles garbled ACK/NAKs
Wait for
call 0 from
above
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_send(data)
Wait for
ACK or
NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isNAK(rcvpkt) )
rdt rcv(rcvpkt) rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
Transport Layer 3-32
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
rdt_send(data)
_ ( p)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isNAK(rcvpkt) )
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt)
Wait for
call 1 from
above
Wait for
ACK or
NAK 1
Λ Λ
rdt2.1: receiver, handles garbled ACK/NAKs
sndpkt = make_pkt(NAK, chksum)
udt_send(sndpkt)
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)
udt_send(sndpkt)
Transport Layer 3-33
Wait for
0 from
below rdt_rcv(rcvpkt) &&
not corrupt(rcvpkt) &&
has_seq0(rcvpkt)
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
Wait for
1 from
below
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
not corrupt(rcvpkt) &&
has_seq1(rcvpkt)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt2.1: discussion
Sender:
ˆ seq # added to pkt
ˆ two seq. #’s (0,1) will
suffice. Why?
t h k if i d
Receiver:
ˆ must check if received
packet is duplicate
 state indicates whether
0 or 1 is expected pkt
Transport Layer 3-34
ˆ must check if received
ACK/NAK corrupted
ˆ twice as many states
 state must “remember”
whether “current” pkt
has 0 or 1 seq. #
0 or s expected pkt
seq #
ˆ note: receiver can not
know if its last
ACK/NAK received OK
at sender
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
Transport Layer 3-35
NAK: retransmit current pkt
rdt2.2: sender, receiver fragments
Wait for
call 0 from
above
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,1) )
rdt rcv(rcvpkt)
Wait for
ACK
0
sender FSM
fragment
Transport Layer 3-36
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt,0)
fragment
Wait for
0 from
below
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK1, chksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
(corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)
receiver FSM
fragment
Λ7
rdt3.0: channels with errors and loss
New assumption:
underlying channel can
also lose packets (data
or ACKs)
 checksum, seq. #, ACKs,
Approach: sender waits
“reasonable” amount of
time for ACK
ˆ retransmits if no ACK
received in this time
Transport Layer 3-37
,q, ,
retransmissions will be
of help, but not enough
ˆ if pkt (or ACK) just delayed
(not lost):
 retransmission will be
duplicate, but use of seq.
#’s already handles this
 receiver must specify seq
# of pkt being ACKed
ˆ requires countdown timer
rdt3.0 sender
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
start_timer
rdt_send(data)
Wait
for
ACK0
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,1) )
rdt_rcv(rcvpkt)
&& t t( kt)
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt 1)
udt_send(sndpkt)
start_timer
timeout
rdt_rcv(rcvpkt)
Wait for
call 0from
above
Λ
Λ
Transport Layer 3-38
Wait for
call 1 from
above
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
start_timer
rdt_send(data)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt,0)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,0) )
&& isACK(rcvpkt,1)
stop_timer
stop_timer
udt_send(sndpkt)
start_timer
timeout Wait
for
ACK1
Λ
rdt_rcv(rcvpkt)
Λ
rdt3.0 in action
Transport Layer 3-39
rdt3.0 in action
Transport Layer 3-40
Performance of rdt3.0
ˆ rdt3.0 works, but performance stinks
ˆ example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet:
Ttransmit = 8kb/pkt
10**9 b/sec = 8 microsec L (packet length in bits)
R (transmission rate, bps) =
Transport Layer 3-41
 U sender: utilization – fraction of time sender busy sending
Usender = .008
30.008 = 0.00027 L / R
RTT + L / R =
( p)
 1KB pkt every 30 msec -> 33kB/sec thruput over 1 Gbps link
 network protocol limits use of physical resources!
rdt3.0: stop-and-wait operation
first packet bit transmitted, t = 0
sender receiver
RTT
last packet bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
Transport Layer 3-42
ACK arrives, send next
packet, t = RTT + L / R
Usender = .008
30.008 = 0.00027 L / R
RTT + L / R = 8
Pipelined protocols
Pipelining: sender allows multiple, “in-flight”, yet-tobe-acknowledged
pkts
 range of sequence numbers must be increased
 buffering at sender and/or receiver
Transport Layer 3-43
ˆ Two generic forms of pipelined protocols: go-Back-N,
selective repeat
Pipelining: increased utilization
first packet bit transmitted, t = 0
sender receiver
RTT
last bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
last bit of 2nd packet arrives, send ACK
last bit of 3rd packet arrives send ACK
Transport Layer 3-44
ACK arrives, send next
packet, t = RTT + L / R
last bit of 3rd packet arrives, send ACK
Usender = .024
30.008 = 0.0008 3 * L / R
RTT + L / R =
Increase utilization
by a factor of 3!
Go-Back-N
Sender:
ˆ k-bit seq # in pkt header
ˆ “window” of up to N, consecutive unack’ed pkts allowed
Transport Layer 3-45
ˆ ACK(n): ACKs all pkts up to, including seq # n – “cumulative ACK”
 may receive duplicate ACKs (see receiver)
ˆ timer for each in-flight pkt
ˆ timeout(n): retransmit pkt n and all higher seq # pkts in window
GBN: 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++
}
else
refuse_data(data) base=1
Λ
Transport Layer 3-46
Wait start_timer
udt_send(sndpkt[base])
udt_send(sndpkt[base+1])

udt_send(sndpkt[nextseqnum-1])
timeout
base = getacknum(rcvpkt)+1
If (base == nextseqnum)
stop_timer
else
start_timer
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
base 1
nextseqnum=1
rdt_rcv(rcvpkt)
&& corrupt(rcvpkt)
GBN: receiver extended FSM
Wait
udt_send(sndpkt)
default
rdt_rcv(rcvpkt)
&& notcurrupt(rcvpkt)
&& hasseqnum(rcvpkt,expectedseqnum)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(expectedseqnum,ACK,chksum)
udt_send(sndpkt)
expectedseqnum++
expectedseqnum=1
sndpkt =
make_pkt(expectedseqnum,ACK,chksum)
Λ
Transport Layer 3-47
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 #
GBN in
action
Transport Layer 3-489
Selective Repeat
ˆ receiver individually acknowledges all correctly
received pkts
 buffers pkts, as needed, for eventual in-order delivery
to upper layer
ˆ sender only resends pkts for which ACK not
i d
Transport Layer 3-49
received
 sender timer for each unACKed pkt
ˆ sender window
 N consecutive seq #’s
 again limits seq #s of sent, unACKed pkts
Selective repeat: sender, receiver windows
Transport Layer 3-50
Selective repeat
data from above :
ˆ if next available seq # in
window, send pkt
timeout(n):
ˆ resend pkt n, restart timer
sender
pkt n in [rcvbase, rcvbase+N-1]
ˆ send ACK(n)
ˆ out-of-order: buffer
ˆ in-order: deliver (also
deliver buffered, in-order
receiver
Transport Layer 3-51
resend pkt n, restart t mer
ACK(n) in [sendbase,sendbase+N]:
ˆ mark pkt n as received
ˆ if n smallest unACKed pkt,
advance window base to
next unACKed seq #
pkts), advance window to
next not-yet-received pkt
pkt n in [rcvbase-N,rcvbase-1]
ˆ ACK(n)
otherwise:
ˆ ignore
Selective repeat in action
Transport Layer 3-52
Selective repeat:
dilemma
Example:
ˆ seq #’s: 0, 1, 2, 3
ˆ window size=3
ˆ receiver sees no
Transport Layer 3-53
difference in two
scenarios!
ˆ incorrectly passes
duplicate data as new
in (a)
Q: what relationship
between seq # size
and window size?
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-54
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control10
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
ˆ full duplex data:
 bi-directional data flow
in same connection
 MSS: maximum segment
size
ˆ point-to-point:
 one sender, one receiver
ˆ reliable, in-order byte
steam:
 no “message boundaries”
Transport Layer 3-55
ˆ connection-oriented:
 handshaking (exchange
of control msgs) init’s
sender, receiver state
before data exchange
ˆ flow controlled:
 sender will not
overwhelm receiver
 no message boundaries
ˆ pipelined:
 TCP congestion and flow
control set window size
ˆ send & receive buffers
socket
door
TCP
send buffer
TCP
receive buffer
socket
door
segment
application
writes data
application
reads data
TCP segment structure
source port # dest port #
32 bits
sequence number
acknowledgement number
Receive window
checksum Urg data pnter
UAP RSF head
len
not
used
URG: urgent data
(generally not used)
ACK: ACK #
valid
PSH: push data now
(generally not used) # bytes
illi
counting
by bytes
of data
(not segments!)
Transport Layer 3-56
application
data
(variable length)
Urg data pnter
RST, SYN, FIN: Options (variable length) connection estab
(setup, teardown
commands)
rcvr willing
to accept
Internet
checksum
(as in UDP)
TCP seq. #’s and ACKs
Seq. #’s:
 byte stream
“number” of first
byte in segment’s
data
ACKs:
# f t b t
Host A Host B
User
types
‘C’ host ACKs
receipt of
‘C’, echoes
b k ‘C’
Transport Layer 3-57
 seq # of next byte
expected from
other side
 cumulative ACK
Q: how receiver handles
out-of-order segments
 A: TCP spec doesn’t
say, – up to
implementor
host ACKs
receipt
of echoed
‘C’
back ‘C’
time
simple telnet scenario
TCP Round Trip Time and Timeout
Q: how to set TCP
timeout value?
ˆ longer than RTT
 but RTT varies
ˆ too short: premature
timeout
Q: how to estimate RTT?
ˆ SampleRTT: measured time from
segment transmission until ACK
receipt
 ignore retransmissions
ˆ SampleRTT will vary, want
Transport Layer 3-58
timeout
 unnecessary
retransmissions
ˆ too long: slow reaction
to segment loss
p y,
estimated RTT “smoother”
 average several recent
measurements, not just
current SampleRTT
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT
ˆ Exponential weighted moving average
ˆ influence of past sample decreases exponentially fast
ˆ typical value: α = 0.125
Transport Layer 3-59
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
250
300
350
onds)
Transport Layer 3-60
100
150
200
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT (milliseco
SampleRTT Estimated RTT11
TCP Round Trip Time and Timeout
Setting the timeout
ˆ EstimtedRTT plus “safety margin”
 large variation in EstimatedRTT -> larger safety margin
ˆ first estimate of how much SampleRTT deviates from
EstimatedRTT:
Transport Layer 3-61
TimeoutInterval = EstimatedRTT + 4*DevRTT
DevRTT = (1-β)*DevRTT +
β*|SampleRTT-EstimatedRTT|
(typically, β = 0.25)
Then set timeout interval:
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-62
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP reliable data transfer
ˆ TCP creates rdt
service on top of IP’s
unreliable service
ˆ Pipelined segments
ˆ Cumulative acks
ˆ Retransmissions are
triggered by:
 timeout events
 duplicate acks
ˆ Initially consider
Transport Layer 3-63
ˆ Cumulative acks
ˆ TCP uses single
retransmission timer
ˆ Initially consider
simplified TCP sender:
 ignore duplicate acks
 ignore flow control,
congestion control
TCP sender events:
data rcvd from app:
ˆ Create segment with
seq #
ˆ seq # is byte-stream
number of first data
byte in segment
timeout:
ˆ retransmit segment
that caused timeout
ˆ restart timer
Ack rcvd:
ˆ If acknowledges
Transport Layer 3-64
y g
ˆ start timer if not
already running (think
of timer as for oldest
unacked segment)
ˆ expiration interval:
TimeOutInterval
ˆ If acknowledges
previously unacked
segments
 update what is known to
be acked
 start timer if there are
outstanding segments
TCP
sender
(simplified)
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
loop (forever) {
switch(event)
event: data received from application above
create TCP segment with sequence number NextSeqNum
if (timer currently not running)
start timer
pass segment to IP
NextSeqNum = NextSeqNum + length(data)
t ti ti t
Comment:
• SendBase-1: last
cumulatively
Transport Layer 3-65
event: timer timeout
retransmit not-yet-acknowledged segment with
smallest sequence number
start timer
event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
} /* end of loop forever */
cumulatively
ack’ed byte
Example:
• SendBase-1 = 71;
y= 73, so the rcvr
wants 73+ ;
y > SendBase, so
that new data is
acked
TCP: retransmission scenarios
Host A Host B
eq=92 timeout
Host A
l
timeout
Host B
X
Transport Layer 3-66
time
premature timeout
Se
loss
lost ACK scenario time
SendBase
Seq=92 timeout
= 100
SendBase
= 120
SendBase
= 120
Sendbase
= 10012
TCP retransmission scenarios (more)
Host A
l
timeout
Host B
X
Transport Layer 3-67
loss
Cumulative ACK scenario
time
SendBase
= 120
TCP ACK generation [RFC 1122, RFC 2581]
Event at Receiver
Arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
A i l fi d t ith
TCP Receiver action
Delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
I di t l d i l l ti
Transport Layer 3-68
Arrival of in-order segment with
expected seq #. One other
segment has ACK pending
Arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
Arrival of segment that
partially or completely fills gap
Immediately send single cumulative
ACK, ACKing both in-order segments
Immediately send duplicate ACK,
indicating seq. # of next expected byte
Immediate send ACK, provided that
segment startsat lower end of gap
Fast Retransmit
ˆ Time-out period often
relatively long:
 long delay before
resending lost packet
ˆ Detect lost segments
ˆ If sender receives 3
ACKs for the same
data, it supposes that
segment after ACKed
data was lost:
Transport Layer 3-69
gm
via duplicate ACKs.
 Sender often sends
many segments back-toback
 If segment is lost,
there will likely be many
duplicate ACKs.
 fast retransmit: resend
segment before timer
expires
event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
Fast retransmit algorithm:
Transport Layer 3-70
else {
increment count of dup ACKs received for y
if (count of dup ACKs received for y = 3) {
resend segment with sequence number y
}
a duplicate ACK for
already ACKed segment
fast retransmit
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-71
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP Flow Control
ˆ receive side of TCP
connection has a
receive buffer:
ˆ d t hi
sender won’t overflow
receiver’s buffer by
transmitting too much,
too fast
flow control
Transport Layer 3-72
ˆ speed-matching
service: matching the
send rate to the
receiving app’s drain
rate
ˆ app process may be
slow at reading from
buffer13
TCP Flow control: how it works
(S TCP i
ˆ Rcvr advertises spare
room by including value
of RcvWindow in
segments
ˆ Sender limits unACKed
Transport Layer 3-73
(Suppose TCP receiver
discards out-of-order
segments)
ˆ spare room in buffer
= RcvWindow
= RcvBuffer-[LastByteRcvd –
LastByteRead]
data to RcvWindow
 guarantees receive
buffer doesn’t overflow
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-74
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP Connection Management
Recall: TCP sender, receiver
establish “connection”
before exchanging data
segments
ˆ initialize TCP variables:
 seq. #s
 buffers, flow control
if ( R Wi d )
Three way handshake:
Step 1: client host sends TCP
SYN segment to server
 specifies initial seq #
 no data
Step 2: server host receives
YN li i h YN CK
Transport Layer 3-75
info (e.g. RcvWindow)
ˆ client: connection initiator
Socket clientSocket = new
Socket(“hostname”,”port
number”);
ˆ server: contacted by client
Socket connectionSocket =
welcomeSocket.accept();
SYN, replies with SYNACK
segment
 server allocates buffers
 specifies server initial
seq. #
Step 3: client receives SYNACK,
replies with ACK segment,
which may contain data
TCP Connection Management (cont.)
Closing a connection:
client closes socket:
clientSocket.close();
Step 1: client end system
client server
close
l
Transport Layer 3-76
Step 1: client end system
sends TCP FIN control
segment to server
Step 2: server receives
FIN, replies with ACK.
Closes connection, sends
FIN.
close
closed timed wait
TCP Connection Management (cont.)
Step 3: client receives FIN,
replies with ACK.
 Enters “timed wait” –
will respond with ACK
to received FINs
client server
closing
l i
Transport Layer 3-77
to received FINs
Step 4: server, receives
ACK. Connection closed.
Note: with small
modification, can handle
simultaneous FINs.
closing
closed timed wait
closed
TCP Connection Management (cont)
TCP server
lifecycle
Transport Layer 3-78
TCP client
lifecycle14
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-79
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Principles of Congestion Control
Congestion:
ˆ informally: “too many sources sending too much
data too fast for network to handle”
ˆ different from flow control!
Transport Layer 3-80
ˆ manifestations:
 lost packets (buffer overflow at routers)
 long delays (queueing in router buffers)
ˆ a top-10 problem!
Causes/costs of congestion: scenario 1
ˆ two senders, two
receivers
ˆ one router,
infinite buffers
ˆ no retransmission
unlimited shared
output link buffers
Host A
λin : original data
Host B
λout
Transport Layer 3-81
ˆ large delays
when congested
ˆ maximum
achievable
throughput
Causes/costs of congestion: scenario 2
ˆ one router, finite buffers
ˆ sender retransmission of lost packet
Host A λin : original
data
λout
Transport Layer 3-82
finite shared output
link buffers
Host B
λ’
in : original data, plus
retransmitted data
Causes/costs of congestion: scenario 2
ˆ always: (goodput)
ˆ “perfect” retransmission only when loss:
ˆ retransmission of delayed (not lost) packet makes larger
(than perfect case) for same
λin
λout =
λin
λout >
λin
λout
R/2 R/2 R/2
Transport Layer 3-83
“costs” of congestion:
ˆ more work (retrans) for given “goodput”
ˆ unneeded retransmissions: link carries multiple copies of pkt
R/2 λin
λout
b.
R/2 λin
λout
a.
R/2 λin
λout
c.
R/4
R/3
Causes/costs of congestion: scenario 3
ˆ four senders
ˆ multihop paths
ˆ timeout/retransmit
λin Q: what happens as
and increase λ ? in
Host A λin : original data λout
λ’
in : original data, plus
retransmitted data
Transport Layer 3-84
finite shared output
link buffers
Host B15
Causes/costs of congestion: scenario 3
H
o
s
t
A
H
o
s
t
B
λ
o
u
t
Transport Layer 3-85
Another “cost” of congestion:
ˆ when packet dropped, any “upstream transmission
capacity used for that packet was wasted!
Approaches towards congestion control
End-end congestion
control:
ˆ no explicit feedback from
network
Network-assisted
congestion control:
ˆ routers provide feedback
to end systems
Two broad approaches towards congestion control:
Transport Layer 3-86
network
ˆ congestion inferred from
end-system observed loss,
delay
ˆ approach taken by TCP
to end systems
 single bit indicating
congestion (SNA,
DECbit, TCP/IP ECN,
ATM)
 explicit rate sender
should send at
Case study: ATM ABR congestion control
ABR: available bit rate:
ˆ “elastic service”
ˆ if sender’s path
“underloaded”:
 sender should use
RM (resource management)
cells:
ˆ sent by sender, interspersed
with data cells
ˆ bits in RM cell set by switches
Transport Layer 3-87
available bandwidth
ˆ if sender’s path
congested:
 sender throttled to
minimum guaranteed
rate
(“network-assisted”)
 NI bit: no increase in rate
(mild congestion)
 CI bit: congestion
indication
ˆ RM cells returned to sender by
receiver, with bits intact
Case study: ATM ABR congestion control
Transport Layer 3-88
ˆ two-byte ER (explicit rate) field in RM cell
 congested switch may lower ER value in cell
 sender’ send rate thus maximum supportable rate on path
ˆ EFCI bit in data cells: set to 1 in congested switch
 if data cell preceding RM cell has EFCI set, sender sets CI
bit in returned RM cell
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-89
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP congestion control: additive increase,
multiplicative decrease
ˆ Approach: increase transmission rate (window size),
probing for usable bandwidth, until loss occurs
 additive increase: increase CongWin by 1 MSS
every RTT until loss detected
 multiplicative decrease: cut CongWin in half after
Transport Layer 3-90
8 Kbytes
16 Kbytes
24 Kbytes
time
congestion
window
loss
congestion window size
time
Saw tooth
behavior: probing
for bandwidth16
TCP Congestion Control: details
ˆ sender limits transmission:
LastByteSent-LastByteAcked
≤ CongWin
ˆ Roughly,
How does sender
perceive congestion?
ˆ loss event = timeout or
3 duplicate acks
C Wi ˆ TCP sender reduces
Transport Layer 3-91
ˆ CongWin is dynamic, function
of perceived network
congestion
ˆ TCP sender reduces
rate (CongWin) after
loss event
three mechanisms:
 AIMD
 slow start
 conservative after
timeout events
rate = CongWin
RTT Bytes/sec
TCP Slow Start
ˆ When connection begins,
CongWin = 1 MSS
 Example: MSS = 500
bytes & RTT = 200 msec
 initial rate = 20 kbps
ˆ When connection begins,
increase rate
exponentially fast until
first loss event
Transport Layer 3-92
ˆ available bandwidth may
be >> MSS/RTT
 desirable to quickly ramp
up to respectable rate
TCP Slow Start (more)
ˆ When connection
begins, increase rate
exponentially until
first loss event:
 double CongWin every
Host A
RTT
Host B
Transport Layer 3-93
g y
RTT
 done by incrementing
CongWin for every ACK
received
ˆ Summary: initial rate
is slow but ramps up
exponentially fast time
Refinement
Q: When should the
exponential
increase switch to
linear?
A: When CongWin
gets to 1/2 of its
value before
Transport Layer 3-94
timeout.
Implementation:
ˆ Variable Threshold
ˆ At loss event, Threshold is
set to 1/2 of CongWin just
before loss event
Refinement: inferring loss
ˆ After 3 dup ACKs:
 CongWin is cut in half
 window then grows
linearly
ˆ But after timeout event:
‰ 3 dup ACKs indicates
network capable of
Philosophy:
Transport Layer 3-95
ˆ But after timeout event:
 CongWin instead set to
1 MSS;
 window then grows
exponentially
 to a threshold, then
grows linearly
n w r apa f
delivering some segments
‰ timeout indicates a
“more alarming”
congestion scenario
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.
Transport Layer 3-96
congestion
ˆ 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.17
TCP sender congestion control
State Event TCP Sender Action Commentary
Slow Start
(SS)
ACK receipt
for previously
unacked
data
CongWin = CongWin + MSS,
If (CongWin > Threshold)
set state to “Congestion
Avoidance”
Resulting in a doubling of
CongWin every RTT
Congestion
Avoidance
(CA)
ACK receipt
for previously
unacked
data
CongWin = CongWin+MSS *
(MSS/CongWin)
Additive increase, resulting
in increase of CongWin by
1 MSS every RTT
Transport Layer 3-97
SS or CA Loss event
detected by
triple
duplicate
ACK
Threshold = CongWin/2,
CongWin = Threshold,
Set state to “Congestion
Avoidance”
Fast recovery,
implementing multiplicative
decrease. CongWin will not
drop below 1 MSS.
SS or CA Timeout Threshold = CongWin/2,
CongWin = 1 MSS,
Set state to “Slow Start”
Enter slow start
SS or CA Duplicate
ACK
Increment duplicate ACK count
for segment being acked
CongWin and Threshold not
changed
TCP throughput
ˆ What’s the average throughout of TCP as a
function of window size and RTT?
 Ignore slow start
ˆ Let W be the window size when loss occurs.
Transport Layer 3-98
ˆ When window is W, throughput is W/RTT
ˆ Just after loss, window drops to W/2,
throughput to W/2RTT.
ˆ Average throughout: .75 W/RTT
TCP Futures: TCP over “long, fat pipes”
ˆ Example: 1500 byte segments, 100ms RTT, want 10
Gbps throughput
ˆ Requires window size W = 83,333 in-flight
segments
ˆ Throughput in terms of loss rate:
Transport Layer 3-99
ˆ ➜ L = 2·10-10 Wow
ˆ New versions of TCP for high-speed
RTT L
1.22⋅MSS
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 Fairness
Transport Layer 3-100
bottleneck
router
capacity R
TCP
connection 2
Why is TCP fair?
Two competing sessions:
ˆ Additive increase gives slope of 1, as throughout increases
ˆ multiplicative decrease decreases throughput proportionally
R equal bandwidth share
Transport Layer 3-101
Connection 1 throughput R
congestion avoidance: additive increase
loss: decrease window by factor of 2
congestion avoidance: additive increase
loss: decrease window by factor of 2
Fairness (more)
Fairness and UDP
ˆ Multimedia apps often
do not use TCP
 do not want rate
throttled by congestion
control
ˆ Instead use UDP:
Fairness and parallel TCP
connections
ˆ nothing prevents app from
opening parallel
connections between 2
hosts.
ˆ Web browsers do this
Transport Layer 3-102
ˆ Instead use UDP:
 pump audio/video at
constant rate, tolerate
packet loss
ˆ Research area: TCP
friendly
ˆ Web browsers do this
ˆ Example: link of rate R
supporting 9 connections;
 new app asks for 1 TCP, gets
rate R/10
 new app asks for 11 TCPs,
gets R/2 !18
Chapter 3: Summary
ˆ principles behind transport
layer services:
 multiplexing,
demultiplexing
 reliable data transfer
Transport Layer 3-103
 flow control
 congestion control
ˆ instantiation and
implementation in the
Internet
 UDP
 TCP
Next:
ˆ leaving the network
“edge” (application,
transport layers)
ˆ into the network
“core”

Attachment

1
Chapter 3
Transport Layer
Transport Layer 3-1
Computer Networking:
A Top Down Approach
4th edition.
Jim Kurose, Keith Ross
Addison-Wesley, July
2007.
A note on the use of these ppt slides:
We’re making these slides freely available to all (faculty, students, readers).
They’re in PowerPoint form so you 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) in substantially unaltered form,
that you mention their source (after all, we’d like people to use our book!)
‰ If you post any slides in substantially unaltered form 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.
Thanks and enjoy! JFK/KWR
All material copyright 1996-2007
J.F Kurose and K.W. Ross, All Rights Reserved
Chapter 3: Transport Layer
Our goals:
ˆ understand principles
behind transport
layer services:
 multiplexing/demultipl
xin
ˆ learn about transport
layer protocols in the
Internet:
 UDP: connectionless
transport
Transport Layer 3-2
exing
 reliable data transfer
 flow control
 congestion control
transport
 TCP: connection-oriented
transport
 TCP congestion control
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-3
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Transport services and protocols
ˆ provide logical communication
between app processes
running on different hosts
ˆ transport protocols run in
end systems
 send side: breaks app
application
transport
network
data link
physical
Transport Layer 3-4
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
Transport vs. network layer
ˆ network layer: logical
communication
between hosts
ˆ transport layer: logical
communication
Household analogy:
12 kids sending letters to
12 kids
ˆ processes = kids
ˆ app messages = letters
Transport Layer 3-5
communication
between processes
 relies on, enhances,
network layer services
ˆ app messages = letters
in envelopes
ˆ hosts = houses
ˆ transport protocol =
Ann and Bill
ˆ network-layer protocol
= postal service
Internet transport-layer protocols
ˆ reliable, in-order
delivery (TCP)
 congestion control
 flow control
 connection setup
li bl d d
application
transport
network
data link
physical network
data link
physical
nt k
network
data link
physical
Transport Layer 3-6
ˆ unreliable, unordered
delivery: UDP
 no-frills extension of
“best-effort” IP
ˆ services not available:
 delay guarantees
 bandwidth guarantees
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical2
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-7
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Multiplexing/demultiplexing
= socket = process
delivering received segments
to correct socket
Demultiplexing at rcv host:
gathering data from multiple
sockets, enveloping data with
header (later used for
demultiplexing)
Multiplexing at send host:
Transport Layer 3-8
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P3 P2 P4 P1
host 1 host 2 host 3
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
source port # dest port #
32 bits
other header fields
Transport Layer 3-9
 each segment has source,
destination port number
ˆ host uses IP addresses & port
numbers to direct segment to
appropriate socket
application
data
(message)
TCP/UDP segment format
Connectionless demultiplexing
ˆ Create sockets with port
numbers:
DatagramSocket mySocket1 = new
DatagramSocket(12534);
DatagramSocket mySocket2 = new
DatagramSocket(12535);
ˆ When host receives UDP
segment:
 checks destination port
number in segment
 directs UDP segment to
socket with that port
Transport Layer 3-10
DatagramSocket(12535);
ˆ UDP socket identified by
two-tuple:
(dest IP address, dest port number)
socket with that port
number
ˆ IP datagrams with
different source IP
addresses and/or source
port numbers directed
to same socket
Connectionless demux (cont)
DatagramSocket serverSocket = new DatagramSocket(6428);
P2 P1P1 P3
Transport Layer 3-11
Client
IP:B
client
IP: A server
IP: C
SP: 6428
DP: 9157
SP: 9157
DP: 6428
SP: 6428
DP: 5775
SP: 5775
DP: 6428
SP provides “return address”
Connection-oriented demux
ˆ TCP socket identified
by 4-tuple:
 source IP address
 source port number
 dest IP address
ˆ Server host may support
many simultaneous TCP
sockets:
 each socket identified by
its own 4-tuple
Transport Layer 3-12
 dest port number
ˆ recv host uses all four
values to direct
segment to appropriate
socket
ˆ Web servers have
different sockets for
each connecting client
 non-persistent HTTP will
have different socket for
each request3
Connection-oriented demux
(cont)
P1 P4 P5 P6 P2 P1P3
SP: 5775
DP: 80
Transport Layer 3-13
Client
IP:B
client
IP: A server
IP: C
SP: 9157
DP: 80
SP: 9157
DP: 80
D-IP:C
S-IP: A
D-IP:C
S-IP: B
D 80
D-IP:C
S-IP: B
Connection-oriented demux:
Threaded Web Server
P1 P4 P2 P1P3
SP: 5775
DP: 80
Transport Layer 3-14
Client
IP:B
client
IP: A server
IP: C
SP: 9157
DP: 80
SP: 9157
DP: 80
D-IP:C
S-IP: A
D-IP:C
S-IP: B
D 80
D-IP:C
S-IP: B
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-15
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
UDP: User Datagram Protocol [RFC 768]
ˆ “no frills,” “bare bones”
Internet transport
protocol
ˆ “best effort” service, UDP
segments may be:
 lost
Why is there a UDP?
ˆ no connection
establishment (which can
add delay)
ˆ simple: no connection state
Transport Layer 3-16
 delivered out of order
to app
ˆ connectionless:
 no handshaking between
UDP sender, receiver
 each UDP segment
handled independently
of others
ˆ simple: no connection state
at sender, receiver
ˆ small segment header
ˆ no congestion control: UDP
can blast away as fast as
desired
UDP: more
ˆ often used for streaming
multimedia apps
 loss tolerant
 rate sensitive
ˆ other UDP uses
DNS
source port # dest port #
32 bits
length checksum
Length, in
bytes of UDP
segment,
including
h d
Transport Layer 3-17
 DNS
 SNMP
ˆ reliable transfer over UDP:
add reliability at
application layer
 application-specific
error recovery!
Application
data
(message)
UDP segment format
header
UDP checksum
Sender:
ˆ treat segment contents
f 16 bit
Receiver:
ˆ compute checksum of
i d s t
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
Transport Layer 3-18
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? More later
….4
Internet Checksum Example
ˆ Note
 When adding numbers, a carryout from the
most significant bit needs to be added to the
result
ˆ Example: add two 16-bit integers
Transport Layer 3-19
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
wraparound
sum
checksum
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-20
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-21
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-22
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Principles of Reliable data transfer
ˆ important in app., transport, link layers
ˆ top-10 list of important networking topics!
Transport Layer 3-23
ˆ characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
Reliable data transfer: getting started
send receive
rdt_send(): called from above,
(e.g., by app.). Passed data to
deliver to receiver upper layer
deliver_data(): called by
rdt to deliver data to upper
Transport Layer 3-24
send
side
receive
side
udt_send(): called by rdt,
to transfer packet over
unreliable channel to receiver
rdt_rcv(): called when packet
arrives on rcv-side of channel5
Reliable data transfer: getting started
We’ll:
ˆ incrementally develop sender, receiver sides of
reliable data transfer protocol (rdt)
ˆ consider only unidirectional data transfer
 but control info will flow on both directions!
Transport Layer 3-25
ˆ use finite state machines (FSM) to specify
sender, receiver
state
1
state
2
event causing state transition
actions taken on state transition
state: when in this
“state” next state
uniquely determined
by next event
event
actions
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
i d d t f d l i h l
Transport Layer 3-26
 receiver read data from underlying channel
Wait for
call from
above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)
extract (packet,data)
deliver_data(data)
Wait for
call from
below
rdt_rcv(packet)
sender receiver
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
Transport Layer 3-27
tells sender that pkt had errors
 sender retransmits pkt on receipt of NAK
ˆ new mechanisms in rdt2.0 (beyond rdt1.0):
 error detection
 receiver feedback: control msgs (ACK,NAK) rcvr->sender
rdt2.0: FSM specification
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
receiver
rdt_send(data)
Transport Layer 3-28
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below sender
Λ
rdt2.0: operation with no errors
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
rdt_send(data)
Transport Layer 3-29
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below
Λ
rdt2.0: error scenario
Wait for
call from
above
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
Wait for
ACK or
NAK
rdt_send(data)
Transport Layer 3-30
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && isACK(rcvpkt) Wait for
call from
below
Λ6
rdt2.0 has a fatal flaw!
What happens if
ACK/NAK corrupted?
ˆ sender doesn’t know what
happened at receiver!
ˆ can’t just retransmit:
Handling duplicates:
ˆ sender retransmits current
pkt if ACK/NAK garbled
ˆ sender adds sequence
number to each pkt
Transport Layer 3-31
possible duplicate ˆ receiver discards (doesn’t
deliver up) duplicate pkt
Sender sends one packet,
then waits for receiver
response
stop and wait
rdt2.1: sender, handles garbled ACK/NAKs
Wait for
call 0 from
above
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_send(data)
Wait for
ACK or
NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isNAK(rcvpkt) )
rdt rcv(rcvpkt) rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
Transport Layer 3-32
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
rdt_send(data)
_ ( p)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isNAK(rcvpkt) )
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt)
Wait for
call 1 from
above
Wait for
ACK or
NAK 1
Λ Λ
rdt2.1: receiver, handles garbled ACK/NAKs
sndpkt = make_pkt(NAK, chksum)
udt_send(sndpkt)
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)
udt_send(sndpkt)
Transport Layer 3-33
Wait for
0 from
below rdt_rcv(rcvpkt) &&
not corrupt(rcvpkt) &&
has_seq0(rcvpkt)
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
Wait for
1 from
below
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
not corrupt(rcvpkt) &&
has_seq1(rcvpkt)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
rdt2.1: discussion
Sender:
ˆ seq # added to pkt
ˆ two seq. #’s (0,1) will
suffice. Why?
t h k if i d
Receiver:
ˆ must check if received
packet is duplicate
 state indicates whether
0 or 1 is expected pkt
Transport Layer 3-34
ˆ must check if received
ACK/NAK corrupted
ˆ twice as many states
 state must “remember”
whether “current” pkt
has 0 or 1 seq. #
0 or s expected pkt
seq #
ˆ note: receiver can not
know if its last
ACK/NAK received OK
at sender
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
Transport Layer 3-35
NAK: retransmit current pkt
rdt2.2: sender, receiver fragments
Wait for
call 0 from
above
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,1) )
rdt rcv(rcvpkt)
Wait for
ACK
0
sender FSM
fragment
Transport Layer 3-36
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt,0)
fragment
Wait for
0 from
below
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK1, chksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
(corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)
receiver FSM
fragment
Λ7
rdt3.0: channels with errors and loss
New assumption:
underlying channel can
also lose packets (data
or ACKs)
 checksum, seq. #, ACKs,
Approach: sender waits
“reasonable” amount of
time for ACK
ˆ retransmits if no ACK
received in this time
Transport Layer 3-37
,q, ,
retransmissions will be
of help, but not enough
ˆ if pkt (or ACK) just delayed
(not lost):
 retransmission will be
duplicate, but use of seq.
#’s already handles this
 receiver must specify seq
# of pkt being ACKed
ˆ requires countdown timer
rdt3.0 sender
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
start_timer
rdt_send(data)
Wait
for
ACK0
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,1) )
rdt_rcv(rcvpkt)
&& t t( kt)
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt 1)
udt_send(sndpkt)
start_timer
timeout
rdt_rcv(rcvpkt)
Wait for
call 0from
above
Λ
Λ
Transport Layer 3-38
Wait for
call 1 from
above
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt)
start_timer
rdt_send(data)
&& notcorrupt(rcvpkt)
&& isACK(rcvpkt,0)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
isACK(rcvpkt,0) )
&& isACK(rcvpkt,1)
stop_timer
stop_timer
udt_send(sndpkt)
start_timer
timeout Wait
for
ACK1
Λ
rdt_rcv(rcvpkt)
Λ
rdt3.0 in action
Transport Layer 3-39
rdt3.0 in action
Transport Layer 3-40
Performance of rdt3.0
ˆ rdt3.0 works, but performance stinks
ˆ example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet:
Ttransmit = 8kb/pkt
10**9 b/sec = 8 microsec L (packet length in bits)
R (transmission rate, bps) =
Transport Layer 3-41
 U sender: utilization – fraction of time sender busy sending
Usender = .008
30.008 = 0.00027 L / R
RTT + L / R =
( p)
 1KB pkt every 30 msec -> 33kB/sec thruput over 1 Gbps link
 network protocol limits use of physical resources!
rdt3.0: stop-and-wait operation
first packet bit transmitted, t = 0
sender receiver
RTT
last packet bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
Transport Layer 3-42
ACK arrives, send next
packet, t = RTT + L / R
Usender = .008
30.008 = 0.00027 L / R
RTT + L / R = 8
Pipelined protocols
Pipelining: sender allows multiple, “in-flight”, yet-tobe-acknowledged
pkts
 range of sequence numbers must be increased
 buffering at sender and/or receiver
Transport Layer 3-43
ˆ Two generic forms of pipelined protocols: go-Back-N,
selective repeat
Pipelining: increased utilization
first packet bit transmitted, t = 0
sender receiver
RTT
last bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
last bit of 2nd packet arrives, send ACK
last bit of 3rd packet arrives send ACK
Transport Layer 3-44
ACK arrives, send next
packet, t = RTT + L / R
last bit of 3rd packet arrives, send ACK
Usender = .024
30.008 = 0.0008 3 * L / R
RTT + L / R =
Increase utilization
by a factor of 3!
Go-Back-N
Sender:
ˆ k-bit seq # in pkt header
ˆ “window” of up to N, consecutive unack’ed pkts allowed
Transport Layer 3-45
ˆ ACK(n): ACKs all pkts up to, including seq # n – “cumulative ACK”
 may receive duplicate ACKs (see receiver)
ˆ timer for each in-flight pkt
ˆ timeout(n): retransmit pkt n and all higher seq # pkts in window
GBN: 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++
}
else
refuse_data(data) base=1
Λ
Transport Layer 3-46
Wait start_timer
udt_send(sndpkt[base])
udt_send(sndpkt[base+1])

udt_send(sndpkt[nextseqnum-1])
timeout
base = getacknum(rcvpkt)+1
If (base == nextseqnum)
stop_timer
else
start_timer
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
base 1
nextseqnum=1
rdt_rcv(rcvpkt)
&& corrupt(rcvpkt)
GBN: receiver extended FSM
Wait
udt_send(sndpkt)
default
rdt_rcv(rcvpkt)
&& notcurrupt(rcvpkt)
&& hasseqnum(rcvpkt,expectedseqnum)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(expectedseqnum,ACK,chksum)
udt_send(sndpkt)
expectedseqnum++
expectedseqnum=1
sndpkt =
make_pkt(expectedseqnum,ACK,chksum)
Λ
Transport Layer 3-47
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 #
GBN in
action
Transport Layer 3-489
Selective Repeat
ˆ receiver individually acknowledges all correctly
received pkts
 buffers pkts, as needed, for eventual in-order delivery
to upper layer
ˆ sender only resends pkts for which ACK not
i d
Transport Layer 3-49
received
 sender timer for each unACKed pkt
ˆ sender window
 N consecutive seq #’s
 again limits seq #s of sent, unACKed pkts
Selective repeat: sender, receiver windows
Transport Layer 3-50
Selective repeat
data from above :
ˆ if next available seq # in
window, send pkt
timeout(n):
ˆ resend pkt n, restart timer
sender
pkt n in [rcvbase, rcvbase+N-1]
ˆ send ACK(n)
ˆ out-of-order: buffer
ˆ in-order: deliver (also
deliver buffered, in-order
receiver
Transport Layer 3-51
resend pkt n, restart t mer
ACK(n) in [sendbase,sendbase+N]:
ˆ mark pkt n as received
ˆ if n smallest unACKed pkt,
advance window base to
next unACKed seq #
pkts), advance window to
next not-yet-received pkt
pkt n in [rcvbase-N,rcvbase-1]
ˆ ACK(n)
otherwise:
ˆ ignore
Selective repeat in action
Transport Layer 3-52
Selective repeat:
dilemma
Example:
ˆ seq #’s: 0, 1, 2, 3
ˆ window size=3
ˆ receiver sees no
Transport Layer 3-53
difference in two
scenarios!
ˆ incorrectly passes
duplicate data as new
in (a)
Q: what relationship
between seq # size
and window size?
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-54
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control10
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
ˆ full duplex data:
 bi-directional data flow
in same connection
 MSS: maximum segment
size
ˆ point-to-point:
 one sender, one receiver
ˆ reliable, in-order byte
steam:
 no “message boundaries”
Transport Layer 3-55
ˆ connection-oriented:
 handshaking (exchange
of control msgs) init’s
sender, receiver state
before data exchange
ˆ flow controlled:
 sender will not
overwhelm receiver
 no message boundaries
ˆ pipelined:
 TCP congestion and flow
control set window size
ˆ send & receive buffers
socket
door
TCP
send buffer
TCP
receive buffer
socket
door
segment
application
writes data
application
reads data
TCP segment structure
source port # dest port #
32 bits
sequence number
acknowledgement number
Receive window
checksum Urg data pnter
UAP RSF head
len
not
used
URG: urgent data
(generally not used)
ACK: ACK #
valid
PSH: push data now
(generally not used) # bytes
illi
counting
by bytes
of data
(not segments!)
Transport Layer 3-56
application
data
(variable length)
Urg data pnter
RST, SYN, FIN: Options (variable length) connection estab
(setup, teardown
commands)
rcvr willing
to accept
Internet
checksum
(as in UDP)
TCP seq. #’s and ACKs
Seq. #’s:
 byte stream
“number” of first
byte in segment’s
data
ACKs:
# f t b t
Host A Host B
User
types
‘C’ host ACKs
receipt of
‘C’, echoes
b k ‘C’
Transport Layer 3-57
 seq # of next byte
expected from
other side
 cumulative ACK
Q: how receiver handles
out-of-order segments
 A: TCP spec doesn’t
say, – up to
implementor
host ACKs
receipt
of echoed
‘C’
back ‘C’
time
simple telnet scenario
TCP Round Trip Time and Timeout
Q: how to set TCP
timeout value?
ˆ longer than RTT
 but RTT varies
ˆ too short: premature
timeout
Q: how to estimate RTT?
ˆ SampleRTT: measured time from
segment transmission until ACK
receipt
 ignore retransmissions
ˆ SampleRTT will vary, want
Transport Layer 3-58
timeout
 unnecessary
retransmissions
ˆ too long: slow reaction
to segment loss
p y,
estimated RTT “smoother”
 average several recent
measurements, not just
current SampleRTT
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT
ˆ Exponential weighted moving average
ˆ influence of past sample decreases exponentially fast
ˆ typical value: α = 0.125
Transport Layer 3-59
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
250
300
350
onds)
Transport Layer 3-60
100
150
200
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT (milliseco
SampleRTT Estimated RTT11
TCP Round Trip Time and Timeout
Setting the timeout
ˆ EstimtedRTT plus “safety margin”
 large variation in EstimatedRTT -> larger safety margin
ˆ first estimate of how much SampleRTT deviates from
EstimatedRTT:
Transport Layer 3-61
TimeoutInterval = EstimatedRTT + 4*DevRTT
DevRTT = (1-β)*DevRTT +
β*|SampleRTT-EstimatedRTT|
(typically, β = 0.25)
Then set timeout interval:
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-62
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP reliable data transfer
ˆ TCP creates rdt
service on top of IP’s
unreliable service
ˆ Pipelined segments
ˆ Cumulative acks
ˆ Retransmissions are
triggered by:
 timeout events
 duplicate acks
ˆ Initially consider
Transport Layer 3-63
ˆ Cumulative acks
ˆ TCP uses single
retransmission timer
ˆ Initially consider
simplified TCP sender:
 ignore duplicate acks
 ignore flow control,
congestion control
TCP sender events:
data rcvd from app:
ˆ Create segment with
seq #
ˆ seq # is byte-stream
number of first data
byte in segment
timeout:
ˆ retransmit segment
that caused timeout
ˆ restart timer
Ack rcvd:
ˆ If acknowledges
Transport Layer 3-64
y g
ˆ start timer if not
already running (think
of timer as for oldest
unacked segment)
ˆ expiration interval:
TimeOutInterval
ˆ If acknowledges
previously unacked
segments
 update what is known to
be acked
 start timer if there are
outstanding segments
TCP
sender
(simplified)
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
loop (forever) {
switch(event)
event: data received from application above
create TCP segment with sequence number NextSeqNum
if (timer currently not running)
start timer
pass segment to IP
NextSeqNum = NextSeqNum + length(data)
t ti ti t
Comment:
• SendBase-1: last
cumulatively
Transport Layer 3-65
event: timer timeout
retransmit not-yet-acknowledged segment with
smallest sequence number
start timer
event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
} /* end of loop forever */
cumulatively
ack’ed byte
Example:
• SendBase-1 = 71;
y= 73, so the rcvr
wants 73+ ;
y > SendBase, so
that new data is
acked
TCP: retransmission scenarios
Host A Host B
eq=92 timeout
Host A
l
timeout
Host B
X
Transport Layer 3-66
time
premature timeout
Se
loss
lost ACK scenario time
SendBase
Seq=92 timeout
= 100
SendBase
= 120
SendBase
= 120
Sendbase
= 10012
TCP retransmission scenarios (more)
Host A
l
timeout
Host B
X
Transport Layer 3-67
loss
Cumulative ACK scenario
time
SendBase
= 120
TCP ACK generation [RFC 1122, RFC 2581]
Event at Receiver
Arrival of in-order segment with
expected seq #. All data up to
expected seq # already ACKed
A i l fi d t ith
TCP Receiver action
Delayed ACK. Wait up to 500ms
for next segment. If no next segment,
send ACK
I di t l d i l l ti
Transport Layer 3-68
Arrival of in-order segment with
expected seq #. One other
segment has ACK pending
Arrival of out-of-order segment
higher-than-expect seq. # .
Gap detected
Arrival of segment that
partially or completely fills gap
Immediately send single cumulative
ACK, ACKing both in-order segments
Immediately send duplicate ACK,
indicating seq. # of next expected byte
Immediate send ACK, provided that
segment startsat lower end of gap
Fast Retransmit
ˆ Time-out period often
relatively long:
 long delay before
resending lost packet
ˆ Detect lost segments
ˆ If sender receives 3
ACKs for the same
data, it supposes that
segment after ACKed
data was lost:
Transport Layer 3-69
gm
via duplicate ACKs.
 Sender often sends
many segments back-toback
 If segment is lost,
there will likely be many
duplicate ACKs.
 fast retransmit: resend
segment before timer
expires
event: ACK received, with ACK field value of y
if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
Fast retransmit algorithm:
Transport Layer 3-70
else {
increment count of dup ACKs received for y
if (count of dup ACKs received for y = 3) {
resend segment with sequence number y
}
a duplicate ACK for
already ACKed segment
fast retransmit
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-71
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP Flow Control
ˆ receive side of TCP
connection has a
receive buffer:
ˆ d t hi
sender won’t overflow
receiver’s buffer by
transmitting too much,
too fast
flow control
Transport Layer 3-72
ˆ speed-matching
service: matching the
send rate to the
receiving app’s drain
rate
ˆ app process may be
slow at reading from
buffer13
TCP Flow control: how it works
(S TCP i
ˆ Rcvr advertises spare
room by including value
of RcvWindow in
segments
ˆ Sender limits unACKed
Transport Layer 3-73
(Suppose TCP receiver
discards out-of-order
segments)
ˆ spare room in buffer
= RcvWindow
= RcvBuffer-[LastByteRcvd –
LastByteRead]
data to RcvWindow
 guarantees receive
buffer doesn’t overflow
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-74
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP Connection Management
Recall: TCP sender, receiver
establish “connection”
before exchanging data
segments
ˆ initialize TCP variables:
 seq. #s
 buffers, flow control
if ( R Wi d )
Three way handshake:
Step 1: client host sends TCP
SYN segment to server
 specifies initial seq #
 no data
Step 2: server host receives
YN li i h YN CK
Transport Layer 3-75
info (e.g. RcvWindow)
ˆ client: connection initiator
Socket clientSocket = new
Socket(“hostname”,”port
number”);
ˆ server: contacted by client
Socket connectionSocket =
welcomeSocket.accept();
SYN, replies with SYNACK
segment
 server allocates buffers
 specifies server initial
seq. #
Step 3: client receives SYNACK,
replies with ACK segment,
which may contain data
TCP Connection Management (cont.)
Closing a connection:
client closes socket:
clientSocket.close();
Step 1: client end system
client server
close
l
Transport Layer 3-76
Step 1: client end system
sends TCP FIN control
segment to server
Step 2: server receives
FIN, replies with ACK.
Closes connection, sends
FIN.
close
closed timed wait
TCP Connection Management (cont.)
Step 3: client receives FIN,
replies with ACK.
 Enters “timed wait” –
will respond with ACK
to received FINs
client server
closing
l i
Transport Layer 3-77
to received FINs
Step 4: server, receives
ACK. Connection closed.
Note: with small
modification, can handle
simultaneous FINs.
closing
closed timed wait
closed
TCP Connection Management (cont)
TCP server
lifecycle
Transport Layer 3-78
TCP client
lifecycle14
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-79
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
Principles of Congestion Control
Congestion:
ˆ informally: “too many sources sending too much
data too fast for network to handle”
ˆ different from flow control!
Transport Layer 3-80
ˆ manifestations:
 lost packets (buffer overflow at routers)
 long delays (queueing in router buffers)
ˆ a top-10 problem!
Causes/costs of congestion: scenario 1
ˆ two senders, two
receivers
ˆ one router,
infinite buffers
ˆ no retransmission
unlimited shared
output link buffers
Host A
λin : original data
Host B
λout
Transport Layer 3-81
ˆ large delays
when congested
ˆ maximum
achievable
throughput
Causes/costs of congestion: scenario 2
ˆ one router, finite buffers
ˆ sender retransmission of lost packet
Host A λin : original
data
λout
Transport Layer 3-82
finite shared output
link buffers
Host B
λ’
in : original data, plus
retransmitted data
Causes/costs of congestion: scenario 2
ˆ always: (goodput)
ˆ “perfect” retransmission only when loss:
ˆ retransmission of delayed (not lost) packet makes larger
(than perfect case) for same
λin
λout =
λin
λout >
λin
λout
R/2 R/2 R/2
Transport Layer 3-83
“costs” of congestion:
ˆ more work (retrans) for given “goodput”
ˆ unneeded retransmissions: link carries multiple copies of pkt
R/2 λin
λout
b.
R/2 λin
λout
a.
R/2 λin
λout
c.
R/4
R/3
Causes/costs of congestion: scenario 3
ˆ four senders
ˆ multihop paths
ˆ timeout/retransmit
λin Q: what happens as
and increase λ ? in
Host A λin : original data λout
λ’
in : original data, plus
retransmitted data
Transport Layer 3-84
finite shared output
link buffers
Host B15
Causes/costs of congestion: scenario 3
H
o
s
t
A
H
o
s
t
B
λ
o
u
t
Transport Layer 3-85
Another “cost” of congestion:
ˆ when packet dropped, any “upstream transmission
capacity used for that packet was wasted!
Approaches towards congestion control
End-end congestion
control:
ˆ no explicit feedback from
network
Network-assisted
congestion control:
ˆ routers provide feedback
to end systems
Two broad approaches towards congestion control:
Transport Layer 3-86
network
ˆ congestion inferred from
end-system observed loss,
delay
ˆ approach taken by TCP
to end systems
 single bit indicating
congestion (SNA,
DECbit, TCP/IP ECN,
ATM)
 explicit rate sender
should send at
Case study: ATM ABR congestion control
ABR: available bit rate:
ˆ “elastic service”
ˆ if sender’s path
“underloaded”:
 sender should use
RM (resource management)
cells:
ˆ sent by sender, interspersed
with data cells
ˆ bits in RM cell set by switches
Transport Layer 3-87
available bandwidth
ˆ if sender’s path
congested:
 sender throttled to
minimum guaranteed
rate
(“network-assisted”)
 NI bit: no increase in rate
(mild congestion)
 CI bit: congestion
indication
ˆ RM cells returned to sender by
receiver, with bits intact
Case study: ATM ABR congestion control
Transport Layer 3-88
ˆ two-byte ER (explicit rate) field in RM cell
 congested switch may lower ER value in cell
 sender’ send rate thus maximum supportable rate on path
ˆ EFCI bit in data cells: set to 1 in congested switch
 if data cell preceding RM cell has EFCI set, sender sets CI
bit in returned RM cell
Chapter 3 outline
ˆ 3.1 Transport-layer
services
ˆ 3.2 Multiplexing and
demultiplexing
ˆ 3 3 Connectionless
ˆ 3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
Transport Layer 3-89
ˆ 3.3 Connectionless
transport: UDP
ˆ 3.4 Principles of
reliable data transfer
f
 connection management
ˆ 3.6 Principles of
congestion control
ˆ 3.7 TCP congestion
control
TCP congestion control: additive increase,
multiplicative decrease
ˆ Approach: increase transmission rate (window size),
probing for usable bandwidth, until loss occurs
 additive increase: increase CongWin by 1 MSS
every RTT until loss detected
 multiplicative decrease: cut CongWin in half after
Transport Layer 3-90
8 Kbytes
16 Kbytes
24 Kbytes
time
congestion
window
loss
congestion window size
time
Saw tooth
behavior: probing
for bandwidth16
TCP Congestion Control: details
ˆ sender limits transmission:
LastByteSent-LastByteAcked
≤ CongWin
ˆ Roughly,
How does sender
perceive congestion?
ˆ loss event = timeout or
3 duplicate acks
C Wi ˆ TCP sender reduces
Transport Layer 3-91
ˆ CongWin is dynamic, function
of perceived network
congestion
ˆ TCP sender reduces
rate (CongWin) after
loss event
three mechanisms:
 AIMD
 slow start
 conservative after
timeout events
rate = CongWin
RTT Bytes/sec
TCP Slow Start
ˆ When connection begins,
CongWin = 1 MSS
 Example: MSS = 500
bytes & RTT = 200 msec
 initial rate = 20 kbps
ˆ When connection begins,
increase rate
exponentially fast until
first loss event
Transport Layer 3-92
ˆ available bandwidth may
be >> MSS/RTT
 desirable to quickly ramp
up to respectable rate
TCP Slow Start (more)
ˆ When connection
begins, increase rate
exponentially until
first loss event:
 double CongWin every
Host A
RTT
Host B
Transport Layer 3-93
g y
RTT
 done by incrementing
CongWin for every ACK
received
ˆ Summary: initial rate
is slow but ramps up
exponentially fast time
Refinement
Q: When should the
exponential
increase switch to
linear?
A: When CongWin
gets to 1/2 of its
value before
Transport Layer 3-94
timeout.
Implementation:
ˆ Variable Threshold
ˆ At loss event, Threshold is
set to 1/2 of CongWin just
before loss event
Refinement: inferring loss
ˆ After 3 dup ACKs:
 CongWin is cut in half
 window then grows
linearly
ˆ But after timeout event:
‰ 3 dup ACKs indicates
network capable of
Philosophy:
Transport Layer 3-95
ˆ But after timeout event:
 CongWin instead set to
1 MSS;
 window then grows
exponentially
 to a threshold, then
grows linearly
n w r apa f
delivering some segments
‰ timeout indicates a
“more alarming”
congestion scenario
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.
Transport Layer 3-96
congestion
ˆ 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.17
TCP sender congestion control
State Event TCP Sender Action Commentary
Slow Start
(SS)
ACK receipt
for previously
unacked
data
CongWin = CongWin + MSS,
If (CongWin > Threshold)
set state to “Congestion
Avoidance”
Resulting in a doubling of
CongWin every RTT
Congestion
Avoidance
(CA)
ACK receipt
for previously
unacked
data
CongWin = CongWin+MSS *
(MSS/CongWin)
Additive increase, resulting
in increase of CongWin by
1 MSS every RTT
Transport Layer 3-97
SS or CA Loss event
detected by
triple
duplicate
ACK
Threshold = CongWin/2,
CongWin = Threshold,
Set state to “Congestion
Avoidance”
Fast recovery,
implementing multiplicative
decrease. CongWin will not
drop below 1 MSS.
SS or CA Timeout Threshold = CongWin/2,
CongWin = 1 MSS,
Set state to “Slow Start”
Enter slow start
SS or CA Duplicate
ACK
Increment duplicate ACK count
for segment being acked
CongWin and Threshold not
changed
TCP throughput
ˆ What’s the average throughout of TCP as a
function of window size and RTT?
 Ignore slow start
ˆ Let W be the window size when loss occurs.
Transport Layer 3-98
ˆ When window is W, throughput is W/RTT
ˆ Just after loss, window drops to W/2,
throughput to W/2RTT.
ˆ Average throughout: .75 W/RTT
TCP Futures: TCP over “long, fat pipes”
ˆ Example: 1500 byte segments, 100ms RTT, want 10
Gbps throughput
ˆ Requires window size W = 83,333 in-flight
segments
ˆ Throughput in terms of loss rate:
Transport Layer 3-99
ˆ ➜ L = 2·10-10 Wow
ˆ New versions of TCP for high-speed
RTT L
1.22⋅MSS
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 Fairness
Transport Layer 3-100
bottleneck
router
capacity R
TCP
connection 2
Why is TCP fair?
Two competing sessions:
ˆ Additive increase gives slope of 1, as throughout increases
ˆ multiplicative decrease decreases throughput proportionally
R equal bandwidth share
Transport Layer 3-101
Connection 1 throughput R
congestion avoidance: additive increase
loss: decrease window by factor of 2
congestion avoidance: additive increase
loss: decrease window by factor of 2
Fairness (more)
Fairness and UDP
ˆ Multimedia apps often
do not use TCP
 do not want rate
throttled by congestion
control
ˆ Instead use UDP:
Fairness and parallel TCP
connections
ˆ nothing prevents app from
opening parallel
connections between 2
hosts.
ˆ Web browsers do this
Transport Layer 3-102
ˆ Instead use UDP:
 pump audio/video at
constant rate, tolerate
packet loss
ˆ Research area: TCP
friendly
ˆ Web browsers do this
ˆ Example: link of rate R
supporting 9 connections;
 new app asks for 1 TCP, gets
rate R/10
 new app asks for 11 TCPs,
gets R/2 !18
Chapter 3: Summary
ˆ principles behind transport
layer services:
 multiplexing,
demultiplexing
 reliable data transfer
Transport Layer 3-103
 flow control
 congestion control
ˆ instantiation and
implementation in the
Internet
 UDP
 TCP
Next:
ˆ leaving the network
“edge” (application,
transport layers)
ˆ into the network
“core”

Leave a Reply