TCP protocol specification

zhaozj2021-02-08  262

Transmission Control Protocol (TCP) TCP Protocol Lord implements high reliability package exchange transfer protocols between hosts. This article will describe some methods of protocol standards and implementation. Because computer networks are indispensable in modern society, TCP protocols are mainly used when the network is unreliable, and the military may be particularly useful, but it is also applicable to the government and commercial departments. TCP is a reliable protocol that is connected to end-to-end. It supports a variety of web applications. TCP does not require much requirements for the underlying service, it assumes that the lower layer can only provide unreliable datagram services, which can run on a network composed of a variety of hardware. The following figure is the location of the TCP in the hierarchical structure. Its underlying is the IP protocol, and the TCP can segment, reorganize the data according to the data transmitted in the IP protocol, and the IP protocol is responsible for segmentation, reorganizing the data, in a variety of networks Transfer. The top of the TCP is the application. The following is the IP protocol, the upper interface includes a series of calls similar to the operating system interrupt. For the upper application, TCP should be able to transfer data asynchronously. The underlying interface We assume an IP protocol interface. In order to implement a connection-oriented reliable transmission data on a unreliable network, TCP must resolve reliability, traffic control, must be able to provide multiple interfaces for the upper application, and provide data for multiple applications while TCP The connection problem must be resolved, so that TCP can be called up-oriented, and finally, TCP must also be able to solve communication security issues. The network environment includes a network connected by a gateway (or other device), the network can be a local area network or some metro network or a wide area network, but no matter what they are, they must be based on packet exchange. Different protocols on the host have different port numbers, and a pair process communicates through this port number. This communication does not include I / O operations within the computer, including only operations on the network. Computers on the network are viewed as the source and destination of the package. It should be noted that different processes in the computer may communicate simultaneously, when they use port numbers that do not receive the data of the forward A process by the B process. In order to transfer data, the process will call the TCP, transfer the data and the corresponding parameters to the TCP, so TCP will transfer the data to the destination TCP, of course, by transmitting the TCP package in the IP package to the network. The receiver TCP communicates the upper application after receiving the data, and the TCP guarantees the correctness of the receiving data order. Although the underlying protocol may not guarantee the order is correct. What needs to be explained here is that after receiving this package, it will be packed, see if it has already arrived, if not, what is the route to achieve the destination, after the decision, the gateway will be based on the next one The protocol in the network is once again transmitted the TCP package. If necessary, you have to divide this package into several segments. The process of this landing check is a time consuming process. From above, we can see the basic procedure of TCP transmission, of course, the specific process may be much more complicated. On the host of TCP, TCP can be seen as a module, and the file system is not very different. TCP can also call some operating system functions, TCP does not directly and network, control the network task by dedicated device drive module carry out. TCP only calls the IP interface, and the IP provides services that all TCPs needed to TCP. Through the figure below, we can see the structure of the TCP protocol. It has been said that the TCP connection is reliable, and ensures the order in which the packet is transmitted, and the guarantee order is guaranteed by a serial number. A serial number is also included in the response package, indicating that the recipient is ready for the package.

