2024 Postgraduate Entrance Examination 408-Computer Network Chapter 5-Transport Layer Study Notes

Article directory

Preface

Currently preparing for the 24 Postgraduate Entrance Examination, I will now summarize and organize the knowledge points learned in 408 of 24 Computer Kings.

Blogger blog article directory index: Blog directory index (continuously updated)

image-20230807102236865


1. Services provided by the transport layer

1.1. Functions of the transport layer

The transport layer is a layer that only hosts have.

image-20230807102339420

Transport layer functions :

1. The transport layer provides logical communication between processes.

  • Logical communication: On the surface, it is communication between processes of two hosts. In actual communication, the sender will first encapsulate it step by step from the top layer to the physical layer, put the bit stream into the link for transmission, and then go through the intermediate process. Multiple intermediate systems eventually reach the host and are decapsulated step by step, and finally the specified application requests the data.

image-20230807102711715

  • The network layer provides logical communication between hosts.

2. Reuse and deuse.

  • For example: the data sent by WeChat and QQ will eventually use the same transport layer protocol for transmission (multiplexing), and the target mobile phone will split the datagram at the transport layer at the same time and pass it to different applications. (for separate use).

3. The transport layer performs error detection on the received messages.

  • The network layer stage contains a header check, which is used to check the header of the IP datagram. The reason why there is no error detection function is because the upper transport layer will perform error detection on the transport layer segment. For the transport layer + network layer, a reliable transmission function can be realized.
  • Reliable transmission is not necessarily possible in the transport layer because it includes UDP and TCP, among which TCP guarantees reliable transmission.

1.2. Two protocols at the transport layer (TCP, UDP)

The two protocols are : TCP, UDP. The former is reliable, the latter is unreliable.

Comparison of TCP and UDP protocols :

TCP: Connection-oriented transmission control protocol.

  • Data transmission process : A connection must be established before data transmission, and the connection must be released after the data transmission is completed. No broadcast or multicast services are provided.
  • Since TCP needs to provide reliable connection-oriented transmission services, it inevitably adds a lot of overhead: confirmation, flow control, timers and connection management, etc.
  • Is it reliable ? Reliable, face-to-face connection, large delay.
  • Application scenario : Suitable for large files.

UDP: Connectionless User Datagram Protocol UDP.

  • Data transmission process : There is no need to establish a connection before transmitting data, and no confirmation is required after receiving the UDP message.
  • Reliability : unreliable, no connection, small delay.
  • Application scenario : Suitable for small files.

1.3. Transport layer addressing and ports (introduction to common ports)

Reuse and deuse :

  • 复用: All application processes in the application layer can be transmitted to the network layer through the transport layer.
  • 分用: The transport layer delivers the data to the specified application process after receiving the data from the network layer.

Port : SAP at the transport layer, used to identify the application process in the host. Each application process will have a port number when running.

  • Mainly divided into : logical port/software port, which refers to the port of the application process. For hardware ports, it refers to some interfaces on the motherboard in the real physical world.
  • Port relationship : Port numbers have only local meaning, and there is no connection between the same ports on different computers on the Internet.
  • Port number length : 16 bits, which can represent 65536 different ports.

Port numbers are divided according to range : including the port number of the server and the port number used by the client.

image-20230807104512998

Some of the common ports used by fixed application services are as follows :

image-20230807104714701

A combination of sender and receiver sockets is used to identify endpoints in the network .

Socket : uniquely identifies a host on the network and a process on it.

  • 套接字Socket = (主机IP地址,端口号), where the host IP address can identify and locate a host in a network, while the port number is used to represent a process on the host.

2. UDP protocol

2.1. Understand UDP functions and characteristics

UDP function : only provides few functions on top of IP datagram services, such as multiplexing, demultiplexing and error detection functions.

Main features of UDP :

1. UDP is connectionless , reducing overhead and delay before sending data.

2. UDP uses best-effort delivery, which means reliable delivery is not guaranteed .

  • If the UDP protocol cannot guarantee reliable delivery, then reliable delivery is left to the upper application layer of the transport layer to ensure reliable and sequential delivery.

3. UDP is message-oriented and suitable for network applications that transmit a small amount of data at one time.

No matter how long the application layer sends UDP messages, UDP will send them as usual, that is, one complete message at a time . Since it is also unreliable delivery, it can easily lead to data loss. If the amount of data transmitted is not large, even if a loss occurs Environmental losses are also relatively small.

image-20230807114742179

  • If the data is too large, it needs to be fragmented at the network layer , because there is an MTU requirement in the link layer for subsequent transmission to the link layer.
  • If the data is too small, less than the header, then the efficiency of the network layer will be reduced. What is hoped is that a datagram contains as much data information as possible and as little additional information as possible in the header.

