Presentation is loading. Please wait.

Presentation is loading. Please wait.

Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 1 Transmission Control Protocol (TCP), Tahir Azim.

Similar presentations


Presentation on theme: "Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 1 Transmission Control Protocol (TCP), Tahir Azim."— Presentation transcript:

1 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 1 Transmission Control Protocol (TCP), Tahir Azim

2 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 2 The Need for TCP  Network Layer (IP) provides a best-effort service  Need to build a reliable layer on top of IP  Possible problems sending messages from one host to another:  May be lost  May be reordered  May be delivered multiple times  May be delivered after a long delay  May be broken into smaller messages  May be corrupted

3 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 3 Need for TCP 2  Support services needed by the application  Multiple connections per host  Guaranteed delivery  Messages delivered in the order they were sent  Messages delivered at most once  No limit on message size  Messages not corrupted  Synchronization between sender and receiver  Flow control

4 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 4 Can this be done hop-by-hop instead of end-to-end?  Think of this like the postal service  One major problem: Nodes would not know what happened two or more hops ahead of them  Routing tables incorrect, packets dropped, machine crashed, link failed…  Only ends can be sure of receipt/non-receipt of a message  For others: read “End-to-end arguments for System Design”… Classic, must-read paper, could be on exam

5 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 5 TCP Usage Model  Connection setup  3-way handshake  Data transport  Sender writes data  TCP  Breaks data into segments Sends each segment over IP Retransmits, reorders and removes duplicates as necessary Receiver reads some data  Teardown  4 step exchange

6 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 6 TCP Characteristics  TCP is connection-oriented.  3-way handshake used for connection setup.  TCP provides a stream-of-bytes service.  TCP is full-duplex; data can flow in both directions simultaneously  TCP is reliable:  Acknowledgements indicate delivery of data.  Checksums are used to detect corrupted data.  Detects missing sequence numbers or mis-sequenced data.  Corrupted data is retransmitted after a timeout.  Out of order bytes of data are reordered.  (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 lectures.

7 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 7 TCP is connection-oriented Connection Setup 3-way handshake (Active) Client (Passive) Server Syn (ISN A ) Syn (ISN B ) + Ack (ISN A +1) Ack (ISN B +1) Connection Close/Teardown 2 x 2-way handshake (Active) Client (Passive) Server Fin (SN A ) (Data +) Ack (SN A +1) Fin (SN B ) Ack (SN B +1)

8 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 8 TCP supports a “stream of bytes” service Byte 0Byte 1 Byte 2Byte 3 Byte 0Byte 1Byte 2Byte 3 Host A Host B Byte 80

9 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 9 …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, default 352), 2.Not full, but times out, or 3.“Pushed” by application.

10 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 10 The TCP Segment Format IP Hdr IP Data TCP HdrTCP Data Src portDst port Sequence # Ack Sequence # HLEN 4 RSVD 6 URGACK PSH RSTSYNFIN Flags Window Size ChecksumUrg Pointer (TCP Options) 01531 TCP Data

11 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 11 TCP Segment Header  16-bit source and destination ports  32-bit send and ACK sequence numbers  4-bit header length in 4-byte words  Minimum value of 5  Offset to first data byte  6 1-bit flags  URG: Segment contains urgent data  ACK: ACK sequence number is valid  PSH: Do not delay delivery of data  RST: Reset connection (reject or abn. termination)  SYN: Synchronize segment for setup  FIN: Final segment for teardown

12 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 12 TCP Segment header  16-bit advertised window  Space remaining in receive window  16-bit checksum  Uses IP checksum algorithm  Computed on header and data  16-bit urgent data pointer  If URG = 1  Index of last byte of urgent data in segment

13 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 13 TCP Options  Negotiate maximum segment size (MSS)  Each host suggests a value  Minimum of two values is chosen  Prevents IP fragmentation over first and last hops  Packet timestamp  Allows RTT calculation for retransmitted packets  Extends sequence number space for identification of stray packets  Negotiate advertised window granularity  Allows windows to be scaled to larger sizes  Good for routes with large bandwidth-delay products

