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