Transport Layer: Computer Networking: A Top Down Approach
Transport Layer: Computer Networking: A Top Down Approach
Computer
Networking: A Top
Down Approach
6th edition
Jim Kurose, Keith Ross
Addison-Wesley
March 2012
3-1
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and segment structure
demultiplexing reliable data transfer
connectionless flow control
transport: UDP connection management
principles of congestion
control
TCP congestion control
3-2
Transport services and protocols
application
transport
Provide logical communication network
between app processes running data link
physical
on different hosts
Transport protocols run in end
systems
send side: breaks app messages
into segments, passes to
network layer
rcv side: reassembles segments
into messages, passes to app
layer application
More than one transport protocol transport
network
available to apps data link
physical
Internet: TCP and UDP
3-3
Transport vs. network layer
Network layer: logical communication
between hosts
3-4
Transport layer
Internet transport-layer protocols
application
Reliable, in-order transport
network
network
3-6
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and segment structure
demultiplexing reliable data transfer
connectionless flow control
transport: UDP connection management
principles of congestion
control
TCP congestion control
3-7
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket
application
3-8
How demultiplexing works
Host receives IP
datagrams 32 bits
3-11
Connection-oriented demux: example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
3-13
UDP: User Datagram Protocol [RFC 768]
“best effort” service, UDP use:
UDP segments may be: streaming multimedia
lost apps
delivered out-of-order DNS
to app SNMP
Connectionless: Reliable transfer over
no handshaking UDP:
between UDP sender,
receiver add reliability at
application layer (How?)
each UDP segment
handled independently application-specific error
of others recovery!
3-14
UDP: segment header
length, in bytes of
32 bits UDP segment,
source port # dest port # including header
length checksum
why is there a UDP?
no connection
application establishment (which can
data add delay)
(payload) simple: no connection
state at sender, receiver
small header size
UDP segment format no congestion control:
UDP can blast away as
fast as desired
3-15
Encapsulation & De-capsulation
3-16
Why we need error control at the transport
layer?
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
sender: receiver:
treat segment contents, compute checksum of
including header fields, received segment
as sequence of 16-bit check if computed
integers
checksum equals checksum
checksum: addition field value:
(one’s complement
sum) of segment NO - error detected
contents YES - no error
sender puts checksum
value into UDP
checksum field
3-18
Internet checksum: example
example: add two 16-bit integers
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
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
3-19
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and de- segment structure
multiplexing reliable data transfer
connectionless flow control
transport: UDP connection management
principles of congestion
control
TCP congestion control
3-20
TCP: Overview RFCs: 793,1122,1323, 2018, 2581
3-22
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and de- segment structure
multiplexing connection management
connectionless flow control
transport: UDP reliable data transfer
principles of congestion
control
TCP congestion control
3-23
TCP round trip time, timeout
Q: how to set TCP Q: how to estimate RTT?
timeout value? SampleRTT: measured
time from segment
longer than RTT transmission until ACK
but RTT varies receipt
too short: premature ignore retransmissions
timeout, unnecessary SampleRTT will vary, want
retransmissions estimated RTT “smoother”
average several recent
too long: slow reaction measurements, not just
to segment loss current SampleRTT
3-24
Connection Management
before exchanging data, sender/receiver “handshake”:
agree to establish connection (each knowing the other willing
to establish connection)
agree on connection parameters
3-25
Agreeing to establish a connection
2-way handshake:
Q: will 2-way handshake
always work in
network?
Let’s talk
ESTAB variable delays
OK
ESTAB retransmitted messages
(e.g. req_conn(x)) due to
message loss
can’t “see” other side
choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB
3-26
Agreeing to establish a connection
2-way handshake failure scenarios:
choose x choose x
req_conn(x) req_conn(x)
ESTAB ESTAB
retransmit acc_conn(x) retransmit acc_conn(x)
req_conn(x) req_conn(x)
ESTAB ESTAB
data(x+1) accept
req_conn(x)
retransmit data(x+1)
data(x+1)
connection connection
client x completes server x completes server
client
terminates forgets x terminates forgets x
req_conn(x)
ESTAB ESTAB
data(x+1) accept
half open connection! data(x+1)
(no client!)
3-27
TCP 3-way handshake
3-28
TCP: closing a 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
3-29
TCP: closing a connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
FIN_WAIT_2 wait for server send data
close
LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime
CLOSED
3-30
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and de- segment structure
multiplexing connection management
connectionless reliable data transfer
transport: UDP flow control
principles of congestion
control
TCP congestion control
3-31
TCP reliable data transfer
TCP creates rdt service
on top of IP’s unreliable
service
pipelined segments
cumulative acks let’s initially consider
single retransmission simplified TCP sender:
timer ignore duplicate acks
retransmissions ignore flow control,
triggered by: congestion control
timeout events
duplicate acks
3-32
TCP sender events:
data rcvd from app: timeout:
create segment with retransmit segment
seq # that caused timeout
seq # is byte-stream restart timer
number of first data ack rcvd:
byte in segment if ack acknowledges
start timer if not previously unacked
already running segments
think of timer as for update what is known
oldest unacked to be ACKed
segment
start timer if there are
expiration interval: still unacked segments
TimeOutInterval
3-33
TCP: retransmission scenarios
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
ack1 send ack1 loss
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
3-35
TCP fast retransmit
time-out period often
relatively long: TCP fast retransmit
long delay before if sender receives 3
resending lost packet ACKs for same data
detect lost segments (“triple duplicate ACKs”),
via duplicate ACKs. resend
sender often sends unacknowledged
many segments back- segment with smallest
to-back seq #
if segment is lost, there likely that unacked
will likely be many segment lost, so don’t
duplicate ACKs. wait for timeout
3-36
TCP fast retransmit
Host A Host B
ACK=100
timeout
ACK=100
ACK=100
ACK=100
Seq=100, 20 bytes of data
3-38
TCP flow control
A technique for
assuring that a
transmitting entity Flow Control
does not over-whelm
a receiving entity with Stop-and-Wait Sliding Window
data.
Stop-and-wait flow
control
Sliding window flow
control
3-39
Stop-and-wait operation
Sender transmits one packet and waits for
receiver’s response.
Receiver receives frame and replies with
acknowledgement.
Source waits for ACK before sending next
frame.
Receiver can stop flow by not send ACK.
3-40
Sliding Window operation
Allow multiple frames to be in transit.
Receiver has buffer W long.
Sender can send up to W frames without ACK.
Each frame is numbered.
ACK includes number of next frame expected.
3-41
Sliding window example
Sender Receiver
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
A3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
3
4
5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
6
A4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
3-42
Pipelined protocols
pipelining: sender allows multiple, “in-flight”, yet-
to-be-acknowledged pkts
range of sequence numbers must be increased
buffering at sender and/or receiver
3-44
GBN in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, discard,
012345678 rcv ack0, send pkt4 (re)send ack1
012345678 rcv ack1, send pkt5 receive pkt4, discard,
(re)send ack1
ignore duplicate ACK receive pkt5, discard,
(re)send ack1
pkt 2 timeout
012345678 send pkt2
012345678 send pkt3
012345678 send pkt4 rcv pkt2, deliver, send ack2
012345678 send pkt5 rcv pkt3, deliver, send ack3
rcv pkt4, deliver, send ack4
rcv pkt5, deliver, send ack5
3-45
Selective Repeat
Also called selective retransmission.
Only rejected frames are retransmitted.
Subsequent frames are accepted by the receiver
and buffered.
Minimizes retransmission but receiver must
maintain large enough buffer.
More complex as compared to G-back-n.
3-46
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,
send ack4
record ack3 arrived receive pkt5, buffer,
send ack5
pkt 2 timeout
012345678 send pkt2
012345678 record ack4 arrived
012345678 rcv pkt2; deliver pkt2,
record ack5 arrived
012345678 pkt3, pkt4, pkt5; send ack2
3-47
sender window receiver window
Selective repeat: (after receipt) (after receipt)
3-49
Principles of congestion control
congestion:
informally: “too many sources sending too much
data too fast for network to handle”
different from flow control!
manifestations:
lost packets (buffer overflow at routers)
long delays (queueing in router buffers)
a top-10 problem!
3-50
Causes/costs of congestion: scenario 1
original data: lin throughput: lout
two senders, two
receivers Host A
3-51
Causes/costs of congestion: scenario 2
one router, finite buffers
sender retransmission of timed-out packet
application-layer input = application-layer output: lin =
lout
transport-layer input includes retransmissions
Host A
idealization: perfect
knowledge
sender sends only when
router buffers available
A
no buffer space!
Host B
3-54
Causes/costs of congestion: scenario 2
Idealization: known loss
packets can be lost,
dropped at router due
to full buffers
sender only resends if
packet known to be lost
A
free buffer space!
Host B
3-55
Causes/costs of congestion: scenario 2
Realistic: duplicates
packets can be lost, dropped
at router due to full buffers
sender times out prematurely,
sending two copies, both of
which are delivered
lin
timeout
copy l'in lout
A
free buffer space!
Host B
3-56
Causes/costs of congestion: scenario 2
Realistic: duplicates
packets can be lost, dropped
at router due to full buffers
sender times out prematurely,
sending two copies, both of
which are delivered
“costs” of congestion:
more work (retrans) for given “goodput”
unneeded retransmissions: link carries multiple copies of pkt
decreasing goodput
3-57
Causes/costs of congestion: scenario 3
Host D
Host C
3-58
Causes/costs of congestion: scenario 3
3-59
Approaches towards congestion control
3-60
Outline
transport-layer connection-oriented
services transport: TCP
multiplexing and segment structure
demultiplexing reliable data transfer
connectionless flow control
transport: UDP connection management
principles of congestion
control
TCP congestion control
3-61
TCP congestion control: additive increase
multiplicative decrease
time
3-62
TCP Slow Start
Host A Host B
when connection begins,
increase rate
exponentially until first
loss event:
RTT
initially cwnd = 1 MSS
double cwnd every RTT
done by incrementing
cwnd for every ACK
received
summary: initial rate is
slow but ramps up
exponentially fast time
3-63
TCP: detecting, reacting to loss
loss indicated by timeout:
cwnd set to 1 MSS;
window then grows exponentially (as in slow start)
to threshold, then grows linearly
loss indicated by 3 duplicate ACKs: TCP RENO
dup ACKs indicate network capable of delivering
some segments
cwnd is cut in half window then grows linearly
TCP Tahoe always sets cwnd to 1 (timeout or 3
duplicate acks)
3-64
TCP: switching from slow start
Q: when should the
exponential
increase switch to
linear?
A: when cwnd gets
to 1/2 of its value
before timeout.
Implementation:
variable ssthresh
on loss event, ssthresh
is set to 1/2 of cwnd just
before loss event
3-65
Summary
principles behind
transport layer services:
multiplexing,
demultiplexing
reliable data transfer
flow control
congestion control
instantiation,
implementation in the
Internet
UDP
TCP
3-66