Summary of the invention
Technical problem to be solved by this invention provides a kind of method and system of the token bucket speed limit based on message priority, when overcoming the usefulness token bucket methodology speed limit that exists in the prior art, the height nondistinctive problem of priority packet and defective provide a kind of method of the token bucket speed limit based on priority.
In order to solve the problems of the technologies described above, the invention provides a kind of method of the token bucket speed limit based on priority, comprising:
Speed limit parameter according to the attribute configuration message of message comprises speed limit, and the token buckets at different levels that successively decrease one by one are dark, and guarantees that token number in the highest token bucket is more than or equal to the token number sum in all the other token buckets at different levels;
Receive after the message token number that calculating will be added;
Need not carry out the priority speed limit when determining, then the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit; And
To carry out the priority speed limit when determining, for the message priority number message identical with speed limit progression, the token number that will add simultaneously adds in into highest token bucket and the pairing token bucket of current message progression, utilizes the pairing token bucket of current message progression that current message is carried out speed limit;
For the message priority number message different with speed limit progression, then the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit.
In order to solve the problems of the technologies described above, the present invention also provides a kind of system of the token bucket speed limit based on priority, comprising:
Configuration module is used for the speed limit parameter according to the attribute configuration message of message, comprises speed limit, and the token buckets at different levels that successively decrease one by one are dark, and guarantees that token number in the highest token bucket is more than or equal to the token number sum in all the other token buckets at different levels;
Receiver module is used to receive current message;
Acquisition module obtains the corresponding speed limit parameter that gets with current message attribute;
Computing module is used to receive after the message token number that calculating will be added;
First judge module is used for need not carrying out the priority speed limit when determining, and sends first triggering signal;
First processing module, be used to receive described first triggering signal after, the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit;
Second judge module is used for will carrying out the priority speed limit when determining, and further determines the message priority number when identical with speed limit progression, sends second triggering signal;
Second processing module, the token number that is used for will adding simultaneously adds into highest token bucket and the pairing token bucket of current message progression, utilizes the pairing token bucket of current message progression that current message is carried out speed limit;
The 3rd judge module is used for will carrying out the priority speed limit when determining, and further determines message priority number and speed limit progression not simultaneously, sends the 3rd triggering signal;
The 3rd processing module, the token number that is used for adding are added into highest token bucket, utilize highest token bucket that current message is carried out speed limit.
This method is compared with current techniques, provide a kind of can be based on the token bucket method for limiting speed of priority, make different messages under same speed limit condition, different drop probabilities be arranged, be that high priority can pass through under network congestion fast, the message of low priority has higher drop probability, avoided current techniques when token bucket speed limit, high level message is by the problem of random drop under the network congestion, reached the effect of speed limit, save Internet resources, improved the service quality of network simultaneously.
Embodiment
Main thought of the present invention is that the token bucket of different speed limit progression is set is dark, when the progression of the current message that receives is identical with progression that will speed limit, uses and with the corresponding token bucket of the progression of speed limit current message is carried out speed limit and handle; When the progression of the current message that receives and progression that will speed limit not simultaneously, utilize five-star token bucket that current message is carried out speed limit and handle.Specifically, may further comprise the steps:
The speed limit parameter of configuration message comprises speed limit, and the token buckets at different levels that successively decrease one by one are dark, and guarantees that token number in the highest token bucket is more than or equal to the token number sum in all the other token buckets at different levels;
Receive after the message token number that calculating will be added;
Judge whether to carry out the priority speed limit, if need not carry out the priority speed limit, then the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit;
To carry out the priority speed limit if determine, then further judge the priority of messages number, for the message priority number message identical with speed limit progression, the token number that will add simultaneously adds in into highest token bucket and the pairing token bucket of current message progression, utilize the pairing token bucket of current message progression that current message is carried out speed limit, upgrade the token number in highest token bucket and the pairing token bucket of current message progression afterwards simultaneously;
For the message priority number message different with speed limit progression, then the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit; And guarantee that token number in the highest token bucket is more than or equal to the token number sum in all the other token buckets at different levels.
Be described in further detail below in conjunction with the enforcement of accompanying drawing technical scheme:
In first preferred embodiment of the present invention, speed limit progression comprises two-stage: low priority and high priority, and the method based on the token bucket speed limit of priority in the present embodiment needs following configuration in the time of enforcement:
The speed limit of 1 configuration different attribute message, (unit of speed limit is bps).Concrete numerical value can be set according to actual needs, here the configuration of speed limit is to determine according to different users, the bandwidth ratio that the user that service class is high distributes is bigger, so corresponding speed limit comparatively speaking can be more greatly such as 10M, the general user may be 1M) (the attribute here is meant that different messages is from different sources or user), should comprise whether needing enabling of low priority speed limit simultaneously;
The token bucket degree of depth of 2 configuration message speed limits comprises the total barrel of degree of depth and the low priority token bucket degree of depth, and it should be noted that the low priority bucket is dark must be less than the degree of depth of total bucket, simultaneously must be greater than zero;
3 storage devices that are used for each token bucket token number of real-time storage.
Here specify the execution mode of this method by example.
With reference to shown in Figure 2, for example receive a low priority message, need carry out the low priority speed limit to it, its step is as follows:
1) attribute according to message obtains configuration, the speed of speed limit, and total token bucket bucket is dark, and the bucket of low priority bucket is dark, whether carries out the low priority speed limit;
By above narrating as can be known, based on configuration before, have the corresponding different configuration of message of different attribute, like this,, just can obtain its corresponding configuration according to the attribute of the message that acquires.For example whole network service object has 100, and these 100 users can number 0-99 so, and the corresponding configuration of each numbering is searched corresponding configuration according to numbering when each message arrives.
2) according to the speed limit speed of obtaining, and a last message calculates the token number that needs interpolation to the time difference of current message;
The token number that adds is to obtain according to the speed that the time difference that the adjacent message of same attribute arrives be multiply by speed limit, and unit is a byte number.
3) token number of the interpolation of calculating is added respectively in the low priority token bucket and total bucket, obtain current available token number;
4) token number in the current low priority bucket and current message length are compared,, otherwise be considered as abandoning if token number more than message length, is then transmitted this message;
5) upgrade token number in low priority bucket and the total bucket simultaneously, if current bag abandons, token number in two buckets is respectively the available tokens number after adding in 4, dark for token number after adding token greater than token bucket, it is dark then the degree of depth of token bucket to be updated to bucket, for the situation of the bag that passes through, the token number in its barrel is the poor of available tokens number and message length;
Flow process finishes, for current low priority message, because the dark superficial cause of low priority bucket, limit its maximum burst size, exchange the available tokens number of follow-up high-priority packets for high relatively loss ratio, improve the percent of pass of follow-up high-priority packets, guarantee the service quality of network.
With reference to shown in Figure 3, carry out the non-low priority message of low priority speed limit for needs, then carry out following steps:
1) attribute according to message obtains configuration, the speed of speed limit, and total token bucket bucket is dark, and the bucket of low priority bucket is dark, whether carries out the low priority speed limit;
2) according to the speed limit speed of obtaining, and a last message calculates the token number that needs interpolation to the time difference of current message;
3) token number with the interpolation of calculating only adds in into total bucket, obtains current available token number; As shown in Figure 3
4) token number in current total token bucket and current message length are compared,, otherwise be considered as abandoning if token number more than message length, is then transmitted this message;
5) token number in the total token bucket of renewal, if current bag abandons, token number in total bucket is the available tokens number in 4, dark for token number after adding token greater than token bucket, it is dark then the degree of depth of token bucket to be updated to bucket, for the situation by bag, the token number in total bucket is the poor of available tokens number and current message length.Here it should be noted that token number in the low priority bucket forever less than the token number in total bucket, therefore,, need to upgrade the token number of low priority bucket, the two is equated when the token number in total token bucket during less than the token number in the low priority bucket.
Flow process finishes, for current non-low priority message, though it is required with the low priority speed limit, but it does not belong to the low priority message, the maximum burst size of corresponding permission is greater than low priority packet, for follow-up any message, all is the influence that is not subjected to current message.
For the message that does not need to carry out the low priority speed limit, the step of its enforcement promptly is the current flow process that is widely used, do not need to consider any parameter of low priority bucket, only using total token bucket gets final product, certainly, its effect can only be all other messages of level of same attribute, and identical maximum burst size restriction is all arranged, in network congestion, can discarding by randomness.
Fig. 4 is the method flow diagram of token bucket speed limit based on priority of the present invention.Be about to flow process shown in Figure 2 and flowsheet synthesis shown in Figure 3 gets up to set forth, comprise:
Step 401: add token number according to rate calculations;
Step 402: judge whether to carry out the low priority speed limit; If, execution in step 403, if not, execution in step 411;
Is step 403: the judgment data bag a low priority? if, execution in step 404, if not, execution in step 407;
Step 404: add token toward low priority bucket and total token bucket simultaneously;
Step 405: the algorithm process of carrying out the RFC2697 standard code according to the low priority bucket;
Step 406: discarded packets, do not carry out the reducing of token, carry out the reducing of total bucket and low priority bucket simultaneously by bag, finish;
Step 407: only carry out the interpolation of total token bucket, do not carry out the interpolation of low priority bucket;
Step 408:, carry out the algorithm process of TrTCM according to total token bucket;
Step 409: discarded packets, do not carry out the reducing of token; By bag, only carry out the reducing of total bucket;
Step 410: when total token bucket during, the token number of low priority bucket must be changed to total token number, finish less than the priority bucket;
Step 411: only use total token bucket, in bucket, add token number;
Step 412: carry out the algorithm process of RFC2697 standard code, finish.
In addition, method for limiting speed provided by the invention also can be expanded the speed limit into multipriority, and be not limited only to the difference of high low priority, for example, be respectively high, medium and low three grades of priority, when realizing three grades of speed limits, use set of parameters with the difference of two-stage speed limit be exactly more, and respectively overlapping has certain association between the parameter, specifically implement as follows:
The speed limit speed (the attribute here is meant that different messages is from different sources or user) of 1 configuration different attribute message;
Three token bucket degree of depth of 2 configurations, respectively corresponding high, medium and low priority bucket is dark, and three dark relations of bucket should be among CBS height>CBS>CBS is low, simultaneously among the CBS+CBS is low otherwise greater than the CBS height, three dark priority speed limits that comprise simultaneously of bucket enable; (the dark total bucket that is equivalent in the accompanying drawing of the high priority bucket here is dark)
3 storage devices that are used for each token bucket token number of real-time storage.
Here specify the execution mode of multistage speed limit by example:
For example receive a medium priority message, need carry out the medium priority speed limit to it, its step is as follows
1. the attribute according to message obtains configuration, the speed of speed limit, and the high priority token bucket bucket is dark, and the bucket of medium priority bucket is dark, whether carries out intermediate priority speed limit;
2. according to the speed limit speed of obtaining, and a last message is to the time difference of current message, and calculating needs the token number that adds;
3. the token number with the interpolation of calculating adds respectively in into intermediate priority token bucket and the high priority bucket, obtains current available token number;
4. token number in the current medium priority bucket and current message length are compared,, otherwise be considered as abandoning if token number more than message length, is then transmitted this message;
5. upgrade the token number in medium priority bucket and the high priority bucket simultaneously, if current bag abandons, the token number in two buckets is respectively the available tokens number in 4, and for dark greater than token bucket, it is dark then to be updated to bucket, and for the bag that passes through, its token number is poor for both; Here it should be noted that when the token number in the low priority bucket during, must upgrade token number in the low priority bucket and make it equal token number in the medium priority bucket more than the medium priority token number; High priority bucket rank is the highest, and the token number in the bucket does not change because of the size of the token number in other barrel
Flow process finishes.
Carry out the non-medium priority message of medium priority speed limit for needs, so, may be low priority message or high priority message, if the low priority message, and be that the low priority speed limit enables simultaneously, then the method among Fig. 3 is carried out speed limit.If the low priority speed limit does not also enable or this message is a high priority, then carry out speed limit according to the method among Fig. 2, the corresponding total bucket of high priority bucket, the renewal of middle low priority bucket is with reference to the update method of the low priority bucket among Fig. 2.
With reference to shown in Figure 5, be the system construction drawing of token bucket speed limit based on priority of the present invention.
Configuration module 501 is used for the speed limit parameter according to the attribute configuration message of message, comprises speed limit, and the token buckets at different levels that successively decrease one by one are dark, and guarantees that token number in the highest token bucket is more than or equal to the token number sum in all the other token buckets at different levels;
Receiver module 502 is used to receive current message;
Acquisition module 503 obtains the corresponding speed limit parameter that gets with current message attribute;
Computing module 504 is used to receive after the message token number that calculating will be added;
First judge module 505 is used for need not carrying out the priority speed limit when determining, and sends first triggering signal;
First processing module 506, be used to receive described first triggering signal after, the token number that will add adds in the into highest token bucket, utilizes highest token bucket that current message is carried out speed limit;
Second judge module 507 is used for will carrying out the priority speed limit when determining, and further determines the message priority number when identical with speed limit progression, sends second triggering signal;
Second processing module 508, the token number that is used for will adding simultaneously adds into highest token bucket and the pairing token bucket of current message progression, utilizes the pairing token bucket of current message progression that current message is carried out speed limit;
The 3rd judge module 509 is used for will carrying out the priority speed limit when determining, and further determines message priority number and speed limit progression not simultaneously, sends the 3rd triggering signal;
The 3rd processing module 510, the token number that is used for adding are added into highest token bucket, utilize highest token bucket that current message is carried out speed limit.
In a preferred embodiment of the invention, described second processing module 508 also is used for upgrading simultaneously the token number of highest token bucket and the pairing token bucket of current message progression.
In a preferred embodiment of the invention, described the 3rd processing module 510 also is used for making the token number of highest token bucket more than or equal to the token number sum in all the other token buckets at different levels.
The attribute of described message is meant that different messages is from different sources or user.
Described computing module 504 is used for according to speed limit and this message time difference calculating token number that will add with same attribute message last time.
In a preferred embodiment of the invention,
It is dark that described configuration module 501 is used to dispose the token buckets at different levels that successively decrease one by one, comprises that total token is deeply logical and the low priority token bucket is dark, corresponding,
Receiver module 502 is used to receive a low priority message;
Acquisition module 503 is used for obtaining according to the attribute of message the speed limit parameter of message, and described parameter comprises: speed limit, total token logical dark, the low priority token bucket is dark;
Second judge module 507 is used to determine and need carries out the low priority speed limit to it, sends second triggering signal;
Computing module 504, according to the speed limit that obtains, and a last message calculates the token number that needs interpolation to the time difference of current message;
Second processing module 508, the token number that is used for the interpolation that will calculate adds into low priority token bucket and total bucket respectively, obtains current available token number; Token number in the current low priority bucket and current message length are compared, if token number more than current message length, is then transmitted this current message, otherwise is considered as abandoning current message; Upgrade the token number in low priority bucket and the total bucket simultaneously, if current packet loss, token number in two buckets is respectively the available tokens number after the interpolation, token number after adding is dark greater than token bucket, it is dark then the degree of depth of token bucket to be updated to bucket, current message passes through, then poor for token number after adding and current message length of the token number in the token bucket; Upgrade the token number of total token bucket and low priority token bucket.
In another preferred embodiment of the present invention,
Receiver module 502 also is used to receive a non-low priority message;
Acquisition module 503 is used for obtaining according to the attribute of message the speed limit parameter of message, and described parameter comprises: speed limit, total token logical dark, the low priority token bucket is dark;
According to the speed limit that obtains, and a last message calculates the token number that needs interpolation to the time difference of current message;
Computing module 504 only adds the described token number that needs to add in into total token bucket, obtains current available token number;
The 3rd judge module 509 is used for will carrying out the low priority speed limit when determining, and sends the 3rd triggering signal;
The 3rd processing module 510 is used for the token number and the current message length of current total token bucket are compared, if token number more than current message length, is then transmitted this current message, otherwise is considered as abandoning current message; Upgrade the token number in total token bucket, if current packet loss, token number in total bucket is the available tokens number after the interpolation, token number after adding is dark greater than token bucket, it is dark then the degree of depth of token bucket to be updated to bucket, when current message passes through, poor for token number after adding and current message length of the token number in the token bucket then; Token number in determining total token bucket is less than the token number in the low priority bucket, then upgrades the token number of low priority bucket and equates with token number in total token bucket.
Method provided by the invention can be according to the number of user's requirements extend priority, as long as abide by a principle, the dark configuration of limit priority bucket is not less than the summation of all the other times dark configuration of priority bucket, follow this rule when upgrading the token number storage condition equally, promptly the token number in the low priority bucket must not surpass the token number of high one-level token bucket; Like this, the speed limit of utilizing this method to provide illustrates, can reach the speed limit of multilevel precedence, improves network service quality (QOS).
It is pointed out that the above only is preferred embodiment of the present invention, is not to be used for limiting practical range of the present invention, and every variation and modification according to the equivalence that the present invention did are all covered by claim of the present invention.