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