When the TCP transmits a packet, it places this packet into the retransalence queue while starting the numeric, if you receive the confirmation information about this package, remove this package from the queue, if the timing timeout Re-send this package. Note that the confirmation information returned from TCP does not guarantee that the final recipient receives the data, which is the responsibility of the recipient. Each channel for transmitting TCP has a port mark because this tag is determined by each TCP terminal, so TCP may not be unique, in order to ensure the unique value of this value, to use the network address and port number to achieve unique The purpose of the identification, we call this for sockets, a connection is identified by a socket on both ends, local sockets may communicate with different external sockets, which is a full-duplex. The TCP returns a name that tag this connection by sending an Open command and an external socket parameter to the local port, the TCP returns a name that tag this connection. If the user needs to use this name to mark this connection. In order to save this connection, we assume that there is something called Transmission Control Block, TCB to save. The OPEN command also specifies that the establishment of this connection is a proactive request or passive waiting request. Below we have to involve specific features, the TCP segment is transmitted in the form of Internet Datashers. The IP header transmits different information fields, including source addresses and destination addresses. The TCP header follows the Internet header, providing some information dedicated to the TCP protocol. The picture below shows the TCP cladding format map: source port: 16 digits; destination port: 16-digit series: 32-bit, when SY is appeared, the sequence code is actually the initial sequence code (ISN), and the first data byte is ISN 1; confirmation code: 32 bits, if the ACK control bit is set, this value represents a sequence code for preparing the package; the data offset: 4 digits, indicating where the data begins; retain: 6 bits, these bits must Is 0; control bit: 6 digits; window: 16 bits; check digits: 16 bits; priority pointer: 16 bits, pointing to the byte of priority data; option: long; but the length must be byte; The specific content we are in connection with specific commands; padding: unordered, the content of the filled must be 0, it is to ensure that the binding of the header and the start of the data can be 32, we have said in front, there is a TCB Things, the TCB has variables such as buffer pointers including the sender, the receiver, the transmission and reception of the user. In addition to these variables and send reception serial numbers: Send sequence variable SND.una - Send unrecognized SND.NXT - Send the next SND.Wnd - Send Window SND.UP - Send Priority Pointer SND.WL1 - Used for Finally Window updated sequence number SND.WL2 - Segment authentication number for the last window update ISS - initial transmission number receiving serial number RCV.NXT - Receive the next RCV.Wnd - Receive the next RCV.UP - Receive Priority Pointer IRS - Initial reception sequence number The picture below will help you understand the relationship between sending sequence variables:

Current paragraph variable seg.seq - segment sequence number seg.Ack - segment confirmation mark seg.len - Section long seg.Wnd - Segment window seg.up - Segment emergency pointer seg.prc - segment priority connection process is through a series of states It is expressed, these states are: Listen, Syn-Sent, Syn-Received, Established, Fin-Wait-1, Fin-Wait-2, Close-Wait, Closing, Last-Ack, Time-Wait, and Closed. Closed indicates that there is no connection, the meaning of each state is as follows: Listen - Listening to the connection request from the distant TCP port; SYN-SENT - Synn-time waiting to match the connection request after sending the connection request; Syn-Received - receive and send a connection request After waiting for the confirmation of the connection request; ESTABLISHED - represents an open connection, the data can be transmitted to the user; Fin-Wait-1 - Wait a confirmation of the connection interrupt request of remote TCP, or confirmation of previous connection interrupt requests; Fin-Wait-2 - From the remote TCP waiting for the interrupt request; Close-Wait - Wait a connection request from the local user; Closing - Wait for remote TCP to confirm the connection interrupt; Last-Ack - Wait for the original connection interrupt request to remote TCP Confirm; Time-Wait - Wait a sufficient time to ensure a confirmation of the connection interrupt request; Closed - no connection status; the TCP connection process is a state transformation, which causes the state to convert: Open, Send, Receive, Close, Abort, and Status; the transferred data segment, especially those that include the following marked data segments SYN, ACK, RST, and FIN; there are timeouts, which will change when the TCP state is changed. The following figure shows the conversion of the TCP state, but this figure does not include errors and errors, do not see this picture as a general explanation. 3.3. Serial number Please note that the bytes we sent in TCP have a serial number. Because it is compiled, you can confirm that they have received. The confirmation of the serial number is accumulated, that is, if the user receives the confirmation information of X, this means that the data before X (not including X) is received. The byte is arranged in each paragraph: the first byte is arranged behind the header and in this order. We need to think that the actual sequence space is limited, although it is very large, but it is still limited, its range is 32 times of 32 times of 2. I want to be familiar with the programming must know why it is necessary to use 2 32 times when calculating two sections. The serial number comparison operation species that TCP must perform include the following: (a) Decide some of the sent but unrecognized serial numbers; (b) determine that all serial numbers have been received; (c) determines the next segment The serial number that should be included.

For the transmitted data TCP to receive confirmation, the following comparison operation must be performed when the processing is confirmed: SND.UNA = the oldest confirmation sequence number; SND.NXT = The next serial number to send; seg.ack = Receive TCP Confirmation, receive the next serial number of TCP expectation; seg.seq = first serial number of a data segment; seg.len = data included in the data segment; seg.seq seg.len-1 = data The last serial number of the segment. Note the relationship below: SND.una

Receive window

Test 0

0

Seg.seq = rcv.nxt 0

> 0

Rcv.nxt = 0

0

Unacceptable> 0

> 0

