Method and device for determining placement position of switch table item
By receiving protocol messages and calculating the weight of unoccupied table entries, selecting the best placement position, it solves the problem of low utilization caused by different occupancy positions of different types of table entries in shared table entries, and realizes efficient table entries .
Patent Information
- Application Number
- CN202310609983.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2024-11-26
AI Technical Summary
Different types of table entries occupy different positions in shared table entries, which causes the fixed placement to fail to meet newly added table entries, or leads to the problem of low utilization of shared table entries.
By receiving protocol messages, determine the length and type of the target table entry, use the preset table entry location and hash bucket capacity to calculate the weight of the unoccupied table entry location, and select the best placement position to improve the table entry's Utilization.
The optimal placement of shared table entries is achieved, the utilization of table entries is improved, and efficient and simple entry placement is ensured.
Smart Images

Figure CN119030938A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network technology, and in particular to a method and device for determining a placement position of a switch table entry. Background Art
[0002] When making multicast entries or routing entries, different entries with similar functions, such as DIP entries and DIP+SIP entries for IPv4, DIP entries and DIP+SIP entries for IPv6, etc., are designed as shared entries, that is, a total length is given, and the total length includes multiple basic units of unit length. The size of a single basic unit is defined, and a single basic unit can hold an entry with a minimum key length. Various fields in the entry are placed in the corresponding basic unit of the shared entry in the form of numerical values in a preset format, such as binary numbers. The lengths of binary numbers corresponding to different types of entries are different, and the difference is large.
[0003] Therefore, different types of entries occupy different numbers of basic units in the shared entry, and entries of different lengths are pre-designed to have fixed placement positions.
[0004] In actual applications, there are situations where new entries of different types need to be added to the shared entries. A fixed placement position may result in the entry not being able to be placed therein, or the utilization rate of the shared entries after placement being low. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method and device for determining the placement position of a switch entry, so as to solve the problem of low utilization rate of shared entries.
[0006] In order to solve the above technical problems, this specification is implemented as follows:
[0007] In a first aspect, a method for determining a switch entry placement position is provided, comprising:
[0008] Receive protocol messages;
[0009] Determine a target table entry corresponding to the protocol message;
[0010] According to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch, determining the target position in the unoccupied entry positions of the shared entry;
[0011] The target entry is placed at the target location.
[0012] Optionally, determining the target position in the unoccupied entry positions of the shared entry according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch includes:
[0013] Determine the length of the target entry according to the type of the target entry and a preset mapping relationship table of entry type-entry length;
[0014] According to the length of the target entry, determining a plurality of preset entry positions corresponding to the length in the shared entry;
[0015] Determining the unoccupied table entry position from the preset multiple table entry positions, the unoccupied table entry position includes at least one preset table entry position;
[0016] Determining weights of remaining unoccupied entry positions after the target entry is placed in each preset entry position;
[0017] The target position is determined according to the weight of each remaining unoccupied entry position, wherein the weight is related to the length and quantity of different entries that can be placed in each remaining unoccupied entry position.
[0018] Optionally, determining, according to the length of the target entry, a plurality of preset entry positions corresponding to the length in the shared entry includes:
[0019] Dividing the shared entries into a plurality of hash buckets according to the total length of the shared entries and a preset hash bucket capacity;
[0020] Determine a target hash bucket for placing the target entry according to a comparison key of the target entry;
[0021] According to the length of the target entry, multiple preset entry positions corresponding to the length in the target hash bucket are determined.
[0022] Optionally, determining the unoccupied table entry position from the preset multiple table entry positions includes:
[0023] Converting the length of the target entry into a first value in binary format;
[0024] Converting the preset multiple table entry positions into multiple second numerical values in the binary format respectively;
[0025] performing an AND operation on the first value and each second value respectively;
[0026] The unoccupied entry position is determined according to at least one entry placement position corresponding to a second value whose operation result is zero.
[0027] Optionally, respectively determining weights of remaining unoccupied entry positions after the target entry is placed in each preset entry position includes:
[0028] Determining a target remaining unoccupied entry position after placing the target entry at the target entry position;
[0029] Determine the length Si of the table entry that can be placed in the remaining unoccupied table entry position of the target and the number Ni of preset table entry positions corresponding to the length Si, where i is an identifier of different table entry lengths;
[0030] The product of the length Si and the number Ni of each entry is summed to obtain the weight of the target remaining unoccupied entry position.
[0031] Optionally, determining the target position according to the weight of each remaining unoccupied entry position includes:
[0032] Determine the maximum weight of each remaining unoccupied entry position;
[0033] The first table entry position corresponding to the maximum weight value is determined as the target position.
[0034] Optionally, according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch, before determining the target position in the unoccupied entry positions of the shared entry, the method further includes:
[0035] Dividing the shared table entry into a plurality of hash buckets according to the total length of the shared table entry and a preset hash bucket capacity;
[0036] List the unoccupied entry positions corresponding to the unoccupied entry positions in the target hash bucket;
[0037] Determine respectively the second entry positions where entries of different lengths are placed at the respective unoccupied entry positions;
[0038] The relationship between the position of each table item and the position of the second table item corresponding to the different lengths is saved in a mapping table;
[0039] According to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch, determining the target position in the unoccupied entry positions of the shared entry includes:
[0040] According to the length of the target entry and the currently unoccupied entry position in the hash bucket corresponding to the target entry, obtaining the corresponding second entry position from the mapping table;
[0041] The acquired second table entry position is used as the target position.
[0042] Optionally, respectively determining the second entry positions at which entries of different lengths are placed at respective unoccupied entry positions includes:
[0043] Determine the target remaining unoccupied entry position after placing the entry of the target length at the target entry position;
[0044] Determine the length Si of the table entry that can be placed in the remaining unoccupied table entry position of the target and the number Ni of preset table entry positions corresponding to the length Si, where i is an identifier of different table entry lengths;
[0045] Sum the product of the length Si and the number Ni of each entry to obtain the weight of the remaining unoccupied entry position of the target;
[0046] The entry position corresponding to the maximum weight value of each remaining unoccupied entry position is determined as the second entry position.
[0047] Optionally, each unoccupied entry position corresponding to each entry position in the target hash bucket when the entry position is not occupied is listed, including:
[0048] Determine each unoccupied entry position corresponding to each entry position in the target hash bucket when the entry position is not occupied;
[0049] According to the capacity unit of the preset hash bucket, converting each of the unoccupied table entry positions into a third value in the binary format, wherein one capacity unit corresponds to one table entry position;
[0050] The unoccupied table entry positions are listed according to the third value.
[0051] In a second aspect, a device for determining a switch entry placement position is provided, comprising a memory and a processor electrically connected to the memory, wherein the memory stores a computer program executable by the processor, and when the computer program is executed by the processor, the steps of the method described in the first aspect are implemented.
[0052] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0053] In an embodiment of the present application, a protocol message is received and a target table item corresponding to the protocol message is determined. According to the length of the target table item and a plurality of preset table item positions corresponding to the length in the shared table items of the switch, a target position is determined in the table item positions that are not occupied by the shared table items, and the target table item is placed at the target position. Thus, the table items of different lengths of the shared table items can be placed at the best position, so that the utilization rate of the table items can be maximized, and high efficiency and simplicity are achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0055] Figure 1 It is a flowchart of a method for determining a switch entry placement position according to an embodiment of the present application.
[0056] Figure 2 It is a schematic diagram of different table item lengths and preset table item positions in an embodiment of the present application.
[0057] Figure 3 It is a schematic diagram of determining the position of unoccupied table entries according to an embodiment of the present application.
[0058] Figure 4 It is a structural block diagram of a device for determining a switch entry placement position according to an embodiment of the present application. DETAILED DESCRIPTION
[0059] 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 part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application. The numbering of the drawings in this application is only used to distinguish the various steps in the scheme, and is not used to limit the execution order of the various steps. The specific execution order is subject to the description in the specification.
[0060] In order to solve the problems existing in the prior art, the embodiment of the present application provides a method for determining the placement position of a switch table entry. Figure 1 It is a flowchart of a method for determining a switch entry placement position according to an embodiment of the present application.
[0061] like Figure 1 As shown, the following steps are included:
[0062] Step 102, receiving a protocol message;
[0063] Step 104, determining the target table entry corresponding to the protocol message;
[0064] Step 106, determining a target position in unoccupied entry positions of the shared entry according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch;
[0065] Step 108: placing the target entry at the target position.
[0066] When the switch executes Internet Group Management Protocol Snooping (IGMP Snooping) and Multicast Listener Discovery Snooping (MLDSnooping), it will add multicast or routing table entries according to the protocol message. Therefore, the corresponding target table entry is determined according to the received protocol message. For example, if there is a packet with a multicast IP of 224.1.1.1, and the multicast is added to Port 1 and Port 2, the switch will find this table entry according to the protocol message of the packet, and place the table entry in the shared table entry, and then forward the packet with a multicast IP of 224.1.1.1 to Port 1 and Port 2.
[0067] In the embodiment of the present application, it is necessary to find the best position, that is, the target position, from the shared table entries of the switch to place the table entries that need to be added according to the protocol message, so that the shared table entries can place as many table entries as possible, thereby improving the utilization rate of the shared table entries.
[0068] Optionally, determining the target position in the unoccupied item position of the shared item according to the length of the target item and a plurality of preset item positions corresponding to the length in the shared item of the switch includes: determining the length of the target item according to the type of the target item and a preset item type-item length mapping relationship table; determining a plurality of preset item positions corresponding to the length in the shared item according to the length of the target item; determining the unoccupied item position from the preset plurality of item positions, the unoccupied item position including at least one preset item position; respectively determining the weights of the remaining unoccupied item positions after the target item is placed in each preset item position; determining the target position according to the weights of each remaining unoccupied item position, the weight being related to the length and quantity of different items that can be placed in each remaining unoccupied item position.
[0069] The basic unit length of the table entry is determined according to the application. For example, if the basic unit length is 80 bytes, then one basic unit is 80 bytes, two basic units are 160 bytes, and four basic units are 320 bytes.
[0070] Schematically, the length of the DIP table entry of IPv4 is 50 bytes, the length of the DIP+SIP table entry of IPv4 is 100 bytes, the length of the DIP table entry of IPv6 is 240 bytes, and the length of the IPv6 DIP+SIP table entry is 320 bytes, but the unit lengths occupied by the above table entries correspond to 1, 2, 3, and 4 basic units respectively.
[0071] That is, the type of the table item and the length of the basic unit of the table item have a corresponding mapping relationship, and the mapping relationship can be saved in a table to obtain a mapping relationship table. In this way, after determining the target table item corresponding to the received protocol message in step 104, the length of the target table item can be determined according to the type of the target table item and the mapping relationship table, so as to determine the number of basic units occupied by the target table item in the shared table item. Different types of table items occupy different numbers of basic units in the shared table item, and table items of different lengths are pre-designed to have fixed placement positions. Depending on the length of the table item, the corresponding fixed placement position may include one or more.
[0072] Combination Figure 2 In the illustrated example, the shared table entry includes multiple hash buckets 0-4, each hash bucket includes 8 basic units, and one basic unit corresponds to a unit table entry placement position.
[0073] For example, table entry 12 and table entry 14 each occupy one basic unit, and the pre-designed table entry 12 and 14 can be placed at any position from position 0 to position 7. Table entry 22 occupies two basic units, and the pre-designed table entry 22 can be placed at an even position, such as position 0, position 2, position 4, and position 6. Here, position 0, position 2, position 4, and position 6 are the starting positions for placing table entry 22. For example, if it is placed at position 0, it corresponds to the continuous occupation of two basic units corresponding to position 0 and position 1.
[0074] Table entry 32 and table entry 34 occupy 3 basic units respectively, so it is pre-designed that table entry 32 and table entry 34 can be placed at position 0 and position 3. Similarly, table entry 42 occupies 4 basic units, so it is pre-designed that table entry 42 can be placed at position 0 and position 4.
[0075] In one embodiment, the shared entry may include multiple hash buckets. According to the length of the target entry, determining the preset multiple entry positions corresponding to the length in the shared entry includes: dividing the shared entry into multiple hash buckets according to the total length of the shared entry and the preset hash bucket capacity; determining the target hash bucket for placing the target entry according to the comparison key of the target entry; and determining the preset multiple entry positions corresponding to the length in the target hash bucket according to the length of the target entry.
[0076] The capacity of a hash bucket refers to the number of basic units included in the hash bucket. For example, a hash bucket can accommodate 6 basic units, or 8 basic units, or other numbers of basic units. In this way, the total number of basic units that a shared entry can support can be determined based on the total length of the shared entry. The total number of basic units is divided by the capacity of the hash bucket, and the shared entry can be evenly divided into multiple hash buckets.
[0077] Taking the example that the shared table entry supports 512 basic units and the capacity of each hash bucket includes 8 basic units, the shared table entry can be divided into 512 / 8=64 hash buckets.
[0078] The characteristics of the packet can be extracted to obtain the comparison key of the target entry, and the hash bucket for placing the target entry can be determined. And according to the length of the target entry, multiple preset entry positions in the hash bucket that can be used to place the target entry can be determined.
[0079] When a target entry is newly added to a shared entry, one or more corresponding preset entry positions can be determined according to the length of the target entry, and the target entry can be added to the corresponding position according to the current occupancy of the preset entry position. When there are multiple entry positions that can be placed for the target entry, if one is selected arbitrarily for placement, it may result in that the positions for placing other entries of different lengths subsequently cannot be fully utilized, resulting in the remaining entry positions being idle, thereby reducing the utilization rate of the shared entry.
[0080] Therefore, the present application proposes to determine an unoccupied table entry position from a plurality of preset table entry positions, and then select the best placement position for placing the table entry currently to be added from the unoccupied table entry positions.
[0081] Determining the unoccupied table entry position from the preset multiple table entry positions includes: converting the length of the target table entry into a first value in binary format; converting the preset multiple table entry positions into multiple second values in binary format respectively; performing AND operations on the first value and each second value respectively; and determining the unoccupied table entry position according to at least one table entry placement position corresponding to the second value whose operation result is zero.
[0082] refer to Figure 3 , with a hash bucket (corresponding to Figure 1 For example, the hash bucket 0) includes 8 basic units, corresponding to 8 table entry positions, namely positions 0-7. The binary value 1 represents that the position is occupied, and the binary value 0 represents that the position is not occupied. As shown in the figure, the currently occupied table entry position 100 includes position 0 and position 1, and the unoccupied table entry position 200 includes positions 2-7 that are not occupied.
[0083] Initialize the 8-bit bitmask of the hash bucket to 0: Uint8 Entry_bitmask
[64] = {0,}; / /
[64] represents 64 hash buckets.
[0084] but Figure 2 The usage of the entries in the five hash buckets in the example is as follows:
[0085] Entry_bitmask[0] = 0b00000011; / / Position 0, 1 is already occupied
[0086] Entry_bitmask[1] = 0b00000011; / / Position 0, 1 is already occupied
[0087] Entry_bitmask[2] = 0b11110111; / Positions 0, 1, 2, 4, 5, 6, 7 are already occupied
[0088] Entry_bitmask[3] = 0b00111000; / / Positions 3, 4, and 5 are already occupied
[0089] Entry_bitmask[4] = 0b00000000; / / No position is occupied
[0090] If, in the current state, a target table entry that needs to occupy two basic units needs to be added, the hash bucket position of the target table entry is first calculated, assuming it is hash bucket 0. Figure 3 As shown, currently, the positions preset in hash bucket 0 where entries with a length corresponding to two basic units can be placed are position 0, position 2, position 4, and position 6.
[0091] To determine the unoccupied entry position among these four positions, you can first convert the length of the target entry into a binary value: 2 size -1=0b11, size indicates that the length of the target table entry is 2.
[0092] It is also necessary to convert the preset entry positions corresponding to the target entry, namely position 0, position 2, position 4 and position 6, into corresponding values in binary format, for example, position 0 is 0b11, position 2 is 0b00, position 4 is 0b00, and position 6 is 0b00.
[0093] And execute steps 1 to 4 in the order from position 0 to position 4, that is, perform AND operations on the binary number corresponding to the length of the target table item and the binary numbers corresponding to the above-mentioned multiple preset table item positions in sequence. If the result of the AND operation is not 0, it means that the corresponding table item position has been occupied by other table items and cannot be placed, such as position 0 in step 1.
[0094] Through step 2 to step 4, it can be determined that the result of the AND operation is 0, indicating that position 2, position 4 and position 6 are not occupied by other entries and can be used to place the target entry. That is, the unoccupied entry position 200 includes 3 preset entry positions.
[0095] Position 0 is already used, so there are 3 positions, namely position 2, position 4 and position 6, where the target position can be placed, so the best position among the 3 positions needs to be calculated. Specifically, it can be determined according to the weight of the remaining unoccupied entry position after placing the target entry in each entry position.
[0096] For example, the target entry is placed at the unoccupied entry position 210 corresponding to position 2, and the remaining unoccupied entry positions are the entry positions 220 corresponding to positions 4 and 6, then the weights of the remaining unoccupied entry positions 220 after the target entry is placed are calculated.
[0097] The weight is related to the length and number of different entries that can be placed in each remaining unoccupied entry position, such as Figure 2 As shown, the number of basic units occupied by different types of entries is 1, 2, 3, and 4, and the weights are also defined as 1, 2, 3, and 4. When a hash bucket is empty, 8 entries with a length corresponding to 1 basic unit (corresponding to position 0 to position 7), or 4 entries with a length corresponding to 2 basic units (corresponding to position 0, position 2, position 4, and position 6), or 2 entries with a length corresponding to 3 basic units (corresponding to position 0 and position 3), or 2 entries with a length corresponding to 4 basic units (corresponding to position 0 and position 4) can be placed. The weight of an empty hash bucket is: 8*1+4*2+2*3+2*4=30.
[0098] In the same way, Figure 2 The weight of the remaining unoccupied entry positions of hash bucket 0 is Weigth = 6*1+3*2+1*3+1*4 = 19. That is, 6 entries corresponding to 1 basic unit can be placed (corresponding to positions 2 to 7), or 3 entries corresponding to 2 basic units (corresponding to positions 2, 4, and 6), or 1 entry corresponding to 3 basic units (corresponding to position 3), or 1 entry corresponding to 4 basic units (corresponding to position 4).
[0099] That is, the length of the table entry that can be placed in the unoccupied table entry position is represented by Si, i is the identifier of different table entry lengths, i=1,2,3,4, for example, i=1 indicates the length corresponding to 1 unit, i=2 indicates the length corresponding to 2 basic units, i=3 indicates the length corresponding to 3 basic units, i=4 indicates the length corresponding to 4 basic units, then S1=1, S2=2, S3=3, S4=4. The number of preset table entry positions corresponding to the length Si is represented by Ni, then when the hash bucket is empty, N1=8, N2=4, N3=2, N4=2, and the corresponding unoccupied table entry position weight is 8*1+4*2+2*3+2*4=30.
[0100] That is, the weight of the unoccupied table entry position is the sum of the product of the length Si and the number Ni of each table entry.
[0101]
[0102] Continue with the above text Figure 3 Taking the addition of a target table entry occupying two basic units as an example, after placing the target table entry at the preset table entry position corresponding to position 2 in step 2, the Weight of the remaining unoccupied table entry positions is 4*1+2*2+0*3+1*4=12; after placing the target table entry at the preset table entry position corresponding to position 4 in step 3, the Weight of the remaining unoccupied table entry positions is 4*1+2*2+0*3+0*4=8; after placing the target table entry at the preset table entry position corresponding to position 6 in step 4, the Weight of the remaining unoccupied table entry positions is 4*1+2*2+1*3+0*4=9.
[0103] By placing the target entry at multiple preset entry positions in the unoccupied entry positions, and calculating the weights of the remaining unoccupied entry positions after placement, multiple weight values can be obtained, from which the target position for placing the target entry, i.e., the optimal position, is determined.
[0104] Optionally, the target position is determined according to the weights of the remaining unoccupied table entry positions, including: determining the maximum weight value of the remaining unoccupied table entry positions; and determining the first table entry position corresponding to the maximum weight value as the target position.
[0105] The above is a method for calculating the weights of the remaining unoccupied table item positions. If a new table item needs to be added, the table item is placed in one or more positions where it can be placed. If there are multiple table item positions that can be placed, the weights of the remaining unoccupied table item positions are calculated again. When the weight of the remaining unoccupied table item positions is the largest, it is the best placement position for the table item.
[0106] By targeting Figure 3 From the above calculation of the example, it can be seen that after placing the target entry at the preset entry position corresponding to position 2 in step 2, the Weight=12 of the unoccupied entry position is the largest, so it can be concluded that the current best position of the target entry is placement position 2. Then, update Entry_bitmask[0]=0b00001111, and obtain the best placement position of the target entry of the newly added 2 basic units.
[0107] Similarly, if the table entry added at this time is of other types of lengths, the same calculation method is used. Or, if the table entry added at this time is other hash buckets, the same processing method is used.
[0108] In the above embodiment, the weight of the unoccupied entry position in the target hash bucket corresponding to the target entry can be calculated in real time to determine the best position for placing the target entry, thereby improving the utilization of the entry position in the hash bucket and further improving the position utilization of the shared entry.
[0109] In another embodiment, according to the length of the target table item and a plurality of preset table item positions corresponding to the length in the shared table items of the switch, before determining the target position in the unoccupied table item position of the shared table item, it also includes: dividing the shared table item into a plurality of hash buckets according to the total length of the shared table item and a preset hash bucket capacity; listing each unoccupied table item position corresponding to each table item position in the target hash bucket when it is unoccupied; respectively determining second table item positions where items of different lengths are placed on each unoccupied table item position; and saving the relationship between each table item position and the second table item position corresponding to different lengths in a mapping table.
[0110] According to the length of the target table item and a plurality of preset table item positions corresponding to the length in the shared table items of the switch, the target position is determined in the table item positions that are not occupied by the shared table items, including: according to the length of the target table item and the currently unoccupied table item positions in the hash bucket corresponding to the target table item, obtaining the corresponding second table item position from the mapping table; and using the obtained second table item position as the target position.
[0111] In this embodiment, optimal positions corresponding to different entry types or entry lengths in a plurality of hash buckets included in the shared entry may be defined in advance.
[0112] The method includes: determining the unoccupied table entry positions corresponding to the table entry positions in the target hash bucket when the table entry positions are not occupied; converting the unoccupied table entry positions into a third numerical value in the binary format according to the capacity unit of the preset hash bucket, wherein one capacity unit corresponds to one table entry position; and listing the unoccupied table entry positions according to the third numerical value.
[0113] Taking a hash bucket with 8 capacity units as an example, an 8-bit binary data is needed to record the occupancy of the table item position. To list the corresponding unoccupied table item positions in a hash bucket when each table item position is not occupied, 2 8 = 256 cases. If a hash bucket includes 6 basic units, for example, a 6-bit binary data is needed to record the occupancy of the table entry position, so 2 6 =64 situations.
[0114] Then, according to the occupancy of each table entry position, the placement positions of table entries of different lengths are defined, and the second table entry position is also the best position for placing the table entry.
[0115] Taking the four cases where the table length type includes 1 basic unit, 2 basic units, 3 basic units and 4 basic units as an example, the binary numbers corresponding to the 256 corresponding table item positions can be obtained. For example, the list starts from the target hash bucket being empty (the corresponding table item position is 0b00000000), and then lists one table item position being occupied, two table item positions being occupied, ..., all 8 table item positions are occupied (the corresponding table item positions are 0b11111111).
[0116] For each case, the second table item position where the table items of different lengths are placed on the unoccupied table item position is determined, and then the best position matrix of
[256] [4] can be obtained. The relationship between each table item position and the second table item position corresponding to different lengths is saved in a mapping table. When it is necessary to place the target table item in the corresponding hash bucket, the corresponding second table item position can be obtained from the mapping table according to the length of the target table item and the currently unoccupied table item position in the hash bucket, and the target table item is placed, so that the target table item is placed in the best position.
[0117] If the table entry position occupancy of the current target hash bucket is 0b0000000, that is, the hash bucket is empty, then for the four different table entry lengths corresponding to 1 basic unit, 2 basic units, 3 basic units and 4 basic units, the corresponding optimal positions can be calculated as {6, 6, 0, 4} according to the algorithm, and this set of data is defined in advance.
[0118] That is, the best placement position for an entry corresponding to a length of 1 basic unit when the hash bucket is empty is position 6, the best placement position for an entry corresponding to a length of 2 basic units when the hash bucket is empty is position 6, the best placement position for an entry corresponding to a length of 3 basic units when the hash bucket is empty is position 0, and the best placement position for an entry corresponding to a length of 4 basic units when the hash bucket is empty is position 4.
[0119] If the table entry position occupancy of the previous target hash bucket is 0b11111100, then for the above four table entry lengths, the corresponding optimal positions can be calculated as {0, 0, -1, -1} respectively according to the algorithm.
[0120] That is, in the above-mentioned table entry position occupancy situation, the best placement position for the table entry corresponding to the table entry length of 1 basic unit is position 0, and the best placement position for the table entry corresponding to the table entry length of 2 basic units is position 0. Position -1 means that it cannot be placed, that is, the table entry corresponding to 2 or 3 basic units cannot be placed under the current circumstances.
[0121] The array matrix of the best position of
[256] [4] above can be saved in the mapping table Map. The best positions corresponding to the 256 table entry positions and the 4 table entry lengths are as follows:
[0122] {{6, 6, 0, 4}, / *0b00000000* / ,......{0,0,-1,-1} / *0b11111100* / ,{1,-1,-1,-1} / *0b11111101* / ,{1,-1,-1,-1} / *0b11111110* / ,{-1,-1,-1,-1} / *0b11111111* /
[0123] }
[0124] In the mapping table Map, the 256 types of table item position occupancy are identified by binary arrays corresponding to 0 to 255, and the four types of table item lengths are identified by arrays corresponding to 0 to 3. For example, map[][0] in the mapping table Map stores the best position of the table item whose length corresponds to 1 basic unit, map[][3] stores the best position of the table item whose length corresponds to 4 basic units, and map
[255] [3] stores the best position of the table item with a length of 1 basic unit under the 256th type of table item position occupancy.
[0125] In this way, when a target table entry corresponding to 4 basic units needs to be added, the hash bucket where the target table entry should be placed is calculated first. If the table entry position occupancy of the hash bucket is: 0b00000000 (the hash bucket is empty), then through the mapping table Map, map[0][3]=4 can be directly taken from the table, that is, the best position is 4.
[0126] Similarly, if the entry position occupancy of the hash bucket is 0b11111110, and a table entry with a length of 2 basic units needs to be added, the best position obtained through the mapping table Map is: map[0b11111110][1]=-1, which means that no location can be allocated for the table entry.
[0127] The above embodiment first calculates each possible situation of the table item position occupation of the hash bucket, then calculates the best position for placing table items of different lengths, and then when the table item needs to be placed, directly searches the mapping table according to the table item length and the table item position occupation of the current hash bucket, so as to directly obtain the best position. The mapping table will occupy some memory, but the best position can be directly obtained without real-time calculation at runtime. As a result, the speed of table item placement can be significantly improved.
[0128] In an embodiment of the present application, a protocol message is received and a target table item corresponding to the protocol message is determined. According to the length of the target table item and a plurality of preset table item positions corresponding to the length in the shared table items of the switch, a target position is determined in the table item positions that are not occupied by the shared table items, and the target table item is placed at the target position. Thus, the table items of different lengths of the shared table items can be placed at the best position, so that the utilization rate of the table items can be maximized, and high efficiency and simplicity are achieved.
[0129] Optionally, the embodiment of the present application further provides a device for determining a switch entry placement position, Figure 4 It is a structural block diagram of a device for determining a switch entry placement position according to an embodiment of the present application.
[0130] like Figure 4 As shown, the device 2000 for determining the placement position of a switch table entry includes a memory 2200 and a processor 2400 electrically connected to the memory 2200. The memory 2200 stores a computer program that can be executed on the processor 2400. When the computer program is executed by the processor, each process of any of the above-mentioned embodiments of the method for determining the placement position of a switch table entry can be implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0131] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of any of the above-mentioned embodiments of the method for determining the placement position of a switch table entry can be implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0132] It should be noted that, in this article, the terms "include", "comprises" or any other variations 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, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0133] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0134] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A method for determining the placement of switch table entries, characterized in that: include: Receive protocol messages; Determining a target table entry corresponding to the protocol message; Determining a target position in unoccupied entry positions of the shared entry according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch; The target entry is placed at the target location.
2. The method according to claim 1, wherein Determining a target position in unoccupied entry positions of the shared entry according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch includes: Determining the length of the target entry according to the type of the target entry and a preset mapping relationship table between entry type and entry length; Determining, according to the length of the target entry, a plurality of preset entry positions corresponding to the length in the shared entry; Determining the unoccupied table entry position from the plurality of preset table entry positions, the unoccupied table entry position including at least one preset table entry position; respectively determining weights of remaining unoccupied entry positions after the target entry is placed in each preset entry position; The target position is determined according to the weight of each remaining unoccupied entry position, wherein the weight is related to the length and quantity of different entries that can be placed in each remaining unoccupied entry position.
3. The method according to claim 2, wherein Determining, according to the length of the target entry, a plurality of preset entry positions corresponding to the length in the shared entry, including: Divide the shared entries into multiple hash buckets according to the total length of the shared entries and a preset hash bucket capacity; Determining a target hash bucket for placing the target entry according to the comparison key of the target entry; According to the length of the target entry, a plurality of preset entry positions corresponding to the length in the target hash bucket are determined.
4. The method according to claim 2, wherein Determining the unoccupied table entry position from the preset multiple table entry positions includes: Converting the length of the target entry into a first binary value; Converting the plurality of preset table entry positions into a plurality of second values in the binary format respectively; performing an AND operation on the first value and each second value respectively; The unoccupied entry position is determined according to at least one entry placement position corresponding to a second value whose operation result is zero.
5. The method according to claim 4, wherein Determining weights of remaining unoccupied entry positions after the target entry is placed in each preset entry position, respectively, includes: Determining a target remaining unoccupied entry position after placing the target entry at the target entry position; Determine the length Si of the entry that can be placed in the target remaining unoccupied entry position and the number Ni of preset entry positions corresponding to the length Si, where i is an identifier of different entry lengths; The product of the length Si and the number Ni of each entry is summed to obtain the weight of the target remaining unoccupied entry position.
6. The method according to claim 5, wherein Determining the target position according to the weights of the remaining unoccupied entry positions includes: Determine the maximum weight of each remaining unoccupied entry position; The first table entry position corresponding to the maximum weight value is determined as the target position.
7. The method according to claim 2, wherein According to the length of the target entry and a plurality of preset entry positions corresponding to the lengths in the shared entries of the switch, before determining the target position in the unoccupied entry positions of the shared entries, the method further includes: Dividing the shared entries into a plurality of hash buckets according to the total length of the shared entries and a preset hash bucket capacity; List the unoccupied entry positions corresponding to the unoccupied entry positions in the target hash bucket; Determine respectively the second entry positions at which entries of different lengths are placed at the respective unoccupied entry positions; The relationship between the position of each entry and the position of the second entry corresponding to the different lengths is stored in a mapping table; Determining a target position in unoccupied entry positions of the shared entry according to the length of the target entry and a plurality of preset entry positions corresponding to the length in the shared entry of the switch includes: Obtaining a corresponding second entry position from the mapping table according to the length of the target entry and a currently unoccupied entry position in the hash bucket corresponding to the target entry; The obtained second table entry position is used as the target position.
8. The method according to claim 7, wherein Determining respectively where entries of different lengths are placed in second entry positions at respective unoccupied entry positions includes: Determine a target remaining unoccupied entry position after placing the entry of the target length at the target entry position; Determine the length Si of the entry that can be placed in the target remaining unoccupied entry position and the number Ni of preset entry positions corresponding to the length Si, where i is an identifier of different entry lengths; Sum the product of the length Si of each entry and the number Ni to obtain the weight of the remaining unoccupied entry position of the target; The entry position corresponding to the maximum weight value of each remaining unoccupied entry position is determined as the second entry position.
9. The method according to claim 7, wherein List the unoccupied entry positions in the target hash bucket when the entry positions are not occupied, including: Determine each unoccupied entry position corresponding to each entry position in the target hash bucket when the entry position is unoccupied; Converting each unoccupied entry position into a third value in binary format according to the preset capacity unit of the hash bucket, wherein one capacity unit corresponds to one entry position; The unoccupied entry positions are listed according to the third value.
10. A device for determining the placement position of a switch table entry, characterized in that: include: A memory and a processor electrically connected to the memory, wherein the memory stores a computer program executable by the processor, and when the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 9 are implemented.
