blob: cbeb76dc68c731f1a0f2bc5194bc0d78efb2f732 [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 ..
521 if devEvent == cmn.MibDatabaseSync {
522 if oo.devState < cmn.MibDatabaseSync { //devState has not been synced yet
523 oo.devState = cmn.MibDatabaseSync
524 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
525 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
526 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000527 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored",
528 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000529 }
530 } else if devEvent == cmn.MibDownloadDone {
531 if oo.devState < cmn.MibDownloadDone { //devState has not been synced yet
532 oo.devState = cmn.MibDownloadDone
533 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
534 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000535 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored",
536 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000537 }
538 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000539 logger.Warnw(ctx, "device-event not yet handled",
540 log.Fields{"device-id": oo.deviceID, "state": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000541 }
542}
543
544// RestoreDataFromOnuKvStore - TODO: add comment
545func (oo *OnuDeviceEntry) RestoreDataFromOnuKvStore(ctx context.Context) error {
546 if oo.onuKVStore == nil {
547 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530548 return fmt.Errorf("onuKVStore-not-set-abort-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000549 }
550 oo.MutexPersOnuConfig.Lock()
551 defer oo.MutexPersOnuConfig.Unlock()
552 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530553 onuPersistentData{
554 PersTcontMap: make(map[uint16]uint16),
555 PersSerialNumber: "",
556 PersMacAddress: "",
557 PersVendorID: "",
558 PersVersion: "",
559 PersEquipmentID: "",
560 PersActiveSwVersion: "",
561 PersAdminState: "",
562 PersOperState: "",
563 PersUniConfig: make([]uniPersConfig, 0),
564 PersMibAuditInterval: oo.mibAuditInterval,
565 PersAlarmAuditInterval: oo.alarmAuditInterval,
566 PersOnuID: 0,
567 PersIntfID: 0,
568 PersMibLastDbSync: 0,
569 PersIsExtOmciSupported: false,
570 PersUniUnlockDone: false,
571 PersUniDisableDone: false,
572 PersMibDataSyncAdpt: 0,
573 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000574 oo.mutexOnuKVStore.RLock()
575 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
576 oo.mutexOnuKVStore.RUnlock()
577 if err == nil {
578 if Value != nil {
579 logger.Debugw(ctx, "ONU-data read",
580 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
581 tmpBytes, _ := kvstore.ToByte(Value.Value)
582
583 if err = json.Unmarshal(tmpBytes, &oo.SOnuPersistentData); err != nil {
584 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530585 return fmt.Errorf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000586 }
587 logger.Debugw(ctx, "ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
588 "device-id": oo.deviceID})
589 } else {
590 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
591 return fmt.Errorf("no-ONU-data-found")
592 }
593 } else {
594 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530595 return fmt.Errorf("unable-to-read-from-KVstore-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000596 }
597 return nil
598}
599
600// DeleteDataFromOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530601func (oo *OnuDeviceEntry) DeleteDataFromOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000602
603 if oo.onuKVStore == nil {
604 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530605 return errors.New("onu-data delete aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000606 }
Akash Soni840f8d62024-12-11 19:37:06 +0530607 err := oo.deletePersistentData(ctx)
608 if err != nil {
609 logger.Errorf(ctx, "onu-data delete aborted: during kv-access", log.Fields{"device-id": oo.deviceID, "err": err})
610 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000611 }
Akash Soni840f8d62024-12-11 19:37:06 +0530612 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000613}
614
Akash Soni840f8d62024-12-11 19:37:06 +0530615func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000616
617 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000618 oo.MutexPersOnuConfig.Lock()
619 defer oo.MutexPersOnuConfig.Unlock()
620
621 oo.SOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
622 oo.SOnuPersistentData =
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530623 onuPersistentData{
624 PersTcontMap: make(map[uint16]uint16),
625 PersSerialNumber: "",
626 PersMacAddress: "",
627 PersVendorID: "",
628 PersVersion: "",
629 PersEquipmentID: "",
630 PersActiveSwVersion: "",
631 PersAdminState: "",
632 PersOperState: "",
633 PersUniConfig: make([]uniPersConfig, 0),
634 PersMibAuditInterval: oo.mibAuditInterval,
635 PersAlarmAuditInterval: oo.alarmAuditInterval,
636 PersOnuID: 0,
637 PersIntfID: 0,
638 PersMibLastDbSync: 0,
639 PersIsExtOmciSupported: false,
640 PersUniUnlockDone: false,
641 PersUniDisableDone: false,
642 PersMibDataSyncAdpt: 0,
643 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000644 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
645 oo.mutexOnuKVStore.Lock()
646 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
647 oo.mutexOnuKVStore.Unlock()
648 if err != nil {
649 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530650 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000651 }
Akash Soni840f8d62024-12-11 19:37:06 +0530652 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000653}
654
655// UpdateOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530656func (oo *OnuDeviceEntry) UpdateOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000657
658 if oo.onuKVStore == nil {
659 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530660 return errors.New("onu-data update aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661 }
Akash Soni840f8d62024-12-11 19:37:06 +0530662 err := oo.storeDataInOnuKvStore(ctx)
663 if err != nil {
664 logger.Errorf(ctx, "onu-data update aborted: during writing process", log.Fields{"device-id": oo.deviceID, "err": err})
665 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000666 }
Akash Soni840f8d62024-12-11 19:37:06 +0530667 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000668}
669
Akash Soni840f8d62024-12-11 19:37:06 +0530670func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000671
672 oo.MutexPersOnuConfig.Lock()
673 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000674
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675 oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
676 if _, exist := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID); !exist {
677 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000678 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
Akash Soni840f8d62024-12-11 19:37:06 +0530679 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000680 }
681 oo.baseDeviceHandler.RLockMutexDeletionInProgressFlag()
682 if oo.baseDeviceHandler.GetDeletionInProgress() {
683 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000684 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
685 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
Akash Soni840f8d62024-12-11 19:37:06 +0530686 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000687 }
688 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
689 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
690
nikesh.krishnan1249be92023-11-27 04:20:12 +0530691 //assign values which are not already present when NewOnuDeviceEntry() is called
692 onuIndication := oo.baseDeviceHandler.GetOnuIndication()
693 if onuIndication != nil {
694 oo.SOnuPersistentData.PersOnuID = onuIndication.OnuId
695 oo.SOnuPersistentData.PersIntfID = onuIndication.IntfId
696 //TODO: verify usage of these values during restart UC
697 oo.SOnuPersistentData.PersAdminState = onuIndication.AdminState
698 oo.SOnuPersistentData.PersOperState = onuIndication.OperState
699 } else {
700 logger.Errorw(ctx, "onuIndication not set, unable to load ONU-data", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530701 return errors.New("onuIndication not set, unable to load ONU-data")
nikesh.krishnan1249be92023-11-27 04:20:12 +0530702 }
703
704 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "SOnuPersistentData": oo.SOnuPersistentData})
705
706 Value, err := json.Marshal(oo.SOnuPersistentData)
707 if err != nil {
708 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
709 "device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530710 return err
nikesh.krishnan1249be92023-11-27 04:20:12 +0530711 }
712
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000713 oo.mutexOnuKVStore.Lock()
714 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
715 oo.mutexOnuKVStore.Unlock()
716 if err != nil {
Akash Soni840f8d62024-12-11 19:37:06 +0530717 logger.Errorf(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
718 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000719 }
Akash Soni840f8d62024-12-11 19:37:06 +0530720 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000721}
722
723// UpdateOnuUniTpPath - TODO: add comment
724func (oo *OnuDeviceEntry) UpdateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
725 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
726 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
727 no specific concurrency protection to SOnuPersistentData is required here
728 */
729 oo.MutexPersOnuConfig.Lock()
730 defer oo.MutexPersOnuConfig.Unlock()
731
732 for k, v := range oo.SOnuPersistentData.PersUniConfig {
733 if v.PersUniID == aUniID {
734 existingPath, ok := oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
735 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
736 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
737 if !ok {
738 logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString})
739 }
740 if existingPath != aPathString {
741 if aPathString == "" {
742 //existing entry to be deleted
743 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
744 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
745 } else {
746 //existing entry to be modified
747 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
748 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
749 }
750 return true
751 }
752 //entry already exists
753 if aPathString == "" {
754 //no active TechProfile
755 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
756 "device-id": oo.deviceID, "uniID": aUniID})
757 } else {
758 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
759 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
760 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
761 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
762 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
763 //no deviceReason update (DeviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
764 // (during which the flows are removed/re-assigned but the techProf is left active)
765 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
766 // (should not be the case, but should not harm or be more robust ...)
767 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
768 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
769 if oo.pOnuTP != nil {
770 oo.pOnuTP.SetProfileToDelete(aUniID, aTpID, false)
771 }
772 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
773 }
774 return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
775 }
776 }
777 //no entry exists for uniId
778
779 if aPathString == "" {
780 //delete request in non-existing state , accept as no change
781 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
782 return false
783 }
784 //new entry to be created
785 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
786 perSubTpPathMap := make(map[uint8]string)
787 perSubTpPathMap[aTpID] = aPathString
788 oo.SOnuPersistentData.PersUniConfig =
789 append(oo.SOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]cmn.UniVlanFlowParams, 0)})
790 return true
791}
792
793// UpdateOnuUniFlowConfig - TODO: add comment
794func (oo *OnuDeviceEntry) UpdateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]cmn.UniVlanFlowParams) {
795
796 oo.MutexPersOnuConfig.Lock()
797 defer oo.MutexPersOnuConfig.Unlock()
798
799 for k, v := range oo.SOnuPersistentData.PersUniConfig {
800 if v.PersUniID == aUniID {
801 oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))
802 copy(oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
803 return
804 }
805 }
806 //flow update was faster than tp-config - create PersUniConfig-entry
807 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
808 // (e.g after flow removal from RemoveUniFlowParams()).
809 // 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
810 // 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
811 // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests
812 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))}
813 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
814 oo.SOnuPersistentData.PersUniConfig = append(oo.SOnuPersistentData.PersUniConfig, tmpConfig)
815}
816
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000817// ResetKvProcessingErrorIndication - TODO: add comment
818func (oo *OnuDeviceEntry) ResetKvProcessingErrorIndication() {
819 oo.mutexOnuKVStoreProcResult.Lock()
820 oo.onuKVStoreProcResult = nil
821 oo.mutexOnuKVStoreProcResult.Unlock()
822}
823
824// GetKvProcessingErrorIndication - TODO: add comment
825func (oo *OnuDeviceEntry) GetKvProcessingErrorIndication() error {
826 oo.mutexOnuKVStoreProcResult.RLock()
827 value := oo.onuKVStoreProcResult
828 oo.mutexOnuKVStoreProcResult.RUnlock()
829 return value
830}
831
Akash Soni840f8d62024-12-11 19:37:06 +0530832// func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
833// oo.mutexOnuKVStoreProcResult.Lock()
834// oo.onuKVStoreProcResult = value
835// oo.mutexOnuKVStoreProcResult.Unlock()
836// }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837
838// IncrementMibDataSync - TODO: add comment
839func (oo *OnuDeviceEntry) IncrementMibDataSync(ctx context.Context) {
840 oo.MutexPersOnuConfig.Lock()
841 defer oo.MutexPersOnuConfig.Unlock()
842 if oo.SOnuPersistentData.PersMibDataSyncAdpt < 255 {
843 oo.SOnuPersistentData.PersMibDataSyncAdpt++
844 } else {
845 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
846 oo.SOnuPersistentData.PersMibDataSyncAdpt = 1
847 }
848 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.SOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
849}
850
851// ModifySwImageInactiveVersion - updates the inactive SW image version stored
852func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
853 oo.mutexOnuSwImageIndications.Lock()
854 defer oo.mutexOnuSwImageIndications.Unlock()
855 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
856 "device-id": oo.deviceID, "version": aImageVersion})
857 oo.onuSwImageIndications.InActiveEntityEntry.Version = aImageVersion
858 //inactive SW version is not part of persistency data (yet) - no need to update that
859}
860
861// ModifySwImageActiveCommit - updates the active SW commit flag stored
862func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
863 oo.mutexOnuSwImageIndications.Lock()
864 defer oo.mutexOnuSwImageIndications.Unlock()
865 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
866 "device-id": oo.deviceID, "committed": aCommitted})
867 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = aCommitted
868 //commit flag is not part of persistency data (yet) - no need to update that
869}
870
871// GetActiveImageVersion - returns the active SW image version stored
872func (oo *OnuDeviceEntry) GetActiveImageVersion(ctx context.Context) string {
873 oo.mutexOnuSwImageIndications.RLock()
874 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
875 value := oo.onuSwImageIndications.ActiveEntityEntry.Version
876 oo.mutexOnuSwImageIndications.RUnlock()
877 return value
878 }
879 oo.mutexOnuSwImageIndications.RUnlock()
880 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
881 return ""
882}
883
884// GetInactiveImageVersion - TODO: add comment
885func (oo *OnuDeviceEntry) GetInactiveImageVersion(ctx context.Context) string {
886 oo.mutexOnuSwImageIndications.RLock()
887 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
888 value := oo.onuSwImageIndications.InActiveEntityEntry.Version
889 oo.mutexOnuSwImageIndications.RUnlock()
890 return value
891 }
892 oo.mutexOnuSwImageIndications.RUnlock()
893 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
894 return ""
895}
896
897func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
898 oo.MutexPersOnuConfig.RLock()
899 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000900 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.SOnuPersistentData.PersVendorID, oo.SOnuPersistentData.PersVersion,
901 oo.SOnuPersistentData.PersActiveSwVersion)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000902}
903
904// AllocateFreeTcont - TODO: add comment
905func (oo *OnuDeviceEntry) AllocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
906 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
907 "allocated-instances": oo.SOnuPersistentData.PersTcontMap})
908
mpagenko2c3f6c52021-11-23 11:22:10 +0000909 oo.MutexPersOnuConfig.Lock()
910 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000911 if entityID, ok := oo.SOnuPersistentData.PersTcontMap[allocID]; ok {
912 //tcont already allocated before, return the used instance-id
913 return entityID, true, nil
914 }
915 //First allocation of tcont. Find a free instance
916 if tcontInstKeys := oo.pOnuDB.GetSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
917 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
918 for _, instID := range tcontInstKeys {
919 instExist := false
920 //If this instance exist in map, it means it is not empty. It is allocated before
921 for _, v := range oo.SOnuPersistentData.PersTcontMap {
922 if v == instID {
923 instExist = true
924 break
925 }
926 }
927 if !instExist {
928 oo.SOnuPersistentData.PersTcontMap[allocID] = instID
929 return instID, false, nil
930 }
931 }
932 }
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530933 return 0, false, fmt.Errorf("no-free-tcont-left-for-device-%s", oo.deviceID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000934}
935
936// FreeTcont - TODO: add comment
937func (oo *OnuDeviceEntry) FreeTcont(ctx context.Context, allocID uint16) {
938 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
mpagenko2c3f6c52021-11-23 11:22:10 +0000939 oo.MutexPersOnuConfig.Lock()
940 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000941 delete(oo.SOnuPersistentData.PersTcontMap, allocID)
942}
943
944// GetDevOmciCC - TODO: add comment
945func (oo *OnuDeviceEntry) GetDevOmciCC() *cmn.OmciCC {
946 return oo.PDevOmciCC
947}
948
949// GetOnuDB - TODO: add comment
950func (oo *OnuDeviceEntry) GetOnuDB() *devdb.OnuDeviceDB {
951 return oo.pOnuDB
952}
953
954// GetPersSerialNumber - TODO: add comment
955func (oo *OnuDeviceEntry) GetPersSerialNumber() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000956 oo.MutexPersOnuConfig.RLock()
957 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000958 value := oo.SOnuPersistentData.PersSerialNumber
959 return value
960}
961
962// GetPersVendorID - TODO: add comment
963func (oo *OnuDeviceEntry) GetPersVendorID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000964 oo.MutexPersOnuConfig.RLock()
965 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000966 value := oo.SOnuPersistentData.PersVendorID
967 return value
968}
969
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000970// GetPersIsExtOmciSupported - TODO: add comment
971func (oo *OnuDeviceEntry) GetPersIsExtOmciSupported() bool {
972 oo.MutexPersOnuConfig.RLock()
973 defer oo.MutexPersOnuConfig.RUnlock()
974 value := oo.SOnuPersistentData.PersIsExtOmciSupported
975 return value
976}
977
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000978// GetPersVersion - TODO: add comment
979func (oo *OnuDeviceEntry) GetPersVersion() string {
980 oo.MutexPersOnuConfig.RLock()
981 defer oo.MutexPersOnuConfig.RUnlock()
982 value := oo.SOnuPersistentData.PersVersion
983 return value
984}
985
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000986// GetPersEquipmentID - TODO: add comment
987func (oo *OnuDeviceEntry) GetPersEquipmentID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000988 oo.MutexPersOnuConfig.RLock()
989 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000990 value := oo.SOnuPersistentData.PersEquipmentID
991 return value
992}
993
994// GetMibUploadFsmCommChan - TODO: add comment
995func (oo *OnuDeviceEntry) GetMibUploadFsmCommChan() chan cmn.Message {
996 return oo.PMibUploadFsm.CommChan
997}
998
999// GetMibDownloadFsmCommChan - TODO: add comment
1000func (oo *OnuDeviceEntry) GetMibDownloadFsmCommChan() chan cmn.Message {
1001 return oo.PMibDownloadFsm.CommChan
1002}
1003
1004// GetOmciRebootMsgRevChan - TODO: add comment
1005func (oo *OnuDeviceEntry) GetOmciRebootMsgRevChan() chan cmn.Message {
1006 return oo.omciRebootMessageReceivedChannel
1007}
1008
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001009// GetPersActiveSwVersion - TODO: add comment
1010func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string {
mpagenko2c3f6c52021-11-23 11:22:10 +00001011 oo.MutexPersOnuConfig.RLock()
1012 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013 return oo.SOnuPersistentData.PersActiveSwVersion
1014}
1015
1016// SetPersActiveSwVersion - TODO: add comment
1017func (oo *OnuDeviceEntry) SetPersActiveSwVersion(value string) {
mpagenko2c3f6c52021-11-23 11:22:10 +00001018 oo.MutexPersOnuConfig.Lock()
1019 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001020 oo.SOnuPersistentData.PersActiveSwVersion = value
1021}
1022
mpagenko101ac942021-11-16 15:01:29 +00001023// setReconcilingFlows - TODO: add comment
1024func (oo *OnuDeviceEntry) setReconcilingFlows(value bool) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001025 oo.mutexReconcilingFlowsFlag.Lock()
1026 oo.reconcilingFlows = value
1027 oo.mutexReconcilingFlowsFlag.Unlock()
1028}
1029
mpagenko101ac942021-11-16 15:01:29 +00001030// SendChReconcilingFlowsFinished - TODO: add comment
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001031func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) {
mpagenko101ac942021-11-16 15:01:29 +00001032 if oo != nil { //if the object still exists (might have been already deleted in background)
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301033 // wait for some time before exiting, as the receiver might not have started and will lead to Mib reset if this signal is missed
1034 expiry := vlanConfigSendChanExpiry * time.Second
mpagenko101ac942021-11-16 15:01:29 +00001035 select {
1036 case oo.chReconcilingFlowsFinished <- value:
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301037 logger.Info(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID})
Sridhar Ravindra27afb582025-02-10 13:18:11 +05301038 case <-time.After(expiry):
1039 logger.Infow(ctx, "reconciling - timer expired, flows finished not sent!", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +00001040 }
1041 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001042}
1043
mpagenko101ac942021-11-16 15:01:29 +00001044// isReconcilingFlows - TODO: add comment
1045func (oo *OnuDeviceEntry) isReconcilingFlows() bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001046 oo.mutexReconcilingFlowsFlag.RLock()
1047 value := oo.reconcilingFlows
1048 oo.mutexReconcilingFlowsFlag.RUnlock()
1049 return value
1050}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001051
1052// PrepareForGarbageCollection - remove references to prepare for garbage collection
1053func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1054 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1055 oo.baseDeviceHandler = nil
1056 oo.pOnuTP = nil
1057 if oo.PDevOmciCC != nil {
1058 oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID)
1059 }
1060 oo.PDevOmciCC = nil
1061}
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001062
nikesh.krishnan1249be92023-11-27 04:20:12 +05301063// SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001064func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) {
1065
1066 oo.MutexPersOnuConfig.RLock()
1067 context := make(map[string]string)
1068 context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10)
1069 context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10)
1070 context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber
1071 oo.MutexPersOnuConfig.RUnlock()
1072
1073 deviceEvent := &voltha.DeviceEvent{
1074 ResourceId: oo.deviceID,
1075 DeviceEventName: aDeviceEventName,
1076 Description: aDescription,
1077 Context: context,
1078 }
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001079 logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": oo.deviceID})
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001080 _ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix())
1081}
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301082
1083// IsMIBTemplateGenerated checks if a MIB Template is already present for this type of ONT.
1084func (oo *OnuDeviceEntry) IsMIBTemplateGenerated(ctx context.Context) bool {
1085
1086 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1087 defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
1088
1089 if _, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); !exist {
1090 logger.Infow(ctx, "MIB template not Generated , further proceed to do MIB sync upload ", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1091 return false
1092 }
1093 return true
1094}