Skip to content

Commit

Permalink
add OffloadHorizon
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Jan 2, 2025
1 parent ff2cd3c commit 73ac984
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 10 additions & 6 deletions q_fq.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
tcaFqHorizonDrop
tcaFqPrioMap
tcaFqWeights
tcaFqOffloadHorizon
)

// FqPrioQopt according to tc_prio_qopt in /include/uapi/linux/pkt_sched.h
Expand Down Expand Up @@ -54,6 +55,7 @@ type Fq struct {
HorizonDrop *uint8
PrioMap *FqPrioQopt
Weights *[]int32
OffloadHorizon *uint32
}

// unmarshalFq parses the Fq-encoded data and stores the result in the value pointed to by info.
Expand All @@ -62,7 +64,6 @@ func unmarshalFq(data []byte, info *Fq) error {
if err != nil {
return err
}
var multiError error
for ad.Next() {
switch ad.Type() {
case tcaFqPLimit:
Expand Down Expand Up @@ -97,21 +98,21 @@ func unmarshalFq(data []byte, info *Fq) error {
info.HorizonDrop = uint8Ptr(ad.Uint8())
case tcaFqPrioMap:
priomap := &FqPrioQopt{}
err := unmarshalStruct(ad.Bytes(), priomap)
multiError = concatError(multiError, err)
err = unmarshalStruct(ad.Bytes(), priomap)
info.PrioMap = priomap
case tcaFqWeights:
size := len(ad.Bytes()) / 4
weights := make([]int32, size)
reader := bytes.NewReader(ad.Bytes())
err := binary.Read(reader, nativeEndian, weights)
multiError = concatError(multiError, err)
err = binary.Read(reader, nativeEndian, weights)
info.Weights = &weights
case tcaFqOffloadHorizon:
info.OffloadHorizon = uint32Ptr(ad.Uint32())
default:
return fmt.Errorf("unmarshalFq()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
}
return concatError(multiError, ad.Err())
return concatError(err, ad.Err())
}

// marshalFq returns the binary encoding of Fq
Expand Down Expand Up @@ -180,6 +181,9 @@ func marshalFq(info *Fq) ([]byte, error) {
multiError = concatError(multiError, err)
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaFqWeights, Data: buf.Bytes()})
}
if info.OffloadHorizon != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqOffloadHorizon, Data: uint32Value(info.OffloadHorizon)})
}

if multiError != nil {
return []byte{}, multiError
Expand Down
9 changes: 8 additions & 1 deletion q_fq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func TestFq(t *testing.T) {
Bands: 3,
PrioMap: [16]uint8{1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
},
Weights: &weights,
Weights: &weights,
OffloadHorizon: uint32Ptr(73),
},
},
}
Expand Down Expand Up @@ -84,4 +85,10 @@ func TestFq(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("unmarshalFq(0x0)", func(t *testing.T) {
err := unmarshalFq([]byte{0x0}, nil)
if err == nil {
t.Fatalf("expected error but got none")
}
})
}

0 comments on commit 73ac984

Please sign in to comment.