Transmission Control Protocol (TCP)
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, 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 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. The initial serial number selection protocol has no restrictions on specific connections. 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 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.