blob: 2c9ebd4b062619159bf8ddc19fce3f387e08b0dc [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 Hildebrandtfa074992020-03-27 15:42:06 +000025 "sync"
26 "time"
27
Holger Hildebrandt60652202021-11-02 11:09:36 +000028 "github.com/opencord/voltha-lib-go/v7/pkg/db"
khenaidoo7d3c5582021-08-11 18:09:44 -040029 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
dbainbri4d3a0dc2020-12-02 00:33:42 +000030
khenaidoo7d3c5582021-08-11 18:09:44 -040031 conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
32 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040033 "github.com/opencord/voltha-protos/v5/go/health"
34 "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040035 "google.golang.org/grpc"
khenaidoo55cebc62021-12-08 14:44:41 -050036 "google.golang.org/grpc/codes"
37 "google.golang.org/grpc/status"
khenaidoo7d3c5582021-08-11 18:09:44 -040038
39 "github.com/golang/protobuf/ptypes/empty"
40 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
41 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
42 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoo42dcdfd2021-10-19 17:34:12 -040043 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo7d3c5582021-08-11 18:09:44 -040044 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo42dcdfd2021-10-19 17:34:12 -040045 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
46 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidoo7d3c5582021-08-11 18:09:44 -040047 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000048
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000049 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Matteo Scandolo761f7512020-11-23 15:52:40 -080050 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandt60652202021-11-02 11:09:36 +000051 pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000052 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
53 uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000054)
55
khenaidoo55cebc62021-12-08 14:44:41 -050056type reachabilityFromRemote struct {
57 lastKeepAlive time.Time
58 keepAliveInterval int64
59}
60
Holger Hildebrandtfa074992020-03-27 15:42:06 +000061//OpenONUAC structure holds the ONU core information
62type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053063 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000064 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000065 mutexDeviceHandlersMap sync.RWMutex
khenaidoo7d3c5582021-08-11 18:09:44 -040066 coreClient *vgrpc.Client
67 parentAdapterClients map[string]*vgrpc.Client
68 lockParentAdapterClients sync.RWMutex
khenaidoo55cebc62021-12-08 14:44:41 -050069 reachableFromRemote map[string]*reachabilityFromRemote
70 lockReachableFromRemote sync.RWMutex
Himani Chawlac07fda02020-12-09 16:21:21 +053071 eventProxy eventif.EventProxy
mpagenkoaf801632020-07-03 10:00:42 +000072 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080073 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074 config *config.AdapterFlags
75 numOnus int
Matteo Scandolo127c59d2021-01-28 11:31:18 -080076 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000077 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000078 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000079 mibTemplatesGenerated map[string]bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000080 mutexMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 exitChannel chan int
82 HeartbeatCheckInterval time.Duration
83 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000084 AcceptIncrementalEvto bool
khenaidoo55cebc62021-12-08 14:44:41 -050085 pSupportedFsms *cmn.OmciDeviceFsms
86 maxTimeoutInterAdapterComm time.Duration
87 maxTimeoutReconciling time.Duration
88 pDownloadManager *swupg.AdapterDownloadManager
89 pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete
90 MetricsEnabled bool
91 mibAuditInterval time.Duration
92 omciTimeout int // in seconds
93 alarmAuditInterval time.Duration
94 dlToOnuTimeout4M time.Duration
95 rpcTimeout time.Duration
96 maxConcurrentFlowsPerUni int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000097}
98
99//NewOpenONUAC returns a new instance of OpenONU_AC
khenaidoo7d3c5582021-08-11 18:09:44 -0400100func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy,
101 kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102 var openOnuAc OpenONUAC
103 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530104 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000105 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
khenaidoo7d3c5582021-08-11 18:09:44 -0400106 openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client)
khenaidoo55cebc62021-12-08 14:44:41 -0500107 openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000108 openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000109 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800110 openOnuAc.cm = cm
khenaidoo7d3c5582021-08-11 18:09:44 -0400111 openOnuAc.coreClient = coreClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112 openOnuAc.numOnus = cfg.OnuNumber
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +0000114 openOnuAc.kvClient = kvClient
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800115 openOnuAc.KVStoreAddress = cfg.KVStoreAddress
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +0000117 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000118 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000119 openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
121 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +0000122 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +0530123 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000124 openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000126 openOnuAc.MetricsEnabled = cfg.MetricsEnabled
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000127 openOnuAc.mibAuditInterval = cfg.MibAuditInterval
Girish Gowdra0b235842021-03-09 13:06:46 -0800128 // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion
129 openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds())
Himani Chawla075f1642021-03-15 19:23:24 +0530130 openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
mpagenkoc26d4c02021-05-06 14:27:57 +0000131 openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
khenaidoo7d3c5582021-08-11 18:09:44 -0400132 openOnuAc.rpcTimeout = cfg.RPCTimeout
Girish Gowdrae95687a2021-09-08 16:30:58 -0700133 openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000134
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000135 openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000136 "mib-synchronizer": {
137 //mibSyncFsm, // Implements the MIB synchronization state machine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000138 DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530139 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000140 AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000141 // map[string]func() error{
142 // "mib-upload": onuDeviceEntry.MibUploadTask,
143 // "mib-template": onuDeviceEntry.MibTemplateTask,
144 // "get-mds": onuDeviceEntry.GetMdsTask,
145 // "mib-audit": onuDeviceEntry.GetMdsTask,
146 // "mib-resync": onuDeviceEntry.MibResyncTask,
147 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
148 // },
149 },
150 }
151
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx)
153 openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx)
mpagenkoc26d4c02021-05-06 14:27:57 +0000154 openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
mpagenkoc8bba412021-01-15 15:38:44 +0000155
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000156 return &openOnuAc
157}
158
159//Start starts (logs) the adapter
160func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 logger.Info(ctx, "starting-openonu-adapter")
mpagenkoc8bba412021-01-15 15:38:44 +0000162
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163 return nil
164}
165
Himani Chawla6d2ae152020-09-02 13:11:20 +0530166/*
167//stop terminates the session
168func (oo *OpenONUAC) stop(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000169 logger.Info(ctx,"stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170 oo.exitChannel <- 1
dbainbri4d3a0dc2020-12-02 00:33:42 +0000171 logger.Info(ctx,"device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000172 return nil
173}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530174*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175
Himani Chawla6d2ae152020-09-02 13:11:20 +0530176func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 oo.mutexDeviceHandlersMap.Lock()
178 defer oo.mutexDeviceHandlersMap.Unlock()
179 if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist {
180 oo.deviceHandlers[agent.DeviceID] = agent
181 oo.deviceHandlers[agent.DeviceID].start(ctx)
182 if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist {
183 logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID})
184 oo.deviceHandlersCreateChan[agent.DeviceID] <- true
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000185 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000186 }
187}
188
Himani Chawla6d2ae152020-09-02 13:11:20 +0530189func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000190 oo.mutexDeviceHandlersMap.Lock()
191 defer oo.mutexDeviceHandlersMap.Unlock()
192 delete(oo.deviceHandlers, agent.DeviceID)
193 delete(oo.deviceHandlersCreateChan, agent.DeviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000194}
195
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000196//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000197func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000198 oo.mutexDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000199 agent, ok := oo.deviceHandlers[deviceID]
200 if aWait && !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000201 logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000202 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000203 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
204 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
205 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800206 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000207 //keep the read sema short to allow for subsequent write
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000208 oo.mutexDeviceHandlersMap.Unlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000209 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
210 // so it might be needed to wait here for that event with some timeout
211 select {
212 case <-time.After(1 * time.Second): //timer may be discussed ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000213 logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000214 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800215 case <-deviceCreateChan:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000216 logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000217 oo.mutexDeviceHandlersMap.RLock()
218 defer oo.mutexDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000219 return oo.deviceHandlers[deviceID]
220 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000222 oo.mutexDeviceHandlersMap.Unlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000223 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000224}
225
khenaidoo7d3c5582021-08-11 18:09:44 -0400226// GetHealthStatus is used as a service readiness validation as a grpc connection
khenaidoo55cebc62021-12-08 14:44:41 -0500227func (oo *OpenONUAC) GetHealthStatus(ctx context.Context, clientConn *common.Connection) (*health.HealthStatus, error) {
228 // Update the remote reachability
229 oo.updateReachabilityFromRemote(ctx, clientConn)
230
khenaidoo42dcdfd2021-10-19 17:34:12 -0400231 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000232}
233
khenaidoo7d3c5582021-08-11 18:09:44 -0400234// AdoptDevice creates a new device handler if not present already and then adopts the device
235func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000236 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000237 logger.Warn(ctx, "voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400238 return nil, errors.New("nil-device")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000239 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000240 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530241 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000242 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400243 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000244 oo.addDeviceHandlerToMap(ctx, handler)
khenaidoo7d3c5582021-08-11 18:09:44 -0400245
246 // Setup the grpc communication with the parent adapter
247 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
248 // TODO: Cleanup on failure needed
249 return nil, err
250 }
251
252 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000253 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400254 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000255}
256
khenaidoo7d3c5582021-08-11 18:09:44 -0400257//ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart
258func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000259 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000260 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400261 return nil, errors.New("nil-device")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000262 }
khenaidoo55cebc62021-12-08 14:44:41 -0500263 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId})
264
265 // Check whether the grpc client in the adapter of the parent device can reach us yet
266 if !oo.isReachableFromRemote(device.ProxyAddress.AdapterEndpoint, device.ParentId) {
267 return nil, status.Errorf(codes.Unavailable, "adapter-not-reachable-from-parent-%s", device.ProxyAddress.AdapterEndpoint)
268 }
269
Himani Chawla6d2ae152020-09-02 13:11:20 +0530270 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400272 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000273 oo.addDeviceHandlerToMap(ctx, handler)
274 handler.device = device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400275 if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{
khenaidoo7d3c5582021-08-11 18:09:44 -0400276 DeviceId: device.Id,
277 OperStatus: voltha.OperStatus_RECONCILING,
278 ConnStatus: device.ConnectStatus,
279 }); err != nil {
280 return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error())
Maninderb5187552021-03-23 22:23:42 +0530281 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400282 // Setup the grpc communication with the parent adapter
283 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
284 // TODO: Cleanup on failure needed
285 return nil, err
286 }
287
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000288 handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false)
khenaidoo7d3c5582021-08-11 18:09:44 -0400289 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000290 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000291 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400292 return nil, fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000293 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400294 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295}
296
khenaidoo7d3c5582021-08-11 18:09:44 -0400297//DisableDevice disables the given device
298func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
300 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400301 go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
302 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300303 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000304 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400305 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000306}
307
khenaidoo7d3c5582021-08-11 18:09:44 -0400308//ReEnableDevice enables the onu device after disable
309func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
311 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400312 go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
313 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300314 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000315 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400316 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000317}
318
khenaidoo7d3c5582021-08-11 18:09:44 -0400319//RebootDevice reboots the given device
320func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000321 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
322 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400323 go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking
324 return &empty.Empty{}, nil
ozgecanetsiae11479f2020-07-06 09:44:47 +0300325 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000326 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400327 return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000328}
329
khenaidoo7d3c5582021-08-11 18:09:44 -0400330// DeleteDevice deletes the given device
331func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
332 nctx := log.WithSpanFromContext(context.Background(), ctx)
khenaidoo7d3c5582021-08-11 18:09:44 -0400333 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 +0000334
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra0e533642021-03-02 22:02:51 -0800336 var errorsList []error
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000337
338 handler.mutexDeletionInProgressFlag.Lock()
339 handler.deletionInProgress = true
340 handler.mutexDeletionInProgressFlag.Unlock()
341
Holger Hildebrandt60652202021-11-02 11:09:36 +0000342 if err := handler.resetFsms(ctx, true); err != nil {
343 errorsList = append(errorsList, err)
344 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700345 for _, uni := range handler.uniEntityMap {
346 if handler.GetFlowMonitoringIsRunning(uni.UniID) {
347 handler.stopFlowMonitoringRoutine[uni.UniID] <- true
348 logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id})
349 }
350 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000351 //don't leave any garbage in kv-store
352 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
353 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000354 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000355 oo.deleteDeviceHandlerToMap(handler)
356 go handler.PrepareForGarbageCollection(ctx, handler.DeviceID)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000357
Girish Gowdra0e533642021-03-02 22:02:51 -0800358 if len(errorsList) > 0 {
359 logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400360 return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
Girish Gowdra0e533642021-03-02 22:02:51 -0800361 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400362 return &empty.Empty{}, nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000363 }
Holger Hildebrandt60652202021-11-02 11:09:36 +0000364 logger.Infow(ctx, "no handler found for device-deletion - trying to delete remaining data in the kv-store ", log.Fields{"device-id": device.Id})
365
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000366 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
367 return nil, err
Holger Hildebrandt60652202021-11-02 11:09:36 +0000368 }
369 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000370}
371
khenaidoo7d3c5582021-08-11 18:09:44 -0400372//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400373func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400374 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000375
mpagenkofc4f56e2020-11-04 17:17:49 +0000376 //flow config is relayed to handler even if the device might be in some 'inactive' state
377 // let the handler or related FSM's decide, what to do with the modified flow state info
378 // 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 +0000379
380 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000381 // but processing is continued for flowUpdate possibly also set in the request
khenaidoo7d3c5582021-08-11 18:09:44 -0400382 if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil {
383 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000384 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400385 if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil {
386 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000387 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400388 if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil {
389 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000390 }
391
khenaidoo7d3c5582021-08-11 18:09:44 -0400392 if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil {
393 if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
394 return nil, err
395 }
396 return &empty.Empty{}, nil
mpagenkodff5dda2020-08-28 11:52:01 +0000397 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400398 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id})
399 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000400}
401
khenaidoo7d3c5582021-08-11 18:09:44 -0400402//UpdatePmConfig returns PmConfigs nil or error
khenaidoo42dcdfd2021-10-19 17:34:12 -0400403func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400404 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId})
405 if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil {
406 if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil {
407 return nil, err
408 }
409 return &empty.Empty{}, nil
Girish Gowdrae09a6202021-01-12 18:10:59 -0800410 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400411 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId})
412 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000413}
414
khenaidoo7d3c5582021-08-11 18:09:44 -0400415//DownloadImage requests downloading some image according to indications as given in request
Andrea Campanella71e546a2021-02-26 11:09:33 +0100416//The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400417func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400418 ctx = log.WithSpanFromContext(context.Background(), ctx)
419 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000420 if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400421 logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image})
mpagenko15ff4a52021-03-02 10:09:20 +0000422 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
423 // the download itself is later done in background
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000424 if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400425 return nil, err
426 }
427 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000428 }
429 // image already exists
khenaidoo7d3c5582021-08-11 18:09:44 -0400430 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image})
431 return imageInfo.Image, nil
mpagenkoc8bba412021-01-15 15:38:44 +0000432 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400433
434 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000435}
436
mpagenko59862f02021-10-11 08:53:18 +0000437//ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI
Andrea Campanella71e546a2021-02-26 11:09:33 +0100438// according to indications as given in request and on success activate the image on the ONU
439//The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400440func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400441 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000442 if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400443 if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000444 logger.Debugw(ctx, "image download on omci requested", log.Fields{
khenaidoo7d3c5582021-08-11 18:09:44 -0400445 "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
446 if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
447 return nil, err
448 }
449 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000450 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400451 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
452 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000453 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400454 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
455 return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000456 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400457 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000458}
459
khenaidoo7d3c5582021-08-11 18:09:44 -0400460//GetSingleValue handles the core request to retrieve uni status
461func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500462 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
463
464 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
465 switch reqType := request.GetRequest().GetRequest().(type) {
466 case *extension.GetValueRequest_UniInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000467 return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700468 case *extension.GetValueRequest_OnuOpticalInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000469 CommChan := make(chan cmn.Message)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700470 respChan := make(chan extension.SingleGetValueResponse)
471 // Initiate the self test request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000472 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700473 return &extension.SingleGetValueResponse{
474 Response: &extension.GetValueResponse{
475 Status: extension.GetValueResponse_ERROR,
476 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
477 },
478 }, err
479 }
480 // The timeout handling is already implemented in omci_self_test_handler module
481 resp := <-respChan
482 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530483 case *extension.GetValueRequest_OnuInfo:
484 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
kesavandfdf77632021-01-26 23:40:33 -0500485 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000486 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
kesavandfdf77632021-01-26 23:40:33 -0500487
488 }
489 }
490 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000491 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000492}
493
mpagenko83144272021-04-27 10:06:22 +0000494//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000495// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
496// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
497// The reason for that was never finally investigated.
498// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000499
khenaidoo7d3c5582021-08-11 18:09:44 -0400500// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000501// if the image is not yet present on the adapter it has to be automatically downloaded
khenaidoo7d3c5582021-08-11 18:09:44 -0400502func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000503 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
504 loResponse := voltha.DeviceImageResponse{}
505 imageIdentifier := (*request).Image.Version
mpagenkoc497ee32021-11-10 17:30:20 +0000506 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000507 firstDevice := true
508 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000509 var onuVolthaDevice *voltha.Device
510 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000511 for _, pCommonID := range (*request).DeviceId {
mpagenko38662d02021-08-11 09:45:19 +0000512 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000513 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000514 loDeviceImageState := voltha.DeviceImageState{}
515 loDeviceImageState.DeviceId = loDeviceID
516 loImageState := voltha.ImageState{}
517 loDeviceImageState.ImageState = &loImageState
518 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko38662d02021-08-11 09:45:19 +0000519
mpagenko59862f02021-10-11 08:53:18 +0000520 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400521 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000522 if handler != nil {
523 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
524 } else {
525 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
526 devErr = errors.New("no handler found for device-id")
khenaidoo7d3c5582021-08-11 18:09:44 -0400527 }
mpagenko59862f02021-10-11 08:53:18 +0000528 if devErr != nil || onuVolthaDevice == nil {
529 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
530 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000531 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
532 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000533 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000534 } else {
mpagenko38662d02021-08-11 09:45:19 +0000535 if firstDevice {
536 //start/verify download of the image to the adapter based on first found device only
537 // use the OnuVendor identification from first given device
mpagenkoc497ee32021-11-10 17:30:20 +0000538
539 // note: if the request was done for a list of devices on the Voltha interface, rwCore
540 // 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 +0000541 firstDevice = false
542 vendorID = onuVolthaDevice.VendorId
543 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
mpagenkoc497ee32021-11-10 17:30:20 +0000544 logger.Infow(ctx, "download request for file",
545 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000546
mpagenkoc497ee32021-11-10 17:30:20 +0000547 // call the StartDownload synchronously to detect 'immediate' download problems
548 // the real download itself is later done in background
549 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko38662d02021-08-11 09:45:19 +0000550 // note: If the image (with vendorId+name) has already been downloaded before from some other
mpagenkoc497ee32021-11-10 17:30:20 +0000551 // valid URL, the current download request is not executed (current code delivers URL error).
552 // If the operators want to ensure that the new URL
mpagenko38662d02021-08-11 09:45:19 +0000553 // is really used, then they first have to use the 'abort' API to remove the existing image!
554 // (abort API can be used also after some successful download to just remove the image from adapter)
mpagenkoc497ee32021-11-10 17:30:20 +0000555 if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted {
556 downloadStartDone = true
557 } //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 +0000558 }
559 } else {
560 //for all following devices verify the matching vendorID
561 if onuVolthaDevice.VendorId != vendorID {
562 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
563 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
564 vendorIDMatch = false
565 }
566 }
mpagenkoc497ee32021-11-10 17:30:20 +0000567 if downloadStartDone && vendorIDMatch {
mpagenko38662d02021-08-11 09:45:19 +0000568 // start the ONU download activity for each possible device
mpagenkoc497ee32021-11-10 17:30:20 +0000569 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko59862f02021-10-11 08:53:18 +0000570 "image-id": imageIdentifier, "device-id": loDeviceID})
571 //onu upgrade handling called in background without immediate error evaluation here
572 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
573 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
574 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
575 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
576 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
577 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +0000578 } else {
579 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
mpagenkoc497ee32021-11-10 17:30:20 +0000580 if !downloadStartDone {
581 //based on above fileState more descriptive error codes would be possible, e.g
582 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko38662d02021-08-11 09:45:19 +0000583 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
584 } else { //only logical option is !vendorIDMatch
585 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
586 }
587 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
588 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000589 }
mpagenko2f2f2362021-06-07 08:25:22 +0000590 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000591 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000592 pImageResp := &loResponse
593 return pImageResp, nil
594 }
595 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000596}
597
khenaidoo7d3c5582021-08-11 18:09:44 -0400598// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
mpagenko83144272021-04-27 10:06:22 +0000599// status for the requested image
khenaidoo7d3c5582021-08-11 18:09:44 -0400600func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000601 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
602 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000603 imageIdentifier := (*in).Version
mpagenko38662d02021-08-11 09:45:19 +0000604 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000605 firstDevice := true
606 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000607 var onuVolthaDevice *voltha.Device
608 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000609 for _, pCommonID := range (*in).DeviceId {
610 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400611 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
mpagenko59862f02021-10-11 08:53:18 +0000612 vendorIDSet = false
613 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400614 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000615 if handler != nil {
616 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
617 } else {
618 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
619 devErr = errors.New("no handler found for device-id")
mpagenko38662d02021-08-11 09:45:19 +0000620 }
mpagenko59862f02021-10-11 08:53:18 +0000621 if devErr != nil || onuVolthaDevice == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000622 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
mpagenko59862f02021-10-11 08:53:18 +0000623 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000624 pImageState := &voltha.ImageState{
625 Version: (*in).Version,
626 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
627 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
628 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000629 }
mpagenko38662d02021-08-11 09:45:19 +0000630 pDeviceImageState.ImageState = pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000631 } else {
mpagenko38662d02021-08-11 09:45:19 +0000632 if firstDevice {
633 //start/verify download of the image to the adapter based on first found device only
634 // use the OnuVendor identification from first given device
635 firstDevice = false
636 vendorID = onuVolthaDevice.VendorId
637 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
638 vendorIDSet = true
639 logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier})
640 } else {
641 //for all following devices verify the matching vendorID
642 if onuVolthaDevice.VendorId != vendorID {
643 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
644 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
645 } else {
646 vendorIDSet = true
647 }
648 }
649 if !vendorIDSet {
650 pImageState := &voltha.ImageState{
651 Version: (*in).Version,
652 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
653 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
654 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
655 }
656 pDeviceImageState.ImageState = pImageState
657 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400658 logger.Debugw(ctx, "image status request for", log.Fields{
659 "image-id": imageIdentifier, "device-id": loDeviceID})
660 //status request is called synchronously to collect the indications for all concerned devices
661 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenko38662d02021-08-11 09:45:19 +0000662 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000663 }
664 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000665 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000666 pImageResp := &loResponse
667 return pImageResp, nil
668 }
669 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000670}
671
khenaidoo7d3c5582021-08-11 18:09:44 -0400672// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
673func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000674 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
675 loResponse := voltha.DeviceImageResponse{}
676 imageIdentifier := (*in).Version
677 firstDevice := true
678 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000679 var vendorIDSet bool
680 var onuVolthaDevice *voltha.Device
681 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000682 for _, pCommonID := range (*in).DeviceId {
683 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400684 pDeviceImageState := &voltha.DeviceImageState{}
685 loImageState := voltha.ImageState{}
686 pDeviceImageState.ImageState = &loImageState
mpagenko59862f02021-10-11 08:53:18 +0000687 vendorIDSet = false
688 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400689 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000690 if handler != nil {
691 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
692 } else {
693 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
694 devErr = errors.New("no handler found for device-id")
695 }
696 if devErr != nil || onuVolthaDevice == nil {
697 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
698 log.Fields{"device-id": loDeviceID, "err": devErr})
khenaidoo7d3c5582021-08-11 18:09:44 -0400699 pDeviceImageState.DeviceId = loDeviceID
700 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko59862f02021-10-11 08:53:18 +0000701 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
702 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
khenaidoo7d3c5582021-08-11 18:09:44 -0400703 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoaa3afe92021-05-21 16:20:58 +0000704 } else {
mpagenko59862f02021-10-11 08:53:18 +0000705 if firstDevice {
706 //start/verify download of the image to the adapter based on first found device only
707 // use the OnuVendor identification from first given device
708 firstDevice = false
709 vendorID = onuVolthaDevice.VendorId
710 vendorIDSet = true
711 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
712 logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier})
713 } else {
714 //for all following devices verify the matching vendorID
715 if onuVolthaDevice.VendorId != vendorID {
716 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
717 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
718 pDeviceImageState.DeviceId = loDeviceID
719 pDeviceImageState.ImageState.Version = (*in).Version
720 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
721 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
722 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
723 } else {
724 vendorIDSet = true
725 }
726 }
727 if vendorIDSet {
728 // cancel the ONU upgrade activity for each possible device
729 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
730 "image-id": imageIdentifier, "device-id": loDeviceID})
731 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
732 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
mpagenkoaa3afe92021-05-21 16:20:58 +0000733 }
734 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000735 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000736 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000737 if !firstDevice {
738 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
739 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
740 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
741 }
742 pImageResp := &loResponse
743 return pImageResp, nil
744 }
745 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000746}
747
khenaidoo7d3c5582021-08-11 18:09:44 -0400748// GetOnuImages retrieves the ONU SW image status information via OMCI
749func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
750 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
751 if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530752 images, err := handler.getOnuImages(ctx)
753 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000754 return images, nil
755 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400756 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000757 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400758 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
759 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
mpagenko83144272021-04-27 10:06:22 +0000760}
761
khenaidoo7d3c5582021-08-11 18:09:44 -0400762// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
mpagenkoc26d4c02021-05-06 14:27:57 +0000763// precondition: image downloaded and not yet activated or image refers to current inactive image
khenaidoo7d3c5582021-08-11 18:09:44 -0400764func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000765 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
766 loResponse := voltha.DeviceImageResponse{}
767 imageIdentifier := (*in).Version
768 //let the deviceHandler find the adequate way of requesting the image activation
769 for _, pCommonID := range (*in).DeviceId {
770 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000771 loDeviceImageState := voltha.DeviceImageState{}
772 loDeviceImageState.DeviceId = loDeviceID
773 loImageState := voltha.ImageState{}
774 loDeviceImageState.ImageState = &loImageState
775 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000776 //compared to download procedure the vendorID (from device) is secondary here
777 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
778 // start image activation activity for each possible device
779 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
780 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
781 logger.Debugw(ctx, "onu image activation requested", log.Fields{
782 "image-id": imageIdentifier, "device-id": loDeviceID})
783 //onu activation handling called in background without immediate error evaluation here
784 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
785 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000786 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
787 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
788 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
789 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
790 } else {
791 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
792 loDeviceImageState.ImageState.Reason = pImageStates.Reason
793 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
794 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000795 } else {
796 //cannot start SW activation for requested device
797 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000798 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000799 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
800 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000801 }
mpagenko2f2f2362021-06-07 08:25:22 +0000802 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000803 }
804 pImageResp := &loResponse
805 return pImageResp, nil
806 }
807 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000808}
809
khenaidoo7d3c5582021-08-11 18:09:44 -0400810// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000811// precondition: image activated and not yet committed
khenaidoo7d3c5582021-08-11 18:09:44 -0400812func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000813 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
814 loResponse := voltha.DeviceImageResponse{}
815 imageIdentifier := (*in).Version
816 //let the deviceHandler find the adequate way of requesting the image activation
817 for _, pCommonID := range (*in).DeviceId {
818 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000819 loDeviceImageState := voltha.DeviceImageState{}
820 loDeviceImageState.DeviceId = loDeviceID
821 loImageState := voltha.ImageState{}
822 loDeviceImageState.ImageState = &loImageState
823 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000824 //compared to download procedure the vendorID (from device) is secondary here
825 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
826 // start image activation activity for each possible device
827 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
828 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
829 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
830 "image-id": imageIdentifier, "device-id": loDeviceID})
831 //onu commitment handling called in background without immediate error evaluation here
832 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
833 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000834 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
mpagenko38662d02021-08-11 09:45:19 +0000835 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
836 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
mpagenko183647c2021-06-08 15:25:04 +0000837 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
838 } else {
839 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
840 loDeviceImageState.ImageState.Reason = pImageStates.Reason
841 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
842 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000843 } else {
844 //cannot start SW commitment for requested device
845 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000846 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000847 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
848 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000849 }
mpagenko2f2f2362021-06-07 08:25:22 +0000850 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000851 }
852 pImageResp := &loResponse
853 return pImageResp, nil
854 }
855 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000856}
857
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000858// Adapter interface required methods ################ end #########
859// #################################################################
khenaidoo7d3c5582021-08-11 18:09:44 -0400860
861/*
862 *
863 * ONU inter adapter service
864 *
865 */
866
867// OnuIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400868func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400869 logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
870
871 if onuInd == nil || onuInd.OnuIndication == nil {
872 return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
873 }
874
875 onuIndication := onuInd.OnuIndication
876 onuOperstate := onuIndication.GetOperState()
877 waitForDhInstPresent := false
878 if onuOperstate == "up" {
879 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
880 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
881 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
882 //Adopt_device() arrived and DeviceHandler instance was created
883 waitForDhInstPresent = true
884 }
885 if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
886 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
887 "OnuId": onuIndication.GetOnuId(),
888 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
889 "SNR": onuIndication.GetSerialNumber()})
890
891 if onuOperstate == "up" {
892 if err := handler.createInterface(ctx, onuIndication); err != nil {
893 return nil, err
894 }
895 return &empty.Empty{}, nil
896 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
ozgecanetsia76db57a2022-02-03 15:32:03 +0300897 if err := handler.updateInterface(ctx, onuIndication); err != nil {
898 return nil, err
899 }
900 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400901 } else {
902 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
903 return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
904 }
905 }
906 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
907 "msgToDeviceId": onuInd.DeviceId})
908 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
909}
910
911// OmciIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400912func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400913 logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
914
915 if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
916 if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
917 return nil, err
918 }
919 return &empty.Empty{}, nil
920 }
921 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
922}
923
924// DownloadTechProfile is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400925func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000926 logger.Debugw(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400927
928 if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
929 if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
930 return nil, err
931 }
932 return &empty.Empty{}, nil
933 }
934 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
935}
936
937// DeleteGemPort is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400938func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400939 logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
940
941 if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
942 if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
943 return nil, err
944 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000945 } else {
946 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId})
947 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400948 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000949 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400950}
951
952// DeleteTCont is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400953func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000954 logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf})
khenaidoo7d3c5582021-08-11 18:09:44 -0400955
956 if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
957 if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); 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": tConf.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/*
968 * Parent GRPC clients
969 */
970
khenaidoo55cebc62021-12-08 14:44:41 -0500971func getHash(endpoint, contextInfo string) string {
972 strToHash := endpoint + contextInfo
973 h := fnv.New128().Sum([]byte(strToHash))
974 return string(h)
975}
976
977func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) {
978 logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote})
979 oo.lockReachableFromRemote.Lock()
980 defer oo.lockReachableFromRemote.Unlock()
981 endpointHash := getHash(remote.Endpoint, remote.ContextInfo)
982 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
983 oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now()
984 oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval
985 return
986 }
987 logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote})
988 oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval}
989}
990
991func (oo *OpenONUAC) isReachableFromRemote(endpoint string, contextInfo string) bool {
992 oo.lockReachableFromRemote.RLock()
993 defer oo.lockReachableFromRemote.RUnlock()
994 endpointHash := getHash(endpoint, contextInfo)
995 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
996 // Assume the connection is down if we did not receive 2 keep alives in succession
997 maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2)
998 return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait
999 }
1000 return false
1001}
1002
khenaidoo7d3c5582021-08-11 18:09:44 -04001003func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
1004 logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
1005 oo.lockParentAdapterClients.Lock()
1006 defer oo.lockParentAdapterClients.Unlock()
1007 if _, ok := oo.parentAdapterClients[endpoint]; ok {
1008 return nil
1009 }
1010
khenaidoo55cebc62021-12-08 14:44:41 -05001011 childClient, err := vgrpc.NewClient(
1012 oo.config.AdapterEndpoint,
1013 endpoint,
1014 oo.oltAdapterRestarted)
khenaidoo7d3c5582021-08-11 18:09:44 -04001015
1016 if err != nil {
1017 return err
1018 }
1019
1020 oo.parentAdapterClients[endpoint] = childClient
1021
khenaidoo55cebc62021-12-08 14:44:41 -05001022 go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), setAndTestOltInterAdapterServiceHandler)
khenaidoo7d3c5582021-08-11 18:09:44 -04001023
1024 // Wait until we have a connection to the child adapter.
1025 // Unlimited retries or until context expires
1026 subCtx := log.WithSpanFromContext(context.TODO(), ctx)
1027 backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
1028 for {
1029 client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
1030 if err == nil && client != nil {
1031 logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
1032 break
1033 }
1034 logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
1035 // Backoff
1036 if err = backoff.Backoff(subCtx); err != nil {
1037 logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
1038 break
1039 }
1040 }
1041 return nil
1042}
1043
khenaidoo42dcdfd2021-10-19 17:34:12 -04001044func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001045 // First check from cache
1046 oo.lockParentAdapterClients.RLock()
1047 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1048 oo.lockParentAdapterClients.RUnlock()
1049 return pgClient.GetOltInterAdapterServiceClient()
1050 }
1051 oo.lockParentAdapterClients.RUnlock()
1052
1053 // Set the parent connection - can occur on restarts
1054 ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
1055 err := oo.setupParentInterAdapterClient(ctx, endpoint)
1056 cancel()
1057 if err != nil {
1058 return nil, err
1059 }
1060
1061 // Get the parent client now
1062 oo.lockParentAdapterClients.RLock()
1063 defer oo.lockParentAdapterClients.RUnlock()
1064 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1065 return pgClient.GetOltInterAdapterServiceClient()
1066 }
1067
1068 return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
1069}
1070
1071// TODO: Any action the adapter needs to do following an olt adapter restart?
1072func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
1073 logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
1074 return nil
1075}
1076
khenaidoo55cebc62021-12-08 14:44:41 -05001077// setAndTestOltInterAdapterServiceHandler is used to test whether the remote gRPC service is up
1078func setAndTestOltInterAdapterServiceHandler(ctx context.Context, conn *grpc.ClientConn, clientConn *common.Connection) interface{} {
khenaidoo42dcdfd2021-10-19 17:34:12 -04001079 svc := olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn)
khenaidoo55cebc62021-12-08 14:44:41 -05001080 if h, err := svc.GetHealthStatus(ctx, clientConn); err != nil || h.State != health.HealthStatus_HEALTHY {
khenaidoo7d3c5582021-08-11 18:09:44 -04001081 return nil
1082 }
1083 return svc
1084}
1085
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001086func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error {
1087 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 -08001088 var errorsList []error
1089 // delete onu persitent data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001090 onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix)
1091 logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath,
1092 "device-id": aDeviceID})
1093 onuKvbackend := &db.Backend{
1094 Client: oo.kvClient,
1095 StoreType: oo.KVStoreType,
1096 Address: oo.KVStoreAddress,
1097 Timeout: oo.KVStoreTimeout,
1098 PathPrefix: onuBaseKvStorePath,
1099 }
1100 err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID)
1101 if err != nil {
1102 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": onuBaseKvStorePath, "device-id": aDeviceID, "err": err})
1103 // continue to delete kv data, but accumulate any errors
1104 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001105 }
Girish Gowdraf10379e2022-02-02 21:49:44 -08001106 // delete pm data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001107 pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix)
1108 logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath,
1109 "device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001110 pmKvbackend := &db.Backend{
1111 Client: oo.kvClient,
1112 StoreType: oo.KVStoreType,
1113 Address: oo.KVStoreAddress,
1114 Timeout: oo.KVStoreTimeout,
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001115 PathPrefix: pmBaseKvStorePath,
Girish Gowdraf10379e2022-02-02 21:49:44 -08001116 }
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001117 err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID)
Girish Gowdraf10379e2022-02-02 21:49:44 -08001118 if err != nil {
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001119 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 -08001120 // accumulate any errors
1121 errorsList = append(errorsList, err)
1122 }
1123 if len(errorsList) > 0 {
1124 return fmt.Errorf("one or more error deleting kv data, error: %v", errorsList)
1125 }
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001126 return nil
1127}
1128
khenaidoo7d3c5582021-08-11 18:09:44 -04001129/*
1130 *
1131 * Unimplemented APIs
1132 *
1133 */
1134
1135//GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202].
1136// OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort()
1137//
khenaidoo42dcdfd2021-10-19 17:34:12 -04001138func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001139 return nil, errors.New("unImplemented")
1140}
1141
1142//SimulateAlarm is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001143func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001144 return nil, errors.New("unImplemented")
1145}
1146
1147//SetExtValue is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001148func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001149 return nil, errors.New("unImplemented")
1150}
1151
1152//SetSingleValue is unimplemented
1153func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
1154 return nil, errors.New("unImplemented")
1155}
1156
1157//StartOmciTest not implemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001158func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001159 return nil, errors.New("unImplemented")
1160}
1161
1162//SuppressEvent unimplemented
1163func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1164 return nil, errors.New("unImplemented")
1165}
1166
1167//UnSuppressEvent unimplemented
1168func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1169 return nil, errors.New("unImplemented")
1170}
1171
1172//GetImageDownloadStatus is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001173func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001174 return nil, errors.New("unImplemented")
1175}
1176
1177//CancelImageDownload is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001178func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001179 return nil, errors.New("unImplemented")
1180}
1181
1182//RevertImageUpdate is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001183func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001184 return nil, errors.New("unImplemented")
1185}
1186
1187// UpdateFlowsBulk is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001188func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001189 return nil, errors.New("unImplemented")
1190}
1191
1192//SelfTestDevice unimplented
1193func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
1194 return nil, errors.New("unImplemented")
1195}
1196
1197//SendPacketOut sends packet out to the device
khenaidoo42dcdfd2021-10-19 17:34:12 -04001198func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001199 return nil, errors.New("unImplemented")
1200}
1201
1202// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
1203func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1204 return nil, errors.New("unImplemented")
1205}
1206
1207// DisablePort to Disable pon/nni interface - seems not to be used/required according to python code
1208func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1209 return nil, errors.New("unImplemented")
1210}
1211
1212// GetExtValue - unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001213func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001214 return nil, errors.New("unImplemented")
1215}
1216
1217// ChildDeviceLost - unimplemented
1218func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
1219 return nil, errors.New("unImplemented")
1220}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001221
1222// GetSupportedFsms - TODO: add comment
1223func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
1224 return oo.pSupportedFsms
1225}
1226
1227// LockMutexMibTemplateGenerated - TODO: add comment
1228func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
1229 oo.mutexMibTemplateGenerated.Lock()
1230}
1231
1232// UnlockMutexMibTemplateGenerated - TODO: add comment
1233func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
1234 oo.mutexMibTemplateGenerated.Unlock()
1235}
1236
1237// GetMibTemplatesGenerated - TODO: add comment
1238func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
1239 value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
1240 return value, exist
1241}
1242
1243// SetMibTemplatesGenerated - TODO: add comment
1244func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
1245 oo.mibTemplatesGenerated[mibTemplatePath] = value
1246}
1247
1248// RLockMutexDeviceHandlersMap - TODO: add comment
1249func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
1250 oo.mutexDeviceHandlersMap.RLock()
1251}
1252
1253// RUnlockMutexDeviceHandlersMap - TODO: add comment
1254func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
1255 oo.mutexDeviceHandlersMap.RUnlock()
1256}
1257
1258// GetDeviceHandler - TODO: add comment
1259func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
1260 value, exist = oo.deviceHandlers[deviceID]
1261 return value, exist
1262}