MAC address storage method and device, electronic equipment and storage medium

By using the longest prefix matching mechanism and a hierarchical storage architecture, MAC addresses are split into a common prefix and a different suffix for separate storage, which solves the problems of storage space waste and performance degradation caused by hash collisions and achieves efficient and collision-free MAC address management.

CN122069249APending Publication Date: 2026-05-19SUZHOU CENTEC COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SUZHOU CENTEC COMM CO LTD
Filing Date
2026-03-27
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

Existing MAC address storage methods based on hash algorithms suffer from hash collisions, leading to wasted storage space and reduced lookup performance, making it difficult to support large-scale terminal access.

Method used

The longest prefix matching mechanism is adopted to split the MAC address into a common prefix and a different suffix for separate storage. A heterogeneous storage architecture combining tri-state content addressing memory and static random access memory is used, and a prefix splitting mechanism is designed to dynamically expand the storage space.

Benefits of technology

It achieves conflict-free and efficient MAC address storage, improves storage density and system scalability, and avoids performance loss caused by hash collisions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122069249A_ABST
    Figure CN122069249A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an MAC address storage method and device, electronic equipment and a storage medium, and relates to the technical field of communication. The method comprises the following steps: receiving a to-be-stored MAC address, performing prefix comparison on the to-be-stored MAC address and each stored MAC address in a prefix table, extracting a public prefix meeting a longest prefix matching condition, if the public prefix exists, obtaining a target suffix storage block corresponding to the public prefix, storing the suffix of the MAC address into the target suffix storage block, and if the public prefix does not exist, storing the suffix of the MAC address into the target suffix storage block. And splitting the to-be-stored MAC address into a to-be-stored prefix and a to-be-stored suffix according to a preset rule, and respectively storing the to-be-stored prefix and the to-be-stored suffix into the prefix table and the suffix table. Therefore, the density and efficiency of MAC address storage can be improved, and performance reduction caused by hash conflicts is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and more specifically, to a MAC address storage method, apparatus, electronic device, and storage medium. Background Technology

[0002] In data communication networks, switches, as core forwarding devices, have one of their basic functions as learning and maintaining Media Access Control (MAC) address tables to achieve accurate forwarding of Layer 2 frames. When a switch receives a data frame, it extracts the source MAC address for learning and binds the address to its corresponding ingress port information. In subsequent forwarding, if the destination MAC address exists in the local MAC table, the packet is forwarded to the designated port based on the lookup result; otherwise, it is broadcast.

[0003] Currently, the mainstream MAC address storage method uses a hash algorithm for fast lookup. Specifically, during the MAC entry writing phase, the system performs a preset hash function calculation on the target MAC address to generate a fixed-length hash value. This hash value is then used as an index to store the MAC address and its associated forwarding information (such as the outgoing port, VLAN identifier, etc.) in the corresponding hash bucket location in the chip's memory. During the lookup phase, the switching chip performs the same hash operation on the destination MAC address of the received data frame. After obtaining the hash index, it reads the MAC entry from the corresponding address and determines whether a match has been found by comparing the MAC address in the entry with the destination MAC address of the packet.

[0004] However, the MAC address storage method based on hash algorithms has an inherent flaw: due to the mapping characteristics of hash functions, different MAC addresses may be mapped to the same hash value, that is, hash collisions occur. Summary of the Invention

[0005] In view of this, the object of the present invention is to provide a MAC address storage method, apparatus, electronic device and storage medium to at least partially improve the above-mentioned problems.

