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 ( |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 20 | "context" |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 21 | "fmt" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 22 | "strconv" |
| 23 | "strings" |
| 24 | "sync" |
| 25 | |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 26 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 27 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 28 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 29 | "github.com/opencord/voltha-protos/v3/go/voltha" |
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 { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 48 | coreProxy adapterif.CoreProxy |
| 49 | flows map[uint64]*voltha.OfpFlowStats |
| 50 | flowLock sync.RWMutex |
| 51 | devices map[string]*voltha.Device |
| 52 | deviceLock sync.RWMutex |
| 53 | failFlowAdd bool |
| 54 | failFlowDelete bool |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 55 | } |
| 56 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 57 | // NewAdapter creates adapter instance |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 58 | func NewAdapter(cp adapterif.CoreProxy) *Adapter { |
| 59 | return &Adapter{ |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 60 | flows: map[uint64]*voltha.OfpFlowStats{}, |
| 61 | devices: map[string]*voltha.Device{}, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 62 | coreProxy: cp, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func (ta *Adapter) storeDevice(d *voltha.Device) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 67 | ta.deviceLock.Lock() |
| 68 | defer ta.deviceLock.Unlock() |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 69 | if d != nil { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 70 | ta.devices[d.Id] = d |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 74 | func (ta *Adapter) getDevice(id string) *voltha.Device { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 75 | ta.deviceLock.RLock() |
| 76 | defer ta.deviceLock.RUnlock() |
| 77 | return ta.devices[id] |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 78 | } |
| 79 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 80 | func (ta *Adapter) updateDevice(d *voltha.Device) { |
| 81 | ta.storeDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 82 | } |
| 83 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 84 | // Adapter_descriptor - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 85 | func (ta *Adapter) Adapter_descriptor(ctx context.Context) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 86 | return nil |
| 87 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 88 | |
| 89 | // Device_types - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 90 | func (ta *Adapter) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 91 | return nil, nil |
| 92 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 93 | |
| 94 | // Health - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 95 | func (ta *Adapter) Health(ctx context.Context) (*voltha.HealthStatus, error) { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 96 | return nil, nil |
| 97 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 98 | |
| 99 | // Adopt_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 100 | func (ta *Adapter) Adopt_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 101 | return nil |
| 102 | } |
| 103 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 104 | // Reconcile_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 105 | func (ta *Adapter) Reconcile_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 106 | return nil |
| 107 | } |
| 108 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 109 | // Abandon_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 110 | func (ta *Adapter) Abandon_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 111 | return nil |
| 112 | } |
| 113 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 114 | // Disable_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 115 | func (ta *Adapter) Disable_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 116 | return nil |
| 117 | } |
| 118 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 119 | // Reenable_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 120 | func (ta *Adapter) Reenable_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 121 | return nil |
| 122 | } |
| 123 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 124 | // Reboot_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 125 | func (ta *Adapter) Reboot_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 126 | return nil |
| 127 | } |
| 128 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 129 | // Self_test_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 130 | func (ta *Adapter) Self_test_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 131 | return nil |
| 132 | } |
| 133 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 134 | // Delete_device - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 135 | func (ta *Adapter) Delete_device(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 136 | return nil |
| 137 | } |
| 138 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 139 | // Get_device_details - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 140 | func (ta *Adapter) Get_device_details(ctx context.Context, device *voltha.Device) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 141 | return nil |
| 142 | } |
| 143 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 144 | // Update_flows_bulk - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 145 | func (ta *Adapter) Update_flows_bulk(ctx context.Context, 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] | 146 | return nil |
| 147 | } |
| 148 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 149 | // Update_flows_incrementally mocks the incremental flow update |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 150 | func (ta *Adapter) Update_flows_incrementally(ctx context.Context, device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 151 | ta.flowLock.Lock() |
| 152 | defer ta.flowLock.Unlock() |
| 153 | |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 154 | if flows.ToAdd != nil && len(flows.ToAdd.Items) > 0 { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 155 | if ta.failFlowAdd { |
| 156 | return fmt.Errorf("flow-add-error") |
| 157 | } |
| 158 | for _, f := range flows.ToAdd.Items { |
| 159 | ta.flows[f.Id] = f |
| 160 | } |
| 161 | } |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 162 | if flows.ToRemove != nil && len(flows.ToRemove.Items) > 0 { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 163 | if ta.failFlowDelete { |
| 164 | return fmt.Errorf("flow-delete-error") |
| 165 | } |
| 166 | for _, f := range flows.ToRemove.Items { |
| 167 | delete(ta.flows, f.Id) |
| 168 | } |
| 169 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 170 | return nil |
| 171 | } |
| 172 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 173 | // Update_pm_config - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 174 | func (ta *Adapter) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 175 | return nil |
| 176 | } |
| 177 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 178 | // Receive_packet_out - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 179 | func (ta *Adapter) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, msg *of.OfpPacketOut) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 180 | return nil |
| 181 | } |
| 182 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 183 | // Suppress_event - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 184 | func (ta *Adapter) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 185 | return nil |
| 186 | } |
| 187 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 188 | // Unsuppress_event - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 189 | func (ta *Adapter) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error { // nolint |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 190 | return nil |
| 191 | } |
| 192 | |
| 193 | // Get_ofp_device_info - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 194 | func (ta *Adapter) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 195 | return &ic.SwitchCapability{ |
| 196 | Desc: &of.OfpDesc{ |
| 197 | HwDesc: "adapter_mock", |
| 198 | SwDesc: "adapter_mock", |
| 199 | SerialNum: "000000000", |
| 200 | }, |
| 201 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 202 | NBuffers: 256, |
| 203 | NTables: 2, |
| 204 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 205 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 206 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 207 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 208 | }, |
| 209 | }, nil |
| 210 | } |
| 211 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 212 | // Process_inter_adapter_message - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 213 | func (ta *Adapter) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 214 | return nil |
| 215 | } |
| 216 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 217 | // Download_image - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 218 | func (ta *Adapter) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 219 | return nil, nil |
| 220 | } |
| 221 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 222 | // Get_image_download_status - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 223 | func (ta *Adapter) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 224 | return nil, nil |
| 225 | } |
| 226 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 227 | // Cancel_image_download - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 228 | func (ta *Adapter) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 229 | return nil, nil |
| 230 | } |
| 231 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 232 | // Activate_image_update - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 233 | func (ta *Adapter) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 234 | return nil, nil |
| 235 | } |
| 236 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 237 | // Revert_image_update - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 238 | func (ta *Adapter) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 239 | return nil, nil |
| 240 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 241 | |
| 242 | // Enable_port - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 243 | func (ta *Adapter) Enable_port(ctx context.Context, deviceId string, port *voltha.Port) error { //nolint |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 244 | return nil |
| 245 | } |
| 246 | |
| 247 | // Disable_port - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 248 | func (ta *Adapter) Disable_port(ctx context.Context, deviceId string, port *voltha.Port) error { //nolint |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 249 | return nil |
| 250 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 251 | |
| 252 | // Child_device_lost - |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 253 | func (ta *Adapter) Child_device_lost(ctx context.Context, pDeviceID string, pPortNo uint32, onuID uint32) error { //nolint |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 254 | return nil |
| 255 | } |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 256 | |
| 257 | // Start_omci_test |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 258 | func (ta *Adapter) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { //nolint |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 259 | return nil, nil |
| 260 | } |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 261 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 262 | func (ta *Adapter) Get_ext_value(ctx context.Context, deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { //nolint |
Dinesh Belwalkar | c1129f1 | 2020-02-27 10:41:33 -0800 | [diff] [blame] | 263 | return nil, nil |
| 264 | } |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 265 | |
| 266 | // GetFlowCount returns the total number of flows presently under this adapter |
| 267 | func (ta *Adapter) GetFlowCount() int { |
| 268 | ta.flowLock.RLock() |
| 269 | defer ta.flowLock.RUnlock() |
| 270 | |
| 271 | return len(ta.flows) |
| 272 | } |
| 273 | |
| 274 | // ClearFlows removes all flows in this adapter |
| 275 | func (ta *Adapter) ClearFlows() { |
| 276 | ta.flowLock.Lock() |
| 277 | defer ta.flowLock.Unlock() |
| 278 | |
| 279 | ta.flows = map[uint64]*voltha.OfpFlowStats{} |
| 280 | } |
| 281 | |
| 282 | // SetFlowAction sets the adapter action on addition and deletion of flows |
| 283 | func (ta *Adapter) SetFlowAction(failFlowAdd, failFlowDelete bool) { |
| 284 | ta.failFlowAdd = failFlowAdd |
| 285 | ta.failFlowDelete = failFlowDelete |
| 286 | } |