Data packet transmission method and device

By storing the subnet mask into a quad-tree structure, the problem of low matching performance of subnet masks is solved, and the stability and efficiency of matching speed are achieved.

CN119814737APending Publication Date: 2025-04-11CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411773083.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

As the subnet mask configuration increases, the performance of subnet mask matching is not high, resulting in a decrease in matching speed.

Method used

By storing the target network address and subnet mask into a quad-tree structure, a quad-tree tree is generated and its nodes are traversed to match the target network address and subnet mask.

Benefits of technology

No matter how many subnet masks are configured, the number of matches is fixed to the tree height of the quad-tree (up to 16 times). Therefore, even if the subnet mask configuration increases linearly, the matching speed remains unchanged, ensuring the performance of subnet mask matching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119814737A_ABST
    Figure CN119814737A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a data packet transmission method and device. The method comprises the following steps: acquiring a data packet; obtaining at least one configuration according to the target network address; the configuration comprises a network address, a subnet mask and a next hop address; the subnet masks have corresponding mask lengths; generating a quadtree according to the target network address and the mask length of the subnet mask; the quadtree comprises a plurality of nodes; the nodes comprise matching nodes matched with the masks in length, the matching nodes comprise configuration information, and the configuration information comprises a network address, a subnet mask and a next hop address; traversing the quadtree to obtain configuration information in each matching node in the quadtree; and matching the network address and the subnet mask in the configuration information of each matching node with a target, and taking the next hop address in the configuration information which is successfully matched and has the mask length meeting a preset condition as the next hop address of the data packet. According to the embodiment of the invention, the performance of subnet mask matching is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of communication technology, and in particular to a data packet transmission method, a data packet transmission device, an electronic device, and a computer-readable storage medium. Background Art

[0002] A subnet mask is also called a network mask, an address mask, or a subnet mask. It is used to indicate which bits of an IP address identify the subnet (network) where the host is located, and which bits identify the bit mask of the host. A subnet mask cannot exist alone and needs to be used in conjunction with an IP address. IP subnet mask matching (subnet mask matching) is a technology used in network communications to determine the network to which an IP address belongs. It determines whether an IP address belongs to a specific network by performing a logical operation on the IP address and the subnet mask.

[0003] However, as the subnet mask configuration continues to grow, the matching speed decreases, resulting in low performance of subnet mask matching. Therefore, it is urgent to propose a method that can ensure the performance of subnet mask matching. Summary of the invention

[0004] In view of the above problems, a method and device for transmitting data packets is proposed to overcome the above problems or at least partially solve the above problems. The specific technical solution is as follows:

[0005] In a first aspect of the present invention, a method for transmitting a data packet is provided, the method comprising:

[0006] Acquire a data packet; the data packet includes a target network address;

[0007] Acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length;

[0008] Generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include a matching node that matches the mask length, the matching node includes configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address;

[0009] Traversing the quadtree to obtain configuration information of each matching node in the quadtree;

[0010] The network address and subnet mask in the configuration information of each matching node are matched with the target network address, and the next hop address in the configuration information where the match is successful and the mask length meets the preset condition is used as the next hop address of the data packet.

[0011] In one embodiment of the present invention, after acquiring at least one configuration according to the target network address, the method further includes:

[0012] The target network address, the network address and the subnet mask are converted into binary versions of the network address and the subnet mask.

[0013] In one embodiment of the present invention, generating a quadtree according to the target network address and the mask length of the subnet mask includes:

[0014] Sequentially obtain the first two bits of the target network address as node identifiers of nodes of the quadtree;

[0015] When the mask length of the subnet mask is zero, the node is marked as a matching node, and configuration information is stored in the matching node.

[0016] In one embodiment of the present invention, generating a quadtree according to the target network address and the mask length of the subnet mask includes:

[0017] When the mask length of the subnet mask is not zero, determining whether the node corresponding to the node identifier exists in the quadtree;

[0018] If a node corresponding to the node identifier does not exist in the quadtree, creating a node for the node identifier in the quadtree, and creating a node reference count for the node;

[0019] If the node corresponding to the node identifier exists in the quadtree, increase the node reference count of the node corresponding to the node identifier;

[0020] Subtract two bits from the mask length, and return to the step of sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree.

[0021] In one embodiment of the present invention, before sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree, the method further includes:

[0022] Determine whether the mask length of the subnet mask is an odd number;

