[Computer Network] IP Protocol (Part 1)

The relationship between TCP and IP

For example: Suppose when you were in high school, there was a classmate named Zhang San in your class, and his father was the principal of the school.
You feel that you have the ability to get 100 points in every exam.
Being able does not mean that you will definitely do it 100%. To
be capable means to have a greater probability of


If you want Zhang San to get 100% perfect score every time he takes the exam
, he took the exam several times, and one of them got 99, which is not a perfect score. Zhang San went to his father. His father was not satisfied that Zhang San did not get a perfect score, so he asked him
. Zhang San said, I will give you the test alone until you get a perfect score.
Because his father thinks that Zhang San has a high probability of getting a perfect score, so he must ensure that he gets a perfect score every time.

The combination of Zhang San and the principal's father can ensure that he can get full marks in every exam.
Zhang San is the one who really participates in the exam.
The principal's father controls the exam and provides strategies for Zhang San's exam.


The IP protocol provides the ability to send data from host A across the network to host B. What
the IP protocol provides is a high probability,
but what the user wants can be achieved 100%,
so TCP and IP are needed. The combination of
TCP can be regarded as It is the principal's father who provides the transmission strategy
IP. It can be regarded as Zhang San, who provides the execution when actually forwarding the message.

TCP delivers the packet to IP. If IP loses packets, TCP will re-deliver it.

The combination of TCP and IP means that data is sent from host A to host B reliably across the network.

Understanding IP addresses

For example: You want to go to Beijing, but actually go to Tiananmen Square in Beijing
. When you are in Changchun, you can say you are going to Beijing, but when you arrive in Beijing, you have to confirm that you are going to Tiananmen Square.

So generally when talking about where to go, you should first go to the city where the attraction is located, and then arrive at the attraction.

The IP address is equal to the target network plus the target host.

Protocol header format

1. How to separate header and payload?

There is a standard length of 20 bits in IP.
There is a 4-bit header length, which represents the length of the entire header.
The basic unit of the 4-bit header length is 4 bytes.

Extract the first 20 bytes of the message (the first 20 bytes must be the standard header)
and extract the header length field
based on the header length field * 4 minus 20 bytes
. If it is 0, it means that there is no option and the message is a standard header. Just read the payload directly.
If it is not 0 and there are a few bytes left, it means there are several bytes of options. The entire message length minus the standard header and option length
can get the payload.

2. 8-bit protocol

The 8-bit protocol indicates what message the payload is, that is, which protocol the payload is delivered to.

3. 4-bit version

There is a 4-bit version in the IP protocol header, generally represented as IPV4 (a 4-byte 32-bit representation of an IP address used to identify a unique Internet host in the world)

4. 8-bit service type

For example: Zhang San is going to take an exam, and the principal’s father wants full marks. At the same time, Zhang San asked his father whether he wanted to write the paper in the neatest way or be the first to hand it in.

IP provides services to TCP. When TCP asks IP to send data, IP asks TCP whether to deliver the data as quickly as possible or to choose a path that will not lose packets when sending data. What type of service is provided
?

The 8-bit service type corresponds to different types of IP delivery strategies.

Among them, the 3-bit priority field is abandoned, the 4-bit type of service (TOS) field and the 1-bit reserved field (must be set to 0). The 4-bit service type respectively
represents: minimum delay, maximum throughput, maximum reliability, and minimum cost.

5. 16-bit total length

Indicates the length of the entire message (header + payload)


The 4-bit header length and the standard 20-byte length can be used to separate the standard header and options of a protected message. The
header and payload can be separated using a further 16-bit total length.

6. 8-bit time-to-live TTL


If data is sent from host B to host C, when router D fails, router D does not transfer the data to host C. Router D transfers the data to router
I. Router I transfers
the data to router J, and router J transfers the data to host C. To router H, router H passes the data to router C, and
finally router C passes the data to router D, causing a loop problem.

TTL: The maximum number of routers this packet can pass through during forwarding.

Each time it passes through the router, the TTL is reduced by one
. When the TTL is reduced to 0, it means that the packet can no longer be forwarded. If it does not arrive at this time, the packet will be discarded directly.

Network segmentation

One day, Zhang San was walking and picked up a wallet. There was a student ID card in it, but only a string of student numbers could be seen on it. So Zhang San only knew that
the wallet had a student number on it, and could only use the student number to find the person who lost the wallet. Master
, but it’s too inefficient to go searching alone.

The student number on the wallet has a unique identifier. If one person asks for the student number one by one, it is traversing everyone in the school
but excluding one person at a time, which leads to inefficiency.

Zhang San can be regarded as a message, and the wallet is the destination IP address. The person who lost the wallet can be regarded as the target host.
If the message delivers the data to the target host, if the entire network is asked one by one according to the destination IP address, the efficiency will be high. will be very low


