[Network Principle 2] IP protocol at the network layer, Ethernet protocol and MTU at the data link layer

network layer protocol

IP protocol

IP protocol format

insert image description here

4-digit version number (version) : Specifies the version of the IP protocol, which is 4 for IPv4.
4-bit header length (header length) : How many 32bits is the length of the IP header, that is, the number of bytes of length *4. 4bit means that the maximum number is 15, so the maximum length of the IP header is 60 bytes.
8-bit Type of Service (Type of Service) : 3-bit priority field (deprecated), 4-bit TOS field, and 1-bit reserved field (must be set to 0). The 4-bit TOS respectively represent: minimum delay, maximum throughput, highest reliability, and minimum cost. These four conflict with each other, and only one can be chosen. For applications like ssh/telnet, minimum latency is more important; for programs like ftp, maximum throughput is more important.
16-bit total length (totallength) : how many bytes the IP datagram occupies as a whole.
16-bit identifier (id) : uniquely identifies the message sent by the host. If the IP packet is fragmented at the data link layer, the id in each fragment is the same.
3-bit flag field:
the first bit is reserved (reserved means that it is not used now, but it may be used in the future if I haven't figured it out yet).
If the second bit is 1, fragmentation is prohibited. At this time, if the packet length exceeds the MTU, the IP module will discard the packet.
The third bit means "more fragments". If fragmented, the last fragment is set to 0, and the others are 1. Similar to a closing tag. If it is currently expressed as more fragments, it means that the message seen may be part of a large message body.
13-bit fragmentation offset (framegament offset): is the offset of the fragment relative to the beginning of the original IP packet. In fact, it indicates where the current fragment is in the original message. The actual number of bytes offset is obtained by this value * 8. Therefore, except for the last message, the length of other messages must be an integer multiple of 8 (otherwise the message will be discontinuous)
8-bit time to live (Time To Live, TTL) : The value of TTL indicates that every After a network device, it will be reduced by 1. If the TTL is reduced to 0, it means that the network is unavailable. This field is mainly used to prevent routing loops.
insert image description here

8-bit protocol : Indicates which protocol TCP, UDP...
16-bit checksum : CRC checksum is used in the transport layer .
32-bit source IP and destination IP address : The source IP and destination IP determined by the network layer.
Options : payload, data sent by the transport layer.

IP address

insert image description here

IPv4

The total length is 32 bits, which can represent up to 4.2 billion addresses. How to assign IP addresses on the network so that computers can visit each other?
1. Dynamic allocation : The device obtains an IP when it is online, and it will be taken back when it goes offline. An IP can only represent one host at the same time.
2. NET mechanism : All machines in a subnet share a public IP address, and the machines in the subnet are assigned intranet IPs. Intranet IP addresses can be repeated in different subnets, and public network IP addresses cannot be repeated.

insert image description here

IP addresses are divided into two categories:
external network IP/public network IP;
internal network IP/LAN IP: convention 10., 172.16.~172.31., 196.168.

IPv6

The total length is 128 bits to represent the IP address, which is approximately equal to 4.2 billion x 4.2 billion x 4.2 billion x 4.2 billion. IPV6 is not compatible with IPV4.

IP Address Rules - Address Management

Subnet mask : It is also 32 bits, and the left side is represented by 1, which is used to determine the network number. It will not be mixed with 1 and 0 to indicate how many 1s there are, which means how many bits on the left side of the IP address are the network number. The IP address and the subnet mask are bitwise ANDed, and the result is the network number.
Default gateway : All traffic must pass through the gateway, where traffic control can be done.

insert image description here

routing

How to reach the target host after sending a request. Imagine a map navigation route, there can be many. The route selection process itself is also a dynamic process. In the process of route selection, each query and advance to the target, one hop , the complete communication process is completed by hop by hop.
Specific process:

When the network datagram arrives at the router, the router itself will have a "routing table (the road that the router already knows), but a router cannot recognize the whole picture of the network but knows a part of it. If the current destination IP is known by the router, it will be A clear route will be given. If the current destination IP router does not know it, he will send this data to the next "more knowledgeable" router (more knowledgeable paths), the next hop, and eventually Find the path to the destination IP.

Is it possible to ask a long circle and not find the destination? It is possible. For example, if the IP address does not exist, every time you ask the router (routing and forwarding), the TTL will be reduced by 1. When the TTL is 0, the response will time out. Host not found.

How do machines in the internal network access resources on the external network, and how does the response from the external network be returned to the requesting machine?
1. Through DNS to resolve the IP address. DNS saves the correspondence between the domain names of all websites (such as the string "www.baidu.com") and IPs.
2. By setting the source IP and destination IP to perform layer-by-layer routing, and finally reach the target server.
3. After processing the response, return it to the sender in the same way.
insert image description here

Data Link Layer Protocol

ethernet protocol

"Ethernet" is not a specific network, but a technical standard; it includes not only the content of the data link layer, but also some content of the physical layer. For example: the network topology, access control method, transmission rate, etc. are specified; for example, the network cable in Ethernet must use twisted pair; the transmission rate is 10M, 100M, 1000M, etc.; Ethernet is currently the most widely used LAN technology; and There are token ring network, wireless LAN and so on in parallel with Ethernet.

protocol format

insert image description here

The source address and destination address refer to the hardware address of the network card (also called MAC address), the length is 48 bits, and it is solidified when the network card leaves the factory.
The type field has three values, corresponding to IP, ARP, and RARP;
the end of the frame is a CRC check code.

MTU (Maximum Transmission Unit)

MTU is equivalent to the limit on the package size when sending express. This limitation is the limitation caused by the physical layer corresponding to different data links.
The data length in the Ethernet frame stipulates a minimum of 46 bytes and a maximum of 1500 bytes. The length of the ARP packet is less than 46 bytes, and padding bits must be added later; the maximum value of 1500 is called the maximum
transmission unit (MTU) of Ethernet. Different network types have different MTUs;
if a data packet is routed from Ethernet to a dial-up link, and the length of the data packet is greater than the MTU of the dial-up link, the data packet needs to be fragmented (fragmentation); different data
links The MTU of the road layer standard is different;

Effect of MTU on IP protocol

● Due to the limitation of the MTU of the data link layer, larger IP data packets need to be divided into packets. Divide a large IP packet into multiple small packets, and label each small packet;
● The 16-bit identifier (id) of the IP protocol header of each small packet is the same;
● The 3-bit flag of the IP protocol header of each small packet In the field, the second bit is 0, which means fragmentation is allowed, and the third bit is the end mark (whether it is the last small packet at present, set it to 1 if yes, otherwise set it to 0)
; , will be reassembled in sequence, assembled together and returned to the transport layer;
● Once any of these small packets is lost, the reassembly at the receiving end will fail. But the IP layer will not be responsible for retransmitting data;

insert image description here

The impact of MTU on the UDP protocol

● Once the data carried by UDP exceeds 1472 (1500 - 20 (IP header) - 8 (UDP header)), it will be divided into multiple IP datagrams at the network layer.
● If any one of these multiple IP datagrams is lost, the network layer reassembly at the receiving end will fail. Then this means that if the UDP datagram is fragmented at the network layer, the probability of the entire data being lost is greatly increased.

The impact of MTU on the TCP protocol

● A TCP datagram cannot be infinitely large, and is still subject to the MTU. The maximum message length of a single TCP datagram is called MSS (Max Segment Size);
● In the process of establishing a TCP connection, the communication parties will conduct MSS negotiation.
● Ideally, the value of MSS is just the maximum length that IP will not be fragmented (this length is still subject to the MTU of the data link layer).
● When both parties send SYN, they will write the MSS value they can support in the TCP header. After the two parties learn the MSS value of the other party, they select the smaller one as the final MSS.
● The value of MSS is in the 40-byte variable length option of the TCP header (kind=2);

open question

Enter a URL in the browser, to the final display page, what will happen?

1. Perform DNS domain name resolution.
a. On the network, the IP address is used as the identification of the host, but the IP is not easy to remember, so a domain name is used to represent the IP address b. The
function of the DNS server is to convert the domain name into an IP address
c. There are 13 DNS servers in the world Root servers, one of which is called the main root, and 12 are auxiliary roots

2. Perform data encapsulation
a. The browser constructs an HTTP request (application layer protocol) according to the data requested by the user
b. Pass it to the transport layer TCP
C.TCP performs a three-way handshake and establishes a connection with the destination host
d. Sends the data to the network Layer, using IP protocol for encapsulation
e. The network layer then delivers the data to the data link layer
f. The data link layer encapsulates the data and then hands it over to the physical layer for transmission

3. Transmission process
a. In the middle, it will go through network devices such as switches and routers
b. Each network device will be divided, and then encapsulated for transmission to adjacent nodes. This division is to replace the source IP

4. Arrive at the target server
a. Perform layer-by-layer splitting
b. After reaching the HTTP layer, the service can parse out the resource requested by the user
c. The server responds (the business logic to be processed by the server program)

5. The server repackages the response data and sends it to the next layer
6. The response data is forwarded through the middle and returned to the client
7. The client parses the data to get the response data
8. The browser renders and presents the content


Keep going~
insert image description here

Guess you like

Origin blog.csdn.net/qq_43243800/article/details/131537095