Today we discuss TCP flow control and data transfer. After our TCP connection is established, by three way hand shake procedure, to provide a reliable data transfer, TCP uses a selective repeat ARQ protocol, with positive acknowledgement implemented by a sliding window. The differences here is that the window slides on a byte basis instead of per packet basis. TCP can also apply flow control over a connection by dynamically advertising the window size. But let's first revisit a connection establishment in the context of a client server application that will use TCP service. Let the client reside in Host A, and a server in Host B. This figure shows that the server must first carry out a passive open to indicate to TCP that it is willing to accept connections. When using BSD sockets, a passive open is performed by the core sockets, bind, listen, and accept. When client A wish to initiate a session, it performs an active open. This step involves making a socket call at a time t1 and a connection call at a time t2. So that initiates the TCP connection. This action causes the kind of TCP module to initiate the three way handshake. When the server TCP receives the first sync connection, it returns a sentiment with ACK and its own sync number. When the client TCP receives this ACK, it connects call returns at a time t3, and client sends an ACK. Upon receiving the ACK, accept call returns at time t4 in the server. And the server is ready to read data. The client and the server can then request and reply message by write and recalls. This figure illustrates an sample of TCP flow control and data transfer. At time t0, the TCP module in host B advertised a window size of 2,048 bytes, and expected the next byte received to have a sequence number 3,000. The advertised window size allows host A to transmit up to 2,048 bytes of unacknowledged data. At time t1, TCP module A only has 1,024 bytes to transmit. So it transmits all the data starting with sequence number 2000. The TCP module at A also advertise its own window size, let's say 1,024 bytes, to host B, and the next byte is expected to have a sequence number 1. When the segment is received, host B choose to delay the acknowledgement in the hope, that acknowledgement may get a free ride with data. Meanwhile, at a time t2, Host A has another one solved in 24 bytes of data and then it transmits. After the transmission, Host A's sending window closed completely. It is not allowed to transmit any more data until an acknowledgment comes back. At time t3, Host B has 128 bytes of data to transmit. And also wants to acknowledge the first two segments of data from Host A. Host B can simply piggyback acknowledgement by specifying the ACK number, 4008, to the data segment. At this time, Host B also finds it can allocate only 512 bytes of receiver buffer space, due to the buffer competition from other connections. So it shrinks the advertised window from 2048 to 512 bytes. When Host A receives the segment, it changes the send window to 512 bytes. If at time t4, Host A has 2048 bytes of data to transmit, it will only transmit 512 bytes. We see that the window advertisement controls the flow of data from the sender to the receiver. And it prevents the receiver buffer from overflow. The initial sequence number is used to protect against segments from previous connections. Then it may circulate in the network and arrive at a much later time. TCP uses a local clock to select the initial sequence number. Time to clock to go through a full cycle should be greater than the maximum lifetime of a segment, which is usually 120 seconds. But the high bandwidth links pose a problem. Let's see how long it takes to wrap around the sequence numbers space using our high speed transmission line. The 32 bit sequence number wraps around when 2 power 32 bytes data have been sent. But at 1 gigabit per second transmission line, the sequence number may wrap around in just 34 seconds, which is smaller than the maximum segment life time. And that means new segments could mix up with old segments. When the timestamp option is used, the sending TCP can insert another 32 bit timestamp into a 4 byte field, in the header of each segment it transmits. By combining the 32 bit timestamp with a 32 bit sequence number, we actually can obtain our 64 sequence number to deal with this wraparound problem. This concludes our lesson today.