TCP/IP Detailed learning Note--IP protocol

Source: Internet
Author: User


an overview The IP protocol is the most central protocol in the TCP/IP protocol cluster, and all TCP, UDP, ICMP, and IGMP data are transmitted in an IP datagram format. The IP protocol provides unreliable, non-connected data transfer services. Unreliable means that it does not guarantee that the IP datagram will successfully reach its destination. IP only provides the best transfer service. It means that I do my best to transmit the data, not to pass it, and not to blame me. When a certain error occurs, such as a router's buffer is slow, the router can not receive new data, directly discard processing, and then send an ICMP message to the source side, tell him I try my best. If reliable transmission is required, it must be provided by the upper layer protocol, such as the TCP protocol. No connection means that IP does not maintain any status information about subsequent datagrams. Each datagram is processed independently of each other. In other words, IP datagrams are not necessarily received in the order in which they are sent. For example, a source sends two consecutive datagrams to the same message (a, then B), and when the message is received, B may be received before a, since A and B are not sent by the same path, they are independent. In addition, it is possible that the IP datagram may be copied in transit, or the data will be changed when it encounters some error. And these problems need to be resolved through the upper level protocol.
Two IP header, IPv4 datagram format. The IPV4 header normal size is 20 bytes, which is more than 20 bytes if some options need to be set, but this is rare. The IPV6 header size is twice times that of IPv4, but the IPV6 header has no options, so its size is fixed. However, IPV6 may have an extension header, which we will discuss later.