[0023] When the mask length of the subnet mask is an odd number, the mask length of the network portion is adjusted to an even number.

[0024] In one embodiment of the present invention, when the mask length of the subnet mask is zero, marking the node as a matching node, and after storing configuration information in the matching node, the method further includes:

[0025] When the mask length of the subnet mask is an odd number, the node is marked as a matching node, a new matching node is added, and configuration information is stored in the matching node and the new matching node.

[0026] In an embodiment of the present invention, the preset condition is maximum mask matching.

[0027] The embodiment of the present invention further discloses a data packet transmission device, the device comprising:

[0028] A data packet receiving module, used to obtain a data packet; the data packet includes a target network address;

[0029] A configuration acquisition module, configured to acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length;

[0030] A quadtree generation module, configured to generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include a matching node that matches the mask length, the matching node includes configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address;

[0031] A quadtree traversal module, used for traversing the quadtree and obtaining configuration information of each matching node in the quadtree;

[0032] The address determination module is used to match the network address and subnet mask in the configuration information of each matching node with the target network address, and use the next hop address in the configuration information that is successfully matched and the mask length meets the preset conditions as the next hop address of the data packet.

[0033] In another aspect of the present invention, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed on a computer, the computer executes any of the above-mentioned data packet transmission methods.

[0034] In another aspect of the present invention, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned data packet transmission methods.

[0035] Compared with the related art, the embodiments of the present invention have at least the following advantages:

[0036] In an embodiment of the present invention, a device obtains a data packet, which includes a target network address; obtains at least one configuration according to the target network address, the configuration may include a network address, a subnet mask and a next hop address, the subnet mask has a corresponding mask length, generates a quadtree according to the target network address and the mask length of the subnet mask, the generated quadtree includes a plurality of nodes, the nodes of the quadtree may include matching nodes that match the mask length, the matching nodes include configuration information, the configuration information includes the network address, the subnet mask and the next hop address, traverses the quadtree, obtains the configuration information in each matching node in the quadtree, matches the network address and the subnet mask in the configuration information of each matching node with the target network address, and uses the next hop address in the configuration information that is successfully matched and whose mask length meets a preset condition as the next hop address of the data packet, so that the data packet can be forwarded to the device corresponding to the next hop address. The embodiment of the present invention stores the target network address and the subnet mask configuration into a quadtree structure. In this way, the number of matches between the target network address and the subnet mask is the tree height of the quadtree. No matter how many subnet masks are configured (configured), the number of matches is related to the tree height of the quadtree. The maximum height of the quadtree is 16. Therefore, even if the subnet mask configuration increases linearly, the matching speed remains unchanged, thereby ensuring the performance of the subnet mask matching. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.

[0038] Figure 1 A flowchart of a method for transmitting a data packet provided in an embodiment of the present invention;

[0039] Figure 2 A schematic diagram of a quadtree node entry structure design provided in an embodiment of the present invention;

[0040] Figure 3 A schematic diagram of a quadtree root node entry structure design provided in an embodiment of the present invention;

[0041] Figure 4 A quadtree memory structure diagram provided in an embodiment of the present invention;

[0042] Figure 5 A schematic diagram of a quadtree IP subnet mask matching process provided in an embodiment of the present invention;

[0043] Figure 6 A schematic diagram of comparing subnet mask matching performance provided in an embodiment of the present invention;

[0044] Figure 7A structural block diagram of a data packet transmission device provided in an embodiment of the present invention;

[0045] Figure 8 The present invention is a block diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0047] At present, IP subnet mask matching is based on the maximum mask matching. Taking ipv4 as an example, the maximum mask is 32 bits, and one mask corresponds to one linked list. There need to be 32 linked lists, each of which records all the subnets with its own mask. Then, the ip subnet mask matching starts from the highest 32-bit mask linked list. If the 32-bit linked list fails to match, the 31-bit linked list will be matched again until the match is successful or all matches are completed. It can be seen that the current IP subnet mask belongs to linear matching. With the linear increase of subnet mask configuration (configuration), the matching performance of subnet mask will also decrease linearly. As the user's usage configuration increases to a certain amount, the performance of subnet mask will be insufficient.

