Total network connection timeout? Analyze how the network is connected from the four layer model

Time:2021-10-22

Total network connection timeout? Analyze how the network is connected from the four layer model

In the information age, almost everyone needs to use devices to access resources on the network. In this process, the connectivity realized by establishing network connection is the most basic function of computer network. Today, let’s share a knowledge about computer network——  How is the network connected?

The browser generates a message and sends it

The overall process of sending a message is as follows

Total network connection timeout? Analyze how the network is connected from the four layer model

Generate HTTP request message

Take chestnuts, when we type in the browserhttps://www.jdl.cn/img/servic…When the web address is, the browser will first parse the URL:

  • https: represents the mechanism for accessing the data source, that is, the protocol
  • www.jdl.cn: Web server name
  • img : Indicates the directory name
  • service.843585b7.pngThis represents the file name, and then the HTTP message will be generated. It is about long

Total network connection timeout? Analyze how the network is connected from the four layer model

What are the specific contents of these fields? You can refer to this article:Five thousand word essay, yes, we have an HTTP.

DNS domain name resolves to IP address

After the browser generates this HTTP message, where will it be sent? Of course, it’s a server, so we need to resolve which server this domain name corresponds to and what the IP address is. Because the IP address is difficult to remember, we have the corresponding domain name for our human memory.

  1. The browser will check whether there is an IP address corresponding to this domain name in the cache
  2. The operating system will check the cache (that is, the hosts file)
  3. The operating system will send it to the DNS server in this region to help resolve the DNS server and accept the query from the client, including the following three contents:
  • Domain name:  Server, name of mail server
  • Class:  In the earliest design of DNS, the application of DNS in other networks other than the Internet was also considered, and class is used to identify network information. However, there are no other networks except the Internet, so the value of class always represents the in of the Internet
  • Record type:  Indicates the record type corresponding to the domain name
  • When a records, the domain name directly corresponds to the IP address
  • When CNAME, this domain name corresponds to other domain names
  • MX indicates that the domain name corresponds to the mail server, and the response data is different for different record types

Total network connection timeout? Analyze how the network is connected from the four layer model

Hierarchy of domain names

  • The more right, the higher the level, one level from right to left: for example, www.jdl.cn is CN – > JDL – > WWW;
  • The domain name information with this hierarchy will be registered in the DNS server, and each domain is handled as a whole. The interaction process between the client and the DNS server is roughly as follows;
  • The DNS server IP address of its subordinate domain shall be registered in the superior DNS server, and then the IP address of the superior DNS server shall be registered in the higher-level DNS server, and so on this time;
  • The DNS server information of the root domain is saved to all DNS servers in the Internet. In this way, all DNS servers will find the root domain, and then look down level by level until they find the domain name they want;
  • There are only 13 IP addresses assigned to the root domain, which are the IP addresses corresponding to the top-level domain names (COM, CN, etc.).

Total network connection timeout? Analyze how the network is connected from the four layer model

  • The specific interaction is as follows

Total network connection timeout? Analyze how the network is connected from the four layer model

However, there is not enough storage in one server, so DNS servers generally relay to find this IP address, as shown in the figure below:

Total network connection timeout? Analyze how the network is connected from the four layer model

The client finds the nearest DNS server and looks up the information of www.jdl.cn, but the nearest DNS server does not have this information, so it forwards it to the root domain server. After judgment, it is found that it is the top-level domain name of CN, so the root domain DNS server will return the IP address of the DNS server in the CN domain it manages. Next, The recent DNS server goes back to the server of COM domain name, and so on. Finally, the IP address of the server www.jdl.cn will be found.

Delegate protocol stack to send message

After knowing the IP address, you can entrust the protocol stack inside the operating system to send messages to the target IP address.

Total network connection timeout? Analyze how the network is connected from the four layer model

  • The internal structure of protocol stack;

Total network connection timeout? Analyze how the network is connected from the four layer model

  • General applications such as browser and mail use TCP when sending and receiving data;
  • UDP is used for sending and receiving short control data such as DNS query.

Network layering

Total network connection timeout? Analyze how the network is connected from the four layer model

  • OSI seven layer model

Open system interconnection reference model (OSI for short) is a conceptual model proposed by the international organization for standardization, which is a standard framework that attempts to interconnect various computers into networks all over the world. Defined in ISO / IEC 7498-1.

  • TCP / IP quartic model
  • Application layer: HTTP、DNS、FTP;
  • Transport layer: TCP、UDP;
  • Network layer: IP;
  • Network interface layer.

