Transmission Control Protocol (TCP) (below)

xiaoxiao2021-03-06  45

3.4. Establish a connection

Establishing a connection application is three news handshake. If both parties send SYN, there is no relationship, the two sides will find that this SYN has not confirmed, so I know this situation, usually, I should send a "reset" section to solve this situation. Three news handshakes reduces the possibility of connecting failed. Below is an example, in a spare brackets, it is the content and tag in the data segment. There are not many other words.

On the second line, TCP A transmits the SYN initialization serial number, indicating that it is to use the serial number 100; in line 3, TCP B gives a confirmation, and looks forward to the data segment of the serial number 101; line 4, TCP A gives a confirmation, and in line 5, it also gives a confirmation, and sends some data. Note that the serial number of the fourth line is the same as No. 5, because the ACK information does not occupy the serial number in the serial number. . At the same time, the request is generated is only complicated as shown in the figure below.

The main reason for shaking hands using the three news is to prevent the use of expired data segments. For this purpose, new control messages must be introduced, and reset. If the TCP processes the non-synchronous state, returns to the Listen state after receiving the reset. If the TCP processes the following states ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, Close-Wait, Closing, Last-Ack, Time-Wait, abandon the connection and pass the user. Let's take a detailed description of the following cases.

Through the above example, we can see how the TCP connection is recovered from the interference of the expired data segment. Note the RST (RESET signal) in Chain 4 and 5th lines.

Half open connection and other abnormal state

If one party closes the connection without passing by the other, it is called a semi-open connection. The connection will automatically reset when party attempts to send data. However, this situation is abnormal. It should be processed accordingly. If the connection at A is closed, B is not known. When b wants to send data to A, it will receive a RESET signal, indicating that the TCP connection is incorrect, and it is aborted.

Assuming that the A and B are communicating with each other, A of the TCP has failed, and a relies on the operating system to support TCP presence, usually there will be recovery mechanisms to play, when TCP is recovering, A may wish to Recovery points start working. Thus A may try the OPEN connection, then transmit data on this it thinks or open, which will "not open connection" on the local (i.e.) TCP. The TCP of A will send a data segment including SYN. The following example will display this process:

In this example, the information received by A did not confirm anything, this time A found a problem, so I sent RST control information. Another situation is that the following example can represent this case when A failed, and the B party still tries to send data. The following example can indicate this situation. Note that the information sent by A on the second line is not known.

In the following example, the Passive connection of the A and B is waiting for SYN information. The expiration package transferred to the B response to the B response, but the received A is not discovered, the RST control information is not transmitted, and the B returns a passive Listen state.

There are too many reality, and we list some rules that generate RST control information as follows: Normally, the RST is not generated when the information received is not expected. If you do not easily send RST control information when you cannot be sure. There are three types of situations:

