This is the first article in a series on the Web, with more to come. Stay tuned! Let’s ride the waves together!

preface

Network is one of the basic skills of our engineers, after all, we can’t do anything without network! From the recruitment requirements of major companies, the network is also a key part of the assessment. Today, I’d like to review my college lessons with you. TCP/IP Indicates the IP protocol of the TCP/IP cluster.

The body of the

Understanding the network model

The web’s designers have come up with a layered design that separates functions and delivers them to different layers, both for ease of update and maintenance (the arrival of IPv6 did not redesign the entire network) and for ease of learning and understanding. The following is the structure diagram of each version of the network system:

  • Application layer, the layer protocol is responsible for the rules of interaction between applications. Such as HTTP and DNS, the unit of data exchanged can be called “message “.
  • The transport layer provides general data transmission services for the application layer. TCP and UDP are transport layer protocols.
  • The network layer provides communication services for different hosts in the network. The IP protocol works at this layer.
  • Data link layer, responsible for the data transmission of two adjacent points.
  • Physical layer, transmission bit stream, 0 or 1.

Each layer encapsulates the data into a data format that it can understand and delivers it to the next layer. The next layer adds the necessary data of the layer as its own data and delivers it downward until the link layer delivers it to the destination. Then, each layer removes the necessary data of the layer and delivers it to the upper layer. The diagram below:

Understand IP protocols

With an understanding of the network model and the direct coordination of the layers, let’s move on to today’s topic, The Internet Protocol (IP).

This section focuses on understanding what the IP protocol provides for us, specifically what it can do.

  • Provide id cards for hosts (PCS or routes or gateways) in the network.
  • Defines the basic communication mode of the network host, as can be seen from the format of IP datagrams.
  • Facilitates route addressing, as can be seen from the routing table structure.

Any protocol can consist of three parts: syntax, semantics, and synchronization.

  • Syntax: Format of exchanged information. For IP protocol, format of IP packets.
  • Semantics, which is what kind of control information needs to be sent and how to respond when it is received.
  • Synchronization, a detailed description of the order of events.

That is, it defines the rules for using IP protocol to communicate.

IPv4

IPv4 is the fourth version of the IP protocol that we use today. Take a look at this release in several ways.

The IP address

Hosts on a network need an IP address so they know where each other is. The IPv4 address consists of 32 bits and is usually expressed in dotted decimal notation (192.168.1.1).

classification

IP address classification is to classify all IP addresses into several categories, each of which consists of fields of fixed length. The network ID and host ID are respectively. The following is a schematic diagram of each type of address:

  • A class A address with an 8-bit network number. The first digit is 0. There are only 126 available network numbers (2^7-2) from 0 to 127. 2 is subtracted because: If all IP addresses are 0, “local network” is reserved. The network ID 127 is used for software loopback test. If a host sends data destined for 127.0.0.1, the data is not sent to any host on the network. That is, addresses starting with 127 cannot be used.

    For each network number in A class A address, there are (2^24-2) corresponding host numbers: All 0s indicate the host number, all 1s indicate the network address corresponding to the network number, and all 1s indicate all hosts.

  • The network number of a Class B address is 16 bits, but the first two bits are fixed as 1 0. No matter how the value is set, all zeros and ones cannot occur. The 128.0.0.0 network address is not used. So there are 2^14-1 network addresses for class B.

  • A class C address has a 24-bit network number. The first three bits are fixed as 1, 1, 0.192.0.0.0, and the smallest class C address is 192.0.1.0

The summary is as follows:

