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) { |
| 102 | return new(empty.Empty), nil |
| 103 | } |
| 104 | |
| 105 | func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) { |
| 106 | return new(empty.Empty), nil |
| 107 | } |
| 108 | |
| 109 | func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 110 | if len(args) < 3 { |
| 111 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 112 | err := errors.New("invalid-number-of-args") |
| 113 | return nil, err |
| 114 | } |
| 115 | |
| 116 | device := &voltha.Device{} |
| 117 | transactionID := &ic.StrType{} |
| 118 | fromTopic := &ic.StrType{} |
| 119 | for _, arg := range args { |
| 120 | switch arg.Key { |
| 121 | case "device": |
| 122 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 123 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 124 | return nil, err |
| 125 | } |
| 126 | case kafka.TransactionKey: |
| 127 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 128 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 129 | return nil, err |
| 130 | } |
| 131 | case kafka.FromTopic: |
| 132 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 133 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 134 | return nil, err |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | //Update the core reference for that device |
| 139 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 140 | //Invoke the Disable_device API on the adapter |
| 141 | if err := rhp.adapter.Disable_device(device); err != nil { |
| 142 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 143 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 144 | return new(empty.Empty), nil |
| 145 | } |
| 146 | |
| 147 | func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 148 | if len(args) < 3 { |
| 149 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 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 { |
| 161 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 162 | return nil, err |
| 163 | } |
| 164 | case kafka.TransactionKey: |
| 165 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 166 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 167 | return nil, err |
| 168 | } |
| 169 | case kafka.FromTopic: |
| 170 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 171 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 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 Reenable_device API on the adapter |
| 179 | if err := rhp.adapter.Reenable_device(device); err != nil { |
| 180 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 181 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 182 | return new(empty.Empty), nil |
| 183 | } |
| 184 | |
| 185 | func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) { |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 186 | if len(args) < 3 { |
| 187 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 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 { |
| 199 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 200 | return nil, err |
| 201 | } |
| 202 | case kafka.TransactionKey: |
| 203 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 204 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 205 | return nil, err |
| 206 | } |
| 207 | case kafka.FromTopic: |
| 208 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 209 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 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 Reboot_device API on the adapter |
| 217 | if err := rhp.adapter.Reboot_device(device); err != nil { |
| 218 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 219 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 220 | return new(empty.Empty), nil |
Girish Gowdru | 894d97d | 2019-05-28 05:07:18 -0400 | [diff] [blame] | 221 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) { |
| 225 | return new(empty.Empty), nil |
| 226 | } |
| 227 | |
| 228 | func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 229 | if len(args) < 3 { |
| 230 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 231 | err := errors.New("invalid-number-of-args") |
| 232 | return nil, err |
| 233 | } |
| 234 | |
| 235 | device := &voltha.Device{} |
| 236 | transactionID := &ic.StrType{} |
| 237 | fromTopic := &ic.StrType{} |
| 238 | for _, arg := range args { |
| 239 | switch arg.Key { |
| 240 | case "device": |
| 241 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 242 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 243 | return nil, err |
| 244 | } |
| 245 | case kafka.TransactionKey: |
| 246 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 247 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 248 | return nil, err |
| 249 | } |
| 250 | case kafka.FromTopic: |
| 251 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 252 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 253 | return nil, err |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | //Update the core reference for that device |
| 258 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 259 | //Invoke the delete_device API on the adapter |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 260 | if err := rhp.adapter.Delete_device(device); err != nil { |
| 261 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 262 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 263 | return new(empty.Empty), nil |
| 264 | } |
| 265 | |
| 266 | func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) { |
| 267 | return new(empty.Empty), nil |
| 268 | } |
| 269 | |
| 270 | func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 271 | log.Debug("Update_flows_bulk") |
| 272 | if len(args) < 4 { |
| 273 | log.Warn("Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args}) |
| 274 | err := errors.New("invalid-number-of-args") |
| 275 | return nil, err |
| 276 | } |
| 277 | device := &voltha.Device{} |
| 278 | transactionID := &ic.StrType{} |
| 279 | flows := &voltha.Flows{} |
| 280 | groups := &voltha.FlowGroups{} |
| 281 | for _, arg := range args { |
| 282 | switch arg.Key { |
| 283 | case "device": |
| 284 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 285 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 286 | return nil, err |
| 287 | } |
| 288 | case "flows": |
| 289 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
| 290 | log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err}) |
| 291 | return nil, err |
| 292 | } |
| 293 | case "groups": |
| 294 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
| 295 | log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err}) |
| 296 | return nil, err |
| 297 | } |
| 298 | case kafka.TransactionKey: |
| 299 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 300 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 301 | return nil, err |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | log.Debugw("Update_flows_bulk", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 306 | //Invoke the bulk flow update API of the adapter |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 307 | if err := rhp.adapter.Update_flows_bulk(device, flows, groups); err != nil { |
| 308 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 309 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 310 | return new(empty.Empty), nil |
| 311 | } |
| 312 | |
| 313 | func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 314 | log.Debug("Update_flows_incrementally") |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 315 | if len(args) < 3 { |
| 316 | log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args}) |
| 317 | err := errors.New("invalid-number-of-args") |
| 318 | return nil, err |
| 319 | } |
| 320 | device := &voltha.Device{} |
| 321 | transactionID := &ic.StrType{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 322 | flows := &openflow_13.FlowChanges{} |
| 323 | groups := &openflow_13.FlowGroupChanges{} |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 324 | for _, arg := range args { |
| 325 | switch arg.Key { |
| 326 | case "device": |
| 327 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 328 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 329 | return nil, err |
| 330 | } |
| 331 | case "flow_changes": |
| 332 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
| 333 | log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err}) |
| 334 | return nil, err |
| 335 | } |
| 336 | case "group_changes": |
| 337 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
| 338 | log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err}) |
| 339 | return nil, err |
| 340 | } |
| 341 | case kafka.TransactionKey: |
| 342 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 343 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 344 | return nil, err |
| 345 | } |
| 346 | } |
| 347 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 348 | log.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups}) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 349 | //Invoke the incremental flow update API of the adapter |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 350 | if err := rhp.adapter.Update_flows_incrementally(device, flows, groups); err != nil { |
| 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_pm_config(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 357 | log.Debug("Update_pm_config") |
| 358 | if len(args) < 2 { |
| 359 | log.Warn("Update_pm_config-invalid-number-of-args", log.Fields{"args": args}) |
| 360 | err := errors.New("invalid-number-of-args") |
| 361 | return nil, err |
| 362 | } |
| 363 | device := &voltha.Device{} |
| 364 | transactionID := &ic.StrType{} |
| 365 | pmConfigs := &voltha.PmConfigs{} |
| 366 | for _, arg := range args { |
| 367 | switch arg.Key { |
| 368 | case "device": |
| 369 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 370 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 371 | return nil, err |
| 372 | } |
| 373 | case "pm_configs": |
| 374 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
| 375 | log.Warnw("cannot-unmarshal-pm-configs", log.Fields{"error": err}) |
| 376 | return nil, err |
| 377 | } |
| 378 | case kafka.TransactionKey: |
| 379 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 380 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 381 | return nil, err |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | log.Debugw("Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs}) |
| 386 | //Invoke the pm config update API of the adapter |
| 387 | if err := rhp.adapter.Update_pm_config(device, pmConfigs); err != nil { |
| 388 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 389 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 390 | return new(empty.Empty), nil |
| 391 | } |
| 392 | |
| 393 | func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) { |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 394 | log.Debugw("Receive_packet_out", log.Fields{"args": args}) |
| 395 | if len(args) < 3 { |
| 396 | log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
| 397 | err := errors.New("invalid-number-of-args") |
| 398 | return nil, err |
| 399 | } |
| 400 | deviceId := &ic.StrType{} |
| 401 | egressPort := &ic.IntType{} |
| 402 | packet := &openflow_13.OfpPacketOut{} |
| 403 | transactionID := &ic.StrType{} |
| 404 | for _, arg := range args { |
| 405 | switch arg.Key { |
| 406 | case "deviceId": |
| 407 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 408 | log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err}) |
| 409 | return nil, err |
| 410 | } |
| 411 | case "outPort": |
| 412 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
| 413 | log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err}) |
| 414 | return nil, err |
| 415 | } |
| 416 | case "packet": |
| 417 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
| 418 | log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
| 419 | return nil, err |
| 420 | } |
| 421 | case kafka.TransactionKey: |
| 422 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 423 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 424 | return nil, err |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet}) |
| 429 | //Invoke the adopt device on the adapter |
| 430 | if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil { |
| 431 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 432 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 433 | return new(empty.Empty), nil |
| 434 | } |
| 435 | |
| 436 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 437 | return new(empty.Empty), nil |
| 438 | } |
| 439 | |
| 440 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 441 | return new(empty.Empty), nil |
| 442 | } |
| 443 | |
| 444 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 445 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 446 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 447 | err := errors.New("invalid-number-of-args") |
| 448 | return nil, err |
| 449 | } |
| 450 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 451 | transactionID := &ic.StrType{} |
| 452 | for _, arg := range args { |
| 453 | switch arg.Key { |
| 454 | case "device": |
| 455 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 456 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 457 | return nil, err |
| 458 | } |
| 459 | case kafka.TransactionKey: |
| 460 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 461 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 462 | return nil, err |
| 463 | } |
| 464 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 465 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 466 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 467 | log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
| 468 | |
| 469 | var cap *ic.SwitchCapability |
| 470 | var err error |
| 471 | if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil { |
| 472 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 473 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 474 | log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 475 | return cap, nil |
| 476 | } |
| 477 | |
| 478 | func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 479 | if len(args) < 3 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 480 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 481 | err := errors.New("invalid-number-of-args") |
| 482 | return nil, err |
| 483 | } |
| 484 | device := &voltha.Device{} |
| 485 | pNo := &ic.IntType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 486 | transactionID := &ic.StrType{} |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 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 "port_no": |
| 495 | if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil { |
| 496 | log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
| 497 | return nil, err |
| 498 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 499 | case kafka.TransactionKey: |
| 500 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 501 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 502 | return nil, err |
| 503 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val}) |
| 507 | var cap *ic.PortCapability |
| 508 | var err error |
| 509 | if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil { |
| 510 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 511 | } |
| 512 | return cap, nil |
| 513 | } |
| 514 | |
| 515 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 516 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 517 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 518 | err := errors.New("invalid-number-of-args") |
| 519 | return nil, err |
| 520 | } |
| 521 | iaMsg := &ic.InterAdapterMessage{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 522 | transactionID := &ic.StrType{} |
| 523 | for _, arg := range args { |
| 524 | switch arg.Key { |
| 525 | case "msg": |
| 526 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
| 527 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 528 | return nil, err |
| 529 | } |
| 530 | case kafka.TransactionKey: |
| 531 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 532 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 533 | return nil, err |
| 534 | } |
| 535 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
| 539 | |
| 540 | //Invoke the inter adapter API on the handler |
| 541 | if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil { |
| 542 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 543 | } |
| 544 | |
| 545 | return new(empty.Empty), nil |
| 546 | } |
| 547 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 548 | func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 549 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 550 | } |
| 551 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 552 | func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 553 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 554 | } |
| 555 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 556 | func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 557 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 558 | } |
| 559 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 560 | func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 561 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 562 | } |
| 563 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 564 | func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 565 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 566 | } |