CN117221224A - Table item construction and search method and device, network equipment and storage medium - Google Patents

Table item construction and search method and device, network equipment and storage medium Download PDF

Info

Publication number
CN117221224A
CN117221224A CN202311483639.5A CN202311483639A CN117221224A CN 117221224 A CN117221224 A CN 117221224A CN 202311483639 A CN202311483639 A CN 202311483639A CN 117221224 A CN117221224 A CN 117221224A
Authority
CN
China
Prior art keywords
value
prefix
entry
mapping
lookup table
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202311483639.5A
Other languages
Chinese (zh)
Other versions
CN117221224B (en
Inventor
杨逸
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Gechuang Communication Zhejiang Co ltd
Original Assignee
Gechuang Communication Zhejiang Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Gechuang Communication Zhejiang Co ltd filed Critical Gechuang Communication Zhejiang Co ltd
Priority to CN202311483639.5A priority Critical patent/CN117221224B/en
Publication of CN117221224A publication Critical patent/CN117221224A/en
Application granted granted Critical
Publication of CN117221224B publication Critical patent/CN117221224B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiment of the application provides a method, a device, network equipment and a storage medium for constructing and searching table items, which relate to the technical field of communication and comprise the following steps: acquiring a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value; storing a first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in a first-stage lookup table, wherein the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value and the first mapping value are in one-to-one correspondence; and storing the first mapping value, the first identification value and the search result into a second table entry in the second-level lookup table. By applying the technical scheme provided by the embodiment of the application, the storage space required by the lookup table is reduced, and the hardware cost is reduced.

Description

Table item construction and search method and device, network equipment and storage medium
Technical Field
The present application relates to the field of communications technologies, and in particular, to a method and apparatus for constructing and searching a table entry, a network device, and a storage medium.
Background
The network device adopts a table entry searching mode to acquire the relevant information of the IP (Internet Protocol ) address. Currently, to achieve accurate lookup, the complete IP address is stored in the table entry as a key (key value) for the table entry lookup. However, the length of the IP address is relatively large, for example, the length of the IPv6 (Internet Protocol Version, internet protocol version 6) address is 128bits, which makes the space occupied by the key in the table entry relatively large. The problem that the space occupied by the key is larger is more prominent by combining a large number of table entries in the lookup table, so that a memory with larger storage space is needed to store the lookup table, and the hardware cost is higher.
Disclosure of Invention
The embodiment of the application aims to provide a table entry construction and search method, a device, network equipment and a storage medium, so as to reduce the storage space required by a lookup table and reduce the hardware cost. The specific technical scheme is as follows:
in a first aspect of an embodiment of the present application, there is provided a method for constructing an entry, the method including:
acquiring a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value;
storing the first prefix value and a first mapping value corresponding to the first prefix value into a first table entry in a first-level lookup table, wherein a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value and the first mapping value are in one-to-one correspondence;
storing the first mapping value, the first identification value and the search result to a second table entry in a second-level lookup table, wherein a key value field of the second table entry stores the first mapping value and the first identification value, and a result field of the second table entry stores the search result.
In some embodiments, the step of storing the first prefix value and the first mapping value corresponding to the first prefix value into a first entry in a first level lookup table includes:
calculating a first hash value of the first prefix value;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in a first-stage lookup table according to a first target position indicated by the first hash value in the first-stage lookup table.
In some embodiments, the step of storing the first prefix value and the first mapping value corresponding to the first prefix value to the first entry in the first level lookup table according to the first target location indicated by the first hash value in the first level lookup table includes:
if the table entry at the first target position indicated by the first hash value in the first-level lookup table is unoccupied, taking the table entry at the first target position as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
In some embodiments, the step of storing the first prefix value and the first mapping value corresponding to the first prefix value to the first entry in the first level lookup table according to the first target location indicated by the first hash value in the first level lookup table includes:
If the table entry at the first target position indicated by the first hash value in the first-level lookup table is occupied, matching the first prefix value with a second prefix value stored in the table entry at the first target position;
if the matching fails, an unoccupied table entry is distributed in the first-stage lookup table and is used as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
In some embodiments, the method further comprises:
and if the matching is successful, taking the second mapping value stored in the table entry at the first target position as the first mapping value, and executing the step of storing the first mapping value, the first identification value and the search result into a second table entry in a second-level lookup table.
In some embodiments, the step of storing the first mapping value and the first identification value, the lookup result, to a second entry in a second level lookup table includes:
calculating a second hash value of the first mapping value and the first identification value;
and storing the first mapping value, the first identification value and the search result to a second table entry in a second-level lookup table according to a second target position indicated by the second hash value in the second-level lookup table.
In some embodiments, the step of storing the first mapping value, the first identification value, and the lookup result to a second entry in a second level lookup table according to a second target location indicated by the second hash value in the second level lookup table includes:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is not occupied, taking the table entry at the second target position as a second table entry;
and storing the first mapping value, the first identification value and the search result to the second table entry.
In some embodiments, the step of storing the first mapping value, the first identification value, and the lookup result to a second entry in a second level lookup table according to a second target location indicated by the second hash value in the second level lookup table includes:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, distributing unoccupied second table entries in the second-level lookup table;
and storing the first mapping value, the first identification value and the search result to the second table entry.
In some embodiments, the first mapping value of 2 is greater than or equal to the total number of prefix values supported by the local device.
In some embodiments, the first prefix value is a value of a network prefix, and the first identification value is a value of an interface identification.
In a second aspect of the embodiment of the present application, there is provided a method for searching an entry, the method including:
acquiring a target IP address, wherein the target IP address comprises a target prefix value and a target identification value;
searching a target mapping value corresponding to the target prefix value from each table item of a first-level lookup table, wherein the first-level lookup table is constructed according to the table item construction method of the first aspect;
and searching target searching results corresponding to the target mapping value and the target identification value from each table item of a second-level searching table, wherein the second-level searching table is constructed according to the table item construction method of the first aspect.
In a third aspect of the embodiment of the present application, there is provided an entry construction apparatus, including:
the first acquisition module is used for acquiring a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value;
The first storage module is used for storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in a first-stage lookup table, wherein a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value corresponds to the first mapping value one by one;
the second storage module is configured to store the first mapping value, the first identification value, and the search result to a second table entry in a second level lookup table, where a key value field of the second table entry stores the first mapping value and the first identification value, and a result field of the second table entry stores the search result.
In some embodiments, the first storage sub-module includes:
a first computing sub-module for computing a first hash value of the first prefix value;
and the first storage sub-module is used for storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in the first-stage lookup table according to the first target position indicated by the first hash value in the first-stage lookup table.
In some embodiments, the first storage sub-module is specifically configured to:
if the table entry at the first target position indicated by the first hash value in the first-level lookup table is unoccupied, taking the table entry at the first target position as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
In some embodiments, the first storage sub-module is specifically configured to:
if the table entry at the first target position indicated by the first hash value in the first-level lookup table is occupied, matching the first prefix value with a second prefix value stored in the table entry at the first target position;
if the matching fails, an unoccupied table entry is distributed in the first-stage lookup table and is used as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
In some embodiments, the first storage sub-module is further configured to:
and if the matching is successful, taking the second mapping value stored in the table entry at the first target position as the first mapping value, and executing the step of storing the first mapping value, the first identification value and the search result into a second table entry in a second-level lookup table.
In some embodiments, the second storage module comprises:
a second computing sub-module, configured to compute a second hash value of the first mapping value and the first identification value;
and the second storage sub-module is used for storing the first mapping value, the first identification value and the search result to a second table entry in the second-stage lookup table according to a second target position indicated by the second hash value in the second-stage lookup table.
In some embodiments, the second storage sub-module is specifically configured to:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is not occupied, taking the table entry at the second target position as a second table entry;
and storing the first mapping value, the first identification value and the search result to the second table entry.
In some embodiments, the second storage sub-module is specifically configured to:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, distributing unoccupied second table entries in the second-level lookup table;
and storing the first mapping value, the first identification value and the search result to the second table entry.
In some embodiments, the first mapping value of 2 is greater than or equal to the total number of prefix values supported by the local device.
In some embodiments, the first prefix value is a value of a network prefix, and the first identification value is a value of an interface identification.
In a fourth aspect of the embodiment of the present application, there is provided an entry lookup apparatus, including:
the second acquisition module is used for acquiring a target IP address, wherein the target IP address comprises a target prefix value and a target identification value;
a first lookup module, configured to find a target mapping value corresponding to the target prefix value from each entry in a first-level lookup table, where the first-level lookup table is constructed according to the entry construction apparatus described in the third aspect;
and the second lookup module is used for searching the target lookup result corresponding to the target mapping value and the target identification value from each table item of a second-level lookup table, and the second-level lookup table is constructed according to the table item construction device in the third aspect.
In a fifth aspect of the embodiments of the present application, there is provided a network device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
A memory for storing a computer program;
a processor configured to implement the method steps of any one of the first or second aspects when executing a program stored on a memory.
In a sixth aspect of the embodiments of the present application, there is provided a computer readable storage medium having stored therein a computer program which when executed by a processor implements the method steps of any of the first or second aspects described above.
The embodiment of the application has the beneficial effects that:
in the technical scheme provided by the embodiment of the application, an IP address is divided into two parts of a prefix value and an identification value, and a one-to-one correspondence relation is established between the prefix value with higher repeatability and the mapping value with smaller length and is stored in a first-stage lookup table; and then storing the mapping value, the identification value and the corresponding relation of the search result into a second-stage lookup table. On the one hand, the prefix values of the plurality of IP addresses may be the same, i.e. the plurality of IP addresses can multiplex the entries in one first-level lookup table without repeatedly storing the same prefix value; in the two aspects, the length of the mapping value is smaller, the short mapping value is used for replacing the long prefix value, and the storage space occupied by the key value field in the second-stage lookup table is greatly reduced, so that the storage space required by the lookup table is reduced, and a memory with smaller storage space can be used for storing the lookup table, and the hardware cost is reduced.
Of course, it is not necessary for any one product or method of practicing the application to achieve all of the advantages set forth above at the same time.
Drawings
In order to more clearly illustrate the embodiments of the application or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the application, and other embodiments may be obtained according to these drawings to those skilled in the art.
FIG. 1 is a first flowchart of a method for constructing an entry according to an embodiment of the present application;
FIG. 2 is a second flowchart of a method for constructing an entry according to an embodiment of the present application;
FIG. 3 is a third flow chart of a method for constructing an entry according to an embodiment of the present application;
FIG. 4 is a fourth flowchart of a method for constructing an entry according to an embodiment of the present application;
FIG. 5 is a fifth flowchart of a method for constructing an entry according to an embodiment of the present application;
FIG. 6 is a sixth flowchart of a method for constructing an entry according to an embodiment of the present application;
FIG. 7 is a schematic flow chart of a method for searching table entries according to an embodiment of the present application;
FIG. 8 is a schematic structural diagram of an entry construction device according to an embodiment of the present application;
FIG. 9 is a schematic structural diagram of an entry lookup apparatus according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a network device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. Based on the embodiments of the present application, all other embodiments obtained by the person skilled in the art based on the present application are included in the scope of protection of the present application.
The network device adopts a table entry searching mode to acquire the relevant information of the IP address, namely a searching result, wherein the searching result can be set according to actual requirements, for example, the searching result can be an output interface identifier, a destination IP address, a transmission protocol and the like of the message.
A more common table entry lookup method is to look up a table by a hash algorithm. Taking an IPv4 (Internet Protocol Version, internet protocol version 4) FIB (Forwarding Information Base, forwarding information table) as an example, the network device supports FIB of 1M (mega) specification, the number of IPv4 addresses reaches 4G (gigabit), and the possible value space of 4G is compressed into the possible value space of 1M by a hash algorithm, where each value corresponds to an entry in FIB. The method can store a limited number of IPv4 addresses supported by the network device in the FIB, but brings about hash conflict, namely, a plurality of IPv4 addresses correspond to the same value (hash value) of a hash algorithm, which causes the problem that a required search result, namely, false positive, cannot be accurately found.
In order to eliminate the possible false positive problem caused by the hash collision, each table item in the FIB is divided into a key field and a value field, wherein the key field stores a complete IPv4 address, and the value field stores a search result. Therefore, when one table item is hit through the hash value, the search result can be accurately obtained through one-time accurate matching of the key field value, and the hash conflict is eliminated.
However, the length of the IP address is relatively large, for example, the length of the IPv4 address is 32bits and the length of the IPv6 address is 128bits. Taking an IPv6 address as an example, when the FIB takes the IPv6 address as a key field value, in the case that the network device supports a FIB of 1M specification, only the key field stores a storage space occupied by one IPv6 address, and then 128bits×1m=16m Bytes (Bytes) is reached. Further, in some cases, the key field of the lookup table needs to store a plurality of IPv6 addresses, for example, the source IPv6 address and the destination IPv6 address need to be stored in the flow table, and in this case, in the case that the network device supports the FIB with 1M specification, the storage space occupied by storing two IPv6 addresses in the key field only reaches 2×128bits×1m=32m Bytes.
The key field of the lookup table occupies a relatively large space, which requires a memory with a relatively large memory space to store the lookup table, and the hardware cost is relatively high. When the chip realizes the acceleration of table lookup, the table contents are stored in SRAM (Static Random Access Memory ), and 16-32M Bytes of SRAM is too expensive, and the hardware cost is higher.
In order to reduce the storage space required by the lookup table and reduce the hardware cost, the embodiment of the application provides a table item construction method which can be applied to network equipment such as a mobile terminal, a server, a switch, a router and the like.
Referring to fig. 1, fig. 1 is a schematic flow chart of a table entry construction method according to an embodiment of the present application, where the method includes the following steps.
Step S11, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value.
Step S12, storing the first prefix value and a first mapping value corresponding to the first prefix value into a first table item in a first-stage lookup table, wherein a key value field of the first table item stores the first prefix value, a result field of the first table item stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value corresponds to the first mapping value one by one.
Step S13, storing the first mapping value, the first identification value and the search result into a second table item in the second-stage search table, wherein a key value field of the second table item stores the first mapping value and the first identification value, and a result field of the second table item stores the search result.
In the technical scheme provided by the embodiment of the application, an IP address is divided into two parts of a prefix value and an identification value, and a one-to-one correspondence relation is established between the prefix value with higher repeatability and the mapping value with smaller length and is stored in a first-stage lookup table; and then storing the mapping value, the identification value and the corresponding relation of the search result into a second-stage lookup table. On the one hand, the prefix values of the plurality of IP addresses may be the same, i.e. the plurality of IP addresses can multiplex the entries in one first-level lookup table without repeatedly storing the same prefix value; in the two aspects, the length of the mapping value is smaller, the short mapping value is used for replacing the long prefix value, and the storage space occupied by the key value field in the second-stage lookup table is greatly reduced, so that the storage space required by the lookup table is reduced, and a memory with smaller storage space can be used for storing the lookup table, and the hardware cost is reduced.
In the step S11, the first IP address may be any IPv6 address or any IPv4 address. The first IP address includes a prefix value (i.e., a first prefix value) and an identification value (i.e., a first identification value), where the first prefix value may be a value of a first preset number of bits before the first IP address, and the first identification value may be a value of a second preset number of bits after the first IP address, where the first prefix value of the first preset number of bits and the first identification value of the second preset number of bits constitute the first IP address.
In the embodiment of the application, the prefix value can be the value of the network prefix, and the identification value can be the value of the interface identification. When the prefix value of the second IP address is the same as that of the first IP address, the identification value of the second IP address is different from that of the first IP address, and if the prefix value and the identification value are the same, the same IP address is obtained. The network prefix is the network segment. The lookup result may include an interface identification, a forwarding path identification, a processor identification, and so on. The correspondence between the first IP address and the search result needs to be stored with entries for searching. The network device may obtain, from other devices or its own memory, the first IP address and the search result that need to be stored using the table entry.
In the step S12, the first-level lookup table may be a linked list, a table or other forms of tables. When the first-level lookup table is a linked list, one table item in the first-level lookup table can be a node in the linked list; when the first level lookup table is a table, one entry in the first level lookup table may be a row or a column in the table. The entries in the first level lookup table include a key value field, which may store a prefix value, and a result field, which may store a mapping value, such as a cookie value. The mapping value may be a binary number, and the length of the mapping value is smaller than the length of the prefix value, for example, the prefix value is 96bits, and the mapping value is 20bits.
In the embodiment of the present application, the length power of the mapping value of 2 is greater than or equal to the total number of prefix values supported by the local device, where the local device is a device storing the first IP address, that is, the network device. For example, the total number of prefix values supported by the network device is 64K (thousands), the length of the mapping value is x, then 2 x Should be greater than 64K,2 15 =32768<64K,2 16 =65536>64K, x may be any natural number greater than or equal to 16.
In the embodiment of the application, the prefix values and the mapping values are in one-to-one correspondence, and for two IP addresses with the same prefix value, the two IP addresses correspond to the same mapping value.
In the embodiment of the application, the network device can acquire the first mapping value corresponding to the first prefix value, determine the table item corresponding to the first IP address in the first-stage lookup table, namely the first table item, store the first prefix value in the key value field of the first table item, and store the first mapping value in the result field of the first table item.
In the embodiment of the application, for two IP addresses with the same prefix value, the mapping values corresponding to the two IP addresses are the same, and the two IP addresses can multiplex the same table entry, so that the number of the table entries stored in the first-stage lookup table is far smaller than the number of all the IP addresses to be stored for all the IP addresses to be stored. For example. The network device needs to store 1M different IP addresses, where the 1M different IP addresses have 64K different prefix values, and only 64K entries in the first-stage lookup table are needed, which makes the storage space occupied by the first-stage lookup table smaller.
In the step S13, the second level lookup table may be a linked list, a table or other forms of tables. When the second-level lookup table is a linked list, one table item in the second-level lookup table can be one node in the linked list; when the second level lookup table is a table, one entry in the second level lookup table may be a row or a column in the table. One entry in the second level lookup table includes a key value field that may store a mapped value and an identification value and a result field that may store a lookup result. In the embodiment of the application, the IP addresses to be stored are different from each other, and each IP address corresponds to a search result.
In the embodiment of the application, the network device can determine the table item corresponding to the first IP address in the second-level lookup table, namely the second table item, store the first mapping value and the first identification value stored in the first table item in the key value field of the second table item in combination, and store the lookup result in the result field of the second table item. In the embodiment of the application, the identification values of the two IP addresses with the same prefix value are necessarily different, otherwise, the two IP addresses are the same IP address, that is, different IP addresses correspond to different second entries. For example, if the network device needs to store 1M different IP addresses and the lookup results corresponding to the 1M different IP addresses, there are 1M entries in the second level lookup table.
In some embodiments, as shown in fig. 2, fig. 2 is a second flowchart of a table entry construction method according to an embodiment of the present application, where the method may include the following steps.
Step S21, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value and is the same as the step S11.
Step S22, calculating a first hash value of the first prefix value.
Step S23, according to the first target position indicated by the first hash value in the first-stage lookup table, the first prefix value and the first mapping value corresponding to the first prefix value are stored into the first table entry in the first-stage lookup table.
Step S24, storing the first mapping value, the first identification value and the search result into a second table item in the second-stage search table, wherein a key value field of the second table item stores the first mapping value and the first identification value, and a result field of the second table item stores the search result, which is the same as the step S13.
In the technical scheme provided by the embodiment of the application, the network equipment can find the table entry corresponding to the first target position according to the first hash value by calculating the first hash value of the first prefix value, and then store the first prefix value and the first mapping value corresponding to the first prefix value into the first-stage lookup table according to the table entry corresponding to the first target position. The hash value is utilized to compress the larger value space into the smaller value space which can be searched, so that the first prefix value and the first mapping value are conveniently stored in the first-stage lookup table, and the first-stage lookup table is conveniently searched according to the hash value to obtain a search result.
In the above step S22, the network device may calculate a hash value of the first prefix value, that is, the first hash value, according to the first hash function. The form of the first hash function may be configured according to the actual situation. When the first-level lookup table is a table, the hash value may be a natural number, e.g., 1, 2, 3, … …, and the hash value may be a row number or a column number of the table entry, e.g., the hash value is 1, and the hash value may indicate the table entry of the 1 st row or the table entry of the 1 st column in the first-level lookup table; when the first level lookup table is a linked list, the hash value may also be a pointer to the linked list, pointing to a linked list node.
In the above step S23, the first hash value indicates a first target position, where the first target position is a position of one entry in the first level lookup table. If the first hash value is 1, the corresponding first target location may be row 1 or column 1 in the first-level lookup table. The first hash value may also be a pointer to a linked list node, where the location of the linked list node is a first target location, and the linked list node is an entry. The network device may determine a first entry in the first level lookup table according to the first target location, and further store the first prefix value and a first mapping value corresponding to the first prefix value to the first entry, where the first entry may be an entry at the first target location.
In some embodiments, the step S23 may be: and judging whether the table entry at the first target position indicated by the first hash value in the first-level lookup table is occupied. If the judgment result is negative, that is, the table item at the first target position indicated by the first hash value in the first-stage lookup table is not occupied, indicating that the first prefix value is not stored, and taking the table item at the first target position as a first table item; and storing the first prefix value and a first mapping value corresponding to the first prefix value into the first table entry.
If the determination result is yes, that is, the table entry at the first target position indicated by the first hash value in the first-stage lookup table is occupied, two cases can be classified as follows:
in case 1, when hash values of different prefix values are different, the first prefix value is considered to be stored, and the second mapping value stored in the table entry at the first target position may be used as the first mapping value, and the above-described step S24 may be performed based on the first mapping value and the first identification value.
In case 2, in the case that hash values of different prefix values may be the same, it is considered that whether the first prefix value is stored cannot be determined, and in order to eliminate hash collision, the first prefix value is matched with a second prefix value stored in an entry at the first target position; if the matching fails, that is, the first prefix value is different from the second prefix value, the first prefix value is not stored, unoccupied table entries are distributed in the first-stage lookup table to serve as first table entries, and then the first prefix value and a first mapping value corresponding to the first prefix value are stored in the first table entries. In the embodiment of the present application, the manner of allocating the first table entry is not specifically limited.
In some embodiments, if the first prefix value matches the second prefix value successfully, it indicates that the first prefix value is already stored, and it can be divided into two cases:
in case 1, when the hash value of the prefix value is different for different IP addresses, the storage flow of the first IP address is ended.
In case 2, in the case where the hash values of the prefix values may be the same for different IP addresses, the above-described step S24 may be performed based on the first mapping value and the first identification value with the second mapping value stored in the entry at the first target position as the first mapping value.
The above-mentioned method for constructing an entry will be described with reference to a third flow chart of the method for constructing an entry shown in fig. 3. The method may include the following steps.
Step S31, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value and is the same as the step S11 and the step S21.
Step S32, calculating a first hash value of the first prefix value is the same as step S22 described above.
Step S33, judging whether the table item at the first target position indicated by the first hash value in the first-stage lookup table is occupied, if not, executing step S34, and if occupied, executing step S35.
Step S34, taking the table item at the first target position as a first table item, and executing step S38.
Step S35, matching the first prefix value with a second prefix value stored in an item at the first target position, and if the matching fails, executing step S36; if the matching is successful, step S37 is performed.
Step S36, an unoccupied table item is allocated in the first-level lookup table as a first table item, and step S38 is executed.
Step S37, taking the second mapping value stored in the table entry at the first target position as the first mapping value, and executing step S39.
Step S38, storing the first prefix value and the first mapping value corresponding to the first prefix value in the first table entry, and executing step S39.
Step S39, storing the first mapping value, the first identification value and the search result in a second table item in the second level search table, wherein a key value field of the second table item stores the first mapping value and the first identification value, and a result field of the second table item stores the search result, which is the same as the step S13.
In the technical scheme provided by the embodiment of the application, since the hash values of different prefix values calculated by the network equipment are possibly the same, in order to avoid hash collision, when the table item at the first target position indicated by the first hash value is occupied, the network equipment needs to judge whether the table item is caused by the same prefix value of other IP addresses or caused by different prefix values of other IP addresses so as to perform corresponding processing, thereby ensuring that the first-stage lookup table can accurately store the corresponding relation between the first prefix value and the first mapping value, avoiding resource waste caused by repeated storage of the IP addresses and ensuring the integrity of the first-stage lookup table.
In the step S33, the network device first determines whether the table entry at the first target location is occupied, if not, step S34 may be executed, where the table entry at the first target location is used as the first table entry, so as to store the first prefix value and the first mapping value corresponding to the first prefix value into the first table entry subsequently; if the table entry at the first target location is occupied, the network device executes step S35 to obtain a prefix value stored in the key value field of the table entry at the first target location, that is, a second prefix value, match the first prefix value with the second prefix value, and determine whether the table entry is occupied by the same prefix value of other IP addresses or is occupied by different prefix values of other IP addresses.
In the step S35, the network device matches the first prefix value with the second prefix value, if the matching fails, the network device indicates that different prefix values of other IP addresses occupy the table entry at the first target location, and then executes step S36 to reassign an unoccupied table entry as the first table entry, so as to store the first prefix value and the first mapping value corresponding to the first prefix value into the first table entry subsequently; if the matching is successful, the same prefix value of the other IP address occupies the table entry at the first target location, and the prefix value of the first IP address may multiplex the table entry, perform step S37, take the second mapping value stored in the result field in the table entry at the first target location as the first mapping value, and perform step S39.
In the above step S36, the network device may reassign the unoccupied table entry for the first prefix value according to the cuckoohash algorithm, the open addressing method, the chain address method, and the like.
Taking an open addressing method as an example, taking a first-stage lookup table as a table for example, the network device calculates that a first hash value corresponding to a first prefix value is 1, and if a 1 st row in the first-stage lookup table corresponding to the first hash value is occupied by a prefix value different from the first prefix value, the network device searches the next row in sequence until an empty row such as a 3 rd row is found, and allocates the empty row as a first table item to the first prefix value.
Taking a chain address method as an example, taking a first-level lookup table as a linked list, taking each linked list node as a table item, each table item is provided with a plurality of next pointers, the plurality of table items can form a unidirectional linked list according to the next pointers, when the network equipment IP address calculates that the table item pointed by the first hash value corresponding to the first prefix value is occupied by the prefix value different from the first prefix value, the network equipment searches the unidirectional linked list according to the next pointers stored in the table item pointed by the first hash value, searches the table item with the next empty storage content, and allocates the table item with the empty storage content as the first table item to the first prefix value.
In the above step S38, the network device stores the first prefix value in the key value field of the first table entry, and stores the first mapping value corresponding to the first prefix value in the result field of the first table entry.
In some embodiments, as shown in fig. 4, fig. 4 is a fourth flowchart of a table entry construction method according to an embodiment of the present application, where the method may include the following steps.
Step S41, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value and is the same as the step S11.
Step S42, storing the first prefix value and the first mapping value corresponding to the first prefix value into a first table entry in the first-stage lookup table, wherein a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value corresponds to the first mapping value one by one, which is the same as that of the step S12.
In step S43, a second hash value of the first mapping value and the first identification value is calculated.
And S44, storing the first mapping value, the first identification value and the search result into a second table entry in the second-stage lookup table according to the second target position indicated by the second hash value in the second-stage lookup table.
In the technical scheme provided by the embodiment of the application, the network equipment can find the table entry corresponding to the second target position according to the second hash value by calculating the second hash value of the first mapping value and the first identification value, and then store the first mapping value, the first identification value and the search result into the second-stage lookup table according to the table entry corresponding to the second target position. The hash value is utilized to compress the larger value space into the smaller value space which can be searched, so that the first mapping value, the first identification value and the search result are conveniently stored in the second-stage search table, and the second-stage search table is conveniently searched according to the hash value to obtain the search result.
In the above step S43, the network device may calculate a hash value of the first mapping value and the first identification value, that is, the second hash value, according to the second hash function. The form of the second hash function may be configured according to the actual situation. When the second level lookup table is a table, the hash value may be a natural number, e.g., 1, 2, 3, … …, the hash value may be a row number or a column number of the table entry, e.g., the hash value is 1, the hash value may indicate the table entry of the 1 st row or the table entry of the 1 st column in the second level lookup table; when the second level lookup table is a linked list, the hash value may also be a pointer to the linked list, pointing to a linked list node.
In the above step S44, the second hash value indicates the second target position, where the second target position is the position of one entry in the second-level lookup table. If the second hash value is 1, the corresponding second target location may be row 1 or column 1 in the second level lookup table. The second hash value may also be a pointer to a linked list node, where the location of the linked list node is a second target location, and the linked list node is an entry. The network device may determine a second entry in the second level lookup table according to the second target location, and further store the first mapping value, the first identification value, and the lookup result to the second entry, where the second entry may be an entry at the second target location.
In some embodiments, the step S44 may be: and judging whether the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied. If the judgment result is negative, that is, the table item at the second target position indicated by the second hash value in the second-level lookup table is not occupied, indicating that the first mapping value and the first identification value are not stored, and taking the table item at the second target position as a second table item; and storing the first mapping value, the first identification value and the search result into a second table entry.
If the determination result is yes, that is, the table entry at the second target position indicated by the second hash value in the second-stage lookup table is occupied, two cases can be classified as follows:
in case 1, when the hash values corresponding to the different first mapping values and the first identification values are different, the storage flow of the first IP address is ended.
In case 2, under the condition that hash values corresponding to different first mapping values and first identification values may be the same, an unoccupied second table entry may be allocated in the second-level lookup table; and storing the first mapping value, the first identification value and the search result into a second table entry.
The above-mentioned table entry construction method will be described with reference to a fifth flowchart of the table entry construction method shown in fig. 5. The method may include the following steps.
Step S51, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value and is the same as the step S11.
Step S52, storing the first prefix value and the first mapping value corresponding to the first prefix value into a first table entry in the first-stage lookup table, storing the first prefix value in a key value field of the first table entry, storing the first mapping value in a result field of the first table entry, wherein the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value corresponds to the first mapping value one by one, which is the same as that in the step S12.
Step S53, calculating a second hash value of the first mapping value and the first identification value is the same as step S43.
Step S54, judging whether the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, if not, executing step S55; if occupied, step S56 is performed.
Step S55, step S57 is executed with the entry at the second target position as the second entry.
Step S56, the unoccupied second table item is allocated in the second-level lookup table, and step S57 is executed.
Step S57, storing the first mapping value, the first identification value and the search result into the second table item.
In the technical scheme provided by the embodiment of the application, as the hash values of different first mapping values and first identification values calculated by the network equipment are possibly the same, in order to avoid hash collision, the network equipment needs to judge whether the table entry at the second target position indicated by the second hash value is occupied or not so as to carry out corresponding processing, thereby ensuring that the second-stage lookup table can accurately store the corresponding relation between the first mapping values and the first identification values as well as the lookup result, avoiding resource waste caused by repeated storage of the IP address and ensuring the integrity of the second-stage lookup table.
In the step S54, the network device determines whether the table entry at the second target location is occupied, if not, step S55 may be executed, where the table entry at the second target location is used as the second table entry, so as to store the first mapping value, the first identification value, and the search result to the second table entry subsequently; if the entry at the second target location is occupied, the network device performs step S56 to reassign an unoccupied second entry in a second level lookup table.
In the above step S56, the network device may reassign the unoccupied second entry in the second-level lookup table according to the cuckoohash algorithm, the open addressing method, the chain address method, and the like. Specifically, the description of reallocating the unoccupied entries for the first prefix value by the network device in the above step S36 may be referred to, and will not be repeated herein.
In order to describe the above table entry construction method in detail, the embodiment of the present application further provides a flowchart of the table entry construction method, as shown in fig. 6, where the method includes the following steps.
Step S61, obtaining a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value and is the same as the step S11, the step S21 and the step S31.
Step S62, a first hash value of the first prefix value is calculated, which is the same as that in steps S22 and 32.
Step S63, judging whether the table item at the first target position indicated by the first hash value in the first-stage lookup table is occupied, if not, executing step S64, and if occupied, executing step S65, which is the same as the step S33.
Step S64, step S68 is performed with the entry at the first target position as the first entry, as in step S34 described above.
Step S65, matching the first prefix value with the second prefix value stored in the first table entry, if the matching fails, executing step S66; if the matching is successful, step S67 is executed, which is the same as step S35 described above.
Step S66, allocating an unoccupied entry in the first level lookup table as a first entry, and executing step S68, which is the same as step S36 described above.
Step S67, the second mapping value stored in the table entry at the first target position is taken as the first mapping value, and step S69 is performed, which is the same as step S37 described above.
Step S68, storing the first prefix value and the first mapping value corresponding to the first prefix value in the first table entry, and executing step S69, which is the same as the above step S38.
Step S69, calculating a second hash value of the first mapping value and the first identification value is the same as step S53.
Step S610, judging whether the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, if not, executing step S611; if occupied, step S612 is performed, as in step S54 described above.
Step S611, step S613 is performed with the entry at the second target position as the second entry, as in step S55 described above.
Step S612, allocating an unoccupied second entry in the second-level lookup table, and executing step S613, which is the same as step S56 described above.
Step S613, the first mapping value, the first identification value, and the search result are stored in the second table entry, which is the same as the above step S57.
The table entry construction method provided by the embodiment of the application is described below with reference to an example.
The network device obtains an IP address, S1+ H1, where S1 is a prefix value (network segment) of 96bits, H1 is an identification value (interface identification) of 32bits, a hash value a of S1 is calculated to be 1, and corresponds to line 1 in the first-stage lookup table, if the network device detects that line 1 in the first-stage lookup table is empty, S1 and Cookie (mapping value) =11 allocated for S1 are stored in line 1 in the first-stage lookup table, as shown in table 1 below.
TABLE 1
S1 Cookie=11
Combining cookie=11 with H1, calculating a hash value b, i.e. calculating a hash value b of 11+h1 as 1, corresponding to the 1 st row in the second-stage lookup table, and storing 11+h1 in the second-stage lookup table if the network device detects that the 1 st row in the second-stage lookup table is empty, as shown in table 2 below.
TABLE 2
11+H1 Search results corresponding to S1+H2
The network device obtains an IP address again, where s2+h2, S2 and S1 are different in value, where S2 is a prefix value of 96bits, H2 is an identification value of 32bits, a hash value c corresponding to S2 is calculated to be 1, and corresponds to the 1 st row in the first-stage lookup table, if the network device detects that the 1 st row in the first-stage lookup table is occupied, S1 and S2 are matched, if the matching fails, the location where the S2 reassignment entry is empty is stored, if the 2 nd row in the first-stage lookup table, S2 and a Cookie (mapping value) =22 corresponding to S2 are stored in the 2 nd row in the first-stage lookup table, as shown in table 3 below.
TABLE 3 Table 3
S1 Cookie=11
S2 Cookie=22
Combining cookie=22 with H2, calculating a hash value d, i.e. calculating a hash value d of 22+h2 as 2, corresponding to row 2 in the second level lookup table, and storing 22+h2 in the second level lookup table if the network device detects that row 2 in the second level lookup table is empty, as shown in table 4 below.
TABLE 4 Table 4
And similarly, storing all the IP addresses into the first-stage lookup table and the second-stage lookup table, and completing the construction of the first-stage lookup table and the second-stage lookup table.
In the technical scheme provided by the embodiment of the application, the storage space required by the lookup table is greatly reduced by constructing the first-stage lookup table and the second-stage lookup table. This is illustrated by the following example.
The network equipment supports IPv6 FIB of 1M specification and 64K network segments, the network prefix length of the IPv6 address is 96bits, the interface identification length is 32bits, and then:
1. the first-stage lookup table is established to comprise 64K table entries, the key field length of each table entry is 96bits, and taking the result field length of the first-stage lookup table as an example, the first-stage lookup table occupies 64K× (96+20) =7.424M bits;
2. the second-level lookup table needs to be built to include 1M table entries, each table entry has a key field length of 20+32=52 bits, and taking the result field length of the second-level lookup table as an example of 32bits, the first-level lookup table occupies 1m× (52+32) =84M bits.
By adopting the technical scheme provided by the embodiment of the application, the first-stage lookup table and the second-stage lookup table occupy 7.424+84= 91.424 Mbits. Whereas the space required to construct entries using prior art techniques is 1 mx (128+32) =160 Mbits. Compared with the prior art, the table entry construction method provided by the embodiment of the application has the advantage that the occupied space is compressed to be 91.424/160=58% originally.
By adopting the technical scheme provided by the embodiment of the application, the compression of the storage space of the hash table can be realized. When the chip realizes the acceleration of table lookup and adopts the SRAM to store the table contents, the storage space of the SRAM can be controlled below 16M Bytes, thereby greatly reducing the hardware cost.
Based on the above table entry construction method, the embodiment of the application also provides a table entry searching method, as shown in fig. 7, which comprises the following steps.
Step S71, a target IP address is acquired, wherein the target IP address comprises a target prefix value and a target identification value.
Step S72, searching a target mapping value corresponding to the target prefix value from each table item of the first-stage lookup table, wherein the first-stage lookup table is constructed according to any one of the table item construction methods in the above-mentioned figures 1-6.
Step S73, searching a target searching result corresponding to the target mapping value and the target identification value from each table item of the second-level searching table, wherein the second-level searching table is constructed according to any one of the table item construction methods in the figures 1-6.
In the technical scheme provided by the embodiment of the application, an IP address is divided into two parts of a prefix value and an identification value, and a one-to-one correspondence relation is established between the prefix value with higher repeatability and the mapping value with smaller length and is stored in a first-stage lookup table; and then storing the mapping value, the identification value and the corresponding relation of the search result into a second-stage lookup table. On the one hand, the prefix values of the plurality of IP addresses may be the same, i.e. the plurality of IP addresses can multiplex the entries in one first-level lookup table without repeatedly storing the same prefix value; in the two aspects, the length of the mapping value is smaller, the short mapping value is used for replacing the long prefix value, and the storage space occupied by the key value field in the second-stage lookup table is greatly reduced, so that the storage space required by the lookup table is reduced, and a memory with smaller storage space can be used for storing the lookup table, and the hardware cost is reduced.
The above table entry searching method is described below by way of an example.
The network equipment acquires a target IP address of S2+H2, calculates the hash value of S2 of 1, and corresponds to the 1 st row in the table 3, the network equipment matches S2 with S1, if the matching fails, the network equipment searches the next row, if the matching between the 2 nd row and S2 is successful, the network equipment acquires a target mapping value 22 corresponding to S2; and then calculating the hash value of 22+H2 as 2, and corresponding to the line 2 in the table 4, matching the 22+H2 with the 22+H2 in the table by the network equipment, and obtaining a corresponding search result if the matching is successful.
Corresponding to the above table entry construction method, the embodiment of the present application further provides a table entry construction device, as shown in fig. 8, where the device includes:
a first obtaining module 81, configured to obtain a first IP address and a search result corresponding to the first IP address, where the first IP address includes a first prefix value and a first identification value, and when there is a second IP address whose prefix value is the first prefix value, the identification value of the second IP address is different from the first identification value;
the first storage module 82 is configured to store a first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in the first level lookup table, a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, a length of the first mapping value is smaller than a length of the first prefix value, and the first prefix value corresponds to the first mapping value one to one;
The second storage module 83 is configured to store the first mapping value, the first identification value, and the search result to a second table entry in the second level lookup table, where a key value field of the second table entry stores the first mapping value and the first identification value, and a result field of the second table entry stores the search result.
In the technical scheme provided by the embodiment of the application, an IP address is divided into two parts of a prefix value and an identification value, and a one-to-one correspondence relation is established between the prefix value with higher repeatability and the mapping value with smaller length and is stored in a first-stage lookup table; and then storing the mapping value, the identification value and the corresponding relation of the search result into a second-stage lookup table. On the one hand, the prefix values of the plurality of IP addresses may be the same, i.e. the plurality of IP addresses can multiplex the entries in one first-level lookup table without repeatedly storing the same prefix value; in the two aspects, the length of the mapping value is smaller, the short mapping value is used for replacing the long prefix value, and the storage space occupied by the key value field in the second-stage lookup table is greatly reduced, so that the storage space required by the lookup table is reduced, and a memory with smaller storage space can be used for storing the lookup table, and the hardware cost is reduced.
In some embodiments, the first storage module 82 may include:
A first calculation sub-module for calculating a first hash value of the first prefix value;
the first storage sub-module is used for storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in the first level lookup table according to a first target position indicated by the first hash value in the first level lookup table.
In some embodiments, the first storage sub-module may be specifically configured to:
if the table entry at the first target position indicated by the first hash value in the first-stage lookup table is unoccupied, taking the table entry at the first target position as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value into the first table entry.
In some embodiments, the first storage sub-module may be specifically configured to:
if the table entry at the first target position indicated by the first hash value in the first-stage lookup table is occupied, matching the first prefix value with a second prefix value stored in the first table entry;
if the matching fails, an unoccupied table entry is distributed in the first-stage lookup table and is used as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value into the first table entry.
In some embodiments, the first storage sub-module may also be configured to:
And if the matching is successful, taking the second mapping value stored in the table entry at the first target position as the first mapping value.
In some embodiments, the second storage module 83 may include:
the second computing sub-module is used for computing a second hash value of the first mapping value and the first identification value;
and the second storage sub-module is used for storing the first mapping value, the first identification value and the search result into a second table entry in the second-stage lookup table according to the second target position indicated by the second hash value in the second-stage lookup table.
In some embodiments, the second storage sub-module may be specifically configured to:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is unoccupied, taking the table entry at the second target position as a second table entry;
and storing the first mapping value, the first identification value and the search result into a second table entry.
In some embodiments, the second storage sub-module may be specifically configured to:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, distributing unoccupied second table entries in the second-level lookup table;
and storing the first mapping value, the first identification value and the search result into a second table entry.
In some embodiments, the first mapped value of 2 is greater than or equal to the total number of prefix values supported by the local device.
In some embodiments, the first prefix value is a value of a network prefix and the first identification value is a value of an interface identification.
Corresponding to the above table entry searching method, the embodiment of the present application further provides a table entry searching device, as shown in fig. 9, where the device includes:
a second obtaining module 91, configured to obtain a target IP address, where the target IP address includes a target prefix value and a target identification value;
the first lookup module 92 is configured to lookup a target mapping value corresponding to the target prefix value from each entry in the first-level lookup table, where the first-level lookup table is constructed according to any one of the entry construction methods described above;
the second lookup module 93 is configured to lookup a target lookup result corresponding to the target mapping value and the target identification value from each table entry of the second-level lookup table, where the second-level lookup table is constructed according to any one of the table entry construction methods described above.
In the technical scheme provided by the embodiment of the application, an IP address is divided into two parts of a prefix value and an identification value, and a one-to-one correspondence relation is established between the prefix value with higher repeatability and the mapping value with smaller length and is stored in a first-stage lookup table; and then storing the mapping value, the identification value and the corresponding relation of the search result into a second-stage lookup table. On the one hand, the prefix values of the plurality of IP addresses may be the same, i.e. the plurality of IP addresses can multiplex the entries in one first-level lookup table without repeatedly storing the same prefix value; in the two aspects, the length of the mapping value is smaller, the short mapping value is used for replacing the long prefix value, and the storage space occupied by the key value field in the second-stage lookup table is greatly reduced, so that the storage space required by the lookup table is reduced, and a memory with smaller storage space can be used for storing the lookup table, and the hardware cost is reduced.
The embodiment of the present application also provides a network device, as shown in fig. 10, including a processor 101, a communication interface 102, a memory 103, and a communication bus 104, where the processor 101, the communication interface 102, and the memory 103 perform communication with each other through the communication bus 104,
a memory 103 for storing a computer program;
the processor 101 is configured to implement any one of the above-mentioned table entry construction method or table entry search method when executing the program stored in the memory 103.
The communication bus mentioned by the above network device may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the network device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present application, a computer readable storage medium is provided, in which a computer program is stored, where the computer program, when executed by a processor, implements any one of the above-mentioned method for constructing a table entry or method for searching a table entry.
In yet another embodiment of the present application, a computer program product comprising instructions which, when run on a computer, cause the computer to perform any of the table entry construction methods or table entry lookup methods of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may 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 loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, 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 may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the apparatus, network device, storage medium embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and references to the parts of the description of the method embodiments are only needed.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims (15)

1. A method of table entry construction, the method comprising:
acquiring a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value;
storing the first prefix value and a first mapping value corresponding to the first prefix value into a first table entry in a first-level lookup table, wherein a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value and the first mapping value are in one-to-one correspondence;
storing the first mapping value, the first identification value and the search result to a second table entry in a second-level lookup table, wherein a key value field of the second table entry stores the first mapping value and the first identification value, and a result field of the second table entry stores the search result.
2. The method of claim 1, wherein the step of storing the first prefix value and the first mapped value corresponding to the first prefix value to a first entry in a first level lookup table comprises:
calculating a first hash value of the first prefix value;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in a first-stage lookup table according to a first target position indicated by the first hash value in the first-stage lookup table.
3. The method of claim 2, wherein the step of storing the first prefix value and a first mapping value corresponding to the first prefix value to a first entry in a first level lookup table according to a first target location indicated by the first hash value in the first level lookup table comprises:
if the table entry at the first target position indicated by the first hash value in the first-level lookup table is unoccupied, taking the table entry at the first target position as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
4. The method of claim 2, wherein the step of storing the first prefix value and a first mapping value corresponding to the first prefix value to a first entry in a first level lookup table according to a first target location indicated by the first hash value in the first level lookup table comprises:
If the table entry at the first target position indicated by the first hash value in the first-level lookup table is occupied, matching the first prefix value with a second prefix value stored in the table entry at the first target position;
if the matching fails, an unoccupied table entry is distributed in the first-stage lookup table and is used as a first table entry;
and storing the first prefix value and a first mapping value corresponding to the first prefix value to the first table entry.
5. The method according to claim 4, wherein the method further comprises:
and if the matching is successful, taking the second mapping value stored in the table entry at the first target position as the first mapping value, and executing the step of storing the first mapping value, the first identification value and the search result into a second table entry in a second-level lookup table.
6. The method of claim 1, wherein the step of storing the first mapping value and the first identification value, the lookup result, to a second entry in a second level lookup table comprises:
calculating a second hash value of the first mapping value and the first identification value;
and storing the first mapping value, the first identification value and the search result to a second table entry in a second-level lookup table according to a second target position indicated by the second hash value in the second-level lookup table.
7. The method of claim 6, wherein the step of storing the first mapping value and the first identification value, the lookup result, to a second entry in a second level lookup table according to a second target location indicated by the second hash value in the second level lookup table comprises:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is not occupied, taking the table entry at the second target position as a second table entry;
and storing the first mapping value, the first identification value and the search result to the second table entry.
8. The method of claim 6, wherein the step of storing the first mapping value and the first identification value, the lookup result, to a second entry in a second level lookup table according to a second target location indicated by the second hash value in the second level lookup table comprises:
if the table entry at the second target position indicated by the second hash value in the second-level lookup table is occupied, distributing unoccupied second table entries in the second-level lookup table;
and storing the first mapping value, the first identification value and the search result to the second table entry.
9. The method according to any of claims 1-8, wherein the first mapping value of 2 is to the power of the length of greater than or equal to the total number of prefix values supported by the local device.
10. The method according to any of claims 1-8, wherein the first prefix value is a value of a network prefix and the first identification value is a value of an interface identification.
11. A method for table entry lookup, the method comprising:
acquiring a target IP address, wherein the target IP address comprises a target prefix value and a target identification value;
searching for a target mapping value corresponding to the target prefix value from each entry of a first level lookup table constructed according to the method of any one of claims 1-10;
looking up a target lookup result corresponding to the target mapping value and the target identification value from respective entries of a second level lookup table constructed according to the method of any one of claims 1-10.
12. An entry construction device, the device comprising:
the first acquisition module is used for acquiring a first IP address and a search result corresponding to the first IP address, wherein the first IP address comprises a first prefix value and a first identification value, and when a second IP address with the prefix value being the first prefix value exists, the identification value of the second IP address is different from the first identification value;
The first storage module is used for storing the first prefix value and a first mapping value corresponding to the first prefix value to a first table entry in a first-stage lookup table, wherein a key value field of the first table entry stores the first prefix value, a result field of the first table entry stores the first mapping value, the length of the first mapping value is smaller than that of the first prefix value, and the first prefix value corresponds to the first mapping value one by one;
the second storage module is configured to store the first mapping value, the first identification value, and the search result to a second table entry in a second level lookup table, where a key value field of the second table entry stores the first mapping value and the first identification value, and a result field of the second table entry stores the search result.
13. An entry lookup apparatus, the apparatus comprising:
the second acquisition module is used for acquiring a target IP address, wherein the target IP address comprises a target prefix value and a target identification value;
a first lookup module configured to lookup a target mapping value corresponding to the target prefix value from each entry of a first level lookup table constructed according to the apparatus of claim 12;
A second lookup module, configured to lookup a target lookup result corresponding to the target mapping value and the target identification value from each entry of a second level lookup table, where the second level lookup table is constructed according to the apparatus of claim 12.
14. The network equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1-10 or claim 11 when executing a program stored on a memory.
15. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of any of claims 1-10 or claim 11.
CN202311483639.5A 2023-11-09 2023-11-09 Table item construction and search method and device, network equipment and storage medium Active CN117221224B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311483639.5A CN117221224B (en) 2023-11-09 2023-11-09 Table item construction and search method and device, network equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311483639.5A CN117221224B (en) 2023-11-09 2023-11-09 Table item construction and search method and device, network equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117221224A true CN117221224A (en) 2023-12-12
CN117221224B CN117221224B (en) 2024-02-06

Family

ID=89051477

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311483639.5A Active CN117221224B (en) 2023-11-09 2023-11-09 Table item construction and search method and device, network equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117221224B (en)

Citations (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1507229A (en) * 2002-12-10 2004-06-23 ����ͨѶ�ɷ����޹�˾ Route list organizing and searching method
US20040255045A1 (en) * 2003-05-26 2004-12-16 Hyesook Lim IP address lookup method and hardware architecture using hashing
CN1929447A (en) * 2006-06-01 2007-03-14 华为技术有限公司 Method and device for searching address prefixion and message transfer method and system
KR20090089166A (en) * 2008-02-18 2009-08-21 연세대학교 산학협력단 Apparatus for searching ip address and method for controlling the same
CN101778142A (en) * 2009-12-11 2010-07-14 东南大学 Anonymization method for reserving network address prefix combining bit string and hash function
CN101827137A (en) * 2010-04-13 2010-09-08 西安邮电学院 Hash table-based and extended memory-based high-performance IPv6 address searching method
CN103179038A (en) * 2013-04-19 2013-06-26 清华大学 Internetwork routing method and network forwarding equipment
US20140086249A1 (en) * 2012-09-27 2014-03-27 Avaya, Inc. Method for IPv6 Longest Prefix Match
US20140086248A1 (en) * 2012-09-26 2014-03-27 Avaya, Inc. Method for IP Longest Prefix Match Using Prefix Length Sorting
CN104426892A (en) * 2013-09-09 2015-03-18 中国电信股份有限公司 Method and system for compressing external IPv6 (Internet protocol version 6) address passing in and out of Internet of things
CN109905413A (en) * 2019-04-30 2019-06-18 新华三信息安全技术有限公司 A kind of matching process and device of IP address
CN110555020A (en) * 2018-03-26 2019-12-10 阿里巴巴集团控股有限公司 Mapping relation establishing and data querying methods, devices and equipment
CN111797180A (en) * 2020-05-21 2020-10-20 网宿科技股份有限公司 Method for establishing geographic position information index and inquiring information and electronic equipment
WO2021057530A1 (en) * 2019-09-25 2021-04-01 华为技术有限公司 Method, apparatus and system for determining mapping relationship between routing prefix and segment identification
CN113343034A (en) * 2021-06-08 2021-09-03 湖南大学 IP searching method, system and storage medium
CN114710467A (en) * 2022-03-25 2022-07-05 阿里巴巴(中国)有限公司 IP address storage method, device and hardware gateway
CN114884877A (en) * 2022-06-14 2022-08-09 电子科技大学 IPv6 route searching method combining hash table and HOT
CN115396365A (en) * 2022-10-26 2022-11-25 中国人民解放军军事科学院***工程研究院 Scale-independent fast route convergence method
CN116319553A (en) * 2023-03-24 2023-06-23 新华三技术有限公司 Table item searching method and network equipment

Patent Citations (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1507229A (en) * 2002-12-10 2004-06-23 ����ͨѶ�ɷ����޹�˾ Route list organizing and searching method
US20040255045A1 (en) * 2003-05-26 2004-12-16 Hyesook Lim IP address lookup method and hardware architecture using hashing
CN1929447A (en) * 2006-06-01 2007-03-14 华为技术有限公司 Method and device for searching address prefixion and message transfer method and system
KR20090089166A (en) * 2008-02-18 2009-08-21 연세대학교 산학협력단 Apparatus for searching ip address and method for controlling the same
CN101778142A (en) * 2009-12-11 2010-07-14 东南大学 Anonymization method for reserving network address prefix combining bit string and hash function
CN101827137A (en) * 2010-04-13 2010-09-08 西安邮电学院 Hash table-based and extended memory-based high-performance IPv6 address searching method
US20140086248A1 (en) * 2012-09-26 2014-03-27 Avaya, Inc. Method for IP Longest Prefix Match Using Prefix Length Sorting
US20140086249A1 (en) * 2012-09-27 2014-03-27 Avaya, Inc. Method for IPv6 Longest Prefix Match
CN103179038A (en) * 2013-04-19 2013-06-26 清华大学 Internetwork routing method and network forwarding equipment
CN104426892A (en) * 2013-09-09 2015-03-18 中国电信股份有限公司 Method and system for compressing external IPv6 (Internet protocol version 6) address passing in and out of Internet of things
CN110555020A (en) * 2018-03-26 2019-12-10 阿里巴巴集团控股有限公司 Mapping relation establishing and data querying methods, devices and equipment
CN109905413A (en) * 2019-04-30 2019-06-18 新华三信息安全技术有限公司 A kind of matching process and device of IP address
WO2021057530A1 (en) * 2019-09-25 2021-04-01 华为技术有限公司 Method, apparatus and system for determining mapping relationship between routing prefix and segment identification
CN111797180A (en) * 2020-05-21 2020-10-20 网宿科技股份有限公司 Method for establishing geographic position information index and inquiring information and electronic equipment
CN113343034A (en) * 2021-06-08 2021-09-03 湖南大学 IP searching method, system and storage medium
CN114710467A (en) * 2022-03-25 2022-07-05 阿里巴巴(中国)有限公司 IP address storage method, device and hardware gateway
CN114884877A (en) * 2022-06-14 2022-08-09 电子科技大学 IPv6 route searching method combining hash table and HOT
CN115396365A (en) * 2022-10-26 2022-11-25 中国人民解放军军事科学院***工程研究院 Scale-independent fast route convergence method
CN116319553A (en) * 2023-03-24 2023-06-23 新华三技术有限公司 Table item searching method and network equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王亚刚;杜慧敏;杨康平;: "使用Hash表和树位图的两级IPv6地址查找算法", 计算机科学, no. 09 *

Also Published As

Publication number Publication date
CN117221224B (en) 2024-02-06

Similar Documents

Publication Publication Date Title
US20200220840A1 (en) Method, server and system for resolving domain name
US8769057B1 (en) Employing a hierarchy of servers to resolve fractional IP addresses
US20110188503A1 (en) Ethernet Forwarding Database Method
CN101043421B (en) Memory based method for searching quickly the longest matching of IP address
CN109558091B (en) Lookup table storage method and device and computer readable storage medium
CN105991660B (en) System for resource sharing among multiple cloud storage systems
CN112860592B (en) Data caching method and device based on linked list, electronic equipment and storage medium
CN111526225B (en) Session management method and device
CN104954431A (en) Network selection method, device and system
CN108664518B (en) Method and device for realizing table look-up processing
WO2022267018A1 (en) Packet matching method and apparatus, network device, and medium
CN110659019A (en) Parameter checking method and device and server
CN117221224B (en) Table item construction and search method and device, network equipment and storage medium
US20230041395A1 (en) Method and Device for Processing Routing Table Entries
WO2013013477A1 (en) Data packet processing and tracing method, device and system
CN115334013B (en) Flow statistics method, network card and electronic equipment
CN112187636A (en) ECMP route storage method and device
CN115086221B (en) Message processing method, device, forwarding equipment and storage medium
CN105634999A (en) Aging method and device for medium access control address
TWI580217B (en) Management server and the operation method thereof and server system
CN103368852A (en) Method and system for processing hash conflict
CN114268608A (en) Address segment retrieval method and device, electronic equipment and storage medium
CN111444218A (en) Matching method and device of combination rules
US20240137317A1 (en) Method and apparatus for packet matching, network device, and medium
CN115065662A (en) Method and system for processing MAC address hash collision

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant