/
pciNetDevice.go
142 lines (120 loc) · 3.3 KB
/
pciNetDevice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package resources
import (
"github.com/intel/sriov-network-device-plugin/pkg/types"
"github.com/intel/sriov-network-device-plugin/pkg/utils"
"github.com/jaypipes/ghw"
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
)
type pciNetDevice struct {
pciDevice *ghw.PCIDevice
ifName string
pfName string
pfAddr string
driver string
vendor string
product string
vfID int
linkSpeed string
env string
numa string
apiDevice *pluginapi.Device
deviceSpecs []*pluginapi.DeviceSpec
mounts []*pluginapi.Mount
rdmaSpec types.RdmaSpec
}
// NewPciNetDevice returns an instance of PciNetDevice interface
func NewPciNetDevice(pciDevice *ghw.PCIDevice, rFactory types.ResourceFactory) (types.PciNetDevice, error) {
// populate all fields in pciNetDevice here
// 1. get PF details, add PF info in its pciNetDevice struct
// 2. Get driver info
var ifName string
pciAddr := pciDevice.Address
driverName, err := utils.GetDriverName(pciAddr)
if err != nil {
return nil, err
}
netDevs, _ := utils.GetNetNames(pciAddr)
if len(netDevs) == 0 {
ifName = ""
} else {
ifName = netDevs[0]
}
pfName, err := utils.GetPfName(pciAddr)
if err != nil {
return nil, err
}
// 3. Get Device file info (e.g., uio, vfio specific)
// Get DeviceInfoProvider using device driver
infoProvider := rFactory.GetInfoProvider(driverName)
dSpecs := infoProvider.GetDeviceSpecs(pciAddr)
mnt := infoProvider.GetMounts(pciAddr)
env := infoProvider.GetEnvVal(pciAddr)
rdmaSpec := rFactory.GetRdmaSpec(pciDevice.Address)
apiDevice := &pluginapi.Device{
ID: pciAddr,
Health: pluginapi.Healthy,
}
// 4. Create pciNetDevice object with all relevent info
return &pciNetDevice{
pciDevice: pciDevice,
ifName: ifName,
pfName: pfName,
driver: driverName,
vfID: 0, // TO-DO: Get this using utils pkg if needed
linkSpeed: "", // TO-DO: Get this using utils pkg
apiDevice: apiDevice,
deviceSpecs: dSpecs,
mounts: mnt,
env: env,
numa: "", // TO-DO: Get this using utils pkg
rdmaSpec: rdmaSpec,
}, nil
}
func (nd *pciNetDevice) GetPFName() string {
return nd.pfName
}
func (nd *pciNetDevice) GetNetName() string {
return nd.ifName
}
func (nd *pciNetDevice) GetPfPciAddr() string {
return nd.pfAddr
}
func (nd *pciNetDevice) GetVendor() string {
return nd.pciDevice.Vendor.ID
}
func (nd *pciNetDevice) GetDeviceCode() string {
return nd.pciDevice.Product.ID
}
func (nd *pciNetDevice) GetPciAddr() string {
return nd.pciDevice.Address
}
func (nd *pciNetDevice) GetDriver() string {
return nd.driver
}
func (nd *pciNetDevice) IsSriovPF() bool {
return false
}
func (nd *pciNetDevice) GetLinkSpeed() string {
return nd.linkSpeed
}
func (nd *pciNetDevice) GetSubClass() string {
return nd.pciDevice.Subclass.ID
}
func (nd *pciNetDevice) GetDeviceSpecs() []*pluginapi.DeviceSpec {
return nd.deviceSpecs
}
func (nd *pciNetDevice) GetEnvVal() string {
return nd.env
}
func (nd *pciNetDevice) GetMounts() []*pluginapi.Mount {
return nd.mounts
}
func (nd *pciNetDevice) GetAPIDevice() *pluginapi.Device {
return nd.apiDevice
}
func (nd *pciNetDevice) GetRdmaSpec() types.RdmaSpec {
return nd.rdmaSpec
}
func getPFInfos(pciAddr string) (pfAddr, pfName string, err error) {
return "", "", nil
}