4. UDP has no congestion control and is suitable for many real-time applications.

  • **This does not mean that there is no congestion control. Even if the network is congested again, UDP will not slow down the sender, and this problem will not be controlled at this time. Do you think this agreement is not good in this situation? **Actually not, because UDP does not have congestion control, it also brings some advantages, such as being suitable for many real-time applications, such as IP telephony and video conferencing, and it allows some data to be discarded when network congestion occurs. , because these real-time applications cannot allow too much delay in data. In fact, a little loss is allowed.
  • For particularly serious congestion situations, certain remedial measures will be taken, such as forward error correction or retransmission of lost messages.

5. UDP header overhead is small, 8B , while TCP is 20B.


2.2. UDP header format

The total number of header fields is fixed at 8B , including 源端口号, 目的端口号, UDP长度and UDP检验和are all 2B (16 bits) .

image-20230807142226875

16位UDP长度: Refers to the data field + header field. If the data field is 7B, then the UDP length is 15.

16位UDP检验和

  • Case 1: Check whether the entire UDP datagram has errors and discard it if it does.
  • Case 2: When splitting (when the receiving end receives it, it needs to split it to different processes according to the port number). If the corresponding destination port number cannot be found, then the message will be discarded and ICMP "port" will be sent to the sender. Unreachable" error message.

2.3. UDP pseudo header field analysis

The pseudo header only appears when calculating the checksum, and is neither sent downward nor submitted upward. The pseudo header is the simulated IP datagram header.

image-20230807142643976

  • 源IP地址: 4 bytes.
  • 目的IP地址: 4 bytes.
  • 0: 1 byte, all 0s, that is, the third field of the header is fixed with all 0s.
  • In the pseudo header 17: 1 byte, the protocol field of the IP datagram header encapsulating the UDP message is 17 .
  • UDP长度: 2 bytes, UDP长度 = UDP首部8B + 数据部分长度(excluding pseudo header)

2.4. Pseudo header verification UDP user datagram process

How to use pseudo headers to verify whether there are errors in UDP user datagrams?

Think of it as many 16-bit strings connected together, that is, many 4-byte components. As shown in the right half of the figure below, every 16 bits are written side by side as a group:

image-20230807143733417

On the sending side :

1. Fill in the pseudo header.

2. Fill the checksum field with all zeros.

3. Fill the data part with all 0s (UDP datagrams should be regarded as many 4B strings concatenated).

4. Calculation: Sum the pseudo header + header + data parts using binary one’s complement code.

5. Fill in the one 's complement of the sum into the checksum field in the header .

6. Remove the pseudo header and send.

On the receiving end :

1. Fill in the pseudo header.

2. The pseudo header + header + data part is summed using binary complement.

  • Note: The checksum at the sender is all 0 when calculating the sum , while at the receiver the checksum is the inversion of the previous summation result. Here we add the checksum .

3. If the final result is all 1, there is no error. Otherwise, the datagram will be discarded or the application layer will attach an error warning.

The following difference in the summation is the checksum part. At the receiving end, this checksum is the checksum at the sending end, and it is no longer calculated using all 0s:

image-20230807144229421

**Why does the final sum equal to 1? **It can be seen that the final result obtained at the sending end is the inverse code and put into the verification end. Then the calculated value + the inverse code value is all 1. Add the following two lines.

image-20230807144431704


3. TCP protocol

3.1. TCP protocol characteristics and message format

3.1.1. Characteristics of TCP protocol

1. TCP is a connection-oriented (virtual connection) transport layer protocol.

  • Virtual connection: Same as the transport layer logical communication, it is not an actual physical connection. The physical connection refers to adding the headers of each layer to the datagram and putting it on the link for transmission, and then going to the receiving end for step by step Decapsulation, this is a complete physical connection. The use of the TCP protocol is as if the two processes have established a point-to-point connection, so it is a virtual connection.

2. Each TCP connection can only have two ports, and each TCP connection can only be point-to-point.

3. TCP provides reliable delivery services, with no errors, no loss, no duplication, and in-order arrival. [Reliable and orderly, nothing lost or heavy]

4. TCP provides full-duplex communication.

  • In full-duplex communication, both ends can send and receive data at the same time.
  • For its characteristics, both ends of the TCP protocol connection will be equipped with a sending buffer (queue ready to send) and a receiving buffer (queue ready to receive) .
    • 发送缓存: Data ready to be sent & data sent but not yet confirmed. (For some data that has been sent but has not yet received confirmation, it cannot be deleted directly from the cache, because once a timeout occurs, it will need to be retransmitted)
    • 接收缓存: Data that arrives in order but has not yet been read by the accepting application & data that arrives out of order. (For each data that arrives in order, only when the order of the data is arranged, can the receiver take out the data one by one from the receive buffer and deliver it to the corresponding process).

