EEC484584 Computer Networks Lecture 8 Wenbing Zhao wenbingzgmail
EEC-484/584 Computer Networks Lecture 8 Wenbing Zhao wenbingz@gmail. com (Part of the slides are based on Drs. Kurose & Ross’s slides for their Computer Networking book)
Outline n TCP q q q Segment header structure Connection management Reliable data transfer Flow control Congestion control 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP: Overview n Point-to-point: q n q q No “message boundaries” Pipelined: q n One sender, one receiver Full duplex data: Reliable, in-order byte steam: q n n TCP congestion and flow control set window size n Connection-oriented: q Send & receive buffers n Handshaking (exchange of control msgs) init’s sender, receiver state before data exchange Flow controlled: q 9/30/2020 Bi-directional data flow in same connection MSS: maximum segment size Sender will not overwhelm receiver EEC-484/584: Computer Networks Wenbing Zhao
TCP: Overview n n n TCP connection is byte stream, not message stream, no message boundaries TCP may send immediately or buffer before sending Receiver stores the received bytes in a buffer 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Segment Structure 32 bits URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) 9/30/2020 source port # dest port # sequence number acknowledgement number head not UA P R S F len used checksum Receive window Urg data pnter Options (variable length) application data (variable length) EEC-484/584: Computer Networks counting by bytes of data (not segments!) # bytes rcvr willing to accept A TCP segment must fit into an IP datagram! Wenbing Zhao
The TCP Segment Header n n Source port and destination port: identify local end points of the connection q Source and destination end points together identify the connection Sequence number: identify the byte in the stream of data that the first byte of data in this segment represents Acknowledgement number: the next sequence number that the sender of the ack expects to receive q Ack # = Last received seq num + 1 q Ack is cumulative: an ack of 5 means 0 -4 bytes have been received TCP header length – number of 32 -bit words in header 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
The TCP Segment Header n n n n URG – indicates urgent pointer field is set Urgent pointer – points to the seq num of the last byte in a sequence of urgent data ACK – acknowledgement number is valid SYN – used to establish a connection q Connection request: ACK = 0, SYN = 1 q Connection confirm: ACK=1, SYN = 1 FIN – release a connection, sender has no more data RST – reset a connection that is confused PSH – sender asked to send data immediately 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
The TCP Segment Header n n Receiver window size –number of bytes that may be sent beyond the byte acked Checksum – add the header, the data, and the conceptual pseudoheader as 16 -bit words, take 1’s complement of sum q n For more info: http: //www. netfor 2. com/tcpsum. htm http: //www. netfor 2. com/checksum. html Options – provides a way to add extra facilities not covered by the regular header q E. g. , communicate buffer sizes during set up 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Sequence Numbers and ACKs Sequence numbers: q byte stream “number” of first byte in segment’s data User types ‘C’ Seq=4 2, ACK = ACKs: q q Host B Host A seq # of next byte expected from other side cumulative ACK 79, da ta ata = d , 3 4 K= , AC q=79 Se host ACKs receipt of echoed ‘C’ = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=4 3, ACK =80 simple telnet/ssh scenario 9/30/2020 EEC-484/584: Computer Networks time Wenbing Zhao
TCP Connection Management n n TCP sender, receiver establish “connection” before exchanging data segments Initialize TCP variables: q Sequence numbers q Buffers, flow control info (e. g. Rcv. Window) Client: connection initiator Socket client. Socket = new number"); n Socket("hostname", "port Server: contacted by client Socket connection. Socket = welcome. Socket. accept(); 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Connection Management Three way handshake: Step 1: client host sends TCP SYN segment to server q q specifies initial sequence number no data Step 2: server host receives SYN, replies with SYN/ACK segment server allocates buffers q specifies server initial sequence number Step 3: client receives SYN/ACK, replies with ACK segment, which may contain data q 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Connection Management Three way handshake: n n client connect SYN segment is considered as 1 byte SYN/ACK segment is also considered as 1 byte SYN ( seq=x EEC-484/584: Computer Networks accept ) x+1) CK ( YN/A K= y, AC seq= S ACK 9/30/2020 server (seq= x+1, A CK=y +1) Wenbing Zhao
TCP Connection Management client Closing a connection: close client closes socket: client. Socket. close(); Step 1: client end system sends close FIN timed wait replies with ACK. Closes connection, sends FIN ACK TCP FIN control segment to server Step 2: server receives FIN, server ACK closed 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Connection Management client Step 3: client receives FIN, replies with ACK. q closing Enters “timed wait” - will respond with ACK to received FINs server FIN ACK closing FIN Step 4: server, receives ACK. Note: with small modification, can handle simultaneous FINs timed wait Connection closed. ACK closed 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
Exercise n A process at host A wants to establish a TCP connection with another process at host B. Assuming that host A chooses to use 1628 as the initial sequence number, and host B chooses to use 3217 as the initial sequence number for this connection, show the segments involved with the connection establishment process. You must include the following information for each such segment: (1) sequence number, (2) acknowledgement number (if applicable), (3) the SYN flag bit status, and (4) the ACK flag bit status. 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Reliable Data Transfer n n TCP creates rdt service on top of IP’s unreliable service Pipelined segments Cumulative acks TCP uses single retransmission timer n Retransmissions are triggered by: q q n Initially consider simplified TCP sender: q q 9/30/2020 timeout events duplicate acks EEC-484/584: Computer Networks ignore duplicate acks ignore flow control, congestion control Wenbing Zhao
TCP Sender Events: Data rcvd from app: n n n Create segment with sequence number seq # is byte-stream number of first data byte in segment Start retransmission timer if not already running (think of timer as for oldest unacked segment) Timeout: n n retransmit segment that caused timeout restart timer Ack rcvd: n If acknowledges previously unacked segments q q 9/30/2020 update what is known to be acked restart timer if there are outstanding segment EEC-484/584: Computer Networks Wenbing Zhao
TCP: Retransmission Scenarios Host A Host B Seq=9 timeout 2, 8 by t es dat a =100 X ACK loss Seq=9 2, 8 by t es dat a =100 ACK Send. Base = 100 time 9/30/2020 lost ACK scenario EEC-484/584: Computer Networks Wenbing Zhao
TCP: Retransmission Scenarios Host A Host B Seq=92 timeout Seq= Send. Base = 120 100, 2 0 byte Seq=9 2, 8 by t a s data es dat a 20 =1 CK A time 9/30/2020 es dat 0 10 = K 120 = C K A AC Seq=92 timeout Sendbase = 100 Send. Base = 120 2, 8 by t premature timeout EEC-484/584: Computer Networks Wenbing Zhao
TCP Retransmission Scenarios Host A Host B Seq=9 timeout 2, 8 by t Send. Base = 120 es dat a =100 K C A 00, 20 bytes data Seq=1 X loss 120 = ACK time Cumulative ACK scenario 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP ACK Generation Event at Receiver TCP Receiver action Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed Delayed ACK. Wait up to 500 ms for next segment. If no next segment, send ACK Arrival of in-order segment with expected seq #. One other segment has ACK pending Immediately send single cumulative ACK, ACKing both in-order segments Arrival of out-of-order segment higher-than-expect seq. #. Gap detected Immediately send duplicate ACK, indicating seq. # of next expected byte Arrival of segment that partially or completely fills gap Immediate send ACK, provided that segment starts at lower end of gap 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Flow Control n Receive side of TCP connection has a receive buffer: Flow control: sender won’t overflow receiver’s buffer by transmitting too much, too fast n • App process may be slow at reading from buffer 9/30/2020 EEC-484/584: Computer Networks Speed-matching service: matching the send rate to the receiving app’s drain rate Wenbing Zhao
TCP Flow Control n (Suppose TCP receiver discards outof-order segments) n Spare room in buffer = Rcv. Window = Rcv. Buffer-[Last. Byte. Rcvd Last. Byte. Read] 9/30/2020 EEC-484/584: Computer Networks Rcvr advertises spare room by including value of Rcv. Window in segments Sender limits un. ACKed data to Rcv. Window q guarantees receive buffer doesn’t overflow Wenbing Zhao
Principles of Congestion Control Congestion: n n n Informally: “too many sources sending too much data too fast for network to handle” Different from flow control! Manifestations: q lost packets (buffer overflow at routers) q long delays (queueing in router buffers) 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
Approaches towards Congestion Control Two broad approaches towards congestion control End-end congestion control: n no explicit feedback from network congestion inferred from end-system observed loss, delay approach taken by TCP 9/30/2020 Network-assisted congestion control: n routers provide feedback to end systems q single bit indicating congestion (SNA, DECbit, TCP/IP ECN, ATM) q explicit rate sender should send at EEC-484/584: Computer Networks Wenbing Zhao
TCP Congestion Control: Additive Increase, Multiplicative Decrease • Approach: increase transmission rate (window size), probing for usable bandwidth, until loss occurs – Additive increase: increase cwnd every RTT until loss detected – Multiplicative decrease: cut cwnd after loss Saw tooth behavior: probing for bandwidth 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Congestion Control n Sender limits transmission: Last. Byte. Sent-Last. Byte. Acked cwnd n Roughly, rate = n cwnd RTT Bytes/sec cwnd is dynamic, function of perceived network congestion 9/30/2020 How does sender perceive congestion? n loss event = timeout or 3 duplicate acks n TCP sender reduces rate (cwnd) after loss event EEC-484/584: Computer Networks Wenbing Zhao
TCP Slow Start n When connection begins, cwnd = 1 MSS q q n Example: MSS = 500 bytes & RTT = 200 msec Initial rate = 2. 5 k. Bps • When connection begins, increase rate exponentially fast until first loss event Available bandwidth may be >> MSS/RTT q Desirable to quickly ramp up to respectable rate 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Slow Start When connection begins, increase rate exponentially until first loss event: q q n Host A RTT n Double cwnd every RTT Done by incrementing cwnd for every ACK received Summary: initial rate is slow but ramps up exponentially fast 9/30/2020 EEC-484/584: Computer Networks Host B one segme nt two segme nts four segme nts time Wenbing Zhao
Congestion Avoidance Q: When should the exponential increase switch to linear? A: When cwnd gets to 1/2 of its value before timeout Implementation: n n Variable Threshold At loss event, Threshold is set to 1/2 of cwnd just before loss event 9/30/2020 How to increase cwnd linearly: cwnd (new) = cwnd + mss*mss/cwnd EEC-484/584: Computer Networks Wenbing Zhao
Congestion Control n After 3 duplicated ACKs: q cwnd is cut in half q q n window then grows linearly Of course, retransmit segment (i. e. , fast recovery/retransmit) But after timeout event: q cwnd instead set to 1 MSS q q Philosophy: window then grows exponentially to a threshold, then grows linearly 9/30/2020 q 3 dup ACKs indicates network capable of delivering some segments q timeout indicates a “more alarming” congestion scenario EEC-484/584: Computer Networks Wenbing Zhao
Summary: TCP Congestion Control n When cwnd is below Threshold, sender in slow-start phase, window grows exponentially n When cwnd is above Threshold, sender is in congestionavoidance phase, window grows linearly n When a triple duplicate ACK occurs, Threshold set to cwnd/2 and cwnd set to Threshold n When timeout occurs, Threshold set to cwnd/2 and cwnd is set to 1 MSS 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Sender Congestion Control State Event Slow Start (SS) ACK receipt for previously unacked data cwnd = cwnd + MSS, Congestion Avoidance ACK receipt for previously unacked data cwnd = cwnd+ MSS * (MSS/cwnd) (CA) 9/30/2020 TCP Sender Action If (cwnd > Threshold) set state to “Congestion Avoidance” EEC-484/584: Computer Networks Commentary Resulting in a doubling of Cong. Win every RTT Additive increase, resulting in increase of Cong. Win by 1 MSS every RTT Wenbing Zhao
TCP Sender Congestion Control State Event TCP Sender Action Commentary SS or CA Loss event detected by triple duplicate ACK Threshold = cwnd/2, cwnd = Threshold, Set state to “Congestion Avoidance” Fast recovery, implementing multiplicative decrease. Cong. Win will not drop below 1 MSS. SS or CA Timeout Threshold = cwnd/2, cwnd= 1 MSS, Set state to “Slow Start” Enter slow start SS or CA Duplicate ACK Increment duplicate ACK count for segment being acked Cong. Win and Threshold not changed 9/30/2020 EEC-484/584: Computer Networks Wenbing Zhao
TCP Congestion Control Slow start Segment lost 9/30/2020 Repeated acks EEC-484/584: Computer Networks Wenbing Zhao
- Slides: 35