Rcv.nxt = b SYN The serial number is X 2) A <- b ACK This sequence number is confirmed 3) A <- b SYN The other party serial number is Y 4) a-> b ACK confirmation The second steps and third steps above the other party can be merged. At this time, it can be a 3-stage, so we can call it three messages. This process is necessary, because the serial number does not associate with the global clock, TCP can also have different mechanisms to select ISN. The receiver receiving the first SYN cannot know that this data segment is not delayed unless it remembers the nearest serial number used in the connection (this is usually impossible), so it must require the sender confirm. In order to ensure that the confirmation of TCP is generated by the segment sent, not still generated in the old data segment in the network, so TCP must remain silent within the MSL time. In this article, we assume that MSL = 2 hours, this is for engineering needs, if the user feels that he can change the MSL.

Note that if the TCP is reinitial, the serial number in the memory is being used, but it is not necessary to confirm that the serial number used is larger than the current usage. If a host fails without retaining any serial numbers, it should not issue any data segments within the MSL time. This will be described below. The implementation of TCP may not comply with this rule, but this will cause old data to be received as new data, and new data is used as an old data rejection. Whenever the data segment is formed and enters the output queue, the TCP will specify a value in the sequence space. Multiple reputation detection and sequence algorithms in TCP rely on this address space, and 32 times that will not exceed 2 before the other party is transmitted or received, in the output queue. All excess data segments will be deleted. If there is no such provision, there will be a case where multiple data segments are assigned the same serial number, which will cause confusion. The serial number in the data segment is as much as the number of bytes in the data segment. Under normal circumstances, TCP retains the next serial number to send and the oldest serial number that has not been confirmed, do not use it again without confirmation, this will be a bit risk, it is because of this purpose, so the sequence The space is very. For 2M network, it takes 4.5 hours to deplete the sequence space, because a data segment may have a maximum survival time is not more than ten minutes, which has a sufficient space; and 5.4 minutes on the 100M network. Although it is less, it is also possible. If there is no space for the saving serial number when implementing the TCP, the clearing package may not be implemented, so recommending this type of TCP implementation is best waiting for MSL time after failure, so that excess pack is deleted. This situation sometimes occurs in the TCP implementation of the reserved serial number. If the TCP is selected when selecting a sequence number being used by another TCP connection, this host suddenly failed, which has a problem. The essence of this problem is that the host does not know how long it has failed, and it doesn't know that the extra copy is still in the network. The way to deal with this problem is to wait for the MSL time. If it is not, it is necessary to take the risk of receiving the data, and wait for the time to be called "silence time." The implementation can make the user choose whether it is waiting, but no matter how the user is not waiting for MSL time. 3.4. Creating a connection to establish 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 status If one party is closed without passing the connection, or the two parties have different steps in different steps. 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. In addition to other states outside the SYN-SENT state, the RST process 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 "this part 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 is listed below: Situation 1: Local users closes this case, you can create a FIN segment to place 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. Situation 2: TCP receives a FIN from the network if the FIN is received without the request, the TCP can return ACK and notify 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 closes the two parties simultaneously closing 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 safety TCP operations must be done between 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 has established a connection to transfer data. TCP is reloaded to each data segment, because there is a re-transfer, so the other party may receive two identical packages, so it must be based on internal serial numbers. Judging which data segment 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. Revitalization timeout because there is no type of network in the network, and 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) 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 the lower boundary of the timeout (such as 1 second), Alpha is smoothing factor (such as 0.8 to 0.9), beta is a delay variable (such as 1.3 to 2.0). The emergency mechanism for transmitting the emergency message TCP 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, so it does not distinguish who is first. 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. Here are some suggestions: When using fewer big data, allocate very small windows to make 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. The hierarchical structure of the interface network protocol determines that TCP has two interfaces, upward user interfaces, and the following interface. 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. Some TCP commands are described below under the User / TCP interface, 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. The commands defined below the TCP User Commands are similar to those defined in other advanced languages, but some trap are 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. To implement communication, TCP cannot only receive commands, and can return messages to its service process, including: (a) Topic messages about connections, such as interrupt, remote shutdown, etc.; (b) doing user commands By picking up, it is successful or failed. Open format: Open (Local Port, Foreign Socket, Active / Passive [, Timeout] [, Precedence] [, Security / Compartment] [, Options]) -> Local Connection Name We assume that local TCP notes the process tags it serve And will check the process of the process. 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, Buff, Urgent Flag [, Timeout]) This command allows the data to specify the data in the specified buffer, returns an error if the connection is not opened, some implementation The SEND may be called 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, Buffer Address, Byte Count) -> Byte Count, Urgent Flag, PUSH FLAG This command assigns a receive 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. More complex implementation methods Allow multiple receivers at the same time, which will increase efficiency. This makes high efficiency in the case of control complicated. If the data before PUSH has filled the buffer, then a PUSH bit is not set to the Receive response. The buffer will contain as many data as possible, and if you see the Push bit before the buffer is filled, the data in the buffer is returned and the PUSH is set. When processing emergency, if there is a Urgent tag, there is an emergency data; if there is no Urgent tag, all emergency data is returned, and the user leaves the emergency state. Note that those data after the emergency pointer points to the point of the emergency cannot return with the emergency data, even if they are in the same buffer, of course, if the user specifies to do this. In order to distinguish multiple Receive and ensure that the buffer is not full, the returned data should also include a buffer pointer and a counter indicating how much data is received. Receive can have its own buffer, or you can share a buffer with the user. Close format: Close (Local Connection Name) This command off connection if the connection is not open, or unauthorized can turn off the connection back error. At the time of closing, you should pay close to normal shutdown, so that all senders are transmitted, or as mentioned above, add a few Sends, which requires the user to still be received after receiving the Close. Therefore, Close means "I don't have more data to be sent", it doesn't mean "I will no longer send any data." The shutdown party may not issue all the data before the timeout, in which case it is transferred to the Abort state by Close. Users can decide to close the connection at any time, or close according to the prompt returned by the TCP. So close the operational and external TCP for communication, so in the closed state, you may stay in a time, and the call is turned on before the Close is not returned, and an error will be returned. Status format: status -> status data This command is related to specific implementations, and it may have a negative effect. The returned information is typically derived from a connection-related TCB. The following information is included in the data block: local socket, jacket, local connection name, receive window, send window, connection status, wait for the number of buffers, waiting for the number of buffers, emergency, Priority, Security / Compartment, and Transmission Timeout. Therefore, there is different, so there may be no meaning or do not exist in the above data items. If the calling process is not authorized to use this connection, return an error. This will prevent unauthorized processes from getting a connection status. Abort format: Abort This command aborts all Send and Receive, delete TCB, will send a special reset information to the other party TCP. The specific return information will vary depending on the implementation. TCP to user information assumes that the operating system provides a mechanism that allows TCP asynchronous transmission information to the user program. Some specific information will be returned when TCP does notify the user program. Usually there will be error messages in this information, and in other cases information about completing Send or Receive or other user calls.

