blob: 5a9130e82941065c855c658731f050bbfaf3eb82 [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 (
Rohan Agrawal31f21802020-06-12 05:38:46 +000020 "context"
khenaidoo8b4abbf2020-04-24 17:04:30 -040021 "fmt"
npujar1d86a522019-11-14 17:11:16 +053022 "strconv"
23 "strings"
24 "sync"
khenaidood948f772021-08-11 17:49:24 -040025 "time"
npujar1d86a522019-11-14 17:11:16 +053026
khenaidood948f772021-08-11 17:49:24 -040027 "github.com/golang/protobuf/ptypes/empty"
28 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
29 "github.com/opencord/voltha-lib-go/v7/pkg/log"
30 "github.com/opencord/voltha-lib-go/v7/pkg/probe"
khenaidoo9beaaf12021-10-19 17:32:01 -040031 "github.com/opencord/voltha-protos/v5/go/adapter_service"
khenaidood948f772021-08-11 17:49:24 -040032 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo9beaaf12021-10-19 17:32:01 -040033 "github.com/opencord/voltha-protos/v5/go/core_service"
34 "github.com/opencord/voltha-protos/v5/go/health"
khenaidood948f772021-08-11 17:49:24 -040035 "google.golang.org/grpc"
36
khenaidoo9beaaf12021-10-19 17:32:01 -040037 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidood948f772021-08-11 17:49:24 -040038 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo9beaaf12021-10-19 17:32:01 -040039 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidood948f772021-08-11 17:49:24 -040040 "github.com/opencord/voltha-protos/v5/go/openflow_13"
41 "github.com/opencord/voltha-protos/v5/go/voltha"
42)
43
44const (
45 numONUPerOLT = 4
46 startingUNIPortNo = 100
khenaidooab1f7bd2019-11-14 14:00:27 -050047)
48
49func macAddressToUint32Array(mac string) []uint32 {
50 slist := strings.Split(mac, ":")
51 result := make([]uint32, len(slist))
52 var err error
53 var tmp int64
54 for index, val := range slist {
55 if tmp, err = strconv.ParseInt(val, 16, 32); err != nil {
56 return []uint32{1, 2, 3, 4, 5, 6}
57 }
58 result[index] = uint32(tmp)
59 }
60 return result
61}
62
khenaidood948f772021-08-11 17:49:24 -040063// GetNumONUPerOLT returns number of ONUs per OLT
64func GetNumONUPerOLT() int {
65 return numONUPerOLT
66}
67
68// Returns the starting UNI port number
69func GetStartingUNIPortNo() int {
70 return startingUNIPortNo
71}
72
npujar1d86a522019-11-14 17:11:16 +053073// Adapter represents adapter attributes
khenaidooab1f7bd2019-11-14 14:00:27 -050074type Adapter struct {
khenaidood948f772021-08-11 17:49:24 -040075 flows map[string]map[uint64]*openflow_13.OfpFlowStats
76 flowLock sync.RWMutex
77 devices map[string]*voltha.Device
78 deviceLock sync.RWMutex
79 failFlowAdd map[string]bool
80 failFlowAddLock sync.RWMutex
81 failFlowDelete map[string]bool
82 failFlowDeleteLock sync.RWMutex
83 failDeleteDevice map[string]bool
84 failDeleteDeviceLock sync.RWMutex
85 coreEnpoint string
86 coreClient *vgrpc.Client
87 serviceEndpoint string
88 DeviceType string
89 vendor string
90 Probe *probe.Probe
khenaidooab1f7bd2019-11-14 14:00:27 -050091}
92
npujar1d86a522019-11-14 17:11:16 +053093// NewAdapter creates adapter instance
khenaidood948f772021-08-11 17:49:24 -040094func NewAdapter(serviceEndpoint, coreEndpoint, deviceType, vendor string) *Adapter {
khenaidooab1f7bd2019-11-14 14:00:27 -050095 return &Adapter{
khenaidood948f772021-08-11 17:49:24 -040096 flows: map[string]map[uint64]*openflow_13.OfpFlowStats{},
97 devices: map[string]*voltha.Device{},
98 failFlowAdd: map[string]bool{},
99 failFlowDelete: map[string]bool{},
100 failDeleteDevice: map[string]bool{},
101 coreEnpoint: coreEndpoint,
102 serviceEndpoint: serviceEndpoint,
103 DeviceType: deviceType,
104 vendor: vendor,
khenaidooab1f7bd2019-11-14 14:00:27 -0500105 }
106}
107
khenaidood948f772021-08-11 17:49:24 -0400108func (ta *Adapter) IsReady() bool {
109 return ta.Probe.IsReady()
110}
111
khenaidooab1f7bd2019-11-14 14:00:27 -0500112func (ta *Adapter) storeDevice(d *voltha.Device) {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400113 ta.deviceLock.Lock()
114 defer ta.deviceLock.Unlock()
khenaidooab1f7bd2019-11-14 14:00:27 -0500115 if d != nil {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400116 ta.devices[d.Id] = d
khenaidooab1f7bd2019-11-14 14:00:27 -0500117 }
118}
119
khenaidooab1f7bd2019-11-14 14:00:27 -0500120func (ta *Adapter) getDevice(id string) *voltha.Device {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400121 ta.deviceLock.RLock()
122 defer ta.deviceLock.RUnlock()
123 return ta.devices[id]
khenaidooab1f7bd2019-11-14 14:00:27 -0500124}
125
khenaidoo8b4abbf2020-04-24 17:04:30 -0400126func (ta *Adapter) updateDevice(d *voltha.Device) {
127 ta.storeDevice(d)
khenaidooab1f7bd2019-11-14 14:00:27 -0500128}
129
khenaidood948f772021-08-11 17:49:24 -0400130func (ta *Adapter) GetEndPoint() string {
131 return ta.serviceEndpoint
khenaidooab1f7bd2019-11-14 14:00:27 -0500132}
npujar1d86a522019-11-14 17:11:16 +0530133
khenaidoo9beaaf12021-10-19 17:32:01 -0400134func (ta *Adapter) GetCoreClient() (core_service.CoreServiceClient, error) {
khenaidood948f772021-08-11 17:49:24 -0400135 // Wait until the Core is up and running
136 for {
137 if ta.coreClient != nil {
138 client, err := ta.coreClient.GetClient()
139 if err != nil {
140 logger.Infow(context.Background(), "got-error-core-client", log.Fields{"error": err})
141 time.Sleep(1 * time.Second)
142 continue
143 }
khenaidoo9beaaf12021-10-19 17:32:01 -0400144 c, ok := client.(core_service.CoreServiceClient)
khenaidood948f772021-08-11 17:49:24 -0400145 if ok {
146 logger.Debug(context.Background(), "got-valid-client")
147 return c, nil
148 }
149 }
150 logger.Info(context.Background(), "waiting-for-grpc-core-client")
151 time.Sleep(1 * time.Second)
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530152 }
khenaidooab1f7bd2019-11-14 14:00:27 -0500153}
154
khenaidood948f772021-08-11 17:49:24 -0400155// Helper methods
156// startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server
khenaidoo9beaaf12021-10-19 17:32:01 -0400157func (ta *Adapter) startGRPCService(ctx context.Context, server *vgrpc.GrpcServer, handler adapter_service.AdapterServiceServer, serviceName string) {
khenaidood948f772021-08-11 17:49:24 -0400158 logger.Infow(ctx, "service-created", log.Fields{"service": serviceName})
159
khenaidoo9beaaf12021-10-19 17:32:01 -0400160 server.AddService(func(gs *grpc.Server) { adapter_service.RegisterAdapterServiceServer(gs, handler) })
khenaidood948f772021-08-11 17:49:24 -0400161 logger.Infow(ctx, "service-added", log.Fields{"service": serviceName})
162
163 ta.Probe.UpdateStatus(ctx, serviceName, probe.ServiceStatusRunning)
164 logger.Infow(ctx, "service-started", log.Fields{"service": serviceName})
165
166 // Note that there is a small window here in which the core could return its status as ready,
167 // when it really isn't. This is unlikely to cause issues, as the delay is incredibly short.
168 server.Start(ctx)
169 ta.Probe.UpdateStatus(ctx, serviceName, probe.ServiceStatusStopped)
khenaidooab1f7bd2019-11-14 14:00:27 -0500170}
171
khenaidooa46458b2021-12-15 16:50:44 -0500172func setCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
173 if conn == nil {
khenaidood948f772021-08-11 17:49:24 -0400174 return nil
175 }
khenaidooa46458b2021-12-15 16:50:44 -0500176 return core_service.NewCoreServiceClient(conn)
khenaidooab1f7bd2019-11-14 14:00:27 -0500177}
178
khenaidood948f772021-08-11 17:49:24 -0400179// gRPC service
khenaidoo25057da2021-12-08 14:40:45 -0500180func (ta *Adapter) GetHealthStatus(ctx context.Context, clientConn *common.Connection) (*health.HealthStatus, error) {
khenaidoo9beaaf12021-10-19 17:32:01 -0400181 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
khenaidood948f772021-08-11 17:49:24 -0400182}
183
184// Device
185
186func (ta *Adapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
187 return &empty.Empty{}, nil
188}
189
190func (ta *Adapter) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
191 return &empty.Empty{}, nil
192}
193
194func (ta *Adapter) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
195 ta.failDeleteDeviceLock.RLock()
196 haveToFail, ok := ta.failDeleteDevice[device.Id]
197 if ok && haveToFail {
198 ta.failDeleteDeviceLock.RUnlock()
199 return nil, fmt.Errorf("delete-device-failure")
200 }
201 ta.failDeleteDeviceLock.RUnlock()
202 if ok {
203 ta.RemoveDevice(device.Id)
204 }
205 logger.Debugw(ctx, "device-deleted-in-adapter", log.Fields{"device-id": device.Id})
206 return &empty.Empty{}, nil
207}
208
209func (ta *Adapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
210 return &empty.Empty{}, nil
211}
212
213func (ta *Adapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
214 return &empty.Empty{}, nil
215}
216
217func (ta *Adapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
218 return &empty.Empty{}, nil
219}
220
221func (ta *Adapter) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
222 return &empty.Empty{}, nil
223}
224
225func (ta *Adapter) ChildDeviceLost(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
226 return &empty.Empty{}, nil
227}
228
khenaidoo9beaaf12021-10-19 17:32:01 -0400229func (ta *Adapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidood948f772021-08-11 17:49:24 -0400230 return nil, nil
231}
232
233// Ports
234
235func (ta *Adapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
236 return &empty.Empty{}, nil
237}
238
239func (ta *Adapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
240 return &empty.Empty{}, nil
241}
242
243// Flows
khenaidoo9beaaf12021-10-19 17:32:01 -0400244func (ta *Adapter) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400245 return &empty.Empty{}, nil
246}
247
khenaidoo9beaaf12021-10-19 17:32:01 -0400248func (ta *Adapter) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400249 ta.flowLock.Lock()
250 defer ta.flowLock.Unlock()
251
khenaidood948f772021-08-11 17:49:24 -0400252 if _, ok := ta.flows[incrFlows.Device.Id]; !ok {
253 ta.flows[incrFlows.Device.Id] = map[uint64]*openflow_13.OfpFlowStats{}
254 }
255
256 if incrFlows.Flows.ToAdd != nil && len(incrFlows.Flows.ToAdd.Items) > 0 {
257 ta.failFlowAddLock.RLock()
258 if haveToFail, ok := ta.failFlowAdd[incrFlows.Device.Id]; ok && haveToFail {
259 ta.failFlowAddLock.RUnlock()
260 return nil, fmt.Errorf("flow-add-error")
khenaidoo8b4abbf2020-04-24 17:04:30 -0400261 }
khenaidood948f772021-08-11 17:49:24 -0400262 ta.failFlowAddLock.RUnlock()
263 for _, f := range incrFlows.Flows.ToAdd.Items {
264 ta.flows[incrFlows.Device.Id][f.Id] = f
khenaidoo8b4abbf2020-04-24 17:04:30 -0400265 }
266 }
khenaidood948f772021-08-11 17:49:24 -0400267 if incrFlows.Flows.ToRemove != nil && len(incrFlows.Flows.ToRemove.Items) > 0 {
268 ta.failFlowDeleteLock.RLock()
269 if haveToFail, ok := ta.failFlowDelete[incrFlows.Device.Id]; ok && haveToFail {
270 ta.failFlowDeleteLock.RUnlock()
271 return nil, fmt.Errorf("flow-delete-error")
khenaidoo8b4abbf2020-04-24 17:04:30 -0400272 }
khenaidood948f772021-08-11 17:49:24 -0400273 ta.failFlowDeleteLock.RUnlock()
274 for _, f := range incrFlows.Flows.ToRemove.Items {
275 delete(ta.flows[incrFlows.Device.Id], f.Id)
khenaidoo8b4abbf2020-04-24 17:04:30 -0400276 }
277 }
khenaidood948f772021-08-11 17:49:24 -0400278 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500279}
280
khenaidood948f772021-08-11 17:49:24 -0400281//Packets
khenaidoo9beaaf12021-10-19 17:32:01 -0400282func (ta *Adapter) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400283 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500284}
285
khenaidood948f772021-08-11 17:49:24 -0400286// PM
khenaidoo9beaaf12021-10-19 17:32:01 -0400287func (ta *Adapter) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400288 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500289}
290
khenaidood948f772021-08-11 17:49:24 -0400291// Image
292func (ta *Adapter) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
293 return &voltha.DeviceImageResponse{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500294}
295
khenaidood948f772021-08-11 17:49:24 -0400296func (ta *Adapter) GetOnuImageStatus(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
297 return &voltha.DeviceImageResponse{}, nil
npujar1d86a522019-11-14 17:11:16 +0530298}
299
khenaidood948f772021-08-11 17:49:24 -0400300func (ta *Adapter) AbortOnuImageUpgrade(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
301 return &voltha.DeviceImageResponse{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500302}
303
khenaidood948f772021-08-11 17:49:24 -0400304func (ta *Adapter) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
305 return &voltha.OnuImages{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500306}
307
khenaidood948f772021-08-11 17:49:24 -0400308func (ta *Adapter) ActivateOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
309 return &voltha.DeviceImageResponse{}, nil
310}
311
312func (ta *Adapter) CommitOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
313 return &voltha.DeviceImageResponse{}, nil
314}
315
316// Deprecated image APIs
khenaidoo9beaaf12021-10-19 17:32:01 -0400317func (ta *Adapter) DownloadImage(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400318 return &voltha.ImageDownload{}, nil
319}
320
khenaidoo9beaaf12021-10-19 17:32:01 -0400321func (ta *Adapter) GetImageDownloadStatus(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400322 return &voltha.ImageDownload{}, nil
323}
324
khenaidoo9beaaf12021-10-19 17:32:01 -0400325func (ta *Adapter) CancelImageDownload(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400326 return &voltha.ImageDownload{}, nil
327}
328
khenaidoo9beaaf12021-10-19 17:32:01 -0400329func (ta *Adapter) ActivateImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400330 return &voltha.ImageDownload{}, nil
331}
332
khenaidoo9beaaf12021-10-19 17:32:01 -0400333func (ta *Adapter) RevertImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400334 return &voltha.ImageDownload{}, nil
335}
336
337// OMCI test
khenaidoo9beaaf12021-10-19 17:32:01 -0400338func (ta *Adapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidooab1f7bd2019-11-14 14:00:27 -0500339 return nil, nil
340}
341
khenaidood948f772021-08-11 17:49:24 -0400342// Events
343func (ta *Adapter) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
344 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500345}
346
khenaidood948f772021-08-11 17:49:24 -0400347func (ta *Adapter) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
348 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500349}
350
khenaidoo9beaaf12021-10-19 17:32:01 -0400351func (ta *Adapter) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidood948f772021-08-11 17:49:24 -0400352 return &common.OperationResp{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500353}
354
khenaidoo9beaaf12021-10-19 17:32:01 -0400355func (ta *Adapter) GetExtValue(context.Context, *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
356 return &extension.ReturnValues{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500357}
kesavandbc2d1622020-01-21 00:42:01 -0500358
khenaidoo9beaaf12021-10-19 17:32:01 -0400359func (ta *Adapter) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400360 return &empty.Empty{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500361}
362
khenaidood948f772021-08-11 17:49:24 -0400363func (ta *Adapter) GetSingleValue(context.Context, *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
364 return &extension.SingleGetValueResponse{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500365}
Scott Baker0e78ba22020-02-24 17:58:47 -0800366
khenaidood948f772021-08-11 17:49:24 -0400367func (ta *Adapter) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
368 return &extension.SingleSetValueResponse{}, nil
Scott Baker0e78ba22020-02-24 17:58:47 -0800369}
Scott Baker432f9be2020-03-26 11:56:30 -0700370
khenaidood948f772021-08-11 17:49:24 -0400371// APIs for test ONLY
khenaidoo8b4abbf2020-04-24 17:04:30 -0400372// GetFlowCount returns the total number of flows presently under this adapter
khenaidood948f772021-08-11 17:49:24 -0400373func (ta *Adapter) GetFlowCount(deviceID string) int {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400374 ta.flowLock.RLock()
375 defer ta.flowLock.RUnlock()
376
khenaidood948f772021-08-11 17:49:24 -0400377 if _, ok := ta.flows[deviceID]; ok {
378 return len(ta.flows[deviceID])
379 }
380 return 0
khenaidoo8b4abbf2020-04-24 17:04:30 -0400381}
382
khenaidood948f772021-08-11 17:49:24 -0400383// RemoveDevice removes all flows in this adapter
384func (ta *Adapter) RemoveDevice(deviceID string) {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400385 ta.flowLock.Lock()
386 defer ta.flowLock.Unlock()
khenaidood948f772021-08-11 17:49:24 -0400387 ta.failFlowAddLock.Lock()
388 defer ta.failFlowAddLock.Unlock()
389 ta.failFlowDeleteLock.Lock()
390 defer ta.failFlowDeleteLock.Unlock()
khenaidoo8b4abbf2020-04-24 17:04:30 -0400391
khenaidood948f772021-08-11 17:49:24 -0400392 delete(ta.flows, deviceID)
393 delete(ta.failFlowAdd, deviceID)
394 delete(ta.failFlowDelete, deviceID)
khenaidoo8b4abbf2020-04-24 17:04:30 -0400395}
396
397// SetFlowAction sets the adapter action on addition and deletion of flows
khenaidood948f772021-08-11 17:49:24 -0400398func (ta *Adapter) SetFlowAction(deviceID string, failFlowAdd, failFlowDelete bool) {
399 ta.failFlowAddLock.Lock()
400 defer ta.failFlowAddLock.Unlock()
401 ta.failFlowDeleteLock.Lock()
402 defer ta.failFlowDeleteLock.Unlock()
403 ta.failFlowAdd[deviceID] = failFlowAdd
404 ta.failFlowDelete[deviceID] = failFlowDelete
khenaidoo8b4abbf2020-04-24 17:04:30 -0400405}
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530406
407// SetDeleteAction sets the adapter action on delete device
khenaidood948f772021-08-11 17:49:24 -0400408func (ta *Adapter) SetDeleteAction(deviceID string, failDeleteDevice bool) {
409 ta.failDeleteDeviceLock.Lock()
410 defer ta.failDeleteDeviceLock.Unlock()
411 ta.failDeleteDevice[deviceID] = failDeleteDevice
yasin sapli5458a1c2021-06-14 22:24:38 +0000412}