TCP/IP Family of Protocols (cont.) TCP: Transmission Control Protocol UDP: User Datagram Protocol www.comnets.uni-bremen.de TCP - 1
Layer 4 Addressing: Port Numbers To talk to another port, a sender needs to know both the IP address and the port number at the destination Each message must carry destination IP and destination port number, as well as the source IP and source port number www.comnets.uni-bremen.de TCP - 2
What is TCP? TCP is the reliable transport protocol of TCP/IP TCP is an Automatic Repeat request (ARQ), Continuous RQ (packets are continually sent), protocol TCP utilizes acknowledgements (ACKs) TCP maintains a sliding window TCP maintains a retransmission timeout TCP uses flow and congestion control Computer Networking: A Top Down Approach Jim Kurose, Keith Ross Chapter 3: Transport Layer www.comnets.uni-bremen.de TCP - 3
Flow Control vs Congestion Control Andrew S. Tanenbaum: Computer Networks Flow control: avoid flooding the receiver Fig.(a) Congestion control: avoid flooding the network - Fig.(b) Causes of congestion in the network? www.comnets.uni-bremen.de TCP - 4
Structure of a TCP-segment Bit 0 4 8 16 32 Octet Source Port Destination Port 4 Sequence Number 8 12 Data Offset Reserved U R G Acknowledgement Number A C K P SH R ST S YN F IN buffer size of sending node used as an indication of what the node is willing to accept (advertised window size/max. window size) Window 16 Checksum Urgent Pointer 20 Options Padding Data Original TCP RFC 793, Extension for TCP is given in RFC 1323 www.comnets.uni-bremen.de TCP - 5
Code Bit (Flag) Settings URG: The data contained within this packet is urgent (i.e. keystroke data). The urgent pointer field is active and valid. ACK: The acknowledgment field is valid. PSH: Forces an immediate pushing of all data through lower layers to transmit or the pushing of all data from the transport layers to the upper layer protocols. This feature circumvents TCP s typical collection routines that may hold data before releasing to higher or lower layers if other processes are underway. RST: Reset the connection. This occurs when some unexpected event interferes with communication. SYN: Synchronize the sequence numbers. This bit initiates a communication relationship. The sender will send a packet with this code active. The receiver will acknowledge with a properly sequenced acknowledgment and its own sequence number. The sender will then respond with its own properly sequenced acknowledgment to begin the communication. FIN: Data transmission is finished. This connection is a candidate at for termination. n. www.comnets.uni-bremen.de TCP - 6
Sliding Window The window size represents the maximum amount of unacknowledged packets on flight at any given time The Sliding Window Algorithm is: Transmit all new segments according to window Wait W for acknowledgement Slide the window www.comnets.uni-bremen.de TCP - 7
Sliding Window (cont.)...3 2 1 0 [0 1 2 3] 4 5 6 7 8 9 ---------------> ACK0... (slide window) <--------------...4 0 [1 2 3 4] 5 6 7 8 9 -------------->... ACK4... (slide window) <--------------...8 7 6 5 0 1 2 3 4 [5 6 7 8] 9 --------------> www.comnets.uni-bremen.de TCP - 8
TCP Sliding Window ACKed Not ACKed 0 1 2 3 4 5 6 7 8 9 Already sent Can send Cannot send lastsegmentsent LastSegmentAcked min(cwnd, rvwnd) lastbytesent LastByteAcked min(cwnd, rvwnd) Receiver s advertised window (rwnd) Receiver-side limit on amount of data that can be sent Size advertised d by receiver Congestion window (cwnd) Sender-side limit on amount of data that can be sent Size determined by congestion control algorithms www.comnets.uni-bremen.de TCP - 9
Reaching Equilibrium P r P b Bandwidth Sender P b Receiver A s A r Time www.comnets.uni-bremen.de TCP - 10
Reaching Equilibrium (cont.) A connection is said to have reached equilibrium when: Transmitted data acquires an inter-packet spacing equal to the transmission time of the packets on the slowest link in the path www.comnets.uni-bremen.de TCP - 11
TCP - Round Trip Time Control is based on the Round Trip Time, RTT (Average) Round-Trip-Time Ti Ti estimations i RTT:=α*old_RTT + (1 - α)*new_round_trip_sample 0 α < 1, e.g. α:=0.9 α close to 1: reacts slowly to changes α close to 0: reacts quickly to changes New_Round_Trip_Sample: measured as the time between sending a segment and receiving the acknowledgement www.comnets.uni-bremen.de TCP - 12
TCP Timeout Value & Karn s Algorithm TCP timeout value TimeOut timeout:= β * RTT is based on Round-Trip-Time (RTT) estimations Seg (n) Ack (n+1) In the event of retransmission, TCP is unable to distinguish between ACKs for the same sequence number. Measured RTT Seg (n) Ack (n+1) Karn suggested to cease RTT estimations during TCP timeouts. www.comnets.uni-bremen.de TCP - 13
TCP Congestion Control End-to-end No explicit assistance from network Congestion state inferred by network observation (loss, delay) Congestion assumed if Triple duplicate ACK (4 ACKs with same seq. no.) Timeout: no ACK received for predefined time Algorithms [RFC5681]: Slow Start Congestion Avoidance Fast Retransmit Fast Recovery www.comnets.uni-bremen.de TCP - 14
Slow-Start Aims to identify link capacity Algorithm Description: 1. Start sending one packet 2. For each ACK received, send two packets Slow-Start forces an exponential increase of cwnd (congestion window size) cwnd doubles after approx. RTT cwnd reaches maximum size (MaxWin) in RTT*log 2 (MaxWin) www.comnets.uni-bremen.de TCP - 15
Congestion Avoidance (state) Congestion Avoidance is always implemented with Slow-Start: When an ACK is received: if (cwnd <= ssthresh) cwnd += 1; else cwnd += 1/cwnd; If a timeout occurs: ssthresh=cwnd/2; cwnd=1 AIMD: Additive Increase and Multiplicative Decrease www.comnets.uni-bremen.de TCP - 16
TCP Congestion Control ssthresh cwnd in seg gments 14 12 10 8 6 congestion avoidance Time out congestion avoidance ssthresh = cwnd/2 4 2 slow start slow start 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Transmission Round Aims to preserve equilibrium: if cwnd <= ssthresh slow start else congestion avoidance Endif www.comnets.uni-bremen.de TCP - 17
Fast Retransmit Aims to avoid long timeout intervals TCP may only acknowledge in order received packets TCP does not utilize NACKs In the event of single packet loss all subsequent packets are received out-of-orderof order TCP responds with duplicate ACKs (dupacks) If the dupacks exceed a threshold, TCP responds with retransmission without prior timeout Fast Retransmit is succeeded by Slow-Start www.comnets.uni-bremen.de TCP - 18
Fat Retransmit and Fast Recovery Aims at a faster window recovery Fast Recovery dictates that Fast Retransmit should be followed by Congestion Avoidance: When a dupack is received: if (dupack = 3) { retransmit(last); ssthresh = min(cwnd,advwnd)/2; cwnd = ssthresh + 3; else cwnd += 1/cwnd; When an ACK for retransmitted segment is received: cwnd = ssthresh; Se egment Sent 56 57 58 59 60 ACK received 57 58 58 58 61 58 58 62 www.comnets.uni-bremen.de TCP - 19
Fast Retransmit and Fast Recovery ssthresh cwnd in seg gments 14 12 10 8 congestion avoidance 3 DupAcks congestion avoidance 6 ssthresh = cwnd/2 4 2 slow start 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Transmission Round How comes 3 DupAcks? www.comnets.uni-bremen.de TCP - 20
TCP Flavors: Reno & Tahoe www.comnets.uni-bremen.de TCP - 21
TCP A Opening a TCP-connection TCP B 3-Way Handshake Protocol www.comnets.uni-bremen.de TCP - 22
2K Segment TCP Data Transmission Receiver Buffer (rwnd) 0K 4K Empty 2K 3K from App For simplicity, initial seq. num is set to 0 www.comnets.uni-bremen.de TCP - 23
TCP A Closing a TCP-connection TCP B Sends segment with activated FIN Flag Connection from A to B closed Receives FIN segment and informs application layer Sends confirmation Sends segment with activated FIN Flag Receives FIN segment and confirms receipt Connection from B to A closed www.comnets.uni-bremen.de TCP - 24
TCP: finite state machine/ state transition diagram begin passive open syn/syn + ack anything/reset CLOSED close active open/syn (1) LISTEN SYN RECVD reset ack send/syn syn/syn + ack syn + ack/ack (2) SYN SENT close/ time out/ reset A connection starts with the state CLOSED. Input/Output denotes the input causing a state transition and the output generated. FIN WAIT-1 close/fin close/fin fin/ack ESTAB- LISHED CLOSING fin/ack (3) close/fin CLOSE WAIT LAST ACK ack/ ack/ FIN WAIT-2 fin/ack ack/ TIME WAIT timeout after 2 segment lifetimes www.comnets.uni-bremen.de TCP - 25
4.3BSD Tahoe Slow-start with Congestion Avoidance 100 90 Congestion Window Slow-start t Threshold h 80 70 60 Packets 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 Time (seconds) www.comnets.uni-bremen.de TCP - 26
4.3BSD Tahoe Packet Trace 2500 TCP Packet Dropped Packets 2000 (Sequence Numb TCP Packets er) 1500 1000 500 0 0 10 20 30 40 50 60 70 80 90 100 Time (seconds) www.comnets.uni-bremen.de TCP - 27
4.3BSD Reno 4.3BSD Tahoe with Fast Retransmit & Recovery 100 90 Congestion Window Slow-start t Threshold h 80 70 60 Packets 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 Time (seconds) www.comnets.uni-bremen.de TCP - 28
4.3BSD Reno Packet Trace 2500 TCP Packet Dropped Packets 2000 (Sequence Numb TCP Packets er) 1500 1000 500 0 0 10 20 30 40 50 60 70 80 90 100 Time (seconds) www.comnets.uni-bremen.de TCP - 29
www.comnets.uni-bremen.de TCP - 30
Summary: TCP 3-way handshake h Reliable transport Sequence numbers Acknowledgements Timers TCP Flow Control Prevent overload at receiver Use sliding window, self-clocking TCP Congestion Control Prevent overload in network, ensure fairness Adapt sending rate based on observed congestion www.comnets.uni-bremen.de TCP - 31
Problems with TCP TCP provokes packet losses to get an idea about the state of the network. The protocol has no explicit feedback only implicit feedback when something goes wrong. The use of the available bandwidth oscillates. This means that the load of the network varies; small load: space left, unused available capacity overload: network overflow, packet losses, delays, retransmissions, i.e. slower than it has to be. There has been a shift in the Internet traffic. Due to short transmissions, TCP is almost always in slow start, measurements show 85% in slow start. There is no difference between different trace classes, such as ftp files, video streams or e-mail. Originally i less than 1% packet losses, now 5-7%, which means many retransmissions (13%), most of which are due to timeouts. TCP always assumes that packet losses are due to congestion. Problem in Mobile Networks!!! www.comnets.uni-bremen.de TCP - 32