The following message will be provided: the local connection name provides a response string to provide buffer address transmission and receiving bytes to receive the PUSH tag Receive the Urgent tag to receive the TCP and the lower interface TCP actually call the underlying service to transmit data on the network. We usually think that the next layer of TCP is an IP protocol. If the next layer is an IP layer, it provides some parameters for the type of service and the time of life. TCP uses these parameters as follows: type of service = precedence: Routine, Delay: Normal, Throughput: Normal, Reliability: Normal; or numeric 00000000. Time to Live = One minute, or numeric 00111100. Please note: Assuming maximum data segment is 2 minutes, here is a $ 1 minute. If the lower layer is IP and uses the source address rout, the interface must allow communication of routing information. This is important for establishing connectivity and routing. Of course, it is also possible to use IP protocols as the underlying protocol of TCP, but no matter what the lower level protocol is, the source address, destination address, and protocol domain, and some domains that determine the TCP length, in sum, to provide similar to IP Function. 3.9. Event Process The process below is possible, other implementations, and this example may have a little bit different, but only in detail, and will never be the result. TCP activities can be summarized as responses to events. Events can be divided into three categories: user call, receive data segments, and timeouts. The following describes the response of TCP on specific events, in many cases, related action (response) is related to the connection state. The user calls are: Open Send Receive Close Abort Status Received Data Section: Segment Arrives Timeout A: User Timeout Retransmission Timeout Time-Wait Timeout TCP may be immediate or delayed. The error message is given in the form of a string. Below is a specific error message: Error: Connection Not Open. Also, remember 32 times the serial number of space size is 2. The order of processing data segments is first received, then check the serial number, if it is to be received, put the reception queue. In addition, the TCP maintains the original state when the state shift is not explained. Open Call the Closed Status Creating a new TCB Save Connection Status information, populates the local socket tag, jacket, priority, security / compartment, and user timeout information. Note that a portion of jacket is not explained in passive open. If it is proactive, the jacket is not specified, returns "error: foreign socket unspect"; if it is active, the jacket is specified, send a SYN data segment. Select the initial sequence number ISS. The format of the SYN data segment is as shown in , set SND.una to ISS, SND.NXT is ISS 1, and the SYN-Sent status is performed, and then returns. If the caller cannot access the specified local socket, return "Error: Connection Illegal for this Process". Returns "error: insufficient resources" if there is no space to receive a new connection.

