khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 17 | package mocks |
| 18 | |
| 19 | import ( |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 20 | "strconv" |
| 21 | "strings" |
| 22 | "sync" |
| 23 | |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 24 | "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" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | func 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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 46 | // Adapter represents adapter attributes |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 47 | type Adapter struct { |
| 48 | coreProxy adapterif.CoreProxy |
| 49 | devices sync.Map |
| 50 | } |
| 51 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 52 | // NewAdapter creates adapter instance |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 53 | func NewAdapter(cp adapterif.CoreProxy) *Adapter { |
| 54 | return &Adapter{ |
| 55 | coreProxy: cp, |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func (ta *Adapter) storeDevice(d *voltha.Device) { |
| 60 | if d != nil { |
| 61 | ta.devices.Store(d.Id, d) |
| 62 | } |
| 63 | } |
| 64 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 65 | func (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 | |
| 74 | func (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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 83 | // Adapter_descriptor - |
| 84 | func (ta *Adapter) Adapter_descriptor() error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 85 | return nil |
| 86 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 87 | |
| 88 | // Device_types - |
| 89 | func (ta *Adapter) Device_types() (*voltha.DeviceTypes, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 90 | return nil, nil |
| 91 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 92 | |
| 93 | // Health - |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 94 | func (ta *Adapter) Health() (*voltha.HealthStatus, error) { |
| 95 | return nil, nil |
| 96 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 97 | |
| 98 | // Adopt_device - |
| 99 | func (ta *Adapter) Adopt_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 100 | return nil |
| 101 | } |
| 102 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 103 | // Reconcile_device - |
| 104 | func (ta *Adapter) Reconcile_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 105 | return nil |
| 106 | } |
| 107 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 108 | // Abandon_device - |
| 109 | func (ta *Adapter) Abandon_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 110 | return nil |
| 111 | } |
| 112 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 113 | // Disable_device - |
| 114 | func (ta *Adapter) Disable_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 115 | return nil |
| 116 | } |
| 117 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 118 | // Reenable_device - |
| 119 | func (ta *Adapter) Reenable_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 120 | return nil |
| 121 | } |
| 122 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 123 | // Reboot_device - |
| 124 | func (ta *Adapter) Reboot_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 125 | return nil |
| 126 | } |
| 127 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 128 | // Self_test_device - |
| 129 | func (ta *Adapter) Self_test_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 130 | return nil |
| 131 | } |
| 132 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 133 | // Delete_device - |
| 134 | func (ta *Adapter) Delete_device(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 135 | return nil |
| 136 | } |
| 137 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 138 | // Get_device_details - |
| 139 | func (ta *Adapter) Get_device_details(device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 140 | return nil |
| 141 | } |
| 142 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 143 | // Update_flows_bulk - |
| 144 | func (ta *Adapter) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 145 | return nil |
| 146 | } |
| 147 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 148 | // Update_flows_incrementally - |
| 149 | func (ta *Adapter) Update_flows_incrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 150 | return nil |
| 151 | } |
| 152 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 153 | // Update_pm_config - |
| 154 | func (ta *Adapter) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 155 | return nil |
| 156 | } |
| 157 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 158 | // Receive_packet_out - |
| 159 | func (ta *Adapter) Receive_packet_out(deviceID string, egressPortNo int, msg *of.OfpPacketOut) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 160 | return nil |
| 161 | } |
| 162 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 163 | // Suppress_event - |
| 164 | func (ta *Adapter) Suppress_event(filter *voltha.EventFilter) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 165 | return nil |
| 166 | } |
| 167 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 168 | // Unsuppress_event - |
| 169 | func (ta *Adapter) Unsuppress_event(filter *voltha.EventFilter) error { // nolint |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // Get_ofp_device_info - |
| 174 | func (ta *Adapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 175 | 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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 192 | // Get_ofp_port_info - |
| 193 | func (ta *Adapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 194 | 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, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 208 | DevicePortNo: uint32(portNo), |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 209 | }, |
| 210 | }, nil |
| 211 | } |
| 212 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 213 | // Process_inter_adapter_message - |
| 214 | func (ta *Adapter) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 215 | return nil |
| 216 | } |
| 217 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 218 | // Download_image - |
| 219 | func (ta *Adapter) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 220 | return nil, nil |
| 221 | } |
| 222 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 223 | // Get_image_download_status - |
| 224 | func (ta *Adapter) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 225 | return nil, nil |
| 226 | } |
| 227 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 228 | // Cancel_image_download - |
| 229 | func (ta *Adapter) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 230 | return nil, nil |
| 231 | } |
| 232 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 233 | // Activate_image_update - |
| 234 | func (ta *Adapter) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 235 | return nil, nil |
| 236 | } |
| 237 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 238 | // Revert_image_update - |
| 239 | func (ta *Adapter) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 240 | return nil, nil |
| 241 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 242 | |
| 243 | // Enable_port - |
| 244 | func (ta *Adapter) Enable_port(deviceId string, port *voltha.Port) error { //nolint |
| 245 | return nil |
| 246 | } |
| 247 | |
| 248 | // Disable_port - |
| 249 | func (ta *Adapter) Disable_port(deviceId string, port *voltha.Port) error { //nolint |
| 250 | return nil |
| 251 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 252 | |
| 253 | // Child_device_lost - |
| 254 | func (ta *Adapter) Child_device_lost(pDeviceID string, pPortNo uint32, onuID uint32) error { //nolint |
| 255 | return nil |
| 256 | } |