directory

  • Packet capture and TCP packet header
  • Reliable transport
  • Window concept extraction
    • Receiving window RWND and sending window CWND
  • Flow control
    • This section provides an example to illustrate the TCP traffic control process
  • Congestion control
    • Slow start and congestion avoidance algorithms
    • Fast retransmission and fast recovery algorithms
  • Difference between flow control and congestion control

Packet capture and TCP packet header

The Wireshark is used to capture packets. Use the two most common curl and ping commands to display the packet capture and enable packet capture.

# # to access my own homepage curl https://zengzhiqin.kuaizhan.com # # to check my own website address ping https://zengzhiqin.kuaizhan.comCopy the code

The Wireshark filters packets based on the IP address obtained from the ping command to obtain the packets obtained from the preceding two commands, including TCP (HTTPS based on TCP) and ICMP (ping based on ICMP), as shown in the following figure:

Caught analysis
TCP header data one-to-one mapping
The TCP header

Reliable transport

TCP reliable transmission of four implementation methods:

  1. check
  2. The serial number
  3. confirm
  4. The retransmission

The first and second mechanisms are explained in detail in another article of my official account. Here I mainly talk about the third and fourth mechanisms.

Reliable transmission purpose: is to let the sender send all the data, the receiver can be complete, in order to receive.

Just like Miyamoto Musashi’s phrase “line up, one at a time”, use the dumbest method to solve the most difficult problems, since you want to be reliable then confirm one by one, as long as you don’t tell me you received, then I will always resend.

How reliable transport works: Stop wait protocol

Reliable and unreliable solutions

The vertical line represents the time axis, and RTT represents the round trip time of sending the packet and confirming the packet back. They are analyzed respectively under the condition of “no error”, “sending timeout or failure”, “confirmation timeout” and “confirmation loss”. With this confirmation retransmission mechanism, TCP can implement reliable transmission, which is the way points 3 and 4 are implemented. It is important to know that retransmission is a spontaneous action of the sender and does not require the receiver to tell it to retransmit.

Window concept extraction

The above method, really good ha, with the simplest method to solve the problem of reliable transmission, but the network is always so busy, I wait for you to confirm that Miyamoto Musashi a big move jump out to estimate is a section of the ground, daylily are cold.

The biggest problem of the above – mentioned stop – wait protocol is that channel utilization is too low.

Stop waiting for transmission

RTT time is determined by network conditions and cannot be saved. T2 is also generally fixed. It can be seen from the formula that the channel utilization rate can only be improved from T1.

Pipeline transmission

The sender can send multiple packets consecutively without stopping to wait for confirmation each time. The packets consecutively sent above are contained in a window, which is the origin of TCP window, as shown below:

The sliding window

Since your sender can have windowing techniques in order not to send packets one by one, I am sure that our receiver has learned to accumulate acknowledgments instead of one by one.

Recipient cumulative confirmation mode

Receiving window RWND and sending window CWND

There are two Windows involved:

  1. Receiver window(RWND), yesThe receiving partyThe size of the receive cache value set according to its own capacity reflects the receiving capacity of the receiver,To do flow control.
  2. Congestion window(CWND)The senderThe value of the network window set according to the degree of network congestion, sending window =min(RWND, CWND) is the minimum value of the receiving window and congestion window,To do congestion control.

The window data structure is as follows:

Window data structure

In fact, the seemingly profound things, step by step to come over is so simple, “Ah, intelligent human” (naughty ha ha ha).

Flow control

I talked about increasing channel utilization through Windows, and then how to set the size of the window, how big, what else can the window be used for?

If the sender sends too fast, then the receiver will have no time to accept, and will lose the packet, which is definitely not ok, in case someone sent me a lot of red packets, I don’t want to lose one

Segmented transmission

Traffic control purpose: Enable the sender to dynamically adjust the sending frequency according to the network status so that the receiver can receive data in time.

TCP uses the sliding window mechanism for traffic control. The sending window of the sender changes dynamically, depending on the window size of the packet segment returned by the receiver. It may be a data packet segment or a confirmation packet, because there is window information in the header of TCP packets.

This section provides an example to illustrate the TCP traffic control process

