WO2022206397A1 - Buffering method and integrated circuit - Google Patents

Buffering method and integrated circuit Download PDF

Info

Publication number
WO2022206397A1
WO2022206397A1 PCT/CN2022/081320 CN2022081320W WO2022206397A1 WO 2022206397 A1 WO2022206397 A1 WO 2022206397A1 CN 2022081320 W CN2022081320 W CN 2022081320W WO 2022206397 A1 WO2022206397 A1 WO 2022206397A1
Authority
WO
WIPO (PCT)
Prior art keywords
prefix
routing
node
length
address
Prior art date
Application number
PCT/CN2022/081320
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 WO2022206397A1 publication Critical patent/WO2022206397A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/24Multipath
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/742Route cache; Operation thereof
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • H04L45/748Address table lookup; Address filtering using longest matching prefix
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5007Internet protocol [IP] addresses

Abstract

Provided in the present application are a buffering method and an integrated circuit, which can avoid a false hit. The buffering method comprises: acquiring a first packet, wherein the first packet comprises a destination internet protocol (IP) address; searching a buffer for a routing prefix that matches the destination IP address; in response to the fact that the routing prefix is not stored in the buffer, searching, according to the destination IP address, for a tree structure corresponding to a routing table, and determining a prefix node that matches the destination IP address; in response to the fact that the prefix node is not a leaf node, a processor determining a first prefix match length, wherein the first prefix match length is equal to the length between a root node and a tail node of the tree structure; determining a first routing prefix according to the first prefix match length and the destination IP address; and triggering the buffer to store a first correspondence, wherein the first correspondence is a correspondence between the first routing prefix and routing information that corresponds to the prefix node.

Description

