Computer Network (3)-IP Datagram Format

When it comes to the most important protocol at the network layer, it is undoubtedly the IP protocol. The IP protocol is based on the end-to-end design principle. IP only provides a connectionless, unreliable, best-effort datagram transmission service for the host. The purpose of designing IP addresses is to improve the scalability of the network. On the one hand, it solves Internet problems and realizes the interconnection and intercommunication of large-scale and heterogeneous networks; on the other hand, it divides the coupling relationship between top-level network applications and bottom-level network applications, which is beneficial to both Independent development.

1. IP datagram format

IP datagram

As shown in the figure, the IP datagram is divided into a header and a data part.

1) Data part: TCP or UDP message from the transport layer

2) Header: The main embodiment of the IP protocol, transport layer data + IP header = IP datagram. The header can be divided into a fixed part and a variable part, please read down for specific instructions.

Second, the detailed explanation of the IP datagram header

image-20200617104527352

The first part of the IP datagram is a fixed part and a variable part. As shown in the figure, each line is four bytes, the fixed part occupies 5 lines, a total of 20 bytes, and the variable part has a variable size, but does not exceed 40 bytes, and must be an integer multiple of 4 bytes. For each part in the header, the following is a detailed description:

1) Version: The version of the IP datagram is specified, the commonly used ones are IPv4 (4) and IPv6 (6)

2) Header length: specifies the length of the IP datagram header, in 4 bytes.

​ For example, if the length of the header is 0111->7, it means that the header occupies a total of 7*4=28 bytes, and it can also be deduced that the variable part is 28-20=8 bytes

3) Differentiated service: Specify the service type of the upper layer protocol of this IP datagram, usually not applicable, set to 0.

​ At special times, if some datagrams wish to pass through with priority, a differentiated service field can be added to these data packets, and all routers can be notified so that datagrams with the differentiated service field are transmitted first

4) Total length: Specify the length of the entire IP datagram, the unit is 1 byte, and the maximum value is 65535. However, due to the limitation of MTU, this length cannot usually be reached.

It can be seen from the above that the total length of the IP datagram may be greater than the MTU (Maximum Transmission Unit of Link Layer Data Frame), and the IP datagram needs to be fragmented. The fragment management after fragmentation is related to the following three fields: identification, logo, and fragment offset

5) Identification: Different fragments of the same datagram take a common mark to indicate that they are "same family."

6) Flags: a total of three bits, one useless bit (set to 0), one forbid fragmentation bit (DF), and one more fragmentation bit (MF)

​ When DF=1, it means that the datagram is not fragmented, and other fragment-related fields are meaningless.

​ When DF=0, it means that the packet has undergone fragmentation processing. If MF=0, it means that the datagram is the last fragment among multiple fragments, that is, there are no more fragments after that, if MF= 1, which means that the datagram is not the last fragment

7) Chip offset: Specify the offset bit of this datagram in the original datagram, the unit is 8 bytes.

8) Time to live: Specify the maximum time to live of an IP datagram. After passing a router -1, the IP datagram will be destroyed if it is reduced to 0.

​ This field can solve the problem of bandwidth wasted by stray IP datagrams caused by loop infinite loop.

​ The default survival time of datagrams sent by each system: Linux (64), Windows (128), Unix (255)

9) Protocol: Specify which protocol process this datagram should be delivered to.

​ Common protocol numbers: ICMP (1) IGMP (2) TCP (6) UDP (17) IPv6 (41) OSPF (89)
10) Header checksum: a check field to check whether the header has been modified.

​ The verification algorithm is: the sender aligns the first two bytes and sums up the negation code, and the result obtained is stored in the first checksum. The receiver aligns the headers in pairs and sums up the inverse codes. If the final result is 0, the header is considered normal, otherwise, the datagram is discarded.

11) Source address/destination address: the source IP address/destination IP address of the datagram (the IP address is explained in detail in the next section)

12) Optional fields: enrich the functions that IP datagrams can provide, not detailed.

13) filled: variable size because an optional field, need to fill the entire header field filled into an integral multiple of 4 bytes, byte alignment to ensure that the principles 4

Guess you like

Origin blog.csdn.net/weixin_44580146/article/details/106865090