blob: f84910de2afc5de2d2c2e36bd59a2ef5dd96629a [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"
34 "github.com/opencord/voltha-protos/v5/go/extension"
35 ic "github.com/opencord/voltha-protos/v5/go/inter_container"
36 "github.com/opencord/voltha-protos/v5/go/voltha"
Girish Gowdru0c588b22019-04-23 23:24:56 -040037)
38
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070039//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040040type OpenOLT struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -080041 configManager *conf.ConfigManager
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053042 deviceHandlers map[string]*DeviceHandler
khenaidoo106c61a2021-08-11 18:05:46 -040043 coreClient *vgrpc.Client
Himani Chawlacd407802020-12-10 12:08:59 +053044 eventProxy eventif.EventProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053045 config *config.AdapterFlags
46 numOnus int
Neha Sharma3f221ae2020-04-29 19:02:12 +000047 KVStoreAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053048 KVStoreType string
49 exitChannel chan int
50 HeartbeatCheckInterval time.Duration
51 HeartbeatFailReportInterval time.Duration
52 GrpcTimeoutInterval time.Duration
53 lockDeviceHandlersMap sync.RWMutex
Gamze Abakafcbd6e72020-12-17 13:25:16 +000054 enableONUStats bool
55 enableGemStats bool
khenaidoo106c61a2021-08-11 18:05:46 -040056 rpcTimeout time.Duration
Girish Gowdru0c588b22019-04-23 23:24:56 -040057}
58
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070059//NewOpenOLT returns a new instance of OpenOLT
khenaidoo106c61a2021-08-11 18:05:46 -040060func NewOpenOLT(ctx context.Context,
61 coreClient *vgrpc.Client,
Himani Chawlacd407802020-12-10 12:08:59 +053062 eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040063 var openOLT OpenOLT
64 openOLT.exitChannel = make(chan int, 1)
65 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053066 openOLT.config = cfg
67 openOLT.numOnus = cfg.OnuNumber
khenaidoo106c61a2021-08-11 18:05:46 -040068 openOLT.coreClient = coreClient
Devmalya Paulfb990a52019-07-09 10:01:49 -040069 openOLT.eventProxy = eventProxy
Neha Sharma3f221ae2020-04-29 19:02:12 +000070 openOLT.KVStoreAddress = cfg.KVStoreAddress
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053071 openOLT.KVStoreType = cfg.KVStoreType
72 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
73 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
74 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040075 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
Matteo Scandolodfa7a972020-11-06 13:03:40 -080076 openOLT.configManager = cm
Gamze Abakafcbd6e72020-12-17 13:25:16 +000077 openOLT.enableONUStats = cfg.EnableONUStats
78 openOLT.enableGemStats = cfg.EnableGEMStats
khenaidoo106c61a2021-08-11 18:05:46 -040079 openOLT.rpcTimeout = cfg.RPCTimeout
Girish Gowdru0c588b22019-04-23 23:24:56 -040080 return &openOLT
81}
82
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070083//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040084func (oo *OpenOLT) Start(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000085 logger.Info(ctx, "starting-device-manager")
86 logger.Info(ctx, "device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 return nil
88}
89
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070090//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040091func (oo *OpenOLT) Stop(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000092 logger.Info(ctx, "stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040093 oo.exitChannel <- 1
Neha Sharma96b7bf22020-06-15 10:37:32 +000094 logger.Info(ctx, "device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040095 return nil
96}
97
Girish Gowdru0c588b22019-04-23 23:24:56 -040098func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
99 oo.lockDeviceHandlersMap.Lock()
100 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530101 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
102 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400103 }
104}
105
106func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
107 oo.lockDeviceHandlersMap.Lock()
108 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530109 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110}
111
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700112func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400113 oo.lockDeviceHandlersMap.Lock()
114 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700115 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400116 return agent
117 }
118 return nil
119}
120
khenaidoo106c61a2021-08-11 18:05:46 -0400121// GetHealthStatus is used as a service readiness validation as a grpc connection
122func (oo *OpenOLT) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) {
123 return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil
124}
125
126// AdoptDevice creates a new device handler if not present already and then adopts the device
127func (oo *OpenOLT) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400129 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400130 }
divyadesai3af43e12020-08-18 07:10:54 +0000131 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400132 var handler *DeviceHandler
133 if handler = oo.getDeviceHandler(device.Id); handler == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400134 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400135 oo.addDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400136 go handler.AdoptDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400137 }
khenaidoo106c61a2021-08-11 18:05:46 -0400138 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400139}
140
khenaidoo106c61a2021-08-11 18:05:46 -0400141//GetOfpDeviceInfo returns OFP information for the given device
142func (oo *OpenOLT) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
143 logger.Infow(ctx, "get_ofp_device_info", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144 if handler := oo.getDeviceHandler(device.Id); handler != nil {
145 return handler.GetOfpDeviceInfo(device)
146 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000147 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400148}
149
khenaidoo106c61a2021-08-11 18:05:46 -0400150//ReconcileDevice unimplemented
151func (oo *OpenOLT) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530152 if device == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400153 return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530154 }
divyadesai3af43e12020-08-18 07:10:54 +0000155 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530156 var handler *DeviceHandler
157 if handler = oo.getDeviceHandler(device.Id); handler == nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400158 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
Gamze Abakac2c32a62021-03-11 11:44:18 +0000159 handler.adapterPreviouslyConnected = true
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530160 oo.addDeviceHandlerToMap(handler)
161 handler.transitionMap = NewTransitionMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400162
Manindere49938d2021-03-19 00:23:24 +0530163 //Setting state to RECONCILING
khenaidoo106c61a2021-08-11 18:05:46 -0400164 cgClient, err := oo.coreClient.GetCoreServiceClient()
Manindere49938d2021-03-19 00:23:24 +0530165 if err != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400166 return nil, err
Manindere49938d2021-03-19 00:23:24 +0530167 }
khenaidoo106c61a2021-08-11 18:05:46 -0400168 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout)
169 defer cancel()
170 if _, err := cgClient.DeviceStateUpdate(subCtx, &ic.DeviceStateFilter{
171 DeviceId: device.Id,
172 OperStatus: voltha.OperStatus_RECONCILING,
173 ConnStatus: device.ConnectStatus,
174 }); err != nil {
175 return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err)
176 }
177
178 handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530179 }
khenaidoo106c61a2021-08-11 18:05:46 -0400180 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400181}
182
khenaidoo106c61a2021-08-11 18:05:46 -0400183//DisableDevice disables the given device
184func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000185 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400186 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400187 if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
188 return nil, err
189 }
190 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400191 }
khenaidoo106c61a2021-08-11 18:05:46 -0400192 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400193}
194
khenaidoo106c61a2021-08-11 18:05:46 -0400195//ReEnableDevice enables the olt device after disable
196func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000197 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400198 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400199 if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
200 return nil, err
201 }
202 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400203 }
khenaidoo106c61a2021-08-11 18:05:46 -0400204 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400205}
206
khenaidoo106c61a2021-08-11 18:05:46 -0400207//RebootDevice reboots the given device
208func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000209 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400210 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400211 if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
212 return nil, err
213 }
214 return &empty.Empty{}, nil
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400215 }
khenaidoo106c61a2021-08-11 18:05:46 -0400216 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
217
Girish Gowdru0c588b22019-04-23 23:24:56 -0400218}
219
khenaidoo106c61a2021-08-11 18:05:46 -0400220//DeleteDevice deletes a device
221func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000222 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400223 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400224 if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000225 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400226 }
227 oo.deleteDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400228 return &empty.Empty{}, nil
Devmalya Paul495b94a2019-08-27 19:42:00 -0400229 }
khenaidoo106c61a2021-08-11 18:05:46 -0400230 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400231}
232
khenaidoo106c61a2021-08-11 18:05:46 -0400233//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
234func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) {
235 logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata})
236 if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil {
237 if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
238 return nil, err
239 }
240 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400241 }
khenaidoo106c61a2021-08-11 18:05:46 -0400242 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": incrFlows.Device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243}
244
khenaidoo106c61a2021-08-11 18:05:46 -0400245//UpdatePmConfig returns PmConfigs nil or error
246func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) {
247 logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs})
248 if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil {
249 handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs)
250 return &empty.Empty{}, nil
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000251 }
khenaidoo106c61a2021-08-11 18:05:46 -0400252 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": configs.DeviceId}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400253}
254
khenaidoo106c61a2021-08-11 18:05:46 -0400255//SendPacketOut sends packet out to the device
256func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) {
257 logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet})
258 if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil {
259 if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil {
260 return nil, err
261 }
262 return &empty.Empty{}, nil
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400263 }
khenaidoo106c61a2021-08-11 18:05:46 -0400264 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil)
265
Girish Gowdru0c588b22019-04-23 23:24:56 -0400266}
267
khenaidoo106c61a2021-08-11 18:05:46 -0400268// EnablePort to Enable PON/NNI interface
269func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
270 logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port})
271 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil {
272 return nil, err
273 }
274 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400275}
276
khenaidoo106c61a2021-08-11 18:05:46 -0400277// DisablePort to Disable pon/nni interface
278func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
279 logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port})
280 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil {
281 return nil, err
282 }
283 return &empty.Empty{}, nil
kesavand39e0aa32020-01-28 20:58:50 -0500284}
285
286// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000287func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000288 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500289 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530290 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800291 "reason": "port cannot be nil",
292 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000293 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500294 }
295 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000296 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500297 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000298 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000299 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500300 }
301 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000302 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000303 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500304 }
305 }
306 }
307 return nil
308}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500309
khenaidoo106c61a2021-08-11 18:05:46 -0400310//ChildDeviceLost deletes the ONU and its references from PONResources
311func (oo *OpenOLT) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
Girish Gowdraa0870562021-03-11 14:30:14 -0800312 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id})
313 if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400314 if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil {
315 return nil, err
316 }
317 return &empty.Empty{}, nil
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500318 }
khenaidoo106c61a2021-08-11 18:05:46 -0400319 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"parent-device-id": childDevice.ParentId}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500320}
Scott Baker24f83e22020-03-30 16:14:28 -0700321
khenaidoo106c61a2021-08-11 18:05:46 -0400322// GetExtValue retrieves a value on a particular ONU
323func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ic.GetExtValueMessage) (*voltha.ReturnValues, error) {
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800324 var err error
325 resp := new(voltha.ReturnValues)
khenaidoo106c61a2021-08-11 18:05:46 -0400326 logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id})
327 if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil {
328 if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil {
329 logger.Errorw(ctx, "error-occurred-during-get-ext-value",
330 log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id, "error": err})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800331 return nil, err
332 }
333 }
334 return resp, nil
335}
kesavand62126212021-01-12 04:56:06 -0500336
khenaidoo106c61a2021-08-11 18:05:46 -0400337//GetSingleValue handles get uni status on ONU and ondemand metric on OLT
338func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
339 logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request})
kesavand62126212021-01-12 04:56:06 -0500340
341 errResp := func(status extension.GetValueResponse_Status,
342 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
343 return &extension.SingleGetValueResponse{
344 Response: &extension.GetValueResponse{
345 Status: status,
346 ErrReason: reason,
347 },
348 }
349 }
350 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
351 switch reqType := request.GetRequest().GetRequest().(type) {
352 case *extension.GetValueRequest_OltPortInfo:
353 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530354 case *extension.GetValueRequest_OnuPonInfo:
355 return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil
Gamze Abaka85e9a142021-05-26 13:41:39 +0000356 case *extension.GetValueRequest_RxPower:
357 return handler.getRxPower(ctx, reqType.RxPower), nil
kesavand62126212021-01-12 04:56:06 -0500358 default:
359 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
360 }
361 }
362
363 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
364 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
365}
khenaidoo106c61a2021-08-11 18:05:46 -0400366
367/*
368 * OLT Inter-adapter service
369 */
370
371// ProxyOmciRequest proxies an OMCI request from the child adapter
372func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ic.OmciMessage) (*empty.Empty, error) {
373 logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request})
374
375 if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil {
376 if err := handler.ProxyOmciMessage(ctx, request); err != nil {
377 return nil, errors.New(err.Error())
378 }
379 return &empty.Empty{}, nil
380 }
381 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log()
382}
383
384// GetTechProfileInstance returns an instance of a tech profile
385func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) {
386 logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request})
387
388 targetDeviceID := request.ParentDeviceId
389 if targetDeviceID == "" {
390 return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
391 }
392 if handler := oo.getDeviceHandler(targetDeviceID); handler != nil {
393 return handler.GetTechProfileDownloadMessage(ctx, request)
394 }
395 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
396
397}
398
399/*
400 *
401 * Unimplemented APIs
402 *
403 */
404
405//SimulateAlarm is unimplemented
406func (oo *OpenOLT) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*voltha.OperationResp, error) {
407 return nil, olterrors.ErrNotImplemented
408}
409
410//SetExtValue is unimplemented
411func (oo *OpenOLT) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) {
412 return nil, olterrors.ErrNotImplemented
413}
414
415//SetSingleValue is unimplemented
416func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
417 return nil, olterrors.ErrNotImplemented
418}
419
420//StartOmciTest not implemented
421func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) {
422 return nil, olterrors.ErrNotImplemented
423}
424
425//SuppressEvent unimplemented
426func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
427 return nil, olterrors.ErrNotImplemented
428}
429
430//UnSuppressEvent unimplemented
431func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
432 return nil, olterrors.ErrNotImplemented
433}
434
435//DownloadImage is unimplemented
436func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
437 return nil, olterrors.ErrNotImplemented
438}
439
440//GetImageDownloadStatus is unimplemented
441func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
442 return nil, olterrors.ErrNotImplemented
443}
444
445//CancelImageDownload is unimplemented
446func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
447 return nil, olterrors.ErrNotImplemented
448}
449
450//ActivateImageUpdate is unimplemented
451func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
452 return nil, olterrors.ErrNotImplemented
453}
454
455//RevertImageUpdate is unimplemented
456func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
457 return nil, olterrors.ErrNotImplemented
458}
459
460//DownloadOnuImage unimplemented
461func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
462 return nil, olterrors.ErrNotImplemented
463}
464
465//GetOnuImageStatus unimplemented
466func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
467 return nil, olterrors.ErrNotImplemented
468}
469
470//AbortOnuImageUpgrade unimplemented
471func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
472 return nil, olterrors.ErrNotImplemented
473}
474
475//GetOnuImages unimplemented
476func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) {
477 return nil, olterrors.ErrNotImplemented
478}
479
480//ActivateOnuImage unimplemented
481func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
482 return nil, olterrors.ErrNotImplemented
483}
484
485//CommitOnuImage unimplemented
486func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
487 return nil, olterrors.ErrNotImplemented
488}
489
490// UpdateFlowsBulk is unimplemented
491func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) {
492 return nil, olterrors.ErrNotImplemented
493}
494
495//SelfTestDevice unimplemented
496func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
497 return nil, olterrors.ErrNotImplemented
498}