blob: 23b2073f2bcf4118702184f31f81da149356d528 [file] [log] [blame]
khenaidoob9203542018-09-17 22:56:37 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package core
17
18import (
19 "context"
20 "github.com/golang/protobuf/ptypes"
khenaidoo92e62c52018-10-03 14:02:54 -040021 a "github.com/golang/protobuf/ptypes/any"
khenaidoob9203542018-09-17 22:56:37 -040022 "github.com/opencord/voltha-go/common/log"
23 "github.com/opencord/voltha-go/kafka"
William Kurkiandaa6bb22019-03-07 12:26:28 -050024 ic "github.com/opencord/voltha-protos/go/inter_container"
25 "github.com/opencord/voltha-protos/go/openflow_13"
26 "github.com/opencord/voltha-protos/go/voltha"
khenaidoob9203542018-09-17 22:56:37 -040027 "google.golang.org/grpc/codes"
28 "google.golang.org/grpc/status"
29)
30
31type AdapterProxy struct {
serkant.uluderya334479d2019-04-10 08:26:15 -070032 TestMode bool
khenaidoo54e0ddf2019-02-27 16:21:33 -050033 deviceTopicRegistered bool
serkant.uluderya334479d2019-04-10 08:26:15 -070034 coreTopic *kafka.Topic
35 kafkaICProxy *kafka.InterContainerProxy
khenaidoob9203542018-09-17 22:56:37 -040036}
37
khenaidoo43c82122018-11-22 18:38:28 -050038func NewAdapterProxy(kafkaProxy *kafka.InterContainerProxy) *AdapterProxy {
khenaidoob9203542018-09-17 22:56:37 -040039 var proxy AdapterProxy
khenaidoo43c82122018-11-22 18:38:28 -050040 proxy.kafkaICProxy = kafkaProxy
khenaidoo54e0ddf2019-02-27 16:21:33 -050041 proxy.deviceTopicRegistered = false
khenaidoob9203542018-09-17 22:56:37 -040042 return &proxy
43}
44
khenaidoo92e62c52018-10-03 14:02:54 -040045func unPackResponse(rpc string, deviceId string, success bool, response *a.Any) error {
46 if success {
47 return nil
48 } else {
khenaidoo79232702018-12-04 11:00:41 -050049 unpackResult := &ic.Error{}
khenaidoo92e62c52018-10-03 14:02:54 -040050 var err error
51 if err = ptypes.UnmarshalAny(response, unpackResult); err != nil {
52 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
khenaidoo6d055132019-02-12 16:51:19 -050053 return err
khenaidoo92e62c52018-10-03 14:02:54 -040054 }
55 log.Debugw("response", log.Fields{"rpc": rpc, "deviceId": deviceId, "success": success, "error": err})
56 // TODO: Need to get the real error code
57 return status.Errorf(codes.Canceled, "%s", unpackResult.Reason)
58 }
59}
60
khenaidoo54e0ddf2019-02-27 16:21:33 -050061func (ap *AdapterProxy) updateCoreTopic(coreTopic *kafka.Topic) {
62 ap.coreTopic = coreTopic
63}
64
serkant.uluderya334479d2019-04-10 08:26:15 -070065func (ap *AdapterProxy) getCoreTopic() kafka.Topic {
khenaidoo54e0ddf2019-02-27 16:21:33 -050066 if ap.coreTopic != nil {
67 return *ap.coreTopic
68 }
serkant.uluderya334479d2019-04-10 08:26:15 -070069 return kafka.Topic{Name: ap.kafkaICProxy.DefaultTopic.Name}
khenaidoo54e0ddf2019-02-27 16:21:33 -050070}
71
serkant.uluderya334479d2019-04-10 08:26:15 -070072func (ap *AdapterProxy) getAdapterTopic(adapterName string) kafka.Topic {
khenaidoo54e0ddf2019-02-27 16:21:33 -050073 return kafka.Topic{Name: adapterName}
74}
75
khenaidoob9203542018-09-17 22:56:37 -040076func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) error {
77 log.Debugw("AdoptDevice", log.Fields{"device": device})
khenaidoo92e62c52018-10-03 14:02:54 -040078 rpc := "adopt_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -050079 toTopic := ap.getAdapterTopic(device.Adapter)
80 //topic := kafka.Topic{Name: device.Adapter}
khenaidoob9203542018-09-17 22:56:37 -040081 args := make([]*kafka.KVArg, 1)
82 args[0] = &kafka.KVArg{
83 Key: "device",
84 Value: device,
85 }
khenaidoo43c82122018-11-22 18:38:28 -050086 // Use a device topic for the response as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -050087 replyToTopic := ap.getCoreTopic()
khenaidoo54e0ddf2019-02-27 16:21:33 -050088 ap.deviceTopicRegistered = true
khenaidoobdcb8e02019-03-06 16:28:56 -050089 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo43c82122018-11-22 18:38:28 -050090 log.Debugw("AdoptDevice-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success})
khenaidoo92e62c52018-10-03 14:02:54 -040091 return unPackResponse(rpc, device.Id, success, result)
92}
93
94func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) error {
95 log.Debugw("DisableDevice", log.Fields{"deviceId": device.Id})
96 rpc := "disable_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -050097 toTopic := ap.getAdapterTopic(device.Adapter)
98
khenaidoo43c82122018-11-22 18:38:28 -050099 // Use a device specific topic to send the request. The adapter handling the device creates a device
100 // specific topic
khenaidoo54e0ddf2019-02-27 16:21:33 -0500101 //toTopic := kafka.CreateSubTopic(device.Adapter, device.Id)
khenaidoo92e62c52018-10-03 14:02:54 -0400102 args := make([]*kafka.KVArg, 1)
103 args[0] = &kafka.KVArg{
104 Key: "device",
105 Value: device,
khenaidoob9203542018-09-17 22:56:37 -0400106 }
khenaidoo43c82122018-11-22 18:38:28 -0500107 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500108 //replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id)
109 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500110 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo92e62c52018-10-03 14:02:54 -0400111 log.Debugw("DisableDevice-response", log.Fields{"deviceId": device.Id, "success": success})
112 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400113}
114
khenaidoo4d4802d2018-10-04 21:59:49 -0400115func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) error {
116 log.Debugw("ReEnableDevice", log.Fields{"deviceId": device.Id})
117 rpc := "reenable_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500118 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400119 args := make([]*kafka.KVArg, 1)
120 args[0] = &kafka.KVArg{
121 Key: "device",
122 Value: device,
123 }
khenaidoo43c82122018-11-22 18:38:28 -0500124 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500125 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500126 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400127 log.Debugw("ReEnableDevice-response", log.Fields{"deviceid": device.Id, "success": success})
128 return unPackResponse(rpc, device.Id, success, result)
129}
130
131func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) error {
132 log.Debugw("RebootDevice", log.Fields{"deviceId": device.Id})
133 rpc := "reboot_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500134 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400135 args := make([]*kafka.KVArg, 1)
136 args[0] = &kafka.KVArg{
137 Key: "device",
138 Value: device,
139 }
khenaidoo43c82122018-11-22 18:38:28 -0500140 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500141 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500142 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400143 log.Debugw("RebootDevice-response", log.Fields{"deviceid": device.Id, "success": success})
144 return unPackResponse(rpc, device.Id, success, result)
145}
146
147func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) error {
148 log.Debugw("DeleteDevice", log.Fields{"deviceId": device.Id})
149 rpc := "delete_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500150 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400151 args := make([]*kafka.KVArg, 1)
152 args[0] = &kafka.KVArg{
153 Key: "device",
154 Value: device,
155 }
khenaidoo43c82122018-11-22 18:38:28 -0500156 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500157 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500158 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400159 log.Debugw("DeleteDevice-response", log.Fields{"deviceid": device.Id, "success": success})
khenaidoo43c82122018-11-22 18:38:28 -0500160
khenaidoo4d4802d2018-10-04 21:59:49 -0400161 return unPackResponse(rpc, device.Id, success, result)
162}
163
khenaidoo79232702018-12-04 11:00:41 -0500164func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
khenaidoo4d4802d2018-10-04 21:59:49 -0400165 log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500166 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400167 args := make([]*kafka.KVArg, 1)
168 args[0] = &kafka.KVArg{
169 Key: "device",
170 Value: device,
171 }
khenaidoo43c82122018-11-22 18:38:28 -0500172 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500173 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500174 success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_device_info", &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400175 log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result})
176 if success {
khenaidoo79232702018-12-04 11:00:41 -0500177 unpackResult := &ic.SwitchCapability{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400178 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
179 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
180 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
181 }
182 return unpackResult, nil
183 } else {
khenaidoo79232702018-12-04 11:00:41 -0500184 unpackResult := &ic.Error{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400185 var err error
186 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
187 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
188 }
189 log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
190 // TODO: Need to get the real error code
191 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
192 }
193}
194
khenaidoo79232702018-12-04 11:00:41 -0500195func (ap *AdapterProxy) GetOfpPortInfo(ctx context.Context, device *voltha.Device, portNo uint32) (*ic.PortCapability, error) {
khenaidoo4d4802d2018-10-04 21:59:49 -0400196 log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500197 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400198 args := make([]*kafka.KVArg, 2)
199 args[0] = &kafka.KVArg{
200 Key: "device",
201 Value: device,
202 }
khenaidoo79232702018-12-04 11:00:41 -0500203 pNo := &ic.IntType{Val: int64(portNo)}
khenaidoo4d4802d2018-10-04 21:59:49 -0400204 args[1] = &kafka.KVArg{
205 Key: "port_no",
206 Value: pNo,
207 }
khenaidoo43c82122018-11-22 18:38:28 -0500208 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500209 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500210 success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_port_info", &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400211 log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success})
212 if success {
khenaidoo79232702018-12-04 11:00:41 -0500213 unpackResult := &ic.PortCapability{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400214 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
215 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
216 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
217 }
218 return unpackResult, nil
219 } else {
khenaidoo79232702018-12-04 11:00:41 -0500220 unpackResult := &ic.Error{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400221 var err error
222 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
223 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
224 }
225 log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
226 // TODO: Need to get the real error code
227 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
228 }
229}
230
231//TODO: Implement the functions below
232
khenaidoob9203542018-09-17 22:56:37 -0400233func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) {
234 log.Debug("AdapterDescriptor")
235 return nil, nil
236}
237
238func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) {
239 log.Debug("DeviceTypes")
240 return nil, nil
241}
242
243func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) {
244 log.Debug("Health")
245 return nil, nil
246}
247
khenaidoo92e62c52018-10-03 14:02:54 -0400248func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error {
khenaidoob9203542018-09-17 22:56:37 -0400249 log.Debug("ReconcileDevice")
250 return nil
251}
252
253func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error {
254 log.Debug("AbandonDevice")
255 return nil
256}
257
khenaidoob9203542018-09-17 22:56:37 -0400258func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) {
259 log.Debug("GetDeviceDetails")
260 return nil, nil
261}
262
khenaidoof5a5bfa2019-01-23 22:20:29 -0500263func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
264 log.Debugw("DownloadImage", log.Fields{"deviceId": device.Id, "image": download.Name})
265 rpc := "download_image"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500266 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500267 args := make([]*kafka.KVArg, 2)
268 args[0] = &kafka.KVArg{
269 Key: "device",
270 Value: device,
271 }
272 args[1] = &kafka.KVArg{
273 Key: "request",
274 Value: download,
275 }
276 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500277 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500278 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500279 log.Debugw("DownloadImage-response", log.Fields{"deviceId": device.Id, "success": success})
280
281 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400282}
283
khenaidoof5a5bfa2019-01-23 22:20:29 -0500284func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (*voltha.ImageDownload, error) {
285 log.Debugw("GetImageDownloadStatus", log.Fields{"deviceId": device.Id, "image": download.Name})
286 rpc := "get_image_download_status"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500287 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500288 args := make([]*kafka.KVArg, 2)
289 args[0] = &kafka.KVArg{
290 Key: "device",
291 Value: device,
292 }
293 args[1] = &kafka.KVArg{
294 Key: "request",
295 Value: download,
296 }
297 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500298 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500299 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500300 log.Debugw("GetImageDownloadStatus-response", log.Fields{"deviceId": device.Id, "success": success})
301
302 if success {
303 unpackResult := &voltha.ImageDownload{}
304 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
305 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
306 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
307 }
308 return unpackResult, nil
309 } else {
310 unpackResult := &ic.Error{}
311 var err error
312 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
313 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
314 return nil, err
315 }
316 log.Debugw("GetImageDownloadStatus-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
317 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
318 }
khenaidoob9203542018-09-17 22:56:37 -0400319}
320
khenaidoof5a5bfa2019-01-23 22:20:29 -0500321func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
322 log.Debugw("CancelImageDownload", log.Fields{"deviceId": device.Id, "image": download.Name})
323 rpc := "cancel_image_download"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500324 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500325 args := make([]*kafka.KVArg, 2)
326 args[0] = &kafka.KVArg{
327 Key: "device",
328 Value: device,
329 }
330 args[1] = &kafka.KVArg{
331 Key: "request",
332 Value: download,
333 }
334 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500335 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500336 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500337 log.Debugw("CancelImageDownload-response", log.Fields{"deviceId": device.Id, "success": success})
338
339 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400340}
341
khenaidoof5a5bfa2019-01-23 22:20:29 -0500342func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
343 log.Debugw("ActivateImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name})
344 rpc := "activate_image_update"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500345 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500346 args := make([]*kafka.KVArg, 2)
347 args[0] = &kafka.KVArg{
348 Key: "device",
349 Value: device,
350 }
351 args[1] = &kafka.KVArg{
352 Key: "request",
353 Value: download,
354 }
355 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500356 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500357 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500358 log.Debugw("ActivateImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success})
359
360 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400361}
362
khenaidoof5a5bfa2019-01-23 22:20:29 -0500363func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
364 log.Debugw("RevertImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name})
365 rpc := "revert_image_update"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500366 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500367 args := make([]*kafka.KVArg, 2)
368 args[0] = &kafka.KVArg{
369 Key: "device",
370 Value: device,
371 }
372 args[1] = &kafka.KVArg{
373 Key: "request",
374 Value: download,
375 }
376 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500377 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500378 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500379 log.Debugw("RevertImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success})
380
381 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400382}
383
384func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) {
385 log.Debug("SelfTestDevice")
386 return nil, nil
387}
388
khenaidoofdbad6e2018-11-06 22:26:38 -0500389func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error {
390 log.Debugw("packetOut", log.Fields{"deviceId": deviceId})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500391 toTopic := ap.getAdapterTopic(deviceType)
khenaidoofdbad6e2018-11-06 22:26:38 -0500392 rpc := "receive_packet_out"
khenaidoo79232702018-12-04 11:00:41 -0500393 dId := &ic.StrType{Val: deviceId}
khenaidoofdbad6e2018-11-06 22:26:38 -0500394 args := make([]*kafka.KVArg, 3)
395 args[0] = &kafka.KVArg{
396 Key: "deviceId",
397 Value: dId,
398 }
khenaidoo79232702018-12-04 11:00:41 -0500399 op := &ic.IntType{Val: int64(outPort)}
khenaidoofdbad6e2018-11-06 22:26:38 -0500400 args[1] = &kafka.KVArg{
401 Key: "outPort",
402 Value: op,
403 }
404 args[2] = &kafka.KVArg{
405 Key: "packet",
406 Value: packet,
407 }
408
409 // TODO: Do we need to wait for an ACK on a packet Out?
khenaidoo43c82122018-11-22 18:38:28 -0500410 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500411 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500412 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
khenaidoofdbad6e2018-11-06 22:26:38 -0500413 log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success})
414 return unPackResponse(rpc, deviceId, success, result)
415}
416
khenaidoo19d7b632018-10-30 10:49:50 -0400417func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error {
khenaidoo0458db62019-06-20 08:50:36 -0400418 log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id, "flowsInUpdate": len(flows.Items), "groupsToUpdate": len(groups.Items)})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500419 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo19d7b632018-10-30 10:49:50 -0400420 rpc := "update_flows_bulk"
421 args := make([]*kafka.KVArg, 3)
422 args[0] = &kafka.KVArg{
423 Key: "device",
424 Value: device,
425 }
426 args[1] = &kafka.KVArg{
427 Key: "flows",
428 Value: flows,
429 }
430 args[2] = &kafka.KVArg{
431 Key: "groups",
432 Value: groups,
433 }
434
khenaidoo43c82122018-11-22 18:38:28 -0500435 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500436 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500437 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo19d7b632018-10-30 10:49:50 -0400438 log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success})
439 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400440}
441
khenaidoo19d7b632018-10-30 10:49:50 -0400442func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error {
khenaidoo0458db62019-06-20 08:50:36 -0400443 log.Debugw("UpdateFlowsIncremental",
444 log.Fields{
445 "deviceId": device.Id,
446 "flowsToAdd": len(flowChanges.ToAdd.Items),
447 "flowsToDelete": len(flowChanges.ToRemove.Items),
448 "groupsToAdd": len(groupChanges.ToAdd.Items),
449 "groupsToDelete": len(groupChanges.ToRemove.Items),
450 "groupsToUpdate": len(groupChanges.ToUpdate.Items),
451 })
khenaidoo54e0ddf2019-02-27 16:21:33 -0500452 toTopic := ap.getAdapterTopic(device.Adapter)
Matt Jeanneretb0037422019-03-23 14:36:51 -0400453 rpc := "update_flows_incrementally"
khenaidoo19d7b632018-10-30 10:49:50 -0400454 args := make([]*kafka.KVArg, 3)
455 args[0] = &kafka.KVArg{
456 Key: "device",
457 Value: device,
458 }
459 args[1] = &kafka.KVArg{
460 Key: "flow_changes",
461 Value: flowChanges,
462 }
463 args[2] = &kafka.KVArg{
464 Key: "group_changes",
465 Value: groupChanges,
466 }
467
khenaidoo43c82122018-11-22 18:38:28 -0500468 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500469 replyToTopic := ap.getCoreTopic()
khenaidoobdcb8e02019-03-06 16:28:56 -0500470 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
khenaidoo19d7b632018-10-30 10:49:50 -0400471 log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success})
472 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400473}
474
475func (ap *AdapterProxy) UpdatePmConfig(device voltha.Device, pmConfigs voltha.PmConfigs) error {
476 log.Debug("UpdatePmConfig")
477 return nil
478}
479
480func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error {
481 log.Debug("ReceivePacketOut")
482 return nil
483}
484
485func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error {
486 log.Debug("SuppressAlarm")
487 return nil
488}
489
490func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error {
491 log.Debug("UnSuppressAlarm")
492 return nil
khenaidoo89b0e942018-10-21 21:11:33 -0400493}
serkant.uluderya334479d2019-04-10 08:26:15 -0700494
495func (ap *AdapterProxy) SimulateAlarm(ctx context.Context, device *voltha.Device, simulatereq *voltha.SimulateAlarmRequest) error {
496 log.Debugw("SimulateAlarm", log.Fields{"id": simulatereq.Id})
497 rpc := "simulate_alarm"
498 toTopic := ap.getAdapterTopic(device.Adapter)
499 args := make([]*kafka.KVArg, 2)
500 args[0] = &kafka.KVArg{
501 Key: "device",
502 Value: device,
503 }
504 args[1] = &kafka.KVArg{
505 Key: "request",
506 Value: simulatereq,
507 }
508
509 // Use a device topic for the response as we are the only core handling requests for this device
510 replyToTopic := ap.getCoreTopic()
511 ap.deviceTopicRegistered = true
512 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
513 log.Debugw("SimulateAlarm-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success})
514 return unPackResponse(rpc, device.Id, success, result)
515}