Transport layer: UDP protocol

The transport layer provides communication services to the application layer above it. When a process in the application layer sends a message, the message will be added with control information on the application layer. It is then delivered to the transport layer below it. After the transport layer receives the message, it processes it, and then delivers it to the lower layer... This section summarizes the relevant knowledge of the lower transport layer, which mainly summarizes related knowledge such as UDP. As for the most important TCP, a separate summary is opened.

Knowledge points

Insert picture description here

1. Transport layer agreement

1. Communication between processes

(1) Notice

When two computers at the edge of the network use the functions of the core part of the network for end-to-end communication, only the host's protocol stack has a transport layer. The router at the core of the network only uses the protocols below the transport layer when forwarding packets (only the lower two layers are used in the TCP/IP protocol, namely the Internet layer and the network interface layer. Only the lower three layers are used in the five-layer network protocol. , Namely network layer, data link layer, physical layer.)

(2) Question resolution

As shown in the figure below: The IP protocol can send the packets sent by the source host A to the destination host B according to the destination address in the header, so why do we need a transport layer?

Insert picture description here

1. From the ip layer, the two ends of the communication are two hosts, and the header of the ip datagram also clearly marks the IP addresses of the two hosts. But this means that the communication between the two hosts is not accurate enough. Because the real communication is the communication between the processes on the two hosts. For example, in the figure above, the AP1 process of host A communicates with the AP3 of host B. Therefore, strictly speaking, the communication between the two hosts is the communication between the application processes between the two hosts. Although the IP protocol can send the packet to the destination host, the packet still stays at the network layer of the host and has not passed the transport layer to the application process.
2. From the perspective of the transport layer, the real endpoint of communication is not the host, but the process between the hosts, that is to say, the end-to-end communication is the communication between the application processes.
3. In fact, communication between two computers is generally not a single process communication. It is possible that multiple processes on computer A communicate with multiple processes on computer B. In fact, the transport layer also hasSharewithReuseFunction.

  • Multiplexing: different processes of the sender canUse the same transport layer protocol to transmit data, Plus appropriate header control distinction.
  • Sharing:Transport layer of the receiver, Get the message, after stripping the header from the message, you can send the received message information to the corresponding process correctly.

4. It can be seen from the figureNetwork layerIP layers) Provides logical communication between hosts (it can be recognized as, send a message to the Internet, and another host will receive it),Transport layerProvide logical communication for the application process.
5. The transportation layer mustMessagePerform error detection, and the network layerip datagram headerPerform error detection (check only the header but not the data part, the data part is detected at the transport layer)

2. The main agreement of the transport layer

(1) Main agreement

According to the different needs of the application, the transportation layer mainly has two different transportation protocols

  • User Datagram Protocol (UDP) [RFC 768]
  • Transmission Control Protocol TCP (Transmission Control Protocol) [RFC 793]

(2) Terminology introduction

1. In OSI terminology, the unit of data transmitted by two peer transport entities during communication is calledTransport protocol data unitTPDU (Transport Protocol Data Unit)
2. In the TCP/IP system, depending on whether the protocol used is TCP or UDP, they are respectively called TCP segment or UDP user datagram.

(3) Some applications use protocol chestnuts
Insert picture description here

3. Ports of the transport layer

(1) Re-understand demultiplexing

Insert picture description here

1. All application processes in the application layer are availableThrough the transport layerThen transmit to the IP layer (network layer), which is multiplexing.
2,Transport layerAfter receiving the data from the IP layer, it must be delivered to the specified application process. This is division.

Obviously,It is very important to give a very clear mark to each application process in the application layer.
3. Use the port to identify an application (note that the port identifies the application, not the application process)

(2) The origin of the port

1. Port: The process running in the computer is usedProcess identifier(Pid) to sign. In order to enable the application processes of computers running different operating systems to communicate with each other, a unified method must be used to mark the application processes of the TCP/IP system. The way to solve this problem is to use the protocol port number or port in the transport layer. Although the end of the communication is the application process, as long as the message to be transmitted is delivered to a suitable destination port of the destination host, the rest of the work (that is, the final delivery to the destination process) is done by TCP/UDP. The port number only has a local meaning, it is just to mark the inter-layer interface of the local computer application layer when interacting with the transport layer.
2. The abstract protocol port between the protocol stack layers is a software port, which is a completely different concept from a hardware port on a router or switch. A hardware port is an interface for different hardware devices to interact, and a software port is an address for interaction between various protocol processes of the application layer and the transport entity.

Reference: the connection between process ID [PID(Process ID)] and port number [(Port ID)]

(3) Application layer port

