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 ( |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 19 | "context" |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 20 | "errors" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 21 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 22 | "github.com/golang/protobuf/ptypes" |
| 23 | "github.com/golang/protobuf/ptypes/empty" |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame^] | 24 | "github.com/opencord/voltha-lib-go/v5/pkg/adapters" |
| 25 | "github.com/opencord/voltha-lib-go/v5/pkg/adapters/adapterif" |
| 26 | "github.com/opencord/voltha-lib-go/v5/pkg/kafka" |
| 27 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/v4/go/extension" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 29 | ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 30 | "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 31 | "github.com/opencord/voltha-protos/v4/go/voltha" |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 32 | "google.golang.org/grpc/codes" |
| 33 | "google.golang.org/grpc/status" |
| 34 | ) |
| 35 | |
| 36 | type RequestHandlerProxy struct { |
| 37 | TestMode bool |
| 38 | coreInstanceId string |
| 39 | adapter adapters.IAdapter |
kdarapu | 283d154 | 2019-07-31 17:21:11 +0530 | [diff] [blame] | 40 | coreProxy adapterif.CoreProxy |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 41 | } |
| 42 | |
kdarapu | 283d154 | 2019-07-31 17:21:11 +0530 | [diff] [blame] | 43 | func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy adapterif.CoreProxy) *RequestHandlerProxy { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 44 | var proxy RequestHandlerProxy |
| 45 | proxy.coreInstanceId = coreInstanceId |
| 46 | proxy.adapter = iadapter |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 47 | proxy.coreProxy = cProxy |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 48 | return &proxy |
| 49 | } |
| 50 | |
| 51 | func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) { |
| 52 | return new(empty.Empty), nil |
| 53 | } |
| 54 | |
| 55 | func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) { |
| 56 | return nil, nil |
| 57 | } |
| 58 | |
| 59 | func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) { |
| 60 | return nil, nil |
| 61 | } |
| 62 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 63 | func (rhp *RequestHandlerProxy) Adopt_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 64 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 65 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 66 | err := errors.New("invalid-number-of-args") |
| 67 | return nil, err |
| 68 | } |
| 69 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 70 | transactionID := &ic.StrType{} |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 71 | fromTopic := &ic.StrType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 72 | for _, arg := range args { |
| 73 | switch arg.Key { |
| 74 | case "device": |
| 75 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 76 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 77 | return nil, err |
| 78 | } |
| 79 | case kafka.TransactionKey: |
| 80 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 81 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 82 | return nil, err |
| 83 | } |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 84 | case kafka.FromTopic: |
| 85 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 86 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 87 | return nil, err |
| 88 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 89 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 90 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 91 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 92 | logger.Debugw(ctx, "Adopt_device", log.Fields{"deviceId": device.Id}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 93 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 94 | //Update the core reference for that device |
| 95 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 96 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 97 | //Invoke the adopt device on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 98 | if err := rhp.adapter.Adopt_device(ctx, device); err != nil { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 99 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 100 | } |
| 101 | |
| 102 | return new(empty.Empty), nil |
| 103 | } |
| 104 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 105 | func (rhp *RequestHandlerProxy) Reconcile_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 106 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 107 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 108 | err := errors.New("invalid-number-of-args") |
| 109 | return nil, err |
| 110 | } |
| 111 | |
| 112 | device := &voltha.Device{} |
| 113 | transactionID := &ic.StrType{} |
| 114 | fromTopic := &ic.StrType{} |
| 115 | for _, arg := range args { |
| 116 | switch arg.Key { |
| 117 | case "device": |
| 118 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 119 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 120 | return nil, err |
| 121 | } |
| 122 | case kafka.TransactionKey: |
| 123 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 124 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 125 | return nil, err |
| 126 | } |
| 127 | case kafka.FromTopic: |
| 128 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 129 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 130 | return nil, err |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | //Update the core reference for that device |
| 135 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 136 | |
| 137 | //Invoke the reconcile device API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 138 | if err := rhp.adapter.Reconcile_device(ctx, device); err != nil { |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 139 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 140 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 141 | return new(empty.Empty), nil |
| 142 | } |
| 143 | |
| 144 | func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) { |
| 145 | return new(empty.Empty), nil |
| 146 | } |
| 147 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 148 | func (rhp *RequestHandlerProxy) Disable_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 149 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 150 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 151 | err := errors.New("invalid-number-of-args") |
| 152 | return nil, err |
| 153 | } |
| 154 | |
| 155 | device := &voltha.Device{} |
| 156 | transactionID := &ic.StrType{} |
| 157 | fromTopic := &ic.StrType{} |
| 158 | for _, arg := range args { |
| 159 | switch arg.Key { |
| 160 | case "device": |
| 161 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 162 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 163 | return nil, err |
| 164 | } |
| 165 | case kafka.TransactionKey: |
| 166 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 167 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 168 | return nil, err |
| 169 | } |
| 170 | case kafka.FromTopic: |
| 171 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 172 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 173 | return nil, err |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | //Update the core reference for that device |
| 178 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 179 | //Invoke the Disable_device API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 180 | if err := rhp.adapter.Disable_device(ctx, device); err != nil { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 181 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 182 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 183 | return new(empty.Empty), nil |
| 184 | } |
| 185 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 186 | func (rhp *RequestHandlerProxy) Reenable_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 187 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 188 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 189 | err := errors.New("invalid-number-of-args") |
| 190 | return nil, err |
| 191 | } |
| 192 | |
| 193 | device := &voltha.Device{} |
| 194 | transactionID := &ic.StrType{} |
| 195 | fromTopic := &ic.StrType{} |
| 196 | for _, arg := range args { |
| 197 | switch arg.Key { |
| 198 | case "device": |
| 199 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 200 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 201 | return nil, err |
| 202 | } |
| 203 | case kafka.TransactionKey: |
| 204 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 205 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 206 | return nil, err |
| 207 | } |
| 208 | case kafka.FromTopic: |
| 209 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 210 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 211 | return nil, err |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | //Update the core reference for that device |
| 216 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 217 | //Invoke the Reenable_device API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 218 | if err := rhp.adapter.Reenable_device(ctx, device); err != nil { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 219 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 220 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 221 | return new(empty.Empty), nil |
| 222 | } |
| 223 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 224 | func (rhp *RequestHandlerProxy) Reboot_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 225 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 226 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 227 | err := errors.New("invalid-number-of-args") |
| 228 | return nil, err |
| 229 | } |
| 230 | |
| 231 | device := &voltha.Device{} |
| 232 | transactionID := &ic.StrType{} |
| 233 | fromTopic := &ic.StrType{} |
| 234 | for _, arg := range args { |
| 235 | switch arg.Key { |
| 236 | case "device": |
| 237 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 238 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 239 | return nil, err |
| 240 | } |
| 241 | case kafka.TransactionKey: |
| 242 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 243 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 244 | return nil, err |
| 245 | } |
| 246 | case kafka.FromTopic: |
| 247 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 248 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 249 | return nil, err |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | //Update the core reference for that device |
| 254 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 255 | //Invoke the Reboot_device API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 256 | if err := rhp.adapter.Reboot_device(ctx, device); err != nil { |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 257 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 258 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 259 | return new(empty.Empty), nil |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 260 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) { |
| 264 | return new(empty.Empty), nil |
| 265 | } |
| 266 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 267 | func (rhp *RequestHandlerProxy) Delete_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 268 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 269 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 270 | err := errors.New("invalid-number-of-args") |
| 271 | return nil, err |
| 272 | } |
| 273 | |
| 274 | device := &voltha.Device{} |
| 275 | transactionID := &ic.StrType{} |
| 276 | fromTopic := &ic.StrType{} |
| 277 | for _, arg := range args { |
| 278 | switch arg.Key { |
| 279 | case "device": |
| 280 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 281 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 282 | return nil, err |
| 283 | } |
| 284 | case kafka.TransactionKey: |
| 285 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 286 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 287 | return nil, err |
| 288 | } |
| 289 | case kafka.FromTopic: |
| 290 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 291 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 292 | return nil, err |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | //Update the core reference for that device |
| 297 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 298 | //Invoke the delete_device API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 299 | if err := rhp.adapter.Delete_device(ctx, device); err != nil { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 300 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 301 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 302 | return new(empty.Empty), nil |
| 303 | } |
| 304 | |
| 305 | func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) { |
| 306 | return new(empty.Empty), nil |
| 307 | } |
| 308 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 309 | func (rhp *RequestHandlerProxy) Update_flows_bulk(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 310 | logger.Debug(ctx, "Update_flows_bulk") |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 311 | if len(args) < 5 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 312 | logger.Warn(ctx, "Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 313 | err := errors.New("invalid-number-of-args") |
| 314 | return nil, err |
| 315 | } |
| 316 | device := &voltha.Device{} |
| 317 | transactionID := &ic.StrType{} |
| 318 | flows := &voltha.Flows{} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 319 | flowMetadata := &voltha.FlowMetadata{} |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 320 | groups := &voltha.FlowGroups{} |
| 321 | for _, arg := range args { |
| 322 | switch arg.Key { |
| 323 | case "device": |
| 324 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 325 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 326 | return nil, err |
| 327 | } |
| 328 | case "flows": |
| 329 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 330 | logger.Warnw(ctx, "cannot-unmarshal-flows", log.Fields{"error": err}) |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 331 | return nil, err |
| 332 | } |
| 333 | case "groups": |
| 334 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 335 | logger.Warnw(ctx, "cannot-unmarshal-groups", log.Fields{"error": err}) |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 336 | return nil, err |
| 337 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 338 | case "flow_metadata": |
| 339 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 340 | logger.Warnw(ctx, "cannot-unmarshal-metadata", log.Fields{"error": err}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 341 | return nil, err |
| 342 | } |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 343 | case kafka.TransactionKey: |
| 344 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 345 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 346 | return nil, err |
| 347 | } |
| 348 | } |
| 349 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "Update_flows_bulk", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 351 | //Invoke the bulk flow update API of the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 352 | if err := rhp.adapter.Update_flows_bulk(ctx, device, flows, groups, flowMetadata); err != nil { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 353 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 354 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 355 | return new(empty.Empty), nil |
| 356 | } |
| 357 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 358 | func (rhp *RequestHandlerProxy) Update_flows_incrementally(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 359 | logger.Debug(ctx, "Update_flows_incrementally") |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 360 | if len(args) < 5 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 361 | logger.Warn(ctx, "Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args}) |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 362 | err := errors.New("invalid-number-of-args") |
| 363 | return nil, err |
| 364 | } |
| 365 | device := &voltha.Device{} |
| 366 | transactionID := &ic.StrType{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 367 | flows := &openflow_13.FlowChanges{} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 368 | flowMetadata := &voltha.FlowMetadata{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 369 | groups := &openflow_13.FlowGroupChanges{} |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 370 | for _, arg := range args { |
| 371 | switch arg.Key { |
| 372 | case "device": |
| 373 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 374 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 375 | return nil, err |
| 376 | } |
| 377 | case "flow_changes": |
| 378 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 379 | logger.Warnw(ctx, "cannot-unmarshal-flows", log.Fields{"error": err}) |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 380 | return nil, err |
| 381 | } |
| 382 | case "group_changes": |
| 383 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 384 | logger.Warnw(ctx, "cannot-unmarshal-groups", log.Fields{"error": err}) |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 385 | return nil, err |
| 386 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 387 | case "flow_metadata": |
| 388 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 389 | logger.Warnw(ctx, "cannot-unmarshal-metadata", log.Fields{"error": err}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 390 | return nil, err |
| 391 | } |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 392 | case kafka.TransactionKey: |
| 393 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 394 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 395 | return nil, err |
| 396 | } |
| 397 | } |
| 398 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 399 | logger.Debugw(ctx, "Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 400 | //Invoke the incremental flow update API of the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 401 | if err := rhp.adapter.Update_flows_incrementally(ctx, device, flows, groups, flowMetadata); err != nil { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 402 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 403 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 404 | return new(empty.Empty), nil |
| 405 | } |
| 406 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 407 | func (rhp *RequestHandlerProxy) Update_pm_config(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 408 | logger.Debug(ctx, "Update_pm_config") |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 409 | if len(args) < 2 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 410 | logger.Warn(ctx, "Update_pm_config-invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 411 | err := errors.New("invalid-number-of-args") |
| 412 | return nil, err |
| 413 | } |
| 414 | device := &voltha.Device{} |
| 415 | transactionID := &ic.StrType{} |
| 416 | pmConfigs := &voltha.PmConfigs{} |
| 417 | for _, arg := range args { |
| 418 | switch arg.Key { |
| 419 | case "device": |
| 420 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 421 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 422 | return nil, err |
| 423 | } |
| 424 | case "pm_configs": |
| 425 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 426 | logger.Warnw(ctx, "cannot-unmarshal-pm-configs", log.Fields{"error": err}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 427 | return nil, err |
| 428 | } |
| 429 | case kafka.TransactionKey: |
| 430 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 431 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 432 | return nil, err |
| 433 | } |
| 434 | } |
| 435 | } |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 436 | logger.Debugw(ctx, "Update_pm_config", log.Fields{"device-id": device.Id, "pmConfigs": pmConfigs}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 437 | //Invoke the pm config update API of the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 438 | if err := rhp.adapter.Update_pm_config(ctx, device, pmConfigs); err != nil { |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 439 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 440 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 441 | return new(empty.Empty), nil |
| 442 | } |
| 443 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 444 | func (rhp *RequestHandlerProxy) Receive_packet_out(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 445 | logger.Debugw(ctx, "Receive_packet_out", log.Fields{"args": args}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 446 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 447 | logger.Warn(ctx, "Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 448 | err := errors.New("invalid-number-of-args") |
| 449 | return nil, err |
| 450 | } |
| 451 | deviceId := &ic.StrType{} |
| 452 | egressPort := &ic.IntType{} |
| 453 | packet := &openflow_13.OfpPacketOut{} |
| 454 | transactionID := &ic.StrType{} |
| 455 | for _, arg := range args { |
| 456 | switch arg.Key { |
| 457 | case "deviceId": |
| 458 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 459 | logger.Warnw(ctx, "cannot-unmarshal-device-id", log.Fields{"error": err}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 460 | return nil, err |
| 461 | } |
| 462 | case "outPort": |
| 463 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 464 | logger.Warnw(ctx, "cannot-unmarshal-egressPort", log.Fields{"error": err}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 465 | return nil, err |
| 466 | } |
| 467 | case "packet": |
| 468 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 469 | logger.Warnw(ctx, "cannot-unmarshal-packet", log.Fields{"error": err}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 470 | return nil, err |
| 471 | } |
| 472 | case kafka.TransactionKey: |
| 473 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 474 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 475 | return nil, err |
| 476 | } |
| 477 | } |
| 478 | } |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 479 | logger.Debugw(ctx, "Receive_packet_out", log.Fields{"device-id": deviceId.Val, "outPort": egressPort, "packet": packet}) |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 480 | //Invoke the adopt device on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 481 | if err := rhp.adapter.Receive_packet_out(ctx, deviceId.Val, int(egressPort.Val), packet); err != nil { |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 482 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 483 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 484 | return new(empty.Empty), nil |
| 485 | } |
| 486 | |
| 487 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 488 | return new(empty.Empty), nil |
| 489 | } |
| 490 | |
| 491 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 492 | return new(empty.Empty), nil |
| 493 | } |
| 494 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 495 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(ctx context.Context, args []*ic.Argument) (*ic.SwitchCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 496 | if len(args) < 2 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 497 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 498 | err := errors.New("invalid-number-of-args") |
| 499 | return nil, err |
| 500 | } |
| 501 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 502 | transactionID := &ic.StrType{} |
| 503 | for _, arg := range args { |
| 504 | switch arg.Key { |
| 505 | case "device": |
| 506 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 507 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 508 | return nil, err |
| 509 | } |
| 510 | case kafka.TransactionKey: |
| 511 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 512 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 513 | return nil, err |
| 514 | } |
| 515 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 516 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 517 | |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 518 | logger.Debugw(ctx, "Get_ofp_device_info", log.Fields{"device-id": device.Id}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 519 | |
| 520 | var cap *ic.SwitchCapability |
| 521 | var err error |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 522 | if cap, err = rhp.adapter.Get_ofp_device_info(ctx, device); err != nil { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 523 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 524 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 525 | logger.Debugw(ctx, "Get_ofp_device_info", log.Fields{"cap": cap}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 526 | return cap, nil |
| 527 | } |
| 528 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 529 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 530 | if len(args) < 2 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 531 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 532 | err := errors.New("invalid-number-of-args") |
| 533 | return nil, err |
| 534 | } |
| 535 | iaMsg := &ic.InterAdapterMessage{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 536 | transactionID := &ic.StrType{} |
| 537 | for _, arg := range args { |
| 538 | switch arg.Key { |
| 539 | case "msg": |
| 540 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 541 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 542 | return nil, err |
| 543 | } |
| 544 | case kafka.TransactionKey: |
| 545 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 546 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 547 | return nil, err |
| 548 | } |
| 549 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 550 | } |
| 551 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 552 | logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 553 | |
| 554 | //Invoke the inter adapter API on the handler |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 555 | if err := rhp.adapter.Process_inter_adapter_message(ctx, iaMsg); err != nil { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 556 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 557 | } |
| 558 | |
| 559 | return new(empty.Empty), nil |
| 560 | } |
| 561 | |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame^] | 562 | func (rhp *RequestHandlerProxy) Process_tech_profile_instance_request(ctx context.Context, args []*ic.Argument) (*ic.InterAdapterTechProfileDownloadMessage, error) { |
| 563 | if len(args) < 2 { |
| 564 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
| 565 | err := errors.New("invalid-number-of-args") |
| 566 | return nil, err |
| 567 | } |
| 568 | iaTpReqMsg := &ic.InterAdapterTechProfileInstanceRequestMessage{} |
| 569 | transactionID := &ic.StrType{} |
| 570 | for _, arg := range args { |
| 571 | switch arg.Key { |
| 572 | case "msg": |
| 573 | if err := ptypes.UnmarshalAny(arg.Value, iaTpReqMsg); err != nil { |
| 574 | logger.Warnw(ctx, "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 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 580 | return nil, err |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | logger.Debugw(ctx, "Process_tech_profile_instance_request", log.Fields{"tpPath": iaTpReqMsg.TpInstancePath}) |
| 586 | |
| 587 | //Invoke the tech profile instance request |
| 588 | tpInst := rhp.adapter.Process_tech_profile_instance_request(ctx, iaTpReqMsg) |
| 589 | |
| 590 | return tpInst, nil |
| 591 | } |
| 592 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 593 | func (rhp *RequestHandlerProxy) Download_image(ctx context.Context, args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 594 | device, image, err := unMarshalImageDowload(args, ctx) |
| 595 | if err != nil { |
| 596 | return nil, err |
| 597 | } |
| 598 | |
| 599 | imageDownload, err := rhp.adapter.Download_image(ctx, device, image) |
| 600 | if err != nil { |
| 601 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 602 | } |
| 603 | return imageDownload, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 604 | } |
| 605 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 606 | func (rhp *RequestHandlerProxy) Get_image_download_status(ctx context.Context, args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 607 | device, image, err := unMarshalImageDowload(args, ctx) |
| 608 | if err != nil { |
| 609 | return nil, err |
| 610 | } |
| 611 | |
| 612 | imageDownload, err := rhp.adapter.Get_image_download_status(ctx, device, image) |
| 613 | if err != nil { |
| 614 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 615 | } |
| 616 | return imageDownload, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 617 | } |
| 618 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 619 | func (rhp *RequestHandlerProxy) Cancel_image_download(ctx context.Context, args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 620 | device, image, err := unMarshalImageDowload(args, ctx) |
| 621 | if err != nil { |
| 622 | return nil, err |
| 623 | } |
| 624 | |
| 625 | imageDownload, err := rhp.adapter.Cancel_image_download(ctx, device, image) |
| 626 | if err != nil { |
| 627 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 628 | } |
| 629 | return imageDownload, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 630 | } |
| 631 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 632 | func (rhp *RequestHandlerProxy) Activate_image_update(ctx context.Context, args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 633 | |
| 634 | device, image, err := unMarshalImageDowload(args, ctx) |
| 635 | if err != nil { |
| 636 | return nil, err |
| 637 | } |
| 638 | |
| 639 | imageDownload, err := rhp.adapter.Activate_image_update(ctx, device, image) |
| 640 | if err != nil { |
| 641 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 642 | } |
| 643 | return imageDownload, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 646 | func (rhp *RequestHandlerProxy) Revert_image_update(ctx context.Context, args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 647 | device, image, err := unMarshalImageDowload(args, ctx) |
| 648 | if err != nil { |
| 649 | return nil, err |
| 650 | } |
| 651 | |
| 652 | imageDownload, err := rhp.adapter.Revert_image_update(ctx, device, image) |
| 653 | if err != nil { |
| 654 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 655 | } |
| 656 | return imageDownload, nil |
| 657 | } |
| 658 | |
| 659 | func unMarshalImageDowload(args []*ic.Argument, ctx context.Context) (*voltha.Device, *voltha.ImageDownload, error) { |
| 660 | if len(args) < 4 { |
| 661 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
| 662 | err := errors.New("invalid-number-of-args") |
| 663 | return nil, nil, err |
| 664 | } |
| 665 | device := &voltha.Device{} |
| 666 | image := &voltha.ImageDownload{} |
| 667 | transactionID := &ic.StrType{} |
| 668 | fromTopic := &ic.StrType{} |
| 669 | for _, arg := range args { |
| 670 | switch arg.Key { |
| 671 | case "device": |
| 672 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 673 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
| 674 | return nil, nil, err |
| 675 | } |
| 676 | case "request": |
| 677 | if err := ptypes.UnmarshalAny(arg.Value, image); err != nil { |
| 678 | logger.Warnw(ctx, "cannot-unmarshal-image", log.Fields{"error": err}) |
| 679 | return nil, nil, err |
| 680 | } |
| 681 | case kafka.TransactionKey: |
| 682 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 683 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 684 | return nil, nil, err |
| 685 | } |
| 686 | case kafka.FromTopic: |
| 687 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 688 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 689 | return nil, nil, err |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | return device, image, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 694 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 695 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 696 | func (rhp *RequestHandlerProxy) Enable_port(ctx context.Context, args []*ic.Argument) error { |
| 697 | logger.Debugw(ctx, "enable_port", log.Fields{"args": args}) |
| 698 | deviceId, port, err := rhp.getEnableDisableParams(ctx, args) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 699 | if err != nil { |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 700 | logger.Warnw(ctx, "enable_port", log.Fields{"args": args, "device-id": deviceId, "port": port}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 701 | return err |
| 702 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 703 | return rhp.adapter.Enable_port(ctx, deviceId, port) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 704 | } |
| 705 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 706 | func (rhp *RequestHandlerProxy) Disable_port(ctx context.Context, args []*ic.Argument) error { |
| 707 | logger.Debugw(ctx, "disable_port", log.Fields{"args": args}) |
| 708 | deviceId, port, err := rhp.getEnableDisableParams(ctx, args) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 709 | if err != nil { |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 710 | logger.Warnw(ctx, "disable_port", log.Fields{"args": args, "device-id": deviceId, "port": port}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 711 | return err |
| 712 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 713 | return rhp.adapter.Disable_port(ctx, deviceId, port) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 714 | } |
| 715 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 716 | func (rhp *RequestHandlerProxy) getEnableDisableParams(ctx context.Context, args []*ic.Argument) (string, *voltha.Port, error) { |
| 717 | logger.Debugw(ctx, "getEnableDisableParams", log.Fields{"args": args}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 718 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 719 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 720 | return "", nil, errors.New("invalid-number-of-args") |
| 721 | } |
| 722 | deviceId := &ic.StrType{} |
| 723 | port := &voltha.Port{} |
| 724 | for _, arg := range args { |
| 725 | switch arg.Key { |
| 726 | case "deviceId": |
| 727 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 728 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 729 | return "", nil, err |
| 730 | } |
| 731 | case "port": |
| 732 | if err := ptypes.UnmarshalAny(arg.Value, port); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 733 | logger.Warnw(ctx, "cannot-unmarshal-port", log.Fields{"error": err}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 734 | return "", nil, err |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | return deviceId.Val, port, nil |
| 739 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 740 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 741 | func (rhp *RequestHandlerProxy) Child_device_lost(ctx context.Context, args []*ic.Argument) error { |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 742 | if len(args) < 2 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 743 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 744 | return errors.New("invalid-number-of-args") |
| 745 | } |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 746 | childDevice := &voltha.Device{} |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 747 | fromTopic := &ic.StrType{} |
| 748 | for _, arg := range args { |
| 749 | switch arg.Key { |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 750 | case "childDevice": |
| 751 | if err := ptypes.UnmarshalAny(arg.Value, childDevice); err != nil { |
| 752 | logger.Warnw(ctx, "cannot-unmarshal-child-device", log.Fields{"error": err}) |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 753 | return err |
| 754 | } |
| 755 | case kafka.FromTopic: |
| 756 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 757 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 758 | return err |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | //Update the core reference for that device |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 763 | rhp.coreProxy.UpdateCoreReference(childDevice.ParentId, fromTopic.Val) |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 764 | //Invoke the Child_device_lost API on the adapter |
Girish Gowdra | 6f9b10e | 2021-03-11 14:36:39 -0800 | [diff] [blame] | 765 | if err := rhp.adapter.Child_device_lost(ctx, childDevice); err != nil { |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 766 | return status.Errorf(codes.NotFound, "%s", err.Error()) |
| 767 | } |
| 768 | return nil |
| 769 | } |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 770 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 771 | func (rhp *RequestHandlerProxy) Start_omci_test(ctx context.Context, args []*ic.Argument) (*ic.TestResponse, error) { |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 772 | if len(args) < 2 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 773 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 774 | err := errors.New("invalid-number-of-args") |
| 775 | return nil, err |
| 776 | } |
| 777 | |
| 778 | // TODO: See related comment in voltha-go:adapter_proxy_go:startOmciTest() |
| 779 | // Second argument should perhaps be uuid instead of omcitestrequest |
| 780 | |
| 781 | device := &voltha.Device{} |
| 782 | request := &voltha.OmciTestRequest{} |
| 783 | for _, arg := range args { |
| 784 | switch arg.Key { |
| 785 | case "device": |
| 786 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 787 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 788 | return nil, err |
| 789 | } |
| 790 | case "omcitestrequest": |
| 791 | if err := ptypes.UnmarshalAny(arg.Value, request); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 792 | logger.Warnw(ctx, "cannot-unmarshal-omcitestrequest", log.Fields{"error": err}) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 793 | return nil, err |
| 794 | } |
| 795 | } |
| 796 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 797 | logger.Debugw(ctx, "Start_omci_test", log.Fields{"device-id": device.Id, "req": request}) |
| 798 | result, err := rhp.adapter.Start_omci_test(ctx, device, request) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 799 | if err != nil { |
| 800 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 801 | } |
| 802 | return result, nil |
| 803 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 804 | func (rhp *RequestHandlerProxy) Get_ext_value(ctx context.Context, args []*ic.Argument) (*voltha.ReturnValues, error) { |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 805 | if len(args) < 3 { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 806 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 807 | return nil, errors.New("invalid-number-of-args") |
| 808 | } |
| 809 | |
| 810 | pDeviceId := &ic.StrType{} |
| 811 | device := &voltha.Device{} |
| 812 | valuetype := &ic.IntType{} |
| 813 | for _, arg := range args { |
| 814 | switch arg.Key { |
| 815 | case "device": |
| 816 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 817 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 818 | return nil, err |
| 819 | } |
| 820 | case "pDeviceId": |
| 821 | if err := ptypes.UnmarshalAny(arg.Value, pDeviceId); err != nil { |
Girish Gowdra | 9a50f03 | 2020-09-16 13:21:10 -0700 | [diff] [blame] | 822 | logger.Warnw(ctx, "cannot-unmarshal-parent-device-id", log.Fields{"error": err}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 823 | return nil, err |
| 824 | } |
| 825 | case "valuetype": |
| 826 | if err := ptypes.UnmarshalAny(arg.Value, valuetype); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 827 | logger.Warnw(ctx, "cannot-unmarshal-valuetype", log.Fields{"error": err}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 828 | return nil, err |
| 829 | } |
| 830 | default: |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 831 | logger.Warnw(ctx, "key-not-found", log.Fields{"arg.Key": arg.Key}) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
| 835 | //Invoke the Get_value API on the adapter |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 836 | return rhp.adapter.Get_ext_value(ctx, pDeviceId.Val, device, voltha.ValueType_Type(valuetype.Val)) |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 837 | } |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 838 | |
| 839 | func (rhp *RequestHandlerProxy) Single_get_value_request(ctx context.Context, args []*ic.Argument) (*extension.SingleGetValueResponse, error) { |
| 840 | logger.Debugw(ctx, "req handler Single_get_value_request", log.Fields{"no of args": len(args), "args": args}) |
| 841 | |
| 842 | if len(args) < 1 { |
| 843 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
| 844 | return nil, errors.New("invalid-number-of-args") |
| 845 | } |
| 846 | singleGetvalueReq := extension.SingleGetValueRequest{} |
| 847 | errResp := func(status extension.GetValueResponse_Status, reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 848 | return &extension.SingleGetValueResponse{ |
| 849 | Response: &extension.GetValueResponse{ |
| 850 | Status: status, |
| 851 | ErrReason: reason, |
| 852 | }, |
| 853 | } |
| 854 | } |
| 855 | for _, arg := range args { |
| 856 | switch arg.Key { |
| 857 | case "request": |
| 858 | if err := ptypes.UnmarshalAny(arg.Value, &singleGetvalueReq); err != nil { |
| 859 | logger.Warnw(ctx, "cannot-unmarshal-singleGetvalueReq", log.Fields{"error": err}) |
| 860 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_REASON_UNDEFINED), nil |
| 861 | } |
| 862 | default: |
| 863 | logger.Warnw(ctx, "key-not-found", log.Fields{"arg.Key": arg.Key}) |
| 864 | } |
| 865 | } |
| 866 | logger.Debugw(ctx, "invoke rhp.adapter.Single_get_value_request ", log.Fields{"singleGetvalueReq": singleGetvalueReq}) |
| 867 | return rhp.adapter.Single_get_value_request(ctx, singleGetvalueReq) |
| 868 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 869 | |
| 870 | func (rhp *RequestHandlerProxy) getDeviceDownloadImageRequest(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageDownloadRequest, error) { |
| 871 | logger.Debugw(ctx, "getDeviceDownloadImageRequest", log.Fields{"args": args}) |
| 872 | if len(args) < 1 { |
| 873 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
| 874 | return nil, errors.New("invalid-number-of-args") |
| 875 | } |
| 876 | |
| 877 | deviceDownloadImageReq := ic.DeviceImageDownloadRequest{} |
| 878 | |
| 879 | for _, arg := range args { |
| 880 | switch arg.Key { |
| 881 | case "deviceImageDownloadReq": |
| 882 | if err := ptypes.UnmarshalAny(arg.Value, &deviceDownloadImageReq); err != nil { |
| 883 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
| 884 | return nil, err |
| 885 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | return &deviceDownloadImageReq, nil |
| 889 | } |
| 890 | |
| 891 | func (rhp *RequestHandlerProxy) getDeviceImageRequest(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageRequest, error) { |
| 892 | logger.Debugw(ctx, "getDeviceImageRequest", log.Fields{"args": args}) |
| 893 | if len(args) < 1 { |
| 894 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
| 895 | return nil, errors.New("invalid-number-of-args") |
| 896 | } |
| 897 | |
| 898 | deviceImageReq := ic.DeviceImageRequest{} |
| 899 | |
| 900 | for _, arg := range args { |
| 901 | switch arg.Key { |
| 902 | case "deviceImageReq": |
| 903 | if err := ptypes.UnmarshalAny(arg.Value, &deviceImageReq); err != nil { |
| 904 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
| 905 | return nil, err |
| 906 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | return &deviceImageReq, nil |
| 910 | } |
| 911 | |
| 912 | func (rhp *RequestHandlerProxy) getDeviceID(ctx context.Context, args []*ic.Argument) (string, error) { |
| 913 | logger.Debugw(ctx, "getDeviceID", log.Fields{"args": args}) |
| 914 | |
| 915 | deviceId := &ic.StrType{} |
| 916 | |
| 917 | for _, arg := range args { |
| 918 | switch arg.Key { |
| 919 | case "deviceId": |
| 920 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 921 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
| 922 | return "", err |
| 923 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 924 | } |
| 925 | } |
ssiddiqui | 47348f6 | 2021-05-20 20:41:15 +0530 | [diff] [blame] | 926 | |
| 927 | if deviceId.Val == "" { |
| 928 | return "", errors.New("invalid argument") |
| 929 | } |
| 930 | |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 931 | return deviceId.Val, nil |
| 932 | } |
| 933 | |
| 934 | func (rhp *RequestHandlerProxy) Download_onu_image(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageResponse, error) { |
| 935 | imageDownloadReq, err := rhp.getDeviceDownloadImageRequest(ctx, args) |
| 936 | if err != nil { |
| 937 | return nil, err |
| 938 | } |
| 939 | |
| 940 | imageDownloadRsp, err := rhp.adapter.Download_onu_image(ctx, imageDownloadReq) |
| 941 | if err != nil { |
| 942 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 943 | } |
| 944 | return imageDownloadRsp, nil |
| 945 | } |
| 946 | |
| 947 | func (rhp *RequestHandlerProxy) Get_onu_image_status(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageResponse, error) { |
| 948 | imageStatusReq, err := rhp.getDeviceImageRequest(ctx, args) |
| 949 | if err != nil { |
| 950 | return nil, err |
| 951 | } |
| 952 | |
| 953 | imageStatus, err := rhp.adapter.Get_onu_image_status(ctx, imageStatusReq) |
| 954 | if err != nil { |
| 955 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 956 | } |
| 957 | return imageStatus, nil |
| 958 | } |
| 959 | |
| 960 | func (rhp *RequestHandlerProxy) Abort_onu_image_upgrade(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageResponse, error) { |
| 961 | imageAbortReq, err := rhp.getDeviceImageRequest(ctx, args) |
| 962 | if err != nil { |
| 963 | return nil, err |
| 964 | } |
| 965 | |
| 966 | imageAbortRsp, err := rhp.adapter.Abort_onu_image_upgrade(ctx, imageAbortReq) |
| 967 | if err != nil { |
| 968 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 969 | } |
| 970 | return imageAbortRsp, nil |
| 971 | } |
| 972 | |
| 973 | func (rhp *RequestHandlerProxy) Activate_onu_image(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageResponse, error) { |
| 974 | imageActivateReq, err := rhp.getDeviceImageRequest(ctx, args) |
| 975 | if err != nil { |
| 976 | return nil, err |
| 977 | } |
| 978 | |
| 979 | imageActivateRsp, err := rhp.adapter.Activate_onu_image(ctx, imageActivateReq) |
| 980 | if err != nil { |
| 981 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 982 | } |
| 983 | return imageActivateRsp, nil |
| 984 | } |
| 985 | |
| 986 | func (rhp *RequestHandlerProxy) Commit_onu_image(ctx context.Context, args []*ic.Argument) (*voltha.DeviceImageResponse, error) { |
| 987 | imageCommitReq, err := rhp.getDeviceImageRequest(ctx, args) |
| 988 | if err != nil { |
| 989 | return nil, err |
| 990 | } |
| 991 | |
| 992 | imageCommitRsp, err := rhp.adapter.Commit_onu_image(ctx, imageCommitReq) |
| 993 | if err != nil { |
| 994 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 995 | } |
| 996 | |
| 997 | return imageCommitRsp, nil |
| 998 | } |
| 999 | |
| 1000 | func (rhp *RequestHandlerProxy) Get_onu_images(ctx context.Context, args []*ic.Argument) (*voltha.OnuImages, error) { |
| 1001 | deviceID, err := rhp.getDeviceID(ctx, args) |
| 1002 | if err != nil { |
| 1003 | return nil, err |
| 1004 | } |
| 1005 | |
| 1006 | onuImages, err := rhp.adapter.Get_onu_images(ctx, deviceID) |
| 1007 | if err != nil { |
| 1008 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 1009 | } |
| 1010 | return onuImages, nil |
| 1011 | } |