5. TCP is oriented to byte streams

  • It refers to the fact that TCP sees the data handed over by the application as just a series of unstructured byte streams .
  • : A sequence of bytes flowing into or out of a process.

As shown in the picture below, the file contains multiple bytes. We put 10 bytes into the cache and wait for sending:

image-20230807151534399

When sending begins, 3 bytes may be first taken to form a TCP segment, and then the TCP header is added to this segment to form a complete segment, and then placed on the link for transmission. For this The number of bytes transferred varies depending on the specific situation:

image-20230807151713433

So the TCP protocol is byte-oriented or byte stream.


3.1.2. TCP segment header format

Overall description of the TCP segment header :

  • A TCP message segment consists of a TCP header and a TCP data part.
  • The number of data bits in the TCP header is required to be an integer multiple of 4B. At this time, the TCP header needs to be filled with some data, usually all 0s.
  • The header contains a fixed 20B, and other options and padding fields are calculated separately.

image-20230807161416442

The following is a detailed description of the 11 fields in the TCP header :

①-② 源端口、目的端口: Each occupies 2B, which is 16 bits.

序号位: Occupies 4B. Each byte in the byte stream transmitted in a TCP connection is numbered in sequence. This field indicates the sequence number of the first byte of the data sent in this segment.

  • In Example 1, you can see that 1, 2, and 3 bytes are sent continuously, then the sequence number in the TCP header is 1 (the first byte transmitted), which means the first byte.
  • In Example 2, you can see that 4, 5, and 6 bytes are sent continuously, so the sequence number in the TCP header is also 4 (the first byte transmitted), which represents the fourth byte.

image-20230807153056946

确认号: Expect to receive the sequence number of the first data byte of the other party's next message segment. If the confirmation number is N, it proves that all data up to sequence number N - 1 have been received correctly.

  • This confirmation number is sent through the target host . When the number of bytes 1, 2, and 3 transmitted by our first message arrives, the target will return a confirmation message segment. At this time, the header of the confirmation message segment contains a confirmation number = 4, which means The problem is that bytes 1, 2, and 3 have been received, and I now hope to receive byte No. 4.

image-20230807153438376

数据偏移(首部长度): How far is the starting position J of the data in the TCP segment from the start of the TCP segment, in 4B bit units, that is, one value is 4B.

The TCP segment length refers to the following figure:

image-20230807153929498

Since the unit is 4B, if the data offset is 1111, then it is 16 x 4B = 64B. The current TCP header is 64 bytes, fixed at 20B, and optional + padding is 44B.

⑥6 control bits :

  • 紧急位URG: When URG = 1, it indicates that there is urgent data in this message segment. It is high-priority data and should be transmitted as soon as possible without queuing in the cache. It is used in conjunction with the emergency pointer field . (As follows, when multiple segments of the message to be sent have been split in the cache, then the message in the 4th segment on the way contains URG=1, which means that the data needs to be transmitted as soon as possible, and a priority is given to it. At this point, you can move to the front without having to wait in line for its turn.)
    • image-20230807154407866
  • 确认位ACK: When ACK = 1, the confirmation number is valid. After the connection is established, all transmitted message segments must have ACK set to 1.
  • 推送位PSH: When PSH = 1, the receiver delivers the application process as soon as possible, and does not wait until the cache is filled before delivering it upwards. (Refers to an emergency processing performed by the receiver . As shown in the figure below, if the second segment of the cache area is PSH=1, then it will be given the priority of a message segment and will be quickly delivered to the application layer. process.)
    • image-20230807155123909
  • 复位RST: When RST = 1, it indicates that a serious error occurred in the TCP connection and the connection must be released and then the transmission link re-established.
  • 同步位YSN: When SYN = 1, it indicates a connection request/link acceptance message. (As shown in the figure below, if the sender sends SYN = 1, the receiving end will also return a SYN = 1).
    • image-20230807155430077
  • 终止位FIN: When FIN = 1, it indicates that the sender data of this segment has been sent and the connection is required to be released.

Let’s have a brief understanding of the push bit and reset exams.

窗口字段: Refers to the receiving window of the party sending this segment, that is, the amount of data the other party is allowed to send now.

  • Example 1: At this time, the message segment header sent by the receiving end has a window bit of 65536. If the sending end A receives it at this time, it will set the window size of its own sending buffer to 65536.
    • image-20230807160443296
  • Example 2: At this time, the confirmation number in the message segment sent by the receiving end B is 701 and the window field is 1000. At this time, the sender will set its own sending buffer to 1000 and send its own 701-1700 bytes to the receiving end. Square B.
    • image-20230807160745599

校验和: Check header + data, add 12B pseudo header when checking, and the fourth field (corresponding to the protocol field) is 6.

