Port multiplexing method and device, electronic equipment, medium and computer program product
By adjusting the sequence number retention time and initial sequence number of the FIN data packet in the load balancing device, the problem of port multiplexing failure is solved, port multiplexing is successfully achieved, and the port multiplexing success rate is improved.
Patent Information
- Application Number
- CN202510731304.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2045-05-30
AI Technical Summary
In a load balancing device, during port reuse, the FIN sequence number of the previous communication session cannot be obtained, resulting in the initial sequence number of the next communication session being smaller than the FIN sequence number of the previous communication session, causing port reuse failure.
By obtaining the sequence number of the FIN data packet of the first communication session, determining the retention time based on the preset relationship, and adjusting the initial sequence number of the second communication session within the retention time to make it greater than the sequence number of the first communication session, successful port multiplexing is ensured.
By adjusting the retention time of the serial number and determining the initial serial number, the port reuse is ensured to be successful, the problem of port reuse failure is avoided, and the port reuse success rate is improved.
Smart Images

Figure CN120614336A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of communication technology, and in particular relates to a port multiplexing method, device, electronic device, medium and computer program product. Background Art
[0002] Current load balancing devices typically need to adjust the initial sequence number (ISN) in client device data packets after performing Source Network Address Translation (SNAT). During port reuse, if the ISN of the next communication session is lower than the FIN (Finish) sequence number of the previous communication session, port reuse will fail. Summary of the Invention
[0003] Embodiments of the present application provide a port multiplexing method, apparatus, electronic device, medium, and computer program product.
[0004] An embodiment of the present application provides a port multiplexing method, the method comprising:
[0005] Obtaining a first sequence number corresponding to a first communication session; the first sequence number is a sequence number of a FIN data packet corresponding to the first communication session;
[0006] Determining, based on a preset relationship, a second sequence number corresponding to a first moment, wherein the first moment is an initial moment of a retention duration to be determined for the first communication session;
[0007] Determining the retention duration based on a magnitude relationship between the first sequence number and the second sequence number, such that after the retention duration, a sequence number obtained by incrementing the second sequence number is greater than the first sequence number;
[0008] When the reuse time is within the reserved duration, an initial sequence number of the second communication session is determined based on the first sequence number; the reuse time indicates a time when the second communication session needs to perform port multiplexing with the first communication session.
[0009] In some embodiments, determining the retention duration based on the size relationship between the first sequence number and the second sequence number includes: when the first sequence number is greater than or equal to the second sequence number, obtaining a third sequence number obtained by incrementing the second sequence number at the end of the time wait (TIME WAIT) state based on the incremental characteristic of the second sequence number; and determining the retention duration based on the size relationship between the third sequence number and the first sequence number.
[0010] In some embodiments, determining the retention duration based on the size relationship between the third sequence number and the first sequence number includes: when the third sequence number is greater than the first sequence number, based on the incremental characteristics of the second sequence number, determining the first duration required for the second sequence number to increase to the first sequence number within the TIME WAIT state duration; and determining the retention duration based on the first duration.
[0011] It can be seen that the method for determining the retention time provided in this embodiment ensures that the first sequence number within the retention time can be obtained before the second sequence number is incremented to the size of the first sequence number. By obtaining the first sequence number, it can be ensured that the initial sequence number of the second communication session is definitely greater than the first sequence number, further ensuring successful port multiplexing.
[0012] In some embodiments, the method further includes: when the third sequence number is less than or equal to the first sequence number, using the TIME WAIT state duration as the retention duration.
[0013] As can be seen, when the third sequence number is less than the first sequence number, it indicates that neither the second sequence number nor the sequence number generated by incrementing the second sequence number can be used as the initial sequence number for the second communication session within the TIME WAIT state duration. By ensuring that the first sequence number can be obtained within the TIME WAIT state duration and determining the initial sequence number for the second communication session based on the first sequence number, port reuse failure can be avoided.
[0014] In some embodiments, the method further includes: when the first sequence number is smaller than the second sequence number, directly using the second sequence number, or a sequence number obtained by incrementing the second sequence number, as the initial sequence number corresponding to the second communication session.
[0015] In some embodiments, the method further comprises: determining an initial sequence number of the second communication session based on the incremented sequence number of the second sequence number when the reuse time is after the retention time.
[0016] It can be seen that since the sequence number obtained by incrementing the second sequence number after the retention period must be greater than the first sequence number, when the initial sequence number of the second communication session is determined after the retention period, the initial sequence number of the second communication session is determined based on the sequence number after the second sequence number is incremented, which can ensure that port multiplexing is successful.
[0017] In some embodiments, the first sequence number and the second sequence number are obtained based on a load balancing device; the load balancing device is used to receive data packets of a communication session, modify the sequence numbers in the data packets, and forward the data packets based on the modified sequence numbers.
[0018] The present application also provides a port multiplexing device, the device comprising:
[0019] An acquisition module, configured to acquire a first sequence number corresponding to a first communication session; the first sequence number being a sequence number of a FIN data packet corresponding to the first communication session;
[0020] a determination module, configured to determine, based on a preset relationship, a second sequence number corresponding to a first moment; the first moment being an initial moment of a retention duration to be determined for the first communication session; and determine the retention duration based on a magnitude relationship between the first sequence number and the second sequence number such that, after the retention duration, a sequence number obtained by incrementing the second sequence number is greater than the first sequence number;
[0021] A processing module is configured to determine an initial sequence number of a second communication session based on the first sequence number when a reuse time is within the reservation duration; the reuse time indicates a time when the second communication session needs to perform port reuse with the first communication session.
[0022] An embodiment of the present application provides an electronic device, comprising a processor and a memory for storing a computer program that can be run on the processor; wherein,
[0023] The processor is configured to run the computer program to execute any one of the above port multiplexing methods.
[0024] An embodiment of the present application provides a computer storage medium having a computer program stored thereon. When the computer program is executed by a processor, any of the above-mentioned port multiplexing methods is implemented.
[0025] An embodiment of the present application provides a computer program product, including a computer program, which implements any of the above-mentioned port multiplexing methods when executed by a processor.
[0026] Embodiments of the present application provide a port multiplexing method, apparatus, electronic device, medium, and computer program product. By modifying the retention duration of the sequence number of the FIN data packet corresponding to the first communication session, it is possible to ensure that the sequence number of the FIN data packet corresponding to the first communication session is obtained within the retention duration, ensure that the initial sequence number of the next communication session is greater than the FIN sequence number, and ensure successful port multiplexing. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 A flow chart of a port multiplexing method provided in an embodiment of the present application;
[0028] Figure 2 A flowchart of a serial number generation algorithm provided in an embodiment of the present application;
[0029] Figure 3 A schematic diagram of the structure of a port multiplexing device provided in an embodiment of the present application;
[0030] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] In the TCP protocol, the timestamp option is an optional feature used to improve the performance and reliability of network connections. When the timestamp option is not enabled, the condition for successful server port reuse requires that the initial sequence number of the SYN of the new communication session is greater than the FIN sequence number at the end of the previous communication session (FIN in the client direction). When a FIN packet is sent in the first communication session, the load balancing device records the sequence number of the FIN packet, such as S1. When the five-tuple connection of the second communication session arrives at the load balancing device, the initial SYN sequence number of the second communication session is adjusted to S1 plus a certain value, and then forwarded to the server to ensure that port reuse is successful when different client devices access the server.
[0032] The implementation of the above method depends on the size of the FIN sequence number in the FIN packet of the first communication session. When the connection tracking information of the first communication session is deregistered on the load balancing device, the FIN sequence number recorded in the first communication session cannot be obtained after deregistration. In this case, it is impossible to ensure that the second communication session can successfully achieve port reuse after reaching the server.
[0033] Specifically, when the first communication session is deregistered, based on the current call mechanism, there are two scenarios where the server port reuse conditions cannot be met, resulting in the second TCP connection's handshake with the server failing, causing the request to fail and an access anomaly. In one case, when the first communication session is a persistent connection, because the connection tracking information for the first communication session has been deregistered, when the second communication session reaches the load balancing device again based on the same five-tuple connection, the FIN sequence number of the first communication session is not available. When the initial sequence number of the second communication session is recalculated, there is no guarantee that the newly generated initial sequence number will be greater than the FIN sequence number of the first communication session, and the server cannot successfully reuse the port in the TIME WAIT state. In another case, when the network bandwidth is high and the amount of data transmitted is large (corresponding to the scenario of high-speed large file upload), the sequence number corresponding to the transmitted data in the first communication session increases at a rate greater than the rate of increase of the load balancing device's sequence number generation algorithm, resulting in the load balancing device's newly generated sequence number not being guaranteed to be greater than the FIN sequence number.
[0034] In response to the above-mentioned problems, the embodiments of the present application provide a port multiplexing method, apparatus, electronic device, medium, and computer program product, which can solve the problem of port multiplexing failure in the above-mentioned scenario.
[0035] The following is a further detailed description of the embodiments of the present application in conjunction with the accompanying drawings and examples. It should be understood that the embodiments provided herein are merely for explaining the embodiments of the present application and are not intended to limit the embodiments of the present application. In addition, the embodiments provided below are partial embodiments for implementing the present application, rather than providing all embodiments for implementing the present application. In the absence of conflict, the technical solutions described in the embodiments of the present application can be implemented in any combination.
[0036] It should be noted that, in the embodiments of the present application, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a method or apparatus comprising a series of elements includes not only the elements explicitly stated, but also other elements not explicitly listed, or also includes elements inherent to the implementation of the method or apparatus. In the absence of further restrictions, an element defined by the sentence "include..." does not exclude the presence of other related elements (such as steps in the method or units in the apparatus, for example, a unit in the apparatus may be a portion of a circuit, a portion of a processor, a portion of a program or software, etc.) in the method or apparatus comprising the element.
[0037] The port multiplexing method provided in the embodiment of the present application includes a series of steps, but the port multiplexing method provided in the embodiment of the present application is not limited to the recorded steps. Similarly, the port multiplexing device provided in the embodiment of the present application includes a series of modules, but the device provided in the embodiment of the present application is not limited to including the modules explicitly recorded, and may also include modules required to obtain relevant information or perform processing based on the information.
[0038] An embodiment of the present application provides a port multiplexing method that can be applied to a first device. The first device can specifically be a device used to forward data packets between a server and a client device in TCP transmission. The first device can process and modify the sequence number of each communication session to achieve orderly transmission of data packets in the communication session. Figure 1 A flow chart of a port multiplexing method is shown, as shown in FIG. Figure 1 As shown, Figure 1 The port multiplexing methods shown include:
[0039] Step 101: Obtain a first sequence number corresponding to a first communication session; the first sequence number is the sequence number of a FIN data packet corresponding to the first communication session.
[0040] The first communication session is a communication session established based on the TCP protocol. In a TCP communication session, FIN is a flag in the TCP protocol that is used to terminate a TCP connection. When one party in communication wants to end the communication session, it sends a TCP data packet with the FIN flag set to 1. The data packet includes a FIN sequence number, which is the first sequence number given in this step. After receiving the FIN data packet, the receiver will reply with an acknowledgment (ACK) to confirm that it has received the FIN data packet and all previous data. The sequence number of the FIN data packet and the receiver's ACK confirmation number together ensure the reliable closure of the connection. Only when the receiver confirms the FIN data packet will the sender actually close the current connection.
[0041] In this step, obtaining the first sequence number means that the first communication session is about to end. In the TCP protocol, when the party sending the FIN packet receives the other party's ACK, it will enter the TIME WAIT state to ensure that all sent data packets disappear in the network.
[0042] In an embodiment of the present application, a first device is set between the sender and the receiver of the communication session. The first device can be a load balancing device for achieving load balancing of data transmission. In actual applications, the first device first receives the data packet sent by the client device and modifies the serial number in the data packet. In order to enable the first device to uniformly manage the data packets sent by different client devices, a serial number generation algorithm can be preset in the first device, and based on the preset serial number generation algorithm, the original serial number in the received data packet can be changed, and the data packet with the changed serial number is forwarded to the server. After receiving the data packet, the server confirms the data packet with the changed serial number based on the first device. Specifically, a serial number can be calculated based on the value of the quintuple, such as the hash value of the quintuple, and time.
[0043] After receiving the confirmation data packet replied by the server, the first device modifies the serial number in the confirmation data packet to the serial number corresponding to the confirmation data packet of the client device, that is, modifies the serial number in the confirmation data packet again, and obtains a confirmation data packet replied to the client device.
[0044] When the first device modifies the serial number in the communication session, it will record and save the serial numbers before and after the modification and related information of the communication session. After the retention period, the saved information will be cancelled and the related information of the communication session and the corresponding serial number will be deleted.
[0045] Step 102: Based on a preset relationship, determine a second sequence number corresponding to a first moment; the first moment is an initial moment of a retention duration to be determined for the first communication session.
[0046] Before determining the retention duration of the first communication session, or at a moment when the retention duration needs to be determined, a second sequence number corresponding to the moment is determined.
[0047] According to the method described in step 101, the first device can obtain a sequence number generated by the algorithm based on the sequence number generation algorithm and the TCP protocol, namely the second sequence number. The second sequence number is calculated based on the quintuple and time. Therefore, as time changes, the sequence number generation algorithm ensures that the second sequence number continues to increase over time. As can be seen, because the second random number is randomly generated, there is no guarantee that the second sequence number, or the sequence number after the second sequence number is incremented, will be greater than the first sequence number.
[0048] In some of the specific scenarios described above, using the second sequence number as the initial sequence number for the second communication session, and if the second sequence number is smaller than the first sequence number, may cause port reuse to fail. However, if the first sequence number is retained in the first device, the second sequence number, or a sequence number incremented from the second sequence number, can be compared with the first sequence number based on a sequence number generation algorithm to ensure that the initial sequence number for the second communication session is greater than the sequence number of the FIN packet.
[0049] Step 103: Based on the size relationship between the first sequence number and the second sequence number, determine the retention time, so that after the retention time, the sequence number obtained by incrementing the second sequence number is greater than the first sequence number.
[0050] Based on the above method, if the first sequence number is greater than or equal to the second sequence number, and the second sequence number is directly used as the initial sequence number corresponding to the second communication session for data packet transmission, if the first communication session and the second communication session have the same quintuple, port multiplexing may fail. Therefore, if the first sequence number is greater than or equal to the second sequence number, the growth of the second sequence number can be calculated using a sequence number generation algorithm, and the growth time required for the second sequence number to increase to the first sequence number can be determined, so that the retention time of the first sequence number is greater than the growth time. This ensures that when the second sequence number, and the sequence number after the second sequence number increases, is less than the first sequence number, by comparing the retained first sequence number, the initial sequence number of the second communication session is greater than the first sequence number. When the second sequence number increases to be greater than the first sequence number, port multiplexing is successful. At this time, the first sequence number or related information of the first communication session can be promptly deregistered, and the resources occupied by the first communication session can be promptly released.
[0051] Specifically, in this step, the retention period can be determined based on the size relationship between the first sequence number and the second sequence number. For example, when the second sequence number is greater than the first sequence number, it is considered that when the initial sequence number of the second communication session is determined based on the second sequence number, the port multiplexing can be successfully guaranteed. In this case, the information of the first communication session can be cancelled according to the preset retention period, or the retention period can be set to the shortest period that meets the TCP transmission conditions.
[0052] When the second serial number is less than or equal to the first serial number, the preset retention time can be extended on the basis of the preset retention time to determine the final retention time, so that after the retention time, that is, after the information of the first communication session is cancelled, the port reuse can be guaranteed to be successful.
[0053] Step 104: When the reuse time is within the reserved duration, determine the initial sequence number of the second communication session based on the first sequence number; the reuse time indicates the time when the second communication session needs to perform port multiplexing with the first communication session.
[0054] When the second communication session reaches the first device and needs to be port-reused with the first communication session, this moment is obtained as the reusing moment. If the reusing moment falls within the reserved duration, then, if the second sequence number or a sequence number incremented by the second sequence number is used as the initial sequence number for the second communication session, the initial sequence number of the second communication session will be smaller than the first sequence number, causing port reusing to fail. In this case, the method described in this step determines the initial sequence number of the second communication session based on the first sequence number. For example, a random number is added to the first sequence number according to a preset algorithm to serve as the initial sequence number of the second communication session. This ensures that the initial sequence number of the second communication session is greater than the first sequence number, thus ensuring successful port reusing.
[0055] When the second communication session reaches the first device, the retention period has expired and the first device has deregistered the information of the first communication session, that is, when the reuse moment is after the retention period, the initial sequence number of the second communication session is determined based on the sequence number after the second sequence number is incremented.
[0056] If the reuse time is after the retention period, the sequence number after the second sequence number is incremented must be greater than the first sequence number. In this case, the initial sequence number of the second communication session can be determined based on the sequence number after the second sequence number is incremented. For example, the sequence number after the second sequence number is incremented can be used as the initial sequence number of the second communication session, or the sequence number obtained by adding a random number to the second sequence number can be used as the initial sequence number of the second communication session to ensure successful port reuse.
[0057] As can be seen, in the embodiment of the present application, the first communication session is the communication session preceding the second communication session. By adjusting the cancellation time of the sequence number of the FIN packet, that is, adjusting the retention period, it is possible to ensure that the first sequence number can be saved as comparison information when it is uncertain whether port reuse will succeed. By ensuring that the initial sequence number of the second communication session is greater than the first sequence number, port reuse success is guaranteed.
[0058] In practical applications, steps 101 to 104 can be implemented based on a processor, and the processor can be at least one of an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a CPU, a controller, a microcontroller, and a microprocessor.
[0059] In some embodiments, the above-mentioned determination of the retention period based on the size relationship between the first sequence number and the second sequence number includes: when the first sequence number is greater than or equal to the second sequence number, based on the incremental characteristic of the second sequence number, obtaining a third sequence number that is incremented at the end of the TIME WAIT state period of the second sequence number; and determining the retention period based on the size relationship between the third sequence number and the first sequence number.
[0060] Since the session resources of the first communication session are released after the TIME WAIT state ends, the transmission of data packets in the second communication session will not be affected after the TIME WAIT state ends. This embodiment uses the TIME WAIT state duration as a benchmark and a sequence number generation algorithm to pre-calculate a third sequence number that is incremented by the second sequence number at the end of the TIME WAIT state.
[0061] For example, assuming the second sequence number is G0, the TIME WAIT state duration is 120 seconds, and the second sequence number increases at a rate of N per second, the third sequence number can be calculated to be G0 + 120N.
[0062] As can be seen, when the third sequence number is less than or equal to the first sequence number, it is assumed that before the TIME WAIT state ends, a sequence number greater than the first sequence number cannot be obtained based on the increment rate of the second sequence number. Since port multiplexing will not be affected after the TIME WAIT state ends, the sequence number obtained by incrementing the second sequence number can be directly used as the initial sequence number corresponding to the second communication session.
[0063] If the third sequence number is greater than the first sequence number, it is assumed that a sequence number greater than the first sequence number can be obtained within the TIME WAIT state duration based on the increment rate of the second sequence number. In this case, the first sequence number can be deregistered based on the time when the second sequence number increases to the first sequence number, thereby determining the retention duration of the first communication session.
[0064] In some embodiments, the above-mentioned determination of the retention period based on the size relationship between the third sequence number and the first sequence number includes: when the third sequence number is greater than the first sequence number, based on the increasing characteristics of the second sequence number, determining the first time period required for the second sequence number to increase to the first sequence number within the TIME WAIT state period; and determining the retention period based on the first time period.
[0065] Based on the method provided in the above embodiment, if the third sequence number is greater than the first sequence number, it indicates that before the TIME WAIT state ends, the second sequence number can be incremented to obtain an initial sequence number that satisfies successful port reuse. In this case, the first sequence number can be deregistered before the TIME WAIT state ends.
[0066] For example, assuming the first sequence number is Gf, and based on the second sequence number's growth rate N per second, the first duration required for the second sequence number to increase to Gf is calculated as (Gf - G0) / N (in seconds). By determining the first duration as the logout duration of the first communication session, that is, the retention duration, the logout time of the first communication session can be obtained by adding the first time to the first duration.
[0067] After the first duration and before the TIME WAIT state ends, the sequence number obtained by incrementing the second sequence number will be greater than the first sequence number. Therefore, even if the first sequence number is deregistered after the first duration, the sequence number obtained by incrementing the second sequence number will be greater than the first sequence number. After the first duration and before the TIME WAIT state ends, when the first data packet of the second communication session arrives at the first device, the first device can determine the initial sequence number corresponding to the second communication session based on the sequence number obtained by incrementing the second sequence number. During the first duration, when the first data packet of the second communication session arrives at the first device, the initial sequence number of the second communication session can be determined based on the first sequence number using the method described in the above embodiment.
[0068] It can be seen that by setting the retention time before the TIME WAIT state ends, it can be ensured that the initial sequence number of the second communication session is greater than the sequence number of the FIN data packet, and port multiplexing is successfully achieved.
[0069] In some embodiments, the above method further includes: when the third sequence number is less than or equal to the first sequence number, using the TIME WAIT state duration as the retention duration.
[0070] Based on the method provided in the above embodiment, before the TIME WAIT state ends, the second sequence number obtained by incrementing based on the sequence number generation algorithm cannot be greater than the first sequence number. In this case, port multiplexing cannot be successfully achieved. Therefore, the retention duration can be set equal to the TIME WAIT state duration. When the data packet of the second communication session reaches the first device within the TIME WAIT state duration, the first device determines the initial sequence number of the second communication session based on the first sequence number.
[0071] After the TIME WAIT state duration, that is, when port multiplexing is not affected, the first device uses the sequence number obtained by incrementing the second sequence number as the initial sequence number of the second communication session to forward the data packet.
[0072] In some embodiments, the above method further includes: when the first sequence number is smaller than the second sequence number, directly using the second sequence number, or a sequence number obtained by incrementing the second sequence number, as the initial sequence number corresponding to the second communication session.
[0073] Based on the method described in the above embodiment, if the obtained second sequence number is already greater than the sequence number of the FIN packet, the second sequence number can be directly used as the initial sequence number for the second communication session, without affecting port reuse. In this case, the sequence number obtained by incrementing the second sequence number based on the time when the packet in the second communication session arrives at the first device can be directly used as the initial sequence number for the second communication session. When the time when the packet in the second communication session arrives at the first device is equal to the time when the second sequence number is generated, the second sequence number can be directly used as the initial sequence number for the second communication session.
[0074] In some embodiments, the first sequence number and the second sequence number are obtained based on a load balancing device; the load balancing device is used to receive data packets of a communication session, modify the sequence numbers in the data packets, and forward the data packets based on the modified sequence numbers.
[0075] In the embodiments of the present application, the first device for implementing the port multiplexing method can also be a load balancing device in TCP transmission. In TCP transmission, the load balancing device is located between the client device and the server, responsible for receiving TCP connection requests from the client device and distributing the requests to multiple backend servers according to a preset load balancing algorithm and strategy, effectively alleviating the pressure on a single server and improving the overall processing capacity of the system.
[0076] A second sequence number can be generated based on a preset sequence number generation algorithm, and the load balancing device can modify the original sequence number in the received first data packet based on the second sequence number to obtain a second data packet, which is then sent to the server. The load balancing device also receives a first response data packet from the server to the second data packet, and modifies the sequence number in the first response data packet based on the sequence number of the first data packet to obtain a second response data packet applicable to the first data packet, which is then sent to the client device.
[0077] In this embodiment of the present application, when the load balancing device receives a FIN packet sent by a client device, it first adjusts the sequence number of the FIN packet to the sequence number relative to the load balancing device, ensuring that the sequence numbers corresponding to all clients are consistent when they reach the server. The load balancing device records the adjusted sequence number of the FIN packet (i.e., the first sequence number in the FIN packet sent to the server) in the relevant information for connection tracking.
[0078] When receiving FIN packets from both the client and server, the load balancing device sets a retention duration, t, based on the method described in the above embodiment. After t seconds, the corresponding communication session information is deleted. When setting the retention duration, the initial sequence number of the next communication session, i.e., the second communication session, is recalculated to obtain the second sequence number. This is followed by a sequence number incremented from the second sequence number after the TIME WAIT state duration. The load balancing device's sequence number generation algorithm ensures that the generated sequence numbers increase monotonically over time.
[0079] It can be seen that by using the port multiplexing method provided by the load balancing device based on the above embodiment to modify the sequence number in the data packet of the communication session, it is beneficial to uniformly manage the data packets sent by different client devices on the load balancing device side.
[0080] Based on the port multiplexing method given in the above embodiment, Figure 2 A flowchart of a sequence number generation algorithm is shown, including:
[0081] Step 201: Start.
[0082] Step 202: Record the first communication session FIN sequence number Gf.
[0083] The sequence number of the FIN data packet of the first communication session is recorded as Gf.
[0084] Step 203: Calculate the current second sequence number G0.
[0085] Generate G0 based on the sequence number generation algorithm. G0 may be less than or equal to Gf, or greater than Gf.
[0086] Step 204: Calculate the sequence number Gs after s seconds.
[0087] Here, s seconds represents the duration of the TIME WAIT state. G0 is calculated incrementally according to the time change to obtain the sequence number when the TIME WAIT state ends, that is, the third sequence number in the above embodiment.
[0088] Step 205: Determine whether Gf is smaller than G0.
[0089] If Gf<G0, execute step 206; otherwise, execute step 207.
[0090] Step 206: Maintain the preset retention time.
[0091] Within s seconds, Gf < G0 is always satisfied. That is, at any time within s seconds, when a new communication session reaches the load balancing device again, the sequence number recalculated by the load balancing device is greater than Gf, and the server can be successfully reused. In this case, it is only necessary to maintain the original preset retention time of the load balancing device. There is no need to extend the retention time of Gf or extend the cancellation time of the first communication session.
[0092] Step 207: Determine whether Gf is smaller than Gs.
[0093] If Gf<Gs, execute step 208; otherwise, execute step 209.
[0094] Step 208: The retention duration is determined to be (Gf-G0) / N seconds.
[0095] If G0 ≤ Gf < Gs, and the sequence number G0 increases by N per second, then within (Gf - G0) / N seconds, Gf will be greater than the newly generated sequence number by the load balancing device. If the session is deregistered, then when a second communication session with the same quintuple as the first communication session arrives at the load balancing device and the corresponding data packet is forwarded to the server, port reuse will fail. In this case, the retention duration must be set to (Gf - G0) / N seconds to ensure that the information corresponding to the first communication session is not deregistered within (Gf - G0) / N seconds.
[0096] Step 209: The retention duration is set to s seconds.
[0097] If Gf ≥ Gs, since Gf is greater than the newly generated sequence number by the load balancing device within s seconds, if the information corresponding to the first communication session is cancelled within s seconds, the second communication session with the same quintuple as the first communication session will reach the load balancing device and forward the corresponding data packet to the server, port reuse will not succeed. In this case, the retention duration should be set to s seconds to ensure that the information corresponding to the first communication session is not cancelled within s seconds.
[0098] Step 210: Cancel the first serial number information.
[0099] After the above retention time or the preset retention time expires, the first sequence number and other information corresponding to the first communication session are no longer retained in the load balancing device.
[0100] Step 211: End.
[0101] According to the port multiplexing method provided in an embodiment of the present application, when setting the logout time of a first communication session, the sequence number of the new communication session (the second communication session) generated by the load balancing device at the current moment is compared with the sequence number of the FIN packet of the first communication session. Based on the size relationship, a decision is made as to whether to change the preset retention time in the load balancing device. If the sequence number newly generated by the load balancing device is smaller than the sequence number of the FIN packet corresponding to the first communication session, the preset retention time is changed. Within the changed retention time, if the second communication session reaches the load balancing device again, since the sequence number of the FIN packet in the first communication session can be obtained at this time, when the sequence number of the second communication session is regenerated based on the sequence number of the FIN packet, it can be ensured to be larger than the sequence number of the FIN packet of the previous communication session (the first communication session) to ensure that the port multiplexing condition is met.
[0102] The embodiment of the present application adaptively adjusts the deregistration time of the relevant information of the previous communication session, ensuring that the handshake with the server can be completed normally in the port reuse scenario after the traffic of different client devices passes through the first device, and the port reuse success rate is increased to 100%. This effectively avoids the situation where port reuse failures caused by the size of the generated sequence number are caused, and avoids the access anomalies caused by this.
[0103] Those skilled in the art will understand that, in the above-mentioned specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0104] Based on the port multiplexing method proposed in the above embodiment, the embodiment of the present application also proposes a port multiplexing device, such as Figure 3 As shown, Figure 3 A schematic structural diagram of a port multiplexing device is shown, the device comprising:
[0105] The acquisition module 301 is configured to acquire a first sequence number corresponding to a first communication session; the first sequence number is a sequence number of a FIN data packet corresponding to the first communication session.
[0106] Determination module 302 is used to determine the second sequence number corresponding to the first moment based on a preset relationship; the first moment is the initial moment of the retention duration to be determined for the first communication session; based on the size relationship between the first sequence number and the second sequence number, determine the retention duration so that after the retention duration, the sequence number obtained by incrementing the second sequence number is greater than the first sequence number.
[0107] The processing module 303 is configured to determine an initial sequence number of the second communication session based on the first sequence number when the reuse time is within the reserved duration; the reuse time indicates a time when the second communication session needs to perform port reuse with the first communication session.
[0108] In practical applications, the acquisition module 301 , the determination module 302 , and the processing module 303 may be implemented based on a processor and a communication device.
[0109] In some embodiments, the determination module 302 is specifically used to obtain, when the first sequence number is greater than or equal to the second sequence number, a third sequence number obtained by incrementing the second sequence number at the end of the TIME WAIT state duration based on the incremental characteristic of the second sequence number; and determine the retention duration based on the size relationship between the third sequence number and the first sequence number.
[0110] In some embodiments, the determination module 302 is specifically used to determine, when the third sequence number is greater than the first sequence number, based on the increasing characteristics of the second sequence number, within the TIME WAIT state duration, a first duration required for the second sequence number to increase to the first sequence number; and determine the retention duration based on the first duration.
[0111] In some embodiments, the determination module 302 is further configured to use the TIME WAIT state duration as the retention duration when the third sequence number is less than or equal to the first sequence number.
[0112] In some embodiments, the processing module 303 is further configured to, when the first sequence number is smaller than the second sequence number, directly use the second sequence number, or a sequence number obtained by incrementing the second sequence number, as the initial sequence number corresponding to the second communication session.
[0113] In some embodiments, the processing module 303 is further configured to determine an initial sequence number of the second communication session based on the sequence number after the second sequence number is incremented when the reuse time is after the retention time.
[0114] It should be noted that the description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the same method embodiment. For technical details not disclosed in the device embodiment of this application, please refer to the description of the method embodiment of this application for understanding.
[0115] It should be noted that, in the embodiment of the present application, if the above method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a terminal, server, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0116] An embodiment of the present application also provides an electronic device. Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the electronic device 40 may include:
[0117] The memory 401 is used to store executable instructions.
[0118] The processor 402 is configured to implement any one of the above port multiplexing methods when executing the executable instructions stored in the memory 401.
[0119] The processor 402 may be at least one of an ASIC, a DSP, a DSPD, a PLD, an FPGA, a CPU, a controller, a microcontroller, and a microprocessor.
[0120] The computer-readable storage medium or memory 402 may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); or various terminals including one or any combination of the above memories, such as a mobile phone, a computer, a tablet device, a personal digital assistant, etc. The electronic device 40 provided in the embodiment of the present application may further include a communication interface for receiving and forwarding data packets sent by a client device or a server.
[0121] Accordingly, an embodiment of the present application further provides a computer storage medium, on which computer executable instructions are stored. The computer executable instructions are used to implement any one of the port multiplexing methods provided in the above embodiments.
[0122] Correspondingly, an embodiment of the present application further provides a computer program product, which includes computer-executable instructions, and the computer-executable instructions are used to implement any one of the port multiplexing methods provided in the above embodiments.
[0123] In some embodiments, the functions or modules included in the device provided in the embodiments of the present application can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.
[0124] The above description of the various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced with each other and will not be repeated herein for the sake of brevity.
[0125] The methods disclosed in the various method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0126] The features disclosed in the various product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0127] The features disclosed in the various method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0128] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0129] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are protected by this application.
Claims
1. A port multiplexing method, characterized in that: The method comprises: Obtaining a first sequence number corresponding to a first communication session; the first sequence number is a sequence number of a FIN data packet corresponding to the first communication session; Determining, based on a preset relationship, a second sequence number corresponding to a first moment, wherein the first moment is an initial moment of a retention duration to be determined for the first communication session; Determining the retention duration based on a magnitude relationship between the first sequence number and the second sequence number, such that after the retention duration, a sequence number obtained by incrementing the second sequence number is greater than the first sequence number; When the reuse time is within the reserved duration, an initial sequence number of the second communication session is determined based on the first sequence number; the reuse time indicates a time when the second communication session needs to perform port multiplexing with the first communication session.
2. The method according to claim 1, characterized in that The determining the retention duration based on the magnitude relationship between the first sequence number and the second sequence number includes: If the first sequence number is greater than or equal to the second sequence number, based on the incrementing characteristic of the second sequence number, obtain a third sequence number obtained by incrementing the second sequence number at the end of the TIME WAIT state. The retention duration is determined based on a magnitude relationship between the third sequence number and the first sequence number.
3. The method according to claim 2, characterized in that The determining the retention duration based on the magnitude relationship between the third sequence number and the first sequence number includes: If the third sequence number is greater than the first sequence number, based on the incrementing characteristic of the second sequence number, determining a first duration required for the second sequence number to increment to the first sequence number within the TIME WAIT state duration; The retention duration is determined based on the first duration.
4. The method according to claim 2, characterized in that The method further comprises: When the third sequence number is less than or equal to the first sequence number, the TIME WAIT state duration is used as the retention duration.
5. The method according to claim 1, wherein The method further comprises: In the case that the first sequence number is smaller than the second sequence number, the second sequence number, or a sequence number obtained by incrementing the second sequence number, is directly used as the initial sequence number corresponding to the second communication session.
6. The method according to claim 1, characterized in that The method further comprises: In a case where the multiplexing time is after the reservation duration, an initial sequence number of the second communication session is determined based on the sequence number after the second sequence number is incremented.
7. The method according to claim 1, characterized in that The first sequence number and the second sequence number are obtained based on a load balancing device; the load balancing device is used to receive data packets of a communication session, modify the sequence numbers in the data packets, and forward the data packets based on the modified sequence numbers.
8. A port multiplexing device, characterized in that: The device comprises: An acquisition module, configured to acquire a first sequence number corresponding to a first communication session; the first sequence number being a sequence number of a FIN data packet corresponding to the first communication session; a determination module, configured to determine, based on a preset relationship, a second sequence number corresponding to a first moment; the first moment being an initial moment of a retention duration to be determined for the first communication session; and determine the retention duration based on a magnitude relationship between the first sequence number and the second sequence number such that, after the retention duration, a sequence number obtained by incrementing the second sequence number is greater than the first sequence number; A processing module is configured to determine an initial sequence number of a second communication session based on the first sequence number when a reuse time is within the reservation duration; the reuse time indicates a time when the second communication session needs to perform port reuse with the first communication session.
9. An electronic device, characterized in that: The electronic device comprises a processor and a memory for storing a computer program that can be run on the processor; wherein, The processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.
10. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product comprising a computer program, characterized in that The computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Patent Citations
Method for determining antenna port mapping and terminal
CN111835488A
Traffic arrangement method and device, electronic equipment and storage medium
CN119945748A
Method of maintaining packet order in multipath transmission systems having non-uniform traffic splitting
US6788686B1
