blob: 683123754fcdec166ed4d8696064fe0fe3acf7ea [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
Joey Armstronge8c091f2023-01-17 16:56:26 -05002 * Copyright 2020-2023 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 {
khenaidoo7d3c5582021-08-11 18:09:44 -0400287 return nil, fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000288 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400289 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000290}
291
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530292// DisableDevice disables the given device
khenaidoo7d3c5582021-08-11 18:09:44 -0400293func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000294 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
295 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400296 go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
297 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300298 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400300 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000301}
302
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530303// ReEnableDevice enables the onu device after disable
khenaidoo7d3c5582021-08-11 18:09:44 -0400304func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000305 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
306 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400307 go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
308 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300309 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400311 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000312}
313
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530314// RebootDevice reboots the given device
khenaidoo7d3c5582021-08-11 18:09:44 -0400315func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000316 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
317 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400318 go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking
319 return &empty.Empty{}, nil
ozgecanetsiae11479f2020-07-06 09:44:47 +0300320 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000321 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400322 return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000323}
324
khenaidoo7d3c5582021-08-11 18:09:44 -0400325// DeleteDevice deletes the given device
326func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
327 nctx := log.WithSpanFromContext(context.Background(), ctx)
khenaidoo7d3c5582021-08-11 18:09:44 -0400328 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 +0000329
dbainbri4d3a0dc2020-12-02 00:33:42 +0000330 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra0e533642021-03-02 22:02:51 -0800331 var errorsList []error
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000332
333 handler.mutexDeletionInProgressFlag.Lock()
334 handler.deletionInProgress = true
335 handler.mutexDeletionInProgressFlag.Unlock()
336
Girish Gowdraabcceb12022-04-13 23:35:22 -0700337 // Setting the device deletion progress flag will cause the PM FSM to cleanup for GC after FSM moves to NULL state
338 handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true)
339
Holger Hildebrandt60652202021-11-02 11:09:36 +0000340 if err := handler.resetFsms(ctx, true); err != nil {
341 errorsList = append(errorsList, err)
342 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700343 for _, uni := range handler.uniEntityMap {
344 if handler.GetFlowMonitoringIsRunning(uni.UniID) {
345 handler.stopFlowMonitoringRoutine[uni.UniID] <- true
346 logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id})
347 }
348 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000349 //don't leave any garbage in kv-store
350 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
351 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000352 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000353 oo.deleteDeviceHandlerToMap(handler)
354 go handler.PrepareForGarbageCollection(ctx, handler.DeviceID)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000355
Girish Gowdra0e533642021-03-02 22:02:51 -0800356 if len(errorsList) > 0 {
357 logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400358 return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
Girish Gowdra0e533642021-03-02 22:02:51 -0800359 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400360 return &empty.Empty{}, nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000361 }
Holger Hildebrandt60652202021-11-02 11:09:36 +0000362 logger.Infow(ctx, "no handler found for device-deletion - trying to delete remaining data in the kv-store ", log.Fields{"device-id": device.Id})
363
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000364 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
365 return nil, err
Holger Hildebrandt60652202021-11-02 11:09:36 +0000366 }
367 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000368}
369
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530370// UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400371func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400372 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000373
mpagenkofc4f56e2020-11-04 17:17:49 +0000374 //flow config is relayed to handler even if the device might be in some 'inactive' state
375 // let the handler or related FSM's decide, what to do with the modified flow state info
376 // 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 +0000377
378 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000379 // but processing is continued for flowUpdate possibly also set in the request
khenaidoo7d3c5582021-08-11 18:09:44 -0400380 if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil {
381 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000382 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400383 if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil {
384 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000385 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400386 if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil {
387 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000388 }
389
khenaidoo7d3c5582021-08-11 18:09:44 -0400390 if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil {
391 if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
392 return nil, err
393 }
394 return &empty.Empty{}, nil
mpagenkodff5dda2020-08-28 11:52:01 +0000395 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400396 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id})
397 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000398}
399
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530400// UpdatePmConfig returns PmConfigs nil or error
khenaidoo42dcdfd2021-10-19 17:34:12 -0400401func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400402 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId})
403 if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil {
404 if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil {
405 return nil, err
406 }
407 return &empty.Empty{}, nil
Girish Gowdrae09a6202021-01-12 18:10:59 -0800408 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400409 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId})
410 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000411}
412
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530413// DownloadImage requests downloading some image according to indications as given in request
414// The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400415func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400416 ctx = log.WithSpanFromContext(context.Background(), ctx)
417 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt52f271b2022-06-02 09:32:27 +0000418 if strings.Contains(imageInfo.Image.Url, "https:") {
419 return nil, errors.New("image download via https not supported")
420 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000421 if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400422 logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image})
mpagenko15ff4a52021-03-02 10:09:20 +0000423 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
424 // the download itself is later done in background
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000425 if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400426 return nil, err
427 }
428 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000429 }
430 // image already exists
khenaidoo7d3c5582021-08-11 18:09:44 -0400431 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image})
432 return imageInfo.Image, nil
mpagenkoc8bba412021-01-15 15:38:44 +0000433 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400434
435 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000436}
437
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530438// ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI
439//
440// according to indications as given in request and on success activate the image on the ONU
441//
442// The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400443func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400444 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000445 if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400446 if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000447 logger.Debugw(ctx, "image download on omci requested", log.Fields{
khenaidoo7d3c5582021-08-11 18:09:44 -0400448 "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
449 if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
450 return nil, err
451 }
452 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000453 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400454 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
455 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000456 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400457 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
458 return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000459 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400460 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000461}
462
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530463// GetSingleValue handles the core request to retrieve uni status
khenaidoo7d3c5582021-08-11 18:09:44 -0400464func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500465 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
466
467 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
468 switch reqType := request.GetRequest().GetRequest().(type) {
469 case *extension.GetValueRequest_UniInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000470 return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700471 case *extension.GetValueRequest_OnuOpticalInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000472 CommChan := make(chan cmn.Message)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700473 respChan := make(chan extension.SingleGetValueResponse)
474 // Initiate the self test request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000475 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700476 return &extension.SingleGetValueResponse{
477 Response: &extension.GetValueResponse{
478 Status: extension.GetValueResponse_ERROR,
479 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
480 },
481 }, err
482 }
483 // The timeout handling is already implemented in omci_self_test_handler module
484 resp := <-respChan
485 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530486 case *extension.GetValueRequest_OnuInfo:
487 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000488 case *extension.GetValueRequest_OnuOmciStats:
489 return handler.getOnuOMCIStats(ctx)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530490 case *extension.GetValueRequest_OnuActiveAlarms:
491 resp := handler.getOnuActiveAlarms(ctx)
492 logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp})
493 return resp, nil
kesavandfdf77632021-01-26 23:40:33 -0500494 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000495 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
kesavandfdf77632021-01-26 23:40:33 -0500496 }
497 }
498 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000499 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000500}
501
mpagenko83144272021-04-27 10:06:22 +0000502//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000503// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
504// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
505// The reason for that was never finally investigated.
506// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000507
khenaidoo7d3c5582021-08-11 18:09:44 -0400508// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530509//
510// if the image is not yet present on the adapter it has to be automatically downloaded
khenaidoo7d3c5582021-08-11 18:09:44 -0400511func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000512 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
Holger Hildebrandt52f271b2022-06-02 09:32:27 +0000513 if strings.Contains((*request).Image.Url, "https:") {
514 return nil, errors.New("image download via https not supported")
515 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000516 loResponse := voltha.DeviceImageResponse{}
517 imageIdentifier := (*request).Image.Version
mpagenkoc497ee32021-11-10 17:30:20 +0000518 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000519 firstDevice := true
520 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000521 var onuVolthaDevice *voltha.Device
522 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000523 for _, pCommonID := range (*request).DeviceId {
mpagenko38662d02021-08-11 09:45:19 +0000524 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000525 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000526 loDeviceImageState := voltha.DeviceImageState{}
527 loDeviceImageState.DeviceId = loDeviceID
528 loImageState := voltha.ImageState{}
529 loDeviceImageState.ImageState = &loImageState
530 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko38662d02021-08-11 09:45:19 +0000531
mpagenko59862f02021-10-11 08:53:18 +0000532 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400533 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000534 if handler != nil {
535 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
536 } else {
537 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
538 devErr = errors.New("no handler found for device-id")
khenaidoo7d3c5582021-08-11 18:09:44 -0400539 }
mpagenko59862f02021-10-11 08:53:18 +0000540 if devErr != nil || onuVolthaDevice == nil {
541 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
542 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000543 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
544 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000545 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000546 } else {
mpagenko38662d02021-08-11 09:45:19 +0000547 if firstDevice {
548 //start/verify download of the image to the adapter based on first found device only
549 // use the OnuVendor identification from first given device
mpagenkoc497ee32021-11-10 17:30:20 +0000550
551 // note: if the request was done for a list of devices on the Voltha interface, rwCore
552 // 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 +0000553 firstDevice = false
554 vendorID = onuVolthaDevice.VendorId
555 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
mpagenkoc497ee32021-11-10 17:30:20 +0000556 logger.Infow(ctx, "download request for file",
557 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000558
mpagenkoc497ee32021-11-10 17:30:20 +0000559 // call the StartDownload synchronously to detect 'immediate' download problems
560 // the real download itself is later done in background
561 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko38662d02021-08-11 09:45:19 +0000562 // note: If the image (with vendorId+name) has already been downloaded before from some other
mpagenkoc497ee32021-11-10 17:30:20 +0000563 // valid URL, the current download request is not executed (current code delivers URL error).
564 // If the operators want to ensure that the new URL
mpagenko38662d02021-08-11 09:45:19 +0000565 // is really used, then they first have to use the 'abort' API to remove the existing image!
566 // (abort API can be used also after some successful download to just remove the image from adapter)
mpagenkoc497ee32021-11-10 17:30:20 +0000567 if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted {
568 downloadStartDone = true
569 } //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 +0000570 }
571 } else {
572 //for all following devices verify the matching vendorID
573 if onuVolthaDevice.VendorId != vendorID {
574 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
575 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
576 vendorIDMatch = false
577 }
578 }
mpagenkoc497ee32021-11-10 17:30:20 +0000579 if downloadStartDone && vendorIDMatch {
mpagenko38662d02021-08-11 09:45:19 +0000580 // start the ONU download activity for each possible device
mpagenkoc497ee32021-11-10 17:30:20 +0000581 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko59862f02021-10-11 08:53:18 +0000582 "image-id": imageIdentifier, "device-id": loDeviceID})
583 //onu upgrade handling called in background without immediate error evaluation here
584 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
585 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
586 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
587 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
588 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
589 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +0000590 } else {
591 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
mpagenkoc497ee32021-11-10 17:30:20 +0000592 if !downloadStartDone {
593 //based on above fileState more descriptive error codes would be possible, e.g
594 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko38662d02021-08-11 09:45:19 +0000595 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
596 } else { //only logical option is !vendorIDMatch
597 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
598 }
599 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
600 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000601 }
mpagenko2f2f2362021-06-07 08:25:22 +0000602 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000603 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000604 pImageResp := &loResponse
605 return pImageResp, nil
606 }
607 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000608}
609
khenaidoo7d3c5582021-08-11 18:09:44 -0400610// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530611//
612// status for the requested image
khenaidoo7d3c5582021-08-11 18:09:44 -0400613func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000614 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
615 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000616 imageIdentifier := (*in).Version
mpagenko38662d02021-08-11 09:45:19 +0000617 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000618 firstDevice := true
619 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000620 var onuVolthaDevice *voltha.Device
621 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000622 for _, pCommonID := range (*in).DeviceId {
623 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400624 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
mpagenko59862f02021-10-11 08:53:18 +0000625 vendorIDSet = false
626 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400627 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000628 if handler != nil {
629 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
630 } else {
631 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
632 devErr = errors.New("no handler found for device-id")
mpagenko38662d02021-08-11 09:45:19 +0000633 }
mpagenko59862f02021-10-11 08:53:18 +0000634 if devErr != nil || onuVolthaDevice == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000635 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
mpagenko59862f02021-10-11 08:53:18 +0000636 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000637 pImageState := &voltha.ImageState{
638 Version: (*in).Version,
639 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
640 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
641 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000642 }
mpagenko38662d02021-08-11 09:45:19 +0000643 pDeviceImageState.ImageState = pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000644 } else {
mpagenko38662d02021-08-11 09:45:19 +0000645 if firstDevice {
646 //start/verify download of the image to the adapter based on first found device only
647 // use the OnuVendor identification from first given device
648 firstDevice = false
649 vendorID = onuVolthaDevice.VendorId
650 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
651 vendorIDSet = true
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000652 logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000653 } else {
654 //for all following devices verify the matching vendorID
655 if onuVolthaDevice.VendorId != vendorID {
656 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000657 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko38662d02021-08-11 09:45:19 +0000658 } else {
659 vendorIDSet = true
660 }
661 }
662 if !vendorIDSet {
663 pImageState := &voltha.ImageState{
664 Version: (*in).Version,
665 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
666 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
667 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
668 }
669 pDeviceImageState.ImageState = pImageState
670 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400671 logger.Debugw(ctx, "image status request for", log.Fields{
672 "image-id": imageIdentifier, "device-id": loDeviceID})
673 //status request is called synchronously to collect the indications for all concerned devices
674 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenko38662d02021-08-11 09:45:19 +0000675 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000676 }
677 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000678 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000679 pImageResp := &loResponse
680 return pImageResp, nil
681 }
682 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000683}
684
khenaidoo7d3c5582021-08-11 18:09:44 -0400685// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
686func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000687 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
688 loResponse := voltha.DeviceImageResponse{}
689 imageIdentifier := (*in).Version
690 firstDevice := true
691 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000692 var vendorIDSet bool
693 var onuVolthaDevice *voltha.Device
694 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000695 for _, pCommonID := range (*in).DeviceId {
696 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400697 pDeviceImageState := &voltha.DeviceImageState{}
698 loImageState := voltha.ImageState{}
699 pDeviceImageState.ImageState = &loImageState
mpagenko59862f02021-10-11 08:53:18 +0000700 vendorIDSet = false
701 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400702 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000703 if handler != nil {
704 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
705 } else {
706 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
707 devErr = errors.New("no handler found for device-id")
708 }
709 if devErr != nil || onuVolthaDevice == nil {
710 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
711 log.Fields{"device-id": loDeviceID, "err": devErr})
khenaidoo7d3c5582021-08-11 18:09:44 -0400712 pDeviceImageState.DeviceId = loDeviceID
713 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko59862f02021-10-11 08:53:18 +0000714 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
715 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
khenaidoo7d3c5582021-08-11 18:09:44 -0400716 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoaa3afe92021-05-21 16:20:58 +0000717 } else {
mpagenko59862f02021-10-11 08:53:18 +0000718 if firstDevice {
719 //start/verify download of the image to the adapter based on first found device only
720 // use the OnuVendor identification from first given device
721 firstDevice = false
722 vendorID = onuVolthaDevice.VendorId
723 vendorIDSet = true
724 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000725 logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko59862f02021-10-11 08:53:18 +0000726 } else {
727 //for all following devices verify the matching vendorID
728 if onuVolthaDevice.VendorId != vendorID {
729 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000730 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko59862f02021-10-11 08:53:18 +0000731 pDeviceImageState.DeviceId = loDeviceID
732 pDeviceImageState.ImageState.Version = (*in).Version
733 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
734 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
735 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
736 } else {
737 vendorIDSet = true
738 }
739 }
740 if vendorIDSet {
741 // cancel the ONU upgrade activity for each possible device
742 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
743 "image-id": imageIdentifier, "device-id": loDeviceID})
744 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
745 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
mpagenkoaa3afe92021-05-21 16:20:58 +0000746 }
747 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000748 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000749 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000750 if !firstDevice {
751 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
752 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
753 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
754 }
755 pImageResp := &loResponse
756 return pImageResp, nil
757 }
758 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000759}
760
khenaidoo7d3c5582021-08-11 18:09:44 -0400761// GetOnuImages retrieves the ONU SW image status information via OMCI
762func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
763 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
764 if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530765 images, err := handler.getOnuImages(ctx)
766 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000767 return images, nil
768 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400769 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000770 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400771 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
772 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
mpagenko83144272021-04-27 10:06:22 +0000773}
774
khenaidoo7d3c5582021-08-11 18:09:44 -0400775// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530776//
777// precondition: image downloaded and not yet activated or image refers to current inactive image
khenaidoo7d3c5582021-08-11 18:09:44 -0400778func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000779 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
780 loResponse := voltha.DeviceImageResponse{}
781 imageIdentifier := (*in).Version
782 //let the deviceHandler find the adequate way of requesting the image activation
783 for _, pCommonID := range (*in).DeviceId {
784 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000785 loDeviceImageState := voltha.DeviceImageState{}
786 loDeviceImageState.DeviceId = loDeviceID
787 loImageState := voltha.ImageState{}
788 loDeviceImageState.ImageState = &loImageState
789 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000790 //compared to download procedure the vendorID (from device) is secondary here
791 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
792 // start image activation activity for each possible device
793 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
794 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
795 logger.Debugw(ctx, "onu image activation requested", log.Fields{
796 "image-id": imageIdentifier, "device-id": loDeviceID})
797 //onu activation handling called in background without immediate error evaluation here
798 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
799 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000800 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
801 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
802 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
803 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
804 } else {
805 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
806 loDeviceImageState.ImageState.Reason = pImageStates.Reason
807 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
808 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000809 } else {
810 //cannot start SW activation for requested device
811 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000812 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000813 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
814 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000815 }
mpagenko2f2f2362021-06-07 08:25:22 +0000816 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000817 }
818 pImageResp := &loResponse
819 return pImageResp, nil
820 }
821 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000822}
823
khenaidoo7d3c5582021-08-11 18:09:44 -0400824// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
praneeth nalmas5a0a5502022-12-23 15:57:00 +0530825//
826// precondition: image activated and not yet committed
khenaidoo7d3c5582021-08-11 18:09:44 -0400827func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000828 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
829 loResponse := voltha.DeviceImageResponse{}
830 imageIdentifier := (*in).Version
831 //let the deviceHandler find the adequate way of requesting the image activation
832 for _, pCommonID := range (*in).DeviceId {
833 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000834 loDeviceImageState := voltha.DeviceImageState{}
835 loDeviceImageState.DeviceId = loDeviceID
836 loImageState := voltha.ImageState{}
837 loDeviceImageState.ImageState = &loImageState
838 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000839 //compared to download procedure the vendorID (from device) is secondary here
840 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
841 // start image activation activity for each possible device
842 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
843 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
844 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
845 "image-id": imageIdentifier, "device-id": loDeviceID})
846 //onu commitment handling called in background without immediate error evaluation here
847 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
848 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000849 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
mpagenko38662d02021-08-11 09:45:19 +0000850 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
851 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
mpagenko183647c2021-06-08 15:25:04 +0000852 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
853 } else {
854 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
855 loDeviceImageState.ImageState.Reason = pImageStates.Reason
856 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
857 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000858 } else {
859 //cannot start SW commitment for requested device
860 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000861 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000862 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
863 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000864 }
mpagenko2f2f2362021-06-07 08:25:22 +0000865 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000866 }
867 pImageResp := &loResponse
868 return pImageResp, nil
869 }
870 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000871}
872
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000873// Adapter interface required methods ################ end #########
874// #################################################################
khenaidoo7d3c5582021-08-11 18:09:44 -0400875
876/*
877 *
878 * ONU inter adapter service
879 *
880 */
881
882// OnuIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400883func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400884 logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
885
886 if onuInd == nil || onuInd.OnuIndication == nil {
887 return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
888 }
889
890 onuIndication := onuInd.OnuIndication
891 onuOperstate := onuIndication.GetOperState()
892 waitForDhInstPresent := false
893 if onuOperstate == "up" {
894 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
895 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
896 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
897 //Adopt_device() arrived and DeviceHandler instance was created
898 waitForDhInstPresent = true
899 }
900 if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
901 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
902 "OnuId": onuIndication.GetOnuId(),
903 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
904 "SNR": onuIndication.GetSerialNumber()})
905
906 if onuOperstate == "up" {
907 if err := handler.createInterface(ctx, onuIndication); err != nil {
908 return nil, err
909 }
910 return &empty.Empty{}, nil
911 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
Holger Hildebrandt68854a82022-09-05 07:00:21 +0000912 if err := handler.UpdateInterface(ctx); err != nil {
ozgecanetsia76db57a2022-02-03 15:32:03 +0300913 return nil, err
914 }
915 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400916 } else {
917 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
918 return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
919 }
920 }
921 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
922 "msgToDeviceId": onuInd.DeviceId})
923 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
924}
925
926// OmciIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400927func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400928 logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
929
930 if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
931 if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
932 return nil, err
933 }
934 return &empty.Empty{}, nil
935 }
936 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
937}
938
939// DownloadTechProfile is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400940func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530941 logger.Info(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400942
943 if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
944 if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
945 return nil, err
946 }
947 return &empty.Empty{}, nil
948 }
949 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
950}
951
952// DeleteGemPort is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400953func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400954 logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
955
956 if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
957 if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
958 return nil, err
959 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000960 } else {
961 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId})
962 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400963 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000964 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400965}
966
967// DeleteTCont is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400968func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000969 logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf})
khenaidoo7d3c5582021-08-11 18:09:44 -0400970
971 if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
972 if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil {
973 return nil, err
974 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000975 } else {
976 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId})
977 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400978 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000979 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400980}
981
982/*
983 * Parent GRPC clients
984 */
985
khenaidoo55cebc62021-12-08 14:44:41 -0500986func getHash(endpoint, contextInfo string) string {
987 strToHash := endpoint + contextInfo
988 h := fnv.New128().Sum([]byte(strToHash))
989 return string(h)
990}
991
992func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) {
993 logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote})
994 oo.lockReachableFromRemote.Lock()
995 defer oo.lockReachableFromRemote.Unlock()
996 endpointHash := getHash(remote.Endpoint, remote.ContextInfo)
997 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
998 oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now()
999 oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval
1000 return
1001 }
1002 logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote})
1003 oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval}
1004}
1005
khenaidoof3333552021-12-15 16:52:31 -05001006func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool {
1007 logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo})
khenaidoo55cebc62021-12-08 14:44:41 -05001008 oo.lockReachableFromRemote.RLock()
1009 defer oo.lockReachableFromRemote.RUnlock()
1010 endpointHash := getHash(endpoint, contextInfo)
1011 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
khenaidoof3333552021-12-15 16:52:31 -05001012 logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)})
khenaidoo55cebc62021-12-08 14:44:41 -05001013 // Assume the connection is down if we did not receive 2 keep alives in succession
1014 maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2)
1015 return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait
1016 }
1017 return false
1018}
1019
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301020// stopAllGrpcClients stops all grpc clients in use
khenaidoof3333552021-12-15 16:52:31 -05001021func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) {
1022 // Stop the clients that connect to the parent
1023 oo.lockParentAdapterClients.Lock()
1024 for key := range oo.parentAdapterClients {
1025 oo.parentAdapterClients[key].Stop(ctx)
1026 delete(oo.parentAdapterClients, key)
1027 }
1028 oo.lockParentAdapterClients.Unlock()
1029
1030 // Stop core client connection
1031 oo.coreClient.Stop(ctx)
1032}
1033
khenaidoo7d3c5582021-08-11 18:09:44 -04001034func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
1035 logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
1036 oo.lockParentAdapterClients.Lock()
1037 defer oo.lockParentAdapterClients.Unlock()
1038 if _, ok := oo.parentAdapterClients[endpoint]; ok {
1039 return nil
1040 }
1041
khenaidoo55cebc62021-12-08 14:44:41 -05001042 childClient, err := vgrpc.NewClient(
1043 oo.config.AdapterEndpoint,
1044 endpoint,
khenaidoof3333552021-12-15 16:52:31 -05001045 "olt_inter_adapter_service.OltInterAdapterService",
khenaidoo55cebc62021-12-08 14:44:41 -05001046 oo.oltAdapterRestarted)
khenaidoo7d3c5582021-08-11 18:09:44 -04001047
1048 if err != nil {
1049 return err
1050 }
nikesh.krishnance4879a2023-08-01 18:36:57 +05301051 retryCodes := []codes.Code{
1052 codes.Unavailable, // server is currently unavailable
1053 codes.DeadlineExceeded, // deadline for the operation was exceeded
1054 }
1055 backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(oo.config.PerRPCRetryTimeout, 0.2))
1056 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 -04001057
1058 oo.parentAdapterClients[endpoint] = childClient
nikesh.krishnance4879a2023-08-01 18:36:57 +05301059 go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler, grpcRetryOptions)
khenaidoo7d3c5582021-08-11 18:09:44 -04001060 // Wait until we have a connection to the child adapter.
1061 // Unlimited retries or until context expires
1062 subCtx := log.WithSpanFromContext(context.TODO(), ctx)
1063 backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
1064 for {
1065 client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
1066 if err == nil && client != nil {
1067 logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
1068 break
1069 }
1070 logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
1071 // Backoff
1072 if err = backoff.Backoff(subCtx); err != nil {
1073 logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
1074 break
1075 }
1076 }
1077 return nil
1078}
1079
khenaidoo42dcdfd2021-10-19 17:34:12 -04001080func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001081 // First check from cache
1082 oo.lockParentAdapterClients.RLock()
1083 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1084 oo.lockParentAdapterClients.RUnlock()
1085 return pgClient.GetOltInterAdapterServiceClient()
1086 }
1087 oo.lockParentAdapterClients.RUnlock()
1088
1089 // Set the parent connection - can occur on restarts
1090 ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
1091 err := oo.setupParentInterAdapterClient(ctx, endpoint)
1092 cancel()
1093 if err != nil {
1094 return nil, err
1095 }
1096
1097 // Get the parent client now
1098 oo.lockParentAdapterClients.RLock()
1099 defer oo.lockParentAdapterClients.RUnlock()
1100 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1101 return pgClient.GetOltInterAdapterServiceClient()
1102 }
1103
1104 return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
1105}
1106
1107// TODO: Any action the adapter needs to do following an olt adapter restart?
1108func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
1109 logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
1110 return nil
1111}
1112
khenaidoof3333552021-12-15 16:52:31 -05001113// getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service
1114func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
1115 if conn == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -04001116 return nil
1117 }
khenaidoof3333552021-12-15 16:52:31 -05001118 return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn)
khenaidoo7d3c5582021-08-11 18:09:44 -04001119}
1120
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001121func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error {
1122 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 -08001123 var errorsList []error
1124 // delete onu persitent data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001125 onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix)
1126 logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath,
1127 "device-id": aDeviceID})
1128 onuKvbackend := &db.Backend{
1129 Client: oo.kvClient,
1130 StoreType: oo.KVStoreType,
1131 Address: oo.KVStoreAddress,
1132 Timeout: oo.KVStoreTimeout,
1133 PathPrefix: onuBaseKvStorePath,
1134 }
1135 err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID)
1136 if err != nil {
1137 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": onuBaseKvStorePath, "device-id": aDeviceID, "err": err})
1138 // continue to delete kv data, but accumulate any errors
1139 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001140 }
Girish Gowdraf10379e2022-02-02 21:49:44 -08001141 // delete pm data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001142 pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix)
1143 logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath,
1144 "device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001145 pmKvbackend := &db.Backend{
1146 Client: oo.kvClient,
1147 StoreType: oo.KVStoreType,
1148 Address: oo.KVStoreAddress,
1149 Timeout: oo.KVStoreTimeout,
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001150 PathPrefix: pmBaseKvStorePath,
Girish Gowdraf10379e2022-02-02 21:49:44 -08001151 }
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001152 err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID)
Girish Gowdraf10379e2022-02-02 21:49:44 -08001153 if err != nil {
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001154 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 -08001155 // accumulate any errors
1156 errorsList = append(errorsList, err)
1157 }
1158 if len(errorsList) > 0 {
1159 return fmt.Errorf("one or more error deleting kv data, error: %v", errorsList)
1160 }
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001161 return nil
1162}
1163
khenaidoof3333552021-12-15 16:52:31 -05001164// GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter.
1165func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error {
1166 ctx := context.Background()
1167 logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream})
1168
1169 if stream == nil {
1170 return fmt.Errorf("conn-is-nil %v", stream)
1171 }
1172 initialRequestTime := time.Now()
1173 var remoteClient *common.Connection
1174 var tempClient *common.Connection
1175 var err error
1176loop:
1177 for {
1178 tempClient, err = stream.Recv()
1179 if err != nil {
1180 logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1181 break loop
1182 }
1183 // Send a response back
1184 err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY})
1185 if err != nil {
1186 logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1187 break loop
1188 }
1189 remoteClient = tempClient
1190
1191 logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient})
1192
1193 select {
1194 case <-stream.Context().Done():
1195 logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()})
1196 break loop
1197 case <-oo.exitChannel:
1198 logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime})
1199 break loop
1200 default:
1201 }
1202 }
1203 logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime})
1204 return err
1205}
1206
khenaidoo7d3c5582021-08-11 18:09:44 -04001207/*
1208 *
1209 * Unimplemented APIs
1210 *
1211 */
1212
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301213// GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202].
khenaidoo7d3c5582021-08-11 18:09:44 -04001214// 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 -04001215func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001216 return nil, errors.New("unImplemented")
1217}
1218
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301219// SimulateAlarm is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001220func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001221 return nil, errors.New("unImplemented")
1222}
1223
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301224// SetExtValue is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001225func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001226 return nil, errors.New("unImplemented")
1227}
1228
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301229// SetSingleValue is unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001230func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
1231 return nil, errors.New("unImplemented")
1232}
1233
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301234// StartOmciTest not implemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001235func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001236 return nil, errors.New("unImplemented")
1237}
1238
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301239// SuppressEvent unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001240func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1241 return nil, errors.New("unImplemented")
1242}
1243
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301244// UnSuppressEvent unimplemented
khenaidoo7d3c5582021-08-11 18:09:44 -04001245func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1246 return nil, errors.New("unImplemented")
1247}
1248
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301249// GetImageDownloadStatus is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001250func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001251 return nil, errors.New("unImplemented")
1252}
1253
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301254// CancelImageDownload is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001255func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001256 return nil, errors.New("unImplemented")
1257}
1258
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301259// RevertImageUpdate is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001260func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001261 return nil, errors.New("unImplemented")
1262}
1263
1264// UpdateFlowsBulk is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001265func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001266 return nil, errors.New("unImplemented")
1267}
1268
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301269// SelfTestDevice unimplented
khenaidoo7d3c5582021-08-11 18:09:44 -04001270func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
1271 return nil, errors.New("unImplemented")
1272}
1273
praneeth nalmas5a0a5502022-12-23 15:57:00 +05301274// SendPacketOut sends packet out to the device
khenaidoo42dcdfd2021-10-19 17:34:12 -04001275func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001276 return nil, errors.New("unImplemented")
1277}
1278
1279// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
1280func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1281 return nil, errors.New("unImplemented")
1282}
1283
1284// DisablePort to Disable pon/nni interface - seems not to be used/required according to python code
1285func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1286 return nil, errors.New("unImplemented")
1287}
1288
1289// GetExtValue - unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001290func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001291 return nil, errors.New("unImplemented")
1292}
1293
1294// ChildDeviceLost - unimplemented
1295func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
1296 return nil, errors.New("unImplemented")
1297}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001298
1299// GetSupportedFsms - TODO: add comment
1300func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
1301 return oo.pSupportedFsms
1302}
1303
1304// LockMutexMibTemplateGenerated - TODO: add comment
1305func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
1306 oo.mutexMibTemplateGenerated.Lock()
1307}
1308
1309// UnlockMutexMibTemplateGenerated - TODO: add comment
1310func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
1311 oo.mutexMibTemplateGenerated.Unlock()
1312}
1313
1314// GetMibTemplatesGenerated - TODO: add comment
1315func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
1316 value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
1317 return value, exist
1318}
1319
1320// SetMibTemplatesGenerated - TODO: add comment
1321func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
1322 oo.mibTemplatesGenerated[mibTemplatePath] = value
1323}
1324
1325// RLockMutexDeviceHandlersMap - TODO: add comment
1326func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
1327 oo.mutexDeviceHandlersMap.RLock()
1328}
1329
1330// RUnlockMutexDeviceHandlersMap - TODO: add comment
1331func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
1332 oo.mutexDeviceHandlersMap.RUnlock()
1333}
1334
1335// GetDeviceHandler - TODO: add comment
1336func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
1337 value, exist = oo.deviceHandlers[deviceID]
1338 return value, exist
1339}