Question? Leave a message!




TCP Connection Management

TCP Connection Management 15
Dr.ShivJindal Profile Pic
Dr.ShivJindal,India,Teacher
Published Date:19-07-2017
Website URL
Comment
Computer Communication Networks (CCN) 1TCP: Overview • Point-to-point: – one sender, one receiver • Reliable, in-order byte steam: – no “message boundaries” – But TCP chops it up into segments for transmission internally • Pipelined (window) flow control: – Window size decided by receiver and network • Send & receive buffers Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 2TCP: Overview application application writes data reads data socket socket door door TCP TCP send buffer receive buffer segment Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 3TCP: Overview • 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 & Congestion Control: – sender will not overwhelm receiver or the network Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 4TCP 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 UAPRS F rcvr window size PSH: push data now len used bytes (generally not used) checksum ptr urgent data rcvr willing to accept RST, SYN, FIN: Options (variable length) connection estab (setup, teardown commands) application data Internet (variable length) checksum (as in UDP) Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 5TCP seq. ’s and ACKs (I) Sequence Numbers: – 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 Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 6TCP Seq. ’s and ACKs (II) Host B Host A User types ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ host ACKs receipt of echoed ‘C’ simple telnet scenario Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 7Temporal Redundancy Model Packets • Sequence Numbers • CRC or Checksum Timeout • ACKs Status Reports • NAKs, • SACKs • Bitmaps Retransmissions • Packets • FEC information Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 8Status Report Design • Cumulative acks: – Robust to losses on the reverse channel – Can work with go-back-N retransmission – Cannot pinpoint blocks of data which are lost • The first lost packet can be pinpointed because the receiver would generate duplicate acks Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 9TCP: reliable data transfer (I) event: data received from application above create, send segment • one way data transfer • no flow, congestion event: timer timeout for wait wait segment with seq y for for control retransmit segment event event event: ACK received, with ACK y ACK processing Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 1000 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 TCP: 08 pass segment to IP 09 nextseqnum = nextseqnum + length(data) 10 event: timer timeout for segment with sequence number y reliable 11 retransmit segment with sequence number y 12 compute new timeout interval for segment y 13 restart timer for sequence number y data 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 transfer (II) 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) Simplified 22 / TCP fast retransmit / 23 resend segment with sequence number y 24 restart timer for segment y TCP 25 26 / end of loop forever / sender Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 11TCP ACK generation TCP Receiver action Event in-order segment arrival, delayed ACK. Wait up to 500ms for next segment. If no next segment, no gaps, send ACK everything else already ACKed immediately send single in-order segment arrival, cumulative ACK no gaps, one delayed ACK pending out-of-order segment arrival send duplicate ACK, indicating seq. of next expected byte higher-than-expect seq. gap detected immediate ACK if segment starts arrival of segment that partially or completely fills gap at lower end of gap Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 12TCP: retransmission scenarios Host A Host B Host A Host B X loss time time premature timeout, lost ACK scenario cumulative ACKs Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 13 timeout Seq=100 timeout Seq=92 timeoutTCP Flow Control flow control receiver: explicitly sender won’t overrun informs sender of receiver’s buffers by free buffer space transmitting too much, – RcvWindow too fast field in TCP segment RcvBuffer = size or TCP Receive Buffer sender: keeps the RcvWindow = amount of spare room in Buffer amount of transmitted, unACKed data less than most recently received RcvWindow receiver buffering Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 14Timeout and RTT Estimation • Timeout: for robust detection of packet loss • Problem: How long should timeout be ? – Too long = underutilization – Too short = wasteful retransmissions – Solution: adaptive timeout: based on estimate of max RTT Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 15How to estimate max RTT? • RTT = prop + queuing delay – Queuing delay highly variable – So, different samples of RTTs will give different random values of queuing delay • Chebyshev’s Theorem: – MaxRTT = Avg RTT + kDeviation – Error probability is less than 1/(k2) – Result true for ANY distribution of samples Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 16Round Trip Time and Timeout (II) Q: how to estimate RTT? • SampleRTT: measured time from segment transmission until ACK receipt – ignore retransmissions, cumulatively ACKed segments • SampleRTT will vary wildly = want estimated RTT “smoother” – use several recent measurements, not just current SampleRTT to calculate “AverageRTT” Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 17TCP Round Trip Time and Timeout (III) AverageRTT = (1-x)AverageRTT + xSampleRTT • Exponential weighted moving average (EWMA) • influence of given sample decreases exponentially fast; x = 0.1 Setting the timeout • AverageRTT plus “safety margin” proportional to variation Timeout = AverageRTT + 4Deviation Deviation = (1-x)Deviation + xSampleRTT- AverageRTT Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 18TCP Connection Management - 1 Recall: TCP sender, receiver establish connection before exchanging data segments • initialize TCP variables: – seq. s – buffers, flow control info (e.g. RcvWindow) • client: connection initiator Socket clientSocket = new Socket("hostname","port number"); • server: contacted by client Socket connectionSocket = welcomeSocket.accept(); Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 19TCP Connection Management - 2 Three way handshake: Step 1: client end system sends TCP SYN control segment to server – specifies initial seq Step 2: server end system receives SYN, replies with SYNACK control segment – ACKs received SYN – allocates buffers – specifies server- receiver initial seq. Rensselaer Polytechnic Institute © Shivkumar Kalvanaraman & © Biplab Sikdar 20