Mind mapping

Computer networks are structured in layers

An overview of the

The physical layer

The unit of bits transmitted over the physical layer, which specifies the electrical properties of the network, is responsible for the conversion of 0,1 bits between streams and electronic signals, or, if there is no physical layer, 0,1 bits

Streams will not propagate through physical media.

The link layer

Data link layer, also known as the link layer, simply doesn’t make any sense to 0 and 1 is, must provide the reading way, how many electrical signals to calculate a group, each electric signal again have what meaning, this is the role of the data link layer, data link layer, there are three main functions, respectively is encapsulated into a frame, transparent transmission, error control. We’ll explain all three in turn.

Encapsulated into a frame

To delimit frames by adding a header and a tail before and after a piece of data. Delimited as follows

Transparent transmission

Since whatever data is being transmitted should be able to be transmitted over the link, transparent transmission presents a problem. When the combination of bits in the data is exactly the same, if inappropriate measures are taken, the data can be shred. As shown in the figure below.

In this case, the transparent transmission problem is realized by using byte padding method. When the control character SOH or ETO appears in the link layer on the sending end, an escape character is added before ESC. If ESC also appears, an escape character is added before ESC, as shown below.

Error control

In the process of data transmission, if there is loss or frame damage, error control is needed to detect and correct, and this protocol will be explained in the network layer.

The MAC address

So the data frame is ready, and there’s another problem, computer A and computer B are sending data to each other, but who’s sending it to whom, how to tell it apart, and then the MAC address comes up. MAC address: Each computer in the human network has a network interface card (NIC) interface. Each NIC has a unique address, called a MAC address, which is used to transmit MAC addresses between computer networks.

The network layer

The main function of the network layer is to forward data between different networks. The router implements this function.

If you were in hangzhou computer A computer to give New York B communication, here will use broadcast mode to send data packets, and then compare the MAC address, the same, different, it is obvious that such A pretty at enmity with you, so in the network layer, divides the subnet, agreement, if be in the same subnet, They broadcast the data to each other or, if they are not on the same subnet, to the gateway for forwarding.

The transport layer

Through the network layer, A has been sent to B, here is the transport layer, transport layer, the main function of process for the application of the communication with each other, provide data transmission service, when computer A and computer B communication, on the transport layer, also need to specify A port, to A particular application, i.e., the transport layer functions is to establish A communication port to port, The function of the network layer is to establish host-to-host communication.

At the transport layer, TCP/UDP is used.

TCP establishes sessions during data transmission and divides files to be transferred to provide reliable transmission and traffic control. For example, when a large amount of data is downloaded, TCP is used.

UDP: A single packet can complete data communication, that is, there is no need to establish a session, no need for traffic control, and unreliable transmission, such as DNS domain name resolution, screen broadcast, is used here.

The application layer

When data is transmitted to the data at the transport layer, it needs to be interpreted, because the Internet is open and the application layer defines the data format of applications. For example, TCP protocol can transmit Email, WWW, FTP and other data formats of these protocols. For example, DNS for domain names, HTTP protocol for the World Wide Web, SMTP protocol for E-mail and so on. These data units are called packets.

TCP/IP based

Specific meaning

TCP/IP refers to some protocol group, specifically IP or ICMP, TCP, UDP, FTP, etc., and TCP/IP, HTTP, etc., all of these protocols are called TCP/IP Internet Protocol group. When communicating over the Internet, the corresponding network protocol is required. TCP/IP is a customized protocol developed for the Internet. In this case, the Internet protocol is TCP/IP, and TCP/IP is some protocols of the Internet. The protocol is shown below

Basic Working Principle

TCP/IP model has four layers, namely application layer, Internet layer, and network interface layer. Each layer has different functions. TCP/IP protocol is a combination of multiple protocols at different layers

The process of packaging and disassembly is shown below

Here, the relevant datagrams will be added, as well as the relevant data information, to achieve the purpose of data transmission.

The packet

In this case, it refers to the data unit of TCP/IP data communication, namely, the packet, that is, the data unit sent from the top layer, layer by layer, up to the network layer, and finally through the data link layer. Namely. A packet is a complete data unit. If it exceeds the MTU, it is combined with multiple frames to form a complete packet.

The packet is layered as follows

In network transmission, the packet consists of two parts, one is the header needed by the protocol, and the other is the data passed by the previous layer. The structure of the header is defined by the protocol specification. In the header of the packet, it clearly indicates how the protocol should read the data, that is, when the header is seen, It is clear what information is required and what data is needed to process the protocol.

Transport neutralizes TCP and UDP

port

