github.com/cilium/cilium@v1.16.2/pkg/datapath/tables/bandwidth_qdisc.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package tables
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/cilium/statedb"
    10  	"github.com/cilium/statedb/index"
    11  	"github.com/cilium/statedb/reconciler"
    12  
    13  	"github.com/cilium/cilium/pkg/time"
    14  )
    15  
    16  // BandwidthQDisc defines the desired state for a qdisc. Used by Bandwidth Manager
    17  // to setup the correct queueing disciplines on the native devices to enforce
    18  // bandwidth limits.
    19  type BandwidthQDisc struct {
    20  	LinkIndex int               // Interface index
    21  	LinkName  string            // Interface name (purely informative)
    22  	FqHorizon time.Duration     // Maximum allowed departure time
    23  	FqBuckets uint32            // Hash table size for flow lookup (2^FqBuckets)
    24  	Status    reconciler.Status // Reconciliation status
    25  }
    26  
    27  func (dq *BandwidthQDisc) TableHeader() []string {
    28  	return []string{
    29  		"LinkIndex",
    30  		"LinkName",
    31  		"FqHorizon",
    32  		"FqBuckets",
    33  		"Status",
    34  	}
    35  }
    36  
    37  func (dq *BandwidthQDisc) TableRow() []string {
    38  	return []string{
    39  		fmt.Sprintf("%d", dq.LinkIndex),
    40  		dq.LinkName,
    41  		fmt.Sprintf("%d", dq.FqHorizon),
    42  		fmt.Sprintf("%d", dq.FqBuckets),
    43  		dq.Status.String(),
    44  	}
    45  }
    46  
    47  func (dq *BandwidthQDisc) GetStatus() reconciler.Status {
    48  	return dq.Status
    49  }
    50  
    51  func (dq *BandwidthQDisc) SetStatus(s reconciler.Status) *BandwidthQDisc {
    52  	dq.Status = s
    53  	return dq
    54  }
    55  
    56  func (dq *BandwidthQDisc) Clone() *BandwidthQDisc {
    57  	dq2 := *dq
    58  	return &dq2
    59  }
    60  
    61  var (
    62  	BandwidthQDiscIndex = statedb.Index[*BandwidthQDisc, int]{
    63  		Name: "id",
    64  		FromObject: func(obj *BandwidthQDisc) index.KeySet {
    65  			return index.NewKeySet(index.Int(obj.LinkIndex))
    66  		},
    67  		FromKey: index.Int,
    68  		Unique:  true,
    69  	}
    70  
    71  	BandwidthQDiscTableName = "bandwidth-qdiscs"
    72  )
    73  
    74  func NewBandwidthQDiscTable(db *statedb.DB) (statedb.RWTable[*BandwidthQDisc], error) {
    75  	tbl, err := statedb.NewTable(
    76  		BandwidthQDiscTableName,
    77  		BandwidthQDiscIndex,
    78  	)
    79  	if err == nil {
    80  		err = db.RegisterTable(tbl)
    81  	}
    82  	return tbl, err
    83  }