blob: 5b8cc1b8895af638835b6b47673e814bd727abaf [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
khenaidood948f772021-08-11 17:49:24 -0400172func setAndTestCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
khenaidoo9beaaf12021-10-19 17:32:01 -0400173 svc := core_service.NewCoreServiceClient(conn)
174 if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != health.HealthStatus_HEALTHY {
khenaidood948f772021-08-11 17:49:24 -0400175 return nil
176 }
177 return svc
khenaidooab1f7bd2019-11-14 14:00:27 -0500178}
179
khenaidood948f772021-08-11 17:49:24 -0400180// gRPC service
khenaidoo9beaaf12021-10-19 17:32:01 -0400181func (ta *Adapter) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*health.HealthStatus, error) {
182 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
khenaidood948f772021-08-11 17:49:24 -0400183}
184
185// Device
186
187func (ta *Adapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
188 return &empty.Empty{}, nil
189}
190
191func (ta *Adapter) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
192 return &empty.Empty{}, nil
193}
194
195func (ta *Adapter) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
196 ta.failDeleteDeviceLock.RLock()
197 haveToFail, ok := ta.failDeleteDevice[device.Id]
198 if ok && haveToFail {
199 ta.failDeleteDeviceLock.RUnlock()
200 return nil, fmt.Errorf("delete-device-failure")
201 }
202 ta.failDeleteDeviceLock.RUnlock()
203 if ok {
204 ta.RemoveDevice(device.Id)
205 }
206 logger.Debugw(ctx, "device-deleted-in-adapter", log.Fields{"device-id": device.Id})
207 return &empty.Empty{}, nil
208}
209
210func (ta *Adapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
211 return &empty.Empty{}, nil
212}
213
214func (ta *Adapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
215 return &empty.Empty{}, nil
216}
217
218func (ta *Adapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
219 return &empty.Empty{}, nil
220}
221
222func (ta *Adapter) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
223 return &empty.Empty{}, nil
224}
225
226func (ta *Adapter) ChildDeviceLost(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
227 return &empty.Empty{}, nil
228}
229
khenaidoo9beaaf12021-10-19 17:32:01 -0400230func (ta *Adapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidood948f772021-08-11 17:49:24 -0400231 return nil, nil
232}
233
234// Ports
235
236func (ta *Adapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
237 return &empty.Empty{}, nil
238}
239
240func (ta *Adapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
241 return &empty.Empty{}, nil
242}
243
244// Flows
khenaidoo9beaaf12021-10-19 17:32:01 -0400245func (ta *Adapter) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400246 return &empty.Empty{}, nil
247}
248
khenaidoo9beaaf12021-10-19 17:32:01 -0400249func (ta *Adapter) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400250 ta.flowLock.Lock()
251 defer ta.flowLock.Unlock()
252
khenaidood948f772021-08-11 17:49:24 -0400253 if _, ok := ta.flows[incrFlows.Device.Id]; !ok {
254 ta.flows[incrFlows.Device.Id] = map[uint64]*openflow_13.OfpFlowStats{}
255 }
256
257 if incrFlows.Flows.ToAdd != nil && len(incrFlows.Flows.ToAdd.Items) > 0 {
258 ta.failFlowAddLock.RLock()
259 if haveToFail, ok := ta.failFlowAdd[incrFlows.Device.Id]; ok && haveToFail {
260 ta.failFlowAddLock.RUnlock()
261 return nil, fmt.Errorf("flow-add-error")
khenaidoo8b4abbf2020-04-24 17:04:30 -0400262 }
khenaidood948f772021-08-11 17:49:24 -0400263 ta.failFlowAddLock.RUnlock()
264 for _, f := range incrFlows.Flows.ToAdd.Items {
265 ta.flows[incrFlows.Device.Id][f.Id] = f
khenaidoo8b4abbf2020-04-24 17:04:30 -0400266 }
267 }
khenaidood948f772021-08-11 17:49:24 -0400268 if incrFlows.Flows.ToRemove != nil && len(incrFlows.Flows.ToRemove.Items) > 0 {
269 ta.failFlowDeleteLock.RLock()
270 if haveToFail, ok := ta.failFlowDelete[incrFlows.Device.Id]; ok && haveToFail {
271 ta.failFlowDeleteLock.RUnlock()
272 return nil, fmt.Errorf("flow-delete-error")
khenaidoo8b4abbf2020-04-24 17:04:30 -0400273 }
khenaidood948f772021-08-11 17:49:24 -0400274 ta.failFlowDeleteLock.RUnlock()
275 for _, f := range incrFlows.Flows.ToRemove.Items {
276 delete(ta.flows[incrFlows.Device.Id], f.Id)
khenaidoo8b4abbf2020-04-24 17:04:30 -0400277 }
278 }
khenaidood948f772021-08-11 17:49:24 -0400279 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500280}
281
khenaidood948f772021-08-11 17:49:24 -0400282//Packets
khenaidoo9beaaf12021-10-19 17:32:01 -0400283func (ta *Adapter) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400284 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500285}
286
khenaidood948f772021-08-11 17:49:24 -0400287// PM
khenaidoo9beaaf12021-10-19 17:32:01 -0400288func (ta *Adapter) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400289 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500290}
291
khenaidood948f772021-08-11 17:49:24 -0400292// Image
293func (ta *Adapter) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
294 return &voltha.DeviceImageResponse{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500295}
296
khenaidood948f772021-08-11 17:49:24 -0400297func (ta *Adapter) GetOnuImageStatus(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
298 return &voltha.DeviceImageResponse{}, nil
npujar1d86a522019-11-14 17:11:16 +0530299}
300
khenaidood948f772021-08-11 17:49:24 -0400301func (ta *Adapter) AbortOnuImageUpgrade(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
302 return &voltha.DeviceImageResponse{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500303}
304
khenaidood948f772021-08-11 17:49:24 -0400305func (ta *Adapter) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
306 return &voltha.OnuImages{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500307}
308
khenaidood948f772021-08-11 17:49:24 -0400309func (ta *Adapter) ActivateOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
310 return &voltha.DeviceImageResponse{}, nil
311}
312
313func (ta *Adapter) CommitOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
314 return &voltha.DeviceImageResponse{}, nil
315}
316
317// Deprecated image APIs
khenaidoo9beaaf12021-10-19 17:32:01 -0400318func (ta *Adapter) DownloadImage(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400319 return &voltha.ImageDownload{}, nil
320}
321
khenaidoo9beaaf12021-10-19 17:32:01 -0400322func (ta *Adapter) GetImageDownloadStatus(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400323 return &voltha.ImageDownload{}, nil
324}
325
khenaidoo9beaaf12021-10-19 17:32:01 -0400326func (ta *Adapter) CancelImageDownload(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400327 return &voltha.ImageDownload{}, nil
328}
329
khenaidoo9beaaf12021-10-19 17:32:01 -0400330func (ta *Adapter) ActivateImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400331 return &voltha.ImageDownload{}, nil
332}
333
khenaidoo9beaaf12021-10-19 17:32:01 -0400334func (ta *Adapter) RevertImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidood948f772021-08-11 17:49:24 -0400335 return &voltha.ImageDownload{}, nil
336}
337
338// OMCI test
khenaidoo9beaaf12021-10-19 17:32:01 -0400339func (ta *Adapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidooab1f7bd2019-11-14 14:00:27 -0500340 return nil, nil
341}
342
khenaidood948f772021-08-11 17:49:24 -0400343// Events
344func (ta *Adapter) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
345 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500346}
347
khenaidood948f772021-08-11 17:49:24 -0400348func (ta *Adapter) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
349 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500350}
351
khenaidoo9beaaf12021-10-19 17:32:01 -0400352func (ta *Adapter) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidood948f772021-08-11 17:49:24 -0400353 return &common.OperationResp{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500354}
355
khenaidoo9beaaf12021-10-19 17:32:01 -0400356func (ta *Adapter) GetExtValue(context.Context, *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
357 return &extension.ReturnValues{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500358}
kesavandbc2d1622020-01-21 00:42:01 -0500359
khenaidoo9beaaf12021-10-19 17:32:01 -0400360func (ta *Adapter) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400361 return &empty.Empty{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500362}
363
khenaidood948f772021-08-11 17:49:24 -0400364func (ta *Adapter) GetSingleValue(context.Context, *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
365 return &extension.SingleGetValueResponse{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500366}
Scott Baker0e78ba22020-02-24 17:58:47 -0800367
khenaidood948f772021-08-11 17:49:24 -0400368func (ta *Adapter) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
369 return &extension.SingleSetValueResponse{}, nil
Scott Baker0e78ba22020-02-24 17:58:47 -0800370}
Scott Baker432f9be2020-03-26 11:56:30 -0700371
khenaidood948f772021-08-11 17:49:24 -0400372// APIs for test ONLY
khenaidoo8b4abbf2020-04-24 17:04:30 -0400373// GetFlowCount returns the total number of flows presently under this adapter
khenaidood948f772021-08-11 17:49:24 -0400374func (ta *Adapter) GetFlowCount(deviceID string) int {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400375 ta.flowLock.RLock()
376 defer ta.flowLock.RUnlock()
377
khenaidood948f772021-08-11 17:49:24 -0400378 if _, ok := ta.flows[deviceID]; ok {
379 return len(ta.flows[deviceID])
380 }
381 return 0
khenaidoo8b4abbf2020-04-24 17:04:30 -0400382}
383
khenaidood948f772021-08-11 17:49:24 -0400384// RemoveDevice removes all flows in this adapter
385func (ta *Adapter) RemoveDevice(deviceID string) {
khenaidoo8b4abbf2020-04-24 17:04:30 -0400386 ta.flowLock.Lock()
387 defer ta.flowLock.Unlock()
khenaidood948f772021-08-11 17:49:24 -0400388 ta.failFlowAddLock.Lock()
389 defer ta.failFlowAddLock.Unlock()
390 ta.failFlowDeleteLock.Lock()
391 defer ta.failFlowDeleteLock.Unlock()
khenaidoo8b4abbf2020-04-24 17:04:30 -0400392
khenaidood948f772021-08-11 17:49:24 -0400393 delete(ta.flows, deviceID)
394 delete(ta.failFlowAdd, deviceID)
395 delete(ta.failFlowDelete, deviceID)
khenaidoo8b4abbf2020-04-24 17:04:30 -0400396}
397
398// SetFlowAction sets the adapter action on addition and deletion of flows
khenaidood948f772021-08-11 17:49:24 -0400399func (ta *Adapter) SetFlowAction(deviceID string, failFlowAdd, failFlowDelete bool) {
400 ta.failFlowAddLock.Lock()
401 defer ta.failFlowAddLock.Unlock()
402 ta.failFlowDeleteLock.Lock()
403 defer ta.failFlowDeleteLock.Unlock()
404 ta.failFlowAdd[deviceID] = failFlowAdd
405 ta.failFlowDelete[deviceID] = failFlowDelete
khenaidoo8b4abbf2020-04-24 17:04:30 -0400406}
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530407
408// SetDeleteAction sets the adapter action on delete device
khenaidood948f772021-08-11 17:49:24 -0400409func (ta *Adapter) SetDeleteAction(deviceID string, failDeleteDevice bool) {
410 ta.failDeleteDeviceLock.Lock()
411 defer ta.failDeleteDeviceLock.Unlock()
412 ta.failDeleteDevice[deviceID] = failDeleteDevice
yasin sapli5458a1c2021-06-14 22:24:38 +0000413}