A table item storage, search method, device, network equipment and storage medium
By using three lookup tables in network devices, the problem of limited SRAM capacity is solved, the purpose of storing more table entries is achieved, providing larger table entries specifications and reducing storage space waste.
Patent Information
- Application Number
- CN202411482797.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-10-23
AI Technical Summary
In the prior art, SRAM has limited capacity and is difficult to effectively store and find more table entries, resulting in limited table entries specifications.
By using three lookup tables in network devices: the first lookup table is used to store the address, the second lookup table is used to store the search results, and a mapping relationship between the address and the search results is established through the third lookup table, thereby realizing the Find multiplexing and compression of results.
Efficiently utilize limited SRAM capacity to store more table entries, provide larger table entries specifications, and reduce waste of storage space caused by repeated storage search results.
Smart Images

Figure CN119003385B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a table entry storage, search method, device, network equipment and storage medium. Background Art
[0002] In order to match the forwarding capability of the forwarding chip in the network equipment, most of them use static random access memory (SRAM) to store table items, such as table items for storing addresses and table items for storing search results. However, the capacity of SRAM is limited. How to use the limited SRAM capacity to store more table items and provide larger table item specifications is an urgent problem to be solved. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a table entry storage, search method, device, network device and storage medium, so as to utilize the limited SRAM capacity to store more table entries and provide a larger table entry specification. The specific technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides a table entry storage method, the method comprising:
[0005] Obtaining a first address to be stored and a first search result associated with the first address;
[0006] Storing the first address in a first table entry in a first lookup table, the first lookup table being used to store addresses;
[0007] Searching for a second table entry storing the first search result in a second search table, wherein the second search table is used to store the search result;
[0008] If the second table entry is found, the second table entry is associated with a third table entry associated with the first address stored in the first table entry in a third lookup table, and the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0009] In some embodiments, the method further comprises:
[0010] If the second table entry is not found, creating the second table entry in the second lookup table;
[0011] Storing the first search result in the second table item;
[0012] The step of associating the second entry with a third entry in a third lookup table associated with the first address stored in the first entry is performed.
[0013] In some embodiments, the first table entry stores a first index corresponding to the first address; and the step of associating the second table entry with a third table entry in a third lookup table associated with the first address stored in the first table entry includes:
[0014] The second index of the second entry is stored in the third entry at the first index in the third lookup table.
[0015] In some embodiments, the second lookup table is further used to store a summary of the search result; the step of searching the second table entry storing the first search result in the second lookup table includes:
[0016] Calculating a first summary of the first search result;
[0017] searching a second lookup table for a candidate entry storing the first digest;
[0018] If the candidate entry is found, determining whether the first search result is stored in the candidate entry;
[0019] If the first search result is stored, the candidate entry is used as the second entry.
[0020] In some embodiments, the method further comprises:
[0021] If the candidate entry is not found, or if it is determined that the first search result is not stored in the candidate entry, it is determined that the second entry is not found.
[0022] In some embodiments, the method further comprises:
[0023] Obtaining a deletion instruction, where the deletion instruction is used to instruct to delete the first address;
[0024] The first address is deleted, and the association between the second entry and the third entry is deleted.
[0025] In some embodiments, the method further comprises:
[0026] Obtain a modification instruction, where the modification instruction is used to instruct to modify the search result associated with the first address to be a second search result;
[0027] Searching the second lookup table for a fourth table entry storing the second lookup result;
[0028] If the fourth table entry is found, the association relationship between the second table entry and the third table entry is deleted, and the fourth table entry is associated with the third table entry associated with the first address in the third lookup table.
[0029] In some embodiments, the second lookup table is further used to store the number of addresses of the multiplexed lookup result; the step of deleting the association between the second table entry and the third table entry includes:
[0030] Obtaining the second table entry and the third table entry associated with the first address through the third lookup table and the second lookup table;
[0031] Delete the third table item;
[0032] If the number of addresses stored in the second table entry is greater than 1, the number of addresses stored in the second table entry is reduced by 1; if the number of addresses stored in the second table entry is equal to 1, the second table entry is deleted.
[0033] In a second aspect, an embodiment of the present application provides a table entry search method, the method comprising:
[0034] Get the second address to be found;
[0035] searching a fifth table entry storing a third address in a first lookup table, the third address matching the second address, the first lookup table being used to store addresses;
[0036] Obtaining a sixth table entry associated with a third address stored in the fifth table entry in a third lookup table, wherein the third lookup table is used to store a mapping relationship between addresses and lookup results;
[0037] Obtaining a seventh table item associated with the sixth table item in a second lookup table, wherein the second lookup table is used to store the lookup result;
[0038] The search result stored in the seventh table entry is used as a third search result associated with the second address.
[0039] In some embodiments, the fifth table entry stores a third index corresponding to the third address; the step of obtaining a sixth table entry associated with the third address stored in the fifth table entry in the third lookup table includes: obtaining the sixth table entry at the third index in the third lookup table;
[0040] The step of obtaining the seventh table entry associated with the sixth table entry in the second lookup table includes: obtaining the seventh table entry at the fourth index stored in the sixth table entry in the second lookup table.
[0041] In a third aspect, an embodiment of the present application provides a table entry storage device, the device comprising:
[0042] A first acquisition module, used to acquire a first address to be stored and a first search result associated with the first address;
[0043] A storage module, used for storing the first address into a first table entry in a first lookup table, where the first lookup table is used for storing addresses;
[0044] A first search module, used for searching a second table entry storing the first search result in a second search table, wherein the second search table is used for storing the search result;
[0045] The association module is used to associate the second table entry with a third table entry associated with the first address stored in the first table entry in a third lookup table if the second table entry is found, and the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0046] In some embodiments, the association module is further configured to:
[0047] If the second table entry is not found, creating the second table entry in the second lookup table;
[0048] Storing the first search result in the second table item;
[0049] The step of associating the second entry with a third entry in a third lookup table associated with the first address stored in the first entry is performed.
[0050] In some embodiments, the first table entry stores a first index corresponding to the first address; and the association module is specifically configured to:
[0051] The second index of the second entry is stored in the third entry at the first index in the third lookup table.
[0052] In some embodiments, the second lookup table is further used to store a summary of the search result; and the storage module is specifically used to:
[0053] Calculating a first summary of the first search result;
[0054] searching a second lookup table for a candidate entry storing the first digest;
[0055] If the candidate entry is found, determining whether the first search result is stored in the candidate entry;
[0056] If the first search result is stored, the candidate entry is used as the second entry.
[0057] In some embodiments, the storage module is further used to:
[0058] If the candidate entry is not found, or if it is determined that the first search result is not stored in the candidate entry, it is determined that the second entry is not found.
[0059] In some embodiments, the apparatus further comprises a deletion module, configured to:
[0060] Obtaining a deletion instruction, where the deletion instruction is used to instruct to delete the first address;
[0061] The first address is deleted, and the association between the second entry and the third entry is deleted.
[0062] In some embodiments, the apparatus further comprises a modification module, configured to:
[0063] Obtain a modification instruction, where the modification instruction is used to instruct to modify the search result associated with the first address to be a second search result;
[0064] Searching the second lookup table for a fourth table entry storing the second lookup result;
[0065] If the fourth table entry is found, the association relationship between the second table entry and the third table entry is deleted, and the fourth table entry is associated with the third table entry associated with the first address in the third lookup table.
[0066] In some embodiments, the second lookup table is further used to store the address quantity of the multiplexed lookup result; the deletion module or the modification module is specifically used to:
[0067] Obtaining the second table entry and the third table entry associated with the first address through the third lookup table and the second lookup table;
[0068] Delete the third table item;
[0069] If the number of addresses stored in the second table entry is greater than 1, the number of addresses stored in the second table entry is reduced by 1; if the number of addresses stored in the second table entry is equal to 1, the second table entry is deleted.
[0070] In a fourth aspect, an embodiment of the present application provides a table entry search device, the device comprising:
[0071] A second acquisition module, used to acquire a second address to be searched;
[0072] a second search module, configured to search a fifth table entry storing a third address in a first search table, the third address matching the second address, the first search table being used to store addresses;
[0073] A third acquisition module, used to acquire a sixth table item associated with a third address stored in the fifth table item in a third lookup table, wherein the third lookup table is used to store a mapping relationship between an address and a lookup result;
[0074] A fourth acquisition module, used to acquire a seventh table item associated with the sixth table item in a second lookup table, wherein the second lookup table is used to store the lookup result;
[0075] The obtaining module is used to use the search result stored in the seventh table entry as the third search result associated with the second address.
[0076] In some embodiments, the fifth table entry stores a third index corresponding to the third address; the third acquisition module is specifically used to: acquire a sixth table entry at the third index in the third lookup table;
[0077] The fourth acquisition module is specifically used to: acquire the seventh entry at the fourth index stored in the sixth entry in the second lookup table.
[0078] In a fifth aspect, an embodiment of the present application provides a network device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0079] Memory, used to store computer programs;
[0080] The processor is used to implement any of the methods described in the first aspect or the second aspect when executing the program stored in the memory.
[0081] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented.
[0082] In a seventh aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the methods described in the first or second aspects of the above embodiments.
[0083] Beneficial effects of the embodiments of the present application:
[0084] In the technical solution provided by the embodiment of the present application, after the first address is stored in the first table item, the first search result associated with the first address is first searched in the stored search results, that is, the second table item storing the first search result is searched. If the second table item is found, it means that the first search result has been stored in the second search table, and the first search result can be directly reused to establish an association relationship between the second table item and the third table item associated with the first address, so as to realize the association between the first address and the first search result, without the need to create a new table item storing the first search result. In the subsequent search process, it is only necessary to determine the search result associated with the address to be searched based on the table items associated with the address to be searched in the third search table and the second search table. Applying the technical solution provided by the embodiment of the present application, the search result to be stored is first searched to determine whether the search result to be stored has been stored in the second search table. In this way, the same search result only needs to be stored once in the second search table, saving the storage space required for storing the search result, realizing compression of the second search table, reducing the waste of storage space caused by repeated storage of the search result, and then using the limited SRAM capacity to store more table items, providing a larger table item specification.
[0085] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0086] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0087] Figure 1 A schematic diagram of a first flow chart of a table entry storage method provided in an embodiment of the present application;
[0088] Figure 2 A second flow chart of the table entry storage method provided in an embodiment of the present application;
[0089] Figure 3 A third flow chart of the table entry storage method provided in the embodiment of the present application;
[0090] Figure 4 A schematic diagram of a flow chart of a table entry search method provided in an embodiment of the present application;
[0091] Figure 5 A schematic diagram of the first structure of the table provided in the embodiment of the present application;
[0092] Figure 6 A second structural diagram of a table item provided in an embodiment of the present application;
[0093] Figure 7 A schematic diagram of the structure of a table entry storage device provided in an embodiment of the present application;
[0094] Figure 8 A schematic diagram of the structure of a table entry search device provided in an embodiment of the present application;
[0095] Fig. 9 A schematic diagram of the structure of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0096] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0097] In order to match the forwarding capability of the forwarding chip in the network device, SRAM is mostly used to store table items, such as table items for storing addresses and table items for storing search results. At present, the table item specifications are getting larger and larger. For example, when the Longest Prefix Match (LPM) algorithm is used for message forwarding, the table item specifications need to reach 1.5 megabytes (M) or even more than 2M. However, due to the area and cost of the forwarding chip, the capacity of SRAM is limited. Therefore, how to use the limited SRAM capacity to store more table items and provide larger table item specifications is an urgent problem to be solved.
[0098] In order to solve the above problems, the embodiment of the present application provides a table entry storage method, which can be applied to network devices such as routers and switches, and can also be applied to forwarding chips in network devices. For the convenience of description, the following will be based on network devices as the execution subject, which does not play a limiting role. Figure 1 , is a first flow chart of the table item storage method provided in the embodiment of the present application. The above table item storage method includes the following steps.
[0099] Step S11, obtaining a first address to be stored and a first search result associated with the first address.
[0100] Step S12: store the first address into a first table entry in a first lookup table, where the first lookup table is used to store addresses.
[0101] Step S13, searching the second table entry storing the first search result in the second search table, the second search table being used to store the search result. If the second table entry is found, executing step S14.
[0102] Step S14: Associating the second table entry with a third table entry associated with the first address stored in the first table entry in the third lookup table, where the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0103] In the technical solution provided by the embodiment of the present application, after the network device stores the first address in the first table item, it first searches for the first search result associated with the first address in the stored search results, that is, searches for the second table item storing the first search result. If the second table item is found, it means that the first search result has been stored in the second search table, and the network device can directly reuse the first search result, establish the association relationship between the second table item and the third table item associated with the first address, and realize the association between the first address and the first search result, without the need to create a new table item for storing the first search result. In the subsequent search process, the network device only needs to determine the search result associated with the address to be searched according to the table items associated with the address to be searched in the third search table and the second search table. Applying the technical solution provided by the embodiment of the present application, the network device first searches for the search result to be stored and determines whether the search result to be stored has been stored in the second search table. In this way, the same search result only needs to be stored once in the second search table, saving the storage space required for storing the search result, realizing compression of the second search table, reducing the waste of storage space caused by repeated storage of the search result, and then using the limited SRAM capacity to store more table items, providing a larger table item specification.
[0104] In the above step S11, the first address is any address to be stored by the network device. The address to be stored by the network device can be an Internet Protocol (IP) address, an IP address prefix, or a Media Access Control (MAC) address or other address. The form of the address to be stored is not limited here. For ease of description, the following description is based on the example that the address to be stored is an IP address prefix, which does not serve as a limitation. The search result associated with the first address is the first search result.
[0105] The network device obtains the sent table entry to be stored, and obtains the table entry to be stored including the first address to be stored and the associated first search result. For example, the table entry to be stored obtained by the network device may be an LPM table entry, and the LPM table entry includes the IP address prefix to be stored and the associated search result.
[0106] In the above step S12, the first lookup table is a hash table for storing addresses, and the addresses are stored in the table items of the first lookup table. For the convenience of distinction, the table items of the first lookup table are referred to as address table items in the following. The network device can pre-set the specifications of the first lookup table according to actual conditions, such as the specifications of the first lookup table can be 1M, 2M, etc., which is not limited.
[0107] The network device may determine an address table entry in the first lookup table according to the acquired first address, and the determined address table entry is the first table entry storing the first address. The network device may store the first address in the first table entry.
[0108] In an embodiment of the present application, the network device may use a compressed or uncompressed first lookup table to store addresses. When an uncompressed first lookup table is used to store addresses, only one address is stored in an address table item, and the network device may determine the index of the first table item by a hash algorithm, a trie tree, or a combination of the two, that is, determine the location where the first address is stored in the first lookup table, and store the first address in the first table item through the index of the first table item. For example, the network device may modulo the hash value corresponding to the first address according to the specifications of the first lookup table, obtain the modulo value as the index of the first table item, and store the first address in the first table item.
[0109] In order to save storage resources, the network device may also use a compressed first lookup table to store addresses. In this case, one or more addresses may be stored in an address table entry. The data of the first length before the one or more addresses are the same. The data of the first length before the one or more addresses is the public address of the one or more addresses (the public prefix for the IP address prefix), and the public address is stored in the public address field in the address table entry. The other data in the one or more addresses except the public address is the special address of the corresponding address (the special prefix for the IP address prefix), and the one or more special addresses are stored in the special address field in the address table entry. In other words, the public address of the one or more addresses is stored only once in the address table entry, reducing the space waste of the first lookup table.
[0110] For different address table entries, the first length may be different, that is, the length of the public address of different address table entries may be different. For example, for address table entry 1, the first length is 12, indicating that the data of the first 12 bits of the address stored in address table entry 1 are the same. For another example, for address table entry 2, the first length is 14, indicating that the data of the first 14 bits of the address stored in address table entry 1 are the same. The above-mentioned first length value is only an example and does not serve as a limitation.
[0111] For example, for the four IP address prefixes {192.172.0.0 / 16, 192.173.0.0 / 16, 192.174.0.0 / 16, 192.175.0.0 / 16}, the network device can compress them into the format of common prefix (common_prefix) + unique prefix (unique_prefix). The common prefix is {192.172.0.0 / 14}, and the unique prefix is {00,01,10,11}, that is, the above four IP address prefixes can be compressed into {192.172.0.0 / 14|00,01,10,11}.
[0112] The network device can use any length as the first length, extract the data of the first length from the first address as the public address of the first address, use the other data except the public address as the special address of the first address, and calculate the index of the first table item according to the public address of the first address through the hash algorithm, write the public address of the first address into the public address field of the first table item through the index of the first table item, and write the special address of the first address into the special address field of the first table item. If other addresses are already stored in the first table item before storing the first address, the network device can only write the special address of the first address into the special address field. The first lookup table used by the network device and the method of storing the first address in the first lookup table are not limited here.
[0113] In the above step S13, the second lookup table is a hash table for storing the search results, and the search results are stored in the table items of the second lookup table. For the sake of distinction, the table items of the second lookup table are referred to as result table items in the following. The network device can pre-set the specifications of the second lookup table according to the number of outbound interfaces and sub-interfaces and the forwarding behavior of each interface. For example, the specifications of the second lookup table can be 32 kilobytes (K), 64K, etc., and there is no limitation on this. The network device can pre-set the length of the result table item to any length greater than or equal to the length of the search result. For example, when the length of the search result is 5 bytes (Byte, B), the length of the result table item can be 5B, 6B, etc., and there is no limitation on this.
[0114] The network device can search for the first search result in the search results stored in the result table item of the second search table, and the result table item storing the first search result is the second table item. The network device determines whether the first search result is stored in the second search table by searching the second table item.
[0115] If the network device finds the second table entry, that is, determines that the first search result has been stored in the second search table, step S14 may be executed.
[0116] In step S14, the third lookup table is a hash table for storing the mapping relationship between addresses and search results. The mapping relationship between addresses and search results is stored in the table items of the third lookup table. For the sake of distinction, the table items of the third lookup table are referred to as identification (ID) table items. The network device can pre-set the specifications of the third lookup table according to actual conditions. The specifications of the third lookup table are the number of addresses that can actually be stored. For example, the specifications of the third lookup table can be 1M, 2M, etc., and there is no limitation on this. The network device can also pre-set the length of the identification table item according to the specifications of the second lookup table. For example, when the specifications of the second lookup table are 64K, due to 2 16 >64K, the length of the identification table entry can be 2B, 3B, etc., and there is no limitation on this.
[0117] In the embodiment of the present application, each address stored in each address table entry is respectively associated with an identification table entry of the third lookup table. For example, the first lookup table includes address table entry 1 and address table entry 2; address table entry 1 stores address 1 and address 2, and address 1 and address 2 are respectively associated with an identification table entry, address 1 is associated with identification table entry 1, and address 2 is associated with identification table entry 2; address table entry 2 stores address 3, and address 3 is associated with identification table entry 3.
[0118] After storing the first address in the first table entry, the network device may create a new identification table entry and establish an association relationship between the first address and the newly created identification table entry, and the newly created identification table entry is the third table entry.
[0119] In an embodiment of the present application, when an uncompressed first lookup table is used to store addresses, the network device can allocate an empty position for the first address from all empty positions in the third lookup table to create a new identification table entry, and the newly created identification table entry is the third table entry, and an association relationship between the first address and the third table entry is established. For example, the network device can randomly select an empty position from all empty positions to create a new identification table entry. For another example, the network device can calculate a hash value based on the first address, determine the empty position indicated by the hash value, and create a new identification table entry. The way in which the network device allocates the third table entry is not limited here.
[0120] When the compressed first lookup table is used to store the address, the identification table items associated with the addresses stored in the address table items are continuous, and the order of address storage is the order of the identification table items. Still taking the 4 IP address prefixes in the above step S12 as an example, if the order in which these 4 IP address prefixes are stored in the address table items is: {192.172.0.0 / 16}, {192.173.0.0 / 16}, {192.174.0.0 / 16} and {192.175.0.0 / 16}, and these 4 IP address prefixes are respectively associated with identification table item a, identification table item b, identification table item c and identification table item d, then the special prefix stored in the address table item is {00,01,10,11}, identification table items a to identification table item d are continuous, and the order is: identification table item a, identification table item b, identification table item c and identification table item d. If the order in which the four IP address prefixes are stored in the address table entry is: {192.174.0.0 / 16}, {192.173.0.0 / 16}, {192.172.0.0 / 16}, and {192.175.0.0 / 16}, the special prefix stored in the address table entry is {10,01,00,11}, and identification entry a to identification entry d are continuous and in the order: identification entry c, identification entry b, identification entry a, and identification entry d.
[0121] If the number of addresses stored in the first table entry is greater than 1, that is, other addresses have been stored in the first table entry before the first address is stored, the network device can determine the third table entry based on the order of the first address in all addresses and the identification table entries associated with other addresses, and establish an association relationship between the first address and the third table entry. Usually, the first address is stored after the last address of the other addresses, and the network device can determine the next identification table entry of the identification table entry associated with the last address as the third table entry.
[0122] If the number of addresses stored in the first table entry is equal to 1, that is, the network device creates a first table entry and stores the first address in the newly created first table entry, then the network device can assign an identification table entry to the first address as the third table entry, and establish an association relationship between the first address and the third table entry, which is the same as the case of using an uncompressed first lookup table to store addresses, and will not be repeated here.
[0123] After determining the third table entry associated with the first address, the network device can establish an association relationship between the second table entry and the third table entry to associate the second table entry storing the first search result with the first address, thereby realizing storage of the table entry.
[0124] In the technical solution provided in the embodiment of the present application, in order to save storage resources, the network device can compress the lookup table (also called the address table) storing the address, and store multiple addresses in the same address table entry. However, since the lookup table (also called the result table) storing the search results stores the search results associated with each address in different result table entries, and the number of result table entries is the same as the number of stored addresses, the storage space required to store the search results is large. Applying the technical solution provided in the embodiment of the present application, different search results are stored only once in the result table, and multiple addresses with the same associated search results can share one result table entry. When the forwarding behavior (that is, the search results) of the network device is less than the addresses that need to be stored, the storage space required to store the search results can be significantly reduced, the waste of storage space is reduced, and storage resources are further saved.
[0125] In some embodiments, the network device may establish an association relationship using an index. The first table entry may store a first index corresponding to the first address, and the above step S14 may be implemented by the following steps: storing the second index of the second table entry in the third table entry at the first index in the third lookup table.
[0126] In the embodiment of the present application, the address table item may store the index of the identification table item associated with the address in the third lookup table. The first index is the index of the third table item associated with the first address in the third lookup table, and the network device realizes the association between the first address and the third table item by storing the first index in the first table item.
[0127] The network device may also store the index of the result table item storing the search result in the second search table in the identification table item. The second index is the index of the second table item in the second search table. After obtaining the second table item, the network device may determine the position of the third table item in the third search table according to the first index, write the second index into the third table item, and associate the third table item with the second table item by storing the second index in the third table item. Then, through the association relationship between the third table item and the first address, the association between the first address and the second table item is achieved, that is, the association between the first address and the first search result is achieved.
[0128] In the embodiment of the present application, after determining the third table entry, the network device may write the first index into the first table entry to associate the first address with the third table entry.
[0129] When an uncompressed first lookup table is used to store addresses, the index corresponding to the address stored in the address table entry is stored in the result index field of the address table entry, and the network device can directly write the first index into the result index field of the first table entry.
[0130] When a compressed first lookup table is used to store addresses, the result index field of the address table entry can be divided into a base field and an index field. The base field is used to store the index corresponding to the first address stored in the address table entry (called the base index), and the index field stores the offsets of the indexes corresponding to all addresses relative to the base index in order. Still taking the four IP address prefixes in the above step S12 as an example, the indexes of the identification table items a to d associated with these four IP address prefixes are: 100, 101, 102 and 103 respectively. If the order in which these four IP address prefixes are stored in the address table items is: {192.172.0.0 / 16}, {192.173.0.0 / 16}, {192.174.0.0 / 16} and {192.175.0.0 / 16}, then the cardinality index is {100}, the content of the cardinality field is {100}, the offsets corresponding to all addresses are {00, 01, 10, 11}, and the content of the index field is {00, 01, 10, 11}, as shown in Table 1.
[0131] Table 1
[0132]
[0133] Among them, the keyword is the IP address prefix, which is only an example and is not actually stored in the address table entry; the public prefix is the public address field in the address table entry, and the content of the public address field is {192.172.0.0 / 14}; the special prefix is the special address field in the address table entry, and the content of the special address field is {00,01,10,11}. The content in the public address field and the content in the special address field constitute the IP address prefix; the cardinality is the cardinality field in the address table entry, and the content of the cardinality field is {100}; the index is the index field in the address table entry, and the content of the index field is {00,01,10,11}. The content in the cardinality field and the content in the index field constitute the index of identification table entry a to identification table entry d.
[0134] If the number of addresses stored in the first table entry is greater than 1, the network device may write the offset of the first index relative to the index corresponding to the first address into the index field of the first table entry in the order in which the addresses are stored in the first table entry. Typically, the first address is stored after the last address of other addresses, and the network device may write the corresponding offset after the offset corresponding to the last address.
[0135] If the number of addresses stored in the first table entry is equal to 1, the network device may write the first index into the base field of the first table entry, and write the offset (eg, 00) into the index field of the first table entry.
[0136] In an embodiment of the present application, the result index field may also include only the base field but not the index field, that is, the address table entry only stores the index corresponding to the first address, and the indexes corresponding to other addresses can be determined according to the order in which the addresses are stored to further save storage space.
[0137] In some embodiments, see Figure 2 , is a second flow chart of the table item storage method provided in the embodiment of the present application. The above table item storage method may include the following steps.
[0138] Step S21, obtaining a first address to be stored and a first search result associated with the first address.
[0139] Step S22: store the first address into a first table entry in a first lookup table, where the first lookup table is used to store addresses.
[0140] Step S23, searching the second table entry storing the first search result in the second search table, the second search table is used to store the search result. If the second table entry is not found, then execute step S24; if the second table entry is found, then execute step S25.
[0141] Step S24: create a second table entry in the second lookup table, and store the first lookup result in the second table entry.
[0142] Step S25 , associating the second table entry with a third table entry associated with the first address stored in the first table entry in the third lookup table, where the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0143] The above steps S21 and S22 are the same as the above steps S11 and S12. For the above step S23, reference may be made to the relevant description of the above step S13. The above step S25 is the same as the above step S14.
[0144] In the technical solution provided by the embodiment of the present application, when the network device fails to find the second table entry, a new second table entry is created to store the first search result, ensuring that the search results that need to be stored are stored in the second search table, so that the address-associated search results can be accurately found in subsequent searches.
[0145] In the above step S24, since the network device did not find the second table entry, the network device determined that the first search result was not stored in the second search table. The network device can allocate an empty position for the first search result in all empty positions in the second search table to create a new result table entry. The newly created result table entry is the second table entry, and the first search result is written into the second table entry.
[0146] In some embodiments, the second lookup table is also used to store a digest of the search result, that is, the result table item also stores a digest of the search result, and the length of the digest can be any length, for example, the length of the digest can be 1B, 2B, etc., which is not limited. The above step S13 can be implemented by the following steps: calculating the first digest of the first search result; searching the candidate table item storing the first digest in the second lookup table.
[0147] In the embodiment of the present application, the network device may calculate the hash value corresponding to the first search result through a hash algorithm, and use the hash value as the first summary of the first search result. The network device may search for the first summary in the summary stored in the result table item of the second search table, and the result table item storing the first summary is the candidate table item. The candidate table item indicates the result table item in the second search table that may store the first search result. The candidate table item may be one, multiple, or non-existent, and the number of candidate table items is not limited here.
[0148] Depending on whether the network device finds the candidate table entry, it can be divided into the following two situations.
[0149] Case 1: The network device finds a candidate table item. The network device obtains a candidate table item that may store the first search result, further searches for the first search result in the search results stored in the candidate table item, and determines whether the first search result is stored in the candidate table item, so as to determine whether the first search result is stored in the second search table.
[0150] If the network device finds the first search result in any candidate table item, the network device can determine that the first search result is stored in the candidate table item, that is, determine that the first search result is stored in the second search table. The network device can use the candidate table item storing the first search result as the second table item, and execute step S25 to establish an association relationship between the second table item and the third table item. For details, please refer to the relevant description of the above step S14.
[0151] If the network device does not find the first search result in all candidate entries, the network device may determine that the first search result is not stored in the candidate entry, that is, determine that the second entry is not found, and determine that the first search result is not stored in the second search table. In this case, the network device may create a second entry in the second search table, store the first search result in the newly created second entry, and establish an association relationship between the second entry and the third entry. For details, please refer to the relevant description of the above steps S24 and S14.
[0152] Case 2: The network device does not find the candidate table item. The network device determines that the candidate table item that may store the first search result does not exist, that is, it determines that the second table item is not found, and determines that the first search result is not stored in the second search table. In this case, the network device can create a second table item in the second search table, store the first search result in the newly created second table item, and establish an association relationship between the second table item and the third table item. For details, please refer to the relevant description of the above steps S24 and S14.
[0153] Based on the above description, see Figure 3 , is a third flow chart of the table item storage method provided in the embodiment of the present application. The above table item storage method may include the following steps.
[0154] Step S31, obtaining a first address to be stored and a first search result associated with the first address.
[0155] Step S32: store the first address into a first table entry in a first lookup table, where the first lookup table is used to store addresses.
[0156] Step S33: Calculate a first summary of the first search result.
[0157] Step S34, searching the second search table for a candidate entry storing the first summary. If the candidate entry is found, executing step S35; if the candidate entry is not found, determining that the second entry is not found, executing step S38;
[0158] Step S35, determine whether the first search result is stored in the candidate table item; if so, that is, the first search result is stored in the candidate table item, execute step S36; if not, that is, the first search result is not stored in the candidate table item, it is determined that the second table item is not found, and execute step S38.
[0159] Step S36: taking the candidate entry as the second entry.
[0160] Step S37: associate the second table entry with a third table entry associated with the first address stored in the first table entry in the third lookup table, where the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0161] Step S38, creating a second table entry in the second lookup table, storing the first lookup result in the second table entry, and executing step S37.
[0162] The above steps S31 to S32 are the same as the above steps S11 to S12, the above step S37 is the same as the above step S14, the above step S38 is the same as the above step S24, and the above steps S33 to S36 may refer to the relevant description of the above step S13 for details.
[0163] In the technical solution provided by the embodiment of the present application, the network device first searches for a candidate table item storing the first summary, and by searching the candidate table item, screens out the result table item that may store the first search result, and then searches for the first search result in the screened candidate table item. Since the length of the summary is less than the length of the search result, the network device can find the candidate table item more quickly to quickly narrow the search scope, thereby improving the efficiency of searching for the second table item. In addition, when the network device fails to find the candidate table item, it directly determines that the second table item has not been found, and no subsequent search is performed, thereby further improving the search efficiency.
[0164] In some embodiments, the network device can also delete table entries, that is, delete the stored address table entries and identification table entries in the first lookup table and the third lookup table respectively, and delete the result table entries stored in the second lookup table according to the specific situation. The network device can delete table entries by the following steps: obtaining a deletion instruction, the deletion instruction is used to instruct to delete the first address; deleting the first address, and deleting the association between the second table entry and the third table entry.
[0165] In the embodiment of the present application, the network device may receive a deletion instruction from other devices, and the other devices may be other network devices, or electronic devices such as computers and servers, which are not limited to this. The network device determines from the deletion instruction that the first address is to be deleted, deletes the first address, and the association between the first address and the third table item, and deletes the association between the second table item and the third table item.
[0166] When an uncompressed first lookup table is used to store addresses, or a compressed first lookup table is used to store addresses and the number of addresses stored in the first table entry is equal to 1, the network device may directly delete the first table entry to delete the first address.
[0167] When a compressed first lookup table is used to store addresses and the number of addresses stored in the first table entry is greater than 1, the network device can delete the special address of the first address in the special address field and delete the offset corresponding to the first address in the index field, that is, delete the first index corresponding to the first address in the first table entry to achieve deletion of the first address.
[0168] Before deleting the first address, the network device can first obtain the third table item associated with the first address from the third lookup table through the first index corresponding to the first address stored in the first table item, and delete the third table item to delete the association between the second table item and the third table item. By deleting unnecessary addresses in the first lookup table, the network device can free up storage space to store other addresses.
[0169] In the embodiment of the present application, the network device can also obtain the second table item associated with the third table item and storing the first search result from the second search table through the second index stored in the third table item, and determine whether there are other addresses other than the first address that reuse the first search result, that is, determine whether there are other addresses associated with the first search result. If it is determined that other addresses reuse the first search result, the network device does not delete the second table item; if it is determined that no other addresses reuse the first search result, the network device deletes the second table item to save storage resources.
[0170] In some embodiments, the second lookup table is also used to store the address quantity of the multiplexed search result, that is, the result table entry also stores the address quantity of the search result, indicating the number of addresses associated with the search result. The length of the address quantity can be any length, for example, the length of the address quantity can be 1B, 2B, etc., which is not limited.
[0171] The network device can use the following steps to delete the association between the second table entry and the third table entry: obtain the second table entry and the third table entry associated with the first address through the third lookup table and the second lookup table; delete the third table entry; if the number of addresses stored in the second table entry is greater than 1, reduce the number of addresses stored in the second table entry by 1; if the number of addresses stored in the second table entry is equal to 1, delete the second table entry.
[0172] In an embodiment of the present application, the network device obtains the third table entry associated with the first address from the third lookup table through the first index stored in the first table entry, and obtains the second table entry associated with the third table entry from the second lookup table through the second index stored in the third table entry, and deletes the third table entry.
[0173] The network device can determine whether there are other addresses that reuse the first search result based on the number of addresses. When the number of addresses stored in the second table item is greater than 1, the network device determines that there are other addresses that reuse the first search result, then the network device does not delete the second table item, and reduces the number of addresses by 1. When the number of addresses stored in the second table item is equal to 1, the network device determines that there are no other addresses that reuse the first search result, then the network device deletes the second table item. By storing the number of addresses that reuse the search result, the network device can quickly determine whether there are other addresses that reuse the search result, so as to improve the efficiency of deleting table items and save storage resources.
[0174] The network device may also determine whether other identification entries in the third lookup table besides the third entry also store the second index based on the second index stored in the third entry, so as to determine whether other addresses reuse the first lookup result, which is not limited.
[0175] In an embodiment of the present application, when the network device finds the second table entry, after associating the second table entry with the third table entry, the number of addresses stored in the second table entry can be increased by 1; when the network device does not find the second table entry, after creating the second table entry and associating the second table entry with the third table entry, the number of addresses stored in the second table entry can be set to 1.
[0176] In some embodiments, the network device can also modify the table item, that is, modify the search result stored in the corresponding result table item in the second lookup table. The network device can modify the table item by the following steps: obtaining a modification instruction, the modification instruction is used to instruct to modify the search result associated with the first address to the second search result; searching the second lookup table for a fourth table item storing the second search result; if the fourth table item is found, deleting the association between the second table item and the third table item, and associating the fourth table item with the third table item associated with the first address in the third lookup table.
[0177] In the embodiment of the present application, the network device may receive a modification instruction from other devices, and the other devices may be other network devices, or may be electronic devices such as computers and servers, which are not limited thereto. The network device determines from the modification instruction that the first search result associated with the first address is modified to the second search result, and the network device may delete the association relationship between the second table item and the third table item, and search for the second search result in the search results stored in the result table item of the second search table, and the result table item storing the second search result is the fourth table item. The network device determines whether the second search result has been stored in the second search table by searching the fourth table item.
[0178] If the network device finds the fourth table entry, that is, determines that the second search result has been stored in the second search table, the network device can establish an association relationship between the fourth table entry and the third table entry, that is, modify the second index stored in the third table entry to the index of the fourth table entry, so as to associate the fourth table entry storing the second search result with the first address.
[0179] If the network device does not find the fourth table item, that is, it determines that the second search result is not stored in the second search table, the network device can allocate an empty position for the second search result in all empty positions in the second search table to create a new result table item, the newly created result table item is the fourth table item, and the second search result is written into the fourth table item. Afterwards, the network device can establish an association relationship between the fourth table item and the third table item.
[0180] The specific process of the network device deleting the association relationship between the second table entry and the third table entry can be found in the relevant description of the above-mentioned deleting table entry part, which will not be described in detail here.
[0181] In the technical solution provided in the embodiment of the present application, the network device implements modification of the search result through the first address, the third lookup table and the second lookup table, and deletes the corresponding result table entry when it is determined that the search result is not associated with any address to save storage resources.
[0182] In an embodiment of the present application, the network device may also modify the address stored in the address table entry. In this case, the network device may first execute the step of deleting the table entry, and then execute the step of storing the table entry.
[0183] The table entry storage method provided in the embodiment of the present application is described in detail below.
[0184] Step 1: The network device receives a new LPM entry X (i.e., the first address) sent down, and the entry X includes the IP address prefix and the associated search result (i.e., the first search result). The network device first inserts the entry X into the prefix table (i.e., the first search table, i.e., the address table), and assigns a corresponding unique ID (i.e., the first index) to the entry X, and the ID entry (i.e., the third entry) in the corresponding index and identifier mapping table (i.e., the third search table, i.e., the identifier table).
[0185] Step 2: The network device calculates a digest (ie, a first digest) of the search result of the table entry X with a length of 5B.
[0186] Step 3: The network device uses the summary as a keyword to search in the result table, and determines whether the summary stored in the result table is the same as the summary corresponding to the entry X.
[0187] Step 4: If it is determined that the summary stored in the result table is the same as the summary corresponding to the entry X, the network device further accurately compares whether the search result stored in the result table is the same as the search result included in the entry X.
[0188] Step 5: If it is determined that the search result stored in the result table is the same as the search result included in the table item X, the network device can directly reuse the search result, increase the reuse quantity (i.e., the number of addresses) stored in the result table item (i.e., the second table item) by 1, and return the index R (i.e., the second index) of the result table item recorded in the result table.
[0189] Step 6, write the value of the ID-th entry in the index and identifier mapping table as R, that is, index_to_id[ID]=R.
[0190] Step 7: If it is determined that the summary stored in the result table is different from the summary corresponding to the table item X, that is, the summary corresponding to the table item X cannot be found in the result table, it means that the search result included in the table item X is a new search result that has not been recorded. The network device allocates a new table item in the result table, writes the search result included in the table item X, sets the number of multiplexes stored in the newly allocated table item to 1, returns the index R' of the newly allocated table item record in the result table, and returns to execute step 6.
[0191] Step 8: If it is determined that the summary stored in the result table is the same as the summary corresponding to the entry X, and it is determined that the search result stored in the result table is different from the search result included in the entry X, then execute step 7 and insert a new result entry.
[0192] By applying the technical solution provided in the embodiments of the present application, different search results are stored only once in the result table, and multiple addresses with the same associated search results can share one result table entry, reducing the storage space required to store the search results, compressing the result table, reducing the waste of storage space, and utilizing limited SRAM capacity to store more table entries, thereby providing a larger table entry specification.
[0193] Corresponding to the above-mentioned table item storage method, the embodiment of the present application also provides a table item search method, which can be applied to network devices such as routers and switches, and can also be applied to forwarding chips in network devices. For the convenience of description, the following will be based on network devices as the execution subject, which does not play a limiting role. Figure 4 , is a flow chart of a table entry search method provided in an embodiment of the present application. The above table entry search method includes the following steps.
[0194] Step S41, obtaining the second address to be searched.
[0195] Step S42, searching the first lookup table for a fifth entry storing the third address, the third address matches the second address, and the first lookup table is used to store addresses.
[0196] Step S43, obtaining a sixth table entry associated with the third address stored in the fifth table entry in the third lookup table, where the third lookup table is used to store a mapping relationship between addresses and lookup results.
[0197] Step S44, obtaining the seventh table item associated with the sixth table item in the second lookup table, where the second lookup table is used to store the lookup result.
[0198] Step S45: Use the search result stored in the seventh table entry as the third search result associated with the second address.
[0199] In the technical solution provided by the embodiment of the present application, after the network device stores the first address in the first table item, it first searches for the first search result associated with the first address in the stored search results, that is, searches for the second table item storing the first search result. If the second table item is found, it means that the first search result has been stored in the second search table, and the network device can directly reuse the first search result, establish an association relationship between the second table item and the third table item associated with the first address, and realize the association between the first address and the first search result without creating a new table item for storing the first search result. In the subsequent search process, the network device only needs to determine the search result associated with the address to be searched based on the table items associated with the address to be searched in the third search table and the second search table.
[0200] By applying the technical solution provided in the embodiment of the present application, the network device first searches for the search results to be stored, and determines whether the search results to be stored have been stored in the second search table. In this way, the same search results only need to be stored once in the second search table, saving the storage space required to store the search results, compressing the second search table, reducing the waste of storage space caused by repeated storage of search results, and then using the limited SRAM capacity to store more table items, providing a larger table item specification. At the same time, the network device can accurately find the search results associated with the address through the search results stored in the second search table and the mapping relationship between the address and the search results stored in the third search table, thereby ensuring the accuracy of the search.
[0201] In the above step S41, the second address is any address to be searched by the network device. In the embodiment of the present application, the address to be searched by the network device corresponds to the address stored in the first lookup table. For example, when the address stored in the first lookup table is an IP address or an IP address prefix, the address to be searched by the network device is an IP address. For another example, when the address stored in the first lookup table is other addresses such as a MAC address, the address to be searched by the network device is the corresponding other address. The address to be searched by the network device is not limited here.
[0202] The network device obtains the second address to be searched, and executes step S42 to match the second address in the first search table, that is, to search for an address table entry matching the second address.
[0203] When the address stored in the first lookup table is an IP address prefix, the second address is an IP address, and the network device uses the LPM algorithm to match the second address with the IP address prefix stored in the address table entry, and selects the IP address prefix with the longest length from the matched IP address prefixes as the third address matching the second address, and uses the address table entry storing the third address as the fifth table entry.
[0204] When the address stored in the first lookup table is an IP address, the second address is also an IP address. The network device searches for the second address in the addresses stored in the address table entry. The found address is the third address, and the address table entry storing the third address is used as the fifth entry.
[0205] If the network device does not search for the fifth table entry, the network device determines that the second address fails to match, and returns a result of failed matching.
[0206] In the embodiment of the present application, when an uncompressed first lookup table is used to store addresses, the network device can directly match the second address in the first lookup table to find the fifth table entry.
[0207] When a compressed first lookup table is used to store addresses, the network device can first match the second address with the public address stored in the public address field of the address table item. When the data of the first first length of the second address is the same as the public address, the remaining data of the second address is matched with the special address stored in the special address field of the address table item. When both the public address and the special address match, the network device determines that the second address matches.
[0208] The network device can also decompose the second address into public addresses and special addresses corresponding to the first lengths according to the first lengths of the address table items stored in the first lookup table, and calculate the index of the address table item according to the public addresses corresponding to the first lengths through a hash algorithm to determine whether there is an address table item at each index in the first lookup table. When it is determined that the address table item exists, the network device further searches for the corresponding special address to match the second address. The method of matching the second address is not limited here.
[0209] In the above step S43, since the address stored in the first lookup table is associated with the identification entry in the third lookup table, after finding the fifth entry, the network device can determine the identification entry associated with the third address stored in the fifth entry, which is the sixth entry.
[0210] In the above step S44, since the identification entry in the third lookup table is associated with the result entry in the second lookup table, after determining the sixth entry, the network device can determine the result entry associated with the sixth entry, which is the seventh entry.
[0211] In the above step S45, after obtaining the seventh table entry, the network device may extract a search result from the seventh table entry, and the extracted search result is the third search result associated with the second address.
[0212] In some embodiments, the network device may establish an association relationship using an index. The fifth table item stores a third index corresponding to the third address; the above step S43 may be implemented by the following steps: obtaining the sixth table item at the third index in the third lookup table. The above step S44 may be implemented by the following steps: obtaining the seventh table item at the fourth index stored in the sixth table item in the second lookup table.
[0213] In the embodiment of the present application, the address table item stores the index of the identification table item associated with the address in the third lookup table, and the third index is the index of the sixth table item associated with the third address stored in the fifth table item in the third lookup table. The network device can obtain the third index from the fifth table item, and obtain the identification table item at the third index in the third lookup table as the sixth table item through the third index.
[0214] When the uncompressed first lookup table is used to store the address, the network device may extract the content of the result index field of the fifth table entry to obtain the third index.
[0215] When a compressed first lookup table is used to store addresses, the network device can extract the content of the result index field of the fifth table item, extract the radix index from the radix field, and extract the offset corresponding to the third address from the index field, and obtain the third index through the radix index and the offset. If the result index field only includes the radix field, the network device can determine the offset corresponding to the third address according to the order of the third address in all addresses stored in the fifth table item. The way in which the network device obtains the third index is not limited here.
[0216] In the embodiment of the present application, the identification table item stores the index of the associated result table item in the second lookup table, and the fourth index is the index of the seventh table item stored in the sixth table item and associated with the sixth table item. The network device can obtain the fourth index from the sixth table item, and obtain the result table item at the fourth index in the second lookup table as the seventh table item through the fourth index.
[0217] In the technical solution provided in the embodiment of the present application, the network device realizes the association between the address and the identification table item by storing the index of the identification table item in the address table item, so as to quickly find the identification table item associated with the address; and realizes the association between the identification table item and the result table item by storing the index of the result table item in the identification table item, so as to quickly find the result table item associated with the identification table item, thereby improving the speed of table item search.
[0218] Below through Figure 5 and Figure 6 The table item storage and table item search method provided in the embodiment of the present application is described in detail, and the example of using a compressed first search table to store addresses and storing addresses as IP address prefixes is used for description, which is not limiting.
[0219] like Figure 5 The table entry structure is shown. Figure 5 The lookup table includes two lookup tables, namely, a prefix table storing IP address prefixes (i.e., a first lookup table, i.e., an address table) and a result table storing the lookup results (i.e., a second lookup table). For example, the prefix table stores two prefix table items (i.e., prefix group 1 and prefix group 2, i.e., address table items) and the result table stores five result table items.
[0220] Prefix group 1 stores three IP address prefixes (namely prefix_A, prefix_B, and prefix_C), and the search results associated with these three IP address prefixes (namely result_A, result_B, and result_C) are stored in three result table items of the result table, respectively. The indexes of these three result table items (namely index_1, index_2, and index_3) are stored in the corresponding positions of prefix group 1, thus realizing the association between the three IP address prefixes and the three search results. Prefix group 2 stores two IP address prefixes (namely prefix_X and prefix_Y), and the search results associated with these two IP address prefixes (namely result_X and result_Y) are stored in two result table items of the result table, respectively. The indexes of these two result table items (namely index_m and index_n) are stored in the corresponding positions of prefix group 2, thus realizing the association between the two IP address prefixes and the two search results.
[0221] When the size of the result table is 2M and the length of each search result is 5B, the maximum number of addresses that can be stored is 2M. Since the search result of each address needs to be stored, the storage of the search result requires 2M×5B=10MB of storage space. When the same search results exist in the result table entries of the result table, such as result_B and result_C are the same, and result_Y and result_A are the same, it will lead to a waste of storage space.
[0222] like Figure 6 The table entry structure is shown. Figure 6 The system includes three lookup tables, namely, a prefix table storing IP address prefixes, an index and identifier mapping table (i.e., the third lookup table, i.e., the identifier table), and a result table storing the lookup results. The index and identifier mapping table stores five identifier table entries.
[0223] The indexes stored in the prefix table (i.e., Index_1, Index_2, Index_3, Index_m, and Index_n) are the indexes of the identifier entries in the index and identifier mapping table, rather than the indexes of the result entries in the result table. The IP address prefix is associated with the identifier entry in the index and identifier mapping table through the corresponding index.
[0224] Since result_B is the same as result_C, and result_Y is the same as result_A, the result table only needs to store result table items including result_A, result_B, and result_X. At this time, the search result associated with prefix_A and prefix_Y is result_A, and the index of the result table item storing result_A is ID_A, so ID_A is stored in the identification table item associated with prefix_A and prefix_Y; the search result associated with prefix_B and prefix_C is result_B, and the index of the result table item storing result_B is ID_B, so ID_B is stored in the identification table item associated with prefix_B and prefix_C; the search result associated with prefix_X is result_X, and the index of the result table item storing result_X is ID_X, so ID_X is stored in the identification table item associated with prefix_X, thus realizing the association between 5 IP address prefixes and 3 search results. The result table item also includes a summary of each search result and the number of reuses of the search result (i.e., the number of addresses).
[0225] When the maximum number of addresses stored is still 2M, the length of each search result is 5B, and the length of the summary and reuse quantity is 1B respectively, the specification of the index and identification mapping table is 2M, and the length of the result table entry is 1+5+1=7B. Assuming that a maximum of 64K different search results are supported, that is, when the specification of the result table is 64K, the length of each identification table entry can be 2B, then the index and identification mapping table needs to occupy 2M×2B=4MB of storage space, and the result table needs to occupy 64K×7B=448KB of storage space. In addition, storing the search results requires a total of 4MB+448KB=4.4375MB, and calculating 4.4375MB / 10MB=0.44375, therefore, in the technical solution provided in the embodiment of the present application, the storage space occupied by storing the search results is only 44.375% of the existing solution.
[0226] By applying the technical solution provided in the embodiment of the present application, the two lookup tables of the original solution are expanded into three lookup tables: an address table, an index and identification mapping table, and a result table. The index and identification mapping table is used to realize a many-to-one mapping from multiple addresses to one lookup result.
[0227] Corresponding to the above-mentioned table item storage method embodiment, the present application embodiment also provides a table item storage device, see Figure 7 , is a schematic diagram of a structure of a table entry storage device provided in an embodiment of the present application. The table entry storage device includes:
[0228] A first acquisition module 71, used to acquire a first address to be stored and a first search result associated with the first address;
[0229] A storage module 72, used to store the first address into a first table entry in a first lookup table, where the first lookup table is used to store addresses;
[0230] A first search module 73, used to search a second table entry storing the first search result in a second search table, where the second search table is used to store the search result;
[0231] The association module 74 is used to associate the second table entry with a third table entry associated with the first address stored in the first table entry in the third lookup table if the second table entry is found, and the third lookup table is used to store the mapping relationship between the address and the lookup result.
[0232] In the technical solution provided by the embodiment of the present application, after the first address is stored in the first table item, the first search result associated with the first address is first searched in the stored search results, that is, the second table item storing the first search result is searched. If the second table item is found, it means that the first search result has been stored in the second search table, and the first search result can be directly reused to establish an association relationship between the second table item and the third table item associated with the first address, so as to realize the association between the first address and the first search result, without the need to create a new table item storing the first search result. In the subsequent search process, it is only necessary to determine the search result associated with the address to be searched based on the table items associated with the address to be searched in the third search table and the second search table. Applying the technical solution provided by the embodiment of the present application, the search result to be stored is first searched to determine whether the search result to be stored has been stored in the second search table. In this way, the same search result only needs to be stored once in the second search table, saving the storage space required for storing the search result, realizing compression of the second search table, reducing the waste of storage space caused by repeated storage of the search result, and then using the limited SRAM capacity to store more table items, providing a larger table item specification.
[0233] In some embodiments, the association module 74 may also be used to:
[0234] If the second table entry is not found, creating a second table entry in the second lookup table;
[0235] Storing the first search result in the second table item;
[0236] The step of associating the second entry with a third entry in the third lookup table associated with the first address stored in the first entry is performed.
[0237] In some embodiments, the first table entry may store a first index corresponding to the first address; the above-mentioned association module 74 may be specifically used for:
[0238] The second index of the second entry is stored in the third entry at the first index in the third lookup table.
[0239] In some embodiments, the second lookup table may also be used to store a summary of the search result; the storage module 72 may be specifically used to:
[0240] Calculate a first digest of a first search result;
[0241] searching the second lookup table for a candidate entry storing the first digest;
[0242] If a candidate entry is found, determining whether the first search result is stored in the candidate entry;
[0243] If the first search result is stored, the candidate entry is used as the second entry.
[0244] In some embodiments, the storage module 72 may also be used to:
[0245] If the candidate entry is not found, or it is determined that the first search result is not stored in the candidate entry, it is determined that the second entry is not found.
[0246] In some embodiments, the above-mentioned table item storage device may further include a deletion module, which is used to:
[0247] Obtaining a deletion instruction, where the deletion instruction is used to instruct to delete the first address;
[0248] The first address is deleted, and the association between the second entry and the third entry is deleted.
[0249] In some embodiments, the above-mentioned table item storage device may further include a modification module, which is used to:
[0250] Obtain a modification instruction, where the modification instruction is used to instruct to modify the search result associated with the first address to be a second search result;
[0251] Searching the second lookup table for a fourth table entry storing the second lookup result;
[0252] If the fourth table entry is found, the association relationship between the second table entry and the third table entry is deleted, and the fourth table entry is associated with the third table entry associated with the first address in the third lookup table.
[0253] In some embodiments, the second lookup table may also be used to store the number of addresses of the multiplexed lookup results; the above-mentioned deletion module or modification module may be specifically used to:
[0254] Obtaining a second table entry and a third table entry associated with the first address through a third lookup table and a second lookup table;
[0255] Delete the third table item;
[0256] If the number of addresses stored in the second entry is greater than 1, the number of addresses stored in the second entry is reduced by 1; if the number of addresses stored in the second entry is equal to 1, the second entry is deleted.
[0257] Corresponding to the above-mentioned table entry search method embodiment, the present application embodiment also provides a table entry search device, see Figure 8 , is a schematic diagram of a structure of a table entry search device provided in an embodiment of the present application, the table entry search device comprising:
[0258] A second acquisition module 81, used to acquire a second address to be searched;
[0259] A second search module 82, configured to search a fifth table entry storing a third address in the first search table, the third address matching the second address, the first search table being used to store addresses;
[0260] A third acquisition module 83, used to acquire a sixth table item associated with a third address stored in a fifth table item in a third lookup table, where the third lookup table is used to store a mapping relationship between addresses and lookup results;
[0261] A fourth acquisition module 84, used to acquire a seventh table item associated with a sixth table item in a second lookup table, where the second lookup table is used to store the lookup result;
[0262] The obtaining module 85 is used to use the search result stored in the seventh table entry as the third search result associated with the second address.
[0263] In the technical solution provided by the embodiment of the present application, after the first address is stored in the first table item, the first search result associated with the first address is first searched in the stored search results, that is, the second table item storing the first search result is searched. If the second table item is found, it means that the first search result has been stored in the second search table, and the first search result can be directly reused to establish an association relationship between the second table item and the third table item associated with the first address, so as to realize the association between the first address and the first search result, without the need to create a new table item for storing the first search result. In the subsequent search process, the search result associated with the address to be searched can be determined based on the table items associated with the address to be searched in the third search table and the second search table.
[0264] By applying the technical solution provided in the embodiment of the present application, the search results to be stored are first searched to determine whether the search results to be stored have been stored in the second search table. In this way, the same search results only need to be stored once in the second search table, saving the storage space required for storing the search results, compressing the second search table, reducing the waste of storage space caused by repeated storage of search results, and then using the limited SRAM capacity to store more table items, providing a larger table item specification. At the same time, through the search results stored in the second search table and the mapping relationship between the address and the search results stored in the third search table, the search results associated with the address are accurately found, ensuring the accuracy of the search.
[0265] In some embodiments, the fifth table entry may store a third index corresponding to the third address; the third acquisition module 83 may be specifically used to: acquire a sixth table entry at the third index in the third lookup table;
[0266] The fourth acquisition module 84 may be specifically used to acquire the seventh entry at the fourth index stored in the sixth entry in the second lookup table.
[0267] The present application also provides a network device, such as Fig. 9 As shown, it includes a processor 91, a communication interface 92, a memory 93 and a communication bus 94, wherein the processor 91, the communication interface 92 and the memory 93 communicate with each other through the communication bus 94;
[0268] Memory 93, used for storing computer programs;
[0269] The processor 91 is used to implement the steps of any of the above-mentioned table item storage methods or table item search methods when executing the program stored in the memory 93.
[0270] The communication bus mentioned in the above network device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0271] The communication interface is used for communication between the above network devices and other devices.
[0272] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0273] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0274] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, any of the above-mentioned table entry storage methods or table entry search methods is implemented.
[0275] In another embodiment provided in the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the steps of any table entry storage method or table entry search method in the above embodiments.
[0276] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
[0277] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0278] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, network device, computer storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0279] The above description is only a preferred embodiment of the present application and is not intended to limit the protection 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
1. A table entry storage method, characterized in that: The method comprises: Obtaining a first address to be stored and a first search result associated with the first address; Storing the first address in a first table entry in a first lookup table, the first lookup table being used to store addresses; Calculating a first summary of the first search result; searching a second lookup table for a candidate table entry storing the first summary, wherein the second lookup table is used to store a search result and a summary of the search result; If the candidate entry is found, determining whether the first search result is stored in the candidate entry; If the first search result is stored, taking the candidate entry as the second entry; If the second entry is found, the second entry is associated with the third entry in the third lookup table to associate the second entry with the first address. The third lookup table is used to store the mapping relationship between the address and the lookup result, and the third entry is associated with the first address stored in the first entry.
2. The method according to claim 1, characterized in that The method further comprises: If the second table entry is not found, creating the second table entry in the second lookup table; Storing the first search result in the second table item; The step of associating the second entry with a third entry in a third lookup table is performed.
3. The method according to claim 1 or 2, characterized in that: The first table entry stores a first index corresponding to the first address; The step of associating the second entry with a third entry in a third lookup table comprises: The second index of the second entry is stored in the third entry at the first index in the third lookup table.
4. The method according to claim 1, characterized in that: The method further comprises: If the candidate entry is not found, or if it is determined that the first search result is not stored in the candidate entry, it is determined that the second entry is not found.
5. The method according to claim 1, characterized in that The method further comprises: Obtaining a deletion instruction, where the deletion instruction is used to instruct to delete the first address; The first address is deleted, and the association between the second entry and the third entry is deleted.
6. The method according to claim 1, characterized in that The method further comprises: Obtain a modification instruction, where the modification instruction is used to instruct to modify the search result associated with the first address to be a second search result; Searching the second lookup table for a fourth table entry storing the second lookup result; If the fourth table entry is found, the association relationship between the second table entry and the third table entry is deleted, and the fourth table entry is associated with the third table entry associated with the first address in the third lookup table.
7. The method according to claim 5 or 6, characterized in that: The second lookup table is also used to store the address quantity of the multiplexed lookup result; The step of deleting the association relationship between the second entry and the third entry includes: Obtaining the second table entry and the third table entry associated with the first address through the third lookup table and the second lookup table; Delete the third table item; If the number of addresses stored in the second table entry is greater than 1, the number of addresses stored in the second table entry is reduced by 1; if the number of addresses stored in the second table entry is equal to 1, the second table entry is deleted.
8. A table entry search method, characterized in that: The method comprises: Get the second address to be found; searching a fifth table entry storing a third address in a first lookup table, the third address matching the second address, the first lookup table being used to store addresses, the addresses stored in the first lookup table being associated with the table entries in the third lookup table, the third address stored in the fifth table entry being associated with a sixth table entry in the third lookup table, the third lookup table being used to store a mapping relationship between addresses and lookup results; Obtain a sixth table entry in a third lookup table, wherein the table entry in the third lookup table is associated with the table entry in the second lookup table, and the sixth table entry is associated with the seventh table entry in the second lookup table, and the second lookup table is used to store the lookup result; Obtain the seventh table entry in the second lookup table; The search result stored in the seventh table entry is used as a third search result associated with the second address.
9. The method according to claim 8, characterized in that The fifth table entry stores a third index corresponding to the third address; The step of obtaining the sixth table entry associated with the third address stored in the fifth table entry in the third lookup table includes: Obtain a sixth entry at the third index in the third lookup table; The step of obtaining the seventh table entry associated with the sixth table entry in the second lookup table includes: The seventh table entry at the fourth index stored in the sixth table entry in the second lookup table is obtained.
10. A table entry storage device, characterized in that: The device comprises: A first acquisition module, used to acquire a first address to be stored and a first search result associated with the first address; A storage module, used for storing the first address into a first table entry in a first lookup table, where the first lookup table is used for storing addresses; a first search module, configured to calculate a first summary of the first search result; search a candidate table item storing the first summary in a second search table, the second search table being configured to store the search result and the summary of the search result; if the candidate table item is found, determine whether the first search result is stored in the candidate table item; if the first search result is stored, use the candidate table item as the second table item; An association module is used to associate the second table entry with a third table entry in a third lookup table if the second table entry is found, so as to associate the second table entry with the first address, the third lookup table is used to store a mapping relationship between an address and a lookup result, and the third table entry is associated with the first address stored in the first table entry.
11. A table entry search device, characterized in that: The device comprises: A second acquisition module, used to acquire a second address to be searched; a second search module, configured to search a fifth table entry storing a third address in the first search table, the third address matching the second address, the first search table being configured to store addresses, the addresses stored in the first search table being associated with the table entries in the third search table, the third address stored in the fifth table entry being associated with the sixth table entry in the third search table, the third search table being configured to store a mapping relationship between addresses and search results; A third acquisition module, used to acquire a sixth table item in a third lookup table, wherein the table items in the third lookup table are associated with table items in a second lookup table, wherein the sixth table item is associated with a seventh table item in the second lookup table, and the second lookup table is used to store the lookup result; A fourth acquisition module, used to acquire a seventh table entry in the second lookup table; The obtaining module is used to use the search result stored in the seventh table entry as the third search result associated with the second address.
12. A network device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; A processor, for implementing any method of claims 1-7 or any method of claims 8-9 when executing a program stored in a memory.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of claims 1 to 7 or any one of claims 8 to 9 is implemented.
Citation Information
Patent Citations
Method for storing and searching routing list and device therefor
CN101783761A
Table item construction method and device, table item search method and device, network equipment and storage medium
CN117221224A