Skip to content

Commit

Permalink
extend q_pie
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <dev@der-flo.net>
  • Loading branch information
florianl committed Dec 28, 2024
1 parent 72197c3 commit e564dcb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 14 additions & 7 deletions q_pie.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const (
tcaPieBeta
tcaPieECN
tcaPieBytemode
tcaPieDqRateEstimator
)

// Pie contains attributes of the pie discipline
type Pie struct {
Target *uint32
Limit *uint32
TUpdate *uint32
Alpha *uint32
Beta *uint32
ECN *uint32
Bytemode *uint32
Target *uint32
Limit *uint32
TUpdate *uint32
Alpha *uint32
Beta *uint32
ECN *uint32
Bytemode *uint32
DqRateEstimator *uint32
}

// unmarshalPie parses the Pie-encoded data and stores the result in the value pointed to by info.
Expand All @@ -50,6 +52,8 @@ func unmarshalPie(data []byte, info *Pie) error {
info.ECN = uint32Ptr(ad.Uint32())
case tcaPieBytemode:
info.Bytemode = uint32Ptr(ad.Uint32())
case tcaPieDqRateEstimator:
info.DqRateEstimator = uint32Ptr(ad.Uint32())
default:
return fmt.Errorf("extractPieOptions()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
Expand Down Expand Up @@ -87,5 +91,8 @@ func marshalPie(info *Pie) ([]byte, error) {
if info.Bytemode != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaPieBytemode, Data: uint32Value(info.Bytemode)})
}
if info.DqRateEstimator != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaPieDqRateEstimator, Data: uint32Value(info.DqRateEstimator)})
}
return marshalAttributes(options)
}
15 changes: 14 additions & 1 deletion q_pie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ func TestPie(t *testing.T) {
err1 error
err2 error
}{
"simple": {val: Pie{Target: uint32Ptr(1), Limit: uint32Ptr(2), TUpdate: uint32Ptr(3), Alpha: uint32Ptr(4), Beta: uint32Ptr(5), ECN: uint32Ptr(6), Bytemode: uint32Ptr(7)}},
"simple": {val: Pie{
Target: uint32Ptr(1),
Limit: uint32Ptr(2),
TUpdate: uint32Ptr(3),
Alpha: uint32Ptr(4),
Beta: uint32Ptr(5),
ECN: uint32Ptr(6),
Bytemode: uint32Ptr(7),
DqRateEstimator: uint32Ptr(8)}},
}

for name, testcase := range tests {
Expand Down Expand Up @@ -45,4 +53,9 @@ func TestPie(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("unmarshal(nil)", func(t *testing.T) {
if err := unmarshalPie([]byte{0x0}, nil); err == nil {
t.Fatal("expectec error but got none")
}
})
}

0 comments on commit e564dcb

Please sign in to comment.