github.com/cilium/cilium@v1.16.2/pkg/maps/bwmap/cell.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package bwmap 5 6 import ( 7 "github.com/cilium/hive/cell" 8 "github.com/cilium/statedb" 9 "github.com/cilium/statedb/reconciler" 10 11 "github.com/cilium/cilium/pkg/bpf" 12 "github.com/cilium/cilium/pkg/datapath/types" 13 ) 14 15 // Cell manages the cilium_throttle BPF map for implementing per-endpoint 16 // bandwidth management. The cell provides RWTable[Edt] to which per 17 // endpoint bandwidth limits can be inserted. Use [NewEdt] to create the 18 // object. The table can be inspected with "cilium-dbg statedb bandwidth-edts". 19 // A reconciler is registered that reconciles the table with the cilium_throttle 20 // map. 21 var Cell = cell.Module( 22 "bwmap", 23 "Manages the endpoint bandwidth limit BPF map", 24 25 cell.Provide( 26 NewEdtTable, 27 statedb.RWTable[Edt].ToTable, 28 newThrottleMap, 29 ), 30 cell.Invoke( 31 statedb.RegisterTable[Edt], 32 registerReconciler, 33 bpf.RegisterTablePressureMetricsJob[Edt, throttleMap], 34 ), 35 ) 36 37 func registerReconciler(cfg types.BandwidthConfig, m throttleMap, edts statedb.RWTable[Edt], params reconciler.Params) error { 38 if cfg.EnableBandwidthManager { 39 ops := bpf.NewMapOps[Edt](m.Map) 40 _, err := reconciler.Register( 41 params, 42 edts, 43 func(e Edt) Edt { return e }, 44 func(e Edt, s reconciler.Status) Edt { 45 e.Status = s 46 return e 47 }, 48 func(e Edt) reconciler.Status { 49 return e.Status 50 }, 51 ops, 52 nil, 53 ) 54 return err 55 } 56 return nil 57 }