blob: 9fa259797ec16f915147f05dd338faed197a5406 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandtfa074992020-03-27 15:42:06 +00003 *
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 */
16
praneeth nalmas5a0a5502022-12-23 15:57:00 +053017// Package core provides the utility for onu devices, flows and statistics
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package core
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
22 "errors"
23 "fmt"
nikesh.krishnance4879a2023-08-01 18:36:57 +053024 grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
25 "github.com/opencord/voltha-lib-go/v7/pkg/db"
26 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
27 codes "google.golang.org/grpc/codes"
khenaidoo55cebc62021-12-08 14:44:41 -050028 "hash/fnv"
Holger Hildebrandt52f271b2022-06-02 09:32:27 +000029 "strings"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 "sync"
31 "time"
32
khenaidoo7d3c5582021-08-11 18:09:44 -040033 conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
khenaidoof3333552021-12-15 16:52:31 -050034 "github.com/opencord/voltha-protos/v5/go/adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040035 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040036 "github.com/opencord/voltha-protos/v5/go/health"
37 "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040038 "google.golang.org/grpc"
khenaidoo55cebc62021-12-08 14:44:41 -050039 "google.golang.org/grpc/status"
khenaidoo7d3c5582021-08-11 18:09:44 -040040
41 "github.com/golang/protobuf/ptypes/empty"
42 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
43 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
44 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoo42dcdfd2021-10-19 17:34:12 -040045 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo7d3c5582021-08-11 18:09:44 -040046 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo42dcdfd2021-10-19 17:34:12 -040047 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
48 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidoo7d3c5582021-08-11 18:09:44 -040049 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000050
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000051 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Matteo Scandolo761f7512020-11-23 15:52:40 -080052 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandt60652202021-11-02 11:09:36 +000053 pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000054 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
55 uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000056)
57
khenaidoo55cebc62021-12-08 14:44:41 -050058type reachabilityFromRemote struct {
59 lastKeepAlive time.Time
60 keepAliveInterval int64
61}
62
praneeth nalmas5a0a5502022-12-23 15:57:00 +053063// OpenONUAC structure holds the ONU core information
Holger Hildebrandtfa074992020-03-27 15:42:06 +000064type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053065 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000066 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000067 mutexDeviceHandlersMap sync.RWMutex
khenaidoo7d3c5582021-08-11 18:09:44 -040068 coreClient *vgrpc.Client
69 parentAdapterClients map[string]*vgrpc.Client
70 lockParentAdapterClients sync.RWMutex
khenaidoo55cebc62021-12-08 14:44:41 -050071 reachableFromRemote map[string]*reachabilityFromRemote
72 lockReachableFromRemote sync.RWMutex
Himani Chawlac07fda02020-12-09 16:21:21 +053073 eventProxy eventif.EventProxy
mpagenkoaf801632020-07-03 10:00:42 +000074 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080075 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000076 config *config.AdapterFlags
77 numOnus int
Matteo Scandolo127c59d2021-01-28 11:31:18 -080078 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000079 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000080 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000081 mibTemplatesGenerated map[string]bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000082 mutexMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083 exitChannel chan int
84 HeartbeatCheckInterval time.Duration
85 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000086 AcceptIncrementalEvto bool
khenaidoo55cebc62021-12-08 14:44:41 -050087 pSupportedFsms *cmn.OmciDeviceFsms
88 maxTimeoutInterAdapterComm time.Duration
89 maxTimeoutReconciling time.Duration
90 pDownloadManager *swupg.AdapterDownloadManager
91 pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete
92 MetricsEnabled bool
Holger Hildebrandtc572e622022-06-22 09:19:17 +000093 ExtendedOmciSupportEnabled bool
khenaidoo55cebc62021-12-08 14:44:41 -050094 mibAuditInterval time.Duration
95 omciTimeout int // in seconds
96 alarmAuditInterval time.Duration
97 dlToOnuTimeout4M time.Duration
98 rpcTimeout time.Duration
99 maxConcurrentFlowsPerUni int
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000100}
101
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530102// NewOpenONUAC returns a new instance of OpenONU_AC
khenaidoo7d3c5582021-08-11 18:09:44 -0400103func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy,
104 kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000105 var openOnuAc OpenONUAC
106 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530107 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000108 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
khenaidoo7d3c5582021-08-11 18:09:44 -0400109 openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client)
khenaidoo55cebc62021-12-08 14:44:41 -0500110 openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000111 openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800113 openOnuAc.cm = cm
khenaidoo7d3c5582021-08-11 18:09:44 -0400114 openOnuAc.coreClient = coreClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115 openOnuAc.numOnus = cfg.OnuNumber
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +0000117 openOnuAc.kvClient = kvClient
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800118 openOnuAc.KVStoreAddress = cfg.KVStoreAddress
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +0000120 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000121 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000122 openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000123 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
124 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +0000125 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +0530126 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000127 openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000128 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129 openOnuAc.MetricsEnabled = cfg.MetricsEnabled
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000130 openOnuAc.ExtendedOmciSupportEnabled = cfg.ExtendedOmciSupportEnabled
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000131 openOnuAc.mibAuditInterval = cfg.MibAuditInterval
Girish Gowdra0b235842021-03-09 13:06:46 -0800132 // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion
133 openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds())
Himani Chawla075f1642021-03-15 19:23:24 +0530134 openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
mpagenkoc26d4c02021-05-06 14:27:57 +0000135 openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
khenaidoo7d3c5582021-08-11 18:09:44 -0400136 openOnuAc.rpcTimeout = cfg.RPCTimeout
Girish Gowdrae95687a2021-09-08 16:30:58 -0700137 openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000138
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000140 "mib-synchronizer": {
141 //mibSyncFsm, // Implements the MIB synchronization state machine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000142 DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530143 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000144 AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000145 // map[string]func() error{
146 // "mib-upload": onuDeviceEntry.MibUploadTask,
147 // "mib-template": onuDeviceEntry.MibTemplateTask,
148 // "get-mds": onuDeviceEntry.GetMdsTask,
149 // "mib-audit": onuDeviceEntry.GetMdsTask,
150 // "mib-resync": onuDeviceEntry.MibResyncTask,
151 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
152 // },
153 },
154 }
155
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000156 openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx)
157 openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx)
mpagenkoc26d4c02021-05-06 14:27:57 +0000158 openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
mpagenkoc8bba412021-01-15 15:38:44 +0000159
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000160 return &openOnuAc
161}
162
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530163// Start starts (logs) the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000165 logger.Info(ctx, "starting-openonu-adapter")
mpagenkoc8bba412021-01-15 15:38:44 +0000166
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167 return nil
168}
169
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530170// Stop terminates the session
khenaidoof3333552021-12-15 16:52:31 -0500171func (oo *OpenONUAC) Stop(ctx context.Context) error {
172 logger.Info(ctx, "stopping-device-manager")
173 close(oo.exitChannel)
174 oo.stopAllGrpcClients(ctx)
175 logger.Info(ctx, "device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176 return nil
177}
178
Himani Chawla6d2ae152020-09-02 13:11:20 +0530179func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000180 oo.mutexDeviceHandlersMap.Lock()
181 defer oo.mutexDeviceHandlersMap.Unlock()
182 if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist {
183 oo.deviceHandlers[agent.DeviceID] = agent
184 oo.deviceHandlers[agent.DeviceID].start(ctx)
185 if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist {
186 logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID})
187 oo.deviceHandlersCreateChan[agent.DeviceID] <- true
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000188 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000189 }
190}
191
Himani Chawla6d2ae152020-09-02 13:11:20 +0530192func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000193 oo.mutexDeviceHandlersMap.Lock()
194 defer oo.mutexDeviceHandlersMap.Unlock()
195 delete(oo.deviceHandlers, agent.DeviceID)
196 delete(oo.deviceHandlersCreateChan, agent.DeviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000197}
198
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530199// getDeviceHandler gets the ONU deviceHandler and may wait until it is created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000200func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000201 oo.mutexDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000202 agent, ok := oo.deviceHandlers[deviceID]
203 if aWait && !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000204 logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000205 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000206 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
207 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
208 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800209 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000210 //keep the read sema short to allow for subsequent write
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000211 oo.mutexDeviceHandlersMap.Unlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000212 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
213 // so it might be needed to wait here for that event with some timeout
214 select {
215 case <-time.After(1 * time.Second): //timer may be discussed ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000216 logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000217 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800218 case <-deviceCreateChan:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000219 logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000220 oo.mutexDeviceHandlersMap.RLock()
221 defer oo.mutexDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000222 return oo.deviceHandlers[deviceID]
223 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000224 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000225 oo.mutexDeviceHandlersMap.Unlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000226 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000227}
228
khenaidoo7d3c5582021-08-11 18:09:44 -0400229// AdoptDevice creates a new device handler if not present already and then adopts the device
230func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000232 logger.Warn(ctx, "voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400233 return nil, errors.New("nil-device")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000235 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530236 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000237 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400238 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000239 oo.addDeviceHandlerToMap(ctx, handler)
khenaidoo7d3c5582021-08-11 18:09:44 -0400240
241 // Setup the grpc communication with the parent adapter
242 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
243 // TODO: Cleanup on failure needed
244 return nil, err
245 }
246
247 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000248 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400249 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000250}
251
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530252// ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart
khenaidoo7d3c5582021-08-11 18:09:44 -0400253func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000254 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000255 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400256 return nil, errors.New("nil-device")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000257 }
khenaidoo55cebc62021-12-08 14:44:41 -0500258 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId})
259
260 // Check whether the grpc client in the adapter of the parent device can reach us yet
khenaidoof3333552021-12-15 16:52:31 -0500261 if !oo.isReachableFromRemote(ctx, device.ProxyAddress.AdapterEndpoint, device.ProxyAddress.DeviceId) {
khenaidoo55cebc62021-12-08 14:44:41 -0500262 return nil, status.Errorf(codes.Unavailable, "adapter-not-reachable-from-parent-%s", device.ProxyAddress.AdapterEndpoint)
263 }
264
Himani Chawla6d2ae152020-09-02 13:11:20 +0530265 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000266 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400267 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000268 oo.addDeviceHandlerToMap(ctx, handler)
269 handler.device = device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400270 if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{
khenaidoo7d3c5582021-08-11 18:09:44 -0400271 DeviceId: device.Id,
272 OperStatus: voltha.OperStatus_RECONCILING,
273 ConnStatus: device.ConnectStatus,
274 }); err != nil {
275 return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error())
Maninderb5187552021-03-23 22:23:42 +0530276 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400277 // Setup the grpc communication with the parent adapter
278 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
279 // TODO: Cleanup on failure needed
280 return nil, err
281 }
282
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000283 handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false)
khenaidoo7d3c5582021-08-11 18:09:44 -0400284 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000285 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000286 } else {
nikesh.krishnan9d2bbf72023-12-11 07:36:57 +0530287 logger.Warnf(ctx, "device-already-reconciled-or-active", log.Fields{"device-id": device.Id, "parent-id": device.ParentId})
288 return &empty.Empty{}, status.Errorf(codes.AlreadyExists, "handler exists: %s", device.Id)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000289 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400290 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000291}
292
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530293// DisableDevice disables the given device
khenaidoo7d3c5582021-08-11 18:09:44 -0400294func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000295 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
296 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400297 go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
298 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300299 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000300 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400301 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000302}
303
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530304// ReEnableDevice enables the onu device after disable
khenaidoo7d3c5582021-08-11 18:09:44 -0400305func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000306 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
307 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400308 go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
309 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300310 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000311 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400312 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000313}
314
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530315// RebootDevice reboots the given device
khenaidoo7d3c5582021-08-11 18:09:44 -0400316func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000317 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
318 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400319 go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking
320 return &empty.Empty{}, nil
ozgecanetsiae11479f2020-07-06 09:44:47 +0300321 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000322 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400323 return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000324}
325
khenaidoo7d3c5582021-08-11 18:09:44 -0400326// DeleteDevice deletes the given device
327func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
328 nctx := log.WithSpanFromContext(context.Background(), ctx)
khenaidoo7d3c5582021-08-11 18:09:44 -0400329 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber, "ctx": ctx, "nctx": nctx})
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000330
dbainbri4d3a0dc2020-12-02 00:33:42 +0000331 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra0e533642021-03-02 22:02:51 -0800332 var errorsList []error
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000333
334 handler.mutexDeletionInProgressFlag.Lock()
335 handler.deletionInProgress = true
336 handler.mutexDeletionInProgressFlag.Unlock()
337
Girish Gowdraabcceb12022-04-13 23:35:22 -0700338 // Setting the device deletion progress flag will cause the PM FSM to cleanup for GC after FSM moves to NULL state
nikesh.krishnan1249be92023-11-27 04:20:12 +0530339 if handler.pOnuMetricsMgr != nil {
340 handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true)
341 }
praneeth nalmasf405e962023-08-07 15:02:03 +0530342
343 handler.deviceDeleteCommChan <- true
Holger Hildebrandt60652202021-11-02 11:09:36 +0000344 if err := handler.resetFsms(ctx, true); err != nil {
345 errorsList = append(errorsList, err)
346 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700347 for _, uni := range handler.uniEntityMap {
348 if handler.GetFlowMonitoringIsRunning(uni.UniID) {
349 handler.stopFlowMonitoringRoutine[uni.UniID] <- true
350 logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id})
351 }
352 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000353 //don't leave any garbage in kv-store
354 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
355 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000356 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000357 oo.deleteDeviceHandlerToMap(handler)
358 go handler.PrepareForGarbageCollection(ctx, handler.DeviceID)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000359
Girish Gowdra0e533642021-03-02 22:02:51 -0800360 if len(errorsList) > 0 {
361 logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400362 return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
Girish Gowdra0e533642021-03-02 22:02:51 -0800363 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400364 return &empty.Empty{}, nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000365 }
Holger Hildebrandt60652202021-11-02 11:09:36 +0000366 logger.Infow(ctx, "no handler found for device-deletion - trying to delete remaining data in the kv-store ", log.Fields{"device-id": device.Id})
367
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000368 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
369 return nil, err
Holger Hildebrandt60652202021-11-02 11:09:36 +0000370 }
371 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000372}
373
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530374// UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400375func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400376 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000377
mpagenkofc4f56e2020-11-04 17:17:49 +0000378 //flow config is relayed to handler even if the device might be in some 'inactive' state
379 // let the handler or related FSM's decide, what to do with the modified flow state info
380 // at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here
mpagenkodff5dda2020-08-28 11:52:01 +0000381
382 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000383 // but processing is continued for flowUpdate possibly also set in the request
khenaidoo7d3c5582021-08-11 18:09:44 -0400384 if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil {
385 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000386 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400387 if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil {
388 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000389 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400390 if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil {
391 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000392 }
393
khenaidoo7d3c5582021-08-11 18:09:44 -0400394 if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil {
395 if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
396 return nil, err
397 }
398 return &empty.Empty{}, nil
mpagenkodff5dda2020-08-28 11:52:01 +0000399 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400400 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id})
401 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000402}
403
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530404// UpdatePmConfig returns PmConfigs nil or error
khenaidoo42dcdfd2021-10-19 17:34:12 -0400405func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400406 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId})
407 if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil {
408 if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil {
409 return nil, err
410 }
411 return &empty.Empty{}, nil
Girish Gowdrae09a6202021-01-12 18:10:59 -0800412 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400413 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId})
414 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000415}
416
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530417// DownloadImage requests downloading some image according to indications as given in request
418// The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400419func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400420 ctx = log.WithSpanFromContext(context.Background(), ctx)
421 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt52f271b2022-06-02 09:32:27 +0000422 if strings.Contains(imageInfo.Image.Url, "https:") {
423 return nil, errors.New("image download via https not supported")
424 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000425 if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400426 logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image})
mpagenko15ff4a52021-03-02 10:09:20 +0000427 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
428 // the download itself is later done in background
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000429 if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400430 return nil, err
431 }
432 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000433 }
434 // image already exists
khenaidoo7d3c5582021-08-11 18:09:44 -0400435 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image})
436 return imageInfo.Image, nil
mpagenkoc8bba412021-01-15 15:38:44 +0000437 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400438
439 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000440}
441
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530442// ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI
443//
444// according to indications as given in request and on success activate the image on the ONU
445//
446// The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400447func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400448 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000449 if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400450 if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000451 logger.Debugw(ctx, "image download on omci requested", log.Fields{
khenaidoo7d3c5582021-08-11 18:09:44 -0400452 "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
453 if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
454 return nil, err
455 }
456 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000457 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400458 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
459 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000460 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400461 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
462 return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000463 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400464 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000465}
466
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530467// GetSingleValue handles the core request to retrieve uni status
khenaidoo7d3c5582021-08-11 18:09:44 -0400468func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500469 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
470
471 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
472 switch reqType := request.GetRequest().GetRequest().(type) {
473 case *extension.GetValueRequest_UniInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000474 return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700475 case *extension.GetValueRequest_OnuOpticalInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000476 CommChan := make(chan cmn.Message)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700477 respChan := make(chan extension.SingleGetValueResponse)
478 // Initiate the self test request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000479 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700480 return &extension.SingleGetValueResponse{
481 Response: &extension.GetValueResponse{
482 Status: extension.GetValueResponse_ERROR,
483 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
484 },
485 }, err
486 }
487 // The timeout handling is already implemented in omci_self_test_handler module
488 resp := <-respChan
489 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530490 case *extension.GetValueRequest_OnuInfo:
491 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000492 case *extension.GetValueRequest_OnuOmciStats:
493 return handler.getOnuOMCIStats(ctx)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530494 case *extension.GetValueRequest_OnuActiveAlarms:
495 resp := handler.getOnuActiveAlarms(ctx)
496 logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp})
497 return resp, nil
kesavandfdf77632021-01-26 23:40:33 -0500498 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000499 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
kesavandfdf77632021-01-26 23:40:33 -0500500 }
501 }
502 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000503 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000504}
505
mpagenko83144272021-04-27 10:06:22 +0000506//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000507// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
508// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
509// The reason for that was never finally investigated.
510// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000511
khenaidoo7d3c5582021-08-11 18:09:44 -0400512// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530513//
514// if the image is not yet present on the adapter it has to be automatically downloaded
khenaidoo7d3c5582021-08-11 18:09:44 -0400515func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000516 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
Holger Hildebrandt52f271b2022-06-02 09:32:27 +0000517 if strings.Contains((*request).Image.Url, "https:") {
518 return nil, errors.New("image download via https not supported")
519 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000520 loResponse := voltha.DeviceImageResponse{}
521 imageIdentifier := (*request).Image.Version
mpagenkoc497ee32021-11-10 17:30:20 +0000522 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000523 firstDevice := true
524 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000525 var onuVolthaDevice *voltha.Device
526 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000527 for _, pCommonID := range (*request).DeviceId {
mpagenko38662d02021-08-11 09:45:19 +0000528 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000529 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000530 loDeviceImageState := voltha.DeviceImageState{}
531 loDeviceImageState.DeviceId = loDeviceID
532 loImageState := voltha.ImageState{}
533 loDeviceImageState.ImageState = &loImageState
534 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko38662d02021-08-11 09:45:19 +0000535
mpagenko59862f02021-10-11 08:53:18 +0000536 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400537 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000538 if handler != nil {
539 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
540 } else {
541 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
542 devErr = errors.New("no handler found for device-id")
khenaidoo7d3c5582021-08-11 18:09:44 -0400543 }
mpagenko59862f02021-10-11 08:53:18 +0000544 if devErr != nil || onuVolthaDevice == nil {
545 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
546 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000547 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
548 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000549 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000550 } else {
mpagenko38662d02021-08-11 09:45:19 +0000551 if firstDevice {
552 //start/verify download of the image to the adapter based on first found device only
553 // use the OnuVendor identification from first given device
mpagenkoc497ee32021-11-10 17:30:20 +0000554
555 // note: if the request was done for a list of devices on the Voltha interface, rwCore
556 // translates that into a new rpc for each device, hence each device will be the first device in parallel requests!
mpagenko38662d02021-08-11 09:45:19 +0000557 firstDevice = false
558 vendorID = onuVolthaDevice.VendorId
559 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
mpagenkoc497ee32021-11-10 17:30:20 +0000560 logger.Infow(ctx, "download request for file",
561 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000562
mpagenkoc497ee32021-11-10 17:30:20 +0000563 // call the StartDownload synchronously to detect 'immediate' download problems
564 // the real download itself is later done in background
565 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko38662d02021-08-11 09:45:19 +0000566 // note: If the image (with vendorId+name) has already been downloaded before from some other
mpagenkoc497ee32021-11-10 17:30:20 +0000567 // valid URL, the current download request is not executed (current code delivers URL error).
568 // If the operators want to ensure that the new URL
mpagenko38662d02021-08-11 09:45:19 +0000569 // is really used, then they first have to use the 'abort' API to remove the existing image!
570 // (abort API can be used also after some successful download to just remove the image from adapter)
mpagenkoc497ee32021-11-10 17:30:20 +0000571 if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted {
572 downloadStartDone = true
573 } //else fileState may also indicate error situation, where the requested image is not ready to be used for other devices
mpagenko38662d02021-08-11 09:45:19 +0000574 }
575 } else {
576 //for all following devices verify the matching vendorID
577 if onuVolthaDevice.VendorId != vendorID {
578 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
579 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
580 vendorIDMatch = false
581 }
582 }
mpagenkoc497ee32021-11-10 17:30:20 +0000583 if downloadStartDone && vendorIDMatch {
mpagenko38662d02021-08-11 09:45:19 +0000584 // start the ONU download activity for each possible device
mpagenkoc497ee32021-11-10 17:30:20 +0000585 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko59862f02021-10-11 08:53:18 +0000586 "image-id": imageIdentifier, "device-id": loDeviceID})
587 //onu upgrade handling called in background without immediate error evaluation here
588 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
589 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
590 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
591 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
592 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
593 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +0000594 } else {
595 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
mpagenkoc497ee32021-11-10 17:30:20 +0000596 if !downloadStartDone {
597 //based on above fileState more descriptive error codes would be possible, e.g
598 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko38662d02021-08-11 09:45:19 +0000599 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
600 } else { //only logical option is !vendorIDMatch
601 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
602 }
603 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
604 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000605 }
mpagenko2f2f2362021-06-07 08:25:22 +0000606 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000607 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000608 pImageResp := &loResponse
609 return pImageResp, nil
610 }
611 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000612}
613
khenaidoo7d3c5582021-08-11 18:09:44 -0400614// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530615//
616// status for the requested image
khenaidoo7d3c5582021-08-11 18:09:44 -0400617func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000618 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
619 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000620 imageIdentifier := (*in).Version
mpagenko38662d02021-08-11 09:45:19 +0000621 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000622 firstDevice := true
623 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000624 var onuVolthaDevice *voltha.Device
625 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000626 for _, pCommonID := range (*in).DeviceId {
627 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400628 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
mpagenko59862f02021-10-11 08:53:18 +0000629 vendorIDSet = false
630 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400631 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000632 if handler != nil {
633 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
634 } else {
635 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
636 devErr = errors.New("no handler found for device-id")
mpagenko38662d02021-08-11 09:45:19 +0000637 }
mpagenko59862f02021-10-11 08:53:18 +0000638 if devErr != nil || onuVolthaDevice == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000639 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
mpagenko59862f02021-10-11 08:53:18 +0000640 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000641 pImageState := &voltha.ImageState{
642 Version: (*in).Version,
643 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
644 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
645 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000646 }
mpagenko38662d02021-08-11 09:45:19 +0000647 pDeviceImageState.ImageState = pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000648 } else {
mpagenko38662d02021-08-11 09:45:19 +0000649 if firstDevice {
650 //start/verify download of the image to the adapter based on first found device only
651 // use the OnuVendor identification from first given device
652 firstDevice = false
653 vendorID = onuVolthaDevice.VendorId
654 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
655 vendorIDSet = true
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000656 logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000657 } else {
658 //for all following devices verify the matching vendorID
659 if onuVolthaDevice.VendorId != vendorID {
660 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000661 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko38662d02021-08-11 09:45:19 +0000662 } else {
663 vendorIDSet = true
664 }
665 }
666 if !vendorIDSet {
667 pImageState := &voltha.ImageState{
668 Version: (*in).Version,
669 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
670 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
671 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
672 }
673 pDeviceImageState.ImageState = pImageState
674 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400675 logger.Debugw(ctx, "image status request for", log.Fields{
676 "image-id": imageIdentifier, "device-id": loDeviceID})
677 //status request is called synchronously to collect the indications for all concerned devices
678 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenko38662d02021-08-11 09:45:19 +0000679 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000680 }
681 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000682 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000683 pImageResp := &loResponse
684 return pImageResp, nil
685 }
686 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000687}
688
khenaidoo7d3c5582021-08-11 18:09:44 -0400689// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
690func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000691 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
692 loResponse := voltha.DeviceImageResponse{}
693 imageIdentifier := (*in).Version
694 firstDevice := true
695 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000696 var vendorIDSet bool
697 var onuVolthaDevice *voltha.Device
698 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000699 for _, pCommonID := range (*in).DeviceId {
700 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400701 pDeviceImageState := &voltha.DeviceImageState{}
702 loImageState := voltha.ImageState{}
703 pDeviceImageState.ImageState = &loImageState
mpagenko59862f02021-10-11 08:53:18 +0000704 vendorIDSet = false
705 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400706 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000707 if handler != nil {
708 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
709 } else {
710 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
711 devErr = errors.New("no handler found for device-id")
712 }
713 if devErr != nil || onuVolthaDevice == nil {
714 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
715 log.Fields{"device-id": loDeviceID, "err": devErr})
khenaidoo7d3c5582021-08-11 18:09:44 -0400716 pDeviceImageState.DeviceId = loDeviceID
717 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko59862f02021-10-11 08:53:18 +0000718 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
719 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
khenaidoo7d3c5582021-08-11 18:09:44 -0400720 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoaa3afe92021-05-21 16:20:58 +0000721 } else {
mpagenko59862f02021-10-11 08:53:18 +0000722 if firstDevice {
723 //start/verify download of the image to the adapter based on first found device only
724 // use the OnuVendor identification from first given device
725 firstDevice = false
726 vendorID = onuVolthaDevice.VendorId
727 vendorIDSet = true
728 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000729 logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko59862f02021-10-11 08:53:18 +0000730 } else {
731 //for all following devices verify the matching vendorID
732 if onuVolthaDevice.VendorId != vendorID {
733 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000734 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko59862f02021-10-11 08:53:18 +0000735 pDeviceImageState.DeviceId = loDeviceID
736 pDeviceImageState.ImageState.Version = (*in).Version
737 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
738 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
739 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
740 } else {
741 vendorIDSet = true
742 }
743 }
744 if vendorIDSet {
745 // cancel the ONU upgrade activity for each possible device
746 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
747 "image-id": imageIdentifier, "device-id": loDeviceID})
748 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
749 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
mpagenkoaa3afe92021-05-21 16:20:58 +0000750 }
751 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000752 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000753 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000754 if !firstDevice {
755 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
756 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
757 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
758 }
759 pImageResp := &loResponse
760 return pImageResp, nil
761 }
762 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000763}
764
khenaidoo7d3c5582021-08-11 18:09:44 -0400765// GetOnuImages retrieves the ONU SW image status information via OMCI
766func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
767 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
768 if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530769 images, err := handler.getOnuImages(ctx)
770 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000771 return images, nil
772 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400773 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000774 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400775 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
776 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
mpagenko83144272021-04-27 10:06:22 +0000777}
778
khenaidoo7d3c5582021-08-11 18:09:44 -0400779// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530780//
781// precondition: image downloaded and not yet activated or image refers to current inactive image
khenaidoo7d3c5582021-08-11 18:09:44 -0400782func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000783 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
784 loResponse := voltha.DeviceImageResponse{}
785 imageIdentifier := (*in).Version
786 //let the deviceHandler find the adequate way of requesting the image activation
787 for _, pCommonID := range (*in).DeviceId {
788 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000789 loDeviceImageState := voltha.DeviceImageState{}
790 loDeviceImageState.DeviceId = loDeviceID
791 loImageState := voltha.ImageState{}
792 loDeviceImageState.ImageState = &loImageState
793 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000794 //compared to download procedure the vendorID (from device) is secondary here
795 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
796 // start image activation activity for each possible device
797 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
798 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
799 logger.Debugw(ctx, "onu image activation requested", log.Fields{
800 "image-id": imageIdentifier, "device-id": loDeviceID})
801 //onu activation handling called in background without immediate error evaluation here
802 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
803 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000804 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
805 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
806 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
807 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
808 } else {
809 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
810 loDeviceImageState.ImageState.Reason = pImageStates.Reason
811 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
812 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000813 } else {
814 //cannot start SW activation for requested device
815 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000816 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000817 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
818 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000819 }
mpagenko2f2f2362021-06-07 08:25:22 +0000820 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000821 }
822 pImageResp := &loResponse
823 return pImageResp, nil
824 }
825 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000826}
827
khenaidoo7d3c5582021-08-11 18:09:44 -0400828// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530829//
830// precondition: image activated and not yet committed
khenaidoo7d3c5582021-08-11 18:09:44 -0400831func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000832 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
833 loResponse := voltha.DeviceImageResponse{}
834 imageIdentifier := (*in).Version
835 //let the deviceHandler find the adequate way of requesting the image activation
836 for _, pCommonID := range (*in).DeviceId {
837 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000838 loDeviceImageState := voltha.DeviceImageState{}
839 loDeviceImageState.DeviceId = loDeviceID
840 loImageState := voltha.ImageState{}
841 loDeviceImageState.ImageState = &loImageState
842 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000843 //compared to download procedure the vendorID (from device) is secondary here
844 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
845 // start image activation activity for each possible device
846 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
847 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
848 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
849 "image-id": imageIdentifier, "device-id": loDeviceID})
850 //onu commitment handling called in background without immediate error evaluation here
851 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
852 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000853 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
mpagenko38662d02021-08-11 09:45:19 +0000854 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
855 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
mpagenko183647c2021-06-08 15:25:04 +0000856 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
857 } else {
858 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
859 loDeviceImageState.ImageState.Reason = pImageStates.Reason
860 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
861 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000862 } else {
863 //cannot start SW commitment for requested device
864 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000865 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000866 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
867 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000868 }
mpagenko2f2f2362021-06-07 08:25:22 +0000869 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000870 }
871 pImageResp := &loResponse
872 return pImageResp, nil
873 }
874 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000875}
876
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000877// Adapter interface required methods ################ end #########
878// #################################################################
khenaidoo7d3c5582021-08-11 18:09:44 -0400879
880/*
881 *
882 * ONU inter adapter service
883 *
884 */
885
886// OnuIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400887func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400888 logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
889
890 if onuInd == nil || onuInd.OnuIndication == nil {
891 return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
892 }
893
894 onuIndication := onuInd.OnuIndication
895 onuOperstate := onuIndication.GetOperState()
896 waitForDhInstPresent := false
897 if onuOperstate == "up" {
898 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
899 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
900 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
901 //Adopt_device() arrived and DeviceHandler instance was created
902 waitForDhInstPresent = true
903 }
904 if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
905 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
906 "OnuId": onuIndication.GetOnuId(),
907 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
908 "SNR": onuIndication.GetSerialNumber()})
909
910 if onuOperstate == "up" {
911 if err := handler.createInterface(ctx, onuIndication); err != nil {
912 return nil, err
913 }
914 return &empty.Empty{}, nil
915 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
Holger Hildebrandt68854a82022-09-05 07:00:21 +0000916 if err := handler.UpdateInterface(ctx); err != nil {
ozgecanetsia76db57a2022-02-03 15:32:03 +0300917 return nil, err
918 }
919 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400920 } else {
921 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
922 return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
923 }
924 }
925 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
926 "msgToDeviceId": onuInd.DeviceId})
927 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
928}
929
930// OmciIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400931func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400932 logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
933
934 if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
935 if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
936 return nil, err
937 }
938 return &empty.Empty{}, nil
939 }
940 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
941}
942
943// DownloadTechProfile is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400944func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530945 logger.Info(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400946
947 if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
948 if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
949 return nil, err
950 }
951 return &empty.Empty{}, nil
952 }
953 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
954}
955
956// DeleteGemPort is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400957func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400958 logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400959 if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
nikesh.krishnan1249be92023-11-27 04:20:12 +0530960 if handler.GetDeletionInProgress() {
961 logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": gPort.DeviceId})
962 return nil, fmt.Errorf("device deletion in progress for device-id: %s", gPort.DeviceId)
963 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400964 if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
965 return nil, err
966 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000967 } else {
968 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId})
969 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400970 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000971 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400972}
973
974// DeleteTCont is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400975func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000976 logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf})
khenaidoo7d3c5582021-08-11 18:09:44 -0400977 if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
nikesh.krishnan1249be92023-11-27 04:20:12 +0530978 if handler.GetDeletionInProgress() {
979 logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": tConf.DeviceId})
980 return nil, fmt.Errorf("device deletion in progress for device-id: %s", tConf.DeviceId)
981 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400982 if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil {
983 return nil, err
984 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000985 } else {
986 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId})
987 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400988 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000989 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400990}
991
992/*
993 * Parent GRPC clients
994 */
995
khenaidoo55cebc62021-12-08 14:44:41 -0500996func getHash(endpoint, contextInfo string) string {
997 strToHash := endpoint + contextInfo
998 h := fnv.New128().Sum([]byte(strToHash))
999 return string(h)
1000}
1001
1002func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) {
1003 logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote})
1004 oo.lockReachableFromRemote.Lock()
1005 defer oo.lockReachableFromRemote.Unlock()
1006 endpointHash := getHash(remote.Endpoint, remote.ContextInfo)
1007 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
1008 oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now()
1009 oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval
1010 return
1011 }
1012 logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote})
1013 oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval}
1014}
1015
khenaidoof3333552021-12-15 16:52:31 -05001016func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool {
1017 logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo})
khenaidoo55cebc62021-12-08 14:44:41 -05001018 oo.lockReachableFromRemote.RLock()
1019 defer oo.lockReachableFromRemote.RUnlock()
1020 endpointHash := getHash(endpoint, contextInfo)
1021 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
khenaidoof3333552021-12-15 16:52:31 -05001022 logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)})
khenaidoo55cebc62021-12-08 14:44:41 -05001023 // Assume the connection is down if we did not receive 2 keep alives in succession
1024 maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2)
1025 return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait
1026 }
1027 return false
1028}
1029
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301030// stopAllGrpcClients stops all grpc clients in use
khenaidoof3333552021-12-15 16:52:31 -05001031func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) {
1032 // Stop the clients that connect to the parent
1033 oo.lockParentAdapterClients.Lock()
1034 for key := range oo.parentAdapterClients {
1035 oo.parentAdapterClients[key].Stop(ctx)
1036 delete(oo.parentAdapterClients, key)
1037 }
1038 oo.lockParentAdapterClients.Unlock()
1039
1040 // Stop core client connection
1041 oo.coreClient.Stop(ctx)
1042}
1043
khenaidoo7d3c5582021-08-11 18:09:44 -04001044func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
1045 logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
1046 oo.lockParentAdapterClients.Lock()
1047 defer oo.lockParentAdapterClients.Unlock()
1048 if _, ok := oo.parentAdapterClients[endpoint]; ok {
1049 return nil
1050 }
1051
khenaidoo55cebc62021-12-08 14:44:41 -05001052 childClient, err := vgrpc.NewClient(
1053 oo.config.AdapterEndpoint,
1054 endpoint,
khenaidoof3333552021-12-15 16:52:31 -05001055 "olt_inter_adapter_service.OltInterAdapterService",
khenaidoo55cebc62021-12-08 14:44:41 -05001056 oo.oltAdapterRestarted)
khenaidoo7d3c5582021-08-11 18:09:44 -04001057
1058 if err != nil {
1059 return err
1060 }
nikesh.krishnance4879a2023-08-01 18:36:57 +05301061 retryCodes := []codes.Code{
1062 codes.Unavailable, // server is currently unavailable
1063 codes.DeadlineExceeded, // deadline for the operation was exceeded
1064 }
1065 backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(oo.config.PerRPCRetryTimeout, 0.2))
1066 grpcRetryOptions := grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(oo.config.MaxRetries), grpc_retry.WithPerRetryTimeout(oo.config.PerRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption)
khenaidoo7d3c5582021-08-11 18:09:44 -04001067
1068 oo.parentAdapterClients[endpoint] = childClient
nikesh.krishnance4879a2023-08-01 18:36:57 +05301069 go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler, grpcRetryOptions)
khenaidoo7d3c5582021-08-11 18:09:44 -04001070 // Wait until we have a connection to the child adapter.
1071 // Unlimited retries or until context expires
1072 subCtx := log.WithSpanFromContext(context.TODO(), ctx)
1073 backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
1074 for {
1075 client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
1076 if err == nil && client != nil {
1077 logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
1078 break
1079 }
1080 logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
1081 // Backoff
1082 if err = backoff.Backoff(subCtx); err != nil {
1083 logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
1084 break
1085 }
1086 }
1087 return nil
1088}
1089
khenaidoo42dcdfd2021-10-19 17:34:12 -04001090func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001091 // First check from cache
1092 oo.lockParentAdapterClients.RLock()
1093 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1094 oo.lockParentAdapterClients.RUnlock()
1095 return pgClient.GetOltInterAdapterServiceClient()
1096 }
1097 oo.lockParentAdapterClients.RUnlock()
1098
1099 // Set the parent connection - can occur on restarts
1100 ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
1101 err := oo.setupParentInterAdapterClient(ctx, endpoint)
1102 cancel()
1103 if err != nil {
1104 return nil, err
1105 }
1106
1107 // Get the parent client now
1108 oo.lockParentAdapterClients.RLock()
1109 defer oo.lockParentAdapterClients.RUnlock()
1110 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1111 return pgClient.GetOltInterAdapterServiceClient()
1112 }
1113
1114 return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
1115}
1116
1117// TODO: Any action the adapter needs to do following an olt adapter restart?
1118func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
1119 logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
1120 return nil
1121}
1122
khenaidoof3333552021-12-15 16:52:31 -05001123// getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service
1124func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
1125 if conn == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -04001126 return nil
1127 }
khenaidoof3333552021-12-15 16:52:31 -05001128 return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn)
khenaidoo7d3c5582021-08-11 18:09:44 -04001129}
1130
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001131func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error {
1132 logger.Debugw(ctx, "force deletion of ONU device specific data in kv store", log.Fields{"device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001133 var errorsList []error
1134 // delete onu persitent data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001135 onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix)
1136 logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath,
1137 "device-id": aDeviceID})
1138 onuKvbackend := &db.Backend{
1139 Client: oo.kvClient,
1140 StoreType: oo.KVStoreType,
1141 Address: oo.KVStoreAddress,
1142 Timeout: oo.KVStoreTimeout,
1143 PathPrefix: onuBaseKvStorePath,
1144 }
1145 err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID)
1146 if err != nil {
1147 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": onuBaseKvStorePath, "device-id": aDeviceID, "err": err})
1148 // continue to delete kv data, but accumulate any errors
1149 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001150 }
Girish Gowdraf10379e2022-02-02 21:49:44 -08001151 // delete pm data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001152 pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix)
1153 logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath,
1154 "device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001155 pmKvbackend := &db.Backend{
1156 Client: oo.kvClient,
1157 StoreType: oo.KVStoreType,
1158 Address: oo.KVStoreAddress,
1159 Timeout: oo.KVStoreTimeout,
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001160 PathPrefix: pmBaseKvStorePath,
Girish Gowdraf10379e2022-02-02 21:49:44 -08001161 }
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001162 err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID)
Girish Gowdraf10379e2022-02-02 21:49:44 -08001163 if err != nil {
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001164 logger.Errorw(ctx, "unable to delete PM in KVstore", log.Fields{"service": pmBaseKvStorePath, "device-id": aDeviceID, "err": err})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001165 // accumulate any errors
1166 errorsList = append(errorsList, err)
1167 }
1168 if len(errorsList) > 0 {
1169 return fmt.Errorf("one or more error deleting kv data, error: %v", errorsList)
1170 }
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001171 return nil
1172}
1173
khenaidoof3333552021-12-15 16:52:31 -05001174// GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter.
1175func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error {
1176 ctx := context.Background()
1177 logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream})
1178
1179 if stream == nil {
1180 return fmt.Errorf("conn-is-nil %v", stream)
1181 }
1182 initialRequestTime := time.Now()
1183 var remoteClient *common.Connection
1184 var tempClient *common.Connection
1185 var err error
1186loop:
1187 for {
1188 tempClient, err = stream.Recv()
1189 if err != nil {
1190 logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1191 break loop
1192 }
1193 // Send a response back
1194 err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY})
1195 if err != nil {
1196 logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1197 break loop
1198 }
1199 remoteClient = tempClient
1200
1201 logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient})
1202
1203 select {
1204 case <-stream.Context().Done():
1205 logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()})
1206 break loop
1207 case <-oo.exitChannel:
1208 logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime})
1209 break loop
1210 default:
1211 }
1212 }
1213 logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime})
1214 return err
1215}
1216
khenaidoo7d3c5582021-08-11 18:09:44 -04001217/*
1218 *
1219 * Unimplemented APIs
1220 *
1221 */
1222
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301223// GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202].
khenaidoo7d3c5582021-08-11 18:09:44 -04001224// OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort()
khenaidoo42dcdfd2021-10-19 17:34:12 -04001225func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001226 return nil, errors.New("unImplemented")
1227}
1228
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301229// SimulateAlarm is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001230func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001231 return nil, errors.New("unImplemented")
1232}
1233
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301234// SetExtValue is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001235func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001236 return nil, errors.New("unImplemented")
1237}
1238
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301239// SetSingleValue is unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001240func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
1241 return nil, errors.New("unImplemented")
1242}
1243
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301244// StartOmciTest not implemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001245func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001246 return nil, errors.New("unImplemented")
1247}
1248
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301249// SuppressEvent unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001250func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1251 return nil, errors.New("unImplemented")
1252}
1253
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301254// UnSuppressEvent unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001255func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1256 return nil, errors.New("unImplemented")
1257}
1258
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301259// GetImageDownloadStatus is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001260func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001261 return nil, errors.New("unImplemented")
1262}
1263
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301264// CancelImageDownload is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001265func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001266 return nil, errors.New("unImplemented")
1267}
1268
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301269// RevertImageUpdate is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001270func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001271 return nil, errors.New("unImplemented")
1272}
1273
1274// UpdateFlowsBulk is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001275func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001276 return nil, errors.New("unImplemented")
1277}
1278
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301279// SelfTestDevice unimplented
khenaidoo7d3c5582021-08-11 18:09:44 -04001280func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
1281 return nil, errors.New("unImplemented")
1282}
1283
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301284// SendPacketOut sends packet out to the device
khenaidoo42dcdfd2021-10-19 17:34:12 -04001285func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001286 return nil, errors.New("unImplemented")
1287}
1288
1289// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
1290func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1291 return nil, errors.New("unImplemented")
1292}
1293
1294// DisablePort to Disable pon/nni interface - seems not to be used/required according to python code
1295func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1296 return nil, errors.New("unImplemented")
1297}
1298
1299// GetExtValue - unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001300func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001301 return nil, errors.New("unImplemented")
1302}
1303
1304// ChildDeviceLost - unimplemented
1305func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
1306 return nil, errors.New("unImplemented")
1307}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001308
1309// GetSupportedFsms - TODO: add comment
1310func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
1311 return oo.pSupportedFsms
1312}
1313
1314// LockMutexMibTemplateGenerated - TODO: add comment
1315func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
1316 oo.mutexMibTemplateGenerated.Lock()
1317}
1318
1319// UnlockMutexMibTemplateGenerated - TODO: add comment
1320func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
1321 oo.mutexMibTemplateGenerated.Unlock()
1322}
1323
1324// GetMibTemplatesGenerated - TODO: add comment
1325func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
1326 value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
1327 return value, exist
1328}
1329
1330// SetMibTemplatesGenerated - TODO: add comment
1331func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
1332 oo.mibTemplatesGenerated[mibTemplatePath] = value
1333}
1334
1335// RLockMutexDeviceHandlersMap - TODO: add comment
1336func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
1337 oo.mutexDeviceHandlersMap.RLock()
1338}
1339
1340// RUnlockMutexDeviceHandlersMap - TODO: add comment
1341func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
1342 oo.mutexDeviceHandlersMap.RUnlock()
1343}
1344
1345// GetDeviceHandler - TODO: add comment
1346func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
1347 value, exist = oo.deviceHandlers[deviceID]
1348 return value, exist
1349}