TCP guarantees reliability, the process of establishing the connection and disconnection

TCP guarantees reliability:

(1) sequence number, acknowledgment, retransmission timeout

Data arrives at the receiving side, the receiving side needs to send a confirmation response indicating the data segment has been received, the acknowledgment number and the data sequence number will be described next time it needs to receive. If the sender has not yet received an acknowledgment response, it may be transmitted data is lost, it may be the acknowledgment is lost, then the sender after waiting a certain time will be retransmitted. This time is generally 2 * RTT (round trip time segment) + an offset value.

(2) the window control and high-speed retransmission control / fast retransmission (duplicate acknowledgment)

TCP will use window controls to increase the transmission speed, which means within a window size, do not have to wait for a response before sending the next piece of data, the window size is no need to wait for confirmation and can continue to send data to the maximum. If you do not use window controls, each did not receive the acknowledgment of the data to be retransmitted.

Using the control window, if the data segment is lost 1001-2000, behind each transmission data, will continue to send the acknowledgment number 1001 as a response, to receive the data I represents the beginning of 1001, the transmit end receives three times if the same response, it will be retransmitted immediately; but there is a situation there may be data are received, but some responses are missing, this will not be retransmitted because the sender knows that if the data segment is lost, the receiver does not will let it, it would be crazy to remind ......

(3) Congestion Control

If the window is given a large, continuous sending end sends large amounts of data may result in network congestion (we are using the network, what are you crazy hair, throughput is so big, of course, will be blocked), and even cause the network paralysis. Therefore, in order to prevent this TCP performs congestion control.

Slow start: Define congestion window, start the window size to 1, after each receive a confirmation reply (after a rtt), the congestion window size * 2.

Congestion Avoidance: Set slow start threshold, generally are set to begin 65536. Congestion avoidance is when the congestion window size reaches the threshold value of the congestion window no longer rose, but the increase in the adder (each acknowledgment / each RTT, the congestion window size + 1), in order to avoid congestion.

The retransmission timeout seen as congested segment, the event of retransmission timeout, we need to first set the threshold to half of the current window size, and window size to the initial value of 1, and then re-enter the slow start.

Fast retransmit: immediately retransmitted in the face 3 times repeated acknowledgment response (high-speed retransmission control), Representative received three segments, but the one before that segment is lost, it will be.

Then, the first threshold is set to half of the current window size, then the congestion window size to the size of the slow start threshold +3.

This can be achieved: when TCP traffic, showed a gradual increase in network throughput, and throughput to reduce congestion with, and then slowly rise into the process, the network paralysis does not occur easily.

TCP connection establishment and disconnection:

 

 

Three-way handshake:

1. Client SYN flag bit is set to 1, a randomly generated value seq = J, and the packet is sent to the Server, Client enters the SYN_SENT state, waiting for acknowledgment Server.

2. Server receives the packet data from the flag bit SYN = 1 know Client requests to establish a connection, Server SYN and ACK flag bit are set to 1, ack = J + 1, a randomly generated value seq = K, the data and packet to the connection request to confirm Client, Server enters SYN_RCVD state.

3. Client receives the acknowledgment, checking whether the ack J + 1, ACK is 1, then if the correct ACK flag is set to 1, ack = K + 1, and the packet is sent to the Server, Server checks ack whether K + 1, ACK is 1, if correct, the connection is established, Client and Server enters eSTABLISHED state, complete the three-way handshake, then you can begin to transfer data between Client and Server.

 

Four wave:

Since the TCP connection is full-duplex, thus, each direction must be shut down separately, this principle is that when one task is finished sending data, sending a FIN to terminate the connection in this direction, but means receives a FIN There is no data on the flow in that direction, that is no longer receive data, but still be able to send data over the TCP connection until this direction also send a FIN. First off will be the one to perform active close, while the other performs a passive close.

1. After completing the data transfer, the client application process makes a connection release segment, and stops sending data, the client enters FIN_WAIT_1 state, then the client may still receiving data sent by the server.

2. After the server receives the FIN, ACK sent to a client, the acknowledgment number is the sequence number + 1 received, the server enters CLOSE_WAIT state. FIN_WAIT_2 into the client after receipt of state.

3. When the server is no data to send, the server sends a FIN packet, which the server enters LAST_ACK state, waiting for confirmation of the client

4. client after the server receives a FIN packet, sends an ACK packet to the server to confirm the sequence number of the received sequence number +1. In this case the client enters the TIME_WAIT state, waiting 2MSL (MSL: segment maximum survival time), and then close the connection.

Guess you like

Origin www.cnblogs.com/davebryant/p/11258523.html