A route matching method for IPv6 subnet
Through the combination of hash table and linked list structure, the problem of increased search times caused by the expansion of prefix length in IPv6 subnet route matching is solved, efficient route matching and memory management are achieved, and forwarding performance and memory utilization are improved.
Patent Information
- Application Number
- CN202310232074.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-12
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2043-03-12
AI Technical Summary
During the IPv6 subnet route matching process, due to the expansion of the prefix length and the increase in the number of lookups, the forwarding performance is low and cannot meet the high bandwidth requirements of the network.
Using a hash table structure, the IPv6 prefix is divided into 16 segments with a step size of 8. Each segment implements O(1) search, and the start mask of the configured prefix segment is recorded through a linked list, and the mask length is from long to Short sorting reduces the number of table lookups and improves forwarding performance.
Significantly improves table lookup performance, reduces memory overhead, supports VPC subnet table-level expansion, improves memory utilization, and saves memory overhead.
Smart Images

Figure CN116366548B
Abstract
Description
Technical Field
[0001] The invention relates to the field of routing forwarding in data communication, and in particular to an IPv6 subnet routing matching method. Background Art
[0002] In recent years, with the rapid advancement of IPv6 networks, cloud computing virtual networks also need to deploy IPv6 protocol stacks. In virtual cloud networks based on soft forwarding, the IPv6 address prefix length is as long as 128 bits. When performing subnet scenario matching routing forwarding, the data structure and matching method are key factors affecting the table lookup performance and forwarding performance.
[0003] In virtual cloud networks, common IPv6 subnet route matching methods are as follows: 1) The kernel uses a binary tree structure, and any route forwarding requires up to hundreds of lookups, which has very low performance; 2) Some open source framework designs use a hash structure, which traverses all prefixes one by one to search, which also requires dozens of O(1) searches, and has low performance.
[0004] In summary, in the IPv6 subnet route matching process, due to the increase in prefix length, the number of lookups generally increases, which greatly reduces the lookup performance and cannot guarantee the forwarding performance and high network bandwidth requirements. Summary of the invention
[0005] In view of this, the present invention proposes an IPv6 subnet route matching method, which adopts a hash table structure, divides the prefix into 16 segments with a step size of 8, and implements O(1) search for each segment; records the starting mask of the configured prefix segment through a linked list, sorts the masks in the linked list from long to short, and traverses them sequentially during search, thereby further reducing the number of table lookups and improving forwarding performance; redesigns the table entry structure, and solves the problem of large memory overhead caused by VPC subnet table-level expansion through the design of dynamically allocating hash tables and prefix bitmaps.
[0006] In a first aspect, the present invention provides an IPv6 subnet route matching method, characterized in that the method comprises the following steps:
[0007] S1, match the host route with mask 128 in the hash table, return the index value after the match is completed, and determine whether the index value is 0. If so, execute step S2, otherwise execute step S3;
[0008] S2, sequentially traverse the mask linked list, continue to use shorter masks to search, if the match is successful, execute step S3, otherwise execute step S4;
[0009] S3, end the route search and forward the message according to the route next hop information;
[0010] S4, perform packet loss processing on the message.
[0011] Furthermore, the host route matching mask 128 includes using mask mask and ip to calculate a hash value, hash(ip&mask). If the hash value does not match the corresponding hash bucket entry, the index value is assigned to 0, otherwise the index value is assigned to entry->index.
[0012] Furthermore, in step S2, the mask linked list only stores configured masks and only records the starting mask of the prefix segment where the mask is located; during the routing configuration process, the masks are sorted when inserted into the linked list and inserted in order from long to short.
[0013] Furthermore, step S2 comprises the following sub-steps:
[0014] S21, use the mask and IP to perform hash calculation, match the calculated hash value with the hash bucket entry, if the match fails, assign the index value to 0 and go to step S23, otherwise assign the index value to entry->index and go to step S22;
[0015] S22, first get the index of the route corresponding to the starting mask, and then further search whether the IP with the longest mask is configured in this mask segment. If the IP with the longest mask is configured, update the route index and return the index value;
[0016] S23, determine whether the index is 0, if so, execute S4, otherwise execute S3.
[0017] In a second aspect, the present invention provides a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0018] The memory is used to store at least one executable program, and the executable program enables the processor to perform operations corresponding to the aforementioned IPv6 subnet route matching method.
[0019] The IPv6 subnet routing matching method proposed in the present invention has the following advantages and effects by redesigning the data structure layout and matching search method:
[0020] 1. The main structure of the method proposed in the present invention is a hash table, which is lightweight in memory, easy to expand at the massive table level, and can be flexibly applied to VPC subnet scenarios;
[0021] 2. The method proposed in the present invention divides the prefix into prefix segments with a step size of 8, and each prefix segment is searched in O(1) routing. Compared with any prefix traversal scenario, the table lookup performance is improved by 16 times;
[0022] 3. The method proposed in the present invention designs a mask linked list to record the configured masks, and only needs to identify the starting prefix corresponding to the mask. The table lookup process reduces the matching process of invalid masks, further reduces the number of table lookups, and compares the sequential matching method to further improve the table lookup performance by 6 times.
[0023] 4. In the method proposed by the present invention, the IP routing index covered by the intra-segment prefix in each prefix segment is dynamically allocated based on the prefix configuration, thereby improving memory utilization and saving memory overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly explain the technical solutions in the present invention or the prior art, the drawings required for the description of the present invention or the prior art are briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 It is the ipv6 route matching process;
[0026] Figure 2 It is a hash table structure;
[0027] Figure 3 It is the table item structure;
[0028] Figure 4 Divide into prefix segments;
[0029] Figure 5 Add a process to the table item;
[0030] Figure 6 Delete the process for the table item. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two.
[0033] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0034] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0035] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a product or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such a product or system. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the product or system including these elements.
[0036] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0037] As attached Figure 1 As shown, the present invention provides an IPv6 subnet route matching method, the method comprising the following steps:
[0038] S1, match the 128-bit mask host route in the hash table, return the index value after the match is completed, and determine whether the index value is 0. If so, execute step S2, otherwise execute step S3.
[0039] The host route matching mask 128 includes using mask mask and ip to calculate a hash value, hash(ip&mask). If the hash value does not match the corresponding hash bucket entry, the index value is assigned to 0, otherwise the index value is assigned to entry->index.
[0040] The hash table structure is shown in the attached Figure 2 The hash table entry structure design is shown in the attached Figure 3 shown.
[0041] The table entry is obtained by hashing the starting prefix of the prefix segment where the IP and prefix are located. The table entry stores the index of the routing information of the current IP and all IPs in the corresponding prefix segment. In each prefix segment, the hash value is calculated based on the IP address after the starting prefix mask through the hash function algorithm, and is used as an index to search the hash table.
[0042] The prefix segment is divided as shown in the attached Figure 4 As shown in the figure, the prefix 128 is divided into segments with a step size of 8. The IPv6 address is divided into 16 segments, namely ipv6
[16] . When the prefix is less than 128, the prefix in each segment will cover the range of ipv6[prefix / 8].
[0043] The following is a description of the specific parameters of the hash table item structure:
[0044] List node: Associated with next node, used to resolve hash conflicts.
[0045] Ipv6 addr: Calculates the prefix range based on the configured prefix. This value is the starting prefix in the prefix range plus the IP address value after the configured IP mask.
[0046] Starting prefix table entry index: The table entry index value of the starting prefix corresponding to the IP in the prefix segment, the actual memory location of the index table entry. If the starting prefix of this IP is not configured in the prefix segment, this value is an illegal value of 0, otherwise, this value is a legal value.
[0047] ip_bit structure pointer: dynamically allocates memory according to the configured prefix, stores all table entry indexes of the IPs covered in the prefix segment corresponding to the above starting prefix (with a step length of 8, it covers a maximum of 255 IP ranges in the prefix segment), and is used to quickly index the IP range of the entire prefix segment during forwarding. The structure stores the table entry indexes and prefixes of all IPs in the prefix segment corresponding to the current IP. Memory is dynamically allocated only when the mask of a non-starting prefix in the mask segment is configured.
[0048] Prefix segment mask linked list: dynamically allocated according to the configured prefix, stores all the prefixes and table entry indexes in the segment where the current IP is located, mainly used for iterative coverage of addition and deletion.
[0049] Number of prefix segment mask linked lists: The number of nodes configured in the prefix segment of the current IP, which is used as a dynamic releasable mark for the mask linked list. When prefix is 128, there is no ip_bit structure pointer and mask linked list.
[0050] Table entry index: Use index to point to the memory structure of routing entity information, making the table entry structure lightweight. At the same time, routing information is designed as a global memory pool, which is shared by all tables, effectively improving memory utilization and facilitating the planning of machine specifications.
[0051] S2, sequentially traverse the mask linked list, continue to use a shorter (eg: 120 bits) mask to search, if the match is successful, execute step S3, otherwise execute step S4.
[0052] In order to reduce the number of lookups, a mask linked list is designed in each routing table. The linked list only stores configured masks and only records the starting mask of the prefix segment where the mask is located. During the routing configuration process, the masks are sorted when inserted into the linked list, and inserted in order from long to short to facilitate subsequent lookups.
[0053] In the full mask case, the linked list only needs to record a maximum of 16 masks, and usually, commonly used masks only use a few of the possible ones, such as the common 56, 64, 96, 112, 120, 128 bits, etc.
[0054] Since this mask linked list only records the starting prefix of the mask segment where the configured mask is located, such as 56 / 64 / 112 / 120, and the masks are sorted in a linked list from large to small, in the case of a universal full mask, a maximum of only 16 searches are required.
[0055] S21, use the mask of the mask linked list and the IP to perform hash calculation, match the calculated hash value with the hash bucket entry, if the match fails, assign the index value to 0 and go to step S23, otherwise assign the index value to entry->index and go to step S22.
[0056] S22, first get the index of the route corresponding to the starting mask, and then further search whether the IP with the longest mask is configured in this mask segment. If the IP with the longest mask is configured, update the route index and return the index value.
[0057] S23, determine whether the index is 0, if so, execute S4, otherwise execute S3.
[0058] S3, end the route search and forward the message according to the route next hop information.
[0059] S4, perform packet loss processing on the message.
[0060] If the sequential traversal ends and there is still no routing index match, the packet is discarded.
[0061] The present invention also includes a hash table preconfiguration step before step S1.
[0062] The pre-configuration includes a table entry adding / updating process and a table entry deleting process.
[0063] 1) Table item adding process, table item adding / updating process is as shown in the attached Figure 5 shown.
[0064] When configuring a routing entry, configure the IP address and prefix at the same time. According to the prefix segment where the prefix mapping is located, the IP address is masked according to the starting prefix in the segment, and after calculating the hash value, it is determined whether there is an entry in the index hash bucket. Based on whether the hash bucket is empty, the predetermined configuration operations are performed respectively.
[0065] When the hash bucket is empty, it indicates that the starting prefix of the prefix segment corresponding to the current IP and prefix is not configured. At this time, the hash bucket table entry memory is directly allocated. If the prefix value is the starting prefix of the prefix segment at this time, the starting prefix table entry index is directly updated to a legal non-zero value. If the prefix value is not the starting prefix of the prefix segment at this time, the ip_bit structure memory is allocated, and the IP segment range that can be covered by the prefix in the segment is calculated based on the prefix. For the possible covered IP (a maximum of 256 IPs in the segment), the table entry index is updated to a legal non-zero value, and the mask linked list and the number of nodes in the mask linked list are updated.
[0066] When the hash bucket is not empty, it indicates that the starting prefix of the prefix segment corresponding to the current IP and prefix has been configured. It is necessary to check and distinguish the IP range that this prefix and the configured prefix can cover. If the prefix value is the starting prefix of the prefix segment at this time, the table entry index of the starting prefix is directly updated. If the prefix value is not the starting prefix of the prefix segment at this time, check whether the ip_bit structure memory has been allocated. If not, directly allocate the ip_bit structure memory. If it has been allocated, it is necessary to compare and check the size of the configured mask and the current prefix in the ip_bit structure. At this time, traverse the IP segment covered by the current prefix. Only when the current prefix is greater than or equal to the configured mask, update the table entry index to avoid incorrect coverage. Then traverse and update the mask linked list and the number of mask linked list nodes.
[0067] 2) Item deletion process, the item deletion process is as follows Figure 6 shown.
[0068] When deleting a route entry, it is also based on the IP address and prefix. First, the prefix segment where the prefix is mapped is used. According to the starting prefix in the segment, the IP address is masked, the hash value is calculated, and then the hash bucket is searched to see if there is an entry.
[0069] If the entry in the hash bucket does not exist, the flag is not configured.
[0070] If the entry in the hash bucket exists, check the prefix further. When prefix is the starting prefix of the corresponding prefix segment, directly update the starting prefix entry index in the entry to the illegal value 0. If the prefix is not the starting prefix of the corresponding prefix segment, traverse the mask linked list. If it is not found in the mask linked list, it indicates that this prefix is not configured and returns success directly. If it is found in the mask linked list, it indicates that it has been configured. Continue to find whether a prefix smaller than this prefix is configured. The index of this prefix segment needs to be overwritten with the index of the configured short prefix. Then traverse the corresponding IP range in the prefix segment where the prefix is located and update the corresponding entry index. Finally, check whether the ip_bit structure and hash bucket entry need to be released. When the number of mask linked list nodes is 0, release ip_bit. When ip_bit has been released and the entry index of the starting prefix in the entry is 0, release the memory of this hash bucket entry.
[0071] The method proposed in the present invention adopts a hash table as the main structure, and the table structure solves hash conflicts by dynamically allocating linked list nodes. Due to the light memory overhead of the table structure, it can be flexibly applied to tenant-isolated subnets and subnet routing scenarios, and supports massive table-level and table item expansion.
[0072] The present invention also provides a computer device. The computer device is in the form of a general-purpose computing device. The components of the computer device may include but are not limited to: one or more processors or processing units, a system memory, and a bus connecting different system components.
[0073] Computer devices typically include a variety of computer system readable media. These media can be any available media that can be accessed by the computer device, including volatile and non-volatile media, removable and non-removable media.
[0074] The system memory may include a computer system readable medium in the form of volatile memory. The memory may include at least one program product having a set (eg, at least one) of program modules configured to perform the functions of various embodiments of the present invention.
[0075] The processing unit executes various functional applications and data processing by running programs stored in the system memory, such as implementing the methods provided in other embodiments of the present invention.
[0076] The present invention also provides a storage medium containing computer executable instructions, on which a computer program is stored. When the program is executed by a processor, the method provided by other embodiments of the present invention is implemented.
[0077] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A matching method for IPv6 subnet routing, It is characterized in that The method comprises the following steps: S1, match the host route with mask 128 in the hash table, return the index value after the match, and determine whether the index value is 0. If so, execute step S2, otherwise execute step S3; the host route matching mask 128 includes calculating the hash value using mask mask and ip. If the hash value does not match the corresponding hash bucket entry, the index value is assigned to 0, otherwise the index value is assigned to entry->index; the specific parameters of the hash table structure are: List node: associated with next node, used to resolve hash conflicts; ipv6 addr: the starting prefix in the prefix segment and the IP address value after the configured IP mask; Starting prefix table entry index: the table entry index value of the starting prefix corresponding to the IP in the prefix segment, the actual memory location of the index table entry; ip_bit structure pointer: This memory is dynamically allocated according to the configured prefix to store all table entry indexes of the IP covered in the prefix segment corresponding to the above starting prefix; Prefix segment mask linked list: dynamically allocated according to the configured prefix, storing all configured prefixes and table entry indexes in the prefix segment where the current IP is located; Number of prefix segment mask linked lists: the number of nodes configured with prefixes in the current IP prefix segment; Table entry index: The index used in the table entry points to the memory of the routing entity information; The prefix segment division method is as follows: when dividing, the prefix 128 is divided into segments with a step length of 8; the IPv6 address is divided into 16 segments, namely IPv6[16]; when the prefix is less than 128, the prefix in each segment will cover the range of IPv6[prefix / 8] respectively; S2, sequentially traverse the mask chain list, continue to use shorter masks for searching, if the match is successful, execute step S3, otherwise execute step S4; in step S2, the mask chain list only stores the configured masks, and only records the starting mask of the prefix segment where the mask is located; in the routing configuration process, the masks are sorted when inserted into the chain list, and are inserted in order from long to short; step S2 includes the following sub-steps: S21, use the mask of the mask linked list and the IP to perform hash calculation, match the calculated hash value with the hash bucket entry, if the match fails, assign the index value to 0 and go to step S23, otherwise assign the index value to entry->index and go to step S22; S22, first get the index of the route corresponding to the starting mask, and then further search whether the IP with the longest mask is configured in this mask segment. If the IP with the longest mask is configured, update the route index and return the index value; S23, determine whether the index is 0, if so, execute S4, otherwise execute S3; S3, end the route search and forward the message according to the route next hop information; S4, perform packet loss processing on the message.
2. The method according to claim 1, Features , before step S1, it also includes hash table pre-configuration; the pre-configuration includes table entry adding / updating process and table entry deleting process.
3. The method according to claim 2, Features ,The table entry adding / updating process includes: When configuring a routing entry, configure the IP address and prefix at the same time. According to the prefix segment where the prefix mapping is located, according to the starting prefix in the segment, mask the IP address, calculate the hash value, and determine whether there is an entry in the index hash bucket. Based on whether the hash bucket is empty, perform the predetermined configuration operations.
4. The method according to claim 2, Features ,The table entry deletion process includes: When deleting a routing entry, first mask the IP address according to the prefix segment where the prefix mapping is located and the starting prefix in the segment, calculate the hash value, and then determine whether there is an entry in the index hash bucket. Perform the predetermined configuration operations based on whether the hash bucket is empty.
5. A computing device, include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable program, and the executable program enables the processor to perform operations corresponding to the routing matching method for an IPv6 subnet as described in any one of claims 1-4.
Citation Information
Patent Citations
Fast indexing method
CN1852238A
Jump on a Match Optimization for Longest Prefix Match using a Binary Search Tree
US20170366459A1
