Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend q_pie #194

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
})
}
Loading