[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows: In a first aspect, embodiments of the present invention provide a MAC address storage method, including: Receive the MAC address to be stored; The MAC address to be stored is compared with each stored MAC address in the prefix table to extract the common prefix that meets the longest prefix matching condition; If a common prefix exists, obtain the target suffix storage block corresponding to the common prefix, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address to be stored excluding the common prefix; If there is no common prefix, the MAC address to be stored is split into a prefix and a suffix to be stored according to a preset rule, and the prefix and the suffix to be stored are stored in the prefix table and the suffix table respectively.

[0007] Optionally, before the step of storing the suffix of the MAC address to be stored into the target suffix storage block, the method further includes: Determine whether the target suffix storage block is capable of storing the suffix of the MAC address to be stored; If so, then execute the step of storing the suffix of the MAC address to be stored into the target suffix storage block; If not, the common prefix is ​​split, and all suffixes in the target suffix storage block and the suffix of the MAC address to be stored are re-stored.

[0008] Optionally, splitting the common prefix and re-storing all suffixes in the target suffix storage block and the suffix of the MAC address to be stored includes: Take all the suffixes in the target suffix storage block and the suffix of the MAC address to be stored as suffixes to be processed, and extract at least two extension bits from each of the suffixes to be processed; Each of the aforementioned extension bits is concatenated after the common prefix to obtain the split prefix; Remove the extension bits corresponding to each of the suffixes to be processed to obtain the remaining suffixes of each of the suffixes to be processed; Based on each of the split prefixes, a corresponding first prefix storage block is created in the prefix table, and a first suffix storage block is allocated to each of the first prefix storage blocks. Each of the split prefixes is stored in the corresponding first prefix storage block, and each of the remaining suffixes is stored in the corresponding first suffix storage block.

[0009] Optionally, the step of extracting at least two extension bits from each of the suffixes to be processed includes: Starting from the highest bit of each of the suffixes to be processed, extract one or more consecutive bits as extension bits until the suffixes to be processed can be distinguished into at least two different groups.

[0010] Optionally, the step of splitting the MAC address to be stored into a prefix and a suffix according to a preset rule, and storing the prefix and suffix into the prefix table and suffix table respectively, includes: The MAC address to be stored is split into a prefix to be stored and a suffix to be stored according to a preset prefix length; wherein, the length of the prefix to be stored is the preset prefix length; A second prefix storage block is created in the prefix table for the prefix to be stored, and a second suffix storage block is allocated to the second prefix storage block; The prefix to be stored is stored in the second prefix storage block, and the suffix to be stored is stored in the second suffix storage block.

[0011] Optionally, the prefix table is a tri-state content-addressable memory, and the suffix table is a static random access memory.

[0012] Optionally, the method further includes: Obtain the destination MAC address of the packet to be forwarded; The destination MAC address is used to perform the longest prefix matching with each common prefix in the prefix table; If a common prefix is ​​matched, the suffix of the destination MAC address is searched in its corresponding third suffix storage block; If a match is found in the third suffix storage block, the message is forwarded according to the exit information corresponding to the matched suffix.

[0013] In a second aspect, embodiments of the present invention provide a MAC address storage device, comprising: MAC address receiving unit, used to receive MAC addresses to be stored; The common prefix matching unit is used to compare the MAC address to be stored with each stored MAC address in the prefix table and extract the common prefix that satisfies the longest prefix matching condition. A MAC address storage unit is used to, if a common prefix exists, obtain the target suffix storage block corresponding to the common prefix, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address to be stored excluding the common prefix; if no common prefix exists, the MAC address to be stored is split into a prefix to be stored and a suffix to be stored according to a preset rule, and the prefix to be stored and the suffix to be stored are stored into the prefix table and the suffix table respectively.

[0014] Thirdly, embodiments of the present invention provide an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the method described in any of the above-mentioned embodiments.

[0015] Fourthly, embodiments of the present invention provide a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in any of the preceding claims.

[0016] The present invention provides a MAC address storage method, apparatus, electronic device, and storage medium. By employing the longest prefix matching mechanism to organize and store MAC addresses in a hierarchical manner, MAC addresses with common prefixes are merged and managed, and only their differences are stored, thereby significantly improving the storage density of the MAC address table. At the same time, it avoids the performance degradation and space waste caused by mapping collisions in traditional hash algorithms, and achieves collision-free and highly efficient MAC address storage.

[0017] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 A schematic structural block diagram of an electronic device provided in an embodiment of the present invention; Figure 2 This is a flowchart illustrating a MAC address storage method provided in an embodiment of the present invention. Figure 3 This is another flowchart illustrating a MAC address storage method provided in an embodiment of the present invention; Figure 4 A flowchart illustrating step S229 provided in an embodiment of the present invention; Figure 5 This is a schematic diagram illustrating a MAC address storage result provided in an embodiment of the present invention; Figure 6 This is another schematic diagram of a MAC address storage result provided in an embodiment of the present invention; Figure 7 This is another schematic diagram of a MAC address storage result provided in an embodiment of the present invention; Figure 8 A flowchart illustrating step S240 provided in an embodiment of the present invention; Figure 9 This is another schematic diagram of a MAC address storage result provided in an embodiment of the present invention; Figure 10 This is another flowchart illustrating a MAC address storage method provided in an embodiment of the present invention; Figure 11 This is a schematic structural block diagram of a MAC address storage device provided in an embodiment of the present invention.

[0020] Icons: 100 - Electronic device; 101 - Memory; 102 - Communication interface; 103 - Processor; 104 - Communication bus; 400 - MAC address storage device; 410 - MAC address receiving unit; 420 - Common prefix matching unit; 430 - MAC address storage unit. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0022] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0023] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0024] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0025] As described in the background section, the MAC address storage method based on hash algorithms has inherent defects. Due to the mapping characteristics of hash functions, different MAC addresses may be mapped to the same hash value, i.e., hash collisions occur.

