In today's class, we discuss two important fields in TCP header, the sequence number and acknowledgement number, and how they are used for TCP three-way handshake. As TCP was built upon the best effort IP, it is possible for older segments from previous connections to arrive at the receiver, complicating the task of eliminating duplicate assignments. TCP deals with this problem by using a 32 bit long sequence number and by establishing randomly selected initial sequence numbers during collection set up. At any given time, your receiver is accepting sequencing number from a much smaller window. So the likelihood of accepting a very old message is very low. Further, TCP enforce a timeout period at the end of each connection called maximum segment lifetime, to allow the network to clear old segments from the network. The maximum segment lifetime is usually two minutes, but it is a round trip delay dependent. The TCP sequence number identifies the position of the first byte of this segment in the sender's byte stream, the sequence number reps back to zero after two powers 32 bytes data transferred. Note that TCP identifies a sequence number for each byte. For example, if the sequence number is 100 and the data area contains 5 bytes, the next time this TCP sends a segment, the sequence number will be 105. The initial sequence number, ISN is selected during connection setup when the flag bit SYN is set one, the sequence number of the first byte of data for this byte of stream will be ISN plus one. It is important to note that a TCP connection is 40 plex, so that at each point independently maintains its own sequence number. The acknowledgement number identifies a sequence number of the next data byte that the sender expects to receive. This field also indicates that the sender has successfully received all prior data. It is valid only if ACK fag bit is set. In TCP header, there are six control bits. The ACK bit is to set as acknowledgement. If RST bit is set, it tells the receiving TCP module to abort the connection. SYN bit is to request a new connection, FIN bit is to tell the receiver that the sender doesn't have more data to send. The sender can still receive data from the other direction and here it will receive a second from the FIN bit set. Before any host can send data, a connection must be established. TCP establish the connection using a three-way handshake protocol as shown in the figure. The handshake is described in the following three steps. In the first step, host A randomly generates an initial sequence number x and a sends a connection request to a host B by setting the sync bit. The host A also registers its initial sequence number to use. In the second step, host B acknowledges the request by setting that ACK bit, and indicating the expected byte to receive, that is, ACK number it is x plus one. The pathway is needed because acknowledgement consumes one sequence number. At the same time, host B also randomly generates an initial sequence number Y from its side, sets as a SYN bit and registered its initial sequence number to use. In the second step, host A acknowledges the request from B by setting the ACK bit and computes the next data byte to receive. In this case, ACK number is y plus one. Note that the sequence number from this connection is x plus one. On receipt at the host B, the connection is established. If during a connection establishment interface, one of the host decides to refuse a connection request, it will send a reset segment. By setting the IST bit because the TCP segment can be delayed, lost and duplicated. The initial sequence number should be different each time a host requests a connection. To see why, consider a case that a host always uses the same initial sequence number n as shown in the figure. Of the connection established, at the latest segment from the previous connection arrives. Host B accepts this segment, since the sequence number turns out to be legal. If the segment from the current connection arrives later, it will be rejected by host B thinking that the second one is a duplicate. Therefore host B cannot distinguish a delayed segment from the new one. The three-way handshake protocol can ensure that both end points agree on their initial sequence numbers. TCP provides for a graceful close that involves an independent termination of each direction of the connection. That TCP entity completes transmission of its data and upon receiving acknowledgment from the receiver. It assures a segment with the FIN bit set. Upon receiving a FIN segment, the TCP entity informs its application that the other entity has terminated its transmission of data. For example, in this figure, the TCP entity in host A, terminates its transmission by issuing a FIN segment. Host B sends an acknowledgment to act as a receipt of the FIN segment from A. Note that the FIN segment uses one byte, so the acknowledgement number is 5,087 in this example. After B receives the FIN segment, the direction of the flow from B to A is still open. The TCP in host A enters the time-wait state for graceful close. Usually for true maximum segment alines. This concludes-