Presentation on theme: "1 CS492B Project #2 TCP Tutorial #1 2003. 9. 15 Jin Hyun Ju."— Presentation transcript:
1 CS492B Project #2 TCP Tutorial # Jin Hyun Ju
2 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, User Datagram Protocol (UDP), and Transmission Control Protocol (TCP) Nick McKeown Professor of Electrical Engineering and Computer Science, Stanford University
3 Outline The TCP Protocol TCP Characteristics TCP Connection setup TCP Segments TCP Sequence Numbers TCP Sliding Window ACK Policy Timeouts and Retransmission (Congestion Control and Avoidance)
4 TCP Characteristics TCP is connection-oriented. TCP provides a stream-of-bytes service. TCP is reliable: Acknowledgements indicate delivery of data. Checksums are used to detect corrupted data. Sequence numbers detect missing, or mis-sequenced data. Corrupted data is retransmitted after a timeout. Mis-sequenced data is re-sequenced. (Window-based) Flow control prevents over-run of receiver. TCP uses congestion control to share network capacity among users. We’ll study this in the next lecture.
5 TCP is connection-oriented Connection Setup 3-way handshake (Active) Client (Passive) Server Syn Syn + Ack Ack Connection Close/Teardown 2 x 2-way handshake (Active) Client (Passive) Server Fin (Data +) Ack Fin Ack TIME_WAIT CLOSED
6 TCP supports a “stream of bytes” service Byte 0Byte 1 Byte 2Byte 3 Byte 0Byte 1Byte 2Byte 3 Host A Host B Byte 80
7 …which is emulated using TCP “segments” Byte 0Byte 1 Byte 2Byte 3 Byte 0Byte 1Byte 2Byte 3 Host A Host B Byte 80 TCP Data Byte 80 Segment sent when: 1.Segment full (MSS bytes), 2.Not full, but times out, or 3.“Pushed” by application.
8 The TCP Segment Format TCP HdrTCP Data Src portDst port Sequence # Ack Sequence # HLEN 4 RSVD 6 URGACK PSH RSTSYNFIN Flags Window Size ChecksumUrg Pointer (TCP Options) TCP Data
9 Sequence Numbers Host A Host B TCP Data TCP HDR TCP HDR ISN (initial sequence number) Sequence number = 1 st byte Ack sequence number = next expected byte
10 Initial Sequence Numbers Connection Setup 3-way handshake (Active) Client (Passive) Server Syn +ISN A Syn + Ack +ISN B Ack
11 TCP Window Pipelining Retransmission Flow control (Congestion control)
12 TCP Sliding Window How much data can a TCP sender have outstanding in the network? How much data should TCP retransmit when an error occurs? Just selectively repeat the missing data? How does the TCP sender avoid over- running the receiver’s buffers?
13 TCP Sliding Window Window Size Outstanding Un-ack’d data Data OK to send Data not OK to send yet Data ACK’d Retransmission policy is “Go Back N”. Current window size is “advertised” by receiver (usually 4k – 8k Bytes when connection set-up). ACK
14 TCP Sliding Window Host A Host B ACK Window Size Round-trip time (1) RTT > Window size ACK Window Size Round-trip time (2) RTT = Window size ACK Window Size ???
15 Delayed ACK Data types in TCP segment: Bulk data (FTP, , News, HTTP) : 90% Interactive data (Telnet, Rlogin) : 10% one key-stroke generates one segment, carrying only 1 byte. 90% of Telnet & Rlogin packets carry less than 10 bytes of user data TCP can be silly without any optimization!
16 Delayed ACK Event in-order segment arrival, no gaps, everything else already ACKed in-order segment arrival, no gaps, one delayed ACK pending out-of-order segment arrival higher-than-expect seq. # gap detected arrival of segment that partially or completely fills gap TCP Receiver action delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK immediately send single cumulative ACK send duplicate ACK, indicating seq. # of next expected byte immediate ACK if segment starts at lower end of gap
17 TCP: Retransmission and Timeouts Host A Host B ACK Round-trip time (RTT) ACK Retransmission TimeOut (RTO) Estimated RTT Data1Data2 Guard Band TCP uses an adaptive retransmission timeout value: Congestion Changes in Routing RTT changes frequently
18 TCP: Retransmission and Timeouts Picking the RTO is important: Pick a values that’s too big and it will wait too long to retransmit a packet, Pick a value too small, and it will unnecessarily retransmit packets. The original algorithm for picking RTO: 1. EstimatedRTT = EstimatedRTT + (1 - ) SampleRTT 2. RTO = 2 * EstimatedRTT Characteristics of the original algorithm: Variance is assumed to be fixed. But in practice, variance increases as congestion increases.
20 TCP: Retransmission and Timeouts Karn’s Algorithm Retransmission Wrong RTT Sample Host AHost B Retransmission Wrong RTT Sample Host AHost B Problem: How can we estimate RTT when packets are retransmitted? Solution: On retransmission, don’t update estimated RTT (and double RTO).