IP Datagram Format detailed

Source: Internet
Author: User

IP protocol provides unreliable non-connected datagram transport service, the IP layer provides services through the IP layer of datagram encapsulation and unpacking to achieve. The format of IP datagram is divided into two parts: header area and data area, in which the header area is a variety of control information to transmit the high-level data correctly, and the data area includes the data that the high-level protocol needs to transmit.

The format of the IP datagram is as follows:

Note that the above figure represents the highest bit on the left and is recorded as 0 bits; the lowest bit is on the right and is recorded as 31 bits. When transmitting data in the network, the 0~7 bit is transmitted first, followed by the 8~15 bit, then the 16~23 bit is transmitted, and the 24~31 bit is transmitted finally. Because all the binary numbers in the TCP/IP protocol header are required to be transmitted in the network in this order, it is called the network byte order. In actual programming, binary numbers stored in other forms must convert the head to network byte order before transmitting the data using the corresponding function of the network programming API.

The functions of the IP datagram fields are as follows:

1) Version number: occupies a 4-bit binary number that represents the IP protocol version used by the IP datagram. Currently the internet is mainly used in the TCP/IP protocol family version number 4 of the IP protocol.

2) head Length: occupies 4-bit bits, this field indicates the length of the entire header (including options), which is a count of 32-bit binary numbers, which can be used by the receiving side to calculate where the header ends and where to begin reading the data. Normal IP datagram (no options) The value of this field is 5 (that is, 20 bytes in length).

3) service type (TOS, type of Service): 8-bit bits used to specify how this datagram is processed. The 8 bits of the service Type field are divided into 5 subdomains:

(1)-The greater the number of priority (0-7), the higher the priority of the datagram. Routers in the network can use priority congestion control, such as when the network congestion can be based on the priority of the datagram to determine the choice of the datagram.

(2)-Short delay bit D (delay): At this position 1 o'clock, the datagram request is transmitted in a short delay channel and 0 indicates a normal delay.

(3)-High throughput bit T (throughput): At this location 1 o'clock, datagram requests are transmitted at high throughput channels and 0 are normal.

(4)-high reliable bit R (reliability): At this location 1 o'clock, datagram requests are transmitted in a high-reliability channel and 0 is normal.

(5)-reserved bit.

The TCP/IP protocol currently in use in the Internet does not handle the TOS in most cases, but when actually programming, there is a special function to set the fields for that field. Some of the important Internet application protocols are set up with the recommended TOS values:

As can be seen from the above table, for the application of direct interaction with the user, the general use of short delay; For applications that have a large amount of data to be transmitted, high throughput is generally chosen, and high reliability is generally chosen for the application of the data datagram to transmit control information. The TOS field is set to 0x00 if the TOS is not supported during the lifetime of the datagram.

4) Total Length: 16-bit bits, total length field refers to the length of the entire IP datagram (header area + data area), in bytes. The starting position and length of the data content in the IP datagram can be calculated using the head length field and the total Length field. Because the field is 16-bit binary, the theoretical IP datagram can be up to 65,536 bytes in length (in fact, it is much smaller than this value due to physical network limitations).

5) Survival time (Ttl,time to live): 8-bit bits, which specifies the maximum time that datagrams can be transmitted over the network. In practice, the time-to-live field is set to the maximum number of routers that datagrams can pass through. The initial value of the TTL is set by the source host (typically 32, 64, 128, or 256), and its value is reduced by 1 once it passes through a router that handles it. When the field is 0 o'clock, the datagram is discarded and an ICMP packet is sent to notify the source host, thus preventing the datagram from being transmitted indefinitely when entering a loop loop.

6) Upper layer protocol identification: Occupy 8-bit bits, IP protocol can carry a variety of upper layer protocol, the target side according to the protocol identification can send the received IP data to TCP or UDP processing the upper layer protocol of this message.

Common Internet Protocol Number:

7) Checksum: The use of 16-bit binary number, for the validity of the protocol header data validation, can guarantee the IP header area in the transmission of correctness and integrity. The head check and the field are calculated based on the IP protocol header, and the data behind it is calculated.

Principle: The sender first put the inspection and field 0, and then the head of each 16 bits of binary number to the inverse code sum operation, and the results in the checksum field. Because the receiver contains a checksum of the sender's head in the calculation, the receiver calculates a total of 1 if the head does not have any errors during transmission.

8) Source Address: Occupies a 32-bit binary number representing the sending IP address.

9) Destination Address: Occupies a 32-bit binary number, stating the destination IP address.

======================ip datagram Fragmentation and reassembly ======================

Maximum Transmission unit:

When an IP datagram is transmitted over the Internet, it may take more than one physical network to transfer from the source to the destination. Different networks due to the different physical characteristics of the link layer and the media, there is a limit on the maximum length of the data frame during data transfer, which is the Maximum Transmission Unit MTU (Maximum Transmission Unit).

When communicating between two hosts on the same network, the MTU value of the network is deterministic and there is no fragmentation problem. Sharding problems generally exist only in the Internet with different MTU values. Because the internet is now primarily used by routers for network connectivity, sharding work is usually the responsibility of the router.

When communication between two hosts passes through multiple networks with different MTU values, the bottleneck of the MTU is the smallest MTU value on the communication path, which is known as the Path MTU. Because route selection is not necessarily symmetric (routes from A to B may differ from B to a route), the path MTU is not necessarily consistent in two directions, and the following table is the MTU value for several common networks:

Shards:

