WO2014127605A1 - Mac address hardware learning method and system based on hash table and tcam table - Google Patents

Mac address hardware learning method and system based on hash table and tcam table Download PDF

Info

Publication number
WO2014127605A1
WO2014127605A1 PCT/CN2013/080000 CN2013080000W WO2014127605A1 WO 2014127605 A1 WO2014127605 A1 WO 2014127605A1 CN 2013080000 W CN2013080000 W CN 2013080000W WO 2014127605 A1 WO2014127605 A1 WO 2014127605A1
Authority
WO
WIPO (PCT)
Prior art keywords
entry
tcam
mac address
hash table
hash
Prior art date
Application number
PCT/CN2013/080000
Other languages
French (fr)
Chinese (zh)
Inventor
周万涛
徐剑辉
Original Assignee
烽火通信科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 烽火通信科技股份有限公司 filed Critical 烽火通信科技股份有限公司
Publication of WO2014127605A1 publication Critical patent/WO2014127605A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L49/00Packet switching elements
    • H04L49/30Peripheral units, e.g. input or output ports
    • H04L49/3009Header conversion, routing tables or routing tags

Definitions

  • the present invention relates to the field of MAC (Media Access Control) address learning, and particularly relates to a MAC address hardware learning based on a HASH (Hash) table and a TCAM (Ternary Content Addressable Memory) table.
  • HASH Hash
  • TCAM Ternary Content Addressable Memory
  • VPLS Virtual Private LAN Service
  • MPLS Multi-Protocol Label Switching
  • the VPLS guides the forwarding of user packets by looking up the MAC address forwarding table of the VSI (Virtual Switch Instance).
  • the MAC address forwarding table is created through the MAC address learning function. Therefore, the MAC address learning function is a key factor in implementing VPLS.
  • the two trigger conditions for MAC address learning are:
  • a VSI receives a known source MAC address, but the corresponding forwarding entry needs to be updated. For example, the receiving VP (Virtual Port, virtual switching port in the VSI) has changed.
  • VP Virtual Port, virtual switching port in the VSI
  • the hash algorithm maps binary values of arbitrary length to smaller binary values of fixed length to achieve data compression, and suppresses data conflicts generated by mapping by breaking and discretizing the original data.
  • hashing algorithms include MD2 (Message Digest Algorithm 2, Message Digest Algorithm Second Edition), MD5 (Message Digest Algorithm 5, Message Digest Algorithm Fifth Edition), CRC (Cyclic Redundancy Check) 32, etc. . In practical applications, CRC32 is often used as a hash algorithm.
  • the single hash bucket cache conflict method reduces the collision probability by extending the number of discrete values. For each lbit discrete value, the conflict table capacity needs to be doubled, so the conflict table resource is wasted. Moreover, since this method relies entirely on discrete values for the location of entries, no matter how the entries are expanded, it is not always possible to cache multiple MAC addresses with identical discrete values. In addition, when the MAC address sample changes, the probability of collision allowed in the system design cannot be guaranteed.
  • ASIC Application Specific Integrated Circuit
  • the multi-bucket cache conflict method largely solves the problem that a single hash bucket cannot cache the same MAC address with the same discrete value, and the utilization efficiency of hardware resources is also relatively high.
  • this method requires a large number of conflict buckets to work together, and requires dedicated The hardware circuit supports, and the search method of the idle entry in each conflict bucket requires a dedicated hardware circuit to implement the search algorithm. Since the algorithm implemented is not disclosed, the application is not flexible; in addition, since the method only utilizes the current conflict The free table entry resource in the bucket caches the conflict. Therefore, only up to 8 MAC addresses with the same discrete value can be cached. The ability to cache conflicts is limited for more severe cases with the same discrete value. Summary of the invention
  • the object of the present invention is to overcome the deficiencies of the above background art, and to provide a MAC address hardware learning method and system based on a hash table and a TCAM table, which are implemented on a universal programmable switching chip without the support of a dedicated hardware circuit.
  • the learning rate is higher; the occupied memory resources are less, the general algorithm is adopted, the application is flexible, and the collision probability can be completely controlled.
  • the MAC address hardware learning method based on the hash table and the TCAM table provided by the present invention includes the following steps:
  • the virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs;
  • the MAC address is the source MAC address of the packet;
  • the table entry full flag is set to 1, indicating that the TCAM table has been learned. Search in the item;
  • the source MAC address of the packet, the virtual forwarding instance number of the packet, and the virtual switching port received by the packet are stored in the current hash entry, and the valid entry of the entry is set to 1, and the process proceeds to S15.
  • TCAM memory does not have a free entry, give up learning, go to S15;
  • the virtual forwarding instance number of the key value is filled in as the virtual forwarding instance number of the packet, and the mask is set to 1 ;
  • the MAC address is filled in as the source MAC address of the packet, and the mask is set. 1;
  • the entry full flag is set to 1, the mask is set to 1;
  • the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, go to S15;
  • step S1 the step of initializing the entry is further included: determining whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, returning an exception; otherwise, determining whether the index value of the initialization entry is located in the hash.
  • initialize the hash table directly locate the hash table with the initialization index value, and clear all the contents of the table entry; otherwise, determine whether the index of the initialization entry is the last item of the TCAM, if yes , initializes the last TCAM entry, all fields in the key value are initialized to 0, the mask is 0, all fields in the data are assigned a value of 0, indicating that the entry is the last entry of the TCAM; otherwise, the key value is The middle entry full flag is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, the remaining fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0.
  • the step of aging includes the step of aging: determining whether the index of the aging entry is greater than the maximum value of the entry, and if yes, returning an exception; otherwise, determining whether the index value of the aging entry is located in the hash table index If yes, the aging hash table is used to directly locate the hash table with the initial index value, and clear the contents of the entry to 0; otherwise, determine whether the aging entry index is the last item of the TCAM, and if so, Indicates that the last item of the TCAM is an entry matching any key value, and the aging is ended; otherwise, the full value of the table entry in the key value is cleared to 0, the mask is set to 1, the remaining fields are cleared to 0, the mask is cleared to 0, and the entry status is set. If the value is set to null, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry,
  • the hash table is stored in SRAM or DRAM.
  • the TCAM entry is stored in a TCAM memory.
  • the present invention also provides a MAC address hardware learning system based on a hash table and a TCAM table, including a search unit, a TCAM entry determination unit, a hash table determination unit, a hash table comparison unit, and a hash collision processing unit, where:
  • the searching unit is configured to: calculate a hash value by using a virtual forwarding instance number and a source MAC address to which the packet belongs, and search the hash table by using a hash value; organize the search for the key value of the TCAM entry: virtual forwarding instance
  • the number is the virtual forwarding instance number to which the packet belongs.
  • the MAC address is the source MAC address of the packet. If the entry full flag is set to 1, the search is performed in the learned TCAM entry.
  • the TCAM entry determining unit is configured to: determine whether a valid flag in the TCAM entry data is set, and if set, compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch port, and if yes, The table entry is not updated; otherwise, the virtual switch port in the current TCAM entry data is updated to actually receive the virtual switch port; if not set, the hash table judgment trigger signal is generated and sent to the hash table judgment unit;
  • the hash table determining unit is configured to: when receiving the hash table determining the trigger signal, determine whether the data valid flag in the hash table is set, if not set, the source MAC address of the packet and the virtual forwarding of the packet.
  • the virtual switch port received by the instance number and the packet is stored in the current hash entry, and the valid entry of the entry is set to 1. If set, the comparison trigger signal is generated and sent to the hash table comparison unit.
  • the hash table comparison unit is configured to: when receiving the comparison trigger signal, compare whether the virtual forwarding instance number and the MAC address in the hash table match the virtual forwarding instance number and the MAC address to which the packet belongs, and if yes, Indicates that the current address has been learned in the hash table. Compares whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the learning is ended. Otherwise, the update is performed.
  • the virtual forwarding port number in the pre-hash entry is the actual virtual port number received by the packet, and the learning is ended; if not, the hash conflict processing trigger signal is generated and sent to the hash conflict processing unit;
  • the hash conflict processing unit is configured to: when receiving the hash conflict processing trigger signal, organize to search for a key value of the TCAM entry to find an idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address 0, the entry full flag is 0, indicating that the search is in the idle TCAM entry; then it is determined whether the valid flag in the TCAM data is set, if set, the first free entry is found, and the MAC address is cached to the current In the idle TCAM entry, the virtual forwarding instance number of the key is filled in as the virtual forwarding instance number of the packet, the mask is set to 1, the MAC address is filled in as the source MAC address of the packet, the mask is set to 1, and the entry full flag is set to 1. The mask is set to 1.
  • the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, and the learning is ended. If it is not set, it indicates that the TCAM memory has no free entry, and the learning is abandoned.
  • the method further includes: an initialization unit, configured to: determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the initialization entry is in the index range of the hash table Inside, if yes, initialize the hash table, directly locate the hash table with the initialization index value, and clear all the contents of the table entry; otherwise, determine whether the index of the initialization entry is the last item of the TCAM, and if so, initialize The last TCAM entry, all the fields in the key value are initialized to 0, the mask is 0, all fields in the data are assigned 0, indicating that the entry is the last entry of the TCAM; otherwise, the key in the key entry The full flag is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, the remaining fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0,
  • the aging unit is further configured to: determine whether the index of the aging entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the aging entry is in the index range of the hash table.
  • the aging hash table directly locates the hash table with the initial index value, and clears the contents of the entry to 0; otherwise, determines whether the aging entry index is the last item of the TCAM, and if so, The last item of the TCAM is an entry that matches any key value, and the aging is ended; otherwise, the full value of the table entry in the key value is cleared to 0, the mask is set to 1, the remaining fields are cleared to 0, the mask is cleared to 0, and the state of the entry is set. If it is empty, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
  • the hash table is stored in an SRAM or a DRAM.
  • the TCAM entry is stored in a TCAM memory.
  • the present invention uses a hash table to store the learned MAC address when there is no MAC address conflict.
  • the hash table hardware is implemented by SRAM or DRAM, and the capacity and bandwidth can be made larger, and the hash is preferred. Tables store address entries and take full advantage of AM's large-capacity hardware resources.
  • the TCAM table is used to cache the conflicting MAC address.
  • the TCAM table hardware is implemented by TCAM memory. Since the TCAM hardware is parallel search, the free entry can be located in one search, and the number of TCAM entries is It is the number of conflicting MAC addresses that can actually be cached. Therefore, not only can the advantages of TCAM fast parallel search be fully utilized, but also the collision probability can be fully controlled.
  • the hash table since the hash table is not used to cache the conflicting MAC address, it occupies Less memory resources.
  • the present invention can be implemented on a general-purpose programmable switching chip, does not require the support of a dedicated hardware circuit, and adopts a general-purpose algorithm, and the application is very flexible.
  • the present invention uses the TCAM table to buffer the conflicting MAC address.
  • the total number of conflicting MAC addresses that can be cached is less than the total amount of TCAMs opened, and the probability of collision is controllable.
  • the number of conflicting MAC addresses that can be cached is determined. The constant, does not change with the change of the MAC address sample, the ability to cache the conflicting MAC address is guaranteed, even in the worst case of conflict, the TCAM table can still cache almost all MAC address conflicts.
  • 1 is a flow chart of initialization of an entry in an embodiment of the present invention.
  • FIG. 2 is a flow chart of a MAC address hardware learning method based on a hash table and a TCAM table in an embodiment of the present invention.
  • FIG. 3 is a flow chart of aging in an embodiment of the present invention. detailed description
  • TCAM is a three-state content-addressable memory.
  • Each bit of data in the TCAM has three states: In addition to the normal "0" and "1", there is also a “don't care” (ie, there is no need to match the bit). State, so called “three states.”
  • the "three-state” function is implemented by a mask, that is, the mask is 0, indicating "dont' t care "given key value; a mask of 1, indicating that an exact key value needs to be matched exactly.
  • This feature of TC AM allows it to perform both exact and fuzzy matching.
  • Another feature of TCAM is that "Parallel lookup", that is, given a key value, the TCAM will match all hardware entries at the same time, and return the index of the entry with the smallest address index value.
  • the AM storage hash table is used as the main memory for MAC address learning, and the characteristics of the "three-state storage" and the "parallel search" of the TCAM memory are combined to cache the conflicting MAC address.
  • the hash table acts as the main memory for the MAC address
  • the TCAM table is responsible for the core functions of the cache address conflict.
  • the hash table and the TCAM table cooperate with each other to complete the function of MAC address learning, and the implementation requires initialization, address learning, and address aging to achieve the three.
  • the hash table is stored in SRAM or DRAM, and the TCAM entry is stored in the TCAM memory.
  • the data structure of the hash table includes the virtual forwarding instance (Vsi), the Mac address, the table valid flag (Valid), and the virtual switch port (Vp).
  • Table 1 Data structure definition table of hash table As shown in Table 2, the data structure of the TCAM entry includes the key value (Key) and the data (Data).
  • the key value includes the virtual forwarding instance (Vsi), the Mac address, and the table entry full flag (FlagFull), and the data ( Data) includes the entry valid flag (Valid) and the virtual switch port (Vp).
  • the process of initializing an entry in the embodiment of the present invention is as follows:
  • Step 101 Determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, go to step 102; otherwise, go to step 103;
  • Step 102 the index of the initialization entry exceeds the maximum value of the entry, returns an exception, and proceeds to step 108;
  • Step 103 determining whether the initialization table entry index value is within the hash table index range, and if so, then proceeds to step 104; otherwise, proceeds to step 105;
  • Step 104 Initialize the hash table, directly locate the hash table entry by using the initialization index value, and clear all the contents of the entry to 0, and go to step 108;
  • Step 105 Determine whether the initialization entry index is the last item of the TCAM, and if yes, go to step 106; otherwise, go to step 107;
  • Step 106 Initialize the last TCAM entry, all fields in the key value are initialized to 0, and the mask is 0, that is, the entry is a "catch all" (match any key value) entry; all fields in the data If the entry is 0, it indicates that the entry is the last entry of the TCAM and cannot be used to cache address conflicts.
  • the last entry of the TCAM is: (1) When the service forwards the entry, the entire TCAM table can be judged. The MAC address is not cached in the entry, so the hash table needs to be searched to guide the service forwarding. (2) When the MAC address learns to search for the idle entry, the TCAM conflict cache is full and the cache cannot be cached again. The MAC address is; therefore, the total amount of conflicts that can actually be cached is the total number of TCAM entries minus 1, go to step 108;
  • step 107 the full value of the entry in the key value is cleared to 0, and the mask is set to 1 (indicating that the initial state of the current entry is empty), the remaining fields in the key value are cleared to 0, the mask is cleared to 0, and the valid entry of the entry in the data is set to 1.
  • the remaining fields are cleared to 0, indicating that the entry is not the last entry, and can be used to cache the conflicting MAC address, and proceeds to step 108;
  • Step 108 the process of initializing the entry ends.
  • an embodiment of the present invention provides a MAC address hardware learning method based on a hash table and a TCAM table, including the following steps:
  • Step 201 Calculate a hash value by using a virtual forwarding instance number and a source MAC address to which the packet belongs, and search the hash table by using a hash value index.
  • Step 202 Search for the key value of the TCAM entry:
  • the virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs;
  • the MAC address is the source MAC address of the packet; and
  • the table entry full flag is set to 1, indicating that the TCAM has been learned. Search in the table entry;
  • Step 203 Determine whether the valid flag in the TCAM entry data is set, if set, go to step 204; otherwise, go to step 206;
  • Step 204 comparing whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch port, if yes, the entry does not need to be updated, go to step 215; otherwise, the TCAM entry needs to be updated, go to step 205; Step 205, update the current TCAM entry data in the virtual switch port as the packet actually receives the virtual switch port, go to step 215;
  • Step 206 determining whether the data valid flag in the hash table is set, if set, go to step 208; otherwise, go to step 207;
  • Step 207 The source MAC address of the packet, the virtual forwarding instance number of the packet, and the virtual switching port received by the packet are stored in the current hash entry, and the valid entry of the entry is set to 1, and the process proceeds to step 215;
  • Step 208 Compare the virtual forwarding instance number and the MAC address in the hash table with the virtual forwarding instance number and the source MAC address to which the packet belongs. If the matching, the current address has been learned in the hash table, and then go to Step 209; otherwise, go to step 211;
  • Step 209 Compare whether the virtual switch port in the current hash table is equal to the packet actually receiving the virtual switch port. If they are equal, the hash table item does not need to be updated, go to step 215; otherwise, go to step 210; Step 210, update The virtual forwarding port number in the current hash entry is the actual virtual port number received by the packet, and the process proceeds to step 215.
  • Step 211 Generate a hash conflict, and organize the search for the key value of the TCAM entry to find the idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address is 0, and the entry full flag is 0, indicating that it is idle. Search in the TCAM entry;
  • Step 212 determining whether the valid flag in the TCAM data is set, if set, indicating that the first free entry is found, go to step 214; otherwise, go to step 213;
  • Step 213 The TCAM memory has no free entries to cache conflicts, abandon learning, and go to the step
  • Step 214 Cache the MAC address into the current idle TCAM entry:
  • the virtual forwarding instance number of the key value is filled in as the virtual forwarding instance number of the packet, and the mask is set to 1;
  • the MAC address is filled in as the source MAC address of the packet, and the mask is Set to 1;
  • the entry full flag is set to 1, the mask is set to 1;
  • the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, go to step 215;
  • Step 215 The MAC address hardware learning process ends.
  • the process of aging in the embodiment of the present invention is as follows:
  • Step 301 Determine whether the index of the aging entry is greater than the maximum value of the entry, if yes, go to step 302; otherwise, go to step 303;
  • Step 302 The index of the initialization entry exceeds the maximum value of the entry, and returns an exception. Go to step 308.
  • Step 304 aging the hash table, directly using the initialization index value to locate the hash table entry, and clear all the contents of the table entry, go to step 308;
  • Step 305 Determine whether the aging entry index is the last item of the TCAM, and if yes, go to step 306; otherwise, go to step 307;
  • Step 306 the last item of the TCAM is a "catch all" (match any key value) of the entry, once initialized does not need to operate on it, go to step 308;
  • Step 307 Clear the key of the key in the key value to 0, the mask is set to 1, the other fields are cleared to 0, the mask is cleared to 0, the state of the entry is set to null, the valid flag of the entry in the data is set to 1, and the remaining fields are cleared. , indicating that the entry is not the last entry, can be used to cache the conflicting MAC address, go to step 308;
  • Step 308 The MAC address aging process ends.
  • the embodiment of the invention further provides a MAC address hardware learning system based on a hash table and a TCAM table, including an initialization unit, a search unit, a TCAM entry determination unit, a hash table determination unit, a hash table comparison unit, and a hash collision.
  • Processing unit and aging unit wherein:
  • An initialization unit configured to: determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the initialization entry is within the index range of the hash table, and if so, initialize the hash table Directly use the initialization index value to locate the hash table entry, and clear all the contents of the table entry; otherwise, determine whether the initialization entry index is the last item of the TCAM, and if so, initialize the last TCAM entry, all in the key value
  • the fields are initialized to 0, the mask is 0, and all fields in the data are assigned a value of 0, indicating that the entry is the last entry of the TCAM; otherwise, the full value of the entry in the key value is cleared to 0, and the mask is set to 1, Indicates that the initial state of the current entry is empty, the other fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the
  • the search unit is configured to: calculate a hash value by using the virtual forwarding instance number and the source MAC address to which the packet belongs, and search the hash table by using a hash value index, and the hash table is stored in the SRAM or the DRAM; the TCAM entry is stored.
  • the organization searches for the key value of the TCAM entry: the virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs; the MAC address is the source MAC address of the packet; the table entry full flag is set to 1, indicating that it has learned Search in the TCAM entry;
  • the TCAM entry determining unit is configured to: determine whether the valid flag in the TCAM entry data is set, and if set, compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch. The port, if yes, does not update the entry; otherwise, the virtual switch port in the current TCAM entry data is updated to receive the virtual switch port for the packet; if not set, the hash table judgment trigger signal is generated and sent to the hash. Table judgment unit;
  • the hash table determining unit is configured to: when receiving the hash table determining the trigger signal, determine whether the data valid flag in the hash table is set, if not set, the source MAC address of the packet and the virtual forwarding instance number of the packet And the virtual switch port received by the packet is stored in the current hash table entry, and the entry valid flag is set to 1; if set, the comparison trigger signal is generated and sent to the hash table comparison unit;
  • the hash table comparison unit is configured to: when the comparison trigger signal is received, compare whether the virtual forwarding instance number and the MAC address in the hash table match the virtual forwarding instance number and the MAC address to which the packet belongs, and if they match, the current The address has been learned in the hash table. It compares whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the learning is ended. Otherwise, the virtual forwarding port number in the current hash table entry is updated. Ending the learning by actually receiving the virtual port number for the packet; if not, generating a hash conflict processing trigger signal, and sending the hash conflict processing unit to the hash conflict processing unit;
  • the hash conflict processing unit is configured to: when receiving the hash conflict processing trigger signal, organize the search for the key value of the TCAM entry to find the idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, and the MAC address is 0. If the entry full flag is 0, it means searching in the idle TCAM entry; then determining whether the valid flag in the TCAM data is set, if set, indicating that the first free entry is found, and the MAC address is cached to the current idle TCAM.
  • the virtual forwarding instance number of the key is filled in as the virtual forwarding instance number of the packet, the mask is set to 1, the MAC address is filled in as the source MAC address of the packet, the mask is set to 1, and the entry full flag is set to 1.
  • the code is set to 1, the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, and the learning is ended; if not set, it indicates that the TCAM memory has no free entry, and the learning is abandoned;
  • the aging unit is configured to: determine whether the index of the aging entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the aging entry is in the index range of the hash table, and if yes, the aging hash table Directly use the initial index value to locate the hash table entry, and clear all the contents of the table entry; otherwise, determine whether the aging entry index is the last item of the TCAM, and if so, the last item of the TCAM is a match for any key value. If the entry is cleared, the mask is set to 0, the remaining fields are cleared to 0, the mask is cleared to 0, the entry status is set to null, and the entry in the data is valid. 1. The remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.