紧急指针: It is meaningful only when URG = 1, indicating the number of bytes of emergency data in this segment.

  • Example: If the emergency pointer is 50, it means that the TCP data part from the 1st byte to the 50th byte is urgent data.
  • image-20230807161110574

10 选项: Maximum segment length MSS, window expansion, timestamp, selection confirmation...

11 填充字段: If the option field is not an integer multiple of 4B, then it needs to be filled in to an integer multiple of 4B.


3.2. TCP connection management

3.2.1. Three stages of TCP connection transmission

There are three stages of TCP connection transmission :

image-20230807170338871

The TCP connection is established using the client/server method . The application process that actively initiates the connection establishment is called the client, and the application process that passively waits for the connection establishment is called the server.

Three-way handshake when connecting:

image-20230807192627428


3.2.2. TCP connection establishment process

3.2.2.1. Detailed explanation of three-way handshake for connection

image-20230807200326652

ROUND1 : The client sends a connection request segment without application layer data.

SYN = 1,seq = x(随机)

  • SYN = 1: It is 1 when the connection is requested.
  • seq = x (random): Sequence number bit. This sequence number is randomly generated and can start from any random number at the beginning.
  • The confirmation number is invalid here because the client has not received enough message segments from the server, so the client does not know which sequence number message segment it will expect from the server next. At this time, it confirms The number is meaningless.

There are only two situations for SYN to be set to 1, one is a connection request, and the other is a confirmation of the connection request.

ROUND2 : The server allocates cache and variables for the TCP connection, and returns a confirmation message segment to the client , allowing the connection without application layer data.

SYN=1,ACK=1,seq=y(随机),ack=x+1

  • SYN=1: The acceptance of the connection request is still 1.
  • ACK=1: When ACK=1, lowercase ack is also valid at this time, and these two need to be used together.
  • ack=x+1: At this time, the confirmation number should be filled with the first byte of the message segment expected to be sent by the other party. Since the sequence number requested by the client last time indicates that the segment is x, the next byte the server wants to receive at this time should start from x+1.
  • seq=y (random): At this time, the confirmation message segment also has a sequence number byte, and this sequence number itself is also randomly assigned by the host itself.

ROUND3 : After the client receives the confirmation from the server, it should return a confirmation to tell the server that we have established a connection, and then we can send you data. What is different from the first two message segments is that this third message segment A message segment can carry data. At this time, the data to be officially sent can be put into the message segment.

  • The client allocates cache and variables for the TCP connection and returns a confirmed confirmation to the server, which can carry data.

SYN=0,ACK=1,seq=x+1,ack=y+1

  • SYN=0: There is currently no connection request or confirmation of the connection request. It is 0 at this time. The data SYN sent after that is all 0.
  • ACK = 1: When ACK=1, the lowercase ack is also valid at this time, and these two need to be used together.
  • seq = x + 1: The first byte of the segment it sends is x+1.
  • ack = y + 1: Since the previous seq sequence wanted to receive y, the next sequence number to be expected at this time is y+1.

3.2.2.2. Possible problems in the three-way handshake: flooding attack

For the second and third steps, both the server and the client allocate cache and variables around the TCP connection process, which will cause problems : 洪泛攻击.

Reason : Hacker attack problem caused by three-way handshake.

Attack description: The SYN flooding attack occurs on the fourth layer of OSI. This method uses the characteristics of the TCP protocol, which is the three-way handshake . The attacker sends TCP SYN. ​​SYN is the first packet of the TCP three-way handshake. When the server returns ACK, the attacker does not reconfirm it . Then the TCP connection is in a suspended state, which is the so-called half. Connection status . If the server cannot receive the re-confirmation, it will repeatedly send ACK to the attacker, which will waste more server resources.

  • At this time, the attacker takes advantage of the repeated situation described above and continues to send a very large number of such TCP connections to the server. Since each one cannot complete the three-way handshake, at this time on the server, these TCP connections will be hung due to In this state, CPU and memory are consumed, and eventually the server may crash and cannot provide services to normal users.

Solution to syn flooding attack : set up syn cookie.


3.2.3. TCP connection release process (four waves)

Wave four times when closing the connection :

image-20230807192814533

Either of the two processes participating in a TCP connection can terminate the connection . After the connection is completed, the "resources" (cache and variables) in the host will be released.

image-20230807192947459

ROUND1 : The client sends a connection release segment , stops sending data, and actively closes the TCP connection.

FIN = 1,seq = u

  • FIN = 1: When the connection is released, the FIN end bit should be set to 1.
  • seq = u: refers to the sequence number of the first byte of such a message segment. Since this message segment usually does not contain data, a sequence number can represent such a message segment.

