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" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 25 | "time" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 26 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 27 | "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" |
| 31 | "github.com/opencord/voltha-protos/v5/go/adapter_services" |
| 32 | "github.com/opencord/voltha-protos/v5/go/common" |
| 33 | "github.com/opencord/voltha-protos/v5/go/core" |
| 34 | "google.golang.org/grpc" |
| 35 | |
| 36 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 37 | ic "github.com/opencord/voltha-protos/v5/go/inter_container" |
| 38 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 39 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| 40 | ) |
| 41 | |
| 42 | const ( |
| 43 | numONUPerOLT = 4 |
| 44 | startingUNIPortNo = 100 |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 45 | ) |
| 46 | |
| 47 | func macAddressToUint32Array(mac string) []uint32 { |
| 48 | slist := strings.Split(mac, ":") |
| 49 | result := make([]uint32, len(slist)) |
| 50 | var err error |
| 51 | var tmp int64 |
| 52 | for index, val := range slist { |
| 53 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 54 | return []uint32{1, 2, 3, 4, 5, 6} |
| 55 | } |
| 56 | result[index] = uint32(tmp) |
| 57 | } |
| 58 | return result |
| 59 | } |
| 60 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 61 | // GetNumONUPerOLT returns number of ONUs per OLT |
| 62 | func GetNumONUPerOLT() int { |
| 63 | return numONUPerOLT |
| 64 | } |
| 65 | |
| 66 | // Returns the starting UNI port number |
| 67 | func GetStartingUNIPortNo() int { |
| 68 | return startingUNIPortNo |
| 69 | } |
| 70 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 71 | // Adapter represents adapter attributes |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 72 | type Adapter struct { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 73 | flows map[string]map[uint64]*openflow_13.OfpFlowStats |
| 74 | flowLock sync.RWMutex |
| 75 | devices map[string]*voltha.Device |
| 76 | deviceLock sync.RWMutex |
| 77 | failFlowAdd map[string]bool |
| 78 | failFlowAddLock sync.RWMutex |
| 79 | failFlowDelete map[string]bool |
| 80 | failFlowDeleteLock sync.RWMutex |
| 81 | failDeleteDevice map[string]bool |
| 82 | failDeleteDeviceLock sync.RWMutex |
| 83 | coreEnpoint string |
| 84 | coreClient *vgrpc.Client |
| 85 | serviceEndpoint string |
| 86 | DeviceType string |
| 87 | vendor string |
| 88 | Probe *probe.Probe |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 89 | } |
| 90 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 91 | // NewAdapter creates adapter instance |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 92 | func NewAdapter(serviceEndpoint, coreEndpoint, deviceType, vendor string) *Adapter { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 93 | return &Adapter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 94 | flows: map[string]map[uint64]*openflow_13.OfpFlowStats{}, |
| 95 | devices: map[string]*voltha.Device{}, |
| 96 | failFlowAdd: map[string]bool{}, |
| 97 | failFlowDelete: map[string]bool{}, |
| 98 | failDeleteDevice: map[string]bool{}, |
| 99 | coreEnpoint: coreEndpoint, |
| 100 | serviceEndpoint: serviceEndpoint, |
| 101 | DeviceType: deviceType, |
| 102 | vendor: vendor, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 106 | func (ta *Adapter) IsReady() bool { |
| 107 | return ta.Probe.IsReady() |
| 108 | } |
| 109 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 110 | func (ta *Adapter) storeDevice(d *voltha.Device) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 111 | ta.deviceLock.Lock() |
| 112 | defer ta.deviceLock.Unlock() |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 113 | if d != nil { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 114 | ta.devices[d.Id] = d |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 118 | func (ta *Adapter) getDevice(id string) *voltha.Device { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 119 | ta.deviceLock.RLock() |
| 120 | defer ta.deviceLock.RUnlock() |
| 121 | return ta.devices[id] |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 122 | } |
| 123 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 124 | func (ta *Adapter) updateDevice(d *voltha.Device) { |
| 125 | ta.storeDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 126 | } |
| 127 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 128 | func (ta *Adapter) GetEndPoint() string { |
| 129 | return ta.serviceEndpoint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 130 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 131 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 132 | func (ta *Adapter) GetCoreClient() (core.CoreServiceClient, error) { |
| 133 | // Wait until the Core is up and running |
| 134 | for { |
| 135 | if ta.coreClient != nil { |
| 136 | client, err := ta.coreClient.GetClient() |
| 137 | if err != nil { |
| 138 | logger.Infow(context.Background(), "got-error-core-client", log.Fields{"error": err}) |
| 139 | time.Sleep(1 * time.Second) |
| 140 | continue |
| 141 | } |
| 142 | c, ok := client.(core.CoreServiceClient) |
| 143 | if ok { |
| 144 | logger.Debug(context.Background(), "got-valid-client") |
| 145 | return c, nil |
| 146 | } |
| 147 | } |
| 148 | logger.Info(context.Background(), "waiting-for-grpc-core-client") |
| 149 | time.Sleep(1 * time.Second) |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 150 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 151 | } |
| 152 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 153 | // Helper methods |
| 154 | // startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server |
| 155 | func (ta *Adapter) startGRPCService(ctx context.Context, server *vgrpc.GrpcServer, handler adapter_services.AdapterServiceServer, serviceName string) { |
| 156 | logger.Infow(ctx, "service-created", log.Fields{"service": serviceName}) |
| 157 | |
| 158 | server.AddService(func(gs *grpc.Server) { adapter_services.RegisterAdapterServiceServer(gs, handler) }) |
| 159 | logger.Infow(ctx, "service-added", log.Fields{"service": serviceName}) |
| 160 | |
| 161 | ta.Probe.UpdateStatus(ctx, serviceName, probe.ServiceStatusRunning) |
| 162 | logger.Infow(ctx, "service-started", log.Fields{"service": serviceName}) |
| 163 | |
| 164 | // Note that there is a small window here in which the core could return its status as ready, |
| 165 | // when it really isn't. This is unlikely to cause issues, as the delay is incredibly short. |
| 166 | server.Start(ctx) |
| 167 | ta.Probe.UpdateStatus(ctx, serviceName, probe.ServiceStatusStopped) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 168 | } |
| 169 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 170 | func setAndTestCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 171 | svc := core.NewCoreServiceClient(conn) |
| 172 | if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != voltha.HealthStatus_HEALTHY { |
| 173 | return nil |
| 174 | } |
| 175 | return svc |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 176 | } |
| 177 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 178 | // gRPC service |
| 179 | func (ta *Adapter) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) { |
| 180 | return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil |
| 181 | } |
| 182 | |
| 183 | // Device |
| 184 | |
| 185 | func (ta *Adapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 186 | return &empty.Empty{}, nil |
| 187 | } |
| 188 | |
| 189 | func (ta *Adapter) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 190 | return &empty.Empty{}, nil |
| 191 | } |
| 192 | |
| 193 | func (ta *Adapter) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 194 | ta.failDeleteDeviceLock.RLock() |
| 195 | haveToFail, ok := ta.failDeleteDevice[device.Id] |
| 196 | if ok && haveToFail { |
| 197 | ta.failDeleteDeviceLock.RUnlock() |
| 198 | return nil, fmt.Errorf("delete-device-failure") |
| 199 | } |
| 200 | ta.failDeleteDeviceLock.RUnlock() |
| 201 | if ok { |
| 202 | ta.RemoveDevice(device.Id) |
| 203 | } |
| 204 | logger.Debugw(ctx, "device-deleted-in-adapter", log.Fields{"device-id": device.Id}) |
| 205 | return &empty.Empty{}, nil |
| 206 | } |
| 207 | |
| 208 | func (ta *Adapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 209 | return &empty.Empty{}, nil |
| 210 | } |
| 211 | |
| 212 | func (ta *Adapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 213 | return &empty.Empty{}, nil |
| 214 | } |
| 215 | |
| 216 | func (ta *Adapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 217 | return &empty.Empty{}, nil |
| 218 | } |
| 219 | |
| 220 | func (ta *Adapter) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 221 | return &empty.Empty{}, nil |
| 222 | } |
| 223 | |
| 224 | func (ta *Adapter) ChildDeviceLost(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 225 | return &empty.Empty{}, nil |
| 226 | } |
| 227 | |
| 228 | func (ta *Adapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
| 229 | return nil, nil |
| 230 | } |
| 231 | |
| 232 | // Ports |
| 233 | |
| 234 | func (ta *Adapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 235 | return &empty.Empty{}, nil |
| 236 | } |
| 237 | |
| 238 | func (ta *Adapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 239 | return &empty.Empty{}, nil |
| 240 | } |
| 241 | |
| 242 | // Flows |
| 243 | func (ta *Adapter) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) { |
| 244 | return &empty.Empty{}, nil |
| 245 | } |
| 246 | |
| 247 | func (ta *Adapter) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 248 | ta.flowLock.Lock() |
| 249 | defer ta.flowLock.Unlock() |
| 250 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 251 | if _, ok := ta.flows[incrFlows.Device.Id]; !ok { |
| 252 | ta.flows[incrFlows.Device.Id] = map[uint64]*openflow_13.OfpFlowStats{} |
| 253 | } |
| 254 | |
| 255 | if incrFlows.Flows.ToAdd != nil && len(incrFlows.Flows.ToAdd.Items) > 0 { |
| 256 | ta.failFlowAddLock.RLock() |
| 257 | if haveToFail, ok := ta.failFlowAdd[incrFlows.Device.Id]; ok && haveToFail { |
| 258 | ta.failFlowAddLock.RUnlock() |
| 259 | return nil, fmt.Errorf("flow-add-error") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 260 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 261 | ta.failFlowAddLock.RUnlock() |
| 262 | for _, f := range incrFlows.Flows.ToAdd.Items { |
| 263 | ta.flows[incrFlows.Device.Id][f.Id] = f |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 264 | } |
| 265 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 266 | if incrFlows.Flows.ToRemove != nil && len(incrFlows.Flows.ToRemove.Items) > 0 { |
| 267 | ta.failFlowDeleteLock.RLock() |
| 268 | if haveToFail, ok := ta.failFlowDelete[incrFlows.Device.Id]; ok && haveToFail { |
| 269 | ta.failFlowDeleteLock.RUnlock() |
| 270 | return nil, fmt.Errorf("flow-delete-error") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 271 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 272 | ta.failFlowDeleteLock.RUnlock() |
| 273 | for _, f := range incrFlows.Flows.ToRemove.Items { |
| 274 | delete(ta.flows[incrFlows.Device.Id], f.Id) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 275 | } |
| 276 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 277 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 278 | } |
| 279 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 280 | //Packets |
| 281 | func (ta *Adapter) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) { |
| 282 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 283 | } |
| 284 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 285 | // PM |
| 286 | func (ta *Adapter) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) { |
| 287 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 288 | } |
| 289 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 290 | // Image |
| 291 | func (ta *Adapter) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 292 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 293 | } |
| 294 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 295 | func (ta *Adapter) GetOnuImageStatus(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 296 | return &voltha.DeviceImageResponse{}, nil |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 297 | } |
| 298 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 299 | func (ta *Adapter) AbortOnuImageUpgrade(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 300 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 301 | } |
| 302 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 303 | func (ta *Adapter) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 304 | return &voltha.OnuImages{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 305 | } |
| 306 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 307 | func (ta *Adapter) ActivateOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 308 | return &voltha.DeviceImageResponse{}, nil |
| 309 | } |
| 310 | |
| 311 | func (ta *Adapter) CommitOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 312 | return &voltha.DeviceImageResponse{}, nil |
| 313 | } |
| 314 | |
| 315 | // Deprecated image APIs |
| 316 | func (ta *Adapter) DownloadImage(ctx context.Context, in *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 317 | return &voltha.ImageDownload{}, nil |
| 318 | } |
| 319 | |
| 320 | func (ta *Adapter) GetImageDownloadStatus(ctx context.Context, in *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 321 | return &voltha.ImageDownload{}, nil |
| 322 | } |
| 323 | |
| 324 | func (ta *Adapter) CancelImageDownload(ctx context.Context, in *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 325 | return &voltha.ImageDownload{}, nil |
| 326 | } |
| 327 | |
| 328 | func (ta *Adapter) ActivateImageUpdate(ctx context.Context, in *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 329 | return &voltha.ImageDownload{}, nil |
| 330 | } |
| 331 | |
| 332 | func (ta *Adapter) RevertImageUpdate(ctx context.Context, in *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 333 | return &voltha.ImageDownload{}, nil |
| 334 | } |
| 335 | |
| 336 | // OMCI test |
| 337 | func (ta *Adapter) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 338 | return nil, nil |
| 339 | } |
| 340 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 341 | // Events |
| 342 | func (ta *Adapter) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 343 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 344 | } |
| 345 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 346 | func (ta *Adapter) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 347 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 348 | } |
| 349 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 350 | func (ta *Adapter) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*common.OperationResp, error) { |
| 351 | return &common.OperationResp{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 352 | } |
| 353 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 354 | func (ta *Adapter) GetExtValue(context.Context, *ic.GetExtValueMessage) (*common.ReturnValues, error) { |
| 355 | return &common.ReturnValues{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 356 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 357 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 358 | func (ta *Adapter) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) { |
| 359 | return &empty.Empty{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 360 | } |
| 361 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 362 | func (ta *Adapter) GetSingleValue(context.Context, *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 363 | return &extension.SingleGetValueResponse{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 364 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 365 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 366 | func (ta *Adapter) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 367 | return &extension.SingleSetValueResponse{}, nil |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 368 | } |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 369 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 370 | // APIs for test ONLY |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 371 | // GetFlowCount returns the total number of flows presently under this adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 372 | func (ta *Adapter) GetFlowCount(deviceID string) int { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 373 | ta.flowLock.RLock() |
| 374 | defer ta.flowLock.RUnlock() |
| 375 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 376 | if _, ok := ta.flows[deviceID]; ok { |
| 377 | return len(ta.flows[deviceID]) |
| 378 | } |
| 379 | return 0 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 380 | } |
| 381 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 382 | // RemoveDevice removes all flows in this adapter |
| 383 | func (ta *Adapter) RemoveDevice(deviceID string) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 384 | ta.flowLock.Lock() |
| 385 | defer ta.flowLock.Unlock() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 386 | ta.failFlowAddLock.Lock() |
| 387 | defer ta.failFlowAddLock.Unlock() |
| 388 | ta.failFlowDeleteLock.Lock() |
| 389 | defer ta.failFlowDeleteLock.Unlock() |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 390 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 391 | delete(ta.flows, deviceID) |
| 392 | delete(ta.failFlowAdd, deviceID) |
| 393 | delete(ta.failFlowDelete, deviceID) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // SetFlowAction sets the adapter action on addition and deletion of flows |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 397 | func (ta *Adapter) SetFlowAction(deviceID string, failFlowAdd, failFlowDelete bool) { |
| 398 | ta.failFlowAddLock.Lock() |
| 399 | defer ta.failFlowAddLock.Unlock() |
| 400 | ta.failFlowDeleteLock.Lock() |
| 401 | defer ta.failFlowDeleteLock.Unlock() |
| 402 | ta.failFlowAdd[deviceID] = failFlowAdd |
| 403 | ta.failFlowDelete[deviceID] = failFlowDelete |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 404 | } |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 405 | |
| 406 | // SetDeleteAction sets the adapter action on delete device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 407 | func (ta *Adapter) SetDeleteAction(deviceID string, failDeleteDevice bool) { |
| 408 | ta.failDeleteDeviceLock.Lock() |
| 409 | defer ta.failDeleteDeviceLock.Unlock() |
| 410 | ta.failDeleteDevice[deviceID] = failDeleteDevice |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 411 | } |