Each college has its own group, and each college has its own student union president. There is also a group among the student union presidents
of these colleges. Zhang San belongs to the students of the School of Computer Science. The number of the School of Computer Science is 10. He belongs to the college. 210, his student number is 10210.
No student in the school has the same student number.
Assuming that the student number of the wallet he picked up is 12003,
Zhang San didn’t want to look for it himself, so he took a photo and sent it to the group of the School of Computer Science.
The student union president of the School of Computer Science knew that the number in front of each student number represented that college, so he found out that the person who lost his wallet was from the School of Chemical Engineering. He forwarded the
photo to the student union president group and notified the corresponding student union president of Chemical Engineering.

At this time, the chairman of the Chemical Engineering Student Union found out that it was a classmate from their college who lost it, so he forwarded the photo to the group of the Chemical Engineering College and notified classmate No. 003

In this process, the efficiency of return has improved, because this time the search is not done by individuals, but by groups. The
essence of search is a process of elimination. Selecting a group means excluding all other groups. Search efficiency is greatly improved


The student number can be seen as an IP address
. The group can be seen as a subnet. The president of the student union of the college can be seen as a router .
The group of student union presidents can be seen as a public network. The person who lost his wallet can be seen as a target host
. First find the target subnet (group) and then find it. target host


In order to send data from one host to another more efficiently across the network, subnets must be divided (each college has its own group) . The IP address is equal to the target network plus the IP address of
the target host. The subnet is
The result of the division is to improve the efficiency of one host finding another host
(because in order to quickly notify the school, each hospital needs to have its own group. For better management, it is Please bring your school ID number)

IP address division

The IP address is divided into two parts.
Network number: ensure that the two network segments connected to each other have different identities
(for each college, the college numbers cannot be the same as each other, and the college number is used to distinguish different colleges)

Host number: In the same network segment, hosts have the same network number, but they must have different host numbers
(Zhang San and Wang Wu are classmates, and they are all in the School of Computer Science, but their student numbers are different)

Subnetting

According to the IP address, the entire IP address is divided into five categories

Since only the first bit of Class A is 0, it proves that it is Class A. Class
A network has at most 2^7 networks, and there will be 2^24 hosts in each network.

The first bit of a Class B network is 1, which proves that it is not Class A. The second bit is 0, which proves that it is Class B. Class
B networks have up to 2^14 networks, and each network has 2^16 hosts.

The first bit of a Class C network is 1, proving that it is not Class A. The second bit is 1, proving that it is not Class B. The third bit is 0, proving that it is Class C. Class C networks have at most 2^
21 networks, each network has 2^8 hosts

If all applications for the Class B network are completed, it will be difficult to use up the 2^16 hosts in the Class B network, and others will not be able to use it, so it will be wasted.


Proposal of CIDR

Therefore, based on the original plan, a new improved plan was proposed, called CIDR

Introducing an additional subnet mask to distinguish the network number and the host number.
The subnet mask is a 32-bit positive integer, usually ending with a string of "0" (all 1 on the left and 0 on the right)
. Perform a bitwise AND operation on the address and subnet mask, and the result is the network number.
The division of the network number and the host number has nothing to do with whether the IP address is Class A, Class B, or Class C.

How to understand CIDR

There are only 2^32 IP addresses, so IP addresses are limited.
For better understanding, countries are used to divide IPs.


The first 8 digits of IP addresses are different in each country

Each country has its own international router.
Each international router will have a network number corresponding to the national network it is directly connected to.
For example: China's international router will have a network number corresponding to the Chinese network it is directly connected to.

In order to be called the global Internet, everyone's international routers are connected to the same network, called the public network, which is built by global operators.


There are many provinces in China, including Jilin Province, Liaoning Province, and Heilongjiang Province as examples

The first 8 digits of the IP address represent the country, and the next 6 digits represent the host. There are 32 digits in total, followed by . for 0.


There are inter-provincial routers between each province to build a public network, which is built by domestic operators.


Take Jilin Province as an example, including Changchun City and Jilin City. Both have their own IP addresses and build public networks .


Suppose there is an Internet company in Changchun City that provides a network service to the outside world. Americans want to access it.
Therefore, the company in Changchun must have its own external IP address.


Treat 2 digits in hexadecimal as 1 digit, which is 1 byte, which is 2.4.4.0/18 (the network number of Changchun City).
Assume that the IP address of this company in Changchun is 2.4.4.23 (belonging to one of the companies in Changchun City) , so there is a corresponding host number 23)


If an American wants to access the service corresponding to the company in Changchun, the American thinks that the network corresponding to their country starts with 1...
Since 2.4.4.23 is not an American IP, the IP is delivered to the public through an American router. Online
, through the public network, forwarded to the router in China

By bitwise ANDing 2.4.4.23 with China's subnet mask 0000 0010, we get the network number 2.0.0.0, which proves that it is from China.


The network number obtained by bitwise ANDing 2.4.4.23 with the subnet mask of Jilin Province is 2.4.0.0, and Jilin Province starts with 2.4, which proves that it is from Jilin Province. Bitwise
ANDing 2.4.4.23 with the subnet mask of Changchun City The obtained network number is 2.4.4.0, and the one in Changchun City starts with 2.4.4, which proves that it is from Changchun City.

Guess you like

Origin blog.csdn.net/qq_62939852/article/details/133044559