blob: 60d2f81d23c885f767bd38fa28c385f56ece346d [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"
khenaidoof3333552021-12-15 16:52:31 -050032 "github.com/opencord/voltha-protos/v5/go/adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040033 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040034 "github.com/opencord/voltha-protos/v5/go/health"
35 "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service"
khenaidoo7d3c5582021-08-11 18:09:44 -040036 "google.golang.org/grpc"
khenaidoo55cebc62021-12-08 14:44:41 -050037 "google.golang.org/grpc/codes"
38 "google.golang.org/grpc/status"
khenaidoo7d3c5582021-08-11 18:09:44 -040039
40 "github.com/golang/protobuf/ptypes/empty"
41 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
42 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
43 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoo42dcdfd2021-10-19 17:34:12 -040044 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo7d3c5582021-08-11 18:09:44 -040045 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo42dcdfd2021-10-19 17:34:12 -040046 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
47 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidoo7d3c5582021-08-11 18:09:44 -040048 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000049
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000050 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Matteo Scandolo761f7512020-11-23 15:52:40 -080051 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandt60652202021-11-02 11:09:36 +000052 pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000053 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
54 uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000055)
56
khenaidoo55cebc62021-12-08 14:44:41 -050057type reachabilityFromRemote struct {
58 lastKeepAlive time.Time
59 keepAliveInterval int64
60}
61
Holger Hildebrandtfa074992020-03-27 15:42:06 +000062//OpenONUAC structure holds the ONU core information
63type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053064 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000065 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000066 mutexDeviceHandlersMap sync.RWMutex
khenaidoo7d3c5582021-08-11 18:09:44 -040067 coreClient *vgrpc.Client
68 parentAdapterClients map[string]*vgrpc.Client
69 lockParentAdapterClients sync.RWMutex
khenaidoo55cebc62021-12-08 14:44:41 -050070 reachableFromRemote map[string]*reachabilityFromRemote
71 lockReachableFromRemote sync.RWMutex
Himani Chawlac07fda02020-12-09 16:21:21 +053072 eventProxy eventif.EventProxy
mpagenkoaf801632020-07-03 10:00:42 +000073 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080074 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000075 config *config.AdapterFlags
76 numOnus int
Matteo Scandolo127c59d2021-01-28 11:31:18 -080077 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000079 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000080 mibTemplatesGenerated map[string]bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000081 mutexMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000082 exitChannel chan int
83 HeartbeatCheckInterval time.Duration
84 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000085 AcceptIncrementalEvto bool
khenaidoo55cebc62021-12-08 14:44:41 -050086 pSupportedFsms *cmn.OmciDeviceFsms
87 maxTimeoutInterAdapterComm time.Duration
88 maxTimeoutReconciling time.Duration
89 pDownloadManager *swupg.AdapterDownloadManager
90 pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete
91 MetricsEnabled bool
92 mibAuditInterval time.Duration
93 omciTimeout int // in seconds
94 alarmAuditInterval time.Duration
95 dlToOnuTimeout4M time.Duration
96 rpcTimeout time.Duration
97 maxConcurrentFlowsPerUni int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000098}
99
100//NewOpenONUAC returns a new instance of OpenONU_AC
khenaidoo7d3c5582021-08-11 18:09:44 -0400101func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy,
102 kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000103 var openOnuAc OpenONUAC
104 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530105 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000106 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
khenaidoo7d3c5582021-08-11 18:09:44 -0400107 openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client)
khenaidoo55cebc62021-12-08 14:44:41 -0500108 openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000109 openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800111 openOnuAc.cm = cm
khenaidoo7d3c5582021-08-11 18:09:44 -0400112 openOnuAc.coreClient = coreClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113 openOnuAc.numOnus = cfg.OnuNumber
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000114 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +0000115 openOnuAc.kvClient = kvClient
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800116 openOnuAc.KVStoreAddress = cfg.KVStoreAddress
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +0000118 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000119 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000120 openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000121 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
122 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +0000123 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +0530124 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000125 openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000127 openOnuAc.MetricsEnabled = cfg.MetricsEnabled
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000128 openOnuAc.mibAuditInterval = cfg.MibAuditInterval
Girish Gowdra0b235842021-03-09 13:06:46 -0800129 // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion
130 openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds())
Himani Chawla075f1642021-03-15 19:23:24 +0530131 openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
mpagenkoc26d4c02021-05-06 14:27:57 +0000132 openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
khenaidoo7d3c5582021-08-11 18:09:44 -0400133 openOnuAc.rpcTimeout = cfg.RPCTimeout
Girish Gowdrae95687a2021-09-08 16:30:58 -0700134 openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000135
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000136 openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000137 "mib-synchronizer": {
138 //mibSyncFsm, // Implements the MIB synchronization state machine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530140 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000141 AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000142 // map[string]func() error{
143 // "mib-upload": onuDeviceEntry.MibUploadTask,
144 // "mib-template": onuDeviceEntry.MibTemplateTask,
145 // "get-mds": onuDeviceEntry.GetMdsTask,
146 // "mib-audit": onuDeviceEntry.GetMdsTask,
147 // "mib-resync": onuDeviceEntry.MibResyncTask,
148 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
149 // },
150 },
151 }
152
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000153 openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx)
154 openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx)
mpagenkoc26d4c02021-05-06 14:27:57 +0000155 openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
mpagenkoc8bba412021-01-15 15:38:44 +0000156
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157 return &openOnuAc
158}
159
160//Start starts (logs) the adapter
161func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000162 logger.Info(ctx, "starting-openonu-adapter")
mpagenkoc8bba412021-01-15 15:38:44 +0000163
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164 return nil
165}
166
khenaidoof3333552021-12-15 16:52:31 -0500167//Stop terminates the session
168func (oo *OpenONUAC) Stop(ctx context.Context) error {
169 logger.Info(ctx, "stopping-device-manager")
170 close(oo.exitChannel)
171 oo.stopAllGrpcClients(ctx)
172 logger.Info(ctx, "device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000173 return nil
174}
175
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// AdoptDevice creates a new device handler if not present already and then adopts the device
227func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000228 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Warn(ctx, "voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400230 return nil, errors.New("nil-device")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000232 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530233 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000234 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400235 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000236 oo.addDeviceHandlerToMap(ctx, handler)
khenaidoo7d3c5582021-08-11 18:09:44 -0400237
238 // Setup the grpc communication with the parent adapter
239 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
240 // TODO: Cleanup on failure needed
241 return nil, err
242 }
243
244 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000245 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400246 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000247}
248
khenaidoo7d3c5582021-08-11 18:09:44 -0400249//ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart
250func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000251 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000252 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
khenaidoo7d3c5582021-08-11 18:09:44 -0400253 return nil, errors.New("nil-device")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000254 }
khenaidoo55cebc62021-12-08 14:44:41 -0500255 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId})
256
257 // Check whether the grpc client in the adapter of the parent device can reach us yet
khenaidoof3333552021-12-15 16:52:31 -0500258 if !oo.isReachableFromRemote(ctx, device.ProxyAddress.AdapterEndpoint, device.ProxyAddress.DeviceId) {
khenaidoo55cebc62021-12-08 14:44:41 -0500259 return nil, status.Errorf(codes.Unavailable, "adapter-not-reachable-from-parent-%s", device.ProxyAddress.AdapterEndpoint)
260 }
261
Himani Chawla6d2ae152020-09-02 13:11:20 +0530262 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000263 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400264 handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000265 oo.addDeviceHandlerToMap(ctx, handler)
266 handler.device = device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400267 if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{
khenaidoo7d3c5582021-08-11 18:09:44 -0400268 DeviceId: device.Id,
269 OperStatus: voltha.OperStatus_RECONCILING,
270 ConnStatus: device.ConnectStatus,
271 }); err != nil {
272 return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error())
Maninderb5187552021-03-23 22:23:42 +0530273 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400274 // Setup the grpc communication with the parent adapter
275 if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
276 // TODO: Cleanup on failure needed
277 return nil, err
278 }
279
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000280 handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false)
khenaidoo7d3c5582021-08-11 18:09:44 -0400281 go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000282 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000283 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400284 return nil, fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000285 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400286 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000287}
288
khenaidoo7d3c5582021-08-11 18:09:44 -0400289//DisableDevice disables the given device
290func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000291 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
292 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400293 go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
294 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300295 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000296 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400297 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000298}
299
khenaidoo7d3c5582021-08-11 18:09:44 -0400300//ReEnableDevice enables the onu device after disable
301func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000302 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
303 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400304 go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
305 return &empty.Empty{}, nil
ozgecanetsiafce57b12020-05-25 14:39:35 +0300306 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000307 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400308 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000309}
310
khenaidoo7d3c5582021-08-11 18:09:44 -0400311//RebootDevice reboots the given device
312func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000313 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
314 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400315 go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking
316 return &empty.Empty{}, nil
ozgecanetsiae11479f2020-07-06 09:44:47 +0300317 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000318 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400319 return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000320}
321
khenaidoo7d3c5582021-08-11 18:09:44 -0400322// DeleteDevice deletes the given device
323func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
324 nctx := log.WithSpanFromContext(context.Background(), ctx)
khenaidoo7d3c5582021-08-11 18:09:44 -0400325 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 +0000326
dbainbri4d3a0dc2020-12-02 00:33:42 +0000327 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra0e533642021-03-02 22:02:51 -0800328 var errorsList []error
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000329
330 handler.mutexDeletionInProgressFlag.Lock()
331 handler.deletionInProgress = true
332 handler.mutexDeletionInProgressFlag.Unlock()
333
Holger Hildebrandt60652202021-11-02 11:09:36 +0000334 if err := handler.resetFsms(ctx, true); err != nil {
335 errorsList = append(errorsList, err)
336 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700337 for _, uni := range handler.uniEntityMap {
338 if handler.GetFlowMonitoringIsRunning(uni.UniID) {
339 handler.stopFlowMonitoringRoutine[uni.UniID] <- true
340 logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id})
341 }
342 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000343 //don't leave any garbage in kv-store
344 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
345 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000346 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000347 oo.deleteDeviceHandlerToMap(handler)
348 go handler.PrepareForGarbageCollection(ctx, handler.DeviceID)
Holger Hildebrandt60652202021-11-02 11:09:36 +0000349
Girish Gowdra0e533642021-03-02 22:02:51 -0800350 if len(errorsList) > 0 {
351 logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
khenaidoo7d3c5582021-08-11 18:09:44 -0400352 return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
Girish Gowdra0e533642021-03-02 22:02:51 -0800353 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400354 return &empty.Empty{}, nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000355 }
Holger Hildebrandt60652202021-11-02 11:09:36 +0000356 logger.Infow(ctx, "no handler found for device-deletion - trying to delete remaining data in the kv-store ", log.Fields{"device-id": device.Id})
357
Holger Hildebrandtc69f0742021-11-16 13:48:00 +0000358 if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil {
359 return nil, err
Holger Hildebrandt60652202021-11-02 11:09:36 +0000360 }
361 return &empty.Empty{}, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000362}
363
khenaidoo7d3c5582021-08-11 18:09:44 -0400364//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
khenaidoo42dcdfd2021-10-19 17:34:12 -0400365func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400366 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000367
mpagenkofc4f56e2020-11-04 17:17:49 +0000368 //flow config is relayed to handler even if the device might be in some 'inactive' state
369 // let the handler or related FSM's decide, what to do with the modified flow state info
370 // 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 +0000371
372 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000373 // but processing is continued for flowUpdate possibly also set in the request
khenaidoo7d3c5582021-08-11 18:09:44 -0400374 if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil {
375 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000376 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400377 if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil {
378 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000379 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400380 if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil {
381 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000382 }
383
khenaidoo7d3c5582021-08-11 18:09:44 -0400384 if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil {
385 if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
386 return nil, err
387 }
388 return &empty.Empty{}, nil
mpagenkodff5dda2020-08-28 11:52:01 +0000389 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400390 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id})
391 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000392}
393
khenaidoo7d3c5582021-08-11 18:09:44 -0400394//UpdatePmConfig returns PmConfigs nil or error
khenaidoo42dcdfd2021-10-19 17:34:12 -0400395func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400396 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId})
397 if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil {
398 if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil {
399 return nil, err
400 }
401 return &empty.Empty{}, nil
Girish Gowdrae09a6202021-01-12 18:10:59 -0800402 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400403 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId})
404 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000405}
406
khenaidoo7d3c5582021-08-11 18:09:44 -0400407//DownloadImage requests downloading some image according to indications as given in request
Andrea Campanella71e546a2021-02-26 11:09:33 +0100408//The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400409func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400410 ctx = log.WithSpanFromContext(context.Background(), ctx)
411 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000412 if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400413 logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image})
mpagenko15ff4a52021-03-02 10:09:20 +0000414 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
415 // the download itself is later done in background
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000416 if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400417 return nil, err
418 }
419 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000420 }
421 // image already exists
khenaidoo7d3c5582021-08-11 18:09:44 -0400422 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image})
423 return imageInfo.Image, nil
mpagenkoc8bba412021-01-15 15:38:44 +0000424 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400425
426 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000427}
428
mpagenko59862f02021-10-11 08:53:18 +0000429//ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI
Andrea Campanella71e546a2021-02-26 11:09:33 +0100430// according to indications as given in request and on success activate the image on the ONU
431//The ImageDownload needs to be called `request`due to library reflection requirements
khenaidoo42dcdfd2021-10-19 17:34:12 -0400432func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400433 if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000434 if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400435 if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000436 logger.Debugw(ctx, "image download on omci requested", log.Fields{
khenaidoo7d3c5582021-08-11 18:09:44 -0400437 "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
438 if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
439 return nil, err
440 }
441 return imageInfo.Image, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000442 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400443 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
444 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000445 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400446 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
447 return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000448 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400449 return nil, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000450}
451
khenaidoo7d3c5582021-08-11 18:09:44 -0400452//GetSingleValue handles the core request to retrieve uni status
453func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500454 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
455
456 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
457 switch reqType := request.GetRequest().GetRequest().(type) {
458 case *extension.GetValueRequest_UniInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000459 return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700460 case *extension.GetValueRequest_OnuOpticalInfo:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000461 CommChan := make(chan cmn.Message)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700462 respChan := make(chan extension.SingleGetValueResponse)
463 // Initiate the self test request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000464 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700465 return &extension.SingleGetValueResponse{
466 Response: &extension.GetValueResponse{
467 Status: extension.GetValueResponse_ERROR,
468 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
469 },
470 }, err
471 }
472 // The timeout handling is already implemented in omci_self_test_handler module
473 resp := <-respChan
474 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530475 case *extension.GetValueRequest_OnuInfo:
476 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
kesavandfdf77632021-01-26 23:40:33 -0500477 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000478 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
kesavandfdf77632021-01-26 23:40:33 -0500479
480 }
481 }
482 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000483 return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000484}
485
mpagenko83144272021-04-27 10:06:22 +0000486//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000487// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
488// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
489// The reason for that was never finally investigated.
490// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000491
khenaidoo7d3c5582021-08-11 18:09:44 -0400492// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000493// if the image is not yet present on the adapter it has to be automatically downloaded
khenaidoo7d3c5582021-08-11 18:09:44 -0400494func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000495 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
496 loResponse := voltha.DeviceImageResponse{}
497 imageIdentifier := (*request).Image.Version
mpagenkoc497ee32021-11-10 17:30:20 +0000498 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000499 firstDevice := true
500 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000501 var onuVolthaDevice *voltha.Device
502 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000503 for _, pCommonID := range (*request).DeviceId {
mpagenko38662d02021-08-11 09:45:19 +0000504 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000505 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000506 loDeviceImageState := voltha.DeviceImageState{}
507 loDeviceImageState.DeviceId = loDeviceID
508 loImageState := voltha.ImageState{}
509 loDeviceImageState.ImageState = &loImageState
510 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko38662d02021-08-11 09:45:19 +0000511
mpagenko59862f02021-10-11 08:53:18 +0000512 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400513 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000514 if handler != nil {
515 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
516 } else {
517 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
518 devErr = errors.New("no handler found for device-id")
khenaidoo7d3c5582021-08-11 18:09:44 -0400519 }
mpagenko59862f02021-10-11 08:53:18 +0000520 if devErr != nil || onuVolthaDevice == nil {
521 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
522 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000523 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
524 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000525 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000526 } else {
mpagenko38662d02021-08-11 09:45:19 +0000527 if firstDevice {
528 //start/verify download of the image to the adapter based on first found device only
529 // use the OnuVendor identification from first given device
mpagenkoc497ee32021-11-10 17:30:20 +0000530
531 // note: if the request was done for a list of devices on the Voltha interface, rwCore
532 // 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 +0000533 firstDevice = false
534 vendorID = onuVolthaDevice.VendorId
535 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
mpagenkoc497ee32021-11-10 17:30:20 +0000536 logger.Infow(ctx, "download request for file",
537 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000538
mpagenkoc497ee32021-11-10 17:30:20 +0000539 // call the StartDownload synchronously to detect 'immediate' download problems
540 // the real download itself is later done in background
541 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko38662d02021-08-11 09:45:19 +0000542 // note: If the image (with vendorId+name) has already been downloaded before from some other
mpagenkoc497ee32021-11-10 17:30:20 +0000543 // valid URL, the current download request is not executed (current code delivers URL error).
544 // If the operators want to ensure that the new URL
mpagenko38662d02021-08-11 09:45:19 +0000545 // is really used, then they first have to use the 'abort' API to remove the existing image!
546 // (abort API can be used also after some successful download to just remove the image from adapter)
mpagenkoc497ee32021-11-10 17:30:20 +0000547 if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted {
548 downloadStartDone = true
549 } //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 +0000550 }
551 } else {
552 //for all following devices verify the matching vendorID
553 if onuVolthaDevice.VendorId != vendorID {
554 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
555 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
556 vendorIDMatch = false
557 }
558 }
mpagenkoc497ee32021-11-10 17:30:20 +0000559 if downloadStartDone && vendorIDMatch {
mpagenko38662d02021-08-11 09:45:19 +0000560 // start the ONU download activity for each possible device
mpagenkoc497ee32021-11-10 17:30:20 +0000561 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko59862f02021-10-11 08:53:18 +0000562 "image-id": imageIdentifier, "device-id": loDeviceID})
563 //onu upgrade handling called in background without immediate error evaluation here
564 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
565 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
566 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
567 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
568 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
569 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +0000570 } else {
571 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
mpagenkoc497ee32021-11-10 17:30:20 +0000572 if !downloadStartDone {
573 //based on above fileState more descriptive error codes would be possible, e.g
574 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko38662d02021-08-11 09:45:19 +0000575 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
576 } else { //only logical option is !vendorIDMatch
577 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
578 }
579 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
580 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000581 }
mpagenko2f2f2362021-06-07 08:25:22 +0000582 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000583 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000584 pImageResp := &loResponse
585 return pImageResp, nil
586 }
587 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000588}
589
khenaidoo7d3c5582021-08-11 18:09:44 -0400590// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
mpagenko83144272021-04-27 10:06:22 +0000591// status for the requested image
khenaidoo7d3c5582021-08-11 18:09:44 -0400592func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000593 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
594 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000595 imageIdentifier := (*in).Version
mpagenko38662d02021-08-11 09:45:19 +0000596 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000597 firstDevice := true
598 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000599 var onuVolthaDevice *voltha.Device
600 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000601 for _, pCommonID := range (*in).DeviceId {
602 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400603 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
mpagenko59862f02021-10-11 08:53:18 +0000604 vendorIDSet = false
605 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400606 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000607 if handler != nil {
608 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
609 } else {
610 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
611 devErr = errors.New("no handler found for device-id")
mpagenko38662d02021-08-11 09:45:19 +0000612 }
mpagenko59862f02021-10-11 08:53:18 +0000613 if devErr != nil || onuVolthaDevice == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000614 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
mpagenko59862f02021-10-11 08:53:18 +0000615 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenko38662d02021-08-11 09:45:19 +0000616 pImageState := &voltha.ImageState{
617 Version: (*in).Version,
618 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
619 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
620 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000621 }
mpagenko38662d02021-08-11 09:45:19 +0000622 pDeviceImageState.ImageState = pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000623 } else {
mpagenko38662d02021-08-11 09:45:19 +0000624 if firstDevice {
625 //start/verify download of the image to the adapter based on first found device only
626 // use the OnuVendor identification from first given device
627 firstDevice = false
628 vendorID = onuVolthaDevice.VendorId
629 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
630 vendorIDSet = true
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000631 logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000632 } else {
633 //for all following devices verify the matching vendorID
634 if onuVolthaDevice.VendorId != vendorID {
635 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000636 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko38662d02021-08-11 09:45:19 +0000637 } else {
638 vendorIDSet = true
639 }
640 }
641 if !vendorIDSet {
642 pImageState := &voltha.ImageState{
643 Version: (*in).Version,
644 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
645 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
646 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
647 }
648 pDeviceImageState.ImageState = pImageState
649 } else {
khenaidoo7d3c5582021-08-11 18:09:44 -0400650 logger.Debugw(ctx, "image status request for", log.Fields{
651 "image-id": imageIdentifier, "device-id": loDeviceID})
652 //status request is called synchronously to collect the indications for all concerned devices
653 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenko38662d02021-08-11 09:45:19 +0000654 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000655 }
656 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000657 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000658 pImageResp := &loResponse
659 return pImageResp, nil
660 }
661 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000662}
663
khenaidoo7d3c5582021-08-11 18:09:44 -0400664// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
665func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000666 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
667 loResponse := voltha.DeviceImageResponse{}
668 imageIdentifier := (*in).Version
669 firstDevice := true
670 var vendorID string
mpagenko59862f02021-10-11 08:53:18 +0000671 var vendorIDSet bool
672 var onuVolthaDevice *voltha.Device
673 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000674 for _, pCommonID := range (*in).DeviceId {
675 loDeviceID := (*pCommonID).Id
khenaidoo7d3c5582021-08-11 18:09:44 -0400676 pDeviceImageState := &voltha.DeviceImageState{}
677 loImageState := voltha.ImageState{}
678 pDeviceImageState.ImageState = &loImageState
mpagenko59862f02021-10-11 08:53:18 +0000679 vendorIDSet = false
680 onuVolthaDevice = nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400681 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
mpagenko59862f02021-10-11 08:53:18 +0000682 if handler != nil {
683 onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID)
684 } else {
685 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
686 devErr = errors.New("no handler found for device-id")
687 }
688 if devErr != nil || onuVolthaDevice == nil {
689 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
690 log.Fields{"device-id": loDeviceID, "err": devErr})
khenaidoo7d3c5582021-08-11 18:09:44 -0400691 pDeviceImageState.DeviceId = loDeviceID
692 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko59862f02021-10-11 08:53:18 +0000693 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
694 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
khenaidoo7d3c5582021-08-11 18:09:44 -0400695 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoaa3afe92021-05-21 16:20:58 +0000696 } else {
mpagenko59862f02021-10-11 08:53:18 +0000697 if firstDevice {
698 //start/verify download of the image to the adapter based on first found device only
699 // use the OnuVendor identification from first given device
700 firstDevice = false
701 vendorID = onuVolthaDevice.VendorId
702 vendorIDSet = true
703 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000704 logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
mpagenko59862f02021-10-11 08:53:18 +0000705 } else {
706 //for all following devices verify the matching vendorID
707 if onuVolthaDevice.VendorId != vendorID {
708 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000709 log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
mpagenko59862f02021-10-11 08:53:18 +0000710 pDeviceImageState.DeviceId = loDeviceID
711 pDeviceImageState.ImageState.Version = (*in).Version
712 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
713 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
714 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
715 } else {
716 vendorIDSet = true
717 }
718 }
719 if vendorIDSet {
720 // cancel the ONU upgrade activity for each possible device
721 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
722 "image-id": imageIdentifier, "device-id": loDeviceID})
723 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
724 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
mpagenkoaa3afe92021-05-21 16:20:58 +0000725 }
726 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000727 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko59862f02021-10-11 08:53:18 +0000728 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000729 if !firstDevice {
730 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
731 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
732 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
733 }
734 pImageResp := &loResponse
735 return pImageResp, nil
736 }
737 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000738}
739
khenaidoo7d3c5582021-08-11 18:09:44 -0400740// GetOnuImages retrieves the ONU SW image status information via OMCI
741func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
742 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
743 if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530744 images, err := handler.getOnuImages(ctx)
745 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000746 return images, nil
747 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400748 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000749 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400750 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
751 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
mpagenko83144272021-04-27 10:06:22 +0000752}
753
khenaidoo7d3c5582021-08-11 18:09:44 -0400754// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
mpagenkoc26d4c02021-05-06 14:27:57 +0000755// precondition: image downloaded and not yet activated or image refers to current inactive image
khenaidoo7d3c5582021-08-11 18:09:44 -0400756func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000757 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
758 loResponse := voltha.DeviceImageResponse{}
759 imageIdentifier := (*in).Version
760 //let the deviceHandler find the adequate way of requesting the image activation
761 for _, pCommonID := range (*in).DeviceId {
762 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000763 loDeviceImageState := voltha.DeviceImageState{}
764 loDeviceImageState.DeviceId = loDeviceID
765 loImageState := voltha.ImageState{}
766 loDeviceImageState.ImageState = &loImageState
767 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000768 //compared to download procedure the vendorID (from device) is secondary here
769 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
770 // start image activation activity for each possible device
771 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
772 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
773 logger.Debugw(ctx, "onu image activation requested", log.Fields{
774 "image-id": imageIdentifier, "device-id": loDeviceID})
775 //onu activation handling called in background without immediate error evaluation here
776 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
777 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000778 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
779 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
780 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
781 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
782 } else {
783 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
784 loDeviceImageState.ImageState.Reason = pImageStates.Reason
785 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
786 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000787 } else {
788 //cannot start SW activation for requested device
789 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000790 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000791 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
792 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000793 }
mpagenko2f2f2362021-06-07 08:25:22 +0000794 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000795 }
796 pImageResp := &loResponse
797 return pImageResp, nil
798 }
799 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000800}
801
khenaidoo7d3c5582021-08-11 18:09:44 -0400802// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
mpagenko83144272021-04-27 10:06:22 +0000803// precondition: image activated and not yet committed
khenaidoo7d3c5582021-08-11 18:09:44 -0400804func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000805 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
806 loResponse := voltha.DeviceImageResponse{}
807 imageIdentifier := (*in).Version
808 //let the deviceHandler find the adequate way of requesting the image activation
809 for _, pCommonID := range (*in).DeviceId {
810 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000811 loDeviceImageState := voltha.DeviceImageState{}
812 loDeviceImageState.DeviceId = loDeviceID
813 loImageState := voltha.ImageState{}
814 loDeviceImageState.ImageState = &loImageState
815 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000816 //compared to download procedure the vendorID (from device) is secondary here
817 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
818 // start image activation activity for each possible device
819 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
820 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
821 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
822 "image-id": imageIdentifier, "device-id": loDeviceID})
823 //onu commitment handling called in background without immediate error evaluation here
824 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
825 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000826 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
mpagenko38662d02021-08-11 09:45:19 +0000827 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
828 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
mpagenko183647c2021-06-08 15:25:04 +0000829 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
830 } else {
831 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
832 loDeviceImageState.ImageState.Reason = pImageStates.Reason
833 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
834 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000835 } else {
836 //cannot start SW commitment for requested device
837 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000838 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000839 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
840 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000841 }
mpagenko2f2f2362021-06-07 08:25:22 +0000842 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000843 }
844 pImageResp := &loResponse
845 return pImageResp, nil
846 }
847 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000848}
849
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000850// Adapter interface required methods ################ end #########
851// #################################################################
khenaidoo7d3c5582021-08-11 18:09:44 -0400852
853/*
854 *
855 * ONU inter adapter service
856 *
857 */
858
859// OnuIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400860func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400861 logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
862
863 if onuInd == nil || onuInd.OnuIndication == nil {
864 return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
865 }
866
867 onuIndication := onuInd.OnuIndication
868 onuOperstate := onuIndication.GetOperState()
869 waitForDhInstPresent := false
870 if onuOperstate == "up" {
871 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
872 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
873 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
874 //Adopt_device() arrived and DeviceHandler instance was created
875 waitForDhInstPresent = true
876 }
877 if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
878 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
879 "OnuId": onuIndication.GetOnuId(),
880 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
881 "SNR": onuIndication.GetSerialNumber()})
882
883 if onuOperstate == "up" {
884 if err := handler.createInterface(ctx, onuIndication); err != nil {
885 return nil, err
886 }
887 return &empty.Empty{}, nil
888 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
ozgecanetsia76db57a2022-02-03 15:32:03 +0300889 if err := handler.updateInterface(ctx, onuIndication); err != nil {
890 return nil, err
891 }
892 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400893 } else {
894 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
895 return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
896 }
897 }
898 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
899 "msgToDeviceId": onuInd.DeviceId})
900 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
901}
902
903// OmciIndication is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400904func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400905 logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
906
907 if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
908 if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
909 return nil, err
910 }
911 return &empty.Empty{}, nil
912 }
913 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
914}
915
916// DownloadTechProfile is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400917func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000918 logger.Debugw(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId})
khenaidoo7d3c5582021-08-11 18:09:44 -0400919
920 if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
921 if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
922 return nil, err
923 }
924 return &empty.Empty{}, nil
925 }
926 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
927}
928
929// DeleteGemPort is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400930func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400931 logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
932
933 if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
934 if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
935 return nil, err
936 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000937 } else {
938 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId})
939 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400940 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000941 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400942}
943
944// DeleteTCont is part of the ONU Inter-adapter service API.
khenaidoo42dcdfd2021-10-19 17:34:12 -0400945func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000946 logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf})
khenaidoo7d3c5582021-08-11 18:09:44 -0400947
948 if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
949 if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil {
950 return nil, err
951 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000952 } else {
953 logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId})
954 // delete requests for objects of an already deleted ONU should be acknowledged positively - continue
khenaidoo7d3c5582021-08-11 18:09:44 -0400955 }
Holger Hildebrandt5b774062021-11-10 10:24:29 +0000956 return &empty.Empty{}, nil
khenaidoo7d3c5582021-08-11 18:09:44 -0400957}
958
959/*
960 * Parent GRPC clients
961 */
962
khenaidoo55cebc62021-12-08 14:44:41 -0500963func getHash(endpoint, contextInfo string) string {
964 strToHash := endpoint + contextInfo
965 h := fnv.New128().Sum([]byte(strToHash))
966 return string(h)
967}
968
969func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) {
970 logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote})
971 oo.lockReachableFromRemote.Lock()
972 defer oo.lockReachableFromRemote.Unlock()
973 endpointHash := getHash(remote.Endpoint, remote.ContextInfo)
974 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
975 oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now()
976 oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval
977 return
978 }
979 logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote})
980 oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval}
981}
982
khenaidoof3333552021-12-15 16:52:31 -0500983func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool {
984 logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo})
khenaidoo55cebc62021-12-08 14:44:41 -0500985 oo.lockReachableFromRemote.RLock()
986 defer oo.lockReachableFromRemote.RUnlock()
987 endpointHash := getHash(endpoint, contextInfo)
988 if _, ok := oo.reachableFromRemote[endpointHash]; ok {
khenaidoof3333552021-12-15 16:52:31 -0500989 logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)})
khenaidoo55cebc62021-12-08 14:44:41 -0500990 // Assume the connection is down if we did not receive 2 keep alives in succession
991 maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2)
992 return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait
993 }
994 return false
995}
996
khenaidoof3333552021-12-15 16:52:31 -0500997//stopAllGrpcClients stops all grpc clients in use
998func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) {
999 // Stop the clients that connect to the parent
1000 oo.lockParentAdapterClients.Lock()
1001 for key := range oo.parentAdapterClients {
1002 oo.parentAdapterClients[key].Stop(ctx)
1003 delete(oo.parentAdapterClients, key)
1004 }
1005 oo.lockParentAdapterClients.Unlock()
1006
1007 // Stop core client connection
1008 oo.coreClient.Stop(ctx)
1009}
1010
khenaidoo7d3c5582021-08-11 18:09:44 -04001011func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
1012 logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
1013 oo.lockParentAdapterClients.Lock()
1014 defer oo.lockParentAdapterClients.Unlock()
1015 if _, ok := oo.parentAdapterClients[endpoint]; ok {
1016 return nil
1017 }
1018
khenaidoo55cebc62021-12-08 14:44:41 -05001019 childClient, err := vgrpc.NewClient(
1020 oo.config.AdapterEndpoint,
1021 endpoint,
khenaidoof3333552021-12-15 16:52:31 -05001022 "olt_inter_adapter_service.OltInterAdapterService",
khenaidoo55cebc62021-12-08 14:44:41 -05001023 oo.oltAdapterRestarted)
khenaidoo7d3c5582021-08-11 18:09:44 -04001024
1025 if err != nil {
1026 return err
1027 }
1028
1029 oo.parentAdapterClients[endpoint] = childClient
1030
khenaidoof3333552021-12-15 16:52:31 -05001031 go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler)
khenaidoo7d3c5582021-08-11 18:09:44 -04001032
1033 // Wait until we have a connection to the child adapter.
1034 // Unlimited retries or until context expires
1035 subCtx := log.WithSpanFromContext(context.TODO(), ctx)
1036 backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
1037 for {
1038 client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
1039 if err == nil && client != nil {
1040 logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
1041 break
1042 }
1043 logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
1044 // Backoff
1045 if err = backoff.Backoff(subCtx); err != nil {
1046 logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
1047 break
1048 }
1049 }
1050 return nil
1051}
1052
khenaidoo42dcdfd2021-10-19 17:34:12 -04001053func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001054 // First check from cache
1055 oo.lockParentAdapterClients.RLock()
1056 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1057 oo.lockParentAdapterClients.RUnlock()
1058 return pgClient.GetOltInterAdapterServiceClient()
1059 }
1060 oo.lockParentAdapterClients.RUnlock()
1061
1062 // Set the parent connection - can occur on restarts
1063 ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
1064 err := oo.setupParentInterAdapterClient(ctx, endpoint)
1065 cancel()
1066 if err != nil {
1067 return nil, err
1068 }
1069
1070 // Get the parent client now
1071 oo.lockParentAdapterClients.RLock()
1072 defer oo.lockParentAdapterClients.RUnlock()
1073 if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
1074 return pgClient.GetOltInterAdapterServiceClient()
1075 }
1076
1077 return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
1078}
1079
1080// TODO: Any action the adapter needs to do following an olt adapter restart?
1081func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
1082 logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
1083 return nil
1084}
1085
khenaidoof3333552021-12-15 16:52:31 -05001086// getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service
1087func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
1088 if conn == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -04001089 return nil
1090 }
khenaidoof3333552021-12-15 16:52:31 -05001091 return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn)
khenaidoo7d3c5582021-08-11 18:09:44 -04001092}
1093
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001094func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error {
1095 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 -08001096 var errorsList []error
1097 // delete onu persitent data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001098 onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix)
1099 logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath,
1100 "device-id": aDeviceID})
1101 onuKvbackend := &db.Backend{
1102 Client: oo.kvClient,
1103 StoreType: oo.KVStoreType,
1104 Address: oo.KVStoreAddress,
1105 Timeout: oo.KVStoreTimeout,
1106 PathPrefix: onuBaseKvStorePath,
1107 }
1108 err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID)
1109 if err != nil {
1110 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": onuBaseKvStorePath, "device-id": aDeviceID, "err": err})
1111 // continue to delete kv data, but accumulate any errors
1112 errorsList = append(errorsList, err)
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001113 }
Girish Gowdraf10379e2022-02-02 21:49:44 -08001114 // delete pm data
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001115 pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix)
1116 logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath,
1117 "device-id": aDeviceID})
Girish Gowdraf10379e2022-02-02 21:49:44 -08001118 pmKvbackend := &db.Backend{
1119 Client: oo.kvClient,
1120 StoreType: oo.KVStoreType,
1121 Address: oo.KVStoreAddress,
1122 Timeout: oo.KVStoreTimeout,
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001123 PathPrefix: pmBaseKvStorePath,
Girish Gowdraf10379e2022-02-02 21:49:44 -08001124 }
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001125 err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID)
Girish Gowdraf10379e2022-02-02 21:49:44 -08001126 if err != nil {
Girish Gowdrae9ff2612022-02-04 11:34:33 -08001127 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 -08001128 // accumulate any errors
1129 errorsList = append(errorsList, err)
1130 }
1131 if len(errorsList) > 0 {
1132 return fmt.Errorf("one or more error deleting kv data, error: %v", errorsList)
1133 }
Holger Hildebrandtc69f0742021-11-16 13:48:00 +00001134 return nil
1135}
1136
khenaidoof3333552021-12-15 16:52:31 -05001137// GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter.
1138func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error {
1139 ctx := context.Background()
1140 logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream})
1141
1142 if stream == nil {
1143 return fmt.Errorf("conn-is-nil %v", stream)
1144 }
1145 initialRequestTime := time.Now()
1146 var remoteClient *common.Connection
1147 var tempClient *common.Connection
1148 var err error
1149loop:
1150 for {
1151 tempClient, err = stream.Recv()
1152 if err != nil {
1153 logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1154 break loop
1155 }
1156 // Send a response back
1157 err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY})
1158 if err != nil {
1159 logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err})
1160 break loop
1161 }
1162 remoteClient = tempClient
1163
1164 logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient})
1165
1166 select {
1167 case <-stream.Context().Done():
1168 logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()})
1169 break loop
1170 case <-oo.exitChannel:
1171 logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime})
1172 break loop
1173 default:
1174 }
1175 }
1176 logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime})
1177 return err
1178}
1179
khenaidoo7d3c5582021-08-11 18:09:44 -04001180/*
1181 *
1182 * Unimplemented APIs
1183 *
1184 */
1185
1186//GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202].
1187// OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort()
1188//
khenaidoo42dcdfd2021-10-19 17:34:12 -04001189func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001190 return nil, errors.New("unImplemented")
1191}
1192
1193//SimulateAlarm is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001194func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001195 return nil, errors.New("unImplemented")
1196}
1197
1198//SetExtValue is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001199func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001200 return nil, errors.New("unImplemented")
1201}
1202
1203//SetSingleValue is unimplemented
1204func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
1205 return nil, errors.New("unImplemented")
1206}
1207
1208//StartOmciTest not implemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001209func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001210 return nil, errors.New("unImplemented")
1211}
1212
1213//SuppressEvent unimplemented
1214func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1215 return nil, errors.New("unImplemented")
1216}
1217
1218//UnSuppressEvent unimplemented
1219func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
1220 return nil, errors.New("unImplemented")
1221}
1222
1223//GetImageDownloadStatus is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001224func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001225 return nil, errors.New("unImplemented")
1226}
1227
1228//CancelImageDownload is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001229func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001230 return nil, errors.New("unImplemented")
1231}
1232
1233//RevertImageUpdate is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001234func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001235 return nil, errors.New("unImplemented")
1236}
1237
1238// UpdateFlowsBulk is unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001239func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001240 return nil, errors.New("unImplemented")
1241}
1242
1243//SelfTestDevice unimplented
1244func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
1245 return nil, errors.New("unImplemented")
1246}
1247
1248//SendPacketOut sends packet out to the device
khenaidoo42dcdfd2021-10-19 17:34:12 -04001249func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001250 return nil, errors.New("unImplemented")
1251}
1252
1253// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
1254func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1255 return nil, errors.New("unImplemented")
1256}
1257
1258// DisablePort to Disable pon/nni interface - seems not to be used/required according to python code
1259func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
1260 return nil, errors.New("unImplemented")
1261}
1262
1263// GetExtValue - unimplemented
khenaidoo42dcdfd2021-10-19 17:34:12 -04001264func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) {
khenaidoo7d3c5582021-08-11 18:09:44 -04001265 return nil, errors.New("unImplemented")
1266}
1267
1268// ChildDeviceLost - unimplemented
1269func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
1270 return nil, errors.New("unImplemented")
1271}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001272
1273// GetSupportedFsms - TODO: add comment
1274func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
1275 return oo.pSupportedFsms
1276}
1277
1278// LockMutexMibTemplateGenerated - TODO: add comment
1279func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
1280 oo.mutexMibTemplateGenerated.Lock()
1281}
1282
1283// UnlockMutexMibTemplateGenerated - TODO: add comment
1284func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
1285 oo.mutexMibTemplateGenerated.Unlock()
1286}
1287
1288// GetMibTemplatesGenerated - TODO: add comment
1289func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
1290 value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
1291 return value, exist
1292}
1293
1294// SetMibTemplatesGenerated - TODO: add comment
1295func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
1296 oo.mibTemplatesGenerated[mibTemplatePath] = value
1297}
1298
1299// RLockMutexDeviceHandlersMap - TODO: add comment
1300func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
1301 oo.mutexDeviceHandlersMap.RLock()
1302}
1303
1304// RUnlockMutexDeviceHandlersMap - TODO: add comment
1305func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
1306 oo.mutexDeviceHandlersMap.RUnlock()
1307}
1308
1309// GetDeviceHandler - TODO: add comment
1310func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
1311 value, exist = oo.deviceHandlers[deviceID]
1312 return value, exist
1313}