If the Listen State is in active, the jacket is specified, the connection can be changed from passive to active and select ISS. Send a SYN data segment, set SND.UNA for ISS, SND.NXT is ISS 1. Enter the SYN-SENT state. The data along with the Send can be sent with the SYN data segment, or it can be sent after entering the Established state. Returns "Error: Insufficient Resources" if there is no space reception request. Returns "Error: Foreign Socket Unspecified" if not specified. If you are in the following status: SYN-Sent status, Syn-Received, Established status, Fin-Wait-1 state, FIN-WAIT-2 state, Close-Wait state, closing status, return status, Last-Ack status, or Time-Wait state "Error: Connection Already EXIXSTS". Send Calls CLOSED Status If the user does not have access to the connection, return "Error: Connection Illegal for this process". Otherwise returns "Error: Connection Does Not Exist". Listen Status If the jacket is specified, the connection can be changed from passive to active, select an ISS. Send the SYN data segment, set SND.una as ISS, SND.NXT is ISS 1. Enter the SYN-SENT state. The data along with the Send can be sent with the SYN data segment, or it can be sent after entering the Established state. If there is no space reception request, return "Error: InsufFFicial Resources", if you do not specify the jacket, return "Error: Foreign Socket Unspecified". When the SYN-Sent Status and Syn-Received are entered after entering the ESTABLISHED state, the data will be sent to the queue. Returns "Error: Insuff Indicient Resources" if the queue is already free. The ESTABLISHED Status and Close-Wait Status will buffer zone segment, send buffer data, and make it a confirmation value Rcv.nXT. Returns "Error: Insufficient Resources" if there is no space saving buffer. If an emergency tag is set, Snd.up <- snd.nxt-1 is set, and set the emergency pointer points to the corresponding position in the transmitted data segment. Returns "Error: Connection Closing" when Fin-Wait-1, FIN-WAIT-2, Closing, Last-Ack, and Time-Wait status, and ignore requests. Receive Calls CLOSED Status If the user doesn't have the right to access this connection, return "Error: Connection Illegal for this Process". Returns "Error: Connection Does NOT" if there is right. After entering the EstablisHed state in Listen, Syn-Sent, and Syn-Received, put the data into the queue preparation process. If there is no space in the queue, return "Error: Insufficient Resources".

In the Establish, Fin-Wait-1 and Fin-Wait-2 states, if there is no enough data segment satisfied request, put the queue. If there is no space record receive in the queue, return "Error: Insufficient Resources". Reissue the received data segment into the received buffer and return to the user. In this case, a PUSH flag can be set. If rcv.up is larger than it is transmitted to the user, it is notified that there is emergency data. Close-Wait Status Because the distant TCP has sent FIN, Receive must be satisfied by the current buffer but not transmitted to the user. If there is no data, Receive will get the response of "Error: Connection Closing". Returns "Error: Connection Closing" in Closing, Last-Ack, and Time-Wait. Close calls a CLOSED status If the user doesn't have the right to access this connection, return "Error: Connection Illegal for this process". Returns "Error: Connection Does NOT" if there is right. Any receive that exists in the Listen state will return the response of "Error: Closing". Delete the TCB and then go to the Closed status and return. The SYN-Sent Status deletes the TCB and returns "Error: Closing" responded to any Send or Receive in the queue. Syn-Received Status If SEND is not sent, the data segment is formed and transmitted, and the FIN-WAIT-1 state is formed; otherwise save the command in the queue in the queue after entering the EstabLisHe. ESTABLISHED Status Save this command in the queue until all the Send is completed, form and send the FIN data segment, and then enter the Fin-Wait-1 state. Strictly speaking in the Fin-Wait-1 and Fin-Wait-2 states, this will be an error and will receive "error: connection closing". As long as the second FIN is not issued, you can also receive a "OK" response. Close-Wait Status When all Send commands are completed, put this request in queue; then send the FIN data segment, enter the CLOSIING state. Returns "Error: Connection Closing" in Closing, Last-Ack, and Time-Wait state. Abort Calls CLOSED Status If the user doesn't have the right to access this connection, return "Error: Connection Illegal for this Process". Returns "Error: Connection Does NOT" if there is right. There should be "Error: Connection Reset", delete the TCB, go to the Closed state, and return to the CLOSED status. SYN-SENT Status Returns "Connection RESET" for all Send and Receive in the queue, delete TCB, go to the Closed status, and then return.

