TCP 2024
TCP 2024
TCP
Many diagrams & slides are adapted from those by J.F Kurose and K.W. Ross
Many TCP flow diagrams from Stevens’ “TCP/IP Illustrated Vol. 1” 1st ed.
2
Last Lecture
•Apps can send individual packets w/UDP; delivery is not guaranteed.
• Adds a port number and checksum to packets.
But most apps want reliable, stream-oriented transport (eg., TCP):
•Delivery confirmation & ordering is possible by sending ACKs
• After a timeout, resend packet that was not ACK’ed.
•Pipelining packets allow much better use of link capacity.
• Parallelizes ACK’ed communication
• Window size determines the number of allowed in-flight packets
•Go Back N is a simple pipelining protocol that uses cumulative ACKs.
•Selective Repeat adds buffering to the receiver to avoid unnecessary
repetition.
3
TCP is practical reliable transport
•Has evolved from 1970s through today.
•Uses positive ACKS. Combines ideas from go-back-N and selective repeat.
•Also manages connection pacing (flow & congestion control)
•Unlike UDP, TCP requires that two hosts setup a connection before
exchanging data. Why?
• Exchange initial sequence numbers for both directions of the connection.
•Choose a random initial sequence number for two reasons:
• So new packets are not confused with retransmission from prior connection.
• So an attacker cannot easily inject fake packets in the data stream.
4
TCP packet structure 32 bits
URG: urgent data counting by bytes
source port # dest port # of data
(generally not used)
sequence number (not segments!)
ACK: ACK # is valid acknowledgement number
head not
U A P R S F receive window
PSH: push data now len used
(generally not used) checksum urgent data ptr # bytes receiver is
willing to accept
RST, SYN, FIN: options (variable length)
connection establishment
(setup, teardown commands) Any TCP packet can
application data carry an ACK number,
(variable length, so ACKs can be “piggy
checksum as indicated in backed” on data
(as in UDP) flowing in the opposite
IP header)
direction.
outgoing segment from sender 5
TCP seq #s and ACKs source port # dest port #
sequence number
acknowledgement number
•Sequence Numbers: rwnd
checksum urg pointer
• Indicate the offset in the byte stream of app data …
the segment’s first byte
window size
•Cumulative ACKs: N
•Then set
(milliseconds)
timeout > EstimatedRTT
•But how much greater? RTT
STOP
sampleRTT
and EstimatedRTT
THINK
time (seconds)
9
RTT variance (jitter) also affects timeout choice
•Square points show
traffic with high variance
in RTT (high jitter)
• Should choose
timer significantly >
EstimatedRTT
•Circle points show
traffic with low variance
in RTT (low jitter)
• Can choose timer just
slightly > EstimatedRTT
10
Final RTT estimation
•Also track an exponentially-weighted moving average of RTT deviation
(jitter):
DevRTT = (1-β)*DevRTT + β*|SampleRTT-EstimatedRTT|
Typically β=0.25
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeo
ACK=100
ACK=100
X
ut
ut
timeo
ACK=100 X
ut
ACK=120 ACK=120
SendBase=120
processing delayed
time ACK
delayed
ACK
14
TCP ACK generation (RFC 1122, 2581)
Event at Receiver TCP action taken
• Arrival of in-order segment with Delayed ACK. Wait up to 500ms for
expected seq #. All data up to next segment. If no next segment,
expected seq # already ACK’ed. send ACK.
• Arrival of in-order segment with Immediately send a single
expected seq #. One other segment cumulative ACK, ACK’ing both
has ACK pending. in-order segments.
• Arrival of out-of-order segment Immediately send duplicate ACK,
(with higher-than-expect seq #). indicating seq. # of next expected
In other words, a gap was detected. byte.
• Arrival of segment that partially or Immediately send ACK if segment
completely fills gap. starts at beginning of gap.
15
TCP fast retransmit
•With using cumulative ACKs,
duplicate ACKs suggest packet loss. Seq=92, 8 bytes of data
timeout
fast retransmit immediately re-sends ACK=100
lowest un-ACK’ed segment. ACK=100