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