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 | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 21 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 22 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 23 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 24 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 25 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 26 | ) |
| 27 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 28 | // AdapterProxy represents adapter proxy attributes |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 29 | type AdapterProxy struct { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 30 | kafka.EndpointManager |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 31 | deviceTopicRegistered bool |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 32 | corePairTopic string |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 33 | kafkaICProxy kafka.InterContainerProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 34 | } |
| 35 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 36 | // NewAdapterProxy will return adapter proxy instance |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 37 | func NewAdapterProxy(kafkaProxy kafka.InterContainerProxy, corePairTopic string, endpointManager kafka.EndpointManager) *AdapterProxy { |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 38 | return &AdapterProxy{ |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 39 | EndpointManager: endpointManager, |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 40 | kafkaICProxy: kafkaProxy, |
| 41 | corePairTopic: corePairTopic, |
| 42 | deviceTopicRegistered: false, |
| 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 { |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 47 | return kafka.Topic{Name: ap.corePairTopic} |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 50 | func (ap *AdapterProxy) getAdapterTopic(deviceID string, adapterType string) (*kafka.Topic, error) { |
| 51 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 52 | endpoint, err := ap.GetEndpoint(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 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 69 | logger.Errorw("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) { |
| 78 | logger.Debugw("AdoptDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 79 | rpc := "adopt_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 80 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 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() |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 88 | ap.deviceTopicRegistered = true |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 89 | logger.Debugw("adoptDevice-send-request", log.Fields{"device-id": device.Id, "deviceType": device.Type, "serialNumber": device.SerialNumber}) |
| 90 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 93 | // DisableDevice invokes disable device rpc |
| 94 | func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 95 | logger.Debugw("DisableDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 96 | rpc := "disable_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 97 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 101 | args := []*kafka.KVArg{ |
| 102 | {Key: "device", Value: device}, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 103 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 104 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 105 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 108 | // ReEnableDevice invokes reenable device rpc |
| 109 | func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 110 | logger.Debugw("ReEnableDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 111 | rpc := "reenable_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 112 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 116 | args := []*kafka.KVArg{ |
| 117 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 118 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 119 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 120 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 123 | // RebootDevice invokes reboot device rpc |
| 124 | func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 125 | logger.Debugw("RebootDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 126 | rpc := "reboot_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 127 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 131 | args := []*kafka.KVArg{ |
| 132 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 133 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 134 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 135 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 138 | // DeleteDevice invokes delete device rpc |
| 139 | func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 140 | logger.Debugw("DeleteDevice", log.Fields{"device-id": device.Id}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 141 | rpc := "delete_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 142 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 143 | if err != nil { |
| 144 | return nil, err |
| 145 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 146 | args := []*kafka.KVArg{ |
| 147 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 148 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 149 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 150 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 153 | // GetOfpDeviceInfo invokes get ofp device info rpc |
| 154 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 155 | logger.Debugw("GetOfpDeviceInfo", log.Fields{"device-id": device.Id}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 156 | rpc := "get_ofp_device_info" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 157 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 161 | args := []*kafka.KVArg{ |
| 162 | {Key: "device", Value: device}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 163 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 164 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 165 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 168 | // GetOfpPortInfo invokes get ofp port info rpc |
| 169 | func (ap *AdapterProxy) GetOfpPortInfo(ctx context.Context, device *voltha.Device, portNo uint32) (chan *kafka.RpcResponse, error) { |
| 170 | logger.Debugw("GetOfpPortInfo", log.Fields{"device-id": device.Id, "port-no": portNo}) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 171 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 172 | if err != nil { |
| 173 | return nil, err |
| 174 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 175 | args := []*kafka.KVArg{ |
| 176 | {Key: "device", Value: device}, |
| 177 | {Key: "port_no", Value: &ic.IntType{Val: int64(portNo)}}, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 178 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 179 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 180 | return ap.sendRPC(ctx, "get_ofp_port_info", toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 183 | // ReconcileDevice invokes reconcile device rpc |
| 184 | func (ap *AdapterProxy) ReconcileDevice(ctx context.Context, device *voltha.Device) (chan *kafka.RpcResponse, error) { |
| 185 | logger.Debugw("ReconcileDevice", log.Fields{"device-id": device.Id}) |
Matt Jeanneret | 7cf8e0b | 2020-01-09 11:57:51 -0500 | [diff] [blame] | 186 | rpc := "reconcile_device" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 187 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 188 | if err != nil { |
| 189 | return nil, err |
| 190 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 191 | args := []*kafka.KVArg{ |
| 192 | {Key: "device", Value: device}, |
| 193 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [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 | // DownloadImage invokes download image rpc |
| 199 | func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
| 200 | logger.Debugw("DownloadImage", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 201 | rpc := "download_image" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 202 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 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 | // GetImageDownloadStatus invokes get image download status rpc |
| 215 | func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
| 216 | logger.Debugw("GetImageDownloadStatus", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 217 | rpc := "get_image_download_status" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 218 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 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 | // CancelImageDownload invokes cancel image download rpc |
| 231 | func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
| 232 | logger.Debugw("CancelImageDownload", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 233 | rpc := "cancel_image_download" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 234 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 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 | // ActivateImageUpdate invokes activate image update rpc |
| 247 | func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
| 248 | logger.Debugw("ActivateImageUpdate", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 249 | rpc := "activate_image_update" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 250 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 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 | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 262 | // RevertImageUpdate invokes revert image update rpc |
| 263 | func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (chan *kafka.RpcResponse, error) { |
| 264 | logger.Debugw("RevertImageUpdate", log.Fields{"device-id": device.Id, "image": download.Name}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 265 | rpc := "revert_image_update" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 266 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 267 | if err != nil { |
| 268 | return nil, err |
| 269 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 270 | args := []*kafka.KVArg{ |
| 271 | {Key: "device", Value: device}, |
| 272 | {Key: "request", Value: download}, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -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, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 278 | func (ap *AdapterProxy) PacketOut(ctx context.Context, deviceType string, deviceID string, outPort uint32, packet *openflow_13.OfpPacketOut) (chan *kafka.RpcResponse, error) { |
| 279 | logger.Debugw("PacketOut", log.Fields{"device-id": deviceID, "device-type": deviceType, "out-port": outPort}) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 280 | toTopic, err := ap.getAdapterTopic(deviceID, deviceType) |
| 281 | if err != nil { |
| 282 | return nil, err |
| 283 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 284 | rpc := "receive_packet_out" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 285 | args := []*kafka.KVArg{ |
| 286 | {Key: "deviceId", Value: &ic.StrType{Val: deviceID}}, |
| 287 | {Key: "outPort", Value: &ic.IntType{Val: int64(outPort)}}, |
| 288 | {Key: "packet", Value: packet}, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 289 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 290 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 291 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, deviceID, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 292 | } |
| 293 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 294 | // UpdateFlowsBulk invokes update flows bulk rpc |
| 295 | func (ap *AdapterProxy) UpdateFlowsBulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) (chan *kafka.RpcResponse, error) { |
| 296 | logger.Debugw("UpdateFlowsBulk", log.Fields{"device-id": device.Id, "flow-count": len(flows.Items), "group-count": len(groups.Items), "flow-metadata": flowMetadata}) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 297 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 298 | if err != nil { |
| 299 | return nil, err |
| 300 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 301 | rpc := "update_flows_bulk" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 302 | args := []*kafka.KVArg{ |
| 303 | {Key: "device", Value: device}, |
| 304 | {Key: "flows", Value: flows}, |
| 305 | {Key: "groups", Value: groups}, |
| 306 | {Key: "flow_metadata", Value: flowMetadata}, |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 307 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 308 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 309 | return ap.sendRPC(context.TODO(), rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 312 | // UpdateFlowsIncremental invokes update flows incremental rpc |
| 313 | func (ap *AdapterProxy) UpdateFlowsIncremental(ctx context.Context, device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) (chan *kafka.RpcResponse, error) { |
| 314 | logger.Debugw("UpdateFlowsIncremental", |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 315 | log.Fields{ |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 316 | "device-id": device.Id, |
| 317 | "flow-to-add-count": len(flowChanges.ToAdd.Items), |
| 318 | "flow-to-delete-count": len(flowChanges.ToRemove.Items), |
| 319 | "group-to-add-count": len(groupChanges.ToAdd.Items), |
| 320 | "group-to-delete-count": len(groupChanges.ToRemove.Items), |
| 321 | "group-to-update-count": len(groupChanges.ToUpdate.Items), |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 322 | }) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 323 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 324 | if err != nil { |
| 325 | return nil, err |
| 326 | } |
Matt Jeanneret | b003742 | 2019-03-23 14:36:51 -0400 | [diff] [blame] | 327 | rpc := "update_flows_incrementally" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 328 | args := []*kafka.KVArg{ |
| 329 | {Key: "device", Value: device}, |
| 330 | {Key: "flow_changes", Value: flowChanges}, |
| 331 | {Key: "group_changes", Value: groupChanges}, |
| 332 | {Key: "flow_metadata", Value: flowMetadata}, |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 333 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 334 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 335 | return ap.sendRPC(context.TODO(), rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 338 | // UpdatePmConfigs invokes update pm configs rpc |
| 339 | func (ap *AdapterProxy) UpdatePmConfigs(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) (chan *kafka.RpcResponse, error) { |
| 340 | logger.Debugw("UpdatePmConfigs", log.Fields{"device-id": device.Id, "pm-configs-id": pmConfigs.Id}) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 341 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 342 | if err != nil { |
| 343 | return nil, err |
| 344 | } |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 345 | rpc := "Update_pm_config" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 346 | args := []*kafka.KVArg{ |
| 347 | {Key: "device", Value: device}, |
| 348 | {Key: "pm_configs", Value: pmConfigs}, |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 349 | } |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 350 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 351 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 354 | // SimulateAlarm invokes simulate alarm rpc |
| 355 | func (ap *AdapterProxy) SimulateAlarm(ctx context.Context, device *voltha.Device, simulateReq *voltha.SimulateAlarmRequest) (chan *kafka.RpcResponse, error) { |
| 356 | logger.Debugw("SimulateAlarm", log.Fields{"device-id": device.Id, "simulate-req-id": simulateReq.Id}) |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 357 | rpc := "simulate_alarm" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 358 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 359 | if err != nil { |
| 360 | return nil, err |
| 361 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 362 | args := []*kafka.KVArg{ |
| 363 | {Key: "device", Value: device}, |
| 364 | {Key: "request", Value: simulateReq}, |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 365 | } |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 366 | replyToTopic := ap.getCoreTopic() |
| 367 | ap.deviceTopicRegistered = true |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 368 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 369 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 370 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 371 | func (ap *AdapterProxy) DisablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) (chan *kafka.RpcResponse, error) { |
| 372 | logger.Debugw("DisablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 373 | rpc := "disable_port" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 374 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 375 | if err != nil { |
| 376 | return nil, err |
| 377 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 378 | args := []*kafka.KVArg{ |
| 379 | {Key: "deviceId", Value: &ic.StrType{Val: device.Id}}, |
| 380 | {Key: "port", Value: port}, |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 381 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 382 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 383 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 386 | func (ap *AdapterProxy) EnablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) (chan *kafka.RpcResponse, error) { |
| 387 | logger.Debugw("EnablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 388 | rpc := "enable_port" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 389 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 390 | if err != nil { |
| 391 | return nil, err |
| 392 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 393 | args := []*kafka.KVArg{ |
| 394 | {Key: "deviceId", Value: &ic.StrType{Val: device.Id}}, |
| 395 | {Key: "port", Value: port}, |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 396 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 397 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 398 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 399 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 400 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 401 | // ChildDeviceLost invokes child device_lost rpc |
| 402 | func (ap *AdapterProxy) ChildDeviceLost(ctx context.Context, deviceType string, deviceID string, pPortNo uint32, onuID uint32) (chan *kafka.RpcResponse, error) { |
| 403 | logger.Debugw("ChildDeviceLost", log.Fields{"device-id": deviceID, "parent-port-no": pPortNo, "onu-id": onuID}) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 404 | rpc := "child_device_lost" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 405 | toTopic, err := ap.getAdapterTopic(deviceID, deviceType) |
| 406 | if err != nil { |
| 407 | return nil, err |
| 408 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 409 | args := []*kafka.KVArg{ |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 410 | {Key: "pDeviceId", Value: &ic.StrType{Val: deviceID}}, |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 411 | {Key: "pPortNo", Value: &ic.IntType{Val: int64(pPortNo)}}, |
| 412 | {Key: "onuID", Value: &ic.IntType{Val: int64(onuID)}}, |
| 413 | } |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 414 | replyToTopic := ap.getCoreTopic() |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 415 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, deviceID, args...) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 416 | } |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 417 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame^] | 418 | func (ap *AdapterProxy) StartOmciTest(ctx context.Context, device *voltha.Device, omcitestrequest *voltha.OmciTestRequest) (chan *kafka.RpcResponse, error) { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 419 | logger.Debugw("Omci_test_Request_adapter_proxy", log.Fields{"device": device, "omciTestRequest": omcitestrequest}) |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 420 | rpc := "start_omci_test" |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 421 | toTopic, err := ap.getAdapterTopic(device.Id, device.Adapter) |
| 422 | if err != nil { |
| 423 | return nil, err |
| 424 | } |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 425 | // Use a device specific topic as we are the only core handling requests for this device |
| 426 | replyToTopic := ap.getCoreTopic() |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 427 | // TODO: Perhaps this should have used omcitestrequest.uuid as the second argument rather |
| 428 | // than including the whole request, which is (deviceid, uuid) |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 429 | return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, |
onkarkundargi | 8728525 | 2020-01-27 11:34:52 +0530 | [diff] [blame] | 430 | &kafka.KVArg{Key: "device", Value: device}, |
| 431 | &kafka.KVArg{Key: "omcitestrequest", Value: omcitestrequest}) |
| 432 | } |