[0026] To address this problem, existing technologies typically employ the following two strategies: 1. Expanding the hash table space: This reduces the probability of collisions by increasing chip memory capacity. However, this method leads to a significant waste of hardware resources. For example, in typical application scenarios, even with optimized hash functions, the collision rate can still reach 20%-30%, meaning that nearly one-third of the storage space cannot be effectively utilized.

[0027] 2. Multi-bucket chained storage structure: This structure allows the same hash value to correspond to multiple storage units (i.e., multiple hash buckets), forming a linked list or array structure. While it can alleviate collisions to some extent, searching requires traversing all entries with the same hash value one by one, significantly increasing the average search time and affecting forwarding performance, especially in high-density traffic scenarios.

[0028] In summary, existing MAC address storage mechanisms based on hash algorithms are limited by unavoidable collision problems, making it difficult to further increase the capacity of MAC address entries while ensuring lookup efficiency, thus restricting the ability of high-end switching chips to support large-scale terminal access.

[0029] Based on the above, embodiments of the present invention provide a MAC address storage method, device, electronic device, and storage medium. By adopting a hierarchical storage architecture based on longest prefix matching, the MAC address is split into a common prefix and a different suffix for separate storage, thereby achieving a conflict-free, high-density MAC address management mechanism.

[0030] To implement the process steps and functions of the various examples of this invention, please refer to [link / reference]. Figure 1 , Figure 1 This is a schematic structural block diagram of an electronic device provided in an embodiment of the present invention. The electronic device 100 includes a memory 101 and a processor 103, which are electrically connected directly or indirectly to each other to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses 104 or signal lines. The memory 101 can be used to store software programs and modules, and the processor 103 executes the software programs and modules stored in the memory 101, thereby performing various functional applications and data processing.

[0031] Electronic device 100 can be, but is not limited to, a personal computer (PC), a server, a distributed computer, etc. It is understood that electronic device 100 is not limited to a physical server, but can also be a virtual machine on a physical server, a virtual machine built on a cloud platform, or any other computer that can provide the same functionality as the server or virtual machine. The operating system of electronic device 100 can be, but is not limited to, Windows, Linux, etc.

[0032] The memory 101 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0033] The communication connection between the electronic device 100 and external devices is achieved through at least one communication interface 102 (which can be wired or wireless).

[0034] Processor 103 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of this embodiment can be completed by integrated logic circuits in the hardware of processor 103 or by instructions in software form. Processor 103 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0035] Understandable. Figure 1 The structure shown is for illustrative purposes only; the electronic device 100 may also include components that are more advanced than those shown. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.

[0036] The MAC address storage method provided by this invention will be described below by way of example. See [link to documentation]. Figure 2 The method includes, for example Figure 2 The following steps are described: S210: Receive the MAC address to be stored.

[0037] The MAC address to be stored is a standard 48-bit Ethernet MAC address, in the format `XX:XX:XX:XX:XX:XX`.

[0038] S220: Compare the MAC address to be stored with each stored MAC address in the prefix table to extract the common prefix that meets the longest prefix matching condition.

[0039] S230: If a common prefix exists, obtain the target suffix storage block corresponding to the common prefix, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address to be stored excluding the common prefix.

[0040] S240: If there is no common prefix, split the MAC address to be stored into a prefix and a suffix according to the preset rules, and store the prefix and suffix into the prefix table and suffix table respectively.

