blob: 9e7cba245b4e35f241c194a3b801089d074b6b11 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
2 * Copyright 2018-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 */
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"
khenaidoo106c61a2021-08-11 18:05:46 -040022 "errors"
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"
khenaidoo106c61a2021-08-11 18:05:46 -040033 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoodc2116e2021-10-19 17:33:19 -040034 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo106c61a2021-08-11 18:05:46 -040035 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoodc2116e2021-10-19 17:33:19 -040036 "github.com/opencord/voltha-protos/v5/go/health"
37 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
38 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidoo106c61a2021-08-11 18:05:46 -040039 "github.com/opencord/voltha-protos/v5/go/voltha"
Girish Gowdru0c588b22019-04-23 23:24:56 -040040)
41
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070042//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040043type OpenOLT struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -080044 configManager *conf.ConfigManager
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053045 deviceHandlers map[string]*DeviceHandler
khenaidoo106c61a2021-08-11 18:05:46 -040046 coreClient *vgrpc.Client
Himani Chawlacd407802020-12-10 12:08:59 +053047 eventProxy eventif.EventProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053048 config *config.AdapterFlags
49 numOnus int
Neha Sharma3f221ae2020-04-29 19:02:12 +000050 KVStoreAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053051 KVStoreType string
52 exitChannel chan int
53 HeartbeatCheckInterval time.Duration
54 HeartbeatFailReportInterval time.Duration
55 GrpcTimeoutInterval time.Duration
56 lockDeviceHandlersMap sync.RWMutex
Gamze Abakafcbd6e72020-12-17 13:25:16 +000057 enableONUStats bool
58 enableGemStats bool
khenaidoo106c61a2021-08-11 18:05:46 -040059 rpcTimeout time.Duration
Girish Gowdru0c588b22019-04-23 23:24:56 -040060}
61
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070062//NewOpenOLT returns a new instance of OpenOLT
khenaidoo106c61a2021-08-11 18:05:46 -040063func NewOpenOLT(ctx context.Context,
64 coreClient *vgrpc.Client,
Himani Chawlacd407802020-12-10 12:08:59 +053065 eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040066 var openOLT OpenOLT
67 openOLT.exitChannel = make(chan int, 1)
68 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053069 openOLT.config = cfg
70 openOLT.numOnus = cfg.OnuNumber
khenaidoo106c61a2021-08-11 18:05:46 -040071 openOLT.coreClient = coreClient
Devmalya Paulfb990a52019-07-09 10:01:49 -040072 openOLT.eventProxy = eventProxy
Neha Sharma3f221ae2020-04-29 19:02:12 +000073 openOLT.KVStoreAddress = cfg.KVStoreAddress
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053074 openOLT.KVStoreType = cfg.KVStoreType
75 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
76 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
77 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040078 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
Matteo Scandolodfa7a972020-11-06 13:03:40 -080079 openOLT.configManager = cm
Gamze Abakafcbd6e72020-12-17 13:25:16 +000080 openOLT.enableONUStats = cfg.EnableONUStats
81 openOLT.enableGemStats = cfg.EnableGEMStats
khenaidoo106c61a2021-08-11 18:05:46 -040082 openOLT.rpcTimeout = cfg.RPCTimeout
Girish Gowdru0c588b22019-04-23 23:24:56 -040083 return &openOLT
84}
85
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070086//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040087func (oo *OpenOLT) Start(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000088 logger.Info(ctx, "starting-device-manager")
89 logger.Info(ctx, "device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040090 return nil
91}
92
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070093//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040094func (oo *OpenOLT) Stop(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000095 logger.Info(ctx, "stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040096 oo.exitChannel <- 1
Neha Sharma96b7bf22020-06-15 10:37:32 +000097 logger.Info(ctx, "device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040098 return nil
99}
100
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
102 oo.lockDeviceHandlersMap.Lock()
103 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530104 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
105 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400106 }
107}
108
109func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
110 oo.lockDeviceHandlersMap.Lock()
111 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530112 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400113}
114
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700115func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400116 oo.lockDeviceHandlersMap.Lock()
117 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700118 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400119 return agent
120 }
121 return nil
122}
123
khenaidoo106c61a2021-08-11 18:05:46 -0400124// GetHealthStatus is used as a service readiness validation as a grpc connection
khenaidoodc2116e2021-10-19 17:33:19 -0400125func (oo *OpenOLT) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*health.HealthStatus, error) {
126 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
khenaidoo106c61a2021-08-11 18:05:46 -0400127}
128
129// AdoptDevice creates a new device handler if not present already and then adopts the device
130func (oo *OpenOLT) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400131 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400132 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 }
divyadesai3af43e12020-08-18 07:10:54 +0000134 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400135 var handler *DeviceHandler
136 if handler = oo.getDeviceHandler(device.Id); handler == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400137 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400138 oo.addDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400139 go handler.AdoptDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140 }
khenaidoo106c61a2021-08-11 18:05:46 -0400141 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142}
143
khenaidoo106c61a2021-08-11 18:05:46 -0400144//GetOfpDeviceInfo returns OFP information for the given device
khenaidoodc2116e2021-10-19 17:33:19 -0400145func (oo *OpenOLT) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400146 logger.Infow(ctx, "get_ofp_device_info", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400147 if handler := oo.getDeviceHandler(device.Id); handler != nil {
148 return handler.GetOfpDeviceInfo(device)
149 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000150 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151}
152
khenaidoo106c61a2021-08-11 18:05:46 -0400153//ReconcileDevice unimplemented
154func (oo *OpenOLT) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530155 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400156 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530157 }
divyadesai3af43e12020-08-18 07:10:54 +0000158 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530159 var handler *DeviceHandler
160 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Manindere49938d2021-03-19 00:23:24 +0530161 //Setting state to RECONCILING
khenaidoo106c61a2021-08-11 18:05:46 -0400162 cgClient, err := oo.coreClient.GetCoreServiceClient()
Manindere49938d2021-03-19 00:23:24 +0530163 if err != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400164 return nil, err
Manindere49938d2021-03-19 00:23:24 +0530165 }
khenaidoo106c61a2021-08-11 18:05:46 -0400166 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout)
167 defer cancel()
khenaidoodc2116e2021-10-19 17:33:19 -0400168 if _, err := cgClient.DeviceStateUpdate(subCtx, &ca.DeviceStateFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400169 DeviceId: device.Id,
170 OperStatus: voltha.OperStatus_RECONCILING,
171 ConnStatus: device.ConnectStatus,
172 }); err != nil {
173 return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err)
174 }
175
Girish Gowdra0fb24a32021-10-27 15:15:27 -0700176 // The OperState of the device is set to RECONCILING in the previous section. This also needs to be set on the
177 // locally cached copy of the device struct.
178 device.OperStatus = voltha.OperStatus_RECONCILING
179 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
180 handler.adapterPreviouslyConnected = true
181 oo.addDeviceHandlerToMap(handler)
182 handler.transitionMap = NewTransitionMap(handler)
183
khenaidoo106c61a2021-08-11 18:05:46 -0400184 handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530185 }
khenaidoo106c61a2021-08-11 18:05:46 -0400186 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400187}
188
khenaidoo106c61a2021-08-11 18:05:46 -0400189//DisableDevice disables the given device
190func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000191 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400192 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400193 if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
194 return nil, err
195 }
196 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400197 }
khenaidoo106c61a2021-08-11 18:05:46 -0400198 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400199}
200
khenaidoo106c61a2021-08-11 18:05:46 -0400201//ReEnableDevice enables the olt device after disable
202func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000203 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400204 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400205 if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
206 return nil, err
207 }
208 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400209 }
khenaidoo106c61a2021-08-11 18:05:46 -0400210 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400211}
212
khenaidoo106c61a2021-08-11 18:05:46 -0400213//RebootDevice reboots the given device
214func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000215 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400216 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400217 if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
218 return nil, err
219 }
220 return &empty.Empty{}, nil
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400221 }
khenaidoo106c61a2021-08-11 18:05:46 -0400222 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
223
Girish Gowdru0c588b22019-04-23 23:24:56 -0400224}
225
khenaidoo106c61a2021-08-11 18:05:46 -0400226//DeleteDevice deletes a device
227func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000228 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400229 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400230 if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000231 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400232 }
233 oo.deleteDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400234 return &empty.Empty{}, nil
Devmalya Paul495b94a2019-08-27 19:42:00 -0400235 }
khenaidoo106c61a2021-08-11 18:05:46 -0400236 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237}
238
khenaidoo106c61a2021-08-11 18:05:46 -0400239//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoodc2116e2021-10-19 17:33:19 -0400240func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400241 logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata})
242 if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil {
243 if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
244 return nil, err
245 }
246 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400247 }
khenaidoo106c61a2021-08-11 18:05:46 -0400248 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": incrFlows.Device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400249}
250
khenaidoo106c61a2021-08-11 18:05:46 -0400251//UpdatePmConfig returns PmConfigs nil or error
khenaidoodc2116e2021-10-19 17:33:19 -0400252func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400253 logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs})
254 if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil {
255 handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs)
256 return &empty.Empty{}, nil
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000257 }
khenaidoo106c61a2021-08-11 18:05:46 -0400258 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": configs.DeviceId}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400259}
260
khenaidoo106c61a2021-08-11 18:05:46 -0400261//SendPacketOut sends packet out to the device
khenaidoodc2116e2021-10-19 17:33:19 -0400262func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400263 logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet})
264 if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil {
265 if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil {
266 return nil, err
267 }
268 return &empty.Empty{}, nil
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400269 }
khenaidoo106c61a2021-08-11 18:05:46 -0400270 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil)
271
Girish Gowdru0c588b22019-04-23 23:24:56 -0400272}
273
khenaidoo106c61a2021-08-11 18:05:46 -0400274// EnablePort to Enable PON/NNI interface
275func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
276 logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port})
277 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil {
278 return nil, err
279 }
280 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400281}
282
khenaidoo106c61a2021-08-11 18:05:46 -0400283// DisablePort to Disable pon/nni interface
284func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
285 logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port})
286 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil {
287 return nil, err
288 }
289 return &empty.Empty{}, nil
kesavand39e0aa32020-01-28 20:58:50 -0500290}
291
292// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000293func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000294 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500295 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530296 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800297 "reason": "port cannot be nil",
298 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000299 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500300 }
301 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000302 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500303 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000304 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000305 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500306 }
307 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000308 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000309 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500310 }
311 }
312 }
313 return nil
314}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500315
khenaidoo106c61a2021-08-11 18:05:46 -0400316//ChildDeviceLost deletes the ONU and its references from PONResources
317func (oo *OpenOLT) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
Girish Gowdraa0870562021-03-11 14:30:14 -0800318 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id})
319 if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400320 if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil {
321 return nil, err
322 }
323 return &empty.Empty{}, nil
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500324 }
khenaidoo106c61a2021-08-11 18:05:46 -0400325 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"parent-device-id": childDevice.ParentId}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500326}
Scott Baker24f83e22020-03-30 16:14:28 -0700327
khenaidoo106c61a2021-08-11 18:05:46 -0400328// GetExtValue retrieves a value on a particular ONU
khenaidoodc2116e2021-10-19 17:33:19 -0400329func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800330 var err error
khenaidoodc2116e2021-10-19 17:33:19 -0400331 resp := new(extension.ReturnValues)
khenaidoo106c61a2021-08-11 18:05:46 -0400332 logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id})
333 if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil {
334 if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil {
335 logger.Errorw(ctx, "error-occurred-during-get-ext-value",
336 log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id, "error": err})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800337 return nil, err
338 }
339 }
340 return resp, nil
341}
kesavand62126212021-01-12 04:56:06 -0500342
khenaidoo106c61a2021-08-11 18:05:46 -0400343//GetSingleValue handles get uni status on ONU and ondemand metric on OLT
344func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
345 logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request})
kesavand62126212021-01-12 04:56:06 -0500346
347 errResp := func(status extension.GetValueResponse_Status,
348 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
349 return &extension.SingleGetValueResponse{
350 Response: &extension.GetValueResponse{
351 Status: status,
352 ErrReason: reason,
353 },
354 }
355 }
356 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
357 switch reqType := request.GetRequest().GetRequest().(type) {
358 case *extension.GetValueRequest_OltPortInfo:
359 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530360 case *extension.GetValueRequest_OnuPonInfo:
361 return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil
Gamze Abaka85e9a142021-05-26 13:41:39 +0000362 case *extension.GetValueRequest_RxPower:
363 return handler.getRxPower(ctx, reqType.RxPower), nil
kesavand62126212021-01-12 04:56:06 -0500364 default:
365 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
366 }
367 }
368
369 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
370 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
371}
khenaidoo106c61a2021-08-11 18:05:46 -0400372
373/*
374 * OLT Inter-adapter service
375 */
376
377// ProxyOmciRequest proxies an OMCI request from the child adapter
khenaidoodc2116e2021-10-19 17:33:19 -0400378func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400379 logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request})
380
381 if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil {
382 if err := handler.ProxyOmciMessage(ctx, request); err != nil {
383 return nil, errors.New(err.Error())
384 }
385 return &empty.Empty{}, nil
386 }
387 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log()
388}
389
390// GetTechProfileInstance returns an instance of a tech profile
khenaidoodc2116e2021-10-19 17:33:19 -0400391func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ia.TechProfileInstanceRequestMessage) (*ia.TechProfileDownloadMessage, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400392 logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request})
393
394 targetDeviceID := request.ParentDeviceId
395 if targetDeviceID == "" {
396 return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
397 }
398 if handler := oo.getDeviceHandler(targetDeviceID); handler != nil {
399 return handler.GetTechProfileDownloadMessage(ctx, request)
400 }
401 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
402
403}
404
405/*
406 *
407 * Unimplemented APIs
408 *
409 */
410
411//SimulateAlarm is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400412func (oo *OpenOLT) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*voltha.OperationResp, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400413 return nil, olterrors.ErrNotImplemented
414}
415
416//SetExtValue is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400417func (oo *OpenOLT) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400418 return nil, olterrors.ErrNotImplemented
419}
420
421//SetSingleValue is unimplemented
422func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
423 return nil, olterrors.ErrNotImplemented
424}
425
426//StartOmciTest not implemented
khenaidoodc2116e2021-10-19 17:33:19 -0400427func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400428 return nil, olterrors.ErrNotImplemented
429}
430
431//SuppressEvent unimplemented
432func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
433 return nil, olterrors.ErrNotImplemented
434}
435
436//UnSuppressEvent unimplemented
437func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
438 return nil, olterrors.ErrNotImplemented
439}
440
441//DownloadImage is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400442func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400443 return nil, olterrors.ErrNotImplemented
444}
445
446//GetImageDownloadStatus is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400447func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400448 return nil, olterrors.ErrNotImplemented
449}
450
451//CancelImageDownload is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400452func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400453 return nil, olterrors.ErrNotImplemented
454}
455
456//ActivateImageUpdate is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400457func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400458 return nil, olterrors.ErrNotImplemented
459}
460
461//RevertImageUpdate is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400462func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400463 return nil, olterrors.ErrNotImplemented
464}
465
466//DownloadOnuImage unimplemented
467func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
468 return nil, olterrors.ErrNotImplemented
469}
470
471//GetOnuImageStatus unimplemented
472func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
473 return nil, olterrors.ErrNotImplemented
474}
475
476//AbortOnuImageUpgrade unimplemented
477func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
478 return nil, olterrors.ErrNotImplemented
479}
480
481//GetOnuImages unimplemented
482func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) {
483 return nil, olterrors.ErrNotImplemented
484}
485
486//ActivateOnuImage unimplemented
487func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
488 return nil, olterrors.ErrNotImplemented
489}
490
491//CommitOnuImage unimplemented
492func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
493 return nil, olterrors.ErrNotImplemented
494}
495
496// UpdateFlowsBulk is unimplemented
khenaidoodc2116e2021-10-19 17:33:19 -0400497func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo106c61a2021-08-11 18:05:46 -0400498 return nil, olterrors.ErrNotImplemented
499}
500
501//SelfTestDevice unimplemented
502func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
503 return nil, olterrors.ErrNotImplemented
504}