A kind of bandwidth fairness control method based on layering token bucket
Technical field
The present invention relates to a kind of network bandwidth control technology, specifically, relate to a kind of band based on layering token bucket
Wide fairness control method.
Background technology
The router traffic management that HTB (Hierarchical Token Bucket) algorithm is the most relatively advanced is calculated
Method, it can be effectively improved bandwidth availability ratio and limit the use of the mass download softwares such as P2P: for the Intranet of normal online
Main frame, system will allow it accidentally to break through maximum speed limit;Conversely, for the intranet host of the softwares such as Long-Time Service P2P, system will
Its bandwidth can be reduced so that it is the impact on other main frames is preferably minimized.
HTB algorithm support flows to row major level according to information such as IP address, agreement, ports and arranges data, then for
Different classes of data stream carries out bandwidth control, it is intended that main frame or service are reserved bandwidth, limited high bandwidth, also can realize average
Distribution bandwidth, row major level of going forward side by side manages, is particularly suitable for the network of voice and video and data mixing.
But, HTB algorithm, owing to using serial mechanism, although it ensure that the primary bandwidth needs of user, exists
Can not the defect of Appropriate application bandwidth effective, maximum.
Summary of the invention
It is an object of the invention to provide a kind of bandwidth fairness control method based on layering token bucket, mainly solve existing
The problem that HTB algorithm is not ideal enough to flow-control effect, bandwidth availability ratio is not reasonable.
To achieve these goals, the technical solution used in the present invention is as follows:
A kind of bandwidth fairness control method based on layering token bucket, comprises the following steps:
(1) HTB queue and queue bandwidth are initialized;
(2) packet is received by transceiver module;
(3) by application type and the IP address of identification module identification packet;
(4) set up into buffer queue according to the application type of packet, and packet is stored in correspondence enter buffer queue,
Perform (5) afterwards;
(5) set up out buffer queue according to the IP address that packet is corresponding, and packet is stored in correspondence go out buffer queue;
(6) check that currently going out buffer queue sends whether packet reaches quota restrictions value, if not up to, the most directly sent out
This is given to go out the packet in buffer queue, otherwise, then check that the next one goes out buffer queue transmission packet and is according to polling mode
The no quota restrictions value that reaches, and send packet not up to quota restrictions value the buffer queue that goes out all directly transmit packet;
(7) until all go out buffer queue send packet all reach quota restrictions value after, reset all go out buffer queue
Quota restrictions value, return (6).
Further, in described (3), the application type of identification module identification includes webpage, download and video three types.
Yet further, in described (6) each go out buffer queue sending after packet, to the quota going out buffer queue
Limits value is updated, and the quota restrictions value before i.e. this sends packet deducts this length sending packet.
Further, described (7) reset all go out buffer queue quota restrictions value, refer to go out to cache team by all
The quota restrictions value full recovery of row is the state value not sending any packet.
In order to realize above-mentioned bandwidth fairness control method, the invention provides a kind of bandwidth fairness based on HTB and control system
System, including
Initialization module: be used for initializing HTB queue and queue bandwidth;
Transceiver module: carry out packet transmission and receive operation;
Identification module: the application type and the IP address that carry out packet judge;
Control module: create into buffer queue according to the application type of packet, and carry out data bag enqueue operations;According to
Host IP address is created that buffer queue, check each IP address corresponding go out buffer queue, carry out data according to fairness mechanism
Bag dequeue operation, and update or reset each IP address corresponding go out buffer queue quota restrictions value.
Compared with prior art, the method have the advantages that
(1) present invention achieves the equilibrium use of bandwidth on application type, enters to cache team according to what application type was set up
Row, enter out buffer queue according to fairness mechanism, make each application type have the opportunity to use Internet resources, it is to avoid existing
HTB algorithm causes the problem that the application type that part priority is low cannot use Internet resources all the time because priority arranges;
(2) equilibrium that the present invention achieves bandwidth at different host aspects uses, slow according to going out of host IP address foundation
Deposit queue, use polling mode when sending packet, and carry out dequeue operation according to fairness mechanism, it is ensured that each main frame
Fair can use bandwidth, it is to avoid the part main frame that existing HTB algorithm causes cannot surf the Net all the time, cannot obtain or send data
Problem;
(3) present invention passes through, enters the setting of buffer queue, and the fairness mechanism that packet sends, and substantially increases
The utilization rate of bandwidth, decreases bandwidth waste.
Accompanying drawing explanation
Fig. 1 is the schematic flow sheet of the present invention.
Fig. 2 is the system block diagram of the present invention.
Detailed description of the invention
The invention will be further described with embodiment below in conjunction with the accompanying drawings, and embodiments of the present invention include but not limited to
The following example.
As depicted in figs. 1 and 2, bandwidth fairness control method based on HTB, its hardware uses initialization module, transmitting-receiving mould
Block, identification module and control module composition.Wherein, initialization module is mainly used in carrying out HTB queue and queue bandwidth initially
Changing, transceiver module is mainly used in receiving and sending packet, and identification module is then mainly with to the application type of packet and IP ground
Location judges, the subsequent operation for packet lays the first stone, and control module is then for setting up into buffer queue and going out slow
Deposit queue, and complete packet enter to go out operation, and complete renewal and the replacement of quota restrictions value.
Below by example, operation principle and the implementation process of the present invention are illustrated.
Embodiment 1
As a example by tri-main frames of A, B, C, its IP address corresponding respectively and the packet application type such as table one related to:
Host name |
IP address |
Application type |
A |
192.168.1.1 |
Online Video |
B |
192.168.1.2 |
A sudden peal of thunder is downloaded |
C |
192.168.1.3 |
Game on line |
Table one
Assume that bandwidth is limited to 800k byte per second, under existing HTB algorithm, the distribution of each main frame actual bandwidth and effect
As shown in Table 2:
Host name |
Actual bandwidth distributes |
Effect |
A |
40k byte per second |
Online Video cannot normally be watched |
B |
760k byte per second |
A sudden peal of thunder downloads complete occupied bandwidth |
C |
0k byte per second |
Game on line cannot be properly functioning |
Table two
Owing to the priority of HTB algorithm is arranged, game on line cannot obtain any data because priority is low, causes
Cannot be properly functioning, although and Online Video priority is higher, it is possible to obtain a part of data, be also because obtain data
Less and cannot normally watch.Only news thunder is downloaded and is occupied all bandwidth because priority is the highest, can normally use.
And under the bandwidth fairness control method of the present invention, the utilization process of its network data is as follows:
After HTB queue and queue bandwidth initialize, first transceiver module receives from the packet sending port, false
If the packet 1 that synchronization receives, packet 2 and packet 3, after identification module identification, its specifying information such as table
Three:
Packet |
Application type |
Length |
Corresponding IP address |
Packet 1 |
Online Video |
350k byte |
192.168.1.1 |
Packet 2 |
News thunder is downloaded |
450k byte |
192.168.1.2 |
Packet 3 |
Game on line |
30k byte |
192.168.1.3 |
Table three
Now, first look at and the most enter buffer queue about what Online Video, game on line Homeway.com thunder were downloaded, if
No, then set up and enter buffer queue accordingly, enter among buffer queue accordingly, i.e. if it has, then directly packet is stored in
Entering among buffer queue what packet 1 was stored in Online Video, what packet 2 was stored in game on line enters among buffer queue, number
According to bag 3 be stored in news thunder download enter among buffer queue.
When all packets be all stored in correspondence enter buffer queue after, check in table that three IP addresses are the most existing
Going out buffer queue, if it is not, set up out buffer queue, what packet 1 was stored in host A afterwards goes out among buffer queue,
What packet 2 was stored in host B goes out among buffer queue, and packet 3 is stored in going out among buffer queue of host C.
Assume host A, the current residual bandwidth share limits value of B, C is respectively 350 bytes, 500 bytes, 300 bytes, this
Time host A, B, C be polled operation.Whether first look at the current quota restrictions value of host A more than or equal to packet 1
Length, it is assumed that the current quota restrictions value being not yet transmitted across packet, i.e. host A before host A is still 350 bytes, and counts
Length according to bag 1 is also 350 bytes, equal to the current quota restrictions value of host A, therefore allows to send the whole of this packet 1
Data;Afterwards, that checks host B goes out whether buffer queue current quota restrictions value is more than or equal to the length of packet 2, now
Having sent data 200 byte before assuming host B, its current quota restrictions value is 500 byte-200 byte=300 bytes, due to
A length of 450 bytes of packet 2, more than the current quota restrictions value of host B, do not allow to send this packet 2, can only
Send after resetting Deng quota restrictions value next time;After having processed host B, then check that the current quota restrictions of host C are the biggest
In or equal to the length of packet 3, it is assumed that being the most not yet transmitted across any data before host C, its current quota restrictions value is still
300 bytes, and the length of packet 3 is also 300 bytes, therefore allows to send the total data of packet 3.So far, a next round
Asking end of operation, host A, B, C update current quota restrictions value, owing to now updating the current quota restrictions value of aft engine B are
300 bytes, and the current quota restrictions value of host A and C is 0, the most next time during poll, only send a data package size less than or
The data corresponding to host B equal to 300, until the current quota restrictions value of host B is that 0 or B no data bag can send,
Be default high quota limits value by the current quota restrictions value reset all of host A, B, C again, next time during poll then with
Quota restrictions value after replacement is as the criterion and processes.
After being controlled by above-mentioned bandwidth fairness, host A, the application program ruuning situation such as table four of B, C:
Host name |
Actual bandwidth distributes |
Effect |
A |
350k byte per second |
Online Video is normally watched |
B |
420k byte per second |
A sudden peal of thunder downloads complete occupied bandwidth |
C |
30k byte per second |
Game on line is properly functioning |
Table four
As can be seen here, after applying bandwidth fairness control method of the present invention, three main frames in net can be just
Often use bandwidth resources, it is achieved the normal work of each application program, therefore, bandwidth availability ratio is obviously improved, the present invention
Practical value and technology content find full expression, creative apparent.
Embodiment 2
The present embodiment is with the difference of embodiment 1, and in terms of setting, in the present embodiment, packet 1 and packet 2 should
Being Online Video by type, other are the most identical, and in this case, the present embodiment is adding bandwidth fairness control method, number
As follows according to transmitting procedure:
After identification module identification packet 1, packet 2 and the application type of packet 3 and corresponding IP address, first
Check whether to exist Online Video and have online enter buffer queue.Have, then packet 1 and packet 2 are stored in Online Video
Enter among buffer queue, packet 3 is stored in entering among buffer queue of game on line;Nothing, then set up and enter caching accordingly
After queue, then it is stored in packet to enter accordingly among buffer queue.Application type phase due to packet 1 and packet 2
With, be Online Video, therefore, these two packets be stored in same enter among buffer queue, two need not be divided into enter caching
Queue stores.
Hereafter transmission data procedures is same as in Example 1, first checks that three main frames have gone out buffer queue, has,
Then being stored in by packet according to IP address corresponding to packet goes out among buffer queue accordingly, nothing, then set up go out accordingly slow
After depositing queue, then row storage.Afterwards, check that host A, going out of B, C cache whether the corresponding data volume sent reaches quota
Limits value, if the transmission data volume of certain main frame has reached quota restrictions value, then to should the packet of main frame stop sending out
Send, only send the packet of other main frames corresponding, during until the transmission data volume of All hosts all reaches quota restrictions value, weight
Put the quota restrictions value of All hosts, make the transmission data volume of All hosts reset, will quota restrictions value be all set to
Maximum quota restrictions value.Re-start polling operation, the packet not sent before is sent, and send newly received
The packet arrived.
Update as the current quota restrictions value going out buffer queue, the statistical being gradually increased can be taked, it is also possible to
Take the statistical gradually decreased.The statistical that what is called is gradually increased, is that the initial quota pointing out buffer queue is set to
0, the most often send a secondary data, just plus the length of transmission data on the basis of initial quota, go out caching in this, as this
The current quota value of queue, when current quota value reaches the quota restrictions value set, this goes out buffer queue and stops sending data.
As: the quota restrictions value going out buffer queue of host A is 300 bytes, when sending for the first time data, host A go out to cache team
The initial quota value of row is 0, sends a length of 100 bytes of packet for the first time, and it is 150 bytes that second time sends packet,
If third time data packet length to be sent is 100 bytes, and now host A only allows to send the data of 50, therefore, then and third time
Packet to be sent does not allow to send, and can only send after quota restrictions value resets.The so-called statistical gradually decreased,
The statistical being then and be gradually increased is contrary, and the initial quota value of host A is this quota restrictions value 300 going out buffer queue
Byte, often sends a secondary data, just on the basis of initial quota value, deducts the length sending data, when current quota value is 0
Time, this goes out buffer queue and stops sending data.With three transmission data instances in the above-mentioned statistical being gradually increased, it is worked as
Front quota restrictions value renewal process is 300 byte-100 byte-150 byte=50 bytes, and last packet surpasses due to size
Cross the size allowing to send, can only send when poll next time, and only have when in quota restrictions value, remaining 50 bytes complete number
After sending, just carry out quota restrictions value replacement.
Use the present embodiment, equally ensure that different main frame, the program of different application type can use network, protect
Demonstrate,prove the normal work of each main frame, each application program.
As for the initialization module related in the present invention, transceiver module, identification module, control module, it is existing skill
Art, does not repeats them here.
Above-described embodiment is only a preferred embodiment of the present invention, is not defined protection scope of the present invention.
In the present invention, the kind of application type, quantity, the quantity of main frame, quota restrictions value setting going out buffer queue etc., the most permissible
Change flexibly, therefore, as long as using the simple transformation done by know-why of the present invention and other non-creativeness to change,
Within belonging to protection scope of the present invention.