blob: 63474efb5121ea16a0efd0ad138d985ad1890508 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001/*
2 * Copyright 2019-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 */
npujar1d86a522019-11-14 17:11:16 +053016
khenaidooab1f7bd2019-11-14 14:00:27 -050017package mocks
18
19import (
npujar1d86a522019-11-14 17:11:16 +053020 "strconv"
21 "strings"
22 "sync"
23
serkant.uluderya2ae470f2020-01-21 11:13:09 -080024 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
25 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
26 of "github.com/opencord/voltha-protos/v3/go/openflow_13"
27 "github.com/opencord/voltha-protos/v3/go/voltha"
khenaidooab1f7bd2019-11-14 14:00:27 -050028 "google.golang.org/grpc/codes"
29 "google.golang.org/grpc/status"
khenaidooab1f7bd2019-11-14 14:00:27 -050030)
31
32func macAddressToUint32Array(mac string) []uint32 {
33 slist := strings.Split(mac, ":")
34 result := make([]uint32, len(slist))
35 var err error
36 var tmp int64
37 for index, val := range slist {
38 if tmp, err = strconv.ParseInt(val, 16, 32); err != nil {
39 return []uint32{1, 2, 3, 4, 5, 6}
40 }
41 result[index] = uint32(tmp)
42 }
43 return result
44}
45
npujar1d86a522019-11-14 17:11:16 +053046// Adapter represents adapter attributes
khenaidooab1f7bd2019-11-14 14:00:27 -050047type Adapter struct {
48 coreProxy adapterif.CoreProxy
49 devices sync.Map
50}
51
npujar1d86a522019-11-14 17:11:16 +053052// NewAdapter creates adapter instance
khenaidooab1f7bd2019-11-14 14:00:27 -050053func NewAdapter(cp adapterif.CoreProxy) *Adapter {
54 return &Adapter{
55 coreProxy: cp,
56 }
57}
58
59func (ta *Adapter) storeDevice(d *voltha.Device) {
60 if d != nil {
61 ta.devices.Store(d.Id, d)
62 }
63}
64
khenaidooab1f7bd2019-11-14 14:00:27 -050065func (ta *Adapter) getDevice(id string) *voltha.Device {
66 if val, ok := ta.devices.Load(id); ok && val != nil {
67 if device, ok := val.(*voltha.Device); ok {
68 return device
69 }
70 }
71 return nil
72}
73
74func (ta *Adapter) updateDevice(d *voltha.Device) error {
75 if d != nil {
76 if _, ok := ta.devices.LoadOrStore(d.Id, d); !ok {
77 return status.Errorf(codes.Internal, "error updating device %s", d.Id)
78 }
79 }
80 return nil
81}
82
npujar1d86a522019-11-14 17:11:16 +053083// Adapter_descriptor -
84func (ta *Adapter) Adapter_descriptor() error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -050085 return nil
86}
npujar1d86a522019-11-14 17:11:16 +053087
88// Device_types -
89func (ta *Adapter) Device_types() (*voltha.DeviceTypes, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -050090 return nil, nil
91}
npujar1d86a522019-11-14 17:11:16 +053092
93// Health -
khenaidooab1f7bd2019-11-14 14:00:27 -050094func (ta *Adapter) Health() (*voltha.HealthStatus, error) {
95 return nil, nil
96}
npujar1d86a522019-11-14 17:11:16 +053097
98// Adopt_device -
99func (ta *Adapter) Adopt_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500100 return nil
101}
102
npujar1d86a522019-11-14 17:11:16 +0530103// Reconcile_device -
104func (ta *Adapter) Reconcile_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500105 return nil
106}
107
npujar1d86a522019-11-14 17:11:16 +0530108// Abandon_device -
109func (ta *Adapter) Abandon_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500110 return nil
111}
112
npujar1d86a522019-11-14 17:11:16 +0530113// Disable_device -
114func (ta *Adapter) Disable_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500115 return nil
116}
117
npujar1d86a522019-11-14 17:11:16 +0530118// Reenable_device -
119func (ta *Adapter) Reenable_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500120 return nil
121}
122
npujar1d86a522019-11-14 17:11:16 +0530123// Reboot_device -
124func (ta *Adapter) Reboot_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500125 return nil
126}
127
npujar1d86a522019-11-14 17:11:16 +0530128// Self_test_device -
129func (ta *Adapter) Self_test_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500130 return nil
131}
132
npujar1d86a522019-11-14 17:11:16 +0530133// Delete_device -
134func (ta *Adapter) Delete_device(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500135 return nil
136}
137
npujar1d86a522019-11-14 17:11:16 +0530138// Get_device_details -
139func (ta *Adapter) Get_device_details(device *voltha.Device) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500140 return nil
141}
142
npujar1d86a522019-11-14 17:11:16 +0530143// Update_flows_bulk -
144func (ta *Adapter) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500145 return nil
146}
147
npujar1d86a522019-11-14 17:11:16 +0530148// Update_flows_incrementally -
149func (ta *Adapter) Update_flows_incrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500150 return nil
151}
152
npujar1d86a522019-11-14 17:11:16 +0530153// Update_pm_config -
154func (ta *Adapter) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500155 return nil
156}
157
npujar1d86a522019-11-14 17:11:16 +0530158// Receive_packet_out -
159func (ta *Adapter) Receive_packet_out(deviceID string, egressPortNo int, msg *of.OfpPacketOut) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500160 return nil
161}
162
Devmalya Paulc594bb32019-11-06 07:34:27 +0000163// Suppress_event -
164func (ta *Adapter) Suppress_event(filter *voltha.EventFilter) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500165 return nil
166}
167
Devmalya Paulc594bb32019-11-06 07:34:27 +0000168// Unsuppress_event -
169func (ta *Adapter) Unsuppress_event(filter *voltha.EventFilter) error { // nolint
npujar1d86a522019-11-14 17:11:16 +0530170 return nil
171}
172
173// Get_ofp_device_info -
174func (ta *Adapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500175 return &ic.SwitchCapability{
176 Desc: &of.OfpDesc{
177 HwDesc: "adapter_mock",
178 SwDesc: "adapter_mock",
179 SerialNum: "000000000",
180 },
181 SwitchFeatures: &of.OfpSwitchFeatures{
182 NBuffers: 256,
183 NTables: 2,
184 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
185 of.OfpCapabilities_OFPC_TABLE_STATS |
186 of.OfpCapabilities_OFPC_PORT_STATS |
187 of.OfpCapabilities_OFPC_GROUP_STATS),
188 },
189 }, nil
190}
191
npujar1d86a522019-11-14 17:11:16 +0530192// Get_ofp_port_info -
193func (ta *Adapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500194 capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
195 return &ic.PortCapability{
196 Port: &voltha.LogicalPort{
197 OfpPort: &of.OfpPort{
198 HwAddr: macAddressToUint32Array("11:11:33:44:55:66"),
199 Config: 0,
200 State: uint32(of.OfpPortState_OFPPS_LIVE),
201 Curr: capability,
202 Advertised: capability,
203 Peer: capability,
204 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
205 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
206 },
207 DeviceId: device.Id,
npujar1d86a522019-11-14 17:11:16 +0530208 DevicePortNo: uint32(portNo),
khenaidooab1f7bd2019-11-14 14:00:27 -0500209 },
210 }, nil
211}
212
npujar1d86a522019-11-14 17:11:16 +0530213// Process_inter_adapter_message -
214func (ta *Adapter) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500215 return nil
216}
217
npujar1d86a522019-11-14 17:11:16 +0530218// Download_image -
219func (ta *Adapter) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500220 return nil, nil
221}
222
npujar1d86a522019-11-14 17:11:16 +0530223// Get_image_download_status -
224func (ta *Adapter) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500225 return nil, nil
226}
227
npujar1d86a522019-11-14 17:11:16 +0530228// Cancel_image_download -
229func (ta *Adapter) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500230 return nil, nil
231}
232
npujar1d86a522019-11-14 17:11:16 +0530233// Activate_image_update -
234func (ta *Adapter) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500235 return nil, nil
236}
237
npujar1d86a522019-11-14 17:11:16 +0530238// Revert_image_update -
239func (ta *Adapter) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500240 return nil, nil
241}
kesavandbc2d1622020-01-21 00:42:01 -0500242
243// Enable_port -
244func (ta *Adapter) Enable_port(deviceId string, port *voltha.Port) error { //nolint
245 return nil
246}
247
248// Disable_port -
249func (ta *Adapter) Disable_port(deviceId string, port *voltha.Port) error { //nolint
250 return nil
251}
Scott Baker0e78ba22020-02-24 17:58:47 -0800252
253// Child_device_lost -
254func (ta *Adapter) Child_device_lost(pDeviceID string, pPortNo uint32, onuID uint32) error { //nolint
255 return nil
256}