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