blob: 8a41a010bfaaf02be7d124ce07043810de2295cc [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
Joey Armstrongf9bffdf2022-12-27 07:05:28 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
Girish Gowdru0c588b22019-04-23 23:24:56 -04003
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 */
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070016
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
Girish Gowdru0c588b22019-04-23 23:24:56 -040019
20import (
21 "context"
khenaidooefff76e2021-12-15 16:51:30 -050022 "fmt"
Girish Gowdru0c588b22019-04-23 23:24:56 -040023 "sync"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053024 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040025
khenaidoo106c61a2021-08-11 18:05:46 -040026 "github.com/golang/protobuf/ptypes/empty"
27 conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
28 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
29 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
30 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080031 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053032 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
khenaidooefff76e2021-12-15 16:51:30 -050033 "github.com/opencord/voltha-protos/v5/go/adapter_service"
khenaidoo106c61a2021-08-11 18:05:46 -040034 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoodc2116e2021-10-19 17:33:19 -040035 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo106c61a2021-08-11 18:05:46 -040036 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoodc2116e2021-10-19 17:33:19 -040037 "github.com/opencord/voltha-protos/v5/go/health"
38 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
39 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidoo106c61a2021-08-11 18:05:46 -040040 "github.com/opencord/voltha-protos/v5/go/voltha"
Girish Gowdru0c588b22019-04-23 23:24:56 -040041)
42
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070043//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040044type OpenOLT struct {
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053045 configManager *conf.ConfigManager
46 deviceHandlers map[string]*DeviceHandler
47 coreClient *vgrpc.Client
48 eventProxy eventif.EventProxy
49 config *config.AdapterFlags
50 numOnus int
51 KVStoreAddress string
52 KVStoreType string
53 exitChannel chan struct{}
54 HeartbeatCheckInterval time.Duration
55 HeartbeatFailReportInterval time.Duration
56 GrpcTimeoutInterval time.Duration
57 lockDeviceHandlersMap sync.RWMutex
58 enableONUStats bool
59 enableGemStats bool
60 rpcTimeout time.Duration
61 CheckOnuDevExistenceAtOnuDiscovery bool
Girish Gowdru0c588b22019-04-23 23:24:56 -040062}
63
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070064//NewOpenOLT returns a new instance of OpenOLT
khenaidoo106c61a2021-08-11 18:05:46 -040065func NewOpenOLT(ctx context.Context,
66 coreClient *vgrpc.Client,
Himani Chawlacd407802020-12-10 12:08:59 +053067 eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040068 var openOLT OpenOLT
khenaidooefff76e2021-12-15 16:51:30 -050069 openOLT.exitChannel = make(chan struct{})
Girish Gowdru0c588b22019-04-23 23:24:56 -040070 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053071 openOLT.config = cfg
72 openOLT.numOnus = cfg.OnuNumber
khenaidoo106c61a2021-08-11 18:05:46 -040073 openOLT.coreClient = coreClient
Devmalya Paulfb990a52019-07-09 10:01:49 -040074 openOLT.eventProxy = eventProxy
Neha Sharma3f221ae2020-04-29 19:02:12 +000075 openOLT.KVStoreAddress = cfg.KVStoreAddress
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053076 openOLT.KVStoreType = cfg.KVStoreType
77 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
78 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
79 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040080 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
Matteo Scandolodfa7a972020-11-06 13:03:40 -080081 openOLT.configManager = cm
Gamze Abakafcbd6e72020-12-17 13:25:16 +000082 openOLT.enableONUStats = cfg.EnableONUStats
83 openOLT.enableGemStats = cfg.EnableGEMStats
khenaidoo106c61a2021-08-11 18:05:46 -040084 openOLT.rpcTimeout = cfg.RPCTimeout
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053085 openOLT.CheckOnuDevExistenceAtOnuDiscovery = cfg.CheckOnuDevExistenceAtOnuDiscovery
Girish Gowdru0c588b22019-04-23 23:24:56 -040086 return &openOLT
87}
88
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070089//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040090func (oo *OpenOLT) Start(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000091 logger.Info(ctx, "starting-device-manager")
92 logger.Info(ctx, "device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040093 return nil
94}
95
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070096//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040097func (oo *OpenOLT) Stop(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000098 logger.Info(ctx, "stopping-device-manager")
khenaidooefff76e2021-12-15 16:51:30 -050099 close(oo.exitChannel)
100 // Stop the device handlers
101 oo.stopAllDeviceHandlers(ctx)
102
103 // Stop the core grpc client connection
104 if oo.coreClient != nil {
105 oo.coreClient.Stop(ctx)
106 }
107
Neha Sharma96b7bf22020-06-15 10:37:32 +0000108 logger.Info(ctx, "device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400109 return nil
110}
111
Girish Gowdru0c588b22019-04-23 23:24:56 -0400112func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
113 oo.lockDeviceHandlersMap.Lock()
114 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530115 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
116 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400117 }
118}
119
120func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
121 oo.lockDeviceHandlersMap.Lock()
122 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530123 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400124}
125
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700126func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400127 oo.lockDeviceHandlersMap.Lock()
128 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700129 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400130 return agent
131 }
132 return nil
133}
134
khenaidooefff76e2021-12-15 16:51:30 -0500135func (oo *OpenOLT) stopAllDeviceHandlers(ctx context.Context) {
136 oo.lockDeviceHandlersMap.Lock()
137 defer oo.lockDeviceHandlersMap.Unlock()
138 for _, handler := range oo.deviceHandlers {
139 handler.Stop(ctx)
140 }
khenaidoo106c61a2021-08-11 18:05:46 -0400141}
142
143// AdoptDevice creates a new device handler if not present already and then adopts the device
144func (oo *OpenOLT) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400145 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400146 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400147 }
divyadesai3af43e12020-08-18 07:10:54 +0000148 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149 var handler *DeviceHandler
150 if handler = oo.getDeviceHandler(device.Id); handler == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400151 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400152 oo.addDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400153 go handler.AdoptDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400154 }
khenaidoo106c61a2021-08-11 18:05:46 -0400155 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400156}
157
khenaidoo106c61a2021-08-11 18:05:46 -0400158//GetOfpDeviceInfo returns OFP information for the given device
khenaidoodc2116e2021-10-19 17:33:19 -0400159func (oo *OpenOLT) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400160 logger.Infow(ctx, "get_ofp_device_info", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400161 if handler := oo.getDeviceHandler(device.Id); handler != nil {
162 return handler.GetOfpDeviceInfo(device)
163 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000164 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400165}
166
khenaidoo106c61a2021-08-11 18:05:46 -0400167//ReconcileDevice unimplemented
168func (oo *OpenOLT) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530169 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400170 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530171 }
divyadesai3af43e12020-08-18 07:10:54 +0000172 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530173 var handler *DeviceHandler
174 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Manindere49938d2021-03-19 00:23:24 +0530175 //Setting state to RECONCILING
khenaidoo106c61a2021-08-11 18:05:46 -0400176 cgClient, err := oo.coreClient.GetCoreServiceClient()
Manindere49938d2021-03-19 00:23:24 +0530177 if err != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400178 return nil, err
Manindere49938d2021-03-19 00:23:24 +0530179 }
khenaidoo106c61a2021-08-11 18:05:46 -0400180 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout)
181 defer cancel()
khenaidoodc2116e2021-10-19 17:33:19 -0400182 if _, err := cgClient.DeviceStateUpdate(subCtx, &ca.DeviceStateFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400183 DeviceId: device.Id,
184 OperStatus: voltha.OperStatus_RECONCILING,
185 ConnStatus: device.ConnectStatus,
186 }); err != nil {
187 return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err)
188 }
189
Girish Gowdra0fb24a32021-10-27 15:15:27 -0700190 // The OperState of the device is set to RECONCILING in the previous section. This also needs to be set on the
191 // locally cached copy of the device struct.
192 device.OperStatus = voltha.OperStatus_RECONCILING
193 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
194 handler.adapterPreviouslyConnected = true
195 oo.addDeviceHandlerToMap(handler)
196 handler.transitionMap = NewTransitionMap(handler)
197
khenaidoo106c61a2021-08-11 18:05:46 -0400198 handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530199 }
khenaidoo106c61a2021-08-11 18:05:46 -0400200 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400201}
202
khenaidoo106c61a2021-08-11 18:05:46 -0400203//DisableDevice disables the given device
204func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000205 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400206 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400207 if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
208 return nil, err
209 }
210 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400211 }
khenaidoo106c61a2021-08-11 18:05:46 -0400212 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400213}
214
khenaidoo106c61a2021-08-11 18:05:46 -0400215//ReEnableDevice enables the olt device after disable
216func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000217 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400218 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400219 if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
220 return nil, err
221 }
222 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400223 }
khenaidoo106c61a2021-08-11 18:05:46 -0400224 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225}
226
khenaidoo106c61a2021-08-11 18:05:46 -0400227//RebootDevice reboots the given device
228func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000229 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400230 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400231 if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
232 return nil, err
233 }
234 return &empty.Empty{}, nil
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400235 }
khenaidoo106c61a2021-08-11 18:05:46 -0400236 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
237
Girish Gowdru0c588b22019-04-23 23:24:56 -0400238}
239
khenaidoo106c61a2021-08-11 18:05:46 -0400240//DeleteDevice deletes a device
241func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000242 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400243 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400244 if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
Gustavo Silva41af9122022-10-11 11:05:13 -0300245 return nil, err
Devmalya Paul495b94a2019-08-27 19:42:00 -0400246 }
247 oo.deleteDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400248 return &empty.Empty{}, nil
Devmalya Paul495b94a2019-08-27 19:42:00 -0400249 }
khenaidoo106c61a2021-08-11 18:05:46 -0400250 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400251}
252
khenaidoo106c61a2021-08-11 18:05:46 -0400253//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoodc2116e2021-10-19 17:33:19 -0400254func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400255 logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata})
256 if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil {
257 if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
258 return nil, err
259 }
260 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400261 }
khenaidoo106c61a2021-08-11 18:05:46 -0400262 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": incrFlows.Device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400263}
264
khenaidoo106c61a2021-08-11 18:05:46 -0400265//UpdatePmConfig returns PmConfigs nil or error
khenaidoodc2116e2021-10-19 17:33:19 -0400266func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400267 logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs})
268 if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil {
269 handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs)
270 return &empty.Empty{}, nil
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000271 }
khenaidoo106c61a2021-08-11 18:05:46 -0400272 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": configs.DeviceId}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400273}
274
khenaidoo106c61a2021-08-11 18:05:46 -0400275//SendPacketOut sends packet out to the device
khenaidoodc2116e2021-10-19 17:33:19 -0400276func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400277 logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet})
278 if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil {
279 if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil {
280 return nil, err
281 }
282 return &empty.Empty{}, nil
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400283 }
khenaidoo106c61a2021-08-11 18:05:46 -0400284 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil)
285
Girish Gowdru0c588b22019-04-23 23:24:56 -0400286}
287
khenaidoo106c61a2021-08-11 18:05:46 -0400288// EnablePort to Enable PON/NNI interface
289func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
290 logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port})
291 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil {
292 return nil, err
293 }
294 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400295}
296
khenaidoo106c61a2021-08-11 18:05:46 -0400297// DisablePort to Disable pon/nni interface
298func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
299 logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port})
300 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil {
301 return nil, err
302 }
303 return &empty.Empty{}, nil
kesavand39e0aa32020-01-28 20:58:50 -0500304}
305
306// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000307func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000308 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500309 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530310 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800311 "reason": "port cannot be nil",
312 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000313 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500314 }
315 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000316 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500317 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000318 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000319 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500320 }
321 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000322 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000323 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500324 }
325 }
326 }
327 return nil
328}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500329
khenaidoo106c61a2021-08-11 18:05:46 -0400330//ChildDeviceLost deletes the ONU and its references from PONResources
331func (oo *OpenOLT) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
Girish Gowdraa0870562021-03-11 14:30:14 -0800332 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id})
333 if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400334 if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil {
335 return nil, err
336 }
337 return &empty.Empty{}, nil
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500338 }
khenaidoo106c61a2021-08-11 18:05:46 -0400339 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"parent-device-id": childDevice.ParentId}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500340}
Scott Baker24f83e22020-03-30 16:14:28 -0700341
khenaidoo106c61a2021-08-11 18:05:46 -0400342// GetExtValue retrieves a value on a particular ONU
khenaidoodc2116e2021-10-19 17:33:19 -0400343func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800344 var err error
khenaidoodc2116e2021-10-19 17:33:19 -0400345 resp := new(extension.ReturnValues)
khenaidoo106c61a2021-08-11 18:05:46 -0400346 logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id})
347 if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil {
348 if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil {
349 logger.Errorw(ctx, "error-occurred-during-get-ext-value",
350 log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id, "error": err})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800351 return nil, err
352 }
353 }
354 return resp, nil
355}
kesavand62126212021-01-12 04:56:06 -0500356
khenaidoo106c61a2021-08-11 18:05:46 -0400357//GetSingleValue handles get uni status on ONU and ondemand metric on OLT
358func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
359 logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request})
kesavand62126212021-01-12 04:56:06 -0500360
361 errResp := func(status extension.GetValueResponse_Status,
362 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
363 return &extension.SingleGetValueResponse{
364 Response: &extension.GetValueResponse{
365 Status: status,
366 ErrReason: reason,
367 },
368 }
369 }
370 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
371 switch reqType := request.GetRequest().GetRequest().(type) {
372 case *extension.GetValueRequest_OltPortInfo:
373 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530374 case *extension.GetValueRequest_OnuPonInfo:
375 return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil
Gamze Abaka85e9a142021-05-26 13:41:39 +0000376 case *extension.GetValueRequest_RxPower:
377 return handler.getRxPower(ctx, reqType.RxPower), nil
kesavand62126212021-01-12 04:56:06 -0500378 default:
379 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
380 }
381 }
382
383 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
384 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
385}
khenaidoo106c61a2021-08-11 18:05:46 -0400386
387/*
388 * OLT Inter-adapter service
389 */
390
kesavandb9f54fd2021-11-25 20:08:04 +0530391// ProxyOmciRequests proxies an onu sw download OMCI request from the child adapter
392func (oo *OpenOLT) ProxyOmciRequests(ctx context.Context, request *ia.OmciMessages) (*empty.Empty, error) {
393 if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil {
394 if err := handler.ProxyOmciRequests(ctx, request); err != nil {
Abhilash Laxmeshwar092e6ca2022-12-08 19:51:27 +0530395 return nil, err
kesavandb9f54fd2021-11-25 20:08:04 +0530396 }
397 return &empty.Empty{}, nil
398 }
399 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log()
400}
401
khenaidoo106c61a2021-08-11 18:05:46 -0400402// ProxyOmciRequest proxies an OMCI request from the child adapter
khenaidoodc2116e2021-10-19 17:33:19 -0400403func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400404 logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request})
405
406 if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil {
407 if err := handler.ProxyOmciMessage(ctx, request); err != nil {
Abhilash Laxmeshwar092e6ca2022-12-08 19:51:27 +0530408 return nil, err
khenaidoo106c61a2021-08-11 18:05:46 -0400409 }
410 return &empty.Empty{}, nil
411 }
412 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log()
413}
414
415// GetTechProfileInstance returns an instance of a tech profile
khenaidoodc2116e2021-10-19 17:33:19 -0400416func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ia.TechProfileInstanceRequestMessage) (*ia.TechProfileDownloadMessage, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400417 logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request})
418
419 targetDeviceID := request.ParentDeviceId
420 if targetDeviceID == "" {
421 return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
422 }
423 if handler := oo.getDeviceHandler(targetDeviceID); handler != nil {
424 return handler.GetTechProfileDownloadMessage(ctx, request)
425 }
426 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
427
428}
429
khenaidooefff76e2021-12-15 16:51:30 -0500430// GetHealthStatus is used by a OltAdapterService client to detect a connection
431// lost with the gRPC server hosting the OltAdapterService service
432func (oo *OpenOLT) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error {
433 ctx := context.Background()
434 logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream})
435
436 if stream == nil {
437 return fmt.Errorf("conn-is-nil %v", stream)
438 }
439 initialRequestTime := time.Now()
440 var remoteClient *common.Connection
441 var tempClient *common.Connection
442 var err error
443loop:
444 for {
445 tempClient, err = stream.Recv()
446 if err != nil {
447 logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
448 break loop
449 }
450 // Send a response back
451 err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY})
452 if err != nil {
453 logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
454 break loop
455 }
456
457 remoteClient = tempClient
458 logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient})
459
460 select {
461 case <-stream.Context().Done():
462 logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()})
463 break loop
464 case <-oo.exitChannel:
465 logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime})
466 break loop
467 default:
468 }
469 }
470 logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime})
471 return err
472}
473
khenaidoo106c61a2021-08-11 18:05:46 -0400474/*
475 *
476 * Unimplemented APIs
477 *
478 */
479
480//SimulateAlarm is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400481func (oo *OpenOLT) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*voltha.OperationResp, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400482 return nil, olterrors.ErrNotImplemented
483}
484
485//SetExtValue is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400486func (oo *OpenOLT) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400487 return nil, olterrors.ErrNotImplemented
488}
489
490//SetSingleValue is unimplemented
491func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
492 return nil, olterrors.ErrNotImplemented
493}
494
495//StartOmciTest not implemented
khenaidoodc2116e2021-10-19 17:33:19 -0400496func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400497 return nil, olterrors.ErrNotImplemented
498}
499
500//SuppressEvent unimplemented
501func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
502 return nil, olterrors.ErrNotImplemented
503}
504
505//UnSuppressEvent unimplemented
506func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
507 return nil, olterrors.ErrNotImplemented
508}
509
510//DownloadImage is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400511func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400512 return nil, olterrors.ErrNotImplemented
513}
514
515//GetImageDownloadStatus is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400516func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400517 return nil, olterrors.ErrNotImplemented
518}
519
520//CancelImageDownload is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400521func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400522 return nil, olterrors.ErrNotImplemented
523}
524
525//ActivateImageUpdate is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400526func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400527 return nil, olterrors.ErrNotImplemented
528}
529
530//RevertImageUpdate is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400531func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400532 return nil, olterrors.ErrNotImplemented
533}
534
535//DownloadOnuImage unimplemented
536func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
537 return nil, olterrors.ErrNotImplemented
538}
539
540//GetOnuImageStatus unimplemented
541func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
542 return nil, olterrors.ErrNotImplemented
543}
544
545//AbortOnuImageUpgrade unimplemented
546func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
547 return nil, olterrors.ErrNotImplemented
548}
549
550//GetOnuImages unimplemented
551func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) {
552 return nil, olterrors.ErrNotImplemented
553}
554
555//ActivateOnuImage unimplemented
556func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
557 return nil, olterrors.ErrNotImplemented
558}
559
560//CommitOnuImage unimplemented
561func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
562 return nil, olterrors.ErrNotImplemented
563}
564
565// UpdateFlowsBulk is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400566func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400567 return nil, olterrors.ErrNotImplemented
568}
569
570//SelfTestDevice unimplemented
571func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
572 return nil, olterrors.ErrNotImplemented
573}