blob: 65d223faa9306e1e09b5bc9d185eebbd0f244070 [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"`
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530165 PersRebootInProgress bool `json:"reboot_in_progress"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000166 PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000167}
168
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000169//type UniTpidInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
170
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000171// OnuDeviceEntry - ONU device info and FSM events.
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530172//
173//nolint:govet
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000174type OnuDeviceEntry struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530175 SOnuPersistentData onuPersistentData
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000176 baseDeviceHandler cmn.IdeviceHandler
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000177 eventProxy eventif.EventProxy
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000178 pOpenOnuAc cmn.IopenONUAC
179 pOnuTP cmn.IonuUniTechProf
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530180 onuKVStoreProcResult error //error indication of processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000181 coreClient *vgrpc.Client
182 PDevOmciCC *cmn.OmciCC
183 pOnuDB *devdb.OnuDeviceDB
184 mibTemplateKVStore *db.Backend
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000185 ReconciledTpInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000186 chReconcilingFlowsFinished chan bool //channel to indicate that reconciling of flows has been finished
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000187 onuKVStore *db.Backend
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000188 POnuImageStatus *swupg.OnuImageStatus
189 //lockDeviceEntries sync.RWMutex
190 mibDbClass func(context.Context) error
191 supportedFsms cmn.OmciDeviceFsms
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530192
193 // for mibUpload
194 PMibUploadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
195 // for mibDownload
196 PMibDownloadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
197 pLastTxMeInstance *me.ManagedEntity
198 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
199 omciRebootMessageReceivedChannel chan cmn.Message // channel needed by reboot request
200 lastTxParamStruct sLastTxMeParameter
201 deviceID string
202 mibTemplatePath string
203 onuKVStorePath string
204 onuSwImageIndications cmn.SswImageIndications
205 devState cmn.OnuDeviceEvent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000206 // Audit and MDS
207 mibAuditInterval time.Duration
208 alarmAuditInterval time.Duration
209 // TODO: periodical mib resync will be implemented with story VOL-3792
210 //mibNextDbResync uint32
211
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530212 MutexPersOnuConfig sync.RWMutex
213 MutexReconciledTpInstances sync.RWMutex
214 mutexReconcilingFlowsFlag sync.RWMutex
215 mutexOnuKVStore sync.RWMutex
216 mutexOnuKVStoreProcResult sync.RWMutex
217 mutexOnuSwImageIndications sync.RWMutex
218 MutexOnuImageStatus sync.RWMutex
Girish Gowdra37c9d912022-02-08 16:24:57 -0800219 mutexLastTxParamStruct sync.RWMutex
Girish Gowdra37c9d912022-02-08 16:24:57 -0800220 mutexMibSyncMsgProcessorRunning sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000221 //remark: general usage of pAdapterFsm would require generalization of CommChan usage and internal event setting
222 // within the FSM event procedures
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530223 mutexPLastTxMeInstance sync.RWMutex
224 reconcilingFlows bool
225 mibSyncMsgProcessorRunning bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000226}
227
nikesh.krishnan1249be92023-11-27 04:20:12 +0530228// NewOnuDeviceEntry returns a new instance of a OnuDeviceEntry
229// mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000230func NewOnuDeviceEntry(ctx context.Context, cc *vgrpc.Client, dh cmn.IdeviceHandler,
231 openonu cmn.IopenONUAC) *OnuDeviceEntry {
232 var onuDeviceEntry OnuDeviceEntry
233 onuDeviceEntry.deviceID = dh.GetDeviceID()
234 logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": onuDeviceEntry.deviceID})
235 onuDeviceEntry.baseDeviceHandler = dh
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000236 onuDeviceEntry.eventProxy = dh.GetEventProxy()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000237 onuDeviceEntry.pOpenOnuAc = openonu
238 onuDeviceEntry.coreClient = cc
239 onuDeviceEntry.devState = cmn.DeviceStatusInit
240 onuDeviceEntry.SOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
241 onuDeviceEntry.SOnuPersistentData.PersTcontMap = make(map[uint16]uint16)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000242 onuDeviceEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000243 onuDeviceEntry.chReconcilingFlowsFinished = make(chan bool)
244 onuDeviceEntry.reconcilingFlows = false
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530245 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000246 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
247 //OMCI related databases are on a per-agent basis. State machines and tasks
248 //are per ONU Vendor
249 //
250 // MIB Synchronization Database - possible overloading from arguments
251 supportedFsms := onuDeviceEntry.pOpenOnuAc.GetSupportedFsms()
252 if supportedFsms != nil {
253 onuDeviceEntry.supportedFsms = *supportedFsms
254 } else {
255 // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only!
256 //var mibSyncFsm = NewMibSynchronizer()
257 // use some internal defaults, if not defined from outside
258 onuDeviceEntry.supportedFsms = cmn.OmciDeviceFsms{
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530259 "mib-synchronizer": cmn.ActivityDescr{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000260 //mibSyncFsm, // Implements the MIB synchronization state machine
261 DatabaseClass: onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
262 //true, // Advertise events on OpenOMCI event bus
263 AuditInterval: dh.GetAlarmAuditInterval(), // Time to wait between MIB audits. 0 to disable audits.
264 // map[string]func() error{
265 // "mib-upload": onuDeviceEntry.MibUploadTask,
266 // "mib-template": onuDeviceEntry.MibTemplateTask,
267 // "get-mds": onuDeviceEntry.GetMdsTask,
268 // "mib-audit": onuDeviceEntry.GetMdsTask,
269 // "mib-resync": onuDeviceEntry.MibResyncTask,
270 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
271 // },
272 },
273 }
274 }
275 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].DatabaseClass
276 logger.Debug(ctx, "access2mibDbClass")
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530277 go func() {
278 _ = onuDeviceEntry.mibDbClass(ctx)
279 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000280 if !dh.IsReconciling() {
281 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].AuditInterval
282 onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval
283 onuDeviceEntry.alarmAuditInterval = dh.GetAlarmAuditInterval()
284 onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval
285 } else {
286 logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": onuDeviceEntry.deviceID})
287 // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of
288 // vendor- or deviceID-specific configurations via voltctl-commands
289 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval
290 onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval
291 }
292 logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval,
293 "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval})
294 // TODO: periodical mib resync will be implemented with story VOL-3792
295 //onuDeviceEntry.mibNextDbResync = 0
296
297 // Omci related Mib upload sync state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530298 mibUploadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000299 onuDeviceEntry.PMibUploadFsm = cmn.NewAdapterFsm("MibUpload", onuDeviceEntry.deviceID, mibUploadChan)
300 onuDeviceEntry.PMibUploadFsm.PFsm = fsm.NewFSM(
301 UlStDisabled,
302 fsm.Events{
303
304 {Name: UlEvStart, Src: []string{UlStDisabled}, Dst: UlStStarting},
305
306 {Name: UlEvResetMib, Src: []string{UlStStarting}, Dst: UlStResettingMib},
307 {Name: UlEvGetVendorAndSerial, Src: []string{UlStResettingMib}, Dst: UlStGettingVendorAndSerial},
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000308 {Name: UlEvGetVersion, Src: []string{UlStGettingVendorAndSerial}, Dst: UlStGettingVersion},
309 {Name: UlEvGetEquipIDAndOmcc, Src: []string{UlStGettingVersion}, Dst: UlStGettingEquipIDAndOmcc},
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000310 {Name: UlEvTestExtOmciSupport, Src: []string{UlStGettingEquipIDAndOmcc}, Dst: UlStTestingExtOmciSupport},
311 {Name: UlEvGetFirstSwVersion, Src: []string{UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport}, Dst: UlStGettingFirstSwVersion},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000312 {Name: UlEvGetSecondSwVersion, Src: []string{UlStGettingFirstSwVersion}, Dst: UlStGettingSecondSwVersion},
313 {Name: UlEvGetMacAddress, Src: []string{UlStGettingSecondSwVersion}, Dst: UlStGettingMacAddress},
314 {Name: UlEvGetMibTemplate, Src: []string{UlStGettingMacAddress}, Dst: UlStGettingMibTemplate},
315
316 {Name: UlEvUploadMib, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploading},
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000317
318 {Name: UlEvVerifyAndStoreTPs, Src: []string{UlStStarting}, Dst: UlStVerifyingAndStoringTPs},
319 {Name: UlEvSuccess, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStExaminingMds},
320 {Name: UlEvMismatch, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStResettingMib},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000321
322 {Name: UlEvSuccess, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploadDone},
323 {Name: UlEvSuccess, Src: []string{UlStUploading}, Dst: UlStUploadDone},
324
325 {Name: UlEvSuccess, Src: []string{UlStUploadDone}, Dst: UlStInSync},
326 //{Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStInSync},
327 {Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStExaminingMdsSuccess},
328 // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers
329 // mib-reset and new provisioning at this point
330 //{Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResynchronizing},
331 {Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResettingMib},
332
333 {Name: UlEvSuccess, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStInSync},
334 {Name: UlEvMismatch, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStResettingMib},
335
336 {Name: UlEvAuditMib, Src: []string{UlStInSync}, Dst: UlStAuditing},
337
338 {Name: UlEvSuccess, Src: []string{UlStOutOfSync}, Dst: UlStInSync},
339 {Name: UlEvAuditMib, Src: []string{UlStOutOfSync}, Dst: UlStAuditing},
340
341 {Name: UlEvSuccess, Src: []string{UlStAuditing}, Dst: UlStInSync},
342 {Name: UlEvMismatch, Src: []string{UlStAuditing}, Dst: UlStReAuditing},
343 {Name: UlEvForceResync, Src: []string{UlStAuditing}, Dst: UlStResynchronizing},
344
345 {Name: UlEvSuccess, Src: []string{UlStReAuditing}, Dst: UlStInSync},
346 {Name: UlEvMismatch, Src: []string{UlStReAuditing}, Dst: UlStResettingMib},
347
348 {Name: UlEvSuccess, Src: []string{UlStResynchronizing}, Dst: UlStInSync},
349 {Name: UlEvDiffsFound, Src: []string{UlStResynchronizing}, Dst: UlStOutOfSync},
350
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000351 {Name: UlEvTimeout, Src: []string{UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000352 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
353 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStStarting},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000354
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000355 {Name: UlEvStop, Src: []string{UlStStarting, UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000356 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
357 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStDisabled},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000358 },
359
360 fsm.Callbacks{
361 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibUploadFsm.LogFsmStateChange(ctx, e) },
362 "enter_" + UlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) },
363 "enter_" + UlStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) },
364 "enter_" + UlStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) },
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000365 "enter_" + UlStGettingVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingVersionState(ctx, e) },
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000366 "enter_" + UlStGettingEquipIDAndOmcc: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipIDAndOmccVersState(ctx, e) },
367 "enter_" + UlStTestingExtOmciSupport: func(e *fsm.Event) { onuDeviceEntry.enterTestingExtOmciSupportState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000368 "enter_" + UlStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) },
369 "enter_" + UlStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) },
370 "enter_" + UlStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) },
371 "enter_" + UlStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) },
372 "enter_" + UlStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) },
373 "enter_" + UlStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) },
374 "enter_" + UlStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) },
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000375 "enter_" + UlStVerifyingAndStoringTPs: func(e *fsm.Event) { onuDeviceEntry.enterVerifyingAndStoringTPsState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000376 "enter_" + UlStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) },
377 "enter_" + UlStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) },
378 "enter_" + UlStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) },
379 "enter_" + UlStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) },
380 "enter_" + UlStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) },
381 "enter_" + UlStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) },
382 },
383 )
384 // Omci related Mib download state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530385 mibDownloadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000386 onuDeviceEntry.PMibDownloadFsm = cmn.NewAdapterFsm("MibDownload", onuDeviceEntry.deviceID, mibDownloadChan)
387 onuDeviceEntry.PMibDownloadFsm.PFsm = fsm.NewFSM(
388 DlStDisabled,
389 fsm.Events{
390
391 {Name: DlEvStart, Src: []string{DlStDisabled}, Dst: DlStStarting},
392
393 {Name: DlEvCreateGal, Src: []string{DlStStarting}, Dst: DlStCreatingGal},
394 {Name: DlEvRxGalResp, Src: []string{DlStCreatingGal}, Dst: DlStSettingOnu2g},
395 {Name: DlEvRxOnu2gResp, Src: []string{DlStSettingOnu2g}, Dst: DlStBridgeInit},
396 // the bridge state is used for multi ME config for alle UNI related ports
397 // maybe such could be reflected in the state machine as well (port number parametrized)
398 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
399 {Name: DlEvRxBridgeResp, Src: []string{DlStBridgeInit}, Dst: DlStDownloaded},
400
401 {Name: DlEvTimeoutSimple, Src: []string{DlStCreatingGal, DlStSettingOnu2g}, Dst: DlStStarting},
402 {Name: DlEvTimeoutBridge, Src: []string{DlStBridgeInit}, Dst: DlStStarting},
403
404 {Name: DlEvReset, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
405 DlStBridgeInit, DlStDownloaded}, Dst: DlStResetting},
406 // exceptional treatment for all states except DlStResetting
407 {Name: DlEvRestart, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
408 DlStBridgeInit, DlStDownloaded, DlStResetting}, Dst: DlStDisabled},
409 },
410
411 fsm.Callbacks{
412 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibDownloadFsm.LogFsmStateChange(ctx, e) },
413 "enter_" + DlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) },
414 "enter_" + DlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) },
415 "enter_" + DlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) },
416 "enter_" + DlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) },
417 "enter_" + DlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) },
418 "enter_" + DlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) },
419 },
420 )
421 if onuDeviceEntry.PMibDownloadFsm == nil || onuDeviceEntry.PMibDownloadFsm.PFsm == nil {
422 logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": onuDeviceEntry.deviceID})
423 // TODO some specific error treatment - or waiting for crash ?
424 }
425
426 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, cBasePathMibTemplateKvStore)
427 if onuDeviceEntry.mibTemplateKVStore == nil {
428 logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service",
429 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": cBasePathMibTemplateKvStore})
430 }
431
432 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
Holger Hildebrandt60652202021-11-02 11:09:36 +0000433 baseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, dh.GetBackendPathPrefix())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000434 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, baseKvStorePath)
435 if onuDeviceEntry.onuKVStore == nil {
436 logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service",
437 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": baseKvStorePath})
438 }
439
440 // Alarm Synchronization Database
441
442 //self._alarm_db = None
443 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
444 return &onuDeviceEntry
445}
446
nikesh.krishnan1249be92023-11-27 04:20:12 +0530447// Start starts (logs) the omci agent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000448func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
449 logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
450 if oo.PDevOmciCC == nil {
451 oo.PDevOmciCC = cmn.NewOmciCC(ctx, oo.deviceID, oo.baseDeviceHandler, oo, oo.baseDeviceHandler.GetOnuAlarmManager(), oo.coreClient)
452 if oo.PDevOmciCC == nil {
453 logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
454 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
455 }
456 }
457 return nil
458}
459
nikesh.krishnan1249be92023-11-27 04:20:12 +0530460// Stop stops/resets the omciCC
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000461func (oo *OnuDeviceEntry) Stop(ctx context.Context, abResetOmciCC bool) error {
462 logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
463 if abResetOmciCC && (oo.PDevOmciCC != nil) {
464 _ = oo.PDevOmciCC.Stop(ctx)
465 }
466 //to allow for all event notifications again when re-using the device and omciCC
467 oo.devState = cmn.DeviceStatusInit
468 return nil
469}
470
471// Reboot - TODO: add comment
472func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error {
473 logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
474 if oo.PDevOmciCC != nil {
475 if err := oo.PDevOmciCC.SendReboot(ctx, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.omciRebootMessageReceivedChannel); err != nil {
476 logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
477 return err
478 }
479 }
480 return nil
481}
482
483// WaitForRebootResponse - TODO: add comment
484func (oo *OnuDeviceEntry) WaitForRebootResponse(ctx context.Context, responseChannel chan cmn.Message) error {
485 select {
486 case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
487 logger.Warnw(ctx, "reboot timeout", log.Fields{"for device-id": oo.deviceID})
488 return fmt.Errorf("rebootTimeout")
489 case data := <-responseChannel:
490 switch data.Data.(cmn.OmciMessage).OmciMsg.MessageType {
491 case omci.RebootResponseType:
492 {
493 msgLayer := (*data.Data.(cmn.OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
494 if msgLayer == nil {
495 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
496 }
497 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
498 if !msgOk {
499 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
500 }
501 logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
502 if msgObj.Result != me.Success {
503 logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
504 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
505 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
506 msgObj.Result, oo.deviceID)
507 }
508 return nil
509 }
510 }
511 logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
512 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
513 }
514}
515
nikesh.krishnan1249be92023-11-27 04:20:12 +0530516// Relay the InSync message via Handler to Rw core - Status update
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000517func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000518 logger.Debugw(ctx, "relaying system-event", log.Fields{"device-id": oo.deviceID, "Event": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000519 // decouple the handler transfer from further processing here
520 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
mgoudad611f4c2025-10-30 14:49:27 +0530521 switch devEvent {
522 case cmn.MibDatabaseSync:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000523 if oo.devState < cmn.MibDatabaseSync { //devState has not been synced yet
524 oo.devState = cmn.MibDatabaseSync
525 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
526 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
527 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000528 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored",
529 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000530 }
mgoudad611f4c2025-10-30 14:49:27 +0530531 case cmn.MibDownloadDone:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000532 if oo.devState < cmn.MibDownloadDone { //devState has not been synced yet
533 oo.devState = cmn.MibDownloadDone
534 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
535 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000536 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored",
537 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000538 }
mgoudad611f4c2025-10-30 14:49:27 +0530539 default:
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000540 logger.Warnw(ctx, "device-event not yet handled",
541 log.Fields{"device-id": oo.deviceID, "state": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542 }
543}
544
545// RestoreDataFromOnuKvStore - TODO: add comment
546func (oo *OnuDeviceEntry) RestoreDataFromOnuKvStore(ctx context.Context) error {
547 if oo.onuKVStore == nil {
548 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530549 return fmt.Errorf("onuKVStore-not-set-abort-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000550 }
551 oo.MutexPersOnuConfig.Lock()
552 defer oo.MutexPersOnuConfig.Unlock()
553 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530554 onuPersistentData{
555 PersTcontMap: make(map[uint16]uint16),
556 PersSerialNumber: "",
557 PersMacAddress: "",
558 PersVendorID: "",
559 PersVersion: "",
560 PersEquipmentID: "",
561 PersActiveSwVersion: "",
562 PersAdminState: "",
563 PersOperState: "",
564 PersUniConfig: make([]uniPersConfig, 0),
565 PersMibAuditInterval: oo.mibAuditInterval,
566 PersAlarmAuditInterval: oo.alarmAuditInterval,
567 PersOnuID: 0,
568 PersIntfID: 0,
569 PersMibLastDbSync: 0,
570 PersIsExtOmciSupported: false,
571 PersUniUnlockDone: false,
572 PersUniDisableDone: false,
573 PersMibDataSyncAdpt: 0,
574 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000575 oo.mutexOnuKVStore.RLock()
576 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
577 oo.mutexOnuKVStore.RUnlock()
578 if err == nil {
579 if Value != nil {
580 logger.Debugw(ctx, "ONU-data read",
581 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
582 tmpBytes, _ := kvstore.ToByte(Value.Value)
583
584 if err = json.Unmarshal(tmpBytes, &oo.SOnuPersistentData); err != nil {
585 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530586 return fmt.Errorf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000587 }
588 logger.Debugw(ctx, "ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
589 "device-id": oo.deviceID})
590 } else {
591 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
592 return fmt.Errorf("no-ONU-data-found")
593 }
594 } else {
595 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530596 return fmt.Errorf("unable-to-read-from-KVstore-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000597 }
598 return nil
599}
600
601// DeleteDataFromOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530602func (oo *OnuDeviceEntry) DeleteDataFromOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000603
604 if oo.onuKVStore == nil {
605 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530606 return errors.New("onu-data delete aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000607 }
Akash Soni840f8d62024-12-11 19:37:06 +0530608 err := oo.deletePersistentData(ctx)
609 if err != nil {
610 logger.Errorf(ctx, "onu-data delete aborted: during kv-access", log.Fields{"device-id": oo.deviceID, "err": err})
611 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000612 }
Akash Soni840f8d62024-12-11 19:37:06 +0530613 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000614}
615
Akash Soni840f8d62024-12-11 19:37:06 +0530616func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000617
618 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000619 oo.MutexPersOnuConfig.Lock()
620 defer oo.MutexPersOnuConfig.Unlock()
621
622 oo.SOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
623 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530624 onuPersistentData{
625 PersTcontMap: make(map[uint16]uint16),
626 PersSerialNumber: "",
627 PersMacAddress: "",
628 PersVendorID: "",
629 PersVersion: "",
630 PersEquipmentID: "",
631 PersActiveSwVersion: "",
632 PersAdminState: "",
633 PersOperState: "",
634 PersUniConfig: make([]uniPersConfig, 0),
635 PersMibAuditInterval: oo.mibAuditInterval,
636 PersAlarmAuditInterval: oo.alarmAuditInterval,
637 PersOnuID: 0,
638 PersIntfID: 0,
639 PersMibLastDbSync: 0,
640 PersIsExtOmciSupported: false,
641 PersUniUnlockDone: false,
642 PersUniDisableDone: false,
643 PersMibDataSyncAdpt: 0,
644 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000645 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
646 oo.mutexOnuKVStore.Lock()
647 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
648 oo.mutexOnuKVStore.Unlock()
649 if err != nil {
650 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530651 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000652 }
Akash Soni840f8d62024-12-11 19:37:06 +0530653 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000654}
655
656// UpdateOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530657func (oo *OnuDeviceEntry) UpdateOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000658
659 if oo.onuKVStore == nil {
660 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530661 return errors.New("onu-data update aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000662 }
Akash Soni840f8d62024-12-11 19:37:06 +0530663 err := oo.storeDataInOnuKvStore(ctx)
664 if err != nil {
665 logger.Errorf(ctx, "onu-data update aborted: during writing process", log.Fields{"device-id": oo.deviceID, "err": err})
666 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000667 }
Akash Soni840f8d62024-12-11 19:37:06 +0530668 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000669}
670
Akash Soni840f8d62024-12-11 19:37:06 +0530671func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000672
673 oo.MutexPersOnuConfig.Lock()
674 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000676 oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
677 if _, exist := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID); !exist {
678 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000679 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
Akash Soni840f8d62024-12-11 19:37:06 +0530680 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000681 }
682 oo.baseDeviceHandler.RLockMutexDeletionInProgressFlag()
683 if oo.baseDeviceHandler.GetDeletionInProgress() {
684 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000685 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
686 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
Akash Soni840f8d62024-12-11 19:37:06 +0530687 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000688 }
689 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
690 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
691
nikesh.krishnan1249be92023-11-27 04:20:12 +0530692 //assign values which are not already present when NewOnuDeviceEntry() is called
693 onuIndication := oo.baseDeviceHandler.GetOnuIndication()
694 if onuIndication != nil {
695 oo.SOnuPersistentData.PersOnuID = onuIndication.OnuId
696 oo.SOnuPersistentData.PersIntfID = onuIndication.IntfId
697 //TODO: verify usage of these values during restart UC
698 oo.SOnuPersistentData.PersAdminState = onuIndication.AdminState
699 oo.SOnuPersistentData.PersOperState = onuIndication.OperState
700 } else {
701 logger.Errorw(ctx, "onuIndication not set, unable to load ONU-data", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530702 return errors.New("onuIndication not set, unable to load ONU-data")
nikesh.krishnan1249be92023-11-27 04:20:12 +0530703 }
704
705 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "SOnuPersistentData": oo.SOnuPersistentData})
706
707 Value, err := json.Marshal(oo.SOnuPersistentData)
708 if err != nil {
709 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
710 "device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530711 return err
nikesh.krishnan1249be92023-11-27 04:20:12 +0530712 }
713
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000714 oo.mutexOnuKVStore.Lock()
715 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
716 oo.mutexOnuKVStore.Unlock()
717 if err != nil {
Akash Soni840f8d62024-12-11 19:37:06 +0530718 logger.Errorf(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
719 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000720 }
Akash Soni840f8d62024-12-11 19:37:06 +0530721 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000722}
723
724// UpdateOnuUniTpPath - TODO: add comment
725func (oo *OnuDeviceEntry) UpdateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
726 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
727 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
728 no specific concurrency protection to SOnuPersistentData is required here
729 */
730 oo.MutexPersOnuConfig.Lock()
731 defer oo.MutexPersOnuConfig.Unlock()
732
733 for k, v := range oo.SOnuPersistentData.PersUniConfig {
734 if v.PersUniID == aUniID {
735 existingPath, ok := oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
736 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
737 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
738 if !ok {
739 logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString})
740 }
741 if existingPath != aPathString {
742 if aPathString == "" {
743 //existing entry to be deleted
744 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
745 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
746 } else {
747 //existing entry to be modified
748 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
749 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
750 }
751 return true
752 }
753 //entry already exists
754 if aPathString == "" {
755 //no active TechProfile
756 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
757 "device-id": oo.deviceID, "uniID": aUniID})
758 } else {
759 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
760 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
761 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
762 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
763 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
764 //no deviceReason update (DeviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
765 // (during which the flows are removed/re-assigned but the techProf is left active)
766 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
767 // (should not be the case, but should not harm or be more robust ...)
768 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
769 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
770 if oo.pOnuTP != nil {
771 oo.pOnuTP.SetProfileToDelete(aUniID, aTpID, false)
772 }
773 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
774 }
775 return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
776 }
777 }
778 //no entry exists for uniId
779
780 if aPathString == "" {
781 //delete request in non-existing state , accept as no change
782 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
783 return false
784 }
785 //new entry to be created
786 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
787 perSubTpPathMap := make(map[uint8]string)
788 perSubTpPathMap[aTpID] = aPathString
789 oo.SOnuPersistentData.PersUniConfig =
790 append(oo.SOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]cmn.UniVlanFlowParams, 0)})
791 return true
792}
793
794// UpdateOnuUniFlowConfig - TODO: add comment
795func (oo *OnuDeviceEntry) UpdateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]cmn.UniVlanFlowParams) {
796
797 oo.MutexPersOnuConfig.Lock()
798 defer oo.MutexPersOnuConfig.Unlock()
799
800 for k, v := range oo.SOnuPersistentData.PersUniConfig {
801 if v.PersUniID == aUniID {
802 oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))
803 copy(oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
804 return
805 }
806 }
807 //flow update was faster than tp-config - create PersUniConfig-entry
808 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
809 // (e.g after flow removal from RemoveUniFlowParams()).
810 // 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
811 // 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
812 // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests
813 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))}
814 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
815 oo.SOnuPersistentData.PersUniConfig = append(oo.SOnuPersistentData.PersUniConfig, tmpConfig)
816}
817
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000818// ResetKvProcessingErrorIndication - TODO: add comment
819func (oo *OnuDeviceEntry) ResetKvProcessingErrorIndication() {
820 oo.mutexOnuKVStoreProcResult.Lock()
821 oo.onuKVStoreProcResult = nil
822 oo.mutexOnuKVStoreProcResult.Unlock()
823}
824
825// GetKvProcessingErrorIndication - TODO: add comment
826func (oo *OnuDeviceEntry) GetKvProcessingErrorIndication() error {
827 oo.mutexOnuKVStoreProcResult.RLock()
828 value := oo.onuKVStoreProcResult
829 oo.mutexOnuKVStoreProcResult.RUnlock()
830 return value
831}
832
Akash Soni840f8d62024-12-11 19:37:06 +0530833// func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
834// oo.mutexOnuKVStoreProcResult.Lock()
835// oo.onuKVStoreProcResult = value
836// oo.mutexOnuKVStoreProcResult.Unlock()
837// }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000838
839// IncrementMibDataSync - TODO: add comment
840func (oo *OnuDeviceEntry) IncrementMibDataSync(ctx context.Context) {
841 oo.MutexPersOnuConfig.Lock()
842 defer oo.MutexPersOnuConfig.Unlock()
843 if oo.SOnuPersistentData.PersMibDataSyncAdpt < 255 {
844 oo.SOnuPersistentData.PersMibDataSyncAdpt++
845 } else {
846 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
847 oo.SOnuPersistentData.PersMibDataSyncAdpt = 1
848 }
849 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.SOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
850}
851
852// ModifySwImageInactiveVersion - updates the inactive SW image version stored
853func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
854 oo.mutexOnuSwImageIndications.Lock()
855 defer oo.mutexOnuSwImageIndications.Unlock()
856 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
857 "device-id": oo.deviceID, "version": aImageVersion})
858 oo.onuSwImageIndications.InActiveEntityEntry.Version = aImageVersion
859 //inactive SW version is not part of persistency data (yet) - no need to update that
860}
861
862// ModifySwImageActiveCommit - updates the active SW commit flag stored
863func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
864 oo.mutexOnuSwImageIndications.Lock()
865 defer oo.mutexOnuSwImageIndications.Unlock()
866 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
867 "device-id": oo.deviceID, "committed": aCommitted})
868 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = aCommitted
869 //commit flag is not part of persistency data (yet) - no need to update that
870}
871
872// GetActiveImageVersion - returns the active SW image version stored
873func (oo *OnuDeviceEntry) GetActiveImageVersion(ctx context.Context) string {
874 oo.mutexOnuSwImageIndications.RLock()
875 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
876 value := oo.onuSwImageIndications.ActiveEntityEntry.Version
877 oo.mutexOnuSwImageIndications.RUnlock()
878 return value
879 }
880 oo.mutexOnuSwImageIndications.RUnlock()
881 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
882 return ""
883}
884
885// GetInactiveImageVersion - TODO: add comment
886func (oo *OnuDeviceEntry) GetInactiveImageVersion(ctx context.Context) string {
887 oo.mutexOnuSwImageIndications.RLock()
888 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
889 value := oo.onuSwImageIndications.InActiveEntityEntry.Version
890 oo.mutexOnuSwImageIndications.RUnlock()
891 return value
892 }
893 oo.mutexOnuSwImageIndications.RUnlock()
894 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
895 return ""
896}
897
898func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
899 oo.MutexPersOnuConfig.RLock()
900 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000901 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.SOnuPersistentData.PersVendorID, oo.SOnuPersistentData.PersVersion,
902 oo.SOnuPersistentData.PersActiveSwVersion)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000903}
904
905// AllocateFreeTcont - TODO: add comment
906func (oo *OnuDeviceEntry) AllocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
907 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
908 "allocated-instances": oo.SOnuPersistentData.PersTcontMap})
909
mpagenko2c3f6c52021-11-23 11:22:10 +0000910 oo.MutexPersOnuConfig.Lock()
911 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000912 if entityID, ok := oo.SOnuPersistentData.PersTcontMap[allocID]; ok {
913 //tcont already allocated before, return the used instance-id
914 return entityID, true, nil
915 }
916 //First allocation of tcont. Find a free instance
917 if tcontInstKeys := oo.pOnuDB.GetSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
918 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
919 for _, instID := range tcontInstKeys {
920 instExist := false
921 //If this instance exist in map, it means it is not empty. It is allocated before
922 for _, v := range oo.SOnuPersistentData.PersTcontMap {
923 if v == instID {
924 instExist = true
925 break
926 }
927 }
928 if !instExist {
929 oo.SOnuPersistentData.PersTcontMap[allocID] = instID
930 return instID, false, nil
931 }
932 }
933 }
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530934 return 0, false, fmt.Errorf("no-free-tcont-left-for-device-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000935}
936
937// FreeTcont - TODO: add comment
938func (oo *OnuDeviceEntry) FreeTcont(ctx context.Context, allocID uint16) {
939 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
mpagenko2c3f6c52021-11-23 11:22:10 +0000940 oo.MutexPersOnuConfig.Lock()
941 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000942 delete(oo.SOnuPersistentData.PersTcontMap, allocID)
943}
944
945// GetDevOmciCC - TODO: add comment
946func (oo *OnuDeviceEntry) GetDevOmciCC() *cmn.OmciCC {
947 return oo.PDevOmciCC
948}
949
950// GetOnuDB - TODO: add comment
951func (oo *OnuDeviceEntry) GetOnuDB() *devdb.OnuDeviceDB {
952 return oo.pOnuDB
953}
954
955// GetPersSerialNumber - TODO: add comment
956func (oo *OnuDeviceEntry) GetPersSerialNumber() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000957 oo.MutexPersOnuConfig.RLock()
958 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 value := oo.SOnuPersistentData.PersSerialNumber
960 return value
961}
962
963// GetPersVendorID - TODO: add comment
964func (oo *OnuDeviceEntry) GetPersVendorID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000965 oo.MutexPersOnuConfig.RLock()
966 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967 value := oo.SOnuPersistentData.PersVendorID
968 return value
969}
970
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000971// GetPersIsExtOmciSupported - TODO: add comment
972func (oo *OnuDeviceEntry) GetPersIsExtOmciSupported() bool {
973 oo.MutexPersOnuConfig.RLock()
974 defer oo.MutexPersOnuConfig.RUnlock()
975 value := oo.SOnuPersistentData.PersIsExtOmciSupported
976 return value
977}
978
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000979// GetPersVersion - TODO: add comment
980func (oo *OnuDeviceEntry) GetPersVersion() string {
981 oo.MutexPersOnuConfig.RLock()
982 defer oo.MutexPersOnuConfig.RUnlock()
983 value := oo.SOnuPersistentData.PersVersion
984 return value
985}
986
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000987// GetPersEquipmentID - TODO: add comment
988func (oo *OnuDeviceEntry) GetPersEquipmentID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000989 oo.MutexPersOnuConfig.RLock()
990 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000991 value := oo.SOnuPersistentData.PersEquipmentID
992 return value
993}
994
995// GetMibUploadFsmCommChan - TODO: add comment
996func (oo *OnuDeviceEntry) GetMibUploadFsmCommChan() chan cmn.Message {
997 return oo.PMibUploadFsm.CommChan
998}
999
1000// GetMibDownloadFsmCommChan - TODO: add comment
1001func (oo *OnuDeviceEntry) GetMibDownloadFsmCommChan() chan cmn.Message {
1002 return oo.PMibDownloadFsm.CommChan
1003}
1004
1005// GetOmciRebootMsgRevChan - TODO: add comment
1006func (oo *OnuDeviceEntry) GetOmciRebootMsgRevChan() chan cmn.Message {
1007 return oo.omciRebootMessageReceivedChannel
1008}
1009
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001010// GetPersActiveSwVersion - TODO: add comment
1011func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string {
mpagenko2c3f6c52021-11-23 11:22:10 +00001012 oo.MutexPersOnuConfig.RLock()
1013 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 return oo.SOnuPersistentData.PersActiveSwVersion
1015}
1016
1017// SetPersActiveSwVersion - TODO: add comment
1018func (oo *OnuDeviceEntry) SetPersActiveSwVersion(value string) {
mpagenko2c3f6c52021-11-23 11:22:10 +00001019 oo.MutexPersOnuConfig.Lock()
1020 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001021 oo.SOnuPersistentData.PersActiveSwVersion = value
1022}
1023
mpagenko101ac942021-11-16 15:01:29 +00001024// setReconcilingFlows - TODO: add comment
1025func (oo *OnuDeviceEntry) setReconcilingFlows(value bool) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001026 oo.mutexReconcilingFlowsFlag.Lock()
1027 oo.reconcilingFlows = value
1028 oo.mutexReconcilingFlowsFlag.Unlock()
1029}
1030
mpagenko101ac942021-11-16 15:01:29 +00001031// SendChReconcilingFlowsFinished - TODO: add comment
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001032func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) {
mpagenko101ac942021-11-16 15:01:29 +00001033 if oo != nil { //if the object still exists (might have been already deleted in background)
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301034 // wait for some time before exiting, as the receiver might not have started and will lead to Mib reset if this signal is missed
1035 expiry := vlanConfigSendChanExpiry * time.Second
mpagenko101ac942021-11-16 15:01:29 +00001036 select {
1037 case oo.chReconcilingFlowsFinished <- value:
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301038 logger.Info(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID})
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301039 case <-time.After(expiry):
1040 logger.Infow(ctx, "reconciling - timer expired, flows finished not sent!", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +00001041 }
1042 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001043}
1044
mpagenko101ac942021-11-16 15:01:29 +00001045// isReconcilingFlows - TODO: add comment
1046func (oo *OnuDeviceEntry) isReconcilingFlows() bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001047 oo.mutexReconcilingFlowsFlag.RLock()
1048 value := oo.reconcilingFlows
1049 oo.mutexReconcilingFlowsFlag.RUnlock()
1050 return value
1051}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001052
1053// PrepareForGarbageCollection - remove references to prepare for garbage collection
1054func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1055 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1056 oo.baseDeviceHandler = nil
1057 oo.pOnuTP = nil
1058 if oo.PDevOmciCC != nil {
1059 oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID)
1060 }
1061 oo.PDevOmciCC = nil
1062}
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001063
nikesh.krishnan1249be92023-11-27 04:20:12 +05301064// SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001065func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) {
1066
1067 oo.MutexPersOnuConfig.RLock()
1068 context := make(map[string]string)
1069 context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10)
1070 context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10)
1071 context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber
1072 oo.MutexPersOnuConfig.RUnlock()
1073
1074 deviceEvent := &voltha.DeviceEvent{
1075 ResourceId: oo.deviceID,
1076 DeviceEventName: aDeviceEventName,
1077 Description: aDescription,
1078 Context: context,
1079 }
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001080 logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": oo.deviceID})
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001081 _ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix())
1082}
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301083
1084// IsMIBTemplateGenerated checks if a MIB Template is already present for this type of ONT.
1085func (oo *OnuDeviceEntry) IsMIBTemplateGenerated(ctx context.Context) bool {
1086
1087 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1088 defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
1089
1090 if _, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); !exist {
1091 logger.Infow(ctx, "MIB template not Generated , further proceed to do MIB sync upload ", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1092 return false
1093 }
1094 return true
1095}