The Transport Layer TCP Timeouts and Connection management

  • Slides: 23
Download presentation
The Transport Layer: TCP Timeouts and Connection management CS 352, Lecture 11, Spring 2020

The Transport Layer: TCP Timeouts and Connection management CS 352, Lecture 11, Spring 2020 http: //www. cs. rutgers. edu/~sn 624/352 Srinivas Narayana 1

Course announcements • Project 2 will go online today • Quiz 4 will go

Course announcements • Project 2 will go online today • Quiz 4 will go online today • Due Tue 03/10 at 10 PM • Mid-term grades will be released this weekend • Papers in class on Wednesday

Review of concepts • TCP congestion control: need distributed, efficient, fair • signals (loss)

Review of concepts • TCP congestion control: need distributed, efficient, fair • signals (loss) and knobs (congestion window) • ACK clocking • Slow start • Additive increase and the slow start threshold • Multiplicative decrease • Triple duplicate ACKs and fast retransmit

TCP performs additive increase and multiplicative decrease of its congestion window. This is often

TCP performs additive increase and multiplicative decrease of its congestion window. This is often termed AIMD results in the so-called TCP sawtooth.

Why AIMD? (x 1, x 2) • Converges to fairness (b. Dx 1+a. I,

Why AIMD? (x 1, x 2) • Converges to fairness (b. Dx 1+a. I, b. Dx 2+a. I) User 2: x 2 • Can also show it converges to efficiency fairness line (b. Dx 1, b. Dx 2) • Intuition: Increments to rate get smaller as fairness increases efficiency line User 1: x 1 5

Calculating the TCP timeout

Calculating the TCP timeout

TCP timeout (RTO) • Useful for reliable delivery and congestion control • How to

TCP timeout (RTO) • Useful for reliable delivery and congestion control • How to pick the RTO value? • Too long: slow reaction to loss • Too short: premature unnecessary retransmissions • Intuition: somehow use the observed RTT (sample. RTT) • Can we just directly set the latest RTT as the RTO? • RTT can vary significantly! • Intermittent congestion, path changes, signal quality changes on wireless channel, etc.

Estimated RTT • Exponential weighted moving average (typical alpha = 1/8) Estimated. RTT =

Estimated RTT • Exponential weighted moving average (typical alpha = 1/8) Estimated. RTT = (1 - )*Estimated. RTT + *Sample. RTT (milliseconds) RTT: gaia. cs. umass. edu to fantasia. eurecom. fr sample. RTT Estimated. RTT

Timeout == estimated RTT + safety • Estimated RTT can have a large variance

Timeout == estimated RTT + safety • Estimated RTT can have a large variance • Use a larger safety margin if larger variance

Timeout == estimated RTT + safety Dev. RTT = (1 - )*Dev. RTT +

Timeout == estimated RTT + safety Dev. RTT = (1 - )*Dev. RTT + *|Sample. RTT-Estimated. RTT| (typically, = 0. 25) Timeout. Interval = Estimated. RTT + 4*Dev. RTT estimated RTT “safety margin”

Managing a single timer data rcvd from app: § create segment with seq #

Managing a single timer data rcvd from app: § create segment with seq # § seq # is byte-stream number of first data byte in segment § start timer if not already running • think of timer as for oldest unacked segment • expiration interval: Time. Out. Interval timeout: § retransmit segment that caused timeout § restart timer ack rcvd: § if acknowledges previously unacked segments • update what is known to be ACKed • restart timer if there are still unacked segments

Problem with sample. RTT calculation Sender Receiver 2 K SEQ= 0 Sender Timeout RTT?

Problem with sample. RTT calculation Sender Receiver 2 K SEQ= 0 Sender Timeout RTT? 2 K RTT? SEQ= 0 K AC =2 048

Retransmission ambiguity • If you retransmitted, how do you measure sample. RTT for it?

Retransmission ambiguity • If you retransmitted, how do you measure sample. RTT for it? • Measure RTT from original data segment? • Measure RTT from most recent (retransmitted) segment? • There could be an error in RTT estimate, since we can’t be sure • One solution • Never update RTT measurements based on acknowledgements from retransmitted packets • Problem: Sudden change in RTT, coupled with many retransmissions, can cause system to update RTT very late • Ex: Primary path failure leads to a slower secondary path 13

Karn’s algorithm • Use back-off as part of sample. RTT computation • Whenever packet

Karn’s algorithm • Use back-off as part of sample. RTT computation • Whenever packet loss, RTO is increased by a factor • Use this increased RTO as RTO estimate for the next segment (not from Estimated. RTT) • Only after an acknowledgment received for a successful transmission is the timer set to new RTT obtained from Estimated. RTT 14

Connection Management

Connection Management

Connection Management before exchanging data, sender/receiver “handshake”: • agree to establish connection • agree

Connection Management before exchanging data, sender/receiver “handshake”: • agree to establish connection • agree on connection parameters application connection state: ESTAB connection variables: seq # client-to-server-to-client rcv. Buffer size at server, client connection state: ESTAB connection Variables: seq # client-to-server-to-client rcv. Buffer size at server, client network Socket client. Socket = new. Socket("hostname", "port number"); Socket connection. Socket = welcome. Socket. accept(); 16

Agreeing to establish a connection 2 -way handshake: Let’s talk ESTAB choose x ESTAB

Agreeing to establish a connection 2 -way handshake: Let’s talk ESTAB choose x ESTAB OK ESTAB req_conn(x) acc_conn(x) ESTAB Q: will 2 -way handshake always work in network? • variable delays • retransmitted messages (e. g. req_conn(x)) due to message loss • message reordering • can’t “see” other side 17

2 -way handshake failure scenarios choose x req_conn(x) ESTAB retransmit req_conn(x) acc_conn(x) ESTAB req_conn(x)

2 -way handshake failure scenarios choose x req_conn(x) ESTAB retransmit req_conn(x) acc_conn(x) ESTAB req_conn(x) client terminates connection x completes acc_conn(x) data(x+1) retransmit data(x+1) server forgets x ESTAB half open connection! (no client!) client terminates connection x completes req_conn(x) data(x+1) accept data(x+1) server forgets x ESTAB accept data(x+1) 18

TCP 3 -way handshake client state LISTEN choose init seq num, x send TCP

TCP 3 -way handshake client state LISTEN choose init seq num, x send TCP SYN msg SYNSENT server state LISTEN SYNbit=1, Seq=x SYNbit=1, Seq=y ACKbit=1; ACKnum=x+1 choose init seq num, y send TCP SYNACK SYN RCVD msg, acking SYN received SYNACK(x) ESTAB indicates server is live; send ACK for SYNACK; this segment may contain ACKbit=1, ACKnum=y+1 client-to-server data received ACK(y) indicates client is live ESTAB 19

TCP state machine (partially shown) closed socket connection. Socket = server. Socket. accept(); L

TCP state machine (partially shown) closed socket connection. Socket = server. Socket. accept(); L SYN(x) SYNACK(seq=y, ACKnum=x+1) create new socket for communication back to client listen SYN(seq=x) SYN sent SYN rcvd ACK(ACKnum=y+1) socket client. Socket = socket. connect("hostname", "port number"); ESTAB SYNACK(seq=y, ACKnum=x+1) ACK(ACKnum=y+1) L 20

TCP: closing a connection § client, server each close their side of connection •

TCP: closing a connection § client, server each close their side of connection • send TCP segment with FIN bit = 1 • In general, TCP is full-duplex: both sides can send • But FIN is unidirectional: stop one side of the communication • respond to received FIN with ACK • on receiving FIN, ACK can be combined with own FIN § simultaneous FIN exchanges can be handled 21

TCP: closing a connection client state server state ESTAB client. Socket. close() FIN_WAIT_1 FIN_WAIT_2

TCP: closing a connection client state server state ESTAB client. Socket. close() FIN_WAIT_1 FIN_WAIT_2 can no longer send but can receive data FINbit=1, seq=x CLOSE_WAIT ACKbit=1; ACKnum=x+1 wait for server close FINbit=1, seq=y TIMED_WAIT timed wait for 2*max segment lifetime can still send data LAST_ACK can no longer send data ACKbit=1; ACKnum=y+1 CLOSED 22

TCP summary • Reliability • Ordering • Flow control • Congestion control • Timeout

TCP summary • Reliability • Ordering • Flow control • Congestion control • Timeout computation • Connection management, state machine