14 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 14 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

15 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 15 TCP State Transition Diagram  Original ASCII art diagram in RFC 793

16 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 16 TCP State Descriptions CLOSEDDisconnected LISTENWaiting for incoming connection SYN_RCVDConnection request received SYN_SENTConnection request sent ESTABLISHEDConnection ready for data transport CLOSE_WAITConnection closed by peer LAST_ACKConnection closed by peer, closed locally, await ACK FIN_WAIT_1Connection closed locally FIN_WAIT_2Connection closed locally and ACK’d CLOSING Connection closed by both sides simultaneously TIME_WAIT Wait for network to discard related packets

17 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 17 TCP State Transition Diagram

18 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 18 TCP State Transition Diagram

19 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 19 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?

20 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 20 TCP Sliding Window Window Size Outstanding Un-ack’d data Data OK to send Data not OK to send yet Data ACK’d  Window is meaningful to the sender.  Current window size is “advertised” by receiver (usually 4k – 8k Bytes when connection set-up).  TCP’s Retransmission policy is “Go Back N”.

21 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 21 TCP Sliding Window Protocol – Sender Side  Variables:  LastByteAcked: The last byte acked by receiver  LastByteSent: The last byte sent by sender  LastByteWritten: The last byte written by application layer onto the transport layer  LastByteAcked <= LastByteSent  LastByteSent <= LastByteWritten  Buffer bytes between LastByteAcked and LastByteWritten

22 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 22 TCP Sliding Window Protocol – Receiver Side  Variables:  LastByteRcvd: The last byte received by receiver  NextByteExpected : The next byte still to be received from the sender  LastByteRead: The last byte passed to the application layer by the transport layer  LastByteRead < NextByteExpected  NextByteExpected <= LastByteRcvd + 1  Buffer bytes between LastByteRead and LastByteRcvd

23 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 23 TCP Flow Control  Receiving side  Receive buffer size = MaxRcvBuffer  LastByteRcvd - LastByteRead < = MaxRcvBuffer  AdvertisedWindow= MaxRcvBuffer - (NextByteExpected - LastByteRead) Shrinks as data arrives and Grows as the application consumes data  Sending side  Send buffer size = MaxSendBuffer  LastByteSent - LastByteAcked < = AdvertisedWindow  EffectiveWindow = AdvertisedWindow - (LastByteSent – LastByteAcked) EffectiveWindow > 0 to send data  LastByteWritten - LastByteAcked < = MaxSendBuffer  block sender if (LastByteWritten – LastByteAcked) > MaxSenderBuffer

24 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 24 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 ???

25 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 25 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

26 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 26 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 k =  EstimatedRTT k-1 + (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. Determined empirically

27 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 27 TCP: Retransmission and Timeouts  There will be some (unknown) distribution of RTTs.  We are trying to estimate an RTO to minimize the probability of a false timeout. RTT Probability mean variance Load (Amount of traffic arriving to router) Average Queueing Delay Variance grows rapidly with load  Router queues grow when there is more traffic, until they become unstable.  As load grows, variance of delay grows rapidly.

28 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 28 TCP: Retransmission and Timeouts Newer Algorithm includes estimate of variance in RTT:  Difference = SampleRTT - EstimatedRTT  EstimatedRTT k = EstimatedRTT k-1 + (  *Difference)  Deviation = Deviation +  *( |Difference| - Deviation )  RTO =  * EstimatedRTT +  * Deviation   1   4 Same as before

29 Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 29 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).


Download ppt "Courtesy: Nick McKeown, Stanford Umar Kalim, NIIT Robin Kravets, UIUC 1 Transmission Control Protocol (TCP), Tahir Azim."

Similar presentations


Ads by Google