blob: 1995a9af1b9efa985d64d4e8e2481e0552bf9f9f [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package core provides the utility for onu devices, flows and statistics
18package core
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
22 "errors"
23 "fmt"
khenaidoo55cebc62021-12-08 14:44:41 -050024 "hash/fnv"
Holger Hildebrandt52f271b2022-06-02 09:32:27 +000025 "strings"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000026 "sync"
27 "time"
28
Holger Hildebrandt60652202021-11-02 11:09:36 +000029 "github.com/opencord/voltha-lib-go/v7/pkg/db"
khenaidoo7d3c5582021-08-11 18:09:44 -040030 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
dbainbri4d3a0dc2020-12-02 00:33:42 +000031
khenaidoo7d3c5582021-08-11 18:09:44 -040032 conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
khenaidoof3333552021-12-15 16:52:31 -050033 "github.com/opencord/voltha-protos/v5/go/adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040034 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040035 "github.com/opencord/voltha-protos/v5/go/health"
36 "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040037 "google.golang.org/grpc"
khenaidoo55cebc62021-12-08 14:44:41 -050038 "google.golang.org/grpc/codes"
39 "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
Holger Hildebrandtfa074992020-03-27 15:42:06 +000063//OpenONUAC structure holds the ONU core information
64type 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
102//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
163//Start starts (logs) the adapter
164func (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
khenaidoof3333552021-12-15 16:52:31 -0500170//Stop terminates the session
171func (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
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000199//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
khenaidoo7d3c5582021-08-11 18:09:44 -0400252//ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart
253func (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
khenaidoo7d3c5582021-08-11 18:09:44 -0400292//DisableDevice disables the given device
293func (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
khenaidoo7d3c5582021-08-11 18:09:44 -0400303//ReEnableDevice enables the onu device after disable
304func (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
khenaidoo7d3c5582021-08-11 18:09:44 -0400314//RebootDevice reboots the given device
315func (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
khenaidoo7d3c5582021-08-11 18:09:44 -0400370//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
khenaidoo7d3c5582021-08-11 18:09:44 -0400400//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
khenaidoo7d3c5582021-08-11 18:09:44 -0400413//DownloadImage requests downloading some image according to indications as given in request
Andrea Campanella71e546a2021-02-26 11:09:33 +0100414//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
mpagenko59862f02021-10-11 08:53:18 +0000438//ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI
Andrea Campanella71e546a2021-02-26 11:09:33 +0100439// according to indications as given in request and on success activate the image on the ONU
440//The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400441func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400442 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000443 if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400444 if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000445 logger.Debugw(ctx, "image download on omci requested", log.Fields{
khenaidoo7d3c5582021-08-11 18:09:44 -0400446 "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
447 if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
448 return nil, err
449 }
450 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000451 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400452 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
453 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000454 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400455 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
456 return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000457 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400458 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000459}
460
khenaidoo7d3c5582021-08-11 18:09:44 -0400461//GetSingleValue handles the core request to retrieve uni status
462func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500463 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
464
465 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
466 switch reqType := request.GetRequest().GetRequest().(type) {
467 case *extension.GetValueRequest_UniInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000468 return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700469 case *extension.GetValueRequest_OnuOpticalInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000470 CommChan := make(chan cmn.Message)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700471 respChan := make(chan extension.SingleGetValueResponse)
472 // Initiate the self test request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000473 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700474 return &extension.SingleGetValueResponse{
475 Response: &extension.GetValueResponse{
476 Status: extension.GetValueResponse_ERROR,
477 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
478 },
479 }, err
480 }
481 // The timeout handling is already implemented in omci_self_test_handler module
482 resp := <-respChan
483 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530484 case *extension.GetValueRequest_OnuInfo:
485 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000486 case *extension.GetValueRequest_OnuOmciStats:
487 return handler.getOnuOMCIStats(ctx)
kesavandfdf77632021-01-26 23:40:33 -0500488 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000489 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
kesavandfdf77632021-01-26 23:40:33 -0500490 }
491 }
492 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000493 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000494}
495
mpagenko83144272021-04-27 10:06:22 +0000496//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000497// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
498// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
499// The reason for that was never finally investigated.
500// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000501
khenaidoo7d3c5582021-08-11 18:09:44 -0400502// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000503// if the image is not yet present on the adapter it has to be automatically downloaded
khenaidoo7d3c5582021-08-11 18:09:44 -0400504func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000505 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
Holger Hildebrandt52f271b2022-06-02 09:32:27 +0000506 if strings.Contains((*request).Image.Url, "https:") {
507 return nil, errors.New("image download via https not supported")
508 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000509 loResponse := voltha.DeviceImageResponse{}
510 imageIdentifier := (*request).Image.Version
mpagenkoc497ee32021-11-10 17:30:20 +0000511 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000512 firstDevice := true
513 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000514 var onuVolthaDevice *voltha.Device
515 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000516 for _, pCommonID := range (*request).DeviceId {
mpagenko38662d02021-08-11 09:45:19 +0000517 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000518 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000519 loDeviceImageState := voltha.DeviceImageState{}
520 loDeviceImageState.DeviceId = loDeviceID
521 loImageState := voltha.ImageState{}
522 loDeviceImageState.ImageState = &loImageState
523 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko38662d02021-08-11 09:45:19 +0000524
mpagenko59862f02021-10-11 08:53:18 +0000525 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400526 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000527 if handler != nil {
528 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
529 } else {
530 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
531 devErr = errors.New("no handler found for device-id")
khenaidoo7d3c5582021-08-11 18:09:44 -0400532 }
mpagenko59862f02021-10-11 08:53:18 +0000533 if devErr != nil || onuVolthaDevice == nil {
534 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
535 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000536 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
537 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000538 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000539 } else {
mpagenko38662d02021-08-11 09:45:19 +0000540 if firstDevice {
541 //start/verify download of the image to the adapter based on first found device only
542 // use the OnuVendor identification from first given device
mpagenkoc497ee32021-11-10 17:30:20 +0000543
544 // note: if the request was done for a list of devices on the Voltha interface, rwCore
545 // 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 +0000546 firstDevice = false
547 vendorID = onuVolthaDevice.VendorId
548 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
mpagenkoc497ee32021-11-10 17:30:20 +0000549 logger.Infow(ctx, "download request for file",
550 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000551
mpagenkoc497ee32021-11-10 17:30:20 +0000552 // call the StartDownload synchronously to detect 'immediate' download problems
553 // the real download itself is later done in background
554 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko38662d02021-08-11 09:45:19 +0000555 // note: If the image (with vendorId+name) has already been downloaded before from some other
mpagenkoc497ee32021-11-10 17:30:20 +0000556 // valid URL, the current download request is not executed (current code delivers URL error).
557 // If the operators want to ensure that the new URL
mpagenko38662d02021-08-11 09:45:19 +0000558 // is really used, then they first have to use the 'abort' API to remove the existing image!
559 // (abort API can be used also after some successful download to just remove the image from adapter)
mpagenkoc497ee32021-11-10 17:30:20 +0000560 if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted {
561 downloadStartDone = true
562 } //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 +0000563 }
564 } else {
565 //for all following devices verify the matching vendorID
566 if onuVolthaDevice.VendorId != vendorID {
567 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
568 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
569 vendorIDMatch = false
570 }
571 }
mpagenkoc497ee32021-11-10 17:30:20 +0000572 if downloadStartDone && vendorIDMatch {
mpagenko38662d02021-08-11 09:45:19 +0000573 // start the ONU download activity for each possible device
mpagenkoc497ee32021-11-10 17:30:20 +0000574 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko59862f02021-10-11 08:53:18 +0000575 "image-id": imageIdentifier, "device-id": loDeviceID})
576 //onu upgrade handling called in background without immediate error evaluation here
577 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
578 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
579 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
580 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
581 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
582 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +0000583 } else {
584 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
mpagenkoc497ee32021-11-10 17:30:20 +0000585 if !downloadStartDone {
586 //based on above fileState more descriptive error codes would be possible, e.g
587 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko38662d02021-08-11 09:45:19 +0000588 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
589 } else { //only logical option is !vendorIDMatch
590 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
591 }
592 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
593 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000594 }
mpagenko2f2f2362021-06-07 08:25:22 +0000595 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000596 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000597 pImageResp := &loResponse
598 return pImageResp, nil
599 }
600 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000601}
602
khenaidoo7d3c5582021-08-11 18:09:44 -0400603// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
mpagenko83144272021-04-27 10:06:22 +0000604// status for the requested image
khenaidoo7d3c5582021-08-11 18:09:44 -0400605func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000606 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
607 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000608 imageIdentifier := (*in).Version
mpagenko38662d02021-08-11 09:45:19 +0000609 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000610 firstDevice := true
611 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000612 var onuVolthaDevice *voltha.Device
613 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000614 for _, pCommonID := range (*in).DeviceId {
615 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400616 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
mpagenko59862f02021-10-11 08:53:18 +0000617 vendorIDSet = false
618 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400619 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000620 if handler != nil {
621 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
622 } else {
623 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
624 devErr = errors.New("no handler found for device-id")
mpagenko38662d02021-08-11 09:45:19 +0000625 }
mpagenko59862f02021-10-11 08:53:18 +0000626 if devErr != nil || onuVolthaDevice == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000627 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
mpagenko59862f02021-10-11 08:53:18 +0000628 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000629 pImageState := &voltha.ImageState{
630 Version: (*in).Version,
631 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
632 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
633 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000634 }
mpagenko38662d02021-08-11 09:45:19 +0000635 pDeviceImageState.ImageState = pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000636 } else {
mpagenko38662d02021-08-11 09:45:19 +0000637 if firstDevice {
638 //start/verify download of the image to the adapter based on first found device only
639 // use the OnuVendor identification from first given device
640 firstDevice = false
641 vendorID = onuVolthaDevice.VendorId
642 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
643 vendorIDSet = true
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000644 logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000645 } else {
646 //for all following devices verify the matching vendorID
647 if onuVolthaDevice.VendorId != vendorID {
648 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000649 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko38662d02021-08-11 09:45:19 +0000650 } else {
651 vendorIDSet = true
652 }
653 }
654 if !vendorIDSet {
655 pImageState := &voltha.ImageState{
656 Version: (*in).Version,
657 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
658 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
659 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
660 }
661 pDeviceImageState.ImageState = pImageState
662 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400663 logger.Debugw(ctx, "image status request for", log.Fields{
664 "image-id": imageIdentifier, "device-id": loDeviceID})
665 //status request is called synchronously to collect the indications for all concerned devices
666 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenko38662d02021-08-11 09:45:19 +0000667 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000668 }
669 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000670 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000671 pImageResp := &loResponse
672 return pImageResp, nil
673 }
674 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000675}
676
khenaidoo7d3c5582021-08-11 18:09:44 -0400677// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
678func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000679 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
680 loResponse := voltha.DeviceImageResponse{}
681 imageIdentifier := (*in).Version
682 firstDevice := true
683 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000684 var vendorIDSet bool
685 var onuVolthaDevice *voltha.Device
686 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000687 for _, pCommonID := range (*in).DeviceId {
688 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400689 pDeviceImageState := &voltha.DeviceImageState{}
690 loImageState := voltha.ImageState{}
691 pDeviceImageState.ImageState = &loImageState
mpagenko59862f02021-10-11 08:53:18 +0000692 vendorIDSet = false
693 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400694 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000695 if handler != nil {
696 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
697 } else {
698 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
699 devErr = errors.New("no handler found for device-id")
700 }
701 if devErr != nil || onuVolthaDevice == nil {
702 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
703 log.Fields{"device-id": loDeviceID, "err": devErr})
khenaidoo7d3c5582021-08-11 18:09:44 -0400704 pDeviceImageState.DeviceId = loDeviceID
705 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko59862f02021-10-11 08:53:18 +0000706 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
707 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
khenaidoo7d3c5582021-08-11 18:09:44 -0400708 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoaa3afe92021-05-21 16:20:58 +0000709 } else {
mpagenko59862f02021-10-11 08:53:18 +0000710 if firstDevice {
711 //start/verify download of the image to the adapter based on first found device only
712 // use the OnuVendor identification from first given device
713 firstDevice = false
714 vendorID = onuVolthaDevice.VendorId
715 vendorIDSet = true
716 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000717 logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko59862f02021-10-11 08:53:18 +0000718 } else {
719 //for all following devices verify the matching vendorID
720 if onuVolthaDevice.VendorId != vendorID {
721 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000722 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko59862f02021-10-11 08:53:18 +0000723 pDeviceImageState.DeviceId = loDeviceID
724 pDeviceImageState.ImageState.Version = (*in).Version
725 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
726 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
727 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
728 } else {
729 vendorIDSet = true
730 }
731 }
732 if vendorIDSet {
733 // cancel the ONU upgrade activity for each possible device
734 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
735 "image-id": imageIdentifier, "device-id": loDeviceID})
736 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
737 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
mpagenkoaa3afe92021-05-21 16:20:58 +0000738 }
739 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000740 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000741 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000742 if !firstDevice {
743 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
744 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
745 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
746 }
747 pImageResp := &loResponse
748 return pImageResp, nil
749 }
750 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000751}
752
khenaidoo7d3c5582021-08-11 18:09:44 -0400753// GetOnuImages retrieves the ONU SW image status information via OMCI
754func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
755 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
756 if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530757 images, err := handler.getOnuImages(ctx)
758 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000759 return images, nil
760 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400761 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000762 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400763 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
764 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
mpagenko83144272021-04-27 10:06:22 +0000765}
766
khenaidoo7d3c5582021-08-11 18:09:44 -0400767// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
mpagenkoc26d4c02021-05-06 14:27:57 +0000768// precondition: image downloaded and not yet activated or image refers to current inactive image
khenaidoo7d3c5582021-08-11 18:09:44 -0400769func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000770 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
771 loResponse := voltha.DeviceImageResponse{}
772 imageIdentifier := (*in).Version
773 //let the deviceHandler find the adequate way of requesting the image activation
774 for _, pCommonID := range (*in).DeviceId {
775 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000776 loDeviceImageState := voltha.DeviceImageState{}
777 loDeviceImageState.DeviceId = loDeviceID
778 loImageState := voltha.ImageState{}
779 loDeviceImageState.ImageState = &loImageState
780 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000781 //compared to download procedure the vendorID (from device) is secondary here
782 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
783 // start image activation activity for each possible device
784 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
785 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
786 logger.Debugw(ctx, "onu image activation requested", log.Fields{
787 "image-id": imageIdentifier, "device-id": loDeviceID})
788 //onu activation handling called in background without immediate error evaluation here
789 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
790 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000791 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
792 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
793 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
794 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
795 } else {
796 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
797 loDeviceImageState.ImageState.Reason = pImageStates.Reason
798 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
799 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000800 } else {
801 //cannot start SW activation for requested device
802 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000803 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000804 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
805 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000806 }
mpagenko2f2f2362021-06-07 08:25:22 +0000807 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000808 }
809 pImageResp := &loResponse
810 return pImageResp, nil
811 }
812 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000813}
814
khenaidoo7d3c5582021-08-11 18:09:44 -0400815// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000816// precondition: image activated and not yet committed
khenaidoo7d3c5582021-08-11 18:09:44 -0400817func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000818 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
819 loResponse := voltha.DeviceImageResponse{}
820 imageIdentifier := (*in).Version
821 //let the deviceHandler find the adequate way of requesting the image activation
822 for _, pCommonID := range (*in).DeviceId {
823 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000824 loDeviceImageState := voltha.DeviceImageState{}
825 loDeviceImageState.DeviceId = loDeviceID
826 loImageState := voltha.ImageState{}
827 loDeviceImageState.ImageState = &loImageState
828 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000829 //compared to download procedure the vendorID (from device) is secondary here
830 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
831 // start image activation activity for each possible device
832 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
833 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
834 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
835 "image-id": imageIdentifier, "device-id": loDeviceID})
836 //onu commitment handling called in background without immediate error evaluation here
837 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
838 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000839 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
mpagenko38662d02021-08-11 09:45:19 +0000840 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
841 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
mpagenko183647c2021-06-08 15:25:04 +0000842 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
843 } else {
844 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
845 loDeviceImageState.ImageState.Reason = pImageStates.Reason
846 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
847 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000848 } else {
849 //cannot start SW commitment for requested device
850 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000851 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000852 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
853 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000854 }
mpagenko2f2f2362021-06-07 08:25:22 +0000855 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000856 }
857 pImageResp := &loResponse
858 return pImageResp, nil
859 }
860 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000861}
862
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000863// Adapter interface required methods ################ end #########
864// #################################################################
khenaidoo7d3c5582021-08-11 18:09:44 -0400865
866/*
867 *
868 * ONU inter adapter service
869 *
870 */
871
872// OnuIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400873func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400874 logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
875
876 if onuInd == nil || onuInd.OnuIndication == nil {
877 return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
878 }
879
880 onuIndication := onuInd.OnuIndication
881 onuOperstate := onuIndication.GetOperState()
882 waitForDhInstPresent := false
883 if onuOperstate == "up" {
884 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
885 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
886 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
887 //Adopt_device() arrived and DeviceHandler instance was created
888 waitForDhInstPresent = true
889 }
890 if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
891 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
892 "OnuId": onuIndication.GetOnuId(),
893 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
894 "SNR": onuIndication.GetSerialNumber()})
895
896 if onuOperstate == "up" {
897 if err := handler.createInterface(ctx, onuIndication); err != nil {
898 return nil, err
899 }
900 return &empty.Empty{}, nil
901 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
ozgecanetsia76db57a2022-02-03 15:32:03 +0300902 if err := handler.updateInterface(ctx, onuIndication); err != nil {
903 return nil, err
904 }
905 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400906 } else {
907 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
908 return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
909 }
910 }
911 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
912 "msgToDeviceId": onuInd.DeviceId})
913 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
914}
915
916// OmciIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400917func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400918 logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
919
920 if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
921 if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
922 return nil, err
923 }
924 return &empty.Empty{}, nil
925 }
926 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
927}
928
929// DownloadTechProfile is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400930func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000931 logger.Debugw(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400932
933 if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
934 if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
935 return nil, err
936 }
937 return &empty.Empty{}, nil
938 }
939 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
940}
941
942// DeleteGemPort is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400943func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400944 logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
945
946 if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
947 if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
948 return nil, err
949 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000950 } else {
951 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId})
952 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400953 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000954 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400955}
956
957// DeleteTCont is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400958func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000959 logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf})
khenaidoo7d3c5582021-08-11 18:09:44 -0400960
961 if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
962 if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil {
963 return nil, err
964 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000965 } else {
966 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId})
967 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400968 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000969 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400970}
971
972/*
973 * Parent GRPC clients
974 */
975
khenaidoo55cebc62021-12-08 14:44:41 -0500976func getHash(endpoint, contextInfo string) string {
977 strToHash := endpoint + contextInfo
978 h := fnv.New128().Sum([]byte(strToHash))
979 return string(h)
980}
981
982func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) {
983 logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote})
984 oo.lockReachableFromRemote.Lock()
985 defer oo.lockReachableFromRemote.Unlock()
986 endpointHash := getHash(remote.Endpoint, remote.ContextInfo)
987 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
988 oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now()
989 oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval
990 return
991 }
992 logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote})
993 oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval}
994}
995
khenaidoof3333552021-12-15 16:52:31 -0500996func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool {
997 logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo})
khenaidoo55cebc62021-12-08 14:44:41 -0500998 oo.lockReachableFromRemote.RLock()
999 defer oo.lockReachableFromRemote.RUnlock()
1000 endpointHash := getHash(endpoint, contextInfo)
1001 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
khenaidoof3333552021-12-15 16:52:31 -05001002 logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)})
khenaidoo55cebc62021-12-08 14:44:41 -05001003 // Assume the connection is down if we did not receive 2 keep alives in succession
1004 maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2)
1005 return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait
1006 }
1007 return false
1008}
1009
khenaidoof3333552021-12-15 16:52:31 -05001010//stopAllGrpcClients stops all grpc clients in use
1011func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) {
1012 // Stop the clients that connect to the parent
1013 oo.lockParentAdapterClients.Lock()
1014 for key := range oo.parentAdapterClients {
1015 oo.parentAdapterClients[key].Stop(ctx)
1016 delete(oo.parentAdapterClients, key)
1017 }
1018 oo.lockParentAdapterClients.Unlock()
1019
1020 // Stop core client connection
1021 oo.coreClient.Stop(ctx)
1022}
1023
khenaidoo7d3c5582021-08-11 18:09:44 -04001024func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
1025 logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
1026 oo.lockParentAdapterClients.Lock()
1027 defer oo.lockParentAdapterClients.Unlock()
1028 if _, ok := oo.parentAdapterClients[endpoint]; ok {
1029 return nil
1030 }
1031
khenaidoo55cebc62021-12-08 14:44:41 -05001032 childClient, err := vgrpc.NewClient(
1033 oo.config.AdapterEndpoint,
1034 endpoint,
khenaidoof3333552021-12-15 16:52:31 -05001035 "olt_inter_adapter_service.OltInterAdapterService",
khenaidoo55cebc62021-12-08 14:44:41 -05001036 oo.oltAdapterRestarted)
khenaidoo7d3c5582021-08-11 18:09:44 -04001037
1038 if err != nil {
1039 return err
1040 }
1041
1042 oo.parentAdapterClients[endpoint] = childClient
1043
khenaidoof3333552021-12-15 16:52:31 -05001044 go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler)
khenaidoo7d3c5582021-08-11 18:09:44 -04001045
1046 // Wait until we have a connection to the child adapter.
1047 // Unlimited retries or until context expires
1048 subCtx := log.WithSpanFromContext(context.TODO(), ctx)
1049 backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
1050 for {
1051 client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
1052 if err == nil && client != nil {
1053 logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
1054 break
1055 }
1056 logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
1057 // Backoff
1058 if err = backoff.Backoff(subCtx); err != nil {
1059 logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
1060 break
1061 }
1062 }
1063 return nil
1064}
1065
khenaidoo42dcdfd2021-10-19 17:34:12 -04001066func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001067 // First check from cache
1068 oo.lockParentAdapterClients.RLock()
1069 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1070 oo.lockParentAdapterClients.RUnlock()
1071 return pgClient.GetOltInterAdapterServiceClient()
1072 }
1073 oo.lockParentAdapterClients.RUnlock()
1074
1075 // Set the parent connection - can occur on restarts
1076 ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
1077 err := oo.setupParentInterAdapterClient(ctx, endpoint)
1078 cancel()
1079 if err != nil {
1080 return nil, err
1081 }
1082
1083 // Get the parent client now
1084 oo.lockParentAdapterClients.RLock()
1085 defer oo.lockParentAdapterClients.RUnlock()
1086 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1087 return pgClient.GetOltInterAdapterServiceClient()
1088 }
1089
1090 return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
1091}
1092
1093// TODO: Any action the adapter needs to do following an olt adapter restart?
1094func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
1095 logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
1096 return nil
1097}
1098
khenaidoof3333552021-12-15 16:52:31 -05001099// getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service
1100func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
1101 if conn == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -04001102 return nil
1103 }
khenaidoof3333552021-12-15 16:52:31 -05001104 return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn)
khenaidoo7d3c5582021-08-11 18:09:44 -04001105}
1106
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001107func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error {
1108 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 -08001109 var errorsList []error
1110 // delete onu persitent data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001111 onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix)
1112 logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath,
1113 "device-id": aDeviceID})
1114 onuKvbackend := &db.Backend{
1115 Client: oo.kvClient,
1116 StoreType: oo.KVStoreType,
1117 Address: oo.KVStoreAddress,
1118 Timeout: oo.KVStoreTimeout,
1119 PathPrefix: onuBaseKvStorePath,
1120 }
1121 err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID)
1122 if err != nil {
1123 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": onuBaseKvStorePath, "device-id": aDeviceID, "err": err})
1124 // continue to delete kv data, but accumulate any errors
1125 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001126 }
Girish Gowdraf10379e2022-02-02 21:49:44 -08001127 // delete pm data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001128 pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix)
1129 logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath,
1130 "device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001131 pmKvbackend := &db.Backend{
1132 Client: oo.kvClient,
1133 StoreType: oo.KVStoreType,
1134 Address: oo.KVStoreAddress,
1135 Timeout: oo.KVStoreTimeout,
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001136 PathPrefix: pmBaseKvStorePath,
Girish Gowdraf10379e2022-02-02 21:49:44 -08001137 }
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001138 err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID)
Girish Gowdraf10379e2022-02-02 21:49:44 -08001139 if err != nil {
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001140 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 -08001141 // accumulate any errors
1142 errorsList = append(errorsList, err)
1143 }
1144 if len(errorsList) > 0 {
1145 return fmt.Errorf("one or more error deleting kv data, error: %v", errorsList)
1146 }
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001147 return nil
1148}
1149
khenaidoof3333552021-12-15 16:52:31 -05001150// GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter.
1151func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error {
1152 ctx := context.Background()
1153 logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream})
1154
1155 if stream == nil {
1156 return fmt.Errorf("conn-is-nil %v", stream)
1157 }
1158 initialRequestTime := time.Now()
1159 var remoteClient *common.Connection
1160 var tempClient *common.Connection
1161 var err error
1162loop:
1163 for {
1164 tempClient, err = stream.Recv()
1165 if err != nil {
1166 logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1167 break loop
1168 }
1169 // Send a response back
1170 err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY})
1171 if err != nil {
1172 logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1173 break loop
1174 }
1175 remoteClient = tempClient
1176
1177 logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient})
1178
1179 select {
1180 case <-stream.Context().Done():
1181 logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()})
1182 break loop
1183 case <-oo.exitChannel:
1184 logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime})
1185 break loop
1186 default:
1187 }
1188 }
1189 logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime})
1190 return err
1191}
1192
khenaidoo7d3c5582021-08-11 18:09:44 -04001193/*
1194 *
1195 * Unimplemented APIs
1196 *
1197 */
1198
1199//GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202].
1200// OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort()
1201//
khenaidoo42dcdfd2021-10-19 17:34:12 -04001202func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001203 return nil, errors.New("unImplemented")
1204}
1205
1206//SimulateAlarm is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001207func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001208 return nil, errors.New("unImplemented")
1209}
1210
1211//SetExtValue is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001212func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001213 return nil, errors.New("unImplemented")
1214}
1215
1216//SetSingleValue is unimplemented
1217func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
1218 return nil, errors.New("unImplemented")
1219}
1220
1221//StartOmciTest not implemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001222func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001223 return nil, errors.New("unImplemented")
1224}
1225
1226//SuppressEvent unimplemented
1227func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1228 return nil, errors.New("unImplemented")
1229}
1230
1231//UnSuppressEvent unimplemented
1232func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1233 return nil, errors.New("unImplemented")
1234}
1235
1236//GetImageDownloadStatus is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001237func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001238 return nil, errors.New("unImplemented")
1239}
1240
1241//CancelImageDownload is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001242func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001243 return nil, errors.New("unImplemented")
1244}
1245
1246//RevertImageUpdate is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001247func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001248 return nil, errors.New("unImplemented")
1249}
1250
1251// UpdateFlowsBulk is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001252func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001253 return nil, errors.New("unImplemented")
1254}
1255
1256//SelfTestDevice unimplented
1257func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
1258 return nil, errors.New("unImplemented")
1259}
1260
1261//SendPacketOut sends packet out to the device
khenaidoo42dcdfd2021-10-19 17:34:12 -04001262func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001263 return nil, errors.New("unImplemented")
1264}
1265
1266// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
1267func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1268 return nil, errors.New("unImplemented")
1269}
1270
1271// DisablePort to Disable pon/nni interface - seems not to be used/required according to python code
1272func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1273 return nil, errors.New("unImplemented")
1274}
1275
1276// GetExtValue - unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001277func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001278 return nil, errors.New("unImplemented")
1279}
1280
1281// ChildDeviceLost - unimplemented
1282func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
1283 return nil, errors.New("unImplemented")
1284}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001285
1286// GetSupportedFsms - TODO: add comment
1287func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
1288 return oo.pSupportedFsms
1289}
1290
1291// LockMutexMibTemplateGenerated - TODO: add comment
1292func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
1293 oo.mutexMibTemplateGenerated.Lock()
1294}
1295
1296// UnlockMutexMibTemplateGenerated - TODO: add comment
1297func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
1298 oo.mutexMibTemplateGenerated.Unlock()
1299}
1300
1301// GetMibTemplatesGenerated - TODO: add comment
1302func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
1303 value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
1304 return value, exist
1305}
1306
1307// SetMibTemplatesGenerated - TODO: add comment
1308func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
1309 oo.mibTemplatesGenerated[mibTemplatePath] = value
1310}
1311
1312// RLockMutexDeviceHandlersMap - TODO: add comment
1313func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
1314 oo.mutexDeviceHandlersMap.RLock()
1315}
1316
1317// RUnlockMutexDeviceHandlersMap - TODO: add comment
1318func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
1319 oo.mutexDeviceHandlersMap.RUnlock()
1320}
1321
1322// GetDeviceHandler - TODO: add comment
1323func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
1324 value, exist = oo.deviceHandlers[deviceID]
1325 return value, exist
1326}