Skip to content

Commit

Permalink
add CeThresholdSelector and CeThresholdMask
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Jan 4, 2025
1 parent 73ac984 commit 71a58c4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
35 changes: 26 additions & 9 deletions q_fqCodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
tcaFqCodelCeThreshold
tcaFqCodelDropBatchSize
tcaFqCodelMemoryLimit
tcaFqCodelCeThresholdSelector
tcaFqCodelCeThresholdMask
)

const (
Expand All @@ -26,15 +28,17 @@ const (

// 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
Target *uint32
Limit *uint32
Interval *uint32
ECN *uint32
Flows *uint32
Quantum *uint32
CEThreshold *uint32
DropBatchSize *uint32
MemoryLimit *uint32
CeThresholdSelector *uint8
CeThresholdMask *uint8
}

// marshalFqCodel returns the binary encoding of FqCodel
Expand Down Expand Up @@ -82,6 +86,15 @@ func marshalFqCodel(info *FqCodel) ([]byte, error) {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqCodelMemoryLimit, Data: uint32Value(info.MemoryLimit)})
}

if info.CeThresholdSelector != nil {
options = append(options, tcOption{Interpretation: vtUint8, Type: tcaFqCodelCeThresholdSelector, Data: uint8Value(info.CeThresholdSelector)})

}

if info.CeThresholdMask != nil {
options = append(options, tcOption{Interpretation: vtUint8, Type: tcaFqCodelCeThresholdMask, Data: uint8Value(info.CeThresholdMask)})
}

return marshalAttributes(options)
}

Expand Down Expand Up @@ -111,6 +124,10 @@ func unmarshalFqCodel(data []byte, info *FqCodel) error {
info.DropBatchSize = uint32Ptr(ad.Uint32())
case tcaFqCodelMemoryLimit:
info.MemoryLimit = uint32Ptr(ad.Uint32())
case tcaFqCodelCeThresholdSelector:
info.CeThresholdSelector = uint8Ptr(ad.Uint8())
case tcaFqCodelCeThresholdMask:
info.CeThresholdMask = uint8Ptr(ad.Uint8())
default:
return fmt.Errorf("unmarshalFqCodel()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
Expand Down
19 changes: 18 additions & 1 deletion q_fqCodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ func TestFqCodel(t *testing.T) {
err1 error
err2 error
}{
"simple": {val: FqCodel{Target: uint32Ptr(1), Limit: uint32Ptr(2), Interval: uint32Ptr(3), ECN: uint32Ptr(4), Flows: uint32Ptr(5), Quantum: uint32Ptr(6), CEThreshold: uint32Ptr(7), DropBatchSize: uint32Ptr(8), MemoryLimit: uint32Ptr(9)}},
"simple": {val: FqCodel{
Target: uint32Ptr(1),
Limit: uint32Ptr(2),
Interval: uint32Ptr(3),
ECN: uint32Ptr(4),
Flows: uint32Ptr(5),
Quantum: uint32Ptr(6),
CEThreshold: uint32Ptr(7),
DropBatchSize: uint32Ptr(8),
MemoryLimit: uint32Ptr(9),
CeThresholdSelector: uint8Ptr(10),
CeThresholdMask: uint8Ptr(11)}},
}

for name, testcase := range tests {
Expand Down Expand Up @@ -45,4 +56,10 @@ func TestFqCodel(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("nil", func(t *testing.T) {
err := unmarshalFqCodel([]byte{0x0}, nil)
if err == nil {
t.Fatalf("expected error but got none")
}
})
}

0 comments on commit 71a58c4

Please sign in to comment.