Network Layer (II)

Source: Internet
Author: User

IP datagram Format
It is often described in 32-bit, 4-byte units. Consists of the first and the data two parts. The first part of the header is fixed length, a total of 20 bytes, is all the IP datagram must have, after the fixed part of the header is some optional fields, the length is variable.

Fixed part of IP datagram header:

1, version, 4 bit, IP protocol version, communication both sides IP protocol version must be consistent. Ipv4,ipv6.
2, the first ministerial degree, 4 digits, can represent the maximum decimal value 15. This field represents a 32-bit word (4 bytes), and the header length is 4*15=60 bytes when the IP header length is 1111. When the IP packet header length is not 4-byte integer multiples, it must be populated with a post-populated field. The most commonly used header length is 20 bytes, or 0101, when no option is available.

3, differentiated services, 8-bit, only used when differentiated services.

4, the length of the total length, 16 bits, header and the sum of the data, the datagram maximum is 2^16-1=65535 bytes. Each data link layer below the IP layer has its own frame format, including the maximum length of the data field in the frame format, and the MTU. The total length of an IP datagram encapsulated into a data link layer datagram cannot exceed the MTU. For efficient transmission, the host and router must be able to handle IP datagram lengths of not less than 576 bytes, which is the total length of the smallest datagram. If the MTU is exceeded, the sum of each shard header length and data after the Shard is the total length of the header in the datagram.

5, identification, 16 bits, each generating a datagram, the counter is + 1, the value is assigned to the Identity field. The value of the same identity field causes each datagram after the Shard to be correctly re-loaded as the original datagram.

6, logo, 3 bits, currently only the first two bits make sense. The lowest bit mf=1, and the Shard, mf=0 the last one. Middle one df=0 allow sharding

7, slice offset, 13 bits, fragment, the relative position of a piece in the original group, in the offset unit of 8 bytes, the length of each shard is an integer multiple of 8 bytes.

8, time-to-live, 8-bit, TTL, datagram life in the network, TTL is the hop count, the meaning of the TTL index is reported in the Internet, the maximum number of routers can pass. A maximum of 255,ttl is set to 1 and can only be propagated on LAN.

9, protocol, 8-bit, what protocol is used for data that the datagram carries.

10, first checksum, 16 bits. Only the header of the datagram is inspected, but the data section is not included. The router has to recalculate the first checksum for each router. Calculation method: The datagram header is divided into a number of 16-bit word sequence, the checksum field is set to 0, with the inverse code arithmetic operation to add the 16-bit words, write checksum field. The receiver, when received, adds the first 16-bit words once. The resulting and reversed, if the header does not change, the result must be 0. The data is persisted, otherwise the data is discarded.


11, original address, destination address, 32-bit

IP Datagram Header Variable part: 1 to 40 bytes in order to increase the IP datagram header function.

The IP layer forwards the packet flow.


If the network on which the router is located is delivered directly, if not, forward to the next hop. The main information for each route in the routing table, (destination network address, next hop address),

Setting a default route reduces the time it takes to search the route table.

When the router receives the datagram to be forwarded, after the router IP address of the next hop through the routing table, it is not to fill in the IP datagram, but to the lower network interface software, which is responsible for the next-hop router's IP address into a hardware address, and put the address on the link layer of the Mac frame header, Then locate the next hop router based on the hardware address.


Packet forwarding algorithm:
1, extract the IP address D from the datagram header, and obtain the network address n
2, if n for the router directly connected to the network address, direct delivery (including IP conversion hardware address, packaging Mac frames, send frames). otherwise do 3
3, if the routing table has destination D's host route, sent to the next hop router.
4, if the routing table has n routes, forward to the next hop router, otherwise 5
5, if the routing table has a default route, the datagram is sent to the indicated default route, otherwise 6
6, report forwarding packet error.


Dividing subnets, constructing hyper-nets

Unreasonable IP address design
1,IP Low Address space utilization
2, assigning a network number to each physical network causes the routing table to become too large and the network performance becomes worse.
3, level Two IP address is not flexible

Dividing subnets:
1, the network outside the unit can not see the subnet inside, subnet inside, the external is still a network
2, the molecular network two-level IP becomes a 3-level IP, borrowing the host IP bit.
ip::={< Network number >,< subnet number >,< host number;}
3, the other network sends the unit host IP datagram, and the same, by the network number to find the router on the unit network. After the router receives, the IP datagram is sent to the host by locating the subnet according to the destination network and subnet number.


Subnet Mask:
Using a subnet mask enables a router to be sent to a subnet by converting a 2-level address into a 3-level address. The subnet mask and IP address are the network address of the subnet. Regardless of whether the subnet is divided, the and operation is performed.

Default Subnet mask

Dividing subnets adds flexibility, but reduces the total number of hosts that can be connected to the network.

The same IP address and different subnet masks can be used to derive the same network address, with different mask effects

Group forwarding when using subnets:
The routing table contains: Destination network address, subnet mask, next hop address.

Algorithm:
1, extract the datagram header destination IP address
2, judge whether direct delivery, no execution 3
3, if the routing table has destination D, forwards the next hop route, otherwise 4
4, the route table each row and subnet mask operation, the result and destination network address matching is transmitted to the next hop router. otherwise 5
5, if there is a default route, forward to the default route otherwise 6
6, Report forwarding error.

Network Layer (II)

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.