Computer network foundation (2) — network layer – detailed explanation of IP protocol

Time:2020-9-22

An overview of the article
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

Virtual Internet

From the last article mentioned a problem to lead toVirtual Internet
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

For this network topology, a very important problem was raised in the last articleHow does computer a transfer data across devices to computer C?

In fact, this small network topology can be enlarged
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

In this large network topology, how computer a transfers data to computer B has the same properties as the simple network topology above. This network has manyrouteThe data of computer a can be transferred to computer B, for example:
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

Computer a’s data goes throughmedium-size networkLarge networkmedium-size networkSmall networkAnd then arriveComputer B。 In addition to the path shown in the figure above, many other paths can be drawn. Through this network topology, we can know that there are many transmission paths of A. In fact, these network paths, for users, do not need to care, that is to say, we do not care about how the network is connected or how the packets go. This is solved by the network layer. The network layer proposes a very important concept,Virtual Internet

Virtual Internet

  • The actual computer network is complicated
  • Different physical devices shield the differences between physical networks by using IP protocol
  • When the hosts in the network are connected by IP protocol, they do not need to pay attention to the details of the networkEnd to end connections

In other words, we don’t need to care about the complex network topology mentioned above. Just look at the middle part asVirtual InternetThat’s fine. As shown in the figure below,Computer aConnect to aVirtual InternetMedium,Computer BIt’s also connected to this virtual Internet. Then computer a only needs to send data to the virtual Internet, which can be solveddata transmissionAnd accurately transmit it to computer B. This is itVirtual InternetThe concept of

Computer network foundation (2) -- network layer - detailed explanation of IP protocol

IP protocol

  • For the network layer,IP protocolIs one of the very important agreements
  • IP protocol makes the complex real network become oneVirtual interconnected network(that is, we only need to connect the terminal device to this network, and we don’t need to care about the actual complex network inside.)
  • IP protocol enables the network layer toShielding bottom detailsAnd focus on the network layerData forwarding(if we look at the network layer alone, we don’t have to caredata packetIs it transmitted to the destination computer via submarine cable or wireless WiFi)
  • IP protocolThe problem of datagram transmission path in virtual network is solved

It was mentioned in the overview of the last articleMAC addressFor each network device or network cardIDAs long as the data link is in the MAC layer, you can have the MAC addressData frameIt’s transmitted.The MAC address is 48 bits and is represented in hexadecimal。 We can expand the MAC address into binary format
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

staynetwork layerThere is also a concept of address, which is called “address”IP address。 IP address has 32 bits in totaldotted decimal express. It can also be expanded into binary format
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

IP address is similar to MAC address for network layer and MAC address for data link layer. The IP address here is the unique identity of each network devicenetwork layerFor every network device, it has oneUniqueIP address, through which you can identify a unique device

Differences between MAC address and IP address

For MAC addresses, it isUniqueAnd it isUnchangeable。 Because the network card moves from one place to another, the MAC address is unchanged. howeverIP addressDifferent, if our laptop is connected to WiFi at home with IP address a, when we take the laptop to the company or coffee shop, the IP address will change. Therefore, the IP address is variable for network devices. in other words,If the network environment of network equipment changes, the IP address will change accordingly

IP address

  • IP address length is32 bit, often divided into4 8 bits
  • IP address is often useddotted decimal (0 ~ 255.0 ~ 255.0 ~ 255.0 ~ 255.0 ~ 255, we can know by calculation that the maximum number of IP addresses is 32 times of 2, about 4.2 billion)

IP protocol

UnderstandingIP protocolLet’s take a look at the location of the IP protocol. In the physical layer, it transmits something like 0 and 1BitstreamAt the data link layer, theData frameData frame includes frame head, frame tail and “frame” data, and “frame” data is mainly IP datagram. Now the IP datagram for detailed analysis, it will be divided intoIP headerandIP datagram dataTwo parts

Computer network foundation (2) -- network layer - detailed explanation of IP protocol

To learn IP protocol, IP protocolThe firstIs a very important content, the following will also focus on the IP header information. Below is the specific format of the IP header

Computer network foundation (2) -- network layer - detailed explanation of IP protocol

As can be seen from the figure above, the IP header contains a lot of information, includingeditionagreementIP addressEtc. Every line on the top is32Bits, that is4Bytes,The first five elements must existThe sixth line is optional and the seventh line is IP data. So for IP head,It will be at least 20 bytes long

Meaning of each part in IP header

  • edition: 4 bits, refers to the version of IP protocol, the version of both sides of communication must be consistent, the current mainstream version is 4, that is, IPv4, also has IPv6
  • header length : occupies 4 bits, and the maximum value is 15. It represents the length of the IP header, and the unit is “32-bit word” (4 bytes), that is to sayIP headerThe maximum length is 60 bytes
  • Service typeThis is generally not a concern
  • Total length: takes up 16 bits, and the maximum value is 65535Total length of IP datagram(IP header + IP data) (in the introduction of the data link layer, we also mentioned a length. The length of the data link layer is calledMTU, usually 1500 bytes. The maximum length of IP datagram is 65535 bytes, which is larger than MTU. If this happens during the real transmission, the data link layer will perform the IP datagramSectioning, that is to split a long IP datagram into multiple data frames for transmission)
  • identification: used within the protocol, no need to care
  • sign: mark whether IP message can be partitioned
  • Slice offset: as mentioned above, if the length of IP datagram is too long, IP packets will be partitioned, and an IP message will be split into multiple data frames for data link layer transmission. Therefore, if split, you need to useSlice offsetTo record the current data frameIP data of the first offset
  • TTL: 8 bits, indicating that the IP data packets in the networklifeWhen TTL = 0, the network device mustdiscardThis message (its solution is to avoid unlimited transmission of network packets in the network to consume bandwidth when network packets cannot find the destination)
  • agreement: 8 bits, indicating the specific data carried by IP dataagreementFor example, TCP, UDP, etc. for the corresponding values of some protocols, please refer to the figure below)
  • Check sum: 16 bits, check whether there is an error in the IP header (the receiver will also check after receiving the IP header, if there is an error, it will be discarded directly)
  • Source IP addresssend outIP address of network device of IP datagram
  • Destination IP addressIP datagramarriveThe IP address of the destination network device

Values corresponding to some protocols
Computer network foundation (2) -- network layer - detailed explanation of IP protocol

When the data of these protocols is transmitted by IP protocol, it willAssign different values to the protocols in the IP header。 We can see that there are also values corresponding to IP protocol. In other words, for IP protocol, the data of IP protocol can continue to encapsulate IP data, that is, IP data in IP data. In some special occasions, it also has its role

It is the core competitiveness of a technical person to look for invariance in the rapidly changing technology. Unity of knowledge and practice, combination of theory and Practice

Computer network foundation (2) -- network layer - detailed explanation of IP protocol

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]