From e564dcb65e0ec8da61f208890dda5a2c7caa1586 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Sat, 28 Dec 2024 11:02:48 +0100 Subject: [PATCH] extend q_pie Signed-off-by: Florian Lehner --- q_pie.go | 21 ++++++++++++++------- q_pie_test.go | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/q_pie.go b/q_pie.go index c74170a..6c5bf99 100644 --- a/q_pie.go +++ b/q_pie.go @@ -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. @@ -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()) } @@ -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) } diff --git a/q_pie_test.go b/q_pie_test.go index 5f64b80..385f383 100644 --- a/q_pie_test.go +++ b/q_pie_test.go @@ -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 { @@ -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") + } + }) }