700 likes | 940 Views
TCP : Transmission Control Protocol ( Stevens TCP/ IP Illustrated Volume 1). Chapter 17 and 18:. TCP is connection oriented Unit of information passed by TCP to IP is a segment A segment is retransmitted if an acknowledgement is not received within ticks of a timer
E N D
TCP : Transmission Control Protocol( Stevens TCP/ IP Illustrated Volume 1) Chapter 17 and 18: • TCP is connection oriented • Unit of information passed by TCP to IP is a segment • A segment is retransmitted if an acknowledgement is not received within • ticks of a timer • TCP upon receipt of data sends an ACK. Normally does not send this • ACK immediately • TCP reorders out of order data • TCP uses flow control
TCP Connection Establishment And Termination • [ Fig 18.3] Use “tcpdump” to obtain data for this • Clint sends a SYN with initial sequence number • Notation 1415531521:1415531521 (0) Number of Bytes sent Starting Sequence Number Starting Sequence Number Plus Number of Bytes Sent • Server responds with SYN • Client ACK the SYN from server • This is 3 way handshake. It takes four segments to terminate and is called “ Half Close”
TCP Header : Bit 0 4 10 31 ( 32 Bits) 15 SOURCE PORT DESTINATION PORT SEQUENCE NUMBER 20 BYTES ACKNOWLEDGEMENT NUMBER FLAGS HEADER LENGTH RST FIN URG PSH SYN ACK UNUSED WINDOW CHECKSUM URGENT POINTER OPTIONS + PADDING
Maximum segment size (MSS) is largest amount of data each TCP sender is • willing to receive • Advertised by each end and can be different in different directions. It is not “negotiated.” • If no MSS sent default 536 is used • For ethernet 1460 bytes is the MSS. • [ Fig 18.12 and 18.13] State Diagram Of TCP • When TCP active close occurs and sends final Ack, connection stays in Time-Wait state • for twice maximum segment lifetime (MSS) value. • 1. In case must resend final ACK • 2. In case attempt to reuse IP address and port again while old segments may still • be in network. • Reset segment RST is sent when error occurs.
TCP Interactive Flow(TCP/IP Vol. 1, Stevens Chapter 19) • - Look at flow of data for rlogin connection which is a TCP application. • - Each keystroke generates a data packet. • [ Fig 19.1] • - Modified TCP dump output for session with five characters date\n (connection • establishment not shown in Fig 19.2). • [ Fig 19.2 ] • [ Fig 19.3 ] Time Line For Fig 19.2, much easier to follow • - ACK can be sent along with next data going in same direction called ACK piggyback. • - ACK usually wait up to 200 ms delay to see if must travel alone or get to piggyback. • Notation in Fig 19.2/19.3 0:1(1) means sent (1) data byte with sequence number 0. • The next starting sequence number will be 1.
To prevent lots of very small data segments in a network: • Nagle Algorithm (For the sending TCP algorithm) • The sending TCP sends the (small) data even if it is only one byte. • After sending the first data segment, sending TCP accumulates data until receiver sends an ACK or until data accumulated is an MSS. At this point sender can send data. • Repeat step two for remainder of transmission. • This algorithm causes a fast application program on a slow network to accumulate and send larger (mss) segments. A slow application program on a fast network will send less than mss. • There are situations like x window mouse where small mouse movements need to immediately be sent, in that case would not want to use Nagle since want to sendsmall size data immediately. • Fig [19.5-19.8]
TCP Bulk Data Flow Chapter 20 Normal Data Flow Example Transfer of 8192 bytes of data from srv4 to bsdi [Fig 20.1] Warning: This example appears to not use slow start (discussed later). - Sender transmits 3 data segments (4-6) - Next segment (7) acknowledges the first two data segments only. This is because of the following: - When TCP processes segment 4 the connection is marked to generate a delayed ACK - When segment 5 arrives TCP has two outstanding segments and immediately acknowledges. * TCP Immediately ACK's two outstanding segments. - Next segment (8) ACK's the third data segment due to ACK acknowledgement timer reaching a “ 200 ms Interval”. - Window of only 3072 advertised since 1024 bytes of data still in TCP receive buffer - In TCP ACK's are cumulative. They acknowledge receipt of up through ACK sequence number minus one. Note in Fig. 20.1 that the FIN segment has no data and is 8193:8193(0). The ACK for this is an ACK8194 which is one more than the last data. This is always true. A FIN uses up one ACK number.
Another Normal Data Flow Example: [Fig 20.2] Same as before but data sent a bit different. Warning: This example appears to not use slow start (discussed later). Fast Sender, Slow Receiver Example: [Fig 20.3] Warning: This example appears to not use slow start (discussed later). - Sender transmits four back-to-back data segments (4-7) to fill receivers window. - Receiver sends ACK but with advertised window 0. Application has not yet read data - Another ACK called a window update is sent later announcing some room at the Inn. Warning: Fig 20.3 does not follow the ack no more than every other segment rule.
PUSH Flag A notification from the sender to the receiver to pass all the data the receiver has to the receiving application. Some implementations of TCP automatically set the push flag if the data in the segment being sent empties the send buffer. These same implementations ignore a received PUSH flag because they normally deliver the received data to the application as soon as possible. In Fig 20.3 missing 3 PSH because sends did not empty the send buffer. Application has already sent all of its data to the send buffer so only last write empties the send buffer. We cannot manually set this flag through the Sockets Application Programming Interface.
Sliding Windows [Fig 20.4] Sliding window example [Fig 20.6] and [Fig 20.1]
Slow Start • Steven’s examples did not use slow start up until now. All TCP implementations must now use the slow start algorithm. You must always use slow start in this class. Some examples in the book do not do this, in this class you must ALWAYS use slow start. • An Intermediate router queue may run out of space. Best not to send too much too fast. Slow start Algorithm notes that the rate it should inject new packets into the network is the rate at which acknowledgements are returned by the other end. • ADD A CONGESTION WINDOW “ cwnd ” on the SENDER side (Note different from (buffer) window discussed before.) • In a new connection, the congestion window is initialized to one MSS announced • by other end. • - cwnd is maintained in bytes however cwnd is incremented by segment size. • - For each ACK received cwnd is increased by one segment.
- Sender can transmit up to minimum of (the congestion window and the advertised window) • (Congestion window cwnd is set by sender while advertised window is set by receiver). • Sender starts by transmitting one segment and waiting for its ACK. When that ACK is • acknowledged, congestion window is incremented from one to two and two segments • can be sent. • When each of those two segments acknowledged, congestion window set to four. • This provides an exponential increase. • At some point an intermediate router will discard packets. Congestion window • cwnd is too large.
Slow Start Example • [ Fig 20.8] MSS=512 • Bulk data throughput - interaction of window size, windowed flow control, and slow start • on the throughput of a TCP connection. • [Fig 20.9& 20.10] • - At time 0 sender transmits one segment cwnd = 1, must wait for ACK. • - At times 1, 2, 3, segment moves one time unit right. • - At time 4 ACK generated. • At time 7 ACK received at sender. • - At time 8 sender can transmit two segments, cwnd = 2 (we have round trip time = 8 ). • - At times 12, 13 ACK 2 and ACK 3 generated. • - At time 15, 16 ACK's RCVD and with cwnd = 4 sender transmits four segments. • - At time 24 and on can always transmit.
Bandwidth - Delay Product In previous example sender needs to have 8 segments outstanding and unacknowledged for max throughput. Thus receivers advertised window must be at least that large so as not to limit throughput. Capacity of pipe = bandwidth ( bits/ sec ) x round trip time ( sec ) ( also know as bandwidth-delay product) Example: What size should receivers advertised window be for a T1 Cross USA country phone line? = 1, 544, 000 Bits / Sec x 0.060 Sec round trip time. = 11,580 byte window Congestion The spacing of the ACKs will correspond to the bandwidth of the slowest links [ Fig 20.13]
So what do mean by increase cwnd for each ACK received? • Stevens book says “Each time an ACK is received, the congestion window is increased by one segment” • 2) RFC2001 Network Working Group W. Stevens Request for Comments: 2001 January 1997 “TCP Slow Start, Congestion Avoidance, Fast Retransmit, and Fast Recovery Algorithms” : Each time an ACK is received, the congestion window is increased by one segment……..this provides an exponential growth, although it is not exactly exponential because the receiver may delay its ACKs, typically sending one ACK for every two segments that it receives. • 3) RFC 2581 TCP Congestion Control APRIL 1999 says “ During Slow start, TCP increments cwnd by at most mss bytes for each ACK received that acknowledges new data” • 4) From: Internet Engineering Task Force , Mark Allman INTERNET DRAFT draft-allman-tcp-abc-00.txt July, 2000 Expires: January, 2001 TCP Congestion Control with Appropriate Byte Counting • Delayed ACKs [RFC1122,RFC2581] allow a TCP receiver to refrain from sending an ACK for each incoming segment. However, a receiver SHOULD send an ACK for every second full-sized segment that arrives. Furthermore, a receiver MUST NOT withhold an ACK for more than [200] ms. By reducing the number of ACKs sent to the data originator the receiver is slowing the growth of the congestion window under an ACK counting system.
Conclusion: So clearly we are counting individual ACKS not the amount of data being ACKed. For this class always assume cwnd is incremented by only one MSS when an “ACK very other segment” is used and this ACK datagram contains an ACK for more than one segment. Aside: Is this definitely 100% for sure always true in the real world? Well ….. Forouzan in “TCP/IP Protocol Suite” McGraw Hill 2000 says “For each segment that is acknowledged, increase the congestion window by one maximum segment size until you reach a threshold of half the allowable window size.” Lets stick with the ACK counting approach at the top of this slide.
Congestion Example [Fig 21.6] Starting sequence number versus time Retransmission is negative slope. Only 3 retransmissions occur. (one segment in each) Look At The First Segment Loss At Time 10 [Fig 21.7] Zoom in at around 10 second point This figure shows segments numbered according to their send or receive order with respect to host. Removed unrelated segments 44,47, and 49; removed window advertisements slip=4096, vangogh=8192 Segment 45 gets lost and is not received. ACK for up to 6657 is received in segment 58. When vangogh receives segment 6913: 7169 ( 256) it repeats ACK for last received in sequence that is ACK 6657 again. This happens 9 times. On slip receipt of the third duplicate ACK for the same thing: a retransmission of the first (and in this case only) missing segment is done. * Note in this case only the single segment that was not received is retransmitted. After retransmission of segment 63 which is 6657:6913 (256) sender keeps on going with segment 67 8961:9217 (256), segment 69 and segment 71. Continued….
* TCP does not wait for the other end to acknowledge the retransmission. - At the receiver (vangogh) normal data is received in sequence (segment 43) - 256 bytes of data is passed up to the user process. - Next received segment (segment 46) is out of order, it starts at 6913 but 6657 is expected. - TCP saves out of order and immediately ACK’s with highest sequence number received in order plus 1 (6657) - Next seven segments received by vangogh are also out of order but are saved. Duplicate ACK of 6657 sent for each. - When missing data segment 63 6657: 6913 (256) arrives receiving TCP already has 6657 through 8960 so an ACK for 8960 + 1 is sent. - Window of 5888 which is 8192 - 2304 is advertised since receiving process has not yet read the buffer.
So how do we decide how big the sliding window (cwnd) in the sender should be? Congestion Avoidance Algorithm Two possible indications of Packet Loss - Timeout occurring - Receipt of duplicate ACK’s If congestion, we want to slow down transmission. Congestion avoidance and slow start work together. Congestion window cwnd Slow start threshold size ssthresh Algorithms: 1. cwnd = 1 segment ssthresh = 65535 Bytes Initially
2. TCP never sends more than minimum of [cwnd and receiver’s advertised window]. 3. When congestion encountered set ssthresh = minimum of (1/2) (cwnd, receivers advertise window) or at least 2 segments. {Rounded down to a segment size multiple} And if congestion seen by timeout set cwnd = one segment 4. For each ACK of new data (does not happen if a duplicate ACK) if cwnd < ssthresh use slow start which means increment cwnd by one segment for each ACK else increment cwnd by (This is not slow start so is congestion avoidance) segsize * segsize + segsize cwnd 8 For each ACK received Note: Maximum increment in congestion avoidance allowed is 1 MSS segment.
Example : Assume congestion when cwnd was 32 segements so we will make ssthresh = 16 This is Fig 21.8 redrawn: Segments ( Think Bytes) ssthresh = cwnd segments But actually stored in bytes! 20 18 16 14 12 10 8 6 4 2 0 0 1 2 3 4 5 6 7 Round Trip Times