1 package netlink
2
3 import (
4 "fmt"
5 )
6
7
8 type Class interface {
9 Attrs() *ClassAttrs
10 Type() string
11 }
12
13
14
15
16
17
18 type GnetStatsBasic struct {
19 Bytes uint64
20 Packets uint32
21 }
22
23
24 type GnetStatsRateEst struct {
25 Bps uint32
26 Pps uint32
27 }
28
29
30 type GnetStatsRateEst64 struct {
31 Bps uint64
32 Pps uint64
33 }
34
35
36 type GnetStatsQueue struct {
37 Qlen uint32
38 Backlog uint32
39 Drops uint32
40 Requeues uint32
41 Overlimits uint32
42 }
43
44
45
46 type ClassStatistics struct {
47 Basic *GnetStatsBasic
48 Queue *GnetStatsQueue
49 RateEst *GnetStatsRateEst
50 BasicHw *GnetStatsBasic
51 }
52
53
54 func NewClassStatistics() *ClassStatistics {
55 return &ClassStatistics{
56 Basic: &GnetStatsBasic{},
57 Queue: &GnetStatsQueue{},
58 RateEst: &GnetStatsRateEst{},
59 BasicHw: &GnetStatsBasic{},
60 }
61 }
62
63
64
65
66 type ClassAttrs struct {
67 LinkIndex int
68 Handle uint32
69 Parent uint32
70 Leaf uint32
71 Statistics *ClassStatistics
72 }
73
74 func (q ClassAttrs) String() string {
75 return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Leaf: %d}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Leaf)
76 }
77
78
79 type HtbClassAttrs struct {
80
81 Rate uint64
82 Ceil uint64
83 Buffer uint32
84 Cbuffer uint32
85 Quantum uint32
86 Level uint32
87 Prio uint32
88 }
89
90 func (q HtbClassAttrs) String() string {
91 return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
92 }
93
94
95 type HtbClass struct {
96 ClassAttrs
97 Rate uint64
98 Ceil uint64
99 Buffer uint32
100 Cbuffer uint32
101 Quantum uint32
102 Level uint32
103 Prio uint32
104 }
105
106 func (q HtbClass) String() string {
107 return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
108 }
109
110
111 func (q *HtbClass) Attrs() *ClassAttrs {
112 return &q.ClassAttrs
113 }
114
115
116 func (q *HtbClass) Type() string {
117 return "htb"
118 }
119
120
121
122 type GenericClass struct {
123 ClassAttrs
124 ClassType string
125 }
126
127
128 func (class *GenericClass) Attrs() *ClassAttrs {
129 return &class.ClassAttrs
130 }
131
132
133 func (class *GenericClass) Type() string {
134 return class.ClassType
135 }
136
137
138
139
140
141 type ServiceCurve struct {
142 m1 uint32
143 d uint32
144 m2 uint32
145 }
146
147
148 func (c *ServiceCurve) Attrs() (uint32, uint32, uint32) {
149 return c.m1, c.d, c.m2
150 }
151
152
153 func (c *ServiceCurve) Burst() uint32 {
154 return c.m1
155 }
156
157
158 func (c *ServiceCurve) Delay() uint32 {
159 return c.d
160 }
161
162
163 func (c *ServiceCurve) Rate() uint32 {
164 return c.m2
165 }
166
167
168 type HfscClass struct {
169 ClassAttrs
170 Rsc ServiceCurve
171 Fsc ServiceCurve
172 Usc ServiceCurve
173 }
174
175
176
177 func (hfsc *HfscClass) SetUsc(m1 uint32, d uint32, m2 uint32) {
178 hfsc.Usc = ServiceCurve{m1: m1, d: d, m2: m2}
179 }
180
181
182
183 func (hfsc *HfscClass) SetFsc(m1 uint32, d uint32, m2 uint32) {
184 hfsc.Fsc = ServiceCurve{m1: m1, d: d, m2: m2}
185 }
186
187
188
189 func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32) {
190 hfsc.Rsc = ServiceCurve{m1: m1, d: d, m2: m2}
191 }
192
193
194
195
196 func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32) {
197 hfsc.SetRsc(m1, d, m2)
198 hfsc.SetFsc(m1, d, m2)
199 }
200
201
202
203
204 func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32) {
205 hfsc.SetUsc(m1, d, m2)
206 }
207
208
209
210
211 func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32) {
212 hfsc.SetFsc(m1, d, m2)
213 }
214
215
216 func NewHfscClass(attrs ClassAttrs) *HfscClass {
217 return &HfscClass{
218 ClassAttrs: attrs,
219 Rsc: ServiceCurve{},
220 Fsc: ServiceCurve{},
221 Usc: ServiceCurve{},
222 }
223 }
224
225
226 func (hfsc *HfscClass) String() string {
227 return fmt.Sprintf(
228 "{%s -- {RSC: {m1=%d d=%d m2=%d}} {FSC: {m1=%d d=%d m2=%d}} {USC: {m1=%d d=%d m2=%d}}}",
229 hfsc.Attrs(), hfsc.Rsc.m1*8, hfsc.Rsc.d, hfsc.Rsc.m2*8, hfsc.Fsc.m1*8, hfsc.Fsc.d, hfsc.Fsc.m2*8, hfsc.Usc.m1*8, hfsc.Usc.d, hfsc.Usc.m2*8,
230 )
231 }
232
233
234 func (hfsc *HfscClass) Attrs() *ClassAttrs {
235 return &hfsc.ClassAttrs
236 }
237
238
239 func (hfsc *HfscClass) Type() string {
240 return "hfsc"
241 }
242
View as plain text