TCAM Multi-Priority Storage Method, Apparatus and Readable Storage Medium
By judging the index maximum value of the entry in TCAM and the index maximum value of the adjacent priority, and using shift rules to realize multi-priority storage in TCAM, the problem of difficulty in inserting entries in TCAM is solved, ensuring that high-priority entries are found first.
Patent Information
- Application Number
- CN202210952049.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-09
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2042-08-09
AI Technical Summary
The prior art cannot effectively realize the storage of multiple priority in TCAM, resulting in the inability to insert entries in priority order, especially when the priority exceeds two, resulting in the failure of insertion.
By determining whether the entry to be inserted is a first-time storage entry, the index maximum value and the index maximum value of the adjacent priority determine whether there is a blank index. If not, the index maximum value of other priority is shifted based on the preset shift rule to obtain the target index, and the index maximum value of each priority is updated to insert the entry.
It realizes the storage of entry under multiple priority in TCAM, ensuring that high priority entries are found first, and solves the problem of difficulty in inserting multiple priority in the prior art.
Smart Images

Figure CN115422406B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technologies, and particularly to a TCAM multi-priority storage method, apparatus, and readable storage medium. Background Art
[0002] TCAM (Ternary Content Addressable Memory) is a commonly used table entry in the design of switching chips. Among them, the search order of TCAM is from front to back, that is, the smaller the index value, the higher the priority, and the larger the index value, the lower the priority. Currently, the commonly used TCAM is configured for two priorities, that is, the high priority is allocated from front to back, and the low priority is allocated from back to front.
[0003] However, in actual use, there are scenarios where the priority corresponding to an entry exceeds two, and the priorities are strictly matched; for example, entries 1 to 5 correspond to priorities 0 to 4 respectively. At this time, if an entry 6 with a priority of 3 needs to be inserted into the TCAM, according to the existing principle of allocating the high priority from front to back and the low priority from back to front, it will cause the entry 6 with a priority of 3 to be unable to be inserted between priorities 4 and 2. Thus, how to achieve multi-priority storage of TCAM is an urgent problem to be solved currently. Summary of the Invention
[0004] This application provides a TCAM multi-priority storage method, apparatus, and readable storage medium to solve the problem in related technologies that multi-priority storage of TCAM cannot be achieved.
[0005] In a first aspect, a TCAM multi-priority storage method is provided, including the following steps:
[0006] When a to-be-inserted entry is detected, determine whether the to-be-inserted entry is the first stored entry in the corresponding first priority;
[0007] If not, determine whether there is an index for storing the to-be-inserted entry according to the index maximum and minimum in the first priority and the index maximum and minimum in the second priority adjacent to the first priority;
[0008] If not, shift the entry corresponding to the index maximum and minimum in other priorities based on a preset shift rule to obtain a target index;
[0009] Insert the to-be-inserted entry into the position corresponding to the target index, and update the index maximum and minimum in each priority.
[0010] In some embodiments, the shifting the entry corresponding to the index maximum and minimum in other priorities based on a preset shift rule to obtain a target index includes:
[0011] Determine whether the second priority adjacent to the first priority is an invalid priority;
[0012] If not, determine whether there are entries stored in the second priority;
[0013] If there are entries stored in the second priority, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority;
[0014] If it can be successfully shifted, shift the entry corresponding to the first index extreme value to the target position, and use the first index extreme value as the target index of the first priority.
[0015] In some embodiments, after the step of determining whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority, it further includes:
[0016] If it cannot be successfully shifted, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the position corresponding to the third index extreme value in the third priority adjacent to the second priority, where the first index extreme value and the third index extreme value are index extreme values with the same attribute, and the first index extreme value is adjacent to the index extreme value in the first priority;
[0017] If it can be successfully shifted, shift the entry corresponding to the first index extreme value to the position corresponding to the third index extreme value, and use the first index extreme value as the target index of the first priority.
[0018] In some embodiments, after the step of determining whether the second priority adjacent to the first priority is an invalid priority, it further includes:
[0019] If the second priority adjacent to the first priority is an invalid priority, then determine whether the fourth priority adjacent to the first priority in the other direction is an invalid priority;
[0020] If the fourth priority is not an invalid priority, then use the fourth priority as the second priority and execute the step of determining whether there are entries stored in the second priority.
[0021] In some embodiments, the determining whether there is an index for storing the entry to be inserted according to the index extreme value in the first priority and the index extreme value in the second priority adjacent to the first priority includes:
[0022] When the maximum index of the first priority is greater than or equal to the difference between the minimum index in the second priority and 1, it is determined that there is no index for storing the entry to be inserted, where the second priority is lower than the first priority, or;
[0023] When the maximum index in the second priority is greater than or equal to the difference between the minimum index in the first priority and 1, it is determined that there is no index for storing the entry to be inserted, and the second priority is higher than the first priority.
[0024] In some embodiments, after the step of determining whether the entry to be inserted is the initial storage entry in the corresponding first priority, the method further includes:
[0025] If the entry to be inserted is the initial storage entry in the first priority, detect whether the starting index of the first priority is occupied;
[0026] If so, determine whether the first priority is the highest priority or the lowest priority;
[0027] If the first priority is neither the highest priority nor the lowest priority, determine whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1;
[0028] If not, determine that there is no index for storing the entry to be inserted, and perform the step of shifting the entry corresponding to the index extreme value in other priorities based on the preset shifting rule to obtain the target index;
[0029] Wherein, the second priority is higher than the first priority and is adjacent to the first priority, and the third priority is lower than the first priority and is adjacent to the first priority.
[0030] In some embodiments, after the step of determining whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, the method further includes:
[0031] If the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, determine that there is an index for storing the entry to be inserted;
[0032] Insert the entry to be inserted into a position close to the starting index according to the proximity principle, and update the index extreme value of the first priority.
[0033] In some embodiments, the method further includes:
[0034] When a deletion entry is detected, determine whether at least two indexes in the target priority corresponding to the deletion entry are occupied;
[0035] If so, determine whether the first index corresponding to the deletion entry is the maximum index of the target priority;
[0036] If so, delete the deletion entry, and update the maximum index of the target priority to the difference between the first index and 1;
[0037] Otherwise, delete the entry to be deleted, shift the entry corresponding to the maximum index of the target priority to the position corresponding to the first index, and update the maximum index of the target priority.
[0038] In a second aspect, a TCAM multi-priority storage device is provided, including:
[0039] A first determination unit, configured to determine whether the entry to be inserted is the first stored entry in the corresponding first priority when detecting the entry to be inserted;
[0040] A second determination unit, configured to, if not, determine whether there is an index for storing the entry to be inserted according to the index maximum value in the first priority and the index maximum value in the second priority adjacent to the first priority;
[0041] An entry shifting unit, configured to, if not, shift the entry corresponding to the index maximum value in other priorities based on a preset shifting rule to obtain a target index;
[0042] An entry insertion unit, configured to insert the entry to be inserted into the position corresponding to the target index and update the index maximum values in each priority.
[0043] In a third aspect, a computer-readable storage medium is provided. The computer storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is caused to execute the foregoing TCAM multi-priority storage method.
[0044] The beneficial effects brought by the technical solution provided by this application include: realizing the storage of TCAM multi-priority entries.
[0045] This application provides a TCAM multi-priority storage method, device and readable storage medium, including determining whether the entry to be inserted is the first stored entry in the corresponding first priority when detecting the entry to be inserted; if not, determining whether there is an index for storing the entry to be inserted according to the index maximum value in the first priority and the index maximum value in the second priority adjacent to the first priority; if not, shifting the entry corresponding to the index maximum value in other priorities based on a preset shifting rule to obtain a target index; inserting the entry to be inserted into the position corresponding to the target index and updating the index maximum values in each priority. Through this application, it is possible to determine whether there is a blank index for storing the entry to be inserted based on the index maximum values of each priority, and perform a shifting operation on the entry corresponding to the index maximum value, so that the entry to be inserted can be inserted into the corresponding priority, and finally realize the storage of the entry to be inserted under TCAM multi-priority. Description of the Drawings
[0046] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the accompanying drawings required for the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0047] Figure 1 It is a schematic flowchart of a TCAM multi-priority storage method provided by an embodiment of the present application;
[0048] Figure 2 It is a schematic diagram of the multi-priority critical state in TCAM provided by an embodiment of the present application;
[0049] Figure 3 It is a schematic structural diagram of a TCAM multi-priority storage device provided by an embodiment of the present application;
[0050] Figure 4 It is a schematic structural diagram of a TCAM multi-priority storage device provided by an embodiment of the present application. Specific implementation manners
[0051] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts fall within the protection scope of the present application.
[0052] The embodiments of the present application provide a TCAM multi-priority storage method, device, and readable storage medium, which can solve the problem that TCAM multi-priority storage cannot be achieved in the related art.
[0053] Figure 1 It is a TCAM multi-priority storage method provided by an embodiment of the present application, including the following steps:
[0054] Step S10: When a to-be-inserted entry is detected, determine whether the to-be-inserted entry is the first storage entry in the corresponding first priority;
[0055] Exemplarily, in this embodiment, the priority areas are divided in TCAM to form respective priority blocks. It should be noted that the priority blocks involved in this embodiment are not fixed storage spaces in the traditional sense, but are formed by the recorded minimum index and maximum index of each priority; in addition, the minimum index and maximum index referred to in the present application are both indexes occupied by entries.
[0056] For example, taking the scenario where there are 6 priorities for entries as an example, where the priority is expressed as "priority", 5 is the highest level and 0 is the lowest level; assuming the storage space of the TCAM is 30 bytes, the storage space can be evenly divided into 6 blocks, such that each priority has a corresponding starting index. That is, the starting indices of priority5 to priority0 are 0, 5, 10, 15, 20, and 25 in sequence. At this time, if the occupied indices of priority5 are 0, 1, and 2, it means that there are 3 entries with a priority of priority5 stored in the TCAM. Then the minimum index of priority5 (i.e., pri_low_idx[5]) is 0 and the maximum index (i.e., pri_high_idx[5]) is 2. At this time, pri_low_idx[5]=0 to pri_high_idx[5]=2 form the priority block corresponding to priority5. Similarly, if all the indices of priority4 to priority0 are occupied, then pri_low_idx[4]=5 to pri_high_idx[4]=9 form the priority block corresponding to priority4, pri_low_idx[3]=10 to pri_high_idx[3]=14 form the priority block corresponding to priority3, pri_low_idx[2]=15 to pri_high_idx[2]=19 form the priority block corresponding to priority2, pri_low_idx[1]=20 to pri_high_idx[1]=24 form the priority block corresponding to priority1, and pri_low_idx[0]=25 to pri_high_idx[0]=29 form the priority block corresponding to priority0.
[0057] However, at this time, if there is an entry A with a priority of priority4 to be inserted, since all the indexes under priority4 have been occupied, and only index 3 and index 4 are not occupied at this time, the entry A will be allocated to the position closer to the starting index of priority4 (i.e., the position with index 4). Then, pri_low_idx[4] of priority4 will change from 5 to 4, so the priority block corresponding to priority4 is formed by pri_low_idx[4]=4 to pri_high_idx[4]=9. It can be seen that each priority block in this embodiment is determined according to the minimum index and the maximum index of each priority, that is, as long as the minimum index and the maximum index change, the priority block corresponding to the priority will also change accordingly. Therefore, there are no overlapping areas between the respective priority blocks, so that it can be ensured that entries with a higher priority can definitely be found prior to entries with a lower priority.
[0058] Therefore, in this embodiment, it is necessary to store the management storage information for each priority, such as: whether there are entries stored in each priority and the indexes occupied by the stored entries, the minimum index (i.e., the priority lower limit) pri_low_idx occupied by each priority, and the maximum index (i.e., the priority upper limit) pri_high_idx occupied by each priority, etc.
[0059] When initially allocating a certain priority, since the indexes initially set for this priority may have been occupied by entries of other priorities, resulting in the minimum index and the maximum index of this priority being invalid, it is necessary to separate the implementation method of this priority from the priorities that have been allocated. Therefore, in this embodiment, when detecting an entry to be inserted, it can be determined whether the entry to be inserted is the first stored entry in the corresponding first priority according to the stored management storage information, that is, to determine whether the priority corresponding to the entry to be inserted is initially allocated. For example, if there is an entry A with a priority of priority4 to be inserted, and since all the indexes in priority4 have been occupied by the entries with a priority of priority4, the entry A is not the first stored entry in priority4, that is, priority4 is not initially allocated.
[0060] Step S20: If not, determine whether there is an index for storing the entry to be inserted according to the index extreme values in the first priority and the index extreme values in the second priority adjacent to the first priority;
[0061] Exemplarily, in this embodiment, if the entry to be inserted is not the first stored entry in the corresponding first priority, it is necessary to determine whether there is an unallocated blank index value around the first priority for the entry to be inserted to be stored according to the index maximum value in the first priority and the index maximum value in the second priority adjacent to the first priority, and then determine whether a shift operation is required so that the entry to be inserted can be stored under the corresponding priority.
[0062] Specifically, when the maximum index of the first priority is greater than or equal to the difference between the minimum index in the second priority and 1, it is determined that there is no index for storing the entry to be inserted, where the second priority is lower than the first priority, or;
[0063] When the maximum index in the second priority is greater than or equal to the difference between the minimum index in the first priority and 1, it is determined that there is no index for storing the entry to be inserted, where the second priority is higher than the first priority.
[0064] Exemplarily, taking pri_low_idx[4]=5 and pri_high_idx[4]=7 for priority4, pri_low_idx[3]=10 and pri_high_idx[3]=14 for priority3, pri_low_idx[2]=15 and pri_high_idx[2]=19 for priority2, and pri_low_idx[1]=20 to pri_high_idx[1]=22 for priority1 as an example: Suppose there is an entry B with priority priority2 to be inserted. Since pri_low_idx[1]-1 = 19 for priority1, that is, the difference between the minimum index of priority1 and 1 is 19, which is equal to the maximum index of priority2, so there is no unallocated blank index value between priority2 and priority1 for entry B to be inserted and stored; at the same time, since pri_low_idx[2]-1 = 14 for priority2, that is, the difference between the minimum index of priority2 and 1 is 14, which is equal to the maximum index of priority3, so there is also no unallocated blank index value between priority2 and priority3 for entry B to be inserted and stored. At this time, a shift operation is required to enable entry B to be stored under priority2;
[0065] Again, assume that there is an entry C with priority priority3 that needs to be inserted. Since pri_low_idx[2] - 1 of priority2 is 14, that is, the difference between the minimum index of priority2 and 1 is 14, which is equal to the maximum index 14 of priority3. Therefore, there is no blank unallocated index value between priority2 and priority3 for entry C to be inserted and stored. At this time, the return value is empty, indicating that a shift insertion operation needs to be performed. At the same time, since pri_low_idx[3] - 1 of priority3 is 9, that is, the difference between the minimum index of priority3 and 1 is 9, which is not equal to the maximum index 7 of priority4, that is, there are blank unallocated index values (i.e., index 8 and index 9) between priority3 and priority4 for entry C to be inserted and stored. So, entry C can be stored under priority3 without a shift operation. At this time, tmp_idx (i.e., index 8 or index 9) can be returned and assigned to entry C. Therefore, in this embodiment, a non-shift insertion operation will be performed based on tmp_idx. Among them, according to the proximity principle, the index 9 closer to pri_low_idx[3] can be preferably selected as tmp_idx, which can reduce the number of shift operations during subsequent entry insertions.
[0066] Step S30: If not, shift the entry corresponding to the index extreme value in other priorities based on the preset shift rule to obtain the target index;
[0067] Exemplarily, in this embodiment, if there is no blank unallocated index value around the first priority for the entry to be inserted to be inserted and stored, a shift operation needs to be performed to enable the entry to be inserted to be stored under the corresponding priority. For example, as shown in Figure 2 As shown, the six priorities are independent of each other and are marked with boundaries formed by the minimum index and the maximum index. And priorities 4, 3, 2, and 1 form a critical state. For example, pri_low_idx[5] of priority5 is 0 and pri_high_idx[5] is 2, pri_low_idx[4] of priority4 is 5 and pri_high_idx[4] is 9, pri_low_idx[3] of priority3 is 10 and pri_high_idx[3] is 14, pri_low_idx[2] of priority2 is 15 and pri_high_idx[2] is 19, pri_low_idx[1] of priority1 is 20 to pri_high_idx[1] is 22, and pri_low_idx[0] of priority0 is 25 and pri_high_idx[0] is 27.
[0068] When inserting entry D with a priority of priority3, since priorities 4, 3, 2, and 1 all form a critical state, that is, there are no blank and unallocated index values between priority2 and priority3 and between priority3 and priority4 for entry D to be inserted and stored. At this time, a shift operation is required. In this embodiment, it is possible to first determine whether it is possible to shift backward. At this time, it is necessary to judge the chained shift of priority2 and priority1. Of course, it is also possible to first determine whether it is possible to shift forward, then it is necessary to judge the shift of priority4. No matter which method is used, as long as it meets the shift principle of moving the entry corresponding to the smallest index to an index behind the largest index or moving the entry corresponding to the largest index to an index in front of the smallest index to vacate an index for inserting entry D for priority3.
[0069] Further, shifting the entry corresponding to the index extreme value in other priorities based on the preset shift rule to obtain the target index includes:
[0070] Judging whether the second priority adjacent to the first priority is an invalid priority;
[0071] If not, judging whether there is an entry stored in the second priority;
[0072] If there is an entry stored in the second priority, judging whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority;
[0073] If it can be successfully shifted, shifting the entry corresponding to the first index extreme value to the target position and using the first index extreme value as the target index of the first priority.
[0074] Exemplarily, in this embodiment, it is first necessary to determine whether the current priority for the shift operation is valid. Suppose the minimum priority is 0 and the maximum priority is 6, then both priority -1 and priority 7 are invalid priorities. Then, if the shift operation detection function finds that the current priority is -1, it means that the backward shift is unsuccessful. At this time, the return value is full, and no actual backward shift operation is performed. Similarly, if the shift operation detection function finds that the current priority is 7, it means that the forward shift is unsuccessful, and no actual forward shift operation is performed. For example, assume that the priority of the entry E to be inserted is priority0 and all indexes under priority0 have been occupied. At this time, it is impossible to free up an index for storing the entry E to be inserted by backward shifting (that is, priority -1 is an invalid priority and cannot be shifted), and only forward shifting (that is, shifting the entries under priority1) can be used to free up an index for storing the entry E to be inserted.
[0075] If the current priority is a valid priority, it is also necessary to determine whether there is an entry stored in the current priority to decide whether to perform a shift operation judgment on the entries in the current priority and finally determine whether an actual shift operation can be performed. Among them, for the shift operation in this embodiment, it is necessary to first determine whether the shift can be successful. If it can be successful, record the information of the relevant shift steps, and then perform the actual shift operation according to the recorded shift step information, and revise the storage information of each priority while performing the actual shift.
[0076] In addition, the storage data for recording the shift steps can be mov_src[] and mov_dst[], where mov_src[] represents the entry to be shifted corresponding to the index to be shifted, and mov_dst[] represents the target index for storing the entry to be shifted. For example, before shifting, pri_low_idx[3]=5 and pri_high_idx[3]=7 for priority3, pri_low_idx[2]=8 and pri_high_idx[2]=10 for priority2, pri_low_idx[1]=11 and pri_high_idx[1]=13 for priority1; at this time, the entry F with priority priority2 needs to be inserted. If the entry 11 of priority1 is moved to the blank index 14 behind pri_high_idx[1], then mov_src[1]=11 and mov_dst[1]=pri_high_idx[1]+1 = 14.
[0077] Specifically, taking the shift insertion and looking backward first as an example: if the shift operation detection function does not find that the current priority is an invalid priority, then step N10 is executed;
[0078] Step N10: Determine whether there is an entry stored for the current priority 'priority'. If so, go to Step N20; if not, go to Step N50;
[0079] Step N20: Add a new record in the shift step information that the current shift is to shift the minimum index of the current priority to the index immediately after the maximum index, i.e., mov_src[priority]=pri_low_idx[priority], mov_dst[priority]=1 + pri_high_idx[priority], and then go to Step N30;
[0080] Step N30: Determine whether the shift operation mov_dst[priority] will shift to the minimum index of the next priority. If so, go to Step N40; if not, go to Step N70;
[0081] Step N40: Determine whether the next priority can be shifted successfully. If so, go to Step N70; if not, go to Step N60;
[0082] Step N50: Record in the shift step information that the current priority 'priority' does not require a shift operation, and take the next priority as the current priority and execute Step N10;
[0083] Step N60: Clear the relevant stored information about look - behind in the shift step information, indicating that no actual look - behind shift operation is required;
[0084] Step N70: End the shift judgment and return that the shift is successful, indicating that an actual look - behind shift operation is required.
[0085] Among them, if during any shift operation, the detection function finds that the current priority is an invalid priority, indicating that the look - behind shift is unsuccessful, then the return value at this time is full, so that the previously recursively called functions will layer - by - layer return the return value indicating the non - existence of blank indexes until the shift operation function, and clear the relevant stored information about look - behind in the shift step information, that is, no actual look - behind shift operation is required; at this time, a look - ahead shift judgment can be made, and its algorithm is roughly the same as that of the look - behind shift, except that the shift judgment is performed on the previous priority. That is, the specific judgment process of the look - ahead shift can refer to Steps N10 to N70. For the sake of brevity of description, it will not be elaborated here.
[0086] Before shifting, pri_low_idx[4] = 2 and pri_high_idx[4] = 4 for priority4, pri_low_idx[3] = 5 and pri_high_idx[3] = 7 for priority3, pri_low_idx[2] = 8 and pri_high_idx[2] = 9 for priority2, pri_low_idx[1] = 11 and pri_high_idx[1] = 13 for priority1, and there is an entry G with priority priority3 to be inserted. Taking looking backward first as an example:
[0087] Shift the entry corresponding to pri_low_idx[2] = 8 to the position corresponding to pri_high_idx[2] + 1 = 10; At this time, since 10 is not equal to pri_low_idx[1] of priority1, the index 8 can be vacated for storing entry G, indicating that the entry shift in priority2 can directly provide a blank index for entry G without continuing to shift the entries in priority1. Therefore, mov_src[2] = pri_low_idx[2] and mov_dst[2] = 1 + pri_high_idx[2] can be recorded in the shift step information, and according to mov_src[2] = pri_low_idx[2] and mov_dst[2] = 1 + pri_high_idx[2], shift the entry corresponding to pri_low_idx[2] = 8 to the position corresponding to pri_high_idx[2] + 1, and at the same time update pri_low_idx[2] of priority2 to 9 and pri_high_idx[2] to 10; Then use index 8 as the index for storing entry G, that is, entry G will be inserted at index 8, and pri_high_idx[3] of priority3 will be updated to 8.
[0088] Further, after the step of determining whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority, it further includes:
[0089] If it cannot be successfully shifted, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the position corresponding to the third index extreme value in the third priority adjacent to the second priority. The first index extreme value and the third index extreme value are index extreme values with the same attribute, and the first index extreme value is adjacent to the index extreme value in the first priority;
[0090] If the shift is successful, shift the entry corresponding to the first index extreme value to the position corresponding to the third index extreme value, and use the first index extreme value as the target index of the first priority.
[0091] Exemplarily, in this embodiment, before the shift, pri_low_idx[4]=2 and pri_high_idx[4]=4 for priority4, pri_low_idx[3]=5 and pri_high_idx[3]=7 for priority3, pri_low_idx[2]=8 and pri_high_idx[2]=10 for priority2, pri_low_idx[1]=11 and pri_high_idx[1]=13 for priority1, pri_low_idx[0]=17 and pri_high_idx[0]=20 for priority0, and an entry G with priority priority3 needs to be inserted. Taking the backward-looking shift as an example:
[0092] First, shift the entry corresponding to pri_low_idx[2]=8 to the position corresponding to pri_high_idx[2]+1=11. Since 11 is equal to pri_low_idx[1] of priority1, it indicates that shifting the entry in priority2 is not sufficient to provide a blank index for entry G, that is, the entry corresponding to pri_low_idx[2] in priority2 cannot be successfully shifted to the position corresponding to pri_high_idx[2]+1 in the second priority. Therefore, it is necessary to continue shifting the entry in priority1, and record the information of mov_src[2]=pri_low_idx[2] and mov_dst[2]=1+pri_high_idx[2] into the shift step information.
[0093] Then, shift the entry corresponding to pri_low_idx[1]=11 to the position corresponding to pri_high_idx[1]+1=14. Since 14 is not equal to pri_low_idx[1] of priority0, the entry corresponding to pri_low_idx[1]=11 can be shifted to index 14, that is, index 11 can be vacated to store the entry corresponding to pri_low_idx[2]. So at this time, mov_src[1]=pri_low_idx[1] and mov_dst[1]=1+pri_high_idx[1] will be recorded into the shift step information.
[0094] It can be seen that a blank index can be provided for entry G through backward - looking shift. Therefore, in this embodiment, according to mov_src[1]=pri_low_idx[1] and mov_dst[1]=1 + pri_high_idx[1] recorded in the shift step information, the entry corresponding to pri_low_idx[1] (i.e., the minimum index 11) in priority1 is shifted to index 14 to vacate index 11. At the same time, pri_low_idx[1] in priority1 is updated to 12 and pri_high_idx[1] is updated to 14. Then, according to mov_src[2]=pri_low_idx[2] and mov_dst[2]=1 + pri_high_idx[2] recorded in the shift step information, the entry corresponding to pri_low_idx[2] (i.e., the minimum index 8) in priority2 is shifted to index 11 to vacate index 8. At the same time, pri_low_idx[2] in priority2 is updated to 9 and pri_high_idx[2] is updated to 11. Among them, index 8 will be used as the target index for storing entry G with priority priority3.
[0095] It can be seen that after the detection in this embodiment, the actual shift operation of the TCAM entries will be performed according to the recorded mov_src[] and mov_dst[], and when shifting, the management storage information pri_low_idx[] and pri_high_idx[] will be revised synchronously.
[0096] It should be noted that this embodiment is illustrated by taking backward - looking shift as an example. If it is forward - looking shift, the entry corresponding to the maximum index of each priority is shifted. The implementation method and principle are similar to those of backward - looking shift, that is, the forward - looking shift can be implemented by referring to the method and principle of the aforementioned backward - looking shift. Therefore, for the sake of simplicity of description, it will not be elaborated here.
[0097] Further, after the step of determining whether the second priority adjacent to the first priority is an invalid priority, it further includes:
[0098] If the second priority adjacent to the first priority is an invalid priority, then determine whether the fourth priority adjacent to the first priority in the other direction is an invalid priority;
[0099] If the fourth priority is not an invalid priority, then use the fourth priority as the second priority and execute the step of determining whether there is an entry stored in the second priority.
[0100] Exemplarily, in this embodiment, before shifting at each priority level, a determination is made as to whether it is an invalid priority. As long as one of the priorities is an invalid priority, the determination of whether to shift will stop at this invalid priority, that is, the shift in this direction is unsuccessful, and a shift determination needs to be made for the priorities in the opposite direction. Specifically, taking the look - behind shift as an example: If in any shift operation, the detection function finds that the current priority is an invalid priority, indicating that the look - behind shift is unsuccessful, then the return value at this time is full, so that the functions called recursively before will return layer by layer a return value indicating that there is no blank index until the shift operation function, and the relevant stored data regarding the look - behind in the shift step information is cleared; and at this time, a look - ahead shift determination will be made, and its algorithm is roughly the same as that of the look - behind shift.
[0101] For example, the TCAM includes priority5 to priority0, and it is necessary to store the entry H with priority priority3 into the TCAM: When performing a look - behind shift, in this embodiment, after shifting priority2 to priority0, a shift operation on priority - 1 is still required. At this time, since priority - 1 is an invalid priority, it indicates that the look - behind shift is unsuccessful. At this time, the return value is full, and the relevant stored data regarding the look - behind in the shift step information (that is, clearing mov_src[0] to mov_src[2] and mov_dst[0] to mov_dst[2]) is cleared; then continue with the look - ahead shift, that is, make a shift determination for priority4 and priority5. If the determination shows that the shift is successful, the stored data for the look - ahead shift (that is, mov_src[4] and mov_src[5] and mov_dst[4] and mov_dst[5]) is recorded in the shift step information; finally, an actual shift operation is performed on the entries in priority4 and priority5 according to the stored data of the look - ahead shift.
[0102] Step S40: Insert the entry to be inserted into the position corresponding to the target index, and update the index maximum and minimum values in each priority.
[0103] Exemplarily, in this embodiment, after shifting the entries corresponding to the index maximum and minimum values in other priorities, a blank index can be vacated for storing the entry to be inserted, and the index maximum and minimum values of all priorities are updated.
[0104] For example, before shifting, pri_low_idx[4] = 2 and pri_high_idx[4] = 4 for priority4, pri_low_idx[3] = 5 and pri_high_idx[3] = 7 for priority3, pri_low_idx[2] = 8 and pri_high_idx[2] = 10 for priority2, pri_low_idx[1] = 11 and pri_high_idx[1] = 13 for priority1, and there is an entry G with priority priority3 that needs to be inserted. Taking the backward shift as an example: After the shift processing through the above steps, index 8 is vacated to store entry G, and pri_low_idx[1] in priority1 is updated to 12 and pri_high_idx[1] is updated to 14, pri_low_idx[2] in priority2 is updated to 9 and pri_high_idx[2] is updated to 11. At this time, entry G can be inserted at index 8, and pri_high_idx[3] of priority3 is updated to 8.
[0105] Therefore, after shifting: pri_low_idx[4] = 2 and pri_high_idx[4] = 4 for priority4, pri_low_idx[3] = 5 and pri_high_idx[3] = 8 for priority3, pri_low_idx[2] = 9 and pri_high_idx[2] = 11 for priority2, pri_low_idx[1] = 12 and pri_high_idx[1] = 14 for priority1. It can be seen that there are no overlapping regions between the priority blocks in this embodiment, which can ensure that entries with higher priorities can definitely be found before entries with lower priorities, ultimately realizing the storage of entries to be inserted under multiple priorities in TCAM.
[0106] Further, after the step of determining whether the entry to be inserted is the first stored entry in the corresponding first priority, it further includes:
[0107] If the entry to be inserted is the first stored entry in the first priority, detect whether the starting index of the first priority has been occupied;
[0108] If so, determine whether the first priority is the highest priority or the lowest priority;
[0109] If the first priority is neither the highest priority nor the lowest priority, determine whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1;
[0110] If the maximum index of the second priority is not less than the difference between the minimum index of the third priority and 1, it is determined that there is no index for storing the entry to be inserted, and the step of shifting the entry corresponding to the index extreme value in other priorities based on the preset shifting rule to obtain the target index is executed;
[0111] If the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, it is determined that there is an index for storing the entry to be inserted;
[0112] Insert the entry to be inserted near the starting index according to the proximity principle, and update the index extreme value of the first priority;
[0113] Wherein, the second priority is higher than the first priority and adjacent to the first priority, and the third priority is lower than the first priority and adjacent to the first priority.
[0114] Exemplarily, in this embodiment, if it is determined according to the stored management storage information that the entry to be inserted is the first stored entry in the corresponding first priority, it indicates that the priority corresponding to the entry to be inserted is allocated for the first time. At this time, it can be first judged whether the starting index of this priority has been occupied by the entries of other priorities. If it has not been occupied, there is no need to shift, and the starting index is defaultly allocated to the entry to be inserted, and the entry to be inserted is directly inserted at the starting index, thereby realizing the storage of the entry to be inserted; but if it has been occupied by the entries of other priorities, at this time, it is necessary to judge whether there is a blank index around the priority corresponding to the entry to be inserted that can be allocated to the entry to be inserted.
[0115] In addition, if the priority corresponding to the entry to be inserted is the highest priority and its starting index has been occupied by the entries of other priorities, it means that there is no blank index for storing this entry to be inserted. At this time, only the backward-looking shift method can be used to provide a blank index to store this entry to be inserted; if the priority corresponding to the entry to be inserted is the lowest priority and its starting index has been occupied by the entries of other priorities, it can only be judged whether there is a blank index for storing this entry to be inserted by whether the occupied index in the priority that is higher than this priority and closest to this priority and stores entries has reached the limit of the TCAM storage space. If not, the forward-looking shift method can be used to provide a blank index for storing this entry to be inserted; and if the priority corresponding to the entry to be inserted is neither the highest priority nor the lowest priority, it can be judged whether there is a blank index for storing this entry to be inserted through the index extreme values of the priorities that store entries and are adjacent to it on both sides. If not, the backward-looking shift method or the forward-looking shift method can be used to provide a blank index for storing this entry to be inserted. It should be noted that the specific shift method can refer to the backward-looking shift method recorded in the foregoing embodiment and will not be elaborated here.
[0116] Specifically, taking the case where the priority corresponding to the entry to be inserted is neither the highest nor the lowest priority as an example: Assume that the priority of the entry I to be inserted is priority3. At this time, the largest index of the priorities that are higher than priority3 and closest to priority3 and where entries are already stored, and the smallest index of the priorities that are lower than priority3 and closest to priority3 and where entries are already stored can be found. It is judged whether these two indexes satisfy the condition that the largest index < the smallest index - 1. If it is satisfied, it means that there are blank indexes available for allocation; if not, it means that there are no blank indexes available for allocation, and at this time, a shift operation needs to be performed.
[0117] For example, the starting indexes of priority4 to priority1 are 0, 5, 10, and 15 respectively. For priority4, pri_low_idx[4] = 2 and pri_high_idx[4] = 5. There is no entry stored for priority3. For priority2, pri_low_idx[2] = 8 and pri_high_idx[2] = 14. For priority1, pri_low_idx[1] = 15 and pri_high_idx[1] = 19. Assume that there is an entry K with priority priority3 that needs to be inserted: According to the stored management storage information, priority3 is newly allocated and its starting index has been occupied by the entry of priority4. Therefore, it is necessary to judge whether there are blank indexes around priority3 for storing the entry K through the largest index of priority4 and the smallest index of priority2; Since pri_high_idx[4] of priority4 is less than the difference between pri_low_idx[2] of priority2 and 1, that is, 5 < 8 - 1, there are blank indexes (i.e., index 6 and index 7) around priority3 for storing the entry K. Then at this time, the entry K can be inserted at index 6 close to the starting index of priority3 according to the proximity principle, and update pri_low_idx[3] = 6 and pri_high_idx[3] = 6 for priority3.
[0118] For another example, the starting indices of priority4 to priority1 are 0, 5, 10, and 15 respectively. For priority4, pri_low_idx[4]=2 and pri_high_idx[4]=7. No entry is stored for priority3. For priority2, pri_low_idx[2]=8 and pri_high_idx[2]=14. For priority1, pri_low_idx[1]=15 and pri_high_idx[1]=16. Suppose there is an entry M with priority priority3 to be inserted: According to the stored management storage information, priority3 is newly allocated and its starting index has been occupied by the entry of priority4. Since pri_high_idx[4] of priority4 is equal to the difference between pri_low_idx[2] of priority2 and 1, i.e., 7 = 8 - 1, there is no blank index around priority3 for storing entry M. At this time, the entries in priority2 and priority1 need to be shifted respectively to vacate index 8 for storing entry M, and update pri_low_idx[3]=8 and pri_high_idx[3]=8 for priority3, pri_low_idx[2]=9 and pri_high_idx[2]=15 for priority2, and pri_low_idx[1]=16 and pri_high_idx[1]=17 for priority1.
[0119] Further, the method further includes:
[0120] When a to-be-deleted entry is detected, determine whether at least two indices in the target priority corresponding to the to-be-deleted entry are occupied;
[0121] If so, determine whether the first index corresponding to the to-be-deleted entry is the maximum index of the target priority;
[0122] If so, delete the to-be-deleted entry, and update the maximum index of the target priority to the difference between the first index and 1;
[0123] If not, delete the to-be-deleted entry, shift the entry corresponding to the maximum index of the target priority to the position corresponding to the first index, and update the maximum index of the target priority.
[0124] Exemplarily, when deleting an entry of a certain priority, there may be the following three situations: (1) The current priority occupies only one index; (2) The number of indexes occupied by the current priority is greater than or equal to 2, and the deleted entry is the largest index occupied by the current priority; (3) The number of indexes occupied by the current priority is greater than or equal to 2, and the deleted entry is not the largest index occupied by the current priority.
[0125] For the above three situations, the following processing will be performed respectively in this embodiment: (1) Delete the entry to be deleted, and clear the current priority information in the management storage information; (2) Delete the entry to be deleted, and directly subtract 1 from the largest index of the current priority in the management storage information; (3) Delete the entry to be deleted, shift the entry corresponding to the largest index of the current priority to the index position of the deleted entry, and subtract 1 from the largest index of the current priority in the management storage information. Therefore, in this embodiment, when an entry of a certain priority needs to be deleted, only the current priority needs to be operated, without operating other priorities.
[0126] It can be seen that in this embodiment during shifting, each priority involved in shifting only needs to be shifted once. For example, when shifting backward, it is to shift the smallest index of the priority to the index of the largest index plus 1. Therefore, through the software design of this embodiment, the implementation of multi-priority entries (such as 6 priorities) in a 1D TCAM table can be formed, which can meet the multi-priority scenarios in practical applications.
[0127] See Figure 3 As shown, the embodiment of the present application further provides a TCAM multi-priority storage device, including:
[0128] A first judgment unit, which is used to judge whether the entry to be inserted is the first stored entry in the corresponding first priority when detecting the entry to be inserted;
[0129] A second judgment unit, which is used to, if not, judge whether there is an index for storing the entry to be inserted according to the index maximum and minimum in the first priority and the index maximum and minimum in the second priority adjacent to the first priority;
[0130] An entry shifting unit, which is used to, if not, shift the entry corresponding to the index maximum and minimum in other priorities based on a preset shifting rule to obtain a target index;
[0131] An entry inserting unit, which is used to insert the entry to be inserted into the position corresponding to the target index and update the index maximum and minimum in each priority.
[0132] Further, the entry shifting unit is specifically used for:
[0133] Determine whether the second priority adjacent to the first priority is an invalid priority;
[0134] If not, determine whether there are entries stored in the second priority;
[0135] If there are entries stored in the second priority, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority;
[0136] If the shift is successful, shift the entry corresponding to the first index extreme value to the target position, and use the first index extreme value as the target index of the first priority.
[0137] Further, the entry shifting unit is specifically further configured to:
[0138] If the shift is not successful, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the position corresponding to the third index extreme value in the third priority adjacent to the second priority. The first index extreme value and the third index extreme value are index extreme values with the same attribute, and the first index extreme value is adjacent to the index extreme value in the first priority;
[0139] If the shift is successful, shift the entry corresponding to the first index extreme value to the position corresponding to the third index extreme value, and use the first index extreme value as the target index of the first priority.
[0140] Further, the entry shifting unit is specifically further configured to:
[0141] If the second priority adjacent to the first priority is an invalid priority, determine whether the fourth priority adjacent to the first priority in the other direction is an invalid priority;
[0142] If the fourth priority is not an invalid priority, use the fourth priority as the second priority and execute the step of determining whether there are entries stored in the second priority.
[0143] Further, the second determination unit is specifically configured to:
[0144] When the maximum index of the first priority is greater than or equal to the difference between the minimum index in the second priority and 1, it is determined that there is no index for storing the entry to be inserted, and the second priority is lower than the first priority, or;
[0145] When the maximum index in the second priority is greater than or equal to the difference between the minimum index in the first priority and 1, it is determined that there is no index for storing the entry to be inserted, and the second priority is higher than the first priority.
[0146] Further, the second determination unit is specifically further configured to:
[0147] If the entry to be inserted is the first stored entry in the first priority, check whether the starting index of the first priority has been occupied;
[0148] If so, determine whether the first priority is the highest priority or the lowest priority;
[0149] If the first priority is neither the highest priority nor the lowest priority, determine whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1;
[0150] If not, determine that there is no index for storing the entry to be inserted, and perform the step of shifting the entry corresponding to the index extreme value in other priorities based on the preset shifting rule to obtain the target index;
[0151] Wherein, the second priority is higher than the first priority and adjacent to the first priority, and the third priority is lower than the first priority and adjacent to the first priority.
[0152] Furthermore, the second judgment unit is specifically further configured to: if the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, determine that there is an index for storing the entry to be inserted;
[0153] The entry insertion unit is further configured to insert the entry to be inserted into a position close to the starting index according to the proximity principle, and update the index extreme value of the first priority.
[0154] Furthermore, the entry insertion unit is further configured to:
[0155] When detecting an entry to be deleted, determine whether at least two indexes in the target priority corresponding to the entry to be deleted have been occupied;
[0156] If so, determine whether the first index corresponding to the entry to be deleted is the maximum index of the target priority;
[0157] If so, delete the entry to be deleted, and update the maximum index of the target priority to the difference between the first index and 1;
[0158] If not, delete the entry to be deleted, shift the entry corresponding to the maximum index of the target priority to the position corresponding to the first index, and update the maximum index of the target priority.
[0159] It should be noted that those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the above-described device and each unit can refer to the corresponding processes in the foregoing embodiments of the TCAM multi-priority storage method, and will not be elaborated herein.
[0160] The device provided in the above embodiment can be implemented in the form of a computer program, and the computer program can be inFigure 4 running on the TCAM multi-priority storage device shown.
[0161] An embodiment of the present application also provides a TCAM multi-priority storage device, including: a memory, a processor, and a network interface connected through a system bus. At least one instruction is stored in the memory, and the at least one instruction is loaded and executed by the processor to implement all or part of the steps of the foregoing TCAM multi-priority storage method.
[0162] Among them, the network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art can understand that Figure 4 the structure shown in is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0163] The processor may be a CPU, or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may also be any conventional processor, etc. The processor is the control center of the computer device, and connects various parts of the entire computer device through various interfaces and lines.
[0164] The memory can be used to store computer programs and / or modules. The processor realizes various functions of the computer device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as video playback function, image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as video data, image data, etc.), etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one magnetic disk storage device, a flash device, or other volatile solid-state storage devices.
[0165] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, all or part of the steps of the foregoing TCAM multi-priority storage method are implemented.
[0166] The embodiment of the present application implements all or part of the foregoing processes, and can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the foregoing various methods can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0167] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, system, server, or computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.
[0168] The present invention is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the processes and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0169] It should be noted that in this text, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such process, method, article or system. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or system including that element.
[0170] The above are only specific embodiments of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but rather will conform to the broadest scope consistent with the principles and novel features claimed herein.
Claims
1. A TCAM multi-priority storage method, characterized in that, It includes the following steps: When a to-be-inserted entry is detected, determine whether the to-be-inserted entry is the first stored entry in the corresponding first priority; If not, determine whether there is an index for storing the to-be-inserted entry according to the index extreme value in the first priority and the index extreme value in the second priority adjacent to the first priority; If not, shift the entry corresponding to the index extreme value in other priorities based on the preset shift rule to obtain the target index; Insert the to-be-inserted entry into the position corresponding to the target index, and update the index extreme values in each priority; After the step of determining whether the to-be-inserted entry is the first stored entry in the corresponding first priority, it further includes: If the to-be-inserted entry is the first stored entry in the first priority, detect whether the starting index of the first priority is occupied; If so, determine whether the first priority is the highest priority or the lowest priority; If the first priority is neither the highest priority nor the lowest priority, determine whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1; If not, determine that there is no index for storing the to-be-inserted entry, and execute the step of shifting the entry corresponding to the index extreme value in other priorities based on the preset shift rule to obtain the target index; Wherein, the second priority is higher than the first priority and adjacent to the first priority, and the third priority is lower than the first priority and adjacent to the first priority.
2. The TCAM multi-priority storage method according to claim 1, characterized in that, The step of shifting the entry corresponding to the index extreme value in other priorities based on the preset shift rule to obtain the target index includes: Determine whether the second priority adjacent to the first priority is an invalid priority; If not, determine whether there is an entry stored in the second priority; If there is an entry stored in the second priority, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority; If it can be successfully shifted, shift the entry corresponding to the first index extreme value to the target position, and use the first index extreme value as the target index of the first priority.
3. The TCAM multi-priority storage method according to claim 2, wherein, After the step of determining whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the target position adjacent to the second index extreme value in the second priority, it further includes: If it cannot be successfully shifted, determine whether the entry corresponding to the first index extreme value in the second priority can be successfully shifted to the position corresponding to the third index extreme value in the third priority adjacent to the second priority, the first index extreme value and the third index extreme value are index extreme values with the same attribute, and the first index extreme value is adjacent to the index extreme value in the first priority; If it can be successfully shifted, shift the entry corresponding to the first index extreme value to the position corresponding to the third index extreme value, and use the first index extreme value as the target index of the first priority.
4. The TCAM multi-priority storage method according to claim 2, characterized in that, After the step of determining whether the second priority adjacent to the first priority is an invalid priority, it further includes: If the second priority adjacent to the first priority is an invalid priority, then determine whether the fourth priority adjacent to the first priority in the other direction is an invalid priority; If the fourth priority is not an invalid priority, use the fourth priority as the second priority and perform the step of determining whether there is an entry stored in the second priority.
5. The TCAM multi-priority storage method according to claim 1, wherein The determination of whether there is an index for storing the entry to be inserted according to the index maximum value in the first priority and the index maximum value in the second priority adjacent to the first priority includes: When the maximum index of the first priority is greater than or equal to the difference between the minimum index in the second priority and 1, it is determined that there is no index for storing the entry to be inserted, where the second priority is lower than the first priority, or; When the maximum index in the second priority is greater than or equal to the difference between the minimum index in the first priority and 1, it is determined that there is no index for storing the entry to be inserted, where the second priority is higher than the first priority.
6. The TCAM multi-priority storage method according to claim 1, wherein After the step of determining whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, it further includes: If the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1, it is determined that there is an index for storing the entry to be inserted; Insert the entry to be inserted into the position close to the starting index according to the proximity principle and update the index maximum value of the first priority.
7. The TCAM multi-priority storage method according to claim 1, wherein The method further includes: When a deletion entry is detected, determine whether at least two indexes in the target priority corresponding to the deletion entry have been occupied; If so, determine whether the first index corresponding to the deletion entry is the maximum index of the target priority; If so, delete the deletion entry and update the maximum index of the target priority to the difference between the first index and 1; If not, delete the deletion entry, shift the entry corresponding to the maximum index of the target priority to the position corresponding to the first index, and update the maximum index of the target priority.
8. A TCAM multi-priority storage device, characterized in that, It includes: A first determination unit for determining whether the entry to be inserted is the first stored entry in the corresponding first priority when the entry to be inserted is detected; A second determination unit for, if not, determining whether there is an index for storing the entry to be inserted according to the index maximum value in the first priority and the index maximum value in the second priority adjacent to the first priority; An entry shifting unit for, if not, shifting the entry corresponding to the index maximum value in other priorities based on a preset shifting rule to obtain a target index; An entry insertion unit for inserting the entry to be inserted into the position corresponding to the target index and updating the index maximum values in each priority; The second determination unit specifically further includes: If the entry to be inserted is the first stored entry in the first priority, detecting whether the starting index of the first priority has been occupied; If so, determining whether the first priority is the highest priority or the lowest priority; If the first priority is not the highest priority and not the lowest priority, determining whether the maximum index of the second priority is less than the difference between the minimum index of the third priority and 1; If not, determining that there is no index for storing the entry to be inserted and performing the step of shifting the entry corresponding to the index maximum value in other priorities based on a preset shifting rule to obtain a target index; Among them, the second priority is higher than the first priority and adjacent to the first priority, and the third priority is lower than the first priority and adjacent to the first priority.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, which, when executed by a computer, cause the computer to execute the TCAM multi-priority storage method according to any one of claims 1 to 7.
Citation Information
Patent Citations
ACL rule loading method and device
CN105335307A