ROUND2 : The server sends back a confirmation message segment, and the connection from the client to the server in this direction is released. (It is in a semi-closed state at this time )

ACK = 1,seq = v,ack = u+1

  • ACK = 1: ack is effective at this time.
  • seq = v: It depends on where it was sent before. For example, the last message segment sent by this server before, the last byte is v - 1, and seq is marked as 1 at this time.
  • ack = u + 1: Indicates the confirmation of the previous message segment, the previous message seq = u.

When the host receives such a confirmation message segment, it does not need to reply, because the host has now ended the call. It only needs to wait for the server to tell it that it has ended, and then the connection between them is officially closed.

Note: The remaining data will also be sent during this process.

ROUND3 : After the server sends the data, it sends a connection release segment and actively closes the TCP connection.

FIN = 1,ACK = 1,seq = w,ack = u + 1

  • FIN = 1: As long as the connection is requested to be closed, FIN = 1 needs to be initiated.
  • ack = u + 1: Since this request was sent directly after the server phase 2 when the connection was closed, the intermediate client did not send another request. At this time, the ack reply field is still u+1, which is the same as in ROUND2. Confirm the display.
  • seq = v: The actual situation also depends on the amount of data sent by the server after the reply confirmation after the second step.

ROUND4 : The client sends back a confirmation segment, and then waits until the waiting timer is set to 2MSL (the longest segment life). At this time, the connection is completely closed.

  • 2MSL refers to the life of the longest message segment. If the confirmation message segment does not reach the server, then the server will resend the connection close request if it does not receive it at this time. If the connection close request is received within 2MSL, it will reinitiate the confirmation.

ACK=1,seq = u + 1,ack = w + 1


3.3. TCP reliable transmission

Four TCP mechanisms to achieve reliable transmission

Method 1: Verification

Process : Same as UDP verification, adding a pseudo header .

  • The verification method of the UDP protocol is the same as that of adding a header to the sender and receiver, and then using the binary complement sum calculation method to determine whether an error has occurred.

Method 2: Serial number mechanism

Like UDP, the finally sent message segment may be a few bytes in the TCP cache below, then the sequence number indicates the position of the first byte of each segment in the entire TCP cache:

image-20230807201214178


Method 3: Confirmation mechanism (based on serial number mechanism)

Below we can see that when the first segment of the message in our TCP cache is sent to the server, the first segment is not deleted from the TCP cache:

image-20230807202255361

The reason is to wait for confirmation from the server before deleting it . If the confirmation message is not received, the message may be lost. Therefore, how does the sender know that the receiver has correctly and completely received the entire message? , relying on our confirmation mechanism, after the receiver receives this message segment, it will return a confirmation message segment.

It can be seen that when our server returns the confirmation message, the confirmation number field is 4, which means that the data before 4 has been received. At this time, the sender can delete the first segment in the TCP cache. :

image-20230807202526431

Then if there are segments 1, 2, and 3, the second segment in the middle is still delayed (may have been lost), and segments 1 and 3 have been received. At this time, TCP will use cumulative confirmation by default. At this time, the confirmation number The field is still 4, that is, the server tells the client that I will still receive the message starting with the 4th byte:

  • Although it is said to be received sequentially, in this case, the 2nd segment in the middle has not arrived, and the 3rd segment can also be received.

image-20230807202834287

At this time, the client will send the second segment of the message, that is, 4, 5, and 6. When the second segment report is sent to the server, the server has received segments 1, 2, and 3. Then the next time The confirmation number field in the sending confirmation segment is 9.

Description of the situation of arriving at the server in order or out of order :

  • The message segments arrive completely in sequence: At this time, the receiver will return this confirmation to instruct the sender which segment of the message to send next (the order reaches the last bit at the end of the last message segment).
  • The message segments do not arrive in order: then the receiver will return a confirmation message segment. At this time, this message segment can indicate which message the sender should retransmit (the first message segment that has not arrived in the middle The first one).

Method 4: Retransmission (RTTS weighted average round trip time, fast retransmission mechanism)

The acknowledgment and retransmission mechanisms are not separated. If the TCP sender does not receive the acknowledgment within the specified time (retransmission time), it will retransmit the sent message segment. [ Timeout retransmission ]

Question 1: When will it be retransmitted?

  • If the sender exceeds a certain period of time and has not received confirmation from the receiver, then the sender knows that the segment he sent should be lost, and at this time he should remove his segment from the cache. Take it out and retransmit it.

