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