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) |
| 259 | //Invoke the Disable_device API on the adapter |
| 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}) |
| 306 | //Invoke the adopt device on the adapter |
| 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}) |
| 349 | //Invoke the adopt device on the adapter |
| 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) { |
| 357 | return new(empty.Empty), nil |
| 358 | } |
| 359 | |
| 360 | func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) { |
manikkaraj k | 6c9689d | 2019-05-09 12:59:52 -0400 | [diff] [blame] | 361 | log.Debugw("Receive_packet_out", log.Fields{"args": args}) |
| 362 | if len(args) < 3 { |
| 363 | log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args}) |
| 364 | err := errors.New("invalid-number-of-args") |
| 365 | return nil, err |
| 366 | } |
| 367 | deviceId := &ic.StrType{} |
| 368 | egressPort := &ic.IntType{} |
| 369 | packet := &openflow_13.OfpPacketOut{} |
| 370 | transactionID := &ic.StrType{} |
| 371 | for _, arg := range args { |
| 372 | switch arg.Key { |
| 373 | case "deviceId": |
| 374 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 375 | log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err}) |
| 376 | return nil, err |
| 377 | } |
| 378 | case "outPort": |
| 379 | if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil { |
| 380 | log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err}) |
| 381 | return nil, err |
| 382 | } |
| 383 | case "packet": |
| 384 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
| 385 | log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
| 386 | return nil, err |
| 387 | } |
| 388 | case kafka.TransactionKey: |
| 389 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 390 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 391 | return nil, err |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet}) |
| 396 | //Invoke the adopt device on the adapter |
| 397 | if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil { |
| 398 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 399 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 400 | return new(empty.Empty), nil |
| 401 | } |
| 402 | |
| 403 | func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 404 | return new(empty.Empty), nil |
| 405 | } |
| 406 | |
| 407 | func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) { |
| 408 | return new(empty.Empty), nil |
| 409 | } |
| 410 | |
| 411 | func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 412 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 413 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 414 | err := errors.New("invalid-number-of-args") |
| 415 | return nil, err |
| 416 | } |
| 417 | device := &voltha.Device{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 418 | transactionID := &ic.StrType{} |
| 419 | for _, arg := range args { |
| 420 | switch arg.Key { |
| 421 | case "device": |
| 422 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 423 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 424 | return nil, err |
| 425 | } |
| 426 | case kafka.TransactionKey: |
| 427 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 428 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 429 | return nil, err |
| 430 | } |
| 431 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 432 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 433 | |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 434 | log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
| 435 | |
| 436 | var cap *ic.SwitchCapability |
| 437 | var err error |
| 438 | if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil { |
| 439 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 440 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 441 | log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap}) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 442 | return cap, nil |
| 443 | } |
| 444 | |
| 445 | func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 446 | if len(args) < 3 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 447 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 448 | err := errors.New("invalid-number-of-args") |
| 449 | return nil, err |
| 450 | } |
| 451 | device := &voltha.Device{} |
| 452 | pNo := &ic.IntType{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 453 | transactionID := &ic.StrType{} |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 454 | for _, arg := range args { |
| 455 | switch arg.Key { |
| 456 | case "device": |
| 457 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 458 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 459 | return nil, err |
| 460 | } |
| 461 | case "port_no": |
| 462 | if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil { |
| 463 | log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
| 464 | return nil, err |
| 465 | } |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 466 | case kafka.TransactionKey: |
| 467 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 468 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 469 | return nil, err |
| 470 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val}) |
| 474 | var cap *ic.PortCapability |
| 475 | var err error |
| 476 | if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil { |
| 477 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 478 | } |
| 479 | return cap, nil |
| 480 | } |
| 481 | |
| 482 | func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 483 | if len(args) < 2 { |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 484 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 485 | err := errors.New("invalid-number-of-args") |
| 486 | return nil, err |
| 487 | } |
| 488 | iaMsg := &ic.InterAdapterMessage{} |
khenaidoo | 6d05513 | 2019-02-12 16:51:19 -0500 | [diff] [blame] | 489 | transactionID := &ic.StrType{} |
| 490 | for _, arg := range args { |
| 491 | switch arg.Key { |
| 492 | case "msg": |
| 493 | if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil { |
| 494 | log.Warnw("cannot-unmarshal-device", log.Fields{"error": err}) |
| 495 | return nil, err |
| 496 | } |
| 497 | case kafka.TransactionKey: |
| 498 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 499 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 500 | return nil, err |
| 501 | } |
| 502 | } |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id}) |
| 506 | |
| 507 | //Invoke the inter adapter API on the handler |
| 508 | if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil { |
| 509 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 510 | } |
| 511 | |
| 512 | return new(empty.Empty), nil |
| 513 | } |
| 514 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 515 | func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 516 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 517 | } |
| 518 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 519 | func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 520 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 521 | } |
| 522 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 523 | func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 524 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 525 | } |
| 526 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 527 | func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 528 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 529 | } |
| 530 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 531 | func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) { |
| 532 | return &voltha.ImageDownload{}, nil |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 533 | } |