Transmission Control Protocol (TCP) (on)

xiaoxiao2021-03-06  45

The TCP protocol master implements high reliability package exchange transfer protocols between the host. 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. 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 following figure is the TCP cladding format:

Source port: 16 bits;

Destination port: 16 digits

Sequence code: 32 bits, when SYN appears, 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 received package;

Data offset: 4 digits, indicating where the data begins;

Retain: 6 digits, these bits must be 0;

Control bit: 6 digits;

Window: 16 bits;

Check bit: 16 bits;

Priority pointer: 16 bits, pointing to the byte of priority data;

Options: The length is uncertain; but the length must be in byte; the specific content of the options we combine specific commands;

Fill: Unit, the content of the filled must be 0, which is to ensure the binding of the header and the start of the data of the data can be divided by 32;

We have already said that there is a TCB, and the TCB has variables such as a buffer pointer including a sender, a receiver, a transmission and reception of a user. In addition to these, there are some variables and send reception sequence numbers:

Send sequence variable

SND.una - sending unconfirmed

SND.NXT - Send the next one

SND.Wnd - Send Window

SND.UP - Send a priority pointer

SND.WL1 - Segment serial number for the final window update

SND.WL2 - Segment authentication number for the last window update

ISS - initial sequence number

Receive serial number

Rcv.nxt - Receive the next one

Rcv.Wnd - Receive the next one

RCV.UP - Receive Priority Pointer

IRS - initial reception serial number

The following figure will help you understand the relationship between sending sequence variables:

Current paragraph variable

Seg.seq - Segment serial number seg.Ack - segment confirmation tag

Seg.len - Section

Seg.Wnd - Segment window

Seg.UP - Segment emergency pointer

Seg.prc - Segment priority

The connection process is expressed in a series of states, 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 - Wait a connection request after sending a connection request;

SYN-Received - Wait a confirmation of the connection request after receiving and sending a connection request;

ESTABLISHED - represents an open connection, data can be transmitted to the user;

FIN-WAIT-1 - Wait for remote TCP connection interrupt request, or confirmation of previous connection interrupt requests;

FIN-WAIT-2 - From Remote TCP Waiting for Connection Request;

Close-Wait - Wait a connection interrupt request from a local user;

Closing - Waiting for remote TCP to confirm the connection interrupt;

Last-Ack - Waiting for the confirmation of the connection interrupt request to the remote TCP;

Time-Wait - Wait enough time to ensure the confirmation of the remote TCP to receive the connection interrupt request;

CLOSED - No connection status;

The TCP connection process is a state transition that causes the state to convert the user call: Open, send, receive, close, abort, and status; transmitted data segments, especially those including the following markers SYN, ACK, RST, and FIN There is also timeout, what is said to the TCP state changes.

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 sent in the TCP connection 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 of the TCP must perform the species types include the following:

(a) Decide some of the sequence numbers sent but unrecognized;

(b) Deciding that all serial numbers have been received;

(c) Determine the serial number of the next segment.

For the sending data TCP to receive confirmation, the following comparison operation must be performed when the processing is confirmed:

Snd.una = the oldest confirmed serial number;

SND.NXT = The next serial number to send;

Seg.ack = Receive TCP confirmation, receive the next serial number of TCP expectation;

Seg.seq = the first serial number of a data segment;

Seg.len = number of bytes included in the data segment;

Seg.seq seg.len-1 = the last serial number of the data segment. Please pay attention to the following relationship:

SND.UNA

If the serial number of a data segment is less than the value equal to the confirmation number, the entire data segment is confirmed. The comparison operation below when receiving data is required:

Rcv.nxt = The desired serial number and the minimum edge of the receiving window;

Rcv.nxt rcv.Wnd-1 = the last serial number and the highest edge of the receiving window;

Seg.seq = The first serial number received;

Seg.seq seg.len-1 = the last serial number received;

The above quantity has the following relationship:

Rcv.nxt =

The first part of the test is to check if the start portion of the data segment is in the receiving window, and the second part is to check if the end portion of the data segment is also within the receiving window; the above two checks indicate the data of the window required by the window. The actual situation will be more complex, because there are zero windows and zero data segments, so we have the following four situations:

Segment length

Receive window

test

0

0

Seg.seq = rcv.nxt

0

> 0

Rcv.nxt =

> 0

0

Unacceptable

> 0

> 0

Rcv.nxt =

Note that the size of the received window can be zero, which is only used to receive the ACK information, so for a TCP, it can use the zero size window to receive data while sending data. Even if the received window is zero, the TCP must process all RSTs and URG domains that receive information.

We also apply some specific control information by implicitly using some control markers to reliably resend (or confirm) by implicitly using some control markers. Control information is not transmitted in segment data space, so we must control it with implicit specified serial numbers. SYN and FIN are the amount of control that requires protection, both of which are only used when the connection is turned on and off. SYN is considered to be data between the first actual data, and Fin is the data after the last actual data. Segment length (seg.lend) includes data and serial number space, if SYN appears, seg.seq is the serial number of SYN.

Initial serial number selection

There is no restriction on the specific connection is reused for a particular connection. The connection is defined by a pair of sockets. The new connection instance is defined as another recovery of the connection, which brings a problem: TCP If it is determined that multiple data segments are made from the other recovery of previously connected? This problem is displayed quickly on the connection and closing, or because the memory is turned off and then rapidly established.

In order to avoid confusion, users must avoid therefore recovery to use a certain connection, and make the serial number chaos. We must ensure the correctness of the serial number, even if the TCP fails, do not know what the previous serial number is the correctness of the serial number. When a new connection is created, a new initial sequence number (ISN) generating child is generated, which is used to select a new 32-bit ISN. The low-level byte of the generated sub-and 32-bit clock is related to the low-zone refresh frequency is about 4 microseconds, so the cycle time of the ISN is approximately 4.55 hours. So we put the longest survival time (MSL) of the network package less than 4.55 hours, so we can think that ISN is unique. For each connection, there is a sequence number and receiving serial number, the initial transmission serial number (ISS) is selected by the transmission TCP, and the initial reception serial number is generated during the connection establishment process. For connections to be connected or initialized, two TCP must be synchronized with the initial serial number of the other party. This is done by switching a control bit SYN and the initial serial number. We refer to "SYNS" with SYN data segments. The synchronization process is not repeated here, each must send its own serial number and return to the confirmation of the other serial number.

1) a-> b Syn this sequence number is X

2) A <- b Ack this sequence number is confirmed

3) A <- b Syn each other serial number is Y

4) A -> b ACK confirm the other party serial number

The second steps and third steps above 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.

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

New Post(0)