[0041] The process involves comparing the MAC address to be stored with the prefixes of all MAC addresses already stored in the prefix table, bit by bit, to find the existing entry with the longest common prefix and extracting that common prefix. The Longest Prefix Match (LPM) algorithm can be used for this matching. For example, if a common prefix `12:34:56:78:9A:00 / 45` exists in the prefix table, it means the effective length of the prefix is ​​the first 45 bits; the current MAC address to be stored is `12:34:56:78:9A:01`, whose first 45 bits are completely identical to the above prefix; therefore, it is determined that the two have a common prefix ` / 45`, and this is the current longest match result.

[0042] If one or more levels of common prefixes are successfully matched in step S220, firstly, the target suffix storage block associated with that common prefix is ​​determined. Each prefix entry is bound to an independent suffix storage area upon creation, used to store the "difference portion" of all MAC addresses belonging to that common prefix. Then, the remaining bits excluding the common prefix are extracted from the MAC address to be stored to form its suffix portion. For example, under the ` / 45` prefix, the last 3 bits of the MAC address (i.e., bits 46 to 48) are used as the suffix. Finally, this suffix is ​​written into the corresponding target suffix storage block.

[0043] If no valid matching common prefix is ​​found in step S220, it means that the MAC address cannot be classified into the existing prefix structure, and a new storage entry needs to be created for it. In this case, the MAC address is split according to a preset rule. In an optional embodiment, the preset rule is a fixed-length prefix division, for example, taking the first 44 bits as the prefix to be stored and the remaining 4 bits as the suffix to be stored. Subsequently, the prefix to be stored is written into the prefix table and a new entry is allocated for it; at the same time, a corresponding suffix storage block (i.e., the second suffix storage block) is created for the prefix; and the suffix to be stored is written into the newly allocated suffix storage block.

[0044] It is understood that the MAC address to be stored also corresponds to exit information. When storing a MAC address, the exit information will be stored in the storage area pointed to by the suffix and associated with the MAC address to be stored. The core of this embodiment of the invention lies in the storage of MAC addresses, and the exit information will not be described in detail thereafter.

[0045] This method abandons the traditional hashing method and introduces the longest prefix matching mechanism to achieve efficient and conflict-free storage of MAC addresses.

[0046] The prefix table and suffix table in this embodiment of the invention can be implemented through software simulation, that is, logically distinguished on the same memory. However, in order to balance lookup efficiency, storage density, and power consumption cost, in an optional embodiment, a heterogeneous memory architecture can be used to physically implement the prefix table and suffix table: the prefix table uses a ternary content addressable memory (TCAM), and the suffix table uses a static random-access memory (SRAM).

[0047] This invention significantly improves the storage density of MAC address table entries through a prefix sharing mechanism. However, it may encounter situations where the number of MAC addresses aggregated under a certain common prefix is ​​too large, causing the associated target suffix storage block to be unable to accommodate new entries. Therefore, in an optional embodiment, a dynamic expansion mechanism based on prefix splitting is provided to automatically reconstruct the address space structure when suffix storage space is limited, ensuring the scalability and stability of the system. See also... Figure 3 Before performing the step of "storing the suffix of the MAC address into the target suffix storage block", the method may further include: S227: Determine whether the target suffix storage block can store the suffix of the MAC address to be stored. If yes, proceed to step S228; if no, proceed to step S229.

[0048] First, query the suffix storage blocks bound to the currently matched common prefix to obtain their remaining available space information. This can be achieved in the following ways: maintain a "used entries" counter for each suffix storage block; or set a fixed capacity limit (e.g., a maximum of 8 suffix entries); before writing a new suffix, check whether the current number of stored entries has reached the limit.

[0049] For example, the suffix storage block corresponding to a certain ` / 45` prefix supports a maximum of 8 entries. Currently, 7 suffixes have been stored, and there is still 1 empty space, which can be used to directly insert a new suffix. If there are already 8 entries and no empty space, it is determined to be "unaccommodating" and triggers the subsequent split operation.

[0050] If the capacity is not full, proceed to S228; otherwise, proceed to S229 for capacity expansion.

[0051] S228: Then execute the step of storing the suffix of the MAC address to be stored into the target suffix storage block.

[0052] If the judgment result is "can accommodate", then the writing process is executed normally, that is, the suffix part of the MAC address to be stored is written to the free position in the suffix storage block.

[0053] S229: Split the common prefix and re-store all suffixes in the target suffix storage block and the suffix of the MAC address to be stored.

[0054] When the target suffix storage block is full and a new entry cannot be directly inserted, the prefix splitting mechanism is activated. By making a more refined distinction between the existing suffix set, multiple longer new prefixes are generated, thereby distributing the load and relieving storage pressure.

