TCP: Overview rFcs:931221323.20182581 口 point-to- point o full duplex data o one sender one receiver o bi-directional data flow D reliable, in-order byte in same connection steam: o MSS: maximum segment size o no "message boundaries 口 pipelined: g connection-oriented: o TCP congestion and flow o handshaking(exchange of control msgs init's control set window size sender receiver state 0 send receive buffers before data exchange 口 flow controlled socket writes data reads data doo I socket o sender will not overwhelm receiver ve bu seamen→ 3: Transport Layer
3: Transport Layer 3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 full duplex data: bi-directional data flow in same connection MSS: maximum segment size connection-oriented: handshaking (exchange of control msgs) init’s sender, receiver state before data exchange flow controlled: sender will not overwhelm receiver point-to-point: one sender, one receiver reliable, in-order byte steam: no “message boundaries” pipelined: TCP congestion and flow control set window size send & receive buffers socket door TCP send buffer TCP receive buffer socket door segment application writes data application reads data
TCP segment structure 32 bits URG: urgent data countin (generally not used) source port #i dest port by bytes sequence number ACK: ACK of data valid acknowledgement number (not segments!) head not PSH: push data now Rused sf rcvr window size (generally not used checksum ptr urgent data bytes rcvr willing RST SYN. FIN Options(variable length) to accept connection estab (setup, teardown commands) applicaTion Internet data checksum (variable length) (as in UDP 3: Transport Layer 3b-2
3: Transport Layer 3b-2 TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number rcvr window size checksum ptr urgent data UAP RSF head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet checksum (as in UDP)
TCP seg. *'s and ACKs Seq#'s: Host a ost b byte stream number"of first byte in segment's bes Seq=42, ACK=79, data=C data host ACKs ACKs: receipt of seq of next byte Seq=79, ACK=43, data=C'C echoes back c expected from other side host ACks o cumulative ACK receipt Q: how receiver handles of echoed Seq=43, ACK out-of-order segments o A: TCP spec doesn't say,-up to fime simple telnet scenario Implementor 3: Transport Layer 3b-3
3: Transport Layer 3b-3 TCP seq. #’s and ACKs Seq. #’s: byte stream “number” of first byte in segment’s data ACKs: seq # of next byte expected from other side cumulative ACK Q: how receiver handles out-of-order segments A: TCP spec doesn’t say, - up to implementor Host A Host B User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario
TCP: reliable data transfer event: data received from application above simplified sender, assuming create, send segment .one way data transfer no flow, congestion control wait event: timer timeout for fc segment with seq# y or event retransmit segment event: AcK received with ACK #y ACK processing 3: Transport Layer 3b-4
3: Transport Layer 3b-4 TCP: reliable data transfer simplified sender, assuming wait for event wait for event event: data received from application above event: timer timeout for segment with seq # y event: ACK received, with ACK # y create, send segment retransmit segment ACK processing •one way data transfer •no flow, congestion control
TCP 00 sendbase= initial sequence number 01 nextseqnum=initial sequence number 02 reliable 03 loop(forever)i 04 switch(event) 05 event: data received from application above data create TCP segment with sequence number nextseqnum start timer for segment next 08 transfer pass segment to IP 09 nextseqnum= nextseqnum length(data 10 event: timer timeout for segment with sequence number retransmit segment with sequence numbery compue new timeout interval for segment y Simplified restart timer for sequence number TCP 14 event: ACK received, with ACK field value of y 15 if y > sendbase)(/*cumulative ACK of all data up to y * sender 16 cancel all timers for segments with sequence numbers <y send base y 18 19 else(/* a duplicate ACK for already ACKed segment*/ increment number of duplicate ACKs received fory 21 if (number of duplicate ACKS received fory ==3 i 22 / TCP fast retransmit * 23 resend segment with sequence number restart timer for segment y 25 26)/end of loop forever*/ 3: Transport Layer 3b-5
3: Transport Layer 3b-5 TCP: reliable data transfer 00 sendbase = initial_sequence number 01 nextseqnum = initial_sequence number 02 03 loop (forever) { 04 switch(event) 05 event: data received from application above 06 create TCP segment with sequence number nextseqnum 07 start timer for segment nextseqnum 08 pass segment to IP 09 nextseqnum = nextseqnum + length(data) 10 event: timer timeout for segment with sequence number y 11 retransmit segment with sequence number y 12 compue new timeout interval for segment y 13 restart timer for sequence number y 14 event: ACK received, with ACK field value of y 15 if (y > sendbase) { /* cumulative ACK of all data up to y */ 16 cancel all timers for segments with sequence numbers < y 17 sendbase = y 18 } 19 else { /* a duplicate ACK for already ACKed segment */ 20 increment number of duplicate ACKs received for y 21 if (number of duplicate ACKS received for y == 3) { 22 /* TCP fast retransmit */ 23 resend segment with sequence number y 24 restart timer for segment y 25 } 26 } /* end of loop forever */ Simplified TCP sender
TCP ACK generation [RFC 1122, RFC 2581 Event TCP Receiver action in-order segment arrival delayed ACK. Wait up to 500ms no gaps, for next segment. If no next segment, everything else already ACKed send ACK in-order segment arrival immediately send single no gaps, cumulative ACK one delayed ACK pending out-of-order segment arrival send duplicate ACK, indicating seg. ligher-than-expect seq of next expected byte gap detected arrival of segment that immediate AcK if segment starts partially or completely fills gap at lower end of gap 3: Transport Layer 3b-6
3: Transport Layer 3b-6 TCP ACK generation [RFC 1122, RFC 2581] 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
TCP: retransmission scenarios Host A Host B e s92 8b yte lata Seq=92, 8 bytes data 20 by ACK=100 ta OSs Se 92,8 data Seq=92, 8 bytes data CK fime fime lost AcK scenario premature timeout, emulative ACKs 3: Transport Layer 3b-7
3: Transport Layer 3b-7 TCP: retransmission scenarios Host A loss timeout time lost ACK scenario Host B X Host A Seq=92 timeout time premature timeout, cumulative ACKs Host B Seq=100 timeout
TCP Flow Control flow control receiver: explicitly sender won 't overrun informs sender o receiver's buffers by (dynamically changing) transmitting too much amount of free buffer too fast space oRcv啊 indow field in RcvBuffer size or tCP Receive Buffer TCP segment RcWWindow = amount of spare room in Buffer sender: keeps the amount of transmitted Rey Window unACKed data less than most recently received data from TCP application re room RcvW主ndow process in buffer RcvBuffer receiver buffering 3: Transport Layer 3b-8
3: Transport Layer 3b-8 TCP 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 won’t overrun receiver’s buffers by transmitting too much, too fast flow control receiver buffering RcvBuffer = size or TCP Receive Buffer RcvWindow = amount of spare room in Buffer
TCP Round Trip Time and Timeout Q: how to set TCP Q: how to estimate rtt? timeout value? O SampleRTT: measured time from 口 longer than Rtt segment transmission until ACK o note: RTT will vary receipt 口 too short: premature o ignore retransmISSions, timeout cumulatively ACKed segments 口Samp1 eRTT wil‖ I vary,Want o unnecessar estimated rTT"smoother retransmissions o use several recent o too long: slow reaction to segment loss measurements, not just current SampleRTT 3: Transport Layer 3b-9
3: Transport Layer 3b-9 TCP Round Trip Time and Timeout Q: how to set TCP timeout value? longer than RTT note: RTT will vary too short: premature timeout unnecessary retransmissions too long: slow reaction to segment loss Q: how to estimate RTT? SampleRTT: measured time from segment transmission until ACK receipt ignore retransmissions, cumulatively ACKed segments SampleRTT will vary, want estimated RTT “smoother” use several recent measurements, not just current SampleRTT
TCP Round Trip Time and Timeout EstimatedrTT =(1-x)*EstimatedRTT x*SampleRTT D Exponential weighted moving average o influence of given sample decreases exponentially fast typical value of×:O.1 Setting the timeout O EstimtedrTT plus "safety margin o large variation in EstimatedrTT - larger safety margin Timeout Estimatedrtt 4*Deviation Deviation =(1-x)*Deviation x* I SamplerTT-EstimatedRTT I 3: Transport Layer 3b-10
3: Transport Layer 3b-10 TCP Round Trip Time and Timeout EstimatedRTT = (1-x)*EstimatedRTT + x*SampleRTT Exponential weighted moving average influence of given sample decreases exponentially fast typical value of x: 0.1 Setting the timeout EstimtedRTT plus “safety margin” large variation in EstimatedRTT -> larger safety margin Timeout = EstimatedRTT + 4*Deviation Deviation = (1-x)*Deviation + x*|SampleRTT-EstimatedRTT|