Title: COMP 361, Fall 2000
1TCP/UPD Protocols
2TCP Feature Summary
Provides a completely reliable (no data
duplication or loss), connection-oriented,
full-duplex stream transport service that allows
two application programs to form a connection,
send data in either direction and then terminate
the connection.
3Relationship Between TCP and Other Protocols
- TCP on one computer uses IP to communicate with
TCP on another computer
4Achieving Reliability
- Reliable data transmission
- Reliable connection setup
- Reliable connection shutdown
5Reliable Data Transmission
- Positive Acknowledgement
- Receiver returns short message when data arrives
- Called an acknowledgement
- Retransmission
- Sender starts timer whenever message is
transmitted - If timer expires before acknowledgement arrives,
sender retransmits message - Use Go-BackN or Selective Repeat protocols
- Weve seen this before!
6Retransmission Illustrated
7How Long Should TCP Wait Before Retransmitting?
- Time for ACK to arrive depends on
- Distance to destination
- Current traffic conditions
- Multiple connections can be open simultaneously
- Traffic conditions change rapidly
8Important Point
The delay required for data to reach a
destination and an acknowledgement to return
depends on traffic in the internet as well as the
distance to the destination. Since it allows
multiple application programs to communicate with
multiple destinations concurrently, TCP must
handle a variety of delays that can change
rapidly.
9Solving the Retransmission Problem
- Keep estimate of round trip time on each
connection - Use current estimate to set retransmission timer
- Known as adaptive retransmission
- Key to TCPs success
10Adaptive Retransmission
- Timeout depends on current round-trip estimate
11Round-Trip Time Measurements
- Retransmission timer is set to a Retransmission
Timeout (RTO) value - RTO is calculated based on the RTT measurements
- EstimateRTT_n1 a RTT (1 a)
EstimateRTT_n - The new value of EstimateRTT_n1 is weighted
combination of the previous EstimateRTT_n and the
real measured value RTT. - For example, (it will put more weight on the
actual measurement very typical) - EstimateRTT_n1 7/8 RTT 1/8 EstimateRTT_n
12Round-Trip Time Measurements
- Retransmission timer, RTO, should be set so that
it expires only on rare occasions. - It is natural to set the RTO to be equal to
EstimateRTT_n1 plus some margin - This margin should be large when there is a lot
of fluctuation in the EstimateRTT values should
be small when there is little fluctuation. - TCP uses the following formula
- RTO_n1 EstimateRTT_n1 4RTTvariance_n1
13Round-Trip Time Measurements
- The RTTvariance is an estimate of how much RTT
typically deviates from EstimateRTT - It is calculated as follows
- RTTvariance_n1 b (RTT EstimateRTT_n1)
(1-b) RTTvariance_n - TCP uses b 0.25
14Round-Trip Time Measurements
15Karn's Algorithm
- If an ACK for a retransmitted segment is
received, the sender cannot tell if the ACK
belongs to the original or the retransmission.
- Karn' Algorithm
- Don't update EstimateRTT on any segments that
have been retransmitted. - Each time when TCP retransmits, it sets
- RTO_n1 max ( 2RTO_n, 64) (exponential backoff)
16Connection setup/release
17TCP connection management
- TCP is a connection oriented protocol
- first establish a connection
- then send data
- connection establishment three-way handshake
18TCP segment structure
A
19Startup and Shutdown
- Connection Startup
- Must be reliable
- Connection Shutdown
- Must be graceful
- Difficult
20Why Startup/Shutdown is Difficult
- Segments can be
- lost
- duplicated
- delayed
- delivered out of order
- either side can crash
- either side can reboot
- Need to avoid duplicate shutdown message from
affecting later connection
21TCPs Startup Solution
- Use three-message exchange
- Known as the 3-way handshake
- Necessary and sufficient for unambiguous,
reliable startup - SYN messages used for connection establishment
223-Way Handshake Illustrated
23TCPs Shutdown Illustrated
24Sequence numbers
- Segments are labeled with a sequence number
- Protects from out-of-order delivery
- 32-bit number
- Initial Sequence Numbers (ISNs) must be exchanged
at TCP connection establishment
25More Complete Illustration of the 3-Way Handshake
26Simple Solution (which has problems)
- CR (SeqNo x)
- Connection Request, A wants to start with SeqNo
x - ACK (SeqNo y)
- Acknowledge request, B wants to start with SeqNo
y - DATA (SeqNo x)
- Data transmission with SeqNo x
27Problems with Two-Way Handshake
- B responds to CR(SeqNo z), an old duplicate
connection requests from A - In the shown scenario, A believes that the ACK is
for the connection request CR(SeqNo x)
- Result A starts to send data with Sequence x. B
will throw the data away since it expects SeqNo
z
28Connection Termination
- A connection release should involve both sides of
the connection (otherwise data is lost) - Here B should wait after Disconnection Request
(DR) is sent until all data has arrived
29Connection Termination in 4 steps
- An elegant way to terminate connections is to
have each end shut down independently
(half-close) - If one end wants to shut down, it sends a DR
message - Four steps involved
- (1) A sends a DR to B (active close)
- (2) B ACKs the DR, (at this time B can still
send data to A) - (3) and B sends a DR to A (passive close)
- (4) A ACKs the DR
30Connection Termination in 4 steps
- To account for packet losses, a timer is needed
to limit the waiting time of a side
31Connection Termination
- B disconnects after a timeout if it does not
receive an ACK for its DR - Note B knows that both sides have sent a DR
packet hence B knows that no more data is sent
32Connection Termination
- A has a retransmission timer for sending the
first DR
33TCP Flow/Congestion Control
34TCP flow/congestion control
35TCP Flow Control
- receiver explicitly informs sender of
(dynamically changing) amount of free buffer
space - RcvWindow field in TCP segment
- sender keeps the amount of transmitted, unACKed
data less than most recently received RcvWindow
sender wont overrun receivers buffers
by transmitting too much, too fast
RcvBuffer size or TCP Receive Buffer RcvWindow
amount of spare room in Buffer
receiver buffering
36Window Advertisement Decoupling of Ack and flow
control
- Each acknowledgement carries new window
information - Called window advertisement
- Can be zero (called closed window)
- Interpretation I have received up through X and
can take Y more bytes (credit-based flow control)
37Window Advertisement
38Congestion
39TCP Congestion Control
- also makes use of window congestion window
- in case of congestion decrease window size
- if not increase window size
- rapidly upto some threshold
- then more slowly
40How does TCP handle congestion?
- congestion window
- sender uses min (congWin, recvrWin)
- Mechanism
- exponential growth (slow start)
- threshold
- linear growth
41TCP Slowstart
Host A
Host B
one segment
RTT
initialize Congwin 1 for (each segment ACKed)
Congwin until (loss event OR
CongWin gt threshold)
two segments
four segments
- exponential increase (per RTT) in window size
(not so slow!)
42TCP Congestion Avoidance
Congestion avoidance
/ slowstart is over / / Congwin gt
threshold / Until (loss event) every w
segments ACKed Congwin threshold
Congwin/2 Congwin 1 perform slowstart
43TCP Congestion Avoidance