Summary of the invention
In order to reduce hardware cost, improve systematic function, the invention provides a kind of method and device that obtains data rate, technical scheme is as follows:
A method of obtaining data rate, comprising:
The Startup time T of w counter and each counter is set
t, described counter is used for obtaining the data rate through communication node, wherein, w=1,2 ..., N
window,
for window duration T
windowinterior by the packet number of described communication node, Trans
intervalfor data packet transmission minimum interval, t=1,2 ..., w-1, T
t< T
t+1;
From first counter, current counter starts when its Startup time arrives, and obtains the data rate through described communication node;
The data rate acquiring with described current counter upgrades the upper data rate that counter acquires of described current counter.
In the preferred embodiment of the present invention, described current counter starts when its Startup time arrives, and obtains the data rate through described communication node, comprising:
Described current counter starts when its Startup time arrives, and obtains respectively packet number and data package size through described communication node;
Whether the packet number of obtaining described in judgement reaches default value N
window;
If so, according to described data package size and described window duration T
windowobtain the data rate of the described communication node of described process.
In the preferred embodiment of the present invention, if the packet number of obtaining described in judgement does not reach described default value, continue to obtain packet number and the data package size through described communication node, until described in the packet number obtained reach described default value N
window, and according to described data package size and described window duration T
windowobtain the data rate of the described communication node of described process.
In the preferred embodiment of the present invention, obtaining after the data rate step of described communication node, also comprise:
Described current counter resets, and continues to obtain the data rate through described communication node.
In the preferred embodiment of the present invention, the difference of the Startup time of adjacent described counter is steady state value.
A device that obtains data rate, comprising:
Module is set, for the Startup time T of w counter and each counter is set
t, described counter is used for obtaining the data rate through communication node, wherein, w=1,2 ..., N
window,
for window duration T
windowinterior by the packet number of described communication node, Trans
intervalfor data packet transmission minimum interval, t=1,2 ..., w-1, T
t< T
t+1;
W counter, from first counter, current counter, for starting when its Startup time arrives, obtains the data rate through described communication node;
Update module, upgrades the upper data rate that counter acquires of current counter for the data rate with current counter acquires.
In the preferred embodiment of the present invention, described current counter, specifically for starting when its Startup time arrives, obtains packet number and data package size through described communication node;
Whether the packet number of obtaining described in judgement reaches default value N
window;
If so, according to described data package size and described window duration T
windowobtain the data rate of the described communication node of described process.
In the preferred embodiment of the present invention, described current counter, if also do not reach described default value N for the packet number of obtaining described in judgement
window, continue to obtain packet number and the data package size through described communication node, until described in the packet number obtained reach described default value, and according to described data package size and described window duration T
windowobtain the data rate of the described communication node of described process.
In the preferred embodiment of the present invention, described current counter, also, for obtaining after the data rate step of described communication node, resets, and continues to obtain the data rate through described communication node.
In the preferred embodiment of the present invention, the difference of the Startup time of adjacent described counter is steady state value.
The present invention is by being provided for obtaining the counter of data rate and the Startup time of each counter, without the communication node of changing hardware and can meet data traffic frequent variations, obtain the needs of data rate, reduced hardware cost, and parameters is flexible, systematic function and service quality have been improved.
Embodiment
In order to make technical problem to be solved by this invention, technical scheme and beneficial effect clearer, clear, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
As shown in Figure 1, the embodiment of the present invention provides a kind of method of obtaining data rate, comprising:
Step 101, arranges the Startup time T of w counter and each counter
t, this counter is used for obtaining the data rate through communication node, wherein, w=1,2 ..., N
window,
for window duration T
windowinterior by the packet number of described communication node, Trans
intervalfor data packet transmission minimum interval, t=1,2 ..., w-1, T
t< T
t+1;
Step 102, from first counter, current counter starts when its Startup time arrives, and obtains the data rate through this communication node;
Step 103, upgrades the upper data rate that counter acquires of current counter with the data rate that current counter acquires.
In a preferred embodiment of the present invention, this current counter starts when its Startup time arrives, and obtains the data rate through this communication node, comprising:
This current counter starts when its Startup time arrives, and obtains packet number and data package size through this communication node;
Judge whether this packet number of obtaining reaches default value N
window;
If so, according to this data package size and this window duration T
windowobtain the data rate through this communication node.
In a preferred embodiment of the present invention, if judge that this packet number of obtaining does not reach this default value N
window, continue to obtain packet number and the data package size through this communication node, until this packet number of obtaining reaches this default value N
window, and according to this data package size and this window duration T
windowobtain the data rate through this communication node.
In a preferred embodiment of the present invention, obtaining after the data rate step of this communication node, also comprise:
This current counter resets, and continues to obtain the data rate through this communication node.
In a preferred embodiment of the present invention, the difference of the Startup time of adjacent described counter is steady state value.
Wherein, data rate is traffic data rate or controls data rate.
Below by specific embodiment, the present invention is described in detail:,
Take and obtain traffic data rate as example, as shown in Figure 2, the method for obtaining data rate that the present embodiment provides, comprising:
Step 201, determines the Startup time of counter number and counter.
Wherein, counter can accumulator, accumulation subtraction apparatus, the tired device or tired except device etc. of taking advantage of, and for convenient for example, the present embodiment describes with accumulator.The method of determining the Startup time of accumulator number w and counter includes but not limited to following two kinds:
First method:
W accumulator is set, is respectively accumulator S
1, S
2..., S
w, wherein, w=1,2 ..., N
window, the larger precision of w value is higher, and the resource that takes up room is also just more, works as w=N
windowthe present invention's memory space used is identical with sliding window statistics, and statistics is also identical, with the equivalence completely of sliding window statistics.Accumulator adds up for current data packet size and the packet number to by this communication node.
In actual applications, for the ease of realizing, establishing window duration is T
window=2
n, n is positive integer; Accumulator number w=2
k, k≤n wherein, k is positive integer.According to concrete available storage resources, choose rational accumulator number.
After definite accumulator number, need to determine accumulator S
jstartup time T
t, wherein, t=1,2 ..., w-1, T
t< T
t+1.In actual applications, adjacent accumulator Startup time poor, the time interval can be steady state value, also can be to be certain Changing Pattern to change, for example, be equal difference and change, wait and take advantage of variation etc., can also be unordered Changing Pattern, specifically can set according to actual conditions.In the present embodiment, for convenience of description, the difference of adjacent accumulator Startup time is preferably constant duration, specifically can obtain by following formula: time interval T
intervalfor
individual or
individual Trans
intervaleffect is best.
In the present embodiment, T
window=2
n, w=2
k, therefore, T
interval=2
n-k.
Second method:
Consider between poor, the statistical accuracy, space expense of accumulator number, adjacent accumulator Startup time and exist close relationship, can, according to the requirement of statistical accuracy and memory space resource, by the difference of accumulator Startup time, determine accumulator number.Take accumulator Startup time difference as constant duration be example, T
intenal=1,2,3 ..., T
window, for example 1 represents 1 Trans
interval, 2 represent 2 Trans
interval, T
windowrepresent T
windowindividual Trans
interval, the concrete time interval is set as required, T
intervalless, statistical accuracy is higher, and space resources expense is larger, works as T
interval=1Trans
intervaltime, the present embodiment memory space resource used is identical with sliding window statistics, and statistics is also identical, with the equivalence completely of sliding window statistics.According to the statistical accuracy of concrete application, require and available storage resources is chosen rational accumulator number w value and is
individual or
individual.
Step 202, starts counter, calculates packet number and data package size through communication node.
Wherein, if adopt the first method in step 201 to set the time interval that starts accumulator, every 2
n-kindividual Trans
intervalstart an accumulator; If adopt the second method in step 201 to set the startup accumulator time interval, every T
intervalindividual Trans
intervalstart an accumulator.Once accumulator is activated, the data package size through this communication node and packet number are started to statistics.
Step 203, according to data package size sum S
j_PSwith packet number sum S
j_num, calculating and renewal are through the traffic data rate of this communication node
wherein, j=1,2 ..., w.
Referring to Fig. 3, this step is processed as follows in detail:
Step 203a, without loss of generality with accumulator S
jfor example describes, for accumulator S
jonce, starting, this communication node data package size of current process PSi that starts to add up respectively, obtains data package size sum S
j_PS, and cumulative data bag number, obtain packet number sum S
j_num, and judge S
j_numwhether reach N
window, if so, turn to step 203b; If not, turn to step 203c;
Accumulator is at calculated data bag number sum S
j_numtime, no matter whether data package size is 0 all cumulative 1, for data package size PSi, according to actual size, add up.
Step 203b, calculates and exports by the data rate of this communication node
by accumulator S
jreset, preferably, accumulator S
jinitial value is 0, but protection scope of the present invention is not limited to numerical value 0.By accumulator S
jreset is S
j=0, i.e. S
j_PS=0, S
j_num=0, and continue data package size PSi and packet number through this communication node to add up respectively, until S
j_numreach N
window.
Step 203c, accumulator S
jcontinue to add up, and turn to step 203a.
Step 203d, at accumulator S
j+1when Startup time arrives, start accumulator S
j+1data package size PSi and packet number through this communication node are added up, carry out accumulation step and can, referring to 203a-203b, then export new traffic data rate and replace accumulator S
jthe traffic data rate of output.
Wherein, the first method of step 201 is example, accumulator S
jwith accumulator S
j+1between the time interval be 2
n-k.
Inventive concept based on identical with method, as shown in Figure 4, the embodiment of the present invention provides a kind of device that obtains data rate, comprises
Module 401 is set, for the Startup time T of w counter and each counter is set
t, described counter is used for obtaining the data rate through communication node, wherein, w=1,2 ..., N
window,
for window duration T
windowinterior by the packet number of described communication node, Trans
intervalfor data packet transmission minimum interval, t=1,2 ..., w-1, T
t< T
t+1;
W counter 402, from first counter, current counter 402, for starting when its Startup time arrives, obtains the data rate through described communication node;
Update module 403, upgrades the upper data rate that counter acquires of current counter for the data rate with current counter acquires.
In a preferred embodiment of the present invention, current counter 402, specifically for starting when its Startup time arrives, obtains packet number and data package size through communication node;
Whether the packet number of obtaining described in judgement reaches default value N
window;
If so, according to data package size and described window duration T
windowobtain the data rate of the described communication node of described process.
In a preferred embodiment of the present invention, current counter 402, if the packet number of also obtaining for judgement does not reach default value N
window, continue to obtain packet number and the data package size through communication node, until the packet number of obtaining reaches described default value, and according to data package size and window duration T
windowobtain the data rate through communication node.
In a preferred embodiment of the present invention, current counter 402, also, for obtaining after the data rate step of communication node, resets, and continues to obtain the data rate through communication node.
In a preferred embodiment of the present invention, the difference of the Startup time of contiguous counter is steady state value.
The present invention is by being provided for obtaining the counter of data rate and the Startup time of each counter, without the communication node of changing hardware and can meet data traffic frequent variations, obtain the needs of data rate, reduced hardware cost, and parameters is flexible, systematic function and service quality have been improved.In addition, in counter number value hour, for example w=4 or 8 o'clock, can meet and obtain the demand of calculating data rate, and its memory space expense is very little, has saved significantly space resources, has further reduced hardware cost.
Above-mentioned explanation illustrates and has described a preferred embodiment of the present invention, but as previously mentioned, be to be understood that the present invention is not limited to disclosed form herein, should not regard the eliminating to other embodiment as, and can be used for various other combinations, modification and environment, and can, in invention contemplated scope described herein, by technology or the knowledge of above-mentioned instruction or association area, change.And the change that those skilled in the art carry out and variation do not depart from the spirit and scope of the present invention, all should be in the protection range of the appended claim of the present invention.