Abstract

Disclosed in the present invention are a MAC address hardware learning method and system based on a hash table and a TCAM table, relating to the field of MAC address learning. When there is no MAC address conflict, a learnt MAC address is stored in the hash table by means of SRAM or DRAM on hash table hardware; when there is a MAC address conflict, the conflicting MAC address is cached in the TCAM table by means of a TCAM memory on TCAM hardware. Because a parallel search is performed on the TCAM hardware, idle entries can be located by a single search; and the number of the entries of the TCAM is the actual number of conflicting MAC addresses capable of being cached. The present invention can be implemented on a general programmable exchange chip, does not need the support of a dedicated hardware circuit, has a high learning rate, occupies few memory resources, is flexible in application by adopting a general algorithm, and can achieve complete controllability of the conflict probability.

Description

基于哈希表和 TCAM表的 MAC地址硬件学习方法及系统 技术领域  MAC address hardware learning method and system based on hash table and TCAM table
本发明涉及 MAC (Media Access Control, 媒体访问控制) 地址学习领域, 特别是涉及一种基于 HASH (哈希) 表和 TCAM (Ternary Content Addressable Memory, 三态内容寻址存储器) 表的 MAC地址硬件学习方法及系统。 背景技术  The present invention relates to the field of MAC (Media Access Control) address learning, and particularly relates to a MAC address hardware learning based on a HASH (Hash) table and a TCAM (Ternary Content Addressable Memory) table. Method and system. Background technique
随着经济全球化的发展,越来越多的企业分布范围日益扩大, 迫切需要电信 运营商提供链路连接, 以便将企业各分支机构囊括进来, 组成企业内部的专用网 络。 在这样的市场需求下, VPLS (Virtual Private Lan Service, 虚拟专用局域网 业务) 技术应运而生, VPLS 技术结合了以太网技术和 MPLS (Multi-Protocol Label Switching, 多协议标签交换)技术的优势, 通过运营商提供的 IP (Internet Protocol, 网际协议) /MPLS 网络连接地域上隔离的多个由以太网构成的 LAN (Local Area Network, 局域网), 实现了对传统 LAN功能的仿真, 使它们像一 个 LAN那样工作。  With the development of economic globalization, more and more enterprises are expanding in scope, and it is urgent for telecom operators to provide link connections, so as to include all branches of the enterprise and form a dedicated network within the enterprise. Under such market demand, VPLS (Virtual Private LAN Service) technology emerges as the times require. VPLS technology combines the advantages of Ethernet technology and MPLS (Multi-Protocol Label Switching) technology. The IP (Internet Protocol) / MPLS network connection provided by the operator is a geographically isolated LAN (Local Area Network), which simulates the traditional LAN functions and makes them look like a LAN. Work like that.
VPLS通过查找对应 VSI (Virtual Switch Instance, 虚拟转发实例) 的 MAC 地址转发表, 来指导用户报文的转发, 而 MAC地址转发表是通过 MAC地址学 习功能创建的。 因此, MAC地址学习功能是实现 VPLS的关键因素。  The VPLS guides the forwarding of user packets by looking up the MAC address forwarding table of the VSI (Virtual Switch Instance). The MAC address forwarding table is created through the MAC address learning function. Therefore, the MAC address learning function is a key factor in implementing VPLS.
MAC地址学习的 2个触发条件是:  The two trigger conditions for MAC address learning are:
( 1 ) 某个 VSI收到源 MAC是未知单播地址时;  (1) When a VSI receives an unknown MAC address, the source MAC address is unknown;
(2) 某个 VSI收到一个已知的源 MAC地址, 但是对应的转发表项需要更 新, 例如: 接收 VP (Virtual Port, VSI中的虚拟交换端口) 发生了变化。  (2) A VSI receives a known source MAC address, but the corresponding forwarding entry needs to be updated. For example, the receiving VP (Virtual Port, virtual switching port in the VSI) has changed.
在 MAC地址学习中地址冲突是不可避免的问题,原因是 MAC地址有 48bit, 而 VSI根据设备容量的不同取值一般大于 lObit (即最少支持 lk个 VSI)。 理论 上如果要避免 MAC地址冲突, 则需要穷举所有 MAC地址组合情况, 至少需要 2Λ58=256Ρ (计算机存储单位, lPeta=1024T)个表项, 显然不可能用硬件来缓存 如此大数量级的表项。 目前解决 MAC地址冲突的方法有以下三种: Address conflicts are unavoidable in MAC address learning because the MAC address has 48 bits, and the VSI is generally larger than lObit according to the device capacity (that is, at least lk VSIs are supported). In theory, if you want to avoid MAC address conflicts, you need to exhaust all MAC address combinations, at least 2 Λ 58 = 256 Ρ (computer storage unit, lPeta = 1024T) entries, obviously it is impossible to use hardware to cache such a large number of Entry. Currently, there are three methods for resolving MAC address conflicts:
( 1 ) 依赖主控 CPU (Central Processing Unit, 中央处理器) 来协助解决地 址冲突: 一种 MAC地址软件学习方法, 即在主控 CPU上通过实现 "冲突链表" 算法来解决地址冲突问题。 由于主控 CPU通常用来运行复杂的路由协议, 本身 负担已经较重, 因此, 非常浪费宝贵的主控 CPU处理资源, 而且与 MAC地址 硬件学习方法相比, 该 MAC地址软件学习方法的学习速率比较低。  (1) Relying on the central processing unit (Central Processing Unit) to help resolve address conflicts: A MAC address software learning method that solves the address conflict problem by implementing a "collision list" algorithm on the master CPU. Since the main control CPU is usually used to run complex routing protocols, the burden itself is already heavy. Therefore, valuable host CPU processing resources are wasted, and the learning rate of the MAC address software learning method is compared with the MAC address hardware learning method. Relatively low.
(2) 单哈希表缓存冲突方法: 一种 MAC地址硬件学习方法, 使用一个哈 希表来缓存 MAC地址冲突,即通过扩大哈希表的容量,以降低冲突产生的概率, 是一种最简单、 最常见的缓存冲突方法。  (2) Single hash table cache conflict method: A MAC address hardware learning method, which uses a hash table to cache MAC address conflicts, that is, by expanding the capacity of the hash table to reduce the probability of collisions. Simple, most common cache conflict method.
哈希算法将任意长度的二进制值映射为固定长度的较小二进制值,以实现数 据的压缩, 并通过将原始数据打散和离散, 以抑制映射后产生的数据冲突。常用 的哈希算法有 MD2 (Message Digest Algorithm 2, 消息摘要算法第二版)、 MD5 ( Message Digest Algorithm 5, 消息摘要算法第五版)、 CRC ( Cyclic Redundancy Check, 循环冗余校验) 32等。 实际应用中常采用 CRC32来作为哈希算法。 以 64K地址表为例, 将 VSI和源 MAC用 CRC32算法计算出 32bit的哈希散列值, 并将 32bit结果的高、 低 16bit异或之后截取低 16bit (2Λ16=64Κ) 作为索引值, 去索引 AM中的表项。如果两个 MAC地址 16bit离散值相同,则其中一个 MAC 地址无法被缓存; 此时, 只能期望两个 MAC地址 CRC32 Hash值的 bitl7不同, 并将表项容量由 64k扩展 128k, 以此来进一步缓解冲突。 The hash algorithm maps binary values of arbitrary length to smaller binary values of fixed length to achieve data compression, and suppresses data conflicts generated by mapping by breaking and discretizing the original data. Commonly used hashing algorithms include MD2 (Message Digest Algorithm 2, Message Digest Algorithm Second Edition), MD5 (Message Digest Algorithm 5, Message Digest Algorithm Fifth Edition), CRC (Cyclic Redundancy Check) 32, etc. . In practical applications, CRC32 is often used as a hash algorithm. Taking the 64K address table as an example, the VSI and the source MAC are used to calculate the 32-bit hash hash value by using the CRC32 algorithm, and the high- and low- 16-bit XOR of the 32-bit result is followed by the lower 16-bit (2 Λ 16=64Κ) as the index value. , to index the entries in the AM. If the 16-bit discrete values of the two MAC addresses are the same, one of the MAC addresses cannot be cached. In this case, only the bitl7 of the CRC32 Hash value of the two MAC addresses can be expected to be different, and the table entry capacity is extended by 64k from 64k, thereby further Relieve conflicts.
单哈希桶缓存冲突方法通过扩展离散值 bit数的方法来降低冲突概率, 每增 加 lbit离散值,需要将冲突表容量扩展一倍,因此对冲突表资源浪费很大。而且, 由于这种办法完全依赖离散值进行表项的定位, 不管如何扩容表项,始终无法缓 存离散值完全相同的多个 MAC地址。 另外, 当 MAC地址样本发生变化时, 并 不能保证系统设计时所允许的冲突概率。  The single hash bucket cache conflict method reduces the collision probability by extending the number of discrete values. For each lbit discrete value, the conflict table capacity needs to be doubled, so the conflict table resource is wasted. Moreover, since this method relies entirely on discrete values for the location of entries, no matter how the entries are expanded, it is not always possible to cache multiple MAC addresses with identical discrete values. In addition, when the MAC address sample changes, the probability of collision allowed in the system design cannot be guaranteed.
(3 ) 多桶缓存冲突方法: 一种 MAC地址硬件学习方法, 该方法使用多个 桶来缓解冲突, 在一些 ASIC (Application Specific Integrated Circuit, 专用集成电 路)芯片上实现, 即采用硬件电路模拟多个冲突桶, 每个冲突桶具备一定缓存冲 突的能力。仍以 64k地址表项为例,用 CRC32算法离散 MAC地址,并取 32bit Hash 值的低 16bit作为离散结果, 首先使用 16bit离散值的低 13bit (2Λ13=8Κ) 去定 位 8Κ个冲突桶, 每个冲突桶中有 8个冲突表项; 然后在当前定位的冲突桶中, 去搜索 8个冲突表项中空闲的表项,如果有空闲表项则放入空表项中;如果没有, 则无法缓存冲突。 (3) Multi-bucket cache conflict method: A MAC address hardware learning method, which uses multiple buckets to mitigate conflicts. It is implemented on some ASIC (Application Specific Integrated Circuit) chips, that is, using hardware circuits to simulate multiple Conflict buckets, each conflict bucket has the ability to have certain cache conflicts. Taking the 64k address entry as an example, the CRC32 algorithm is used to discretize the MAC address, and the lower 16 bits of the 32-bit Hash value is taken as the discrete result. First, the lower 13 bits (2 Λ 13=8Κ) of the 16-bit discrete value are used to locate 8 collision buckets. There are 8 conflicting entries in each conflict bucket; then in the currently located conflicting bucket, Search for the free entries in the eight conflicting entries. If there are free entries, they are placed in the empty entries. If not, the conflicts cannot be cached.
多桶缓存冲突方法很大程度上解决了单哈希桶无法缓存离散值相同的 MAC 地址的问题, 而且硬件资源的利用效率也比较高, 但是, 该方法需要大量冲突桶 协同工作, 需要专用的硬件电路的支持, 而且每个冲突桶中空闲表项的搜索方法 需要专用的硬件电路来实现搜索算法, 由于其实现的算法并未公开, 因此应用不 灵活; 另外, 由于该方法只利用当前冲突桶中空闲表项资源来缓存冲突, 因此, 只能缓存最多 8个离散值相同的 MAC地址, 对更多离散值相同的恶劣情况其缓 存冲突的能力有限。 发明内容  The multi-bucket cache conflict method largely solves the problem that a single hash bucket cannot cache the same MAC address with the same discrete value, and the utilization efficiency of hardware resources is also relatively high. However, this method requires a large number of conflict buckets to work together, and requires dedicated The hardware circuit supports, and the search method of the idle entry in each conflict bucket requires a dedicated hardware circuit to implement the search algorithm. Since the algorithm implemented is not disclosed, the application is not flexible; in addition, since the method only utilizes the current conflict The free table entry resource in the bucket caches the conflict. Therefore, only up to 8 MAC addresses with the same discrete value can be cached. The ability to cache conflicts is limited for more severe cases with the same discrete value. Summary of the invention
本发明的目的是为了克服上述背景技术的不足, 提供一种基于哈希表和 TCAM表的 MAC地址硬件学习方法及系统, 在通用的可编程交换芯片上实现, 不需专用硬件电路的支持, 学习速率较高; 占用的内存资源较少, 采用通用的算 法, 应用灵活, 能实现冲突概率完全可控。  The object of the present invention is to overcome the deficiencies of the above background art, and to provide a MAC address hardware learning method and system based on a hash table and a TCAM table, which are implemented on a universal programmable switching chip without the support of a dedicated hardware circuit. The learning rate is higher; the occupied memory resources are less, the general algorithm is adopted, the application is flexible, and the collision probability can be completely controlled.
本发明提供的基于哈希表和 TCAM表的 MAC地址硬件学习方法, 包括 以下步骤:  The MAC address hardware learning method based on the hash table and the TCAM table provided by the present invention includes the following steps:
51、 以报文所属的虚拟转发实例号和源 MAC地址计算哈希值, 并以哈希值 为索引搜索哈希表;  51. Calculate a hash value by using the virtual forwarding instance number and the source MAC address to which the packet belongs, and search the hash table by using the hash value as an index;
52、 组织搜索 TCAM表项的键值: 虚拟转发实例号为报文所属的虚拟转发 实例号; MAC地址为报文的源 MAC地址; 表项满标志置 1, 表示在已经学习到 的 TCAM表项中进行搜索;  52. Searching for the key value of the TCAM entry: The virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs; the MAC address is the source MAC address of the packet; the table entry full flag is set to 1, indicating that the TCAM table has been learned. Search in the item;
53、 判断 TCAM表项数据中有效标志是否置位, 如果置位, 则转到 S4; 否 贝 |J, 转到 S6;  53. Determine whether the valid flag in the TCAM entry data is set, if set, go to S4; No Bay |J, go to S6;
54、比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟交换端口, 如果是, 则表项不需要更新, 转到 S15; 否则, 表示 TCAM表项需要更新, 转 到 S5;  54. Compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving the virtual switch port. If yes, the entry does not need to be updated, and the process goes to S15; otherwise, the TCAM entry needs to be updated, and the process goes to S5;
55、 更新当前 TCAM表项数据中虚拟交换端口为报文实际接收虚拟交换端 口, 转到 S15;  55. Update the virtual switch port in the current TCAM entry data to actually receive the virtual switch port, and go to S15;
56、 判断哈希表中数据有效标志是否置位, 如果置位, 则转到 S8; 否则, 转到 S7; 56. Determine whether the data valid flag in the hash table is set, if set, go to S8; otherwise, Go to S7;
57、将报文源 MAC地址、报文所属虚拟转发实例号和报文接收的虚拟交换 端口存储到当前哈希表项中, 表项有效标志置 1, 转到 S15;  57. The source MAC address of the packet, the virtual forwarding instance number of the packet, and the virtual switching port received by the packet are stored in the current hash entry, and the valid entry of the entry is set to 1, and the process proceeds to S15.
58、 比较哈希表中虚拟转发实例号和 MAC地址是否和报文所属的虚拟转发 实例号及源 MAC地址相匹配, 如果匹配, 则表示当前地址已经在哈希表中学到 过, 转到 S9; 否则, 转到 S11 ;  58. Compare the virtual forwarding instance number and the MAC address in the hash table with the virtual forwarding instance number and the source MAC address to which the packet belongs. If it matches, the current address has been learned in the hash table, and go to S9. Otherwise, go to S11;
59、 比较当前哈希表中虚拟交换端口是否等于报文实际接收虚拟交换端口, 如果相等, 则哈希表项不需要更新, 转到 S15; 否则, 转到 S10;  59. Compare whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the hash entry does not need to be updated, and the process goes to S15; otherwise, the process goes to S10;
510、 更新当前哈希表项中的虚拟转发端口号为报文实际接收虚拟端口号, 转到 S15;  510. Update the virtual forwarding port number in the current hash entry to the virtual port number actually received by the packet, and go to S15.
511、 产生哈希冲突, 组织搜索 TCAM表项的键值以寻找空闲 TCAM表项 缓存冲突: 键值中虚拟转发实例号为 0, MAC地址为 0, 表项满标志为 0, 表示 在空闲 TCAM表项中进行搜索;  511. Generate a hash collision, and search for a key value of the TCAM entry to find an idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address is 0, and the entry full flag is 0, indicating that the idle TCAM is in the idle TCAM. Search in the table entry;
512、判断 TCAM数据中有效标志是否置位, 如果置位, 表示找到第一个空 闲表项, 转到 S14; 否则, 转到 S13 ;  512. Determine whether the valid flag in the TCAM data is set. If set, it indicates that the first idle entry is found, and the process goes to S14; otherwise, it goes to S13;
513、 TCAM存储器没有空闲表项, 放弃学习, 转到 S15;  513, TCAM memory does not have a free entry, give up learning, go to S15;
514、 将 MAC地址缓存到当前空闲 TCAM表项中: 键值的虚拟转发实例号 填写为报文所属虚拟转发实例号,掩码置 1 ; MAC地址填写为报文的源 MAC地 址, 掩码置 1 ; 表项满标志置 1, 掩码置 1 ; 数据中虚拟交换端口填写为报文实 际接收虚拟交换端口, 转到 S15; 514. Cache the MAC address into the current idle TCAM entry: The virtual forwarding instance number of the key value is filled in as the virtual forwarding instance number of the packet, and the mask is set to 1 ; the MAC address is filled in as the source MAC address of the packet, and the mask is set. 1; the entry full flag is set to 1, the mask is set to 1; the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, go to S15;
S 15、 MAC地址硬件学习流程结束。  S 15, MAC address hardware learning process ends.
在上述技术方案的基础上, 步骤 S1 之前还包括表项初始化的步骤: 判断 初始化表项索引是否大于表项最大值, 如果是, 则返回异常; 否则, 判断初始化 表项索引值是否位于哈希表索引范围内, 如果是, 则初始化哈希表, 直接用初始 化索引值定位哈希表项, 并将表项内容全部清 0; 否则, 判断初始化表项索引是 否为 TCAM最后一项, 如果是, 则初始化最后一个 TCAM表项, 键值中所有字 段均初始化为 0,掩码为 0,数据中的所有字段均赋值为 0,表示该表项为 TCAM 最后一个表项; 否则, 将键值中表项满标志清 0, 掩码置 1, 表示当前表项初始 状态为空, 键值中其余字段清 0, 掩码清 0, 数据中表项有效标志置 1, 其余字 段清 0, 表示该表项不是最后一个表项, 初始化结束。 在上述技术方案的基础上, 步骤 S15之后还包括老化的步骤: 判断老化表 项索引是否大于表项最大值, 如果是, 则返回异常; 否则, 判断老化表项索引值 是否位于哈希表索引范围内, 如果是, 则老化哈希表, 直接用初始化索引值定位 哈希表项, 并将表项内容全部清 0; 否则, 判断老化表项索引是否为 TCAM最 后一项, 如果是, 则表示 TCAM最后一项是一个匹配任意键值的表项, 结束老 化; 否则, 将键值中表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表 项状态置为空, 数据中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后 一个表项, 老化结束。 On the basis of the foregoing technical solution, before step S1, the step of initializing the entry is further included: determining whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, returning an exception; otherwise, determining whether the index value of the initialization entry is located in the hash. Within the table index range, if yes, initialize the hash table, directly locate the hash table with the initialization index value, and clear all the contents of the table entry; otherwise, determine whether the index of the initialization entry is the last item of the TCAM, if yes , initializes the last TCAM entry, all fields in the key value are initialized to 0, the mask is 0, all fields in the data are assigned a value of 0, indicating that the entry is the last entry of the TCAM; otherwise, the key value is The middle entry full flag is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, the remaining fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0. This entry is not the last entry, and initialization is complete. On the basis of the foregoing technical solution, the step of aging includes the step of aging: determining whether the index of the aging entry is greater than the maximum value of the entry, and if yes, returning an exception; otherwise, determining whether the index value of the aging entry is located in the hash table index If yes, the aging hash table is used to directly locate the hash table with the initial index value, and clear the contents of the entry to 0; otherwise, determine whether the aging entry index is the last item of the TCAM, and if so, Indicates that the last item of the TCAM is an entry matching any key value, and the aging is ended; otherwise, the full value of the table entry in the key value is cleared to 0, the mask is set to 1, the remaining fields are cleared to 0, the mask is cleared to 0, and the entry status is set. If the value is set to null, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
在上述技术方案的基础上, 所述哈希表存储在 SRAM或者 DRAM中。 在上述技术方案的基础上, 所述 TCAM表项存储在 TCAM存储器中。 本发明还提供一种基于哈希表和 TCAM表的 MAC地址硬件学习系统, 包 括搜索单元、 TCAM表项判断单元、 哈希表判断单元、 哈希表比较单元和哈希 冲突处理单元, 其中:  Based on the above technical solution, the hash table is stored in SRAM or DRAM. Based on the foregoing technical solution, the TCAM entry is stored in a TCAM memory. The present invention also provides a MAC address hardware learning system based on a hash table and a TCAM table, including a search unit, a TCAM entry determination unit, a hash table determination unit, a hash table comparison unit, and a hash collision processing unit, where:
所述搜索单元, 用于: 以报文所属的虚拟转发实例号和源 MAC地址计算哈 希值, 并以哈希值为索引搜索哈希表; 组织搜索 TCAM表项的键值: 虚拟转发 实例号为报文所属的虚拟转发实例号; MAC地址为报文的源 MAC地址; 表项 满标志置 1, 表示在已经学习到的 TCAM表项中进行搜索;  The searching unit is configured to: calculate a hash value by using a virtual forwarding instance number and a source MAC address to which the packet belongs, and search the hash table by using a hash value; organize the search for the key value of the TCAM entry: virtual forwarding instance The number is the virtual forwarding instance number to which the packet belongs. The MAC address is the source MAC address of the packet. If the entry full flag is set to 1, the search is performed in the learned TCAM entry.
所述 TCAM表项判断单元, 用于: 判断 TCAM表项数据中有效标志是否置 位, 如果置位, 则比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟 交换端口, 如果是, 则不更新表项; 否则, 更新当前 TCAM表项数据中虚拟交 换端口为报文实际接收虚拟交换端口;如果没有置位,产生哈希表判断触发信号, 并发送到哈希表判断单元;  The TCAM entry determining unit is configured to: determine whether a valid flag in the TCAM entry data is set, and if set, compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch port, and if yes, The table entry is not updated; otherwise, the virtual switch port in the current TCAM entry data is updated to actually receive the virtual switch port; if not set, the hash table judgment trigger signal is generated and sent to the hash table judgment unit;
所述哈希表判断单元, 用于: 收到哈希表判断触发信号时, 判断哈希表中数 据有效标志是否置位, 如果没有置位, 将报文源 MAC地址、 报文所属虚拟转发 实例号和报文接收的虚拟交换端口存储到当前哈希表项中, 表项有效标志置 1 ; 如果置位, 产生比较触发信号, 并发送到哈希表比较单元;  The hash table determining unit is configured to: when receiving the hash table determining the trigger signal, determine whether the data valid flag in the hash table is set, if not set, the source MAC address of the packet and the virtual forwarding of the packet The virtual switch port received by the instance number and the packet is stored in the current hash entry, and the valid entry of the entry is set to 1. If set, the comparison trigger signal is generated and sent to the hash table comparison unit.
所述哈希表比较单元, 用于: 收到比较触发信号时, 比较哈希表中虚拟转发 实例号和 MAC地址是否和报文所属的虚拟转发实例号及 MAC地址相匹配, 如 果匹配, 则表示当前地址已经在哈希表中学到过, 比较当前哈希表中虚拟交换端 口是否等于报文实际接收虚拟交换端口, 如果相等, 则结束学习; 否则, 更新当 前哈希表项中的虚拟转发端口号为报文实际接收虚拟端口号, 结束学习; 如果不 匹配, 产生哈希冲突处理触发信号, 并发送到哈希冲突处理单元; The hash table comparison unit is configured to: when receiving the comparison trigger signal, compare whether the virtual forwarding instance number and the MAC address in the hash table match the virtual forwarding instance number and the MAC address to which the packet belongs, and if yes, Indicates that the current address has been learned in the hash table. Compares whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the learning is ended. Otherwise, the update is performed. The virtual forwarding port number in the pre-hash entry is the actual virtual port number received by the packet, and the learning is ended; if not, the hash conflict processing trigger signal is generated and sent to the hash conflict processing unit;
所述哈希冲突处理单元, 用于: 收到哈希冲突处理触发信号时, 组织搜索 TCAM表项的键值以寻找空闲 TCAM表项缓存冲突: 键值中虚拟转发实例号为 0, MAC地址为 0, 表项满标志为 0, 表示在空闲 TCAM表项中进行搜索; 再判 断 TCAM数据中有效标志是否置位, 如果置位, 表示找到第一个空闲表项, 将 MAC地址缓存到当前空闲 TCAM表项中:键值的虚拟转发实例号填写为报文所 属虚拟转发实例号,掩码置 1, MAC地址填写为报文的源 MAC地址,掩码置 1, 表项满标志置 1, 掩码置 1, 数据中虚拟交换端口填写为报文实际接收虚拟交换 端口, 结束学习; 如果没有置位, 表示 TCAM存储器没有空闲表项, 放弃学习。  The hash conflict processing unit is configured to: when receiving the hash conflict processing trigger signal, organize to search for a key value of the TCAM entry to find an idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address 0, the entry full flag is 0, indicating that the search is in the idle TCAM entry; then it is determined whether the valid flag in the TCAM data is set, if set, the first free entry is found, and the MAC address is cached to the current In the idle TCAM entry, the virtual forwarding instance number of the key is filled in as the virtual forwarding instance number of the packet, the mask is set to 1, the MAC address is filled in as the source MAC address of the packet, the mask is set to 1, and the entry full flag is set to 1. The mask is set to 1. The virtual switch port in the data is filled in as the packet actually receives the virtual switch port, and the learning is ended. If it is not set, it indicates that the TCAM memory has no free entry, and the learning is abandoned.
在上述技术方案的基础上, 还包括初始化单元, 用于: 判断初始化表项索 引是否大于表项最大值, 如果是, 则返回异常; 否则, 判断初始化表项索引值是 否位于哈希表索引范围内, 如果是, 则初始化哈希表, 直接用初始化索引值定位 哈希表项, 并将表项内容全部清 0; 否则, 判断初始化表项索引是否为 TCAM最 后一项, 如果是, 则初始化最后一个 TCAM表项, 键值中所有字段均初始化为 0, 掩码为 0, 数据中的所有字段均赋值为 0, 表示该表项为 TCAM最后一个表 项; 否则, 将键值中表项满标志清 0, 掩码置 1, 表示当前表项初始状态为空, 键值中其余字段清 0, 掩码清 0, 数据中表项有效标志置 1, 其余字段清 0, 表示 该表项不是最后一个表项, 初始化结束。  On the basis of the foregoing technical solution, the method further includes: an initialization unit, configured to: determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the initialization entry is in the index range of the hash table Inside, if yes, initialize the hash table, directly locate the hash table with the initialization index value, and clear all the contents of the table entry; otherwise, determine whether the index of the initialization entry is the last item of the TCAM, and if so, initialize The last TCAM entry, all the fields in the key value are initialized to 0, the mask is 0, all fields in the data are assigned 0, indicating that the entry is the last entry of the TCAM; otherwise, the key in the key entry The full flag is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, the remaining fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating the entry. Not the last entry, initialization is complete.
在上述技术方案的基础上, 还包括老化单元, 用于: 判断老化表项索引是 否大于表项最大值, 如果是, 则返回异常; 否则, 判断老化表项索引值是否位于 哈希表索引范围内,如果是,则老化哈希表,直接用初始化索引值定位哈希表项, 并将表项内容全部清 0; 否则, 判断老化表项索引是否为 TCAM最后一项, 如 果是, 则表示 TCAM最后一项是一个匹配任意键值的表项, 结束老化; 否则, 将键值中表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表项状态置为 空, 数据中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后一个表项, 老化结束。  On the basis of the foregoing technical solution, the aging unit is further configured to: determine whether the index of the aging entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the aging entry is in the index range of the hash table. If yes, the aging hash table directly locates the hash table with the initial index value, and clears the contents of the entry to 0; otherwise, determines whether the aging entry index is the last item of the TCAM, and if so, The last item of the TCAM is an entry that matches any key value, and the aging is ended; otherwise, the full value of the table entry in the key value is cleared to 0, the mask is set to 1, the remaining fields are cleared to 0, the mask is cleared to 0, and the state of the entry is set. If it is empty, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
在上述技术方案的基础上, 所述哈希表存储在 SRAM或者 DRAM中。 在上述技术方案的基础上, 所述 TCAM表项存储在 TCAM存储器中。 与现有技术相比, 本发明的优点如下: ( 1 ) 本发明的 MAC地址硬件学习方法, 完全在交换芯片上实现, 不需要 依赖任何主控 CPU的协助, 学习速率比较高。 Based on the above technical solution, the hash table is stored in an SRAM or a DRAM. Based on the foregoing technical solution, the TCAM entry is stored in a TCAM memory. The advantages of the present invention over the prior art are as follows: (1) The MAC address hardware learning method of the present invention is completely implemented on a switch chip, and does not need to rely on the assistance of any host CPU, and the learning rate is relatively high.
( 2 )本发明在没有 MAC地址冲突的时候,使用哈希表来存储学习到的 MAC 地址, 哈希表硬件上用 SRAM或者 DRAM来实现, 容量和带宽上可以做得比较 大, 首选哈希表来存放地址表项, 能充分利用 AM大容量硬件资源的优势。 存 在 MAC地址冲突时,使用 TCAM表来缓存冲突的 MAC地址, TCAM表硬件上 采用 TCAM存储器来实现, 由于 TCAM硬件上是并行查找, 一次搜索即可定位 空闲表项, 而且 TCAM的表项个数就是实际能缓存的冲突的 MAC地址个数, 因此, 不仅能充分利用 TCAM快速并行查找的优势, 而且能实现冲突概率完全 可控, 此外, 由于不用哈希表来缓存冲突的 MAC地址, 因此占用的内存资源较 少。  (2) The present invention uses a hash table to store the learned MAC address when there is no MAC address conflict. The hash table hardware is implemented by SRAM or DRAM, and the capacity and bandwidth can be made larger, and the hash is preferred. Tables store address entries and take full advantage of AM's large-capacity hardware resources. When there is a MAC address conflict, the TCAM table is used to cache the conflicting MAC address. The TCAM table hardware is implemented by TCAM memory. Since the TCAM hardware is parallel search, the free entry can be located in one search, and the number of TCAM entries is It is the number of conflicting MAC addresses that can actually be cached. Therefore, not only can the advantages of TCAM fast parallel search be fully utilized, but also the collision probability can be fully controlled. In addition, since the hash table is not used to cache the conflicting MAC address, it occupies Less memory resources.
(3 ) 本发明在通用的可编程交换芯片上即可实现, 不需要专用硬件电路的 支持, 采用通用的算法, 应用十分灵活。  (3) The present invention can be implemented on a general-purpose programmable switching chip, does not require the support of a dedicated hardware circuit, and adopts a general-purpose algorithm, and the application is very flexible.
(4)本发明使用 TCAM表来缓存冲突的 MAC地址,能缓存的冲突的 MAC 地址总量为开辟的 TCAM总量减 1, 冲突概率可控, 能缓存的冲突的 MAC地址 的个数是确定不变的,不会随着 MAC地址样本的变化而变化,缓存冲突的 MAC 地址的能力有保障, 即使在冲突最恶劣的情况下, TCAM 表仍然能缓存几乎所 有的 MAC地址冲突。 附图说明  (4) The present invention uses the TCAM table to buffer the conflicting MAC address. The total number of conflicting MAC addresses that can be cached is less than the total amount of TCAMs opened, and the probability of collision is controllable. The number of conflicting MAC addresses that can be cached is determined. The constant, does not change with the change of the MAC address sample, the ability to cache the conflicting MAC address is guaranteed, even in the worst case of conflict, the TCAM table can still cache almost all MAC address conflicts. DRAWINGS
图 1是本发明实施例中表项初始化的流程图。  1 is a flow chart of initialization of an entry in an embodiment of the present invention.
图 2是本发明实施例中基于哈希表和 TCAM表的 MAC地址硬件学习方法 的流程图。  2 is a flow chart of a MAC address hardware learning method based on a hash table and a TCAM table in an embodiment of the present invention.
图 3 是本发明实施例中老化的流程图。 具体实施方式  3 is a flow chart of aging in an embodiment of the present invention. detailed description
下面结合附图及具体实施例对本发明作进一步的详细描述。  The present invention will be further described in detail below with reference to the drawings and specific embodiments.
TCAM是一种三态内容寻址存储器, TCAM中每个 bit数据有三种状态: 除 了普通的 "0"和 " 1 "之外, 还有一个 "don' t care" (即不用匹配该 bit)状态, 所以称之为 "三态"。 "三态"的功能通过掩码来实现, 即掩码为 0, 表示 "dont' t care"给定的键值; 掩码为 1, 表示需要精确匹配给定的键值。 TC AM的这种特 性使其既能完成精确匹配, 也能完成模糊匹配。 TCAM 的另一个特点就是 "并 行查找", 即给定一个键值, 则 TCAM会同时匹配所有的硬件表项, 并且返回地 址索引值最小的那一条表项索引。 TCAM is a three-state content-addressable memory. Each bit of data in the TCAM has three states: In addition to the normal "0" and "1", there is also a "don't care" (ie, there is no need to match the bit). State, so called "three states." The "three-state" function is implemented by a mask, that is, the mask is 0, indicating "dont' t care "given key value; a mask of 1, indicating that an exact key value needs to be matched exactly. This feature of TC AM allows it to perform both exact and fuzzy matching. Another feature of TCAM is that "Parallel lookup", that is, given a key value, the TCAM will match all hardware entries at the same time, and return the index of the entry with the smallest address index value.
本发明实施例采用 AM存放哈希表, 作为 MAC地址学习的主存储器, 结 合 TCAM存储器 "三态存储"和 "并行查找" 的特点, 来缓存冲突的 MAC地 址。 在功能划分上, 哈希表作为 MAC地址的主存储器, 而 TCAM表负责完成 缓存地址冲突的核心功能。 哈希表和 TCAM表互相配合共同完成 MAC地址学 习的功能,其实现上需要初始化、地址的学习和地址的老化三者的密切配合才能 实现。  In the embodiment of the present invention, the AM storage hash table is used as the main memory for MAC address learning, and the characteristics of the "three-state storage" and the "parallel search" of the TCAM memory are combined to cache the conflicting MAC address. In terms of function partitioning, the hash table acts as the main memory for the MAC address, and the TCAM table is responsible for the core functions of the cache address conflict. The hash table and the TCAM table cooperate with each other to complete the function of MAC address learning, and the implementation requires initialization, address learning, and address aging to achieve the three.
哈希表存储在 SRAM或者 DRAM中, TCAM表项存储在 TCAM存储器中。 参见表 1所示, 哈希表的数据结构包括虚拟转发实例 (Vsi)、 Mac地址、 表 项有效标志 (Valid) 和虚拟交换端口 (Vp)。  The hash table is stored in SRAM or DRAM, and the TCAM entry is stored in the TCAM memory. As shown in Table 1, the data structure of the hash table includes the virtual forwarding instance (Vsi), the Mac address, the table valid flag (Valid), and the virtual switch port (Vp).
表 1、 哈希表的数据结构定义表
Figure imgf000010_0001
参见表 2所示, TCAM表项的数据结构包括键值 (Key) 和数据 (Data), 键值 (Key) 包括虚拟转发实例 (Vsi)、 Mac地址和表项满标志 (FlagFull), 数 据 (Data) 包括表项有效标志 (Valid) 和虚拟交换端口 (Vp)。
Table 1. Data structure definition table of hash table
Figure imgf000010_0001
As shown in Table 2, the data structure of the TCAM entry includes the key value (Key) and the data (Data). The key value includes the virtual forwarding instance (Vsi), the Mac address, and the table entry full flag (FlagFull), and the data ( Data) includes the entry valid flag (Valid) and the virtual switch port (Vp).
表 2、 TCAM表项的数据结构定义表  Table 2. Data structure definition table of TCAM entries
Figure imgf000010_0002
参见图 1所示, 本发明实施例中表项初始化的流程如下:
Figure imgf000010_0002
Referring to FIG. 1, the process of initializing an entry in the embodiment of the present invention is as follows:
步骤 101、 判断初始化表项索引是否大于表项最大值, 如果是, 则转到步骤 102; 否则, 转到步骤 103;  Step 101: Determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, go to step 102; otherwise, go to step 103;
步骤 102、初始化表项索引范围超过表项最大值, 返回异常, 转到步骤 108; 步骤 103、 判断初始化表项索引值是否位于哈希表索引范围内, 如果是, 则 转到步骤 104; 否则, 转到步骤 105; Step 102, the index of the initialization entry exceeds the maximum value of the entry, returns an exception, and proceeds to step 108; Step 103, determining whether the initialization table entry index value is within the hash table index range, and if so, then proceeds to step 104; otherwise, proceeds to step 105;
步骤 104、 初始化哈希表, 直接用初始化索引值定位哈希表项, 并将表项内 容全部清 0, 转到步骤 108;  Step 104: Initialize the hash table, directly locate the hash table entry by using the initialization index value, and clear all the contents of the entry to 0, and go to step 108;
步骤 105、 判断初始化表项索引是否为 TCAM最后一项, 如果是, 则转到 步骤 106; 否则, 转到步骤 107;  Step 105: Determine whether the initialization entry index is the last item of the TCAM, and if yes, go to step 106; otherwise, go to step 107;
步骤 106、 初始化最后一个 TCAM表项, 键值中所有字段均初始化为 0, 掩 码为 0, 即该表项是一个 " catch all" (匹配任意键值) 的表项; 数据中的所有字 段均赋值为 0, 表示该表项为 TCAM最后一个表项, 不能用来缓存地址冲突, TCAM最后一个表项的作用是: (1 ) 当业务转发查找到该表项时, 可判断整个 TCAM表项中没有缓存该 MAC地址,因而需要继续搜索哈希表以指导业务转发; (2) 当 MAC地址学习搜索空闲表项时查找到该表项, 则表示 TCAM冲突缓存 已满,无法再缓存冲突的 MAC地址了; 因此实际能缓存的冲突总量是 TCAM表 项总数减 1, 转到步骤 108;  Step 106: Initialize the last TCAM entry, all fields in the key value are initialized to 0, and the mask is 0, that is, the entry is a "catch all" (match any key value) entry; all fields in the data If the entry is 0, it indicates that the entry is the last entry of the TCAM and cannot be used to cache address conflicts. The last entry of the TCAM is: (1) When the service forwards the entry, the entire TCAM table can be judged. The MAC address is not cached in the entry, so the hash table needs to be searched to guide the service forwarding. (2) When the MAC address learns to search for the idle entry, the TCAM conflict cache is full and the cache cannot be cached again. The MAC address is; therefore, the total amount of conflicts that can actually be cached is the total number of TCAM entries minus 1, go to step 108;
步骤 107、 将键值中表项满标志清 0, 掩码置 1 (表示当前表项初始状态为 空), 键值中其余字段清 0, 掩码清 0, 数据中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后一个表项,可以用来缓存冲突的 MAC地址,转到步骤 108; 步骤 108、 表项初始化的流程结束。  In step 107, the full value of the entry in the key value is cleared to 0, and the mask is set to 1 (indicating that the initial state of the current entry is empty), the remaining fields in the key value are cleared to 0, the mask is cleared to 0, and the valid entry of the entry in the data is set to 1. The remaining fields are cleared to 0, indicating that the entry is not the last entry, and can be used to cache the conflicting MAC address, and proceeds to step 108; Step 108, the process of initializing the entry ends.
参见图 2所示, 本发明实施例提供一种基于哈希表和 TCAM表的 MAC地 址硬件学习方法, 包括以下步骤:  Referring to FIG. 2, an embodiment of the present invention provides a MAC address hardware learning method based on a hash table and a TCAM table, including the following steps:
步骤 201、 以报文所属的虚拟转发实例号和源 MAC地址计算哈希值, 并以 哈希值为索引搜索哈希表;  Step 201: Calculate a hash value by using a virtual forwarding instance number and a source MAC address to which the packet belongs, and search the hash table by using a hash value index.
步骤 202、 组织搜索 TCAM表项的键值: 虚拟转发实例号为报文所属的虚 拟转发实例号; MAC地址为报文的源 MAC地址; 表项满标志置 1, 表示在已经 学习到的 TCAM表项中进行搜索;  Step 202: Search for the key value of the TCAM entry: The virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs; the MAC address is the source MAC address of the packet; and the table entry full flag is set to 1, indicating that the TCAM has been learned. Search in the table entry;
步骤 203、 判断 TCAM表项数据中有效标志是否置位, 如果置位, 则转到 步骤 204; 否则, 转到步骤 206;  Step 203: Determine whether the valid flag in the TCAM entry data is set, if set, go to step 204; otherwise, go to step 206;
步骤 204、 比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟交 换端口, 如果是, 则表项不需要更新, 转到步骤 215; 否则, 表示 TCAM表项 需要更新, 转到步骤 205; 步骤 205、 更新当前 TCAM表项数据中虚拟交换端口为报文实际接收虚拟 交换端口, 转到步骤 215; Step 204, comparing whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch port, if yes, the entry does not need to be updated, go to step 215; otherwise, the TCAM entry needs to be updated, go to step 205; Step 205, update the current TCAM entry data in the virtual switch port as the packet actually receives the virtual switch port, go to step 215;
步骤 206、判断哈希表中数据有效标志是否置位,如果置位,则转到步骤 208; 否则, 转到步骤 207;  Step 206, determining whether the data valid flag in the hash table is set, if set, go to step 208; otherwise, go to step 207;
步骤 207、 将报文源 MAC地址, 报文所属虚拟转发实例号和报文接收的虚 拟交换端口存储到当前哈希表项中, 表项有效标志置 1, 转到步骤 215;  Step 207: The source MAC address of the packet, the virtual forwarding instance number of the packet, and the virtual switching port received by the packet are stored in the current hash entry, and the valid entry of the entry is set to 1, and the process proceeds to step 215;
步骤 208、 比较哈希表中虚拟转发实例号和 MAC地址是否和报文所属的虚 拟转发实例号及源 MAC地址相匹配, 如果匹配, 则表示当前地址已经在哈希表 中学到过, 转到步骤 209; 否则, 转到步骤 211 ;  Step 208: Compare the virtual forwarding instance number and the MAC address in the hash table with the virtual forwarding instance number and the source MAC address to which the packet belongs. If the matching, the current address has been learned in the hash table, and then go to Step 209; otherwise, go to step 211;
步骤 209、 比较当前哈希表中虚拟交换端口是否等于报文实际接收虚拟交换 端口, 如果相等, 则哈希表项不需要更新, 转到步骤 215; 否则, 转到步骤 210; 步骤 210、更新当前哈希表项中的虚拟转发端口号为报文实际接收虚拟端口 号, 转到步骤 215;  Step 209: Compare whether the virtual switch port in the current hash table is equal to the packet actually receiving the virtual switch port. If they are equal, the hash table item does not need to be updated, go to step 215; otherwise, go to step 210; Step 210, update The virtual forwarding port number in the current hash entry is the actual virtual port number received by the packet, and the process proceeds to step 215.
步骤 211、 产生哈希冲突, 组织搜索 TCAM表项的键值以寻找空闲 TCAM 表项缓存冲突: 键值中虚拟转发实例号为 0, MAC地址为 0, 表项满标志为 0, 表示在空闲 TCAM表项中进行搜索;  Step 211: Generate a hash conflict, and organize the search for the key value of the TCAM entry to find the idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address is 0, and the entry full flag is 0, indicating that it is idle. Search in the TCAM entry;
步骤 212、 判断 TCAM数据中有效标志是否置位, 如果置位, 表示找到第 一个空闲表项, 转到步骤 214; 否则, 转到步骤 213;  Step 212, determining whether the valid flag in the TCAM data is set, if set, indicating that the first free entry is found, go to step 214; otherwise, go to step 213;
步骤 213、 TCAM存储器没有空闲表项可以缓存冲突, 放弃学习, 转到步骤 Step 213: The TCAM memory has no free entries to cache conflicts, abandon learning, and go to the step
215; 215;
步骤 214、将 MAC地址缓存到当前空闲 TCAM表项中: 键值的虚拟转发实 例号填写为报文所属虚拟转发实例号,掩码置 1; MAC地址填写为报文的源 MAC 地址, 掩码置 1 ; 表项满标志置 1, 掩码置 1 ; 数据中虚拟交换端口填写为报文 实际接收虚拟交换端口, 转到步骤 215;  Step 214: Cache the MAC address into the current idle TCAM entry: The virtual forwarding instance number of the key value is filled in as the virtual forwarding instance number of the packet, and the mask is set to 1; the MAC address is filled in as the source MAC address of the packet, and the mask is Set to 1; the entry full flag is set to 1, the mask is set to 1; the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, go to step 215;
步骤 215、 MAC地址硬件学习流程结束。  Step 215: The MAC address hardware learning process ends.
参见图 3所示, 本发明实施例中老化的流程如下:  Referring to FIG. 3, the process of aging in the embodiment of the present invention is as follows:
步骤 301、判断老化表项索引是否大于表项最大值,如果是,则转到步骤 302; 否则, 转到步骤 303;  Step 301: Determine whether the index of the aging entry is greater than the maximum value of the entry, if yes, go to step 302; otherwise, go to step 303;
步骤 302、初始化表项索引范围超过表项最大值, 返回异常, 转到步骤 308; 步骤 303、 判断老化表项索引值是否位于哈希表索引范围内, 如果是, 则转 到步骤 304; 否则, 转到步骤 305; Step 302: The index of the initialization entry exceeds the maximum value of the entry, and returns an exception. Go to step 308. Step 303: Determine whether the index value of the aging entry is in the index range of the hash table, and if yes, then Go to step 304; otherwise, go to step 305;
步骤 304、 老化哈希表, 直接用初始化索引值定位哈希表项, 并将表项内容 全部清 0, 转到步骤 308;  Step 304, aging the hash table, directly using the initialization index value to locate the hash table entry, and clear all the contents of the table entry, go to step 308;
步骤 305、 判断老化表项索引是否为 TCAM最后一项, 如果是, 则转到步 骤 306; 否则, 转到步骤 307;  Step 305: Determine whether the aging entry index is the last item of the TCAM, and if yes, go to step 306; otherwise, go to step 307;
步骤 306、 TCAM最后一项是一个 " catch all" (匹配任意键值) 的表项, 一旦初始化则不需要对其进行操作, 转到步骤 308;  Step 306, the last item of the TCAM is a "catch all" (match any key value) of the entry, once initialized does not need to operate on it, go to step 308;
步骤 307、 将键值中表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表项状态置为空, 数据中表项有效标志置 1, 其余字段清 0, 表示该表项不是 最后一个表项, 可以用来缓存冲突的 MAC地址, 转到步骤 308;  Step 307: Clear the key of the key in the key value to 0, the mask is set to 1, the other fields are cleared to 0, the mask is cleared to 0, the state of the entry is set to null, the valid flag of the entry in the data is set to 1, and the remaining fields are cleared. , indicating that the entry is not the last entry, can be used to cache the conflicting MAC address, go to step 308;
步骤 308、 MAC地址老化流程结束。  Step 308: The MAC address aging process ends.
本发明实施例还提供一种基于哈希表和 TCAM表的 MAC地址硬件学习系 统, 包括初始化单元、 搜索单元、 TCAM表项判断单元、 哈希表判断单元、 哈 希表比较单元、 哈希冲突处理单元和老化单元, 其中:  The embodiment of the invention further provides a MAC address hardware learning system based on a hash table and a TCAM table, including an initialization unit, a search unit, a TCAM entry determination unit, a hash table determination unit, a hash table comparison unit, and a hash collision. Processing unit and aging unit, wherein:
初始化单元, 用于: 判断初始化表项索引是否大于表项最大值, 如果是, 则 返回异常; 否则, 判断初始化表项索引值是否位于哈希表索引范围内, 如果是, 则初始化哈希表, 直接用初始化索引值定位哈希表项, 并将表项内容全部清 0; 否则, 判断初始化表项索引是否为 TCAM最后一项, 如果是, 则初始化最后一 个 TCAM表项, 键值中所有字段均初始化为 0, 掩码为 0, 数据中的所有字段均 赋值为 0,表示该表项为 TCAM最后一个表项;否则,将键值中表项满标志清 0, 掩码置 1, 表示当前表项初始状态为空, 键值中其余字段清 0, 掩码清 0, 数据 中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后一个表项, 初始化结 束;  An initialization unit, configured to: determine whether the index of the initialization entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the initialization entry is within the index range of the hash table, and if so, initialize the hash table Directly use the initialization index value to locate the hash table entry, and clear all the contents of the table entry; otherwise, determine whether the initialization entry index is the last item of the TCAM, and if so, initialize the last TCAM entry, all in the key value The fields are initialized to 0, the mask is 0, and all fields in the data are assigned a value of 0, indicating that the entry is the last entry of the TCAM; otherwise, the full value of the entry in the key value is cleared to 0, and the mask is set to 1, Indicates that the initial state of the current entry is empty, the other fields in the key value are cleared to 0, the mask is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the initialization ends;
搜索单元,用于:以报文所属的虚拟转发实例号和源 MAC地址计算哈希值, 并以哈希值为索引搜索哈希表, 哈希表存储在 SRAM或者 DRAM中; TCAM表 项存储在 TCAM存储器中, 组织搜索 TCAM表项的键值: 虚拟转发实例号为报 文所属的虚拟转发实例号; MAC地址为报文的源 MAC地址; 表项满标志置 1, 表示在已经学习到的 TCAM表项中进行搜索;  The search unit is configured to: calculate a hash value by using the virtual forwarding instance number and the source MAC address to which the packet belongs, and search the hash table by using a hash value index, and the hash table is stored in the SRAM or the DRAM; the TCAM entry is stored. In the TCAM memory, the organization searches for the key value of the TCAM entry: the virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs; the MAC address is the source MAC address of the packet; the table entry full flag is set to 1, indicating that it has learned Search in the TCAM entry;
TCAM表项判断单元, 用于: 判断 TCAM表项数据中有效标志是否置位, 如果置位, 则比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟交换 端口, 如果是, 则不更新表项; 否则, 更新当前 TCAM表项数据中虚拟交换端 口为报文实际接收虚拟交换端口; 如果没有置位, 产生哈希表判断触发信号, 并 发送到哈希表判断单元; The TCAM entry determining unit is configured to: determine whether the valid flag in the TCAM entry data is set, and if set, compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch. The port, if yes, does not update the entry; otherwise, the virtual switch port in the current TCAM entry data is updated to receive the virtual switch port for the packet; if not set, the hash table judgment trigger signal is generated and sent to the hash. Table judgment unit;
哈希表判断单元, 用于: 收到哈希表判断触发信号时, 判断哈希表中数据有 效标志是否置位, 如果没有置位, 将报文源 MAC地址、 报文所属虚拟转发实例 号和报文接收的虚拟交换端口存储到当前哈希表项中, 表项有效标志置 1 ; 如果 置位, 产生比较触发信号, 并发送到哈希表比较单元;  The hash table determining unit is configured to: when receiving the hash table determining the trigger signal, determine whether the data valid flag in the hash table is set, if not set, the source MAC address of the packet and the virtual forwarding instance number of the packet And the virtual switch port received by the packet is stored in the current hash table entry, and the entry valid flag is set to 1; if set, the comparison trigger signal is generated and sent to the hash table comparison unit;
哈希表比较单元, 用于: 收到比较触发信号时, 比较哈希表中虚拟转发实例 号和 MAC地址是否和报文所属的虚拟转发实例号及 MAC地址相匹配, 如果匹 配, 则表示当前地址已经在哈希表中学到过, 比较当前哈希表中虚拟交换端口是 否等于报文实际接收虚拟交换端口, 如果相等, 则结束学习; 否则, 更新当前哈 希表项中的虚拟转发端口号为报文实际接收虚拟端口号,结束学习;如果不匹配, 产生哈希冲突处理触发信号, 并发送到哈希冲突处理单元;  The hash table comparison unit is configured to: when the comparison trigger signal is received, compare whether the virtual forwarding instance number and the MAC address in the hash table match the virtual forwarding instance number and the MAC address to which the packet belongs, and if they match, the current The address has been learned in the hash table. It compares whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the learning is ended. Otherwise, the virtual forwarding port number in the current hash table entry is updated. Ending the learning by actually receiving the virtual port number for the packet; if not, generating a hash conflict processing trigger signal, and sending the hash conflict processing unit to the hash conflict processing unit;
哈希冲突处理单元, 用于: 收到哈希冲突处理触发信号时, 组织搜索 TCAM 表项的键值以寻找空闲 TCAM表项缓存冲突:键值中虚拟转发实例号为 0, MAC 地址为 0, 表项满标志为 0, 表示在空闲 TCAM表项中进行搜索; 再判断 TCAM 数据中有效标志是否置位, 如果置位, 表示找到第一个空闲表项, 将 MAC地址 缓存到当前空闲 TCAM表项中: 键值的虚拟转发实例号填写为报文所属虚拟转 发实例号, 掩码置 1, MAC地址填写为报文的源 MAC地址, 掩码置 1, 表项满 标志置 1, 掩码置 1, 数据中虚拟交换端口填写为报文实际接收虚拟交换端口, 结束学习; 如果没有置位, 表示 TCAM存储器没有空闲表项, 放弃学习;  The hash conflict processing unit is configured to: when receiving the hash conflict processing trigger signal, organize the search for the key value of the TCAM entry to find the idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, and the MAC address is 0. If the entry full flag is 0, it means searching in the idle TCAM entry; then determining whether the valid flag in the TCAM data is set, if set, indicating that the first free entry is found, and the MAC address is cached to the current idle TCAM. In the entry: The virtual forwarding instance number of the key is filled in as the virtual forwarding instance number of the packet, the mask is set to 1, the MAC address is filled in as the source MAC address of the packet, the mask is set to 1, and the entry full flag is set to 1. The code is set to 1, the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, and the learning is ended; if not set, it indicates that the TCAM memory has no free entry, and the learning is abandoned;
老化单元, 用于: 判断老化表项索引是否大于表项最大值, 如果是, 则返回 异常; 否则, 判断老化表项索引值是否位于哈希表索引范围内, 如果是, 则老化 哈希表, 直接用初始化索引值定位哈希表项, 并将表项内容全部清 0; 否则, 判 断老化表项索引是否为 TCAM最后一项, 如果是, 则表示 TCAM最后一项是一 个匹配任意键值的表项, 结束老化; 否则, 将键值中表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表项状态置为空, 数据中表项有效标志置 1, 其余 字段清 0, 表示该表项不是最后一个表项, 老化结束。  The aging unit is configured to: determine whether the index of the aging entry is greater than the maximum value of the entry, and if yes, return an exception; otherwise, determine whether the index value of the aging entry is in the index range of the hash table, and if yes, the aging hash table Directly use the initial index value to locate the hash table entry, and clear all the contents of the table entry; otherwise, determine whether the aging entry index is the last item of the TCAM, and if so, the last item of the TCAM is a match for any key value. If the entry is cleared, the mask is set to 0, the remaining fields are cleared to 0, the mask is cleared to 0, the entry status is set to null, and the entry in the data is valid. 1. The remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
本领域的技术人员可以对本发明实施例进行各种修改和变型,倘若这些修改 和变型属在本发明权利要求及其等同技术的范围之内,则这些修改和变型也在本 发明的保护范围之内。 A person skilled in the art can make various modifications and variations to the embodiments of the present invention, and if such modifications and variations are within the scope of the appended claims and their equivalents, Within the scope of protection of the invention.
说明书中未详细描述的内容为本领域技术人员公知的现有技术。  The contents not described in detail in the specification are prior art known to those skilled in the art.