[0048] In summary, the embodiment of the present invention proposes a quadtree-based IP subnet mask matching method. For the IP subnet mask, since the IP is 32 bits in the memory, each node of the quadtree is represented by 2 bits, and there are four forms 00, 01, 10, and 11, so it is called quadtree matching. The height of the quadtree is 16, and it is stored in a quadtree structure. No matter how many subnet mask configurations (configurations) there are, the number of subnet mask matching times is the tree height of the quadtree, which is at most 16 times. In this way, the subnet mask configuration is linearly increased, the subnet mask matching speed is unchanged, and the performance of the subnet mask matching is unchanged.

[0049] Reference Figure 1 , is a flowchart of a method for transmitting a data packet provided in an embodiment of the present invention, such as Figure 1 As shown, the method may specifically include the following steps:

[0050] Step 101, obtaining a data packet; the data packet includes a target network address;

[0051] Step 102: acquiring at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length;

[0052] In an embodiment of the present invention, a device can obtain a data packet to be forwarded, and the data packet may include a target network address (target IP address). According to the target IP address, at least one configuration (subnet mask configuration) can be obtained from the device, and each configuration may include a network address, a subnet mask (mask) and a next hop address, wherein the target IP address may be an ipv4 address. Specifically, the network address is the network address to which the data packet is to be sent, the subnet mask is used to determine the range of the target network address, and the next hop address is the IP address of the next device to which the data packet should be forwarded. If the result of the logical AND operation between the subnet mask in the configuration and the target IP address is the same as the network address in the configuration, it can be determined that the subnet mask matches successfully, and then the next hop address corresponding to the maximum subnet mask can be obtained from these successfully matched subnet masks as the next hop address of the data packet, thereby forwarding the data packet to the device corresponding to the next hop address.

[0053] The subnet mask may include a network portion and a host portion. For example, assuming that configuration 1 and configuration 2 are obtained, where configuration 1 is 1.1.1.1 / 8 and configuration 2 is 2.2.2.2 / 15, the mask length of the subnet mask (indicated by the number after the slash, such as / 8, / 15) indicates the mask length of the network portion, and the remaining portion is the host portion.

[0054] Step 103: Generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include matching nodes that match the mask length, the matching nodes include configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address;

[0055] Among them, the quadtree, also known as the quadtree, is a tree-like data structure with four sub-blocks on each node. The quadtree is often used for the analysis and classification of two-dimensional spatial data. The quadtree divides the data into four quadrants, and the data range can be square, rectangular or other arbitrary shapes.

[0056] In an embodiment of the present invention, a quadtree is generated according to the target IP address and the mask length of the subnet mask, wherein the quadtree includes a plurality of nodes, among which matching nodes matching the mask length may be included, and these matching nodes include configuration information corresponding to the configuration, specifically, the configuration information includes a network address, a subnet mask and a next hop address, wherein the network address and the subnet mask at this time may be binary.

[0057] Step 104: traverse the quadtree to obtain configuration information of each matching node in the quadtree;

[0058] Step 105: Match the network address and subnet mask in the configuration information of each matching node with the target network address, and use the next hop address in the configuration information that is successfully matched and whose mask length meets a preset condition as the next hop address of the data packet.

[0059] In an embodiment of the present invention, the preset condition is maximum mask matching.

[0060] In an embodiment of the present invention, after generating a quadtree, the quadtree can be traversed to obtain configuration information in each matching node in the quadtree, namely, the network address, subnet mask and next hop address, and then the configuration information of each matching node can be matched with the target IP address. If the result of a logical AND operation between the subnet mask in the configuration information of the matching node and the target IP address is the same as the network address in the configuration information, it can be determined that the subnet mask matches successfully. If the preset condition is a maximum mask match, the next hop address corresponding to the maximum subnet mask can be obtained from these successfully matched subnet masks as the next hop address of the data packet, thereby forwarding the data packet to the device corresponding to the next hop address.

[0061] In the above-mentioned data packet transmission method, a device obtains a data packet, which includes a target network address; obtains at least one configuration according to the target network address, the configuration may include a network address, a subnet mask and a next hop address, the subnet mask has a corresponding mask length, generates a quadtree according to the target network address and the mask length of the subnet mask, the generated quadtree includes a plurality of nodes, the nodes of the quadtree may include matching nodes that match the mask length, the matching nodes include configuration information, the configuration information includes the network address, the subnet mask and the next hop address, traverses the quadtree, obtains the configuration information of each matching node in the quadtree, matches the network address and the subnet mask in the configuration information of each matching node with the target network address, and uses the next hop address in the configuration information that is successfully matched and whose mask length meets a preset condition as the next hop address of the data packet, so that the data packet can be forwarded to the device corresponding to the next hop address. The embodiment of the present invention stores the target network address and the subnet mask configuration into a quadtree structure. In this way, the number of matches between the target network address and the subnet mask is the tree height of the quadtree. No matter how many subnet masks are configured (configured), the number of matches is related to the tree height of the quadtree. The maximum height of the quadtree is 16. Therefore, even if the subnet mask configuration increases linearly, the matching speed remains unchanged, thereby ensuring the performance of the subnet mask matching.

