-
Notifications
You must be signed in to change notification settings - Fork 105
/
accelerationfunction.go
206 lines (177 loc) · 6.83 KB
/
accelerationfunction.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// AccelerationFunctionType is the type of acceleration provided.
type AccelerationFunctionType string
const (
// EncryptionAccelerationFunctionType is an encryption function.
EncryptionAccelerationFunctionType AccelerationFunctionType = "Encryption"
// CompressionAccelerationFunctionType is a compression function.
CompressionAccelerationFunctionType AccelerationFunctionType = "Compression"
// PacketInspectionAccelerationFunctionType is a packet inspection function.
PacketInspectionAccelerationFunctionType AccelerationFunctionType = "PacketInspection"
// PacketSwitchAccelerationFunctionType is a packet switch function.
PacketSwitchAccelerationFunctionType AccelerationFunctionType = "PacketSwitch"
// SchedulerAccelerationFunctionType is a scheduler function.
SchedulerAccelerationFunctionType AccelerationFunctionType = "Scheduler"
// AudioProcessingAccelerationFunctionType is an audio processing function.
AudioProcessingAccelerationFunctionType AccelerationFunctionType = "AudioProcessing"
// VideoProcessingAccelerationFunctionType is a video processing function.
VideoProcessingAccelerationFunctionType AccelerationFunctionType = "VideoProcessing"
// OEMAccelerationFunctionType is an OEM-defined acceleration function.
OEMAccelerationFunctionType AccelerationFunctionType = "OEM"
)
// AccelerationFunction shall represent the acceleration function that a processor implements in a Redfish
// implementation. This can include functions such as audio processing, compression, encryption, packet inspection,
// packet switching, scheduling, or video processing.
type AccelerationFunction struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AccelerationFunctionType shall contain the string that identifies the acceleration function type.
AccelerationFunctionType AccelerationFunctionType
// Description provides a description of this resource.
Description string
// FPGAReconfigurationSlots shall contain an array of the FPGA reconfiguration slot identifiers that this
// acceleration function occupies.
FPGAReconfigurationSlots []string `json:"FpgaReconfigurationSlots"`
// Manufacturer shall contain a string that identifies the manufacturer of the acceleration function.
Manufacturer string
// PowerWatts shall contain the total acceleration function power consumption, in watt units.
PowerWatts int
// Status shall contain any status or health properties of the Resource.
Status common.Status
// UUID shall contain a UUID for the acceleration function. RFC4122 describes methods that can create the value.
// The value should be considered to be opaque. Client software should only treat the overall value as a UUID and
// should not interpret any subfields within the UUID.
UUID string
// Version shall describe the acceleration function version.
Version string
// endpoints is a colleection of URIs for connected endpoints.
endpoints []string
// EndpointsCount is the number of connected endpoints.
EndpointsCount int
// pcieFunctions is a collection of URIs to associated PCIe functions.
pcieFunctions []string
// PCIeFunctionsCount is the number of PCIe functions associated with this accelerator.
PCIeFunctionsCount int
}
// UnmarshalJSON unmarshals a AccelerationFunction object from the raw JSON.
func (accelerationfunction *AccelerationFunction) UnmarshalJSON(b []byte) error {
type temp AccelerationFunction
type linkReference struct {
Endpoints common.Links
EndpointsCount int `json:"Endpoints@odata.count"`
PCIeFunctions common.Links
PCIeFunctionsCount int `json:"PCIeFunctions@odata.count"`
}
var t struct {
temp
Links linkReference
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*accelerationfunction = AccelerationFunction(t.temp)
accelerationfunction.endpoints = t.Links.Endpoints.ToStrings()
accelerationfunction.EndpointsCount = t.Links.EndpointsCount
accelerationfunction.pcieFunctions = t.Links.PCIeFunctions.ToStrings()
accelerationfunction.PCIeFunctionsCount = t.Links.PCIeFunctionsCount
return nil
}
// GetAccelerationFunction will get a AccelerationFunction instance from the service.
func GetAccelerationFunction(c common.Client, uri string) (*AccelerationFunction, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var accelerationfunction AccelerationFunction
err = json.NewDecoder(resp.Body).Decode(&accelerationfunction)
if err != nil {
return nil, err
}
accelerationfunction.SetClient(c)
return &accelerationfunction, nil
}
// ListReferencedAccelerationFunctions gets the collection of AccelerationFunction from
// a provided reference.
func ListReferencedAccelerationFunctions(c common.Client, link string) ([]*AccelerationFunction, error) {
var result []*AccelerationFunction
if link == "" {
return result, nil
}
type GetResult struct {
Item *AccelerationFunction
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
accelerationfunction, err := GetAccelerationFunction(c, link)
ch <- GetResult{Item: accelerationfunction, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// Endpoints gets the endpoints connected to this accelerator.
func (accelerationfunction *AccelerationFunction) Endpoints() ([]*Endpoint, error) {
var result []*Endpoint
collectionError := common.NewCollectionError()
for _, uri := range accelerationfunction.endpoints {
endpoint, err := GetEndpoint(accelerationfunction.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, endpoint)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// PCIeFunctions gets the PCIe functions associated with this accelerator.
func (accelerationfunction *AccelerationFunction) PCIeFunctions() ([]*PCIeFunction, error) {
var result []*PCIeFunction
collectionError := common.NewCollectionError()
for _, uri := range accelerationfunction.pcieFunctions {
function, err := GetPCIeFunction(accelerationfunction.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, function)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}