The process of dividing a datagram into multiple datagrams for the purpose of network transmission is called sharding, and each IP datagram after being fragmented may reach the target host through a different path.

An IP datagram may or may not be fragmented during transmission. If fragmented, the IP datagram after the Shard is identical to the original IP datagram structure without the Shard, which is also comprised of the IP header and two parts of the IP data area:

After the fragmented IP datagram, the data area is a continuous part of the original IP datagram data area, the head is the original IP data header copy, but with the original non-fragmented IP data header two points are mainly different: flag and slice offset:

(1)-Flag: There is a field called "Flag" in the header of the IP data, denoted by a 3-bit binary number:

The non-fragmented DF (do not Fragment) flag if it is set to 1, the datagram cannot be fragmented during transmission, such as the Network Connectivity Test command ping can be configured with the-F parameter to not shard during data transfer, but this will result in data unreachable errors when the data cannot pass through the network with smaller MTU.

The sheet is not finished MF (more Fragment) flag if set to 1, indicating that the datagram is not the last datagram after the Shard, the last datagram of that bit is set 0.

(2)-slice offset: After the IP datagram is fragmented, the position of each slice data area in the original IP data area is represented by a 13-bit offset. In the figure above, the offset of Shard 1 is 0, the offset of Shard 2 is 600, and the offset of Shard 3 is 1200 actually in the IP address, because the offset is calculated in 8 bytes, so the offset of Shard 1 in the IP datagram is 0, the offset of Shard 2 is 75, and the offset of Shard 3 is 150.

Reorganization:

When the IP datagram of the chip reaches the final target host, the target host assembles each shard and restores the IP datagram when the source host is sent, this process is called the reorganization of IP datagram.

In the IP datagram header, the identity is represented by a 16-bit binary number, which uniquely identifies each datagram sent by the host. When a datagram is fragmented, each shard copies only the value of the datagram "identity" field, so that all shards of a datagram have the same identity.

The principle of the target-side host reorganization datagram is:

(1)-According to the "Identification" field, you can determine which IP datagram the received shard belongs to.

(2)-depending on the "unfinished MF" subfield of the "Flag" field, you can determine if the Shard is the last shard;

(3)-depending on the offset field, you can determine the location of the Shard in the original datagram.

========================ip Datagram Options ========================

There are two main features of the IP datagram "options":

1) used to achieve the control of the datagram transmission process, such as the provision of data to pass the route;

2) Conduct network tests, such as which routers are passed through during a datagram transmission.

The IP options field is divided into four categories, each divided into several options, each with a definite number:

The IP datagram "option" consists of three parts: the option code, the option length, and the option data. The option code and option length each take one byte, and the option length is used to determine the length of the entire option section, and the option code is divided into copy, option class, and option number:

Copy: A placeholder that controls the way an IP datagram with options is processed after it is fragmented. This location 1 o'clock copies the options to all shards; set 0 o'clock copies the options to the first Shard only.

The option class and the option number are used to determine which option is the option in which option, in fact, to determine the functionality of the option.

1) Source routing: When an IP datagram is transmitted over the Internet, the route that is routed is specified by the source host that issued the IP datagram to distinguish it from the route that is obtained by the router's IP layer when the datagram is transmitted over the Internet.

By setting the source routing option, you can test the connectivity of the specified routes in the network so that datagrams bypass the faulty network and can be used to test the throughput of a particular network. Source routing can be divided into two categories: strict source Routing and loose source routing.

(1)-Strict source routing has the sending end to specify that the IP datagram must pass through the path of each router, the adjacent router must not have an intermediate router, and the order of the router can not be changed. If a router sends a source route with the next router specified on its network that is not directly connected, it returns an ICMP error message with "Source Routing failed". The strict source routing option format is as follows:

The Option Code field is 01001 (0x89), which is the 0 class 9th option. The maximum option length is 39, which can hold 9 IP addresses. Because the IP header length field has only a 4-bit binary number, the entire IP header can only contain up to a 32-bit long word (that is, 60 bytes) of <24. Because the IP header has a fixed length of 20 bytes, the option code, the option length, and the pointer share a total of 3 bytes, so there are 60-20-3=37 bytes left to hold the IP address list, so only 9 IP addresses can be stored.

(2)-Loose source routing: The sender indicates a list of IP addresses passed by a datagram, but on the path of the datagram transmission, there can be routers with other IP addresses between the two IP addresses specified in the option. The format is the same as strict, except that the option Code field value is 0x83.

2) Record routing: By setting the logging routing option, the IP datagram can record the IP address of each router on the path through which the datagram is transmitted from the source host to the destination host. The data format for logging routing options is the same as the strict source routing format, but the option Code field value is 0x87 and the pointer initial value is 4, pointing to the location where the first IP address resides. Each router's IP address is stored in the data area of the option, and the value of the pointer field increases (starting from 4 to 8,12,16, up to 36), which always points to the next location where the IP address is to be placed. When 9 IP addresses are logged, the value of the pointer field is 40, indicating that the data area is full.

3) Record the timestamp: the IP datagram has its IP address and time recorded on every router. The time in the timestamp is in MS, and the timestamp value is generally GMT (ut,universal time) The number of milliseconds since midnight the timestamp option format is as follows:

The option code for the timestamp option is 0x44. The length of the option represents the total length of the option (typically 36 or 40), and the pointer points to the next free space pointer (value 5, 9, 13, and so on).

The overflow of field indicates the number of timestamps that could not be recorded due to insufficient space in the timestamp option data area;

The "Flag fl" field is used to control the format of timestamp options, with the following values:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.