Question 2: How to calculate the retransmission time?

  • Since the lower layer of TCP is an Internet environment, the packets sent may pass through the LAN of the highway or the low-speed network. Then the route chosen by each IP datagram is also different, depending on the time. A network situation will cause many message segments sent by the sender to take different paths, so we cannot set a fixed time.
  • Principle: TCP uses an adaptive algorithm to dynamically change the retransmission time. Then this retransmission time is called RTTs(加权平均往返时间), that is, when we send the first message segment, the RTTs refers to the first message fetched. RTT (confirmation is known from the time the first message is sent), and then when the second RTT is sent, there will also be an RTT, and then based on the first and second RTTs, an RTTs can be calculated as the current heavy Pass time. When sending the Nth segment of RTT in the future, a weighted average round-trip time will be set and calculated through a formula .

Question 3: For timeout retransmission, if the timeout period has not been reached, then it will keep waiting. Is there a way to know whether the sender has lost the segment before the timeout event occurs, and then as soon as possible What about the retransmission?

Solution : 冗余ACK(冗余确认), related to the confirmation mechanism.

Process : Whenever a timing message segment larger than the expected sequence number arrives, a redundant ACK is sent to indicate the sequence number of the next expected byte.

For the following situation, you can test the order because 2 is not received after segment 1. At this time, 3, 4, and 5 are coming continuously. At this time, the server will receive them. When a message segment is received, it will actually be sent. For a confirmation number, you can see that after segment 1, since segment 2 has not arrived, the confirmation number in the confirmation message segment is always 2. You can see that the continuous confirmation number at this time is the middle 2 segments, so it is a Redundancy confirmation . When the receiving end receives three segments with the same sequence number (three consecutive segments after sequence number 2 based on 1), it will determine that the segment No. 2 it sent has been lost. will be retransmitted (at this time, the early retransmission effect is achieved )

  • **Why can it arrive out of order? **In TCP, the receiving end does not receive a confirmation mechanism to send a message segment. It can send multiple message segments continuously.

    image-20230807205057487

This technology can also become: fast retransmission technology .


3.4. TCP flow control

3.4.1. Reasons for TCP flow control and sliding window process

Reason : When sending data, we usually hope that the data sending rate can be faster. However, if the sending rate is too fast, the receiver may not have time to receive it, which will lead to very serious packet loss . , at this time, flow control is needed to control a sending rate of the sender.

Flow control : Let the sender slow down so that the receiver has time to receive.

TCP is used 滑动窗口机制to implement flow control.

Sliding window process : During the communication process, the receiver dynamically adjusts the sender's sending window size, that is, the receiving window rwnd (the receiver confirms the window field of the message segment to notify the sender of rwnd) based on the size of its own receiving buffer . , the sender’s sending window takes the minimum value of the receiving window rwnd and the congestion window cwnd .

  • Resource congestion: The network is blocked, which means that the network was using network devices at that time, and there were too many hosts with network resources, which caused problems such as slow sending/slow forwarding and queuing time in the entire network.
  • The sender's sending window depends on the minimum of the receiving window and the congestion window . [Sending window = Min{receiving window, congestion window}]

The window for the sender can be changed dynamically . This depends on a message segment returned by the receiver, which may be a confirmation message or a data message. If the window field is large, it means that the sender can now send more For some data, if the window field is relatively small, then the sender will send less data:

  • As shown in the figure below, the confirmation message is received and returned one by one, in which the sending window is set to 6. At this time, the sender divides 6 windows to send out at one time.

image-20230807213730833


3.4.2. Detailed process of TCP flow control

A sends data to B. When the connection is established, B tells A: "My rwnd = 400 (bytes)". Assume that each message segment is 100B and the initial value of the message segment sequence number is 1.

image-20230807214033482

Detailed process description :

1. First, A requests B to establish a connection, and then B returns a confirmation message segment in which the field rwnd = 400 (bytes) is set.

2. Host A receives the confirmation message segment and reads rwnd = 400. At this time, it divides 400 bytes into its own sending buffer window (since the message segment is 100B, it is exactly 4 segments).

image-20230807221129027

Then 4 message segments are sent continuously according to the size of the window, each segment is 100 bytes. According to the figure, you can see that the first two message segments are successfully received by host B, but the third segment is lost :

image-20230807221538724

3. At this time, host B sends a confirmation message segment, which indicates that I will receive a message segment starting from 201 bytes. At this time, it also indicates that the current window that can be received is 300 bytes.

image-20230807221819129

The sending window of host A starts from 201 bytes that have not been received by the receiving end until 500 bytes:

image-20230807221948467

4. At this time, the sending window of the sender is 300 bytes, and since the 201-300 byte message segment has not yet received the confirmation message, it will remain in the sending window at this time. Next, host A sends data. You can send the data in these two grids starting from 301, the 3rd paragraph, and the 4th paragraph. At this time, it cannot be sent, and the window can only be opened to a maximum of 500 bytes.

image-20230807222329335

5. At this time, the message segment of the window 201-300 bytes has been in a stalemate, waiting for the confirmation from the receiver. After the timeout for the message segment of 201-300 bytes has passed, it will perform a retransmission

