115-441 Computer NetworkingLecture 18 – More TCP & Congestion ControlGood Ideas So Far…• Flow control• Stop & waitp• Parallel stop & wait• Sliding window (e.g., advertised windows)• Loss recovery• Timeouts• Acknowledgement-driven recovery (selective repeat or cumulative acknowledgement)10-30-2007Lecture 18: TCP Details 2• Congestion control• AIMD Æ fairness and efficiency• How does TCP actually implement these?Outline• THE SPOOKY PARTS of TCP•If it d s’t s it ill th Fi l!•If it doesnt scare you now… it will on the Final!• TCP connection setup/data transfer• The Candy-exchange Protocol (TCP)• TCP reliability 10-30-2007Lecture 18: TCP Details 3• How to recover your DEAD packets• TCP congestion avoidance• Avoiding the death-traps of overloaded routersSequence Number Space• Each byte in byte stream is numbered.• 32 bit value• Wraps around• Initial values selected at start up time• TCP breaks up the byte stream into packets.• Packet size is limited to the Maximum Segment Size• Each packet has a sequence number.• Indicates where it fits in the byte stream10-30-2007Lecture 18: TCP Details 4packet 8 packet 9 packet 1013450 14950 16050 175502Establishing Connection:Three-Way handshake• Each side notifies other of starting sequence number it SYN: SeqCwill use for sending• Why not simply chose 0?• Must avoid overlap with earlier incarnation• Security issues• Each side acknowledges th ’ bACK: SeqC+1SYN: SeqSACK: SeqS+110-30-2007Lecture 18: TCP Details 5other’s sequence number• SYN-ACK: Acknowledge sequence number + 1• Can combine second SYN with first ACKClient ServerTCP Connection Setup Example09:23:33.042318 IP 128.2.222.198.3123 > 192.216.219.96.80: S 4019802004:4019802004(0) win 65535 <mss 1260,nop,nop,sackOK> (DF)• Client SYN()09:23:33.118329 IP 192.216.219.96.80 > 128.2.222.198.3123: S 3428951569:3428951569(0) ack 4019802005 win 5840 <mss 1460,nop,nop,sackOK> (DF)09:23:33.118405 IP 128.2.222.198.3123 > 192.216.219.96.80: . ack 3428951570 win 65535 (DF)10-30-2007Lecture 18: TCP Details 6• SeqC: Seq. #4019802004, window 65535, max. seg. 1260• Server SYN-ACK+SYN• Receive: #4019802005 (= SeqC+1)• SeqS: Seq. #3428951569, window 5840, max. seg. 1460• Client SYN-ACK• Receive: #3428951570 (= SeqS+1)TCP State Diagram: Connection SetupCLOSEDactive OPENcreate TCBClientServerSYNSYNLISTENSnd SYN create TCBpassive OPENdelete TCBCLOSEdelete TCBCLOSEsnd SYNSENDsnd SYN ACKrcv SYNrcv SYN10-30-2007Lecture 18: TCP Details 7SENTRCVDESTABSend FINCLOSErcv ACK of SYNSnd ACKRcv SYN, ACKsnd ACKTearing Down Connection• Either side can initiate tear downAB• Send FIN signal• “I’m not going to send any more data”• Other side can continue sending data• Half open connectionMt ti t k ldFIN, SeqAACK, SeqA+1ACKData10-30-2007Lecture 18: TCP Details 8•Must continue to acknowledge• Acknowledging FIN• Acknowledge last sequence number + 1ACK, SeqB+1FIN, SeqB3TCP Connection Teardown Example09:54:17.585396 IP 128.2.222.198.4474 > 128.2.210.194.6616: F 1489294581:1489294581(0) ack 1909787689 win 65434 (DF)09 54 17 585732 IP 128 2 210 194 6616 128 2 222 198 4474 F• Session• Echo client on 128.2.222.198, server on 128.2.210.194• Client FIN09:54:17.585732 IP 128.2.210.194.6616 > 128.2.222.198.4474: F 1909787689:1909787689(0) ack 1489294582 win 5840 (DF)09:54:17.585764 IP 128.2.222.198.4474 > 128.2.210.194.6616: . ack 1909787690 win 65434 (DF)10-30-2007Lecture 18: TCP Details 9• SeqC: 1489294581• Server ACK + FIN• Ack: 1489294582 (= SeqC+1)• SeqS: 1909787689• Client ACK• Ack: 1909787690 (= SeqS+1)State Diagram: Connection Tear-downCLOSECLOSINGCLOSEWAITFINWAIT-1ESTABsnd FINCLOSEsend FINCLOSELAST-ACKFIN WAIT-2send FINCLOSEsend ACKrcv FINsnd ACKrcv FINsnd ACKrcv FIN+ACKACKActive ClosePassive Close10-30-2007Lecture 18: TCP Details 10CLOSINGTIME WAITrcv ACK of FINLASTACKCLOSEDFIN WAIT2snd ACKrcv FINdelete TCBTimeout=2mslrcv ACK of FINsnd ACKOutlineTCP ti t /d t t f•TCP connection setup/data transfer• TCP reliability10-30-2007Lecture 18: TCP Details 11• TCP congestion avoidanceReliability Challenges• Congestion related losses•Variable packet delays•Variable packet delays• What should the timeout be?• Reordering of packets• How to tell the difference between a delayed packet and a lost one?10-30-2007Lecture 18: TCP Details 124TCP = Go-Back-N Variant• Sliding window with cumulative acks• Receiver can only return a single “ack” sequence number to the dsender.• Acknowledges all bytes with a lower sequence number• Starting point for retransmission• Duplicate acks sent when out-of-order packet received • But: sender only retransmits a single packet.• Reason???• Only one that it knows is lost10-30-2007Lecture 18: TCP Details 13• Network is congested Æ shouldn’t overload it• Error control is based on byte sequences, not packets.• Retransmitted packet can be different from the original lost packet –Why?Round-trip Time Estimation• Wait at least one RTT before retransmitting•Importance of accurate RTT estimators:Importance of accurate RTT estimators:• Low RTT estimate• unneeded retransmissions• High RTT estimate• poor throughput• RTT estimator must adapt to change in RTT•But not too fast or too slow!10-30-2007Lecture 18: TCP Details 14•But not too fast, or too slow!• Spurious timeouts• “Conservation of packets” principle – never more than a window worth of packets in flightOriginal TCP Round-trip Estimator• Round trip times exponentially 22.5pyaveraged:• New RTT = α (old RTT) + (1 - α) (new sample)• Recommended value for α: 0.8 - 0.9• 0.875 for most TCP’s00.511.5R t it ti t t (b * RTT) h b 210-30-2007Lecture 18: TCP Details 15•Retransmit timer set to (b * RTT), where b = 2• Every time timer expires, RTO exponentially backed-off• Not good at preventing spurious timeouts• Why?RTT Sample AmbiguityABABXSampleRTTRTOSampleRTTRTOX10-30-2007Lecture 18: TCP Details 16• Karn’s RTT Estimator• If a segment has been retransmitted:• Don’t count RTT sample on ACKs for this segment• Keep backed off time-out for next packet• Reuse RTT estimate only after one successful transmission5Jacobson’s Retransmission Timeout• Key observation:At hi h l d d t i i i hi h•At high loads round trip variance is high• Solution:• Base RTO on RTT and standard deviation• RTO = RTT + 4 * rttvar• new rttvar = β* dev +
View Full Document