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 | */ |
| 16 | package core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "github.com/golang/protobuf/ptypes" |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 21 | a "github.com/golang/protobuf/ptypes/any" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 22 | "github.com/opencord/voltha-go/common/log" |
| 23 | "github.com/opencord/voltha-go/kafka" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame^] | 24 | ic "github.com/opencord/voltha-protos/go/inter_container" |
| 25 | "github.com/opencord/voltha-protos/go/openflow_13" |
| 26 | "github.com/opencord/voltha-protos/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 27 | "google.golang.org/grpc/codes" |
| 28 | "google.golang.org/grpc/status" |
| 29 | ) |
| 30 | |
| 31 | type AdapterProxy struct { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 32 | TestMode bool |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 33 | deviceTopicRegistered bool |
| 34 | coreTopic *kafka.Topic |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 35 | kafkaICProxy *kafka.InterContainerProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 36 | } |
| 37 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 38 | func NewAdapterProxy(kafkaProxy *kafka.InterContainerProxy) *AdapterProxy { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 39 | var proxy AdapterProxy |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 40 | proxy.kafkaICProxy = kafkaProxy |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 41 | proxy.deviceTopicRegistered = false |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 42 | return &proxy |
| 43 | } |
| 44 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 45 | func unPackResponse(rpc string, deviceId string, success bool, response *a.Any) error { |
| 46 | if success { |
| 47 | return nil |
| 48 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 49 | unpackResult := &ic.Error{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 50 | var err error |
| 51 | if err = ptypes.UnmarshalAny(response, unpackResult); err != nil { |
| 52 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 53 | return err |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 54 | } |
| 55 | log.Debugw("response", log.Fields{"rpc": rpc, "deviceId": deviceId, "success": success, "error": err}) |
| 56 | // TODO: Need to get the real error code |
| 57 | return status.Errorf(codes.Canceled, "%s", unpackResult.Reason) |
| 58 | } |
| 59 | } |
| 60 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 61 | func (ap *AdapterProxy) updateCoreTopic(coreTopic *kafka.Topic) { |
| 62 | ap.coreTopic = coreTopic |
| 63 | } |
| 64 | |
| 65 | func (ap *AdapterProxy) getCoreTopic() kafka.Topic{ |
| 66 | if ap.coreTopic != nil { |
| 67 | return *ap.coreTopic |
| 68 | } |
| 69 | return kafka.Topic{Name:ap.kafkaICProxy.DefaultTopic.Name} |
| 70 | } |
| 71 | |
| 72 | func (ap *AdapterProxy) getAdapterTopic(adapterName string) kafka.Topic{ |
| 73 | return kafka.Topic{Name: adapterName} |
| 74 | } |
| 75 | |
| 76 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 77 | func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) error { |
| 78 | log.Debugw("AdoptDevice", log.Fields{"device": device}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 79 | rpc := "adopt_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 80 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 81 | //topic := kafka.Topic{Name: device.Adapter} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 82 | args := make([]*kafka.KVArg, 1) |
| 83 | args[0] = &kafka.KVArg{ |
| 84 | Key: "device", |
| 85 | Value: device, |
| 86 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 87 | // Use a device topic for the response as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 88 | replyToTopic := ap.getCoreTopic() |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 89 | ap.deviceTopicRegistered = true |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 90 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 91 | log.Debugw("AdoptDevice-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 92 | return unPackResponse(rpc, device.Id, success, result) |
| 93 | } |
| 94 | |
| 95 | func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) error { |
| 96 | log.Debugw("DisableDevice", log.Fields{"deviceId": device.Id}) |
| 97 | rpc := "disable_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 98 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 99 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 100 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 101 | // specific topic |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 102 | //toTopic := kafka.CreateSubTopic(device.Adapter, device.Id) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 103 | args := make([]*kafka.KVArg, 1) |
| 104 | args[0] = &kafka.KVArg{ |
| 105 | Key: "device", |
| 106 | Value: device, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 107 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 108 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 109 | //replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 110 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 111 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 112 | log.Debugw("DisableDevice-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 113 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 114 | } |
| 115 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 116 | func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) error { |
| 117 | log.Debugw("ReEnableDevice", log.Fields{"deviceId": device.Id}) |
| 118 | rpc := "reenable_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 119 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 120 | args := make([]*kafka.KVArg, 1) |
| 121 | args[0] = &kafka.KVArg{ |
| 122 | Key: "device", |
| 123 | Value: device, |
| 124 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 125 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 126 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 127 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 128 | log.Debugw("ReEnableDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 129 | return unPackResponse(rpc, device.Id, success, result) |
| 130 | } |
| 131 | |
| 132 | func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) error { |
| 133 | log.Debugw("RebootDevice", log.Fields{"deviceId": device.Id}) |
| 134 | rpc := "reboot_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 135 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 136 | args := make([]*kafka.KVArg, 1) |
| 137 | args[0] = &kafka.KVArg{ |
| 138 | Key: "device", |
| 139 | Value: device, |
| 140 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 141 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 142 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 143 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 144 | log.Debugw("RebootDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 145 | return unPackResponse(rpc, device.Id, success, result) |
| 146 | } |
| 147 | |
| 148 | func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) error { |
| 149 | log.Debugw("DeleteDevice", log.Fields{"deviceId": device.Id}) |
| 150 | rpc := "delete_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 151 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 152 | args := make([]*kafka.KVArg, 1) |
| 153 | args[0] = &kafka.KVArg{ |
| 154 | Key: "device", |
| 155 | Value: device, |
| 156 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 157 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 158 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 159 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 160 | log.Debugw("DeleteDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 161 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 162 | return unPackResponse(rpc, device.Id, success, result) |
| 163 | } |
| 164 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 165 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 166 | log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 167 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 168 | args := make([]*kafka.KVArg, 1) |
| 169 | args[0] = &kafka.KVArg{ |
| 170 | Key: "device", |
| 171 | Value: device, |
| 172 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 173 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 174 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 175 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_device_info", &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 176 | log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result}) |
| 177 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 178 | unpackResult := &ic.SwitchCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 179 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 180 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 181 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 182 | } |
| 183 | return unpackResult, nil |
| 184 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 185 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 186 | var err error |
| 187 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 188 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 189 | } |
| 190 | log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 191 | // TODO: Need to get the real error code |
| 192 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 193 | } |
| 194 | } |
| 195 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 196 | func (ap *AdapterProxy) GetOfpPortInfo(ctx context.Context, device *voltha.Device, portNo uint32) (*ic.PortCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 197 | log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 198 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 199 | args := make([]*kafka.KVArg, 2) |
| 200 | args[0] = &kafka.KVArg{ |
| 201 | Key: "device", |
| 202 | Value: device, |
| 203 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 204 | pNo := &ic.IntType{Val: int64(portNo)} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 205 | args[1] = &kafka.KVArg{ |
| 206 | Key: "port_no", |
| 207 | Value: pNo, |
| 208 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 209 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 210 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 211 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_port_info", &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 212 | log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 213 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 214 | unpackResult := &ic.PortCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 215 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 216 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 217 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 218 | } |
| 219 | return unpackResult, nil |
| 220 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 221 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 222 | var err error |
| 223 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 224 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 225 | } |
| 226 | log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 227 | // TODO: Need to get the real error code |
| 228 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | //TODO: Implement the functions below |
| 233 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 234 | func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) { |
| 235 | log.Debug("AdapterDescriptor") |
| 236 | return nil, nil |
| 237 | } |
| 238 | |
| 239 | func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) { |
| 240 | log.Debug("DeviceTypes") |
| 241 | return nil, nil |
| 242 | } |
| 243 | |
| 244 | func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) { |
| 245 | log.Debug("Health") |
| 246 | return nil, nil |
| 247 | } |
| 248 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 249 | func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 250 | log.Debug("ReconcileDevice") |
| 251 | return nil |
| 252 | } |
| 253 | |
| 254 | func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error { |
| 255 | log.Debug("AbandonDevice") |
| 256 | return nil |
| 257 | } |
| 258 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 259 | func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) { |
| 260 | log.Debug("GetDeviceDetails") |
| 261 | return nil, nil |
| 262 | } |
| 263 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 264 | func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 265 | log.Debugw("DownloadImage", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 266 | rpc := "download_image" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 267 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 268 | args := make([]*kafka.KVArg, 2) |
| 269 | args[0] = &kafka.KVArg{ |
| 270 | Key: "device", |
| 271 | Value: device, |
| 272 | } |
| 273 | args[1] = &kafka.KVArg{ |
| 274 | Key: "request", |
| 275 | Value: download, |
| 276 | } |
| 277 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 278 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 279 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 280 | log.Debugw("DownloadImage-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 281 | |
| 282 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 283 | } |
| 284 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 285 | func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 286 | log.Debugw("GetImageDownloadStatus", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 287 | rpc := "get_image_download_status" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 288 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 289 | args := make([]*kafka.KVArg, 2) |
| 290 | args[0] = &kafka.KVArg{ |
| 291 | Key: "device", |
| 292 | Value: device, |
| 293 | } |
| 294 | args[1] = &kafka.KVArg{ |
| 295 | Key: "request", |
| 296 | Value: download, |
| 297 | } |
| 298 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 299 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 300 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 301 | log.Debugw("GetImageDownloadStatus-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 302 | |
| 303 | if success { |
| 304 | unpackResult := &voltha.ImageDownload{} |
| 305 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 306 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 307 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 308 | } |
| 309 | return unpackResult, nil |
| 310 | } else { |
| 311 | unpackResult := &ic.Error{} |
| 312 | var err error |
| 313 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 314 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 315 | return nil, err |
| 316 | } |
| 317 | log.Debugw("GetImageDownloadStatus-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 318 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 319 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 320 | } |
| 321 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 322 | func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 323 | log.Debugw("CancelImageDownload", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 324 | rpc := "cancel_image_download" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 325 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 326 | args := make([]*kafka.KVArg, 2) |
| 327 | args[0] = &kafka.KVArg{ |
| 328 | Key: "device", |
| 329 | Value: device, |
| 330 | } |
| 331 | args[1] = &kafka.KVArg{ |
| 332 | Key: "request", |
| 333 | Value: download, |
| 334 | } |
| 335 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 336 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 337 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 338 | log.Debugw("CancelImageDownload-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 339 | |
| 340 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 341 | } |
| 342 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 343 | func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 344 | log.Debugw("ActivateImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 345 | rpc := "activate_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 346 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 347 | args := make([]*kafka.KVArg, 2) |
| 348 | args[0] = &kafka.KVArg{ |
| 349 | Key: "device", |
| 350 | Value: device, |
| 351 | } |
| 352 | args[1] = &kafka.KVArg{ |
| 353 | Key: "request", |
| 354 | Value: download, |
| 355 | } |
| 356 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 357 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 358 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 359 | log.Debugw("ActivateImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 360 | |
| 361 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 362 | } |
| 363 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 364 | func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 365 | log.Debugw("RevertImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 366 | rpc := "revert_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 367 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 368 | args := make([]*kafka.KVArg, 2) |
| 369 | args[0] = &kafka.KVArg{ |
| 370 | Key: "device", |
| 371 | Value: device, |
| 372 | } |
| 373 | args[1] = &kafka.KVArg{ |
| 374 | Key: "request", |
| 375 | Value: download, |
| 376 | } |
| 377 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 378 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 379 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 380 | log.Debugw("RevertImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 381 | |
| 382 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) { |
| 386 | log.Debug("SelfTestDevice") |
| 387 | return nil, nil |
| 388 | } |
| 389 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 390 | func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error { |
| 391 | log.Debugw("packetOut", log.Fields{"deviceId": deviceId}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 392 | toTopic := ap.getAdapterTopic(deviceType) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 393 | rpc := "receive_packet_out" |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 394 | dId := &ic.StrType{Val: deviceId} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 395 | args := make([]*kafka.KVArg, 3) |
| 396 | args[0] = &kafka.KVArg{ |
| 397 | Key: "deviceId", |
| 398 | Value: dId, |
| 399 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 400 | op := &ic.IntType{Val: int64(outPort)} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 401 | args[1] = &kafka.KVArg{ |
| 402 | Key: "outPort", |
| 403 | Value: op, |
| 404 | } |
| 405 | args[2] = &kafka.KVArg{ |
| 406 | Key: "packet", |
| 407 | Value: packet, |
| 408 | } |
| 409 | |
| 410 | // TODO: Do we need to wait for an ACK on a packet Out? |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 411 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 412 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 413 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 414 | log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success}) |
| 415 | return unPackResponse(rpc, deviceId, success, result) |
| 416 | } |
| 417 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 418 | func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error { |
| 419 | log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 420 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 421 | rpc := "update_flows_bulk" |
| 422 | args := make([]*kafka.KVArg, 3) |
| 423 | args[0] = &kafka.KVArg{ |
| 424 | Key: "device", |
| 425 | Value: device, |
| 426 | } |
| 427 | args[1] = &kafka.KVArg{ |
| 428 | Key: "flows", |
| 429 | Value: flows, |
| 430 | } |
| 431 | args[2] = &kafka.KVArg{ |
| 432 | Key: "groups", |
| 433 | Value: groups, |
| 434 | } |
| 435 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 436 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 437 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 438 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 439 | log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 440 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 441 | } |
| 442 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 443 | func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error { |
| 444 | log.Debugw("UpdateFlowsIncremental", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 445 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 446 | rpc := "update_flows_bulk" |
| 447 | args := make([]*kafka.KVArg, 3) |
| 448 | args[0] = &kafka.KVArg{ |
| 449 | Key: "device", |
| 450 | Value: device, |
| 451 | } |
| 452 | args[1] = &kafka.KVArg{ |
| 453 | Key: "flow_changes", |
| 454 | Value: flowChanges, |
| 455 | } |
| 456 | args[2] = &kafka.KVArg{ |
| 457 | Key: "group_changes", |
| 458 | Value: groupChanges, |
| 459 | } |
| 460 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 461 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 462 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 463 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 464 | log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 465 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | func (ap *AdapterProxy) UpdatePmConfig(device voltha.Device, pmConfigs voltha.PmConfigs) error { |
| 469 | log.Debug("UpdatePmConfig") |
| 470 | return nil |
| 471 | } |
| 472 | |
| 473 | func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error { |
| 474 | log.Debug("ReceivePacketOut") |
| 475 | return nil |
| 476 | } |
| 477 | |
| 478 | func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error { |
| 479 | log.Debug("SuppressAlarm") |
| 480 | return nil |
| 481 | } |
| 482 | |
| 483 | func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error { |
| 484 | log.Debug("UnSuppressAlarm") |
| 485 | return nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 486 | } |