blob: b3ba10d9bcfc3a86e21c736e8001eea06877cbfa [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"
khenaidoo79232702018-12-04 11:00:41 -050024 ic "github.com/opencord/voltha-go/protos/inter_container"
khenaidoo19d7b632018-10-30 10:49:50 -040025 "github.com/opencord/voltha-go/protos/openflow_13"
khenaidoob9203542018-09-17 22:56:37 -040026 "github.com/opencord/voltha-go/protos/voltha"
27 "google.golang.org/grpc/codes"
28 "google.golang.org/grpc/status"
29)
30
31type AdapterProxy struct {
khenaidoo43c82122018-11-22 18:38:28 -050032 TestMode bool
khenaidoo54e0ddf2019-02-27 16:21:33 -050033 deviceTopicRegistered bool
34 coreTopic *kafka.Topic
khenaidoo43c82122018-11-22 18:38:28 -050035 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
65func (ap *AdapterProxy) getCoreTopic() kafka.Topic{
66 if ap.coreTopic != nil {
67 return *ap.coreTopic
68 }
69 return kafka.Topic{Name:ap.kafkaICProxy.DefaultTopic.Name}
70}
71
72func (ap *AdapterProxy) getAdapterTopic(adapterName string) kafka.Topic{
73 return kafka.Topic{Name: adapterName}
74}
75
76
khenaidoob9203542018-09-17 22:56:37 -040077func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) error {
78 log.Debugw("AdoptDevice", log.Fields{"device": device})
khenaidoo92e62c52018-10-03 14:02:54 -040079 rpc := "adopt_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -050080 toTopic := ap.getAdapterTopic(device.Adapter)
81 //topic := kafka.Topic{Name: device.Adapter}
khenaidoob9203542018-09-17 22:56:37 -040082 args := make([]*kafka.KVArg, 1)
83 args[0] = &kafka.KVArg{
84 Key: "device",
85 Value: device,
86 }
khenaidoo43c82122018-11-22 18:38:28 -050087 // Use a device topic for the response as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -050088 replyToTopic := ap.getCoreTopic()
89 //if !ap.deviceTopicRegistered {
90 // if err := ap.kafkaICProxy.SubscribeWithDefaultRequestHandler(replyToTopic, kafka.OffsetOldest); err != nil {
91 // log.Errorw("Unable-to-subscribe-new-topic", log.Fields{"topic": replyToTopic, "error": err})
92 // return err
93 // }
94 //}
95 ap.deviceTopicRegistered = true
96 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo43c82122018-11-22 18:38:28 -050097 log.Debugw("AdoptDevice-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success})
khenaidoo92e62c52018-10-03 14:02:54 -040098 return unPackResponse(rpc, device.Id, success, result)
99}
100
101func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) error {
102 log.Debugw("DisableDevice", log.Fields{"deviceId": device.Id})
103 rpc := "disable_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500104 toTopic := ap.getAdapterTopic(device.Adapter)
105
khenaidoo43c82122018-11-22 18:38:28 -0500106 // Use a device specific topic to send the request. The adapter handling the device creates a device
107 // specific topic
khenaidoo54e0ddf2019-02-27 16:21:33 -0500108 //toTopic := kafka.CreateSubTopic(device.Adapter, device.Id)
khenaidoo92e62c52018-10-03 14:02:54 -0400109 args := make([]*kafka.KVArg, 1)
110 args[0] = &kafka.KVArg{
111 Key: "device",
112 Value: device,
khenaidoob9203542018-09-17 22:56:37 -0400113 }
khenaidoo43c82122018-11-22 18:38:28 -0500114 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500115 //replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id)
116 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500117 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo92e62c52018-10-03 14:02:54 -0400118 log.Debugw("DisableDevice-response", log.Fields{"deviceId": device.Id, "success": success})
119 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400120}
121
khenaidoo4d4802d2018-10-04 21:59:49 -0400122func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) error {
123 log.Debugw("ReEnableDevice", log.Fields{"deviceId": device.Id})
124 rpc := "reenable_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500125 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400126 args := make([]*kafka.KVArg, 1)
127 args[0] = &kafka.KVArg{
128 Key: "device",
129 Value: device,
130 }
khenaidoo43c82122018-11-22 18:38:28 -0500131 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500132 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500133 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400134 log.Debugw("ReEnableDevice-response", log.Fields{"deviceid": device.Id, "success": success})
135 return unPackResponse(rpc, device.Id, success, result)
136}
137
138func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) error {
139 log.Debugw("RebootDevice", log.Fields{"deviceId": device.Id})
140 rpc := "reboot_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500141 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400142 args := make([]*kafka.KVArg, 1)
143 args[0] = &kafka.KVArg{
144 Key: "device",
145 Value: device,
146 }
khenaidoo43c82122018-11-22 18:38:28 -0500147 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500148 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500149 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400150 log.Debugw("RebootDevice-response", log.Fields{"deviceid": device.Id, "success": success})
151 return unPackResponse(rpc, device.Id, success, result)
152}
153
154func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) error {
155 log.Debugw("DeleteDevice", log.Fields{"deviceId": device.Id})
156 rpc := "delete_device"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500157 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400158 args := make([]*kafka.KVArg, 1)
159 args[0] = &kafka.KVArg{
160 Key: "device",
161 Value: device,
162 }
khenaidoo43c82122018-11-22 18:38:28 -0500163 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500164 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500165 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400166 log.Debugw("DeleteDevice-response", log.Fields{"deviceid": device.Id, "success": success})
khenaidoo43c82122018-11-22 18:38:28 -0500167
khenaidoo3dfc8bc2019-01-10 16:48:25 -0500168 // We no longer need to have this device topic as we won't receive any unsolicited messages on it
169 if err := ap.kafkaICProxy.DeleteTopic(replyToTopic); err != nil {
170 log.Errorw("Unable-to-delete-topic", log.Fields{"topic": replyToTopic, "error": err})
khenaidoo43c82122018-11-22 18:38:28 -0500171 return err
172 }
khenaidoo43c82122018-11-22 18:38:28 -0500173
khenaidoo4d4802d2018-10-04 21:59:49 -0400174 return unPackResponse(rpc, device.Id, success, result)
175}
176
khenaidoo79232702018-12-04 11:00:41 -0500177func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
khenaidoo4d4802d2018-10-04 21:59:49 -0400178 log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500179 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400180 args := make([]*kafka.KVArg, 1)
181 args[0] = &kafka.KVArg{
182 Key: "device",
183 Value: device,
184 }
khenaidoo43c82122018-11-22 18:38:28 -0500185 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500186 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500187 success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_device_info", &toTopic, &replyToTopic, true, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400188 log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result})
189 if success {
khenaidoo79232702018-12-04 11:00:41 -0500190 unpackResult := &ic.SwitchCapability{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400191 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
192 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
193 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
194 }
195 return unpackResult, nil
196 } else {
khenaidoo79232702018-12-04 11:00:41 -0500197 unpackResult := &ic.Error{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400198 var err error
199 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
200 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
201 }
202 log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
203 // TODO: Need to get the real error code
204 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
205 }
206}
207
khenaidoo79232702018-12-04 11:00:41 -0500208func (ap *AdapterProxy) GetOfpPortInfo(ctx context.Context, device *voltha.Device, portNo uint32) (*ic.PortCapability, error) {
khenaidoo4d4802d2018-10-04 21:59:49 -0400209 log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500210 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo4d4802d2018-10-04 21:59:49 -0400211 args := make([]*kafka.KVArg, 2)
212 args[0] = &kafka.KVArg{
213 Key: "device",
214 Value: device,
215 }
khenaidoo79232702018-12-04 11:00:41 -0500216 pNo := &ic.IntType{Val: int64(portNo)}
khenaidoo4d4802d2018-10-04 21:59:49 -0400217 args[1] = &kafka.KVArg{
218 Key: "port_no",
219 Value: pNo,
220 }
khenaidoo43c82122018-11-22 18:38:28 -0500221 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500222 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500223 success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_port_info", &toTopic, &replyToTopic, true, args...)
khenaidoo4d4802d2018-10-04 21:59:49 -0400224 log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success})
225 if success {
khenaidoo79232702018-12-04 11:00:41 -0500226 unpackResult := &ic.PortCapability{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400227 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
228 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
229 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
230 }
231 return unpackResult, nil
232 } else {
khenaidoo79232702018-12-04 11:00:41 -0500233 unpackResult := &ic.Error{}
khenaidoo4d4802d2018-10-04 21:59:49 -0400234 var err error
235 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
236 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
237 }
238 log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
239 // TODO: Need to get the real error code
240 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
241 }
242}
243
244//TODO: Implement the functions below
245
khenaidoob9203542018-09-17 22:56:37 -0400246func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) {
247 log.Debug("AdapterDescriptor")
248 return nil, nil
249}
250
251func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) {
252 log.Debug("DeviceTypes")
253 return nil, nil
254}
255
256func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) {
257 log.Debug("Health")
258 return nil, nil
259}
260
khenaidoo92e62c52018-10-03 14:02:54 -0400261func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error {
khenaidoob9203542018-09-17 22:56:37 -0400262 log.Debug("ReconcileDevice")
263 return nil
264}
265
266func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error {
267 log.Debug("AbandonDevice")
268 return nil
269}
270
khenaidoob9203542018-09-17 22:56:37 -0400271func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) {
272 log.Debug("GetDeviceDetails")
273 return nil, nil
274}
275
khenaidoof5a5bfa2019-01-23 22:20:29 -0500276func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
277 log.Debugw("DownloadImage", log.Fields{"deviceId": device.Id, "image": download.Name})
278 rpc := "download_image"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500279 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500280 args := make([]*kafka.KVArg, 2)
281 args[0] = &kafka.KVArg{
282 Key: "device",
283 Value: device,
284 }
285 args[1] = &kafka.KVArg{
286 Key: "request",
287 Value: download,
288 }
289 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500290 replyToTopic := ap.getCoreTopic()
khenaidoof5a5bfa2019-01-23 22:20:29 -0500291 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
292 log.Debugw("DownloadImage-response", log.Fields{"deviceId": device.Id, "success": success})
293
294 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400295}
296
khenaidoof5a5bfa2019-01-23 22:20:29 -0500297func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (*voltha.ImageDownload, error) {
298 log.Debugw("GetImageDownloadStatus", log.Fields{"deviceId": device.Id, "image": download.Name})
299 rpc := "get_image_download_status"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500300 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500301 args := make([]*kafka.KVArg, 2)
302 args[0] = &kafka.KVArg{
303 Key: "device",
304 Value: device,
305 }
306 args[1] = &kafka.KVArg{
307 Key: "request",
308 Value: download,
309 }
310 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500311 replyToTopic := ap.getCoreTopic()
khenaidoof5a5bfa2019-01-23 22:20:29 -0500312 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
313 log.Debugw("GetImageDownloadStatus-response", log.Fields{"deviceId": device.Id, "success": success})
314
315 if success {
316 unpackResult := &voltha.ImageDownload{}
317 if err := ptypes.UnmarshalAny(result, unpackResult); err != nil {
318 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
319 return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
320 }
321 return unpackResult, nil
322 } else {
323 unpackResult := &ic.Error{}
324 var err error
325 if err = ptypes.UnmarshalAny(result, unpackResult); err != nil {
326 log.Warnw("cannot-unmarshal-response", log.Fields{"error": err})
327 return nil, err
328 }
329 log.Debugw("GetImageDownloadStatus-return", log.Fields{"deviceid": device.Id, "success": success, "error": err})
330 return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason)
331 }
khenaidoob9203542018-09-17 22:56:37 -0400332}
333
khenaidoof5a5bfa2019-01-23 22:20:29 -0500334func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
335 log.Debugw("CancelImageDownload", log.Fields{"deviceId": device.Id, "image": download.Name})
336 rpc := "cancel_image_download"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500337 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500338 args := make([]*kafka.KVArg, 2)
339 args[0] = &kafka.KVArg{
340 Key: "device",
341 Value: device,
342 }
343 args[1] = &kafka.KVArg{
344 Key: "request",
345 Value: download,
346 }
347 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500348 replyToTopic := ap.getCoreTopic()
khenaidoof5a5bfa2019-01-23 22:20:29 -0500349 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
350 log.Debugw("CancelImageDownload-response", log.Fields{"deviceId": device.Id, "success": success})
351
352 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400353}
354
khenaidoof5a5bfa2019-01-23 22:20:29 -0500355func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
356 log.Debugw("ActivateImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name})
357 rpc := "activate_image_update"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500358 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500359 args := make([]*kafka.KVArg, 2)
360 args[0] = &kafka.KVArg{
361 Key: "device",
362 Value: device,
363 }
364 args[1] = &kafka.KVArg{
365 Key: "request",
366 Value: download,
367 }
368 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500369 replyToTopic := ap.getCoreTopic()
khenaidoof5a5bfa2019-01-23 22:20:29 -0500370 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
371 log.Debugw("ActivateImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success})
372
373 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400374}
375
khenaidoof5a5bfa2019-01-23 22:20:29 -0500376func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error {
377 log.Debugw("RevertImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name})
378 rpc := "revert_image_update"
khenaidoo54e0ddf2019-02-27 16:21:33 -0500379 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoof5a5bfa2019-01-23 22:20:29 -0500380 args := make([]*kafka.KVArg, 2)
381 args[0] = &kafka.KVArg{
382 Key: "device",
383 Value: device,
384 }
385 args[1] = &kafka.KVArg{
386 Key: "request",
387 Value: download,
388 }
389 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500390 replyToTopic := ap.getCoreTopic()
khenaidoof5a5bfa2019-01-23 22:20:29 -0500391 success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, args...)
392 log.Debugw("RevertImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success})
393
394 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400395}
396
397func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) {
398 log.Debug("SelfTestDevice")
399 return nil, nil
400}
401
khenaidoofdbad6e2018-11-06 22:26:38 -0500402func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error {
403 log.Debugw("packetOut", log.Fields{"deviceId": deviceId})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500404 toTopic := ap.getAdapterTopic(deviceType)
khenaidoofdbad6e2018-11-06 22:26:38 -0500405 rpc := "receive_packet_out"
khenaidoo79232702018-12-04 11:00:41 -0500406 dId := &ic.StrType{Val: deviceId}
khenaidoofdbad6e2018-11-06 22:26:38 -0500407 args := make([]*kafka.KVArg, 3)
408 args[0] = &kafka.KVArg{
409 Key: "deviceId",
410 Value: dId,
411 }
khenaidoo79232702018-12-04 11:00:41 -0500412 op := &ic.IntType{Val: int64(outPort)}
khenaidoofdbad6e2018-11-06 22:26:38 -0500413 args[1] = &kafka.KVArg{
414 Key: "outPort",
415 Value: op,
416 }
417 args[2] = &kafka.KVArg{
418 Key: "packet",
419 Value: packet,
420 }
421
422 // TODO: Do we need to wait for an ACK on a packet Out?
khenaidoo43c82122018-11-22 18:38:28 -0500423 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500424 replyToTopic := ap.getCoreTopic()
425 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoofdbad6e2018-11-06 22:26:38 -0500426 log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success})
427 return unPackResponse(rpc, deviceId, success, result)
428}
429
khenaidoo19d7b632018-10-30 10:49:50 -0400430func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error {
431 log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500432 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo19d7b632018-10-30 10:49:50 -0400433 rpc := "update_flows_bulk"
434 args := make([]*kafka.KVArg, 3)
435 args[0] = &kafka.KVArg{
436 Key: "device",
437 Value: device,
438 }
439 args[1] = &kafka.KVArg{
440 Key: "flows",
441 Value: flows,
442 }
443 args[2] = &kafka.KVArg{
444 Key: "groups",
445 Value: groups,
446 }
447
khenaidoo43c82122018-11-22 18:38:28 -0500448 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500449 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500450 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo19d7b632018-10-30 10:49:50 -0400451 log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success})
452 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400453}
454
khenaidoo19d7b632018-10-30 10:49:50 -0400455func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error {
456 log.Debugw("UpdateFlowsIncremental", log.Fields{"deviceId": device.Id})
khenaidoo54e0ddf2019-02-27 16:21:33 -0500457 toTopic := ap.getAdapterTopic(device.Adapter)
khenaidoo19d7b632018-10-30 10:49:50 -0400458 rpc := "update_flows_bulk"
459 args := make([]*kafka.KVArg, 3)
460 args[0] = &kafka.KVArg{
461 Key: "device",
462 Value: device,
463 }
464 args[1] = &kafka.KVArg{
465 Key: "flow_changes",
466 Value: flowChanges,
467 }
468 args[2] = &kafka.KVArg{
469 Key: "group_changes",
470 Value: groupChanges,
471 }
472
khenaidoo43c82122018-11-22 18:38:28 -0500473 // Use a device specific topic as we are the only core handling requests for this device
khenaidoo54e0ddf2019-02-27 16:21:33 -0500474 replyToTopic := ap.getCoreTopic()
khenaidoo43c82122018-11-22 18:38:28 -0500475 success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...)
khenaidoo19d7b632018-10-30 10:49:50 -0400476 log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success})
477 return unPackResponse(rpc, device.Id, success, result)
khenaidoob9203542018-09-17 22:56:37 -0400478}
479
480func (ap *AdapterProxy) UpdatePmConfig(device voltha.Device, pmConfigs voltha.PmConfigs) error {
481 log.Debug("UpdatePmConfig")
482 return nil
483}
484
485func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error {
486 log.Debug("ReceivePacketOut")
487 return nil
488}
489
490func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error {
491 log.Debug("SuppressAlarm")
492 return nil
493}
494
495func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error {
496 log.Debug("UnSuppressAlarm")
497 return nil
khenaidoo89b0e942018-10-21 21:11:33 -0400498}