Claims

权 利 要 求 书 Claims
1、 一种基于哈希表和 TCAM表的 MAC地址硬件学习方法, 其特征在于, 包括以下步骤: A MAC address hardware learning method based on a hash table and a TCAM table, characterized in that the method comprises the following steps:
51、 以报文所属的虚拟转发实例号和源 MAC地址计算哈希值, 并以哈希值 为索引搜索哈希表;  51. Calculate a hash value by using the virtual forwarding instance number and the source MAC address to which the packet belongs, and search the hash table by using the hash value as an index;
52、 组织搜索 TCAM表项的键值: 虚拟转发实例号为报文所属的虚拟转发 实例号; MAC地址为报文的源 MAC地址; 表项满标志置 1, 表示在已经学习到 的 TCAM表项中进行搜索;  52. Searching for the key value of the TCAM entry: The virtual forwarding instance number is the virtual forwarding instance number to which the packet belongs; the MAC address is the source MAC address of the packet; the table entry full flag is set to 1, indicating that the TCAM table has been learned. Search in the item;
53、 判断 TCAM表项数据中有效标志是否置位, 如果置位, 则转到 S4; 否 贝 1J, 转到 S6;  53. Determine whether the valid flag in the TCAM entry data is set, if set, go to S4; No Bay 1J, go to S6;
54、比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟交换端口, 如果是, 则表项不需要更新, 转到 S15; 否则, 表示 TCAM表项需要更新, 转 到 S5;  54. Compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving the virtual switch port. If yes, the entry does not need to be updated, and the process goes to S15; otherwise, the TCAM entry needs to be updated, and the process goes to S5;
55、 更新当前 TCAM表项数据中虚拟交换端口为报文实际接收虚拟交换端 口, 转到 S15;  55. Update the virtual switch port in the current TCAM entry data to actually receive the virtual switch port, and go to S15;
56、 判断哈希表中数据有效标志是否置位, 如果置位, 则转到 S8; 否则, 转到 S7;  56. Determine whether the data valid flag in the hash table is set, if set, go to S8; otherwise, go to S7;
57、将报文源 MAC地址、报文所属虚拟转发实例号和报文接收的虚拟交换 端口存储到当前哈希表项中, 表项有效标志置 1, 转到 S15;  57. The source MAC address of the packet, the virtual forwarding instance number of the packet, and the virtual switching port received by the packet are stored in the current hash entry, and the valid entry of the entry is set to 1, and the process proceeds to S15.
58、 比较哈希表中虚拟转发实例号和 MAC地址是否和报文所属的虚拟转发 实例号及源 MAC地址相匹配, 如果匹配, 则表示当前地址已经在哈希表中学到 过, 转到 S9; 否则, 转到 S11 ;  58. Compare the virtual forwarding instance number and the MAC address in the hash table with the virtual forwarding instance number and the source MAC address to which the packet belongs. If it matches, the current address has been learned in the hash table, and go to S9. Otherwise, go to S11;
59、 比较当前哈希表中虚拟交换端口是否等于报文实际接收虚拟交换端口, 如果相等, 则哈希表项不需要更新, 转到 S15; 否则, 转到 S10;  59. Compare whether the virtual switch port in the current hash table is equal to the actual virtual switch port received by the packet. If they are equal, the hash entry does not need to be updated, and the process goes to S15; otherwise, the process goes to S10;
510、 更新当前哈希表项中的虚拟转发端口号为报文实际接收虚拟端口号, 转到 S15;  510. Update the virtual forwarding port number in the current hash entry to the virtual port number actually received by the packet, and go to S15.
511、 产生哈希冲突, 组织搜索 TCAM表项的键值以寻找空闲 TCAM表项 缓存冲突: 键值中虚拟转发实例号为 0, MAC地址为 0, 表项满标志为 0, 表示 在空闲 TCAM表项中进行搜索; 512、判断 TCAM数据中有效标志是否置位, 如果置位, 表示找到第一个空 闲表项, 转到 S14; 否则, 转到 S13; 511. Generate a hash collision, and search for a key value of the TCAM entry to find an idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address is 0, and the entry full flag is 0, indicating that the idle TCAM is in the idle TCAM. Search in the table entry; 512, determining whether the valid flag in the TCAM data is set, if set, indicating that the first free entry is found, go to S14; otherwise, go to S13;
513、 TCAM存储器没有空闲表项, 放弃学习, 转到 S15;  513, TCAM memory does not have a free entry, give up learning, go to S15;
514、 将 MAC地址缓存到当前空闲 TCAM表项中: 键值的虚拟转发实例号 填写为报文所属虚拟转发实例号,掩码置 1 ; MAC地址填写为报文的源 MAC地 址, 掩码置 1 ; 表项满标志置 1, 掩码置 1 ; 数据中虚拟交换端口填写为报文实 际接收虚拟交换端口, 转到 S15; 514. Cache the MAC address into the current idle TCAM entry: The virtual forwarding instance number of the key value is filled in as the virtual forwarding instance number of the packet, and the mask is set to 1 ; the MAC address is filled in as the source MAC address of the packet, and the mask is set. 1; the entry full flag is set to 1, the mask is set to 1; the virtual switch port in the data is filled in as the packet actually receives the virtual switch port, go to S15;
S 15、 MAC地址硬件学习流程结束。  S 15, MAC address hardware learning process ends.
2、如权利要求 1所述的基于哈希表和 TCAM表的 MAC地址硬件学习方法, 其特征在于: 步骤 S1之前还包括表项初始化的步骤: 判断初始化表项索引是否 大于表项最大值, 如果是, 则返回异常; 否则, 判断初始化表项索引值是否位于 哈希表索引范围内, 如果是, 则初始化哈希表, 直接用初始化索引值定位哈希表 项, 并将表项内容全部清 0; 否则, 判断初始化表项索引是否为 TCAM最后一 项, 如果是, 则初始化最后一个 TCAM表项, 键值中所有字段均初始化为 0, 掩码为 0, 数据中的所有字段均赋值为 0, 表示该表项为 TCAM最后一个表项; 否则, 将键值中表项满标志清 0, 掩码置 1, 表示当前表项初始状态为空, 键值 中其余字段清 0, 掩码清 0, 数据中表项有效标志置 1, 其余字段清 0, 表示该表 项不是最后一个表项, 初始化结束。  The method for learning the MAC address hardware based on the hash table and the TCAM table according to claim 1, wherein: step S1 further comprises the step of initializing the entry: determining whether the index of the initialization entry is greater than the maximum value of the entry. If yes, an exception is returned; otherwise, it is determined whether the index value of the initialization entry is within the index range of the hash table, and if so, the hash table is initialized, the hash table entry is directly located with the initialization index value, and the contents of the entry are all Clear 0; otherwise, determine whether the index of the initialization entry is the last item of TCAM. If yes, initialize the last TCAM entry. All fields in the key value are initialized to 0, the mask is 0, and all fields in the data are assigned. If it is 0, it indicates that the entry is the last entry of the TCAM; otherwise, the full value of the entry in the key value is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, and the remaining fields in the key are cleared to 0. The code is cleared to 0, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the initialization ends.
3、如权利要求 1所述的基于哈希表和 TCAM表的 MAC地址硬件学习方法, 其特征在于: 步骤 S15之后还包括老化的步骤:判断老化表项索引是否大于表项 最大值, 如果是, 则返回异常; 否则, 判断老化表项索引值是否位于哈希表索引 范围内, 如果是, 则老化哈希表, 直接用初始化索引值定位哈希表项, 并将表项 内容全部清 0; 否则, 判断老化表项索引是否为 TCAM最后一项, 如果是, 则 表示 TCAM最后一项是一个匹配任意键值的表项, 结束老化; 否则, 将键值中 表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表项状态置为空, 数据 中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后一个表项, 老化结束。  The method for learning the MAC address hardware based on the hash table and the TCAM table according to claim 1, wherein: step S15 further comprises the step of aging: determining whether the index of the aging entry is greater than the maximum value of the entry, if The exception is returned. Otherwise, it is determined whether the index value of the aging entry is in the index range of the hash table. If yes, the aging hash table is used to directly locate the hash table with the initial index value, and all the contents of the table are cleared. Otherwise, it is determined whether the index of the aging entry is the last item of the TCAM. If yes, it means that the last item of the TCAM is an entry matching any key value, and the aging is ended; otherwise, the full flag of the key in the key value is cleared to 0. The mask is set to 1, the other fields are cleared to 0, the mask is cleared to 0, the status of the entry is set to null, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
4、 如权利要求 1至 3中任一项所述的基于哈希表和 TCAM表的 MAC地址 硬件学习方法, 其特征在于: 所述哈希表存储在 SRAM或者 DRAM中。  The MAC address hardware learning method based on the hash table and the TCAM table according to any one of claims 1 to 3, characterized in that the hash table is stored in an SRAM or a DRAM.
5、 如权利要求 1至 3中任一项所述的基于哈希表和 TCAM表的 MAC地址 硬件学习方法, 其特征在于: 所述 TCAM表项存储在 TCAM存储器中。 6、 一种基于哈希表和 TCAM表的 MAC地址硬件学习系统, 其特征在于, 包括搜索单元、 TCAM 表项判断单元、 哈希表判断单元、 哈希表比较单元和哈 希冲突处理单元, 其中: The method for learning a MAC address hardware based on a hash table and a TCAM table according to any one of claims 1 to 3, wherein: the TCAM entry is stored in a TCAM memory. 6. A MAC address hardware learning system based on a hash table and a TCAM table, comprising: a search unit, a TCAM entry determination unit, a hash table determination unit, a hash table comparison unit, and a hash collision processing unit, among them:
所述搜索单元, 用于: 以报文所属的虚拟转发实例号和源 MAC地址计算哈 希值, 并以哈希值为索引搜索哈希表; 组织搜索 TCAM表项的键值: 虚拟转发 实例号为报文所属的虚拟转发实例号; MAC地址为报文的源 MAC地址; 表项 满标志置 1, 表示在已经学习到的 TCAM表项中进行搜索;  The searching unit is configured to: calculate a hash value by using a virtual forwarding instance number and a source MAC address to which the packet belongs, and search the hash table by using a hash value; organize the search for the key value of the TCAM entry: virtual forwarding instance The number is the virtual forwarding instance number to which the packet belongs. The MAC address is the source MAC address of the packet. If the entry full flag is set to 1, the search is performed in the learned TCAM entry.
所述 TCAM表项判断单元, 用于: 判断 TCAM表项数据中有效标志是否置 位, 如果置位, 则比较 TCAM表项数据中虚拟交换端口是否等于报文接收虚拟 交换端口, 如果是, 则不更新表项; 否则, 更新当前 TCAM表项数据中虚拟交 换端口为报文实际接收虚拟交换端口;如果没有置位,产生哈希表判断触发信号, 并发送到哈希表判断单元;  The TCAM entry determining unit is configured to: determine whether a valid flag in the TCAM entry data is set, and if set, compare whether the virtual switch port in the TCAM entry data is equal to the packet receiving virtual switch port, and if yes, The table entry is not updated; otherwise, the virtual switch port in the current TCAM entry data is updated to actually receive the virtual switch port; if not set, the hash table judgment trigger signal is generated and sent to the hash table judgment unit;
所述哈希表判断单元, 用于: 收到哈希表判断触发信号时, 判断哈希表中数 据有效标志是否置位, 如果没有置位, 将报文源 MAC地址、 报文所属虚拟转发 实例号和报文接收的虚拟交换端口存储到当前哈希表项中, 表项有效标志置 1 ; 如果置位, 产生比较触发信号, 并发送到哈希表比较单元;  The hash table determining unit is configured to: when receiving the hash table determining the trigger signal, determine whether the data valid flag in the hash table is set, if not set, the source MAC address of the packet and the virtual forwarding of the packet The virtual switch port received by the instance number and the packet is stored in the current hash entry, and the valid entry of the entry is set to 1. If set, the comparison trigger signal is generated and sent to the hash table comparison unit.
所述哈希表比较单元, 用于: 收到比较触发信号时, 比较哈希表中虚拟转发 实例号和 MAC地址是否和报文所属的虚拟转发实例号及 MAC地址相匹配, 如 果匹配, 则表示当前地址已经在哈希表中学到过, 比较当前哈希表中虚拟交换端 口是否等于报文实际接收虚拟交换端口, 如果相等, 则结束学习; 否则, 更新当 前哈希表项中的虚拟转发端口号为报文实际接收虚拟端口号, 结束学习; 如果不 匹配, 产生哈希冲突处理触发信号, 并发送到哈希冲突处理单元;  The hash table comparison unit is configured to: when receiving the comparison trigger signal, compare whether the virtual forwarding instance number and the MAC address in the hash table match the virtual forwarding instance number and the MAC address to which the packet belongs, and if yes, Indicates that the current address has been learned in the hash table. The virtual switch port in the current hash table is equal to whether the packet actually receives the virtual switch port. If they are equal, the learning is ended. Otherwise, the virtual forwarding in the current hash table is updated. The port number is the packet actually receiving the virtual port number, and the learning is ended; if not, the hash conflict processing trigger signal is generated and sent to the hash conflict processing unit;
所述哈希冲突处理单元, 用于: 收到哈希冲突处理触发信号时, 组织搜索 TCAM表项的键值以寻找空闲 TCAM表项缓存冲突: 键值中虚拟转发实例号为 0, MAC地址为 0, 表项满标志为 0, 表示在空闲 TCAM表项中进行搜索; 再判 断 TCAM数据中有效标志是否置位, 如果置位, 表示找到第一个空闲表项, 将 MAC地址缓存到当前空闲 TCAM表项中:键值的虚拟转发实例号填写为报文所 属虚拟转发实例号,掩码置 1, MAC地址填写为报文的源 MAC地址,掩码置 1, 表项满标志置 1, 掩码置 1, 数据中虚拟交换端口填写为报文实际接收虚拟交换 端口, 结束学习; 如果没有置位, 表示 TCAM存储器没有空闲表项, 放弃学习。 7、如权利要求 6所述的基于哈希表和 TCAM表的 MAC地址硬件学习系统, 其特征在于, 还包括初始化单元, 用于: 判断初始化表项索引是否大于表项最大 值, 如果是, 则返回异常; 否则, 判断初始化表项索引值是否位于哈希表索引范 围内, 如果是, 则初始化哈希表, 直接用初始化索引值定位哈希表项, 并将表项 内容全部清 0; 否则, 判断初始化表项索引是否为 TCAM最后一项, 如果是, 则初始化最后一个 TCAM表项, 键值中所有字段均初始化为 0, 掩码为 0, 数据 中的所有字段均赋值为 0, 表示该表项为 TCAM最后一个表项; 否则, 将键值 中表项满标志清 0, 掩码置 1, 表示当前表项初始状态为空, 键值中其余字段清 0, 掩码清 0, 数据中表项有效标志置 1, 其余字段清 0, 表示该表项不是最后一 个表项, 初始化结束。 The hash conflict processing unit is configured to: when receiving the hash conflict processing trigger signal, organize to search for a key value of the TCAM entry to find an idle TCAM entry cache conflict: the virtual forwarding instance number in the key value is 0, the MAC address 0, the entry full flag is 0, indicating that the search is in the idle TCAM entry; then it is determined whether the valid flag in the TCAM data is set, if set, the first free entry is found, and the MAC address is cached to the current In the idle TCAM entry, the virtual forwarding instance number of the key is filled in as the virtual forwarding instance number of the packet, the mask is set to 1, the MAC address is filled in as the source MAC address of the packet, the mask is set to 1, and the entry full flag is set to 1. The mask is set to 1. The virtual switch port in the data is filled in as the packet actually receives the virtual switch port, and the learning is ended. If it is not set, it indicates that the TCAM memory has no free entry, and the learning is abandoned. The device for learning a MAC address based on a hash table and a TCAM table according to claim 6, further comprising: an initializing unit, configured to: determine whether an index of the initialization entry is greater than a maximum value of the entry, and if so, Return an exception; otherwise, determine whether the index value of the initialization table entry is within the index range of the hash table, and if so, initialize the hash table, directly locate the hash table entry with the initialization index value, and clear all the contents of the table entry; Otherwise, it is determined whether the index of the initialization entry is the last item of the TCAM, and if so, the last TCAM entry is initialized, all fields in the key value are initialized to 0, the mask is 0, and all fields in the data are assigned a value of 0. Indicates that the entry is the last entry of the TCAM; otherwise, the full value of the entry in the key value is cleared to 0, and the mask is set to 1, indicating that the initial state of the current entry is empty, and the remaining fields in the key are cleared to 0, and the mask is cleared. The valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the initialization ends.
8、如权利要求 6所述的基于哈希表和 TCAM表的 MAC地址硬件学习系统, 其特征在于, 还包括老化单元, 用于: 判断老化表项索引是否大于表项最大值, 如果是, 则返回异常; 否则, 判断老化表项索引值是否位于哈希表索引范围内, 如果是, 则老化哈希表, 直接用初始化索引值定位哈希表项, 并将表项内容全部 清 0; 否则, 判断老化表项索引是否为 TCAM最后一项, 如果是, 则表示 TCAM 最后一项是一个匹配任意键值的表项, 结束老化; 否则, 将键值中表项满标志清 0, 掩码置 1, 其余字段清 0, 掩码清 0, 将表项状态置为空, 数据中表项有效标 志置 1, 其余字段清 0, 表示该表项不是最后一个表项, 老化结束。  The device for learning a MAC address based on a hash table and a TCAM table according to claim 6, further comprising: an aging unit, configured to: determine whether an index of the aging entry is greater than a maximum value of the entry, and if so, The exception is returned. Otherwise, it is determined whether the index value of the aging entry is in the index range of the hash table. If yes, the hash table is aged, and the hash table entry is directly located by using the initialization index value, and all the contents of the entry are cleared to 0. Otherwise, it is determined whether the index of the aging entry is the last item of the TCAM. If yes, it indicates that the last item of the TCAM is an entry that matches any key value, and the aging is ended; otherwise, the full value of the entry in the key value is cleared to 0. The code is set to 1, the other fields are cleared to 0, the mask is cleared to 0, the status of the entry is set to null, the valid entry of the entry in the data is set to 1, and the remaining fields are cleared to 0, indicating that the entry is not the last entry, and the aging ends.
9、 如权利要求 6至 8中任一项所述的基于哈希表和 TCAM表的 MAC地址 硬件学习系统, 其特征在于: 所述哈希表存储在 SRAM或者 DRAM中。  The MAC address hardware learning system based on the hash table and the TCAM table according to any one of claims 6 to 8, wherein the hash table is stored in an SRAM or a DRAM.
10、 如权利要求 6至 8中任一项所述的基于哈希表和 TCAM表的 MAC地 址硬件学习系统, 其特征在于: 所述 TCAM表项存储在 TCAM存储器中。  The MAC address hardware learning system based on the hash table and the TCAM table according to any one of claims 6 to 8, wherein the TCAM entry is stored in the TCAM memory.
PCT/CN2013/080000 2013-02-21 2013-07-24 Mac address hardware learning method and system based on hash table and tcam table WO2014127605A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310055657.3A CN103117931B (en) 2013-02-21 2013-02-21 Media access control (MAC) address hardware learning method and system based on hash table and ternary content addressable memory (TCAM) table
CN201310055657.3 2013-02-21

