Part1 TCP computer network

A, TCP protocol

the References: newcoder
TCP / IP protocol, TCP and UDP difference and characteristics

1, four-layer model

Application Layer: contains the application, sends the data to the transport layer. The main protocols are HTTP, SMTP, FTP, DNS and so on.
Transport Layer: communication from the encapsulation format information flow between the application responsible for the application. The main protocols are TCP, UDP.
Network layer: the transport stream layer packed into IP packets, to link layer communication between different hosts. The main protocols are IP.
Link Layer: receiving a network layer IP packets are encapsulated in frames sent to the network; a physical frame received from the network, extracts an IP packet to the network layer.

2, reliability

1). Serial number, acknowledgment, retransmission timeout

Each packet has a sequence number, the receiver can be sorted by sequence number; the received data segment, the receiver returns an acknowledgment character ACK corresponding, generally ACK No. + I have received, that is expect to receive the next the first data byte segment sequence number; if the transmitting end for a certain time (this time is usually within 2 * the RTT (round trip time segment) + an offset value) does not receive the acknowledgment, the corresponding data packet it will be considered lost and retransmitted.

2) Flow control

Sliding window: a receiver's advertised window size of the sender, the sender to prevent too much data transmission time.
If the sender sends the data too quickly, the recipient may be too late to receive, which will result in loss of data. The so-called flow control is to allow the transmission rate of the sender's not too fast, time to let the recipient receives.
Data packets in the sliding window can be sent directly, and when the left side of the window after receiving acknowledgment transmitting window moves to the right.

3) Congestion Control

Congestion window: the sender in order to avoid clogging of the window used in the transmission path.
Window size setting:
Slow Start: start window (the CWND) is set to 1 each time it receives an acknowledgment response (via a the RTT), the congestion window size * 2; when the packet retransmission timeout period, the threshold ( ssthresh) is set to half of the current window size, window size is set to 1, then slow start.
Congestion avoidance: setting a slow start threshold, usually set to 65536 (2 ^ 16). When the congestion window size to reach this threshold, not by 2, but each +1; when the segment retransmission timeout, setting the threshold to half of the current window size, window size is set to 1, then slow start.
Fast retransmit: 3 times receive duplicate ACK, retransmission immediately. For example, three times 1001 received the acknowledgment, it means the beginning of 1001 did not receive the retransmitted data segment 1001 began.
Fast Recovery: receive the ACK three repeats, starting fast retransmit, and fast recovery starts. The threshold is set to half the size of the current window and congestion window size to a new threshold of +3 (as explained previously received three sent three insulation, some without 3). Then just repeat each received a confirmation, congestion window +1. When a new data confirm the ACK, the window size is set to ssthresh, then the congestion avoidance.

3, three-way handshake

references: TCP three-way handshake with the four waving understand and face questions (very comprehensive)

When the transport layer protocol is TCP-based connection is established, the sender and the receiver sends three packets were called 3-way handshake.
The first handshake: sender sends a SYN = 1 (SEQ ID NO synchronization) and the initial sequence number Seq = X (random). Tell the recipient requests to establish a connection. The client enters the SYN_SENT state, requesting a connection, waits for an acknowledgment.
Second handshake: receiver acknowledges the SYN transmitting end (transmitting ACK = X + 1), while themselves transmit a SYN = 1, Seq = Y (random). DESCRIPTION receiver acknowledges receipt of a connection message. Server enter SYN_RECV state.
Third handshake: a receiver acknowledgment SYN + ACK packet, transmitting ACK = Y + 1, Seq = X + 1. At this time, TCP connection succeeds. The client and server into the ESTABLISHED state.

Why is the three-way handshake? Instead of twice or four times?
It has failed to prevent the connection request packet burst to the server segment, thereby generating errors.
For example, when a client first handshake segment in the network because of delays in the arrival of a node server, and the server send a confirmation response, empathy establish a connection. But the client did not request to establish a connection at this time, it will ignore the acknowledgment, because there is no third handshake, then the server will have to wait for the client to send data.

4, four wave

The first wave: the client sends a packet to release the connection, FIN = 1, Seq = u . Request to release the connection. Client enters FIN_WAIT1 (1 terminating wait) state.
Second wave: the server receives the connection release message, a confirmation message ACK = u + 1, and bring its own sequence number Seq = v. In this case, the client connects to the server has been disconnected direction, the client does not continue to send data. In the half-close (the FIN_WAIT2) state. However, the server sends data, the client still has to be accepted. The client waits for the server connection release message. The server into the CLOSE_WAIT (closed waiting) state. The client receives confirmation request to enter the FIN_WAIT2 (2 termination waiting) state.
The third wave: the last server data has been sent, packets sent to the client releases the connection, FIN = 1, ACK = u + 1, Seq = w. Wait for the client to confirm. The server enters LAST_ACK (final confirmation) state, waiting for an acknowledgment message client.
The fourth wave: the client receives the connection release message sent to confirm and enter TIME_WAIT state. ACK = w + 1, Seq = u + 1. The server immediately receive a confirmation message close the TCP connection immediately enter CLOSED state. The client sends an acknowledgment message, it does not close the connection immediately, but other 2 * MSL off (maximum segment lifetime) after. Because the last acknowledgment message may be lost, so to wait, if the server did not receive a confirmation message, the server will timeout retransmission FIN. Therefore, the server breaks the TCP connection earlier than the client. Finally, the client revocation of a TCP connection, enter CLOSED state.

5, while the opened while closed, half-open

references: TCP-IP Comments: TCP half-open connection and simultaneously open while closing the
opened simultaneously:
two applications simultaneously active open, sending the SYN packet into the SYN_SENT state. They all received the other side sent SYN, SYN packets and then sends an ACK packet to the other, then enter SYN_RECV state. After they receive each other's SYN and ACK packets, direct connection is established, enter ESTABLISHED state.

While closing:
The two sides also take the initiative to shut down, sending FIN packet enters FIN_WAIT1 state. Upon receipt of the parties to enter each other's FIN CLOSING state, then sends an ACK to confirm and enter TIME_WAIT state. Finally CLOSED.

Half-open:
one due to an abnormal close (disconnection, power off), and the other without the knowledge, this time in a half-open connection. If the parties do not perform data communication, the party is still connected on the other side does not detect an abnormality has occurred. If you need to send the data, in fact, found here after receiving the connection does not exist, it will return RST packets (reset packets) told forcibly close the connection, this time on the need to re-establish the connection.

Guess you like

Origin www.cnblogs.com/KirinSB/p/12602036.html