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 ( |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 19 | "context" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 20 | "errors" |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 21 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 22 | "github.com/golang/protobuf/ptypes" |
| 23 | "github.com/golang/protobuf/ptypes/empty" |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters" |
| 25 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 28 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 29 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 30 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 31 | "google.golang.org/grpc/codes" |
| 32 | "google.golang.org/grpc/status" |
| 33 | ) |
| 34 | |
| 35 | type RequestHandlerProxy struct { |
| 36 | TestMode bool |
| 37 | coreInstanceId string |
| 38 | adapter adapters.IAdapter |
| 39 | coreProxy adapterif.CoreProxy |
| 40 | } |
| 41 | |
| 42 | func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy adapterif.CoreProxy) *RequestHandlerProxy { |
| 43 | var proxy RequestHandlerProxy |
| 44 | proxy.coreInstanceId = coreInstanceId |
| 45 | proxy.adapter = iadapter |
| 46 | proxy.coreProxy = cProxy |
| 47 | return &proxy |
| 48 | } |
| 49 | |
| 50 | func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) { |
| 51 | return new(empty.Empty), nil |
| 52 | } |
| 53 | |
| 54 | func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) { |
| 55 | return nil, nil |
| 56 | } |
| 57 | |
| 58 | func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) { |
| 59 | return nil, nil |
| 60 | } |
| 61 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 62 | func (rhp *RequestHandlerProxy) Adopt_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 63 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 64 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 65 | err := errors.New("invalid-number-of-args") |
| 66 | return nil, err |
| 67 | } |
| 68 | device := &voltha.Device{} |
| 69 | transactionID := &ic.StrType{} |
| 70 | fromTopic := &ic.StrType{} |
| 71 | for _, arg := range args { |
| 72 | switch arg.Key { |
| 73 | case "device": |
| 74 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 75 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 76 | return nil, err |
| 77 | } |
| 78 | case kafka.TransactionKey: |
| 79 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 80 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 81 | return nil, err |
| 82 | } |
| 83 | case kafka.FromTopic: |
| 84 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 85 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 86 | return nil, err |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 91 | logger.Debugw(ctx, "Adopt_device", log.Fields{"deviceId": device.Id}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 92 | |
| 93 | //Update the core reference for that device |
| 94 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 95 | |
| 96 | //Invoke the adopt device on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 97 | if err := rhp.adapter.Adopt_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 98 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 99 | } |
| 100 | |
| 101 | return new(empty.Empty), nil |
| 102 | } |
| 103 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 104 | func (rhp *RequestHandlerProxy) Reconcile_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 105 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 106 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 107 | err := errors.New("invalid-number-of-args") |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | device := &voltha.Device{} |
| 112 | transactionID := &ic.StrType{} |
| 113 | fromTopic := &ic.StrType{} |
| 114 | for _, arg := range args { |
| 115 | switch arg.Key { |
| 116 | case "device": |
| 117 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 118 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 119 | return nil, err |
| 120 | } |
| 121 | case kafka.TransactionKey: |
| 122 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 123 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 124 | return nil, err |
| 125 | } |
| 126 | case kafka.FromTopic: |
| 127 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 128 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 129 | return nil, err |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | //Update the core reference for that device |
| 134 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 135 | |
| 136 | //Invoke the reconcile device API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 137 | if err := rhp.adapter.Reconcile_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 138 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 139 | } |
| 140 | return new(empty.Empty), nil |
| 141 | } |
| 142 | |
| 143 | func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) { |
| 144 | return new(empty.Empty), nil |
| 145 | } |
| 146 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 147 | func (rhp *RequestHandlerProxy) Disable_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 148 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 149 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 150 | err := errors.New("invalid-number-of-args") |
| 151 | return nil, err |
| 152 | } |
| 153 | |
| 154 | device := &voltha.Device{} |
| 155 | transactionID := &ic.StrType{} |
| 156 | fromTopic := &ic.StrType{} |
| 157 | for _, arg := range args { |
| 158 | switch arg.Key { |
| 159 | case "device": |
| 160 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 161 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 162 | return nil, err |
| 163 | } |
| 164 | case kafka.TransactionKey: |
| 165 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 166 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 167 | return nil, err |
| 168 | } |
| 169 | case kafka.FromTopic: |
| 170 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 171 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 172 | return nil, err |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | //Update the core reference for that device |
| 177 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 178 | //Invoke the Disable_device API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 179 | if err := rhp.adapter.Disable_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 180 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 181 | } |
| 182 | return new(empty.Empty), nil |
| 183 | } |
| 184 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 185 | func (rhp *RequestHandlerProxy) Reenable_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 186 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 187 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 188 | err := errors.New("invalid-number-of-args") |
| 189 | return nil, err |
| 190 | } |
| 191 | |
| 192 | device := &voltha.Device{} |
| 193 | transactionID := &ic.StrType{} |
| 194 | fromTopic := &ic.StrType{} |
| 195 | for _, arg := range args { |
| 196 | switch arg.Key { |
| 197 | case "device": |
| 198 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 199 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 200 | return nil, err |
| 201 | } |
| 202 | case kafka.TransactionKey: |
| 203 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 204 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 205 | return nil, err |
| 206 | } |
| 207 | case kafka.FromTopic: |
| 208 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 209 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 210 | return nil, err |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | //Update the core reference for that device |
| 215 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 216 | //Invoke the Reenable_device API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 217 | if err := rhp.adapter.Reenable_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 218 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 219 | } |
| 220 | return new(empty.Empty), nil |
| 221 | } |
| 222 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 223 | func (rhp *RequestHandlerProxy) Reboot_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 224 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 225 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 226 | err := errors.New("invalid-number-of-args") |
| 227 | return nil, err |
| 228 | } |
| 229 | |
| 230 | device := &voltha.Device{} |
| 231 | transactionID := &ic.StrType{} |
| 232 | fromTopic := &ic.StrType{} |
| 233 | for _, arg := range args { |
| 234 | switch arg.Key { |
| 235 | case "device": |
| 236 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 237 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 238 | return nil, err |
| 239 | } |
| 240 | case kafka.TransactionKey: |
| 241 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 242 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 243 | return nil, err |
| 244 | } |
| 245 | case kafka.FromTopic: |
| 246 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 247 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 248 | return nil, err |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | //Update the core reference for that device |
| 253 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 254 | //Invoke the Reboot_device API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 255 | if err := rhp.adapter.Reboot_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 256 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 257 | } |
| 258 | return new(empty.Empty), nil |
| 259 | |
| 260 | } |
| 261 | |
| 262 | func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) { |
| 263 | return new(empty.Empty), nil |
| 264 | } |
| 265 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 266 | func (rhp *RequestHandlerProxy) Delete_device(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 267 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 268 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 269 | err := errors.New("invalid-number-of-args") |
| 270 | return nil, err |
| 271 | } |
| 272 | |
| 273 | device := &voltha.Device{} |
| 274 | transactionID := &ic.StrType{} |
| 275 | fromTopic := &ic.StrType{} |
| 276 | for _, arg := range args { |
| 277 | switch arg.Key { |
| 278 | case "device": |
| 279 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 280 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 281 | return nil, err |
| 282 | } |
| 283 | case kafka.TransactionKey: |
| 284 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 285 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 286 | return nil, err |
| 287 | } |
| 288 | case kafka.FromTopic: |
| 289 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 290 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 291 | return nil, err |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | //Update the core reference for that device |
| 296 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 297 | //Invoke the delete_device API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 298 | if err := rhp.adapter.Delete_device(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 299 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 300 | } |
| 301 | return new(empty.Empty), nil |
| 302 | } |
| 303 | |
| 304 | func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) { |
| 305 | return new(empty.Empty), nil |
| 306 | } |
| 307 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 308 | func (rhp *RequestHandlerProxy) Update_flows_bulk(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 309 | logger.Debug(ctx, "Update_flows_bulk") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 310 | if len(args) < 5 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 311 | logger.Warn(ctx, "Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 312 | err := errors.New("invalid-number-of-args") |
| 313 | return nil, err |
| 314 | } |
| 315 | device := &voltha.Device{} |
| 316 | transactionID := &ic.StrType{} |
| 317 | flows := &voltha.Flows{} |
| 318 | flowMetadata := &voltha.FlowMetadata{} |
| 319 | groups := &voltha.FlowGroups{} |
| 320 | for _, arg := range args { |
| 321 | switch arg.Key { |
| 322 | case "device": |
| 323 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 324 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 325 | return nil, err |
| 326 | } |
| 327 | case "flows": |
| 328 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 329 | logger.Warnw(ctx, "cannot-unmarshal-flows", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 330 | return nil, err |
| 331 | } |
| 332 | case "groups": |
| 333 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 334 | logger.Warnw(ctx, "cannot-unmarshal-groups", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 335 | return nil, err |
| 336 | } |
| 337 | case "flow_metadata": |
| 338 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 339 | logger.Warnw(ctx, "cannot-unmarshal-metadata", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 340 | return nil, err |
| 341 | } |
| 342 | case kafka.TransactionKey: |
| 343 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 344 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 345 | return nil, err |
| 346 | } |
| 347 | } |
| 348 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 349 | logger.Debugw(ctx, "Update_flows_bulk", log.Fields{"flows": flows, "groups": groups}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 350 | //Invoke the bulk flow update API of the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 351 | if err := rhp.adapter.Update_flows_bulk(ctx, device, flows, groups, flowMetadata); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 352 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 353 | } |
| 354 | return new(empty.Empty), nil |
| 355 | } |
| 356 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 357 | func (rhp *RequestHandlerProxy) Update_flows_incrementally(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 358 | logger.Debug(ctx, "Update_flows_incrementally") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 359 | if len(args) < 5 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 360 | logger.Warn(ctx, "Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 361 | err := errors.New("invalid-number-of-args") |
| 362 | return nil, err |
| 363 | } |
| 364 | device := &voltha.Device{} |
| 365 | transactionID := &ic.StrType{} |
| 366 | flows := &openflow_13.FlowChanges{} |
| 367 | flowMetadata := &voltha.FlowMetadata{} |
| 368 | groups := &openflow_13.FlowGroupChanges{} |
| 369 | for _, arg := range args { |
| 370 | switch arg.Key { |
| 371 | case "device": |
| 372 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 373 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 374 | return nil, err |
| 375 | } |
| 376 | case "flow_changes": |
| 377 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 378 | logger.Warnw(ctx, "cannot-unmarshal-flows", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 379 | return nil, err |
| 380 | } |
| 381 | case "group_changes": |
| 382 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 383 | logger.Warnw(ctx, "cannot-unmarshal-groups", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 384 | return nil, err |
| 385 | } |
| 386 | case "flow_metadata": |
| 387 | if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 388 | logger.Warnw(ctx, "cannot-unmarshal-metadata", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 389 | return nil, err |
| 390 | } |
| 391 | case kafka.TransactionKey: |
| 392 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 393 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 394 | return nil, err |
| 395 | } |
| 396 | } |
| 397 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 398 | logger.Debugw(ctx, "Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 399 | //Invoke the incremental flow update API of the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 400 | if err := rhp.adapter.Update_flows_incrementally(ctx, device, flows, groups, flowMetadata); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 401 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 402 | } |
| 403 | return new(empty.Empty), nil |
| 404 | } |
| 405 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 406 | func (rhp *RequestHandlerProxy) Update_pm_config(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 407 | logger.Debug(ctx, "Update_pm_config") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 408 | if len(args) < 2 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 409 | logger.Warn(ctx, "Update_pm_config-invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 410 | err := errors.New("invalid-number-of-args") |
| 411 | return nil, err |
| 412 | } |
| 413 | device := &voltha.Device{} |
| 414 | transactionID := &ic.StrType{} |
| 415 | pmConfigs := &voltha.PmConfigs{} |
| 416 | for _, arg := range args { |
| 417 | switch arg.Key { |
| 418 | case "device": |
| 419 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 420 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 421 | return nil, err |
| 422 | } |
| 423 | case "pm_configs": |
| 424 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 425 | logger.Warnw(ctx, "cannot-unmarshal-pm-configs", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 426 | return nil, err |
| 427 | } |
| 428 | case kafka.TransactionKey: |
| 429 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 430 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 431 | return nil, err |
| 432 | } |
| 433 | } |
| 434 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 435 | logger.Debugw(ctx, "Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 436 | //Invoke the pm config update API of the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 437 | if err := rhp.adapter.Update_pm_config(ctx, device, pmConfigs); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 438 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 439 | } |
| 440 | return new(empty.Empty), nil |
| 441 | } |
| 442 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 443 | func (rhp *RequestHandlerProxy) Receive_packet_out(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
| 444 | logger.Debugw(ctx, "Receive_packet_out", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 445 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 446 | logger.Warn(ctx, "Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 447 | err := errors.New("invalid-number-of-args") |
| 448 | return nil, err |
| 449 | } |
| 450 | deviceId := &ic.StrType{} |
| 451 | egressPort := &ic.IntType{} |
| 452 | packet := &openflow_13.OfpPacketOut{} |
| 453 | transactionID := &ic.StrType{} |
| 454 | for _, arg := range args { |
| 455 | switch arg.Key { |
| 456 | case "deviceId": |
| 457 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 458 | logger.Warnw(ctx, "cannot-unmarshal-deviceId", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 459 | return nil, err |
| 460 | } |
| 461 | case "outPort": |
| 462 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 463 | logger.Warnw(ctx, "cannot-unmarshal-egressPort", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 464 | return nil, err |
| 465 | } |
| 466 | case "packet": |
| 467 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 468 | logger.Warnw(ctx, "cannot-unmarshal-packet", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 469 | return nil, err |
| 470 | } |
| 471 | case kafka.TransactionKey: |
| 472 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 473 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 474 | return nil, err |
| 475 | } |
| 476 | } |
| 477 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 478 | logger.Debugw(ctx, "Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 479 | //Invoke the adopt device on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 480 | if err := rhp.adapter.Receive_packet_out(ctx, deviceId.Val, int(egressPort.Val), packet); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 481 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 482 | } |
| 483 | return new(empty.Empty), nil |
| 484 | } |
| 485 | |
| 486 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 487 | return new(empty.Empty), nil |
| 488 | } |
| 489 | |
| 490 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 491 | return new(empty.Empty), nil |
| 492 | } |
| 493 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 494 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(ctx context.Context, args []*ic.Argument) (*ic.SwitchCapability, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 495 | if len(args) < 2 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 496 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 497 | err := errors.New("invalid-number-of-args") |
| 498 | return nil, err |
| 499 | } |
| 500 | device := &voltha.Device{} |
| 501 | transactionID := &ic.StrType{} |
| 502 | for _, arg := range args { |
| 503 | switch arg.Key { |
| 504 | case "device": |
| 505 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 506 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 507 | return nil, err |
| 508 | } |
| 509 | case kafka.TransactionKey: |
| 510 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 511 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 512 | return nil, err |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 517 | logger.Debugw(ctx, "Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 518 | |
| 519 | var cap *ic.SwitchCapability |
| 520 | var err error |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 521 | if cap, err = rhp.adapter.Get_ofp_device_info(ctx, device); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 522 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 523 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 524 | logger.Debugw(ctx, "Get_ofp_device_info", log.Fields{"cap": cap}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 525 | return cap, nil |
| 526 | } |
| 527 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 528 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(ctx context.Context, args []*ic.Argument) (*empty.Empty, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 529 | if len(args) < 2 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 530 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 531 | err := errors.New("invalid-number-of-args") |
| 532 | return nil, err |
| 533 | } |
| 534 | iaMsg := &ic.InterAdapterMessage{} |
| 535 | transactionID := &ic.StrType{} |
| 536 | for _, arg := range args { |
| 537 | switch arg.Key { |
| 538 | case "msg": |
| 539 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 540 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 541 | return nil, err |
| 542 | } |
| 543 | case kafka.TransactionKey: |
| 544 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 545 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 546 | return nil, err |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 551 | logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 552 | |
| 553 | //Invoke the inter adapter API on the handler |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 554 | if err := rhp.adapter.Process_inter_adapter_message(ctx, iaMsg); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 555 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 556 | } |
| 557 | |
| 558 | return new(empty.Empty), nil |
| 559 | } |
| 560 | |
| 561 | func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 562 | return &voltha.ImageDownload{}, nil |
| 563 | } |
| 564 | |
| 565 | func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 566 | return &voltha.ImageDownload{}, nil |
| 567 | } |
| 568 | |
| 569 | func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 570 | return &voltha.ImageDownload{}, nil |
| 571 | } |
| 572 | |
| 573 | func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 574 | return &voltha.ImageDownload{}, nil |
| 575 | } |
| 576 | |
| 577 | func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 578 | return &voltha.ImageDownload{}, nil |
| 579 | } |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 580 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 581 | func (rhp *RequestHandlerProxy) Enable_port(ctx context.Context, args []*ic.Argument) error { |
| 582 | logger.Debugw(ctx, "enable_port", log.Fields{"args": args}) |
| 583 | deviceId, port, err := rhp.getEnableDisableParams(ctx, args) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 584 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 585 | logger.Warnw(ctx, "enable_port", log.Fields{"args": args, "deviceId": deviceId, "port": port}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 586 | return err |
| 587 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 588 | return rhp.adapter.Enable_port(ctx, deviceId, port) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 589 | } |
| 590 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 591 | func (rhp *RequestHandlerProxy) Disable_port(ctx context.Context, args []*ic.Argument) error { |
| 592 | logger.Debugw(ctx, "disable_port", log.Fields{"args": args}) |
| 593 | deviceId, port, err := rhp.getEnableDisableParams(ctx, args) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 594 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 595 | logger.Warnw(ctx, "disable_port", log.Fields{"args": args, "deviceId": deviceId, "port": port}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 596 | return err |
| 597 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 598 | return rhp.adapter.Disable_port(ctx, deviceId, port) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 601 | func (rhp *RequestHandlerProxy) getEnableDisableParams(ctx context.Context, args []*ic.Argument) (string, *voltha.Port, error) { |
| 602 | logger.Debugw(ctx, "getEnableDisableParams", log.Fields{"args": args}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 603 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 604 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 605 | return "", nil, errors.New("invalid-number-of-args") |
| 606 | } |
| 607 | deviceId := &ic.StrType{} |
| 608 | port := &voltha.Port{} |
| 609 | for _, arg := range args { |
| 610 | switch arg.Key { |
| 611 | case "deviceId": |
| 612 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 613 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 614 | return "", nil, err |
| 615 | } |
| 616 | case "port": |
| 617 | if err := ptypes.UnmarshalAny(arg.Value, port); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 618 | logger.Warnw(ctx, "cannot-unmarshal-port", log.Fields{"error": err}) |
kesavand | f17f792 | 2020-02-03 17:00:27 -0500 | [diff] [blame] | 619 | return "", nil, err |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | return deviceId.Val, port, nil |
| 624 | } |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 625 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 626 | func (rhp *RequestHandlerProxy) Child_device_lost(ctx context.Context, args []*ic.Argument) error { |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 627 | if len(args) < 4 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 628 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 629 | return errors.New("invalid-number-of-args") |
| 630 | } |
| 631 | |
| 632 | pDeviceId := &ic.StrType{} |
| 633 | pPortNo := &ic.IntType{} |
| 634 | onuID := &ic.IntType{} |
| 635 | fromTopic := &ic.StrType{} |
| 636 | for _, arg := range args { |
| 637 | switch arg.Key { |
| 638 | case "pDeviceId": |
| 639 | if err := ptypes.UnmarshalAny(arg.Value, pDeviceId); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 640 | logger.Warnw(ctx, "cannot-unmarshal-parent-deviceId", log.Fields{"error": err}) |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 641 | return err |
| 642 | } |
| 643 | case "pPortNo": |
| 644 | if err := ptypes.UnmarshalAny(arg.Value, pPortNo); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 645 | logger.Warnw(ctx, "cannot-unmarshal-port", log.Fields{"error": err}) |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 646 | return err |
| 647 | } |
| 648 | case "onuID": |
| 649 | if err := ptypes.UnmarshalAny(arg.Value, onuID); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 650 | logger.Warnw(ctx, "cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 651 | return err |
| 652 | } |
| 653 | case kafka.FromTopic: |
| 654 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 655 | logger.Warnw(ctx, "cannot-unmarshal-from-topic", log.Fields{"error": err}) |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 656 | return err |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | //Update the core reference for that device |
| 661 | rhp.coreProxy.UpdateCoreReference(pDeviceId.Val, fromTopic.Val) |
| 662 | //Invoke the Child_device_lost API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 663 | if err := rhp.adapter.Child_device_lost(ctx, pDeviceId.Val, uint32(pPortNo.Val), uint32(onuID.Val)); err != nil { |
Chaitrashree G S | c4a5c07 | 2020-02-04 17:08:40 -0500 | [diff] [blame] | 664 | return status.Errorf(codes.NotFound, "%s", err.Error()) |
| 665 | } |
| 666 | return nil |
| 667 | } |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 668 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 669 | func (rhp *RequestHandlerProxy) Start_omci_test(ctx context.Context, args []*ic.Argument) (*ic.TestResponse, error) { |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 670 | if len(args) < 2 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 671 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 672 | err := errors.New("invalid-number-of-args") |
| 673 | return nil, err |
| 674 | } |
| 675 | |
| 676 | // TODO: See related comment in voltha-go:adapter_proxy_go:startOmciTest() |
| 677 | // Second argument should perhaps be uuid instead of omcitestrequest |
| 678 | |
| 679 | device := &voltha.Device{} |
| 680 | request := &voltha.OmciTestRequest{} |
| 681 | for _, arg := range args { |
| 682 | switch arg.Key { |
| 683 | case "device": |
| 684 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 685 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 686 | return nil, err |
| 687 | } |
| 688 | case "omcitestrequest": |
| 689 | if err := ptypes.UnmarshalAny(arg.Value, request); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 690 | logger.Warnw(ctx, "cannot-unmarshal-omcitestrequest", log.Fields{"error": err}) |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 691 | return nil, err |
| 692 | } |
| 693 | } |
| 694 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 695 | logger.Debugw(ctx, "Start_omci_test", log.Fields{"device-id": device.Id, "req": request}) |
| 696 | result, err := rhp.adapter.Start_omci_test(ctx, device, request) |
Scott Baker | 04cb5da | 2020-03-26 15:52:22 -0700 | [diff] [blame] | 697 | if err != nil { |
| 698 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 699 | } |
| 700 | return result, nil |
| 701 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 702 | func (rhp *RequestHandlerProxy) Get_ext_value(ctx context.Context, args []*ic.Argument) (*voltha.ReturnValues, error) { |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 703 | if len(args) < 3 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 704 | logger.Warn(ctx, "invalid-number-of-args", log.Fields{"args": args}) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 705 | return nil, errors.New("invalid-number-of-args") |
| 706 | } |
| 707 | |
| 708 | pDeviceId := &ic.StrType{} |
| 709 | device := &voltha.Device{} |
| 710 | valuetype := &ic.IntType{} |
| 711 | for _, arg := range args { |
| 712 | switch arg.Key { |
| 713 | case "device": |
| 714 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 715 | logger.Warnw(ctx, "cannot-unmarshal-device", log.Fields{"error": err}) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 716 | return nil, err |
| 717 | } |
| 718 | case "pDeviceId": |
| 719 | if err := ptypes.UnmarshalAny(arg.Value, pDeviceId); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 720 | logger.Warnw(ctx, "cannot-unmarshal-parent-deviceId", log.Fields{"error": err}) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 721 | return nil, err |
| 722 | } |
| 723 | case "valuetype": |
| 724 | if err := ptypes.UnmarshalAny(arg.Value, valuetype); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 725 | logger.Warnw(ctx, "cannot-unmarshal-valuetype", log.Fields{"error": err}) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 726 | return nil, err |
| 727 | } |
| 728 | default: |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 729 | logger.Warnw(ctx, "key-not-found", log.Fields{"arg.Key": arg.Key}) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | //Invoke the Get_value API on the adapter |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 734 | return rhp.adapter.Get_ext_value(ctx, pDeviceId.Val, device, voltha.ValueType_Type(valuetype.Val)) |
Dinesh Belwalkar | 4c89a1d | 2020-02-28 16:05:32 -0800 | [diff] [blame] | 735 | } |