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