image-20230807222637065

6. Host B can receive it successfully. At this time, host B sends a response message. The response message indicates that the message segment that host B wants to receive now starts from 501, and the sending window size can be limited to 100.

image-20230807222753345

image-20230807222815855

7. Host A starts sending a segment starting at 501 bytes. Since the window size is only 100 bytes, it cannot continue sending after sending this segment.

image-20230807222901572

8. At this time, the receiving host B returns a confirmation message segment, which indicates that it wants to start from 601 bytes and the sending window size is 0.

image-20230807222956168

Since the window is set to 0, the sender cannot send data at this time.

Additional question 1: If host A has been waiting for host B to send a non-zero window notification, and host B sends a new segment (the allowed window size is 400) and is lost during the transmission, if there is no measure at this time , then Host A and Host B will always wait for each other. This situation of waiting for each other is similar to a deadlock. So how to solve it?

Solution : TCP sets a continuous timer for each connection. As long as one party to the TCP connection receives the zero window notification from the other party, this continuous timer will be started . If the timer expires, host A will send a detection message segment , and host B will retransmit the notification message.

  • If the window of the retransmitted notification message is still 0, then host A will reset a continuous timer. At this time, if there is still no notification confirmation message before the timer expires, then host A will send another detection message. segment, let host B retransmit it again.

3.5. TCP congestion control

3.5.2. Understand congestion control and its difference with flow control

What is congestion control?

  • The network condition is not good, and the network is blocked, causing the entire speed of receiving and sending data to slow down.

Conditions for congestion : sum of resource demands > available resources

  • The resources refer to: some link capacity in the network, such as bandwidth, 50M bandwidth in a link, many people send data on this link, resulting in insufficient bandwidth on this link for these people, then at this time This will cause congestion in the network. At the same time, the cache in the switching node and the processor in the switching node , such as the processor in the router, are all resources .

If the total demand for a certain resource in the network exceeds the available part of this resource during a certain period of time, the performance of the network will naturally change. At this time , many resources will be in insufficient supply at the same time, resulting in the following situations:

  • There are many resources in the network that are under-provisioned at the same time -> network performance deteriorates -> network throughput will decrease as the input load increases.

Congestion control function : Prevent excessive data from being injected into the network.

  • By coordinating the coordination between all hosts using this network resource, excessive data can be prevented from being injected into the network, and network congestion can be alleviated.

The difference between congestion control and flow control :

拥塞控制: If the upper part of the figure below is the receiver, and the lower part of the figure is the sender, they both need to send data to the receiver. Since they use the resources on this network at the same time and the same switching node, then this router will make this network It is very busy, and there may even be a congestion situation. The receiver does not know which host or hosts are causing this congestion situation. The sending rate is too fast.

image-20230808104239081

流量控制: It is a kind of traffic control between point-to-point, and it is an end-to-end problem. If the data received by the receiver is too late to receive, then it will be until the sender should receive it.

image-20230808104621684

Summary : Flow control is a point-to-point problem. The sender's rate is too fast, which causes insufficient buffering on the receiver. Congestion control is a global problem , mainly because the network is blocked .


3.5.3. Four algorithms for congestion control

3.5.3.1. Understand the four algorithms of congestion control

Four algorithms : slow start, congestion avoidance, fast retransmission, and fast recovery.

The four above are used in combination with each other in one situation, one is 慢开始+拥塞避免, and the other combination is 快重传+快恢复:

image-20230808104809191

Before learning the above algorithm, make a few assumptions:

1. Data is transmitted in one direction, while only acknowledgment segments are transmitted in the other direction (not valid data is transmitted for a piggyback confirmation).

  • In practice, piggy-back confirmation is also relatively common.

2. The receiver always has enough buffer space, so the sending window size depends on the degree of congestion.

发送窗口 = Min(接受窗口rwnd,拥塞窗口cwnd)

  • Receive window: The receiver sets the value according to the acceptance cache and informs the other party to reflect the receiver capacity.
  • Congestion window: The window value set by the sender based on its own estimate of network congestion, reflecting the current capacity of the network.

3.5.3.2. Combination 1: Slow start and congestion avoidance

Understand the meaning of congestion window and transmission rounds

image-20230808105322792

  • In the postgraduate entrance examination, you must be clear about the application process of Algorithm Ade, and do not examine the specific details of the four algorithms.

The ordinate refers to 拥塞窗口cwndthe initial value of 1, which represents a message segment and a maximum message segment length MSS (at this time, 4 in the figure refers to 4 MSS, and 8 refers to 8 MSS). As the number of transmission rounds increases, the congestion window changes.

