Skip to content

Commit ad6299b

Browse files
committedDec 28, 2024
extend q_pie
Signed-off-by: Florian Lehner <dev@der-flo.net>
1 parent f01d77d commit ad6299b

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed
 

‎q_pie.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ const (
1515
tcaPieBeta
1616
tcaPieECN
1717
tcaPieBytemode
18+
tcaPieDqRateEstimator
1819
)
1920

2021
// Pie contains attributes of the pie discipline
2122
type Pie struct {
22-
Target *uint32
23-
Limit *uint32
24-
TUpdate *uint32
25-
Alpha *uint32
26-
Beta *uint32
27-
ECN *uint32
28-
Bytemode *uint32
23+
Target *uint32
24+
Limit *uint32
25+
TUpdate *uint32
26+
Alpha *uint32
27+
Beta *uint32
28+
ECN *uint32
29+
Bytemode *uint32
30+
DqRateEstimator *uint32
2931
}
3032

3133
// unmarshalPie parses the Pie-encoded data and stores the result in the value pointed to by info.
@@ -50,6 +52,8 @@ func unmarshalPie(data []byte, info *Pie) error {
5052
info.ECN = uint32Ptr(ad.Uint32())
5153
case tcaPieBytemode:
5254
info.Bytemode = uint32Ptr(ad.Uint32())
55+
case tcaPieDqRateEstimator:
56+
info.DqRateEstimator = uint32Ptr(ad.Uint32())
5357
default:
5458
return fmt.Errorf("extractPieOptions()\t%d\n\t%v", ad.Type(), ad.Bytes())
5559
}
@@ -87,5 +91,8 @@ func marshalPie(info *Pie) ([]byte, error) {
8791
if info.Bytemode != nil {
8892
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaPieBytemode, Data: uint32Value(info.Bytemode)})
8993
}
94+
if info.DqRateEstimator != nil {
95+
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaPieDqRateEstimator, Data: uint32Value(info.DqRateEstimator)})
96+
}
9097
return marshalAttributes(options)
9198
}

‎q_pie_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ func TestPie(t *testing.T) {
1313
err1 error
1414
err2 error
1515
}{
16-
"simple": {val: Pie{Target: uint32Ptr(1), Limit: uint32Ptr(2), TUpdate: uint32Ptr(3), Alpha: uint32Ptr(4), Beta: uint32Ptr(5), ECN: uint32Ptr(6), Bytemode: uint32Ptr(7)}},
16+
"simple": {val: Pie{
17+
Target: uint32Ptr(1),
18+
Limit: uint32Ptr(2),
19+
TUpdate: uint32Ptr(3),
20+
Alpha: uint32Ptr(4),
21+
Beta: uint32Ptr(5),
22+
ECN: uint32Ptr(6),
23+
Bytemode: uint32Ptr(7),
24+
DqRateEstimator: uint32Ptr(8)}},
1725
}
1826

1927
for name, testcase := range tests {
@@ -45,4 +53,9 @@ func TestPie(t *testing.T) {
4553
t.Fatalf("unexpected error: %v", err)
4654
}
4755
})
56+
t.Run("unmarshal(nil)", func(t *testing.T) {
57+
if err := unmarshalPie([]byte{0x0}, nil); err == nil {
58+
t.Fatal("expectec error but got none")
59+
}
60+
})
4861
}

0 commit comments

Comments
 (0)