blob: b3606b04c7f882d6363b94d3624aebc509af863d [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"
khenaidood2b6df92018-12-13 16:37:20 -050025 ic "github.com/opencord/voltha-go/protos/inter_container"
26 "github.com/opencord/voltha-go/protos/voltha"
27 "google.golang.org/grpc/codes"
28 "google.golang.org/grpc/status"
29)
30
31type RequestHandlerProxy struct {
32 TestMode bool
33 coreInstanceId string
34 adapter adapters.IAdapter
35}
36
37func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter) *RequestHandlerProxy {
38 var proxy RequestHandlerProxy
39 proxy.coreInstanceId = coreInstanceId
40 proxy.adapter = iadapter
41 return &proxy
42}
43
44func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) {
45 return new(empty.Empty), nil
46}
47
48func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) {
49 return nil, nil
50}
51
52func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) {
53 return nil, nil
54}
55
56func (rhp *RequestHandlerProxy) Adopt_device(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo6d055132019-02-12 16:51:19 -050057 if len(args) != 2 {
khenaidood2b6df92018-12-13 16:37:20 -050058 log.Warn("invalid-number-of-args", log.Fields{"args": args})
59 err := errors.New("invalid-number-of-args")
60 return nil, err
61 }
62 device := &voltha.Device{}
khenaidoo6d055132019-02-12 16:51:19 -050063 transactionID := &ic.StrType{}
64 for _, arg := range args {
65 switch arg.Key {
66 case "device":
67 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
68 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
69 return nil, err
70 }
71 case kafka.TransactionKey:
72 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
73 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
74 return nil, err
75 }
76 }
khenaidood2b6df92018-12-13 16:37:20 -050077 }
khenaidoo6d055132019-02-12 16:51:19 -050078
khenaidood2b6df92018-12-13 16:37:20 -050079 log.Debugw("Adopt_device", log.Fields{"deviceId": device.Id})
80
81 //Invoke the adopt device on the adapter
82 if err := rhp.adapter.Adopt_device(device); err != nil {
83 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
84 }
85
86 return new(empty.Empty), nil
87}
88
89func (rhp *RequestHandlerProxy) Reconcile_device(args []*ic.Argument) (*empty.Empty, error) {
90 return new(empty.Empty), nil
91}
92
93func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) {
94 return new(empty.Empty), nil
95}
96
97func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) {
98 return new(empty.Empty), nil
99}
100
101func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) {
102 return new(empty.Empty), nil
103}
104
105func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) {
106 return new(empty.Empty), nil
107}
108
109func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) {
110 return new(empty.Empty), nil
111}
112
113func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) {
114 return new(empty.Empty), nil
115}
116
117func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) {
118 return new(empty.Empty), nil
119}
120
121func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) {
122 return new(empty.Empty), nil
123}
124
125func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
126 return new(empty.Empty), nil
127}
128
129func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) {
130 return new(empty.Empty), nil
131}
132
133func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) {
134 return new(empty.Empty), nil
135}
136
137func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
138 return new(empty.Empty), nil
139}
140
141func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
142 return new(empty.Empty), nil
143}
144
145func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) {
khenaidoo6d055132019-02-12 16:51:19 -0500146 if len(args) != 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500147 log.Warn("invalid-number-of-args", log.Fields{"args": args})
148 err := errors.New("invalid-number-of-args")
149 return nil, err
150 }
151 device := &voltha.Device{}
khenaidoo6d055132019-02-12 16:51:19 -0500152 transactionID := &ic.StrType{}
153 for _, arg := range args {
154 switch arg.Key {
155 case "device":
156 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
157 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
158 return nil, err
159 }
160 case kafka.TransactionKey:
161 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
162 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
163 return nil, err
164 }
165 }
khenaidood2b6df92018-12-13 16:37:20 -0500166 }
khenaidoo6d055132019-02-12 16:51:19 -0500167
khenaidood2b6df92018-12-13 16:37:20 -0500168 log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
169
170 var cap *ic.SwitchCapability
171 var err error
172 if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil {
173 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
174 }
khenaidoo6d055132019-02-12 16:51:19 -0500175 log.Debugw("Get_ofp_device_info", log.Fields{"cap": cap})
khenaidood2b6df92018-12-13 16:37:20 -0500176 return cap, nil
177}
178
179func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) {
khenaidoo6d055132019-02-12 16:51:19 -0500180 if len(args) != 3 {
khenaidood2b6df92018-12-13 16:37:20 -0500181 log.Warn("invalid-number-of-args", log.Fields{"args": args})
182 err := errors.New("invalid-number-of-args")
183 return nil, err
184 }
185 device := &voltha.Device{}
186 pNo := &ic.IntType{}
khenaidoo6d055132019-02-12 16:51:19 -0500187 transactionID := &ic.StrType{}
khenaidood2b6df92018-12-13 16:37:20 -0500188 for _, arg := range args {
189 switch arg.Key {
190 case "device":
191 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
192 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
193 return nil, err
194 }
195 case "port_no":
196 if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil {
197 log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err})
198 return nil, err
199 }
khenaidoo6d055132019-02-12 16:51:19 -0500200 case kafka.TransactionKey:
201 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
202 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
203 return nil, err
204 }
khenaidood2b6df92018-12-13 16:37:20 -0500205 }
206 }
207 log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val})
208 var cap *ic.PortCapability
209 var err error
210 if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil {
211 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
212 }
213 return cap, nil
214}
215
216func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) {
khenaidoo6d055132019-02-12 16:51:19 -0500217 if len(args) != 2 {
khenaidood2b6df92018-12-13 16:37:20 -0500218 log.Warn("invalid-number-of-args", log.Fields{"args": args})
219 err := errors.New("invalid-number-of-args")
220 return nil, err
221 }
222 iaMsg := &ic.InterAdapterMessage{}
khenaidoo6d055132019-02-12 16:51:19 -0500223 transactionID := &ic.StrType{}
224 for _, arg := range args {
225 switch arg.Key {
226 case "msg":
227 if err := ptypes.UnmarshalAny(arg.Value, iaMsg); err != nil {
228 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
229 return nil, err
230 }
231 case kafka.TransactionKey:
232 if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
233 log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
234 return nil, err
235 }
236 }
khenaidood2b6df92018-12-13 16:37:20 -0500237 }
238
239 log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id})
240
241 //Invoke the inter adapter API on the handler
242 if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil {
243 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
244 }
245
246 return new(empty.Empty), nil
247}
248
khenaidoof5a5bfa2019-01-23 22:20:29 -0500249func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) {
250 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500251}
252
khenaidoof5a5bfa2019-01-23 22:20:29 -0500253func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) {
254 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500255}
256
khenaidoof5a5bfa2019-01-23 22:20:29 -0500257func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) {
258 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500259}
260
khenaidoof5a5bfa2019-01-23 22:20:29 -0500261func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
262 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500263}
264
khenaidoof5a5bfa2019-01-23 22:20:29 -0500265func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
266 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500267}