Current location - Quotes Website - Collection of slogans - Computer network-transport layer protocol
Computer network-transport layer protocol
From the perspective of communication and information processing, the transport layer provides communication services for the application layer on it, which belongs to the highest level of communication-oriented part and the lowest level of user functions. When two hosts at the edge of the network communicate end-to-end using the functions of the core part of the network, only the protocol stack of the host has a transport layer, while the router at the core part of the network only uses the functions of the last three layers when forwarding packets.

Let host A on LAN 1 and host B on LAN2 communicate through the interconnected WAN. We know that IP protocol can send packets sent by source host A to destination host B according to the destination address in the header, so why do we need transport layer?

From the IP layer, there are two hosts at both ends of the communication. The header of IP datagram clearly shows that the real communication entity between the IP addresses of two hosts is a process in the host, and one process in this host is exchanging data (that is, communication) with one process in another host. Communication between two hosts means that the application processes in the two hosts communicate with each other. Although the IP protocol can send the data packet to the destination host, the data packet still stays in the network layer of the host and will not be transmitted to the application process in the host. From the perspective of transport layer, the real communication endpoint is not the host, but the process in the host. In other words, end-to-end communication is communication between application processes. Usually, multiple application processes in one host communicate with multiple application processes in another host at the same time.

For example, when a user uses a browser to find website information, the application layer of his host runs a browser client process. If you want to send feedback to the website by email while browsing the webpage, the application layer of the host will also run the client process of email. In fig. 5- 1, application process AP 1 of host A communicates with application process AP3 of host B, and at the same time, application process AP2 also communicates with application process AP4 of the other party. This shows that the transport layer has a very important function-multiplexing and demultiplexing. "Multiplexing" here means that different application processes of the sender can use the same transport layer protocol to transmit data (of course, appropriate headers need to be added), while "demultiplexing" means that the transport layer of the receiver can correctly deliver these data to the destination application process ① after stripping the header of the message. In Figure 5- 1, there is a two-way thick arrow between the two transport layers, indicating that "the transport layer provides logical communication between application processes". "Logical communication" means: from the application layer, as long as the message from the application layer is handed over to the lower transport layer, the transport layer can pass the message to the other side's transport layer (even if the two sides are far apart, such as thousands of kilometers), as if this communication is to directly transmit data in the horizontal direction. But in fact, there is no horizontal physical connection between the two transport layers. Data transmission is along the direction of the dotted line in the figure (through multiple stages). "Logical communication" means "communication that looks like this, but it is not really such communication".

① Note: IP layer also has the function of multiplexing and demultiplexing. That is, the data of different protocols at the sender can be packaged into p datagrams and sent out, while the IP layer at the receiver is divided according to the protocol fields in the IP header, and the data stripped from the header is delivered to the protocol that should receive these data.

The network layer provides logical communication between hosts, while the transport layer provides end-to-end logical communication between application processes (see Figure 5-2). The transport layer has many other important functions that the network layer cannot replace.

The transport layer also needs to check the received message for errors. In the network layer, the checksum field in the IP datagram header only checks whether there is an error in the header, but not the data part.

According to the different requirements of applications, the transport layer needs two different transport protocols, namely connection-oriented TCP and connectionless UDP. The transport layer hides the following details of the network core (such as network topology, routing protocol, etc.). ) from high-level users, which makes the application process see that there is an end-to-end logical communication channel between two transport layer entities. However, due to the different protocols used by the transport layer, the performance of this logical communication channel to the upper layer is very different. When the transport layer adopts connection-oriented TCP protocol, the network is unreliable (only providing best-effort service), but this logical communication channel is equivalent to a full-duplex reliable channel. However, when the transport layer adopts connectionless UDP protocol, this logical communication channel is still an unreliable channel.

The two main protocols of TCP/P transport layer are the official standards of Internet: User Datagram Protocol (UDP); Transmission control protocol (TCP).

A data unit transmitted by two peer-to-peer transmission entities during communication is called TPDU (Transmission Protocol Data Unit (TPDU)). However, in TCP/IP system, it is called TCP segment or UDP user datagram according to the protocol used.

UDP does not need to establish a connection before transmitting data. The transport layer of the remote host does not need to give any acknowledgement after receiving the UDP message. Although UDP does not provide reliable transmission, in some cases, it is the most effective way to work.

TCP provides connection-oriented services. The connection must be established before data transmission and released after data transmission. TCP does not provide broadcast or multicast services. Because TCP provides reliable connection-oriented transmission services, it inevitably increases a lot of overhead, such as acknowledgement, flow control, timer, connection management and so on. This not only increases the number of protocol data unit headers, but also takes up a lot of processor resources.

