TCP/IP study note IP (Internet Protocol)

Source: Internet
Author: User


TCP/IP Study Notes IP (Internet Protocol) 1. Introduction IP is the most core protocol in the TCP/IP protocol family. All TCP, UDP, ICMP, and IGMP data are transmitted in IP datagram format. Www.2cto.com features: it provides unreliable and connectionless data transmission services. Unreliable: It means it cannot guarantee that the IP datagram can successfully reach the destination. IP addresses only provide the best transmission service. If an error occurs, for example, if a vro has used up the buffer temporarily, the IP address has a simple error processing algorithm: discard the datagram and then send an ICMP message to the source. Any required reliability must be provided by the upper layer (such as TCP ).
Connectionless: the IP address does not maintain any status information about subsequent datagram. The processing of each datagram is independent of each other. This also indicates that IP datagram can be received without sending order. If A Source sends two consecutive data packets (A and B) to the same sink, each data packet is selected independently, and different routes may be selected, therefore, B may arrive before A arrives. 2. The format of the IP header IP datagram is shown in. The normal IP header is 20 bytes, unless it contains an option field.

(Figure 1) IP datagram format and the header of each field in the header (figure 1. The highest bit is on the left, marked as 0 bit; the lowest bit is on the right, marked as 31 bit. The 32-bit values of four bytes are transmitted in the following order: the first is 0 ~ 7 bit, followed by 8 ~ 15 bit, then 1 6 ~ 23 bit, last 24 ~ 31 bit. This transmission order is called the big endian byte order. Because all the binary integers in the header of t c p/I P must be transmitted in this order, it is also called the network byte order. Machines that store binary integers in other forms, such as the little endian format, must convert the header to the network byte before data transmission.  4-digit version: indicates the version of the IP protocol. Both parties must use the same IP protocol version. Recently, the widely used IP protocol version is 4 (IPv4 ). IPv6 is still in its infancy.
Expires 4-digit Header Length: www.2cto.com occupies 4 digits and can represent the maximum decimal value of 15. Note that the unit of the number indicated by this field is 32 characters (the length of one 32-bit character is 4 bytes). Therefore, when the IP address header length is 1111 (that is, 15 in decimal format), the header length is 60 bytes. When the length of the IP Group header is not an integer multiple of 4 bytes, the last filling field must be used. Therefore, the data always starts at an integer multiple of 4 bytes, which makes it easier to implement the IP protocol. The disadvantage of the header length limit of 60 bytes is that it may not be enough. The purpose is to minimize the overhead. The most common header length is 20 bytes (that is, the header length is 0101), and no option is used. ✓ Eight-bit service type: the service type (to s) field contains a three-bit priority subfield (ignored now ), the sub-fields of 4 bit to s and 1 bit are not used, but must be set TO 0. 4-bit to s represents the minimum latency, maximum throughput, maximum reliability, and minimum cost. Only 1 bit can be set in 4 bits. If all 4 bits are 0, it means a General Service. (Figure 2) recommended to s values for different applications (for reference only, because many t c p/I P implementations currently do not support the TO S feature ):

(Figure 2) recommended service type field value ④ 16-bit total length: the total length refers to the length of the sum of capital and data, in bytes. Because the total length field is 16 bits, the maximum length of the datagram is 216-1 = 65 535 bytes. Each data link layer under the IP layer has its own frame format, including the Maximum length of the data field in the frame format, that is, the Maximum transmission Unit MTU (Maximum Transfer Unit ). When a datagram is encapsulated as a link layer frame, the total length of the datagram (that is, the header plus the data part) must not exceed the MTU value of the following data link layer. The total length field is necessary in the I P header, because some data links (such as Ethernet) need to fill in some data to reach the minimum length. Although the minimum frame length of Ethernet is 4 6 bytes (see Figure 2-1), the I P data may be shorter. If there is no total length field, the I p layer does not know how many of the 4 6 bytes are the content of the I P datagram.
⑤ 16-digit ID: 16 digits. The ID field uniquely identifies each datagram sent by the host. Generally, the value of each sent packet is increased by 1. The IP software maintains a counter in the memory. Each time a datagram is generated, the counter is incremented by 1 and the value is assigned to the identification field. However, this "ID" is not a serial number, because the IP address is a connectionless service, and the datagram is not received in order. When a datagram must be sharded because its length exceeds the MTU of the network, the value of this identification field is copied to all the identification fields of the datagram. The value of the same identification field enables the parts of the datagram to be correctly reloaded into the original datagram. Mark 6 (Flag): www.2cto.com occupies three places, but currently only two places make sense. The watermark bit in the flag field is marked as MF (More Fragment ). MF = 1 indicates the datagram with "sharding. MF = 0 indicates that this is the last of several datagram slices. The one in the middle of the sign field is marked as DF (Don't Fragment), meaning "Fragment is not allowed ". Fragment is allowed only when DF = 0.
7. offset: 13 digits. After a long group is split, a part is located in the relative position of the original group. That is to say, where the starting point of the user data field starts from. The part offset is in 8 bytes. This means that the length of each part must be an integer multiple of 8 bytes (64-bit. TTL: indicates the lifetime of a datagram in the network. Set this field by the source point of the sent datagram. The purpose is to prevent undeliverable data packets from entering the Internet without restrictions, so network resources are consumed in vain. The survival time field sets the maximum number of routers that a datagram can pass. It specifies the survival time of the datagram. The initial value of t l is set by the source host (usually 3 2 or 6 4). Once a router processes it, its value is equal to 1. When the value of this field is 0, the datagram is discarded and the I C M P message is sent to the source host.
Protocol: indicates the eight-digit Protocol. The Protocol field indicates the protocol used for the data carried by the datagram, so that the IP layer of the target host can know which processing process the data part should be handed over. Token header test: 16 digits. The header test and field are the test and code calculated based on the I P header. It does not calculate the data after the header. I c m p, I G M P, U D P, and T C P both contain both the header and the data verification code. First, set the test field to 0. Then, calculate the binary inverse sum of each 16 bit in the header (the whole header is regarded as composed of a string of 16 bit characters), and the result is included in the test field. When an I P datagram is received, the sum of the binary anticode for each 16 bit in the header is also carried out. Because the receiver has included the verification in the sender's header in the computation and download process, if the header has no errors during transmission, the receiver's computation result should be all 1. If the result is not all 1 (namely, check and error), I P discards the received datagram. However, no error messages are generated. The upper layer discovers the lost data packets and re-transmits them.
Source Address: 32 bits. Www.2cto.com Destination Address: 32 characters. Options and data: (the variable part of the IP datagram header) the variable part of the IP capital is an optional field. The option field is used to support troubleshooting, measurement, and security measures. The length of this field is variable, ranging from 1 byte to 40 byte, depending on the selected item. Some options only require one byte. It only includes one byte of Option Code. However, there are still some options that require multiple bytes. These options are spliced one by one, without a separator in the middle. Finally, fill the fields with all 0 to become an integer multiple of 4 bytes. The variable part of the added capital is to increase the IP datagram function, but it also makes the length of the IP datagram header variable. This increases the overhead for each vro to process data packets. In fact, these options are rarely used. The new IPv6 will fix the length of the IP datagram header.
Note: ① An IP packet refers to the PDU on the third layer. The IP header is only a part of the packet. It is added to the Layer 3 network layer and displayed to the router. ② The total length of IP data packets is too large. When the maximum MTU of the link is exceeded, data packets are divided into multiple slices. In today's IPv4 network, data transmission is unreliable, the data unit of these shards has different links and time to reach the peer end. ③ the peer end is identified by the identifier and Flag in the IP header) segment offset value field to reorganize the data packet. 3. Select IP routing in a general system, I p can receive and send data packets (locally generated data packets) from t c p, u d p, I c m p, And I G M P, you can also receive and send a datagram (the datagram to be forwarded) from a network interface. The I P layer has a route table in the memory. When you receive and send a data packet, it searches for the table once. When a datagram comes from a network interface, I p first checks whether the destination I p address is one of the local I p addresses or the I P broadcast address. If so, the datagram is sent to the protocol module specified by the I P header protocol field for processing. If the destination is not these addresses, (1) if the I P layer is set as a vro, then the datagram will be forwarded (that is, it will be processed like the sent datagram ); otherwise (2) the datagram is discarded. Each entry in the route table www.2cto.com contains the following information: • destination I P address. It can be either a complete host address or a network address, which is specified by the flag field in the table. The host address has a host number other than 0 to specify a specific host, while the host number in the network address is 0 to specify all hosts in the network (such as Ethernet and ring-based network ). • I p address of the next-hop router or a directly connected network I P address. A next-Stop router is a vro on a directly connected network. It can forward data packets. The next stop router is not the ultimate goal, but it can forward the datagram sent to it to the ultimate goal.
• Logo. One flag indicates whether the destination I P address is a network address or a host address, and the other indicates whether the next stop router is a real next stop router or a directly connected interface. • Specify a network interface for data transmission. I p route selection is based on hop-by-hop (h o p-B y-h o p. From this route table information, we can see that I P does not know the complete path to any target (except for those directly connected to the host ). All I p routes provide only the I P address of the next router for datagram transmission. It assumes that the next-Stop router is closer to the destination than the host that sends the datagram, And the next-Stop router is directly connected to the host. I p route selection mainly completes the following functions: • search the route table to find a table that matches the destination I P address (both the network number and the host number must match ). If yes, the packet is sent to the next-Stop router or directly connected network interface specified in the table (depending on the value of the flag field ). • Search the route table to find the table that matches the destination network number. If yes, the packet is sent to the next-Stop router or directly connected network interface specified in the table (depending on the value of the flag field ). All hosts on the target network can use this table. For example, all hosts on an Ethernet network use this table to find the path. Possible subnet masks must be taken into account in this search network matching method.
• Search the route table and find the table marked as "default (d e f a u l t. If yes, the packet is sent to the next-Stop router specified in this table. Www.2cto.com If none of the above steps are successful, the datagram cannot be transmitted. If the data that cannot be transmitted comes from the local machine, an "inaccessible host" or "inaccessible network" error is generally returned to the application that generates the data. The complete host address match is executed before the network number match. The default route is selected only when both of them fail. Default route, and the I C M P indirect packet sent by the next router (if we select an incorrect default route for the datagram ), is the powerful feature of the I P routing selection mechanism in the general system, I p can receive and send data packets (locally generated data packets) from t c p, u d p, I c m p, And I G M P, you can also receive and send a datagram (the datagram to be forwarded) from a network interface. Specifying a vro for a network without having to specify a vro for each host is another basic feature of the I P routing mechanism. This can greatly reduce the scale of the route table. For example, the vrouters on I n t e r n t have only thousands of tables, instead of more than 0 thousand tables.

Related Article

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.