TCP / IP (Transmission Control Protocol / Internet Protocol) TCP / IP protocol not only refers to TCP and IP, but also refers to a protocol cluster composed of FTP, SMTP, TCP, UDP, IP and other protocols. Just because TCP protocol and IP protocol are the most representative in TCP / IP protocol, it is called TCP / IP protocol.

Client server data transfer process

Total network connection timeout? Analyze how the network is connected from the four layer model

  • A packet passes between the client and the serverEach floorAll need processing;
  • The client side needs to constantly add headers to packets;
  • The server side needs to continuously split this packet.

Three handshakes

When two computers want to transfer data, they must first connect. They have to go through the TCP three-time handshake (only referring to those that need to be connected through the TCP protocol). We usually say that the TCP connection needs to go through the three-time handshake. Let’s take a look at what the TCP three-time handshake is, as shown in the figure

Total network connection timeout? Analyze how the network is connected from the four layer model

  • When the client wants to send, take the initiative fromclosedWhen the status is turned on, the server has been listening since it is startedLISTENstate
  • The client sends syn = 1, SEQ = x to the server, and the client is inSYN_SENDStatus.
  • After receiving, the server sends syn = 1, ACK = 1, SEQ = y, ACK = x + 1 to the client. At this time, the server is inSYN_RCVDstate
  • The client sends ack = 1, SEQ = x + 1, ACK = y + 1 to the server after receiving it. At this time, the client status isESTAB-LISHED
  • After the server receives it, the status changes toESTAB-LISHED
  • After three handshakes, it means that the client and server can transfer data packets for interaction
  • When we talk about syn, ACK, SEQ, ACK, what are these? These are actuallyTCP packetLet’s look down (atTransport layer(explained in)

application layer

HTTP packet splitting

Total network connection timeout? Analyze how the network is connected from the four layer model

  • Generally, the HTTP request message is not too long, and a network package can be installed
  • If the data in the sending buffer exceeds the length of MSS, it will be split by the length of MSS and put into a separate network packet
  • MTU(Maximum Transmission Unit):  The maximum length of a network packet is generally 1500 bytes in Ethernet
  • MSS(Maximum Segment Size):  The maximum length of TCP data contained in a network packet after removing the header

Transport layer

The network package of the upper application layerPlus the TCP header.

TCP message format

Total network connection timeout? Analyze how the network is connected from the four layer model

  • Source port number (16 bits):  Port number to send network packet
  • Destination port number (16 bits):  The port number of the recipient of the network packet
  • Serial number (serial number of transmitted data) (32 bits):  The sender informs the receiver that it has received the first few bytes of all data
  • Confirmation sequence number (sequence number of received data) (32 bits):  The receiver informs the sender that the receiver has received the first few bytes of all data
  • Head length (4 digits):  Represents the beginning of the data, and the data offset
  • Reserved (6 bits):  This field is reserved and is not used now
  • Control bit (6 bits):  Each bit in this field represents the meaning of the following communication control
  • URG:  Indicates that the emergency pointer field is valid
  • ACK:  Indicates that the serial number field of the received data is valid. Generally, it indicates that the data has been received by the receiver
  • PSH:  Represents the data sent through the flush operation
  • RST:  Force disconnection, used in case of abnormal interruption
  • SYN:  The sender and receiver mutually confirm the serial number, indicating the connection operation
  • FIN:  Indicates a disconnect operation
  • Window size (16 bits):  The receiver informs the sender of the window size (i.e. data that can be sent together without waiting for confirmation)
  • Checksum (16 bits):  Used to check for errors
  • Emergency pointer (16 bits):  Indicates the data location of emergency treatment
  • Optional fields (variable length):  In addition to the fixed header fields above, optional fields can be added, but they are rarely used except for connection operations

Remember the serial numbers mentioned in the three handshakes, which are the attributes in this message

network layer

Then the network package abovePlus the IP header

IP message format

Total network connection timeout? Analyze how the network is connected from the four layer model

  • Version number (4 bits):  IP protocol version number, currently version 4
  • Head length (4 bits):  The length of the IP header. The optional field can lead to the change of the header length. Therefore, the header length needs to be specified here
  • Service type (TOS) (8 bits):  Indicates the packet transmission priority. The definition of this parameter in the original protocol specification is very vague. RecentlyDIFFServThe rule redefines the usage of this field
  • Total length (16 bits):  Represents the total length of the IP message
  • ID number (16 bits):  The number used to identify the package, usually the serial number of the. If a packet is IP partitioned, all partitions have the same ID
  • Flag (3 bits):  There are 3 bits in this field, of which 2 bits are valid, respectively representing whether sharding is allowed and whether the current sharding is a sharding packet
  • Slice offset (13 bits):  Indicates that the content of the current packet is the content starting from the first few bytes of the entire IP message
  • Time to live (TTL) (8 bits):  Indicates the lifetime of a packet. This is to avoid that a packet will always rotate in the network when the network loopback occurs. Every time you pass through a router, the value will be reduced by one. If it is reduced to 0, the packet will be discarded
  • Protocol number (8 bits):  The protocol number indicates the type of protocol (the following are hexadecimal)
  • TCP: 06
  • UDP: 17
  • ICMP: 01
  • Header checksum (16 bits):  Used to check for errors. It is no longer in use
  • Sender IP address (32 bits):  IP address of the network packet sender
  • Receiver IP address (32 bits):  IP address of network packet receiver
  • Optional fields (variable length):  In addition to the fixed header fields above, optional fields can be added, but they are rarely used except for connection operations

Then this network packetPlus MAC header

Mac packet

Total network connection timeout? Analyze how the network is connected from the four layer model

  • Receiver MAC address (48 bits):  The MAC address of the network packet receiver, which is used in the LAN to transmit the network packet
  • Sender MAC address (48 bits):  The MAC address of the sender of the network packet, through which the receiver can judge who sent the network packet
  • Ethernet type (16 bits):  The type of protocol used. The following are some common types. Generally, only 0800 and 0806 are used in TCP / IP communication.
  • 0000-05DC: IEEE 802.3
  • 0800 :  IP protocol
  • 0806 :  ARP Protocol
  • 86DD : IPV6

MAC address vs   IP address

  • The IP header is also preceded by the MAC header
  • Why do I need MAC packets? Because in the world of Ethernet, the idea of TCP / IP is not feasible.
  • The way Ethernet judges the destination of network packets is different from TCP / IP, so it must adopt the matching method to send packets to the destination in Ethernet, and the MAC address does this
  • Sender MAC address: the MAC address is written in the ROM during network card production. You only need to read this value and write it into the Ma header

The MAC address of the sender is easy to obtain, but the MAC address of the receiver is not easy to obtain

ARP broadcast

  • ARP :Addresss   Resolution   Protocal address resolution protocol
  • Query by IP addressReceiver MAC addressARP broadcast will be used when
  • In the same subnet, use the broadcast to ask all devices whose IP address XXX is. If other devices find that their IP address is XXX, they will tell the questioner its MAC address, so as to detect the MAC address of the receiver. If they find that their IP address is not XXX, they will discard the message and ignore it.

Total network connection timeout? Analyze how the network is connected from the four layer model

  • If we broadcast every time, many ARP packets will be added to the network. Therefore, in order to improve efficiency, we have ARP cache in memory. Query the ARP cache before querying.
  • When the MAC address corresponding to the IP address of the destination changes, there will be a problem with the MAC cache. Therefore, in order to avoid this problem, the cache will be deleted after a few minutes, which is very simple and rough.
  • Static ARP:  Manual maintenance will not automatically fail
  • Dynamic ARP:  It will automatically fail after a period of time (that’s what the article says)

The IP module is responsible for adding the following two headers:

  • MAC header:  Header for Ethernet, including MAC address
  • IP header:  Header for IP, including IP address

Overall packet

At this time, the packet looks like this:

Total network connection timeout? Analyze how the network is connected from the four layer model

  • MTU(Maximum Transmission Unit):  The maximum length of a network packet, generally 1500 bytes in Ethernet;
  • MSS(Maximum Segment Size):  The maximum length of TCP data contained in a network packet after removing the header;
  • Then, the data packet goes out along the network card, goes to the hub and router for one-stop transmission (involving electrical signal conversion, etc.), arrives at the server, and is peeled layer by layer (as mentioned in the visit, the data packet is split layer by layer).

Disconnect

Four waves

After the two computers are finally connected, disconnect them and continueFour waves

Total network connection timeout? Analyze how the network is connected from the four layer model

actuallyThree handshakesFour wavesThere are still a lot of knowledge points to say, such as why it takes three times to shake hands and four times to wave hands. After that, we will open a separate article to talk to you in depth. Remember to scan the QR code below and pay attention to us!

Recommended reading

Welcome to click【Jingdong Technology】, learn about the developer community

More wonderful technical practices and exclusive dry goods analysis

Welcome to official account of Jingdong technology developer.

Total network connection timeout? Analyze how the network is connected from the four layer model

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]