A message matching method, device, network equipment and medium
Through pipeline mechanism and cache prefetching technology, the problem of slow speed caused by network devices frequently accessing memory during message matching is solved, and faster message matching and forwarding speed is achieved.
Patent Information
- Application Number
- CN202180001644.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-25
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2041-06-25
AI Technical Summary
During the packet matching process, existing network devices have a slow matching speed due to frequent access to memory, and cannot forward messages to be forwarded in time.
Using the pipeline mechanism, data packets are added to the pipeline. The stage of each pipeline is set as the root node of the decision tree. The outgoing interface data corresponding to the hash value is asynchronously prefetched and stored in the cache, reducing the number of accesses to memory and improving Match speed.
By cached prefetching of interface data, the time required for packet matching is reduced, the speed of packet forwarding is improved, and the received data packets can be processed in a timely manner.
Smart Images

Figure CN113632427B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a message matching method, device, network equipment and medium. Background Art
[0002] At present, network devices such as network switches or routers use the forwarding information base (FIB) to guide the forwarding of Internet Protocol (IP) messages or named data networking (NDN) messages. During the message forwarding process, the longest match principle is used to obtain the outbound interface for forwarding messages from the FIB. The FIB entry where the outbound interface is located is the entry in the FIB with the longest prefix length that matches the destination address.
[0003] FIB entries are stored in a hash table in the form of key-value, where the hash value of the prefix / prefix length is the key and the outbound interface corresponding to the prefix / prefix length is the value. In order to speed up the message matching, a dynamic decision tree is introduced. Each node in the decision tree represents a possible prefix length. The root node of the decision tree is the prefix length with the highest hit rate in the message matching process. Other possible prefix lengths are distributed on the child nodes of the decision tree in descending order according to the matching hit rate.
[0004] When a message to be forwarded is received, the destination address of the message to be forwarded is matched by searching the decision tree to obtain the output interface corresponding to the message to be forwarded. That is, the hash value of the destination address and the prefix length corresponding to the node of the decision tree is calculated, and then the hash table in the memory is searched to see whether there is an output interface corresponding to the hash value. The CPU of the network device needs to access the memory multiple times to complete the matching of a message to be forwarded. When a large number of messages to be forwarded are received, the matching speed of the message to be forwarded will be slow, and the message to be forwarded cannot be forwarded in time. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a message matching method, apparatus, network device and medium to speed up the message matching and forward the message in time. The specific technical solution is as follows:
[0006] In a first aspect, the present application provides a message matching method, comprising:
[0007] Adding N first data packets to N pipelines, setting the stage of each pipeline as the root node of a decision tree, wherein each node in the decision tree represents a prefix length and each node represents a different prefix length;
[0008] Calculate a first hash value of a first pipeline among the N pipelines, and asynchronously pre-fetch first output interface data corresponding to the first hash value from a memory, and store the first output interface data in a cache, while pre-fetching the first output interface data from the memory, calculate a second hash value of a second pipeline among the N pipelines, repeat the process of asynchronously pre-fetching output interface data corresponding to the hash value from the memory, storing the output interface data in the cache, and calculating the hash value of the pipeline while pre-fetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped; wherein the hash value of the pipeline is a hash value of the destination address of the data message in the pipeline and the prefix length represented by the stage;
[0009] When the hash value of each pipeline in the N pipelines has been calculated, obtaining the first output interface data from the cache;
[0010] When the first output interface data is characterized as being used to forward the first data packet in the first pipeline, the first data packet in the first pipeline is deleted from the first pipeline, and when a second data packet is received, the second data packet is added to the first pipeline.
[0011] In a possible implementation manner, after acquiring the first outbound interface data from the cache, the method further includes:
[0012] When the first output interface data is not characterized as being used to forward the first data packet in the first pipeline, the stage of the first pipeline is updated to the right child node of the root node, and the output interface information in the first pipeline is updated to the first output interface data.
[0013] In a possible implementation manner, after acquiring the first outbound interface data from the cache, the method further includes:
[0014] Determine whether the right child node of the root node in the decision tree is empty;
[0015] If so, determining that the first outbound interface data representation is used to forward the first data message in the first pipeline;
[0016] If not, it is determined that the first outbound interface data is not characterized as being used to forward the first data packet in the first pipeline.
[0017] In a possible implementation, the method further includes:
[0018] If the first output interface data corresponding to the first hash value cannot be obtained from the cache, the stage of the first pipeline is updated to the left child node of the root node.
[0019] In a possible implementation, the method further includes:
[0020] When the first output interface data is characterized as being used to forward the first data packet in the first pipeline, updating the stage of the first pipeline to complete matching;
[0021] The deleting the first data message in the first pipeline includes:
[0022] When the stages of the N pipelines are all updated once, the first data packet in the pipeline whose stage has completed matching is deleted from the pipeline.
[0023] In a second aspect, the present application provides a message matching device, including:
[0024] A setting module, used for adding N first data packets to N pipelines, setting the stage of each pipeline as the root node of a decision tree, wherein each node in the decision tree represents a prefix length and each node represents a different prefix length;
[0025] A prefetch module, used to calculate a first hash value of a first pipeline among the N pipelines, and asynchronously prefetch first output interface data corresponding to the first hash value from a memory, and store the first output interface data in a cache, and calculate a second hash value of a second pipeline among the N pipelines while prefetching the first output interface data from the memory, and repeat the process of asynchronously prefetching the output interface data corresponding to the hash value from the memory, storing the output interface data in the cache, and calculating the hash value of the pipeline while prefetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped; wherein the hash value of the pipeline is a hash value of the destination address of the data message in the pipeline and the prefix length represented by the stage;
[0026] An acquisition module, configured to acquire the first output interface data from the cache when the hash value of each of the N pipelines has been calculated;
[0027] The setting module is also used to delete the first data packet in the first pipeline from the first pipeline when the first output interface data is characterized as being used to forward the first data packet in the first pipeline, and when a second data packet is received, add the second data packet to the first pipeline.
[0028] In a possible implementation manner, the device further includes:
[0029] An updating module is used to update the stage of the first pipeline to the right child node of the root node and update the output interface information in the first pipeline to the first output interface data when the first output interface data is not represented as being used to forward the first data packet in the first pipeline.
[0030] In a possible implementation, the device further includes: a judgment module, configured to:
[0031] Determine whether the right child node of the root node in the decision tree is empty;
[0032] If so, determining that the first outbound interface data representation is used to forward the first data message in the first pipeline;
[0033] If not, it is determined that the first outbound interface data is not characterized as being used to forward the first data packet in the first pipeline.
[0034] In a possible implementation manner, the device further includes:
[0035] An updating module is used to update the stage of the first pipeline to the left child node of the root node if the first output interface data corresponding to the first hash value cannot be obtained from the cache.
[0036] In a possible implementation manner, the device further includes:
[0037] An updating module, configured to update the stage of the first pipeline to complete matching when the first output interface data is characterized as being used to forward the first data packet in the first pipeline;
[0038] The setting module is specifically used to delete the first data packet in the pipeline whose stage has completed matching from the pipeline after the stages of the N pipelines have all completed an update.
[0039] In a third aspect, an embodiment of the present application provides a network device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0040] Memory, used to store computer programs;
[0041] The processor is used to implement the method steps described in the first aspect when executing the program stored in the memory.
[0042] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method described in the first aspect is implemented.
[0043] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the data processing method described in the first aspect above.
[0044] The message matching method, device, network device and medium provided in the embodiment of the present application can match N first data messages through N pipelines. After adding the N first data messages to the N pipelines, the first hash value of the first pipeline in the N pipelines can be calculated, and the first output interface data corresponding to the first hash value can be pre-fetched from the memory asynchronously, and the first output interface data can be stored in the cache. While pre-fetching the first output interface data from the memory, the second hash value of the second pipeline in the N pipelines can be calculated. In this way, it is equivalent to asynchronously pre-fetching the output interface data corresponding to the hash value from the memory every time the hash value of one pipeline in the N pipelines is calculated. In this way, when it is necessary to obtain the first output interface data corresponding to the first hash value, there is no need to access the memory, and the first output interface data can be directly obtained from the cache, which reduces the time required for message matching. And if the first output interface data is characterized as being used to forward the first data message in the first pipeline, the first data message in the first pipeline is deleted from the first pipeline, so that the second data message is added to the first pipeline for processing. Compared with the prior art in which the first data messages in N pipelines are all forwarded before the received second data message can be processed, in the embodiment of the present application, as long as a data message is deleted from the pipeline, the second data message can be added to the pipeline and processing can be started, which can speed up the matching and forwarding speed of the received data message.
[0045] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present application and the technical solutions of the prior art, the following briefly introduces the drawings required for use in the embodiments and the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 An exemplary schematic diagram of a decision tree provided in an embodiment of the present application;
[0048] Figure 2An exemplary schematic diagram of another decision tree provided in an embodiment of the present application;
[0049] Figure 3 An exemplary schematic diagram of a matrix for generating a decision tree provided in an embodiment of the present application;
[0050] Figure 4a and Figure 4b An exemplary schematic diagram of a process of generating a decision tree provided in an embodiment of the present application;
[0051] Figure 5a , Figure 5b and Figure 5c An exemplary schematic diagram of another process of generating a decision tree provided in an embodiment of the present application;
[0052] Figure 6 A flowchart of a message matching method provided in an embodiment of the present application;
[0053] Figure 7 A schematic diagram of the structure of a message matching device provided in an embodiment of the present application;
[0054] Figure 8 A schematic diagram of the structure of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical scheme, and advantages of the present application more clearly understood, the present application is further described in detail with reference to the accompanying drawings and examples. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0056] To facilitate understanding, relevant concepts involved in the embodiments of the present application are first introduced.
[0057] 1. FIB entries
[0058] FIB entries are used to guide the forwarding of IPv4 / IPv6 / NDN messages. The core structure of FIB entries is: prefix / prefix length+outbound interface. The prefix length is used to indicate which part of the prefix is the valid matching part.
[0059] 1. Taking IPv4 FIB as an example, the two entries included in FIB are as follows:
[0060] Entry1: IP prefix: 10.0.0.0 / 8 Outbound interface: Interface 2.
[0061] Entry2: IP prefix: 10.20.0.0 / 16 Outbound interface: Interface 3.
[0062] The "10.0.0.0" in "10.0.0.0 / 8" is the prefix and "8" is the prefix length, which means that if the destination address of the received message matches "10." in the prefix, the message will be forwarded through interface 2.
[0063] In "10.20.0.0 / 16", "10.20.0.0" is the prefix and "16" is the prefix length, which means that if the destination address of the received packet matches "10.20." in the prefix, the packet will be forwarded through interface 3.
[0064] In addition, the longest match principle is followed when matching packets based on FIB entries. That is, if the destination address of a packet matches multiple entries, the outbound interface in the entry with the longest prefix length among the matched entries is selected.
[0065] For example, assuming that the destination IP address of the received message is 10.0.0.1, the destination IP address can only match the above Entry1, so the network device will select the outbound interface 2 in Entry1 as the forwarding interface of the message.
[0066] For another example, assume that the destination IP address of the received message is 10.20.0.1, which matches both Entry 1 and Entry 2. However, the prefix length 16 of Entry 2 is longer than the prefix length 8 of Entry 1. Therefore, the network device selects outbound interface 3 in Entry 2 as the forwarding interface for the message.
[0067] 2. Taking the FIB of the NDN network as an example, the NDN network is similar to the IP network, which converts the IP address into a directory format, which is a directory that supports text characters.
[0068] For example, the three entries in the FIB are as follows:
[0069] Entry1: NDN prefix: / Book / Fiction / Science Outbound interface: Interface 1
[0070] Entry2: NDN prefix: / Book Outgoing interface: Interface 2
[0071] Entry3: NDN prefix: / Shoe Outgoing interface: Interface 3
[0072] Among them, " / " is used to hierarchize prefixes, and NDN's FIB also follows the longest prefix matching principle.
[0073] For example, if the destination address of the received message is: / Book / Fiction / Science / BladeRunner, the destination address matches both Entry1 and Entry2, but the prefix length of Entry1 is 3 and the prefix length of Entry2 is 1, so the network device uses the outbound interface 1 included in Entry1 as the forwarding interface of the message.
[0074] For another example, if the destination address of the received message is: / Book / Fiction / Ancient, it can be determined that the destination address matches Entry2, so the network device uses the outbound interface 2 included in Entry2 as the forwarding interface of the message.
[0075] IP networks can be considered as special NDN networks: NDN supports prefix segmentation with any characters and any length, IP networks support bit segmentation with 0 / 1, and IP packets have a fixed maximum prefix length. The maximum prefix length of IPv6 is 128 bits, and the maximum prefix length of IPv4 is 32 bits.
[0076] 2. HASH FIB
[0077] The prefix information and outbound interface information included in the FIB table are stored in the hash table in the memory in the form of key-value. Assume that the FIB includes the following table items:
[0078]
[0079] After receiving a message, the destination address of the message needs to be matched with the prefix in each table entry, and the interface corresponding to the longest matched prefix is used as the forwarding interface of the message. However, each time a table entry is matched, the memory must be accessed once, which will result in a longer time required for message matching.
[0080] In order to speed up the matching of messages, you can use binary search to find the table entry that matches the destination address of the message. For a message with a destination address of / a / b / c / d / f, if you use binary search, you will first try to match the prefix / a / b / c. It can be seen that the prefix / a / b / c does not exist in the FIB table entry. At this time, if the network device mistakenly believes that it cannot match a prefix longer than / a / b / c, the network device will look for a shorter prefix in the FIB, such as prefix / a, and forward the message through the outbound interface 2 in Entry2. However, in fact, the longest prefix that matches the destination address should be the prefix / a / b / c / d in Entry3, causing the message to be forwarded incorrectly.
[0081] In order to solve the problem that the HASH FIB cannot be correctly searched through the binary search method, a virtual entry (Virtual Entry) can be added to the HASH FIB.
[0082] Still taking the above HASH FIB as an example, the virtual entries on the path of Entry1 include prefixes: / a, / a / b, / a / b / c, / a / b / c / d, among which / a and / a / b / c / d already exist, so there is no need to add them. It is necessary to add two virtual entries with prefixes / a / b and / a / b / c to Entry1.
[0083] The prefix length of Entry2 is 1, so there is no need to add a virtual entry.
[0084] The virtual entries on the Entry3 path include the following prefixes: / a, / a / b, / a / b / c. / a already exists, so virtual entries with prefixes / a / b / c and / a / b can be added.
[0085] The virtual entries on the Entry4 path include prefixes: / f, and virtual entries with prefix / f can be added.
[0086] After adding the above virtual entry, the obtained HASH FIB includes:
[0087]
[0088] After adding the virtual entry, you can use the binary search method to search for table entries. For example, if the destination address of the received message is / a / b / w / x / y / z. By searching the HASH FIB, it is determined that / a / b / w does not exist, so it can be determined that there must be no prefix match better than / a / b / w for / a / b / w / x / y / z. Therefore, you can directly recursively perform a binary search from / a / b / w, which greatly speeds up the search speed of the HASH FIB. The number of searches can be increased from N times to Log2(N) times, where N is the maximum prefix length. For example, for IPv6 networks, the maximum value of N is 128.
[0089] 3. Optimal Decision Tree
[0090] In order to further improve the message matching speed, in an embodiment of the present application, all possible prefix lengths can be generated into a decision tree. The principle of generating a decision tree is that the prefix length with a higher matching hit rate is closer to the root node of the decision tree, and the prefix length represented by the left child node of each node is shorter than the prefix length of the right child node.
[0091] For example, if most of the messages received by the network device hit a prefix of length 128 (hereinafter referred to as Prefix 128), the generated decision tree is as follows: Figure 1 As shown in the figure, Prefix 128 is the root node, and other prefix lengths are all left branches of the root node. Since the maximum prefix length of an IPv6 message is 128 bits, there is no prefix longer than 128, so the right child node of the root node is empty.
[0092] After receiving a packet with prefix 128, the outbound interface can be determined by matching the root node of the decision tree once.
[0093] For another example, if most of the messages received by the network device hit the prefix of length 127 (i.e. Prefix127), the generated decision tree is as follows: Figure 2 As shown in the figure, Prefix 127 is the root node, Prefix 128 is the right child node of the root node, and other prefix lengths are the left branches of the root node.
[0094] After receiving the message of Prefix 127, it first matches the root node Prefix 127 of the decision tree. At this time, the match is successful. Based on the principle of matching the longest prefix, it needs to match the right child node Prefix 128 of the root node. At this time, the match fails, and the right child node Prefix 128 has no left or right branches, so it is finally determined that the message of Prefix 127 matches the root node. The outbound interface can be determined by matching the decision tree twice.
[0095] The above decision tree can be generated according to the probability of the forwarded message hitting each prefix length. For the convenience of description, in the embodiment of the present application, the meanings of the symbols involved are as follows:
[0096] P x Indicates the probability of a packet hitting Prefix X;
[0097] cost(m,n) represents the expected number of steps required to find the optimal decision tree from prefix m to prefix n.
[0098] Taking IPv6 as an example, the goal of building the optimal decision tree is to solve cost(1,128), that is, to find the optimal decision tree from prefix 1 to prefix 128, and the expected number of steps required.
[0099] For cost (1,128), assuming that 50 is selected as the root node, then the message has P1+P2+…+P 49 The probability of entering the left branch is 50. 50 +P 51 +…+P128 The probability of entering the right branch is 50.
[0100] The expected consumption steps of selecting 50 as the root node are: 1+(P1+P2+…+P 49 )*Cost(1,49)+(P 50 +P 51 +…+P 128 )*Cost(51,128).
[0101] In the above formula, 1 is the number of steps consumed by matching the root node of the decision tree. Cost(1,49) is the number of steps consumed by matching the left branch of the decision tree. Cost(51,128) is the number of steps consumed by matching the right branch of the decision tree.
[0102] When selecting the root node, the goal is to minimize the cost (1,128), that is, the fewer steps consumed by the matching decision tree, the faster the overall message matching speed.
[0103] Therefore, cost(1,128)=min(1+(P1+P2+…+P j-1 )*Cost(1,j-1)+(P j +P j+1 +…+P 128 )*Cost(j+1,128)), where 1<=j<=128, and it is stipulated that when j+1>128, Cost(j+1,128)=0.
[0104] For Cost(1,1), Cost(2,2),…, Cost(n,n), the value is fixed at 1.
[0105] Then, for Cost(m,n), the formula is:
[0106] Cost(m,n)=min(1+(P m-1 +P m +…P j-1 ) / (P m-1 +P m +…P n )*Cost(m,j-1)+(P j +…P n ) / (P m-1 +P m +…P n )*Cost(j+1,n)).
[0107] Where m<=j<=n, and it is stipulated that when j+1>n, Cost(j+1,n)=0. If m-1 is 0, then P m-1 Calculated as 0.
[0108] There are two cases when matching a message from prefix m to prefix n: one is that the longest prefix matched by the message is m-1, and cost(m,n) is entered to confirm whether there is no better match than prefix m-1. The other is that the longest prefix matched by the message is longer than m-1, so a better match needs to be found from prefix m to prefix n.
[0109] For the first case, if the probability of a message hitting m-1 is very high, but the probability of hitting m is very low, assuming that the probability of a message hitting m-1 is not considered when calculating cost(m,n), then the node corresponding to prefix m in the sub-decision tree of cost(m,n) may be far away from the root node of cost(m,n), resulting in more steps being consumed when determining the longest match for m-1. Therefore, in the embodiment of the present application, the probability of a message hitting m-1 is also considered when calculating cost(m,n), thereby speeding up the message matching speed.
[0110] Combined with the definition of Cost(m,n), the optimal decision tree can be dynamically generated through the matrix.
[0111] For IPv6 networks, the maximum length of a prefix is 128 bits, so a 128X 128 matrix can be defined. Each point in the matrix contains two pieces of information: the cost of the node and the split point selected when calculating the cost.
[0112] For example, the point (2,5) records Cost(2,5) and the split point selected when calculating Cost(2,5).
[0113] When calculating the optimal decision tree through a matrix, a matrix can be generated. First, the Cost(m,n) and splitting point (Split) of the points on the diagonal of the matrix are calculated. Then, the diagonal is shifted right by one grid as a whole. The Cost(m,n) and splitting point (Split) of each point on the diagonal obtained after the right shift are calculated. Then, the right shift is continued until all the points on the right side of the diagonal of the matrix are calculated.
[0114] Taking a 5X5 matrix as an example, the calculation order is as follows Figure 3 shown.
[0115] The first round starts from the upper left to the lower right and calculates the cost and splitting point corresponding to the point at the left oblique shadow.
[0116] The second round starts from the upper left to the lower right to calculate the cost and splitting points corresponding to the points at the horizontal line shadow.
[0117] The third round starts from the upper left to the lower right to calculate the cost and splitting point corresponding to the point at the vertical line shadow.
[0118] The fourth round starts from the upper left to the lower right to calculate the cost and splitting point corresponding to the point at the right diagonal shadow.
[0119] The fifth round calculates the cost and splitting points corresponding to the points in the grid shadow.
[0120] Then, we start traversing from (1,5) of the matrix to obtain the final decision tree.
[0121] Assuming the Split of node (1,5) is 2, the resulting decision tree is as follows Figure 4a As shown in the figure, the root node is prefix2, the left child node corresponds to (1,1) in the matrix, and the right child node corresponds to (3,5) in the matrix. Assuming that the Split corresponding to (3,5) is 4, then the optimal decision tree shape is as follows: Figure 4b shown.
[0122] The following is a method for constructing an optimal decision tree using a specific example. Taking the longest prefix of 5 as an example, a 5x 5 matrix is constructed.
[0123] The network device can periodically calculate the probability of the received message hitting each prefix length, and generate an optimal decision tree based on the probability, so that the prefix length with a higher hit rate is closer to the root node.
[0124] Assumption: The probability of hitting Prefix 1 is 20%.
[0125] The probability of hitting Prefix2 is 5%.
[0126] The probability of hitting Prefix3 is 10%.
[0127] The probability of hitting Prefix4 is 10%.
[0128] The probability of hitting Prefix5 is 55%.
[0129] First, the cost and splitting point of each point on the diagonal of the matrix are calculated, Cost(1,1), Cost(2,2),…, Cost(5,5), the value is fixed to 1, and there is no splitting point, so the calculation results are shown in Table 1.
[0130] Table 1
[0131]
[0132] Then calculate Cost(1,2), Cost(2,3), Cost(3,4), Cost(4,5)
[0133] When calculating Cost(1,2), you can choose 1 or 2 as the split point.
[0134] When 1 is selected as the split point, Cost(1,2) is: 1+(20%+5%) / (20%+5%)*Cost(2,2)=2;
[0135] When 2 is selected as the split point, Cost(1,2) is: 1+20% / (20%+5%)*Cost(1,1)=1.8
[0136] Therefore, the splitting point of Cost(1,2) should be 2, and its Cost(1,2)=1.8.
[0137] When calculating Cost(2,3), you can choose 2 or 3 as the split point.
[0138] When 2 is selected as the split point, Cost(2,3)=1+(5%+10%) / (20%+5%+10%)*Cost(3,3)=1.42;
[0139] When 3 is selected as the split point, Cost(2,3)=1+(20%+5%) / (20%+5%+10%)*Cost(2,2)=1.71;
[0140] Therefore, the splitting point of Cost(2,3) should be 2, and Cost(2,3)=1.42.
[0141] When calculating Cost(3,4), you can choose 3 or 4 as the split point.
[0142] When 3 is selected as the split point, Cost(3,4)=1+(10%+10%) / (5%+10%+10%)*Cost(4,4)=1.8;
[0143] When 4 is selected as the split point, Cost(3,4)=1+(5%+10%) / (5%+10%+10%)*Cost(3,3)=1.6;
[0144] Therefore, the split point of Cost(3,4) should be 4, and Cost(3,4)=1.6.
[0145] When calculating Cost(4,5), you can choose 4 or 5 as the split point
[0146] When 4 is selected as the split point, Cost(4,5)=1+(10%+55%) / (10%+10%+55%)*Cost(4,4)=1.86;
[0147] When 5 is selected as the split point, Cost(4,5)=1+(10%+10%) / (10%+10%+55%)*Cost(5,5)=1.26
[0148] Therefore, the split point of Cost(4,5) should be 5, and Cost(4,5)=1.26.
[0149] At this time, the matrix in Table 1 is updated to the following Table 2.
[0150] Table 2
[0151]
[0152] Next, calculate Cost(1,3), Cost(2,4), Cost(3,5)
[0153] For Cost(1,3), you can choose 1, 2 or 3 as the split point:
[0154] When 1 is selected as the split point, Cost(1,3)=1+(20%+5%+10%) / (20%+5%+10%)*Cost(2,3)=2.42;
[0155] When 2 is selected as the split point, Cost(1,3)=1+20% / (20%+5%+10%)*Cost(1,1)+(5%+10%) / (20%+5%+10%)*Cost(3,3)=2;
[0156] When 3 is selected as the split point, Cost(1,3)=1+(20%+5%) / (20%+5%+10%)*Cost(1,2)=2.28;
[0157] Therefore, the splitting point of Cost(1,3) should be 2, and Cost(1,3)=2.
[0158] For Cost(2,4), you can choose 2, 3 or 4 as the split point:
[0159] When 2 is selected as the split point, Cost(2,4)=1+(5%+10%+10%) / (20%+5%+10%+10%)*Cost(3,4)=2.15;
[0160] When 3 is selected as the split point, Cost(2,4)=1+(20%+5%) / (20%+5%+10%+10%)*Cost(2,2)+(10%+10%) / (20%+5%+10%+10%)*Cost4,4)=2;
[0161] When 4 is selected as the split point, Cost(2,4)=1+(20%+5%+10%) / (20%+5%+10%+10%)*Cost(2,3)=2.10;
[0162] Therefore, the split point of Cost(2,4) should be 3, and Cost(2,4)=2.
[0163] For Cost(3,5), you can choose 3, 4 or 5 as the split point:
[0164] When 3 is selected as the split point, Cost(3,5)=1+(10%+10%+55%) / (5%+10%+10%+55%)*Cost(4,5)=2.18;
[0165] When 4 is selected as the split point, Cost(3,5)=1+(5%+10%) / (5%+10%+10%+55%)*Cost(3,3)+(10%+55%) / (5%+10%+10%+55%)*Cost(5,5)=2
[0166] When 5 is selected as the split point, Cost(3,5)=1+(5%+10%+10%) / (5%+10%+10%+55%)*Cost(3,4)=1.5;
[0167] Therefore, the split point of Cost(3,5) should be 5, Cost(3,5)=1.5.
[0168] At this time, the matrix shown in Table 2 is updated to the following Table 3:
[0169] Table 3
[0170]
[0171] Then calculate Cost(1,4) and Cost(2,5).
[0172] For Cost(1,4), the split points that can be chosen are 1, 2, 3, or 4.
[0173] When 1 is selected as the split point, Cost(1,4)=1+(20%+5%+10%+10%) / (20%+5%+10%+10%)*Cost(2,4)=3;
[0174] When 2 is selected as the split point, Cost(1,4)=1+(20%) / (20%+5%+10%+10%)*Cost(1,1)+(5%+10%+10%) / (20%+5%+10%+10%)*Cost(3,4)=2.33;
[0175] When 3 is selected as the split point, Cost(1,4)=1+(20%+5%) / (20%+5%+10%+10%)*Cost(1,2)+(10%+10%) / (20%+5%+10%+10%)*Cost(4,4)=2.44;
[0176] When 4 is selected as the split point, Cost(1,4)=1+(20%+5%+10%) / (20%+5%+10%+10%)*Cost(1,3)=2.55;
[0177] Therefore, the split point of Cost(1,4) should be 2, and Cost(1,4)=2.33.
[0178] For Cost(2,5), the possible split points are 2, 3, 4 or 5.
[0179] When 2 is selected as the split point, Cost(2,5)=1+(5%+10%+10%+55%) / 100%*Cost(3,5)=2.20;
[0180] When 3 is selected as the split point, Cost(2,5)=1+(20%+5%) / 100%*Cost(2,2)+(10%+10%+55%) / 100%*Cost(4,5)=2.195;
[0181] When 4 is selected as the split point, Cost(2,5)=1+(20%+5%+10%) / 100%*Cost(2,3)+(10%+55%) / 100%*Cost(5,5)=2.147;
[0182] When 5 is selected as the split point, Cost(2,5)=1+(20%+5%+10%+10%) / 100%*Cost(2,4)=1.9
[0183] Therefore, the split point of Cost(2,5) should be 5, and Cost(2,5)=1.9.
[0184] At this time, the matrix shown in Table 3 is updated to the following Table 4:
[0185] Table 4
[0186]
[0187]
[0188] Finally, calculate Cost(1,5), where the optional Split points are 1, 2, 3, 4, or 5.
[0189] When 1 is selected as the split point, Cost(1,5)=1+(20%+5%+10%+10%+55%) / 100%*Cost(2,4)=3;
[0190] When 2 is selected as the split point, Cost(1,5)=1+20% / 100%*Cost(1,1)+80% / 100%*Cost(3,5)=2.4;
[0191] When 3 is selected as the split point, Cost(1,5)=1+25% / 100%*Cost(1,2)+75% / 100%*Cost(4,5)=2.395;
[0192] When 4 is selected as the split point, Cost(1,5)=1+35% / 100%*Cost(1,3)+65% / 100%*Cost(5,5)=2.35;
[0193] When 5 is selected as the split point, Cost(1,5)=1+45% / 100%*Cost(1,4)=2.04
[0194] Therefore, the split point of Cost(1,5) should be 5, and Cost(1,5)=2.04.
[0195] At this time, the matrix shown in Table 4 is updated to the following Table 5:
[0196] Table 5
[0197]
[0198] Then, starting from (1,5) of the matrix, we traverse the split points layer by layer to generate a decision tree.
[0199] First, the split point of (1,5) is 5, and the shape of the tree is as follows Figure 5a As shown, prefix 5 is the root node, the left branch of the root node is prefix 1 to prefix 4, and the right branch is empty.
[0200] Then we can see from the matrix that the split point of (1,4) is 2, so the shape of the decision tree is as follows Figure 5b As shown, the left branch of split point 2 is 1, and the right branch is prefix 3 to prefix 4.
[0201] The split point of (3,4) is 4, so the shape of the decision tree is Figure 5c As shown, the left branch of split point 4 is 3, and there is no right branch. Figure 5c This is the optimal decision tree generated.
[0202] In an embodiment of the present application, the above-mentioned optimal decision tree is cached in the CPU cache in the form of an array structure, and the corresponding FIB is stored in the memory in the form of a key-value. During the message matching process, the memory needs to be frequently accessed to obtain the output interface corresponding to the prefix length of the message match, which makes the message matching speed slower.
[0203] In order to speed up the matching speed, a data prefetch instruction (Prefetch) can be used to prompt the CPU that data in certain memory is about to be accessed, so that the CPU's memory management module asynchronously obtains the data to be accessed from the memory.
[0204] However, due to the imbalance of the left and right branches of the optimal decision tree, the search path length for each message to be forwarded is also inconsistent. For example, if message 1 and message 2 are matched at the same time, the outbound interface can be determined after one decision tree match for message 1, while the outbound interface can be determined after five decision tree matches for message 2. Then, after matching message 1 once, the forwarding of message 1 can be completed. Subsequently, the matching is actually performed for message 2, so the pre-fetch operation is meaningless, and the problem of slow message matching still exists.
[0205] In order to solve the above problems, the present application provides a message matching method, such as Figure 6 As shown, the method includes:
[0206] S601. Add N first data packets to N pipelines, and set the stage of each pipeline as the root node of a decision tree.
[0207] The decision trees described below are all optimal decision trees. Each node in the decision tree represents a prefix length. N can be preset based on the processing power of the CPU. As an example, N can be 2.
[0208] Assume that the current network device receives two data packets, namely, packet 1 and packet 2, and the destination addresses of packet 1 and packet 2 are IPv6Addr1 and IPv6Addr2 respectively. Message 1 can be added to pipeline 1, and message 2 can be added to pipeline 2. The stages of pipeline 1 and pipeline 2 are both root nodes of the decision tree. Because the root node of the decision tree is the prefix length with the highest probability of being matched, in the embodiment of the present application, each message to be forwarded starts matching from the root node of the decision tree, which can improve the message matching speed.
[0209] S602, calculate the first hash value of the first pipeline among the N pipelines, and asynchronously pre-fetch the first output interface data corresponding to the first hash value from the memory, and store the first output interface data in the cache, while pre-fetching the first output interface data from the memory, calculate the second hash value of the second pipeline among the N pipelines, repeat the process of asynchronously pre-fetching the output interface data corresponding to the hash value from the memory, storing the output interface data in the cache, and calculating the hash value of the pipeline while pre-fetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped.
[0210] The hash value of each pipeline is the hash value of the destination address of the data message included in the pipeline and the prefix length corresponding to the stage.
[0211] The above-mentioned process of prefetching the first output interface data from the memory is an asynchronous operation. Prefetching the first output interface data from the memory while calculating the second hash value of the second pipeline among the N pipelines means: after calculating the first hash value of the first pipeline, the CPU thread continues to calculate the hash value of the second pipeline. At the same time, the CPU's memory management module starts to asynchronously prefetch the first output interface data from the memory.
[0212] Similarly, after the CPU thread calculates the hash value of the second pipeline, no matter whether the CPU memory management module has pre-fetched the first output interface data, the CPU thread will continue to calculate the hash value of the third pipeline.
[0213] Continuing the example in the previous step, assuming that the prefix length of the root node is PrefixLen1, the network device can calculate the hash value of IPv6Addr1 and PrefixLen1 to obtain HashValue1. The pre-fetch instruction of the CPU of the network device is asynchronously executed, so that the memory management module of the CPU asynchronously obtains the outbound interface data corresponding to HashValue1 from the memory and caches it in the CPU cache.
[0214] Among them, the operation of executing the above-mentioned prefetch instruction is an asynchronous operation, that is, after the CPU thread calculates HashValue1, it continues to calculate the hash value of IPv6Addr2 and PrefixLen1 to obtain HashValue2. The operation of executing the CPU prefetch instruction will not affect the process of the CPU thread calculating the hash value for each of the N pipelines in turn.
[0215] S603: When the hash value of each pipeline in the N pipelines has been calculated, obtain the first output interface data from the cache.
[0216] Because the CPU has obtained the outbound interface data corresponding to HashValue1 from the memory in advance and cached it in the CPU cache, after the network device calculates the hash values of the above N pipelines and needs to obtain the outbound interface data corresponding to HashValue1, the outbound interface data corresponding to HashValue1 has been cached in the CPU cache, so the network device can obtain the outbound interface data corresponding to HashValue1 from the cache.
[0217] Similarly, after calculating HashValue2, the network device will also asynchronously pre-fetch the outbound interface data corresponding to HashValue2 and cache it in the CPU cache. Then, when the network device needs to obtain the outbound interface data corresponding to HashValue2, it does not need to access the memory, but can directly obtain the outbound interface data corresponding to HashValue2 from the cache.
[0218] Accordingly, the network device may sequentially obtain the outbound interface data corresponding to the hash of each pipeline from the cache.
[0219] S604: When the first output interface data is characterized as being used to forward the first data packet in the first pipeline, the first data packet in the first pipeline is deleted from the first pipeline, and when the second data packet is received, the second data packet is added to the first pipeline.
[0220] For each pipeline, if the output interface data corresponding to the hash value of the pipeline is characterized as being used to forward data packets in the pipeline, the data packets in the pipeline are forwarded through the output interface corresponding to the hash value of the pipeline, and the data packets in the pipeline are deleted from the pipeline.
[0221] In an embodiment of the present application, after the first data packet in the first pipeline is deleted from the first pipeline, the first pipeline becomes idle. If the network device receives a second data packet, or there is a second data packet in the network device that does not match the output interface, the second data packet is added to the first pipeline, and the stage of the first pipeline is set to the root node of the decision tree.
[0222] By adopting the embodiment of the present application, N first data messages can be matched through N pipelines. After adding the N first data messages to the N pipelines, the first hash value of the first pipeline in the N pipelines can be calculated, and the first output interface data corresponding to the first hash value can be pre-fetched from the memory asynchronously, and the first output interface data can be stored in the cache. While pre-fetching the first output interface data from the memory, the second hash value of the second pipeline in the N pipelines is calculated. In this way, it is equivalent to asynchronously pre-fetching the output interface data corresponding to the hash value from the memory every time the hash value of one pipeline in the N pipelines is calculated. In this way, when the first output interface data corresponding to the first hash value needs to be obtained, there is no need to access the memory, and the first output interface data can be directly obtained from the cache, which reduces the time required for message matching. And if the first output interface data is characterized as being used to forward the first data message in the first pipeline, the first data message in the first pipeline is deleted from the first pipeline, so that the second data message is added to the first pipeline for processing. Compared with the prior art in which the received second data message can only be processed after the first data messages in N pipelines are forwarded, in the embodiment of the present application, as long as a data message is deleted from the pipeline, the second data message can be added to the pipeline and processing can begin, which can speed up the matching and forwarding speed of the received data message.
[0223] The embodiment of the present application does not limit the storage structure of the HASH FIB in the memory. As an example, in one embodiment of the present application, the summary of the FIB is stored in the hash bucket (Bucket) of the hash table, each Bucket is a storage space of 64Bytes, and can store 8 FIB summaries. Each FIB summary includes a tag (TAG) and a data pointer (DATAPointer). The TAG is a HASH value calculated according to the IPv6Addr and PrefixLen, and the data pointer is used to indicate the storage location of the actual FIB ENTRY.
[0224] Based on the above storage structure, take the current network device receiving two first data messages, and there are two pipelines in the CPU of the network device as an example, assuming that message 1 and message 2 are received, the destination addresses of message 1 and message 2 are IPv6Addr1 and IPv6Addr2 respectively, message 1 is added to pipeline 1, and message 2 is added to pipeline 2. The root node of the decision tree is PrefixLen1. Then the above process can be expressed as:
[0225] HashValue1 = Hash(IPv6Addr1, PrefixLen1); / / Calculate the hash value of IPv6Addr1 and PrefixLen1 to get HashValue1;
[0226] Prefetch(&Bucket[HashValue1]); / / Prompt the CPU to access the Bucket containing HashValue1 so that the CPU prefetches the FIB summary in Bucket[HashValue1];
[0227] HashValue2 = Hash(IPv6Addr2, PrefixLen1);); / / Calculate the hash value of IPv6Addr2 and PrefixLen1 to get HashValue2;
[0228] Prefetch(&Bucket[HashValue2]) / / Prompt the CPU to access the Bucket containing HashValue2 so that the CPU prefetches the FIB summary in Bucket[HashValue2];
[0229] DataPointer1 = Bucket[HashValue1]; / / The network device obtains the data in Bucket[HashValue1]. At this time, because the data in Bucket[HashValue1] is already in the cache, there is no need to access the memory, and the CPU will not wait for data. After obtaining the FIB summary in Bucket[HashValue1], the network device can determine whether the DataPointer1 corresponding to HashValue1 exists in the FIB summary. If so, the outbound interface data corresponding to DataPointer1 will be obtained later.
[0230] Prefetch(DataPointer1); / / Prompt the CPU that DataPointer1 is about to be accessed, so that the CPU prefetches and caches the outbound interface data corresponding to DataPointer1 from the memory.
[0231] DataPointer2 = Bucket[HashValue2]; / / The network device obtains the data in Bucket[HashValue2]. At this time, because the FIB summary in Bucket[HashValue2] is already in the cache, there is no need to access the memory, and the CPU will not wait for data. After obtaining the FIB summary in Bucket[HashValue2], the network device can determine whether the DataPointer2 corresponding to HashValue1 exists in the Bucket. If so, the outbound interface data corresponding to DataPointer2 will be obtained later.
[0232] Prefetch(DataPointer2); / / Prompt the CPU that DataPointer2 is about to be accessed, so that the CPU prefetches and caches the outbound interface data corresponding to DataPointer2 from the memory.
[0233] Access DataPointer1; / / Get the output interface data corresponding to DataPointer1. Since the output interface data corresponding to DataPointer1 already exists in the cache, there is no need to access the memory at this time, and the CPU will not be caused to wait.
[0234] Access DataPointer2; / / Get the output interface data corresponding to DataPointer2. Since the output interface data corresponding to DataPointer2 already exists in the cache, there is no need to access the memory at this time, and the CPU will not be caused to wait.
[0235] Update IPv6Addr1 Stage&Output Interface; / / Update the stage and output interface of the pipeline to which the message of IPv6Addr1 belongs;
[0236] Update IPv6Addr2 Stage&Output Interface / / Update the stage and output interface of the pipeline to which the IPv6Addr2 message belongs.
[0237] It can be seen that each time the network device needs to obtain data in the memory, the data to be accessed has been pre-acquired and cached, which can save the time consumed by the network device to access the memory when it needs to obtain data, and can speed up the message matching speed.
[0238] In another embodiment of the present application, after the first outbound interface data is obtained from the cache in S603, the method further includes:
[0239] Determine whether the right child node of the root node in the decision tree is empty; if so, determine that the first output interface data is characterized as being used to forward the first data message in the first pipeline; if not, determine that the first output interface data is not characterized as being used to forward the first data message in the first pipeline.
[0240] For each node in the decision tree, the prefix length of the left child of the node is less than the prefix length of the right child. If the first outbound interface data has been obtained and the right child of the root node is empty, it means that there is no better match in the decision tree, so it can be determined that the first outbound interface data is characterized as being used to forward the first data message in the first pipeline, then the matching of the message to be forwarded is completed, and the first data message in the first pipeline is forwarded through the first outbound interface data.
[0241] If the right child node of the root node is empty, it means that there is a prefix length longer than the prefix length corresponding to the root node in the HASH FIB. According to the longest match principle, it is necessary to further determine whether the first data message in the first pipeline can hit a longer prefix length, so the first data interface data may not be the best match at this time, that is, the first output interface data is not characterized as being used to forward the first data message in the first pipeline.
[0242] In the embodiment of the present application, when the first outbound interface data is not represented as being used to forward the first data packet in the first pipeline, the stage of the first pipeline is updated to the right child node of the root node, and the outbound interface information in the first pipeline is updated to the first outbound interface data. Thus, in the next round of matching, the first data packet in the first pipeline is matched with the prefix length represented by the updated stage.
[0243] In the next round of matching, the hash value of the prefix length represented by the first data packet in the first pipeline and the updated stage is calculated, and the outbound interface data corresponding to the hash value is obtained asynchronously. If the outbound interface data corresponding to the hash value is not obtained, it means that the first outbound interface data is characterized as being used to forward the first data packet in the first pipeline. If the outbound interface data corresponding to the hash value is obtained, the outbound interface information in the first pipeline is updated to the outbound interface data obtained this time.
[0244] In another embodiment of the present application, if the first output interface data corresponding to the first hash value cannot be obtained from the cache, the stage of the first pipeline is updated to the left child node of the root node.
[0245] Among them, if the first output interface data corresponding to the first hash value cannot be obtained from the cache, it means that the first output interface data corresponding to the first hash value is not pre-fetched from the memory, that is, the first data packet in the first pipeline does not match the prefix length represented by the root node of the decision tree, and should be matched with a shorter prefix length in the next round of matching, so the stage of the first pipeline can be updated to the left child node of the root node.
[0246] It can be understood that in the embodiment of the present application, after matching the first data packet in each pipeline, the stage in the pipeline needs to be updated. Taking the first pipeline as an example, the specific cases are as follows:
[0247] Case 1: The first outbound interface data corresponding to the first hash value of the first pipeline is obtained from the cache, and the first outbound interface data is characterized as being used to forward the first data packet in the first pipeline, then the stage of the first pipeline is updated to complete the match.
[0248] Case 2: The first outbound interface data corresponding to the first hash value of the first pipeline is obtained from the cache, and the first outbound interface data is not represented as being used to forward the first data packet in the first pipeline, then the stage of the first pipeline is updated to the right child node of the current stage.
[0249] For example, if the current stage of the first pipeline is the root node, the stage of the first pipeline is updated to the right child node of the root node.
[0250] Case 3: If the first output interface data corresponding to the first hash value of the first pipeline is not obtained from the cache, the stage of the first pipeline is updated to the left child node of the current stage.
[0251] For example, if the current stage of the first pipeline is the root node, the stage of the first pipeline is updated to the left child node of the root node.
[0252] In the above S603, when the hash value of each of the N pipelines has been calculated, the network device can obtain the output interface data corresponding to the hash value of each pipeline from the cache in turn, and update the stage of the pipeline in turn according to the situation of obtaining the output interface data corresponding to the hash value of each pipeline.
[0253] Among them, the method for updating the stage of each pipeline is the same as the method for updating the stage of the first pipeline described in the embodiment of the present application.
[0254] When the stage of each of the N pipelines has completed an update, the first data packet in the pipeline whose stage has completed matching can be deleted from the pipeline, so that other data packets received by the network device can be added to the pipeline, which can improve the matching and forwarding efficiency of the received data packets.
[0255] It should be noted that, in one case, if the stage of each pipeline in the N pipelines is updated once, and the stage pipeline of the pipeline that does not exist is not matched, then the first data message in the N pipelines is matched in the next round. The method for performing the next round of matching is the same as the method of S602-S604 above.
[0256] In another case, if other data packets received by the network device have been added to the pipeline and there is no idle pipeline at this time; or there are no other data packets to be forwarded in the network device, the next round of matching is performed on the data packets in the N pipelines.
[0257] It can be seen that in the embodiment of the present application, N data packets can be matched through N pipelines. When the matching of any data packet is completed, the data packet is deleted from the pipeline, and other packets to be forwarded are added to the pipeline, which can increase the matching speed of the packets to be forwarded.
[0258] The following Figure 5c Taking the decision tree shown in FIG. 1 as an example, the process of processing the pipeline is explained.
[0259] Assume that the number of pipelines is 2, that is, the maximum number of packets to be forwarded that can be processed simultaneously is 2.
[0260] If there are 4 packets to be forwarded in the current network device, they are sorted in order of receiving time from earliest to latest, namely Packet 1, Packet 2, Packet 3, and Packet 4. Assume that the prefix lengths that can be hit by each packet to be forwarded are:
[0261] Packet 1 hits Prefix 5;
[0262] Packet 2 hits Prefix 3;
[0263] Packet 3 hits Prefix 5;
[0264] Pakcet 4 hits Prefix 2.
[0265] Assume that the output interface corresponding to Prefix1 is 1, the output interface corresponding to Prefix2 is 2, the output interface corresponding to Prefix3 is 3, the output interface corresponding to Prefix4 is 4, and the output interface corresponding to Prefix5 is 5.
[0266] First, add Packet 1 and Packet 2 to the pipeline respectively. The pipeline is now as shown in Table 6:
[0267] Table 6
[0268]
[0269] After a pipeline process (advance operation), the destination address of Packet 1 matches Prefix 5, and Figure 5cAs can be seen, the right child node of Prefix 5 is empty, so Packet 1 is matched, and the Stage of pipeline 1 is updated to match completed (FINISH). And the destination address of Packet 2 fails to match Prefix 5, so Packet 2 needs to match the left child node of Prefix 5, Prefix 2, next time, so the Stage of pipeline 2 is updated to 2. At this time, each pipeline is shown in Table 7:
[0270] Table 7
[0271]
[0272] At this point, each pipeline has been processed once, and it can be detected whether there is a pipeline whose Stage is matched. According to Table 7, Packet 1 has completed the match, so Packet 1 can be deleted from Pipeline 1 and forwarded through outbound interface 5.
[0273] After Packet 1 is deleted from Pipeline 1, Pipeline 1 becomes idle, and Packet 3 can be added to Pipeline 1. Packet 2 is still retained in Pipeline 2 because it has not been matched yet. At this time, the pipelines are shown in Table 8:
[0274] Table 8
[0275]
[0276] After processing the pipelines once more, the pipelines are as shown in Table 9:
[0277] Table 9
[0278]
[0279] According to Table 9, Packet3 has been matched, so Packet3 is deleted from Pipeline1 and Packet4 is added to Pipeline1. At this time, the pipelines are shown in Table 10:
[0280] Table 10
[0281]
[0282] After another processing of the pipeline, each pipeline is as shown in Table 11:
[0283] Table 11
[0284]
[0285] After processing the pipelines again, the pipelines are as shown in Table 12:
[0286] Table 12
[0287]
[0288]
[0289] At this time, Packet2 completes the matching and is deleted from Pipeline2. At this time, there is no newly received message to be forwarded in the network device, so Pipeline2 is empty. After Pipeline1 is processed again, the pipelines are shown in Table 13.
[0290] Table 13
[0291]
[0292] After one more processing, the pipelines are as shown in Table 14.
[0293] Table 14
[0294]
[0295] At this point, the processing of Packet 1, Packet 2, Packet 3, and Packet 4 has been completed.
[0296] Corresponding to the above method embodiment, the present application embodiment also provides a message matching device, such as Figure 7 As shown, the device comprises:
[0297] A setting module 701 is used to add N first data packets to N pipelines, and set the stage of each pipeline as the root node of a decision tree, each node in the decision tree represents a prefix length and each node represents a different prefix length;
[0298] A pre-fetch module 702 is used to calculate a first hash value of a first pipeline among the N pipelines, and asynchronously pre-fetch a first output interface data corresponding to the first hash value from a memory, and store the first output interface data in a cache, and simultaneously calculate a second hash value of a second pipeline among the N pipelines while pre-fetching the first output interface data from the memory, and repeatedly perform the process of asynchronously pre-fetching the output interface data corresponding to the hash value from the memory, and storing the output interface data in the cache, and simultaneously calculating the hash value of the pipeline while pre-fetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped; wherein the hash value of the pipeline is a hash value of the destination address of the data message in the pipeline and the prefix length represented by the stage;
[0299] The acquisition module 703 is used to acquire the first output interface data from the cache when the hash value of each pipeline in the N pipelines has been calculated;
[0300] The setting module 701 is also used to delete the first data packet in the first pipeline from the first pipeline when the first output interface data is characterized as being used to forward the first data packet in the first pipeline, and to add the second data packet to the first pipeline when receiving the second data packet.
[0301] Optionally, the device further comprises:
[0302] The update module is used to update the stage of the first pipeline to the right child node of the root node and update the output interface information in the first pipeline to the first output interface data when the first output interface data is not characterized as being used to forward the first data packet in the first pipeline.
[0303] Optionally, the device further includes: a judgment module, configured to:
[0304] Determine whether the right child node of the root node in the decision tree is empty;
[0305] If so, determining that the first outbound interface data representation is used to forward the first data message in the first pipeline;
[0306] If not, it is determined that the first outbound interface data is not characterized as being used to forward the first data packet in the first pipeline.
[0307] Optionally, the device further comprises:
[0308] The update module is used to update the stage of the first pipeline to the left child node of the root node if the first output interface data corresponding to the first hash value cannot be obtained from the cache.
[0309] Optionally, the device further comprises:
[0310] An updating module, configured to update the stage of the first pipeline to complete matching when the first output interface data is characterized as being used to forward the first data packet in the first pipeline;
[0311] The setting module 701 is specifically used to delete the first data packet in the pipeline whose stage has completed matching from the pipeline after the stages of the N pipelines have all completed an update.
[0312] The present application also provides a network device, such as Figure 8As shown, it includes a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802, and the memory 803 communicate with each other through the communication bus 804.
[0313] Memory 803, used for storing computer programs;
[0314] The processor 801 is used to implement the method steps in the above method embodiment when executing the program stored in the memory 803.
[0315] The communication bus mentioned in the above network device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0316] The communication interface is used for communication between the above network devices and other devices.
[0317] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0318] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0319] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned message matching methods are implemented.
[0320] In another embodiment provided in the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any message matching method in the above embodiments.
[0321] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0322] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0323] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0324] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A message matching method, characterized in that: include: Adding N first data packets to N pipelines, setting the stage of each pipeline as the root node of a decision tree, wherein each node in the decision tree represents a prefix length and each node represents a different prefix length; Calculate a first hash value of a first pipeline among the N pipelines, and asynchronously pre-fetch first output interface data corresponding to the first hash value from a memory, and store the first output interface data in a cache, while pre-fetching the first output interface data from the memory, calculate a second hash value of a second pipeline among the N pipelines, repeat the process of asynchronously pre-fetching output interface data corresponding to the hash value from the memory, storing the output interface data in the cache, and calculating the hash value of the pipeline while pre-fetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped; wherein the hash value of the pipeline is a hash value of the destination address of the data message in the pipeline and the prefix length represented by the stage; When the hash value of each pipeline in the N pipelines has been calculated, obtaining the first output interface data from the cache; When the first output interface data is characterized as being used to forward the first data packet in the first pipeline, the first data packet in the first pipeline is deleted from the first pipeline, and when a second data packet is received, the second data packet is added to the first pipeline.
2. The method according to claim 1, characterized in that After acquiring the first outbound interface data from the cache, the method further includes: When the first output interface data is not characterized as being used to forward the first data packet in the first pipeline, the stage of the first pipeline is updated to the right child node of the root node, and the output interface information in the first pipeline is updated to the first output interface data.
3. The method according to claim 1 or 2, characterized in that: After acquiring the first outbound interface data from the cache, the method further includes: Determine whether the right child node of the root node in the decision tree is empty; If so, determining that the first outbound interface data representation is used to forward the first data message in the first pipeline; If not, it is determined that the first outbound interface data is not characterized as being used to forward the first data packet in the first pipeline.
4. The method according to claim 1, characterized in that: The method further comprises: If the first output interface data corresponding to the first hash value cannot be obtained from the cache, the stage of the first pipeline is updated to the left child node of the root node.
5. The method according to claim 1, characterized in that The method further comprises: When the first output interface data is characterized as being used to forward the first data packet in the first pipeline, updating the stage of the first pipeline to complete matching; The deleting the first data message in the first pipeline includes: When the stages of the N pipelines are all updated once, the first data packet in the pipeline whose stage has completed matching is deleted from the pipeline.
6. A message matching device, characterized in that: include: A setting module, used for adding N first data packets to N pipelines, setting the stage of each pipeline as the root node of a decision tree, wherein each node in the decision tree represents a prefix length and each node represents a different prefix length; A prefetch module, used to calculate a first hash value of a first pipeline among the N pipelines, and asynchronously prefetch first output interface data corresponding to the first hash value from a memory, and store the first output interface data in a cache, and calculate a second hash value of a second pipeline among the N pipelines while prefetching the first output interface data from the memory, and repeat the process of asynchronously prefetching the output interface data corresponding to the hash value from the memory, storing the output interface data in the cache, and calculating the hash value of the pipeline while prefetching the interface data from the memory, until the hash value of each pipeline among the N pipelines has been calculated and stopped; wherein the hash value of the pipeline is a hash value of the destination address of the data message in the pipeline and the prefix length represented by the stage; An acquisition module, configured to acquire the first output interface data from the cache when the hash value of each of the N pipelines has been calculated; The setting module is also used to delete the first data packet in the first pipeline from the first pipeline when the first output interface data is characterized as being used to forward the first data packet in the first pipeline, and when a second data packet is received, add the second data packet to the first pipeline.
7. The device according to claim 6, characterized in that The device also includes: An updating module is used to update the stage of the first pipeline to the right child node of the root node and update the output interface information in the first pipeline to the first output interface data when the first output interface data is not represented as being used to forward the first data packet in the first pipeline.
8. The device according to claim 6 or 7, characterized in that The device further comprises: a judging module, configured to: Determine whether the right child node of the root node in the decision tree is empty; If so, determining that the first outbound interface data representation is used to forward the first data message in the first pipeline; If not, it is determined that the first outbound interface data is not characterized as being used to forward the first data packet in the first pipeline.
9. The device according to claim 6, characterized in that The device also includes: An updating module is used to update the stage of the first pipeline to the left child node of the root node if the first output interface data corresponding to the first hash value cannot be obtained from the cache.
10. The device according to claim 6, characterized in that The device also includes: An updating module, configured to update the stage of the first pipeline to complete matching when the first output interface data is characterized as being used to forward the first data packet in the first pipeline; The setting module is specifically used to delete the first data packet in the pipeline whose stage has completed matching from the pipeline after the stages of the N pipelines have all completed an update.
11. A network device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 5 when executing a program stored in a memory.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method for utilizing content-centric network nodes to process data based on tree and hash table
CN103595637A
Message transmission method, system and apparatus
CN107046503A
Network strategy matching method and system based on longest prefix of IP address
CN112187743A
Index establishment method and device and storage medium
CN112667636A
Method and device for realizing transparent tandem connection, electronic equipment and storage medium
CN112866115A
