blob: 7504d37a1a863e4fcabd1c668e6802bb6c2abf54 [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")
307 if len(args) < 4 {
308 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{}
315 groups := &voltha.FlowGroups{}
316 for _, arg := range args {
317 switch arg.Key {
318 case "device":
319 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
320 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
321 return nil, err
322 }
323 case "flows":
324 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
325 log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
326 return nil, err
327 }
328 case "groups":
329 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
330 log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
331 return nil, err
332 }
333 case kafka.TransactionKey:
334 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
335 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
336 return nil, err
337 }
338 }
339 }
340 log.Debugw("Update_flows_bulk", log.Fields{"flows": flows, "groups": groups})
khenaidoob3127472019-07-24 21:04:55 -0400341 //Invoke the bulk flow update API of the adapter
khenaidoo0458db62019-06-20 08:50:36 -0400342 if err := rhp.adapter.Update_flows_bulk(device, flows, groups); err != nil {
343 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
344 }
khenaidood2b6df92018-12-13 16:37:20 -0500345 return new(empty.Empty), nil
346}
347
348func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo2c6a0992019-04-29 13:46:56 -0400349 log.Debug("Update_flows_incrementally")
mkoodali252f7672019-03-25 12:13:12 +0530350 if len(args) < 3 {
351 log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args})
352 err := errors.New("invalid-number-of-args")
353 return nil, err
354 }
355 device := &voltha.Device{}
356 transactionID := &ic.StrType{}
khenaidoo2c6a0992019-04-29 13:46:56 -0400357 flows := &openflow_13.FlowChanges{}
358 groups := &openflow_13.FlowGroupChanges{}
mkoodali252f7672019-03-25 12:13:12 +0530359 for _, arg := range args {
360 switch arg.Key {
361 case "device":
362 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
363 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
364 return nil, err
365 }
366 case "flow_changes":
367 if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
368 log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
369 return nil, err
370 }
371 case "group_changes":
372 if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
373 log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
374 return nil, err
375 }
376 case kafka.TransactionKey:
377 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
378 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
379 return nil, err
380 }
381 }
382 }
khenaidoo2c6a0992019-04-29 13:46:56 -0400383 log.Debugw("Update_flows_incrementally", log.Fields{"flows": flows, "groups": groups})
khenaidoob3127472019-07-24 21:04:55 -0400384 //Invoke the incremental flow update API of the adapter
khenaidoo2c6a0992019-04-29 13:46:56 -0400385 if err := rhp.adapter.Update_flows_incrementally(device, flows, groups); err != nil {
386 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
387 }
khenaidood2b6df92018-12-13 16:37:20 -0500388 return new(empty.Empty), nil
389}
390
391func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) {
khenaidoob3127472019-07-24 21:04:55 -0400392 log.Debug("Update_pm_config")
393 if len(args) < 2 {
394 log.Warn("Update_pm_config-invalid-number-of-args", log.Fields{"args": args})
395 err := errors.New("invalid-number-of-args")
396 return nil, err
397 }
398 device := &voltha.Device{}
399 transactionID := &ic.StrType{}
400 pmConfigs := &voltha.PmConfigs{}
401 for _, arg := range args {
402 switch arg.Key {
403 case "device":
404 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
405 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
406 return nil, err
407 }
408 case "pm_configs":
409 if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil {
410 log.Warnw("cannot-unmarshal-pm-configs", log.Fields{"error": err})
411 return nil, err
412 }
413 case kafka.TransactionKey:
414 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
415 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
416 return nil, err
417 }
418 }
419 }
420 log.Debugw("Update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs})
421 //Invoke the pm config update API of the adapter
422 if err := rhp.adapter.Update_pm_config(device, pmConfigs); err != nil {
423 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
424 }
khenaidood2b6df92018-12-13 16:37:20 -0500425 return new(empty.Empty), nil
426}
427
428func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) {
manikkaraj k6c9689d2019-05-09 12:59:52 -0400429 log.Debugw("Receive_packet_out", log.Fields{"args": args})
430 if len(args) < 3 {
431 log.Warn("Receive_packet_out-invalid-number-of-args", log.Fields{"args": args})
432 err := errors.New("invalid-number-of-args")
433 return nil, err
434 }
435 deviceId := &ic.StrType{}
436 egressPort := &ic.IntType{}
437 packet := &openflow_13.OfpPacketOut{}
438 transactionID := &ic.StrType{}
439 for _, arg := range args {
440 switch arg.Key {
441 case "deviceId":
442 if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil {
443 log.Warnw("cannot-unmarshal-deviceId", log.Fields{"error": err})
444 return nil, err
445 }
446 case "outPort":
447 if err := ptypes.UnmarshalAny(arg.Value, egressPort); err != nil {
448 log.Warnw("cannot-unmarshal-egressPort", log.Fields{"error": err})
449 return nil, err
450 }
451 case "packet":
452 if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil {
453 log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err})
454 return nil, err
455 }
456 case kafka.TransactionKey:
457 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
458 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
459 return nil, err
460 }
461 }
462 }
463 log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceId.Val, "outPort": egressPort, "packet": packet})
464 //Invoke the adopt device on the adapter
465 if err := rhp.adapter.Receive_packet_out(deviceId.Val, int(egressPort.Val), packet); err != nil {
466 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
467 }
khenaidood2b6df92018-12-13 16:37:20 -0500468 return new(empty.Empty), nil
469}
470
471func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
472 return new(empty.Empty), nil
473}
474
475func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
476 return new(empty.Empty), nil
477}
478
479func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500480 if len(args) < 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500481 log.Warn("invalid-number-of-args", log.Fields{"args": args})
482 err := errors.New("invalid-number-of-args")
483 return nil, err
484 }
485 device := &voltha.Device{}
khenaidoo6d055132019-02-12 16:51:19 -0500486 transactionID := &ic.StrType{}
487 for _, arg := range args {
488 switch arg.Key {
489 case "device":
490 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
491 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
492 return nil, err
493 }
494 case kafka.TransactionKey:
495 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
496 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
497 return nil, err
498 }
499 }
khenaidood2b6df92018-12-13 16:37:20 -0500500 }
khenaidoo6d055132019-02-12 16:51:19 -0500501
khenaidood2b6df92018-12-13 16:37:20 -0500502 log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
503
504 var cap *ic.SwitchCapability
505 var err error
506 if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil {
507 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
508 }
khenaidoo6d055132019-02-12 16:51:19 -0500509 log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap})
khenaidood2b6df92018-12-13 16:37:20 -0500510 return cap, nil
511}
512
513func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500514 if len(args) < 3 {
khenaidood2b6df92018-12-13 16:37:20 -0500515 log.Warn("invalid-number-of-args", log.Fields{"args": args})
516 err := errors.New("invalid-number-of-args")
517 return nil, err
518 }
519 device := &voltha.Device{}
520 pNo := &ic.IntType{}
khenaidoo6d055132019-02-12 16:51:19 -0500521 transactionID := &ic.StrType{}
khenaidood2b6df92018-12-13 16:37:20 -0500522 for _, arg := range args {
523 switch arg.Key {
524 case "device":
525 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
526 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
527 return nil, err
528 }
529 case "port_no":
530 if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil {
531 log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err})
532 return nil, err
533 }
khenaidoo6d055132019-02-12 16:51:19 -0500534 case kafka.TransactionKey:
535 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
536 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
537 return nil, err
538 }
khenaidood2b6df92018-12-13 16:37:20 -0500539 }
540 }
541 log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val})
542 var cap *ic.PortCapability
543 var err error
544 if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil {
545 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
546 }
547 return cap, nil
548}
549
550func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo54e0ddf2019-02-27 16:21:33 -0500551 if len(args) < 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500552 log.Warn("invalid-number-of-args", log.Fields{"args": args})
553 err := errors.New("invalid-number-of-args")
554 return nil, err
555 }
556 iaMsg := &ic.InterAdapterMessage{}
khenaidoo6d055132019-02-12 16:51:19 -0500557 transactionID := &ic.StrType{}
558 for _, arg := range args {
559 switch arg.Key {
560 case "msg":
561 if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil {
562 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
563 return nil, err
564 }
565 case kafka.TransactionKey:
566 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
567 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
568 return nil, err
569 }
570 }
khenaidood2b6df92018-12-13 16:37:20 -0500571 }
572
573 log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id})
574
575 //Invoke the inter adapter API on the handler
576 if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil {
577 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
578 }
579
580 return new(empty.Empty), nil
581}
582
khenaidoof5a5bfa2019-01-23 22:20:29 -0500583func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) {
584 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500585}
586
khenaidoof5a5bfa2019-01-23 22:20:29 -0500587func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) {
588 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500589}
590
khenaidoof5a5bfa2019-01-23 22:20:29 -0500591func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) {
592 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500593}
594
khenaidoof5a5bfa2019-01-23 22:20:29 -0500595func (rhp *RequestHandlerProxy) Activate_image_update(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) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
600 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500601}