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