Send data segment for all Send and Receive, all in the queue in the queue Returns "Connection RESET", etc. All data segments to perform transfer or reload immediately, delete the TCB, enter the Closed status, and then return. Returns "OK" in CLOSIING, LAST-ACK, and TIME-WAIT, delete TCB, go to the Closed status, and then return. Status calls a CLOSED status If the user doesn't have the right to access this connection, return "Error: Connection Illegal for this Process". Returns "Error: Connection Does NOT" if there is right. Listen Status Returns "State = Listen" and TCB pointer. SYN-SENT Status Returns "State = SYN-SEND" and TCB pointers. Syn-Received status Returns "State = Syn-ReceiveD" and TCB pointers. ESTABLISHED Status Returns "State = ESTABLISHED" and TCB pointers. Fin-Wait-1 Status Returns "State = Fin-Wait-1" and TCB pointers. FIN-WAIT-2 Status Returns "State = Fin-Wait-2" and TCB pointers. Close-Wait Status Returns "State = Close-Wait" and TCB pointers. Closing Status Returns "State = Closing" and TCB pointers. Last-Ack Status Returns "State = Last-Ack" and TCB pointers. Time-Wait Status Returns "State = Time-Wait" and TCB pointers. If the data segment is in a closed state, all arrival data is abandoned. It is no exception to RST. Returns an RST if the received data segment does not include RST. For sending TCPs To select it confirmation and serial numbers that it can cognition. If the ACK bit is turned off, the serial number is 0, the format is as follows: If the ACK bit is turned on, the format is as follows: . If in the Listen state, first check the RST, the received RST should be ignored. You should check the ACK. If the connection is in the Listen state, any ACK is wrong. It should return the RST segment, its format is as follows: . The third step should check SYN, if the SYN bit is set, check security, if the security / compartment in the receiving data segment is not matching in the TCB, return the RST segment, the format is as follows: .

In the case where the seg.prc is greater than TCB.PRC, if the user and system allow, set TCB.PRC <-SEG.PRC, if the user and system are not allowed, send the RST segment and returns. The format is as follows: . If seg.prc is smaller than TCB.PRC, continue. Set RCV.NXT to Seg.SEQ 1, IRS is a value in Seg.Seq, other control information, and data. You should choose ISS and send the SYN segment, which is as follows: . SND.NXT is set to ISS 1, and SND.UNA is set to ISS, and the connection state is changed to SYN-Received. Other control information and data will be processed in the Syn-ReceiveD state, but the processing of SYN and ACK should not be repeated. If you are not fully specified, you should be specified. The fourth step is to process other data and control information. Other data segments (excluding SYN) should have an ACK, so do not perform ACK processing. If the RST segment is received, it is illegal. If it is indeed receiving, discard it, return directly. If it is in the SYN-SENT state. First check the ACK bit, if the ACK bit is set, and seg.Ack = SND.NXT is sent to send RST. (Unless the RST bit is set, if so, the data segment is discarded directly). The format of the RST segment is as follows: . Don't use the data segment you receive and return directly. If SND.UNA = , if there is no ACK, the format is .