[0062] In one embodiment of the present invention, after acquiring at least one configuration according to the target network address, the method further includes:

[0063] The target network address, the network address and the subnet mask are converted into binary versions of the network address and the subnet mask.

[0064] In an embodiment of the present invention, after obtaining the target network address of the data packet and multiple configurations, the target network address, and the network address and subnet mask in the configuration need to be converted into binary to facilitate the subsequent generation of a quadtree and subnet mask matching.

[0065] In one embodiment of the present invention, generating a quadtree according to the target network address and the mask length of the subnet mask includes:

[0066] Determine whether the mask length of the subnet mask is an odd number;

[0067] When the mask length of the subnet mask is an odd number, adjusting the mask length of the network portion to an even number;

[0068] Sequentially obtain the first two bits of the target network address as node identifiers of nodes of the quadtree;

[0069] When the mask length of the subnet mask is zero, marking the node as a matching node, and storing configuration information in the matching node;

[0070] When the mask length of the subnet mask is not zero, determining whether the node corresponding to the node identifier exists in the quadtree;

[0071] If a node corresponding to the node identifier does not exist in the quadtree, creating a node for the node identifier in the quadtree, and creating a node reference count for the node;

[0072] If the node corresponding to the node identifier exists in the quadtree, increase the node reference count of the node corresponding to the node identifier;

[0073] Subtract two bits from the mask length, and return to the step of sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree.

[0074] When the mask length of the subnet mask is an odd number, the node is marked as a matching node and a new matching node is added, and configuration information is stored in the matching node and the new matching node.

[0075] The quadtree-based IP subnet mask matching method proposed in the embodiment of the present invention is mainly divided into three parts: quadtree table entry structure design, quadtree memory configuration loading, and quadtree IP subnet mask matching process.

[0076] 1) Design of quadtree node entry structure:

[0077] Reference Figure 2 , is a schematic diagram of a quadtree node table entry structure design provided in an embodiment of the present invention, a quadtree node structure struct ip_tree_node, since ipv4 is composed of 32 bits, each node is represented by 2 bits, there are four forms 00, 01, 10, 11, forming a quadtree match. The quadtree node structure saves the information of the 2-bit child nodes (nodes) under the current node and the node reference count of the node, as well as whether there is a service subnet mask configuration information, that is, binary network address, subnet mask and next hop address and other information.

[0078] In a specific example, the specific parameters of the quadtree node entry structure are described as follows:

[0079] struct cfg_info_t*cfg: Whether the current node is successfully matched with the actual subnet mask configuration (configuration). A subnet mask is an actual configuration. If the cfg pointer is empty, it means that the match is not successful. If it is not empty, it means that the match is successful.

[0080] uint32_t refcnt: number of node references. Each time a subnet mask is added, 2 bits are used for each node. If the node does not exist, a new count of 1 is created. If it exists, the count is increased by 1. Each time a subnet mask is deleted, the node reference count is decreased by -1 when traversing each node. Then, it is determined whether the node reference count is 0. If the node reference count is 0, it means there are no other references, and the node memory can be released.

[0081] struct ip_tree_node*child[4]: an array of 4 child nodes of this node. The array index is a 2-bit value, which is 00, 01, 10, 11 in binary and 0, 1, 2, 3 in decimal.

[0082] 2) Quadtree root node entry:

[0083] Reference Figure 3 , is a schematic diagram of a quadtree root node entry structure design provided in an embodiment of the present invention;

[0084] The quadtree root node structure struct ip_tree_root_node records the actual number of subnet masks configured for the entire tree, the total number of quadtree nodes, and the root child node configuration.

[0085] In a specific example, the specific parameters of the quadtree root node entry structure are as follows: uint32_t cfg_num: the number of all current actual configurations. A subnet mask is an actual configuration, which is equivalent to the total number of subnet masks.