[0055] In one alternative implementation, see [link to implementation details]. Figure 4 Step S229 may include the following sub-steps: S2291: Take all suffixes in the target suffix storage block and the suffix of the MAC address to be stored as suffixes to be processed, and extract at least two extension bits from each suffix to be processed.

[0056] S2292: Concatenate each extension bit after the common prefix to obtain the split prefix.

[0057] S2293: Remove the extension bits corresponding to each suffix to be processed to obtain the remaining suffixes of each suffix to be processed.

[0058] S2294: Based on each split prefix, create the corresponding first prefix storage block in the prefix table, and allocate a first suffix storage block to each first prefix storage block.

[0059] S2295: Store each split prefix into the corresponding first prefix storage block, and store each remaining suffix into the corresponding first suffix storage block.

[0060] Collect all existing suffix values ​​in the current suffix storage block and add the new suffix to be inserted, forming a unified "set of suffixes to be processed". Then extract at least two extension bits from the set of suffixes to be processed. Extracting at least two extension bits from each suffix to be processed includes: Starting from the highest bit of each suffix to be processed, extract one or more consecutive bits as extension bits until the suffix to be processed can be distinguished into at least two different groups.

[0061] Starting from the most significant bit of these suffixes, analyze their bit distribution bit by bit, extract the minimum number of consecutive bits as "extension bits", so that the entire set can be divided into at least two non-empty and distinct groups.

[0062] The suffixes have the same bit width and represent the remaining part of the original MAC address after removing the common prefix. Starting from the first bit (the most significant bit) of each suffix, its value distribution is analyzed; if the bit has at least two different values ​​(both `0` and `1`), it is determined that the bit has the ability to distinguish and can be used as the first extension bit; otherwise, the next bit (the second bit) is checked, and so on.

[0063] For example, the suffix storage block under the original ` / 45` prefix is ​​full (e.g., the maximum capacity is 6 entries), containing the following 6 suffixes (all 3 bits): 000, 001, 010, 011, 100, 101.

[0064] At this point, the system receives a new MAC address to be stored. Its first 45 bits are identical to the common prefix, and the last 3 bits are `111`. Since this suffix value does not yet exist, it needs to be inserted as a new entry. First, the six suffixes in the original storage block are included in the analysis along with the newly arrived `111`, resulting in the set: {`001`, `010`, `011`, `100`, `101`, `110`, `111`} (a total of seven suffixes).

[0065] Starting from the first bit of each suffix, we can analyze its bit distribution. We only need to extract one extension bit to divide it into two groups of `0` and `1`. By concatenating the extension bit to the original ` / 45` prefix, we can form two longer new prefixes: original prefix + `0` → new prefix A, with a mask length of ` / 46`; and original prefix + `1` → new prefix B, with a mask length of ` / 46`.

[0066] Remove the bits that have been used as extension bits, and keep 2 bits as "remaining suffixes" to get group A: `001` → remaining `01`, `010` → remaining `10`, `011` → remaining `11`; group B: `100` → remaining `00`, `101` → remaining `01`, `110` → remaining `10`, `111` → remaining `11`.

[0067] Create a first prefix storage block for ` / 46-A` and allocate a new suffix storage block for it; similarly, create a corresponding first prefix storage block and suffix storage block for ` / 46-B`; write the remaining suffixes of each group into the corresponding new suffix storage blocks.

[0068] See Figure 5 , Figure 6 , Figure 7 The storage of MAC addresses is explained using TCAM and SRAM as prefix and suffix tables, respectively. Figure 5 If there are empty spaces in the SRAM storage block and a new character with the suffix `110` is added, `110` can be directly written into that storage block, such as... Figure 6 As shown. If another `111` appears, the storage block cannot hold the suffix, so the prefix needs to be split, as follows: Figure 7 As shown.

[0069] When the MAC address to be stored cannot match any existing public prefix, a completely new storage entry must be created for it. To this end, one optional implementation employs a standardized splitting strategy based on a preset prefix length to ensure consistency, efficiency, and hardware friendliness during the initialization process. See also Figure 8 The above step S240 may include the following sub-steps: S241: Split the MAC address to be stored into a prefix to be stored and a suffix to be stored according to a preset prefix length; wherein, the length of the prefix to be stored is the preset prefix length.

