A resource allocation method, apparatus, device, and storage medium
By using hardware pool index resources to allocate target indexes and ports for data stream packets, the high complexity of NAPT resource allocation and reclamation is solved, thus improving the performance of network devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NEW H3C TECH CO LTD
- Filing Date
- 2023-02-28
- Publication Date
- 2026-06-05
AI Technical Summary
Existing NAPT technology consumes a lot of computational resources when allocating and reclaiming IP+Port resources, which affects performance and makes the allocation and reclamation process complicated.
The system uses index resources in the hardware pool to allocate target indexes for data stream packets, and quickly determines the target IP address and port based on the pre-established correspondence between the index and IP address and port, and updates the flow table for forwarding.
It enables rapid allocation and reclamation of NAPT resources, reduces the complexity of the resource allocation process, and improves the NAPT performance of network devices.
Smart Images

Figure CN116192808B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a resource allocation method, apparatus, device and storage medium. Background Technology
[0002] Network Address Port Translation (NAPT) technology differs from earlier Network Address Translation (NAT) technology, which only supported address translation. NAPT allows multiple hosts to share one or more public IP addresses to interact with external addresses. Nowadays, NAT generally refers to NAPT. To ensure that multiple hosts sharing a public IP address do not conflict with each other, related technologies are needed to manage and allocate public IP addresses and Layer 4 port resources.
[0003] Currently, available IP+Port resources on NAT devices are primarily identified and managed using bitmaps. That is, bitmaps... Figure 1 Each IP+Port combination corresponds to a single IP address. Setting the value to 0 or 1 indicates whether the combination is idle or in use. However, this scheme uses one or more levels of bitmaps to identify the status of each IP's 64K ports, resulting in a massive dataset and consuming significant network processing chip resources for allocating and reclaiming IP+Ports, severely impacting NAPT performance. Allocating idle IP+Port resources requires multiple status queries; reclaiming resources also requires multiple modifications to the corresponding bitmaps.
[0004] Therefore, how to efficiently achieve rapid allocation and recycling of NAPT resources and improve NAPT performance is one of the technical issues worth considering. Summary of the Invention
[0005] In view of this, this application provides a resource allocation method, apparatus, device and storage medium to efficiently realize the rapid allocation of NAPT resources and improve NAPT performance.
[0006] Specifically, this application is implemented through the following technical solution:
[0007] According to a first aspect of this application, a resource allocation method is provided, comprising:
[0008] Receive data stream messages;
[0009] When it is confirmed that the data stream packet does not hit the flow table based on the packet information, a target index is allocated to the data stream packet based on the index resources in the hardware pool.
[0010] Based on the pre-established correspondence between indexes and IP addresses and ports, the target IP address and target port corresponding to the target index are determined;
[0011] Update the flow table with the target index, the target IP address, and the target port as new entries;
[0012] The data stream packets are forwarded based on the target IP address and the target port.
[0013] According to a second aspect of this application, a resource allocation apparatus is provided, comprising:
[0014] The receiving module is used to receive data stream messages;
[0015] The allocation module is used to allocate a target index to the data stream packet based on the index resources in the hardware pool when it is confirmed that the data stream packet does not hit the flow table according to the packet information of the data stream packet.
[0016] The first determining module is used to determine the target IP address and target port corresponding to the target index based on the pre-established correspondence between the index and the IP address and port;
[0017] The update module is used to update the flow table with the target index, the target IP address, and the target port as new entries;
[0018] The forwarding module is used to forward the data stream packets according to the target IP address and the target port.
[0019] According to a third aspect of this application, a network device is provided, including a processor and a machine-readable storage medium storing a computer program executable by the processor, the processor being prompted by the computer program to perform the method provided in the first aspect of the embodiments of this application.
[0020] According to a fourth aspect of this application, a machine-readable storage medium is provided, which stores a computer program that, when invoked and executed by a processor, causes the processor to perform the method provided in the first aspect of the embodiments of this application.
[0021] The beneficial effects of the embodiments of this application are as follows:
[0022] The resource allocation method, apparatus, device, and storage medium provided in this application embodiment receive data stream packets. When it is confirmed that the data stream packet does not hit the flow table based on the packet information, a target index is allocated to the data stream packet based on the index resources in the hardware pool. Based on the pre-established correspondence between the index and IP address and port, the target IP address and target port corresponding to the target index are determined. The target index, the target IP address, and the target port are updated to the flow table as new entries. The data stream packet is forwarded according to the target IP address and the target port. Therefore, using a hardware pool for the allocation of public IP addresses and ports not only achieves the goal of quickly allocating public IP addresses and ports but also greatly reduces the complexity of the resource allocation process and improves the NAPT performance of network devices. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating a resource allocation method provided in an embodiment of this application;
[0024] Figure 2 This is a schematic diagram of the structure of a resource allocation device provided in an embodiment of this application;
[0025] Figure 3 This is a schematic diagram of the hardware structure of a network device that implements a resource allocation method, as provided in an embodiment of this application. Detailed Implementation
[0026] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.
[0027] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the corresponding listed items.
[0028] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0029] The resource allocation method provided in this application will be explained in detail below.
[0030] See Figure 1 , Figure 1 This is a flowchart illustrating a resource allocation method provided in this application. This method can be applied to network devices, which may be, but are not limited to, routing devices, etc. When implementing the above method, the network device may include the following steps:
[0031] S101, Receive data stream messages.
[0032] S102. When it is confirmed that the data stream packet has not hit the flow table based on the packet information of the data stream packet, a target index is allocated to the data stream packet based on the index resources in the hardware pool.
[0033] In this step, after receiving a data stream packet, in order to hide the hosts on the internal LAN and quickly allocate NAPT resources, this embodiment proposes to extract packet information from the data stream packet and then use this packet information to query the flow table to determine whether the currently received data stream is the first packet of a new data stream. If the flow table is not matched, it indicates that the data stream packet is the first packet of a new data stream, and thus it indicates that NAPT resources need to be allocated to the data stream to achieve the purpose of hiding the hosts on the internal LAN. Based on this, this embodiment proposes to use network processor hardware pool technology to allocate NAPT resources. That is, based on the index resources recorded in the hardware pool, a target index is allocated to the data stream packet. It should be noted that different data stream packets correspond to different indexes.
[0034] When it is confirmed that the above data flow packet hits the flow table, it indicates that the data flow packet is not the first packet of the new data flow, which means that NAPT resources have been allocated to the data flow before. At this time, it is only necessary to forward the packet according to the NAPT resources in the entry of the hit flow table.
[0035] S103. Based on the pre-established correspondence between the index and the IP address and port, determine the target IP address and target port corresponding to the target index.
[0036] In this step, the indexes in the hardware pool are pre-selected based on the NAPT resources to be allocated. The number of indexes in the hardware pool must be no less than the total number of NAPT resources that can be allocated on the network device. Each NAPT resource consists of an IP address and a port. Different NAPT resources contain different information, but there may be several NAPT resources that contain the same IP address but different ports. The specific configuration can be adjusted according to the actual situation.
[0037] Based on this, in order to quickly allocate NAPT resources, this embodiment pre-establishes a correspondence between each NAPT resource and each index. Based on this, after a target index is allocated to the data stream packet in step S102, the target index can be used to match the above correspondence, thereby obtaining the NAPT resource corresponding to the target index, i.e., the target IP address and target port included in the determined NAPT resource.
[0038] It is worth noting that the aforementioned hardware pool refers to the hardware pool equipped with the network processor in the network device. Since hardware access is faster than software access, NAPT resource allocation can be achieved quickly when using the hardware pool for resource allocation. Furthermore, the index in the hardware pool can be initialized based on the number of NAPT resources on the public network. The theoretical range of the index that each hardware pool can manage is 0 to (2...). 32 -1). After initializing the hardware pool, a unique index can be assigned to the IP address and port included in each NAPT resource. This allows us to obtain the mapping between IP address + port and index, as shown in Table 1.
[0039] Table 1
[0040] index IP address port Index1 IP address 1 Port 1 Index2 IP address 1 Port 2 Index3 IP address 2 Port 1 …… …… ……
[0041] To facilitate recording the above correspondences, a table or a hash table can be used. Taking a table as an example, the key in this table can record the index, and the result value `res` can record information such as the IP address and port. It should be noted that the number of tables depends on the amount of public network address resources to be used. Furthermore, since the initialization and table creation processes are completed in advance, they will not affect the actual resource allocation and conversion performance.
[0042] S104. Update the flow table with the target index, the target IP address, and the target port as new entries.
[0043] In this step, since only one NAPT resource needs to be allocated for the same data flow, the above correspondence can be updated into the flow table as a new entry to facilitate the forwarding of subsequent packets in the same data flow. Thus, when subsequent packets of this data flow arrive at the network device, the network device only needs to query the flow table using the packet information of the received packet. If a match is found, the IP address and port in the matched entry can be used as the outer IP address and outer port of the packet for forwarding.
[0044] S105. Forward the data stream packet according to the target IP address and the target port.
[0045] In this step, after assigning the target IP address and target port to the data stream packets, these can be used as the source IP address and source port of the packets, and then forwarded outwards. Thus, by using a hardware pool to allocate public network resources to the data stream, the goal of quickly and conveniently allocating NAPT resources is achieved, while also hiding the hosts on the internal LAN.
[0046] In the resource allocation method provided in this application, a data stream packet is received; when it is confirmed that the data stream packet does not match the flow table based on the packet information, a target index is allocated to the data stream packet based on the index resources in the hardware pool; based on the pre-established correspondence between the index and IP address and port, the target IP address and target port corresponding to the target index are determined; the target index, the target IP address, and the target port are updated to the flow table as new entries; and the data stream packet is forwarded according to the target IP address and the target port. Therefore, using a hardware pool for the allocation of public IP addresses and ports not only achieves the goal of quickly allocating public IP addresses and ports but also greatly reduces the complexity of the resource allocation process and improves the NAPT performance of network devices.
[0047] Optionally, based on any of the above embodiments, the following process can also be executed in this embodiment: when a target entry of the flow table is hit, the data flow packet is NAT translated according to the IP address and port included in the target entry; and the translated data flow packet is forwarded.
[0048] Specifically, when the packet information of a data stream packet hits the target entry in the flow table, since the target entry includes packets preceding the data stream to which the data stream packet belongs, the IP address and port of the data stream have been assigned to the data stream according to the above method. Thus, the private address of the packet can be converted into the IP address and port included in the target entry. Based on this, it can be understood that the converted IP address and port are used as the source IP address and source port for packet forwarding.
[0049] It should be noted that each entry in this flow table, in addition to including the IP address and port allocated according to any of the methods described above in this application, may also include the packet information of the data flow corresponding to that entry. This packet information may, but is not limited to, triples or quintuples, etc.
[0050] Optionally, based on any of the above embodiments, resource recycling also exists after resource allocation. In view of this, the following resource recycling method is proposed in this embodiment, which may include the following process: determining the entries in the flow table that need to be aged; recycling the indexes included in the entries that need to be aged; and deleting the entries that need to be aged.
[0051] Specifically, network devices periodically perform aging checks on each entry in the flow table to determine which entries need to be aged. For example, to identify inactive entries in the flow table, and to ensure that the IP addresses and ports in these entries can provide forwarding services for subsequent new data flows, this embodiment proposes to perform aging processing on inactive entries. During the aging process, the indexes of the entries requiring aging are recycled, and the entries themselves are deleted from the flow table, thus achieving the aging of the entries. Simultaneously, the recycling of IP addresses and ports also achieves the recycling of IP addresses and ports. Therefore, compared to the existing bitmap method for recycling IP addresses and ports, this embodiment uses a hardware pool for IP address and port recycling, significantly improving resource recycling speed.
[0052] Specifically, when identifying inactive entries, access frequency detection can be performed on each entry in the flow table. If any entry is found to have not been accessed within a set time, it can be confirmed as an inactive entry. Of course, this method is only an example and does not constitute a limitation on the method for determining inactive entries.
[0053] Optionally, based on any of the above embodiments, this embodiment can perform step S102 according to the following method: call the interface function of the hardware pool to allocate a target index for the data stream packet.
[0054] Specifically, index allocation can be quickly achieved by calling the hardware pool's interface functions. Specifically, when an index is read using the interface function, this read index is recorded as the target index for the aforementioned data stream packet allocation. Simultaneously, the target index is marked in the hardware pool to indicate that it is already occupied. This allows the network device to filter from unmarked indexes when it receives new data streams and performs index allocation. In short, the aforementioned interface functions can complete the target index allocation and marking operations in one go, and this operation can be completed within one clock cycle without additional software code overhead, thus achieving rapid allocation of NAPT resources.
[0055] Similarly, the steps to reclaim the indexes included in the entries that need to be aged can be performed as follows: call the interface function of the hardware pool to reclaim the indexes included in the entries that need to be aged.
[0056] In this step, during index reclamation, the indexes in the entries to be aged can be passed to the interface function of the hardware pool. This allows the interface function to mark the index in the hardware pool as unoccupied. This not only reclaims the indexes but also ensures that the reclaimed indexes serve the new data streams. Furthermore, since only entries to be aged are deleted from the flow table, IP addresses and ports are also reclaimed simultaneously with index reclamation. Moreover, this application uses a hardware-based approach for resource reclamation, which significantly improves efficiency compared to software-based methods. It also enables efficient and convenient management of public IP addresses and port resources used by NAPT services.
[0057] It should be noted that the hardware pool in this application is an index pool managed by the BMU (Buffer Management Unit) on the network processor. The SDK of this index pool encapsulates hardware acceleration instructions, where the index allocation and release instructions themselves consume only one chip clock cycle, and index allocation and release are atomic operations, compatible with multi-threaded operations. Therefore, by calling the interface functions of the hardware pool, such as the API interface, the allocation and reclamation of index resources can be easily and efficiently implemented, that is, the reclamation of IP addresses and ports can be achieved.
[0058] Furthermore, NAPT resource allocation via a network processor hardware pool enables rapid and convenient allocation of public network resources for packets requiring address translation and reclamation of inactive public network resources. Moreover, this method requires at most one hardware pool operation and one DDR access to complete address resource allocation or reclamation. Compared to dozens of DDR access operations using bitmaps and the complex maintenance process of software pools, this significantly reduces the complexity of resource allocation and reclamation while improving the NAPT performance of network devices.
[0059] Based on the same inventive concept, this application also provides a resource allocation device corresponding to the above-described resource allocation method. Specific implementation details of this resource allocation device can be found in the above description of the resource allocation method, and will not be elaborated upon here.
[0060] See Figure 2 , Figure 2 This application provides an exemplary embodiment of a resource allocation apparatus, comprising:
[0061] Receiver module 201 is used to receive data stream messages;
[0062] The allocation module 202 is used to allocate a target index to the data stream packet based on the index resources in the hardware pool when it is confirmed that the data stream packet does not hit the flow table according to the packet information of the data stream packet.
[0063] The first determining module 203 is used to determine the target IP address and target port corresponding to the target index based on the pre-established correspondence between the index and the IP address and port;
[0064] Update module 204 is used to update the flow table with the target index, the target IP address and the target port as new entries;
[0065] The forwarding module 205 is used to forward the data stream packets according to the target IP address and the target port.
[0066] Optionally, based on the above embodiments, the resource allocation device provided in this embodiment further includes:
[0067] A conversion module (not shown in the figure) is used to perform NAT translation on the data flow packet according to the IP address and port included in the target entry when the target entry of the flow table is hit.
[0068] Based on this, the aforementioned forwarding module 205 is also used to forward the converted data stream packets.
[0069] Based on any of the above embodiments, the resource allocation device provided in this embodiment further includes:
[0070] The second determining module (not shown in the figure) is used to determine the entries in the flow table that need to be aged.
[0071] The recycling module (not shown in the figure) is used to recycle the indexes included in the table entries that need to be aged.
[0072] The deletion module (not shown in the figure) is used to delete the entries that need to be aged.
[0073] Based on any of the above embodiments, in this embodiment, the allocation module is specifically used to call the interface function of the hardware pool to allocate a target index for the data stream packet.
[0074] Accordingly, the aforementioned recycling module is specifically used to call the interface function of the hardware pool to recycle the indexes included in the table entries that need to be aged.
[0075] In any embodiment of this application, the resource allocation apparatus receives a data stream packet. When it is confirmed that the data stream packet does not match the flow table based on the packet information, a target index is allocated to the data stream packet based on the index resources in the hardware pool. Based on the pre-established correspondence between the index and IP address and port, the target IP address and target port corresponding to the target index are determined. The target index, the target IP address, and the target port are updated to the flow table as new entries. The data stream packet is forwarded according to the target IP address and the target port. Therefore, using a hardware pool for the allocation of public IP addresses and ports not only achieves the goal of quickly allocating public IP addresses and ports but also greatly reduces the complexity of the resource allocation process and improves the NAPT performance of the network device.
[0076] Based on the same inventive concept, embodiments of this application provide a network device, such as... Figure 3 As shown, the device includes a processor 301 and a machine-readable storage medium 302. The machine-readable storage medium 302 stores a computer program executable by the processor 301. The processor 301 is prompted by the computer program to execute the resource allocation method provided in any embodiment of this application. Furthermore, the network device also includes a communication interface 303 and a communication bus 304, wherein the processor 301, the communication interface 303, and the machine-readable storage medium 302 communicate with each other via the communication bus 304.
[0077] The communication bus mentioned in the above network devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.
[0078] The communication interface is used for communication between the aforementioned network devices and other devices.
[0079] The machine-readable storage medium 302 described above can be a memory, which may include random access memory (RAM), DDR SRAM (Double Data Rate Synchronous Dynamic Random Access Memory), or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0080] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0081] For network devices and machine-readable storage media embodiments, since the methods involved are basically similar to those described in the foregoing method embodiments, the description is relatively simple, and relevant details can be found in the descriptions of the method embodiments.
[0082] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0083] The specific implementation process of the functions and roles of each unit / module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0084] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units / modules described as separate components may or may not be physically separate. The components shown as units / modules may or may not be physical units / modules, that is, they may be located in one place or distributed across multiple network units / modules. Some or all of the units / modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0085] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A resource allocation method, characterized in that, include: Receive data stream messages; When it is confirmed that the data stream packet does not hit the flow table based on the packet information, a target index is allocated to the data stream packet based on the index resources in the hardware pool. The hardware pool is the hardware pool equipped with the network processor in the network device, and the index in the hardware pool is pre-selected and established based on the NAPT resources to be allocated. Based on the pre-established correspondence between indexes and IP addresses and ports, the target IP address and target port corresponding to the target index are determined; Update the flow table with the target index, the target IP address, and the target port as new entries; The data stream packets are forwarded based on the target IP address and the target port.
2. The method according to claim 1, characterized in that, When a target entry in the flow table is hit, the data flow packet is NAT translated according to the IP address and port included in the target entry. Forward the processed data stream packets.
3. The method according to claim 1, characterized in that, Also includes: Identify the entries in the flow table that need to be aged; The indexes included in the table entries that need to be aged are recycled; Delete the entries that need aging.
4. The method according to claim 1, characterized in that, Based on the index resources in the hardware pool, a target index is allocated to the data stream packet, including: The interface function of the hardware pool is invoked to allocate a target index for the data stream packet.
5. The method according to claim 3, characterized in that, The indexes included in the table entries that need to be aged are recycled, including: Call the hardware pool's interface function to reclaim the indexes included in the table entries that need to be aged.
6. A resource allocation device, characterized in that, include: The receiving module is used to receive data stream messages; The allocation module is used to allocate a target index to the data stream packet based on the index resources in the hardware pool when it is confirmed that the data stream packet does not hit the flow table according to the packet information of the data stream packet. The hardware pool is the hardware pool equipped with the network processor in the network device, and the index in the hardware pool is pre-selected and established based on the NAPT resources to be allocated. The first determining module is used to determine the target IP address and target port corresponding to the target index based on the pre-established correspondence between the index and the IP address and port; The update module is used to update the flow table with the target index, the target IP address, and the target port as new entries; The forwarding module is used to forward the data stream packets according to the target IP address and the target port.
7. The apparatus according to claim 6, characterized in that, Also includes: The conversion module is used to perform NAT translation on the data flow packet based on the IP address and port included in the target entry when the target entry of the flow table is hit. The forwarding module is also used to forward the converted data stream packets.
8. The apparatus according to claim 7, characterized in that, Also includes: The second determining module is used to determine the entries in the flow table that need to be aged. The recycling module is used to recycle the indexes included in the table entries that need to be aged. The deletion module is used to delete the entries that need to be aged.
9. The apparatus according to claim 6, characterized in that, The allocation module is specifically used to call the interface function of the hardware pool to allocate a target index for the data stream packet.
10. The apparatus according to claim 8, characterized in that, The recycling module is specifically used to call the interface function of the hardware pool to recycle the indexes included in the table entries that need to be aged.
11. A network device, characterized in that, The method includes a processor and a machine-readable storage medium storing a computer program executable by the processor, which is prompted by the computer program to perform the method according to any one of claims 1-5.
12. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores a computer program that, when invoked and executed by a processor, causes the processor to perform the method described in any one of claims 1-5.