UDP:user datagram protocol

1 Introduction
1.1 Introduction

The transport layer provides end-to-end (processes in the host) services; the network layer provides services from host to host;

A transport layer protocol may correspond to multiple application layer protocols, so it has a very important function == multiplexing and demultiplexing ==:

  • Multiplexing means that the sender application process can use the same transport layer protocol to send data (plus the appropriate header port number);
  • Demultiplexing means that the receiver's transport layer removes the packets of the transport layer protocol and then delivers the data to the destination "application process" - according to the port of the removed packets;
  • Schematic:

The transmission also needs to provide error checking - checksum;

There are two protocols in the transport layer: UDP (user datagram proportal) and TCP (transmission control portocol). The corresponding application layer protocols and applications are generally as follows (each application layer protocol also has its own default port number):

1.2 Port number (16-bit: 65535)

The multiplexing and demultiplexing functions of the transport layer need to uniquely identify each application process in the application layer:

  • Process identifiers cannot be used as identifiers, because a wide variety of computers on the network have process identifiers in different formats;
  • Protocol port number protocol port number is referred to as prot port: identifies the application process;
  • The port is a software port, which is distinguished from a hardware port;
  • The port number is divided into source port and destination port: the request destination port of a certain protocol of the application layer needs to use the default port, but the source port number is arbitrary. The source port number has only local significance, and the same port number is not associated ;

There are two types of port numbers: server-side port numbers and client-side port numbers:

  1. The most important type of server-side port number is the well-known port number (well-known port number), also known as the system port number, 0~1023 . IANA needs to formulate a well-known port number for each application layer protocol, which is commonly used as follows:
    • 1024~49151 : Unregistered server port number;
  2. The range of port numbers used by the client is 4915265535 , also known as "ephemeral port number", the source port number in the request message;
2. UDP User Datagram Protocol

UDP only adds the functions of multiplexing/demultiplexing and error detection to IP datagrams. Its main features are:

  1. Connectionless: no connection is required to send data;
  2. UDP delivers to the best of our ability;
  3. UDP is message-oriented (TCP is oriented to byte stream), that is, UDP adds the header of the application layer message to the network layer, and does not combine it instead of splitting. The byte stream-oriented TCP will split the application layer data in the sending window; the application layer using the UDP protocol should use a packet of appropriate size, because after UDP delivers the complete packet to the IP layer, the packet is too large. Splitting leads to the failure to report the efficiency of the IP layer. If the IP layer is too small, the header is relatively large and the transmission efficiency is also reduced;
  4. UDP has no congestion control, that is, network congestion will not cause the source host to reduce the sending rate. TCP has a corresponding mechanism to prevent too much data from being sent to the network, causing the routers and other nodes in the network to be overloaded;
  5. UDP supports one-to-one, one-to-many, many-to-one and many-to-many interactive communication . TCP is connection-oriented, so only one-to-one is supported;
  6. UDP header is only 8 bytes, TCP has 20 bytes and an optional length of 40 bytes;
2.1 Header format and its error checksum

The UDP header format has four fields, each with two bytes: source port, destination port, length, and checksum. The format is as follows:

  • source port: If you don't need the other party's reply, you can set it to 0;
  • des port: identifies the application process. If the receiver UDP finds that the port number in the received packet is incorrect and does not exist, it will discard the packet, and ICMP will send a "port unreachable" error packet to the sender;
  • length: The length of the UDP user data packet, in bytes, the minimum value is 8 with only the header, and the maximum value is 2^16b-8b=2^6kb-8b=64kb-8bit;
  • Checksum: discard if there is an error;

The verification of the IP layer only verifies the header of the datagram, but UDP verifies the header and the data part together, even including the source IP and destination IP. The verification method is as follows:

  1. First, a pseudo-header will be added in front of the UDP header, the structure is as follows
  2. The initial value of checksum is all 0 ;
  3. Treat the pseudo-header and UDP datagram (including the data part) as a 16-bit 01 string for division and summation (if it is not enough 16 bits, add 8 0s at the end): the place where the carry after the sum is added is added to the end , and finally the complement is obtained;
  4. == On the receiving end, sum the same as above, fill the high bits with the low bits, and negate them, == == If the final result is all 1, it is regarded as correct == ;

[Note]

  • "N number sum and negation" = check code, "n numbers + check code" sum and negation = check code + check code negation = 1;
  • TCP uses the same verification method;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324729274&siteId=291194637