[0070] S242: Create a second prefix storage block in the prefix table for the prefix to be stored, and allocate a second suffix storage block for the second prefix storage block.

[0071] S243: Store the prefix to be stored into the second prefix storage block, and store the suffix to be stored into the second suffix storage block.

[0072] Based on the pre-configured preset prefix length (e.g., 40 bits, 44 bits), the received 48-bit MAC address is divided into two parts: the prefix to be stored: the highest consecutive bits of the MAC address (the number of bits is equal to the preset prefix length); and the suffix to be stored: the remaining low-order bits.

[0073] After address splitting is completed, storage resource initialization is performed: a new entry area called the "second prefix storage block" is created in the prefix table (such as TCAM implementation) to store the prefix to be stored; at the same time, an independent "second suffix storage block" is associated with and allocated to it, which is located in SRAM and has a fixed capacity.

[0074] Finally, the write operation is performed: the prefix to be stored and its mask information are written to the second prefix storage block in TCAM; the suffix to be stored is written to the second suffix storage block in SRAM.

[0075] For example, for the MAC address `AA:BB:CC:DD:EE:01` (48 bits in binary), no common prefix is ​​matched in the prefix table. If the preset prefix length is 44 bits, the prefix will be `AA:BB:CC:DD:EE:00 / 44`, and the suffix will be `0001`. The MAC address is stored, and the storage result is as follows: Figure 9 As shown.

[0076] This invention also includes a high-speed lookup and forwarding process to ensure rapid location of the target egress point and line-speed forwarding upon data packet arrival. In one optional implementation, see [link to implementation details]. Figure 10 The method may also include the following steps: S310: Obtain the destination MAC address of the packet to be forwarded.

[0077] When a switching chip receives an Ethernet data packet, it parses its Layer 2 header information and extracts the destination MAC address as the basis for subsequent forwarding decisions.

[0078] For example, the message carries the destination MAC address as `12:34:56:78:9A:01`.

[0079] S320: Use the destination MAC address to perform the longest prefix match with each common prefix in the prefix table.

[0080] The destination MAC address is entered into the prefix table, and the longest prefix matching operation is initiated. The prefix table stores multiple common prefixes. The high-order bits of the destination MAC address are compared in parallel with all prefix entries, and the prefix entry with the longest (i.e., the most specific) mask that can be matched is returned.

[0081] For example, the prefix table contains the following two prefixes: `12:34:56:78:9A:00 / 40` and `12:34:56:78:9A:00 / 45`. For the destination MAC address `12:34:56:78:9A:01`, both match, but the ` / 45` entry is chosen as the output because it has a longer valid prefix, conforming to the LPM principle.

[0082] S330: If a common prefix is ​​matched, then search for the suffix of the destination MAC address in its corresponding third suffix storage block.

[0083] Once a common prefix is ​​successfully matched, the third suffix storage block bound to that prefix is ​​immediately retrieved.

[0084] Then, the remaining bits after removing the common prefix are extracted from the original destination MAC address to form its suffix part, and an exact match search is performed in the suffix storage block.

[0085] S340: If a hit is found in the third suffix storage block, the message forwarding is completed according to the exit information corresponding to the hit suffix.

[0086] If a matching suffix entry is found in step S330, it is determined that the "search has been found". At this time, the pre-stored exit information in the suffix entry is read, and then the exit information is passed to the chip's forwarding decision form to guide the next hop behavior of the packet, and finally the packet forwarding is completed.

[0087] Furthermore, embodiments of the present invention also provide a MAC address storage device, see [link to documentation]. Figure 11 The MAC address storage device 400 includes: The MAC address receiving unit 410 is used to receive the MAC address to be stored.

[0088] The common prefix matching unit 420 is used to compare the MAC address to be stored with each stored MAC address in the prefix table and extract the common prefix that meets the longest prefix matching condition.

[0089] The MAC address storage unit 430 is used to obtain the target suffix storage block corresponding to the common prefix if a common prefix exists, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address excluding the common prefix; if no common prefix exists, the MAC address to be stored is split into a prefix to be stored and a suffix to be stored according to a preset rule, and the prefix to be stored and the suffix to be stored are stored into the prefix table and the suffix table respectively.

