blob: 62d8cddf5af01feae81c52ff9fdd4abb4a62c446 [file] [log] [blame]
Scott Baker2c1c4822019-10-16 11:02:41 -07001/*
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 */
16package common
17
18import (
19 "errors"
serkant.uluderyab38671c2019-11-01 09:35:38 -070020
Scott Baker2c1c4822019-10-16 11:02:41 -070021 "github.com/golang/protobuf/ptypes"
22 "github.com/golang/protobuf/ptypes/empty"
serkant.uluderyab38671c2019-11-01 09:35:38 -070023 "github.com/opencord/voltha-lib-go/v3/pkg/adapters"
24 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
25 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
26 "github.com/opencord/voltha-lib-go/v3/pkg/log"
27 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
28 "github.com/opencord/voltha-protos/v3/go/openflow_13"
29 "github.com/opencord/voltha-protos/v3/go/voltha"
Scott Baker2c1c4822019-10-16 11:02:41 -070030 "google.golang.org/grpc/codes"
31 "google.golang.org/grpc/status"
32)
33
34type RequestHandlerProxy struct {
35 TestMode bool
36 coreInstanceId string
37 adapter adapters.IAdapter
38 coreProxy adapterif.CoreProxy
39}
40
41func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy adapterif.CoreProxy) *RequestHandlerProxy {
42 var proxy RequestHandlerProxy
43 proxy.coreInstanceId = coreInstanceId
44 proxy.adapter = iadapter
45 proxy.coreProxy = cProxy
46 return &proxy
47}
48
49func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) {
50 return new(empty.Empty), nil
51}
52
53func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) {
54 return nil, nil
55}
56
57func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) {
58 return nil, nil
59}
60
Scott Bakere6685952020-06-23 04:05:39 +000061func (rhp *RequestHandlerProxy) Adopt_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -070062 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +000063 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -070064 err := errors.New("invalid-number-of-args")
65 return nil, err
66 }
67 device := &voltha.Device{}
68 transactionID := &ic.StrType{}
69 fromTopic := &ic.StrType{}
70 for _, arg := range args {
71 switch arg.Key {
72 case "device":
73 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +000074 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -070075 return nil, err
76 }
77 case kafka.TransactionKey:
78 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +000079 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -070080 return nil, err
81 }
82 case kafka.FromTopic:
83 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +000084 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -070085 return nil, err
86 }
87 }
88 }
89
Scott Bakere6685952020-06-23 04:05:39 +000090 logger.Debugw("Adopt_device", log.Fields{"deviceId": device.Id})
Scott Baker2c1c4822019-10-16 11:02:41 -070091
92 //Update the core reference for that device
93 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
94
95 //Invoke the adopt device on the adapter
Scott Bakere6685952020-06-23 04:05:39 +000096 if err := rhp.adapter.Adopt_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -070097 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
98 }
99
100 return new(empty.Empty), nil
101}
102
Scott Bakere6685952020-06-23 04:05:39 +0000103func (rhp *RequestHandlerProxy) Reconcile_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700104 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000105 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700106 err := errors.New("invalid-number-of-args")
107 return nil, err
108 }
109
110 device := &voltha.Device{}
111 transactionID := &ic.StrType{}
112 fromTopic := &ic.StrType{}
113 for _, arg := range args {
114 switch arg.Key {
115 case "device":
116 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000117 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700118 return nil, err
119 }
120 case kafka.TransactionKey:
121 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000122 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700123 return nil, err
124 }
125 case kafka.FromTopic:
126 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000127 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700128 return nil, err
129 }
130 }
131 }
132 //Update the core reference for that device
133 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
134
135 //Invoke the reconcile device API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000136 if err := rhp.adapter.Reconcile_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700137 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
138 }
139 return new(empty.Empty), nil
140}
141
142func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) {
143 return new(empty.Empty), nil
144}
145
Scott Bakere6685952020-06-23 04:05:39 +0000146func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700147 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000148 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700149 err := errors.New("invalid-number-of-args")
150 return nil, err
151 }
152
153 device := &voltha.Device{}
154 transactionID := &ic.StrType{}
155 fromTopic := &ic.StrType{}
156 for _, arg := range args {
157 switch arg.Key {
158 case "device":
159 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000160 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700161 return nil, err
162 }
163 case kafka.TransactionKey:
164 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000165 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700166 return nil, err
167 }
168 case kafka.FromTopic:
169 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000170 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700171 return nil, err
172 }
173 }
174 }
175 //Update the core reference for that device
176 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
177 //Invoke the Disable_device API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000178 if err := rhp.adapter.Disable_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700179 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
180 }
181 return new(empty.Empty), nil
182}
183
Scott Bakere6685952020-06-23 04:05:39 +0000184func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700185 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000186 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700187 err := errors.New("invalid-number-of-args")
188 return nil, err
189 }
190
191 device := &voltha.Device{}
192 transactionID := &ic.StrType{}
193 fromTopic := &ic.StrType{}
194 for _, arg := range args {
195 switch arg.Key {
196 case "device":
197 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000198 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700199 return nil, err
200 }
201 case kafka.TransactionKey:
202 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000203 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700204 return nil, err
205 }
206 case kafka.FromTopic:
207 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000208 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700209 return nil, err
210 }
211 }
212 }
213 //Update the core reference for that device
214 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
215 //Invoke the Reenable_device API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000216 if err := rhp.adapter.Reenable_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700217 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
218 }
219 return new(empty.Empty), nil
220}
221
Scott Bakere6685952020-06-23 04:05:39 +0000222func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700223 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000224 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700225 err := errors.New("invalid-number-of-args")
226 return nil, err
227 }
228
229 device := &voltha.Device{}
230 transactionID := &ic.StrType{}
231 fromTopic := &ic.StrType{}
232 for _, arg := range args {
233 switch arg.Key {
234 case "device":
235 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000236 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700237 return nil, err
238 }
239 case kafka.TransactionKey:
240 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000241 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700242 return nil, err
243 }
244 case kafka.FromTopic:
245 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000246 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700247 return nil, err
248 }
249 }
250 }
251 //Update the core reference for that device
252 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
253 //Invoke the Reboot_device API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000254 if err := rhp.adapter.Reboot_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700255 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
256 }
257 return new(empty.Empty), nil
258
259}
260
261func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) {
262 return new(empty.Empty), nil
263}
264
Scott Bakere6685952020-06-23 04:05:39 +0000265func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700266 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000267 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700268 err := errors.New("invalid-number-of-args")
269 return nil, err
270 }
271
272 device := &voltha.Device{}
273 transactionID := &ic.StrType{}
274 fromTopic := &ic.StrType{}
275 for _, arg := range args {
276 switch arg.Key {
277 case "device":
278 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000279 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700280 return nil, err
281 }
282 case kafka.TransactionKey:
283 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000284 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700285 return nil, err
286 }
287 case kafka.FromTopic:
288 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000289 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700290 return nil, err
291 }
292 }
293 }
294 //Update the core reference for that device
295 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
296 //Invoke the delete_device API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000297 if err := rhp.adapter.Delete_device(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700298 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
299 }
300 return new(empty.Empty), nil
301}
302
303func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) {
304 return new(empty.Empty), nil
305}
306
Scott Bakere6685952020-06-23 04:05:39 +0000307func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) {
308 logger.Debug("Update_flows_bulk")
Scott Baker2c1c4822019-10-16 11:02:41 -0700309 if len(args) < 5 {
Scott Bakere6685952020-06-23 04:05:39 +0000310 logger.Warn("Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700311 err := errors.New("invalid-number-of-args")
312 return nil, err
313 }
314 device := &voltha.Device{}
315 transactionID := &ic.StrType{}
316 flows := &voltha.Flows{}
317 flowMetadata := &voltha.FlowMetadata{}
318 groups := &voltha.FlowGroups{}
319 for _, arg := range args {
320 switch arg.Key {
321 case "device":
322 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000323 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700324 return nil, err
325 }
326 case "flows":
327 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000328 logger.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700329 return nil, err
330 }
331 case "groups":
332 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000333 logger.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700334 return nil, err
335 }
336 case "flow_metadata":
337 if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000338 logger.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700339 return nil, err
340 }
341 case kafka.TransactionKey:
342 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000343 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700344 return nil, err
345 }
346 }
347 }
Scott Bakere6685952020-06-23 04:05:39 +0000348 logger.Debugw("Update_flows_bulk", log.Fields{"flows": flows, "groups": groups})
Scott Baker2c1c4822019-10-16 11:02:41 -0700349 //Invoke the bulk flow update API of the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000350 if err := rhp.adapter.Update_flows_bulk(device, flows, groups, flowMetadata); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700351 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
352 }
353 return new(empty.Empty), nil
354}
355
Scott Bakere6685952020-06-23 04:05:39 +0000356func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
357 logger.Debug("Update_flows_incrementally")
Scott Baker2c1c4822019-10-16 11:02:41 -0700358 if len(args) < 5 {
Scott Bakere6685952020-06-23 04:05:39 +0000359 logger.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700360 err := errors.New("invalid-number-of-args")
361 return nil, err
362 }
363 device := &voltha.Device{}
364 transactionID := &ic.StrType{}
365 flows := &openflow_13.FlowChanges{}
366 flowMetadata := &voltha.FlowMetadata{}
367 groups := &openflow_13.FlowGroupChanges{}
368 for _, arg := range args {
369 switch arg.Key {
370 case "device":
371 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000372 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700373 return nil, err
374 }
375 case "flow_changes":
376 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000377 logger.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700378 return nil, err
379 }
380 case "group_changes":
381 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000382 logger.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700383 return nil, err
384 }
385 case "flow_metadata":
386 if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000387 logger.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700388 return nil, err
389 }
390 case kafka.TransactionKey:
391 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000392 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700393 return nil, err
394 }
395 }
396 }
Scott Bakere6685952020-06-23 04:05:39 +0000397 logger.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups})
Scott Baker2c1c4822019-10-16 11:02:41 -0700398 //Invoke the incremental flow update API of the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000399 if err := rhp.adapter.Update_flows_incrementally(device, flows, groups, flowMetadata); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700400 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
401 }
402 return new(empty.Empty), nil
403}
404
Scott Bakere6685952020-06-23 04:05:39 +0000405func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) {
406 logger.Debug("Update_pm_config")
Scott Baker2c1c4822019-10-16 11:02:41 -0700407 if len(args) < 2 {
Scott Bakere6685952020-06-23 04:05:39 +0000408 logger.Warn("Update_pm_config-invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700409 err := errors.New("invalid-number-of-args")
410 return nil, err
411 }
412 device := &voltha.Device{}
413 transactionID := &ic.StrType{}
414 pmConfigs := &voltha.PmConfigs{}
415 for _, arg := range args {
416 switch arg.Key {
417 case "device":
418 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000419 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700420 return nil, err
421 }
422 case "pm_configs":
423 if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000424 logger.Warnw("cannot-unmarshal-pm-configs", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700425 return nil, err
426 }
427 case kafka.TransactionKey:
428 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000429 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700430 return nil, err
431 }
432 }
433 }
Scott Bakere6685952020-06-23 04:05:39 +0000434 logger.Debugw("Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs})
Scott Baker2c1c4822019-10-16 11:02:41 -0700435 //Invoke the pm config update API of the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000436 if err := rhp.adapter.Update_pm_config(device, pmConfigs); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700437 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
438 }
439 return new(empty.Empty), nil
440}
441
Scott Bakere6685952020-06-23 04:05:39 +0000442func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) {
443 logger.Debugw("Receive_packet_out", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700444 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000445 logger.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700446 err := errors.New("invalid-number-of-args")
447 return nil, err
448 }
449 deviceId := &ic.StrType{}
450 egressPort := &ic.IntType{}
451 packet := &openflow_13.OfpPacketOut{}
452 transactionID := &ic.StrType{}
453 for _, arg := range args {
454 switch arg.Key {
455 case "deviceId":
456 if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000457 logger.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700458 return nil, err
459 }
460 case "outPort":
461 if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000462 logger.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700463 return nil, err
464 }
465 case "packet":
466 if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000467 logger.Warnw("cannot-unmarshal-packet", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700468 return nil, err
469 }
470 case kafka.TransactionKey:
471 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000472 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700473 return nil, err
474 }
475 }
476 }
Scott Bakere6685952020-06-23 04:05:39 +0000477 logger.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet})
Scott Baker2c1c4822019-10-16 11:02:41 -0700478 //Invoke the adopt device on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000479 if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700480 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
481 }
482 return new(empty.Empty), nil
483}
484
485func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
486 return new(empty.Empty), nil
487}
488
489func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
490 return new(empty.Empty), nil
491}
492
Scott Bakere6685952020-06-23 04:05:39 +0000493func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700494 if len(args) < 2 {
Scott Bakere6685952020-06-23 04:05:39 +0000495 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700496 err := errors.New("invalid-number-of-args")
497 return nil, err
498 }
499 device := &voltha.Device{}
500 transactionID := &ic.StrType{}
501 for _, arg := range args {
502 switch arg.Key {
503 case "device":
504 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000505 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700506 return nil, err
507 }
508 case kafka.TransactionKey:
509 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000510 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700511 return nil, err
512 }
513 }
514 }
515
Scott Bakere6685952020-06-23 04:05:39 +0000516 logger.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
Scott Baker2c1c4822019-10-16 11:02:41 -0700517
518 var cap *ic.SwitchCapability
519 var err error
Scott Bakere6685952020-06-23 04:05:39 +0000520 if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700521 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
522 }
Scott Bakere6685952020-06-23 04:05:39 +0000523 logger.Debugw("Get_ofp_device_info", log.Fields{"cap": cap})
Scott Baker2c1c4822019-10-16 11:02:41 -0700524 return cap, nil
525}
526
Scott Bakere6685952020-06-23 04:05:39 +0000527func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) {
Scott Baker2c1c4822019-10-16 11:02:41 -0700528 if len(args) < 2 {
Scott Bakere6685952020-06-23 04:05:39 +0000529 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker2c1c4822019-10-16 11:02:41 -0700530 err := errors.New("invalid-number-of-args")
531 return nil, err
532 }
533 iaMsg := &ic.InterAdapterMessage{}
534 transactionID := &ic.StrType{}
535 for _, arg := range args {
536 switch arg.Key {
537 case "msg":
538 if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000539 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700540 return nil, err
541 }
542 case kafka.TransactionKey:
543 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000544 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Scott Baker2c1c4822019-10-16 11:02:41 -0700545 return nil, err
546 }
547 }
548 }
549
Scott Bakere6685952020-06-23 04:05:39 +0000550 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id})
Scott Baker2c1c4822019-10-16 11:02:41 -0700551
552 //Invoke the inter adapter API on the handler
Scott Bakere6685952020-06-23 04:05:39 +0000553 if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil {
Scott Baker2c1c4822019-10-16 11:02:41 -0700554 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
555 }
556
557 return new(empty.Empty), nil
558}
559
560func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) {
561 return &voltha.ImageDownload{}, nil
562}
563
564func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) {
565 return &voltha.ImageDownload{}, nil
566}
567
568func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) {
569 return &voltha.ImageDownload{}, nil
570}
571
572func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
573 return &voltha.ImageDownload{}, nil
574}
575
576func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
577 return &voltha.ImageDownload{}, nil
578}
kesavandf17f7922020-02-03 17:00:27 -0500579
Scott Bakere6685952020-06-23 04:05:39 +0000580func (rhp *RequestHandlerProxy) Enable_port(args []*ic.Argument) error {
581 logger.Debugw("enable_port", log.Fields{"args": args})
582 deviceId, port, err := rhp.getEnableDisableParams(args)
kesavandf17f7922020-02-03 17:00:27 -0500583 if err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000584 logger.Warnw("enable_port", log.Fields{"args": args, "deviceId": deviceId, "port": port})
kesavandf17f7922020-02-03 17:00:27 -0500585 return err
586 }
Scott Bakere6685952020-06-23 04:05:39 +0000587 return rhp.adapter.Enable_port(deviceId, port)
kesavandf17f7922020-02-03 17:00:27 -0500588}
589
Scott Bakere6685952020-06-23 04:05:39 +0000590func (rhp *RequestHandlerProxy) Disable_port(args []*ic.Argument) error {
591 logger.Debugw("disable_port", log.Fields{"args": args})
592 deviceId, port, err := rhp.getEnableDisableParams(args)
kesavandf17f7922020-02-03 17:00:27 -0500593 if err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000594 logger.Warnw("disable_port", log.Fields{"args": args, "deviceId": deviceId, "port": port})
kesavandf17f7922020-02-03 17:00:27 -0500595 return err
596 }
Scott Bakere6685952020-06-23 04:05:39 +0000597 return rhp.adapter.Disable_port(deviceId, port)
kesavandf17f7922020-02-03 17:00:27 -0500598}
599
Scott Bakere6685952020-06-23 04:05:39 +0000600func (rhp *RequestHandlerProxy) getEnableDisableParams(args []*ic.Argument) (string, *voltha.Port, error) {
601 logger.Debugw("getEnableDisableParams", log.Fields{"args": args})
kesavandf17f7922020-02-03 17:00:27 -0500602 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000603 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
kesavandf17f7922020-02-03 17:00:27 -0500604 return "", nil, errors.New("invalid-number-of-args")
605 }
606 deviceId := &ic.StrType{}
607 port := &voltha.Port{}
608 for _, arg := range args {
609 switch arg.Key {
610 case "deviceId":
611 if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000612 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
kesavandf17f7922020-02-03 17:00:27 -0500613 return "", nil, err
614 }
615 case "port":
616 if err := ptypes.UnmarshalAny(arg.Value, port); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000617 logger.Warnw("cannot-unmarshal-port", log.Fields{"error": err})
kesavandf17f7922020-02-03 17:00:27 -0500618 return "", nil, err
619 }
620 }
621 }
622 return deviceId.Val, port, nil
623}
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500624
Scott Bakere6685952020-06-23 04:05:39 +0000625func (rhp *RequestHandlerProxy) Child_device_lost(args []*ic.Argument) error {
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500626 if len(args) < 4 {
Scott Bakere6685952020-06-23 04:05:39 +0000627 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500628 return errors.New("invalid-number-of-args")
629 }
630
631 pDeviceId := &ic.StrType{}
632 pPortNo := &ic.IntType{}
633 onuID := &ic.IntType{}
634 fromTopic := &ic.StrType{}
635 for _, arg := range args {
636 switch arg.Key {
637 case "pDeviceId":
638 if err := ptypes.UnmarshalAny(arg.Value, pDeviceId); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000639 logger.Warnw("cannot-unmarshal-parent-deviceId", log.Fields{"error": err})
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500640 return err
641 }
642 case "pPortNo":
643 if err := ptypes.UnmarshalAny(arg.Value, pPortNo); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000644 logger.Warnw("cannot-unmarshal-port", log.Fields{"error": err})
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500645 return err
646 }
647 case "onuID":
648 if err := ptypes.UnmarshalAny(arg.Value, onuID); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000649 logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500650 return err
651 }
652 case kafka.FromTopic:
653 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000654 logger.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500655 return err
656 }
657 }
658 }
659 //Update the core reference for that device
660 rhp.coreProxy.UpdateCoreReference(pDeviceId.Val, fromTopic.Val)
661 //Invoke the Child_device_lost API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000662 if err := rhp.adapter.Child_device_lost(pDeviceId.Val, uint32(pPortNo.Val), uint32(onuID.Val)); err != nil {
Chaitrashree G Sc4a5c072020-02-04 17:08:40 -0500663 return status.Errorf(codes.NotFound, "%s", err.Error())
664 }
665 return nil
666}
Scott Baker04cb5da2020-03-26 15:52:22 -0700667
Scott Bakere6685952020-06-23 04:05:39 +0000668func (rhp *RequestHandlerProxy) Start_omci_test(args []*ic.Argument) (*ic.TestResponse, error) {
Scott Baker04cb5da2020-03-26 15:52:22 -0700669 if len(args) < 2 {
Scott Bakere6685952020-06-23 04:05:39 +0000670 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Scott Baker04cb5da2020-03-26 15:52:22 -0700671 err := errors.New("invalid-number-of-args")
672 return nil, err
673 }
674
675 // TODO: See related comment in voltha-go:adapter_proxy_go:startOmciTest()
676 // Second argument should perhaps be uuid instead of omcitestrequest
677
678 device := &voltha.Device{}
679 request := &voltha.OmciTestRequest{}
680 for _, arg := range args {
681 switch arg.Key {
682 case "device":
683 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000684 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Scott Baker04cb5da2020-03-26 15:52:22 -0700685 return nil, err
686 }
687 case "omcitestrequest":
688 if err := ptypes.UnmarshalAny(arg.Value, request); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000689 logger.Warnw("cannot-unmarshal-omcitestrequest", log.Fields{"error": err})
Scott Baker04cb5da2020-03-26 15:52:22 -0700690 return nil, err
691 }
692 }
693 }
Scott Bakere6685952020-06-23 04:05:39 +0000694 logger.Debugw("Start_omci_test", log.Fields{"device-id": device.Id, "req": request})
695 result, err := rhp.adapter.Start_omci_test(device, request)
Scott Baker04cb5da2020-03-26 15:52:22 -0700696 if err != nil {
697 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
698 }
699 return result, nil
700}
Scott Bakere6685952020-06-23 04:05:39 +0000701func (rhp *RequestHandlerProxy) Get_ext_value(args []*ic.Argument) (*voltha.ReturnValues, error) {
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800702 if len(args) < 3 {
Scott Bakere6685952020-06-23 04:05:39 +0000703 logger.Warn("invalid-number-of-args", log.Fields{"args": args})
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800704 return nil, errors.New("invalid-number-of-args")
705 }
706
707 pDeviceId := &ic.StrType{}
708 device := &voltha.Device{}
709 valuetype := &ic.IntType{}
710 for _, arg := range args {
711 switch arg.Key {
712 case "device":
713 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000714 logger.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800715 return nil, err
716 }
717 case "pDeviceId":
718 if err := ptypes.UnmarshalAny(arg.Value, pDeviceId); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000719 logger.Warnw("cannot-unmarshal-parent-deviceId", log.Fields{"error": err})
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800720 return nil, err
721 }
722 case "valuetype":
723 if err := ptypes.UnmarshalAny(arg.Value, valuetype); err != nil {
Scott Bakere6685952020-06-23 04:05:39 +0000724 logger.Warnw("cannot-unmarshal-valuetype", log.Fields{"error": err})
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800725 return nil, err
726 }
727 default:
Scott Bakere6685952020-06-23 04:05:39 +0000728 logger.Warnw("key-not-found", log.Fields{"arg.Key": arg.Key})
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800729 }
730 }
731
732 //Invoke the Get_value API on the adapter
Scott Bakere6685952020-06-23 04:05:39 +0000733 return rhp.adapter.Get_ext_value(pDeviceId.Val, device, voltha.ValueType_Type(valuetype.Val))
Dinesh Belwalkar4c89a1d2020-02-28 16:05:32 -0800734}