Example of TCP protocol

TCP Connection Management and tcp connection management and problem handling
Dr.GriffinWood Profile Pic
Dr.GriffinWood,United Kingdom,Teacher
Published Date:23-07-2017
Your Website URL(Optional)
TCP EECS 489 Computer Networks http://www.eecs.umich.edu/courses/eecs489/w07 Z. Morley Mao Wednesday Jan 31, 2007 1 Mao W07 Acknowledgement: Some slides taken from Kurose&Ross and Katz&Stoicaƒƒƒ ƒƒƒƒ TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 point-to-point: full duplex data: - one sender, one receiver - bi-directional data flow in same connection reliable, in-order byte steam: - MSS: maximum segment size - no “message boundaries” connection-oriented: pipelined: - handshaking (exchange of - TCP congestion and flow control msgs) init’s sender, control set window size receiver state before data send & receive buffers exchange flow controlled: - sender will not overwhelm receiver application application writes data reads data socket socket door door TCP TCP send buffer receive buffer segment 2 Mao W07TCP segment structure 32 bits URG: urgent data counting source port dest port (generally not used) by bytes sequence number of data ACK: ACK (not segments) acknowledgement number valid head not UAP R S Receive window F PSH: push data now len used bytes (generally not used) checksum Urg data pnter rcvr willing to accept RST, SYN, FIN: Options (variable length) connection estab (setup, teardown commands) application data Internet (variable length) checksum (as in UDP) 3 Mao W07Seq=42, ACK=79, data = ‘C’ Seq=43, ACK=80 TCP seq. ’s and ACKs Host A Host B Seq. ’s: - byte stream User types “number” of first byte ‘C’ in segment’s data host ACKs ACKs: receipt of ‘C’, echoes - seq of next byte back ‘C’ expected from other side host ACKs - cumulative ACK receipt Q: how receiver handles of echoed out-of-order segments ‘C’ - A: TCP spec doesn’t say, - up to time implementor simple telnet scenario 4 Mao W07 Seq=79, ACK=43, data = ‘C’ƒƒ ƒƒƒ TCP Round Trip Time and Timeout Q: how to set TCP timeout Q: how to estimate RTT? value? SampleRTT: measured time from longer than RTT segment transmission until ACK receipt - but RTT varies - ignore retransmissions too short: premature timeout SampleRTT will vary, want estimated - unnecessary RTT “smoother” retransmissions - average several recent too long: slow reaction to measurements, not just current segment loss SampleRTT 5 Mao W07TCP Round Trip Time and Timeout EstimatedRTT = (1-α)EstimatedRTT + αSampleRTT Exponential weighted moving average influence of past sample decreases exponentially fast typical value: α = 0.125 6 Mao W07Example RTT estimation: RTT: gaia.cs.umass.edu to fantasia.eurecom.fr 350 300 250 200 150 100 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106 time (seconnds) SampleRTT Estimated RTT 7 Mao W07 RTT (milliseconds)ƒƒ TCP Round Trip Time and Timeout Setting the timeout EstimtedRTT plus “safety margin” - large variation in EstimatedRTT - larger safety margin first estimate of how much SampleRTT deviates from EstimatedRTT: DevRTT = (1-β)DevRTT + βSampleRTT-EstimatedRTT (typically, β = 0.25) Then set timeout interval: TimeoutInterval = EstimatedRTT + 4DevRTT 8 Mao W07ƒƒ ƒƒƒƒ TCP reliable data transfer TCP creates rdt service on Retransmissions are top of IP’s unreliable triggered by: service - timeout events Pipelined segments - duplicate acks Cumulative acks Initially consider simplified TCP sender: TCP uses single - ignore duplicate acks retransmission timer - ignore flow control, congestion control 9 Mao W07ƒƒƒ ƒƒƒƒ TCP sender events: data rcvd from app: timeout: Create segment with seq retransmit segment that caused timeout seq is byte-stream number of first data byte in segment restart timer start timer if not already Ack rcvd: running (think of timer as for If acknowledges previously oldest unacked segment) unacked segments expiration interval: - update what is known to be TimeOutInterval acked - start timer if there are outstanding segments 10 Mao W07NextSeqNum = InitialSeqNum SendBase = InitialSeqNum TCP sender loop (forever) switch(event) (simplified) event: data received from application above create TCP segment with sequence number NextSeqNum if (timer currently not running) start timer pass segment to IP Comment: NextSeqNum = NextSeqNum + length(data) • SendBase-1: last cumulatively event: timer timeout retransmit not-yet-acknowledged segment with ack’ed byte smallest sequence number Example: start timer • SendBase-1 = 71; y= 73, so the rcvr event: ACK received, with ACK field value of y wants 73+ ; if (y SendBase) y SendBase, so SendBase = y that new data is if (there are currently not-yet-acknowledged segments) acked start timer / end of loop forever / 11 Mao W07Seq=100, 20 bytes data Seq=92, 8 bytes data Seq=92, 8 bytes data Seq=92, 8 bytes data Seq=92, 8 bytes data TCP: retransmission scenarios Host A Host A Host B Host B X loss Sendbase = 100 SendBase = 120 SendBase SendBase = 100 = 120 premature timeout time time lost ACK scenario 12 Mao W07 ACK=100 ACK=100 ACK=120 ACK=120 ACK=100 timeout Seq=92 timeout Seq=92 timeoutSeq=92, 8 bytes data Seq=100, 20 bytes data TCP retransmission scenarios (more) Host A Host B X loss SendBase = 120 time Cumulative ACK scenario 13 Mao W07 ACK=120 ACK=100 timeoutTCP ACK generation RFC 1122, RFC 2581 TCP Receiver action Event at Receiver Arrival of in-order segment with Delayed ACK. Wait up to 500ms for next segment. If no next segment, expected seq . All data up to send ACK expected seq already ACKed Immediately send single cumulative Arrival of in-order segment with expected seq . One other ACK, ACKing both in-order segments segment has ACK pending Arrival of out-of-order segment Immediately send duplicate ACK, indicating seq. of next expected byte higher-than-expect seq. . Gap detected Immediate send ACK, provided that Arrival of segment that partially or completely fills gap segment startsat lower end of gap 14 Mao W07ƒ ƒƒ Fast Retransmit If sender receives 3 ACKs for Time-out period often the same data, it supposes relatively long: that segment after ACKed data - long delay before was lost: resending lost packet - fast retransmit: resend Detect lost segments via segment before timer expires duplicate ACKs. - Sender often sends many segments back-to-back - If segment is lost, there will likely be many duplicate ACKs. 15 Mao W07Fast retransmit algorithm: event: ACK received, with ACK field value of y if (y SendBase) SendBase = y if (there are currently not-yet-acknowledged segments) start timer else increment count of dup ACKs received for y if (count of dup ACKs received for y = 3) resend segment with sequence number y a duplicate ACK for fast retransmit already ACKed segment 16 Mao W07ƒ ƒ TCP Flow Control flow control sender won’t overflow receive side of TCP receiver’s buffer by connection has a receive transmitting too much, buffer: too fast speed-matching service: matching the send rate to the receiving app’s drain rate app process may be slow at reading from buffer 17 Mao W07ƒƒ ƒ TCP Flow control: how it works Rcvr advertises spare room by including value of RcvWindow in segments Sender limits unACKed data to RcvWindow - guarantees receive buffer doesn’t overflow (Suppose TCP receiver discards out-of-order segments) spare room in buffer = RcvWindow = RcvBuffer-LastByteRcvd - LastByteRead 18 Mao W07ƒƒƒ TCP Connection Management Three way handshake: Recall: TCP sender, receiver establish “connection” before Step 1: client host sends TCP exchanging data segments SYN segment to server initialize TCP variables: - specifies initial seq - seq. s - no data - buffers, flow control info (e.g. RcvWindow) Step 2: server host receives SYN, replies with SYNACK segment client: connection initiator Socket clientSocket = new - server allocates buffers Socket("hostname","port - specifies server initial seq. number"); Step 3: client receives SYNACK, server: contacted by client replies with ACK segment, Socket connectionSocket = which may contain data welcomeSocket.accept(); 19 Mao W07FIN ACK TCP Connection Management (cont.) client server Closing a connection: close client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control close segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. closed 20 Mao W07 ACK FIN timed wait

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.