1. At the application layer, data is delivered to the port of an application, and the rest of the work is done by the transport layer.
2. In the header format of UDP and TCP that will be mentioned later, we will see that they all have two important fields: source port and destination port. When the transport layer receives the transport layer message from the IP layer, it can deliver the data to the destination application process of the application layer according to the destination port number in its header.
3. The transport layer of TCP/IP uses a 16-bit port number to mark a port. But please note that the port number only has a local meaning, it is only used to mark the inter-layer interface of each process in the computer application layer when interacting with the transport layer. In different computers on the Internet, the same port number is not related. The 16-bit port number allows 65,535 (2 to the 16th power minus one) different port numbers, this number is sufficient for one computer.
4. It can be seen that the processes in two computers To communicate with each other, you must not only know the other party’s IP address (in order to find the other party’s computer), but also know the other party’s port number (in order to find the application process in the other party’s computer, according to the source port in the header of the message passed by the IP layer or The destination port transport layer can transfer the data to the destination process.)

(4) Port classification

1. The server uses the port

  • System port number (well-known port number): Value 0-1023, these are some important programs of TCP/. (Common as shown below)
    Insert picture description here
  • Registration port: the value is 1024-49352. The use of this type of port number must be registered with IANA in accordance with the prescribed procedures to prevent duplication

2. Client use port

The port number used by the client is 49152~65535. Since this type of port number is dynamically selected only when the client process is running, it is also called an ephemeral port number. This type of port number is left to the client process to choose to use temporarily. When the server process receives the message from the client process, it knows the port number used by the client process, so it can send the data to the client process. After the communication is over, the client port number that has been used just now no longer exists, and this port number can be used by other client processes.

Two, UDP protocol

1. UDP features

(1)Connectionless

There is no need to establish a connection before sending data. Of course, there is no connection to release after sending. Compared with tcp, the overhead is reduced. Reduce the delay before sending data.

(2)Best effort delivery

That is, reliable delivery of data is not guaranteed, and the host does not need to maintain a complicated state connection table (there is a lot of data in the table).

(3)Message-oriented

udp sends or delivers a complete message at a time. As long as the application layer (ip layer) sends (receives) the message, udp delivers the message. In other words, UDP delivers a complete message at one time. In other words, the application must select a message of the appropriate size. If the message is too long, after UDP passes it to the IP layer, the IP layer may have to fragment during transmission, which will reduce the efficiency of the IP layer. Conversely, if the message is too short, after UDP passes it to the IP layer, the relative length of the header of the IP datagram will be too large, which also reduces the efficiency of the IP layer.
Insert picture description here

(4)UDP has no congestion control

The network congestion will not reduce the sending rate of the source host. This is very important for some real-time applications. Many real-time applications require the source host to send data at a constant rate, and allow some data to be lost when network congestion occurs, but data is not allowed to have too much delay, just UDP is suitable.

(5) UDP supports multiple communication methods

One to one, one to many.
Many to one, many to many.

(6)UDP header overhead is small

The header of UDP is only 8 bytes, but the header of TCP is 20 bytes (which is much shorter than TCP)
1. When many source hosts send high-rate real-time video streams to the network at the same time, network congestion may occur, and as a result, everyone They cannot be received normally, but not using UDP will cause more serious congestion.
2. Some real-time applications can appropriately improve UDP to reduce data loss. In this case, the application process itself can add some measures to improve reliability without affecting the real-time performance of the application, such as forward error correction or retransmission of lost packets.

2. UDP header format

Insert picture description here

User datagram UDP has two fields:

  • UDP data: data transmitted by the user
  • UDP header: The header consists of 8 bytes, four fields, and each field occupies 2 bytes.

(1) Source port

That is, the source port number, which is used when the other party needs to reply, and all 0s can be used when not needed

(2) Destination port

That is, the destination port number, which must be used when the end point delivers the message.

(3) Length

The length of the UDP datagram, the minimum value is 8, which means there is only the header.

(4) Checksum

Check whether there are errors in the transmission of UDP user datagrams. Throw away

1. The calculation method of the checksum in the header of the UDP user datagram is somewhat special. When calculating the checksum, a pseudo header of 12 bytes should be added before the UDP user datagram. The so-called "pseudo header" is because this pseudo header is not the real header of the UDP user datagram. It is just added temporarily in front of the UDP user datagram when calculating the checksum to obtain a temporary UDP user datagram. The checksum is calculated according to this temporary UDP user datagram. The pseudo-header is neither sent down nor submitted up, but only to calculate the checksum.
2. The method for UDP to calculate the checksum is similar to that of the IP datagram header. But the difference is:The checksum of the IP datagram only checks the header of the IP datagram, butThe UDP checksum is to check the header and data parts together

3. Transport layer: TCP protocol

End

Summary: <Computer Network (6th Edition)>

Guess you like

Origin blog.csdn.net/qq_38350635/article/details/103905021