khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 17 | package remote |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 18 | |
| 19 | import ( |
| 20 | "context" |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 21 | |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 22 | "github.com/opencord/voltha-lib-go/v4/pkg/kafka" |
| 23 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
Salman Siddiqui | 1cf9504 | 2020-11-19 00:42:56 +0530 | [diff] [blame] | 24 | "github.com/opencord/voltha-protos/v4/go/extension" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 25 | ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 26 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 27 | "github.com/opencord/voltha-protos/v4/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 28 | ) |
| 29 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 30 | // AdapterProxy represents adapter proxy attributes |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 31 | type AdapterProxy struct { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 32 | kafka.EndpointManager |
khenaidoo | dd3324d | 2021-04-27 16:22:55 -0400 | [diff] [blame^] | 33 | coreTopic string |
| 34 | kafkaICProxy kafka.InterContainerProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 35 | } |
| 36 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 37 | // NewAdapterProxy will return adapter proxy instance |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 38 | func NewAdapterProxy(kafkaProxy kafka.InterContainerProxy, coreTopic string, endpointManager kafka.EndpointManager) *AdapterProxy { |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 39 | return &AdapterProxy{ |
khenaidoo | dd3324d | 2021-04-27 16:22:55 -0400 | [diff] [blame^] | 40 | EndpointManager: endpointManager, |
| 41 | kafkaICProxy: kafkaProxy, |
| 42 | coreTopic: coreTopic, |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 43 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 44 | } |
| 45 | |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 46 | func (ap *AdapterProxy) getCoreTopic() kafka.Topic { |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 47 | return kafka.Topic{Name: ap.coreTopic} |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 50 | func (ap *AdapterProxy) getAdapterTopic(ctx context.Context, deviceID string, adapterType string) (*kafka.Topic, error) { |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 51 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 52 | endpoint, err := ap.GetEndpoint(ctx, deviceID, adapterType) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | return &kafka.Topic{Name: string(endpoint)}, nil |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 58 | } |
| 59 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 60 | func (ap *AdapterProxy) sendRPC(ctx context.Context, rpc string, toTopic *kafka.Topic, replyToTopic *kafka.Topic, |
| 61 | waitForResponse bool, deviceID string, kvArgs ...*kafka.KVArg) (chan *kafka.RpcResponse, error) { |
| 62 | |
| 63 | // Sent the request to kafka |
| 64 | respChnl := ap.kafkaICProxy.InvokeAsyncRPC(ctx, rpc, toTopic, replyToTopic, waitForResponse, deviceID, kvArgs...) |
| 65 | |
| 66 | // Wait for first response which would indicate whether the request was successfully sent to kafka. |
| 67 | firstResponse, ok := <-respChnl |
| 68 | if !ok || firstResponse.MType != kafka.RpcSent { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 69 | logger.Errorw(ctx, "failure to request to kafka", log.Fields{"rpc": rpc, "device-id": deviceID, "error": firstResponse.Err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 70 | return nil, firstResponse.Err |
| 71 | } |
| 72 | // return the kafka channel for the caller to wait for the response of the RPC call |
| 73 | return respChnl, nil |
| 74 | } |
| 75 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 76 | // AdoptDevice invokes adopt device rpc |
| 77 | func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 78 | logger.Debugw(ctx, "AdoptDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 79 | rpc := "adopt_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 80 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 84 | args := []*kafka.KVArg{ |
| 85 | {Key: "device", Value: device}, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 86 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 87 | replyToTopic := ap.getCoreTopic() |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 88 | logger.Debugw(ctx, "adoptDevice-send-request", log.Fields{"device-id": device.Id, "deviceType": device.Type, "serialNumber": device.SerialNumber}) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 89 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 92 | // DisableDevice invokes disable device rpc |
| 93 | func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 94 | logger.Debugw(ctx, "DisableDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 95 | rpc := "disable_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 96 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 97 | if err != nil { |
| 98 | return nil, err |
| 99 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 100 | args := []*kafka.KVArg{ |
| 101 | {Key: "device", Value: device}, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 102 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 103 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 104 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 107 | // ReEnableDevice invokes reenable device rpc |
| 108 | func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 109 | logger.Debugw(ctx, "ReEnableDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 110 | rpc := "reenable_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 111 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 115 | args := []*kafka.KVArg{ |
| 116 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 117 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 118 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 119 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 122 | // RebootDevice invokes reboot device rpc |
| 123 | func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 124 | logger.Debugw(ctx, "RebootDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 125 | rpc := "reboot_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 126 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 127 | if err != nil { |
| 128 | return nil, err |
| 129 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 130 | args := []*kafka.KVArg{ |
| 131 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 132 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 133 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 134 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 137 | // DeleteDevice invokes delete device rpc |
| 138 | func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 139 | logger.Debugw(ctx, "DeleteDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 140 | rpc := "delete_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 141 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 142 | if err != nil { |
| 143 | return nil, err |
| 144 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 145 | args := []*kafka.KVArg{ |
| 146 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 147 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 148 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 149 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 152 | // GetOfpDeviceInfo invokes get ofp device info rpc |
| 153 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 154 | logger.Debugw(ctx, "GetOfpDeviceInfo", log.Fields{"device-id": device.Id}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 155 | rpc := "get_ofp_device_info" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 156 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 160 | args := []*kafka.KVArg{ |
| 161 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 162 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 163 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 164 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 167 | // ReconcileDevice invokes reconcile device rpc |
| 168 | func (ap *AdapterProxy) ReconcileDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 169 | logger.Debugw(ctx, "ReconcileDevice", log.Fields{"device-id": device.Id}) |
Matt Jeanneret | 7cf8e0b | 2020-01-09 11:57:51 -0500 | [diff] [blame] | 170 | rpc := "reconcile_device" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 171 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 172 | if err != nil { |
| 173 | return nil, err |
| 174 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 175 | args := []*kafka.KVArg{ |
| 176 | {Key: "device", Value: device}, |
| 177 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 178 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 179 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 182 | // DownloadImage invokes download image rpc |
| 183 | func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 184 | logger.Debugw(ctx, "DownloadImage", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 185 | rpc := "download_image" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 186 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 187 | if err != nil { |
| 188 | return nil, err |
| 189 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 190 | args := []*kafka.KVArg{ |
| 191 | {Key: "device", Value: device}, |
| 192 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 193 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 194 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 195 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 198 | // GetImageDownloadStatus invokes get image download status rpc |
| 199 | func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 200 | logger.Debugw(ctx, "GetImageDownloadStatus", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 201 | rpc := "get_image_download_status" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 202 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 203 | if err != nil { |
| 204 | return nil, err |
| 205 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 206 | args := []*kafka.KVArg{ |
| 207 | {Key: "device", Value: device}, |
| 208 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 209 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 210 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 211 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 214 | // CancelImageDownload invokes cancel image download rpc |
| 215 | func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 216 | logger.Debugw(ctx, "CancelImageDownload", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 217 | rpc := "cancel_image_download" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 218 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 219 | if err != nil { |
| 220 | return nil, err |
| 221 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 222 | args := []*kafka.KVArg{ |
| 223 | {Key: "device", Value: device}, |
| 224 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 225 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 226 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 227 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 230 | // ActivateImageUpdate invokes activate image update rpc |
| 231 | func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 232 | logger.Debugw(ctx, "ActivateImageUpdate", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 233 | rpc := "activate_image_update" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 234 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 235 | if err != nil { |
| 236 | return nil, err |
| 237 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 238 | args := []*kafka.KVArg{ |
| 239 | {Key: "device", Value: device}, |
| 240 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 241 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 242 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 243 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 246 | // RevertImageUpdate invokes revert image update rpc |
| 247 | func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 248 | logger.Debugw(ctx, "RevertImageUpdate", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 249 | rpc := "revert_image_update" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 250 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 251 | if err != nil { |
| 252 | return nil, err |
| 253 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 254 | args := []*kafka.KVArg{ |
| 255 | {Key: "device", Value: device}, |
| 256 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 257 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 258 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 259 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Kent Hagerman | a7c9d79 | 2020-07-16 17:39:01 -0400 | [diff] [blame] | 262 | func (ap *AdapterProxy) PacketOut(ctx context.Context, deviceType string, deviceID string, outPort uint32, packet *ofp.OfpPacketOut) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 263 | logger.Debugw(ctx, "PacketOut", log.Fields{"device-id": deviceID, "device-type": deviceType, "out-port": outPort}) |
| 264 | toTopic, err := ap.getAdapterTopic(ctx, deviceID, deviceType) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 265 | if err != nil { |
| 266 | return nil, err |
| 267 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 268 | rpc := "receive_packet_out" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 269 | args := []*kafka.KVArg{ |
| 270 | {Key: "deviceId", Value: &ic.StrType{Val: deviceID}}, |
| 271 | {Key: "outPort", Value: &ic.IntType{Val: int64(outPort)}}, |
| 272 | {Key: "packet", Value: packet}, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 273 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 274 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 275 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, deviceID, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 276 | } |
| 277 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 278 | // UpdateFlowsBulk invokes update flows bulk rpc |
Kent Hagerman | a7c9d79 | 2020-07-16 17:39:01 -0400 | [diff] [blame] | 279 | func (ap *AdapterProxy) UpdateFlowsBulk(ctx context.Context, device *voltha.Device, flows map[uint64]*ofp.OfpFlowStats, groups map[uint32]*voltha.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) (chan *kafka.RpcResponse, error) { |
| 280 | logger.Debugw(ctx, "UpdateFlowsBulk", log.Fields{"device-id": device.Id, "flow-count": len(flows), "group-count": len(groups), "flow-metadata": flowMetadata}) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 281 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 285 | rpc := "update_flows_bulk" |
Kent Hagerman | a7c9d79 | 2020-07-16 17:39:01 -0400 | [diff] [blame] | 286 | |
| 287 | ctr, flowSlice := 0, make([]*ofp.OfpFlowStats, len(flows)) |
| 288 | for _, flow := range flows { |
| 289 | flowSlice[ctr] = flow |
| 290 | ctr++ |
| 291 | } |
| 292 | ctr, groupSlice := 0, make([]*ofp.OfpGroupEntry, len(groups)) |
| 293 | for _, group := range groups { |
| 294 | groupSlice[ctr] = group |
| 295 | ctr++ |
| 296 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 297 | args := []*kafka.KVArg{ |
| 298 | {Key: "device", Value: device}, |
Kent Hagerman | a7c9d79 | 2020-07-16 17:39:01 -0400 | [diff] [blame] | 299 | {Key: "flows", Value: &voltha.Flows{Items: flowSlice}}, |
| 300 | {Key: "groups", Value: &voltha.FlowGroups{Items: groupSlice}}, |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 301 | {Key: "flow_metadata", Value: flowMetadata}, |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 302 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 303 | replyToTopic := ap.getCoreTopic() |
Rohan Agrawal | cf12f20 | 2020-08-03 04:42:01 +0000 | [diff] [blame] | 304 | return ap.sendRPC(log.WithSpanFromContext(context.TODO(), ctx), rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 307 | // UpdateFlowsIncremental invokes update flows incremental rpc |
Kent Hagerman | a7c9d79 | 2020-07-16 17:39:01 -0400 | [diff] [blame] | 308 | func (ap *AdapterProxy) UpdateFlowsIncremental(ctx context.Context, device *voltha.Device, flowChanges *ofp.FlowChanges, groupChanges *ofp.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 309 | logger.Debugw(ctx, "UpdateFlowsIncremental", |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 310 | log.Fields{ |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 311 | "device-id": device.Id, |
| 312 | "flow-to-add-count": len(flowChanges.ToAdd.Items), |
| 313 | "flow-to-delete-count": len(flowChanges.ToRemove.Items), |
| 314 | "group-to-add-count": len(groupChanges.ToAdd.Items), |
| 315 | "group-to-delete-count": len(groupChanges.ToRemove.Items), |
| 316 | "group-to-update-count": len(groupChanges.ToUpdate.Items), |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 317 | }) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 318 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 319 | if err != nil { |
| 320 | return nil, err |
| 321 | } |
Matt Jeanneret | b003742 | 2019-03-23 14:36:51 -0400 | [diff] [blame] | 322 | rpc := "update_flows_incrementally" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 323 | args := []*kafka.KVArg{ |
| 324 | {Key: "device", Value: device}, |
| 325 | {Key: "flow_changes", Value: flowChanges}, |
| 326 | {Key: "group_changes", Value: groupChanges}, |
| 327 | {Key: "flow_metadata", Value: flowMetadata}, |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 328 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 329 | replyToTopic := ap.getCoreTopic() |
Rohan Agrawal | cf12f20 | 2020-08-03 04:42:01 +0000 | [diff] [blame] | 330 | return ap.sendRPC(log.WithSpanFromContext(context.TODO(), ctx), rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 333 | // UpdatePmConfigs invokes update pm configs rpc |
| 334 | func (ap *AdapterProxy) UpdatePmConfigs(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 335 | logger.Debugw(ctx, "UpdatePmConfigs", log.Fields{"device-id": device.Id, "pm-configs-id": pmConfigs.Id}) |
| 336 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 337 | if err != nil { |
| 338 | return nil, err |
| 339 | } |
Rohan Agrawal | 2a0c449 | 2020-06-29 11:55:06 +0000 | [diff] [blame] | 340 | rpc := "update_pm_config" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 341 | args := []*kafka.KVArg{ |
| 342 | {Key: "device", Value: device}, |
| 343 | {Key: "pm_configs", Value: pmConfigs}, |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 344 | } |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 345 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 346 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 349 | // SimulateAlarm invokes simulate alarm rpc |
| 350 | func (ap *AdapterProxy) SimulateAlarm(ctx context.Context, device *voltha.Device, simulateReq *voltha.SimulateAlarmRequest) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 351 | logger.Debugw(ctx, "SimulateAlarm", log.Fields{"device-id": device.Id, "simulate-req-id": simulateReq.Id}) |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 352 | rpc := "simulate_alarm" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 353 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 354 | if err != nil { |
| 355 | return nil, err |
| 356 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 357 | args := []*kafka.KVArg{ |
| 358 | {Key: "device", Value: device}, |
| 359 | {Key: "request", Value: simulateReq}, |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 360 | } |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 361 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 362 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 363 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 364 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 365 | func (ap *AdapterProxy) DisablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 366 | logger.Debugw(ctx, "DisablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 367 | rpc := "disable_port" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 368 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 369 | if err != nil { |
| 370 | return nil, err |
| 371 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 372 | args := []*kafka.KVArg{ |
| 373 | {Key: "deviceId", Value: &ic.StrType{Val: device.Id}}, |
| 374 | {Key: "port", Value: port}, |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 375 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 376 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 377 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 378 | } |
| 379 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 380 | func (ap *AdapterProxy) EnablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 381 | logger.Debugw(ctx, "EnablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 382 | rpc := "enable_port" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 383 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 384 | if err != nil { |
| 385 | return nil, err |
| 386 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 387 | args := []*kafka.KVArg{ |
| 388 | {Key: "deviceId", Value: &ic.StrType{Val: device.Id}}, |
| 389 | {Key: "port", Value: port}, |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 390 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 391 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 392 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 393 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 394 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 395 | // ChildDeviceLost invokes child device_lost rpc |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 396 | func (ap *AdapterProxy) ChildDeviceLost(ctx context.Context, deviceType string, childDevice *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 397 | logger.Debugw(ctx, "ChildDeviceLost", |
| 398 | log.Fields{"device-id": childDevice.ParentId, "parent-port-no": childDevice.ParentPortNo, |
| 399 | "onu-id": childDevice.ProxyAddress.OnuId, "serial-number": childDevice.SerialNumber}) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 400 | rpc := "child_device_lost" |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 401 | toTopic, err := ap.getAdapterTopic(ctx, childDevice.ParentId, deviceType) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 402 | if err != nil { |
| 403 | return nil, err |
| 404 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 405 | args := []*kafka.KVArg{ |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 406 | {Key: "childDevice", Value: childDevice}, |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 407 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 408 | replyToTopic := ap.getCoreTopic() |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 409 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, childDevice.ParentId, args...) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 410 | } |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 411 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 412 | func (ap *AdapterProxy) StartOmciTest(ctx context.Context, device *voltha.Device, omcitestrequest *voltha.OmciTestRequest) (chan *kafka.RpcResponse, error) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 413 | logger.Debugw(ctx, "Omci_test_Request_adapter_proxy", log.Fields{"device": device, "omciTestRequest": omcitestrequest}) |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 414 | rpc := "start_omci_test" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 415 | toTopic, err := ap.getAdapterTopic(ctx, device.Id, device.Adapter) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 416 | if err != nil { |
| 417 | return nil, err |
| 418 | } |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 419 | // Use a device specific topic as we are the only core handling requests for this device |
| 420 | replyToTopic := ap.getCoreTopic() |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 421 | // TODO: Perhaps this should have used omcitestrequest.uuid as the second argument rather |
| 422 | // than including the whole request, which is (deviceid, uuid) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 423 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 424 | &kafka.KVArg{Key: "device", Value: device}, |
| 425 | &kafka.KVArg{Key: "omcitestrequest", Value: omcitestrequest}) |
| 426 | } |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 427 | |
| 428 | func (ap *AdapterProxy) GetExtValue(ctx context.Context, pdevice *voltha.Device, cdevice *voltha.Device, id string, valuetype voltha.ValueType_Type) (chan *kafka.RpcResponse, error) { |
Girish Kumar | 3e8ee21 | 2020-08-19 17:50:11 +0000 | [diff] [blame] | 429 | logger.Debugw(ctx, "GetExtValue", log.Fields{"device-id": pdevice.Id, "onuid": id}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 430 | rpc := "get_ext_value" |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 431 | toTopic, err := ap.getAdapterTopic(ctx, pdevice.Id, pdevice.Adapter) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 432 | if err != nil { |
| 433 | return nil, err |
| 434 | } |
| 435 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 436 | // specific topic |
| 437 | args := []*kafka.KVArg{ |
| 438 | { |
| 439 | Key: "pDeviceId", |
| 440 | Value: &ic.StrType{Val: pdevice.Id}, |
| 441 | }, |
| 442 | { |
| 443 | Key: "device", |
| 444 | Value: cdevice, |
| 445 | }, |
| 446 | { |
| 447 | Key: "valuetype", |
| 448 | Value: &ic.IntType{Val: int64(valuetype)}, |
| 449 | }} |
| 450 | |
| 451 | replyToTopic := ap.getCoreTopic() |
| 452 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, pdevice.Id, args...) |
| 453 | } |
dpaul | 6268631 | 2020-06-23 14:17:36 +0530 | [diff] [blame] | 454 | |
| 455 | // SetExtValue set some given configs or value |
| 456 | func (ap *AdapterProxy) SetExtValue(ctx context.Context, device *voltha.Device, value *voltha.ValueSet) (chan *kafka.RpcResponse, error) { |
| 457 | logger.Debugw(ctx, "SetExtValue", log.Fields{"device-id": value.Id}) |
| 458 | rpc := "set_ext_value" |
| 459 | toTopic, err := ap.getAdapterTopic(ctx, value.Id, device.Adapter) |
| 460 | if err != nil { |
| 461 | return nil, err |
| 462 | } |
| 463 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 464 | // specific topic |
| 465 | args := []*kafka.KVArg{ |
| 466 | { |
| 467 | Key: "value", |
| 468 | Value: value, |
| 469 | }, |
| 470 | } |
| 471 | replyToTopic := ap.getCoreTopic() |
| 472 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, value.Id, args...) |
| 473 | } |
Salman Siddiqui | 1cf9504 | 2020-11-19 00:42:56 +0530 | [diff] [blame] | 474 | |
| 475 | // GetSingleValue get a value from the adapter, based on the request type |
| 476 | func (ap *AdapterProxy) GetSingleValue(ctx context.Context, adapterType string, request *extension.SingleGetValueRequest) (chan *kafka.RpcResponse, error) { |
| 477 | logger.Debugw(ctx, "GetSingleValue", log.Fields{"device-id": request.TargetId}) |
| 478 | rpc := "single_get_value_request" |
| 479 | toTopic, err := ap.getAdapterTopic(ctx, request.TargetId, adapterType) |
| 480 | if err != nil { |
| 481 | return nil, err |
| 482 | } |
| 483 | |
| 484 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 485 | // specific topic |
| 486 | args := []*kafka.KVArg{ |
| 487 | { |
| 488 | Key: "request", |
| 489 | Value: request, |
| 490 | }, |
| 491 | } |
| 492 | |
| 493 | replyToTopic := ap.getCoreTopic() |
| 494 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, request.TargetId, args...) |
| 495 | } |
| 496 | |
| 497 | // SetSingleValue set a single value on the adapter, based on the request type |
| 498 | func (ap *AdapterProxy) SetSingleValue(ctx context.Context, adapterType string, request *extension.SingleSetValueRequest) (chan *kafka.RpcResponse, error) { |
| 499 | logger.Debugw(ctx, "SetSingleValue", log.Fields{"device-id": request.TargetId}) |
| 500 | rpc := "single_set_value_request" |
| 501 | toTopic, err := ap.getAdapterTopic(ctx, request.TargetId, adapterType) |
| 502 | if err != nil { |
| 503 | return nil, err |
| 504 | } |
| 505 | |
| 506 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 507 | // specific topic |
| 508 | args := []*kafka.KVArg{ |
| 509 | { |
| 510 | Key: "request", |
| 511 | Value: request, |
| 512 | }, |
| 513 | } |
| 514 | |
| 515 | replyToTopic := ap.getCoreTopic() |
| 516 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, request.TargetId, args...) |
| 517 | } |