| 1 |
# |
| 2 |
# Copyright (c) 2011 Thomas Graf <[email protected]> |
| 3 |
# |
| 4 |
|
| 5 |
"""HTB qdisc |
| 6 |
|
| 7 |
""" |
| 8 |
|
| 9 |
from __future__ import absolute_import |
| 10 |
|
| 11 |
from ... import core as netlink |
| 12 |
from ... import util as util |
| 13 |
from .. import capi as capi |
| 14 |
from .. import tc as tc |
| 15 |
|
| 16 |
|
| 17 |
class HTBQdisc(object): |
| 18 |
def __init__(self, qdisc): |
| 19 |
self._qdisc = qdisc |
| 20 |
|
| 21 |
@property |
| 22 |
@netlink.nlattr(type=int) |
| 23 |
def default_class(self): |
| 24 |
return tc.Handle(capi.rtnl_htb_get_defcls(self._qdisc._rtnl_qdisc)) |
| 25 |
|
| 26 |
@default_class.setter |
| 27 |
def default_class(self, value): |
| 28 |
capi.rtnl_htb_set_defcls(self._qdisc._rtnl_qdisc, int(value)) |
| 29 |
|
| 30 |
@property |
| 31 |
@netlink.nlattr(type=int) |
| 32 |
def r2q(self): |
| 33 |
return capi.rtnl_htb_get_rate2quantum(self._qdisc._rtnl_qdisc) |
| 34 |
|
| 35 |
@r2q.setter |
| 36 |
def r2q(self, value): |
| 37 |
capi.rtnl_htb_get_rate2quantum(self._qdisc._rtnl_qdisc, int(value)) |
| 38 |
|
| 39 |
def brief(self): |
| 40 |
fmt = util.MyFormatter(self) |
| 41 |
|
| 42 |
ret = " {s|default-class!k} {a|default_class}" |
| 43 |
|
| 44 |
if self.r2q: |
| 45 |
ret += " {s|r2q!k} {a|r2q}" |
| 46 |
|
| 47 |
return fmt.format(ret) |
| 48 |
|
| 49 |
|
| 50 |
class HTBClass(object): |
| 51 |
def __init__(self, cl): |
| 52 |
self._class = cl |
| 53 |
|
| 54 |
@property |
| 55 |
@netlink.nlattr(type=str) |
| 56 |
def rate(self): |
| 57 |
rate = capi.rtnl_htb_get_rate(self._class._rtnl_class) |
| 58 |
return util.Rate(rate) |
| 59 |
|
| 60 |
@rate.setter |
| 61 |
def rate(self, value): |
| 62 |
capi.rtnl_htb_set_rate(self._class._rtnl_class, int(value)) |
| 63 |
|
| 64 |
@property |
| 65 |
@netlink.nlattr(type=str) |
| 66 |
def ceil(self): |
| 67 |
ceil = capi.rtnl_htb_get_ceil(self._class._rtnl_class) |
| 68 |
return util.Rate(ceil) |
| 69 |
|
| 70 |
@ceil.setter |
| 71 |
def ceil(self, value): |
| 72 |
capi.rtnl_htb_set_ceil(self._class._rtnl_class, int(value)) |
| 73 |
|
| 74 |
@property |
| 75 |
@netlink.nlattr(type=str) |
| 76 |
def burst(self): |
| 77 |
burst = capi.rtnl_htb_get_rbuffer(self._class._rtnl_class) |
| 78 |
return util.Size(burst) |
| 79 |
|
| 80 |
@burst.setter |
| 81 |
def burst(self, value): |
| 82 |
capi.rtnl_htb_set_rbuffer(self._class._rtnl_class, int(value)) |
| 83 |
|
| 84 |
@property |
| 85 |
@netlink.nlattr(type=str) |
| 86 |
def ceil_burst(self): |
| 87 |
burst = capi.rtnl_htb_get_cbuffer(self._class._rtnl_class) |
| 88 |
return util.Size(burst) |
| 89 |
|
| 90 |
@ceil_burst.setter |
| 91 |
def ceil_burst(self, value): |
| 92 |
capi.rtnl_htb_set_cbuffer(self._class._rtnl_class, int(value)) |
| 93 |
|
| 94 |
@property |
| 95 |
@netlink.nlattr(type=int) |
| 96 |
def prio(self): |
| 97 |
return capi.rtnl_htb_get_prio(self._class._rtnl_class) |
| 98 |
|
| 99 |
@prio.setter |
| 100 |
def prio(self, value): |
| 101 |
capi.rtnl_htb_set_prio(self._class._rtnl_class, int(value)) |
| 102 |
|
| 103 |
@property |
| 104 |
@netlink.nlattr(type=int) |
| 105 |
def quantum(self): |
| 106 |
return capi.rtnl_htb_get_quantum(self._class._rtnl_class) |
| 107 |
|
| 108 |
@quantum.setter |
| 109 |
def quantum(self, value): |
| 110 |
capi.rtnl_htb_set_quantum(self._class._rtnl_class, int(value)) |
| 111 |
|
| 112 |
@property |
| 113 |
@netlink.nlattr(type=int) |
| 114 |
def level(self): |
| 115 |
return capi.rtnl_htb_get_level(self._class._rtnl_class) |
| 116 |
|
| 117 |
@level.setter |
| 118 |
def level(self, value): |
| 119 |
capi.rtnl_htb_set_level(self._class._rtnl_class, int(value)) |
| 120 |
|
| 121 |
def brief(self): |
| 122 |
fmt = util.MyFormatter(self) |
| 123 |
|
| 124 |
ret = " {t|prio} {t|rate}" |
| 125 |
|
| 126 |
if self.rate != self.ceil: |
| 127 |
ret += " {s|borrow-up-to!k} {a|ceil}" |
| 128 |
|
| 129 |
ret += " {t|burst}" |
| 130 |
|
| 131 |
return fmt.format(ret) |
| 132 |
|
| 133 |
def details(self): |
| 134 |
fmt = util.MyFormatter(self) |
| 135 |
|
| 136 |
return fmt.nl("\t{t|level} {t|quantum}") |
| 137 |
|
| 138 |
|
| 139 |
def init_qdisc(qdisc): |
| 140 |
qdisc.htb = HTBQdisc(qdisc) |
| 141 |
return qdisc.htb |
| 142 |
|
| 143 |
|
| 144 |
def init_class(cl): |
| 145 |
cl.htb = HTBClass(cl) |
| 146 |
return cl.htb |
| 147 |
|
| 148 |
|
| 149 |
# extern void rtnl_htb_set_quantum(struct rtnl_class *, uint32_t quantum); |