[0086] uint32_t node_num: the number of all current quadtree nodes. A subnet mask is 32 bits, and 2 bits is a quadtree node.

[0087] struct ip_tree_node root: root node member, the quadtree node is described in detail above struct ip_tree_node, please refer to Figure 2 .

[0088] In the specific implementation, when the quadtree memory configuration is loaded, the target IP address is stored in 32 bits in the memory, and the network number is obtained by logically ANDing the target IP address with the subnet mask. Every 2 bits are taken out as a node, and each node has four cases 00, 01, 10, and 11 to generate the quadtree. When the mask is an odd number, 2 nodes need to be added.

[0089] For example, suppose the configuration obtained is:

[0090] 1.1.1.1 / 8 (configuration 1)

[0091] 2.2.2.2 / 15 (Configuration 2)

[0092] Configure 1IP and mask: 0000 0001 0000 0001 0000 0001 0000 0001 / 8. The first 8 bits are valid 0000 0001. A node is added every 2 bits, for a total of 4 nodes.

[0093] Configure 2IP and mask: 0000 0010 0000 0010 0000 0010 0000 0010 / 15. The first 16 bits are valid 0000 0010 0000 0010. A node is added for every 2 bits. Since the mask is an odd number, there are 9 nodes in total.

[0094] If the above configuration 1 and configuration 2 are loaded into memory, the quadtree memory structure diagram can be as follows Figure 4 shown.

[0095] 3) Quadtree IP subnet mask matching process

[0096] In a specific embodiment of the present invention, referring to Figure 5 , is a schematic diagram of a quadtree IP subnet mask matching process provided in an embodiment of the present invention. After obtaining the target network address and at least one configuration (the configuration may include a subnet mask, an IP address, and a next hop address), the specific process steps may include:

[0097] 1) Determine whether the mask length of the subnet mask is an odd number.

[0098] 2) If the mask length is an even number, no special processing is required.

[0099] 3) If the mask length is an odd number, add 1 to the odd mask segment to change it to an even number.

[0100] 4) Take the first two bits of the target IP address as the child node subscript (node ​​identifier).

[0101] 5) Determine whether the mask length is 0.

[0102] 6) If the mask length in step 4 is 0, mark the node as configuration information. If the initial mask is an odd number, add 2 configuration node information, and then complete the configuration loading and exit.

[0103] 7) If the mask length in step 4 is not 0, determine whether the child node exists.

[0104] 8) If the child node in step 7 does not exist, create a new node with the node reference count = 1.

[0105] 9) If the child node in step 7 exists, the node reference count is increased by 1.

[0106] 10) Continue to take the next two digits of the target IP address as the child node index.

[0107] 11) Mask -2, then determine whether the mask is 0

[0108] 12) If the mask in step 11 is 0, mark the node as configuration information (matching node). If the initial mask is an odd number, add 2 configuration node information, and then complete the configuration loading and exit.

[0109] 12) If the mask in step 10 is not 0, enter the loop and go to step 5.

[0110] In an embodiment of the present invention, after the quadtree is generated, the configuration information in the matching nodes in the quadtree can be matched based on the maximum matching method to determine the matching configuration information, and then the data packet is forwarded according to the next hop address in the matching matching information.

[0111] The quadtree-based IO subnet mask matching method of the embodiment of the present invention is applied to a cloud network base, and the network elements such as EIP (Ethereum Improvement Proposals) and VGW (Virtual Private Gateway) in the cloud network base use this method to replace the traditional IP subnet mask matching method. Subnet mask configurations of 100, 500, 1000, 1500, 2000, 2500, and 3000 are used respectively to test the subnet mask matching method of the embodiment of the present invention and the traditional IP subnet mask matching method. Specifically, refer to Figure 6 , which is a comparison diagram of the subnet mask matching performance provided by an embodiment of the present invention, compares the performance of the embodiment of the present invention and the traditional IP subnet mask matching. Obviously, the subnet mask matching performance of the embodiment of the present invention is higher than that of the traditional IP subnet mask matching.

