github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/pkg/host/internal/lib/dputils/dputils.go (about) 1 package dputils 2 3 import ( 4 dputils "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils" 5 ) 6 7 func New() DPUtilsLib { 8 return &libWrapper{} 9 } 10 11 //go:generate ../../../../../bin/mockgen -destination mock/mock_dputils.go -source dputils.go 12 type DPUtilsLib interface { 13 // GetNetNames returns host net interface names as string for a PCI device from its pci address 14 GetNetNames(pciAddr string) ([]string, error) 15 // GetDriverName returns current driver attached to a pci device from its pci address 16 GetDriverName(pciAddr string) (string, error) 17 // GetVFID returns VF ID index (within specific PF) based on PCI address 18 GetVFID(pciAddr string) (vfID int, err error) 19 // IsSriovVF check if a pci device has link to a PF 20 IsSriovVF(pciAddr string) bool 21 // IsSriovPF check if a pci device SRIOV capable given its pci address 22 IsSriovPF(pciAddr string) bool 23 // GetSriovVFcapacity returns SRIOV VF capacity 24 GetSriovVFcapacity(pf string) int 25 // GetVFconfigured returns number of VF configured for a PF 26 GetVFconfigured(pf string) int 27 // SriovConfigured returns true if sriov_numvfs reads > 0 else false 28 SriovConfigured(addr string) bool 29 // GetVFList returns a List containing PCI addr for all VF discovered in a given PF 30 GetVFList(pf string) (vfList []string, err error) 31 } 32 33 type libWrapper struct{} 34 35 // GetNetNames returns host net interface names as string for a PCI device from its pci address 36 func (w *libWrapper) GetNetNames(pciAddr string) ([]string, error) { 37 return dputils.GetNetNames(pciAddr) 38 } 39 40 // GetDriverName returns current driver attached to a pci device from its pci address 41 func (w *libWrapper) GetDriverName(pciAddr string) (string, error) { 42 return dputils.GetDriverName(pciAddr) 43 } 44 45 // GetVFID returns VF ID index (within specific PF) based on PCI address 46 func (w *libWrapper) GetVFID(pciAddr string) (vfID int, err error) { 47 return dputils.GetVFID(pciAddr) 48 } 49 50 // IsSriovVF check if a pci device has link to a PF 51 func (w *libWrapper) IsSriovVF(pciAddr string) bool { 52 return dputils.IsSriovVF(pciAddr) 53 } 54 55 // IsSriovPF check if a pci device SRIOV capable given its pci address 56 func (w *libWrapper) IsSriovPF(pciAddr string) bool { 57 return dputils.IsSriovPF(pciAddr) 58 } 59 60 // GetSriovVFcapacity returns SRIOV VF capacity 61 func (w *libWrapper) GetSriovVFcapacity(pf string) int { 62 return dputils.GetSriovVFcapacity(pf) 63 } 64 65 // GetVFconfigured returns number of VF configured for a PF 66 func (w *libWrapper) GetVFconfigured(pf string) int { 67 return dputils.GetVFconfigured(pf) 68 } 69 70 // SriovConfigured returns true if sriov_numvfs reads > 0 else false 71 func (w *libWrapper) SriovConfigured(addr string) bool { 72 return dputils.SriovConfigured(addr) 73 } 74 75 // GetVFList returns a List containing PCI addr for all VF discovered in a given PF 76 func (w *libWrapper) GetVFList(pf string) (vfList []string, err error) { 77 return dputils.GetVFList(pf) 78 }