blob: 30aa33cb7f6c62c69914fdb75736dc343d753f27 [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 {
Manindere49938d2021-03-19 00:23:24 +0530158 //Setting state to RECONCILING
khenaidoo106c61a2021-08-11 18:05:46 -0400159 cgClient, err := oo.coreClient.GetCoreServiceClient()
Manindere49938d2021-03-19 00:23:24 +0530160 if err != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400161 return nil, err
Manindere49938d2021-03-19 00:23:24 +0530162 }
khenaidoo106c61a2021-08-11 18:05:46 -0400163 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout)
164 defer cancel()
165 if _, err := cgClient.DeviceStateUpdate(subCtx, &ic.DeviceStateFilter{
166 DeviceId: device.Id,
167 OperStatus: voltha.OperStatus_RECONCILING,
168 ConnStatus: device.ConnectStatus,
169 }); err != nil {
170 return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err)
171 }
172
Girish Gowdra0fb24a32021-10-27 15:15:27 -0700173 // The OperState of the device is set to RECONCILING in the previous section. This also needs to be set on the
174 // locally cached copy of the device struct.
175 device.OperStatus = voltha.OperStatus_RECONCILING
176 handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config)
177 handler.adapterPreviouslyConnected = true
178 oo.addDeviceHandlerToMap(handler)
179 handler.transitionMap = NewTransitionMap(handler)
180
khenaidoo106c61a2021-08-11 18:05:46 -0400181 handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530182 }
khenaidoo106c61a2021-08-11 18:05:46 -0400183 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400184}
185
khenaidoo106c61a2021-08-11 18:05:46 -0400186//DisableDevice disables the given device
187func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000188 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400189 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400190 if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
191 return nil, err
192 }
193 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400194 }
khenaidoo106c61a2021-08-11 18:05:46 -0400195 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196}
197
khenaidoo106c61a2021-08-11 18:05:46 -0400198//ReEnableDevice enables the olt device after disable
199func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000200 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400201 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400202 if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
203 return nil, err
204 }
205 return &empty.Empty{}, nil
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400206 }
khenaidoo106c61a2021-08-11 18:05:46 -0400207 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400208}
209
khenaidoo106c61a2021-08-11 18:05:46 -0400210//RebootDevice reboots the given device
211func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000212 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400213 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400214 if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
215 return nil, err
216 }
217 return &empty.Empty{}, nil
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400218 }
khenaidoo106c61a2021-08-11 18:05:46 -0400219 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
220
Girish Gowdru0c588b22019-04-23 23:24:56 -0400221}
222
khenaidoo106c61a2021-08-11 18:05:46 -0400223//DeleteDevice deletes a device
224func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000225 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400226 if handler := oo.getDeviceHandler(device.Id); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400227 if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000228 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400229 }
230 oo.deleteDeviceHandlerToMap(handler)
khenaidoo106c61a2021-08-11 18:05:46 -0400231 return &empty.Empty{}, nil
Devmalya Paul495b94a2019-08-27 19:42:00 -0400232 }
khenaidoo106c61a2021-08-11 18:05:46 -0400233 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400234}
235
khenaidoo106c61a2021-08-11 18:05:46 -0400236//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
237func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) {
238 logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata})
239 if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil {
240 if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
241 return nil, err
242 }
243 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400244 }
khenaidoo106c61a2021-08-11 18:05:46 -0400245 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": incrFlows.Device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400246}
247
khenaidoo106c61a2021-08-11 18:05:46 -0400248//UpdatePmConfig returns PmConfigs nil or error
249func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) {
250 logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs})
251 if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil {
252 handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs)
253 return &empty.Empty{}, nil
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000254 }
khenaidoo106c61a2021-08-11 18:05:46 -0400255 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": configs.DeviceId}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400256}
257
khenaidoo106c61a2021-08-11 18:05:46 -0400258//SendPacketOut sends packet out to the device
259func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) {
260 logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet})
261 if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil {
262 if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil {
263 return nil, err
264 }
265 return &empty.Empty{}, nil
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400266 }
khenaidoo106c61a2021-08-11 18:05:46 -0400267 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil)
268
Girish Gowdru0c588b22019-04-23 23:24:56 -0400269}
270
khenaidoo106c61a2021-08-11 18:05:46 -0400271// EnablePort to Enable PON/NNI interface
272func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
273 logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port})
274 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil {
275 return nil, err
276 }
277 return &empty.Empty{}, nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400278}
279
khenaidoo106c61a2021-08-11 18:05:46 -0400280// DisablePort to Disable pon/nni interface
281func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
282 logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port})
283 if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil {
284 return nil, err
285 }
286 return &empty.Empty{}, nil
kesavand39e0aa32020-01-28 20:58:50 -0500287}
288
289// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000290func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000291 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500292 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530293 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800294 "reason": "port cannot be nil",
295 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000296 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500297 }
298 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000299 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500300 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000301 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000302 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500303 }
304 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000305 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000306 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500307 }
308 }
309 }
310 return nil
311}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500312
khenaidoo106c61a2021-08-11 18:05:46 -0400313//ChildDeviceLost deletes the ONU and its references from PONResources
314func (oo *OpenOLT) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
Girish Gowdraa0870562021-03-11 14:30:14 -0800315 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id})
316 if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil {
khenaidoo106c61a2021-08-11 18:05:46 -0400317 if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil {
318 return nil, err
319 }
320 return &empty.Empty{}, nil
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500321 }
khenaidoo106c61a2021-08-11 18:05:46 -0400322 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"parent-device-id": childDevice.ParentId}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500323}
Scott Baker24f83e22020-03-30 16:14:28 -0700324
khenaidoo106c61a2021-08-11 18:05:46 -0400325// GetExtValue retrieves a value on a particular ONU
326func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ic.GetExtValueMessage) (*voltha.ReturnValues, error) {
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800327 var err error
328 resp := new(voltha.ReturnValues)
khenaidoo106c61a2021-08-11 18:05:46 -0400329 logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id})
330 if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil {
331 if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil {
332 logger.Errorw(ctx, "error-occurred-during-get-ext-value",
333 log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id, "error": err})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800334 return nil, err
335 }
336 }
337 return resp, nil
338}
kesavand62126212021-01-12 04:56:06 -0500339
khenaidoo106c61a2021-08-11 18:05:46 -0400340//GetSingleValue handles get uni status on ONU and ondemand metric on OLT
341func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
342 logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request})
kesavand62126212021-01-12 04:56:06 -0500343
344 errResp := func(status extension.GetValueResponse_Status,
345 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
346 return &extension.SingleGetValueResponse{
347 Response: &extension.GetValueResponse{
348 Status: status,
349 ErrReason: reason,
350 },
351 }
352 }
353 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
354 switch reqType := request.GetRequest().GetRequest().(type) {
355 case *extension.GetValueRequest_OltPortInfo:
356 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530357 case *extension.GetValueRequest_OnuPonInfo:
358 return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil
Gamze Abaka85e9a142021-05-26 13:41:39 +0000359 case *extension.GetValueRequest_RxPower:
360 return handler.getRxPower(ctx, reqType.RxPower), nil
kesavand62126212021-01-12 04:56:06 -0500361 default:
362 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
363 }
364 }
365
366 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
367 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
368}
khenaidoo106c61a2021-08-11 18:05:46 -0400369
370/*
371 * OLT Inter-adapter service
372 */
373
374// ProxyOmciRequest proxies an OMCI request from the child adapter
375func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ic.OmciMessage) (*empty.Empty, error) {
376 logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request})
377
378 if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil {
379 if err := handler.ProxyOmciMessage(ctx, request); err != nil {
380 return nil, errors.New(err.Error())
381 }
382 return &empty.Empty{}, nil
383 }
384 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log()
385}
386
387// GetTechProfileInstance returns an instance of a tech profile
388func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) {
389 logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request})
390
391 targetDeviceID := request.ParentDeviceId
392 if targetDeviceID == "" {
393 return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
394 }
395 if handler := oo.getDeviceHandler(targetDeviceID); handler != nil {
396 return handler.GetTechProfileDownloadMessage(ctx, request)
397 }
398 return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log()
399
400}
401
402/*
403 *
404 * Unimplemented APIs
405 *
406 */
407
408//SimulateAlarm is unimplemented
409func (oo *OpenOLT) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*voltha.OperationResp, error) {
410 return nil, olterrors.ErrNotImplemented
411}
412
413//SetExtValue is unimplemented
414func (oo *OpenOLT) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) {
415 return nil, olterrors.ErrNotImplemented
416}
417
418//SetSingleValue is unimplemented
419func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
420 return nil, olterrors.ErrNotImplemented
421}
422
423//StartOmciTest not implemented
424func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) {
425 return nil, olterrors.ErrNotImplemented
426}
427
428//SuppressEvent unimplemented
429func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
430 return nil, olterrors.ErrNotImplemented
431}
432
433//UnSuppressEvent unimplemented
434func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
435 return nil, olterrors.ErrNotImplemented
436}
437
438//DownloadImage is unimplemented
439func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
440 return nil, olterrors.ErrNotImplemented
441}
442
443//GetImageDownloadStatus is unimplemented
444func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
445 return nil, olterrors.ErrNotImplemented
446}
447
448//CancelImageDownload is unimplemented
449func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
450 return nil, olterrors.ErrNotImplemented
451}
452
453//ActivateImageUpdate is unimplemented
454func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
455 return nil, olterrors.ErrNotImplemented
456}
457
458//RevertImageUpdate is unimplemented
459func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
460 return nil, olterrors.ErrNotImplemented
461}
462
463//DownloadOnuImage unimplemented
464func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
465 return nil, olterrors.ErrNotImplemented
466}
467
468//GetOnuImageStatus unimplemented
469func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
470 return nil, olterrors.ErrNotImplemented
471}
472
473//AbortOnuImageUpgrade unimplemented
474func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
475 return nil, olterrors.ErrNotImplemented
476}
477
478//GetOnuImages unimplemented
479func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) {
480 return nil, olterrors.ErrNotImplemented
481}
482
483//ActivateOnuImage unimplemented
484func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
485 return nil, olterrors.ErrNotImplemented
486}
487
488//CommitOnuImage unimplemented
489func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
490 return nil, olterrors.ErrNotImplemented
491}
492
493// UpdateFlowsBulk is unimplemented
494func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) {
495 return nil, olterrors.ErrNotImplemented
496}
497
498//SelfTestDevice unimplemented
499func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
500 return nil, olterrors.ErrNotImplemented
501}