blob: b18f1d12f871f508986a70226694745de90e690a [file] [log] [blame]
khenaidood2b6df92018-12-13 16:37:20 -05001/*
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"
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"
khenaidoo6d055132019-02-12 16:51:19 -050024 "github.com/opencord/voltha-go/kafka"
William Kurkiandaa6bb22019-03-07 12:26:28 -050025 ic "github.com/opencord/voltha-protos/go/inter_container"
khenaidoo2c6a0992019-04-29 13:46:56 -040026 "github.com/opencord/voltha-protos/go/openflow_13"
William Kurkiandaa6bb22019-03-07 12:26:28 -050027 "github.com/opencord/voltha-protos/go/voltha"
khenaidood2b6df92018-12-13 16:37:20 -050028 "google.golang.org/grpc/codes"
29 "google.golang.org/grpc/status"
30)
31
32type RequestHandlerProxy struct {
33 TestMode bool
34 coreInstanceId string
35 adapter adapters.IAdapter
khenaidoo2c6a0992019-04-29 13:46:56 -040036 coreProxy *CoreProxy
khenaidood2b6df92018-12-13 16:37:20 -050037}
38
khenaidoo54e0ddf2019-02-27 16:21:33 -050039func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy *CoreProxy) *RequestHandlerProxy {
khenaidood2b6df92018-12-13 16:37:20 -050040 var proxy RequestHandlerProxy
41 proxy.coreInstanceId = coreInstanceId
42 proxy.adapter = iadapter
khenaidoo54e0ddf2019-02-27 16:21:33 -050043 proxy.coreProxy = cProxy
khenaidood2b6df92018-12-13 16:37:20 -050044 return &proxy
45}
46
47func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) {
48 return new(empty.Empty), nil
49}
50
51func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) {
52 return nil, nil
53}
54
55func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) {
56 return nil, nil
57}
58
59func (rhp *RequestHandlerProxy) Adopt_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -050060 if len(args) < 3 {
khenaidood2b6df92018-12-13 16:37:20 -050061 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{}
khenaidoo6d055132019-02-12 16:51:19 -050066 transactionID := &ic.StrType{}
khenaidoo54e0ddf2019-02-27 16:21:33 -050067 fromTopic := &ic.StrType{}
khenaidoo6d055132019-02-12 16:51:19 -050068 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 }
khenaidoo54e0ddf2019-02-27 16:21:33 -050080 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 }
khenaidoo6d055132019-02-12 16:51:19 -050085 }
khenaidood2b6df92018-12-13 16:37:20 -050086 }
khenaidoo6d055132019-02-12 16:51:19 -050087
khenaidood2b6df92018-12-13 16:37:20 -050088 log.Debugw("Adopt_device", log.Fields{"deviceId": device.Id})
89
khenaidoo54e0ddf2019-02-27 16:21:33 -050090 //Update the core reference for that device
91 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
92
khenaidood2b6df92018-12-13 16:37:20 -050093 //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
101func (rhp *RequestHandlerProxy) Reconcile_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidooba6b6c42019-08-02 09:11:56 -0400102 if len(args) < 3 {
103 log.Warn("invalid-number-of-args", log.Fields{"args": args})
104 err := errors.New("invalid-number-of-args")
105 return nil, err
106 }
107
108 device := &voltha.Device{}
109 transactionID := &ic.StrType{}
110 fromTopic := &ic.StrType{}
111 for _, arg := range args {
112 switch arg.Key {
113 case "device":
114 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
115 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
116 return nil, err
117 }
118 case kafka.TransactionKey:
119 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
120 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
121 return nil, err
122 }
123 case kafka.FromTopic:
124 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
125 log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
126 return nil, err
127 }
128 }
129 }
130 //Update the core reference for that device
131 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
132
133 //Invoke the reconcile device API on the adapter
134 if err := rhp.adapter.Reconcile_device(device); err != nil {
135 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
136 }
khenaidood2b6df92018-12-13 16:37:20 -0500137 return new(empty.Empty), nil
138}
139
140func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) {
141 return new(empty.Empty), nil
142}
143
144func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo3ab34882019-05-02 21:33:30 -0400145 if len(args) < 3 {
146 log.Warn("invalid-number-of-args", log.Fields{"args": args})
147 err := errors.New("invalid-number-of-args")
148 return nil, err
149 }
150
151 device := &voltha.Device{}
152 transactionID := &ic.StrType{}
153 fromTopic := &ic.StrType{}
154 for _, arg := range args {
155 switch arg.Key {
156 case "device":
157 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
158 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
159 return nil, err
160 }
161 case kafka.TransactionKey:
162 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
163 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
164 return nil, err
165 }
166 case kafka.FromTopic:
167 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
168 log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
169 return nil, err
170 }
171 }
172 }
173 //Update the core reference for that device
174 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
175 //Invoke the Disable_device API on the adapter
176 if err := rhp.adapter.Disable_device(device); err != nil {
177 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
178 }
khenaidood2b6df92018-12-13 16:37:20 -0500179 return new(empty.Empty), nil
180}
181
182func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo3ab34882019-05-02 21:33:30 -0400183 if len(args) < 3 {
184 log.Warn("invalid-number-of-args", log.Fields{"args": args})
185 err := errors.New("invalid-number-of-args")
186 return nil, err
187 }
188
189 device := &voltha.Device{}
190 transactionID := &ic.StrType{}
191 fromTopic := &ic.StrType{}
192 for _, arg := range args {
193 switch arg.Key {
194 case "device":
195 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
196 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
197 return nil, err
198 }
199 case kafka.TransactionKey:
200 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
201 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
202 return nil, err
203 }
204 case kafka.FromTopic:
205 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
206 log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
207 return nil, err
208 }
209 }
210 }
211 //Update the core reference for that device
212 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
213 //Invoke the Reenable_device API on the adapter
214 if err := rhp.adapter.Reenable_device(device); err != nil {
215 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
216 }
khenaidood2b6df92018-12-13 16:37:20 -0500217 return new(empty.Empty), nil
218}
219
220func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) {
Girish Gowdru894d97d2019-05-28 05:07:18 -0400221 if len(args) < 3 {
222 log.Warn("invalid-number-of-args", log.Fields{"args": args})
223 err := errors.New("invalid-number-of-args")
224 return nil, err
225 }
226
227 device := &voltha.Device{}
228 transactionID := &ic.StrType{}
229 fromTopic := &ic.StrType{}
230 for _, arg := range args {
231 switch arg.Key {
232 case "device":
233 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
234 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
235 return nil, err
236 }
237 case kafka.TransactionKey:
238 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
239 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
240 return nil, err
241 }
242 case kafka.FromTopic:
243 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
244 log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
245 return nil, err
246 }
247 }
248 }
249 //Update the core reference for that device
250 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
251 //Invoke the Reboot_device API on the adapter
252 if err := rhp.adapter.Reboot_device(device); err != nil {
253 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
254 }
khenaidood2b6df92018-12-13 16:37:20 -0500255 return new(empty.Empty), nil
Girish Gowdru894d97d2019-05-28 05:07:18 -0400256
khenaidood2b6df92018-12-13 16:37:20 -0500257}
258
259func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) {
260 return new(empty.Empty), nil
261}
262
263func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo0a822f92019-05-08 15:15:57 -0400264 if len(args) < 3 {
265 log.Warn("invalid-number-of-args", log.Fields{"args": args})
266 err := errors.New("invalid-number-of-args")
267 return nil, err
268 }
269
270 device := &voltha.Device{}
271 transactionID := &ic.StrType{}
272 fromTopic := &ic.StrType{}
273 for _, arg := range args {
274 switch arg.Key {
275 case "device":
276 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
277 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
278 return nil, err
279 }
280 case kafka.TransactionKey:
281 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
282 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
283 return nil, err
284 }
285 case kafka.FromTopic:
286 if err := ptypes.UnmarshalAny(arg.Value, fromTopic); err != nil {
287 log.Warnw("cannot-unmarshal-from-topic", log.Fields{"error": err})
288 return nil, err
289 }
290 }
291 }
292 //Update the core reference for that device
293 rhp.coreProxy.UpdateCoreReference(device.Id, fromTopic.Val)
khenaidoob3127472019-07-24 21:04:55 -0400294 //Invoke the delete_device API on the adapter
khenaidoo0a822f92019-05-08 15:15:57 -0400295 if err := rhp.adapter.Delete_device(device); err != nil {
296 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
297 }
khenaidood2b6df92018-12-13 16:37:20 -0500298 return new(empty.Empty), nil
299}
300
301func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) {
302 return new(empty.Empty), nil
303}
304
305func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo0458db62019-06-20 08:50:36 -0400306 log.Debug("Update_flows_bulk")
Manikkaraj kb1a10922019-07-29 12:10:34 -0400307 if len(args) < 5 {
khenaidoo0458db62019-06-20 08:50:36 -0400308 log.Warn("Update_flows_bulk-invalid-number-of-args", log.Fields{"args": args})
309 err := errors.New("invalid-number-of-args")
310 return nil, err
311 }
312 device := &voltha.Device{}
313 transactionID := &ic.StrType{}
314 flows := &voltha.Flows{}
Manikkaraj kb1a10922019-07-29 12:10:34 -0400315 flowMetadata := &voltha.FlowMetadata{}
khenaidoo0458db62019-06-20 08:50:36 -0400316 groups := &voltha.FlowGroups{}
317 for _, arg := range args {
318 switch arg.Key {
319 case "device":
320 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
321 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
322 return nil, err
323 }
324 case "flows":
325 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
326 log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
327 return nil, err
328 }
329 case "groups":
330 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
331 log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
332 return nil, err
333 }
Manikkaraj kb1a10922019-07-29 12:10:34 -0400334 case "flow_metadata":
335 if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil {
336 log.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err})
337 return nil, err
338 }
khenaidoo0458db62019-06-20 08:50:36 -0400339 case kafka.TransactionKey:
340 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
341 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
342 return nil, err
343 }
344 }
345 }
346 log.Debugw("Update_flows_bulk", log.Fields{"flows": flows, "groups": groups})
khenaidoob3127472019-07-24 21:04:55 -0400347 //Invoke the bulk flow update API of the adapter
Manikkaraj kb1a10922019-07-29 12:10:34 -0400348 if err := rhp.adapter.Update_flows_bulk(device, flows, groups, flowMetadata); err != nil {
khenaidoo0458db62019-06-20 08:50:36 -0400349 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
350 }
khenaidood2b6df92018-12-13 16:37:20 -0500351 return new(empty.Empty), nil
352}
353
354func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo2c6a0992019-04-29 13:46:56 -0400355 log.Debug("Update_flows_incrementally")
Manikkaraj kb1a10922019-07-29 12:10:34 -0400356 if len(args) < 5 {
mkoodali252f7672019-03-25 12:13:12 +0530357 log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args})
358 err := errors.New("invalid-number-of-args")
359 return nil, err
360 }
361 device := &voltha.Device{}
362 transactionID := &ic.StrType{}
khenaidoo2c6a0992019-04-29 13:46:56 -0400363 flows := &openflow_13.FlowChanges{}
Manikkaraj kb1a10922019-07-29 12:10:34 -0400364 flowMetadata := &voltha.FlowMetadata{}
khenaidoo2c6a0992019-04-29 13:46:56 -0400365 groups := &openflow_13.FlowGroupChanges{}
mkoodali252f7672019-03-25 12:13:12 +0530366 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 "flow_changes":
374 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
375 log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
376 return nil, err
377 }
378 case "group_changes":
379 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
380 log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
381 return nil, err
382 }
Manikkaraj kb1a10922019-07-29 12:10:34 -0400383 case "flow_metadata":
384 if err := ptypes.UnmarshalAny(arg.Value, flowMetadata); err != nil {
385 log.Warnw("cannot-unmarshal-metadata", log.Fields{"error": err})
386 return nil, err
387 }
mkoodali252f7672019-03-25 12:13:12 +0530388 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 }
khenaidoo2c6a0992019-04-29 13:46:56 -0400395 log.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups})
khenaidoob3127472019-07-24 21:04:55 -0400396 //Invoke the incremental flow update API of the adapter
Manikkaraj kb1a10922019-07-29 12:10:34 -0400397 if err := rhp.adapter.Update_flows_incrementally(device, flows, groups, flowMetadata); err != nil {
khenaidoo2c6a0992019-04-29 13:46:56 -0400398 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
399 }
khenaidood2b6df92018-12-13 16:37:20 -0500400 return new(empty.Empty), nil
401}
402
403func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) {
khenaidoob3127472019-07-24 21:04:55 -0400404 log.Debug("Update_pm_config")
405 if len(args) < 2 {
406 log.Warn("Update_pm_config-invalid-number-of-args", log.Fields{"args": args})
407 err := errors.New("invalid-number-of-args")
408 return nil, err
409 }
410 device := &voltha.Device{}
411 transactionID := &ic.StrType{}
412 pmConfigs := &voltha.PmConfigs{}
413 for _, arg := range args {
414 switch arg.Key {
415 case "device":
416 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
417 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
418 return nil, err
419 }
420 case "pm_configs":
421 if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil {
422 log.Warnw("cannot-unmarshal-pm-configs", log.Fields{"error": err})
423 return nil, err
424 }
425 case kafka.TransactionKey:
426 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
427 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
428 return nil, err
429 }
430 }
431 }
432 log.Debugw("Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs})
433 //Invoke the pm config update API of the adapter
434 if err := rhp.adapter.Update_pm_config(device, pmConfigs); err != nil {
435 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
436 }
khenaidood2b6df92018-12-13 16:37:20 -0500437 return new(empty.Empty), nil
438}
439
440func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) {
manikkaraj k6c9689d2019-05-09 12:59:52 -0400441 log.Debugw("Receive_packet_out", log.Fields{"args": args})
442 if len(args) < 3 {
443 log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args})
444 err := errors.New("invalid-number-of-args")
445 return nil, err
446 }
447 deviceId := &ic.StrType{}
448 egressPort := &ic.IntType{}
449 packet := &openflow_13.OfpPacketOut{}
450 transactionID := &ic.StrType{}
451 for _, arg := range args {
452 switch arg.Key {
453 case "deviceId":
454 if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil {
455 log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err})
456 return nil, err
457 }
458 case "outPort":
459 if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil {
460 log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err})
461 return nil, err
462 }
463 case "packet":
464 if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil {
465 log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err})
466 return nil, err
467 }
468 case kafka.TransactionKey:
469 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
470 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
471 return nil, err
472 }
473 }
474 }
475 log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet})
476 //Invoke the adopt device on the adapter
477 if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil {
478 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
479 }
khenaidood2b6df92018-12-13 16:37:20 -0500480 return new(empty.Empty), nil
481}
482
483func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
484 return new(empty.Empty), nil
485}
486
487func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
488 return new(empty.Empty), nil
489}
490
491func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500492 if len(args) < 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500493 log.Warn("invalid-number-of-args", log.Fields{"args": args})
494 err := errors.New("invalid-number-of-args")
495 return nil, err
496 }
497 device := &voltha.Device{}
khenaidoo6d055132019-02-12 16:51:19 -0500498 transactionID := &ic.StrType{}
499 for _, arg := range args {
500 switch arg.Key {
501 case "device":
502 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
503 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
504 return nil, err
505 }
506 case kafka.TransactionKey:
507 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
508 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
509 return nil, err
510 }
511 }
khenaidood2b6df92018-12-13 16:37:20 -0500512 }
khenaidoo6d055132019-02-12 16:51:19 -0500513
khenaidood2b6df92018-12-13 16:37:20 -0500514 log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
515
516 var cap *ic.SwitchCapability
517 var err error
518 if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil {
519 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
520 }
khenaidoo6d055132019-02-12 16:51:19 -0500521 log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap})
khenaidood2b6df92018-12-13 16:37:20 -0500522 return cap, nil
523}
524
525func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500526 if len(args) < 3 {
khenaidood2b6df92018-12-13 16:37:20 -0500527 log.Warn("invalid-number-of-args", log.Fields{"args": args})
528 err := errors.New("invalid-number-of-args")
529 return nil, err
530 }
531 device := &voltha.Device{}
532 pNo := &ic.IntType{}
khenaidoo6d055132019-02-12 16:51:19 -0500533 transactionID := &ic.StrType{}
khenaidood2b6df92018-12-13 16:37:20 -0500534 for _, arg := range args {
535 switch arg.Key {
536 case "device":
537 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
538 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
539 return nil, err
540 }
541 case "port_no":
542 if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil {
543 log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err})
544 return nil, err
545 }
khenaidoo6d055132019-02-12 16:51:19 -0500546 case kafka.TransactionKey:
547 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
548 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
549 return nil, err
550 }
khenaidood2b6df92018-12-13 16:37:20 -0500551 }
552 }
553 log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val})
554 var cap *ic.PortCapability
555 var err error
556 if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil {
557 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
558 }
559 return cap, nil
560}
561
562func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500563 if len(args) < 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500564 log.Warn("invalid-number-of-args", log.Fields{"args": args})
565 err := errors.New("invalid-number-of-args")
566 return nil, err
567 }
568 iaMsg := &ic.InterAdapterMessage{}
khenaidoo6d055132019-02-12 16:51:19 -0500569 transactionID := &ic.StrType{}
570 for _, arg := range args {
571 switch arg.Key {
572 case "msg":
573 if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil {
574 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
575 return nil, err
576 }
577 case kafka.TransactionKey:
578 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
579 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
580 return nil, err
581 }
582 }
khenaidood2b6df92018-12-13 16:37:20 -0500583 }
584
585 log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id})
586
587 //Invoke the inter adapter API on the handler
588 if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil {
589 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
590 }
591
592 return new(empty.Empty), nil
593}
594
khenaidoof5a5bfa2019-01-23 22:20:29 -0500595func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) {
596 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500597}
598
khenaidoof5a5bfa2019-01-23 22:20:29 -0500599func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) {
600 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500601}
602
khenaidoof5a5bfa2019-01-23 22:20:29 -0500603func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) {
604 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500605}
606
khenaidoof5a5bfa2019-01-23 22:20:29 -0500607func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
608 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500609}
610
khenaidoof5a5bfa2019-01-23 22:20:29 -0500611func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
612 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500613}