]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_cbq.c
2 * tc_cbq.c CBQ maintenance routines.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
27 unsigned int tc_cbq_calc_maxidle(unsigned int bndw
, unsigned int rate
, unsigned int avpkt
,
28 int ewma_log
, unsigned int maxburst
)
31 double g
= 1.0 - 1.0/(1<<ewma_log
);
32 double xmt
= (double)avpkt
/bndw
;
35 if (bndw
!= rate
&& maxburst
) {
36 double vxmt
= (double)avpkt
/rate
- xmt
;
38 vxmt
*= (pow(g
, -(double)maxburst
) - 1);
42 return tc_core_time2tick(maxidle
*(1<<ewma_log
)*TIME_UNITS_PER_SEC
);
45 unsigned int tc_cbq_calc_offtime(unsigned int bndw
, unsigned int rate
, unsigned int avpkt
,
46 int ewma_log
, unsigned int minburst
)
48 double g
= 1.0 - 1.0/(1<<ewma_log
);
49 double offtime
= (double)avpkt
/rate
- (double)avpkt
/bndw
;
54 offtime
*= pow(g
, -(double)minburst
) - 1;
56 offtime
*= 1 + (pow(g
, -(double)(minburst
-1)) - 1)/(1-g
);
57 return tc_core_time2tick(offtime
*TIME_UNITS_PER_SEC
);