ACCSE CSC2B10-Chapter 3 4
ACCSE CSC2B10-Chapter 3 4
Data Communications
Chapter 3.4
Chapter 3 outline
2
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
• point-to-point: • full duplex data:
• one sender, one receiver • bi-directional data flow in same
• reliable, in-order byte steam: connection
• no “message boundaries” • MSS: maximum segment size
• pipelined: • connection-oriented:
• TCP congestion and flow control • handshaking (exchange of control
set window size msgs) inits sender, receiver state
• send & receive buffers before data exchange
application
writes data
application
reads data
• flow controlled:
socket socket
door
TCP
send buffer
TCP
receive buffer
door
• sender will not overwhelm receiver
segment
3
TCP segment structure
32 bits
URG: urgent data counting
(generally not used) source port # dest port #
by bytes
sequence number of data
ACK: ACK #
valid acknowledgement number (not segments!)
head not
PSH: push data now len used
UA P R S F Receive window
(generally not used) # bytes
checksum Urg data pnter
rcvr willing
RST, SYN, FIN: to accept
Options (variable length)
connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)
4
TCP seq. #’s and ACKs
5
TCP Round Trip Time and Timeout
Q: how to set TCP Q: how to estimate RTT?
• SampleRTT: measured time from
timeout value?
segment transmission until ACK
• longer than RTT receipt
• but RTT varies • ignore retransmissions
• too short: premature • SampleRTT will vary, want estimated
timeout RTT “smoother”
• average several recent
• unnecessary
measurements, not just current
retransmissions SampleRTT
• too long: slow reaction
to segment loss
6
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT
7
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
350
300
250
RTT (milliseconds)
200
150
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
8
TCP Round Trip Time and Timeout
Setting the timeout
• EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT -> larger safety margin
• first estimate of how much SampleRTT deviates from
EstimatedRTT:
DevRTT = (1-β)*DevRTT +
β*|SampleRTT-EstimatedRTT|
(typically, β = 0.25)
9
Chapter 3 outline
10
TCP reliable data transfer
11
TCP sender events:
data rcvd from app: timeout:
• Create segment with seq • retransmit segment that
# caused timeout
• seq # is byte-stream • restart timer
number of first data byte Ack rcvd:
in segment • If acknowledges
• start timer if not already previously unacked
running (think of timer as segments
for oldest unacked • update what is known to be
segment) acked
Seq=92 timeout
timeout
X
loss
SendBase
= 100
Seq=92 timeout
SendBase
= 120
SendBase
= 100 SendBase
= 120 premature timeout
time time
lost ACK scenario
14
TCP retransmission scenarios (more)
Host A Host B
timeout
X
loss
SendBase
= 120
time
Cumulative ACK scenario
15
TCP ACK generation [RFC 1122, RFC 2581]
16
Host A Host B
timeout
time
Figure 3.37 Resending a segment after triple duplicate ACK
17
Fast Retransmit
18
Fast retransmit algorithm:
19
Chapter 3 outline
20
TCP Flow Control
flow control
sender won’t overflow
• receive side of TCP receiver’s buffer by
connection has a receive transmitting too much,
too fast
buffer:
• speed-matching service:
matching the send rate to
the receiving app’s drain
rate
app process may be
slow at reading from
buffer
21
TCP Flow control: how it works
23
TCP Connection Management
Recall: TCP sender, receiver Three way handshake:
establish “connection” before
exchanging data segments Step 1: client host sends TCP SYN
• initialize TCP variables: segment to server
24
TCP Connection Management (cont.)
Closing a connection: client server
close
client closes socket:
clientSocket.close();
close
Step 1: client end system
sends TCP FIN control
segment to server
timed wait
Step 2: server receives FIN,
replies with ACK. Closes
closed
connection, sends FIN.
25
TCP Connection Management (cont.)
Step 3: client receives FIN, client server
timed wait
Connection closed.
closed
Note: with small modification,
can handle simultaneous FINs. closed
26
TCP Connection Management (cont)
TCP server
lifecycle
TCP client
lifecycle
27