Publications (1)

Publication Number Publication Date
WO2014127605A1 true WO2014127605A1 (en) 2014-08-28

Family

ID=48416209

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/080000 WO2014127605A1 (en) 2013-02-21 2013-07-24 Mac address hardware learning method and system based on hash table and tcam table

Country Status (4)

Country Link
CN (1) CN103117931B (en)
CL (1) CL2015000917A1 (en)
MY (1) MY170382A (en)
WO (1) WO2014127605A1 (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112118186A (en) * 2020-08-28 2020-12-22 深圳市风云实业有限公司 Exchange chip routing table entry storage method, forwarding method and configuration method
CN112181309A (en) * 2020-10-14 2021-01-05 上海德拓信息技术股份有限公司 Online capacity expansion method for mass object storage
CN112269784A (en) * 2020-10-28 2021-01-26 中科驭数(北京)科技有限公司 Hash table structure based on hardware realization and inserting, inquiring and deleting method
CN112866115A (en) * 2020-12-31 2021-05-28 杭州迪普科技股份有限公司 Method, device, electronic equipment and storage medium for realizing transparent serial connection
CN113489649A (en) * 2021-06-29 2021-10-08 新华三信息安全技术有限公司 Table entry storage method and device
CN113709110A (en) * 2021-07-27 2021-11-26 深圳市风云实业有限公司 Software and hardware combined intrusion detection system and method
CN113726661A (en) * 2021-08-27 2021-11-30 西安微电子技术研究所 High-performance low-power-consumption router hash device and control method thereof
CN113765806A (en) * 2021-09-02 2021-12-07 烽火通信科技股份有限公司 MAC address learning method, device, equipment and readable storage medium
CN113904987A (en) * 2021-10-29 2022-01-07 西安微电子技术研究所 MAC address routing management controller, system and control method
CN114268585A (en) * 2019-11-07 2022-04-01 苏州盛科通信股份有限公司 TCAM-based three-layer route forwarding judgment method
CN115297059A (en) * 2022-07-18 2022-11-04 浙江大学 P4-based transport layer load balancing system
WO2023024799A1 (en) * 2021-08-24 2023-03-02 苏州盛科通信股份有限公司 Packet forwarding method, network forwarding device and computer storage medium
CN117472838A (en) * 2023-12-28 2024-01-30 苏州元脑智能科技有限公司 High-speed serial computer expansion bus equipment identification method, device and related equipment

Families Citing this family (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103117931B (en) * 2013-02-21 2015-07-01 烽火通信科技股份有限公司 Media access control (MAC) address hardware learning method and system based on hash table and ternary content addressable memory (TCAM) table
CN104239337B (en) * 2013-06-19 2019-03-26 中兴通讯股份有限公司 Processing method and processing device of tabling look-up based on TCAM
CN103678553A (en) * 2013-12-06 2014-03-26 上海寰创通信科技股份有限公司 Wireless terminal database establishing method based on shared memory design
CN103731355B (en) * 2013-12-31 2017-01-25 迈普通信技术股份有限公司 Method and system for avoiding Hash collision during MAC address learning
CN105812264B (en) * 2016-03-15 2019-04-19 西安电子科技大学 The MAC address learning of multidiameter delay and the device and method of address search
CN107770076B (en) * 2016-08-23 2020-12-04 中兴通讯股份有限公司 Hash collision processing method and device and switching equipment
CN107332774B (en) * 2017-06-09 2019-12-03 烽火通信科技股份有限公司 A kind of method that MAC address learning is carried out based on software-hardware synergism in VPLS
CN108632148B (en) * 2017-12-29 2020-06-16 西安电子科技大学 Device and method for learning MAC address based on pre-reading mode
CN108307001B (en) * 2018-04-28 2021-07-27 深圳市风云实业有限公司 MAC address aging method and device and electronic equipment
CN109582598B (en) * 2018-12-13 2023-05-02 武汉中元华电软件有限公司 Preprocessing method for realizing efficient hash table searching based on external storage
CN112087389B (en) * 2019-06-14 2023-01-24 深圳市中兴微电子技术有限公司 Message matching table look-up method, system, storage medium and terminal
CN110674138B (en) * 2019-09-23 2024-03-08 苏州雄立科技有限公司 Message searching method and device
CN112003792B (en) * 2020-07-23 2022-04-15 烽火通信科技股份有限公司 Software and hardware cooperative message acceleration method and device
CN112328593B (en) * 2020-10-21 2023-01-31 烽火通信科技股份有限公司 Method, equipment and system for carrying out batch configuration on address learning table
CN112637072B (en) * 2020-12-23 2022-08-02 北京时代民芯科技有限公司 Fast parallel circuit and method for exchanging chip address storage and search
CN112667867B (en) * 2020-12-31 2022-05-10 北京卓讯科信技术有限公司 Matching conflict checking method and equipment based on TCAM (ternary content addressable memory) feature code
CN113779320B (en) * 2021-08-18 2024-02-27 北京计算机技术及应用研究所 Method for solving table entry storage address conflict
CN114253979B (en) * 2021-12-23 2023-10-03 北京百度网讯科技有限公司 Message processing method and device and electronic equipment
CN115065662A (en) * 2022-06-13 2022-09-16 上海亿家芯集成电路设计有限公司 Method and system for processing MAC address hash collision

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1538663A (en) * 2003-04-16 2004-10-20 华为技术有限公司 Method of finding route table item using ltsh chain table
CN1996952A (en) * 2006-12-18 2007-07-11 杭州华为三康技术有限公司 Searching method for TCAM route table and searching device for TCAM route table
CN101841473A (en) * 2010-04-09 2010-09-22 北京星网锐捷网络技术有限公司 Method and apparatus for updating MAC (Media Access Control) address table
CN103117931A (en) * 2013-02-21 2013-05-22 烽火通信科技股份有限公司 Media access control (MAC) address hardware learning method and system based on hash table and ternary content addressable memory (TCAM) table

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7941559B2 (en) * 2002-04-23 2011-05-10 Tellabs Bedford, Inc. Media access control address translation for a fiber to the home system
CN100574281C (en) * 2007-06-22 2009-12-23 中兴通讯股份有限公司 A kind of management method of switch routing table
CN101247337B (en) * 2008-02-18 2012-11-21 华为技术有限公司 Packet forwarding method and equipment
EP2515487B1 (en) * 2010-01-26 2019-01-23 Huawei Technologies Co., Ltd. Method and device for storing and searching keyword
CN102880724A (en) * 2012-10-23 2013-01-16 盛科网络(苏州)有限公司 Method and system for processing Hash collision

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1538663A (en) * 2003-04-16 2004-10-20 华为技术有限公司 Method of finding route table item using ltsh chain table
CN1996952A (en) * 2006-12-18 2007-07-11 杭州华为三康技术有限公司 Searching method for TCAM route table and searching device for TCAM route table
CN101841473A (en) * 2010-04-09 2010-09-22 北京星网锐捷网络技术有限公司 Method and apparatus for updating MAC (Media Access Control) address table
CN103117931A (en) * 2013-02-21 2013-05-22 烽火通信科技股份有限公司 Media access control (MAC) address hardware learning method and system based on hash table and ternary content addressable memory (TCAM) table

Cited By (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114268585A (en) * 2019-11-07 2022-04-01 苏州盛科通信股份有限公司 TCAM-based three-layer route forwarding judgment method
CN114268585B (en) * 2019-11-07 2024-01-23 苏州盛科通信股份有限公司 Three-layer route forwarding judging method based on TCAM
CN112118186A (en) * 2020-08-28 2020-12-22 深圳市风云实业有限公司 Exchange chip routing table entry storage method, forwarding method and configuration method
CN112181309A (en) * 2020-10-14 2021-01-05 上海德拓信息技术股份有限公司 Online capacity expansion method for mass object storage
CN112269784A (en) * 2020-10-28 2021-01-26 中科驭数(北京)科技有限公司 Hash table structure based on hardware realization and inserting, inquiring and deleting method
CN112866115A (en) * 2020-12-31 2021-05-28 杭州迪普科技股份有限公司 Method, device, electronic equipment and storage medium for realizing transparent serial connection
CN112866115B (en) * 2020-12-31 2023-04-07 杭州迪普科技股份有限公司 Method, device, electronic equipment and storage medium for realizing transparent serial connection
CN113489649A (en) * 2021-06-29 2021-10-08 新华三信息安全技术有限公司 Table entry storage method and device
CN113489649B (en) * 2021-06-29 2022-07-22 新华三信息安全技术有限公司 Table entry storage method and device
CN113709110A (en) * 2021-07-27 2021-11-26 深圳市风云实业有限公司 Software and hardware combined intrusion detection system and method
CN113709110B (en) * 2021-07-27 2023-07-21 深圳市风云实业有限公司 Intrusion detection system and method combining soft and hard
WO2023024799A1 (en) * 2021-08-24 2023-03-02 苏州盛科通信股份有限公司 Packet forwarding method, network forwarding device and computer storage medium
CN113726661B (en) * 2021-08-27 2022-10-18 西安微电子技术研究所 High-performance low-power-consumption router hash device and control method thereof
CN113726661A (en) * 2021-08-27 2021-11-30 西安微电子技术研究所 High-performance low-power-consumption router hash device and control method thereof
CN113765806A (en) * 2021-09-02 2021-12-07 烽火通信科技股份有限公司 MAC address learning method, device, equipment and readable storage medium
CN113904987A (en) * 2021-10-29 2022-01-07 西安微电子技术研究所 MAC address routing management controller, system and control method
CN115297059A (en) * 2022-07-18 2022-11-04 浙江大学 P4-based transport layer load balancing system
CN115297059B (en) * 2022-07-18 2023-11-28 浙江大学 Transport layer load balancing system based on P4
CN117472838A (en) * 2023-12-28 2024-01-30 苏州元脑智能科技有限公司 High-speed serial computer expansion bus equipment identification method, device and related equipment
CN117472838B (en) * 2023-12-28 2024-03-15 苏州元脑智能科技有限公司 High-speed serial computer expansion bus equipment identification method, device and related equipment

Also Published As

Publication number Publication date
CN103117931B (en) 2015-07-01
CN103117931A (en) 2013-05-22
MY170382A (en) 2019-07-27
CL2015000917A1 (en) 2015-07-17

Similar Documents

Publication Publication Date Title
WO2014127605A1 (en) Mac address hardware learning method and system based on hash table and tcam table
US11102120B2 (en) Storing keys with variable sizes in a multi-bank database
US9871728B2 (en) Exact match hash lookup databases in network switch devices
US10389633B2 (en) Hash-based address matching
US7760720B2 (en) Translating native medium access control (MAC) addresses to hierarchical MAC addresses and their use
US9385957B1 (en) Flow key lookup involving multiple simultaneous cam operations to identify hash values in a hash bucket
US9569561B2 (en) Label masked addressable memory
KR100705593B1 (en) Apparatus and method for managing ternary content addressable memory
JP5518135B2 (en) Extensible multicast forwarding method and apparatus for data center
US20150131666A1 (en) Apparatus and method for transmitting packet
US20200136971A1 (en) Hash-table lookup with controlled latency
US11362948B2 (en) Exact match and ternary content addressable memory (TCAM) hybrid lookup for network device
IL182820A (en) Double-hash lookup mechanism for searching addresses in a network device
US10397116B1 (en) Access control based on range-matching
CN111937360B (en) Longest prefix matching
US10547547B1 (en) Uniform route distribution for a forwarding table
US7403526B1 (en) Partitioning and filtering a search space of particular use for determining a longest prefix match thereon
WO2008101423A1 (en) System and method for bridge connection
EP3742307A1 (en) Managing network traffic flows
US8503442B2 (en) Transmission information transfer apparatus and method thereof
US20170237691A1 (en) Apparatus and method for supporting multiple virtual switch instances on a network switch
KR100596385B1 (en) Forwarding entry processing method for virtual local area network support router

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13875788

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13875788

Country of ref document: EP

Kind code of ref document: A1