About byte order: There are two types, small endian (Little-endian) and big Endian (Big-endian). The difference between the two is that the small-endian byte sequence is the low-order byte in the memory of the lower address segment, high-order bytes placed in the memory of the higher address segment, big endian byte is placed in the memory of the low address segment, low bytes placed in the memory of the high address segment. For example, for 0x12345678, the highest byte is 12 and the minimum byte is 78, so the order of storage in small-end mode is: 0x78,0x56,0x34,0x12. The order of storage in the big-endian mode is: 0x12,0x34,0x56,0x78. In all TCP/IP protocol headers, the data transfer is carried out by the big-endian, which is also called the network byte order. However, on many PCs, storage is small-end storage, so conversion is required when transferring data. In the IP header diagram, we can see that the left side is starting from 0bit, representing the high, and the right is 31bit, representing the low. In the transmission process, 4 bytes of transmission sequence is, 0-7bit first, then 8-15bit, then 16-23bit, and finally 24-31bit.
Let's take a look at the IP header. The first 4 bits are the Protocol version field. 4 represents ipv4,6 on behalf of IPV6. We see this in the first of IPv4 and IPV6. Note whether using IPV4 or IPV6, the first 4bit of each IP datagram header is either 4 or 6. The Internet header lenght (IHL) field represents the number of 32bit IP headers. Typically 5, the IP header length is 5 32bit, or 20 bytes. Because the IHL occupies 4bit, the IP header maximum length is 60 bytes. This field is not in the IPV6 header because the IPV6 header is fixed to 40 bytes. Next is the 6bit DS field and the 2bit ECN field, which is the same in both IPv4 and IPV6, and these two fields play a special role in the datagram transmission, which we'll discuss later. Next is the total Length field, which represents the overall byte count of the IPV4 datagram. With this field and the IHL field, we can know where the data portion of the IP datagram (except for the rest of the header) starts and how big it is. Because the field occupies 16bit, the maximum value for the IPV4 datagram (including the header) is 65535byte. The total Length field is required because in low-level protocols, such as Ethernet frames, where IP datagrams are included, if the IP datagram is too small, it needs to be populated with 0 after it, so that Ethernet cannot tell what the valid IP datagram is. Although the largest IPv4 datagram is 65536byte, it is often not possible to transmit such a large number of data due to limitations. When you want to transfer big data, you need to Shard (fragment). After sharding, the total Length field represents the length of each shard (not the overall length of the datagram before the Shard). In IPv6, the header does not support sharding, whereas the IPv6 datagram length is represented by the payload-length field. This field represents IPV6 data other than the header. The identification field is used to flag each IPV4 datagram sent from the sending side. Because each piece of data is different, so the value of the flag is not the same, did not send a copy of the data, the value plus 1. Obviously, this field, like the two fields behind it, is closely related to the Shard function. We'll discuss it later.
The Time-to-live (TTL) field that represents the lifetime of the IPV4 datagram. When the IPV4 datagram is sent out, there is an initial value that, during the forwarding process, does not pass a route, the value is reduced by 1, and if the value becomes 0 (it has not reached the destination), it is discarded and then the sender is returned with an ICMP message. This is done to prevent some data from being passed over the network in a wireless loop, which can cause network congestion. The Protocol (PROTOCOL) field represents the data type of the payload portion of the IPV4 datagram, such as 17 for UDP data and 6 for TCP data. Typically, the data for the upper-layer protocol is encapsulated, but there are exceptions. The Header checksum field calculates the length of the IPV4 header and does not include the payload section, which means that the data IP layer of the upper layer protocol encapsulated in the IPV4 datagram is not responsible for checking its correctness, so we say that the IP layer provides unreliable transport services. Therefore, almost all of the protocols encapsulated in the IP datagram (ICMP,IGMP,UDP and TCP), the data of these protocols contain their own detection fields, no way, the IP protocol does not provide, can only find their own ways. Oddly, IPV6 does not provide the checksum field. The algorithm used to calculate checksum, which we call Internet checksum. This algorithm is worth discussing, it is not like the data check in Ethernet, there is a special case, such as IPv4 header in the TTL field, it is changed, so checksum can not be a simple check. But I don't care too much about it, so I'm not going to say it. Of course, in the IP header is indispensable is the source address and destination address, IPV4 is in the 32bit,ipv6 is 128bit. The destination address may be multicast or broadcast.
Let's look back at the DS field and the Ecn field. Before we say that in IPv4, these two fields play a special role in the data forwarding process, so let's take a look at what actually works. The process of sending an IP datagram from the source host to the destination host passes through many routes, with many paths to choose from. When these two fields are set to certain values, these datagrams and ordinary datagrams will have different policies when forwarding them. It allows the data to be forwarded with different queuing delays and other effects. The value in the DS field is called the Differentiated Services Code Point (DSCP), which is actually a pre-agreed value that represents the priority of the datagram. Typically, this value does not change during transmission, but there are exceptions. What is the two bit ECN field used for? When a datagram passes through a more congested router, the ECN field is set as a congestion indicator. What's the use of it? Imagine that when the destination host receives an ECN field labeled datagram, it can know that a routed assassin is congested, and some protocols (such as TCP) will reduce the rate at which the data is transmitted, in order to mitigate congested routing. The position of the DS field and the ECN field is initially used to place the type of Service (ToS) field, which is the Traffic class field in IPV6. Although they are not widely used, the DS fields are still backwards compatible. Let's start with the TOS field.
As shown in the TOS field, D, T, and R represent delay (delay), throughput (throughput), and reliability (reliability), respectively. When placed 1 o'clock, it represents better performance, lower latency, greater throughput and higher reliability. The value of the precedence section is from 000 to 111, representing both the general priority and the network control priority, which is the lowest and highest priority. The following table corresponds to the specific relationship:
Precedence is considered for backwards compatibility in the design of DS fields. Let's take a look at the contents of the DS field:
In standard cases, the value of DS0 is 0. When the other five bits go to different values, they represent different priorities, as follows:
We see that the first eight lines are the same as the previous TOS field, which is backwards compatible. Different datagrams have different priorities, and the priority here is to refer to different privileges when forwarding. For example, some have priority forwarding.
Normally, the IPv4 header totals 20 bytes, which we have already discussed. However, it is possible to add some additional options (IP options) in the IPV4 header. These options have a variety of uses, but they are seldom used, and we no longer detail them.
Three IPV6 expansion Header IPv6 is an agreement that is still being developed and perfected. Have the opportunity to sort it out alone.
Four IP routing ip routing is a very important part of the IP protocol, and is a very complex part of the content. However, the process is very simple for the sending side. If the destination and the sender are directly connected (point-to-point connection), or in a local area network (such as Ethernet), this time the sender only need to send the datagram directly to the destination, do not need a router. Otherwise, the sending side sends the data to the default router, and then lets the router send datagrams to the destination. In most cases, it's that simple. Of course, the situation can be more complicated, and we start with the routing table. 1. The Routing table (Forwarding table) routing table, or forwarding statement, is a table that every router will store, just as each interface in the ARP protocol will have an ARP cache, which records some information. The information that the routing table records is that when the router receives a datagram, it can log this information through the routing table and know where to send the datagram. Each message includes the following (1) destination addresses (Destination). Can be a full host address, or it can be a network address. If the host number is 0, it will be sent to all hosts on the specified network, otherwise, to a specific host. (2) Mask (mask) (3) Next hop (Next-hop) (4) interface (Interface) I found that when I look at the information of the above words, I indefinitely, after looking at the following example, immediately understand, so do not care about these definitions and explanations, directly see the following examples to understand.
What we need to know is that the IP datagram is in the process of forwarding, jumping from one router to another until it reaches the destination or is discarded. It only knows where the next jump is going and doesn't know what the whole path is. And always assume that the next hop is closer to the destination. Some people are very puzzled about this matter, how will it be sure to reach the destination? This is guaranteed by a dedicated routing algorithm, such as Rip,ospe. 2 IP Routing and forwarding process when the router receives an IP datagram, it sends the datagram down, and the process is the IP route forwarding process. The following: When the data is received, the router extracts the destination IP address D, and the D and the mask of each entry in the router's routing table are bitwise AND operation, resulting in the result contains 1 of the most, that is, the best match results. The next hop in the mask corresponding entry is the next hop that the datagram should go to.
3 examples give two examples, direct transmission and indirect transmission. Direct transmission is on the same LAN, or directly connected, indirect transmission is obviously another situation.
The following is an example of an indirect transmission, very clearly understood.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

TCP/IP Detailed learning Note--IP protocol

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.