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" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/core_service" |
| 34 | "github.com/opencord/voltha-protos/v5/go/health" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 35 | "google.golang.org/grpc" |
| 36 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 37 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 38 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 39 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 40 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 41 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| 42 | ) |
| 43 | |
| 44 | const ( |
| 45 | numONUPerOLT = 4 |
| 46 | startingUNIPortNo = 100 |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 47 | ) |
| 48 | |
| 49 | func 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 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 63 | // GetNumONUPerOLT returns number of ONUs per OLT |
| 64 | func GetNumONUPerOLT() int { |
| 65 | return numONUPerOLT |
| 66 | } |
| 67 | |
| 68 | // Returns the starting UNI port number |
| 69 | func GetStartingUNIPortNo() int { |
| 70 | return startingUNIPortNo |
| 71 | } |
| 72 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 73 | // Adapter represents adapter attributes |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 74 | type Adapter struct { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 75 | 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 |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 91 | } |
| 92 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 93 | // NewAdapter creates adapter instance |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 94 | func NewAdapter(serviceEndpoint, coreEndpoint, deviceType, vendor string) *Adapter { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 95 | return &Adapter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 96 | 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, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 108 | func (ta *Adapter) IsReady() bool { |
| 109 | return ta.Probe.IsReady() |
| 110 | } |
| 111 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 112 | func (ta *Adapter) storeDevice(d *voltha.Device) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 113 | ta.deviceLock.Lock() |
| 114 | defer ta.deviceLock.Unlock() |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 115 | if d != nil { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 116 | ta.devices[d.Id] = d |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 120 | func (ta *Adapter) getDevice(id string) *voltha.Device { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 121 | ta.deviceLock.RLock() |
| 122 | defer ta.deviceLock.RUnlock() |
| 123 | return ta.devices[id] |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 124 | } |
| 125 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 126 | func (ta *Adapter) updateDevice(d *voltha.Device) { |
| 127 | ta.storeDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 128 | } |
| 129 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 130 | func (ta *Adapter) GetEndPoint() string { |
| 131 | return ta.serviceEndpoint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 132 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 133 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 134 | func (ta *Adapter) GetCoreClient() (core_service.CoreServiceClient, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 135 | // 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 | } |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 144 | c, ok := client.(core_service.CoreServiceClient) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 145 | 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 Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 152 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 153 | } |
| 154 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 155 | // Helper methods |
| 156 | // startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 157 | func (ta *Adapter) startGRPCService(ctx context.Context, server *vgrpc.GrpcServer, handler adapter_service.AdapterServiceServer, serviceName string) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 158 | logger.Infow(ctx, "service-created", log.Fields{"service": serviceName}) |
| 159 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 160 | server.AddService(func(gs *grpc.Server) { adapter_service.RegisterAdapterServiceServer(gs, handler) }) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 161 | 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) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 170 | } |
| 171 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 172 | func setAndTestCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 173 | svc := core_service.NewCoreServiceClient(conn) |
| 174 | if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != health.HealthStatus_HEALTHY { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 175 | return nil |
| 176 | } |
| 177 | return svc |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 178 | } |
| 179 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 180 | // gRPC service |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 181 | func (ta *Adapter) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*health.HealthStatus, error) { |
| 182 | return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // Device |
| 186 | |
| 187 | func (ta *Adapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 188 | return &empty.Empty{}, nil |
| 189 | } |
| 190 | |
| 191 | func (ta *Adapter) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 192 | return &empty.Empty{}, nil |
| 193 | } |
| 194 | |
| 195 | func (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 | |
| 210 | func (ta *Adapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 211 | return &empty.Empty{}, nil |
| 212 | } |
| 213 | |
| 214 | func (ta *Adapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 215 | return &empty.Empty{}, nil |
| 216 | } |
| 217 | |
| 218 | func (ta *Adapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 219 | return &empty.Empty{}, nil |
| 220 | } |
| 221 | |
| 222 | func (ta *Adapter) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 223 | return &empty.Empty{}, nil |
| 224 | } |
| 225 | |
| 226 | func (ta *Adapter) ChildDeviceLost(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 227 | return &empty.Empty{}, nil |
| 228 | } |
| 229 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 230 | func (ta *Adapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 231 | return nil, nil |
| 232 | } |
| 233 | |
| 234 | // Ports |
| 235 | |
| 236 | func (ta *Adapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 237 | return &empty.Empty{}, nil |
| 238 | } |
| 239 | |
| 240 | func (ta *Adapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 241 | return &empty.Empty{}, nil |
| 242 | } |
| 243 | |
| 244 | // Flows |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 245 | func (ta *Adapter) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 246 | return &empty.Empty{}, nil |
| 247 | } |
| 248 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 249 | func (ta *Adapter) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 250 | ta.flowLock.Lock() |
| 251 | defer ta.flowLock.Unlock() |
| 252 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 253 | 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") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 262 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 263 | ta.failFlowAddLock.RUnlock() |
| 264 | for _, f := range incrFlows.Flows.ToAdd.Items { |
| 265 | ta.flows[incrFlows.Device.Id][f.Id] = f |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 266 | } |
| 267 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 268 | 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") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 273 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 274 | ta.failFlowDeleteLock.RUnlock() |
| 275 | for _, f := range incrFlows.Flows.ToRemove.Items { |
| 276 | delete(ta.flows[incrFlows.Device.Id], f.Id) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 277 | } |
| 278 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 279 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 280 | } |
| 281 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 282 | //Packets |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 283 | func (ta *Adapter) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 284 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 285 | } |
| 286 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 287 | // PM |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 288 | func (ta *Adapter) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 289 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 290 | } |
| 291 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 292 | // Image |
| 293 | func (ta *Adapter) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 294 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 295 | } |
| 296 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 297 | func (ta *Adapter) GetOnuImageStatus(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 298 | return &voltha.DeviceImageResponse{}, nil |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 299 | } |
| 300 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 301 | func (ta *Adapter) AbortOnuImageUpgrade(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 302 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 303 | } |
| 304 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 305 | func (ta *Adapter) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 306 | return &voltha.OnuImages{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 307 | } |
| 308 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 309 | func (ta *Adapter) ActivateOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 310 | return &voltha.DeviceImageResponse{}, nil |
| 311 | } |
| 312 | |
| 313 | func (ta *Adapter) CommitOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 314 | return &voltha.DeviceImageResponse{}, nil |
| 315 | } |
| 316 | |
| 317 | // Deprecated image APIs |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 318 | func (ta *Adapter) DownloadImage(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 319 | return &voltha.ImageDownload{}, nil |
| 320 | } |
| 321 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 322 | func (ta *Adapter) GetImageDownloadStatus(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 323 | return &voltha.ImageDownload{}, nil |
| 324 | } |
| 325 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 326 | func (ta *Adapter) CancelImageDownload(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 327 | return &voltha.ImageDownload{}, nil |
| 328 | } |
| 329 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 330 | func (ta *Adapter) ActivateImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 331 | return &voltha.ImageDownload{}, nil |
| 332 | } |
| 333 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 334 | func (ta *Adapter) RevertImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 335 | return &voltha.ImageDownload{}, nil |
| 336 | } |
| 337 | |
| 338 | // OMCI test |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 339 | func (ta *Adapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 340 | return nil, nil |
| 341 | } |
| 342 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 343 | // Events |
| 344 | func (ta *Adapter) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 345 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 346 | } |
| 347 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 348 | func (ta *Adapter) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 349 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 350 | } |
| 351 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 352 | func (ta *Adapter) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 353 | return &common.OperationResp{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 354 | } |
| 355 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 356 | func (ta *Adapter) GetExtValue(context.Context, *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
| 357 | return &extension.ReturnValues{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 358 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 359 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 360 | func (ta *Adapter) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 361 | return &empty.Empty{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 362 | } |
| 363 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 364 | func (ta *Adapter) GetSingleValue(context.Context, *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 365 | return &extension.SingleGetValueResponse{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 366 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 367 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 368 | func (ta *Adapter) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 369 | return &extension.SingleSetValueResponse{}, nil |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 370 | } |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 371 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 372 | // APIs for test ONLY |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 373 | // GetFlowCount returns the total number of flows presently under this adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 374 | func (ta *Adapter) GetFlowCount(deviceID string) int { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 375 | ta.flowLock.RLock() |
| 376 | defer ta.flowLock.RUnlock() |
| 377 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 378 | if _, ok := ta.flows[deviceID]; ok { |
| 379 | return len(ta.flows[deviceID]) |
| 380 | } |
| 381 | return 0 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 382 | } |
| 383 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 384 | // RemoveDevice removes all flows in this adapter |
| 385 | func (ta *Adapter) RemoveDevice(deviceID string) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 386 | ta.flowLock.Lock() |
| 387 | defer ta.flowLock.Unlock() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 388 | ta.failFlowAddLock.Lock() |
| 389 | defer ta.failFlowAddLock.Unlock() |
| 390 | ta.failFlowDeleteLock.Lock() |
| 391 | defer ta.failFlowDeleteLock.Unlock() |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 392 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 393 | delete(ta.flows, deviceID) |
| 394 | delete(ta.failFlowAdd, deviceID) |
| 395 | delete(ta.failFlowDelete, deviceID) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // SetFlowAction sets the adapter action on addition and deletion of flows |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 399 | func (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 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 406 | } |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 407 | |
| 408 | // SetDeleteAction sets the adapter action on delete device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 409 | func (ta *Adapter) SetDeleteAction(deviceID string, failDeleteDevice bool) { |
| 410 | ta.failDeleteDeviceLock.Lock() |
| 411 | defer ta.failDeleteDeviceLock.Unlock() |
| 412 | ta.failDeleteDevice[deviceID] = failDeleteDevice |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 413 | } |