[0090] In summary, the MAC address storage method, apparatus, electronic device, and storage medium provided by the embodiments of the present invention effectively solve the problems of storage space waste and search performance degradation caused by hash collisions by introducing the longest prefix matching mechanism to replace the traditional hash algorithm, combining prefix sharing and suffix separation storage strategies, and designing a dynamic expansion mechanism for prefix splitting, thereby significantly improving the storage efficiency and system scalability of the MAC address table.

[0091] In the embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0092] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0093] If the functionality is implemented as a software module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0094] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

[0095] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

Claims

1. A method for storing MAC addresses, characterized in that, include: Receive the MAC address to be stored; The MAC address to be stored is compared with each stored MAC address in the prefix table to extract the common prefix that meets the longest prefix matching condition; If a common prefix exists, obtain the target suffix storage block corresponding to the common prefix, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address to be stored excluding the common prefix; If there is no common prefix, the MAC address to be stored is split into a prefix and a suffix to be stored according to a preset rule, and the prefix and the suffix to be stored are stored in the prefix table and the suffix table respectively.

2. The method according to claim 1, characterized in that, Before the step of storing the suffix of the MAC address to be stored into the target suffix storage block, the method further includes: Determine whether the target suffix storage block is capable of storing the suffix of the MAC address to be stored; If so, then execute the step of storing the suffix of the MAC address to be stored into the target suffix storage block; If not, the common prefix is ​​split, and all suffixes in the target suffix storage block and the suffix of the MAC address to be stored are re-stored.

3. The method according to claim 2, characterized in that, The step of splitting the common prefix and re-storing all suffixes in the target suffix storage block and the suffix of the MAC address to be stored includes: Take all the suffixes in the target suffix storage block and the suffix of the MAC address to be stored as suffixes to be processed, and extract at least two extension bits from each of the suffixes to be processed; Each of the aforementioned extension bits is concatenated after the common prefix to obtain the split prefix; Remove the extension bits corresponding to each of the suffixes to be processed to obtain the remaining suffixes of each of the suffixes to be processed; Based on each of the split prefixes, a corresponding first prefix storage block is created in the prefix table, and a first suffix storage block is allocated to each of the first prefix storage blocks. Each of the split prefixes is stored in the corresponding first prefix storage block, and each of the remaining suffixes is stored in the corresponding first suffix storage block.

4. The method according to claim 3, characterized in that, The step of extracting at least two extension bits from each of the suffixes to be processed includes: Starting from the highest bit of each of the suffixes to be processed, extract one or more consecutive bits as extension bits until the suffixes to be processed can be distinguished into at least two different groups.

5. The method according to claim 1, characterized in that, The step of splitting the MAC address to be stored into a prefix and a suffix according to a preset rule, and storing the prefix and suffix into the prefix table and suffix table respectively, includes: The MAC address to be stored is split into a prefix to be stored and a suffix to be stored according to a preset prefix length; wherein, the length of the prefix to be stored is the preset prefix length; A second prefix storage block is created in the prefix table for the prefix to be stored, and a second suffix storage block is allocated to the second prefix storage block; The prefix to be stored is stored in the second prefix storage block, and the suffix to be stored is stored in the second suffix storage block.

6. The method according to claim 1, characterized in that, The prefix table is a tri-state content-addressable memory, and the suffix table is a static random access memory.

7. The method according to claim 1, characterized in that, The method further includes: Obtain the destination MAC address of the packet to be forwarded; The destination MAC address is used to perform the longest prefix matching with each common prefix in the prefix table; If a common prefix is ​​matched, the suffix of the destination MAC address is searched in its corresponding third suffix storage block; If a match is found in the third suffix storage block, the message is forwarded according to the exit information corresponding to the matched suffix.

8. A MAC address storage device, characterized in that, include: MAC address receiving unit, used to receive MAC addresses to be stored; The common prefix matching unit is used to compare the MAC address to be stored with each stored MAC address in the prefix table and extract the common prefix that satisfies the longest prefix matching condition. A MAC address storage unit is used to, if a common prefix exists, obtain the target suffix storage block corresponding to the common prefix, and store the suffix of the MAC address to be stored into the target suffix storage block; wherein, the suffix of the MAC address to be stored is the remaining part of the MAC address to be stored excluding the common prefix; If there is no common prefix, the MAC address to be stored is split into a prefix and a suffix to be stored according to a preset rule, and the prefix and the suffix to be stored are stored in the prefix table and the suffix table respectively.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1 to 7.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 7.