blob: a510e58af5f4bd9c7954e3a25e69d940ca1787b5 [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 */
16package mocks
17
18import (
19 "github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif"
20 ic "github.com/opencord/voltha-protos/v2/go/inter_container"
21 of "github.com/opencord/voltha-protos/v2/go/openflow_13"
22 "github.com/opencord/voltha-protos/v2/go/voltha"
23 "google.golang.org/grpc/codes"
24 "google.golang.org/grpc/status"
25 "strconv"
26 "strings"
27 "sync"
28)
29
30func macAddressToUint32Array(mac string) []uint32 {
31 slist := strings.Split(mac, ":")
32 result := make([]uint32, len(slist))
33 var err error
34 var tmp int64
35 for index, val := range slist {
36 if tmp, err = strconv.ParseInt(val, 16, 32); err != nil {
37 return []uint32{1, 2, 3, 4, 5, 6}
38 }
39 result[index] = uint32(tmp)
40 }
41 return result
42}
43
44type Adapter struct {
45 coreProxy adapterif.CoreProxy
46 devices sync.Map
47}
48
49func NewAdapter(cp adapterif.CoreProxy) *Adapter {
50 return &Adapter{
51 coreProxy: cp,
52 }
53}
54
55func (ta *Adapter) storeDevice(d *voltha.Device) {
56 if d != nil {
57 ta.devices.Store(d.Id, d)
58 }
59}
60
61func (ta *Adapter) deleteDevice(id string) {
62 ta.devices.Delete(id)
63}
64
65func (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
83func (ta *Adapter) Adapter_descriptor() error {
84 return nil
85}
86func (ta *Adapter) Device_types() (*voltha.DeviceTypes, error) {
87 return nil, nil
88}
89func (ta *Adapter) Health() (*voltha.HealthStatus, error) {
90 return nil, nil
91}
92func (ta *Adapter) Adopt_device(device *voltha.Device) error {
93 return nil
94}
95
96func (ta *Adapter) Reconcile_device(device *voltha.Device) error {
97 return nil
98}
99
100func (ta *Adapter) Abandon_device(device *voltha.Device) error {
101 return nil
102}
103
104func (ta *Adapter) Disable_device(device *voltha.Device) error {
105 return nil
106}
107
108func (ta *Adapter) Reenable_device(device *voltha.Device) error {
109 return nil
110}
111
112func (ta *Adapter) Reboot_device(device *voltha.Device) error {
113 return nil
114}
115
116func (ta *Adapter) Self_test_device(device *voltha.Device) error {
117 return nil
118}
119
120func (ta *Adapter) Delete_device(device *voltha.Device) error {
121 return nil
122}
123
124func (ta *Adapter) Get_device_details(device *voltha.Device) error {
125 return nil
126}
127
128func (ta *Adapter) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
129 return nil
130}
131
132func (ta *Adapter) Update_flows_incrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
133 return nil
134}
135func (ta *Adapter) Update_pm_config(device *voltha.Device, pm_configs *voltha.PmConfigs) error {
136 return nil
137}
138
139func (ta *Adapter) Receive_packet_out(deviceId string, egress_port_no int, msg *of.OfpPacketOut) error {
140 return nil
141}
142
143func (ta *Adapter) Suppress_alarm(filter *voltha.AlarmFilter) error {
144 return nil
145}
146
147func (ta *Adapter) Unsuppress_alarm(filter *voltha.AlarmFilter) error {
148 return nil
149}
150
151func (ta *Adapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
152 return &ic.SwitchCapability{
153 Desc: &of.OfpDesc{
154 HwDesc: "adapter_mock",
155 SwDesc: "adapter_mock",
156 SerialNum: "000000000",
157 },
158 SwitchFeatures: &of.OfpSwitchFeatures{
159 NBuffers: 256,
160 NTables: 2,
161 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
162 of.OfpCapabilities_OFPC_TABLE_STATS |
163 of.OfpCapabilities_OFPC_PORT_STATS |
164 of.OfpCapabilities_OFPC_GROUP_STATS),
165 },
166 }, nil
167}
168
169func (ta *Adapter) Get_ofp_port_info(device *voltha.Device, port_no int64) (*ic.PortCapability, error) {
170 capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
171 return &ic.PortCapability{
172 Port: &voltha.LogicalPort{
173 OfpPort: &of.OfpPort{
174 HwAddr: macAddressToUint32Array("11:11:33:44:55:66"),
175 Config: 0,
176 State: uint32(of.OfpPortState_OFPPS_LIVE),
177 Curr: capability,
178 Advertised: capability,
179 Peer: capability,
180 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
181 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
182 },
183 DeviceId: device.Id,
184 DevicePortNo: uint32(port_no),
185 },
186 }, nil
187}
188
189func (ta *Adapter) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
190 return nil
191}
192
193func (ta *Adapter) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
194 return nil, nil
195}
196
197func (ta *Adapter) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
198 return nil, nil
199}
200
201func (ta *Adapter) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
202 return nil, nil
203}
204
205func (ta *Adapter) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
206 return nil, nil
207}
208
209func (ta *Adapter) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
210 return nil, nil
211}