Host A sends data to host B. When establishing A connection, Host B tells HOST A, “My RWND is equal to 400 bytes.” Assume that each packet segment contains 100 bytes and the initial serial number is 1. The three traffic control communication processes are as follows:

In this figure, at the end of the RWND =0, B will actively send his new RWND to A after the receiver has freed up the new receive cache, and A will wait for the notification of the new RWND from the receiver during the 0 window. In order to prevent the loss of the new RWND, many previous articles have analyzed this situation. In order to solve the problem that the packet cannot be received due to timeout, it is set to wait for a period of time before retransmission. In the process of four times waving, it is set to wait for 2MSL time before the sending end is closed. All these times are timed by setting a timer to solve the deadlock caused by packet loss. Similarly, in order to solve the deadlock caused by the loss of the new RWND, the sender will start the timer as long as it receives the 0 window notification. If the time is up, it will send A 0 window detection message again, and the receiver will reply to the current receiving window.

Crazy sounding

Congestion control

The best time of the network in my residential area is from 3-6 in the evening, from 10-12 in the morning, and from 3-5 in the afternoon, during which TIME I play king most freely. During the peak time of network from 8-11 in the evening, I stand in the spring water every time I snap back to my mind (really happy).

Imagine that the original network is not good, and then you also pour so many packets to the network at one time, everyone do not pass the timeout, and then the timeout time is again sent, the vicious cycle makes the original network is not rich even worse, so TCP you have to learn smart, for congestion control. The purpose of congestion control is to prevent so much data from being injected into the network that packets never reach the receiver.

Congestion control plays a role

There are four congestion control algorithms:

  1. Slow start
  2. Congestion avoidance
  3. Fast retransmission
  4. Fast recovery

Slow start and congestion avoidance algorithms

Slow start and congestion avoidance algorithms

A transmission round refers to the time RTT at which a batch of segments is sent and an acknowledgement is received.

Slow start is exponential growth, keep testing the network condition and keep exponential growth if healthy. When the SSTHRESH value, which is the slow start round limit value, began to increase linearly until the network congestion, the cliff type drop overnight back to before liberation, starting from 1, the new SSTHRESH value was lowered to half of the original congestion time and began to increase exponentially, so the dynamic change.

Fast retransmission and fast recovery algorithms

Fast retransmission and fast recovery algorithms

It can be seen from the figure that the algorithm is consistent with the slow start congestion avoidance algorithm in front, mainly by adjusting the cliff-jumping to reduce the sending rate, so that the efficiency is too low from 0. If it is a male and female friend sending wechat, it will not be torturing heart itch.

Congestion window CWND exponential growth once every time is in the case of received A confirmation message, such as A send 1,23,4,5,6 these segments, lost 2, 1345 received so every 345 received send A confirmation 1 received A confirmation message to send 2 (this place on A mentioned), This algorithm is the timeout timer expires in two retransmission immediately after confirmation of the received three 2, drives to the elder brother, the receiver is behind all three confirm package to indicate that the network love is nice when you get lost, so a quick retransmission or new ssthresh value lower half for congestion when began to exponential growth, Now is generally used in this kind of, above that kind of method hesitation efficiency is too low was eliminated.

Difference between flow control and congestion control

Flow control is a point-to-point problem. One-to-one, if the data of the receiver is too late to receive, the culprit can be directly found to the sender, mainly because the receiver is too late to receive the data of the sender;

Congestion control is many-to-one. A receiver faces multiple senders due to network congestion, and the receiver cannot find the specific sender because the data from the sender cannot reach the receiver due to network congestion.

In simple terms, congestion control is the traffic jam on the road, and flow control is the lack of parking space in the parking lot.

I’ve been writing this for a few days, feeling a lot of conceptual stuff, and I’ve tried to write it in a relaxed, chatty tone. It is raining in Beijing today, the trees on both sides of Wudaokou grow luxuriant, look up and see the leaves will tear the sky into pieces, the earphone has been circulating hair not easy low sexy voice singing “all the way to the mountains”, I walk in the heart of the city with an umbrella, all the way looking forward to the future.

Thank you friends watch, harvest friends point to encourage it, thank you ~

Next period: the application layer of those things, but also from our closest layer.