blob: c5f9365bb55f3054d9c268f98a2d9cee4bb975b1 [file] [log] [blame]
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
nikesh.krishnan1249be92023-11-27 04:20:12 +053017// Package mib provides the utilities for managing the onu mib
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package mib
19
20import (
21 "context"
22 "encoding/json"
23 "errors"
24 "fmt"
Holger Hildebrandtc56febd2022-02-09 13:23:30 +000025 "strconv"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000026 "sync"
27 "time"
28
29 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000030 "github.com/opencord/omci-lib-go/v2"
31 me "github.com/opencord/omci-lib-go/v2/generated"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000032 "github.com/opencord/voltha-lib-go/v7/pkg/db"
33 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
Holger Hildebrandtc56febd2022-02-09 13:23:30 +000034 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000035 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000036 "github.com/opencord/voltha-protos/v5/go/inter_adapter"
Holger Hildebrandtc56febd2022-02-09 13:23:30 +000037 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000038
39 "github.com/opencord/voltha-lib-go/v7/pkg/log"
40
41 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
42 devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
43 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
44)
45
46// events of MibUpload FSM
47const (
48 UlEvStart = "UlEvStart"
49 UlEvResetMib = "UlEvResetMib"
50 UlEvGetVendorAndSerial = "UlEvGetVendorAndSerial"
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +000051 UlEvGetVersion = "UlEvGetVersion"
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +000052 UlEvGetEquipIDAndOmcc = "UlEvGetEquipIDAndOmcc"
53 UlEvTestExtOmciSupport = "UlEvTestExtOmciSupport"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000054 UlEvGetFirstSwVersion = "UlEvGetFirstSwVersion"
55 UlEvGetSecondSwVersion = "UlEvGetSecondSwVersion"
56 UlEvGetMacAddress = "UlEvGetMacAddress"
57 UlEvGetMibTemplate = "UlEvGetMibTemplate"
58 UlEvUploadMib = "UlEvUploadMib"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000059 UlEvVerifyAndStoreTPs = "UlEvVerifyAndStoreTPs"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000060 UlEvExamineMds = "UlEvExamineMds"
61 UlEvSuccess = "UlEvSuccess"
62 UlEvMismatch = "UlEvMismatch"
63 UlEvAuditMib = "UlEvAuditMib"
64 UlEvForceResync = "UlEvForceResync"
65 UlEvDiffsFound = "UlEvDiffsFound"
66 UlEvTimeout = "UlEvTimeout"
67 UlEvStop = "UlEvStop"
68)
69
70// states of MibUpload FSM
71const (
72 UlStDisabled = "UlStDisabled"
73 UlStStarting = "UlStStarting"
74 UlStResettingMib = "UlStResettingMib"
75 UlStGettingVendorAndSerial = "UlStGettingVendorAndSerial"
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +000076 UlStGettingVersion = "UlStGettingVersion"
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +000077 UlStGettingEquipIDAndOmcc = "UlStGettingEquipIDAndOmcc"
78 UlStTestingExtOmciSupport = "UlStTestingExtOmciSupport"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000079 UlStGettingFirstSwVersion = "UlStGettingFirstSwVersion"
80 UlStGettingSecondSwVersion = "UlStGettingSecondSwVersion"
81 UlStGettingMacAddress = "UlStGettingMacAddress"
82 UlStGettingMibTemplate = "UlStGettingMibTemplate"
83 UlStUploading = "UlStUploading"
84 UlStUploadDone = "UlStUploadDone"
85 UlStInSync = "UlStInSync"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000086 UlStVerifyingAndStoringTPs = "UlStVerifyingAndStoringTPs"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000087 UlStExaminingMds = "UlStExaminingMds"
88 UlStResynchronizing = "UlStResynchronizing"
89 UlStExaminingMdsSuccess = "UlStExaminingMdsSuccess"
90 UlStAuditing = "UlStAuditing"
91 UlStReAuditing = "UlStReAuditing"
92 UlStOutOfSync = "UlStOutOfSync"
93)
94
95// CMibUlFsmIdleState - TODO: add comment
96const CMibUlFsmIdleState = UlStInSync
97
98// events of MibDownload FSM
99const (
100 DlEvStart = "DlEvStart"
101 DlEvCreateGal = "DlEvCreateGal"
102 DlEvRxGalResp = "DlEvRxGalResp"
103 DlEvRxOnu2gResp = "DlEvRxOnu2gResp"
104 DlEvRxBridgeResp = "DlEvRxBridgeResp"
105 DlEvTimeoutSimple = "DlEvTimeoutSimple"
106 DlEvTimeoutBridge = "DlEvTimeoutBridge"
107 DlEvReset = "DlEvReset"
108 DlEvRestart = "DlEvRestart"
109)
110
111// states of MibDownload FSM
112const (
113 DlStDisabled = "DlStDisabled"
114 DlStStarting = "DlStStarting"
115 DlStCreatingGal = "DlStCreatingGal"
116 DlStSettingOnu2g = "DlStSettingOnu2g"
117 DlStBridgeInit = "DlStBridgeInit"
118 DlStDownloaded = "DlStDownloaded"
119 DlStResetting = "DlStResetting"
120)
121
122// CMibDlFsmIdleState - TODO: add comment
123const CMibDlFsmIdleState = DlStDisabled
124
125const (
126 // NOTE that this hardcoded to service/voltha as the MIB template is shared across stacks
127 cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
128 cSuffixMibTemplateKvStore = "%s/%s/%s"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129)
130
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000131const cEmptyVendorIDString = "____"
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000132const cEmptyVersionString = "______________"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000133const cEmptyMacAddrString = "000000000000"
134const cEmptySerialNumberString = "0000000000000000"
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000135const cEmptyEquipIDString = "EMPTY_EQUIP_ID"
136const cNotPresentEquipIDString = "NOT_PRESENT_EQUIP_ID"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000137
Sridhar Ravindra27afb582025-02-10 13:18:11 +0530138const vlanConfigSendChanExpiry = 5
139
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000140type uniPersConfig struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000141 PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map
142 PersFlowParams []cmn.UniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530143 PersUniID uint8 `json:"uni_id"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000144}
145
146type onuPersistentData struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530147 PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000148 PersSerialNumber string `json:"serial_number"`
149 PersMacAddress string `json:"mac_address"`
150 PersVendorID string `json:"vendor_id"`
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000151 PersVersion string `json:"version"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 PersEquipmentID string `json:"equipment_id"`
153 PersActiveSwVersion string `json:"active_sw_version"`
154 PersAdminState string `json:"admin_state"`
155 PersOperState string `json:"oper_state"`
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530156 PersUniConfig []uniPersConfig `json:"uni_config"`
157 PersMibAuditInterval time.Duration `json:"mib_audit_interval"`
158 PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"`
159 PersOnuID uint32 `json:"onu_id"`
160 PersIntfID uint32 `json:"intf_id"`
161 PersMibLastDbSync uint32 `json:"mib_last_db_sync"`
162 PersIsExtOmciSupported bool `json:"is_ext_omci_supported"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000163 PersUniUnlockDone bool `json:"uni_unlock_done"`
164 PersUniDisableDone bool `json:"uni_disable_done"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000165 PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000166}
167
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000168//type UniTpidInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
169
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000170// OnuDeviceEntry - ONU device info and FSM events.
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530171//
172//nolint:govet
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000173type OnuDeviceEntry struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530174 SOnuPersistentData onuPersistentData
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000175 baseDeviceHandler cmn.IdeviceHandler
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000176 eventProxy eventif.EventProxy
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 pOpenOnuAc cmn.IopenONUAC
178 pOnuTP cmn.IonuUniTechProf
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530179 onuKVStoreProcResult error //error indication of processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000180 coreClient *vgrpc.Client
181 PDevOmciCC *cmn.OmciCC
182 pOnuDB *devdb.OnuDeviceDB
183 mibTemplateKVStore *db.Backend
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000184 ReconciledTpInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000185 chReconcilingFlowsFinished chan bool //channel to indicate that reconciling of flows has been finished
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000186 onuKVStore *db.Backend
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000187 POnuImageStatus *swupg.OnuImageStatus
188 //lockDeviceEntries sync.RWMutex
189 mibDbClass func(context.Context) error
190 supportedFsms cmn.OmciDeviceFsms
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530191
192 // for mibUpload
193 PMibUploadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
194 // for mibDownload
195 PMibDownloadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
196 pLastTxMeInstance *me.ManagedEntity
197 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
198 omciRebootMessageReceivedChannel chan cmn.Message // channel needed by reboot request
199 lastTxParamStruct sLastTxMeParameter
200 deviceID string
201 mibTemplatePath string
202 onuKVStorePath string
203 onuSwImageIndications cmn.SswImageIndications
204 devState cmn.OnuDeviceEvent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000205 // Audit and MDS
206 mibAuditInterval time.Duration
207 alarmAuditInterval time.Duration
208 // TODO: periodical mib resync will be implemented with story VOL-3792
209 //mibNextDbResync uint32
210
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530211 MutexPersOnuConfig sync.RWMutex
212 MutexReconciledTpInstances sync.RWMutex
213 mutexReconcilingFlowsFlag sync.RWMutex
214 mutexOnuKVStore sync.RWMutex
215 mutexOnuKVStoreProcResult sync.RWMutex
216 mutexOnuSwImageIndications sync.RWMutex
217 MutexOnuImageStatus sync.RWMutex
Girish Gowdra37c9d912022-02-08 16:24:57 -0800218 mutexLastTxParamStruct sync.RWMutex
Girish Gowdra37c9d912022-02-08 16:24:57 -0800219 mutexMibSyncMsgProcessorRunning sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000220 //remark: general usage of pAdapterFsm would require generalization of CommChan usage and internal event setting
221 // within the FSM event procedures
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530222 mutexPLastTxMeInstance sync.RWMutex
223 reconcilingFlows bool
224 mibSyncMsgProcessorRunning bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000225}
226
nikesh.krishnan1249be92023-11-27 04:20:12 +0530227// NewOnuDeviceEntry returns a new instance of a OnuDeviceEntry
228// mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000229func NewOnuDeviceEntry(ctx context.Context, cc *vgrpc.Client, dh cmn.IdeviceHandler,
230 openonu cmn.IopenONUAC) *OnuDeviceEntry {
231 var onuDeviceEntry OnuDeviceEntry
232 onuDeviceEntry.deviceID = dh.GetDeviceID()
233 logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": onuDeviceEntry.deviceID})
234 onuDeviceEntry.baseDeviceHandler = dh
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000235 onuDeviceEntry.eventProxy = dh.GetEventProxy()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000236 onuDeviceEntry.pOpenOnuAc = openonu
237 onuDeviceEntry.coreClient = cc
238 onuDeviceEntry.devState = cmn.DeviceStatusInit
239 onuDeviceEntry.SOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
240 onuDeviceEntry.SOnuPersistentData.PersTcontMap = make(map[uint16]uint16)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000241 onuDeviceEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000242 onuDeviceEntry.chReconcilingFlowsFinished = make(chan bool)
243 onuDeviceEntry.reconcilingFlows = false
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530244 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000245 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
246 //OMCI related databases are on a per-agent basis. State machines and tasks
247 //are per ONU Vendor
248 //
249 // MIB Synchronization Database - possible overloading from arguments
250 supportedFsms := onuDeviceEntry.pOpenOnuAc.GetSupportedFsms()
251 if supportedFsms != nil {
252 onuDeviceEntry.supportedFsms = *supportedFsms
253 } else {
254 // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only!
255 //var mibSyncFsm = NewMibSynchronizer()
256 // use some internal defaults, if not defined from outside
257 onuDeviceEntry.supportedFsms = cmn.OmciDeviceFsms{
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530258 "mib-synchronizer": cmn.ActivityDescr{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000259 //mibSyncFsm, // Implements the MIB synchronization state machine
260 DatabaseClass: onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
261 //true, // Advertise events on OpenOMCI event bus
262 AuditInterval: dh.GetAlarmAuditInterval(), // Time to wait between MIB audits. 0 to disable audits.
263 // map[string]func() error{
264 // "mib-upload": onuDeviceEntry.MibUploadTask,
265 // "mib-template": onuDeviceEntry.MibTemplateTask,
266 // "get-mds": onuDeviceEntry.GetMdsTask,
267 // "mib-audit": onuDeviceEntry.GetMdsTask,
268 // "mib-resync": onuDeviceEntry.MibResyncTask,
269 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
270 // },
271 },
272 }
273 }
274 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].DatabaseClass
275 logger.Debug(ctx, "access2mibDbClass")
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530276 go func() {
277 _ = onuDeviceEntry.mibDbClass(ctx)
278 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000279 if !dh.IsReconciling() {
280 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].AuditInterval
281 onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval
282 onuDeviceEntry.alarmAuditInterval = dh.GetAlarmAuditInterval()
283 onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval
284 } else {
285 logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": onuDeviceEntry.deviceID})
286 // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of
287 // vendor- or deviceID-specific configurations via voltctl-commands
288 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval
289 onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval
290 }
291 logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval,
292 "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval})
293 // TODO: periodical mib resync will be implemented with story VOL-3792
294 //onuDeviceEntry.mibNextDbResync = 0
295
296 // Omci related Mib upload sync state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530297 mibUploadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000298 onuDeviceEntry.PMibUploadFsm = cmn.NewAdapterFsm("MibUpload", onuDeviceEntry.deviceID, mibUploadChan)
299 onuDeviceEntry.PMibUploadFsm.PFsm = fsm.NewFSM(
300 UlStDisabled,
301 fsm.Events{
302
303 {Name: UlEvStart, Src: []string{UlStDisabled}, Dst: UlStStarting},
304
305 {Name: UlEvResetMib, Src: []string{UlStStarting}, Dst: UlStResettingMib},
306 {Name: UlEvGetVendorAndSerial, Src: []string{UlStResettingMib}, Dst: UlStGettingVendorAndSerial},
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000307 {Name: UlEvGetVersion, Src: []string{UlStGettingVendorAndSerial}, Dst: UlStGettingVersion},
308 {Name: UlEvGetEquipIDAndOmcc, Src: []string{UlStGettingVersion}, Dst: UlStGettingEquipIDAndOmcc},
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000309 {Name: UlEvTestExtOmciSupport, Src: []string{UlStGettingEquipIDAndOmcc}, Dst: UlStTestingExtOmciSupport},
310 {Name: UlEvGetFirstSwVersion, Src: []string{UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport}, Dst: UlStGettingFirstSwVersion},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000311 {Name: UlEvGetSecondSwVersion, Src: []string{UlStGettingFirstSwVersion}, Dst: UlStGettingSecondSwVersion},
312 {Name: UlEvGetMacAddress, Src: []string{UlStGettingSecondSwVersion}, Dst: UlStGettingMacAddress},
313 {Name: UlEvGetMibTemplate, Src: []string{UlStGettingMacAddress}, Dst: UlStGettingMibTemplate},
314
315 {Name: UlEvUploadMib, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploading},
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000316
317 {Name: UlEvVerifyAndStoreTPs, Src: []string{UlStStarting}, Dst: UlStVerifyingAndStoringTPs},
318 {Name: UlEvSuccess, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStExaminingMds},
319 {Name: UlEvMismatch, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStResettingMib},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000320
321 {Name: UlEvSuccess, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploadDone},
322 {Name: UlEvSuccess, Src: []string{UlStUploading}, Dst: UlStUploadDone},
323
324 {Name: UlEvSuccess, Src: []string{UlStUploadDone}, Dst: UlStInSync},
325 //{Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStInSync},
326 {Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStExaminingMdsSuccess},
327 // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers
328 // mib-reset and new provisioning at this point
329 //{Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResynchronizing},
330 {Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResettingMib},
331
332 {Name: UlEvSuccess, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStInSync},
333 {Name: UlEvMismatch, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStResettingMib},
334
335 {Name: UlEvAuditMib, Src: []string{UlStInSync}, Dst: UlStAuditing},
336
337 {Name: UlEvSuccess, Src: []string{UlStOutOfSync}, Dst: UlStInSync},
338 {Name: UlEvAuditMib, Src: []string{UlStOutOfSync}, Dst: UlStAuditing},
339
340 {Name: UlEvSuccess, Src: []string{UlStAuditing}, Dst: UlStInSync},
341 {Name: UlEvMismatch, Src: []string{UlStAuditing}, Dst: UlStReAuditing},
342 {Name: UlEvForceResync, Src: []string{UlStAuditing}, Dst: UlStResynchronizing},
343
344 {Name: UlEvSuccess, Src: []string{UlStReAuditing}, Dst: UlStInSync},
345 {Name: UlEvMismatch, Src: []string{UlStReAuditing}, Dst: UlStResettingMib},
346
347 {Name: UlEvSuccess, Src: []string{UlStResynchronizing}, Dst: UlStInSync},
348 {Name: UlEvDiffsFound, Src: []string{UlStResynchronizing}, Dst: UlStOutOfSync},
349
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000350 {Name: UlEvTimeout, Src: []string{UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000351 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
352 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStStarting},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000353
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000354 {Name: UlEvStop, Src: []string{UlStStarting, UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000355 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
356 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStDisabled},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000357 },
358
359 fsm.Callbacks{
360 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibUploadFsm.LogFsmStateChange(ctx, e) },
361 "enter_" + UlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) },
362 "enter_" + UlStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) },
363 "enter_" + UlStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) },
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000364 "enter_" + UlStGettingVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingVersionState(ctx, e) },
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000365 "enter_" + UlStGettingEquipIDAndOmcc: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipIDAndOmccVersState(ctx, e) },
366 "enter_" + UlStTestingExtOmciSupport: func(e *fsm.Event) { onuDeviceEntry.enterTestingExtOmciSupportState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000367 "enter_" + UlStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) },
368 "enter_" + UlStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) },
369 "enter_" + UlStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) },
370 "enter_" + UlStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) },
371 "enter_" + UlStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) },
372 "enter_" + UlStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) },
373 "enter_" + UlStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) },
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000374 "enter_" + UlStVerifyingAndStoringTPs: func(e *fsm.Event) { onuDeviceEntry.enterVerifyingAndStoringTPsState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000375 "enter_" + UlStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) },
376 "enter_" + UlStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) },
377 "enter_" + UlStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) },
378 "enter_" + UlStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) },
379 "enter_" + UlStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) },
380 "enter_" + UlStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) },
381 },
382 )
383 // Omci related Mib download state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530384 mibDownloadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000385 onuDeviceEntry.PMibDownloadFsm = cmn.NewAdapterFsm("MibDownload", onuDeviceEntry.deviceID, mibDownloadChan)
386 onuDeviceEntry.PMibDownloadFsm.PFsm = fsm.NewFSM(
387 DlStDisabled,
388 fsm.Events{
389
390 {Name: DlEvStart, Src: []string{DlStDisabled}, Dst: DlStStarting},
391
392 {Name: DlEvCreateGal, Src: []string{DlStStarting}, Dst: DlStCreatingGal},
393 {Name: DlEvRxGalResp, Src: []string{DlStCreatingGal}, Dst: DlStSettingOnu2g},
394 {Name: DlEvRxOnu2gResp, Src: []string{DlStSettingOnu2g}, Dst: DlStBridgeInit},
395 // the bridge state is used for multi ME config for alle UNI related ports
396 // maybe such could be reflected in the state machine as well (port number parametrized)
397 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
398 {Name: DlEvRxBridgeResp, Src: []string{DlStBridgeInit}, Dst: DlStDownloaded},
399
400 {Name: DlEvTimeoutSimple, Src: []string{DlStCreatingGal, DlStSettingOnu2g}, Dst: DlStStarting},
401 {Name: DlEvTimeoutBridge, Src: []string{DlStBridgeInit}, Dst: DlStStarting},
402
403 {Name: DlEvReset, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
404 DlStBridgeInit, DlStDownloaded}, Dst: DlStResetting},
405 // exceptional treatment for all states except DlStResetting
406 {Name: DlEvRestart, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
407 DlStBridgeInit, DlStDownloaded, DlStResetting}, Dst: DlStDisabled},
408 },
409
410 fsm.Callbacks{
411 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibDownloadFsm.LogFsmStateChange(ctx, e) },
412 "enter_" + DlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) },
413 "enter_" + DlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) },
414 "enter_" + DlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) },
415 "enter_" + DlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) },
416 "enter_" + DlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) },
417 "enter_" + DlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) },
418 },
419 )
420 if onuDeviceEntry.PMibDownloadFsm == nil || onuDeviceEntry.PMibDownloadFsm.PFsm == nil {
421 logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": onuDeviceEntry.deviceID})
422 // TODO some specific error treatment - or waiting for crash ?
423 }
424
425 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, cBasePathMibTemplateKvStore)
426 if onuDeviceEntry.mibTemplateKVStore == nil {
427 logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service",
428 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": cBasePathMibTemplateKvStore})
429 }
430
431 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
Holger Hildebrandt60652202021-11-02 11:09:36 +0000432 baseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, dh.GetBackendPathPrefix())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000433 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, baseKvStorePath)
434 if onuDeviceEntry.onuKVStore == nil {
435 logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service",
436 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": baseKvStorePath})
437 }
438
439 // Alarm Synchronization Database
440
441 //self._alarm_db = None
442 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
443 return &onuDeviceEntry
444}
445
nikesh.krishnan1249be92023-11-27 04:20:12 +0530446// Start starts (logs) the omci agent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000447func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
448 logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
449 if oo.PDevOmciCC == nil {
450 oo.PDevOmciCC = cmn.NewOmciCC(ctx, oo.deviceID, oo.baseDeviceHandler, oo, oo.baseDeviceHandler.GetOnuAlarmManager(), oo.coreClient)
451 if oo.PDevOmciCC == nil {
452 logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
453 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
454 }
455 }
456 return nil
457}
458
nikesh.krishnan1249be92023-11-27 04:20:12 +0530459// Stop stops/resets the omciCC
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000460func (oo *OnuDeviceEntry) Stop(ctx context.Context, abResetOmciCC bool) error {
461 logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
462 if abResetOmciCC && (oo.PDevOmciCC != nil) {
463 _ = oo.PDevOmciCC.Stop(ctx)
464 }
465 //to allow for all event notifications again when re-using the device and omciCC
466 oo.devState = cmn.DeviceStatusInit
467 return nil
468}
469
470// Reboot - TODO: add comment
471func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error {
472 logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
473 if oo.PDevOmciCC != nil {
474 if err := oo.PDevOmciCC.SendReboot(ctx, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.omciRebootMessageReceivedChannel); err != nil {
475 logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
476 return err
477 }
478 }
479 return nil
480}
481
482// WaitForRebootResponse - TODO: add comment
483func (oo *OnuDeviceEntry) WaitForRebootResponse(ctx context.Context, responseChannel chan cmn.Message) error {
484 select {
485 case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
486 logger.Warnw(ctx, "reboot timeout", log.Fields{"for device-id": oo.deviceID})
487 return fmt.Errorf("rebootTimeout")
488 case data := <-responseChannel:
489 switch data.Data.(cmn.OmciMessage).OmciMsg.MessageType {
490 case omci.RebootResponseType:
491 {
492 msgLayer := (*data.Data.(cmn.OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
493 if msgLayer == nil {
494 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
495 }
496 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
497 if !msgOk {
498 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
499 }
500 logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
501 if msgObj.Result != me.Success {
502 logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
503 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
504 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
505 msgObj.Result, oo.deviceID)
506 }
507 return nil
508 }
509 }
510 logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
511 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
512 }
513}
514
nikesh.krishnan1249be92023-11-27 04:20:12 +0530515// Relay the InSync message via Handler to Rw core - Status update
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000516func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000517 logger.Debugw(ctx, "relaying system-event", log.Fields{"device-id": oo.deviceID, "Event": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000518 // decouple the handler transfer from further processing here
519 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
520 if devEvent == cmn.MibDatabaseSync {
521 if oo.devState < cmn.MibDatabaseSync { //devState has not been synced yet
522 oo.devState = cmn.MibDatabaseSync
523 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
524 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
525 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000526 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored",
527 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000528 }
529 } else if devEvent == cmn.MibDownloadDone {
530 if oo.devState < cmn.MibDownloadDone { //devState has not been synced yet
531 oo.devState = cmn.MibDownloadDone
532 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
533 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000534 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored",
535 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000536 }
537 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000538 logger.Warnw(ctx, "device-event not yet handled",
539 log.Fields{"device-id": oo.deviceID, "state": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000540 }
541}
542
543// RestoreDataFromOnuKvStore - TODO: add comment
544func (oo *OnuDeviceEntry) RestoreDataFromOnuKvStore(ctx context.Context) error {
545 if oo.onuKVStore == nil {
546 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530547 return fmt.Errorf("onuKVStore-not-set-abort-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000548 }
549 oo.MutexPersOnuConfig.Lock()
550 defer oo.MutexPersOnuConfig.Unlock()
551 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530552 onuPersistentData{
553 PersTcontMap: make(map[uint16]uint16),
554 PersSerialNumber: "",
555 PersMacAddress: "",
556 PersVendorID: "",
557 PersVersion: "",
558 PersEquipmentID: "",
559 PersActiveSwVersion: "",
560 PersAdminState: "",
561 PersOperState: "",
562 PersUniConfig: make([]uniPersConfig, 0),
563 PersMibAuditInterval: oo.mibAuditInterval,
564 PersAlarmAuditInterval: oo.alarmAuditInterval,
565 PersOnuID: 0,
566 PersIntfID: 0,
567 PersMibLastDbSync: 0,
568 PersIsExtOmciSupported: false,
569 PersUniUnlockDone: false,
570 PersUniDisableDone: false,
571 PersMibDataSyncAdpt: 0,
572 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000573 oo.mutexOnuKVStore.RLock()
574 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
575 oo.mutexOnuKVStore.RUnlock()
576 if err == nil {
577 if Value != nil {
578 logger.Debugw(ctx, "ONU-data read",
579 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
580 tmpBytes, _ := kvstore.ToByte(Value.Value)
581
582 if err = json.Unmarshal(tmpBytes, &oo.SOnuPersistentData); err != nil {
583 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530584 return fmt.Errorf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000585 }
586 logger.Debugw(ctx, "ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
587 "device-id": oo.deviceID})
588 } else {
589 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
590 return fmt.Errorf("no-ONU-data-found")
591 }
592 } else {
593 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530594 return fmt.Errorf("unable-to-read-from-KVstore-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000595 }
596 return nil
597}
598
599// DeleteDataFromOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530600func (oo *OnuDeviceEntry) DeleteDataFromOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000601
602 if oo.onuKVStore == nil {
603 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530604 return errors.New("onu-data delete aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000605 }
Akash Soni840f8d62024-12-11 19:37:06 +0530606 err := oo.deletePersistentData(ctx)
607 if err != nil {
608 logger.Errorf(ctx, "onu-data delete aborted: during kv-access", log.Fields{"device-id": oo.deviceID, "err": err})
609 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000610 }
Akash Soni840f8d62024-12-11 19:37:06 +0530611 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000612}
613
Akash Soni840f8d62024-12-11 19:37:06 +0530614func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000615
616 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000617 oo.MutexPersOnuConfig.Lock()
618 defer oo.MutexPersOnuConfig.Unlock()
619
620 oo.SOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
621 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530622 onuPersistentData{
623 PersTcontMap: make(map[uint16]uint16),
624 PersSerialNumber: "",
625 PersMacAddress: "",
626 PersVendorID: "",
627 PersVersion: "",
628 PersEquipmentID: "",
629 PersActiveSwVersion: "",
630 PersAdminState: "",
631 PersOperState: "",
632 PersUniConfig: make([]uniPersConfig, 0),
633 PersMibAuditInterval: oo.mibAuditInterval,
634 PersAlarmAuditInterval: oo.alarmAuditInterval,
635 PersOnuID: 0,
636 PersIntfID: 0,
637 PersMibLastDbSync: 0,
638 PersIsExtOmciSupported: false,
639 PersUniUnlockDone: false,
640 PersUniDisableDone: false,
641 PersMibDataSyncAdpt: 0,
642 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000643 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
644 oo.mutexOnuKVStore.Lock()
645 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
646 oo.mutexOnuKVStore.Unlock()
647 if err != nil {
648 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530649 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000650 }
Akash Soni840f8d62024-12-11 19:37:06 +0530651 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000652}
653
654// UpdateOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530655func (oo *OnuDeviceEntry) UpdateOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000656
657 if oo.onuKVStore == nil {
658 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530659 return errors.New("onu-data update aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000660 }
Akash Soni840f8d62024-12-11 19:37:06 +0530661 err := oo.storeDataInOnuKvStore(ctx)
662 if err != nil {
663 logger.Errorf(ctx, "onu-data update aborted: during writing process", log.Fields{"device-id": oo.deviceID, "err": err})
664 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000665 }
Akash Soni840f8d62024-12-11 19:37:06 +0530666 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000667}
668
Akash Soni840f8d62024-12-11 19:37:06 +0530669func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000670
671 oo.MutexPersOnuConfig.Lock()
672 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000673
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000674 oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
675 if _, exist := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID); !exist {
676 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000677 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
Akash Soni840f8d62024-12-11 19:37:06 +0530678 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000679 }
680 oo.baseDeviceHandler.RLockMutexDeletionInProgressFlag()
681 if oo.baseDeviceHandler.GetDeletionInProgress() {
682 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000683 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
684 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
Akash Soni840f8d62024-12-11 19:37:06 +0530685 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000686 }
687 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
688 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
689
nikesh.krishnan1249be92023-11-27 04:20:12 +0530690 //assign values which are not already present when NewOnuDeviceEntry() is called
691 onuIndication := oo.baseDeviceHandler.GetOnuIndication()
692 if onuIndication != nil {
693 oo.SOnuPersistentData.PersOnuID = onuIndication.OnuId
694 oo.SOnuPersistentData.PersIntfID = onuIndication.IntfId
695 //TODO: verify usage of these values during restart UC
696 oo.SOnuPersistentData.PersAdminState = onuIndication.AdminState
697 oo.SOnuPersistentData.PersOperState = onuIndication.OperState
698 } else {
699 logger.Errorw(ctx, "onuIndication not set, unable to load ONU-data", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530700 return errors.New("onuIndication not set, unable to load ONU-data")
nikesh.krishnan1249be92023-11-27 04:20:12 +0530701 }
702
703 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "SOnuPersistentData": oo.SOnuPersistentData})
704
705 Value, err := json.Marshal(oo.SOnuPersistentData)
706 if err != nil {
707 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
708 "device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530709 return err
nikesh.krishnan1249be92023-11-27 04:20:12 +0530710 }
711
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000712 oo.mutexOnuKVStore.Lock()
713 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
714 oo.mutexOnuKVStore.Unlock()
715 if err != nil {
Akash Soni840f8d62024-12-11 19:37:06 +0530716 logger.Errorf(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
717 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000718 }
Akash Soni840f8d62024-12-11 19:37:06 +0530719 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000720}
721
722// UpdateOnuUniTpPath - TODO: add comment
723func (oo *OnuDeviceEntry) UpdateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
724 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
725 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
726 no specific concurrency protection to SOnuPersistentData is required here
727 */
728 oo.MutexPersOnuConfig.Lock()
729 defer oo.MutexPersOnuConfig.Unlock()
730
731 for k, v := range oo.SOnuPersistentData.PersUniConfig {
732 if v.PersUniID == aUniID {
733 existingPath, ok := oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
734 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
735 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
736 if !ok {
737 logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString})
738 }
739 if existingPath != aPathString {
740 if aPathString == "" {
741 //existing entry to be deleted
742 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
743 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
744 } else {
745 //existing entry to be modified
746 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
747 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
748 }
749 return true
750 }
751 //entry already exists
752 if aPathString == "" {
753 //no active TechProfile
754 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
755 "device-id": oo.deviceID, "uniID": aUniID})
756 } else {
757 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
758 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
759 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
760 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
761 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
762 //no deviceReason update (DeviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
763 // (during which the flows are removed/re-assigned but the techProf is left active)
764 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
765 // (should not be the case, but should not harm or be more robust ...)
766 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
767 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
768 if oo.pOnuTP != nil {
769 oo.pOnuTP.SetProfileToDelete(aUniID, aTpID, false)
770 }
771 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
772 }
773 return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
774 }
775 }
776 //no entry exists for uniId
777
778 if aPathString == "" {
779 //delete request in non-existing state , accept as no change
780 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
781 return false
782 }
783 //new entry to be created
784 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
785 perSubTpPathMap := make(map[uint8]string)
786 perSubTpPathMap[aTpID] = aPathString
787 oo.SOnuPersistentData.PersUniConfig =
788 append(oo.SOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]cmn.UniVlanFlowParams, 0)})
789 return true
790}
791
792// UpdateOnuUniFlowConfig - TODO: add comment
793func (oo *OnuDeviceEntry) UpdateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]cmn.UniVlanFlowParams) {
794
795 oo.MutexPersOnuConfig.Lock()
796 defer oo.MutexPersOnuConfig.Unlock()
797
798 for k, v := range oo.SOnuPersistentData.PersUniConfig {
799 if v.PersUniID == aUniID {
800 oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))
801 copy(oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
802 return
803 }
804 }
805 //flow update was faster than tp-config - create PersUniConfig-entry
806 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
807 // (e.g after flow removal from RemoveUniFlowParams()).
808 // This has the effect of misleading indication that there is still some active UNI entry, even though there might be only some nil flow entry
809 // The effect of this flaw is that at TechProfile removal there is an additional attempt to remove the entry even though no techProfile exists anymore
810 // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests
811 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))}
812 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
813 oo.SOnuPersistentData.PersUniConfig = append(oo.SOnuPersistentData.PersUniConfig, tmpConfig)
814}
815
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000816// ResetKvProcessingErrorIndication - TODO: add comment
817func (oo *OnuDeviceEntry) ResetKvProcessingErrorIndication() {
818 oo.mutexOnuKVStoreProcResult.Lock()
819 oo.onuKVStoreProcResult = nil
820 oo.mutexOnuKVStoreProcResult.Unlock()
821}
822
823// GetKvProcessingErrorIndication - TODO: add comment
824func (oo *OnuDeviceEntry) GetKvProcessingErrorIndication() error {
825 oo.mutexOnuKVStoreProcResult.RLock()
826 value := oo.onuKVStoreProcResult
827 oo.mutexOnuKVStoreProcResult.RUnlock()
828 return value
829}
830
Akash Soni840f8d62024-12-11 19:37:06 +0530831// func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
832// oo.mutexOnuKVStoreProcResult.Lock()
833// oo.onuKVStoreProcResult = value
834// oo.mutexOnuKVStoreProcResult.Unlock()
835// }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000836
837// IncrementMibDataSync - TODO: add comment
838func (oo *OnuDeviceEntry) IncrementMibDataSync(ctx context.Context) {
839 oo.MutexPersOnuConfig.Lock()
840 defer oo.MutexPersOnuConfig.Unlock()
841 if oo.SOnuPersistentData.PersMibDataSyncAdpt < 255 {
842 oo.SOnuPersistentData.PersMibDataSyncAdpt++
843 } else {
844 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
845 oo.SOnuPersistentData.PersMibDataSyncAdpt = 1
846 }
847 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.SOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
848}
849
850// ModifySwImageInactiveVersion - updates the inactive SW image version stored
851func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
852 oo.mutexOnuSwImageIndications.Lock()
853 defer oo.mutexOnuSwImageIndications.Unlock()
854 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
855 "device-id": oo.deviceID, "version": aImageVersion})
856 oo.onuSwImageIndications.InActiveEntityEntry.Version = aImageVersion
857 //inactive SW version is not part of persistency data (yet) - no need to update that
858}
859
860// ModifySwImageActiveCommit - updates the active SW commit flag stored
861func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
862 oo.mutexOnuSwImageIndications.Lock()
863 defer oo.mutexOnuSwImageIndications.Unlock()
864 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
865 "device-id": oo.deviceID, "committed": aCommitted})
866 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = aCommitted
867 //commit flag is not part of persistency data (yet) - no need to update that
868}
869
870// GetActiveImageVersion - returns the active SW image version stored
871func (oo *OnuDeviceEntry) GetActiveImageVersion(ctx context.Context) string {
872 oo.mutexOnuSwImageIndications.RLock()
873 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
874 value := oo.onuSwImageIndications.ActiveEntityEntry.Version
875 oo.mutexOnuSwImageIndications.RUnlock()
876 return value
877 }
878 oo.mutexOnuSwImageIndications.RUnlock()
879 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
880 return ""
881}
882
883// GetInactiveImageVersion - TODO: add comment
884func (oo *OnuDeviceEntry) GetInactiveImageVersion(ctx context.Context) string {
885 oo.mutexOnuSwImageIndications.RLock()
886 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
887 value := oo.onuSwImageIndications.InActiveEntityEntry.Version
888 oo.mutexOnuSwImageIndications.RUnlock()
889 return value
890 }
891 oo.mutexOnuSwImageIndications.RUnlock()
892 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
893 return ""
894}
895
896func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
897 oo.MutexPersOnuConfig.RLock()
898 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000899 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.SOnuPersistentData.PersVendorID, oo.SOnuPersistentData.PersVersion,
900 oo.SOnuPersistentData.PersActiveSwVersion)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000901}
902
903// AllocateFreeTcont - TODO: add comment
904func (oo *OnuDeviceEntry) AllocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
905 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
906 "allocated-instances": oo.SOnuPersistentData.PersTcontMap})
907
mpagenko2c3f6c52021-11-23 11:22:10 +0000908 oo.MutexPersOnuConfig.Lock()
909 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000910 if entityID, ok := oo.SOnuPersistentData.PersTcontMap[allocID]; ok {
911 //tcont already allocated before, return the used instance-id
912 return entityID, true, nil
913 }
914 //First allocation of tcont. Find a free instance
915 if tcontInstKeys := oo.pOnuDB.GetSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
916 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
917 for _, instID := range tcontInstKeys {
918 instExist := false
919 //If this instance exist in map, it means it is not empty. It is allocated before
920 for _, v := range oo.SOnuPersistentData.PersTcontMap {
921 if v == instID {
922 instExist = true
923 break
924 }
925 }
926 if !instExist {
927 oo.SOnuPersistentData.PersTcontMap[allocID] = instID
928 return instID, false, nil
929 }
930 }
931 }
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530932 return 0, false, fmt.Errorf("no-free-tcont-left-for-device-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000933}
934
935// FreeTcont - TODO: add comment
936func (oo *OnuDeviceEntry) FreeTcont(ctx context.Context, allocID uint16) {
937 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
mpagenko2c3f6c52021-11-23 11:22:10 +0000938 oo.MutexPersOnuConfig.Lock()
939 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000940 delete(oo.SOnuPersistentData.PersTcontMap, allocID)
941}
942
943// GetDevOmciCC - TODO: add comment
944func (oo *OnuDeviceEntry) GetDevOmciCC() *cmn.OmciCC {
945 return oo.PDevOmciCC
946}
947
948// GetOnuDB - TODO: add comment
949func (oo *OnuDeviceEntry) GetOnuDB() *devdb.OnuDeviceDB {
950 return oo.pOnuDB
951}
952
953// GetPersSerialNumber - TODO: add comment
954func (oo *OnuDeviceEntry) GetPersSerialNumber() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000955 oo.MutexPersOnuConfig.RLock()
956 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000957 value := oo.SOnuPersistentData.PersSerialNumber
958 return value
959}
960
961// GetPersVendorID - TODO: add comment
962func (oo *OnuDeviceEntry) GetPersVendorID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000963 oo.MutexPersOnuConfig.RLock()
964 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000965 value := oo.SOnuPersistentData.PersVendorID
966 return value
967}
968
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000969// GetPersIsExtOmciSupported - TODO: add comment
970func (oo *OnuDeviceEntry) GetPersIsExtOmciSupported() bool {
971 oo.MutexPersOnuConfig.RLock()
972 defer oo.MutexPersOnuConfig.RUnlock()
973 value := oo.SOnuPersistentData.PersIsExtOmciSupported
974 return value
975}
976
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000977// GetPersVersion - TODO: add comment
978func (oo *OnuDeviceEntry) GetPersVersion() string {
979 oo.MutexPersOnuConfig.RLock()
980 defer oo.MutexPersOnuConfig.RUnlock()
981 value := oo.SOnuPersistentData.PersVersion
982 return value
983}
984
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000985// GetPersEquipmentID - TODO: add comment
986func (oo *OnuDeviceEntry) GetPersEquipmentID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000987 oo.MutexPersOnuConfig.RLock()
988 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989 value := oo.SOnuPersistentData.PersEquipmentID
990 return value
991}
992
993// GetMibUploadFsmCommChan - TODO: add comment
994func (oo *OnuDeviceEntry) GetMibUploadFsmCommChan() chan cmn.Message {
995 return oo.PMibUploadFsm.CommChan
996}
997
998// GetMibDownloadFsmCommChan - TODO: add comment
999func (oo *OnuDeviceEntry) GetMibDownloadFsmCommChan() chan cmn.Message {
1000 return oo.PMibDownloadFsm.CommChan
1001}
1002
1003// GetOmciRebootMsgRevChan - TODO: add comment
1004func (oo *OnuDeviceEntry) GetOmciRebootMsgRevChan() chan cmn.Message {
1005 return oo.omciRebootMessageReceivedChannel
1006}
1007
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008// GetPersActiveSwVersion - TODO: add comment
1009func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string {
mpagenko2c3f6c52021-11-23 11:22:10 +00001010 oo.MutexPersOnuConfig.RLock()
1011 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001012 return oo.SOnuPersistentData.PersActiveSwVersion
1013}
1014
1015// SetPersActiveSwVersion - TODO: add comment
1016func (oo *OnuDeviceEntry) SetPersActiveSwVersion(value string) {
mpagenko2c3f6c52021-11-23 11:22:10 +00001017 oo.MutexPersOnuConfig.Lock()
1018 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001019 oo.SOnuPersistentData.PersActiveSwVersion = value
1020}
1021
mpagenko101ac942021-11-16 15:01:29 +00001022// setReconcilingFlows - TODO: add comment
1023func (oo *OnuDeviceEntry) setReconcilingFlows(value bool) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001024 oo.mutexReconcilingFlowsFlag.Lock()
1025 oo.reconcilingFlows = value
1026 oo.mutexReconcilingFlowsFlag.Unlock()
1027}
1028
mpagenko101ac942021-11-16 15:01:29 +00001029// SendChReconcilingFlowsFinished - TODO: add comment
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001030func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) {
mpagenko101ac942021-11-16 15:01:29 +00001031 if oo != nil { //if the object still exists (might have been already deleted in background)
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301032 // wait for some time before exiting, as the receiver might not have started and will lead to Mib reset if this signal is missed
1033 expiry := vlanConfigSendChanExpiry * time.Second
mpagenko101ac942021-11-16 15:01:29 +00001034 select {
1035 case oo.chReconcilingFlowsFinished <- value:
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301036 logger.Info(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID})
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301037 case <-time.After(expiry):
1038 logger.Infow(ctx, "reconciling - timer expired, flows finished not sent!", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +00001039 }
1040 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001041}
1042
mpagenko101ac942021-11-16 15:01:29 +00001043// isReconcilingFlows - TODO: add comment
1044func (oo *OnuDeviceEntry) isReconcilingFlows() bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001045 oo.mutexReconcilingFlowsFlag.RLock()
1046 value := oo.reconcilingFlows
1047 oo.mutexReconcilingFlowsFlag.RUnlock()
1048 return value
1049}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001050
1051// PrepareForGarbageCollection - remove references to prepare for garbage collection
1052func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1053 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1054 oo.baseDeviceHandler = nil
1055 oo.pOnuTP = nil
1056 if oo.PDevOmciCC != nil {
1057 oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID)
1058 }
1059 oo.PDevOmciCC = nil
1060}
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001061
nikesh.krishnan1249be92023-11-27 04:20:12 +05301062// SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001063func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) {
1064
1065 oo.MutexPersOnuConfig.RLock()
1066 context := make(map[string]string)
1067 context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10)
1068 context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10)
1069 context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber
1070 oo.MutexPersOnuConfig.RUnlock()
1071
1072 deviceEvent := &voltha.DeviceEvent{
1073 ResourceId: oo.deviceID,
1074 DeviceEventName: aDeviceEventName,
1075 Description: aDescription,
1076 Context: context,
1077 }
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001078 logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": oo.deviceID})
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001079 _ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix())
1080}
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301081
1082// IsMIBTemplateGenerated checks if a MIB Template is already present for this type of ONT.
1083func (oo *OnuDeviceEntry) IsMIBTemplateGenerated(ctx context.Context) bool {
1084
1085 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1086 defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
1087
1088 if _, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); !exist {
1089 logger.Infow(ctx, "MIB template not Generated , further proceed to do MIB sync upload ", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1090 return false
1091 }
1092 return true
1093}