If the connection does not exist, the message sent is not RST, then returns RST. This approach can be used if you want to reject SYN that does not exist. If the information reached has an ACK field, the returned RST information can be obtained from the ACK domain. If there is no this domain, set the serial number of the RST to 0, the ACK domain is serial number and arrival segment length. . The connection is still in the CLOSE state. If the connection is in a non-mutual state (Listen, Syn-Sent, Syn-Receive, and the received confirmation is the confirmation of the unmovable package or the security level that receives the data segment is consistent with the unconnected requirements. Send RST. If SYN is not confirmed, and the priority of the received data segment is higher than the required priority, then the local priority (license to obtain the user and system) either sends RST; if the data segment is received The priority is lower than the requirements, even if the match is matched, of course, if the other party finds that the priority does not increase the priority, it is improving the priority in the next package, which is not considered. If the connection has entered SYN, then the priority of the data segment must be the same as the local priority, otherwise the RST is sent. If the information reached has an ACK field, the returned RST information can be obtained from the ACK domain. If there is no this domain, set the serial number of the RST to 0, the ACK domain is serial number and arrival segment length. . The connection is still in the same state as the original.

If the connection is in a synchronous state (Established, Fin-Wait-1, Fin-Wait-2, Close-Wait, Closing, Last-Ack, Time-Wait, any data segment exceeding the serial number exceeding the receiving window produces the following results: A empty confirmation data segment is issued, including the current sequence number, further comprising a confirmation indicating the serial number of the next data segment you want to receive, and the connection is still saved in the original state. If you have problems such as security levels, priority, then send RST signals and enter the Closed status.

RST process

In addition to other states outside the SYN-Sent state, all RST data segments can be found out by checking the SEQ domain. If the serial number is in the receiving window, the RST is effective. When the connection is in the SYN-SENT state, if the ACK field confirms SYN, then RST is also legal.

The RST recipient first confirms its legitimacy and then performs status conversion. If the recipient is in a Listen state, it ignores the RST package. If the recipient is in the Syn-ReceiveD state, and before it is in the Listen state, the recipient returns to the Listen state, otherwise the receiver turns off the connection into the Closed state. When the recipient is in other states, the connection is directly closed back to the Closed state.

3.5. Close connection

Close is an operation, it means that "this party already has data transmission". Because it is a full-duplex, it will cause some trouble because the recipient is a bit troublesome to handle the receiver. In a simple way, we have to continue to receive data before receiving the other party's closed. So the program can initialize several Send after a close, then starting receiving until the other party's Closed and Receive failed. We assume that TCP can notify the user to connect, even if it is still in Receive, this user can be closed. Thus, TCP can reliably send data before the connection is closed. The following are listed below:

Situation 1: Local users close

In this case, a FIN segment can be created in the send queue. TCP no longer receives the user's SEND instruction, TCP enters the Fin-Wait-1 state. Receive is allowed in this state. All data segments and fins will be sent until confirmed. When another TCP confirms the FIN and send its own FIN, the local TCP can confirm this FIN. Note that TCP can also return your own FIN when confirming Fin until the user closes the connection, returns to its own FIN. Case 2: TCP receives a FIN from the network

If the FIN is received without the request, the TCP can return ACK and inform the user connection has been closed. The user can respond with a Close, and the TCP sends its own FIN after sending the remaining data, then the TCP waits for confirmation of this FIN, after receiving, it closes the connection. If you confirm your timeout, you can turn off the connection and notify the user to do.

Situation 3: The two parties are closed at the same time

The two parties will be closed at the same time will result in the exchange of FIN. The two sides will close the connection after receiving the confirmation of the FIN.

3.6. Priority and security

The operation of the TCP must be performed between the two priority ports. The priority and security parameters used by TCP are defined in the IP protocol. The security / interval we mentioned here refers to the priority, user group, and processing defined in IP. If it does not meet, the RST is sent. These content, please see the narrative in the section. TCP also checks the priority of the received data segment during operation, and it is also possible to improve priority in operation. Although the operation is running in a secure environment, the host must also be able to handle security parameters.

3.7. Data communication

After the connection is established, it is transferred data. TCP ensures that each data segment reaches the other party by reloading, so the other party may receive two identical packets, which must determine which data segment must be judged according to the internal serial number. It is acceptable. The sender tracks the next data segment to be transmitted by using SND.NXT, and the receiving party tracks RCV.NXT to know the next data segment to receive. The oldest serial number that the sender must have not confirmed is saved in SND.una.

When the sender forms the data segment and transmits it, SND.NXT is increased; RcV.NX is increased and confirmed when the receiver receives the data segment; when the sender receives the SND.UNA after the sender receives the confirmation. The three are increased at different times because of the transmission delay. And how much is determined by the size of the data in the data segment. Note: After connecting to the ESTABLISHED state, all segments must include current confirmation information. The nature type of the CLOSE user operation is induced, which is the same as the FIN tag in the received data segment.

Retransmission timeout

Because there is a non-type network in the network, the range of TCP is wide and wide, so the retransmission timing must be dynamically determined. An example is given below, and the process of determining the retransmission times can be seen. There are two variables in the following, one is the problem, one is the loop time (RTT), which is obtained by a sequence code, which is given when sending, covered when the confirmation is received; another smoothing ring Road time (SRTT):

SRTT = (Alpha * SRTT) ((1-alpha) * rtt)

Through the above form, you can get retransmission timeout (RTO):

RTO = min [Ubound, Max [lbound, (Beta * SRTT)}

Where ubound is the upper bound (such as 1 minute), LBound is a minimum lower boundary (such as 1 second), Alpha is smoothing factor (e.g., 0.8 to 0.9), Beta is a delay variable (such as 1.3 to 2.0).

Transfer emergency news

TCP's emergency mechanism is to allow the sender to allow the recipient to receive some emergency messages, and let the recipient notify the user immediately after receiving this message. This mechanism is to join a point in the data stream indicating that this is the end point of emergency data. When the recipient is to receive this point, it will notify the user to enter the emergency state, after receiving this data, it will Notifying the user to enter usually. If this emergency is updated when the user enters an emergency, this update must be transparent to the user. The method of applying an emergency domain can reach the above purposes, and the URG control marker indicates whether the emergency domain is used, and the serial number indicating the emergency point must be added in the data segment. If there is no such tag, there is no emergency point. If you need to send emergency data, the sender must start to send a byte.

Management window

If we have learned the web foundation, we must know that there is a window protocol, and each data segment in the TCP includes the next sequence number that is desired to receive. The window is compared to increase the transmission speed. If the transmitted data exceeds the window size, the data will be discarded. This will increase the network burden. If the receiving window at the beginning of the TCP is relatively large, and the last window is reduced, this method is not a good way. For robust TCP, it is best not to narrow the window yourself, but you have to prepare the other party's TCP reduction window.

Even if the send window size is zero, the transmission TCP must be prepared to receive data and can send at least one new data. Even if the receiving window is zero, the sender will resend, and the interval between retransmission is generally two minutes. When the receiving window receiving the TCP is zero, it will still return confirmation when it receives data, including the sequence code that it is desired to receive and the current window size (zero).

Send TCP to packet data into a package that meets the current size, but may be repackaged in the re-transmit queue. This replenishing is not necessary, but it will be very beneficial. If a connection is only one-way data stream, window information can be obtained in confirmation information, which is one of these serial numbers. But this is not a serious problem. The improved approach is to join the latest expectation serial number in the data segment, so that you can distinguish from who is first. Window management has a great impact on transmission efficiency, and below is some suggestions:

When using fewer big data, allocate a very small window to make the data in many small segments. For the sender to avoid waiting until the window is in a certain degree of reality when sending a small data segment. Confirm not to be delayed. When the received window is zero, the data segment to be transmitted may be divided into a segment. If the sending TCP only sends a data segment that allows the window to allow size, it may be sent to data segments than this segment large (or small). From time to time, window size adjustment will make large data segments into small segments without pairs. Try to synthesize a small window.

3.8. Interface

The hierarchical structure of the network protocol determines that TCP has two interfaces, upward user interfaces and the following interfaces. The description of the next reception port is not clear, this work is described by the underlying protocol, but here we also describe some TCP to use the parameters.

User / TCP interface

Some TCP commands are described below, which is functional because different specific implementations of each system may be different. Finally, we must clearly, different TCP implementations may have different user interfaces, but some functions are the most basic, and this section describes the basic function set.

TCP user command

The following defined commands are similar to those defined in other advanced languages, but some trap is required, such as SVC, UUO, and EMT. The following is just a functional introduction, and the specific implementation may be greatly different. If some systems will combine the plurality of commands here into one command to use. In order to implement communication, TCP cannot only receive commands, and can return messages to its services, including:

(a) Regarding the usual message of the connection, such as interrupt, remote shutdown, etc .; (b) answering the user command, it is successful or fail.

Open

Format: Open (Local Port, Foreign Socket, Active / Passive [, Timeout] [, Precedence] [, Security / Compartment] [, Options]) -> Local Connection Name

We assume that local TCP noticed the process tags it served and will check the process of processes. Due to different implementation, TCP authentication of local network and source address may be performed by TCP or by the next protocol (such as an IP protocol). These considerations are mainly based on safety considerations.

If the Active / Passive tag is set to passive, the TCP detects the connection request, which is passive, passive connection can have a fully specified jacket text to wait for a particular connection or unspecified jacket. Wait for any call. A fully defined passive call can be active by performing a series of Send commands. Create a transfer control block (TCB), where part of the parameters are incorporated by the Open command parameters. When active Open, TCP will start synchronous connection immediately. If the parameter Timeout is given, the caller is allowed to apply to all TCP data. If the data is not sent to the destination within the time specified in Timeout, the connection is closed, and the general default value is 5 minutes.

Parameters precedence or security / compartment are used to specify the security of a user to a certain connection, if not specified, use the default value. TCP will match these two parameters, only open connections only when SECURITY / Compartment is consistent and the received Precedence is less than or equal to required PreceptUns. When the connected Precedence is greater than the required value, this value is taken from the received data segment and the relatively large value is used in the connection. Specific implementation can give the user power to control the decision process of Precedence. For example, the user can request precedence to be safe, or if it is increasing Precedence, it is necessary to notify the user.

Local Connection Name Returns users by TCP, which can be replaced by tag a connection.

Send

Format: Send (Local Connection Name, BYTE COUNT, PUSH FLAG, Urgent Flag [, TIMEOUT])

This command causes the data to specify the data in the specified buffer, returns an error if the connection is not open, and some implementations may call the Send before the connection is opened, and the connection is automatically opened by Send. If a PUSH tag is set, the data must be transferred to the recipient immediately, and the last segment of the PUSH bit in the buffer must be set. If there is no setting, this data segment will be transmitted with the data transmitted by the next send command because of the efficiency consideration. If a Urgent tag is set, it must be treated as follows. The number of Urgent settings set by the transmit party is not necessarily equal to the number of times the receiver user.

If no jacket is specified in Open, the buffer data is sent to implicit jacket. Users who do not use jackets to open connections can still be Send without knowing the jacket terminal. However, if Send is performed before specifying the jacket, it will be wrong. Users can use Statues to determine the connection status. If TIMEOUT is specified, the current user Timeout is changed to a new connection for the currently connected.

The easiest implementation method is that Send does not give the control right to the sending process without the transmission of the data, but this may cause a deadlock (for example, both parties try to send, not receiving), the efficiency is not good. A good implementation method is to return control to the sending process after sending a data, of course, if you can send multiple Sends simultaneously, it is better. There are several Sends that need to be served first. For locally, we now assume that Send will generate similar interrupts when sending data, telling the sending process data transmission; of course, the Send can also tell the data transmission immediately after delivery. We can optimize sending is successful. If the send fails, the connection will be closed because of timeout. In implementation, even some asynchronous signals are required, but these asynchronous signals are used to process connections instead of for processing data transmission. Since multiple Sends are allowed to work simultaneously, it is necessary to distinguish it from the information that returns. The specific case will be discussed below.

Receive

Format: Receive (Local Connection Name, BYTE COUNT) -> Byte Count, Urgent Flag, Push Flag

This command assigns a received buffer to the specified connection. If the following is not an Open command or this call is not authorized to use this connection to return an error. The simplest implementation method is that the buffer is not filled before the control is not returned, but this may cause a serious deadlock.

转载请注明原文地址:https://www.9cbs.com/read-53830.html

New Post(0)