Source address conversion method, device, equipment and storage medium
By using data buckets and cache space in source address translation and using bitmap to associate source ports, the problem of low source port allocation efficiency in the existing technology is solved, and more efficient source port allocation is achieved.
Patent Information
- Application Number
- CN202211475082.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2042-11-23
AI Technical Summary
In the prior art, the method of randomly allocating source ports when the number of connections increases, resulting in low efficiency of source port allocation and requires repeated multiple times to complete the allocation.
Through the combination of data buckets and cache space, the bitmap in the bitmap entry is used to associate the source port to be allocated, identify the status information of the bitmap to determine the available source ports, and replace the source port in the data packet to generate the converted packets.
Improve the efficiency of source port allocation, and reduce latency and resource consumption during the allocation process through parallel processing and fast data reading and writing of cache space.
Smart Images

Figure CN115865863B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet communication technology, and in particular to a source address translation method, device, equipment and storage medium. Background Art
[0002] In the Source Network Address Translation (SNAT) scenario, multiple private IP addresses can exist under one public IP address. When multiple connections in a private network access the same public network resource, the data packets transmitted by these connections can share the same public IP address. In order to ensure that the five-tuple information of different connections in the same network is different, different source ports need to be assigned to the data packets of different connections.
[0003] At present, the SNAT device can first randomly assign a source port to the data packet, and then generate the five-tuple information after address conversion according to the randomly assigned source port. If the five-tuple information has been occupied by an existing connection, it is necessary to reassign the source port for the data packet until the five-tuple information after address conversion is not occupied by other connections.
[0004] It can be seen that as the number of connections increases, the method of randomly allocating source ports in the related art needs to be repeated multiple times to complete the allocation of source ports, which will have a low source port allocation efficiency. Summary of the invention
[0005] In view of this, one or more embodiments of the present disclosure provide a source address translation method, apparatus, device, and storage medium to improve the efficiency of source port allocation.
[0006] On the one hand, the present disclosure provides a source address conversion method, which includes: receiving a data packet to be source-addressed, and determining a data bucket corresponding to the data packet, wherein the data bucket stores a plurality of bitmap entries, and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate a source port to be allocated, and the cache space is used to load at least one bitmap entry of the plurality of bitmap entries; for a target bitmap entry currently loaded in a target cache space in the at least one cache space, identifying status information of each bitmap in the target bitmap entry, and determining a currently available target source port based on the status information; and replacing the source port carried in the data packet with the target source port to generate a data packet after source address conversion.
[0007] On the other hand, the present disclosure also provides a source address conversion device, which includes: a data bucket determination unit, which is used to receive a data packet to be converted to a source address, and determine a data bucket corresponding to the data packet, wherein the data bucket stores multiple bitmap entries, and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate a source port to be allocated, and the cache space is used to load at least one bitmap entry of the multiple bitmap entries; a source port determination unit, which is used to identify the status information of each bitmap in the target bitmap entry currently loaded in the target cache space in the at least one cache space, and determine the currently available target source port based on the status information; a replacement unit, which is used to replace the source port carried in the data packet with the target source port to generate a data packet after source address conversion.
[0008] On the other hand, the present disclosure further provides an electronic device, which includes a memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the above-mentioned source address conversion method is implemented.
[0009] On the other hand, the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the above-mentioned source address conversion method is implemented.
[0010] The technical solution provided by one or more embodiments of the present disclosure uses data buckets to allocate source ports for data packets. In the data buckets, the source ports to be allocated can be associated with the bitmap in the bitmap entry. In order to improve the allocation efficiency of the source ports, the data buckets can be associated with one or more cache spaces, and the cache space can be used to load at least one bitmap entry in the data bucket.
[0011] When allocating source ports, the state information of each bitmap can be identified from the target bitmap entries loaded in the cache space, thereby determining the currently available target source port. The source port carried in the data packet is replaced with the target source port, thereby generating a data packet with source address translation.
[0012] It can be seen that the technical solution provided by one or more embodiments of the present disclosure can disperse a large number of data packets into different data buckets for source port allocation, and when performing source port allocation, the currently available source port can be directly determined through the status information of the bitmap loaded in the cache space, thereby improving the efficiency of source port allocation. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The features and advantages of the embodiments of the present disclosure may be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present disclosure in any way. In the accompanying drawings:
[0014] Figure 1 A schematic diagram of the method steps for source address conversion in one embodiment of the present disclosure is shown;
[0015] Figure 2 A schematic diagram of the data structure in a data bucket in one embodiment of the present disclosure is shown;
[0016] Figure 3 A schematic diagram of source address translation in an application scenario is shown;
[0017] Figure 4 A schematic diagram of the process of source port allocation in one embodiment of the present disclosure is shown;
[0018] Figure 5 A schematic diagram of functional modules of a source address translation device in one embodiment of the present disclosure is shown;
[0019] Figure 6 A schematic structural diagram of an electronic device in one embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0021] The source address conversion method provided in one or more embodiments of the present disclosure can be applied to a source port conversion device. The source port conversion device can be a functional module integrated in a gateway. When the gateway receives a data packet sent from a private network, the source address conversion device can be used to convert the source address of the data packet, and the data packet after the source address conversion can be sent to the destination address. Of course, depending on the application scenario, the source port conversion device can also be an electronic device independent of the gateway, and can be connected to the gateway for communication, and the present disclosure does not limit this.
[0022] See also Figure 1 , a source address conversion method provided by an embodiment of the present disclosure may include the following multiple steps.
[0023] S1: Receive a data packet to be converted into a source address, and determine a data bucket corresponding to the data packet, wherein the data bucket stores a plurality of bitmap entries, and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate a source port to be allocated, and the cache space is used to load at least one bitmap entry among the plurality of bitmap entries.
[0024] In this embodiment, the data packet to be source-addressed may be a data packet sent out from a private network. In the five-tuple information in the data packet, the source IP address and the source port may be the intranet IP address and the intranet port in the private network. In order to ensure that the data packet can be transmitted normally in the public network, the source IP address and the source port need to be replaced. Generally speaking, a private network often corresponds to one or more public IP addresses. When receiving a data packet sent from a private network, the source address translation device may first replace the source IP address therein with the public IP address corresponding to the private network. In this way, for some data packets, the source IP address may be replaced with the same public IP address. In order to ensure that data packets of different connections correspond to different five-tuple information, different source ports need to be assigned to these data packets.
[0025] In this embodiment, the source address translation device can determine the data bucket corresponding to the data packet based on part of the information in the five-tuple information of the data packet. Figure 2 In the source address translation device, multiple data buckets can be set, and each data bucket can be used to allocate source ports for data packets. The purpose of setting multiple data buckets is to disperse a large number of data packets into different data buckets for source port allocation. On the one hand, the efficiency of source port allocation can be improved through parallel processing, and on the other hand, the load pressure of the data bucket can be relieved.
[0026] In this embodiment, the protocol information, the destination IP address and the destination port in the five-tuple information of the data packet can be obtained, and the obtained information can be arranged into a string according to a preset rule. Then, by calculating the hash value of the string and performing a modulo operation on the hash value according to the number of data buckets, the data bucket corresponding to the data packet can be determined.
[0027] In this embodiment, a plurality of bitmap entries may be stored in a data bucket, and each bitmap entry may include a specified number of bitmaps. For example, each bitmap entry may include a 64-bit bitmap. Each bitmap may be associated with a source port to be allocated, and whether the source port can be allocated may be represented by the status information of the bitmap. In practical applications, the status information of the bitmap may be the value of the bitmap. A value of 0 may represent a state in which the associated source port can be allocated, and a value of 1 may represent a state in which the associated source port cannot be allocated. In this way, in a practical application scenario, each bitmap entry may be regarded as a 64-bit numerical sequence consisting of 0 and / or 1. For example, in Figure 2 In the example, bucket-1 contains N bitmap entries, and each bitmap entry can contain a 64-bit bitmap. In this way, 64*N source ports can be associated in bucket-1.
[0028] In one embodiment, in order to facilitate the management of numerous bitmap entries, a data linked list (freelist) may also be included in the data bucket, and the data linked list may be used to record the entry information of the bitmap entry currently associated with an available source port. In practical applications, the entry information of the bitmap entry may be represented by the starting position of the bitmap entry. The data linked list may include several data pointers, which may point to the starting position of the bitmap entry. For example, if the starting position of bitmap64-1 is 10, then the starting position of bitmap64-2 may be 74. If both bitmap entries are associated with available source ports, then the data pointers in the data linked list may point to the starting positions of 10 and 74, respectively. It can be seen that since the number of bitmaps contained in the bitmap entry is fixed, any bitmap in the bitmap entry can be quickly located according to the starting position recorded in the data linked list. For example, the storage position of the 5th bitmap in bitmap64-1 is 10+4=14. In this way, the bitmap entries can be managed conveniently by means of a data linked list, thereby quickly locating the bitmap in the bitmap entry.
[0029] It should be noted that, in the data linked list, usually only the entry information of the bitmap entries associated with available source ports is recorded. If the source ports associated with each bitmap in a bitmap entry are all unavailable, the entry information of the bitmap entry is usually not recorded in the data linked list.
[0030] In this embodiment, in order to improve the efficiency of source port allocation, the data bucket can also be associated with one or more cache spaces. Figure 2In , bucket-1 can be associated with T cache spaces. In the cache space, at least one bitmap entry can be loaded from multiple bitmap entries of the data bucket. For example, in Figure 2 In the example, three bitmap entries can be loaded into each cache space. Generally speaking, the bitmap entries loaded into different cache spaces are different from each other. When assigning source ports to data packets later, they can be assigned directly from the bitmap entries loaded into one of the cache spaces. Since the data read and write speed in the cache space is fast, the efficiency of source port assignment can be improved.
[0031] In one embodiment of the present invention, the purpose of associating multiple cache spaces with a data bucket is to enable source port allocation to be performed in parallel by multiple threads. In practical applications, the number of threads running in parallel can be consistent with the number of cache spaces associated with the data bucket. For example, in Figure 2 In the scenario shown, the number of threads running in parallel in the source address translation device may also be T. In this way, different threads can perform source port allocation from different cache spaces, thereby further improving the efficiency of source port allocation.
[0032] In one embodiment, the cache space may be idle when initialized, and the bitmap entries in the data buckets may be loaded into the cache space later according to the entry information recorded in the data linked list. Specifically, the bitmap entries required for the cache space may be screened out according to the entry information recorded in the data linked list. For example, Figure 2 The cache space cache-1 needs to be filled with 3 bitmap entries, so three entry information can be selected from the data linked list, and the bitmap entries corresponding to these three entry information can be used as the filtered bitmap entries. Subsequently, the filtered bitmap entries can be loaded into the cache space. When loading the bitmap entries from the data bucket into the cache space, the status information of each bitmap in the bitmap entry can be directly copied. After the filtered bitmap entries are loaded into the cache space, in order to avoid repeatedly loading these bitmap entries into other cache spaces, the status information of each bitmap in the filtered bitmap entries can be modified in the data bucket to the status information representing that the source port is unavailable. For example, in the data bucket, the value of each bitmap in the filtered bitmap entry can be set to 1, indicating that the associated source port is unavailable. It should be noted that at this time, only the status of the bitmap in the data bucket is changed, and this change does not affect the status information of the bitmap in the bitmap entry loaded in the cache space. That is to say, for the filtered bitmap entries, the values assigned to each bitmap in the data bucket may all be 1, but in the cache space, the value assigned to each bitmap needs to be determined based on whether the associated source port is available.
[0033] In this embodiment, the purpose of changing the state information of the bitmap in the bitmap entry selected from the data bucket is that, according to the recording rule of the entry information in the data linked list, the state information of each bitmap in the selected bitmap entry indicates that the source port is unavailable, and then the entry information of the selected bitmap entry will be removed from the data linked list, thereby avoiding this part of the bitmap entry from being repeatedly loaded into other cache spaces. In this way, the stability and correctness of the source port allocation can be guaranteed.
[0034] S3: for a target bitmap entry currently loaded in a target cache space in the at least one cache space, identifying status information of each bitmap in the target bitmap entry, and determining a currently available target source port based on the status information.
[0035] In this embodiment, after determining the data bucket corresponding to the data packet, the source address translation device can select a target cache space in the cache space associated with the data bucket, and allocate a source port for the data packet based on the target bitmap entry loaded in the target cache space.
[0036] The target cache space has a certain association with the thread that processes the data packet. Specifically, the number of threads running in parallel in the source address translation device can be consistent with the number of cache spaces associated with the data bucket. Figure 2 In the source address translation device, the number of threads running in parallel can also be T, so the thread and the cache space can be in a one-to-one correspondence. In this case, the thread number and the cache space have a binding relationship. At this time, the thread number of the thread that processes the data packet can be identified, and the target cache space that matches the thread number can be determined from at least one cache space associated with the data bucket. For example, the thread numbers of the threads in the source address translation device are from 1 to 10. Assuming that the thread with thread number 5 currently determines the data bucket for the data packet, then the 5th cache space of the 10 cache spaces associated with the data bucket can be used as the target cache space, and the subsequent thread with thread number 5 can allocate the source port for the data packet according to the target bitmap entry loaded in the 5th cache space.
[0037] Of course, in some application scenarios, the number of threads and the number of cache spaces may not correspond one-to-one, but there may be certain mapping rules between the thread number and the cache space, so that the target cache space can be determined from the multiple cache spaces associated with the data bucket according to the thread number.
[0038] In this embodiment, after determining the target cache space, the state information of each bitmap in the target bitmap entry currently loaded in the target cache space can be identified. The state information of the bitmap can characterize whether the associated source port is available. By identifying the state information of the bitmap, the currently available target source port can be determined. For example, the bitmap is assigned a value of 0, indicating that the source port associated with the bitmap is available. By traversing the state information of each bitmap in the target bitmap entry, the first bitmap assigned a value of 0 can be determined, and the source port associated with the bitmap is used as the available target source port.
[0039] S5: Using the target source port to replace the source port carried in the data packet to generate a data packet with source address translation.
[0040] In this embodiment, after determining the target source port, the target source port can be used to replace the source port carried in the data packet, thereby obtaining a data packet after source address translation. The data packet after source address translation can be sent by the gateway to the public network.
[0041] In this embodiment, after the source port carried in the data packet is replaced with the target source port, the target source port cannot be assigned to another data packet before being released. In view of this, the state information of the target bitmap associated with the target source port can be modified to state information representing that the source port is unavailable in the target bitmap entry loaded in the target cache space. For example, the value of the target bitmap can be modified from 0 to 1. In this way, when the source port is subsequently assigned, the target source port will not be assigned to another data packet, so as to ensure the stability and correctness of the source port assignment.
[0042] In one embodiment, in order to speed up the reading speed of data, the bitmap entries in the data bucket can be stored in a continuous memory space. At the same time, the port numbers of the source ports that can be allocated in the network are usually continuous, so the bitmap and the source port can be regarded as the mutual mapping of two continuous numbers. For example, the bitmap of the bitmap entry in the data bucket can be stored in sequence starting from memory address 0. Assuming that a total of 6 bitmap entries are stored in the data bucket, each bitmap entry contains 64 bitmaps, then from memory address 0 to memory address 383, these 384 bitmaps can be stored in sequence. At the same time, the port number of the source port that can be allocated can start from 1000, so 384 source ports to be allocated with port numbers from 1000 to 1383 are obtained. In this way, the memory addresses 0 to 383 and the port numbers 1000 to 1383 can form a mutual mapping relationship, and the port number associated with the bitmap can be quickly queried through the memory address. Similarly, the memory address of the bitmap can also be quickly queried through the port number.
[0043] It should be noted that there are also solutions for allocating source ports by bucketing data. Figure 3 In the example, the data bucket corresponding to the data packet can also be determined based on the quintuple information in the data packet. However, the data bucket stores the port number of the source port to be allocated. These port numbers can be managed through a data linked list. When allocating the source port, the unallocated port number can be directly taken from the data bucket, and the source port corresponding to the port number is used as the source port of the data packet.
[0044] This solution seems to be simple to implement and the allocation process is not complicated, but in actual application, it consumes a lot of memory. The reason is that a port number usually requires two bits of data to represent it. If N port numbers are stored in a data bucket, then 2N bits of data are required to represent them. In the embodiment of the present disclosure, bitmaps are stored in the data bucket, and each bitmap has only one bit of data. Even if N port numbers are associated, only N bits of data are needed to represent them in this embodiment, which greatly saves memory space. In addition, in Figure 3 In the scheme shown, the linked list pointer in the data linked list directly points to the port number, so if there are N allocable source ports, then N linked list pointers are required in the data linked list. However, in the embodiment of the present disclosure, the linked list pointer points to the bitmap entry, and a bitmap entry can contain a specified number of bitmaps (for example, 64 bitmaps). Therefore, taking 64 bitmaps as an example, in the embodiment of the present disclosure, the data linked list only needs N / 64 linked list pointers at most, which also greatly reduces the consumption of memory.
[0045] In addition, Figure 3 In the scheme shown, each time a port number is selected from a data bucket, a read-write lock needs to be added to the data bucket, and the read-write lock can be released only after the selection is completed. This results in that, although the source address translation device supports multi-threaded parallel operation, it is actually still a single-threaded working mode in the data bucket. In the embodiment of the present disclosure, the data bucket will be associated with multiple cache spaces, thereby supporting multi-threaded parallel operation when allocating source ports, greatly improving the efficiency of source port allocation.
[0046] See also Figure 4 If it is determined according to the status information of the bitmap in the target bitmap entry that there is currently no available target source port, it indicates that the target cache space needs to reload the available bitmap entry. Specifically, the bitmap entries associated with the available source ports can be filtered out from the data bucket, and the filtered bitmap entries can be loaded into the target cache space. It should be noted that the way to load the bitmap entry into the target cache space is to overwrite or replace, that is, the newly loaded bitmap entry will replace the previously loaded bitmap entry.
[0047] In one embodiment, the specific implementation method of filtering bitmap entries from the data bucket can refer to the relevant description of the entry information in the data linked list in step S1, which will not be repeated here. Taking the loading of 3 bitmap entries in the target cache space as an example, after filtering out 3 available bitmap entries from the data bucket, these 3 bitmap entries can be loaded into the target cache space. Then, the status information of the bitmaps in these 3 bitmap entries can be modified in the data bucket to remove the entry information of these 3 bitmap entries from the data linked list. That is to say, in the data bucket, the status information of each bitmap in the filtered bitmap entries can be modified to the status information representing the unavailability of the source port, and the entry information of the filtered bitmap entries can be removed from the data linked list used to record the entry information. The specific operation process is as described in step S1, which will not be repeated here.
[0048] In this embodiment, after the bitmap entry is reloaded in the target cache space, a method similar to steps S3 and S5 can be used to determine the currently available target source port in the target cache space based on the filtered bitmap status information, and use the target source port to replace the source port carried in the data packet to generate a data packet with source address conversion.
[0049] It should be noted that, in order to ensure the consistency of data in the data bucket, before filtering out the bitmap entries associated with the available source ports from the data bucket, it is necessary to add a read-write lock to the data bucket, and only after the state information of each bitmap in the filtered bitmap entries is modified to the state information representing that the source port is unavailable, the read-write lock of the data bucket is removed. Although the addition and removal of read-write locks are also involved, in this embodiment, the addition and removal of read-write locks are performed only when the bitmap entries are reloaded into the cache space. This situation occurs very rarely and does not significantly reduce the efficiency of source port allocation.
[0050] In one embodiment, when the target source port allocated to a data packet is released, it indicates that the target source port will become allocatable again. In this case, the bitmap entry to which the target source port belongs can be determined, and the target bitmap matching the target source port can be identified in the bitmap entry.
[0051] Specifically, according to the foregoing, there is a one-to-one correspondence between the bitmap and the source port. When the target source port is released, the port number of the target source port can be obtained first, so that the matching target bitmap can be quickly queried according to the port number. For example, the port number of the target source port is P, and the port number of the current source port to be allocated starts from 1000. Each bitmap entry contains 64 bitmaps. Then, the quotient obtained can be used as the index number of the bitmap entry by calculating (P-1000) / 64, and the bitmap entry to which it belongs can be queried according to the index number of the bitmap entry. Then, the matching target bitmap can be directly located in the bitmap entry to which it belongs through the modulus operation of (P-1000)%64.
[0052] In this embodiment, after determining the location of the target bitmap, it is possible to determine whether the corresponding bitmap entry is currently loaded into the cache space. Based on the determination result, the state information of the target bitmap can be modified in the cache space or in the data bucket.
[0053] The purpose of judging whether the bitmap entry is currently loaded into the cache space is that if the bitmap entry is currently loaded into the cache space, then according to the description above, the value of each bitmap in the bitmap entry in the data bucket will be set to 1. At this time, when the target source port corresponding to the target bitmap is released, the state information of the target bitmap can be directly modified in the cache without modifying it in the data bucket.
[0054] If the bitmap entry is not currently loaded into the cache space, the state information of the bitmap in the data bucket can represent the actual allocation state of the source port. At this time, when the target source port associated with the target bitmap is released, the state information of the target bitmap can be modified in the data bucket.
[0055] That is, if the attributed bitmap entry is currently loaded into the cache space, the state information of the target bitmap is modified in the cache space to state information indicating that the source port is available. If the attributed bitmap entry is not currently loaded into the cache space, the state information of the target bitmap is modified in the data bucket to state information indicating that the source port is available. This ensures that the state information of the target bitmap can correctly indicate the allocation state of the target source port.
[0056] In one embodiment, with the release of some source ports, the status information of some bitmaps in the data bucket may also be modified. Taking the target bitmap as an example, after the status information of the target bitmap is modified to the status information that represents the available source port in the data bucket, it can be determined whether the entry information of the bitmap entry to which the target bitmap belongs is currently written into the data linked list. If it has been written into the data linked list, no additional operation is required. If the entry information of the bitmap entry to which the target bitmap belongs is not currently written into the data linked list, it is necessary to modify the entry information in the data linked list. The reason is that the target source port corresponding to the target bitmap is released, indicating that the bitmap entry to which the target bitmap belongs has been associated with an available source port, and the entry information of the bitmap entry should be written into the data linked list at this time. In view of this, a read-write lock can be added to the data linked list, and the entry information of the bitmap entry to which the target bitmap belongs is written into the data linked list. After the entry information of the bitmap entry to which the target bitmap belongs is written into the data linked list, the read-write lock of the data linked list is removed. By adding and removing the operation of the read-write lock, it can be ensured that the data in the data linked list remains consistent in parallel threads.
[0057] As can be seen from the above, in the embodiments of the present disclosure, read-write locks are added and removed from data buckets only in very rare cases. Similarly, read-write locks are added and removed from data linked lists only in very rare cases, thereby ensuring that there is no significant impact on the efficiency of source port allocation.
[0058] The technical solution provided by one or more embodiments of the present disclosure uses data buckets to allocate source ports for data packets. In the data buckets, the source ports to be allocated can be associated with the bitmap in the bitmap entry. In order to improve the allocation efficiency of the source ports, the data buckets can be associated with one or more cache spaces, and the cache space can be used to load at least one bitmap entry in the data bucket.
[0059] When allocating source ports, the state information of each bitmap can be identified from the target bitmap entries loaded in the cache space, thereby determining the currently available target source port. The source port carried in the data packet is replaced with the target source port, thereby generating a data packet with source address translation.
[0060] It can be seen that the technical solution provided by one or more embodiments of the present disclosure can disperse a large number of data packets into different data buckets for source port allocation, and when performing source port allocation, the currently available source port can be directly determined through the status information of the bitmap loaded in the cache space, thereby improving the efficiency of source port allocation.
[0061] See also Figure 5 In one embodiment of the present disclosure, a source address conversion device is provided, the device comprising:
[0062] The data bucket determination unit 100 is used to receive a data packet to be converted into a source address and determine a data bucket corresponding to the data packet, wherein the data bucket stores a plurality of bitmap entries and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate a source port to be allocated, and the cache space is used to load at least one bitmap entry of the plurality of bitmap entries.
[0063] The source port determination unit 200 is used to identify the status information of each bitmap in the target bitmap entry currently loaded in the target cache space in the at least one cache space, and determine the currently available target source port based on the status information.
[0064] The replacement unit 300 is used to replace the source port carried in the data packet with the target source port to generate a data packet with a source address converted.
[0065] In one embodiment, the data bucket further includes a data linked list, and the data linked list is used to record entry information of a bitmap entry currently associated with an available source port;
[0066] The data bucket determination unit 100 is also used to filter out the bitmap entries required for the cache space according to the entry information recorded in the data linked list, and load the filtered bitmap entries into the cache space; in the data bucket, modify the status information of each bitmap in the filtered bitmap entries to status information representing the unavailability of the source port, and remove the entry information of the filtered bitmap entries from the data linked list.
[0067] In one embodiment, the data bucket determination unit 100 is further used to identify the thread number of the thread that processes the data packet, and determine a target cache space that matches the thread number from the at least one cache space.
[0068] In one embodiment, the device further comprises:
[0069] The state information modifying unit is used to modify the state information of the target bitmap associated with the target source port in the target bitmap entry loaded in the target cache space to state information indicating that the source port is unavailable.
[0070] In one embodiment, the device further comprises:
[0071] a screening unit, configured to screen out bitmap entries associated with available source ports from the data bucket if it is determined according to the status information that there is currently no available target source port, and load the screened bitmap entries into the target cache space;
[0072] The source port determination unit 200 is further configured to determine, in the target cache space, a currently available target source port according to the filtered bitmap status information;
[0073] The replacement unit 300 is further configured to replace the source port carried in the data packet with the target source port to generate a data packet after source address translation.
[0074] In one embodiment, the status information modification unit is also used to modify the status information of each bitmap in the filtered bitmap entries in the data bucket to status information indicating that the source port is unavailable, and remove the entry information of the filtered bitmap entries from the data linked list used to record the entry information.
[0075] In one embodiment, the device further comprises:
[0076] A read-write lock operation unit is used to add a read-write lock to the data bucket before filtering out the bitmap entries associated with the available source ports from the data bucket, and to remove the read-write lock of the data bucket after modifying the status information of each bitmap in the filtered bitmap entries to status information indicating that the source port is unavailable.
[0077] In one embodiment, the device further comprises:
[0078] A bitmap entry determining unit, configured to determine, after the target source port is released, a bitmap entry to which the target source port belongs, and identify a target bitmap matching the target source port in the bitmap entry to which the target source port belongs;
[0079] The state information modification unit is further configured to determine whether the bitmap entry to which the target bitmap belongs is currently loaded into the cache space, and based on the determination result, modify the state information of the target bitmap in the cache space or in the data bucket.
[0080] In one embodiment, the status information modification unit is also used to, if the belonging bitmap entry is currently loaded into the cache space, modify the status information of the target bitmap in the cache space to status information representing the availability of the source port; if the belonging bitmap entry is not currently loaded into the cache space, modify the status information of the target bitmap in the data bucket to status information representing the availability of the source port.
[0081] In one embodiment, the read-write lock operation unit is also used to, after modifying the status information of the target bitmap in the data bucket to status information representing the availability of the source port, add a read-write lock to the data linked list and write the entry information of the belonging bitmap entry into the data linked list if the entry information of the belonging bitmap entry is not currently written into the data linked list for recording the entry information; after writing the entry information of the belonging bitmap entry into the data linked list, remove the read-write lock of the data linked list.
[0082] Each unit described in the above embodiments may be implemented by a computer chip or a product having a certain function. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0083] For the convenience of description, the above devices are described in terms of functions and are described separately in various units. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0084] See also Figure 6 The present disclosure also provides an electronic device, which includes a memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the above-mentioned source address conversion method is implemented.
[0085] The present disclosure also provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the above-mentioned source address conversion method is implemented.
[0086] The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0087] As a non-transitory computer-readable storage medium, the memory can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory, that is, implementing the method in the above method embodiment.
[0088] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0089] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0090] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the device, equipment, and storage medium, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0091] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
[0092] Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A source address translation method, characterized in that: The method comprises: Receive a data packet to be subjected to source address translation, and determine a data bucket corresponding to the data packet, wherein the data bucket stores a plurality of bitmap entries, and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate with a source port to be allocated, and the cache space is used to load at least one bitmap entry of the plurality of bitmap entries; For a target bitmap entry currently loaded in a target cache space in the at least one cache space, identifying state information of each bitmap in the target bitmap entry, and determining a currently available target source port based on the state information; Replacing the source port carried in the data packet with the target source port to generate a data packet after source address translation; The data bucket also includes a data linked list, and the data linked list is used to record the entry information of the bitmap entry currently associated with the available source port; The bitmap entries in the cache space are loaded as follows: Filtering out bitmap entries required by the cache space according to the entry information recorded in the data linked list, and loading the filtered bitmap entries into the cache space; In the data bucket, modifying the state information of each bitmap in the filtered bitmap entries to state information indicating that the source port is unavailable, and removing the entry information of the filtered bitmap entries from the data linked list; In the cache space, the assignment of each bitmap is determined based on whether the associated source port is available.
2. The method according to claim 1, characterized in that The target cache space is determined in the following manner: A thread number of a thread processing the data packet is identified, and a target cache space matching the thread number is determined from the at least one cache space.
3. The method according to claim 1, characterized in that After replacing the source port carried in the data packet with the target source port, the method further includes: In the target bitmap entry loaded into the target cache space, the state information of the target bitmap associated with the target source port is modified to state information indicating that the source port is unavailable.
4. The method according to claim 1, characterized in that: After identifying the status information of each bitmap in the target bitmap entry, the method further includes: If it is determined according to the state information that there is currently no available target source port, filtering out bitmap entries associated with available source ports from the data bucket, and loading the filtered bitmap entries into the target cache space; In the target cache space, determining a currently available target source port according to the filtered bitmap status information; The source port carried in the data packet is replaced with the target source port to generate a data packet with a source address translated.
5. The method according to claim 4, characterized in that After loading the filtered bitmap entries into the target cache space, the method further includes: In the data bucket, the state information of each bitmap in the filtered bitmap entries is modified to state information indicating that the source port is unavailable, and the entry information of the filtered bitmap entries is removed from the data linked list used to record the entry information.
6. The method according to claim 5, characterized in that The method further comprises: Before filtering out the bitmap entries associated with the available source ports from the data bucket, a read-write lock is added to the data bucket, and after modifying the status information of each bitmap in the filtered bitmap entries to status information indicating that the source port is unavailable, the read-write lock of the data bucket is removed.
7. The method according to claim 1, characterized in that The method further comprises: After the target source port is released, determining the bitmap entry to which the target source port belongs, and identifying the target bitmap matching the target source port in the bitmap entry; It is determined whether the bitmap entry to which the target belongs is currently loaded into the cache space, and based on the determination result, the state information of the target bitmap is modified in the cache space or in the data bucket.
8. The method according to claim 7, characterized in that Modifying the state information of the target bitmap in the cache space or in the data bucket includes: If the attributed bitmap entry is currently loaded into the cache space, modify the state information of the target bitmap in the cache space to state information indicating that the source port is available; If the belonging bitmap entry is not currently loaded into the cache space, the state information of the target bitmap is modified in the data bucket to state information indicating that the source port is available.
9. The method according to claim 7 or 8, characterized in that: After modifying the state information of the target bitmap in the data bucket to state information indicating that the source port is available, the method further includes: If the entry information of the attributed bitmap entry is not currently written into the data linked table for recording entry information, adding a read-write lock to the data linked table, and writing the entry information of the attributed bitmap entry into the data linked table; After writing the entry information of the belonging bitmap entry into the data linked list, removing the read-write lock of the data linked list.
10. A source address translation device, characterized in that: The device comprises: A data bucket determination unit, used to receive a data packet to be subjected to source address translation, and determine a data bucket corresponding to the data packet, wherein the data bucket stores a plurality of bitmap entries, and the data bucket is associated with at least one cache space; wherein the bitmap entry includes a specified number of bitmaps, the bitmap is used to associate a source port to be allocated, and the cache space is used to load at least one bitmap entry of the plurality of bitmap entries; a source port determination unit, configured to identify, for a target bitmap entry currently loaded in a target cache space in the at least one cache space, state information of each bitmap in the target bitmap entry, and determine a currently available target source port based on the state information; A replacement unit, used to replace the source port carried in the data packet with the target source port to generate a data packet after source address conversion; The data bucket also includes a data linked list, and the data linked list is used to record the entry information of the bitmap entry currently associated with the available source port; The bitmap entries in the cache space are loaded as follows: Filtering out bitmap entries required by the cache space according to the entry information recorded in the data linked list, and loading the filtered bitmap entries into the cache space; In the data bucket, modifying the state information of each bitmap in the filtered bitmap entries to state information indicating that the source port is unavailable, and removing the entry information of the filtered bitmap entries from the data linked list; In the cache space, the assignment of each bitmap is determined based on whether the associated source port is available.
11. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the method according to any one of claims 1 to 9 is implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
NAT port manager used for realizing port mapping by using remainder
CN106534394A