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) { |
| 186 | return new(empty.Empty), nil |
| 187 | } |
| 188 | |
| 189 | func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) { |
| 190 | return new(empty.Empty), nil |
| 191 | } |
| 192 | |
| 193 | func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 194 | if len(args) < 3 { |
| 195 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 196 | err := errors.New("invalid-number-of-args") |
| 197 | return nil, err |
| 198 | } |
| 199 | |
| 200 | device := &voltha.Device{} |
| 201 | transactionID := &ic.StrType{} |
| 202 | fromTopic := &ic.StrType{} |
| 203 | for _, arg := range args { |
| 204 | switch arg.Key { |
| 205 | case "device": |
| 206 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 207 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 208 | return nil, err |
| 209 | } |
| 210 | case kafka.TransactionKey: |
| 211 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 212 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 213 | return nil, err |
| 214 | } |
| 215 | case kafka.FromTopic: |
| 216 | if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil { |
| 217 | log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err}) |
| 218 | return nil, err |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | //Update the core reference for that device |
| 223 | rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val) |
| 224 | //Invoke the Disable_device API on the adapter |
| 225 | if err := rhp.adapter.Delete_device(device); err != nil { |
| 226 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 227 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 228 | return new(empty.Empty), nil |
| 229 | } |
| 230 | |
| 231 | func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) { |
| 232 | return new(empty.Empty), nil |
| 233 | } |
| 234 | |
| 235 | func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) { |
| 236 | return new(empty.Empty), nil |
| 237 | } |
| 238 | |
| 239 | func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 240 | log.Debug("Update_flows_incrementally") |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 241 | if len(args) < 3 { |
| 242 | log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args}) |
| 243 | err := errors.New("invalid-number-of-args") |
| 244 | return nil, err |
| 245 | } |
| 246 | device := &voltha.Device{} |
| 247 | transactionID := &ic.StrType{} |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 248 | flows := &openflow_13.FlowChanges{} |
| 249 | groups := &openflow_13.FlowGroupChanges{} |
mkoodali | 252f767 | 2019-03-25 12:13:12 +0530 | [diff] [blame] | 250 | for _, arg := range args { |
| 251 | switch arg.Key { |
| 252 | case "device": |
| 253 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 254 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 255 | return nil, err |
| 256 | } |
| 257 | case "flow_changes": |
| 258 | if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil { |
| 259 | log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err}) |
| 260 | return nil, err |
| 261 | } |
| 262 | case "group_changes": |
| 263 | if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil { |
| 264 | log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err}) |
| 265 | return nil, err |
| 266 | } |
| 267 | case kafka.TransactionKey: |
| 268 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 269 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 270 | return nil, err |
| 271 | } |
| 272 | } |
| 273 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 274 | log.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups}) |
| 275 | //Invoke the adopt device on the adapter |
| 276 | if err := rhp.adapter.Update_flows_incrementally(device, flows, groups); err != nil { |
| 277 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 278 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 279 | return new(empty.Empty), nil |
| 280 | } |
| 281 | |
| 282 | func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) { |
| 283 | return new(empty.Empty), nil |
| 284 | } |
| 285 | |
| 286 | func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) { |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 287 | log.Debugw("Receive_packet_out", log.Fields{"args": args}) |
| 288 | if len(args) < 3 { |
| 289 | log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
| 290 | err := errors.New("invalid-number-of-args") |
| 291 | return nil, err |
| 292 | } |
| 293 | deviceId := &ic.StrType{} |
| 294 | egressPort := &ic.IntType{} |
| 295 | packet := &openflow_13.OfpPacketOut{} |
| 296 | transactionID := &ic.StrType{} |
| 297 | for _, arg := range args { |
| 298 | switch arg.Key { |
| 299 | case "deviceId": |
| 300 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 301 | log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err}) |
| 302 | return nil, err |
| 303 | } |
| 304 | case "outPort": |
| 305 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
| 306 | log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err}) |
| 307 | return nil, err |
| 308 | } |
| 309 | case "packet": |
| 310 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
| 311 | log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
| 312 | return nil, err |
| 313 | } |
| 314 | case kafka.TransactionKey: |
| 315 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 316 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 317 | return nil, err |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet}) |
| 322 | //Invoke the adopt device on the adapter |
| 323 | if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil { |
| 324 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 325 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 326 | return new(empty.Empty), nil |
| 327 | } |
| 328 | |
| 329 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 330 | return new(empty.Empty), nil |
| 331 | } |
| 332 | |
| 333 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 334 | return new(empty.Empty), nil |
| 335 | } |
| 336 | |
| 337 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 338 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 339 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 340 | err := errors.New("invalid-number-of-args") |
| 341 | return nil, err |
| 342 | } |
| 343 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 344 | transactionID := &ic.StrType{} |
| 345 | for _, arg := range args { |
| 346 | switch arg.Key { |
| 347 | case "device": |
| 348 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 349 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 350 | return nil, err |
| 351 | } |
| 352 | case kafka.TransactionKey: |
| 353 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 354 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 355 | return nil, err |
| 356 | } |
| 357 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 358 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 359 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 360 | log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
| 361 | |
| 362 | var cap *ic.SwitchCapability |
| 363 | var err error |
| 364 | if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil { |
| 365 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 366 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 367 | log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 368 | return cap, nil |
| 369 | } |
| 370 | |
| 371 | func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 372 | if len(args) < 3 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 373 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 374 | err := errors.New("invalid-number-of-args") |
| 375 | return nil, err |
| 376 | } |
| 377 | device := &voltha.Device{} |
| 378 | pNo := &ic.IntType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 379 | transactionID := &ic.StrType{} |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 380 | for _, arg := range args { |
| 381 | switch arg.Key { |
| 382 | case "device": |
| 383 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 384 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 385 | return nil, err |
| 386 | } |
| 387 | case "port_no": |
| 388 | if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil { |
| 389 | log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
| 390 | return nil, err |
| 391 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 392 | case kafka.TransactionKey: |
| 393 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 394 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 395 | return nil, err |
| 396 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val}) |
| 400 | var cap *ic.PortCapability |
| 401 | var err error |
| 402 | if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil { |
| 403 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 404 | } |
| 405 | return cap, nil |
| 406 | } |
| 407 | |
| 408 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 409 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 410 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 411 | err := errors.New("invalid-number-of-args") |
| 412 | return nil, err |
| 413 | } |
| 414 | iaMsg := &ic.InterAdapterMessage{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 415 | transactionID := &ic.StrType{} |
| 416 | for _, arg := range args { |
| 417 | switch arg.Key { |
| 418 | case "msg": |
| 419 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
| 420 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 421 | return nil, err |
| 422 | } |
| 423 | case kafka.TransactionKey: |
| 424 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 425 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 426 | return nil, err |
| 427 | } |
| 428 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
| 432 | |
| 433 | //Invoke the inter adapter API on the handler |
| 434 | if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil { |
| 435 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 436 | } |
| 437 | |
| 438 | return new(empty.Empty), nil |
| 439 | } |
| 440 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 441 | func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 442 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 443 | } |
| 444 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 445 | func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 446 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 447 | } |
| 448 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 449 | func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 450 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 451 | } |
| 452 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 453 | func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 454 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 455 | } |
| 456 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 457 | func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 458 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 459 | } |