1, the model

What is a model? It’s an abstraction. It gives us the outline of something. You can refer to a model of something when you implement it. For example: design drawings, engineering blueprints. In computers, to enable computers to communicate, a model is defined —– OSI seven-layer model. Just know there is one. That’s not the point.

1-1. OSI seven-layer model

Open System Interconnection applies to all networks.

Take a look at what the seven layers are:

  • The Application layer provides interface services between the network and user Application software
  • Presentation layer provides formatted Presentation and transformation of data services, such as encryption and compression
  • The Session layer (Session) provides a mechanism for establishing and maintaining communication between applications, including access authentication and Session management
  • Establish, maintain, and cancel transport connections to reliably transfer data (PC)
  • Network layer Handles routing between networks to ensure timely transmission of data (router)
  • DataLink layer (DataLink) is responsible for error-free data transmission, frame confirmation, error retransmission, etc. (switch)
  • Physics provides mechanical, electrical, functional, and process characteristics (network card, network cable, twisted pair, coaxial cable, repeater)

Look at this mess up here. How do you remember it? It’s easy. In a word: the chain network will be table.

Here, read it six times, read it three times when you leave work, read it before you go to bed, read it again the next day before you go to work, OK, you definitely remember it. That’s how I remember it.

1-2. TCP/IP reference model

Why another model? TCP/IP is an implementation of the OSI 7 layer model, but it doesn’t follow exactly the 7 layer model, which is normal. Take a look at these five layers:

  • The application layer
  • The transport layer
  • The network layer
  • Data link layer
  • The physical layer

Remember the OSI seven-layer model, you don’t even have to remember that.

2. Brief introduction of the functions of each layer

The most common application layer is HTTP protocol, of course, there are FTP, SMTP and so on. The function of this layer is to accept the user (that is, the programmer) raw data, various data such as letters, numbers, Chinese characters, pictures and so on into binary, and then according to a protocol, the data is wrapped up, and then thrown to the next layer.

2-1. Transport layer

The transport layer provides an end-to-end link that allows data to be sent and received with integrity and order.

The representative protocol of the transport layer is TCP. TCP has the following functions:

  • The data is segmented and packaged for transmission
  • Control the sequence of each packet number
  • Lost, reissued and discarded in transit
  • Flow control to avoid congestion

2-2. Network layer

The network layer is located between the transport layer and the network interface layer. It is used to transmit data from the source host to the target host through several intermediate nodes, and provides the most basic data transmission service to the transport layer, which provides routing and site selection.

There are several concepts involved in this layer, let’s look at them:

Location: The switch is addressed by MAC, and since MAC addresses are hierarchical, the IP address is used to determine the location of the computer. This is location

Routing: The job of routing is to select the shortest path among the multiple paths that can be selected

IP: On the network, each computer has a unique address for others to find it. This address is called an IP address.

2-3. Data link layer

The data link layer is used between the physical layer and the Internet layer to provide data to the network layer, that is, to transmit information from the source computer network layer to the target host.

MAC address:

  • The address embedded in the network card is used to identify the computer during communication
  • Each network card has a globally unique address to identify itself and will not be repeated
  • MAC address A 48-bit binary address, usually divided into six segments, expressed in hexadecimal

2-4. Physical layer

The physical layer is concerned with what signals are used to represent zeros and ones, whether two-way communication is possible, and how the initial connection is established and terminated. The physical layer provides a reliable environment for data transmission.

The main functions of the physical layer are:

  • Provides access for data – end devices to transmit data
  • To transmit data
    • Activate physical connections to form pathways between connected devices
    • Transmit data, care how to package data and control transmission speed
    • Closing a physical connection

3. Three handshakes and four waves

Take a look at the three handshakes:

  • First handshake Host A sends A data segment with the SYN bit to host B to request A connection. Through this data segment, host B tells host B that it wants to establish A connection, needs to reply, and tells host B the start sequence number of the transmission
  • In the second handshake, host B responds to host A with A data segment with an acknowledgement ACK and SYNC sequence number flag bit. On the one hand, host B sends an ACK to tell host A that it has received the data segment, and on the other hand, informs host A which sequence number to mark from.
  • The third handshake is when host A acknowledges that it has received the data segment from host B and can begin transmitting the actual data.

Take a look at the picture above:

So if you look at the graph, you always think, I want to establish a connection with the other person, one, the other person can receive my message, and two, I can receive the other person’s message. As with phone calls, very few people start talking as soon as they dial the number.

Let’s see what four waves are:

  • Host A sends A request for disconnection from the FIN control flag
  • Host B responds by acknowledging the disconnection request – Host B requests a shutdown in the opposite direction
  • Host A acknowledges the connection closure request received from host B

Look at the figure:

4, other

4-1. Appellation in different layers:

  • A data Frame is a unit of information whose starting point and destination point are the data link layer.
  • Packet: Also a unit of information, which starts and ends at the network layer.
  • Segment: Usually refers to a unit of information at the transport layer whose starting point and destination are both.
  • Message: A unit of information whose origin and destination are above the network layer (often at the application layer).

4-2, ASK and answer

Q: Why three handshakes?

A: Make sure that both parties receive and send the goods normally

2. Q: Why do you need four waves?

A: Both parties agree to disconnect the data after sending it

Q: Why wait?

A: The FIN sent by USER A to USER B may be lost

Q: Why do you shake hands three times but wave hands four times?

A: When the Server receives a FIN packet, the SOCKET may not be closed immediately