The abscissa refers to 传输轮次a transmission round as a unit, which refers to the time it takes to send a batch of message segments and receive their confirmation.

  • A transmission round: the time when a batch of message segments are sent and their acknowledgment is received, a round-trip delay RTT. The time from starting to send a batch of message segments within the congestion window to starting to send the next batch of message segments within the congestion window.

Understanding of transmission rounds :

As follows: Host A sends a message segment to Host B. At this time, Host B responds with a message segment to Host A. This is counted as one round.

image-20230808105721054

Since the network condition is very good, several more message segments m2 and m3 will be sent at this time. At this time, host B will return two confirmations in sequence after receiving the two message segments. In this case, until M3 confirms, so The section is the second transmission round.

image-20230808105845165

At this time, the sending window is increased again. At this time, the window is 4. Then 4 message segments can be sent continuously at this time. When the 4th message segment is received in sequence, it is regarded as the third transmission round:

image-20230808110008536


Detailed process of slow start and congestion avoidance

Slow start refers to an exponential growth, a process of explosive growth.

  • The main reason for the slowness is that only one message is injected at the beginning, which will be much slower for the initial injection of many message segments.

Process : First, conduct a probe on this network to see the congestion situation of this network. If it is better, then increase my congestion window sender and increase the congestion window. This multiple is 2 times and is divided into four stages.

①At the beginning, **【Slow Start】 is performed . The first transmission round is 1 MSS, the second transmission round is 2 MSS, the third transmission round is 4 MSS, and the fourth transmission The round is 16 MSS. At this time, you can see that the initial value of ssthresh 16 has been reached, which refers to a slow start threshold**.

image-20230808111632456

②At this time, it will start from slow to **[Congestion Avoidance]**, because there are currently more message segments injected, and you will be worried that congestion will occur soon, so you will slightly reduce the speed. drop. At this time, based on the previous congestion window, one congestion window will be added each time. You can see that it is +1 every time from 5 rounds to 12 rounds, and it reaches 24 MSS at this time.

  • Slow start threshold: Once the initial value of the slow start threshold is reached, the speed will be slightly reduced, and the slow start will be entered into congestion avoidance.
  • Congestion avoidance process: It is a linear growth process, +1 each time based on the slow start threshold.

image-20230808111653221

③ Since when 24MSS is reached, the network is congested and packet loss occurs. At this time, it will re-enter the **[Slow Start State]**, and the congestion window will return to 1, and the number of segments will increase from 24 to 24 in an instant. It is reduced to 1 message segment, and the subsequent process is to continue to execute slow start, 1, 2, 4, 8, and then in the 17th round, note that the threshold value at this time changes to 12.

  • **How ​​is the new threshold determined? **According to the current situation of network congestion, once network congestion occurs, the congestion window/2 will be immediately reduced. Since the congestion window of the previous network congestion was 24, then 24/2 = 12 at this time, then this The current threshold is 12.

image-20230808111712388

④When entering the **[Congestion Avoidance]** state, it will still increase linearly, +1 each time, and the subsequent process will be the same. Once network congestion occurs, a new threshold will be set and return to Start slow.

image-20230808111726052


3.5.3.3. Combination 2: Fast retransmission and fast recovery

The reason for the emergence of fast retransmission is mainly to solve the problem of too long waiting timeout. The mechanism process is as follows :

  • At this time, five message segments M1, 2, 3, 4, and 5 are sent continuously. When M1 is sent to B, a confirmation number will be returned, where ack=2, indicating that the second message is to be received. , message 2 is lost, and then B receives the confirmation message segments of M3, 4, and 5, in which ack=2, then there are a total of four confirmation message segments with ack=2. Based on the last three The same ack=2 will be called a redundant ack . At this time, host A will resend the M2 message .
  • image-20230808112332266

**How ​​is fast recovery reflected? **You can see in the figure below that when the congestion window is 24 at 12 times, because [fast retransmission] is executed after receiving 3 duplicate confirmations, it will then enter [fast recovery state]. At this time There is no need to reduce the congestion window to 1MSS. At this time, it will drop to a new threshold value. At this time, in this 12 threshold value stage, we perform [congestion avoidance] and perform linear addition to increase.

  • **How ​​is the threshold determined? **This is when duplicate confirmation will occur. Set the congestion window at this time to 24/2=12, and then we will perform quick recovery.

image-20230808112933841

**What is quick recovery? **There is no need to lower it to 1, but directly lower it to the new threshold value (congestion window where fast retransmission occurs/2), and then use the congestion avoidance algorithm.

The TCP-Tahoe version in the figure has been abandoned. This version should be when fast retransmission occurs. At this time, the congestion window directly changes to the initial phase 1 of slow start, and then the corresponding strategy is executed.


Organizer: Long Road Time: 2023.8.7-8

Guess you like

Origin blog.csdn.net/cl939974883/article/details/132163746