-
Notifications
You must be signed in to change notification settings - Fork 46
/
q_fqCodel.go
119 lines (101 loc) · 3.25 KB
/
q_fqCodel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package tc
import (
"fmt"
"github.com/mdlayher/netlink"
)
const (
tcaFqCodelUnspec = iota
tcaFqCodelTarget
tcaFqCodelLimit
tcaFqCodelInterval
tcaFqCodelEcn
tcaFqCodelFlows
tcaFqCodelQuantum
tcaFqCodelCeThreshold
tcaFqCodelDropBatchSize
tcaFqCodelMemoryLimit
)
const (
tcaFqCodelXStatsQdisc = iota
tcaFqCodelXStatsClass
)
// FqCodel contains attributes of the fq_codel discipline
type FqCodel struct {
Target *uint32
Limit *uint32
Interval *uint32
ECN *uint32
Flows *uint32
Quantum *uint32
CEThreshold *uint32
DropBatchSize *uint32
MemoryLimit *uint32
}
// marshalFqCodel returns the binary encoding of FqCodel
func marshalFqCodel(info *FqCodel) ([]byte, error) {
options := []tcOption{}
if info == nil {
return []byte{}, fmt.Errorf("FqCodel: %w", ErrNoArg)
}
// TODO: improve logic and check combinations
if info.Target != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelTarget, Data: uint32Value(info.Target)})
}
if info.Limit != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelLimit, Data: uint32Value(info.Limit)})
}
if info.Interval != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelInterval, Data: uint32Value(info.Interval)})
}
if info.ECN != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelEcn, Data: uint32Value(info.ECN)})
}
if info.Flows != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelFlows, Data: uint32Value(info.Flows)})
}
if info.Quantum != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelQuantum, Data: uint32Value(info.Quantum)})
}
if info.CEThreshold != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelCeThreshold, Data: uint32Value(info.CEThreshold)})
}
if info.DropBatchSize != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelDropBatchSize, Data: uint32Value(info.DropBatchSize)})
}
if info.MemoryLimit != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelMemoryLimit, Data: uint32Value(info.MemoryLimit)})
}
return marshalAttributes(options)
}
// unmarshalFqCodel parses the FqCodel-encoded data and stores the result in the value pointed to by info.
func unmarshalFqCodel(data []byte, info *FqCodel) error {
ad, err := netlink.NewAttributeDecoder(data)
if err != nil {
return err
}
for ad.Next() {
switch ad.Type() {
case tcaFqCodelTarget:
info.Target = uint32Ptr(ad.Uint32())
case tcaFqCodelLimit:
info.Limit = uint32Ptr(ad.Uint32())
case tcaFqCodelInterval:
info.Interval = uint32Ptr(ad.Uint32())
case tcaFqCodelEcn:
info.ECN = uint32Ptr(ad.Uint32())
case tcaFqCodelFlows:
info.Flows = uint32Ptr(ad.Uint32())
case tcaFqCodelQuantum:
info.Quantum = uint32Ptr(ad.Uint32())
case tcaFqCodelCeThreshold:
info.CEThreshold = uint32Ptr(ad.Uint32())
case tcaFqCodelDropBatchSize:
info.DropBatchSize = uint32Ptr(ad.Uint32())
case tcaFqCodelMemoryLimit:
info.MemoryLimit = uint32Ptr(ad.Uint32())
default:
return fmt.Errorf("unmarshalFqCodel()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
}
return ad.Err()
}