preface
I’ll keep an eye on JD for the next two years. Found that large factories require computer networks. So ~ so I review the university knowledge, and make a note (HMMM I also greedy factory), I hope you are reading you can also gain, if you think I write bad, do not understand, you can also leave a message in the comment area
A network model
The OSI model
- Physical layer: network cable and optical fiber to transmit data (double glue line to transmit 0,1)
- Data link layer: Data transmission switch (LAN) between two devices Each device has its own MAC address The switch establishes a logical link through the MAC address
- Network layer: Addressing IP Finds the MAC address of the peer through the router
- Transport layer: The network environment is complex and the security is not high, and data transmission has leakage problems. Therefore, TCP is required to provide data integrity
- Session layer: Establishes sessions
- Presentation layer: The representation of data,
- Application layer: the interface that the user ultimately accesses
Why do we do this layering
The idea of functional separation and simplification of complex problems and modularization of our development should be; Similarly, the bottom layer serves the upper layer (from top to bottom: the physical layer serves the data link layer and so on).
This is purely personal understanding, no official basis
The working process of the
- Application layer (application layer, presentation layer, session layer) : Prepare data for transmission
- Transport layer: Packets data at the application layer according to TCP rules, and adds TCP headers to ensure data integrity
- Network layer: Finds the CORRESPONDING MAC address based on the IP address, gives its MAC address to the peer, and repackages TCP packets based on the IP protocol to add an IP header
- Data link layer: Adds MAC address information (the MAC address of the peer found by the upper layer) to the upper-layer packets for transmission
Physical layer: Data is transmitted through network cables
Note: TCP/IP refers not to a single protocol but to a family of protocols (rules for network transport)
Corresponding protocol
Just remember the common ones
- Network layer: An IP protocol used for communication rules in the process of obtaining the MAC address from the router and sending the MAC address to the router
- Transport layer: TCP and UDP
- TCP: a reliable transmission layer is established on the IP layer to provide two-way transmission of data (two-way communication at the same time, namely: duplex service).
- UDP: UDP is used for video transmission.
- The difference between the two (just for understanding)
- TCP has a three-way handshake for establishing a connection, while UDP does not
- Data transmitted through TCP connection is error-free, not lost, and not repeated, and arrives in sequence. Udp may lose frames
- TCP transmission efficiency is relatively low, udp transmission efficiency is high, suitable for high-speed transmission and real-time communication or broadcast communication
- TCP connections can only be point-to-point and one-to-one, while UDP supports one-to-one, one-to-many, many-to-one, and many-to-many interactions
- Application layer: HTTP (Hypertext Transfer Protocol), FTP (file transfer protocol) and so on
tcp
composition
Header ➕ packet
- Header :(port of data source) source port, (port of sending position) destination port)
- Data packet: a maximum of 40 bytes are supported at a time. If the data packet exceeds the value, you need to subcontract it
Three-way handshake
Recommended tool: Wireshark To view TCP handshake and wave information
- The client initiates a link request (a TCP packet) with the syn identifier seq of 1 (telling the server I want to initiate a link with you).
- After receiving the connection request, the client sends a TCP packet with the ACK bit (1) and the received SYN and the seQ value (➕) to the client to inform the client that it wants to initiate a bidirectional connection with the client
- The client leaves a SYN after receiving an ACK and establishing a connection. The ack code of the received ACK is equal to that of the SYN code, and the client sends a TCP packet back to the server indicating ok
The corresponding codes are not just ones and zeros that are relative and not fixed
Off-topic: the relationship between SYN and ACK
1: Is the seQ value from client to server the first handshake? 0: indicates the ack value from the server. 2. Is the ack value from the server to the client for the second handshake? 1 (actually random value) : seq+len 3 from the last client received. The sum of len and syn on the next request is the ack value that the server will return after receiving the request. After receiving ack and SYN from the server, the SYN sent back to the server is the value of the received ACK and len of the received ACKCopy the code
Why three handshakes instead of two or four
- Twice, the server cannot tell whether the client really received its response.
- There is no need for 4 reappearances because both sides have confirmed that the eye is the right person and then start communicating with each other to initiate HTTP requests
Four times to wave
- The client initiates the disconnect request. Fin (Finish) and ACK (ack is the same as seq+len returned from the server) indicate that the client will not initiate the disconnect request again
- The server responds to the disconnect request and ack flag lest the client assume that the server has not received a continuous initiate FIN
- If the server initiates its own FIN + ACK identifier, I will disconnect and will not respond again. (2 and 3 are incompatible: On the one hand, I am afraid that the client initiates fin continuously, on the other hand, I am afraid that there are still incomplete data responses on the way, so I need to confirm and disconnect after completion.)
- The client received the disconnected TCP packet from the server and returned ACK TCP saying ok
The server may initiate the disconnection, but more often the client disconnects
Characteristics of TCP
The sliding window
Two Windows, constantly sliding to determine the area of the sent data and the receiver’s cache area)
- Sliding window TCP is full-duplex, so the sender has a send cache; The receiving end has the receiving cache area, the data to be sent is put into the sending cache area, the sending window (data to be sent) is the part of the cache to be sent
- The core is flow control: when establishing a link, the receiver will tell the sender its window size (RWND is a name), each time the receiver receives data, it will confirm the size (RWND), if it is 0, stop sending data. (And send window probe package, continuously check window size)
- Nagle algorithm: There can be at most one unacknowledged segment at any time (the default of TCP internal control).
- Cork algorithm: sends the maximum Segment Size (MSS) when the maximum Segment Size (MSS) is reached
- The Nagle algorithm is the default for TCP internal control, but we can manually enable Cork without further understanding
The algorithm of sliding window I just do not in-depth study, interested in in-depth understanding of their own
TCP blocking processing
-
What is TCP blocking
Assume that the size of the receiver window is infinite and the ACK packet can be sent after receiving data. Then the transmission of data mainly depends on the network broadband, and the bandwidth size is limited, so blocking is needed
-
Congestion window CWND
TCP maintains a congestion window variable CWND (Congestion Window) (SSthRESH), which is increased without congestion during transmission and reduced if congestion occurs (Retransmission Timeout)
-
CWND < SSTHRESH uses a slow algorithm
-
CWND > sSHRESH uses congestion avoidance algorithm
-
When RTO, update sSTRESH value to half of current window, update CWND =1
Algorithm corresponding article
Occupy a word, HTTP article summary, to be filled out word