ECE 4110 – Internetwork Programming

Embed Size (px)

DESCRIPTION

Transmission Control Protocol (TCP) Connection-oriented Provides Process-to-process communication (using ports) Byte stream delivery: Receiver cannot tell what size the individual writes (by the sender) were. Full-duplex service (each direction is handled separately) Flow control Reliable service. Uses ACKs. Takes care of: Lost packets Damaged packets Duplicate packets Out-of-sequence packets Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming

Citation preview

ECE 4110 Internetwork Programming
Transmission Control Protocol: TCP Transmission Control Protocol (TCP)
Connection-oriented Provides Process-to-process communication (using ports) Byte stream delivery: Receiver cannot tell what size the individual writes (by the sender) were. Full-duplex service (each direction is handled separately) Flow control Reliable service. Uses ACKs. Takes care of: Lost packets Damaged packets Duplicate packets Out-of-sequence packets Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Process-to-Process Communication
Port Numbers * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall ECE 4110 Internetwork Programming
Stream Delivery Data from the application layer is treated as a stream of bytes. Remember: In UDP, each packet is treated independently. TCP creates an imaginary tube to carry the stream. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Stream Delivery (contd)
* From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sending and Receiving Buffers
TCP needs send and receive buffers. Flow Control: Sender and receiver may transmit/receive at different rates. Error Control: Sender may need to retransmit packets. Send and receive buffers need not be the same size. Use circular buffers. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sending and Receiving Buffers (contd)
White: Empty Gray: Sent but not ACKd Pink: Not sent yet White: Empty Pink: Received, but not delivered to the process yet. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Segments IP handles packets, not byte streams. So, TCP has to group bytes into segments. A header is also added to each segment for control purposes. Segments need not be the same size. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Segments (contd) * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Segments (contd) Numbering: TCP header has two fields to keep track of segments: segment number and acknowledgment number. Both fields refer to byte number, not segment number. Numbering is used for flow and error control. Numbering is independent in each direction. Numbering need not start from 0 (a random value between 0 and Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Segments (contd) Numbering (contd): SEQ# is the number of the first byte in the sequence. ACK# is the number of the next byte receiver expects to receive. ACK# is cumulative, i.e., all bytes from the start to ACK#-1 are received properly. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming TCP Segments: Example for Sequence Number
Imagine a TCP connection is transferring a file of 6000 bytes. First byte is numbered What are the sequence numbers for each segment if data is sent in five segments with the first four segments carrying 1,000 bytes and the last segment carrying 2,000 bytes? Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming TCP Segments: Example for Sequence Number (Solution)
Segment 1 10, (10,010 to 11,009) Segment 2 11, (11,010 to 12,009) Segment 3 12, (12,010 to 13,009) Segment 4 13, (13,010 to 14,009) Segment 5 14, (14,010 to 16,009) Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Flow Control in TCP Control the rate at which the sender transmits the data. Avoid overwhelming the destination or any node on the path. Extremes: One ACK for each byte Too slow Too much overhead (ACK larger than data) One ACK for all data Very fast May overwhelm some node(s) Whole stream must be retransmitted in case of error Use Sliding Window Protocol Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol
Both hosts keep two windows (one for each direction). Window is the portion of buffer that can be transmitted without waiting for an ACK. Sender window size is controlled by the receiver. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Sender Buffer * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Receiver Window (RWND) N: Size of receiver buffer M: Number of occupied bytes N-M: Size of RWND * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Sender Buffer and Sender Window (SWND) Sizeof(SWND) sizeof(RWND) * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Sliding the Sender Window * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Expanding the Sender Window Receiver tells sender to increase window size to 10. * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
Shrinking the Sender Window Receiver tells sender to decrease size to 6. * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Sliding Window Protocol (contd)
The source does not have to send a full windows worth of data. The size of the window can be increased or decreased by the destination. The destination can send an acknowledgment at any time. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Silly Window Syndrome Occurs when the sender and/or receiver creates/consumes data very slowly. The overhead due to header (TCP+IP=40 bytes) will be very high. Syndrome created by sender Nagles algorithm Syndrome created by receiver Clarks solution or delayed acknowledgment Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Silly Window Syndrome (contd)
Nagles Algorithm: Send the first piece of data, even if it is only 1 byte. After the first segment, accumulate data until either enough data is collected or receiving TCP sends ACK. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Silly Window Syndrome (contd)
Clarks Solution: Send ACK as soon as data arrives. Announce a window size of zero until: Available space in receiver buffer maximum segment size, or Half of the receiver buffer is empty. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Silly Window Syndrome (contd)
Delayed Acknowledgment: Received segment is not ACKed until there is decent amount of free space in receiver buffer. (ACK delayed typically for 200 ms.) Advantages: Avoids the syndrome Lower traffic volume (less ACKs) Disadvantage: The delay may cause retransmission. (Do not delay more than 500 ms.) Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Error Control: Corrupted Segment
* From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Error Control: Lost Segment
* From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall Error Control: Lost ACK
* From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall ECE 4110 Internetwork Programming
TCP Timers Retransmission Timer: Waiting time for ACK. Used to control lost or discarded segments. Unique and dynamic for each connection. Retransmission time = 2 x RTT Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Timers Calculating RTT: Use timestamps, or Use the time between segment and ACK RTT= x previous RTT + (1- ) x current RTT If a packet is retransmitted and one ACK is received, does the ACK belong to the original segment or the retransmitted segment? Solution Karns algorithm: Do not consider RTT for retransmitted segments. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Timers (contd) Persistence Timer: What if the ACK announcing a non-zero windows size (after a zero-window advertisement) is lost? Sending TCP starts persistence timer. If timer expires, a probe is sent to receiver TCP (repetitively). Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Timers (contd) Keepalive Timer: To prevent long idle connections due to crashes, etc. A probe is sent when timer expires. If multiple probes are not answered, connection is dropped. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
TCP Timers (contd) Time-waited Timer: To avoid multiple FIN segments. A closed connection is not immediately terminated. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Congestion Control TCP assumes that the cause ofa lost segment is due tocongestion in the network. If the cause of the lost segmentis congestion, retransmission of the segment not only does not remove the cause, it aggravates it. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control (contd)
Congestion can be realized by: Timeouts Duplicate ACKs In addition to the receiver, the network should also be able to determine the senders window size. Congestion Window (CWND) SWND size = min (RWND size, CWND size) TCP uses two strategies against congestion: Slow Start and Additive Increase Multiplicative Decrease Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control: Slow Start and Additive Increase
Initialize CWND size to Maximum Segment Size (MSS). For each segment ACKed, increase CWND size by MSS until CWND size reaches the Slow Start Threshold (SSTHRESH), half of allowable window size. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control: Slow Start and Additive Increase
Slow Start (contd): Is this slow start? sizeof(CWND)=1 send 1 segment ACK received sizeof(CWND)=2 send 2 segments 2 ACKs received sizeof(CWND)=4 send 4 segments 4 ACKs received sizeof(CWND)=8 send 8 segments This is not slow. This is exponential. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control: Slow Start and Additive Increase
After reaching SSTHRESH, increase CWND size only by one MSS for each ACK, even if the ACK is for multiple segments. Continues until timeouts or CWND size reaches RWND size. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control: Multiplicative Decrease
Activate congestion is detected. SSTHRESH = min (2xMSS, x current window size) (CWND size or advertised window size) If congestion is detected by timeout CWND size = 1 x MSS SSTHRESH is reduced for each timeout (exponentially). Timeout causes going back to slow start. Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Control (contd)
Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Congestion Avoidance (contd)
Find the mistake in the figure * From TCP/IP Protocol Suite, B. A. Forouzan, Prentice Hall ECE 4110 Internetwork Programming
TCP Header Format Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Control Field Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Options Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Connection Setup: Three-way Handshaking
Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Connection Termination
Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming State Transition Diagram ECE 4110 Internetwork Programming
Client States Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming ECE 4110 Internetwork Programming
Server States Spring 2003 Tuna Tugcu ECE 4110 Internetwork Programming Connection Setup and Termination Transfer 8192 bytes Transfer 8192 bytes (alternative) Sliding Window Example