The port is called connection port, port, and protocol port. Communication protocols at the transport layer usually need to specify port numbers, such as TCP and UDP under the TCP/IP protocol family. At the application layer, the master-slave communication protocol provides multiplexing service at each port. The protocol used by this connection can usually be identified by the well-known port numbers, which are the basic 1024 well-known port numbers. For example, Telnet uses port 23 by default, Secure Shell uses port 22, HTTP uses port 80, and HTTPS uses port 443 by default.

The source port number

Source port number is generally A themselves dynamically generated by the system number from 1024 to 65535, when A computer access to the computer through the network B, if it need each other to return data, it will create A greater than 1023 random port, tell B return the data when the data sent to which port, and then software start listening for the port, Wait for data to return. And B will read after receipt of the data packet source port and destination port, and then, when the software is created to the data returned after the original data packet in the original port port number as the purpose, and leave their port number as the original port, that is to receive the packet in the original purpose and, in turn, and then back to A, A repeats the process until the data transfer is complete. When all data is transmitted, A releases the source port. Therefore, data transmitted by the same software may not be the same source port number each time.

UDP

UDP (User Datagram Protocol) is a simple datagram oriented communication protocol. It is located in the transport layer of OSI model. UDP is an unreliable transport.

It has the following characteristics

  1. Connectionless UDP does not require the same three-way handshake as TCP does before data is sent. It is a data porter and does not process data. Specifically, at the sending end, the application layer transmits data as UDP. UDP only adds a UDP header to the data to identify the UDP protocol. At the receiving end, the network layer passes the data to the transport layer without doing any concatenation.

The function point

With unicast, multicast, broadcast and other functions.

For a message

UDP is packet-oriented and does not merge or split packets. Therefore, applications need to select appropriate packets and send them.

Unreliability.

UDP loopback data loss occurs because there is no related data confirmation process.

High transmission efficiency

Due to the low overhead of the header, the packet efficiency is quite high during data transmission.

TCP

When a computer communicates with another computer, the two computers need to communicate smoothly and reliably in order to ensure data receiving and receiving, so there is a three-way handshake, four-way wave, to achieve data connection.

Three-way handshake

  1. First handshake (SYN=1, seq=x):

The client sends a TCP PACKET with the SYN flag at position 1, indicating the server port to which the client intends to connect, and the initial Sequence Number X, stored in the Sequence Number field of the packet header.

After sending the packets, the client enters the SYN_SEND state.

  1. Second handshake (SYN=1, ACK=1, seq=y, ACKnum=x+1):

The server sends back an acknowledgement (ACK) reply. That is, the SYN flag bit and ACK flag bit are both 1. The server selects its ISN serial Number, puts it in the Seq field, and sets the Acknowledgement Number to the ISN plus 1 of the client, that is, X+1. After sending the packets, the server enters the SYN_RCVD state.

  1. Third handshake (ACK=1, ACKnum=y+1)

The client sends an ACK packet again with the SYN bit 0 and ACK bit 1. The client sends the SEQUENCE number field (+1) of the ACK packet sent by the server in the CONFIRM field, and writes the ISN (+1) in the data segment

After the packet is sent, the client enters the ESTABLISHED state. When the server receives the packet, the TCP handshake ends.

Four times to wave

  1. First wave (FIN=1, seq=x)

Suppose that the client wants to close the connection, the client sends a packet with the FIN flag position 1, indicating that it has no more data to send, but can still accept data.

After sending the packet, the client enters the FIN_WAIT_1 state.

  1. Second wave (ACK=1, ACKnum=x+1)

The server validates the client’s FIN packet and sends an acknowledgement that it has received the client’s request to close the connection but is not ready to close the connection.

After sending the packet, the server enters the CLOSE_WAIT state. After receiving the acknowledgement packet, the client enters the FIN_WAIT_2 state and waits for the server to close the connection.

  1. Third wave (FIN=1, seq=y)

When the server is ready to close the connection, it sends a request to end the connection to the client. FIN is set to 1.

After sending the packet, the server enters the LAST_ACK state and waits for the last ACK from the client.

  1. Fourth wave (ACK=1, ACKnum=y+1)

The client receives a close request from the server, sends an acknowledgement packet, and enters a TIME_WAIT state, waiting for a possible ACK packet requiring retransmission.

After receiving the acknowledgement packet, the server closes the connection and enters the CLOSED state.

The client waits for a fixed period of time (2MSL, 2 Maximum Segment Lifetime), but does not receive an ACK from the server. Therefore, the client closes the connection and enters the CLOSED state.

Zero-based Learning Java, you can join my Java learning garden.