diff --git a/q_fqCodel.go b/q_fqCodel.go index aef311b..7fbdf5d 100644 --- a/q_fqCodel.go +++ b/q_fqCodel.go @@ -17,6 +17,8 @@ const ( tcaFqCodelCeThreshold tcaFqCodelDropBatchSize tcaFqCodelMemoryLimit + tcaFqCodelCeThresholdSelector + tcaFqCodelCeThresholdMask ) const ( @@ -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 @@ -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) } @@ -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()) } diff --git a/q_fqCodel_test.go b/q_fqCodel_test.go index 04debcb..dd4dbfc 100644 --- a/q_fqCodel_test.go +++ b/q_fqCodel_test.go @@ -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 { @@ -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") + } + }) }