Network class The network number The first available network number The last available network number
A 7, 126 (2 ^ 2) 1 126
B 14-1) (2 ^ 16383 128.1 191.255
C (2 ^ 2097151-1) 21 192.0.1 223.255.255

Benefits of classification:

  • Easy to manage,IP address management agencies only need to manage network numbers, the rest can be managed by subordinates.
  • The routing table is reduced by forwarding packets based on network addresses.

Datagram format

Let’s look at the basic format of IP datagrams:

  • Version: a 4-bit IP protocol version number. The communication parties must be the same.

  • Header length, 4 bits, in 4 bytes. Max. (2^4-1) * 4 = 60 bytes. If the length of the header of an IP packet is not an integer multiple of 4, you need to use the padding field.

  • The value is 8 bits, indicating the service type. It is not used.

  • Total length: 16 bits, indicating the total length of the header and the data part (in bytes). So the maximum total length of a datagram is (2^16-1 = 65535) bytes.

  • Identification, 16 bits. If the length of a datagram exceeds the MTU of the lower layer, the datagram needs to be fragmented. The identifiers of the fragmented datagram are the same. In this way, the datagram can be reassembled.

  • Flag, accounting for 3 bits, only 2 bits are meaningful at present

    • The lowest value is MF(More Fragment) = 1And then we have shards.mf = 0 indicates the last fragment in the fragment.
    • The middle bit,DF(Don’t Fragment), does not Fragment. Fragments are allowed only when DF=0
  • Slice offset, accounting for 13 bits. A piece is in the relative position of the original piece after the sharding. It must be an integer multiple of 8 bytes.

  • Time To Live(TTL) : indicates the number of seconds To Live and then changes To the number of hops through the route. For each route, the TTL decreases by 1. When it is 0, the TTL is discarded. Obviously, the maximum hop count is 255, and a hop count of 1 can only be propagated over the LAN.

  • Protocol, 8 bits. Determine which protocol is used for the data in this datagram so that the destination host IP layer knows which protocol to deliver the data to for processing.

    Common protocols and their corresponding values:

    About the name ICMP IGMP IP TCP EGP IGP UDP IPv6 ESP OSPF
    Discussion field values 1 2 4 6 8 9 17 41 50 89
  • Head checksum, 16 bits. The header checksum of a datagram, excluding the data portion.

  • The source address and destination address each contain 32 bits

IPv6

The emergence of IPv6 is to solve the problem of IPv4 resource exhaustion. It still supports connectionless delivery, but delivers PDU packets instead of IPv4 datagrams.

The IP address

IPv6 addresses are 128 bits, which will be sufficient for the foreseeable future. However, the communication between host A using IPv4 and host B using IPv6 is incompatible with the IPv4 version. The method will be described later.

IPv6 address

An IPv6 address consists of eight groups of four hexadecimal digits separated by colons. Such as:

6845:8C64:FFFF:FFFF:0:1180:9000:FFFF
Copy the code
  • If you have all zeros, you can omit three of them.

  • If there are consecutive groups of zeros, you can replace them with colons, but only once

    FF05:0:0:0:0:0:0: B3 can be compressed into FF05: : 1090 B3:0:0:0:8:8 00:20 0 c: 417 a can be compressed into 1090: : 8:8 00:20 0 c: 417 a total of zero can be written as: :Copy the code
  • The last two groups can be expressed in dotted decimal IPv4

    0:0:0:0:0:128.10.2.1 can be expressed as :128.10.2.1Copy the code

Datagram format

The IPv6 datagram consists of two main parts, the base header and the payload. The payload runs with zero or more extension heads.

  • Version: contains four bits. The protocol version must be the same for both parties
  • Traffic class, 8 bits. Distinguish between different IPv6 datagrams or priorities.
  • Stream label, 20 bits. A new mechanism in IPv6 is to support resource preallocation, running routes to assign and associate each datagram with a specific resource. IPv6 introduces the concept of streams. A series of datagrams (such as real-time audio or video transmissions) over the Internet from a specific source to a specific destination, ensuring a specified quality of service along the route the stream takes. All datagrams belonging to the same stream have the same stream label. A value of 0 is off.
  • Payload length, 16 bits. Specifies the number of bytes other than the base header. The largest 64 KB.
  • The next one, eight bits. Protocol field or optional field equivalent to IPv4
    • If IPv6 does not have an extension header, this field is the same as the IPv4 protocol field.
    • If there is an extension header, it represents the type of the first extension header
  • Hop limit, same as IPv4 TTL
  • The source address and destination address each contain 128 bits

Transitioning from IPv4 to IPv6

The network is so large that the transformation from IPv4 to IPv6 cannot be accomplished overnight. To communicate between two versions of the protocol, there are two methods

Double protocol stack

Simply put, a host can understand two versions of the content, so the host must also have two versions of the CORRESPONDING IP address. If a host has a dual protocol stack, the DNS system can know the protocol version used by the destination host.

The following is a schematic diagram of the communication between two hosts using IPv6. They need to convert the protocol between the hosts passing through the dual protocol stack over the IPv4 network when necessary. Of course, some information may be lost during the conversion, which is inevitable.

Use of tunneling technology

When IPv6 data needs to enter the IPv4 network, IPv6 datagrams (PDU, to be exact) are regarded as the data part of IPv4 datagrams and transmitted using the IPv4 version. After leaving the IPv4 network, IPv6 data is assembled and sent to the destination. Here’s a schematic:

conclusion

There is much more that can be said about IP protocols, but I won’t go into it here. I hope you feel like a mirror after reading this. See you next time.

note

  • Some pictures come from the network, if there is infringement, please inform.
  • Please point out any mistakes. ‘!
  • Your liking is the greatest compliment.