Network traffic control method and device, chip, network interface card, computer device, readable storage medium and program product
By leveraging the hardware features of RISC-V to perform hardware updates of the token bucket and packet marking in network flow control, the problems of high system complexity and significant performance impact in existing technologies are solved, achieving efficient rate limiting and reshaping configuration.
Patent Information
- Application Number
- CN202510822034.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-19
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2045-06-19
AI Technical Summary
Existing technologies for network traffic control suffer from high system complexity and significant performance impact, especially in multi-core scenarios where software locking mechanisms are used for rate limiting, leading to low efficiency.
The hardware features of the RISC-V design enable hardware-based reading and updating of the overdraft token quantity in the token bucket. Combined with the rate limiting configuration table, atomic operations are performed to avoid software locking, achieving efficient token bucket updates and message marking.
It improves the processing efficiency of network traffic control, reduces the system load, enhances the level of intelligence, and supports flexible rate limiting and shaping configurations.
Smart Images

Figure CN120321189B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a network traffic control method, device, chip, network interface card, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] With the development of network cloud technology and data centers, the demand for private clouds and personal cloud hosts is gradually increasing. Limiting and shaping device traffic or cloud host traffic is a strong demand in the operation process. It is necessary to be able to measure and limit the rate and burst of traffic. Currently, not only the existing token bucket method is needed to achieve this requirement, but sometimes it is necessary to achieve rate limiting or shaping through parameter configuration for special scenarios.
[0003] However, the current solution is to adjust the traffic speed limit in a timely manner by configuring multiple parameter tables and recording multiple traffic status tables. This may require real-time refreshing of table entries, which increases system complexity and increases the system burden. Alternatively, in multi-core scenarios, a software locking mechanism is used in combination with certain algorithms to improve the efficiency and accuracy of the speed limit. Although the locking mechanism can solve the resource conflict problem in multi-core environments, it has a significant impact on performance. Summary of the Invention
[0004] Based on this, it is necessary to provide a network traffic control method, device, chip, network interface card, computer equipment, computer-readable storage medium and computer program product that can improve processing efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides a network traffic control method, applied to a chip including a RISC-V architecture processor core, the method comprising:
[0006] Determine the number of tokens to be updated corresponding to the token bucket;
[0007] Based on the hardware characteristics of RISC-V design, the number of overdraft tokens corresponding to the token bucket in the speed limit configuration table is read, and the current number of tokens is read;
[0008] Updating the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens;
[0009] Reading the speed limit configuration table, and marking the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the speed limit configuration table;
[0010] The message to be sent is processed based on the actions corresponding to the marks in the rate limit configuration table.
[0011] In one embodiment, the method further comprises:
[0012] receiving a configuration instruction for the rate limit configuration table, the configuration instruction including at least one of a token bucket configuration instruction, a rate limit mode configuration instruction, and a tag-action mapping relationship configuration instruction, wherein the token bucket configuration instruction is used to configure at least one of a priority of each token bucket, a token increase rate in each token bucket, a token bucket size, and whether overflow to a low-priority token bucket is allowed;
[0013] The speed limit configuration table is configured based on the configuration instruction.
[0014] In one embodiment, determining the number of tokens to be updated corresponding to the token bucket includes:
[0015] Obtain a pre-configured speed limit configuration table, and read the token increase rate corresponding to each token bucket from the speed limit configuration table;
[0016] The number of tokens to be updated corresponding to each token bucket is obtained based on the token increase rate.
[0017] In one embodiment, each token bucket has a priority; and updating the current number of tokens in the rate limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens includes:
[0018] For the token bucket of each priority, an initial token quantity is obtained based on the number of tokens to be updated, the number of overdrawn tokens, and the current number of tokens; wherein, if the priority of the token bucket is not the highest priority and tokens in a token bucket of a higher priority are allowed to overflow into the token bucket, the current token quantity of the token bucket is obtained by updating based on the tokens overflowing from the token bucket of the higher priority;
[0019] Based on the initial token quantity and the token bucket size of the token bucket, the initial token quantity is corrected to obtain a target token quantity, and the current token quantity corresponding to the token bucket is replaced by the target token quantity.
[0020] In one embodiment, marking the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the rate limit configuration table includes:
[0021] Read the speed limit mode and the priority of the token bucket in the speed limit configuration table;
[0022] Based on the rate limit mode and the priority of the token bucket, determining in sequence the relationship between the number of available tokens in each token bucket and the number of tokens to be consumed, the number of tokens to be consumed being the sum of the number of overdraft tokens and the length of the message to be sent;
[0023] The message to be sent is marked based on the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and an identifier of whether overflow to a low-priority token bucket is allowed.
[0024] In one embodiment, after marking the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the rate limit configuration table, the method further includes:
[0025] Determine a target token bucket for processing the message to be sent based on a relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and an indicator of whether overflow to a low-priority token bucket is allowed;
[0026] The number of overdraft tokens in the target token bucket is updated based on the number of overdraft tokens in the target token bucket and the length of the message to be sent.
[0027] In a second aspect, the present application further provides a network traffic control device, which is applied to a chip including a RISC-V architecture processor core, and the device includes:
[0028] A module for determining the number of tokens to be updated, used to determine the number of tokens to be updated corresponding to the token bucket;
[0029] A reading module is used to read the number of overdraft tokens corresponding to the token bucket in the speed limit configuration table based on the hardware characteristics of the RISC-V design, and read the current number of tokens;
[0030] An updating module, configured to update the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens;
[0031] a marking module, configured to read the speed limit configuration table and mark the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the speed limit configuration table;
[0032] The traffic processing module is used to process the traffic corresponding to the message to be sent based on the actions corresponding to the marks in the rate limit configuration table.
[0033] In a third aspect, the present application further provides a chip comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method in any one of the above embodiments when executing the computer program.
[0034] In a fourth aspect, the present application also provides a network interface card, comprising a chip as in any one of the above embodiments and a plurality of interfaces, wherein the chip processes data or communicates externally through the interfaces.
[0035] In a fifth aspect, the present application also provides a computer device, comprising a network interface card according to any one of the above embodiments, wherein the network interface card is used for processing data or external communication.
[0036] In a sixth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the method in any one of the above-mentioned embodiments when executed by a processor.
[0037] In a seventh aspect, the present application also provides a computer program product, comprising a computer program, which implements the steps of the method in any one of the above embodiments when executed by a processor.
[0038] The above-mentioned network traffic control method, device, chip, network interface card, computer equipment, computer-readable storage medium and computer program product, wherein the number of tokens to be updated corresponding to the token bucket is determined; the number of overdraft tokens corresponding to the token bucket in the speed limit configuration table is read based on the hardware characteristics of the RISC-V design, and the current number of tokens is read; the current number of tokens in the speed limit configuration table is updated based on the number of tokens to be updated, the number of overdraft tokens and the current number of tokens; the speed limit configuration table is read, and the message to be sent is marked based on the current number of tokens, the number of overdraft tokens and the length of the message to be sent in the speed limit configuration table; based on the actions corresponding to each mark in the speed limit configuration table, the traffic corresponding to the message to be sent is processed. In this way, by introducing the hardware characteristics of the RISC-V design, the speed limit configuration table is locked by hardware without the need for software locking. Compared with the software locking processing method, it is more efficient, and the actions corresponding to the marks can be configured, with a higher level of intelligence. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments of the present application or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 1 is a flow chart of a network traffic control method according to an embodiment;
[0041] Figure 2 A flowchart of a token bucket update step in one embodiment;
[0042] Figure 3 Schematic diagram of a flow chart of a rate limiting step in one embodiment;
[0043] Figure 4 is a structural block diagram of a network traffic control device in one embodiment;
[0044] Figure 5 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0046] With the development of network cloud technology and data centers, the demand for private clouds and personal cloud hosts is gradually increasing. Limiting and shaping device traffic or cloud host traffic is a strong demand in the operation process. It is necessary to be able to measure and limit the rate and burst of traffic. Currently, not only the existing token bucket method is needed to achieve this requirement, but sometimes it is necessary to achieve rate limiting or shaping through parameter configuration for special scenarios.
[0047] In order to solve at least one of the above technical problems, in an exemplary embodiment, as Figure 1 As shown, the present application provides a network traffic control method. This embodiment uses the method to be applied to a chip including a RISC-V architecture processor core as an example. In this embodiment, the method includes the following steps:
[0048] S102: Determine the number of tokens to be updated corresponding to the token bucket.
[0049] Among them, the number of tokens in the token bucket is updated periodically. This application includes two parts. One part is responsible for updating the number of tokens in the token bucket. This part does not process traffic data. The other part is responsible for speed limiting the traffic data according to the algorithm rules. Therefore, both parts need to process the number of tokens in the token bucket.
[0050] In this application, the number of tokens to be updated in step S102 is the process of injecting tokens into the token bucket.
[0051] In some optional embodiments, determining the number of tokens to be updated corresponding to a token bucket includes: obtaining a pre-configured speed limit configuration table, and reading the token increase rate corresponding to each token bucket from the speed limit configuration table; and obtaining the number of tokens to be updated corresponding to each token bucket based on the token increase rate.
[0052] The rate limit configuration table includes the token increment rate for each token bucket. The number of tokens to be updated is equal to the time multiplied by the token increment rate.
[0053] The time calculation is related to the token bucket update period, which is related to the hardware CPU clock frequency and the token bucket unit. Each update period generates at least one byte of token. The update period is equal to 1 second divided by the token bucket unit. For example, if the token bucket unit is 8KB and the CPU is 1GHz, the update period is 125us. It is important to note that the calculated token bucket update period must be less than the hardware CPU clock frequency.
[0054] After determining the token bucket update cycle, obtain the current time and subtract the time read after the last token bucket update from the current time to obtain a time difference. Divide this time difference by the token bucket update cycle to obtain a cycle count value. The number of tokens to be updated during this time difference is CIR*counter, where CIR is the token increase rate in the rate limit configuration table and counter is the cycle count value.
[0055] It's important to note that the rate limit configuration table can include at least one token bucket, and each token bucket can have a different token increment rate. This is not a specific restriction. When calculating the number of tokens to be updated for each token bucket, the calculation can be performed sequentially based on the priority of each bucket, or in parallel. This is not a specific restriction.
[0056] Since this step only reads the data in the speed limit configuration table and does not modify the data, there is no need to lock the speed limit configuration table in this step.
[0057] S104: Based on the hardware characteristics of the RISC-V design, the number of overdraft tokens corresponding to the token bucket in the speed limit configuration table is read, and the current number of tokens is read.
[0058] S106: Update the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdrawn tokens, and the current number of tokens.
[0059] The hardware feature of RISC-V design is to read the value of a certain area in the speed limit configuration table while reading the speed limit configuration table. Currently, the value of the overdraft token area in the speed limit configuration table is read. This ensures atomic operation in hardware, and the table resources can be read without lock in software. Then, the current number of tokens in the speed limit configuration table is updated based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens. After the update is completed, the hardware lock of the speed limit configuration table is released. In this way, the hardware processing is faster and the overall efficiency can be improved.
[0060] The method for updating each token bucket includes adding the calculated number of tokens to be updated (CIR*counter) based on the current number of tokens in the token bucket, and then subtracting the number of overdrawn tokens recorded in the rate limit configuration table. The final value is the number of tokens updated to the token bucket. However, due to the size of the token bucket, tokens in the token bucket may overflow. In this application, if the token bucket supports overflow, the token number of the token bucket is updated, and specifically, a check is made to determine whether the calculated number of tokens updated to the token bucket needs to be adjusted. If the calculated number of tokens updated to the token bucket is greater than the bucket depth of the token bucket, the calculated number of tokens updated to the token bucket is adjusted to equal CBS1. In this case, if overflow is supported for another token bucket, the current number of tokens in the other token bucket is added to the calculated number of tokens updated to the token bucket minus CBS1. If the calculated number of tokens updated to the token bucket is less than the minus value of the bucket depth (CBS), the calculated number of tokens updated to the token bucket is adjusted to equal -CBS. In other cases, the calculated number of tokens updated to the token bucket does not need to be adjusted.
[0061] S108: Read the speed limit configuration table, and mark the message to be sent based on the current token number, the overdraft token number and the length of the message to be sent in the speed limit configuration table.
[0062] S110: Process the message to be sent based on the actions corresponding to the tags in the rate limit configuration table.
[0063] Steps S102 to S106 involve a process of updating the token bucket, while steps S108 to S110 involve a process of rate limiting.
[0064] In this application, the speed limit process also needs to read the speed limit configuration table and use the corresponding tokens in it. In this application, the speed limit configuration table is read and the message to be sent is marked based on the current number of tokens, the number of overdraft tokens and the length of the message to be sent in the speed limit configuration table.
[0065] Among them, based on the current number of tokens, the number of overdrawn tokens and the length of the message to be sent in the speed limit configuration table, the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket can be determined, so that the message to be sent can be marked based on the algorithm rules, for example, by coloring.
[0066] The speed limit configuration table in this application may also include actions corresponding to each mark. The relationship between the mark and the action may be pre-configured. Each time a message to be sent is marked, the action corresponding to the mark in the speed limit configuration table is read, and then the corresponding action is executed to perform speed limit processing on the message to be sent.
[0067] The mark may be a color corresponding to the coloring, and the number of colors is not specifically limited. In addition, the action may include but is not limited to continuing to forward, discarding messages, counting the size of the speed-limited traffic, and counting at least one of the number of messages and the number of bytes that are lost due to speed limiting.
[0068] The above-mentioned network traffic control method determines the number of tokens to be updated corresponding to the token bucket; reads the number of overdrawn tokens corresponding to the token bucket in the speed limit configuration table based on the hardware characteristics of the RISC-V design, and reads the current number of tokens; updates the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdrawn tokens and the current number of tokens; reads the speed limit configuration table, and marks the to-be-sent message based on the current number of tokens, the number of overdrawn tokens and the length of the to-be-sent message in the speed limit configuration table; processes the traffic corresponding to the to-be-sent message based on the action corresponding to each mark in the speed limit configuration table. In this way, by introducing the hardware characteristics of the RISC-V design, atomic operations are guaranteed in hardware, and the table resources can be read without locks in software. Compared with the software locking processing method, the efficiency is higher, and the action corresponding to the mark can be configured, and the intelligence level is higher.
[0069] In one of the optional embodiments, the method also includes a configuration process, which mainly configures the speed limit configuration table. The configuration process mainly includes: receiving configuration instructions for the speed limit configuration table, the configuration instructions including at least one of a token bucket configuration instruction, a speed limit mode configuration instruction, and a tag and action mapping relationship configuration instruction, wherein the token bucket configuration instruction is used to configure the priority of each token bucket, the token increase rate in each token bucket, the token bucket size, and whether overflow to a low-priority token bucket is allowed; and configuring the speed limit configuration table based on the configuration instructions.
[0070] Each instantiation of the rate limit configuration table corresponds to a table entry ID. This table entry ID can be associated with a flow or a cloud host, thereby achieving the purpose of rate limiting and shaping for the specified flow or cloud host. The rate limit configuration table consists of two parts. One part is the rate limit parameter configuration part. To implement the existing token bucket method, this part of the parameters includes the token increase rate CIR (also known as the committed information rate) and the token bucket size CBS (also known as the committed burst size) of each token bucket. Other parameters include the number of tokens in the current token bucket (i.e., the number of remaining tokens) and the number of overdrawn tokens in the current token bucket. The number of remaining tokens and the number of overdrawn tokens can be negative. In addition, because multiple token buckets are included, the token buckets also have priorities. Each token bucket can also include a token bucket priority parameter. Token buckets other than the lowest priority also include whether to allow overflow to the lower priority token bucket (af).
[0071] The rate limit action section includes the rate limit mode (bit rate limit based on bit stream or packet rate limit) and the corresponding action of the flag (green / yellow / red). The action includes discarding and continuing to forward, etc. For details, please refer to the above.
[0072] For convenience, two token buckets are used as an example. The corresponding rate limit configuration table is as follows:
[0073]
[0074] In this embodiment, the priority is represented by the sorting in the speed limit configuration table, that is, the priority of the first token bucket is higher than that of the second token bucket, wherein the user can configure at least one of the priority of the token bucket, the rate of increase of tokens in each token bucket, the size of the token bucket, and whether to allow overflow to the low-priority token bucket. The speed limit mode and the mapping relationship between the mark and the action can also be configured. For example, the action corresponding to the green action in the table is to continue forwarding at 0 and to discard the message at 1. Similarly, the yellow action and red action can also be configured with corresponding actions. The table only uses the example of continuing forwarding at 0 and discarding the message at 1. In other embodiments, other actions can also be used. In addition, the number and type of marks can also be other, for example, there can be 4 marks, 5 marks, etc., and they can be marked by coloring or by other methods. No specific limitation is made here.
[0075] In the above embodiment, the configuration process includes mapping between coloring and actions, which extends the corresponding actions and has a higher level of intelligence.
[0076] In one of the optional embodiments, each token bucket has a priority; the current token number in the speed limit configuration table is updated based on the number of tokens to be updated, the number of overdrawn tokens and the current number of tokens, including: for each priority token bucket, based on the number of tokens to be updated, the number of overdrawn tokens and the current number of tokens, an initial token number is obtained; wherein, when the priority of the token bucket is not the highest priority and tokens in a token bucket with a higher priority are allowed to overflow into the token bucket, the current token number of the token bucket is updated based on the tokens overflowed from the token bucket with a higher priority; based on the initial token number and the token bucket size of the token bucket, the initial token number is corrected to obtain a target token number, and the current token number corresponding to the token bucket is replaced by the target token number.
[0077] Among them, the present application includes multiple token buckets, and the update of each token bucket includes the steps of calculating the initial token number and correcting the initial token number. The initial token number calculation step is based on the number of tokens to be updated, the number of overdraft tokens and the current number of tokens. Specifically, the initial token number new_token=current_token+CIR*counter-loan_token, wherein current_token is the current token number, that is, read from the speed limit configuration table, and loan_token is the overdraft token number, which is read from the speed limit configuration table.
[0078] The step of correcting the initial token quantity is to obtain the correct target token quantity, thereby replacing the current token quantity with the target token quantity. Correcting the target token quantity includes checking whether the calculated initial token quantity, new_token, needs to be corrected. If new_token is greater than the token bucket depth (CBS), then the value of new_token is corrected to be equal to CBS, i.e., the target token quantity is CBS. If new_token is less than the negative value of the token bucket depth (CBS), then the value of new_token is corrected to be equal to -CBS, i.e., the target token quantity is 1CBS. In other cases, new_token does not need to be adjusted, i.e., the target token quantity is new_token.
[0079] Since new_token is larger than the bucket depth CBS of the token bucket, that is, there are extra tokens, if overflow to a token bucket with a lower priority is supported, then the current number of tokens in the token bucket with a lower priority, current_token, needs to be added to the new_token calculated by the overflowed token bucket minus the CBS value corresponding to the overflowed token bucket, that is, the current number of tokens in the token bucket with a lower priority is updated.
[0080] For convenience, we still take two token buckets as an example to explain the token bucket update steps. Figure 2 As shown, the specific steps include:
[0081] The first step is to obtain the current time, subtract the time read after the last token bucket update from this time, and obtain a time difference. This time difference is divided by the token bucket update period to obtain the number of cycles corresponding to the time difference, counter. Based on the number of cycles and the token increase rate (CIR), the number of tokens to be updated (CIR*counter) is calculated. This step is repeated for each token bucket. Therefore, if the number of tokens to be updated for the first token bucket is calculated, the token increase rate is CIR1. If the number of tokens to be updated for the second token bucket is calculated, the token increase rate is CIR2.
[0082] Second, read the corresponding speed limit configuration table based on the instantiated ID and read the value of the overdraft token in the table. This step is mainly based on the hardware characteristics of the RISC-V design. While reading the table items, the value of a certain area in the table is also read. Currently, the value of the overdraft token area in the speed limit configuration table is read. This ensures atomic operations in hardware and lock-free reading of the table resources in software.
[0083] Third, calculate the number of tokens that should be updated to the first token bucket. The calculation method is to add the current number of tokens in the first token bucket to the first calculated number of tokens that should be updated CIR*counter, and then subtract the number of overdrawn tokens recorded in the speed limit configuration table. The final value is the number of tokens new_token1 updated to the first token bucket.
[0084] Fourth, check whether the number of tokens updated to the first token bucket, new_token1, calculated in step 3, needs to be adjusted. If new_token1 is greater than the bucket depth CBS1 of the first token bucket, then the value of new_token1 is adjusted to equal CBS1. At this time, if overflow of the second token bucket is supported, the current number of tokens in the second token bucket, current_token2, needs to be added to the value of new_token1 minus CBS1. If new_token1 is less than the negative value of the bucket depth CBS1 of the first token bucket, then the value of new_token1 is adjusted to equal -CBS1. In other cases, new_token1 does not need to be adjusted.
[0085] Fifth, calculate the number of tokens new_token2 that should be updated to the second token bucket. The calculation method is the same as the third step.
[0086] Sixth, check whether the number of tokens new_token2 calculated in step 5 to be updated to the second token bucket needs to be adjusted. If new_token2 is greater than the bucket depth CBS2 of the second token bucket, then the value of new_token2 is adjusted to equal CBS2. If new_token2 is less than the minus value of the bucket depth CBS2 of the first token bucket, then the value of new_token2 is adjusted to equal -CBS. In other cases, new_token2 does not need to be adjusted.
[0087] In the above embodiment, the software lock-free operation based on the RISC-V hardware device improves the processing efficiency.
[0088] In one of the optional embodiments, based on the current number of tokens, the number of overdraft tokens and the length of the message to be sent in the speed limit configuration table, the message to be sent is marked, including: reading the speed limit mode and the priority of the token bucket in the speed limit configuration table; based on the speed limit mode and the priority of the token bucket, determining the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket in turn, the number of tokens to be consumed being the sum of the number of overdraft tokens and the length of the message to be sent; based on the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and an indication of whether overflow to a low-priority token bucket is allowed, the message to be sent is marked.
[0089] Rate limiting modes include packet limiting and bit limiting. Packet limiting limits the speed of the entire packet, regardless of its length. The packet length is a fixed value, and as long as the number of tokens in the token bucket exceeds this fixed value, the rate limit is passed. This mode is suitable for scenarios where packet forwarding rate limits are required. Bit limiting requires a token for each bit in the rate-limited traffic, providing high rate limiting accuracy.
[0090] When limiting the speed, the corresponding speed limit configuration table is first read according to the instantiated ID to determine whether the speed limit is based on the number of packets. If so, a fixed length is used to deduct the token bucket for each packet of the traffic. The fixed value set in this application is 8K bytes; if not, the actual length of each packet of the traffic is used to deduct the token bucket.
[0091] The priority is used to determine the judgment order of the token bucket. For example, the token bucket with high priority is judged first, and then the token bucket with low priority is judged. The judgment process is to determine the relationship between the number of available tokens in each token bucket and the number of tokens to be consumed. The number of tokens to be consumed is the sum of the number of overdrawn tokens and the length of the message to be sent, and different marks are made for the message to be sent based on the obtained relationship.
[0092] In one of the optional embodiments, after marking the message to be sent based on the current number of tokens, the number of overdraft tokens and the length of the message to be sent in the speed limit configuration table, it also includes: determining the target token bucket for processing the message to be sent based on the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and the identifier of whether overflow to a low-priority token bucket is allowed; updating the number of overdraft tokens in the target token bucket based on the number of overdraft tokens in the target token bucket and the length of the message to be sent.
[0093] In addition, after the target token bucket for processing the message to be sent is determined, the number of overdraft tokens corresponding to the target token bucket is also updated.
[0094] For ease of understanding, combined Figure 3 As shown, Figure 3 This is a flow chart of the rate limiting step in one embodiment. In this embodiment, two token buckets are still used as an example for explanation. In this application, not only can the rate of traffic data (messages to be sent) be limited, but the traffic data can also be colored and corresponding actions can be performed, including:
[0095] First, read the corresponding speed limit configuration table according to the instantiated id.
[0096] Second, determine whether the speed limit is based on the number of packets. If so, use a fixed length for each packet of the traffic to deduct the token bucket. This embodiment sets the fixed value to 8K bytes, which can be other numbers of bytes in other embodiments. If not, use the actual length of each packet of the traffic to deduct the token bucket.
[0097] Third, it is necessary to determine whether the number of tokens in the token bucket can be deducted from the total value of the length of the message to be sent plus the number of overdrawn tokens. If it is determined that the number of tokens in the first token bucket is less than the length of the message to be sent plus the number of overdrawn tokens in the first token bucket, and if the number of tokens in the second token bucket is also less than the current length of the message to be sent plus the number of overdrawn tokens in the second token bucket, the message to be sent is colored red and the action corresponding to red is performed. If the number of tokens in the second token bucket is not less than the current length of the message to be sent plus the number of overdrawn tokens in the second token bucket, the message is colored yellow and the action corresponding to yellow is performed. The number of overdrawn tokens in the second token bucket plus the length of the message to be sent is used as the new number of overdrawn tokens in the second token bucket.
[0098] Fourth, when the number of tokens in the first token bucket is not less than the length of the message to be sent plus the number of overdraft tokens in the first token bucket, if the number of tokens in the first token bucket is not supported to overflow to the second token bucket when it is full, the message will be colored green and the action corresponding to green will be performed. The number of overdraft tokens in the first token bucket plus the length of the message to be sent will be used as the new number of overdraft tokens in the first token bucket.
[0099] Fifth, when the number of tokens in the first token bucket is not less than the length of the message to be sent plus the number of overdrawn tokens, and if the number of tokens in the second token bucket is less than the length of the current message to be sent plus the number of overdrawn tokens in the second token bucket, the message is colored red and the corresponding action for red is performed. If the number of tokens in the second token bucket is not less than the length of the current message to be sent plus the number of overdrawn tokens in the second token bucket, the message is colored green and the corresponding action for green is performed. The number of overdrawn tokens in the first token bucket plus the length of the message to be sent is used as the new number of overdrawn tokens in the first token bucket, and the number of overdrawn tokens in the second token bucket plus the length of the message to be sent is used as the new number of overdrawn tokens in the second token bucket.
[0100] In the above embodiment, in the scenario of smart network card, traffic can be speed-limited or shaped, supporting customized traffic speed-limiting rules and supporting the definition of easily extensible speed-limiting actions, which greatly adapts to QOS and speed-limiting applications in data center or network cloud scenarios.
[0101] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0102] Based on the same inventive concept, the embodiments of the present application also provide a network traffic control device for implementing the aforementioned network traffic control method. The implementation solution provided by the device is similar to the implementation solution described in the aforementioned method. Therefore, the specific limitations in one or more network traffic control device embodiments provided below can be found in the above-mentioned limitations on the network traffic control method and will not be repeated here.
[0103] In an exemplary embodiment, Figure 4 As shown, a network traffic control device is provided, which is applied to a chip including a RISC-V architecture processor core, including: a module 401 for determining the number of tokens to be updated, a reading module 402, an updating module 403, a marking module 404 and a traffic processing module 405, wherein:
[0104] The module 401 for determining the number of tokens to be updated is used to determine the number of tokens to be updated corresponding to the token bucket;
[0105] A reading module 402 is configured to read the number of overdraft tokens corresponding to the token bucket in the speed limit configuration table based on the hardware characteristics of the RISC-V design, and read the current number of tokens;
[0106] An updating module 403 is configured to update the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens;
[0107] a marking module 404 configured to read the speed limit configuration table and mark the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the speed limit configuration table;
[0108] The traffic processing module 405 is configured to process the traffic corresponding to the message to be sent based on the actions corresponding to the marks in the rate limit configuration table.
[0109] In one of the optional embodiments, the above device further includes:
[0110] A configuration module is used to receive configuration instructions for the speed limit configuration table, the configuration instructions including at least one of a token bucket configuration instruction, a speed limit mode configuration instruction, and a tag and action mapping relationship configuration instruction, wherein the token bucket configuration instruction is used to configure at least one of the priority of each token bucket, the token increase rate in each token bucket, the token bucket size, and whether overflow to a low-priority token bucket is allowed; and configure the speed limit configuration table based on the configuration instructions.
[0111] In one of the optional embodiments, the above-mentioned module 401 for determining the number of tokens to be updated is specifically used to obtain a pre-configured speed limit configuration table, and read the token increase rate corresponding to each token bucket from the speed limit configuration table; based on each token increase rate, the number of tokens to be updated corresponding to each token bucket is obtained.
[0112] In one of the optional embodiments, each token bucket has a priority; the above-mentioned update module 403 is specifically used to obtain an initial token number for the token bucket of each priority based on the number of tokens to be updated, the number of overdrawn tokens and the current number of tokens; wherein, when the priority of the token bucket is not the highest priority and the tokens in the token bucket of a higher priority are allowed to overflow into the token bucket, the current token number of the token bucket is updated based on the tokens overflowed from the token bucket of the higher priority; based on the initial token number and the token bucket size of the token bucket, the initial token number is corrected to obtain a target token number, and the current token number corresponding to the token bucket is replaced by the target token number.
[0113] In one of the optional embodiments, the above-mentioned marking module 404 is specifically used to read the speed limit mode and the priority of the token bucket in the speed limit configuration table; based on the speed limit mode and the priority of the token bucket, determine the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket in turn, and the number of tokens to be consumed is the sum of the number of overdraft tokens and the length of the message to be sent; based on the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and the indicator of whether overflow to the low-priority token bucket is allowed, mark the message to be sent.
[0114] In one of the optional embodiments, the above-mentioned device also includes: an overdraft token quantity determination module, which is used to determine the target token bucket for processing the message to be sent based on the relationship between the number of available tokens and the number of tokens to be consumed in each of the token buckets and an indicator of whether overflow to a low-priority token bucket is allowed; and update the number of overdraft tokens in the target token bucket based on the number of overdraft tokens in the target token bucket and the length of the message to be sent.
[0115] Each module in the aforementioned network traffic control device may be implemented in whole or in part through software, hardware, or a combination thereof. Each module may be embedded in or independent of a processor in a computer device in the form of hardware, or may be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0116] In one embodiment, a chip is provided. The chip includes a memory and a processor. The memory stores a computer program. The processor implements the aforementioned access control method when executing the computer program. The chip may be a data processing unit (DPU) chip.
[0117] In one embodiment, a network interface card is provided, comprising the aforementioned chip and multiple interfaces, through which the chip communicates externally, including PCI / PCIE interfaces, network interfaces, and the like.
[0118] In an exemplary embodiment, a computer device is provided, comprising a processor and the aforementioned network interface card, wherein the network interface card is configured to dispatch packets to the processor or the network interface card itself for processing, and the processor is configured to process the packets dispatched by the network interface card. The computer device may be a server, and its internal structure may be as shown in FIG. Figure 5As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O) and a communication interface. The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store corresponding data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a network traffic control method is implemented.
[0119] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0120] In one embodiment, a computer device is further provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps in the above method embodiments when executing the computer program.
[0121] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0122] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0123] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0124] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), quantum computing-based data processing logic devices, artificial intelligence (AI) processors, and the like.
[0125] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0126] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A network traffic control method, characterized in that: Applied to a chip including a RISC-V architecture processor core, the method includes: Determine the number of tokens to be updated corresponding to the token bucket; The hardware characteristics of the RISC-V design are based on reading the number of overdrawn tokens corresponding to the token bucket in the speed limit configuration table and reading the current number of tokens. The hardware characteristics of the RISC-V design ensure atomic operations in hardware and lock-free reading of the speed limit configuration table in software; Updating the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens; Reading the speed limit configuration table, and marking the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the speed limit configuration table; The message to be sent is processed based on the actions corresponding to the marks in the rate limit configuration table.
2. The method according to claim 1, characterized in that The method further comprises: receiving a configuration instruction for the rate limit configuration table, the configuration instruction including at least one of a token bucket configuration instruction, a rate limit mode configuration instruction, and a tag-action mapping relationship configuration instruction, wherein the token bucket configuration instruction is used to configure at least one of a priority of each token bucket, a token increase rate in each token bucket, a token bucket size, and whether overflow to a low-priority token bucket is allowed; The speed limit configuration table is configured based on the configuration instruction.
3. The method according to claim 1, characterized in that Determining the number of tokens to be updated corresponding to the token bucket includes: Obtain a pre-configured speed limit configuration table, and read the token increase rate corresponding to each token bucket from the speed limit configuration table; The number of tokens to be updated corresponding to each token bucket is obtained based on the token increase rate.
4. The method according to claim 1, wherein Each token bucket has a priority; updating the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens includes: For the token bucket of each priority, an initial token quantity is obtained based on the number of tokens to be updated, the number of overdrawn tokens, and the current number of tokens; wherein, if the priority of the token bucket is not the highest priority and tokens in a token bucket of a higher priority are allowed to overflow into the token bucket, the current token quantity of the token bucket is obtained by updating based on the tokens overflowing from the token bucket of the higher priority; Based on the initial token quantity and the token bucket size of the token bucket, the initial token quantity is corrected to obtain a target token quantity, and the current token quantity corresponding to the token bucket is replaced by the target token quantity.
5. The method according to any one of claims 1 to 4, characterized in that The marking of the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the rate limit configuration table includes: Read the speed limit mode and the priority of the token bucket in the speed limit configuration table; Based on the rate limit mode and the priority of the token bucket, determining in sequence the relationship between the number of available tokens in each token bucket and the number of tokens to be consumed, the number of tokens to be consumed being the sum of the number of overdraft tokens and the length of the message to be sent; The message to be sent is marked based on the relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and an identifier of whether overflow to a low-priority token bucket is allowed.
6. The method according to claim 5, characterized in that After marking the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the rate limit configuration table, the method further includes: Determine a target token bucket for processing the message to be sent based on a relationship between the number of available tokens and the number of tokens to be consumed in each token bucket and an indicator of whether overflow to a low-priority token bucket is allowed; The number of overdraft tokens in the target token bucket is updated based on the number of overdraft tokens in the target token bucket and the length of the message to be sent.
7. A network traffic control device, characterized in that: Applied to a chip including a RISC-V architecture processor core, the device includes: A module for determining the number of tokens to be updated, used to determine the number of tokens to be updated corresponding to the token bucket; A reading module is used to read the number of overdrawn tokens corresponding to the token bucket in the speed limit configuration table based on the hardware characteristics of the RISC-V design, and read the current number of tokens. The hardware characteristics of the RISC-V design ensure atomic operations in hardware and lock-free reading of the speed limit configuration table in software; An updating module, configured to update the current number of tokens in the speed limit configuration table based on the number of tokens to be updated, the number of overdraft tokens, and the current number of tokens; a marking module, configured to read the speed limit configuration table and mark the message to be sent based on the current number of tokens, the number of overdraft tokens, and the length of the message to be sent in the speed limit configuration table; The traffic processing module is used to process the message to be sent based on the action corresponding to each mark in the rate limit configuration table.
8. A chip comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A network interface card, characterized in that: The device comprises the chip as claimed in claim 8 and a plurality of interfaces, wherein the chip processes data or communicates externally through the interfaces.
10. A computer device, characterized in that: The network interface card according to claim 9 is used for processing data or external communication.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
12. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Token processing method and device
CN106453127A
Traffic speed limiting method and device, electronic equipment and storage medium
CN116708315A