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 | |
khenaidoo | 3dfc8bc | 2019-01-10 16:48:25 -0500 | [diff] [blame] | 161 | // We no longer need to have this device topic as we won't receive any unsolicited messages on it |
| 162 | if err := ap.kafkaICProxy.DeleteTopic(replyToTopic); err != nil { |
| 163 | log.Errorw("Unable-to-delete-topic", log.Fields{"topic": replyToTopic, "error": err}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 164 | return err |
| 165 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 166 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 167 | return unPackResponse(rpc, device.Id, success, result) |
| 168 | } |
| 169 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 170 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 171 | log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 172 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 173 | args := make([]*kafka.KVArg, 1) |
| 174 | args[0] = &kafka.KVArg{ |
| 175 | Key: "device", |
| 176 | Value: device, |
| 177 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 178 | // Use a device specific topic as we are the only core handling requests for this device |
| 179 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 180 | 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] | 181 | log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result}) |
| 182 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 183 | unpackResult := &ic.SwitchCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 184 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 185 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 186 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 187 | } |
| 188 | return unpackResult, nil |
| 189 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 190 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 191 | var err error |
| 192 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 193 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 194 | } |
| 195 | log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 196 | // TODO: Need to get the real error code |
| 197 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 198 | } |
| 199 | } |
| 200 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 201 | 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] | 202 | log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 203 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 204 | args := make([]*kafka.KVArg, 2) |
| 205 | args[0] = &kafka.KVArg{ |
| 206 | Key: "device", |
| 207 | Value: device, |
| 208 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 209 | pNo := &ic.IntType{Val: int64(portNo)} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 210 | args[1] = &kafka.KVArg{ |
| 211 | Key: "port_no", |
| 212 | Value: pNo, |
| 213 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 214 | // Use a device specific topic as we are the only core handling requests for this device |
| 215 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 216 | 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] | 217 | log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 218 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 219 | unpackResult := &ic.PortCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 220 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 221 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 222 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 223 | } |
| 224 | return unpackResult, nil |
| 225 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 226 | unpackResult := &ic.Error{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 227 | var err error |
| 228 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 229 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 230 | } |
| 231 | log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 232 | // TODO: Need to get the real error code |
| 233 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | //TODO: Implement the functions below |
| 238 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 239 | func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) { |
| 240 | log.Debug("AdapterDescriptor") |
| 241 | return nil, nil |
| 242 | } |
| 243 | |
| 244 | func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) { |
| 245 | log.Debug("DeviceTypes") |
| 246 | return nil, nil |
| 247 | } |
| 248 | |
| 249 | func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) { |
| 250 | log.Debug("Health") |
| 251 | return nil, nil |
| 252 | } |
| 253 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 254 | func (ap *AdapterProxy) ReconcileDevice(device *voltha.Device) error { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 255 | log.Debug("ReconcileDevice") |
| 256 | return nil |
| 257 | } |
| 258 | |
| 259 | func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error { |
| 260 | log.Debug("AbandonDevice") |
| 261 | return nil |
| 262 | } |
| 263 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 264 | func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) { |
| 265 | log.Debug("GetDeviceDetails") |
| 266 | return nil, nil |
| 267 | } |
| 268 | |
| 269 | func (ap *AdapterProxy) DownloadImage(device voltha.Device, download voltha.ImageDownload) error { |
| 270 | log.Debug("DownloadImage") |
| 271 | return nil |
| 272 | } |
| 273 | |
| 274 | func (ap *AdapterProxy) GetImageDownloadStatus(device voltha.Device, download voltha.ImageDownload) error { |
| 275 | log.Debug("GetImageDownloadStatus") |
| 276 | return nil |
| 277 | } |
| 278 | |
| 279 | func (ap *AdapterProxy) CancelImageDownload(device voltha.Device, download voltha.ImageDownload) error { |
| 280 | log.Debug("CancelImageDownload") |
| 281 | return nil |
| 282 | } |
| 283 | |
| 284 | func (ap *AdapterProxy) ActivateImageUpdate(device voltha.Device, download voltha.ImageDownload) error { |
| 285 | log.Debug("ActivateImageUpdate") |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | func (ap *AdapterProxy) RevertImageUpdate(device voltha.Device, download voltha.ImageDownload) error { |
| 290 | log.Debug("RevertImageUpdate") |
| 291 | return nil |
| 292 | } |
| 293 | |
| 294 | func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) { |
| 295 | log.Debug("SelfTestDevice") |
| 296 | return nil, nil |
| 297 | } |
| 298 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 299 | func (ap *AdapterProxy) packetOut(deviceType string, deviceId string, outPort uint32, packet *openflow_13.OfpPacketOut) error { |
| 300 | log.Debugw("packetOut", log.Fields{"deviceId": deviceId}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 301 | toTopic := kafka.CreateSubTopic(deviceType, deviceId) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 302 | rpc := "receive_packet_out" |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 303 | dId := &ic.StrType{Val: deviceId} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 304 | args := make([]*kafka.KVArg, 3) |
| 305 | args[0] = &kafka.KVArg{ |
| 306 | Key: "deviceId", |
| 307 | Value: dId, |
| 308 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 309 | op := &ic.IntType{Val: int64(outPort)} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 310 | args[1] = &kafka.KVArg{ |
| 311 | Key: "outPort", |
| 312 | Value: op, |
| 313 | } |
| 314 | args[2] = &kafka.KVArg{ |
| 315 | Key: "packet", |
| 316 | Value: packet, |
| 317 | } |
| 318 | |
| 319 | // TODO: Do we need to wait for an ACK on a packet Out? |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 320 | // Use a device specific topic as we are the only core handling requests for this device |
| 321 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, deviceId) |
| 322 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, false, args...) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 323 | log.Debugw("packetOut", log.Fields{"deviceid": deviceId, "success": success}) |
| 324 | return unPackResponse(rpc, deviceId, success, result) |
| 325 | } |
| 326 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 327 | func (ap *AdapterProxy) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups) error { |
| 328 | log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 329 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 330 | rpc := "update_flows_bulk" |
| 331 | args := make([]*kafka.KVArg, 3) |
| 332 | args[0] = &kafka.KVArg{ |
| 333 | Key: "device", |
| 334 | Value: device, |
| 335 | } |
| 336 | args[1] = &kafka.KVArg{ |
| 337 | Key: "flows", |
| 338 | Value: flows, |
| 339 | } |
| 340 | args[2] = &kafka.KVArg{ |
| 341 | Key: "groups", |
| 342 | Value: groups, |
| 343 | } |
| 344 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 345 | // Use a device specific topic as we are the only core handling requests for this device |
| 346 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 347 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 348 | log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 349 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 350 | } |
| 351 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 352 | func (ap *AdapterProxy) UpdateFlowsIncremental(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges) error { |
| 353 | log.Debugw("UpdateFlowsIncremental", log.Fields{"deviceId": device.Id}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 354 | toTopic := kafka.CreateSubTopic(device.Type, device.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 355 | rpc := "update_flows_bulk" |
| 356 | args := make([]*kafka.KVArg, 3) |
| 357 | args[0] = &kafka.KVArg{ |
| 358 | Key: "device", |
| 359 | Value: device, |
| 360 | } |
| 361 | args[1] = &kafka.KVArg{ |
| 362 | Key: "flow_changes", |
| 363 | Value: flowChanges, |
| 364 | } |
| 365 | args[2] = &kafka.KVArg{ |
| 366 | Key: "group_changes", |
| 367 | Value: groupChanges, |
| 368 | } |
| 369 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 370 | // Use a device specific topic as we are the only core handling requests for this device |
| 371 | replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 372 | success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 373 | log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 374 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | func (ap *AdapterProxy) UpdatePmConfig(device voltha.Device, pmConfigs voltha.PmConfigs) error { |
| 378 | log.Debug("UpdatePmConfig") |
| 379 | return nil |
| 380 | } |
| 381 | |
| 382 | func (ap *AdapterProxy) ReceivePacketOut(deviceId voltha.ID, egressPortNo int, msg interface{}) error { |
| 383 | log.Debug("ReceivePacketOut") |
| 384 | return nil |
| 385 | } |
| 386 | |
| 387 | func (ap *AdapterProxy) SuppressAlarm(filter voltha.AlarmFilter) error { |
| 388 | log.Debug("SuppressAlarm") |
| 389 | return nil |
| 390 | } |
| 391 | |
| 392 | func (ap *AdapterProxy) UnSuppressAlarm(filter voltha.AlarmFilter) error { |
| 393 | log.Debug("UnSuppressAlarm") |
| 394 | return nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 395 | } |