blob: 3f8465c89eb84543435215530f61e098e457b1f7 [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"
24 ic "github.com/opencord/voltha-go/protos/inter_container"
25 "github.com/opencord/voltha-go/protos/voltha"
26 "google.golang.org/grpc/codes"
27 "google.golang.org/grpc/status"
28)
29
30type RequestHandlerProxy struct {
31 TestMode bool
32 coreInstanceId string
33 adapter adapters.IAdapter
34}
35
36func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter) *RequestHandlerProxy {
37 var proxy RequestHandlerProxy
38 proxy.coreInstanceId = coreInstanceId
39 proxy.adapter = iadapter
40 return &proxy
41}
42
43func (rhp *RequestHandlerProxy) Adapter_descriptor() (*empty.Empty, error) {
44 return new(empty.Empty), nil
45}
46
47func (rhp *RequestHandlerProxy) Device_types() (*voltha.DeviceTypes, error) {
48 return nil, nil
49}
50
51func (rhp *RequestHandlerProxy) Health() (*voltha.HealthStatus, error) {
52 return nil, nil
53}
54
55func (rhp *RequestHandlerProxy) Adopt_device(args []*ic.Argument) (*empty.Empty, error) {
56 if len(args) != 1 {
57 log.Warn("invalid-number-of-args", log.Fields{"args": args})
58 err := errors.New("invalid-number-of-args")
59 return nil, err
60 }
61 device := &voltha.Device{}
62 if err := ptypes.UnmarshalAny(args[0].Value, device); err != nil {
63 log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err})
64 return nil, err
65 }
66 log.Debugw("Adopt_device", log.Fields{"deviceId": device.Id})
67
68 //Invoke the adopt device on the adapter
69 if err := rhp.adapter.Adopt_device(device); err != nil {
70 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
71 }
72
73 return new(empty.Empty), nil
74}
75
76func (rhp *RequestHandlerProxy) Reconcile_device(args []*ic.Argument) (*empty.Empty, error) {
77 return new(empty.Empty), nil
78}
79
80func (rhp *RequestHandlerProxy) Abandon_device(args []*ic.Argument) (*empty.Empty, error) {
81 return new(empty.Empty), nil
82}
83
84func (rhp *RequestHandlerProxy) Disable_device(args []*ic.Argument) (*empty.Empty, error) {
85 return new(empty.Empty), nil
86}
87
88func (rhp *RequestHandlerProxy) Reenable_device(args []*ic.Argument) (*empty.Empty, error) {
89 return new(empty.Empty), nil
90}
91
92func (rhp *RequestHandlerProxy) Reboot_device(args []*ic.Argument) (*empty.Empty, error) {
93 return new(empty.Empty), nil
94}
95
96func (rhp *RequestHandlerProxy) Self_test_device(args []*ic.Argument) (*empty.Empty, error) {
97 return new(empty.Empty), nil
98}
99
100func (rhp *RequestHandlerProxy) Delete_device(args []*ic.Argument) (*empty.Empty, error) {
101 return new(empty.Empty), nil
102}
103
104func (rhp *RequestHandlerProxy) Get_device_details(args []*ic.Argument) (*empty.Empty, error) {
105 return new(empty.Empty), nil
106}
107
108func (rhp *RequestHandlerProxy) Update_flows_bulk(args []*ic.Argument) (*empty.Empty, error) {
109 return new(empty.Empty), nil
110}
111
112func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
113 return new(empty.Empty), nil
114}
115
116func (rhp *RequestHandlerProxy) Update_pm_config(args []*ic.Argument) (*empty.Empty, error) {
117 return new(empty.Empty), nil
118}
119
120func (rhp *RequestHandlerProxy) Receive_packet_out(args []*ic.Argument) (*empty.Empty, error) {
121 return new(empty.Empty), nil
122}
123
124func (rhp *RequestHandlerProxy) Suppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
125 return new(empty.Empty), nil
126}
127
128func (rhp *RequestHandlerProxy) Unsuppress_alarm(args []*ic.Argument) (*empty.Empty, error) {
129 return new(empty.Empty), nil
130}
131
132func (rhp *RequestHandlerProxy) Get_ofp_device_info(args []*ic.Argument) (*ic.SwitchCapability, error) {
133 if len(args) != 1 {
134 log.Warn("invalid-number-of-args", log.Fields{"args": args})
135 err := errors.New("invalid-number-of-args")
136 return nil, err
137 }
138 device := &voltha.Device{}
139 if err := ptypes.UnmarshalAny(args[0].Value, device); err != nil {
140 log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err})
141 return nil, err
142 }
143 log.Debugw("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
144
145 var cap *ic.SwitchCapability
146 var err error
147 if cap, err = rhp.adapter.Get_ofp_device_info(device); err != nil {
148 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
149 }
150 return cap, nil
151}
152
153func (rhp *RequestHandlerProxy) Get_ofp_port_info(args []*ic.Argument) (*ic.PortCapability, error) {
154 if len(args) != 2 {
155 log.Warn("invalid-number-of-args", log.Fields{"args": args})
156 err := errors.New("invalid-number-of-args")
157 return nil, err
158 }
159 device := &voltha.Device{}
160 pNo := &ic.IntType{}
161 for _, arg := range args {
162 switch arg.Key {
163 case "device":
164 if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
165 log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
166 return nil, err
167 }
168 case "port_no":
169 if err := ptypes.UnmarshalAny(arg.Value, pNo); err != nil {
170 log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err})
171 return nil, err
172 }
173 }
174 }
175 log.Debugw("Get_ofp_port_info", log.Fields{"deviceId": device.Id, "portNo": pNo.Val})
176 var cap *ic.PortCapability
177 var err error
178 if cap, err = rhp.adapter.Get_ofp_port_info(device, pNo.Val); err != nil {
179 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
180 }
181 return cap, nil
182}
183
184func (rhp *RequestHandlerProxy) Process_inter_adapter_message(args []*ic.Argument) (*empty.Empty, error) {
185 if len(args) != 1 {
186 log.Warn("invalid-number-of-args", log.Fields{"args": args})
187 err := errors.New("invalid-number-of-args")
188 return nil, err
189 }
190 iaMsg := &ic.InterAdapterMessage{}
191 if err := ptypes.UnmarshalAny(args[0].Value, iaMsg); err != nil {
192 log.Warnw("cannot-unmarshal-message", log.Fields{"error": err})
193 return nil, err
194 }
195
196 log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": iaMsg.Header.Id})
197
198 //Invoke the inter adapter API on the handler
199 if err := rhp.adapter.Process_inter_adapter_message(iaMsg); err != nil {
200 return nil, status.Errorf(codes.NotFound, "%s", err.Error())
201 }
202
203 return new(empty.Empty), nil
204}
205
khenaidoof5a5bfa2019-01-23 22:20:29 -0500206func (rhp *RequestHandlerProxy) Download_image(args []*ic.Argument) (*voltha.ImageDownload, error) {
207 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500208}
209
khenaidoof5a5bfa2019-01-23 22:20:29 -0500210func (rhp *RequestHandlerProxy) Get_image_download_status(args []*ic.Argument) (*voltha.ImageDownload, error) {
211 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500212}
213
khenaidoof5a5bfa2019-01-23 22:20:29 -0500214func (rhp *RequestHandlerProxy) Cancel_image_download(args []*ic.Argument) (*voltha.ImageDownload, error) {
215 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500216}
217
khenaidoof5a5bfa2019-01-23 22:20:29 -0500218func (rhp *RequestHandlerProxy) Activate_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
219 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500220}
221
khenaidoof5a5bfa2019-01-23 22:20:29 -0500222func (rhp *RequestHandlerProxy) Revert_image_update(args []*ic.Argument) (*voltha.ImageDownload, error) {
223 return &voltha.ImageDownload{}, nil
khenaidood2b6df92018-12-13 16:37:20 -0500224}