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 | a46458b | 2021-12-15 16:50:44 -0500 | [diff] [blame] | 172 | func setCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 173 | if conn == nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 174 | return nil |
| 175 | } |
khenaidoo | a46458b | 2021-12-15 16:50:44 -0500 | [diff] [blame] | 176 | return core_service.NewCoreServiceClient(conn) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 177 | } |
| 178 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 179 | // gRPC service |
khenaidoo | 25057da | 2021-12-08 14:40:45 -0500 | [diff] [blame] | 180 | func (ta *Adapter) GetHealthStatus(ctx context.Context, clientConn *common.Connection) (*health.HealthStatus, error) { |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 181 | return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // Device |
| 185 | |
| 186 | func (ta *Adapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 187 | return &empty.Empty{}, nil |
| 188 | } |
| 189 | |
| 190 | func (ta *Adapter) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 191 | return &empty.Empty{}, nil |
| 192 | } |
| 193 | |
| 194 | func (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 | |
| 209 | func (ta *Adapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 210 | return &empty.Empty{}, nil |
| 211 | } |
| 212 | |
| 213 | func (ta *Adapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 214 | return &empty.Empty{}, nil |
| 215 | } |
| 216 | |
| 217 | func (ta *Adapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 218 | return &empty.Empty{}, nil |
| 219 | } |
| 220 | |
| 221 | func (ta *Adapter) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 222 | return &empty.Empty{}, nil |
| 223 | } |
| 224 | |
| 225 | func (ta *Adapter) ChildDeviceLost(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 226 | return &empty.Empty{}, nil |
| 227 | } |
| 228 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 229 | func (ta *Adapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 230 | return nil, nil |
| 231 | } |
| 232 | |
| 233 | // Ports |
| 234 | |
| 235 | func (ta *Adapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 236 | return &empty.Empty{}, nil |
| 237 | } |
| 238 | |
| 239 | func (ta *Adapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 240 | return &empty.Empty{}, nil |
| 241 | } |
| 242 | |
| 243 | // Flows |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 244 | func (ta *Adapter) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 245 | return &empty.Empty{}, nil |
| 246 | } |
| 247 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 248 | func (ta *Adapter) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 249 | ta.flowLock.Lock() |
| 250 | defer ta.flowLock.Unlock() |
| 251 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 252 | 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") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 261 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 262 | ta.failFlowAddLock.RUnlock() |
| 263 | for _, f := range incrFlows.Flows.ToAdd.Items { |
| 264 | ta.flows[incrFlows.Device.Id][f.Id] = f |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 265 | } |
| 266 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 267 | 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") |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 272 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 273 | ta.failFlowDeleteLock.RUnlock() |
| 274 | for _, f := range incrFlows.Flows.ToRemove.Items { |
| 275 | delete(ta.flows[incrFlows.Device.Id], f.Id) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 276 | } |
| 277 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 278 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 279 | } |
| 280 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 281 | //Packets |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 282 | func (ta *Adapter) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 283 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 284 | } |
| 285 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 286 | // PM |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 287 | func (ta *Adapter) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 288 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 289 | } |
| 290 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 291 | // Image |
| 292 | func (ta *Adapter) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 293 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 294 | } |
| 295 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 296 | func (ta *Adapter) GetOnuImageStatus(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 297 | return &voltha.DeviceImageResponse{}, nil |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 298 | } |
| 299 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 300 | func (ta *Adapter) AbortOnuImageUpgrade(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 301 | return &voltha.DeviceImageResponse{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 302 | } |
| 303 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 304 | func (ta *Adapter) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 305 | return &voltha.OnuImages{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 306 | } |
| 307 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 308 | func (ta *Adapter) ActivateOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 309 | return &voltha.DeviceImageResponse{}, nil |
| 310 | } |
| 311 | |
| 312 | func (ta *Adapter) CommitOnuImage(ctx context.Context, request *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 313 | return &voltha.DeviceImageResponse{}, nil |
| 314 | } |
| 315 | |
| 316 | // Deprecated image APIs |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 317 | func (ta *Adapter) DownloadImage(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 318 | return &voltha.ImageDownload{}, nil |
| 319 | } |
| 320 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 321 | func (ta *Adapter) GetImageDownloadStatus(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 322 | return &voltha.ImageDownload{}, nil |
| 323 | } |
| 324 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 325 | func (ta *Adapter) CancelImageDownload(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 326 | return &voltha.ImageDownload{}, nil |
| 327 | } |
| 328 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 329 | func (ta *Adapter) ActivateImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 330 | return &voltha.ImageDownload{}, nil |
| 331 | } |
| 332 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 333 | func (ta *Adapter) RevertImageUpdate(ctx context.Context, in *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 334 | return &voltha.ImageDownload{}, nil |
| 335 | } |
| 336 | |
| 337 | // OMCI test |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 338 | func (ta *Adapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 339 | return nil, nil |
| 340 | } |
| 341 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 342 | // Events |
| 343 | func (ta *Adapter) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 344 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 345 | } |
| 346 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 347 | func (ta *Adapter) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 348 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 349 | } |
| 350 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 351 | func (ta *Adapter) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 352 | return &common.OperationResp{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 353 | } |
| 354 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 355 | func (ta *Adapter) GetExtValue(context.Context, *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
| 356 | return &extension.ReturnValues{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 357 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 358 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 359 | func (ta *Adapter) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 360 | return &empty.Empty{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 361 | } |
| 362 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 363 | func (ta *Adapter) GetSingleValue(context.Context, *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 364 | return &extension.SingleGetValueResponse{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 365 | } |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 366 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 367 | func (ta *Adapter) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 368 | return &extension.SingleSetValueResponse{}, nil |
Scott Baker | 0e78ba2 | 2020-02-24 17:58:47 -0800 | [diff] [blame] | 369 | } |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 370 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 371 | // APIs for test ONLY |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 372 | // GetFlowCount returns the total number of flows presently under this adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 373 | func (ta *Adapter) GetFlowCount(deviceID string) int { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 374 | ta.flowLock.RLock() |
| 375 | defer ta.flowLock.RUnlock() |
| 376 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 377 | if _, ok := ta.flows[deviceID]; ok { |
| 378 | return len(ta.flows[deviceID]) |
| 379 | } |
| 380 | return 0 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 381 | } |
| 382 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 383 | // RemoveDevice removes all flows in this adapter |
| 384 | func (ta *Adapter) RemoveDevice(deviceID string) { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 385 | ta.flowLock.Lock() |
| 386 | defer ta.flowLock.Unlock() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 387 | ta.failFlowAddLock.Lock() |
| 388 | defer ta.failFlowAddLock.Unlock() |
| 389 | ta.failFlowDeleteLock.Lock() |
| 390 | defer ta.failFlowDeleteLock.Unlock() |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 391 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 392 | delete(ta.flows, deviceID) |
| 393 | delete(ta.failFlowAdd, deviceID) |
| 394 | delete(ta.failFlowDelete, deviceID) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | // SetFlowAction sets the adapter action on addition and deletion of flows |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 398 | func (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 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 405 | } |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 406 | |
| 407 | // SetDeleteAction sets the adapter action on delete device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 408 | func (ta *Adapter) SetDeleteAction(deviceID string, failDeleteDevice bool) { |
| 409 | ta.failDeleteDeviceLock.Lock() |
| 410 | defer ta.failDeleteDeviceLock.Unlock() |
| 411 | ta.failDeleteDevice[deviceID] = failDeleteDevice |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 412 | } |