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" |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 24 | ic "github.com/opencord/voltha-go/protos/inter_container" |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 25 | "github.com/opencord/voltha-go/protos/openflow_13" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 26 | "github.com/opencord/voltha-go/protos/voltha" |
| 27 | "google.golang.org/grpc/codes" |
| 28 | "google.golang.org/grpc/status" |
| 29 | ) |
| 30 | |
| 31 | type AdapterProxy struct { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 32 | TestMode bool |
| 33 | kafkaICProxy *kafka.InterContainerProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 34 | } |
| 35 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 36 | func NewAdapterProxy(kafkaProxy *kafka.InterContainerProxy) *AdapterProxy { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 37 | var proxy AdapterProxy |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 38 | proxy.kafkaICProxy = kafkaProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 39 | return &proxy |
| 40 | } |
| 41 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 42 | func unPackResponse(rpc string, deviceId string, success bool, response *a.Any) error { |
| 43 | if success { |
| 44 | return nil |
| 45 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 46 | unpackResult := &ic.Error{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 47 | var err error |
| 48 | if err = ptypes.UnmarshalAny(response, unpackResult); err != nil { |
| 49 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 50 | } |
| 51 | log.Debugw("response", log.Fields{"rpc": rpc, "deviceId": deviceId, "success": success, "error": err}) |
| 52 | // TODO: Need to get the real error code |
| 53 | return status.Errorf(codes.Canceled, "%s", unpackResult.Reason) |
| 54 | } |
| 55 | } |
| 56 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 57 | //func kafka.CreateSubTopic(args ...string) kafka.Topic{ |
| 58 | // topic := "" |
| 59 | // for index , arg := range args { |
| 60 | // if index == 0 { |
| 61 | // topic = arg |
| 62 | // } else { |
| 63 | // topic = fmt.Sprintf("%s_%s", topic, arg) |
| 64 | // } |
| 65 | // } |
| 66 | // return kafka.Topic{Name:topic} |
| 67 | //} |
| 68 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 69 | func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) error { |
| 70 | log.Debugw("AdoptDevice", log.Fields{"device": device}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 71 | rpc := "adopt_device" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 72 | topic := kafka.Topic{Name: device.Type} |
| 73 | args := make([]*kafka.KVArg, 1) |
| 74 | args[0] = &kafka.KVArg{ |
| 75 | Key: "device", |
| 76 | Value: device, |
| 77 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 78 | // Use a device topic for the response as we are the only core handling requests for this device |
| 79 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 80 | if err := ap.kafkaICProxy.SubscribeWithDefaultRequestHandler(replyToTopic); err != nil { |
| 81 | log.Errorw("Unable-to-subscribe-new-topic", log.Fields{"topic": replyToTopic, "error": err}) |
| 82 | return err |
| 83 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 84 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &topic, &replyToTopic, true, args...) |
| 85 | log.Debugw("AdoptDevice-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success}) |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 86 | //if success { |
| 87 | // // From now on, any unsolicited requests from the adapters for this device will come over the device topic. |
| 88 | // // We should therefore include the replyToTopic as part of the target when unsolicited messages come in. |
| 89 | // if err := ap.kafkaICProxy.SubscribeWithDefaultRequestHandler(replyToTopic); err != nil { |
| 90 | // log.Errorw("Unable-to-subscribe-new-topic", log.Fields{"topic": replyToTopic, "error": err}) |
| 91 | // return err |
| 92 | // } |
| 93 | //} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 94 | return unPackResponse(rpc, device.Id, success, result) |
| 95 | } |
| 96 | |
| 97 | func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) error { |
| 98 | log.Debugw("DisableDevice", log.Fields{"deviceId": device.Id}) |
| 99 | rpc := "disable_device" |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 100 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 101 | // specific topic |
| 102 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 103 | args := make([]*kafka.KVArg, 1) |
| 104 | args[0] = &kafka.KVArg{ |
| 105 | Key: "device", |
| 106 | Value: device, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 107 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 108 | // Use a device specific topic as we are the only core handling requests for this device |
| 109 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 110 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, 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 | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 118 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
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 |
| 125 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 126 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, 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 | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 134 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
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 |
| 141 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 142 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, 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 | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 150 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
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 |
| 157 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 158 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, 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 | |
| 161 | // We no longer need to have a target against that topic as we won't receive any unsolicited messages on that |
| 162 | // topic |
| 163 | if err := ap.kafkaICProxy.UnSubscribeFromRequestHandler(replyToTopic); err != nil { |
| 164 | log.Errorw("Unable-to-subscribe-from-target", log.Fields{"topic": replyToTopic, "error": err}) |
| 165 | return err |
| 166 | } |
| 167 | // Now delete the topic altogether |
| 168 | ap.kafkaICProxy.DeleteTopic(replyToTopic) |
| 169 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 170 | return unPackResponse(rpc, device.Id, success, result) |
| 171 | } |
| 172 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 173 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 174 | log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 175 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 176 | args := make([]*kafka.KVArg, 1) |
| 177 | args[0] = &kafka.KVArg{ |
| 178 | Key: "device", |
| 179 | Value: device, |
| 180 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 181 | // Use a device specific topic as we are the only core handling requests for this device |
| 182 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 183 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_device_info", &toTopic, &replyToTopic, true, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 184 | log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result}) |
| 185 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 186 | unpackResult := &ic.SwitchCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 187 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 188 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 189 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 190 | } |
| 191 | return unpackResult, nil |
| 192 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 193 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 194 | var err error |
| 195 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 196 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 197 | } |
| 198 | log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 199 | // TODO: Need to get the real error code |
| 200 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 201 | } |
| 202 | } |
| 203 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 204 | 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] | 205 | log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 206 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 207 | args := make([]*kafka.KVArg, 2) |
| 208 | args[0] = &kafka.KVArg{ |
| 209 | Key: "device", |
| 210 | Value: device, |
| 211 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 212 | pNo := &ic.IntType{Val: int64(portNo)} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 213 | args[1] = &kafka.KVArg{ |
| 214 | Key: "port_no", |
| 215 | Value: pNo, |
| 216 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 217 | // Use a device specific topic as we are the only core handling requests for this device |
| 218 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 219 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_port_info", &toTopic, &replyToTopic, true, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 220 | log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 221 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 222 | unpackResult := &ic.PortCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 223 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 224 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 225 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 226 | } |
| 227 | return unpackResult, nil |
| 228 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 229 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 230 | var err error |
| 231 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 232 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 233 | } |
| 234 | log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 235 | // TODO: Need to get the real error code |
| 236 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | //TODO: Implement the functions below |
| 241 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 242 | func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) { |
| 243 | log.Debug("AdapterDescriptor") |
| 244 | return nil, nil |
| 245 | } |
| 246 | |
| 247 | func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) { |
| 248 | log.Debug("DeviceTypes") |
| 249 | return nil, nil |
| 250 | } |
| 251 | |
| 252 | func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) { |
| 253 | log.Debug("Health") |
| 254 | return nil, nil |
| 255 | } |
| 256 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 257 | func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 258 | log.Debug("ReconcileDevice") |
| 259 | return nil |
| 260 | } |
| 261 | |
| 262 | func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error { |
| 263 | log.Debug("AbandonDevice") |
| 264 | return nil |
| 265 | } |
| 266 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 267 | func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) { |
| 268 | log.Debug("GetDeviceDetails") |
| 269 | return nil, nil |
| 270 | } |
| 271 | |
| 272 | func (ap *AdapterProxy) DownloadImage(device voltha.Device, download voltha.ImageDownload) error { |
| 273 | log.Debug("DownloadImage") |
| 274 | return nil |
| 275 | } |
| 276 | |
| 277 | func (ap *AdapterProxy) GetImageDownloadStatus(device voltha.Device, download voltha.ImageDownload) error { |
| 278 | log.Debug("GetImageDownloadStatus") |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | func (ap *AdapterProxy) CancelImageDownload(device voltha.Device, download voltha.ImageDownload) error { |
| 283 | log.Debug("CancelImageDownload") |
| 284 | return nil |
| 285 | } |
| 286 | |
| 287 | func (ap *AdapterProxy) ActivateImageUpdate(device voltha.Device, download voltha.ImageDownload) error { |
| 288 | log.Debug("ActivateImageUpdate") |
| 289 | return nil |
| 290 | } |
| 291 | |
| 292 | func (ap *AdapterProxy) RevertImageUpdate(device voltha.Device, download voltha.ImageDownload) error { |
| 293 | log.Debug("RevertImageUpdate") |
| 294 | return nil |
| 295 | } |
| 296 | |
| 297 | func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) { |
| 298 | log.Debug("SelfTestDevice") |
| 299 | return nil, nil |
| 300 | } |
| 301 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 302 | func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error { |
| 303 | log.Debugw("packetOut", log.Fields{"deviceId": deviceId}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 304 | toTopic := kafka.CreateSubTopic(deviceType, deviceId) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 305 | rpc := "receive_packet_out" |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 306 | dId := &ic.StrType{Val: deviceId} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 307 | args := make([]*kafka.KVArg, 3) |
| 308 | args[0] = &kafka.KVArg{ |
| 309 | Key: "deviceId", |
| 310 | Value: dId, |
| 311 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 312 | op := &ic.IntType{Val: int64(outPort)} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 313 | args[1] = &kafka.KVArg{ |
| 314 | Key: "outPort", |
| 315 | Value: op, |
| 316 | } |
| 317 | args[2] = &kafka.KVArg{ |
| 318 | Key: "packet", |
| 319 | Value: packet, |
| 320 | } |
| 321 | |
| 322 | // TODO: Do we need to wait for an ACK on a packet Out? |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 323 | // Use a device specific topic as we are the only core handling requests for this device |
| 324 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, deviceId) |
| 325 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, false, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 326 | log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success}) |
| 327 | return unPackResponse(rpc, deviceId, success, result) |
| 328 | } |
| 329 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 330 | func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error { |
| 331 | log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 332 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 333 | rpc := "update_flows_bulk" |
| 334 | args := make([]*kafka.KVArg, 3) |
| 335 | args[0] = &kafka.KVArg{ |
| 336 | Key: "device", |
| 337 | Value: device, |
| 338 | } |
| 339 | args[1] = &kafka.KVArg{ |
| 340 | Key: "flows", |
| 341 | Value: flows, |
| 342 | } |
| 343 | args[2] = &kafka.KVArg{ |
| 344 | Key: "groups", |
| 345 | Value: groups, |
| 346 | } |
| 347 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 348 | // Use a device specific topic as we are the only core handling requests for this device |
| 349 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 350 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 351 | log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 352 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 353 | } |
| 354 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 355 | func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error { |
| 356 | log.Debugw("UpdateFlowsIncremental", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 357 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 358 | rpc := "update_flows_bulk" |
| 359 | args := make([]*kafka.KVArg, 3) |
| 360 | args[0] = &kafka.KVArg{ |
| 361 | Key: "device", |
| 362 | Value: device, |
| 363 | } |
| 364 | args[1] = &kafka.KVArg{ |
| 365 | Key: "flow_changes", |
| 366 | Value: flowChanges, |
| 367 | } |
| 368 | args[2] = &kafka.KVArg{ |
| 369 | Key: "group_changes", |
| 370 | Value: groupChanges, |
| 371 | } |
| 372 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 373 | // Use a device specific topic as we are the only core handling requests for this device |
| 374 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 375 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 376 | log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 377 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | func (ap *AdapterProxy) UpdatePmConfig(device voltha.Device, pmConfigs voltha.PmConfigs) error { |
| 381 | log.Debug("UpdatePmConfig") |
| 382 | return nil |
| 383 | } |
| 384 | |
| 385 | func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error { |
| 386 | log.Debug("ReceivePacketOut") |
| 387 | return nil |
| 388 | } |
| 389 | |
| 390 | func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error { |
| 391 | log.Debug("SuppressAlarm") |
| 392 | return nil |
| 393 | } |
| 394 | |
| 395 | func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error { |
| 396 | log.Debug("UnSuppressAlarm") |
| 397 | return nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 398 | } |