A message processing method and device
By setting a cache area in the FPGA of the network device, the reading frequency of external storage units is reduced, and the problems of excessive resource consumption and low speed limit accuracy in the token bucket speed limit method are solved, and more efficient packets are achieved Processing and accurate speed limit.
Patent Information
- Application Number
- CN202211130347.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-15
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2042-09-15
AI Technical Summary
In the prior art, frequent reading and writing of external memory leads to excessive resource consumption and reduced speed limit accuracy when passing the token bucket speed limit method in the network.
The first cache area and the second cache area are set in the FPGA of the network device. By accumulating the received several messages, the token margin and arrival time are calculated, and the reading frequency of the external storage unit is reduced, and the direct output from The cache area reads the token margin and arrival time to improve the speed limit accuracy.
It reduces the read and write frequency of external storage units, saves resources, improves the accuracy and efficiency of message speed limit, and avoids network blockage and resource waste caused by frequent read and write.
Smart Images

Figure CN115622945B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a message processing method and device. Background Art
[0002] As the Internet is increasingly developed, with the increase in network users, the burden on the Internet is getting heavier and heavier, and the network is becoming more crowded. In serious cases, network congestion may occur, and even business abnormalities may occur, which will also cause waste of network resources. Therefore, there is a need for a mechanism to monitor the rate of traffic entering the network on the network to limit the traffic and improve the efficiency of network resource use, thereby ensuring that limited network resources provide better network services. In order to achieve the above purpose, it is necessary to monitor the traffic entering the network to achieve rate limit.
[0003] In addition, different users have different needs for accessing the network, so it is necessary to limit the speed of different users accessing the network separately. The current speed limit method is based on the token bucket, that is, a token bucket is configured for each user. When users keep changing back and forth, it is necessary to continuously read and write the memory to obtain the token balance and time value of different users. Each user can only forward when the token balance is sufficient, so as to achieve stable and controlled rates for all users. However, continuously reading and writing the memory consumes multiple time beats. If the message has to wait until the token is calculated by reading and writing the memory before it can be forwarded to the next step, it will waste a lot of time beats, resulting in serious network congestion. Therefore, there is a need for a method to monitor the network without affecting the rate of the network users themselves.
[0004] The scheme provided at present is to pre-accumulate the number of tokens that the same user needs to obtain, thereby ensuring that the reading and writing of the memory are not so frequent, and avoiding the congestion caused by the repeated reading and writing of the same user, so that there is enough time when the token surplus and time value are read next time, to calculate the token consumption of the current message. However, there are many network users at present, and the memory used to store the token surplus and time value of the user is generally an external DDR (double data rate synchronous dynamic random access memory) or QDR (quadruple data rate synchronous dynamic random access memory), and their read and write cycles are much longer than built-in RAM (random access memory), and built-in RAM cannot allocate enough space to the token bucket for use. The existing scheme needs to accumulate more messages to ensure that there is enough time to read and write the external memory, and the resources used for pre-accumulation judgment will also increase, which is not only inefficient, but also the more accumulated, the worse the accuracy of the speed limit.
[0005] Therefore, how to solve the problem of excessive resource consumption and reduced speed limit accuracy caused by long reading and writing time of external memory during message processing is one of the technical issues worth considering. Summary of the invention
[0006] In view of this, the present application provides a message processing method and device to solve the problem of excessive resource consumption and reduced speed limit accuracy caused by long time for reading and writing external memory during message processing.
[0007] Specifically, the present application is implemented through the following technical solutions:
[0008] According to a first aspect of the present application, a message processing method is provided, which is applied to a field programmable gate array FPGA in a network device, wherein a first buffer area and a second buffer area are provided inside the network device, and the method comprises:
[0009] After receiving a plurality of beats of messages this time, accumulating the message information of the messages of the same user in the plurality of beats of messages, to obtain the message statistical information of this time;
[0010] Determine the target number of tokens required for sending the user's message this time based on the message statistics information this time;
[0011] Acquire the current token balance of the user from the first buffer area;
[0012] Acquire the recorded arrival time of the last message of the user from the second buffer area;
[0013] Determine, according to the arrival time and the current system time, the token increment of the token of the user when the last message of the user is received this time;
[0014] Determine the total amount of tokens of the user according to the token balance and the token increment;
[0015] If the total number of tokens exceeds the target number of tokens, forwarding the user's message according to the target number of tokens;
[0016] Determine a new token balance according to the total token amount and the target token amount; and write the new token balance into the first buffer area;
[0017] The arrival time of the message of the last beat is written into the second buffer area as the arrival time of the new previous beat message of the user.
[0018] According to a second aspect of the present application, a message processing device is provided, which is arranged in a field programmable gate array FPGA in a network device, wherein a first buffer area and a second buffer area are arranged inside the network device, and the device comprises:
[0019] A receiving module, used for receiving the messages of several beats of this time;
[0020] An accumulation module is used to accumulate the message information of the messages of the same user in the messages of the plurality of beats after receiving the messages of the plurality of beats this time, so as to obtain the message statistics information of this time;
[0021] A first determination module, used to determine the target number of tokens required for sending the message of the user this time according to the message statistics information of this time;
[0022] A first acquisition module, configured to acquire the current token balance of the user from the first buffer area;
[0023] A second acquisition module, used for acquiring the recorded arrival time of the last message of the user from the second buffer area;
[0024] A second determination module is used to determine the token increment of the token of the user when the last message of the user is received this time according to the arrival time and the current system time;
[0025] A third determination module, configured to determine the total amount of tokens of the user according to the token balance and the token increment;
[0026] A forwarding module, configured to forward the user's message according to the target token number if the total token number exceeds the target token number;
[0027] A fourth determination module, used to determine a new token balance according to the total token amount and the target token amount;
[0028] A first writing module, used for writing a new token balance into the first buffer area;
[0029] The second writing module is used to write the arrival time of the message of the last beat into the second buffer area as the arrival time of the new previous beat message of the user.
[0030] Beneficial effects of the embodiments of the present application:
[0031] In the message processing method and device provided by the embodiments of the present application, after receiving several beats of messages this time, the message information of the messages of the same user in the several beats of messages are accumulated and processed to obtain the message statistics information of this time; based on the message statistics information of this time, the target number of tokens required for sending the message of the user this time is determined; the current token balance of the user is obtained from the first cache area; the arrival time of the last beat of the message of the user recorded in the second cache area is obtained; based on the arrival time and the current system time, the token increment of the token of the user when the last beat of the message of the user is received this time is determined; based on the token balance and the token increment, the total number of tokens of the user is determined; if the total number of tokens is not less than the target number of tokens, the message of the user is forwarded according to the target number of tokens. By counting the message information of several beats of messages, and then determining the number of tokens required to send messages to the same user based on the message statistical information obtained, the token number is no longer accessed in units of a single message, which can to a certain extent avoid the problem of excessive resource consumption caused by frequently reading the number of tokens from the outside, and also improve the accuracy of the message speed limit; in addition, the present application sets a first cache area and a second cache area, and then stores the token balance and arrival time in the first cache area and the second cache area respectively. In this way, when reading the token balance, there is no need to read from the external storage unit, and the demand can be met by reading directly from the first cache area. In addition, when calculating the token increment, it is only necessary to read the arrival time from the second cache area, thereby further reducing the frequency of reading the token balance from the external storage unit, thereby saving resources; at the same time, it also further improves the accuracy of the message speed limit result. Furthermore, in order to better implement the message processing method provided by the present application, it is also necessary to determine the new token balance based on the total number of tokens and the target number of tokens; and write the new token balance into the first cache area; and write the arrival time of the last beat of the message into the second cache area as the arrival time of the new last beat of the message of the user, so as to facilitate the speed limit processing of subsequent messages. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a flowchart of a message processing method provided in an embodiment of the present application;
[0033] Figure 2 This is a schematic diagram of message accumulation provided by an embodiment of the present application;
[0034] Figure 3 It is a read and write logic diagram of a token balance read and write process provided by an embodiment of the present application;
[0035] Figure 4It is a structural diagram of a message processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application.
[0037] The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more corresponding listed items.
[0038] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0039] The message processing method provided by this application is described in detail below.
[0040] See also Figure 1 , Figure 1 This is a flow chart of a message processing method provided by the present application. The method can be applied to a field programmable gate array FPGA in a network device. The network device can be, but is not limited to, a network security device such as a firewall. The network device is also provided with a first buffer area and a second buffer area. When the FPGA implements the above message processing method, it can include the following steps:
[0041] S101. After receiving a plurality of beats of messages this time, accumulate the message information of the messages of the same user in the plurality of beats of messages to obtain the message statistical information of this time.
[0042] In this step, the messages received by the FPGA may be sent by different users, and when the message speed limit processing is performed, it is performed based on each user separately, and the speed limit rules for different users are different. In view of this, in order to improve the accuracy of the user's speed limit, this embodiment proposes that after the FPGA receives the messages of several beats this time, since the messages of several beats may be sent by the same or different users, in order to perform message speed limit processing for each user according to their own rules, the FPGA needs to filter out the messages belonging to the same user from the messages of several beats, and then accumulate the message information of the messages used, so as to obtain the message statistical information of the user, so as to perform speed limit processing on the user later.
[0043] Specifically, in the current existing message speed limit, the message of the next beat must wait until the calculation of the message of the current beat is completed before the accurate token balance can be obtained. In order to prevent congestion caused by the message waiting for the calculation of the previous message, the present application proposes to accumulate and process the messages of the same user of several beats received this time. In this way, a certain time interval will be generated after the accumulation processing, so as to make up for the waiting time for the processing of the next message to wait for the completion of the processing of the current message, and at the same time will not affect the overall rate of the message.
[0044] Optionally, the number of beats of the message received this time may be but is not limited to 23 beats, etc. For the convenience of description, the message with 23 beats received this time is taken as an example for explanation.
[0045] Optionally, the message information may include but is not limited to information such as the initial color message length. On this basis, the FPGA may perform cumulative processing on the message information of the same user's messages, thereby obtaining message statistical information. Specifically, for the same user, the FPGA may first calculate the output color based on the initial color in the message information of each message of the user, and then perform setting processing on the message length and the output color, thereby obtaining the message statistical information of the message, and calculating the message statistical information of the user this time based on the message statistical information of each message.
[0046] S102: Determine the target number of tokens required for sending the user's message this time according to the message statistics information this time.
[0047] In this step, in order to reduce the problem of excessive resource consumption and speed limit performance affected by frequent reading and writing of storage space, this embodiment uses a single message of several beats, and obtains message statistical information based on the message aggregation of the same user to determine the number of tokens required to forward the user's message, which is recorded as the above-mentioned target token number, instead of operating on a message basis. In comparison, the present application can effectively reduce resource consumption and improve the speed limit performance of the message.
[0048] S103: Acquire the current token balance of the user from the first buffer area.
[0049] In this step, in order to further avoid the problem of high resource consumption caused by frequently reading the number of tokens from the external storage space, the present application proposes to set a first cache area in the network device, and the FPGA writes the token balance of users who continuously send messages into the first cache area. Specifically, when users frequently access the FPGA, it will definitely lead to frequent reading and writing of token balances. If the token balance is always stored in the external storage unit, it will lead to frequent reading of the external memory, which will accordingly lead to excessive consumption of resources and affect the accuracy of the message speed limit. In view of this, the present application proposes to temporarily store the token balance of users who continuously send messages to the network device in the first cache area.
[0050] On this basis, after the target token number is calculated this time, the token balance of the corresponding user can be read from the first buffer area. If the token balance is read, it indicates that the user has frequently sent messages to the network device in recent times. Then, the FPGA only needs to perform message speed limit processing on the message received from the user this time based on the token balance read by the user, thereby further reducing the occurrence of frequent external reading of the token balance. In addition, since only the token balance needs to be read from the first buffer area inside the network device, the reading time of the token balance is greatly saved, which improves the processing speed of the message speed limit based on the token to a certain extent, that is, improves the accuracy of the speed limit.
[0051] It is worth noting that if the token balance is not read, it means that the user does not send messages frequently, then the token balance of the user is read from the external storage space, and then the subsequent message processing flow is executed.
[0052] S104: Acquire the recorded arrival time of the last message of the user from the second buffer area.
[0053] In this step, in addition, since the number of tokens changes dynamically, that is, a part of the tokens will be occupied during the forwarding process, after the message forwarding is completed, the token used to forward the message will be released and added to the token bucket for the next forwarding. For the speed limit processing of messages for the same user, the number of newly added tokens per unit time is generally fixed. Therefore, it is necessary to determine the number of newly added tokens between the message received from the user this time and the message received from the user last time.
[0054] When determining the number of newly added tokens, it is necessary to record the last determination time. Therefore, in order to avoid the problem of excessive resource consumption caused by frequent access to the external storage unit, the present application will also configure a second cache area in the network device, and the time information will be stored in the second cache area. Specifically, when the user frequently accesses the FPGA, it will definitely lead to frequent reading and writing of time information. If the time information is always stored in the external storage unit, it will lead to frequent reading of the external memory. Correspondingly, it will lead to excessive consumption of resources and affect the accuracy of the message speed limit. In view of this, the present application proposes that for users who frequently send messages to the network device, after processing the user's message each time, the arrival time of the last beat of the message received at the network device is written into the second cache area.
[0055] On this basis, when it is necessary to perform speed limiting processing on the message received this time from the user, the arrival time of the last message of the user can be obtained from the second buffer area, and then the token increment can be determined according to the arrival time.
[0056] S105: Determine, according to the arrival time and the current system time, a token increment of the token of the user when the last message of the user is received this time.
[0057] In this step, after determining the arrival time of the last beat of the message, the current system time can be obtained, and then the token increment of the user's token as of the time when the last beat of the message of the user is received this time can be determined based on these two times and the token increment per unit time.
[0058] S106: Determine the total amount of tokens of the user according to the token balance and the token increment.
[0059] In this step, after the token increment is determined, the sum of the token balance read in step S103 and the token increment determined in step S105 can be determined as the total token amount currently available to the user.
[0060] S107: If the total number of tokens is not less than the target number of tokens, forward the user's message according to the target number of tokens.
[0061] In this step, since the message is sent based on the token, the speed limit is achieved. Therefore, when the total number of tokens exceeds the target number of tokens, it indicates that the currently available number of tokens is sufficient to support the forwarding of the user's message this time, and the user's message can be forwarded according to the target number of tokens.
[0062] When it is determined that the total number of tokens is less than the target number of tokens, it means that the current total number of tokens is insufficient to support the forwarding of the user's message this time. The user's message may be discarded, or the message may be cached to wait for a sufficient number of tokens to forward the user's message this time.
[0063] S108: Determine a new token balance according to the total token amount and the target token amount; and write the new token balance into the first buffer area.
[0064] In this step, after the user's message is forwarded based on the target token number, the target token number tokens will be released. Therefore, the new token balance can be determined based on the total token amount and the target token number, and then the new token balance can be written into the first cache area so that the user's message can be processed next time.
[0065] S109: Write the arrival time of the last beat of the message into the second buffer area as the arrival time of the new previous beat of the message of the user.
[0066] In this step, in order to facilitate the next processing of the user's message, the FPGA will write the arrival time of the last beat of the user's message into the second buffer area.
[0067] By implementing the message processing method provided in the present application, after receiving several beats of messages this time, the message information of the messages of the same user in the several beats of messages are accumulated and processed to obtain the message statistical information of this time; based on the message statistical information of this time, the target number of tokens required for sending the message of the user this time is determined; the current token balance of the user is obtained from the first buffer area; the arrival time of the last beat of the message of the user recorded in the second buffer area is obtained; based on the arrival time and the current system time, the token increment of the token of the user when the last beat of the message of the user is received this time is determined; based on the token balance and the token increment, the total number of tokens of the user is determined; if the total number of tokens is not less than the target number of tokens, the message of the user is forwarded according to the target number of tokens. By counting the message information of several beats of messages, and then determining the number of tokens required to send messages to the same user based on the message statistical information obtained, the token number is no longer accessed in units of a single message, which can to a certain extent avoid the problem of excessive resource consumption caused by frequently reading the number of tokens from the outside, and also improve the accuracy of the message speed limit; in addition, the present application sets a first cache area and a second cache area, and then stores the token balance and arrival time in the first cache area and the second cache area respectively. In this way, when reading the token balance, there is no need to read from the external storage unit, and the demand can be met by reading directly from the first cache area. In addition, when calculating the token increment, it is only necessary to read the arrival time from the second cache area, thereby further reducing the frequency of reading the token balance from the external storage unit, thereby saving resources; at the same time, it also further improves the accuracy of the message speed limit result. Furthermore, in order to better implement the message processing method provided by the present application, it is also necessary to determine the new token balance based on the total number of tokens and the target number of tokens; and write the new token balance into the first cache area; and write the arrival time of the last beat of the message into the second cache area as the arrival time of the new last beat of the message of the user, so as to facilitate the speed limit processing of subsequent messages.
[0068] Optionally, based on any of the above embodiments, after receiving the messages of several beats this time, the number of messages of the same user can be aggregated, and when the number of messages reaches a set number, the execution Figure 1 The process shown, that is, when the user sends enough messages this time, the message processing method provided in this application is implemented; the value of the above-mentioned set number can be configured according to actual conditions.
[0069] When the number of messages of the user received this time does not reach the set number, it can be processed according to the existing process. For details, refer to the following message processing process for messages of several beats that do not include messages of the same user.
[0070] In addition, the source IP addresses of the messages of the same user are the same, so the message statistical information of the same user can be counted based on the source IP address, that is, the message information of the messages with the same source IP address is accumulated to obtain the message statistical information.
[0071] Optionally, based on any of the above embodiments, the message processing method provided in this embodiment may also include the following process: when the messages of the several beats received this time do not include the messages of the same user, determining the number of tokens required to send the message of each user based on the message information of the user; obtaining the current token balance of the user from the external storage unit corresponding to the user; forwarding the message of the user according to the obtained token balance and the number of tokens required to send the message of the user; re-determining the token balance; and writing the determined token balance into the external storage unit of the user.
[0072] Specifically, the first cache area and the second cache area in the present application are used to store the token balance and arrival time of messages continuously sent to the network device. When no message from the same user fails to reach the network device within a short period of time, the token balance and arrival time of the user do not need to be stored in the first cache area and the second cache area, but only need to be read from the external storage unit. In this way, the storage space of the first cache area and the second cache area does not need to be set too large. For example, the cache depth of the first cache area and the second cache area can be set to 32, etc. respectively, but is not limited to it.
[0073] Specifically, when messages from the same user arrive in a short period of time, in order to avoid repeated reading and writing of the external storage unit, the token remainder and arrival time of the continuous messages from the same user are stored in the first buffer area and the second buffer area respectively, and then Figure 1 The process shown takes out the required information from the corresponding buffer area for calculation. When no subsequent message with the same address is about to arrive, the final arrival time and token remainder are written into the external storage unit according to the above process. Since the external storage unit stores the token remainder and arrival time of all users, there is no need to set the storage space of the first buffer area and the second buffer area larger, and thus the normal business processing of the FPGA will not be affected by the larger space setting. In addition, if the message users arriving in a short period of time are not the same, they can be directly read from the external storage unit.
[0074] When detecting whether there is a burst of messages from the same user in a short period of time, only the messages cached for a short period of time need to be detected. For example, it is possible to detect whether there are messages from the same user in the messages cached for 23 clock cycles. If there are no messages from the same user in these 23 clock cycles, there is no burst of messages, and the time for reading the external storage unit is completely sufficient, and it will not be too frequent, and there will be no errors.
[0075] In addition, when determining whether there are identical messages in several beats of this time, the confirmation can be performed based on the cache of several beats of messages in the message cache area, that is, the messages received this time are input into the pipeline 23-level cache, and then the message information of the identical messages in the messages in the set beat is accumulated. For easy understanding, refer to Figure 2 The schematic diagram of message accumulation is shown for explanation. The storage location of the message buffer area is represented by numbers 0 to 22. The message information is the message length. The message statistical information is the length. The message length of each message is 10. Figure 2 The 22nd beat of the message can be understood as the previous beat of the message received. Figure 2 In the figure, it indicates that several beats of messages are sent by two users. For example, in the messages between beats 15 and 21, the messages numbered 15 / 18 / 19 / 21 / 22 are messages from user 1, and in the messages between beats 13 and 20, the messages numbered 16 / 17 / 20 are messages from user 2. For user 1, starting from beat 21, the message lengths of the messages in beats 21, 19, 18, and 15 can be accumulated, so as to obtain the message statistics information of user 1 in the 7 beats from beats 15 to 21, which is 40 in length. Similarly, for user 2, starting from beat 20, the messages in beats 20, 17, 16, and 13 can be accumulated, so as to obtain the message statistics information of user 2 in the 7 beats from beats 13 to 20, which is 40 in length. According to the above method, the message statistics information of the messages of the same user in the messages of several beats received each time can be obtained, so as to accurately determine the target number of tokens required to send the messages of each user received this time.
[0076] It should be noted that the specific values of the above-mentioned several beats can be determined according to the time required for calculation of other subsequent modules, aiming to achieve seamless connection as much as possible.
[0077] On this basis, in the message processing method provided in this embodiment, after executing step S101, the following process may also be included: determining the message interval between the current accumulation processing and the previous accumulation processing.
[0078] Specifically, since this application needs to read and write the first cache area and the second cache area, the addresses of the two cache areas change dynamically. On this basis, in order to more accurately read the user's token balance and arrival time, this application needs to calculate the message interval, that is, calculate the message interval between this accumulation process and the previous accumulation process, and then determine the actual addresses of the first cache area and the second cache area according to the message interval.
[0079] Also Figure 2 For example, after determining the messages between the 15th and 21st beats, the message interval between this and the last accumulation can be determined, that is, the message interval between the 15th and 22nd beats, which can also be recorded as an offset.
[0080] After determining the above-mentioned message interval, in this embodiment, step S103 can be executed according to the following process: determine the current first read address of the first cache area when the last message of the above-mentioned user arrives; determine the first actual read address of the token balance based on the first read address and the message interval; read the token balance from the corresponding position of the first actual read address in the first cache area.
[0081] Similarly, the token balance writing process in step S108 can be executed according to the following process: determine the current first write address of the first cache area when the last message of the user arrives; determine the first actual write address of the new token balance based on the first write address and the message interval; write the new token balance into the corresponding position of the first actual write address in the first cache area.
[0082] Specifically, since the calculation of the message output color and the increase or decrease of the token will consume a certain amount of time, address correction is required when reading the token balance in the first buffer area in order to accurately read the token balance. Similarly, if time is consumed when calculating the message time difference, corresponding address correction is also required to accurately read the arrival time. In addition, the first buffer area and the second buffer area can be arbitrarily and temporarily occupied by each user, and do not conflict with each other. Moreover, the read and write addresses of the buffer area are not limited to user control, but with the automatic growth and circulation of time, considering that the calculation of the increase or decrease of the token and the message time difference requires time, therefore, there is a certain offset when reading and writing the address, and the offset is the above-mentioned message interval. Assuming that the above-mentioned offset is 5 clock cycles, it is necessary to calculate the actual read address or write address based on the current read or write address and the above-mentioned offset, and then accurately read or write the token balance or arrival time based on the actual read address or write address.
[0083] In order to better understand this embodiment, the above message interval is 5 beats as an example for explanation. Figure 3The reading and writing process shown is used as an example for explanation. Assume that when message 1 of user 1 arrives, the current first write address wr_addr=7 and the first read address rd_addr=12. Before message 1, there is message 0 with the same user address (user address of user 1) with a difference of 6 cycles, that is, the message interval is also called offset offset=6. Then, the token remainder calculated for the previous message 0 has an address that is the difference between the first read address and the offset, that is, the first actual read address is rd_addr-offset=6. In this way, the token remainder for user 1 can be read from the first actual read address.
[0084] Similarly, after executing the message forwarding of user 1 based on the read token balance, the token balance of user 1 will be recalculated, that is, the new token balance mentioned above. After calculating the token balance of user 1, when it needs to be written to the first cache area, it is also necessary to determine the first actual write address of the token balance. At this time, the new token balance is written to the first cache area based on the first actual write address. For example, after reading the token balance of user 1 from the first cache area, a new token balance is obtained after 5 cycles. As time goes by, the read / write address also increases. At this time, the new token balance of message 1 is written to the first actual write address of the first cache area: the sum of the current first write address and the message interval, that is, wr_addr+5=12, that is, it is written to the position corresponding to rd_addr when message 1 arrives. Assuming that after another 3 cycles, the next message 2 with the same user address arrives, it is necessary to read the result of the calculation of the previous message 1, that is, use the value of the address 12 space for calculation. If the time difference between message 2 and the previous message 1 is 5+3=8 cycles, that is, offset=8. Since the address will increase over time, the first read address and the first write address will change at this time. For example, the first read address: rd_addr=20 is the same as the method of calculating the actual address above. The first actual read address is: rd_addr-offset=12, that is, the token remainder after the calculation of the previous message 1 is obtained. After receiving several beat messages, the method of performing the actual read address and the actual write address can be obtained by referring to the above description, and will not be listed in detail here. This achieves accurate reading and writing of the token remainder.
[0085] For the same reason, address correction may be required when reading and writing the arrival time. Specifically, step S104 may be performed according to the following method: determining the current second read address of the second buffer area when the last beat message of the user arrives this time; determining the second actual read address of the arrival time when the last beat message of the user arrives last time according to the second read address and the message interval; reading the second actual read address of the arrival time when the last beat message of the user arrives last time from the corresponding position of the second actual read address in the second buffer area.
[0086] Further, step S109 can be performed according to the following method: determine the current second write address of the second cache area when the last beat message of the user arrives this time; determine the second actual write address of the arrival time when the new last beat message of the user arrives based on the second write address and the message interval; write the arrival time when the new last beat message of the user arrives to the corresponding position of the second actual write address in the second cache area.
[0087] It should be noted that the method of reading the arrival time from the second buffer area and writing the arrival time is similar to the method of reading and writing the token remainder, thereby achieving accurate reading and writing of the arrival time.
[0088] Optionally, based on any of the above embodiments, in this embodiment, the token increment in step S105 can be performed according to the following method: determine the time difference between the system time and the arrival time; multiply the time difference by the unit token increment of the user's unit time to determine the token increment of the user's token when the last message of the user is received this time.
[0089] Specifically, when the last beat message of the same user received this time arrives, the arrival time of the last beat message of the user this time can be recorded, that is, the current system time sys_time, and then the arrival time of the last beat message of the user last time recorded is read from the second buffer, recorded as last_time, so that the time difference between the two messages can be obtained, recorded as Δtime. On this basis, the unit token increment of the user per unit time can be obtained, recorded as xIR, and then the token increment of the user within this time difference can be obtained, that is, the product of the time difference and the unit token increment, which can be specifically expressed by referring to the following formula:
[0090] Δtime=sys_time–last_time
[0091] Δtoken=Δtime*xIR
[0092] After determining the token increment, the total token amount of the user at the current time can be calculated based on the token remainder token_remain of the user read from the first buffer area, that is, the sum of the token remainder and the token increment, which can be expressed by the following formula:
[0093] token=token_remain+Δtoken
[0094] After forwarding the message of the user based on the target token balance, the new token balance token_0 of the user after forwarding can be confirmed again, which is expressed by referring to the following formula:
[0095] token_0=token–token_take
[0096] On this basis, the new token balance is used as the aforementioned token balance token_remain, and is written into the first buffer area according to the method of step S108, so as to participate in the subsequent token calculation, thereby realizing the speed limit processing of the message. Similarly, the arrival time of the last message of the user received this time, that is, the current system time sys_time, is used as the arrival time last_time written last, and is written into the second buffer area according to the method of step S109, thereby ensuring the accurate reading and writing of the token balance and arrival time.
[0097] Optionally, based on any of the above embodiments, in this embodiment, the first cache area and the second cache area may be, but are not limited to, RAM, and the external storage unit may be, but is not limited to, QDR.
[0098] In addition, any embodiment of the present application may support single-speed single-bucket mode, single-speed dual-bucket mode, dual-speed dual-bucket mode, etc. when calculating tokens.
[0099] It should be noted that the message involved in this application may be a message that includes speed limit related information such as the user to which the message belongs and the message length. The above-mentioned user may be a real user or a virtual user, such as vsys, etc.
[0100] By implementing the above method, the read and write frequency of the external storage unit can be reduced, which is beneficial to the power consumption and life of the network device and the external storage unit. In addition, there is no need to wait when processing the message speed limit and it can achieve no impact on the original message rate, while improving the accuracy of the speed limit.
[0101] Based on the same inventive concept, the present application also provides a message processing device corresponding to the above message processing method. The implementation of the message processing device can refer to the above description of the message processing method, which will not be discussed here one by one.
[0102] See also Figure 4 , Figure 4 A message processing device provided by an exemplary embodiment of the present application is arranged in a field programmable gate array FPGA in a network device, wherein a first buffer area and a second buffer area are arranged inside the network device, and the above-mentioned device comprises:
[0103] The receiving module 401 is used to receive the messages of several beats of this time;
[0104] The accumulation module 402 is used to accumulate the message information of the messages of the same user in the messages of the plurality of beats after receiving the messages of the plurality of beats this time, so as to obtain the message statistics information of this time;
[0105] A first determination module 403 is used to determine the target number of tokens required for sending the user's message this time according to the message statistics information of this time;
[0106] A first acquisition module 404, configured to acquire the current token balance of the user from the first buffer area;
[0107] The second acquisition module 405 is used to acquire the recorded arrival time of the last message of the user from the second buffer area;
[0108] A second determination module 406 is used to determine the token increment of the token of the user when the last message of the user is received this time according to the arrival time and the current system time;
[0109] A third determination module 407, configured to determine the total amount of tokens of the user according to the token balance and the token increment;
[0110] A forwarding module 408, configured to forward the user's message according to the target token number if the total token number is not less than the target token number;
[0111] A fourth determination module 409, configured to determine a new token balance according to the total token amount and the target token amount;
[0112] A first writing module 410, configured to write a new token balance into the first buffer area;
[0113] The second writing module 411 is used to write the arrival time of the last beat message into the second buffer area as the arrival time of the new last beat message of the user.
[0114] Optionally, based on the above embodiment, the message processing device provided in this embodiment further includes:
[0115] A fifth determination module (not shown in the figure) is used to perform accumulation processing on the message information of the same user in the messages of the plurality of beats in the accumulation module, and after obtaining the message statistical information of this time, determine the message interval between the current accumulation processing and the previous accumulation processing;
[0116] On this basis, the first acquisition module 404 is specifically used to determine the current first read address of the first buffer area when the last beat message of the user arrives; determine the first actual read address of the token balance according to the first read address and the message interval; read the token balance from the corresponding position of the first actual read address in the first buffer area;
[0117] The first writing module 410 is specifically used to determine the current first writing address of the first buffer area when the last message of the user arrives; determine the first actual writing address of the new token balance according to the first writing address and the message interval; and write the new token balance into the corresponding position of the first actual writing address in the first buffer area.
[0118] Optionally, based on the above embodiment, in this embodiment, the above second acquisition module 405 is specifically used to determine the current second read address of the second buffer area when the last beat message of the user arrives this time; determine the second actual read address of the arrival time when the last beat message of the user arrives according to the second read address and the message interval; read the second actual read address of the arrival time when the last beat message of the user arrives from the corresponding position of the second actual read address in the second buffer area;
[0119] The second writing module 411 is specifically used to determine the current second writing address of the second buffer area when the last beat message of the user arrives this time; determine the second actual writing address of the arrival time when the new last beat message of the user arrives according to the second writing address and the message interval; write the arrival time when the new last beat message of the user arrives into the corresponding position of the second actual writing address in the second buffer area.
[0120] Optionally, based on any of the above embodiments, in this embodiment, the above-mentioned second determination module 406 is specifically used to determine the time difference between the system time and the arrival time; determine the unit token increment per unit time; and multiply the product of the time difference and the unit token increment to determine the token increment of the user's token when the last beat of the message of the user is received this time.
[0121] Optionally, based on any of the foregoing embodiments, the message processing device provided in this embodiment further includes:
[0122] A sixth determination module (not shown in the figure) is used to determine the number of tokens required to send the message of each user according to the message information of the user when the messages of the plurality of beats received this time do not include the message of the same user;
[0123] A third acquisition module (not shown in the figure) is used to obtain the current token balance of the user from the external storage unit corresponding to the user;
[0124] On this basis, the forwarding module 408 is further used to forward the message of the user according to the acquired token balance and the number of tokens required to send the message of the user;
[0125] A seventh determination module (not shown in the figure), used to re-determine the token balance;
[0126] The third writing module (not shown in the figure) is used to write the determined token balance into the external storage unit of the user.
[0127] By providing the above-mentioned device, the read and write frequency of the external storage unit can be reduced, which is beneficial to the power consumption and life of the network equipment and the external storage unit. In addition, there is no need to wait when processing the message speed limit and it can achieve no impact on the original message rate, while the accuracy of the speed limit can be improved.
[0128] 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.
[0129] The implementation process of the functions and effects of each unit / module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0130] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are merely schematic, wherein the units / modules described as separate components may or may not be physically separated, and the components displayed as units / modules may or may not be physical units / modules, that is, they may be located in one place, or they may be distributed on multiple network units / modules. Some or all of the units / modules may be selected according to actual needs to achieve the purpose of the present application. A person of ordinary skill in the art can understand and implement it without creative work.
[0131] 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 processing method, It is characterized in that In a field programmable gate array FPGA applied to a network device, the network device is provided with a first buffer area and a second buffer area, and the method comprises: After receiving a plurality of beats of messages this time, accumulating the message information of the messages of the same user in the plurality of beats of messages, to obtain the message statistical information of this time; Determine the target number of tokens required for sending the user's message this time based on the message statistics information this time; Acquire the current token balance of the user from the first buffer area, where the first buffer area is used to store the token balance of the user who continuously sends messages to the network device; Acquire the recorded arrival time of the last last beat message of the user from the second buffer area; Determine, according to the arrival time and the current system time, the token increment of the token of the user when the last message of the user is received this time; Determine the total amount of tokens of the user according to the token balance and the token increment; If the total number of tokens is not less than the target number of tokens, forwarding the user's message according to the target number of tokens; Determine a new token balance according to the total token amount and the target token amount; and write the new token balance into the first buffer area; The arrival time of the last beat message is written into the second buffer area as the new arrival time of the last beat message of the user.
2. The method according to claim 1, It is characterized in that After accumulating the message information of the messages of the same user in the messages of the plurality of beats to obtain the message statistical information of this time, the method further includes: Determine the message interval between this accumulation process and the previous accumulation process; Acquiring the current token balance of the user from the first buffer area includes: Determine the current first read address of the first buffer area when the last beat message of the user arrives; Determining a first actual read address of the token remainder according to the first read address and the message interval; Reading the token remainder from a position corresponding to the first actual read address in the first buffer area; Writing the new token balance into the first buffer area includes: Determine the current first write address of the first buffer area when the last message of the user arrives; Determining a first actual write address of the new token remainder according to the first write address and the message interval; The new token remainder is written into the first buffer area at a position corresponding to the first actual write address.
3. The method according to claim 2, It is characterized in that Acquiring from the second buffer the arrival time of the last message of the user recorded in the previous step, including: Determine the current second read address of the second buffer area when the last beat message of the user arrives; Determine, according to the second read address and the message interval, a second actual read address of the arrival time when the last beat message of the user arrives; Reading the second actual read address of the arrival time when the last beat message of the user arrived from the corresponding position of the second actual read address in the second buffer area; Writing the arrival time of the last beat message of this time as the new arrival time of the last beat message of the user into the second buffer area includes: Determine the current second write address of the second buffer area when the last beat message of the user arrives; Determine, according to the second write address and the message interval, a second actual write address of the arrival time when the new last beat message of the user arrives; The arrival time of the new last beat message of the user is written into the corresponding position of the second actual write address in the second buffer area.
4. The method according to claim 1, It is characterized in that Determining, according to the arrival time and the current system time, a token increment of the token of the user when the last message of the user is received this time, including: determining a time difference between the system time and the arrival time; The product of the time difference and the unit token increment per unit time of the user is determined as the token increment of the user's token when the last beat of the message of the user is received this time.
5. The method according to claim 1, It is characterized in that Also includes: When the messages of the plurality of beats received this time do not include messages of the same user, the number of tokens required to send the message of each user is determined according to the message information of the user; Obtain the current token balance of the user from the external storage unit corresponding to the user; Forward the user's message based on the obtained token balance and the number of tokens required to send the user's message; Re-determine the token balance; The determined token balance is written into the user's external storage unit.
6. A message processing device, It is characterized in that The device is arranged in a field programmable gate array FPGA in a network device, wherein a first buffer area and a second buffer area are arranged inside the network device, and the device comprises: A receiving module, used for receiving the messages of several beats of this time; An accumulation module is used to accumulate the message information of the messages of the same user in the messages of the plurality of beats after receiving the messages of the plurality of beats this time, so as to obtain the message statistics information of this time; A first determination module, used to determine the target number of tokens required for sending the message of the user this time according to the message statistics information of this time; A first acquisition module, used for acquiring the current token balance of the user from the first buffer area, the first buffer area being used for storing the token balance of the user who continuously sends messages to the network device; A second acquisition module is used to acquire the recorded arrival time of the last message of the user from the second buffer area; A second determination module is used to determine the token increment of the token of the user when the last message of the user is received this time according to the arrival time and the current system time; A third determination module, configured to determine the total amount of tokens of the user according to the token balance and the token increment; A forwarding module, configured to forward the user's message according to the target token number if the total token number is not less than the target token number; A fourth determination module, used to determine a new token balance according to the total token amount and the target token amount; A first writing module, used for writing a new token balance into the first buffer area; The second writing module is used to write the arrival time of the last beat message into the second buffer area as the arrival time of the new last beat message of the user.
7. The device according to claim 6, It is characterized in that Also includes: A fifth determination module, configured to perform accumulation processing on the message information of the same user in the messages of the plurality of beats in the accumulation module, and after obtaining the message statistical information of this time, determine the message interval between the current accumulation processing and the previous accumulation processing; The first acquisition module is specifically used to determine the current first read address of the first buffer area when the last beat message of the user arrives; determine the first actual read address of the token balance according to the first read address and the message interval; read the token balance from the corresponding position of the first actual read address in the first buffer area; The first writing module is specifically used to determine the current first writing address of the first buffer area when the last message of the user arrives; determine the first actual writing address of the new token balance according to the first writing address and the message interval; and write the new token balance into the corresponding position of the first actual writing address in the first buffer area.
8. The device according to claim 7, It is characterized in that The second acquisition module is specifically used to determine the current second read address of the second buffer area when the last beat message of the user arrives this time; determine the second actual read address of the arrival time when the last beat message of the user arrives according to the second read address and the message interval; read the second actual read address of the arrival time when the last beat message of the user arrives from the corresponding position of the second actual read address in the second buffer area; The second writing module is specifically used to determine the current second writing address of the second buffer area when the last beat message of the user arrives this time; determine the second actual writing address of the arrival time when the new last beat message of the user arrives according to the second writing address and the message interval; write the arrival time when the new last beat message of the user arrives into the corresponding position of the second actual writing address in the second buffer area.
9. The device according to claim 6, It is characterized in that The second determination module is specifically used to determine the time difference between the system time and the arrival time; determine the unit token increment per unit time; and multiply the time difference by the unit token increment to determine the token increment of the user's token when the last message of the user is received this time.
10. The device according to claim 6, It is characterized in that Also includes: A sixth determination module, configured to determine the number of tokens required to send a message of a user according to the message information of each user when the messages of the plurality of beats received this time do not include a message of the same user; A third acquisition module, used to acquire the current token balance of the user from the external storage unit corresponding to the user; The forwarding module is further used to forward the message of the user according to the acquired token balance and the number of tokens required to send the message of the user; A seventh determination module, used for re-determining the token balance; The third writing module is used to write the determined token balance into the external storage unit of the user.