[0112] In summary, the quadtree-based IP subnet mask matching method proposed in the embodiment of the present invention has the following advantages and effects: high performance: the traditional IP subnet mask matching method will increase with the increase of configuration, and the number of matches will also increase linearly. When the configuration increases to a certain amount, the performance will become a bottleneck, resulting in the inability to add new services. The IP subnet mask matching method in the embodiment of the present invention only needs to match 16 times at most. This is because the IP address is 32 bits, and each node of the quadtree is represented by 2 bits, so there are four forms 00, 01, 10, and 11. In this way, even if all nodes of the quadtree are matching nodes, the number of nodes that need to be matched is at most 16, which is equivalent to no matter how many subnet mask configurations (configurations) there are, 16 searches will definitely have results, that is, the next hop address corresponding to the matching configuration is obtained to forward data packets, and the performance of subnet mask matching is unchanged and efficient.

[0113] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0114] Reference Figure 7 , is a structural block diagram of a data packet transmission device provided in an embodiment of the present invention, such as Figure 7 As shown, the device may specifically include the following modules:

[0115] The data packet receiving module 701 is used to obtain a data packet; the data packet includes a target network address;

[0116] A configuration acquisition module 702, configured to acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length;

[0117] A quadtree generation module 703, configured to generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include matching nodes that match the mask length, the matching nodes include configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address;

[0118] A quadtree traversal module 704, configured to traverse the quadtree and obtain configuration information of each matching node in the quadtree;

[0119] The address determination module 705 is used to match the network address and subnet mask in the configuration information of each matching node with the target network address, and use the next hop address in the configuration information that is successfully matched and the mask length meets the preset conditions as the next hop address of the data packet.

[0120] In one embodiment of the present invention, after acquiring at least one configuration according to the target network address, the apparatus further includes:

[0121] The target network address, the network address and the subnet mask are converted into binary versions of the network address and the subnet mask.

[0122] In one embodiment of the present invention, the quadtree generation module 703 is used to:

[0123] Sequentially obtain the first two bits of the target network address as node identifiers of nodes of the quadtree;

[0124] When the mask length of the subnet mask is zero, the node is marked as a matching node, and configuration information is stored in the matching node.

[0125] In one embodiment of the present invention, the quadtree generation module 703 is used to:

[0126] When the mask length of the subnet mask is not zero, determining whether the node corresponding to the node identifier exists in the quadtree;

[0127] If a node corresponding to the node identifier does not exist in the quadtree, creating a node for the node identifier in the quadtree, and creating a node reference count for the node;

[0128] If the node corresponding to the node identifier exists in the quadtree, increase the node reference count of the node corresponding to the node identifier;

[0129] Subtract two bits from the mask length, and return to the step of sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree.

[0130] In one embodiment of the present invention, the quadtree generation module 703 is used to:

[0131] Determine whether the mask length of the subnet mask is an odd number;

[0132] When the mask length of the subnet mask is an odd number, the mask length of the network portion is adjusted to an even number.

[0133] In one embodiment of the present invention, the quadtree generation module 703 is used to:

[0134] When the mask length of the subnet mask is an odd number, the node is marked as a matching node, a new matching node is added, and configuration information is stored in the matching node and the new matching node.

[0135] In an embodiment of the present invention, the preset condition is maximum mask matching.

[0136] In an embodiment of the present invention, a device obtains a data packet, which includes a target network address; obtains at least one configuration according to the target network address, the configuration may include a network address, a subnet mask and a next hop address, the subnet mask has a corresponding mask length, generates a quadtree according to the target network address and the mask length of the subnet mask, the generated quadtree includes a plurality of nodes, the nodes of the quadtree may include matching nodes that match the mask length, the matching nodes include configuration information, the configuration information includes the network address, the subnet mask and the next hop address, traverses the quadtree, obtains the configuration information in each matching node in the quadtree, matches the network address and the subnet mask in the configuration information of each matching node with the target network address, and uses the next hop address in the configuration information that is successfully matched and whose mask length meets a preset condition as the next hop address of the data packet, so that the data packet can be forwarded to the device corresponding to the next hop address. The embodiment of the present invention stores the target network address and the subnet mask configuration into a quadtree structure. In this way, the number of matches between the target network address and the subnet mask is the tree height of the quadtree. No matter how many subnet masks are configured (configured), the number of matches is related to the tree height of the quadtree. The maximum height of the quadtree is 16. Therefore, even if the subnet mask configuration increases linearly, the matching speed remains unchanged, thereby ensuring the performance of the subnet mask matching.

