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 | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 242 | func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 243 | log.Debug("ReconcileDevice") |
| 244 | return nil |
| 245 | } |
| 246 | |
| 247 | func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error { |
| 248 | log.Debug("AbandonDevice") |
| 249 | return nil |
| 250 | } |
| 251 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 252 | func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) { |
| 253 | log.Debug("GetDeviceDetails") |
| 254 | return nil, nil |
| 255 | } |
| 256 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 257 | func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 258 | log.Debugw("DownloadImage", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 259 | rpc := "download_image" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 260 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 261 | args := make([]*kafka.KVArg, 2) |
| 262 | args[0] = &kafka.KVArg{ |
| 263 | Key: "device", |
| 264 | Value: device, |
| 265 | } |
| 266 | args[1] = &kafka.KVArg{ |
| 267 | Key: "request", |
| 268 | Value: download, |
| 269 | } |
| 270 | // 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] | 271 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 272 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 273 | log.Debugw("DownloadImage-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 274 | |
| 275 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 276 | } |
| 277 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 278 | func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 279 | log.Debugw("GetImageDownloadStatus", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 280 | rpc := "get_image_download_status" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 281 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 282 | args := make([]*kafka.KVArg, 2) |
| 283 | args[0] = &kafka.KVArg{ |
| 284 | Key: "device", |
| 285 | Value: device, |
| 286 | } |
| 287 | args[1] = &kafka.KVArg{ |
| 288 | Key: "request", |
| 289 | Value: download, |
| 290 | } |
| 291 | // 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] | 292 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 293 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 294 | log.Debugw("GetImageDownloadStatus-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 295 | |
| 296 | if success { |
| 297 | unpackResult := &voltha.ImageDownload{} |
| 298 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 299 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 300 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 301 | } |
| 302 | return unpackResult, nil |
| 303 | } else { |
| 304 | unpackResult := &ic.Error{} |
| 305 | var err error |
| 306 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 307 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 308 | return nil, err |
| 309 | } |
| 310 | log.Debugw("GetImageDownloadStatus-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 311 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 312 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 313 | } |
| 314 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 315 | func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 316 | log.Debugw("CancelImageDownload", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 317 | rpc := "cancel_image_download" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 318 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 319 | args := make([]*kafka.KVArg, 2) |
| 320 | args[0] = &kafka.KVArg{ |
| 321 | Key: "device", |
| 322 | Value: device, |
| 323 | } |
| 324 | args[1] = &kafka.KVArg{ |
| 325 | Key: "request", |
| 326 | Value: download, |
| 327 | } |
| 328 | // 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] | 329 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 330 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 331 | log.Debugw("CancelImageDownload-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 332 | |
| 333 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 334 | } |
| 335 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 336 | func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 337 | log.Debugw("ActivateImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 338 | rpc := "activate_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 339 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 340 | args := make([]*kafka.KVArg, 2) |
| 341 | args[0] = &kafka.KVArg{ |
| 342 | Key: "device", |
| 343 | Value: device, |
| 344 | } |
| 345 | args[1] = &kafka.KVArg{ |
| 346 | Key: "request", |
| 347 | Value: download, |
| 348 | } |
| 349 | // 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] | 350 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 351 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 352 | log.Debugw("ActivateImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 353 | |
| 354 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 355 | } |
| 356 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 357 | func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 358 | log.Debugw("RevertImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 359 | rpc := "revert_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 360 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 361 | args := make([]*kafka.KVArg, 2) |
| 362 | args[0] = &kafka.KVArg{ |
| 363 | Key: "device", |
| 364 | Value: device, |
| 365 | } |
| 366 | args[1] = &kafka.KVArg{ |
| 367 | Key: "request", |
| 368 | Value: download, |
| 369 | } |
| 370 | // 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] | 371 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 372 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 373 | log.Debugw("RevertImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 374 | |
| 375 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) { |
| 379 | log.Debug("SelfTestDevice") |
| 380 | return nil, nil |
| 381 | } |
| 382 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 383 | func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error { |
| 384 | log.Debugw("packetOut", log.Fields{"deviceId": deviceId}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 385 | toTopic := ap.getAdapterTopic(deviceType) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 386 | rpc := "receive_packet_out" |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 387 | dId := &ic.StrType{Val: deviceId} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 388 | args := make([]*kafka.KVArg, 3) |
| 389 | args[0] = &kafka.KVArg{ |
| 390 | Key: "deviceId", |
| 391 | Value: dId, |
| 392 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 393 | op := &ic.IntType{Val: int64(outPort)} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 394 | args[1] = &kafka.KVArg{ |
| 395 | Key: "outPort", |
| 396 | Value: op, |
| 397 | } |
| 398 | args[2] = &kafka.KVArg{ |
| 399 | Key: "packet", |
| 400 | Value: packet, |
| 401 | } |
| 402 | |
| 403 | // TODO: Do we need to wait for an ACK on a packet Out? |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 404 | // 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] | 405 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 406 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 407 | log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success}) |
| 408 | return unPackResponse(rpc, deviceId, success, result) |
| 409 | } |
| 410 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 411 | func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 412 | 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] | 413 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 414 | rpc := "update_flows_bulk" |
| 415 | args := make([]*kafka.KVArg, 3) |
| 416 | args[0] = &kafka.KVArg{ |
| 417 | Key: "device", |
| 418 | Value: device, |
| 419 | } |
| 420 | args[1] = &kafka.KVArg{ |
| 421 | Key: "flows", |
| 422 | Value: flows, |
| 423 | } |
| 424 | args[2] = &kafka.KVArg{ |
| 425 | Key: "groups", |
| 426 | Value: groups, |
| 427 | } |
| 428 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 429 | // 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] | 430 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 431 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 432 | log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 433 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 434 | } |
| 435 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 436 | func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 437 | log.Debugw("UpdateFlowsIncremental", |
| 438 | log.Fields{ |
| 439 | "deviceId": device.Id, |
| 440 | "flowsToAdd": len(flowChanges.ToAdd.Items), |
| 441 | "flowsToDelete": len(flowChanges.ToRemove.Items), |
| 442 | "groupsToAdd": len(groupChanges.ToAdd.Items), |
| 443 | "groupsToDelete": len(groupChanges.ToRemove.Items), |
| 444 | "groupsToUpdate": len(groupChanges.ToUpdate.Items), |
| 445 | }) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 446 | toTopic := ap.getAdapterTopic(device.Adapter) |
Matt Jeanneret | b003742 | 2019-03-23 14:36:51 -0400 | [diff] [blame] | 447 | rpc := "update_flows_incrementally" |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 448 | args := make([]*kafka.KVArg, 3) |
| 449 | args[0] = &kafka.KVArg{ |
| 450 | Key: "device", |
| 451 | Value: device, |
| 452 | } |
| 453 | args[1] = &kafka.KVArg{ |
| 454 | Key: "flow_changes", |
| 455 | Value: flowChanges, |
| 456 | } |
| 457 | args[2] = &kafka.KVArg{ |
| 458 | Key: "group_changes", |
| 459 | Value: groupChanges, |
| 460 | } |
| 461 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 462 | // 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] | 463 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 464 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 465 | log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 466 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 467 | } |
| 468 | |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 469 | func (ap *AdapterProxy) UpdatePmConfigs(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
| 470 | log.Debugw("UpdatePmConfigs", log.Fields{"deviceId": device.Id}) |
| 471 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 472 | rpc := "Update_pm_config" |
| 473 | args := make([]*kafka.KVArg, 2) |
| 474 | args[0] = &kafka.KVArg{ |
| 475 | Key: "device", |
| 476 | Value: device, |
| 477 | } |
| 478 | args[1] = &kafka.KVArg{ |
| 479 | Key: "pm_configs", |
| 480 | Value: pmConfigs, |
| 481 | } |
| 482 | |
| 483 | replyToTopic := ap.getCoreTopic() |
| 484 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 485 | log.Debugw("UpdatePmConfigs-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 486 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error { |
| 490 | log.Debug("ReceivePacketOut") |
| 491 | return nil |
| 492 | } |
| 493 | |
| 494 | func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error { |
| 495 | log.Debug("SuppressAlarm") |
| 496 | return nil |
| 497 | } |
| 498 | |
| 499 | func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error { |
| 500 | log.Debug("UnSuppressAlarm") |
| 501 | return nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 502 | } |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 503 | |
| 504 | func (ap *AdapterProxy) SimulateAlarm(ctx context.Context, device *voltha.Device, simulatereq *voltha.SimulateAlarmRequest) error { |
| 505 | log.Debugw("SimulateAlarm", log.Fields{"id": simulatereq.Id}) |
| 506 | rpc := "simulate_alarm" |
| 507 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 508 | args := make([]*kafka.KVArg, 2) |
| 509 | args[0] = &kafka.KVArg{ |
| 510 | Key: "device", |
| 511 | Value: device, |
| 512 | } |
| 513 | args[1] = &kafka.KVArg{ |
| 514 | Key: "request", |
| 515 | Value: simulatereq, |
| 516 | } |
| 517 | |
| 518 | // Use a device topic for the response as we are the only core handling requests for this device |
| 519 | replyToTopic := ap.getCoreTopic() |
| 520 | ap.deviceTopicRegistered = true |
| 521 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 522 | log.Debugw("SimulateAlarm-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success}) |
| 523 | return unPackResponse(rpc, device.Id, success, result) |
| 524 | } |