khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [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 common |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "github.com/golang/protobuf/ptypes" |
| 21 | "github.com/golang/protobuf/ptypes/empty" |
| 22 | "github.com/opencord/voltha-go/adapters" |
| 23 | "github.com/opencord/voltha-go/common/log" |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 24 | "github.com/opencord/voltha-go/kafka" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 25 | ic "github.com/opencord/voltha-protos/go/inter_container" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 26 | "github.com/opencord/voltha-protos/go/openflow_13" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 27 | "github.com/opencord/voltha-protos/go/voltha" |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
| 30 | ) |
| 31 | |
| 32 | type RequestHandlerProxy struct { |
| 33 | TestMode bool |
| 34 | coreInstanceId string |
| 35 | adapter adapters.IAdapter |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 36 | coreProxy *CoreProxy |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 37 | } |
| 38 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 39 | func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy *CoreProxy) *RequestHandlerProxy { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 40 | var proxy RequestHandlerProxy |
| 41 | proxy.coreInstanceId = coreInstanceId |
| 42 | proxy.adapter = iadapter |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 43 | proxy.coreProxy = cProxy |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 44 | return &proxy |
| 45 | } |
| 46 | |
| 47 | func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) { |
| 48 | return new(empty.Empty), nil |
| 49 | } |
| 50 | |
| 51 | func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) { |
| 52 | return nil, nil |
| 53 | } |
| 54 | |
| 55 | func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) { |
| 56 | return nil, nil |
| 57 | } |
| 58 | |
| 59 | func (rhp *RequestHandlerProxy) Adopt_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 60 | if len(args) < 3 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 61 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 62 | err := errors.New("invalid-number-of-args") |
| 63 | return nil, err |
| 64 | } |
| 65 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 66 | transactionID := &ic.StrType{} |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 67 | fromTopic := &ic.StrType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 68 | for _, arg := range args { |
| 69 | switch arg.Key { |
| 70 | case "device": |
| 71 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 72 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 73 | return nil, err |
| 74 | } |
| 75 | case kafka.TransactionKey: |
| 76 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 77 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 78 | return nil, err |
| 79 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 80 | case kafka.FromTopic: |
| 81 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 82 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 83 | return nil, err |
| 84 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 85 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 86 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 87 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 88 | log.Debugw("Adopt_device", log.Fields{"deviceId": device.Id}) |
| 89 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 90 | //Update the core reference for that device |
| 91 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 92 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 93 | //Invoke the adopt device on the adapter |
| 94 | if err := rhp.adapter.Adopt_device(device); err != nil { |
| 95 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 96 | } |
| 97 | |
| 98 | return new(empty.Empty), nil |
| 99 | } |
| 100 | |
| 101 | func (rhp *RequestHandlerProxy) Reconcile_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 102 | if len(args) < 3 { |
| 103 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 104 | err := errors.New("invalid-number-of-args") |
| 105 | return nil, err |
| 106 | } |
| 107 | |
| 108 | device := &voltha.Device{} |
| 109 | transactionID := &ic.StrType{} |
| 110 | fromTopic := &ic.StrType{} |
| 111 | for _, arg := range args { |
| 112 | switch arg.Key { |
| 113 | case "device": |
| 114 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 115 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 116 | return nil, err |
| 117 | } |
| 118 | case kafka.TransactionKey: |
| 119 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 120 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 121 | return nil, err |
| 122 | } |
| 123 | case kafka.FromTopic: |
| 124 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 125 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 126 | return nil, err |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | //Update the core reference for that device |
| 131 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 132 | |
| 133 | //Invoke the reconcile device API on the adapter |
| 134 | if err := rhp.adapter.Reconcile_device(device); err != nil { |
| 135 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 136 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 137 | return new(empty.Empty), nil |
| 138 | } |
| 139 | |
| 140 | func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) { |
| 141 | return new(empty.Empty), nil |
| 142 | } |
| 143 | |
| 144 | func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 145 | if len(args) < 3 { |
| 146 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 147 | err := errors.New("invalid-number-of-args") |
| 148 | return nil, err |
| 149 | } |
| 150 | |
| 151 | device := &voltha.Device{} |
| 152 | transactionID := &ic.StrType{} |
| 153 | fromTopic := &ic.StrType{} |
| 154 | for _, arg := range args { |
| 155 | switch arg.Key { |
| 156 | case "device": |
| 157 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 158 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 159 | return nil, err |
| 160 | } |
| 161 | case kafka.TransactionKey: |
| 162 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 163 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 164 | return nil, err |
| 165 | } |
| 166 | case kafka.FromTopic: |
| 167 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 168 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 169 | return nil, err |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | //Update the core reference for that device |
| 174 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 175 | //Invoke the Disable_device API on the adapter |
| 176 | if err := rhp.adapter.Disable_device(device); err != nil { |
| 177 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 178 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 179 | return new(empty.Empty), nil |
| 180 | } |
| 181 | |
| 182 | func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 183 | if len(args) < 3 { |
| 184 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 185 | err := errors.New("invalid-number-of-args") |
| 186 | return nil, err |
| 187 | } |
| 188 | |
| 189 | device := &voltha.Device{} |
| 190 | transactionID := &ic.StrType{} |
| 191 | fromTopic := &ic.StrType{} |
| 192 | for _, arg := range args { |
| 193 | switch arg.Key { |
| 194 | case "device": |
| 195 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 196 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 197 | return nil, err |
| 198 | } |
| 199 | case kafka.TransactionKey: |
| 200 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 201 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 202 | return nil, err |
| 203 | } |
| 204 | case kafka.FromTopic: |
| 205 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 206 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 207 | return nil, err |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | //Update the core reference for that device |
| 212 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 213 | //Invoke the Reenable_device API on the adapter |
| 214 | if err := rhp.adapter.Reenable_device(device); err != nil { |
| 215 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 216 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 217 | return new(empty.Empty), nil |
| 218 | } |
| 219 | |
| 220 | func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) { |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 221 | if len(args) < 3 { |
| 222 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 223 | err := errors.New("invalid-number-of-args") |
| 224 | return nil, err |
| 225 | } |
| 226 | |
| 227 | device := &voltha.Device{} |
| 228 | transactionID := &ic.StrType{} |
| 229 | fromTopic := &ic.StrType{} |
| 230 | for _, arg := range args { |
| 231 | switch arg.Key { |
| 232 | case "device": |
| 233 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 234 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 235 | return nil, err |
| 236 | } |
| 237 | case kafka.TransactionKey: |
| 238 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 239 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 240 | return nil, err |
| 241 | } |
| 242 | case kafka.FromTopic: |
| 243 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 244 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 245 | return nil, err |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | //Update the core reference for that device |
| 250 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 251 | //Invoke the Reboot_device API on the adapter |
| 252 | if err := rhp.adapter.Reboot_device(device); err != nil { |
| 253 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 254 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 255 | return new(empty.Empty), nil |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 256 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) { |
| 260 | return new(empty.Empty), nil |
| 261 | } |
| 262 | |
| 263 | func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 264 | if len(args) < 3 { |
| 265 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 266 | err := errors.New("invalid-number-of-args") |
| 267 | return nil, err |
| 268 | } |
| 269 | |
| 270 | device := &voltha.Device{} |
| 271 | transactionID := &ic.StrType{} |
| 272 | fromTopic := &ic.StrType{} |
| 273 | for _, arg := range args { |
| 274 | switch arg.Key { |
| 275 | case "device": |
| 276 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 277 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 278 | return nil, err |
| 279 | } |
| 280 | case kafka.TransactionKey: |
| 281 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 282 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 283 | return nil, err |
| 284 | } |
| 285 | case kafka.FromTopic: |
| 286 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 287 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 288 | return nil, err |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | //Update the core reference for that device |
| 293 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 294 | //Invoke the delete_device API on the adapter |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 295 | if err := rhp.adapter.Delete_device(device); err != nil { |
| 296 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 297 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 298 | return new(empty.Empty), nil |
| 299 | } |
| 300 | |
| 301 | func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) { |
| 302 | return new(empty.Empty), nil |
| 303 | } |
| 304 | |
| 305 | func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 306 | log.Debug("Update_flows_bulk") |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 307 | if len(args) < 5 { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 308 | log.Warn("Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args}) |
| 309 | err := errors.New("invalid-number-of-args") |
| 310 | return nil, err |
| 311 | } |
| 312 | device := &voltha.Device{} |
| 313 | transactionID := &ic.StrType{} |
| 314 | flows := &voltha.Flows{} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 315 | flowMetadata := &voltha.FlowMetadata{} |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 316 | groups := &voltha.FlowGroups{} |
| 317 | for _, arg := range args { |
| 318 | switch arg.Key { |
| 319 | case "device": |
| 320 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 321 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 322 | return nil, err |
| 323 | } |
| 324 | case "flows": |
| 325 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
| 326 | log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err}) |
| 327 | return nil, err |
| 328 | } |
| 329 | case "groups": |
| 330 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
| 331 | log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err}) |
| 332 | return nil, err |
| 333 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 334 | case "flow_metadata": |
| 335 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
| 336 | log.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err}) |
| 337 | return nil, err |
| 338 | } |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 339 | case kafka.TransactionKey: |
| 340 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 341 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 342 | return nil, err |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | log.Debugw("Update_flows_bulk", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 347 | //Invoke the bulk flow update API of the adapter |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 348 | if err := rhp.adapter.Update_flows_bulk(device, flows, groups, flowMetadata); err != nil { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 349 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 350 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 351 | return new(empty.Empty), nil |
| 352 | } |
| 353 | |
| 354 | func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 355 | log.Debug("Update_flows_incrementally") |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 356 | if len(args) < 5 { |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 357 | log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args}) |
| 358 | err := errors.New("invalid-number-of-args") |
| 359 | return nil, err |
| 360 | } |
| 361 | device := &voltha.Device{} |
| 362 | transactionID := &ic.StrType{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 363 | flows := &openflow_13.FlowChanges{} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 364 | flowMetadata := &voltha.FlowMetadata{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 365 | groups := &openflow_13.FlowGroupChanges{} |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 366 | for _, arg := range args { |
| 367 | switch arg.Key { |
| 368 | case "device": |
| 369 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 370 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 371 | return nil, err |
| 372 | } |
| 373 | case "flow_changes": |
| 374 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
| 375 | log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err}) |
| 376 | return nil, err |
| 377 | } |
| 378 | case "group_changes": |
| 379 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
| 380 | log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err}) |
| 381 | return nil, err |
| 382 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 383 | case "flow_metadata": |
| 384 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
| 385 | log.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err}) |
| 386 | return nil, err |
| 387 | } |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 388 | case kafka.TransactionKey: |
| 389 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 390 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 391 | return nil, err |
| 392 | } |
| 393 | } |
| 394 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 395 | log.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 396 | //Invoke the incremental flow update API of the adapter |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 397 | if err := rhp.adapter.Update_flows_incrementally(device, flows, groups, flowMetadata); err != nil { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 398 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 399 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 400 | return new(empty.Empty), nil |
| 401 | } |
| 402 | |
| 403 | func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 404 | log.Debug("Update_pm_config") |
| 405 | if len(args) < 2 { |
| 406 | log.Warn("Update_pm_config-invalid-number-of-args", log.Fields{"args": args}) |
| 407 | err := errors.New("invalid-number-of-args") |
| 408 | return nil, err |
| 409 | } |
| 410 | device := &voltha.Device{} |
| 411 | transactionID := &ic.StrType{} |
| 412 | pmConfigs := &voltha.PmConfigs{} |
| 413 | for _, arg := range args { |
| 414 | switch arg.Key { |
| 415 | case "device": |
| 416 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 417 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 418 | return nil, err |
| 419 | } |
| 420 | case "pm_configs": |
| 421 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
| 422 | log.Warnw("cannot-unmarshal-pm-configs", log.Fields{"error": err}) |
| 423 | return nil, err |
| 424 | } |
| 425 | case kafka.TransactionKey: |
| 426 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 427 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 428 | return nil, err |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | log.Debugw("Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs}) |
| 433 | //Invoke the pm config update API of the adapter |
| 434 | if err := rhp.adapter.Update_pm_config(device, pmConfigs); err != nil { |
| 435 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 436 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 437 | return new(empty.Empty), nil |
| 438 | } |
| 439 | |
| 440 | func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) { |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 441 | log.Debugw("Receive_packet_out", log.Fields{"args": args}) |
| 442 | if len(args) < 3 { |
| 443 | log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
| 444 | err := errors.New("invalid-number-of-args") |
| 445 | return nil, err |
| 446 | } |
| 447 | deviceId := &ic.StrType{} |
| 448 | egressPort := &ic.IntType{} |
| 449 | packet := &openflow_13.OfpPacketOut{} |
| 450 | transactionID := &ic.StrType{} |
| 451 | for _, arg := range args { |
| 452 | switch arg.Key { |
| 453 | case "deviceId": |
| 454 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 455 | log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err}) |
| 456 | return nil, err |
| 457 | } |
| 458 | case "outPort": |
| 459 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
| 460 | log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err}) |
| 461 | return nil, err |
| 462 | } |
| 463 | case "packet": |
| 464 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
| 465 | log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
| 466 | return nil, err |
| 467 | } |
| 468 | case kafka.TransactionKey: |
| 469 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 470 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 471 | return nil, err |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet}) |
| 476 | //Invoke the adopt device on the adapter |
| 477 | if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil { |
| 478 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 479 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 480 | return new(empty.Empty), nil |
| 481 | } |
| 482 | |
| 483 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 484 | return new(empty.Empty), nil |
| 485 | } |
| 486 | |
| 487 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 488 | return new(empty.Empty), nil |
| 489 | } |
| 490 | |
| 491 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 492 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 493 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 494 | err := errors.New("invalid-number-of-args") |
| 495 | return nil, err |
| 496 | } |
| 497 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 498 | transactionID := &ic.StrType{} |
| 499 | for _, arg := range args { |
| 500 | switch arg.Key { |
| 501 | case "device": |
| 502 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 503 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 504 | return nil, err |
| 505 | } |
| 506 | case kafka.TransactionKey: |
| 507 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 508 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 509 | return nil, err |
| 510 | } |
| 511 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 512 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 513 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 514 | log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
| 515 | |
| 516 | var cap *ic.SwitchCapability |
| 517 | var err error |
| 518 | if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil { |
| 519 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 520 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 521 | log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 522 | return cap, nil |
| 523 | } |
| 524 | |
| 525 | func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 526 | if len(args) < 3 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 527 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 528 | err := errors.New("invalid-number-of-args") |
| 529 | return nil, err |
| 530 | } |
| 531 | device := &voltha.Device{} |
| 532 | pNo := &ic.IntType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 533 | transactionID := &ic.StrType{} |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 534 | for _, arg := range args { |
| 535 | switch arg.Key { |
| 536 | case "device": |
| 537 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 538 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 539 | return nil, err |
| 540 | } |
| 541 | case "port_no": |
| 542 | if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil { |
| 543 | log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
| 544 | return nil, err |
| 545 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 546 | case kafka.TransactionKey: |
| 547 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 548 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 549 | return nil, err |
| 550 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val}) |
| 554 | var cap *ic.PortCapability |
| 555 | var err error |
| 556 | if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil { |
| 557 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 558 | } |
| 559 | return cap, nil |
| 560 | } |
| 561 | |
| 562 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 563 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 564 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 565 | err := errors.New("invalid-number-of-args") |
| 566 | return nil, err |
| 567 | } |
| 568 | iaMsg := &ic.InterAdapterMessage{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 569 | transactionID := &ic.StrType{} |
| 570 | for _, arg := range args { |
| 571 | switch arg.Key { |
| 572 | case "msg": |
| 573 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
| 574 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 575 | return nil, err |
| 576 | } |
| 577 | case kafka.TransactionKey: |
| 578 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 579 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 580 | return nil, err |
| 581 | } |
| 582 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
| 586 | |
| 587 | //Invoke the inter adapter API on the handler |
| 588 | if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil { |
| 589 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 590 | } |
| 591 | |
| 592 | return new(empty.Empty), nil |
| 593 | } |
| 594 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 595 | func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 596 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 597 | } |
| 598 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 599 | func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 600 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 601 | } |
| 602 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 603 | func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 604 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 605 | } |
| 606 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 607 | func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 608 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 609 | } |
| 610 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 611 | func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 612 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 613 | } |