[0137] As for the above-mentioned device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0138] It should be noted that the embodiments of the present invention may involve the use of user data. In actual applications, user-specific personal data can be used in the scheme described herein within the scope permitted by applicable laws and regulations, subject to the requirements of applicable laws and regulations of the country where the user is located (for example, with the user's explicit consent, effective notification to the user, etc.).

[0139] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.

[0140] Memory 503, used for storing computer programs;

[0141] The processor 501 is used to implement any of the data packet transmission methods described in the above embodiments when executing the program stored in the memory 503:

[0142] Acquire a data packet; the data packet includes a target network address;

[0143] Acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length;

[0144] Generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include a matching node that matches the mask length, the matching node includes configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address;

[0145] Traversing the quadtree to obtain configuration information of each matching node in the quadtree;

[0146] The network address and subnet mask in the configuration information of each matching node are matched with the target network address, and the next hop address in the configuration information where the match is successful and the mask length meets the preset condition is used as the next hop address of the data packet.

[0147] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0148] The communication interface is used for communication between the above terminal and other devices.

[0149] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0150] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0151] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the computer-readable storage medium is executed on a computer, the computer executes the data packet transmission method described in any of the above embodiments.

[0152] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is executed on a computer, the computer executes the data packet transmission method described in any one of the above embodiments.

[0153] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0154] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or still includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0155] Each embodiment in this specification is described in a related 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 system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0156] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A data packet transmission method, characterized in that: The method comprises: Acquire a data packet; the data packet includes a target network address; Acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length; Generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include a matching node that matches the mask length, the matching node includes configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address; Traversing the quadtree to obtain configuration information of each matching node in the quadtree; The network address and subnet mask in the configuration information of each matching node are matched with the target network address, and the next hop address in the configuration information where the match is successful and the mask length meets the preset condition is used as the next hop address of the data packet.

2. The method according to claim 1, characterized in that After acquiring at least one configuration according to the target network address, the method further includes: The target network address, the network address and the subnet mask are converted into binary versions of the network address and the subnet mask.

3. The method according to claim 2, characterized in that Generating a quadtree according to the target network address and the mask length of the subnet mask, comprising: Sequentially obtain the first two bits of the target network address as node identifiers of nodes of the quadtree; When the mask length of the subnet mask is zero, the node is marked as a matching node, and configuration information is stored in the matching node.

4. The method according to claim 3, characterized in that Generating a quadtree according to the target network address and the mask length of the subnet mask, comprising: When the mask length of the subnet mask is not zero, determining whether the node corresponding to the node identifier exists in the quadtree; If a node corresponding to the node identifier does not exist in the quadtree, creating a node for the node identifier in the quadtree, and creating a node reference count for the node; If the node corresponding to the node identifier exists in the quadtree, increase the node reference count of the node corresponding to the node identifier; Subtract two bits from the mask length, and return to the step of sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree.

5. The method according to claim 3, characterized in that: Before sequentially obtaining the first two bits of the target network address as node identifiers of nodes of the quadtree, the method further includes: Determine whether the mask length of the subnet mask is an odd number; When the mask length of the subnet mask is an odd number, the mask length of the network portion is adjusted to an even number.

6. The method according to claim 3, characterized in that When the mask length of the subnet mask is zero, marking the node as a matching node, and after storing configuration information in the matching node, the method further includes: When the mask length of the subnet mask is an odd number, the node is marked as a matching node, a new matching node is added, and configuration information is stored in the matching node and the new matching node.

7. The method according to claim 1, characterized in that The default condition is maximum mask match.

8. A data packet transmission device, characterized in that: The device comprises: A data packet acquisition module, used to acquire a data packet; the data packet includes a target network address; A configuration acquisition module, configured to acquire at least one configuration according to the target network address; the configuration includes a network address, a subnet mask and a next hop address; the subnet mask has a corresponding mask length; A quadtree generation module, configured to generate a quadtree according to the target network address and the mask length of the subnet mask; the quadtree includes a plurality of nodes; the nodes include a matching node that matches the mask length, the matching node includes configuration information, and the configuration information includes a network address, a subnet mask, and a next hop address; A quadtree traversal module, used for traversing the quadtree and obtaining configuration information of each matching node in the quadtree; The address determination module is used to match the network address and subnet mask in the configuration information of each matching node with the target network address, and use the next hop address in the configuration information that is successfully matched and the mask length meets the preset conditions as the next hop address of the data packet.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.