The multiplexing and demultiplexing functions of the transport layer have been mentioned earlier. In fact, there are many examples of reuse and sharing in daily life. Suppose all departments of an organization send official documents to other units through the mailroom, which is equivalent to all departments "reusing" the mailroom. When receiving official documents from other units, the mail room should complete the function of "sharing", that is, deliver the official documents correctly according to the address of the government department written on the envelope.

The multiplexing and demultiplexing functions of the transport layer are similar. All application processes in the application layer can be transmitted to the IP layer (network layer) through the transport layer, which is multiplexing. After receiving the data sent by the IP layer to each application process, the transport layer must deliver it to the designated application process, which is called sharing. Obviously, it is very important to give a very clear sign to each application process in the application layer.

As we know, a process in a single computer is marked by a process identifier (a small integer). However, in the internet environment, it is not feasible to mark various application processes running in the application layer with this process identifier assigned by the computer operating system. This is because there are many computer operating systems used on the Internet, and different operating systems use different formats of process identifiers. In order to make the application processes of computers running different operating systems communicate with each other, it is necessary to use a unified method (which must be independent of the specific operating system) to mark the application processes of TCP/IP system.

However, it is not feasible to designate a specific process running on a specific machine as the final destination of communication on the Internet. This is because the creation and cancellation of processes are dynamic, and it is difficult for the communication party to identify the processes on the other machine. In addition, we often need to use the function provided by the destination host to identify the destination, without knowing which process has realized this function (for example, contacting a mail server on the Internet, without knowing which process on the destination host has realized this server function).

The solution to this problem is to use protocol port numbers at the transport layer, or simply ports. That is to say, although the end point of communication is the application process, as long as the transmitted message is delivered to an appropriate destination port of the destination host, the remaining work (that is, the final delivery of the destination process) will be completed by TCP or UDP.

Note that this abstract protocol port between protocol stacks is a software port, which is completely different from the hardware port on a router or switch. The hardware port is the interface for different hardware devices to interact, while the software port is the address for interaction between the application layer and various protocol processes in the transport entity. Different systems can implement ports in different ways (depending on the operating system used by the system).

The transport layer of TCP/IP marks a port with the port number 16. Please note, however, that the port number only has local significance, and it is only used to mark the inter-layer interface of each process in the application layer of this computer when interacting with the transport layer. In different computers on the Internet, the same port number is irrelevant. The port number of 16 allows 65535 different port numbers, which is enough for a computer.

In this way, in order to communicate with each other, the processes in two computers should not only know each other's P address (in order to find each other's computer), but also know each other's port number (in order to find the application process in the other computer). This is similar to the process of sending letters. When we want to write to someone, we must write down his mailing address on the envelope (this is to find his residence, which is equivalent to P address), and also write down the name of the recipient (this is because there may be several people in the same residence, which is equivalent to the port number). Write your address on the envelope, too It is easy to find the sender's address on the envelope when the recipient replies. Computer communication on Internet adopts client-server mode. When a client initiates a communication request, he must first know the P address and port number of the other server. Therefore, the port number of the transport layer is divided into the following two categories.

(1) Port numbers used on the server side are divided into two categories here. The most important category is called known port number or system port number, and the value is 0-l023. These values can be found on www.iana.org's website. Iana (Internet Assigned Numbers Authority) assigns these port numbers to some of the most important applications of TCPP, so that all users can know them. When a new application appears, IANA must assign it a well-known port, otherwise other application processes on the Internet will not be able to communicate with it.

The other is called the registered port number, and the value is1024-49151. This port number is used by applications that are unfamiliar with port numbers. The use of such port numbers must be registered with IANA according to the prescribed procedures to prevent duplication.

(2) The port number used by the client is 49 152-65535. Because this port number is dynamically selected when the client process is running, it is also called transient port number ①. This port number is reserved for the client process to choose for temporary use. When the server process receives a message from the client process, it knows the port number used by the client process, so it can send data to the client process. After the communication, the client port number just used no longer exists, and this port number can be used by other client processes.

① Note: A short-lived port means that the port exists for a short time. The client process does not care about the port number assigned to it by the operating system, because the client process must have a port number (which must be unique in the local host) so that entities in the transport layer can find themselves. This is different from the well-known port. As soon as the server is turned on, the server program starts running. In order for all client programs on the Internet to find the server program, the port used by the server program (that is, the well-known port) must be fixed and well-known.