When there is no mismatch, if there is an ACK, the priority in the segment must be in the TCB, if not, the RST is sent, the format is: ; if not Discover mismatch, and without ACK, if the priority in the received data segment is higher than the priority in the TCB, the priority in the TCB can be raised in the case where the user and system license are obtained, if the user Or the system is not allowed, increase the PREC, then send RST: in the following format, if the priority in the received data segment is less than in the TCB The priority continues. After the RST is sent, the data segment is discarded and returned. Step 4 Check the SYN bit. This step can only be made only if the ACK bit is legal or there is no ACK and does not include RST in the data segment. If the SYN bit is set, the security / compartment and priority are legal, then rcv.nxt is set to Seg.SEQ 1, and IRS is set to Seg.seq. SND.UNA should be increased and Seg.Ack is equal, and the data segment that is waiting for confirmation in the resend queue and now has been confirmed. If SND.una> ISS, changing the connection status is ESTABLISHED to form the ACK segment in the following format and send: . The control information of the data used to transmit in the queue also sends together, and if there is no data or control information in the segment, the sixth step is performed, otherwise it will return. If SND.una> ISS is not true, forming the SYN, ACK segment, format as follows: , and send it. If there is no data or control information in the segment, the process is processed after the Established state is entered. The fifth step, if the SYN or RST bit is not set, the data segment returns. Let's take a look at other states. First check the serial number. In the following state, the Syn-10 State ESTABLISHED Status FIN-WAIT-1 Status Fin-Wait-2 Status CLOSE-WAIT Status The LAST-ACK Status Time-Wait Status Segment is handled in order, first abandon repetition segments, for future Processing is done according to the size of Seg.seq. If the new and old content in some segments are overlapping together, it is only used to handle the new part. Below is four cases in the acceptability test of the received data: segment length

Receive window

test

0

0

Seg.seq = rcv.nxt

0

> 0

Rcv.nxt =

> 0

0

Not accept

> 0

> 0

Rcv.nxt =

If rcv.Wnd = 0, other data segments are rejected other data segments in addition to legitimate ACK, URG, and RST sections. If the received data segment is unacceptable, a response should be returned, the format is as follows: . After sending a response, discard the unacceptable data segment and return. The second step checks the RST bit. If it is in the Syn-ReceiveD state, and in the case where RST is set, if the connection begins with passive Open, return the connection to the Listen state, and do not need to notify the user; if the connection is opened, the connection, and notify the user " Connection Refused. In any of the cases, all data in the retrace queue is deleted. In the case of active Open, enter the CLOSED state, delete the TCB and return. If you are in the Establish, Fin-Wait-1, Fin-Wait-2 or Close-Wait state, and RST has been set, any existing receive and send will receive "reset". The data segments in all queues should be sent immediately. Users will also receive "Connection RESET". Enter the CLOSED state, delete the TCB and return. If you are in a Closing status, a Last-Ack status, or a Time-Wait state, and RST has been set, go to the Closed status, delete the TCB and return. Check security and priority If the Syn-Received state is sent to the SECURITY / Compartment and the priority and the mismatch in the TCB in the segment, the RST is sent and returned. In the ESTABLISHED state, if the SECURITY / Compartment and the priority and TCB in the segment are sent to the mismatches in the segment, all existed Receive and Send receive "reset", send data segments in all queues, and users receive "Connection" ". Enter the CLOSED state, delete the TCB and return. Step 4 Check the SYN bit, if the connection is in the following status Syn-Received Established Status Fin-Wait State-1 Fin-Wait State-2 Close-Wait Status Closing Status Last-Ack Status Time-Wait Status If SY is in the window is incorrect , Send RST, any existed Receive and Send Receive "reset", all of which are sent immediately in the queue, and the user also receives "Connection RESET", enter the Closed state, delete the TCB and returns. This step does not happen if SYN is not in the window. Step 5 Check the ACK field If the ACK bit is turned off, the data segment is returned. If the ACK domain is opened, if the connection is in the Syn-ReceiveD state, if SND.una = if snd.una

The user should receive active confirmation of the buffer, if the ACK is repeated (seg.ck SND.NXT), you can send an ACK to discard the data segment and return. If SND.UNA . CLOSE-WAIT status, closing status, Last-Ack status or Time-Wait status will not occur at all, because Fin has not been received from remote TCP. Step 8 check the FIN bit. If the status is CLOSED, LISTEN, or SYN-SEN, do not process FIN, because Seg.seq will not be in the meaning of Seg.seq, should directly discard the data segment. If the FIN bit is set, inform the user "Connection Closing" to abort all the pro-undergoing Receive, add RCV.NXT to more than FIN, send confirmation for FIN.

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

New Post(0)