一种缓存方法及集成电路A cache method and integrated circuit
本申请要求于2021年4月2日提交的申请号为202110361730.4、申请名称为“一种缓存方法及集成电路”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202110361730.4 and the application title "A Cache Method and Integrated Circuit" filed on April 2, 2021, the entire contents of which are incorporated into this application by reference.
技术领域technical field
本申请涉及通信技术领域,尤其涉及一种缓存方法及集成电路。The present application relates to the field of communication technologies, and in particular, to a caching method and an integrated circuit.
背景技术Background technique
路由器或交换机等网络设备在转发报文时,可以获取报文中携带的目的互联网协议(Internet Protocol,IP)地址,并从路由表中查找与该目的IP地址对应的路由信息,以便根据查找到的路由信息转发报文。路由表为记载路由前缀与路由信息的表项,预先存储在网络设备中。路由前缀用于确定与目的IP地址相匹配的路由信息,例如可以是IP地址的前n位,n为路由前缀的长度。路由信息可以是网络接口的标识,表示网络设备需要通过哪个网络接口转发报文。When forwarding packets, network devices such as routers or switches can obtain the destination Internet Protocol (Internet Protocol, IP) address carried in the packet, and look up the routing information corresponding to the destination IP address from the routing table. routing information to forward packets. The routing table is an entry that records routing prefixes and routing information, and is pre-stored in the network device. The routing prefix is used to determine routing information matching the destination IP address, for example, it can be the first n bits of the IP address, and n is the length of the routing prefix. The routing information may be an identifier of a network interface, indicating the network interface through which the network device needs to forward the packet.
在查找路由表时,判断目的IP地址与路由前缀是否匹配。例如,假设某个路由前缀的长度为m,且目的IP地址的前m位与该路由前缀一致,可以认为该目的IP地址与该路由前缀相匹配,对应的路由信息即为该路由前缀对应的路由信息。当目的IP地址同时与两个或两个以上的路由前缀相匹配时,可以根据最长前缀匹配(Longest Prefix Match,LPM)原则确定路由前缀。即,可以将与目的IP地址相匹配的多个路由前缀中长度最长的路由前缀的路由信息作为目的IP地址对应的路由信息。When looking up the routing table, determine whether the destination IP address matches the routing prefix. For example, assuming that the length of a routing prefix is m, and the first m bits of the destination IP address are consistent with the routing prefix, it can be considered that the destination IP address matches the routing prefix, and the corresponding routing information is the routing prefix. routing information. When the destination IP address matches two or more routing prefixes at the same time, the routing prefix can be determined according to the Longest Prefix Match (LPM) principle. That is, the routing information of the routing prefix with the longest length among the multiple routing prefixes matching the destination IP address may be used as the routing information corresponding to the destination IP address.
由于查找路由表需要比较路由前缀与目的IP地址是否匹配,网络设备需要查找路由表。显然,调用路由表的速度越快,网络设备转发报文的速度也就越快。目前,为了提高网络设备调用路由表的速度,可以将部分路由前缀和路由信息的对应关系存储在缓存中。但是这种方法往往存在虚假命中的情况。Since looking up the routing table needs to compare whether the routing prefix matches the destination IP address, the network device needs to look up the routing table. Obviously, the faster the routing table is called, the faster the network device can forward packets. At present, in order to improve the speed at which the network device calls the routing table, the corresponding relationship between some routing prefixes and routing information may be stored in the cache. But this method often suffers from false hits.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种缓存方法及集成电路,通过在缓存中记录长度大于路由表中与目的IP地址的第一路由前缀与路由信息之间的对应关系,避免了虚假命中的发生。Embodiments of the present application provide a caching method and an integrated circuit, which avoid false hits by recording the correspondence between the first routing prefix and routing information whose length is greater than that in the routing table and the destination IP address.
第一方面,本申请实施例提供了一种缓存方法,该方法可以应用于网络设备中的处理器。在执行缓存方法时,处理器可以先获取第一报文,并确定第一报文中携带的目的IP地址。接着,处理器可以从缓存中查找与该目的IP地址相匹配的路由前缀。如果缓存中没有存储与该目的IP地址相匹配的路由前缀,处理器可以根据目的IP地址从其他存储器中查找路由表对应的树结构,从而确定树结构中与目的IP地址相匹配的前缀节点,即与目的IP地址相匹配的路由前缀在路由表对应的树结构中的节点。当该前缀节点不为树结构中的叶子节点,即该前缀节点具有子节点时,处理器可以将树结构的根节点到尾节点的长度确定为第一前缀匹配长度。其中,尾节点为树结构中查找路径上的最后一个节点。查找路径为路由表对应的树结构中从根节点沿目的IP地址对应的树结构到路由表对应的树结构中叶子节点的路径。在得到第一前缀匹配长度之后,处理器可以根据第一前缀匹配长度后,处理器可以根据目的IP地址和第一前缀匹配长度确定第一路由前缀,并触发缓存存储第一对应关系,第一对应关系为第一路由前缀和与前缀节点相对应的路由信息之间的对应关系。也 就是说,在前缀节点不为叶子节点的情况下,对应关系中的路由前缀和路由表中记载的路由前缀不同。即,当路由表中存在包括且长度大于目的IP地址对应的路由前缀的其他路由前缀时,处理器可以根据第一前缀匹配长度确定新的第一路由前缀,并在缓存中存储该新的路由前缀和路由信息的对应关系。这样,第一路由前缀的长度可以大于存储器路由表中与目的IP地址相匹配的路由前缀的长度。如此,相较于现有技术,可以起到减小虚假命中出现的概率的作用。In a first aspect, an embodiment of the present application provides a caching method, which can be applied to a processor in a network device. When executing the caching method, the processor may first obtain the first packet, and determine the destination IP address carried in the first packet. Next, the processor can look up a routing prefix that matches the destination IP address from the cache. If there is no routing prefix matching the destination IP address stored in the cache, the processor can look up the tree structure corresponding to the routing table from other memories according to the destination IP address, so as to determine the prefix node in the tree structure that matches the destination IP address, That is, the node in the tree structure corresponding to the routing table with the routing prefix matching the destination IP address. When the prefix node is not a leaf node in the tree structure, that is, when the prefix node has child nodes, the processor may determine the length from the root node to the tail node of the tree structure as the first prefix matching length. The tail node is the last node on the search path in the tree structure. The search path is a path from the root node along the tree structure corresponding to the destination IP address in the tree structure corresponding to the routing table to the leaf node in the tree structure corresponding to the routing table. After obtaining the first prefix matching length, the processor may determine the first routing prefix according to the destination IP address and the first prefix matching length, and trigger the cache to store the first correspondence. The corresponding relationship is the corresponding relationship between the first routing prefix and the routing information corresponding to the prefix node. That is to say, when the prefix node is not a leaf node, the routing prefix in the corresponding relationship is different from the routing prefix recorded in the routing table. That is, when there are other routing prefixes including and longer than the routing prefix corresponding to the destination IP address in the routing table, the processor may determine a new first routing prefix according to the matching length of the first prefix, and store the new routing prefix in the cache The correspondence between prefixes and routing information. In this way, the length of the first routing prefix may be greater than the length of the routing prefix matching the destination IP address in the memory routing table. In this way, compared with the prior art, it can play a role in reducing the probability of false hits.
在一种可能的实现中,第一路由前缀的长度可以大于第一前缀匹配长度。容易理解的是,第一路由前缀的长度越长,出现虚假命中的概率也就越小。当第一路由前缀的长度大于第一前缀匹配长度时,出现虚假命中的概率为0。In a possible implementation, the length of the first routing prefix may be greater than the first prefix matching length. It is easy to understand that the longer the length of the first routing prefix, the smaller the probability of false hits. When the length of the first routing prefix is greater than the first prefix matching length, the probability of false hits is 0.
在一种可能的实现中,当目的IP地址在路由表对应的树结构中尾节点为叶子节点时,第一路由前缀的长度可以等于第一前缀匹配长度。In a possible implementation, when the destination IP address is a leaf node in the tree structure corresponding to the routing table, the length of the first routing prefix may be equal to the matching length of the first prefix.
在一种可能的实现中,路由表对应的树结构可以被划分为虚拟树结构和多个子树结构。处理器可以通过虚拟树结构和子树结构确定与目的IP地址匹配的前缀节点。其中,虚拟树结构可以包括路由表对应的树结构中任意多个节点,多个子树结构中每个子树结构的根节点分别对应虚拟树结构中一个节点。具体的,处理器可以先根据目的IP地址查找与路由表对应的虚拟树结构,确定与目的IP地址最长匹配的虚拟前缀。接着,处理器可以根据该虚拟前缀确定根节点对应的路由前缀为该虚拟前缀的子树结构,并从子树结构中查找与目的IP地址匹配的前缀节点。那么,假设第一长度为虚拟书结构的根节点到虚拟前缀的长度,第二长度为从虚拟前缀到子树结构的查找路径上尾节点的长度,那么第一长度与第二长度之和为前述第一前缀匹配长度。如此,将路由表对应的树结构划分为虚拟树结构和多个子树,可以提高路由前缀的查找效率。In a possible implementation, the tree structure corresponding to the routing table may be divided into a virtual tree structure and multiple sub-tree structures. The processor can determine the prefix node matching the destination IP address through the virtual tree structure and the subtree structure. The virtual tree structure may include any number of nodes in the tree structure corresponding to the routing table, and the root node of each sub-tree structure in the multiple sub-tree structures corresponds to a node in the virtual tree structure respectively. Specifically, the processor may first look up the virtual tree structure corresponding to the routing table according to the destination IP address, and determine the virtual prefix that matches the destination IP address the longest. Next, the processor may determine, according to the virtual prefix, that the routing prefix corresponding to the root node is a subtree structure of the virtual prefix, and search for a prefix node matching the destination IP address from the subtree structure. Then, assuming that the first length is the length from the root node of the virtual book structure to the virtual prefix, and the second length is the length of the tail node on the search path from the virtual prefix to the subtree structure, then the sum of the first length and the second length is the aforementioned The first prefix matches the length. In this way, dividing the tree structure corresponding to the routing table into a virtual tree structure and a plurality of subtrees can improve the search efficiency of routing prefixes.
在一些可能的实现中,处理器还可以存储第二路由前缀和路由信息的对应关系。其中没地儿路由前缀为转发路径上独子节点对应的路由前缀,独子节点为只具有左孩子节点或右孩子节点的子节点。具体的,当与目的IP地址匹配的前缀节点不为叶子节点时,处理器可以根据目的IP地址的转发路径确定转发路径上的独子节点,并根据肚子节点确定第二前缀匹配长度。第二前缀匹配长度等于从根节点到该独子节点的长度。在确定第二前缀匹配长度后,处理器可以根据第二前缀匹配长度确定第二路由前缀,从而存储第二对应关系。In some possible implementations, the processor may also store the correspondence between the second routing prefix and the routing information. The nodier routing prefix is the routing prefix corresponding to the only-child node on the forwarding path, and the only-child node is a child node with only a left child node or a right child node. Specifically, when the prefix node matching the destination IP address is not a leaf node, the processor may determine the only child node on the forwarding path according to the forwarding path of the destination IP address, and determine the second prefix matching length according to the stomach node. The second prefix matching length is equal to the length from the root node to the only child node. After determining the second prefix matching length, the processor may determine the second routing prefix according to the second prefix matching length, so as to store the second correspondence.
在一些可能的实现中,处理器还可以触发缓存存储第一路由前缀的类型。那么在处理器接收到其他报文后,如果该报文的目的IP地址命中第一路由前缀,处理器可以根据第一路由前缀的类型的指示根据第一对应关系从缓存中获取与第一路由前缀对应的路由信息。In some possible implementations, the processor may further trigger the cache to store the type of the first routing prefix. Then after the processor receives other packets, if the destination IP address of the packet hits the first routing prefix, the processor can obtain the first routing prefix from the cache according to the first corresponding relationship according to the indication of the type of the first routing prefix. The routing information corresponding to the prefix.
在一些可能的实现中,当处理器通过虚拟树结构和子树结构确定前缀节点时,处理器可以触发缓存存储第三对应关系,该第三对应关系为虚拟前缀、虚拟前缀的类型和子树结构的信息之间的对应关系。相似地,如果该报文的目的IP地址命中虚拟前缀,处理器可以根据虚拟前缀的类型的指示,从子树结构的信息中查找子树结构,从而确定与第一路由前缀对应的路由信息。In some possible implementations, when the processor determines the prefix node through the virtual tree structure and the subtree structure, the processor may trigger the cache to store a third correspondence relationship, where the third correspondence relationship is the virtual prefix, the type of the virtual prefix, and the subtree structure. Correspondence between information. Similarly, if the destination IP address of the packet hits the virtual prefix, the processor may search the subtree structure from the information of the subtree structure according to the indication of the type of the virtual prefix, so as to determine the routing information corresponding to the first routing prefix.
在一些可能的实现中,考虑到最大长度匹配原则,处理器还可以触发缓存存储第一路由前缀的长度。In some possible implementations, considering the maximum length matching principle, the processor may further trigger the cache to store the length of the first routing prefix.
在一些可能的实现中,所述第一路由前缀的长度等于所述第一前缀匹配长度加1。In some possible implementations, the length of the first routing prefix is equal to the first prefix matching length plus one.
在一些可能的实现中,所述第一路由前缀的长度小于所述目的IP地址的长度。In some possible implementations, the length of the first routing prefix is less than the length of the destination IP address.
在一些可能的实现中,所述目的IP地址包括所述第一路由前缀。In some possible implementations, the destination IP address includes the first routing prefix.
在一些可能的实现中,所述缓存至少包括以下其中一种:三态内容寻址存储器(Ternary Content Addressable Memory,TCAM)、寄存器、线卡板和晶粒。In some possible implementations, the cache includes at least one of the following: a ternary content addressable memory (Ternary Content Addressable Memory, TCAM), a register, a line card board, and a die.
第二方面,本申请实施例提供了一种集成电路,所述集成电路应用于处理器,包括接口电路和控制电路;其中,所述接口电路,用于获取第一报文,所述第一报文包括目的互联网协议IP地址;所述控制电路,用于从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。In a second aspect, an embodiment of the present application provides an integrated circuit, which is applied to a processor and includes an interface circuit and a control circuit; wherein the interface circuit is used to acquire a first message, the first The message includes a destination Internet Protocol IP address; the control circuit is configured to look up a routing prefix matching the destination IP address from the cache; in response to that the routing prefix is not stored in the cache, according to the destination IP address Look up the tree structure corresponding to the routing table, and determine the prefix node matching the destination IP address; in response to the prefix node not being a leaf node, determine the first prefix matching length, and the first prefix matching length is equal to the tree The length between the root node of the structure and the tail node, where the tail node is the last node on the search path of the tree structure; according to the first prefix matching length and the destination IP address, determine the first routing prefix ; Trigger the cache to store a first correspondence, where the first correspondence is the first routing prefix and routing information corresponding to the prefix node.
在一些可能的实现中,所述第一路由前缀的长度大于或等于所述第一前缀匹配长度。In some possible implementations, the length of the first routing prefix is greater than or equal to the first prefix matching length.
在一些可能的实现中,所述控制电路,用于根据所述目的IP地址查找与路由表对应的虚拟树结构,确定与所述目的IP地址最长匹配的虚拟前缀;根据所述目的IP地址查找与所述虚拟前缀对应的子树结构,确定与所述目的IP地匹配的前缀节点,所述虚拟前缀为所述子树结构的根节点;所述第一前缀匹配长度等于第一长度和第二长度之和,所述第一长度为所述虚拟树结构的根节点到所述虚拟前缀的长度,所述第二长度为所述虚拟前缀到尾节点之间的长度,所述尾节点为所述子树结构的查找路径上的最后一个节点。In some possible implementations, the control circuit is configured to look up a virtual tree structure corresponding to the routing table according to the destination IP address, and determine the virtual prefix that matches the destination IP address with the longest length; according to the destination IP address Find the subtree structure corresponding to the virtual prefix, and determine the prefix node that matches the destination IP, and the virtual prefix is the root node of the subtree structure; the first prefix matching length is equal to the first length and The sum of the second lengths, the first length is the length from the root node of the virtual tree structure to the virtual prefix, the second length is the length from the virtual prefix to the tail node, the tail node is the last node on the search path of the subtree structure.
在一些可能的实现中,所述控制电路,还用于响应于所述前缀节点不为叶子节点,确定第二前缀匹配长度,所述第二前缀匹配长度等于所述树结构的根节点到独子节点之间的长度,所述独子节点为所述前缀节点到所述尾节点之间的只具有左孩子节点或只具有右孩子节点的节点;根据所述第二前缀匹配长度和所述目的IP地址,确定第二路由前缀,所述第二路由前缀的长度大于所述第二前缀匹配长度;触发所述缓存存储第二对应关系,所述第二对应关系为所述第二路由前缀和所述前缀节点对应的路由信息。In some possible implementations, the control circuit is further configured to, in response to the prefix node not being a leaf node, determine a second prefix matching length, where the second prefix matching length is equal to the root node to the only child of the tree structure The length between nodes, the single-child node is a node with only a left child node or only a right child node between the prefix node and the tail node; match the length and the destination IP according to the second prefix address, determine a second routing prefix, the length of the second routing prefix is greater than the matching length of the second prefix; trigger the cache to store a second correspondence, the second correspondence is the second routing prefix and all The routing information corresponding to the prefix node described above.
在一些可能的实现中,所述控制电路,还用于触发所述缓存存储所述第一路由前缀的类型,所述第一路由前缀的类型用于指示在所述第一路由前缀被命中时,根据所述第一对应关系在所述缓存中获取与所述第一路由前缀对应的路由信息。In some possible implementations, the control circuit is further configured to trigger the cache to store the type of the first routing prefix, where the type of the first routing prefix is used to indicate when the first routing prefix is hit , and obtain the routing information corresponding to the first routing prefix in the cache according to the first corresponding relationship.
在一些可能的实现中,所述控制电路,还用于触发所述缓存存储第三对应关系,所述第三对应关系为所述虚拟前缀、所述虚拟前缀的类型以及所述子树结构的信息之间的对应关系,所述虚拟前缀的类型用于指示在所述虚拟前缀被命中时,根据所述子树结构的信息查找所述子树结构。In some possible implementations, the control circuit is further configured to trigger the cache to store a third correspondence relationship, where the third correspondence relationship is the virtual prefix, the type of the virtual prefix, and the subtree structure. The corresponding relationship between the information, the type of the virtual prefix is used to indicate that when the virtual prefix is hit, the sub-tree structure is searched according to the information of the sub-tree structure.
在一些可能的实现中,所述控制电路,还用于触发所述缓存存储所述第一路由前缀的长度。In some possible implementations, the control circuit is further configured to trigger the cache to store the length of the first routing prefix.
在一些可能的实现中,所述第一路由前缀的长度等于所述第一前缀匹配长度加1。In some possible implementations, the length of the first routing prefix is equal to the first prefix matching length plus one.
在一些可能的实现中,所述第一路由前缀的长度小于所述目的IP地址的长度。In some possible implementations, the length of the first routing prefix is less than the length of the destination IP address.
在一些可能的实现中,所述目的IP地址包括所述第一路由前缀。In some possible implementations, the destination IP address includes the first routing prefix.
在一些可能的实现中,所述缓存至少包括以下其中一种:TCAM、寄存器、线卡板和晶粒。In some possible implementations, the cache includes at least one of the following: a TCAM, a register, a line card board, and a die.
第三方面,本申请实施例提供了一种缓存装置,所述缓存装置包括获取单元和处理单元。其中,所述获取单元,用于获取第一报文,所述第一报文包括目的互联网协议IP地址。所述处理单元,用于从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。In a third aspect, an embodiment of the present application provides a cache device, where the cache device includes an acquisition unit and a processing unit. Wherein, the obtaining unit is configured to obtain a first packet, where the first packet includes a destination Internet Protocol IP address. The processing unit is configured to look up a routing prefix matching the destination IP address from the cache; in response to the routing prefix not being stored in the cache, look up a tree structure corresponding to the routing table according to the destination IP address, determining a prefix node matching the destination IP address; in response to the prefix node not being a leaf node, determining a first prefix matching length, where the first prefix matching length is equal to the length between the root node and the tail node of the tree structure The length of the tail node is the last node on the search path of the tree structure; according to the first prefix matching length and the destination IP address, determine the first routing prefix; trigger the cache to store the first corresponding The first corresponding relationship is the first routing prefix and routing information corresponding to the prefix node.
第四方面,本申请实施例提供了一种芯片,所述芯片包括存储器和处理器,存储器用于存储指令或程序代码,处理器用于从存储器中调用并运行所述指令或程序代码,以执行如前述第一方面所述的缓存方法。In a fourth aspect, an embodiment of the present application provides a chip, the chip includes a memory and a processor, the memory is used for storing instructions or program codes, and the processor is used for calling and running the instructions or program codes from the memory to execute The caching method according to the aforementioned first aspect.
第五方面,本申请实施例提供了一种设备,所述设备包括处理器芯片和存储器,存储器用于存储指令或程序代码,处理器芯片用于从存储器中调用并运行所述指令或程序代码,以执行如前述第一方面所述的缓存方法。In a fifth aspect, an embodiment of the present application provides a device, the device includes a processor chip and a memory, the memory is used to store instructions or program codes, and the processor chip is used to call and run the instructions or program codes from the memory , so as to execute the caching method described in the first aspect.
第六方面,本申请实施例提供了一种计算机可读存储介质,包括指令、程序或代码,当其在计算机上执行时,使得所述计算机执行如前述第一方面所述的缓存方法。In a sixth aspect, embodiments of the present application provide a computer-readable storage medium, including instructions, programs, or codes, which, when executed on a computer, cause the computer to execute the caching method described in the foregoing first aspect.
附图说明Description of drawings
图1为本申请实施例提供的处理器的一种结构示意图;FIG. 1 is a schematic structural diagram of a processor provided by an embodiment of the present application;
图2为本申请实施例提供的路由前缀对应的树结构的一种结构示意图;2 is a schematic structural diagram of a tree structure corresponding to a routing prefix provided by an embodiment of the present application;
图3-a为本申请实施例提供的网络系统300的一种结构示意图;FIG. 3-a is a schematic structural diagram of a network system 300 provided by an embodiment of the present application;
图3-b为本申请实施例提供的网络设备350的一种结构示意图;FIG. 3-b is a schematic structural diagram of a network device 350 according to an embodiment of the present application;
图3-c为本申请实施例提供的网络设备350的另一种结构示意图;FIG. 3-c is another schematic structural diagram of a network device 350 provided by an embodiment of the present application;
图3-d为本申请实施例提供的网络设备350的又一种结构示意图;FIG. 3-d is another schematic structural diagram of a network device 350 provided by an embodiment of the present application;
图3-e为本申请实施例提供的网络设备360的一种结构示意图;FIG. 3-e is a schematic structural diagram of a network device 360 provided by an embodiment of the present application;
图3-f为本申请实施例提供的网络设备的芯片370的一种结构示意图;FIG. 3-f is a schematic structural diagram of a chip 370 of a network device provided by an embodiment of the present application;
图3-g为本申请实施例提供的虚拟路由器380的一种结构示意图;FIG. 3-g is a schematic structural diagram of a virtual router 380 provided by an embodiment of the present application;
图4为本申请实施例提供的一种缓存方法的流程示意图;4 is a schematic flowchart of a caching method provided by an embodiment of the present application;
图5为本申请实施例提供的路由表对应的树结构的一种结构示意图;5 is a schematic structural diagram of a tree structure corresponding to a routing table provided in an embodiment of the present application;
图6为本申请实施例提供的子树结构的一种结构示意图;6 is a schematic structural diagram of a subtree structure provided by an embodiment of the present application;
图7为本申请实施例提供的路由表对应的树结构的一种结构示意图;7 is a schematic structural diagram of a tree structure corresponding to a routing table provided in an embodiment of the present application;
图8为本申请实施例提供的集成电路800的一种结构示意图;FIG. 8 is a schematic structural diagram of an integrated circuit 800 provided by an embodiment of the present application;
图9为本申请实施例提供的缓存装置900的一种结构示意图;FIG. 9 is a schematic structural diagram of a cache device 900 provided by an embodiment of the present application;
图10为本申请实施例提供的芯片1000的一种结构示意图;FIG. 10 is a schematic structural diagram of a chip 1000 provided by an embodiment of the present application;
图11为本申请实施例提供的一种设备1100的结构示意图;FIG. 11 is a schematic structural diagram of a device 1100 provided by an embodiment of the present application;
图12为本申请实施例提供的一种设备1200的结构示意图。FIG. 12 is a schematic structural diagram of a device 1200 provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合附图对传统技术和本申请实施例提供缓存方法进行介绍。The traditional technology and the caching method provided by the embodiments of the present application will be introduced below with reference to the accompanying drawings.
首先对包括缓存的设备的基本结构进行介绍。参见图1,该图为设备100的一种结构示意图。该设备100包括处理器110和存储器120,处理器110包括处理单元111和缓存112。其中,缓存112可以用于从存储器120中加载数据,处理单元111可以用于从缓存112中读取数据,并对数据进行处理。可选地,当处理器110封装为芯片,该芯片可以被称为中央处理器(central processing unit,CPU)。First, the basic structure of the device including the cache is introduced. Referring to FIG. 1 , the figure is a schematic structural diagram of the device 100 . The device 100 includes a processor 110 and a memory 120 , and the processor 110 includes a processing unit 111 and a cache 112 . The cache 112 can be used to load data from the memory 120, and the processing unit 111 can be used to read data from the cache 112 and process the data. Optionally, when the processor 110 is packaged as a chip, the chip may be referred to as a central processing unit (CPU).
缓存,全称高速缓冲存储器(cache),大多由数据交换速度较快的存储设备组成。在本申请实施方式中,缓存也可以被称为暂时内存(temporary memory)或者暂时存储器(temporary storage)。缓存分别与处理器内部的处理单元和处理器外部的存储器连接,可以存储存储器中存储的部分或全部数据。Cache, the full name of the cache (cache), is mostly composed of storage devices with faster data exchange speed. In the embodiments of the present application, the cache may also be referred to as temporary memory (temporary memory) or temporary storage (temporary storage). The cache is respectively connected with the processing unit inside the processor and the memory outside the processor, and can store part or all of the data stored in the memory.
存储器可以分为外存和内存,外存例如是硬盘(Hard Disk Drive,HDD)等存储设备,内存例如是同步动态随机存取内存器(synchronous dynamic random-access memory,SDRAM)或双倍速度同步动态随机存储器(Double Data Rate SDRAM,DDR)等存储设备。而缓存例如是静态存储器(Static Random Access Memory,SRAM)等存储设备。在与处理器进行数据交换的过程中,SRAM的数据交换速度大于DDR(或SDRAM)的数据交换速度,而DDR的数据交换速度又大于硬盘的数据交换速度。对于当网络设备通过缓存存储部分或全部路由表时,可以先在缓存中创建一个内容为空的路由表。本申请实施例中,缓存中存储的路由表可以被称为缓存路由表,存储器中存储的路由表可以被称为存储器路由表。Memory can be divided into external memory and internal memory. External memory is, for example, storage devices such as hard disk drives (HDD), and memory is, for example, synchronous dynamic random-access memory (SDRAM) or double-speed synchronous memory. Dynamic random access memory (Double Data Rate SDRAM, DDR) and other storage devices. The cache is, for example, a storage device such as a static memory (Static Random Access Memory, SRAM). In the process of data exchange with the processor, the data exchange speed of the SRAM is greater than that of the DDR (or SDRAM), and the data exchange speed of the DDR is greater than that of the hard disk. When the network device stores part or all of the routing table through the cache, you can first create a routing table with empty content in the cache. In this embodiment of the present application, the routing table stored in the cache may be referred to as a cache routing table, and the routing table stored in the memory may be referred to as a memory routing table.
在处理器确定目的IP地址与存储器路由表中某个路由前缀相匹配时,处理器可以将该路由前缀和路由信息存储在缓存路由表中。这样,当网络设备接收到新报文,且新报文的目的IP地址与缓存路由表中已存储的路由前缀相匹配时,处理器可以从缓存路由表中获取对应的路由信息。这样,由于处理器与缓存的数据交换速度较快,提高了路由表的查找速度。当IP地址的前n位分别与该路由前缀一致时,可以称该IP地址与该路由前缀相匹配When the processor determines that the destination IP address matches a routing prefix in the memory routing table, the processor may store the routing prefix and routing information in the cache routing table. In this way, when the network device receives a new packet and the destination IP address of the new packet matches the routing prefix stored in the cached routing table, the processor can obtain the corresponding routing information from the cached routing table. In this way, since the data exchange speed between the processor and the cache is faster, the search speed of the routing table is improved. When the first n bits of the IP address are respectively consistent with the routing prefix, the IP address can be said to match the routing prefix
可选地,缓存路由表可以包括缓存标签(Cache Tag)项和缓存数据(Cache Data)项。其中,缓存标签项可以包括路由前缀,缓存数据项可以用于存储路由信息。相应的,缓存标签项与缓存数据项之间的对应关系可以表示路由前缀与路由信息之间的对应关系。Optionally, the cache routing table may include a cache tag (Cache Tag) item and a cache data (Cache Data) item. The cache label item may include a routing prefix, and the cache data item may be used to store routing information. Correspondingly, the corresponding relationship between the cache label item and the cache data item may represent the corresponding relationship between the routing prefix and the routing information.
考虑到网络设备需要根据最长匹配原则确定与目的IP地址相匹配的路由前缀,缓存标签项还可以包括路由前缀的长度(length,以下简称len)。这样,当目的IP地址同时与缓存中的路由表中多个路由前缀相匹配时,处理器可以将长度最长的路由前缀确定为与目的IP地址相匹配的路由前缀。Considering that the network device needs to determine the route prefix matching the destination IP address according to the longest matching principle, the cache label item may further include the length of the route prefix (length, len for short below). In this way, when the destination IP address matches multiple routing prefixes in the routing table in the cache at the same time, the processor can determine the routing prefix with the longest length as the routing prefix matching the destination IP address.
举例说明。假设网络设备具有网络接口A、网络接口B,且网络设备的存储器中记载了路由前缀0001010*和网络接口A的对应关系,以及路由前缀0*和网络接口B的对应关系。for example. It is assumed that the network device has network interface A and network interface B, and the memory of the network device records the correspondence between the routing prefix 0001010* and the network interface A, and the correspondence between the routing prefix 0* and the network interface B.
如果网络设备接收到了报文M,且报文M的目的IP地址为0001010010100010。网络设备的处理器可以先从存储器路由表中查找与该目的IP地址相匹配的路由前缀和路由信息。在确定目的IP地址0001010010100010与路由前缀0001011*相匹配之后,处理器可以将路由前缀0001010*、路由前缀0001010*的长度和路由前缀0001010*对应的路由信息(即网络接口A)存储在缓存路由表中。该缓存路由表可以如表1所示。If the network device receives the packet M, and the destination IP address of the packet M is 0001010010100010. The processor of the network device may first look up the routing prefix and routing information matching the destination IP address from the routing table in the memory. After determining that the destination IP address 0001010010100010 matches the routing prefix 0001011*, the processor may store the routing prefix 0001010*, the length of the routing prefix 0001010* and the routing information (ie network interface A) corresponding to the routing prefix 0001010* in the cache routing table middle. The cache routing table may be as shown in Table 1.
表1Table 1
Cache tagCache tag Cache dataCache data
0001010*,len=70001010*, len=7 AA
其中,表1的第一行表示路由前缀000101101*与网络接口A相对应,那么目的IP地址第一位为0的报文可以通过网络接口A转发,例如目的IP地址为0001010010100010的报文可以通过网络接口A转发。Among them, the first row of Table 1 indicates that the routing prefix 000101101* corresponds to network interface A, then the packets whose destination IP address is the first 0 can be forwarded through network interface A. For example, the packets whose destination IP address is 0001010010100010 can be forwarded through network interface A. Network interface A forwards.
如果网络设备又接收到报文N,报文N的目的IP地址为0001011010010001。由于该目的IP地址的前7位为0001011,与路由前缀0001010*不一致,网络设备的处理器可以从存储器路由表中查找与目的IP地址0001011010010001相匹配的路由前缀。在确定目的IP地址0001011010010001与路由前缀0*相匹配后,处理器可以将路由前缀0*、路由前缀0*的长度和路由前缀0*对应的路由信息(即网络接口A)存储在缓存路由表中。该缓存路由表可以如表2所示。If the network device receives packet N again, the destination IP address of packet N is 0001011010010001. Since the first 7 digits of the destination IP address are 0001011, which is inconsistent with the routing prefix 0001010*, the processor of the network device can look up the routing prefix matching the destination IP address 0001011010010001 from the memory routing table. After determining that the destination IP address 0001011010010001 matches the routing prefix 0*, the processor may store the routing prefix 0*, the length of the routing prefix 0*, and the routing information (ie, network interface A) corresponding to the routing prefix 0* in the cache routing table middle. The cache routing table may be as shown in Table 2.
表2Table 2
Cache tagCache tag Cache dataCache data
0001010*,len=70001010*, len=7 A A
0*,len=10*, len=1 BB
如果网络设备又接收到了一条目的IP地址为0001011011110100的报文,由于该目的IP地址的第一位与路由前缀0*一致,且目的IP地址的前七位与路由前缀0001010*不一致,处理器可以确定该报文与路由前缀0*相对应,从而通过网络接口B转发该报文。显然,由于处理器从缓存中获取数据的速度较快,将将部分或全部路由前缀和路由信息的对应关系存储在缓存路由表中可以提高网络设备转发报文的速度。If the network device receives another packet whose destination IP address is 0001011011110100, since the first digit of the destination IP address is consistent with the routing prefix 0*, and the first seven digits of the destination IP address are inconsistent with the routing prefix 0001010*, the processor can It is determined that the packet corresponds to the routing prefix 0*, so that the packet is forwarded through the network interface B. Obviously, since the processor obtains data from the cache faster, storing part or all of the correspondence between routing prefixes and routing information in the cache routing table can improve the packet forwarding speed of the network device.
但是,由于缓存路由表中的信息是随着报文的转发而逐渐增加的,在这个过程中,缓存路由表和存储器路由表并不一致。那么,如果两个相似度较高的路由中较长的路由前缀未被存入缓存路由表,而较短的路由前缀已被存入缓存路由表,处理器有可能错误地将较短的路由前缀确定为与报文相匹配的路由前缀,从而根据错误的路由信息转发报文,这种情况被称为虚假命中。However, since the information in the cache routing table is gradually increased along with the forwarding of the message, in this process, the cache routing table and the memory routing table are not consistent. Then, if the longer route prefix has not been stored in the cache routing table, and the shorter route prefix has been stored in the cache routing table, the processor may mistakenly assign the shorter route prefix to the cache routing table. The prefix is determined as the routing prefix that matches the packet, so that the packet is forwarded according to the wrong routing information. This situation is called a false hit.
例如,假设某个报文的目的IP地址与路由前缀X和路由前缀Y相匹配,且路由前缀X已被存储缓存路由表,路由前缀Y未被存入缓存路由表。如果路由前缀X的长度短于路由前缀Y的长度,该报文理论上对应的路由信息应当是路由前缀Y对应的路由信息。但是,处理器在接收到报文后优先从缓存路由表中查找与目的IP地址相匹配的路由前缀。由于缓 存路由表包括路由前缀X,处理器可以能够从缓存路由表中找到与目的IP地址相匹配的路由前缀X,从而利用路由前缀X对应的路由信息转发报文。可见,由于缓存路由表与存储器路由表中存储的路由前缀不同,网络设备在转发目的IP地址与多个路由前缀相匹配的报文时可能出现虚假命中的情况。For example, suppose that the destination IP address of a packet matches routing prefix X and routing prefix Y, and routing prefix X has been stored in the cache routing table, but routing prefix Y has not been stored in the cache routing table. If the length of the routing prefix X is shorter than the length of the routing prefix Y, the routing information corresponding to the packet should be the routing information corresponding to the routing prefix Y in theory. However, after receiving the packet, the processor preferentially looks up the routing prefix matching the destination IP address from the cached routing table. Since the cached routing table includes the routing prefix X, the processor may be able to find the routing prefix X that matches the destination IP address from the cached routing table, so as to forward the packet by using the routing information corresponding to the routing prefix X. It can be seen that since the routing prefixes stored in the cache routing table and the storage routing table are different, the network device may have false hits when forwarding packets whose destination IP addresses match multiple routing prefixes.
仍然以网络设备接收报文M和报文N为例进行说明。假设网络设备先接收到了报文N,那么缓存路由表可以如表3所示:The description is still made by taking the network device receiving the packet M and the packet N as an example. Assuming that the network device receives the packet N first, the cache routing table can be as shown in Table 3:
表3table 3
Cache tagCache tag Cache dataCache data
0*,len=10*, len=1 BB
如果网络设备再次接收到了报文M,由于报文M的目的IP地址为0001010010100010,其第一位为0,与缓存路由表中记录的路由前缀0*一致,处理器可以认为报文M与路由前缀0*相匹配,从而利用网络接口B转发报文M。显然,报文M实际对应的网络接口应当是网络接口A。由于缓存路由表中包括的信息不全,存在虚假命中的情况。If the network device receives the packet M again, since the destination IP address of the packet M is 0001010010100010 and the first bit is 0, which is consistent with the routing prefix 0* recorded in the cache routing table, the processor can consider that the packet M is the same as the route. The prefix 0* matches, so that the packet M is forwarded by the network interface B. Obviously, the network interface actually corresponding to the packet M should be the network interface A. Because the information included in the cache routing table is incomplete, there are cases of false hits.
为了解决上述问题,本申请实施例提供了一种缓存方法,该方法可以在缓存中记录长度大于路由表中与目的IP地址的第一路由前缀与路由信息之间的对应关系,避免了虚假命中的发生。In order to solve the above problem, an embodiment of the present application provides a caching method, which can record in the cache the correspondence between the first routing prefix whose length is greater than the destination IP address in the routing table and the routing information, thereby avoiding false hits happened.
以下,首先对本申请涉及的术语进行简单介绍:Below, first briefly introduce the terms involved in this application:
树结构:树(tree)结构是一种非线性的数据结构。一个树结构可以包括多个节点,每个节点可以用于存储数据。树结构的各个节点之间的连接关系表示各个节点存储的数据之间的关系,例如可以表示数据的顺序关系或从属关系等。树结构中最顶端的节点被称为根节点。一个树结构可以包括多个子树结构,每个子树结构又可以包括一个或多个子树结构。每个子树结构最顶端的节点可以被称为该子树结构的根节点。典型的树结构可以包括二叉树、三叉树和四叉树。Tree structure: A tree structure is a non-linear data structure. A tree structure can include multiple nodes, and each node can be used to store data. The connection relationship between each node of the tree structure represents the relationship between the data stored by each node, for example, it can represent the sequence relationship or the subordination relationship of the data. The topmost node in the tree structure is called the root node. A tree structure may include multiple sub-tree structures, and each sub-tree structure may include one or more sub-tree structures. The topmost node of each subtree structure may be referred to as the root node of the subtree structure. Typical tree structures may include binary trees, ternary trees, and quad trees.
在本申请实施例中,路由前缀可以通过二叉树等树结构表示,通过树结构中相邻两层节点之间的连接关系体现路由前缀每一位的具体值。相似地,路由表也可以通过相似的规则通过树结构表示。例如,可以将路由表中每条路由前缀用树结构表示,再将这些树结构的根节点叠加在一起,最终得到的树结构即为路由表的对应的树结构。为了区分路由表中各个路由前缀,可以将每个路由前缀最后一位对应的节点标记为前缀节点。与路由表对应的树结构可以用于表述路由表中前缀节点的分布。In this embodiment of the present application, the routing prefix may be represented by a tree structure such as a binary tree, and the specific value of each bit of the routing prefix is represented by the connection relationship between two adjacent layers of nodes in the tree structure. Similarly, routing tables can also be represented by a tree structure with similar rules. For example, each routing prefix in the routing table can be represented by a tree structure, and then the root nodes of these tree structures are superimposed together, and the finally obtained tree structure is the corresponding tree structure of the routing table. In order to distinguish each routing prefix in the routing table, the node corresponding to the last digit of each routing prefix may be marked as a prefix node. The tree structure corresponding to the routing table can be used to express the distribution of prefix nodes in the routing table.
在本申请实施例中,路由前缀和路由表可以通过二叉树表示,也可以通过四叉树或十六叉树表示。下面对二叉树进行介绍。需要说明的是,后文为了便于理解以路由表的树结构为二叉树为例进行说明,并不代表本申请全部实施例中路由表的树结构均为二叉树。当路由前缀通过四叉树结构表示时,每个子节点对应路由前缀中的两位数字,例如根节点的四个子节点可以分别表示“00”、“01”、“10”和“11”。如果路由表以树结构表示,该树结构可以拆分为一个虚拟树结构和多个子树结构。关于虚拟树结构的介绍可以参加下文,这里不再赘述。In this embodiment of the present application, the routing prefix and the routing table may be represented by a binary tree, or may be represented by a quad tree or a hexadecimal tree. The following is an introduction to the binary tree. It should be noted that, for ease of understanding, the following description takes the tree structure of the routing table as a binary tree as an example, which does not mean that the tree structure of the routing table in all embodiments of the present application is a binary tree. When the routing prefix is represented by a quad-tree structure, each child node corresponds to two digits in the routing prefix, for example, the four child nodes of the root node can represent "00", "01", "10" and "11" respectively. If the routing table is represented in a tree structure, the tree structure can be split into a virtual tree structure and multiple subtree structures. The introduction of the virtual tree structure can be found below, and will not be repeated here.
二叉树(binary tree):二叉树是指树结构中节点的度不大于2的有序树。即,二叉树具有一个根节点,且二叉树中任意一个节点最多具有两个子节点,当一个节点具有两个子节点时,左侧的子节点可以被称为左孩子节点,右侧的子节点可以被称为右孩子节点。二叉树中任意一个节点。一个二叉树可以包括多个子二叉树。Binary tree: A binary tree is an ordered tree in which the degree of nodes in the tree structure is not greater than 2. That is, a binary tree has one root node, and any node in the binary tree has at most two child nodes. When a node has two child nodes, the left child node can be called the left child node, and the right child node can be called the left child node. is the right child node. any node in a binary tree. A binary tree can contain multiple sub-binary trees.
当路由前缀通过二叉树表示时,从根节点的子节点开始,每一位IP地址对应二叉树的一层。如果IP地址的某一位为0,则二叉树在该层向左侧延伸,如果路由前缀的某一位为1,则二叉树该层向右侧延伸。也就是说,如果路由前缀的第一位为0,那么该路由前缀对应的二叉树的根节点具有左孩子节点,且不具有右孩子节点。When the routing prefix is represented by a binary tree, starting from the child node of the root node, each IP address corresponds to one level of the binary tree. If a certain bit of the IP address is 0, the binary tree extends to the left at this layer, and if a certain bit of the routing prefix is 1, the binary tree extends to the right at this layer. That is, if the first bit of a routing prefix is 0, then the root node of the binary tree corresponding to the routing prefix has a left child node and no right child node.
例如路由前缀10010*对应的树结构可以如图2所示。其中,节点2为根节点1的右孩子节点,连接表示IP地址的第一位为1;节点3为节点2的左孩子节点,连接表示IP地址的第二位为0;节点4为节点3的左孩子节点,连接表示IP地址的第三位为0;节点5为节点4的右孩子节点,连接表示IP地址的第四位为1;节点6为节点5的左孩子节点,连接表示IP地址的第五位为0。For example, the tree structure corresponding to the routing prefix 10010* may be as shown in FIG. 2 . Among them, node 2 is the right child node of root node 1, and the first bit of the connection indicates that the IP address is 1; node 3 is the left child node of node 2, and the second bit of the connection indicates that the IP address is 0; node 4 is node 3 The left child node of the connection indicates that the third bit of the IP address is 0; node 5 is the right child node of node 4, and the fourth bit of the connection indicates that the IP address is 1; node 6 is the left child node of node 5, and the connection indicates IP The fifth bit of the address is 0.
同理,当路由表通过二叉树进行表示时,路由表可以如图5所示。关于这部分内容可以参见后文,这里不再赘述。Similarly, when the routing table is represented by a binary tree, the routing table can be as shown in FIG. 5 . This part of the content can be found later, and will not be repeated here.
独子节点:独子节点为二叉树中仅具有左孩子节点或仅具有右孩子节点的节点。Only child node: An only child node is a node in a binary tree that has only left child nodes or only right child nodes.
叶子节点:叶子节点为树结构中不具有子节点的节点。Leaf node: A leaf node is a node in the tree structure that does not have child nodes.
前缀节点:前缀节点为路由前缀在路由表对应的树结构中对应的节点。Prefix node: The prefix node is the node corresponding to the routing prefix in the tree structure corresponding to the routing table.
查找路径:查找路径为路由表对应的树结构中从根节点沿目的IP地址对应的树结构到路由表对应的树结构中叶子节点的路径。Search path: The search path is the path from the root node along the tree structure corresponding to the destination IP address to the leaf node in the tree structure corresponding to the routing table in the tree structure corresponding to the routing table.
尾节点:尾节点为查找路径中最后一个节点。Tail node: The tail node is the last node in the search path.
本申请实施例提供的方法可以应用于图3-a所示的系统300。该系统300包括网络设备310、网络设备320、网络设备330和网络设备340。The method provided by this embodiment of the present application can be applied to the system 300 shown in FIG. 3-a. The system 300 includes a network device 310 , a network device 320 , a network device 330 and a network device 340 .
在本申请实施例中,网络设备320包括处理器321、缓存322和存储器323。其中,处理器321是网络设备320内部具有数据处理能力的单元,例如可以是处理器内核(core)中用于数据处理的单元,缓存322可以是SRAM等高速存储设备,存储器323可以包括内存和外存中的任意一种或多种。In this embodiment of the present application, the network device 320 includes a processor 321 , a cache 322 and a memory 323 . The processor 321 is a unit with data processing capability inside the network device 320, for example, it may be a unit for data processing in a processor core (core), the cache 322 may be a high-speed storage device such as SRAM, and the memory 323 may include memory and Any one or more of the external storage.
需要说明的是,图3-a中缓存320独立于处理器321,并不表示本申请实施例中提供的缓存必然封装在处理器中。在一些可能的实现方式中,缓存也可以是封装在处理器内部的存储设备。另外,在图1所示实施例中,网络设备320包括一个处理器321和一个缓存322,并不代表本申请实施例中提供的设备只能包括一个处理器和一个缓存。在一些可能的实现方式中,设备可以包括一个或多个处理器,处理器可以包括一个或多个处理单元,以及一个或多个缓存。其中,一个缓存可以对应一个处理单元或多个处理单元,一个处理单元也可以对应一个或多个缓存。本申请实施例对处理器的具体架构不做限定。It should be noted that the cache 320 in FIG. 3-a is independent of the processor 321, which does not mean that the cache provided in the embodiment of the present application is necessarily encapsulated in the processor. In some possible implementations, the cache may also be a storage device packaged inside the processor. In addition, in the embodiment shown in FIG. 1, the network device 320 includes a processor 321 and a cache 322, which does not mean that the device provided in this embodiment of the present application can only include a processor and a cache. In some possible implementations, a device may include one or more processors, which may include one or more processing units, and one or more caches. One cache may correspond to one processing unit or multiple processing units, and one processing unit may also correspond to one or more caches. This embodiment of the present application does not limit the specific architecture of the processor.
在一些可能的实现方式中,网络设备可能具有多级缓存结构,即利用多种存储介质构建多个等级不同的缓存,等级越高的缓存交换数据的速度越快,大小越小。那么,对于具有多级缓存结构的计算机,本申请实施例中的缓存可以是一级缓存(一级缓存为等级最高 的缓存),存储器可以包括等级低于一级缓存的其他缓存,例如二级缓存、三级缓存等。即,在本申请实施例中,缓存为数据交换速度最快的存储设备,存储器为数据交换速度低于缓存的其他所有存储设备的统称。In some possible implementations, the network device may have a multi-level cache structure, that is, multiple caches with different levels are constructed by using multiple storage media, and the caches with higher levels have faster data exchange speed and smaller size. Then, for a computer with a multi-level cache structure, the cache in this embodiment of the present application may be a level-1 cache (the level-1 cache is the cache with the highest level), and the memory may include other caches with a level lower than the level-1 cache, such as level-2 cache cache, L3 cache, etc. That is, in the embodiment of the present application, the cache is a storage device with the fastest data exchange speed, and the memory is a general term for all other storage devices whose data exchange speed is lower than that of the cache.
在本申请实施例中,为了便于路由表项的快速查找,缓存还可以包括三态内容寻址存储器(Ternary Content Addressable Memory,TCAM)、寄存器、线卡版和晶粒等硬件模块。In the embodiment of the present application, in order to facilitate the fast lookup of routing table entries, the cache may further include hardware modules such as a ternary content addressable memory (Ternary Content Addressable Memory, TCAM), a register, a line card board, and a die.
下面先对本申请实施例提供的缓存方法的一些应用场景进行介绍。需要说明的是,本申请实施例提供的应用场景仅仅是一些典型的应用场景,不代表本申请实施例提供的缓存方法只能用于这些应用场景。Some application scenarios of the caching method provided by the embodiments of the present application are first introduced below. It should be noted that the application scenarios provided by the embodiments of the present application are only some typical application scenarios, which does not mean that the caching methods provided by the embodiments of the present application can only be used in these application scenarios.
参见图3-b,该图为本申请实施例提供的一种网络设备的结构示意图。在图3-b所示的实施例中,网络设备350包括处理器351、TCAM352和存储器353。其中,处理器351分别与TCAM352和存储器353连接。存储器353可以用于存储主路由表;TCAM352可以作为缓存用于存储缓存路由表,或根据目的IP地址查找对应的路由信息;处理器351可以用于根据目的IP地址向TCAM352中存储路由前缀和路由信息,或根据TCAM352查找到的路由信息转发报文。Referring to FIG. 3-b, the figure is a schematic structural diagram of a network device provided by an embodiment of the present application. In the embodiment shown in FIG. 3-b , the network device 350 includes a processor 351 , a TCAM 352 and a memory 353 . The processor 351 is connected to the TCAM 352 and the memory 353 respectively. The memory 353 can be used to store the main routing table; the TCAM 352 can be used as a cache to store the cached routing table, or to look up the corresponding routing information according to the destination IP address; the processor 351 can be used to store the routing prefix and route in the TCAM 352 according to the destination IP address. information, or forward packets according to the routing information found by the TCAM352.
可选地,当网络设备具有多个处理器时,每个处理器可以对应各自的TCAM,多个处理器可以对应同一个存储器。具体地,参见图3-c,当网络设备350还包括处理器354时,网络设备350还可以包括TCAM355。其中,处理器351分别与TCAM355和存储器353连接。TCAM355可以作为缓存用于存储处理器354所用的路由表。相似的,TCAM352可以用于存储处理器351所用的路由表。这样,每个处理器都具有相对独立的TCAM,用于存储自身所需的路由表,无需存储全部的路由表。如此,既节省了存储空间,又因为TCAM中存储的内容较少,提高了处理器读取路由表的速度。需要说明的是,在图3-c所示的实施例中,处理器351从TCAM352中读取数据的速度可以不快于处理器351从存储器353中读取数据的速度.Optionally, when the network device has multiple processors, each processor may correspond to a respective TCAM, and the multiple processors may correspond to the same memory. Specifically, referring to FIG. 3-c, when the network device 350 further includes the processor 354, the network device 350 may further include the TCAM 355. The processor 351 is connected to the TCAM 355 and the memory 353 respectively. TCAM 355 may act as a cache for storing routing tables used by processor 354 . Similarly, TCAM 352 may be used to store routing tables used by processor 351. In this way, each processor has a relatively independent TCAM for storing the routing table required by itself, and does not need to store the entire routing table. In this way, not only storage space is saved, but also because less content is stored in the TCAM, the speed at which the processor reads the routing table is improved. It should be noted that, in the embodiment shown in Figure 3-c, the speed at which the processor 351 reads data from the TCAM 352 may not be faster than the speed at which the processor 351 reads data from the memory 353.
关于TCAM352的工作方式可以参见后文表7所在实施例的介绍,这里不再赘述。For the working mode of the TCAM352, reference may be made to the introduction of the embodiment in Table 7 below, which will not be repeated here.
可选地,前述TCAM所起到的作用可以通过并行比较逻辑电路和寄存器实现。具体地,参见图3-d,图3-b所示实施例中TCAM352的作用可以通过并行比较逻辑电路356和寄存器357实现。其中,处理器351与并行比较逻辑电路356连接,并行比较逻辑电路356与寄存器357连接。其中,寄存器357用于存储路由表,并行比较逻辑电路用于确定与目的IP地址相对应的路由信息。Optionally, the role played by the aforementioned TCAM can be implemented by comparing logic circuits and registers in parallel. Specifically, referring to FIG. 3-d, the role of the TCAM 352 in the embodiment shown in FIG. 3-b can be realized by a parallel comparison logic circuit 356 and a register 357. The processor 351 is connected to the parallel comparison logic circuit 356 , and the parallel comparison logic circuit 356 is connected to the register 357 . The register 357 is used to store the routing table, and the parallel comparison logic circuit is used to determine the routing information corresponding to the destination IP address.
可选地,在图3-b、图3-c和图3-d所示的实施例中,处理器351和/或处理器352可以指处理器内核(core)。Optionally, in the embodiments shown in FIGS. 3-b, 3-c and 3-d, the processor 351 and/or the processor 352 may refer to a processor core.
参见图3-e,该图为本申请实施例提供的一种网络设备的结构示意图。在图3-e所示的实施例中,网络设备360包括线卡板361、线卡板362、线卡板363、交换网板364和交换网板365。其中,交换网板364分别与线卡板361、线卡板362和线卡板363连接,交换网板365分别与线卡板361、线卡板362和线卡板363连接。Referring to FIG. 3-e, the figure is a schematic structural diagram of a network device provided by an embodiment of the present application. In the embodiment shown in FIG. 3-e , the network device 360 includes a line card board 361 , a line card board 362 , a line card board 363 , a switch fabric board 364 and a switch fabric board 365 . The switch fabric board 364 is respectively connected with the line card board 361 , the line card board 362 and the line card board 363 , and the switch fabric board 365 is connected with the line card board 361 , the line card board 362 and the line card board 363 respectively.
在图3-e所示的实施例中,每块线卡板可以包括一个缓存,用于存储该线卡板需要使用的缓存路由表。例如,线卡板361包括缓存361-1,用于存储线卡板361需要使用的缓存 路由表;线卡板362包括缓存362-1,用于存储线卡板362需要使用的缓存路由表;线卡板363包括缓存363-1,用于存储线卡板363需要使用的缓存路由表。交换网板可以存储包含全部路由信息的路由表,即前述主路由表。主路由表可以存储在交换网板364和/或交换网板352中,也可以拆分为两部分并分别存储在交换网板364和交换网板352中。可选地,主路由表可以存储在交换网版的缓存中。In the embodiment shown in FIG. 3-e, each line card board may include a cache for storing the cache routing table that the line card board needs to use. For example, the line card board 361 includes a cache 361-1 for storing the cache routing table that the line card board 361 needs to use; the line card board 362 includes a cache 362-1 for storing the cache routing table that the line card board 362 needs to use; The line card board 363 includes a cache 363-1 for storing a cache routing table that the line card board 363 needs to use. The switching fabric board can store a routing table containing all routing information, that is, the aforementioned main routing table. The main routing table may be stored in the switch fabric board 364 and/or the switch fabric board 352 , or may be split into two parts and stored in the switch fabric board 364 and the switch fabric board 352 respectively. Optionally, the main routing table can be stored in the cache of the switch fabric.
参见图3-f,该图为本申请实施例提供的一种网络设备的芯片的结构示意图。在图3-f所示的实施例中,芯片370包括晶粒(die)371、晶粒372、晶粒373和晶粒374。其中,晶粒371分别与晶粒372和晶粒374连接,晶粒373分别与晶粒372和晶粒374连接。当然,在一些其他的实现方式中,芯片中的晶粒还可以以其他的方式连接。Referring to FIG. 3-f, the figure is a schematic structural diagram of a chip of a network device provided by an embodiment of the present application. In the embodiment shown in FIG. 3-f , chip 370 includes die 371 , die 372 , die 373 , and die 374 . The die 371 is connected to the die 372 and the die 374 respectively, and the die 373 is connected to the die 372 and the die 374 respectively. Of course, in some other implementation manners, the dies in the chip may also be connected in other ways.
芯片中任意一个晶粒中可以包括缓存。例如晶粒371可以包括缓存371-1,晶粒372可以包括缓存372-1,晶粒373可以包括缓存373-1,晶粒374可以包括缓存374-1。缓存371-1、缓存372-1、缓存373-1和缓存374-1中任意一个或多个缓存可以用于存储缓存路由表,任意一个或多个缓存可以用于存储主路由表。A cache may be included in any die in the chip. For example, die 371 may include cache 371-1, die 372 may include cache 372-1, die 373 may include cache 373-1, and die 374 may include cache 374-1. Any one or more of the cache 371-1, the cache 372-1, the cache 373-1, and the cache 374-1 may be used to store the cache routing table, and any one or more of the caches may be used to store the main routing table.
在实际的应用场景中,多个网络设备可以作为一个虚拟路由器转发报文。例如,参见图3-g,该图为本申请实施例提供的一种虚拟路由器的结构示意图。在图3-g所示的实施例中,虚拟路由器380包括网络设备381、网络设备382、网络设备383、网络设备384和网络设备385。其中,网络设备383分别与网络设备381、网络设备382、网络设备384和网络设备385连接。在虚拟路由器380中,网络设备385可以用于存储主路由表,网络设备381、网络设备382、网络设备384和网络设备385可以分别存储各自所需要的缓存路由表。可选地,网络设备383可以将主路由表存储在网络设备383的缓存中。In practical application scenarios, multiple network devices can act as a virtual router to forward packets. For example, refer to FIG. 3-g, which is a schematic structural diagram of a virtual router provided by an embodiment of the present application. In the embodiment shown in FIGS. 3-g, virtual router 380 includes network device 381, network device 382, network device 383, network device 384, and network device 385. The network device 383 is connected to the network device 381 , the network device 382 , the network device 384 and the network device 385 respectively. In the virtual router 380, the network device 385 may be used to store the main routing table, and the network device 381, the network device 382, the network device 384, and the network device 385 may store their respective required cache routing tables. Optionally, network device 383 may store the master routing table in a cache of network device 383 .
参见图4,该图4为本申请实施例提供的一种缓存方法的数据交互图。本申请实施例提供的缓存方法包括如下步骤:Referring to FIG. 4 , FIG. 4 is a data interaction diagram of a caching method provided by an embodiment of the present application. The caching method provided by the embodiment of the present application includes the following steps:
S401:处理器获取第一报文。S401: The processor obtains the first packet.
在本申请实施例中,处理器,可以是网络设备中的处理器。例如,处理器可以是图3-a中网络设备320中处理器321,也可以至处理器321中用于对数据进行处理的处理单元。处理器可以通过网络接口接收其他设备发送的第一报文,例如,当处理器为图3-a中处理器321时,处理器321可以接收网络设备310发送的第一报文。当然,在一些可能的实现中,处理器也可以接收终端设备发送的第一报文。当然,下文所述的缓存可以是网络设备中的缓存,例如可以是图3-a中的缓存322。存储器可以是网络设备中的存储器。例如可以是图3-a中的存储器323。In this embodiment of the present application, the processor may be a processor in a network device. For example, the processor may be the processor 321 in the network device 320 in FIG. 3-a, or may be a processing unit in the processor 321 for processing data. The processor may receive the first packet sent by other devices through the network interface. For example, when the processor is the processor 321 in FIG. 3-a, the processor 321 may receive the first packet sent by the network device 310. Certainly, in some possible implementations, the processor may also receive the first packet sent by the terminal device. Of course, the cache described below may be a cache in a network device, for example, the cache 322 in FIG. 3-a. The memory may be memory in a network device. For example, it may be memory 323 in Figure 3-a.
第一报文的目的设备的IP地址被称为第一报文的目的IP地址,表示第一报文需要被发送到哪个设备。那么,在接收到第一报文后,处理器可以对第一报文进行解析,从而确定第一报文的目的IP地址。The IP address of the destination device of the first packet is called the destination IP address of the first packet, and indicates to which device the first packet needs to be sent. Then, after receiving the first packet, the processor may parse the first packet to determine the destination IP address of the first packet.
S402:处理器从缓存中查找与目的IP地址匹配的路由前缀。S402: The processor searches the cache for a routing prefix matching the destination IP address.
在确定第一报文的目的地址后,处理器可以从缓存中查找与目的IP地址相匹配的路由前缀,例如处理器可以从缓存路由表中查找与目的IP地址相匹配的路由前缀。当缓存路由表中存在多条与目的IP地址相匹配的路由前缀时,处理器可以将长度最长的路由前缀确定 为与目的IP地址相匹配的路由前缀。在一些可能的实现中,处理器还可以将缓存路由表转换为对应的二叉树或多叉树等树结构,并通过树结构确定与目的IP地址相匹配的路由前缀。After determining the destination address of the first packet, the processor may look up the routing prefix matching the destination IP address from the cache, for example, the processor may look up the routing prefix matching the destination IP address from the cached routing table. When there are multiple routing prefixes matching the destination IP address in the cache routing table, the processor can determine the routing prefix with the longest length as the routing prefix matching the destination IP address. In some possible implementations, the processor may also convert the cache routing table into a corresponding tree structure such as a binary tree or a polytree, and determine a routing prefix matching the destination IP address through the tree structure.
如果处理器能够从缓存中找到与目的IP地址相匹配的路由前缀,处理器可以从缓存中获取该目的IP地址对应路由信息,从而通过该路由信息转发第一报文。如果处理器无法从缓存中找到与目的IP地址相匹配的路由前缀,说明缓存路由表中未存储目的IP地址对应的路由前缀。那么处理器可以从存储器中查找与目的IP地址匹配的路由前缀和路由信息,并根据查找到的路由前缀和路由信息更新缓存路由表。If the processor can find a routing prefix matching the destination IP address from the cache, the processor can obtain routing information corresponding to the destination IP address from the cache, and forward the first packet through the routing information. If the processor cannot find a routing prefix matching the destination IP address from the cache, it means that the routing prefix corresponding to the destination IP address is not stored in the cache routing table. Then the processor can look up the routing prefix and routing information matching the destination IP address from the memory, and update the cache routing table according to the found routing prefix and routing information.
可选地,更新缓存路由表之前,处理器可以先判断缓存路由表中是否存在用于存储路由前缀和路由信息的存储空间。如果缓存的存储空间已满,处理器可以不更新缓存路由表,或者将缓存中已存储的路由前缀和路由信息删除,从而利用新的存储空间存储新的路由前缀和路由信息。Optionally, before updating the cache routing table, the processor may first determine whether there is a storage space for storing routing prefixes and routing information in the cache routing table. If the storage space of the cache is full, the processor may not update the cache routing table, or delete the routing prefix and routing information already stored in the cache, so as to use the new storage space to store the new routing prefix and routing information.
下面介绍在从缓存中不包括与目的IP地址相匹配的路由前缀的情况下,处理器更新缓存路由表的方法。The following describes a method for the processor to update the cache routing table in the case that the routing prefix matching the destination IP address is not included in the slave cache.
S403:响应于所述缓存未存储所述路由前缀,所述处理器从存储器中查找与所述目的IP地址相对应的前缀节点和路由信息。S403: In response to the cache not storing the routing prefix, the processor searches the memory for a prefix node and routing information corresponding to the destination IP address.
如果缓存中未存储与目的IP地址相对应的路由前缀,处理器可以从存储器中查找与目的IP地址相对应的路由前缀和路由信息。可选地,处理器可以通过与路由表对应的树结构确定与目的IP地址相对应的路由前缀。那么,处理器可以从与路由表对应的树结构中确定与目的IP地址对应的前缀节点,并获取该前缀节点的路由信息。If the routing prefix corresponding to the destination IP address is not stored in the cache, the processor may look up the routing prefix and routing information corresponding to the destination IP address from the memory. Optionally, the processor may determine the routing prefix corresponding to the destination IP address through the tree structure corresponding to the routing table. Then, the processor can determine the prefix node corresponding to the destination IP address from the tree structure corresponding to the routing table, and obtain the routing information of the prefix node.
下面介绍处理器确定前缀节点的方法。The method by which the processor determines the prefix node is described below.
假设存储器中存储的路由表如表4所示:Assume that the routing table stored in the memory is shown in Table 4:
表4Table 4
路由前缀routing prefix 路由信息routing information
0*0* 网络接口X network interfaceX
11*11* 网络接口Anetwork interface A
0000*0000* 网络接口Bnetwork interface B
0001010*0001010* 网络接口Cnetwork interface C
00010111*00010111* 网络接口Dnetwork interface D
0001011111*0001011111* 网络接口Enetwork interface E
00010110000*00010110000* 网络接口Fnetwork interface F
00010110010*00010110010* 网络接口Gnetwork interface G
该路由表对应的属性结构的示意图可以如图5所示。其中,图5中各个节点内的数字表示该节点的编号。那么,其中节点2为对应路由前缀0*的前缀节点;节点2为前缀节点,对应路由前缀11*;节点7为对应路由前缀0000*的前缀节点;节点11为对应路由前缀0001010*的前缀节点;节点14为对应路由前缀00010111*的前缀节点;节点19为对应路由 前缀0001011111*的前缀节点;节点20为对应路由前缀00010110000*的前缀节点;21节点21为对应路由前缀00010110010*的前缀节点。A schematic diagram of the attribute structure corresponding to the routing table may be shown in FIG. 5 . The numbers in each node in FIG. 5 represent the number of the node. Then, node 2 is the prefix node corresponding to routing prefix 0*; node 2 is the prefix node corresponding to routing prefix 11*; node 7 is the prefix node corresponding to routing prefix 0000*; node 11 is the prefix node corresponding to routing prefix 0001010* ; node 14 is the prefix node corresponding to the routing prefix 00010111*; node 19 is the prefix node corresponding to the routing prefix 0001011111*; node 20 is the prefix node corresponding to the routing prefix 00010110000*; 21 Node 21 is the prefix node corresponding to the routing prefix 00010110010*.
如果第一报文的目的IP地址为0001011010010001,由于该目的IP地址仅与路由前缀0*相匹配,处理器可以确定与目的IP地址对应的前缀节点为节点2,对应的路由信息为网络接口X。如果第一报文的目的IP地址为0001010010100010,由于该目的IP与路由前缀0*和路由前缀0001010*相匹配,且路由前缀0001010*的长度大于路由前缀0*的长度,处理器可以确定与目的IP地址对应的前缀节点为节点11,对应的路由信息为网络接口C。If the destination IP address of the first packet is 0001011010010001, since the destination IP address only matches the routing prefix 0*, the processor can determine that the prefix node corresponding to the destination IP address is node 2, and the corresponding routing information is network interface X . If the destination IP address of the first packet is 0001010010100010, since the destination IP matches the route prefix 0* and the route prefix 0001010*, and the length of the route prefix 0001010* is greater than the length of the route prefix 0*, the processor can determine that the destination IP address is the same as the destination IP address. The prefix node corresponding to the IP address is node 11, and the corresponding routing information is network interface C.
在实际的应用场景中,路由表中存储的对应关系的数量往往较多,对应的树结构也较为复杂。那么,为了快速找到与目的IP地址对应的前缀节点,可以将路由表对应的树结构拆分为多个子树结构,这些子树结构的根节点组成的树结构被称为虚拟树结构。每个子树结构的根节点对应一个虚拟前缀。子树结构中各个节点代表的路由前缀可以根据虚拟前缀和该节点在虚拟树结构中的位置确定。例如,假设某个子树结构的虚拟前缀为1000*,那么该子树结构的根节点的右孩子节点对应的路由前缀即为10001*。In practical application scenarios, the number of correspondences stored in the routing table is often large, and the corresponding tree structure is also complex. Then, in order to quickly find the prefix node corresponding to the destination IP address, the tree structure corresponding to the routing table can be divided into multiple sub-tree structures, and the tree structure composed of the root nodes of these sub-tree structures is called a virtual tree structure. The root node of each subtree structure corresponds to a virtual prefix. The routing prefix represented by each node in the subtree structure can be determined according to the virtual prefix and the position of the node in the virtual tree structure. For example, if the virtual prefix of a subtree structure is 1000*, then the routing prefix corresponding to the right child node of the root node of the subtree structure is 10001*.
在查找目的IP地址对应的路由前缀时,处理器可以先从虚拟树结构中查找与目的IP地址最长匹配的虚拟前缀,从与目的IP地址相匹配的虚拟前缀中确定长度最长的虚拟前缀。接着,处理器可以从该虚拟前缀对应的子树结构中确定与目的IP地址匹配的前缀节点。如果虚拟前缀对应的子树中不存在与目的IP地址相匹配的前缀节点,处理器可以将该虚拟前缀对应的前缀节点确定为目的IP地址的前缀节点。When searching for the routing prefix corresponding to the destination IP address, the processor can first search the virtual prefix with the longest matching destination IP address from the virtual tree structure, and determine the virtual prefix with the longest length from the virtual prefixes matching the destination IP address. . Next, the processor may determine a prefix node matching the destination IP address from the sub-tree structure corresponding to the virtual prefix. If there is no prefix node matching the destination IP address in the subtree corresponding to the virtual prefix, the processor may determine the prefix node corresponding to the virtual prefix as the prefix node of the destination IP address.
举例说明。对于图5所示的二叉树,可以将其划分为三个子树结构。这三个子树结构的根节点分别为根节点1、节点6和节点12,虚拟前缀分别为*、00*和0001011*。那么,当用表格的形式表示该虚拟树结构时,该表格可以如表6所示。三个子树可以如图6所示。for example. For the binary tree shown in Figure 5, it can be divided into three subtree structures. The root nodes of the three subtree structures are root node 1, node 6, and node 12, respectively, and the virtual prefixes are *, 00*, and 0001011*, respectively. Then, when the virtual tree structure is represented in the form of a table, the table can be as shown in Table 6. The three subtrees can be shown in Figure 6.
表6Table 6
虚拟前缀virtual prefix 前缀长度prefix length 子树信息subtree information
** 00 子树0 subtree 0
00*00* 22 子树1 subtree 1
0001011*0001011* 77 子树2 subtree 2
其中,表6的第一行表示长度为0的虚拟前缀为*与子树0对应,即目的IP地址不与表6中其他虚拟前缀匹配的情况下,处理器可以从子树0中确定与目的IP地址确定的前缀节点。表6的第二行表示长度为2的虚拟前缀00*与子树1对应。表6的第三行表示长度为7的虚拟前缀0001011*与子树2对应。Among them, the first row of Table 6 indicates that the virtual prefix of length 0 is * and corresponds to subtree 0, that is, if the destination IP address does not match other virtual prefixes in Table 6, the processor can determine from subtree 0 that the The prefix node identified by the destination IP address. The second row of Table 6 indicates that the virtual prefix 00* of length 2 corresponds to subtree 1. The third row of Table 6 indicates that the virtual prefix 0001011* of length 7 corresponds to subtree 2.
在接收到目的IP地址为0001010010100010的第一报文时,由于该目的IP地址与虚拟前缀00*最长匹配,处理器可以从子树1中查找与目的IP地址匹配的前缀节点。由于子树1中节点11的路由前缀为0001010*与目的IP地址相匹配,且节点11为前缀节点,那么处理器可以将路由前缀0001010*确定为与目的IP地址0001010010100010相匹配的路由前缀,节点11为对应的前缀节点。When receiving the first packet with the destination IP address of 0001010010100010, since the destination IP address matches the virtual prefix 00* the longest, the processor can search for a prefix node matching the destination IP address from subtree 1. Since the routing prefix of node 11 in subtree 1 is 0001010* which matches the destination IP address, and node 11 is a prefix node, then the processor can determine the routing prefix 0001010* as the routing prefix matching the destination IP address 0001010010100010, the node 11 is the corresponding prefix node.
在接收到目的IP地址为0001011010010001的第一报文时,由于该目的IP地址与虚拟 前缀00*最长匹配,处理器可以从子树1中查找与目的IP地址匹配的前缀节点。由于子树1中不具有目的IP地址相匹配的前缀节点,处理器可以将虚拟前缀00*对应的前缀节点确定为目的IP地址对应的前缀节点。那么处理器可以确定与目的IP地址0001011010010001匹配的前缀节点为节点2,匹配的路由前缀为0*。When receiving the first packet with the destination IP address 0001011010010001, since the destination IP address matches the virtual prefix 00* the longest, the processor can search for the prefix node matching the destination IP address from subtree 1. Since there is no prefix node matching the destination IP address in the subtree 1, the processor may determine the prefix node corresponding to the virtual prefix 00* as the prefix node corresponding to the destination IP address. Then the processor can determine that the prefix node matching the destination IP address 0001011010010001 is node 2, and the matching route prefix is 0*.
S404:所述处理器根据所述前缀节点和路由信息确定对应关系集合。S404: The processor determines a correspondence set according to the prefix node and routing information.
在确定与目的IP地址相对应的前缀节点和路由信息后,处理器可以根据前缀节点和路由信息确定对应关系集合。其中,对应关系集合可以包括前缀节点的路由前缀与路由信息之间的对应关系,也可以包括第一路由前缀与路由信息之间的对应关系。在本申请实施例中,第一路由前缀与路由信息之间的对应关系可以被称为第一对应关系。具体地,当与目的IP地址匹配的前缀节点为叶子节点时,对应关系可以包括前缀节点的路由前缀与路由信息之间的对应关系;当与目的IP地址匹配的前缀节点不为叶子节点时,对应关系可以包括第一对应关系。有关第一路由前缀的介绍可以参见下文。After determining the prefix node and routing information corresponding to the destination IP address, the processor may determine the corresponding relationship set according to the prefix node and the routing information. The correspondence set may include the correspondence between the routing prefix of the prefix node and the routing information, and may also include the correspondence between the first routing prefix and the routing information. In this embodiment of the present application, the correspondence between the first routing prefix and the routing information may be referred to as the first correspondence. Specifically, when the prefix node matching the destination IP address is a leaf node, the corresponding relationship may include the corresponding relationship between the routing prefix of the prefix node and the routing information; when the prefix node matching the destination IP address is not a leaf node, The correspondence may include a first correspondence. For the introduction of the first routing prefix, please refer to the following.
下面分别对这两种情况进行介绍。The two cases are described below.
在第一种可能的实现中,与目的IP地址匹配的前缀节点为叶子节点,即查找路径的尾节点为前缀节点,那么处理器可以确定对应关系为该前缀节点的路由前缀和路由信息之间的对应关系。In the first possible implementation, the prefix node matching the destination IP address is the leaf node, that is, the tail node of the search path is the prefix node, then the processor can determine that the corresponding relationship is between the routing prefix of the prefix node and the routing information corresponding relationship.
由于叶子节点为不具有子节点的节点,该前缀节点也不具有子节点。也就是说,在路由表所记载的一个或多个路由前缀中,不存在前n位与该路由前缀一致,且长度大于n的其他路由前缀。其中,n为该路由前缀的长度。Since a leaf node is a node without child nodes, the prefix node does not have child nodes either. That is, in one or more routing prefixes recorded in the routing table, there is no other routing prefix whose first n bits are consistent with the routing prefix and whose length is greater than n. Among them, n is the length of the routing prefix.
仍以图5为例进行说明,假设目的IP地址为0001010010100010,那么与该目的IP地址相匹配的前缀节点为节点11。节点11作为叶子节点,并没有子节点。如果节点11具有左孩子节点或右孩子节点,那么节点11的左孩子节点对应的路由前缀为00010100*,节点11的右孩子节点对应队列路由前缀为00010101*。由于这两个子节点并不存在,说明路由表不包括00010100*和00010101*两个路由前缀,自然也不包括其他前7位为0001010且长度大于7的路由前缀。Still taking FIG. 5 as an example for description, assuming that the destination IP address is 0001010010100010, the prefix node matching the destination IP address is node 11 . Node 11 is a leaf node and has no child nodes. If node 11 has a left child node or a right child node, the routing prefix corresponding to the left child node of node 11 is 00010100*, and the queue routing prefix corresponding to the right child node of node 11 is 00010101*. Since these two child nodes do not exist, it means that the routing table does not include the two routing prefixes 00010100* and 00010101*, and naturally does not include other routing prefixes whose first 7 digits are 0001010 and whose length is greater than 7.
可见,由于路由表中不存在前n位与前缀节点的路由前缀一致,且长度大于n的其他路由前缀(n为该路由前缀的长度)。自然,与该前缀节点的路由前缀相匹配的目的IP地址不可能与其他长度大于n的路由前缀匹配。因此,在前缀节点的路由前缀存储到缓存路由表之后,不会出现虚假命中的情况,即不会出现目的IP地址本应匹配一个长度大于n的路由前缀,却因缓存路由表中存储的路由前缀不全匹配到该路由前缀的情况。It can be seen that there are no other routing prefixes whose first n bits are consistent with the routing prefix of the prefix node and whose length is greater than n (n is the length of the routing prefix) in the routing table. Naturally, the destination IP address matching the routing prefix of this prefix node cannot possibly match other routing prefixes whose length is greater than n. Therefore, after the routing prefix of the prefix node is stored in the cache routing table, there will be no false hits, that is, the destination IP address should match a routing prefix with a length greater than n, but the route stored in the cache routing table will not occur. When the prefix does not exactly match the prefix of the route.
那么,处理器可以从存储器中获取前缀节点的路由前缀对应的路由信息,以便在后续步骤中将该路由前缀和路由信息之间的对应关系存储到缓存。Then, the processor may obtain the routing information corresponding to the routing prefix of the prefix node from the memory, so as to store the corresponding relationship between the routing prefix and the routing information in the cache in a subsequent step.
在第二种可能的实现中,与目的IP地址匹配的前缀节点不为叶子节点,即查找路径的尾节点不为前缀节点,那么对应关系集合可以包括第一对应关系。在确定第一对应关系时,处理器可以先确定第一路由前缀。其中,第一路由前缀与目的IP地址相匹配,且其长度是根据第一前缀匹配长度确定的,第一前缀匹配长度为从树结构的根节点到查找路径的尾节点的长度,即查找路径的尾节点到根节点之间的节点的数量加1。In the second possible implementation, the prefix node matching the destination IP address is not a leaf node, that is, the tail node of the search path is not a prefix node, then the correspondence set may include the first correspondence. When determining the first correspondence, the processor may first determine the first routing prefix. The first routing prefix matches the destination IP address, and its length is determined according to the first prefix matching length. The first prefix matching length is the length from the root node of the tree structure to the tail node of the search path, that is, the search path The number of nodes between the tail node and the root node is incremented by 1.
在本申请实施例中,第一路由前缀的长度可以大于第一前缀匹配长度,也可以等于第一前缀匹配长度,还可以小于第一前缀匹配长度。下面分别进行介绍。In this embodiment of the present application, the length of the first routing prefix may be greater than the first prefix matching length, may also be equal to the first prefix matching length, or may be smaller than the first prefix matching length. They are introduced separately below.
首先介绍第一路由前缀大于第一前缀匹配长度的情况。First, the case where the first routing prefix is greater than the matching length of the first prefix is introduced.
在路由表对应的树结构中,由于目的IP地址对应的前缀节点不为叶子节点,说明该前缀节点的子树中包括其他前缀节点,即缓存路由表中存在包括目的IP地址对应的路由前缀的其他路由前缀,且这些路由前缀与目的IP地址并不匹配。因此,为了避免虚假命中,处理器可以将路由表对应的树结构以外,且与目的IP地址相匹配的路由前缀确定为第一路由前缀。In the tree structure corresponding to the routing table, since the prefix node corresponding to the destination IP address is not a leaf node, it means that the subtree of the prefix node includes other prefix nodes, that is, the cache routing table contains the routing prefix corresponding to the destination IP address. Other routing prefixes, and these routing prefixes do not match the destination IP address. Therefore, in order to avoid false hits, the processor may determine a routing prefix that is outside the tree structure corresponding to the routing table and that matches the destination IP address as the first routing prefix.
具体地,处理器可以从目的IP地址中选取长度大于第一前缀匹配长度的部分作为第一路由前缀。其中,第一前缀匹配长度为从树结构的根节点到目的IP地址的查找路径的尾节点的长度,即该尾节点对应的路由前缀的长度。由于目的IP地址对应的前缀节点不为叶子节点,查找路径中的尾节点不为前缀节点,说明目的IP地址对应的树结构与转发表对应的树结构从尾节点的位置开始出现差异。因此,从目的IP地址中选取长度大于第一前缀匹配长度的部分作为第一路由前缀,可以确保第一路由前缀对应的尾节点在转发表对应的树结构以外,即第一路由前缀与路由表对应的树结构中任意一条路由前缀均不重合。这样,路由表中没有记载第一路由前缀,自然也不可能记载长度长于第一路由前缀且包括第一路由前缀的其他路由前缀。也就是说,假设第一路由前缀的长度为n,那么路由表中不存在前n位与目的IP地址一致,且长度大于n的其他路由前缀。自然,包括第一路由前缀的任意一个IP地址不可能与目的路由表中长度大于n的路由前缀相匹配。因此,在前缀节点的路由前缀存储到缓存路由表之后,不会出现虚假命中的情况,即不会出现目的IP地址本应匹配一个长度大于n的路由前缀,却因缓存路由表中存储的路由前缀不全匹配到该路由前缀的情况。Specifically, the processor may select a portion of the destination IP address whose length is greater than the matching length of the first prefix as the first routing prefix. The first prefix matching length is the length of the tail node of the search path from the root node of the tree structure to the destination IP address, that is, the length of the routing prefix corresponding to the tail node. Since the prefix node corresponding to the destination IP address is not a leaf node, and the tail node in the search path is not a prefix node, it means that the tree structure corresponding to the destination IP address and the tree structure corresponding to the forwarding table are different from the position of the tail node. Therefore, selecting the part of the destination IP address whose length is greater than the matching length of the first prefix as the first routing prefix can ensure that the tail node corresponding to the first routing prefix is outside the tree structure corresponding to the forwarding table, that is, the first routing prefix and the routing table Any route prefix in the corresponding tree structure does not overlap. In this way, the first routing prefix is not recorded in the routing table, and naturally it is impossible to record other routing prefixes whose length is longer than that of the first routing prefix and includes the first routing prefix. That is to say, assuming that the length of the first routing prefix is n, then there is no other routing prefix whose first n bits are consistent with the destination IP address and whose length is greater than n in the routing table. Naturally, any IP address including the first routing prefix cannot match the routing prefix whose length is greater than n in the destination routing table. Therefore, after the routing prefix of the prefix node is stored in the cache routing table, there will be no false hits, that is, the destination IP address should match a routing prefix with a length greater than n, but the route stored in the cache routing table will not occur. When the prefix does not exactly match the prefix of the route.
仍以图5为例进行说明。假设目的IP地址为0001011010010001,与该目的IP地址相匹配的路由前缀为0*,该目的IP地址在树结构中的查找路径为“1-2-4-6-8-9-10-12-13”。其尾节点为节点13,第一前缀匹配长度为8。将该目的IP地址在路由表以外的部分通过树结构表示,得到的树结构可以如图7所示。在图5所示实施例的基础上,图7所示的树结构新增了节点22、节点23、节点24、节点25、节点26、节点27、包节点28和节点29。这些节点分别对应目的IP地址的第9-16位。由于这些节点在路由表对应的树结构中并不存在,这些节点又可以被称为虚拟节点。Still take FIG. 5 as an example for description. Assuming that the destination IP address is 0001011010010001, the routing prefix matching the destination IP address is 0*, and the search path of the destination IP address in the tree structure is "1-2-4-6-8-9-10-12- 13". Its tail node is node 13, and the first prefix matching length is 8. The part of the destination IP address outside the routing table is represented by a tree structure, and the obtained tree structure may be as shown in FIG. 7 . On the basis of the embodiment shown in FIG. 5 , node 22 , node 23 , node 24 , node 25 , node 26 , node 27 , package node 28 , and node 29 are newly added to the tree structure shown in FIG. 7 . These nodes correspond to bits 9-16 of the destination IP address, respectively. Since these nodes do not exist in the tree structure corresponding to the routing table, these nodes can also be called virtual nodes.
由于虚拟节点位于目的IP地址对应的树结构在路由表的树结构以外的部分,虚拟节点对应的路由前缀大于第一前缀匹配长度。因此,在确定第一路由前缀时,处理器可以将任意一个虚拟节点对应的路由前缀确定为第一路由前缀。例如处理器可以将直接与尾节点相连的虚拟节点对应的路由前缀确定为第一路由前缀。在图6所示的实施例中,处理器可以将节点22对应的路由前缀000101101*确定为第一路由前缀,该第一路由前缀的长度为第一前缀匹配长度加一。当然,在一些可能的实现方式中,处理器还可以将其他任意一个虚拟节点对应的路由前缀确定为第一路由前缀。例如可以将节点24对应的路由前缀00010110100*确定为第一路由前缀。Since the virtual node is located in a part of the tree structure corresponding to the destination IP address outside the tree structure of the routing table, the routing prefix corresponding to the virtual node is greater than the first prefix matching length. Therefore, when determining the first routing prefix, the processor may determine the routing prefix corresponding to any virtual node as the first routing prefix. For example, the processor may determine the routing prefix corresponding to the virtual node directly connected to the tail node as the first routing prefix. In the embodiment shown in FIG. 6 , the processor may determine the routing prefix 000101101* corresponding to the node 22 as the first routing prefix, and the length of the first routing prefix is the first prefix matching length plus one. Certainly, in some possible implementation manners, the processor may also determine the routing prefix corresponding to any other virtual node as the first routing prefix. For example, the routing prefix 00010110100* corresponding to the node 24 may be determined as the first routing prefix.
根据前文介绍可知,在确定与目的IP地址匹配的前缀节点时,处理器可以先根据虚拟树结构确定目的IP地址对应的虚拟前缀和子树结构,再根据子树结构确定与目的IP地址匹配的前缀节点。相似的,处理器也可以通过虚拟树结构确定第一路由前缀。According to the above description, when determining the prefix node matching the destination IP address, the processor can first determine the virtual prefix and subtree structure corresponding to the destination IP address according to the virtual tree structure, and then determine the prefix matching the destination IP address according to the subtree structure. node. Similarly, the processor may also determine the first routing prefix through the virtual tree structure.
具体地,假设第一长度为虚拟树结构的根节点到与目的IP地址对应的虚拟前缀的长度,即与目的IP地址匹配的虚拟前缀的长度,第二长度为该虚拟前缀到查找路径的尾节点之间的长度,即与目的IP地址对应的子树结构中根节点到尾节点的长度。由于目的IP地址的查找路径为虚拟树结构的根节点到虚拟前缀对应的子树结构的根节点,再从该子树结构的根节点到尾节点,那么第一长度与第二长度之和为第一前缀匹配长度。在确定第一路由前缀时,处理器可以将虚拟前缀确定为第一路由前缀的前半部分,再从目的IP地址中选择长度大于第二长度的部分确定为第一路由前缀的后半部分。Specifically, it is assumed that the first length is the length from the root node of the virtual tree structure to the virtual prefix corresponding to the destination IP address, that is, the length of the virtual prefix matching the destination IP address, and the second length is the virtual prefix to the end of the search path The length between nodes, that is, the length from the root node to the tail node in the subtree structure corresponding to the destination IP address. Since the search path of the destination IP address is from the root node of the virtual tree structure to the root node of the subtree structure corresponding to the virtual prefix, and then from the root node of the subtree structure to the tail node, the sum of the first length and the second length is The first prefix matches the length. When determining the first routing prefix, the processor may determine the virtual prefix as the first half of the first routing prefix, and then select the part whose length is greater than the second length from the destination IP address to determine the second half of the first routing prefix.
以图6所示的实施例为例进行说明,假设目的IP地址为0001011010010001,那么与目的IP地址匹配的虚拟前缀为节点12对应的虚拟前缀,即0001011*。处理器可以将第一路由前缀的前7位确定为0001011*。由于目的IP地址在子树2中的尾节点为节点13,节点12到节点13的长度为1,即第二长度为1,处理器可以从目的IP地址的第8位开始截取长度大于1的部分作为第一路由前缀的后半部分。例如,处理器可以将目的IP地址的第8位和第9位作为第一路由前缀的后半部分,得到的第一路由前缀为000101101*。Taking the embodiment shown in FIG. 6 as an example for description, assuming that the destination IP address is 0001011010010001, the virtual prefix matching the destination IP address is the virtual prefix corresponding to the node 12, that is, 0001011*. The processor may determine the first 7 bits of the first routing prefix as 0001011*. Since the tail node of the destination IP address in subtree 2 is node 13, and the length from node 12 to node 13 is 1, that is, the second length is 1, the processor can intercept the length greater than 1 from the 8th bit of the destination IP address. part as the second half of the first routing prefix. For example, the processor may use the 8th and 9th digits of the destination IP address as the second half of the first routing prefix, and the obtained first routing prefix is 000101101*.
下面介绍第一路由前缀的长度等于第一前缀匹配长度的情况。The following describes the case where the length of the first routing prefix is equal to the matching length of the first prefix.
在实际的应用场景中,由于路由表的修改与树结构的修改可能并不同步,树结构中的叶子节点可能并不是前缀节点。那么,当与目的IP地址对应的前缀节点不为叶子节点,且目的IP地址在树结构中的查找路径的尾节点为叶子节点,处理器可以将该叶子节点对应的路由前缀确定为第一路由前缀。这样,第一路由前缀的长度还可以等于第一前缀匹配长度。In an actual application scenario, since the modification of the routing table may not be synchronized with the modification of the tree structure, the leaf nodes in the tree structure may not be prefix nodes. Then, when the prefix node corresponding to the destination IP address is not a leaf node, and the tail node of the search path of the destination IP address in the tree structure is a leaf node, the processor may determine the route prefix corresponding to the leaf node as the first route prefix. In this way, the length of the first routing prefix may also be equal to the matching length of the first prefix.
具体的,在路由表中某个路由前缀被删除以后,树结构中该路由前缀对应的节点(后称节点A)可能还未被删除。但是由于路由表已被修改,节点A并不为前缀节点。如果节点A不具有子节点,那么节点A即为树结构中不为前缀节点的叶子节点。Specifically, after a certain routing prefix in the routing table is deleted, the node (hereinafter referred to as node A) corresponding to the routing prefix in the tree structure may not be deleted. But since the routing table has been modified, node A is not a prefix node. If node A has no child nodes, then node A is a leaf node that is not a prefix node in the tree structure.
例如,在图5所示实施例中,假设路由前缀0000*从路由表中被删除,但是树结构中可能仍然保留有节点7。那么该节点7为非前缀节点的叶子节点。For example, in the embodiment shown in Figure 5, it is assumed that the routing prefix 0000* is deleted from the routing table, but node 7 may still remain in the tree structure. Then the node 7 is a leaf node of the non-prefix node.
在接收到第一报文后,如果第一报文的目的IP地址为0000101010101010,那么与该目的IP地址相匹配的路由前缀为0*,对应的前缀节点为节点2,查找路径的尾节点为节点7,节点7的路由前缀为0000*,第一前缀匹配长度为4。那么,处理器可以将节点7的路由前缀0000*确定为第一路由前缀。可见,在这种情况下,第一路由前缀的长度与第一前缀匹配长度一致。After receiving the first packet, if the destination IP address of the first packet is 0000101010101010, the route prefix matching the destination IP address is 0*, the corresponding prefix node is node 2, and the tail node of the search path is Node 7, the routing prefix of node 7 is 0000*, and the first prefix matching length is 4. Then, the processor may determine the routing prefix 0000* of the node 7 as the first routing prefix. It can be seen that in this case, the length of the first routing prefix is the same as the matching length of the first prefix.
下面介绍第一路由前缀的长度小于第一前缀匹配长度的情况。The following describes the case where the length of the first routing prefix is smaller than the matching length of the first prefix.
在一些可能的实现中,第一路由前缀的长度也可以小于第一前缀匹配长度,且大于前缀节点对应的路由前缀的长度,即存储器路由表中与目的IP地址相匹配的路由前缀的长度。也就是说,第一路由前缀在树结构中对应的节点为查找路径中前缀节点下层,尾节点上层的节点。这样,虽然第一路由前缀的长度小于第一前缀匹配长度,但是由于第一路由前缀的长度仍然大于存储器路由表中与目的IP地址相匹配的路由前缀的长度,那么相较于现有 技术,将第一路由前缀和路由信息的对应关系存储到缓存,仍然可以起到减小虚假命中出现的概率的作用。容易理解的是,第一路由前缀的长度越长,出现虚假命中的概率也就越小。当第一路由前缀的长度大于第一前缀匹配长度时,出现虚假命中的概率为0.In some possible implementations, the length of the first routing prefix may also be less than the first prefix matching length and greater than the length of the routing prefix corresponding to the prefix node, that is, the length of the routing prefix matching the destination IP address in the memory routing table. That is to say, the node corresponding to the first routing prefix in the tree structure is the node in the lower layer of the prefix node and the upper layer of the tail node in the search path. In this way, although the length of the first routing prefix is less than the matching length of the first prefix, since the length of the first routing prefix is still greater than the length of the routing prefix matching the destination IP address in the memory routing table, compared with the prior art, Storing the correspondence between the first routing prefix and the routing information in the cache can still play a role in reducing the probability of false hits. It is easy to understand that the longer the length of the first routing prefix, the smaller the probability of false hits. When the length of the first routing prefix is greater than the first prefix matching length, the probability of false hits is 0.
举例说明。假设目的IP地址为目的IP地址为0001011010010001,那么与目的IP地址匹配的前缀节点为节点2,对应的路由前缀的长度为1,尾节点为节点12,对应的第一前缀匹配长度为8。那么,处理器可以从目的IP地址的前m位作为第一路由前缀,其中,m为大于1小于8的正整数。例如,处理器可以将路由前缀00010110*确定为第一路由前缀。for example. Assuming that the destination IP address is 0001011010010001, the prefix node matching the destination IP address is node 2, the length of the corresponding routing prefix is 1, the tail node is node 12, and the corresponding first prefix matching length is 8. Then, the processor can use the first m bits of the destination IP address as the first routing prefix, where m is a positive integer greater than 1 and less than 8. For example, the processor may determine the routing prefix 00010110* as the first routing prefix.
上面介绍了处理器确定第一路由前缀的方法,在确定第一路由前缀后,处理器可以根据与目的IP地址相匹配的路由前缀,从存储器存储的路由表中查找路由信息,进而将该路由信息和第一路由前缀之间的对应关系确定为第一对应关系。The method for the processor to determine the first routing prefix is described above. After determining the first routing prefix, the processor can look up routing information from the routing table stored in the memory according to the routing prefix matching the destination IP address, and then use the routing prefix. The correspondence between the information and the first routing prefix is determined as the first correspondence.
可选地,当处理器通过虚拟树结构确定与目的IP地址相匹配的前缀节点时,对应关系集合中还可以包括第三对应关系。其中,第三对应关系可以包括虚拟前缀、虚拟前缀的类型和子树结构的信息。其中,虚拟前缀为与目的IP地址相匹配的虚拟前缀,子树结构的信息用于表示目的IP地址对应哪个子树。虚拟前缀的类型用于指示在虚拟前缀被命中时,根据子树结构的信息查找对应的子树结构。Optionally, when the processor determines the prefix node matching the destination IP address through the virtual tree structure, the correspondence set may further include a third correspondence. Wherein, the third corresponding relationship may include information about virtual prefixes, types of virtual prefixes, and subtree structures. The virtual prefix is a virtual prefix matching the destination IP address, and the information of the subtree structure is used to indicate which subtree the destination IP address corresponds to. The type of the virtual prefix is used to indicate that when the virtual prefix is hit, the corresponding subtree structure is searched according to the information of the subtree structure.
也就是说,在接收到新的报文后,如果该报文的目的IP地址与缓存中存储的虚拟前缀相匹配,处理器可以根据虚拟前缀的类型需要查找与虚拟前缀对应的子树结构,从而根据第三对应关系确定与虚拟前缀对应的子树结构,进而根据子树结构确定与目的IP地址相匹配的路由前缀。That is to say, after receiving a new packet, if the destination IP address of the packet matches the virtual prefix stored in the cache, the processor can search for the subtree structure corresponding to the virtual prefix according to the type of the virtual prefix. Therefore, the sub-tree structure corresponding to the virtual prefix is determined according to the third correspondence, and the routing prefix matching the destination IP address is further determined according to the sub-tree structure.
为了提高查找效率,在一些可能的实现方式中,对应关系集合还可以包括第二对应关系。第二对应关系为第二路由前缀和路由信息之间的对应关系。其中,路由信息为第一报文的目的IP地址对应的路由前缀的路由信息。To improve search efficiency, in some possible implementations, the set of correspondences may further include a second correspondence. The second correspondence is the correspondence between the second routing prefix and the routing information. The routing information is routing information of a routing prefix corresponding to the destination IP address of the first packet.
下面介绍处理器确定第二路由前缀的方法。The following describes a method for the processor to determine the second routing prefix.
在确定目的IP地址对应的前缀节点不为叶子节点后,处理器可以根据树结构确定查找路径中前缀节点以后的上所有的独子节点,即仅具有左孩子节点或右孩子节点的节点。接着,处理器可以将该独子节点对应的路由前缀的长度确定为第二前缀匹配长度。即第二前缀匹配长度等于树结构的根节点到该独子节点之间的长度。接着,处理器可以根据第二前缀匹配长度和目的IP地址确定第二路由前缀。假设第二前缀匹配长度为n,处理器可以将目的IP地址的前n为确定为第二路由前缀。After determining that the prefix node corresponding to the destination IP address is not a leaf node, the processor can determine all the only-child nodes after the prefix node in the search path according to the tree structure, that is, nodes with only left child nodes or right child nodes. Next, the processor may determine the length of the routing prefix corresponding to the single-child node as the second prefix matching length. That is, the length of the second prefix matching is equal to the length between the root node of the tree structure and the single-child node. Next, the processor may determine the second routing prefix according to the second prefix matching length and the destination IP address. Assuming that the matching length of the second prefix is n, the processor may determine the first n of the destination IP address as the second routing prefix.
由于独子节点为目的IP地址的查找路径中前缀节点后的节点,说明任意一个独子节点对应的路由前缀均不在缓存路由表中,且与独子节点相匹配的报文对应的前缀节点均为目的IP地址的前缀节点。因此,与这些独子节点相匹配的IP地址的路由前缀均为前缀节点的路由前缀。又因为独子节点位于目的IP地址的查找路径上,目的IP地址中包括每个独子节点的路由前缀。因此,根据独子节点确定第二前缀匹配长度,再根据第二前缀匹配长度从目的IP地址中选取第二路由前缀,得到的第二路由前缀与目的IP地址的前缀节点对应的路由信息相匹配。因此,处理器可以记录第二路由前缀与路由信息之间的对应关系记录为第二对应关系,并加入对应关系集合以便缓存存储。Since the only-child node is the node after the prefix node in the search path of the destination IP address, it means that the routing prefix corresponding to any single-child node is not in the cache routing table, and the prefix node corresponding to the packet matching the only-child node is the destination IP address The prefix node for the address. Therefore, the routing prefixes of the IP addresses matching these only-child nodes are the routing prefixes of the prefix nodes. Also, because the only-child node is located on the search path of the destination IP address, the destination IP address includes the routing prefix of each only-child node. Therefore, the second prefix matching length is determined according to the only-child node, and then the second routing prefix is selected from the destination IP address according to the second prefix matching length, and the obtained second routing prefix matches the routing information corresponding to the prefix node of the destination IP address. Therefore, the processor may record the correspondence between the second routing prefix and the routing information as the second correspondence, and add the correspondence set for cache storage.
仍以图5所示实施例为例进行说明。在接收到了目的IP地址为0001011010010001的第一报文后,处理器可以确定前缀节点为节点2。尾节点为节点13,前缀节点与尾节点之间的独子节点包括节点4、节点8和节点9。其中节点4对应的第二前缀匹配长度为2、节点8的第二前缀匹配长度为4、节点9的第二前缀匹配长度为5。那么,处理器可以将目的IP地址的前2位、前4位和前5位分别确定为第二路由前缀,即路由前缀00*,路由前缀0001*和路由前缀00010*均为第二路由前缀。接着,处理器可以将这三条路由前缀和路由前缀0*对应的路由信息“网络接口X”之间的对应关系确定为第二对应关系。The embodiment shown in FIG. 5 is still taken as an example for description. After receiving the first packet with the destination IP address of 0001011010010001, the processor may determine that the prefix node is node 2. The tail node is node 13 , and the only child nodes between the prefix node and the tail node include node 4 , node 8 and node 9 . The second prefix matching length corresponding to node 4 is 2, the second prefix matching length of node 8 is 4, and the second prefix matching length of node 9 is 5. Then, the processor can determine the first 2 digits, the first 4 digits and the first 5 digits of the destination IP address as the second routing prefix respectively, that is, the routing prefix 00*, the routing prefix 0001* and the routing prefix 00010* are all the second routing prefix. . Next, the processor may determine the correspondence between the three routing prefixes and the routing information "network interface X" corresponding to the routing prefix 0* as the second correspondence.
S405:所述处理器触发所述缓存存储所述对应关系集合。S405: The processor triggers the cache to store the corresponding relationship set.
在得到对应关系集合后,处理器可以触发缓存存储对应关系集合。可选地,考虑到最长前缀匹配原则,处理器还可以触发缓存存储第一路由前缀的长度。After obtaining the corresponding relationship set, the processor may trigger the cache to store the corresponding relationship set. Optionally, considering the longest prefix matching principle, the processor may further trigger the cache to store the length of the first routing prefix.
另外,当对应关系集合中包括第一对应关系时,处理器还可以触发缓存存储第一路由前缀的类型。该第一路由前缀的类型用于指示处理器在第一路由前缀被命中时,根据第一对应关系在缓存中获取与第一路由前缀对应的路由信息。也就是说,在接收到新的报文后,如果该报文的目的IP地址与缓存中存储的第一路由前缀相匹配,处理器可以根据第一路由前缀的类型从缓存路由表中查找第一路由前缀对应的路由信息,无需从存储器中查找第一路由前缀对应的路由信息。In addition, when the correspondence set includes the first correspondence, the processor may further trigger the cache to store the type of the first routing prefix. The type of the first routing prefix is used to instruct the processor to obtain routing information corresponding to the first routing prefix in the cache according to the first correspondence when the first routing prefix is hit. That is to say, after receiving a new packet, if the destination IP address of the packet matches the first routing prefix stored in the cache, the processor can look up the first routing prefix from the cache routing table according to the type of the first routing prefix. For the routing information corresponding to a routing prefix, it is not necessary to search the routing information corresponding to the first routing prefix from the memory.
下面对TCAM目的IP地址查找对应的路由信息的过程进行介绍。The following describes the process of searching for the corresponding routing information by the destination IP address of the TCAM.
假设作为缓存路由表的TCAM中存储了路由前缀000101101*和网络接口X之间的对应关系,以及路由前缀0001011*和路由前缀0000*和网络接口B之间的对应关系。那么TCAM中存储的表项可以如表7所示。Assume that the TCAM serving as the cache routing table stores the correspondence between the routing prefix 000101101* and the network interface X, and the correspondence between the routing prefix 0001011* and the routing prefix 0000* and the network interface B. Then the entries stored in the TCAM can be as shown in Table 7.
表7Table 7
TCAM keyTCAM key TCAM maskTCAM mask TCAM ADTCAM AD
000101101*000101101* 11111111100000001111111110000000 网络接口Xnetwork interfaceX
0000*0000* 11110000000000001111000000000000 网络接口Bnetwork interface B
其中,表7中表头的第一项为TCAM掩码(TCAM key),用于记录待匹配的路由前缀。表7中表头的第一项为TCAM掩码(TCAM mask),用于检测目的IP地址与TCAM关键词的匹配程度。表7中表头的第一项为TCAM关联数据(Associated Data,AD),用于记录与TCAM关键词对应的路由信息。Among them, the first item of the header in Table 7 is the TCAM mask (TCAM key), which is used to record the routing prefix to be matched. The first item of the header in Table 7 is a TCAM mask (TCAM mask), which is used to detect the matching degree between the destination IP address and the TCAM keyword. The first item of the header in Table 7 is TCAM Associated Data (AD), which is used to record routing information corresponding to TCAM keywords.
表7中第一行表示TCAM可以通过TCAM掩码1111111110000000判断报文的目的IP地址是否与TCAM关键词000101101*匹配,并在确定目的IP地址TCAM关键词000101101*匹配后通过网络接口X发送。表7中第二行表示TCAM可以通过TCAM掩码1111000000000000判断报文的目的IP地址是否与TCAM关键词0000*匹配,并在确定目的IP地址TCAM关键词0000*匹配后通过网络接口B发送。The first row in Table 7 indicates that TCAM can use the TCAM mask 1111111110000000 to determine whether the destination IP address of the packet matches the TCAM keyword 000101101*, and send it through network interface X after determining that the destination IP address TCAM keyword 000101101* matches. The second row in Table 7 indicates that the TCAM can use the TCAM mask 1111000000000000 to determine whether the destination IP address of the packet matches the TCAM keyword 0000*, and send the packet through network interface B after determining that the destination IP address TCAM keyword 0000* matches.
在判断报文的目的IP地址是否与TCAM关键词匹配时,TCAM可以将TCAM掩码与目的IP地址逐位进行“与”运算,并将TCAM关键词和TCAM掩码也逐位进行“与”运算。最后再逐位比较两次运算得到的结果是否完全一致。若两次运算得到的结果完全一致, TCAM可以确定目的IP地址与TCAM关键词相匹配,从而根据TCAM关联数据中记载的路由信息发送该报文。When judging whether the destination IP address of the packet matches the TCAM keyword, the TCAM can perform an "AND" operation on the TCAM mask and the destination IP address bit by bit, and also perform an "AND" with the TCAM keyword and the TCAM mask bit by bit. operation. Finally, compare whether the results obtained by the two operations are completely consistent bit by bit. If the results obtained by the two operations are completely consistent, the TCAM can determine that the destination IP address matches the TCAM keyword, so as to send the packet according to the routing information recorded in the TCAM associated data.
举例说明。假设网络设备接收到了目的IP地址为0001011010010001的报文,处理器可以将目的IP地址0001011010010001分别与TCAM关键词1111111110000000和TCAM掩码1111000000000000进行逐位“与”运算。for example. Assuming that the network device receives the packet with the destination IP address 0001011010010001, the processor can perform a bit-by-bit AND operation on the destination IP address 0001011010010001 with the TCAM keyword 1111111110000000 and the TCAM mask 1111000000000000 respectively.
在进行逐位“与”运算时,如果目的IP地址与TCAM掩码在某一位上的值均为1,那么得到结果为1,若否,得到的结果为0。例如,目的IP地址的第一位为0,TCAM掩码1111111110000000的第一位为1,二者进行“与”运算得到的结果为0。目的IP地址的第四位为1,TCAM掩码1111111110000000的第四位为1,二者进行“与”运算得到的结果为1。During the bit-by-bit AND operation, if the value of the destination IP address and the TCAM mask in a certain bit is 1, the result is 1; otherwise, the result is 0. For example, the first bit of the destination IP address is 0, the first bit of the TCAM mask 1111111110000000 is 1, and the result of the AND operation between the two is 0. The fourth bit of the destination IP address is 1, the fourth bit of the TCAM mask 1111111110000000 is 1, and the result of the AND operation between the two is 1.
依此类推,目的IP地址0001011010010001与TCAM掩码1111111110000000进行逐位“与”运算得到的结果为0001011010000000。目的IP地址0001011010010001与TCAM掩码1111000000000000进行逐位“与”运算得到的结果为0001000000000000。同样,TCAM关键词000101101*与TCAM掩码1111111110000000进行逐位“与”运算得到的结果为0001011010000000。TCAM关键词0000*与TCAM掩码1111111110000000进行逐位“与”运算得到的结果为0000000000000000。By analogy, the result of the bitwise AND operation between the destination IP address 0001011010010001 and the TCAM mask 1111111110000000 is 0001011010000000. The result of the bitwise AND operation between the destination IP address 0001011010010001 and the TCAM mask 1111000000000000 is 0001000000000000. Similarly, the bitwise AND operation of the TCAM keyword 000101101* and the TCAM mask 1111111110000000 results in 0001011010000000. The bit-wise AND operation of the TCAM keyword 0000* and the TCAM mask 1111111110000000 results in 0000000000000000.
接着,由于目的IP地址运算得到的结果与TCAM关键词000101101*运算得到的结果完全一致,TCAM可以确定目的IP地址与路由前缀000101101*相匹配,从而通过网络接口X发送该报文。由于根据目的IP地址运算得到的结果与根据TCAM关键词0000*运算得到的结果不一致,TCAM可以确定目的IP地址与路由前缀0000*不匹配,从而不通过网络接口B发送该报文。Next, since the result obtained by the operation of the destination IP address is exactly the same as the result obtained by the operation of the TCAM keyword 000101101*, the TCAM can determine that the destination IP address matches the routing prefix 000101101*, so that the packet is sent through the network interface X. Since the result obtained by the operation based on the destination IP address is inconsistent with the result obtained by the operation based on the TCAM keyword 0000*, the TCAM can determine that the destination IP address does not match the routing prefix 0000*, so that the packet is not sent through the network interface B.
参见图8,本申请实施例还提供了一种集成电路800,该集成电路800可以实现图4所示实施例中处理器的功能。该集成电路包括接口电路801和控制电路802。所述控制电路801与接口电路802通过通信线路803连接。接口电路802用于使得芯片800通过通信链路,与其它设备相连。其中,所述接口电路601用于实现图4所示实施例中的S401、S402、S403和S405,所述控制电路802用于实现图4所示实施例中S402、S403、S404和S405。Referring to FIG. 8 , an embodiment of the present application further provides an integrated circuit 800 , and the integrated circuit 800 can implement the functions of the processor in the embodiment shown in FIG. 4 . The integrated circuit includes an interface circuit 801 and a control circuit 802 . The control circuit 801 and the interface circuit 802 are connected through a communication line 803 . The interface circuit 802 is used to connect the chip 800 with other devices through a communication link. The interface circuit 601 is used to implement S401 , S402 , S403 and S405 in the embodiment shown in FIG. 4 , and the control circuit 802 is used to implement S402 , S403 , S404 and S405 in the embodiment shown in FIG. 4 .
具体的,所述接口电路801,用于获取第一报文,所述第一报文包括目的互联网协议IP地址。Specifically, the interface circuit 801 is configured to acquire a first packet, where the first packet includes a destination Internet Protocol IP address.
所述控制电路802,用于从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。The control circuit 802 is configured to look up a routing prefix matching the destination IP address from the cache; in response to the routing prefix not being stored in the cache, look up a tree structure corresponding to the routing table according to the destination IP address , determine the prefix node matching the destination IP address; in response to the prefix node not being a leaf node, determine the first prefix matching length, the first prefix matching length is equal to the length between the root node and the tail node of the tree structure The length between the two, the tail node is the last node on the search path of the tree structure; according to the first prefix matching length and the destination IP address, determine the first routing prefix; trigger the cache to store the first routing prefix A corresponding relationship, where the first corresponding relationship is the first routing prefix and routing information corresponding to the prefix node.
具体执行过程请参考上述图4所示实施例中相应步骤的详细描述,这里不再一一赘述。For the specific execution process, please refer to the detailed description of the corresponding steps in the above-mentioned embodiment shown in FIG. 4 , which will not be repeated here.
可选地,本申请实施例中提供的集成电路800还可以包括缓存。该集成电路800中的 接口电路801和控制电路802可以为一个或多个。Optionally, the integrated circuit 800 provided in this embodiment of the present application may further include a cache. The interface circuit 801 and the control circuit 802 in the integrated circuit 800 may be one or more.
示例性的,该集成电路600可以是FPGA,可以是ASIC,还可以是系统芯片(system on chip,SoC),还可以是CPU,还可以是NP,还可以是数字信号处理电路(digital signal processor,DSP),还可以是微控制器(micro controller unit,MCU),还可以是可编程控制器(programmable logic device,PLD)或其他集成芯片。Exemplarily, the integrated circuit 600 may be an FPGA, an ASIC, a system on chip (system on chip, SoC), a CPU, an NP, or a digital signal processing circuit (digital signal processor). , DSP), can also be a microcontroller (micro controller unit, MCU), can also be a programmable logic device (programmable logic device, PLD) or other integrated chips.
参见图9,本申请实施例还提供了一种装置900,该缓存装置900可以实现图4所示实施例中处理器的功能。该缓存装置900包括获取单元901和处理单元902。其中,获取单元901用于实现图4所示实施例中的S401,处理单元402用于实现图4所示实施例中的S402、S403、S404和S405。Referring to FIG. 9 , an embodiment of the present application further provides an apparatus 900 , and the cache apparatus 900 can implement the function of the processor in the embodiment shown in FIG. 4 . The cache device 900 includes an acquisition unit 901 and a processing unit 902 . The acquiring unit 901 is used to implement S401 in the embodiment shown in FIG. 4 , and the processing unit 402 is used to implement S402 , S403 , S404 and S405 in the embodiment shown in FIG. 4 .
具体的,获取单元901,用于获取第一报文,所述第一报文包括目的互联网协议IP地址。Specifically, the obtaining unit 901 is configured to obtain a first packet, where the first packet includes a destination Internet Protocol IP address.
处理单元902,用于从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。The processing unit 902 is configured to look up a routing prefix matching the destination IP address from the cache; in response to the routing prefix not being stored in the cache, look up a tree structure corresponding to the routing table according to the destination IP address, and determine A prefix node matching the destination IP address; in response to the prefix node not being a leaf node, determine a first prefix matching length, and the first prefix matching length is equal to the length between the root node and the tail node of the tree structure. length, the tail node is the last node on the search path of the tree structure; determine the first routing prefix according to the first prefix matching length and the destination IP address; trigger the cache to store the first correspondence , the first correspondence is the first routing prefix and routing information corresponding to the prefix node.
具体执行过程请参考上述图4所示实施例中相应步骤的详细描述,这里不再一一赘述。For the specific execution process, please refer to the detailed description of the corresponding steps in the above-mentioned embodiment shown in FIG. 4 , which will not be repeated here.
需要说明的是,本申请实施例中对单元的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。本申请实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。例如,上述实施例中,获取单元和处理单元可以是同一个单元,也不同的单元。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。It should be noted that the division of units in the embodiments of the present application is illustrative, and is only a logical function division, and other division methods may be used in actual implementation. Each functional unit in the embodiments of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. For example, in the above embodiment, the acquiring unit and the processing unit may be the same unit or different units. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
参见图10,本申请实施例还提供了一种芯片1000,该芯片1000可以实现图4所示实施例中处理器的功能。该芯片包括存储器1001和处理器1002。其中,存储器1001用于存储指令或程序代码,处理器1002用于从存储器1001中调用并运行指令或程序代码,以实现图4所示实施例中的S401、S402、S403、S404和S405。Referring to FIG. 10 , an embodiment of the present application further provides a chip 1000 , and the chip 1000 can implement the functions of the processor in the embodiment shown in FIG. 4 . The chip includes a memory 1001 and a processor 1002 . The memory 1001 is used to store instructions or program codes, and the processor 1002 is used to call and run the instructions or program codes from the memory 1001 to implement S401 , S402 , S403 , S404 and S405 in the embodiment shown in FIG. 4 .
可选地,所述处理器1002可以是图8所示集成电路800。所述处理器1002可以包括缓存。当处理器1002不包括缓存时,所述存储器1001可以包括缓存。Optionally, the processor 1002 may be the integrated circuit 800 shown in FIG. 8 . The processor 1002 may include a cache. When the processor 1002 does not include a cache, the memory 1001 may include a cache.
图11是本申请实施例提供的一种设备1100的结构示意图。上文中处理器所在的设备可以通过位于图11所示的设备来实现。参见图11,该设11900包括至少一个处理器芯片1101和至少一个存储器1102。可选地,该设备1100还可以包括通信总线1103以及至少一个网络接口1104。FIG. 11 is a schematic structural diagram of a device 1100 provided by an embodiment of the present application. The device where the processor is located in the above can be implemented by the device shown in FIG. 11 . Referring to FIG. 11 , the device 11900 includes at least one processor chip 1101 and at least one memory 1102 . Optionally, the device 1100 may further include a communication bus 1103 and at least one network interface 1104 .
处理器芯片1101可以是一个通用中央处理器(central processing unit,CPU)、特定应用集成电路(application-specific integrated circuit,ASIC)或一个或多个用于控制本申请方案程序执行的集成电路(integrated circuit,IC)。该处理器芯片901可以用于实现本申请实 施例中提供的数据缓存方法。The processor chip 1101 may be a general-purpose central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits (integrated circuits) used to control the execution of the programs of the present application. circuit, IC). The processor chip 901 may be used to implement the data caching method provided in the embodiments of the present application.
比如,当图1中的网络设备通过图11所示的设备来实现时,该处理器可以用于,获取第一报文,所述第一报文包括目的互联网协议IP地址;从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。For example, when the network device in FIG. 1 is implemented by the device shown in FIG. 11 , the processor can be used to obtain a first packet, where the first packet includes the destination Internet Protocol IP address; search from the cache A routing prefix matching the destination IP address; in response to the routing prefix not being stored in the cache, look up a tree structure corresponding to the routing table according to the destination IP address, and determine a prefix node matching the destination IP address ; In response to the prefix node not being a leaf node, determine the first prefix matching length, the first prefix matching length is equal to the length between the root node and the tail node of the tree structure, and the tail node is the tree The last node on the search path of the structure; determine the first routing prefix according to the matching length of the first prefix and the destination IP address; trigger the cache to store the first correspondence, and the first correspondence is the A first routing prefix and routing information corresponding to the prefix node.
可选地,处理器芯片1101可以是图10所示实施例中芯片1000,也可以是图8所示实施例中集成电路800。当处理器芯片1001不包括缓存时,所述存储器1102可以包括缓存、内存和外存;当处理器芯片1101包括缓存时,所述存储器1102可以包括内存和外存。Optionally, the processor chip 1101 may be the chip 1000 in the embodiment shown in FIG. 10 , or may be the integrated circuit 800 in the embodiment shown in FIG. 8 . When the processor chip 1001 does not include a cache, the memory 1102 may include a cache, a memory and an external memory; when the processor chip 1101 includes a cache, the memory 1102 may include a memory and an external memory.
存储器1102可以是只读存储器(read-only memory,ROM)或可存储静态信息和指令的其它类型的静态存储设备,存储器902还可以是随机存取存储器(random access memory,RAM)或者可存储信息和指令的其它类型的动态存储设备,也可以是只读光盘(compact disc read-only Memory,CD-ROM)或其它光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质或者其它磁存储设备、或者能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其它介质,但不限于此。存储器1102可以是独立存在,通过通信总线1103与处理器1101相连接。存储器1102也可以和处理器1101集成在一起。可选地,存储器1102可以包括缓存。The memory 1102 can be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, and the memory 902 can also be a random access memory (RAM) or can store information and other types of dynamic storage devices for instructions, also can be compact disc read-only Memory (CD-ROM) or other optical disc storage, optical disc storage (including compact disc, laser disc, optical disc, digital versatile disc, Blu-ray optical disks, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, without limitation. The memory 1102 may exist independently, and is connected to the processor 1101 through the communication bus 1103 . The memory 1102 may also be integrated with the processor 1101 . Optionally, memory 1102 may include a cache.
可选地,存储器1102用于存储执行本申请方案的程序代码或指令,并由处理器1101来控制执行。处理器1101用于执行存储器1102中存储的程序代码或指令。程序代码中可以包括一个或多个软件模块。可选地,处理器1101也可以存储执行本申请方案的程序代码或指令,在这种情况下处理器1101不需要到存储器1102中读取程序代码或指令。Optionally, the memory 1102 is used for storing program codes or instructions for executing the solution of the present application, and the execution is controlled by the processor 1101 . The processor 1101 is used to execute program codes or instructions stored in the memory 1102 . One or more software modules may be included in the program code. Optionally, the processor 1101 may also store program codes or instructions for executing the solutions of the present application, in which case the processor 1101 does not need to read the program codes or instructions from the memory 1102 .
可选地,存储器1102可以用于实现图1所示的设备中存储器120的作用。Optionally, the memory 1102 may be used to implement the role of the memory 120 in the device shown in FIG. 1 .
通信总线1103用于在处理器芯片1101、网络接口1104和存储器1102之间传送信息。The communication bus 1103 is used to transfer information between the processor chip 1101 , the network interface 1104 and the memory 1102 .
网络接口1104可以为收发器一类的装置,用于与其它设备或通信网络通信,通信网络可以为以太网、无线接入网(RAN)或无线局域网(wireless local area networks,WLAN)等。在本申请实施例中,网络接口904可以用于接收分段路由网络中的其他节点发送的报文,也可以向分段路由网络中的其他节点发送报文。网络接口1104可以为以太接口(ethernet)接口、快速以太(fast ethernet,FE)接口或千兆以太(gigabit ethernet,GE)接口等。The network interface 1104 may be a device such as a transceiver for communicating with other devices or a communication network, which may be Ethernet, a radio access network (RAN), or a wireless local area network (WLAN), or the like. In this embodiment of the present application, the network interface 904 may be configured to receive packets sent by other nodes in the segment routing network, and may also send packets to other nodes in the segment routing network. The network interface 1104 may be an ethernet (ethernet) interface, a fast ethernet (FE) interface, or a gigabit ethernet (GE) interface, or the like.
在具体实现中,作为一种实施例,设备1100可以包括多个处理器芯片,例如图9中所示的处理器芯片1101和处理器芯片1105。这些处理器芯片中的每一个可以是一个单核(single-CPU)处理器,也可以是一个多核(multi-CPU)处理器。可选地,图4所示的缓存方法中不同步骤可以由不同的处理器芯片执行。这里的处理器芯片可以指一个或多个设备、电路、和/或用于处理数据(例如计算机程序指令)的处理核。In a specific implementation, as an embodiment, the device 1100 may include multiple processor chips, such as the processor chip 1101 and the processor chip 1105 shown in FIG. 9 . Each of these processor chips can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. Optionally, different steps in the caching method shown in FIG. 4 may be performed by different processor chips. A processor chip herein may refer to one or more devices, circuits, and/or processing cores for processing data (eg, computer program instructions).
图12是本申请实施例提供的一种设备1200的结构示意图。图1中的设备100可以通过图12所示的设备来实现。参见图12所示的设备结构示意图,设备1200包括主控板和一个或多个接口板。主控板与接口板通信连接。主控板也称为主处理单元(main processing unit,MPU)或路由处理卡(route processor card),主控板包括CPU和存储器,主控板负责对设备1000中各个组件的控制和管理,包括路由计算、设备管理和维护功能。接口板也称为线处理单元(line processing unit,LPU)或线卡(line card),用于接收和发送报文。在一些实施例中,主控板与接口板之间或接口板与接口板之间通过总线通信。在一些实施例中,接口板之间通过交换网板通信,在这种情况下设备1200也包括交换网板,交换网板与主控板、接口板通信连接,交换网板用于转发接口板之间的数据,交换网板也可以称为交换网板单元(switch fabric unit,SFU)。接口板包括CPU、存储器、转发引擎和接口卡(interface card,IC),其中接口卡可以包括一个或多个网络接口。网络接口可以为Ethernet接口、FE接口或GE接口等。CPU与存储器、转发引擎和接口卡分别通信连接。存储器用于存储转发表。转发引擎用于基于存储器中保存的转发表转发接收到的报文,如果接收到的报文的目的地址为设备1200的IP地址,则将该报文发送给主控板或接口板的CPU进行处理;如果接收到的报文的目的地址不是设备1200的IP地址,则根据该目的地查转发表,如果从转发表中查找到该目的地址对应的下一跳和出接口,将该报文转发到该目的地址对应的出接口。转发引擎可以是网络处理器(network processor,NP)。接口卡也称为子卡,可安装在接口板上,负责将光电信号转换为数据帧,并对数据帧进行合法性检查后转发给转发引擎处理或接口板CPU。在一些实施例中,CPU也可执行转发引擎的功能,比如基于通用CPU实现软转发,从而接口板中不需要转发引擎。在一些实施例中,转发引擎可以通过ASIC或现场可编程门阵列(field programmable gate array,FPGA)实现。在一些实施例中,存储转发表的存储器也可以集成到转发引擎中,作为转发引擎的一部分。FIG. 12 is a schematic structural diagram of a device 1200 provided by an embodiment of the present application. The device 100 in FIG. 1 can be implemented by the device shown in FIG. 12 . Referring to the schematic diagram of the device structure shown in FIG. 12 , the device 1200 includes a main control board and one or more interface boards. The main control board communicates with the interface board. The main control board is also called the main processing unit (MPU) or the route processor card (route processor card). The main control board includes a CPU and memory. The main control board is responsible for the control and management of various components in the device 1000, including Route calculation, device management and maintenance functions. Interface boards, also known as line processing units (LPUs) or line cards, are used to receive and send messages. In some embodiments, the communication between the main control board and the interface board or between the interface board and the interface board is through a bus. In some embodiments, the interface boards communicate through a switch fabric board. In this case, the device 1200 also includes a switch fabric board. The switch fabric board is communicatively connected to the main control board and the interface board. The switch fabric board is used to forward the interface board. The data between them, the switch fabric board can also be called a switch fabric unit (SFU). The interface board includes a CPU, a memory, a forwarding engine, and an interface card (IC), wherein the interface card may include one or more network interfaces. The network interface can be an Ethernet interface, an FE interface, or a GE interface. The CPU is connected in communication with the memory, the forwarding engine and the interface card, respectively. The memory is used to store the forwarding table. The forwarding engine is used to forward the received packet based on the forwarding table stored in the memory. If the destination address of the received packet is the IP address of the device 1200, the packet is sent to the CPU of the main control board or interface board for processing. Processing; if the destination address of the received message is not the IP address of the device 1200, then look up the forwarding table according to the destination, if the next hop and outgoing interface corresponding to the destination address are found from the forwarding table, the message Forwarding to the outbound interface corresponding to the destination address. The forwarding engine may be a network processor (NP). The interface card, also called a daughter card, can be installed on the interface board and is responsible for converting photoelectric signals into data frames, and after checking the validity of the data frames, forwards them to the forwarding engine for processing or the interface board CPU. In some embodiments, the CPU can also perform the function of a forwarding engine, such as implementing soft forwarding based on a general-purpose CPU, so that a forwarding engine is not required in the interface board. In some embodiments, the forwarding engine may be implemented by an ASIC or a field programmable gate array (FPGA). In some embodiments, the memory that stores the forwarding table may also be integrated into the forwarding engine as part of the forwarding engine.
可选地,该芯片系统中的处理器可以为一个或多个。该处理器可以通过硬件实现也可以通过软件实现。当通过硬件实现时,该处理器可以是逻辑电路、集成电路等。当通过软件实现时,该处理器可以是一个通用处理器,通过读取存储器中存储的软件代码来实现。Optionally, the number of processors in the chip system may be one or more. The processor can be implemented by hardware or by software. When implemented in hardware, the processor may be a logic circuit, an integrated circuit, or the like. When implemented in software, the processor may be a general-purpose processor implemented by reading software codes stored in memory.
可选地,该芯片系统中的存储器也可以为一个或多个。该存储器可以与处理器集成在一起,也可以和处理器分离设置,本申请并不限定。示例性的,存储器可以是非瞬时性处理器,例如只读存储器ROM,其可以与处理器集成在同一块芯片上,也可以分别设置在不同的芯片上,本申请对存储器的类型,以及存储器与处理器的设置方式不作具体限定。Optionally, there may also be one or more memories in the chip system. The memory may be integrated with the processor, or may be provided separately from the processor, which is not limited in this application. Exemplarily, the memory can be a non-transitory processor, such as a read-only memory ROM, which can be integrated with the processor on the same chip, or can be provided on different chips. The setting method of the processor is not particularly limited.
示例性的,该芯片系统可以是FPGA,可以是ASIC,还可以是系统芯片(system on chip,SoC),还可以是CPU,还可以是NP,还可以是数字信号处理电路(digital signal processor,DSP),还可以是微控制器(micro controller unit,MCU),还可以是可编程控制器(programmable logic device,PLD)或其他集成芯片。Exemplarily, the chip system may be an FPGA, an ASIC, a system on chip (system on chip, SoC), a CPU, an NP, or a digital signal processing circuit (digital signal processor, DSP), can also be a microcontroller (micro controller unit, MCU), can also be a programmable logic device (programmable logic device, PLD) or other integrated chips.
应理解,上述方法实施例中的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。结合本申请实施例所公开的方法步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。It should be understood that, each step in the above method embodiments may be implemented by a hardware integrated logic circuit in a processor or an instruction in the form of software. The method steps disclosed in conjunction with the embodiments of the present application may be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
本申请实施例还提供了一种计算机可读存储介质,包括指令,当其在计算机上运行时, 使得计算机执行以上方法实施例提供的、由处理器执行的缓存方法。Embodiments of the present application further provide a computer-readable storage medium, including instructions, which, when executed on a computer, cause the computer to execute the caching method provided by the above method embodiments and executed by a processor.
本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行以上方法实施例提供的、由处理器执行的缓存方法。Embodiments of the present application also provide a computer program product containing instructions, which, when running on a computer, cause the computer to execute the caching method provided by the above method embodiments and executed by a processor.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It is to be understood that data so used may be interchanged under appropriate circumstances so that the embodiments described herein can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having" and any variations thereof, are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those expressly listed Rather, those steps or units may include other steps or units not expressly listed or inherent to these processes, methods, products or devices.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above may refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑模块划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the units is only a logical module division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要获取其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be acquired according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本申请各个实施例中的各模块单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件模块单元的形式实现。In addition, each module unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware, or may be implemented in the form of software module units.
所述集成的单元如果以软件模块单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software module unit and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, and the computer software products are stored in a storage medium , including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes .
本领域技术人员应该可以意识到,在上述一个或多个示例中,本发明所描述的功能可以用硬件、软件、固件或它们的任意组合来实现。当使用软件实现时,可以将这些功能存储在计算机可读介质中或者作为计算机可读介质上的一个或多个指令或代码进行传输。计算机可读介质包括计算机存储介质和通信介质,其中通信介质包括便于从一个地方向另一个地方传送计算机程序的任何介质。存储介质可以是通用或专用计算机能够存取的任何可 用介质。Those skilled in the art should appreciate that, in one or more of the above examples, the functions described in the present invention may be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media includes both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage medium can be any available medium that can be accessed by a general purpose or special purpose computer.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已。The specific embodiments described above further describe the objectives, technical solutions and beneficial effects of the present invention in further detail, and it should be understood that the above descriptions are only specific embodiments of the present invention.
以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: The technical solutions described in the embodiments are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims (25)

  1. 一种缓存方法,其特征在于,所述方法包括:A caching method, characterized in that the method comprises:
    处理器获取第一报文,所述第一报文包括目的互联网协议IP地址;The processor obtains a first packet, where the first packet includes a destination Internet Protocol IP address;
    所述处理器从缓存中查找与所述目的IP地址匹配的路由前缀;The processor searches the cache for a routing prefix matching the destination IP address;
    响应于所述缓存中未存储所述路由前缀,所述处理器根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;In response to the routing prefix not being stored in the cache, the processor searches a tree structure corresponding to the routing table according to the destination IP address, and determines a prefix node matching the destination IP address;
    响应于所述前缀节点不为叶子节点,所述处理器确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;In response to that the prefix node is not a leaf node, the processor determines a first prefix matching length, the first prefix matching length is equal to the length between the root node and the tail node of the tree structure, and the tail node is the last node on the search path of the tree structure;
    所述处理器根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;The processor determines a first routing prefix according to the first prefix matching length and the destination IP address;
    所述处理器触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。The processor triggers the cache to store a first correspondence, where the first correspondence is the first routing prefix and routing information corresponding to the prefix node.
  2. 根据权利要求1所述的方法,其特征在于,所述第一路由前缀的长度大于或等于所述第一前缀匹配长度。The method according to claim 1, wherein the length of the first routing prefix is greater than or equal to the first prefix matching length.
  3. 根据权利要求1或2所述的方法,其特征在于,所述处理器根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点包括:The method according to claim 1 or 2, wherein the processor searches a tree structure corresponding to the routing table according to the destination IP address, and determining a prefix node matching the destination IP address comprises:
    所述处理器根据所述目的IP地址查找与路由表对应的虚拟树结构,确定与所述目的IP地址最长匹配的虚拟前缀;The processor searches the virtual tree structure corresponding to the routing table according to the destination IP address, and determines the virtual prefix that matches the destination IP address longest;
    所述处理器根据所述目的IP地址查找与所述虚拟前缀对应的子树结构,确定与所述目的IP地址匹配的前缀节点,所述虚拟前缀为所述子树结构的根节点;The processor searches for a subtree structure corresponding to the virtual prefix according to the destination IP address, and determines a prefix node matching the destination IP address, where the virtual prefix is the root node of the subtree structure;
    所述第一前缀匹配长度等于第一长度和第二长度之和,所述第一长度为所述虚拟树结构的根节点到所述虚拟前缀的长度,所述第二长度为所述虚拟前缀到尾节点之间的长度,所述尾节点为所述子树结构的查找路径上的最后一个节点。The first prefix matching length is equal to the sum of the first length and the second length, the first length is the length from the root node of the virtual tree structure to the virtual prefix, and the second length is the virtual prefix The length to the tail node, where the tail node is the last node on the search path of the subtree structure.
  4. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, wherein the method further comprises:
    响应于所述前缀节点不为叶子节点,所述处理器确定第二前缀匹配长度,所述第二前缀匹配长度等于所述树结构的根节点到独子节点之间的长度,所述独子节点为所述前缀节点到所述尾节点之间的只具有左孩子节点或只具有右孩子节点的节点;In response to that the prefix node is not a leaf node, the processor determines a second prefix matching length, the second prefix matching length is equal to the length between the root node of the tree structure and the only child node, and the only child node is a node between the prefix node and the tail node that only has left child nodes or only has right child nodes;
    所述处理器根据所述第二前缀匹配长度和所述目的IP地址,确定第二路由前缀,所述第二路由前缀的长度大于所述第二前缀匹配长度;The processor determines a second routing prefix according to the second prefix matching length and the destination IP address, where the length of the second routing prefix is greater than the second prefix matching length;
    所述处理器触发所述缓存存储第二对应关系,所述第二对应关系为所述第二路由前缀和所述前缀节点对应的路由信息。The processor triggers the cache to store a second correspondence, where the second correspondence is routing information corresponding to the second routing prefix and the prefix node.
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-4, wherein the method further comprises:
    所述处理器触发所述缓存存储所述第一路由前缀的类型,所述第一路由前缀的类型用于指示在所述第一路由前缀被命中时,根据所述第一对应关系在所述缓存中获取与所述第一路由前缀对应的路由信息。The processor triggers the cache to store the type of the first routing prefix, where the type of the first routing prefix is used to indicate that when the first routing prefix is hit, according to the first correspondence The routing information corresponding to the first routing prefix is obtained in the cache.
  6. 根据权利要求3所述的方法,其特征在于,所述方法还包括:The method according to claim 3, wherein the method further comprises:
    所述处理器触发所述缓存存储第三对应关系,所述第三对应关系为所述虚拟前缀、所 述虚拟前缀的类型以及所述子树结构的信息之间的对应关系,所述虚拟前缀的类型用于指示在所述虚拟前缀被命中时,根据所述子树结构的信息查找所述子树结构。The processor triggers the cache to store a third correspondence, where the third correspondence is the correspondence between the virtual prefix, the type of the virtual prefix, and the information of the subtree structure, and the virtual prefix The type of is used to indicate that when the virtual prefix is hit, the subtree structure is searched according to the information of the subtree structure.
  7. 根据权利要求1-6任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-6, wherein the method further comprises:
    所述处理器触发所述缓存存储所述第一路由前缀的长度。The processor triggers the cache to store the length of the first routing prefix.
  8. 根据权利要求2所述的方法,其特征在于,所述第一路由前缀的长度等于所述第一前缀匹配长度加1。The method according to claim 2, wherein the length of the first routing prefix is equal to the first prefix matching length plus 1.
  9. 根据权利要求1-8任一项所述的方法,其特征在于,所述第一路由前缀的长度小于所述目的IP地址的长度。The method according to any one of claims 1-8, wherein the length of the first routing prefix is smaller than the length of the destination IP address.
  10. 根据权利要求1-9任一项所述的方法,其特征在于,所述目的IP地址包括所述第一路由前缀。The method according to any one of claims 1-9, wherein the destination IP address includes the first routing prefix.
  11. 根据权利要求1-10任一项所述的方法,其特征在于,所述缓存至少包括以下其中一种:The method according to any one of claims 1-10, wherein the cache includes at least one of the following:
    三态内容寻址存储器TCAM、寄存器、线卡板和晶粒。Tri-state content addressable memory TCAM, registers, line card boards and die.
  12. 一种集成电路,其特征在于,所述集成电路包括接口电路和控制电路;An integrated circuit, characterized in that the integrated circuit includes an interface circuit and a control circuit;
    其中,所述接口电路,用于获取第一报文,所述第一报文包括目的互联网协议IP地址;Wherein, the interface circuit is used to obtain a first packet, and the first packet includes a destination Internet Protocol IP address;
    所述控制电路,用于从缓存中查找与所述目的IP地址匹配的路由前缀;响应于所述缓存中未存储所述路由前缀,根据所述目的IP地址查找与路由表对应的树结构,确定与所述目的IP地址匹配的前缀节点;响应于所述前缀节点不为叶子节点,确定第一前缀匹配长度,所述第一前缀匹配长度等于所述树结构的根节点到尾节点之间的长度,所述尾节点为所述树结构的查找路径上的最后一个节点;根据所述第一前缀匹配长度和所述目的IP地址,确定第一路由前缀;触发所述缓存存储第一对应关系,所述第一对应关系为所述第一路由前缀和与所述前缀节点对应的路由信息。The control circuit is configured to look up a routing prefix matching the destination IP address from the cache; in response to the routing prefix not being stored in the cache, look up a tree structure corresponding to the routing table according to the destination IP address, determining a prefix node matching the destination IP address; in response to the prefix node not being a leaf node, determining a first prefix matching length, where the first prefix matching length is equal to the length between the root node and the tail node of the tree structure The length of the tail node is the last node on the search path of the tree structure; according to the first prefix matching length and the destination IP address, determine the first routing prefix; trigger the cache to store the first corresponding The first corresponding relationship is the first routing prefix and routing information corresponding to the prefix node.
  13. 根据权利要求12所述的集成电路,其特征在于,所述第一路由前缀的长度大于或等于所述第一前缀匹配长度。The integrated circuit of claim 12, wherein the length of the first routing prefix is greater than or equal to the first prefix matching length.
  14. 根据权利要求12或13所述的集成电路,其特征在于,The integrated circuit according to claim 12 or 13, wherein,
    所述控制电路,用于根据所述目的IP地址查找与路由表对应的虚拟树结构,确定与所述目的IP地址最长匹配的虚拟前缀;根据所述目的IP地址查找与所述虚拟前缀对应的子树结构,确定与所述目的IP地匹配的前缀节点,所述虚拟前缀为所述子树结构的根节点;所述第一前缀匹配长度等于第一长度和第二长度之和,所述第一长度为所述虚拟树结构的根节点到所述虚拟前缀的长度,所述第二长度为所述虚拟前缀到尾节点之间的长度,所述尾节点为所述子树结构的查找路径上的最后一个节点。The control circuit is configured to search the virtual tree structure corresponding to the routing table according to the destination IP address, and determine the virtual prefix that matches the destination IP address the longest; search for the virtual prefix corresponding to the destination IP address according to the destination IP address subtree structure, determine the prefix node matching the destination IP address, and the virtual prefix is the root node of the subtree structure; the first prefix matching length is equal to the sum of the first length and the second length, so the virtual prefix is the root node of the subtree structure; The first length is the length from the root node of the virtual tree structure to the virtual prefix, and the second length is the length between the virtual prefix and the tail node, and the tail node is the length of the subtree structure. Find the last node on the path.
  15. 根据权利要求12或13所述的集成电路,其特征在于,The integrated circuit according to claim 12 or 13, wherein,
    所述控制电路,还用于响应于所述前缀节点不为叶子节点,确定第二前缀匹配长度,所述第二前缀匹配长度等于所述树结构的根节点到独子节点之间的长度,所述独子节点为所述前缀节点到所述尾节点之间的只具有左孩子节点或只具有右孩子节点的节点;根据所述第二前缀匹配长度和所述目的IP地址,确定第二路由前缀,所述第二路由前缀的长度大于所述第二前缀匹配长度;触发所述缓存存储第二对应关系,所述第二对应关系为所述第 二路由前缀和所述前缀节点对应的路由信息。The control circuit is further configured to determine a second prefix matching length in response to that the prefix node is not a leaf node, where the second prefix matching length is equal to the length between the root node of the tree structure and the single-child node, so The single-child node is a node with only a left child node or only a right child node between the prefix node and the tail node; according to the second prefix matching length and the destination IP address, determine the second routing prefix , the length of the second routing prefix is greater than the matching length of the second prefix; trigger the cache to store a second correspondence, where the second correspondence is the routing information corresponding to the second routing prefix and the prefix node .
  16. 根据权利要求12-15任一项所述的集成电路,其特征在于,The integrated circuit according to any one of claims 12-15, wherein,
    所述控制电路,还用于触发所述缓存存储所述第一路由前缀的类型,所述第一路由前缀的类型用于指示在所述第一路由前缀被命中时,根据所述第一对应关系在所述缓存中获取与所述第一路由前缀对应的路由信息。The control circuit is further configured to trigger the cache to store the type of the first routing prefix, where the type of the first routing prefix is used to indicate that when the first routing prefix is hit, according to the first corresponding The relationship obtains routing information corresponding to the first routing prefix in the cache.
  17. 根据权利要求14所述的集成电路,其特征在于,The integrated circuit of claim 14, wherein:
    所述控制电路,还用于触发所述缓存存储第三对应关系,所述第三对应关系为所述虚拟前缀、所述虚拟前缀的类型以及所述子树结构的信息之间的对应关系,所述虚拟前缀的类型用于指示在所述虚拟前缀被命中时,根据所述子树结构的信息查找所述子树结构。The control circuit is further configured to trigger the cache to store a third correspondence, where the third correspondence is the correspondence between the virtual prefix, the type of the virtual prefix, and the information of the subtree structure, The type of the virtual prefix is used to indicate that when the virtual prefix is hit, the subtree structure is searched according to the information of the subtree structure.
  18. 根据权利要求12-17任一项所述的集成电路,其特征在于,The integrated circuit according to any one of claims 12-17, wherein,
    所述控制电路,还用于触发所述缓存存储所述第一路由前缀的长度。The control circuit is further configured to trigger the cache to store the length of the first routing prefix.
  19. 根据权利要求13所述的集成电路,其特征在于,所述第一路由前缀的长度等于所述第一前缀匹配长度加1。The integrated circuit of claim 13, wherein the length of the first routing prefix is equal to the first prefix matching length plus one.
  20. 根据权利要求12-19任一项所述的集成电路,其特征在于,所述第一路由前缀的长度小于所述目的IP地址的长度。The integrated circuit according to any one of claims 12-19, wherein the length of the first routing prefix is smaller than the length of the destination IP address.
  21. 根据权利要求12-20任一项所述的集成电路,其特征在于,所述目的IP地址包括所述第一路由前缀。The integrated circuit according to any one of claims 12-20, wherein the destination IP address includes the first routing prefix.
  22. 根据权利要求12-21任一项所述的集成电路,其特征在于,所述缓存至少包括以下其中一种:The integrated circuit according to any one of claims 12-21, wherein the cache includes at least one of the following:
    三态内容寻址存储器TCAM、寄存器、线卡板和晶粒。Tri-state content addressable memory TCAM, registers, line card boards and die.
  23. 一种芯片,其特征在于,所述芯片包括存储器和处理器,存储器用于存储指令或程序代码,处理器用于从存储器中调用并运行所述指令或程序代码,以执行如权利要求1-11任一项所述的缓存方法。A chip, characterized in that the chip includes a memory and a processor, the memory is used to store instructions or program codes, and the processor is used to call and run the instructions or program codes from the memory, so as to execute the instructions or program codes according to claims 1-11 Any of the caching methods described above.
  24. 一种设备,其特征在于,所述设备包括处理器芯片和存储器,存储器用于存储指令或程序代码,处理器芯片用于从存储器中调用并运行所述指令或程序代码,以执行如权利要求1-11任一项所述的缓存方法。A device, characterized in that the device comprises a processor chip and a memory, the memory is used to store instructions or program codes, and the processor chip is used to call and run the instructions or program codes from the memory to execute the instructions or program codes as claimed in the claims The caching method described in any one of 1-11.
  25. 一种计算机可读存储介质,其特征在于,包括指令、程序或代码,当其在计算机上执行时,使得所述计算机执行如权利要求1-11任一项所述的缓存方法。A computer-readable storage medium, characterized in that it includes instructions, programs or codes, which, when executed on a computer, cause the computer to execute the caching method according to any one of claims 1-11.
PCT/CN2022/081320 2021-04-02 2022-03-17 Buffering method and integrated circuit WO2022206397A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110361730.4 2021-04-02
CN202110361730.4A CN115190071A (en) 2021-04-02 2021-04-02 Cache method and integrated circuit

Publications (1)

Publication Number Publication Date
WO2022206397A1 true WO2022206397A1 (en) 2022-10-06

Family

ID=83455609

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/081320 WO2022206397A1 (en) 2021-04-02 2022-03-17 Buffering method and integrated circuit

Country Status (2)

Country Link
CN (1) CN115190071A (en)
WO (1) WO2022206397A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040052251A1 (en) * 2002-09-16 2004-03-18 North Carolina State University Methods and systems for fast binary network address lookups using parent node information stored in routing table entries
CN101577662A (en) * 2008-05-05 2009-11-11 华为技术有限公司 Method and device for matching longest prefix based on tree form data structure
CN107347035A (en) * 2016-05-06 2017-11-14 华为技术有限公司 Method for searching route, device, distribution node, lookup node and Ingress node
CN108259326A (en) * 2016-12-29 2018-07-06 华为技术有限公司 Routing table update method, apparatus, distribution node and leaf message forwarding equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040052251A1 (en) * 2002-09-16 2004-03-18 North Carolina State University Methods and systems for fast binary network address lookups using parent node information stored in routing table entries
CN101577662A (en) * 2008-05-05 2009-11-11 华为技术有限公司 Method and device for matching longest prefix based on tree form data structure
CN107347035A (en) * 2016-05-06 2017-11-14 华为技术有限公司 Method for searching route, device, distribution node, lookup node and Ingress node
CN108259326A (en) * 2016-12-29 2018-07-06 华为技术有限公司 Routing table update method, apparatus, distribution node and leaf message forwarding equipment

Also Published As

Publication number Publication date
CN115190071A (en) 2022-10-14

Similar Documents

Publication Publication Date Title
KR102162730B1 (en) Technologies for distributed routing table lookup
US9871728B2 (en) Exact match hash lookup databases in network switch devices
JP7208008B2 (en) Systems and methods for providing a programmable packet classification framework for use in network devices
US7903666B1 (en) Method and system for compressing route entries in a route table based on equal-cost multi-paths (ECMPs) matches
US11652735B2 (en) Multicast data packet processing method, and apparatus
WO2019185051A1 (en) Integrated flow table-based packet forwarding method and device
US10397116B1 (en) Access control based on range-matching
CN111937360B (en) Longest prefix matching
US20180270153A1 (en) Increasing entropy across routing table segments
US20130242998A1 (en) Multiple Shortest-Path Tree Protocol
CN107547407B (en) Message transmission method, device and implementation device
CN112787927B (en) Segmented routing message forwarding method and device and preset logic circuit unit
TW201436508A (en) Method and apparatus of forwarding Ethernet packet
CN112667526B (en) Method and circuit for realizing access control list circuit
CN109981464B (en) TCAM circuit structure realized in FPGA and matching method thereof
CN102291472A (en) Network address lookup method and device
CN112929281B (en) Message processing method, device and equipment of network equipment based on FPGA
US9985885B1 (en) Aggregating common portions of forwarding routes
WO2022206397A1 (en) Buffering method and integrated circuit
US9973411B2 (en) Synchronization of data and control planes of routers
CN107204926B (en) Rapid route searching method for preprocessing cache
JP3795881B2 (en) Table search method and apparatus
JP2005333220A (en) Network node device
US9444731B2 (en) Methods and systems for data packet routing
WO2023088226A1 (en) Packet forwarding method and related device

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: 22778580

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: 22778580

Country of ref document: EP

Kind code of ref document: A1