TCP/IP study Note 3-IP: Internet Protocol

Source: Internet
Author: User

 
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. It is an unreliable, connectionless datagram transmission service.

Unreliable means that it cannot guarantee that IP datagram can successfully reach the destination. IP addresses only provide the best transmission service.

The connectionless term means that the IP address does not maintain any status information about subsequent datagram. The processing of each datagram is independent of each other.

1. IP Header

The highest bit is on the left, and the lowest Bit is on the right. The 32-bit values of four bytes are transmitted in the following order: the first is 0 ~ 7 bit, followed by 8 ~ 15bit, then 16 ~ 23bit, last 24 ~ 31bit. This transmission order is called the bigendian byte order.

The current Protocol version is 4, so IP is also called IPv4.

The Header Length refers to the number of 32-bit characters in the header, including any options. Because it is a 4-bit field, the header is up to 60 bytes.

The service type (ToS) field includes a 3bit priority subfield (which has been ignored now), a 4bit TOS subfield and a 1bit unused bit, but must be set to 0. The 4bit TOS represents the minimum latency, maximum throughput, maximum reliability, and minimum cost. Only 1bit can be set in 4bit. If all 4bit values are 0, it means a General Service. Currently, most TCP/IP implementations do not support the TOS feature. However, new versions of the system since 4.3bsdreno are configured.

The total length field refers to the length of the entire IP datagram, in bytes. The total length field is necessary in the IP header, because some data links (such as Ethernet) need to fill in some data to reach the minimum length.

The ID field uniquely identifies each datagram sent by the host. Generally, the value of each sent packet is increased by 1.

The TTL (time-to-live) life 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 TTL is set by the source host (usually 32 or 64). Once a router processes it, its value is equal to 1. When the value of this field is 0, the datagram is discarded and an ICMP message is sent to the source host.

The protocol field is used by IP addresses to separate data packets. It can identify which Protocol transmits data to the IP address.

In order to calculate the IP address check of a datagram, the test field is set to 0. Then, calculate the binary inverse sum of each 16bit in the header (the whole header is regarded as composed of a 16-Bit String), and the result is included in the test field. When an IP datagram is received, the sum of the binary anticode for each 16bit in the header is also obtained. ICMP, IGMP, UDP, and TCP all adopt the same test algorithm.

Each IP datagram includes the source IP address and destination IP address.

The last field is any option and is an optional variable length information in the datagram.

2. IP Route Selection
The IP can receive and send datagram (locally generated datagram) from TCP, UDP, ICMP, and IGMP, or receive the datagram (the datagram to be forwarded) from a network interface) and send it. The IP 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, the IP address first checks whether the destination IP address is one of the local IP addresses or the IP broadcast address. If so, the datagram is sent to the protocol module specified by the IP header protocol field for processing. If the destination of the datagram is not these addresses, (1) If the IP layer is set as the router function, the datagram will be forwarded (that is, ); otherwise (2) the datagram is discarded.

Each item in the route table contains the following information:
The destination IP address. It can be either a complete host address or a network address, which is specified by the flag field in the table (as described below ). 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 ).
The IP address of the next (or next hop) router (next-hoprouter) or a directly connected network IP 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.
Flag. One flag indicates whether the destination IP 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.

IP Route Selection mainly includes the following functions:
1) search the route table to find the table that exactly matches the destination IP address (both the network and host numbers 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 ).
2) 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.
3) search the route table and find the table marked as "default. If yes, the packet is sent to the next-Stop router specified in this table.
If none of the preceding steps are successful, the datagram cannot be transmitted.

The complete host address match is executed before the network number match. The default route is selected only when both of them fail.

3. subnet addressing
All Hosts must support subnet addressing. The IP address is not simply composed of a network number and a host number. Instead, the host number is divided into a sub-network number and a host number.
Cause: Because Class A and Class B addresses allocate too much space for the primary host number, the number of hosts can be 2 ^ 24-2 and 2 ^ 16-2 respectively. In fact, in a network, people do not arrange so many hosts because all 0 or all 1 Host numbers are invalid, so the total number is less than 2.

4. Subnet Mask
In addition to IP addresses, the host also needs to know how many bits are used for subnet numbers and how many bits are used for host numbers. This is determined by the subnet mask during the boot process. This mask is a 32-bit value. The bits with a value of 1 are reserved for the network number and subnet number, and the bits with a value of 0 are reserved for the host number.

After the IP address and subnet mask are given, the host can determine the purpose of IP datagram: (1) hosts on the subnetwork; (2) hosts in other subnets of the network; (3) hosts on other networks.

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.