blob: 108a7069492a00531e424c49a498e17748c34a8e [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 {
141 PersUniID uint8 `json:"uni_id"`
142 PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map
143 PersFlowParams []cmn.UniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go
144}
145
146type onuPersistentData struct {
147 PersOnuID uint32 `json:"onu_id"`
148 PersIntfID uint32 `json:"intf_id"`
149 PersSerialNumber string `json:"serial_number"`
150 PersMacAddress string `json:"mac_address"`
151 PersVendorID string `json:"vendor_id"`
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000152 PersVersion string `json:"version"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000153 PersEquipmentID string `json:"equipment_id"`
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000154 PersIsExtOmciSupported bool `json:"is_ext_omci_supported"`
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000155 PersActiveSwVersion string `json:"active_sw_version"`
156 PersAdminState string `json:"admin_state"`
157 PersOperState string `json:"oper_state"`
158 PersUniUnlockDone bool `json:"uni_unlock_done"`
159 PersUniDisableDone bool `json:"uni_disable_done"`
160 PersMibAuditInterval time.Duration `json:"mib_audit_interval"`
161 PersMibLastDbSync uint32 `json:"mib_last_db_sync"`
162 PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"`
163 PersUniConfig []uniPersConfig `json:"uni_config"`
164 PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"`
165 PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map
166}
167
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000168//type UniTpidInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
169
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000170// OnuDeviceEntry - ONU device info and FSM events.
171type OnuDeviceEntry struct {
172 deviceID string
173 baseDeviceHandler cmn.IdeviceHandler
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000174 eventProxy eventif.EventProxy
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000175 pOpenOnuAc cmn.IopenONUAC
176 pOnuTP cmn.IonuUniTechProf
177 coreClient *vgrpc.Client
178 PDevOmciCC *cmn.OmciCC
179 pOnuDB *devdb.OnuDeviceDB
180 mibTemplateKVStore *db.Backend
181 MutexPersOnuConfig sync.RWMutex
182 SOnuPersistentData onuPersistentData
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000183 ReconciledTpInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage
184 MutexReconciledTpInstances sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000185 reconcilingFlows bool
186 mutexReconcilingFlowsFlag sync.RWMutex
187 chReconcilingFlowsFinished chan bool //channel to indicate that reconciling of flows has been finished
188 mibTemplatePath string
189 mutexOnuKVStore sync.RWMutex
190 onuKVStore *db.Backend
191 onuKVStorePath string
192 mutexOnuKVStoreProcResult sync.RWMutex
193 onuKVStoreProcResult error //error indication of processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000194 mutexOnuSwImageIndications sync.RWMutex
195 onuSwImageIndications cmn.SswImageIndications
196 MutexOnuImageStatus sync.RWMutex
197 POnuImageStatus *swupg.OnuImageStatus
198 //lockDeviceEntries sync.RWMutex
199 mibDbClass func(context.Context) error
200 supportedFsms cmn.OmciDeviceFsms
201 devState cmn.OnuDeviceEvent
202 // Audit and MDS
203 mibAuditInterval time.Duration
204 alarmAuditInterval time.Duration
205 // TODO: periodical mib resync will be implemented with story VOL-3792
206 //mibNextDbResync uint32
207
208 // for mibUpload
Girish Gowdra37c9d912022-02-08 16:24:57 -0800209 PMibUploadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
210 mutexLastTxParamStruct sync.RWMutex
211 lastTxParamStruct sLastTxMeParameter
212 mibSyncMsgProcessorRunning bool
213 mutexMibSyncMsgProcessorRunning sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000214 // for mibDownload
215 PMibDownloadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later
216 //remark: general usage of pAdapterFsm would require generalization of CommChan usage and internal event setting
217 // within the FSM event procedures
218 mutexPLastTxMeInstance sync.RWMutex
219 pLastTxMeInstance *me.ManagedEntity
220 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
221 omciRebootMessageReceivedChannel chan cmn.Message // channel needed by reboot request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000222}
223
nikesh.krishnan1249be92023-11-27 04:20:12 +0530224// NewOnuDeviceEntry returns a new instance of a OnuDeviceEntry
225// mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000226func NewOnuDeviceEntry(ctx context.Context, cc *vgrpc.Client, dh cmn.IdeviceHandler,
227 openonu cmn.IopenONUAC) *OnuDeviceEntry {
228 var onuDeviceEntry OnuDeviceEntry
229 onuDeviceEntry.deviceID = dh.GetDeviceID()
230 logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": onuDeviceEntry.deviceID})
231 onuDeviceEntry.baseDeviceHandler = dh
Holger Hildebrandtc56febd2022-02-09 13:23:30 +0000232 onuDeviceEntry.eventProxy = dh.GetEventProxy()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000233 onuDeviceEntry.pOpenOnuAc = openonu
234 onuDeviceEntry.coreClient = cc
235 onuDeviceEntry.devState = cmn.DeviceStatusInit
236 onuDeviceEntry.SOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
237 onuDeviceEntry.SOnuPersistentData.PersTcontMap = make(map[uint16]uint16)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000238 onuDeviceEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000239 onuDeviceEntry.chReconcilingFlowsFinished = make(chan bool)
240 onuDeviceEntry.reconcilingFlows = false
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530241 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000242 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
243 //OMCI related databases are on a per-agent basis. State machines and tasks
244 //are per ONU Vendor
245 //
246 // MIB Synchronization Database - possible overloading from arguments
247 supportedFsms := onuDeviceEntry.pOpenOnuAc.GetSupportedFsms()
248 if supportedFsms != nil {
249 onuDeviceEntry.supportedFsms = *supportedFsms
250 } else {
251 // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only!
252 //var mibSyncFsm = NewMibSynchronizer()
253 // use some internal defaults, if not defined from outside
254 onuDeviceEntry.supportedFsms = cmn.OmciDeviceFsms{
255 "mib-synchronizer": {
256 //mibSyncFsm, // Implements the MIB synchronization state machine
257 DatabaseClass: onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
258 //true, // Advertise events on OpenOMCI event bus
259 AuditInterval: dh.GetAlarmAuditInterval(), // Time to wait between MIB audits. 0 to disable audits.
260 // map[string]func() error{
261 // "mib-upload": onuDeviceEntry.MibUploadTask,
262 // "mib-template": onuDeviceEntry.MibTemplateTask,
263 // "get-mds": onuDeviceEntry.GetMdsTask,
264 // "mib-audit": onuDeviceEntry.GetMdsTask,
265 // "mib-resync": onuDeviceEntry.MibResyncTask,
266 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
267 // },
268 },
269 }
270 }
271 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].DatabaseClass
272 logger.Debug(ctx, "access2mibDbClass")
273 go onuDeviceEntry.mibDbClass(ctx)
274 if !dh.IsReconciling() {
275 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].AuditInterval
276 onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval
277 onuDeviceEntry.alarmAuditInterval = dh.GetAlarmAuditInterval()
278 onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval
279 } else {
280 logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": onuDeviceEntry.deviceID})
281 // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of
282 // vendor- or deviceID-specific configurations via voltctl-commands
283 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval
284 onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval
285 }
286 logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval,
287 "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval})
288 // TODO: periodical mib resync will be implemented with story VOL-3792
289 //onuDeviceEntry.mibNextDbResync = 0
290
291 // Omci related Mib upload sync state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530292 mibUploadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000293 onuDeviceEntry.PMibUploadFsm = cmn.NewAdapterFsm("MibUpload", onuDeviceEntry.deviceID, mibUploadChan)
294 onuDeviceEntry.PMibUploadFsm.PFsm = fsm.NewFSM(
295 UlStDisabled,
296 fsm.Events{
297
298 {Name: UlEvStart, Src: []string{UlStDisabled}, Dst: UlStStarting},
299
300 {Name: UlEvResetMib, Src: []string{UlStStarting}, Dst: UlStResettingMib},
301 {Name: UlEvGetVendorAndSerial, Src: []string{UlStResettingMib}, Dst: UlStGettingVendorAndSerial},
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000302 {Name: UlEvGetVersion, Src: []string{UlStGettingVendorAndSerial}, Dst: UlStGettingVersion},
303 {Name: UlEvGetEquipIDAndOmcc, Src: []string{UlStGettingVersion}, Dst: UlStGettingEquipIDAndOmcc},
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000304 {Name: UlEvTestExtOmciSupport, Src: []string{UlStGettingEquipIDAndOmcc}, Dst: UlStTestingExtOmciSupport},
305 {Name: UlEvGetFirstSwVersion, Src: []string{UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport}, Dst: UlStGettingFirstSwVersion},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000306 {Name: UlEvGetSecondSwVersion, Src: []string{UlStGettingFirstSwVersion}, Dst: UlStGettingSecondSwVersion},
307 {Name: UlEvGetMacAddress, Src: []string{UlStGettingSecondSwVersion}, Dst: UlStGettingMacAddress},
308 {Name: UlEvGetMibTemplate, Src: []string{UlStGettingMacAddress}, Dst: UlStGettingMibTemplate},
309
310 {Name: UlEvUploadMib, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploading},
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000311
312 {Name: UlEvVerifyAndStoreTPs, Src: []string{UlStStarting}, Dst: UlStVerifyingAndStoringTPs},
313 {Name: UlEvSuccess, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStExaminingMds},
314 {Name: UlEvMismatch, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStResettingMib},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315
316 {Name: UlEvSuccess, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploadDone},
317 {Name: UlEvSuccess, Src: []string{UlStUploading}, Dst: UlStUploadDone},
318
319 {Name: UlEvSuccess, Src: []string{UlStUploadDone}, Dst: UlStInSync},
320 //{Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStInSync},
321 {Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStExaminingMdsSuccess},
322 // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers
323 // mib-reset and new provisioning at this point
324 //{Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResynchronizing},
325 {Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResettingMib},
326
327 {Name: UlEvSuccess, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStInSync},
328 {Name: UlEvMismatch, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStResettingMib},
329
330 {Name: UlEvAuditMib, Src: []string{UlStInSync}, Dst: UlStAuditing},
331
332 {Name: UlEvSuccess, Src: []string{UlStOutOfSync}, Dst: UlStInSync},
333 {Name: UlEvAuditMib, Src: []string{UlStOutOfSync}, Dst: UlStAuditing},
334
335 {Name: UlEvSuccess, Src: []string{UlStAuditing}, Dst: UlStInSync},
336 {Name: UlEvMismatch, Src: []string{UlStAuditing}, Dst: UlStReAuditing},
337 {Name: UlEvForceResync, Src: []string{UlStAuditing}, Dst: UlStResynchronizing},
338
339 {Name: UlEvSuccess, Src: []string{UlStReAuditing}, Dst: UlStInSync},
340 {Name: UlEvMismatch, Src: []string{UlStReAuditing}, Dst: UlStResettingMib},
341
342 {Name: UlEvSuccess, Src: []string{UlStResynchronizing}, Dst: UlStInSync},
343 {Name: UlEvDiffsFound, Src: []string{UlStResynchronizing}, Dst: UlStOutOfSync},
344
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000345 {Name: UlEvTimeout, Src: []string{UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000346 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
347 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStStarting},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000348
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000349 {Name: UlEvStop, Src: []string{UlStStarting, UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport,
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000350 UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing,
351 UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStDisabled},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000352 },
353
354 fsm.Callbacks{
355 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibUploadFsm.LogFsmStateChange(ctx, e) },
356 "enter_" + UlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) },
357 "enter_" + UlStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) },
358 "enter_" + UlStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) },
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000359 "enter_" + UlStGettingVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingVersionState(ctx, e) },
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000360 "enter_" + UlStGettingEquipIDAndOmcc: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipIDAndOmccVersState(ctx, e) },
361 "enter_" + UlStTestingExtOmciSupport: func(e *fsm.Event) { onuDeviceEntry.enterTestingExtOmciSupportState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000362 "enter_" + UlStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) },
363 "enter_" + UlStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) },
364 "enter_" + UlStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) },
365 "enter_" + UlStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) },
366 "enter_" + UlStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) },
367 "enter_" + UlStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) },
368 "enter_" + UlStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) },
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000369 "enter_" + UlStVerifyingAndStoringTPs: func(e *fsm.Event) { onuDeviceEntry.enterVerifyingAndStoringTPsState(ctx, e) },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000370 "enter_" + UlStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) },
371 "enter_" + UlStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) },
372 "enter_" + UlStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) },
373 "enter_" + UlStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) },
374 "enter_" + UlStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) },
375 "enter_" + UlStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) },
376 },
377 )
378 // Omci related Mib download state machine
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530379 mibDownloadChan := make(chan cmn.Message, 2)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000380 onuDeviceEntry.PMibDownloadFsm = cmn.NewAdapterFsm("MibDownload", onuDeviceEntry.deviceID, mibDownloadChan)
381 onuDeviceEntry.PMibDownloadFsm.PFsm = fsm.NewFSM(
382 DlStDisabled,
383 fsm.Events{
384
385 {Name: DlEvStart, Src: []string{DlStDisabled}, Dst: DlStStarting},
386
387 {Name: DlEvCreateGal, Src: []string{DlStStarting}, Dst: DlStCreatingGal},
388 {Name: DlEvRxGalResp, Src: []string{DlStCreatingGal}, Dst: DlStSettingOnu2g},
389 {Name: DlEvRxOnu2gResp, Src: []string{DlStSettingOnu2g}, Dst: DlStBridgeInit},
390 // the bridge state is used for multi ME config for alle UNI related ports
391 // maybe such could be reflected in the state machine as well (port number parametrized)
392 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
393 {Name: DlEvRxBridgeResp, Src: []string{DlStBridgeInit}, Dst: DlStDownloaded},
394
395 {Name: DlEvTimeoutSimple, Src: []string{DlStCreatingGal, DlStSettingOnu2g}, Dst: DlStStarting},
396 {Name: DlEvTimeoutBridge, Src: []string{DlStBridgeInit}, Dst: DlStStarting},
397
398 {Name: DlEvReset, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
399 DlStBridgeInit, DlStDownloaded}, Dst: DlStResetting},
400 // exceptional treatment for all states except DlStResetting
401 {Name: DlEvRestart, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g,
402 DlStBridgeInit, DlStDownloaded, DlStResetting}, Dst: DlStDisabled},
403 },
404
405 fsm.Callbacks{
406 "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibDownloadFsm.LogFsmStateChange(ctx, e) },
407 "enter_" + DlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) },
408 "enter_" + DlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) },
409 "enter_" + DlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) },
410 "enter_" + DlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) },
411 "enter_" + DlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) },
412 "enter_" + DlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) },
413 },
414 )
415 if onuDeviceEntry.PMibDownloadFsm == nil || onuDeviceEntry.PMibDownloadFsm.PFsm == nil {
416 logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": onuDeviceEntry.deviceID})
417 // TODO some specific error treatment - or waiting for crash ?
418 }
419
420 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, cBasePathMibTemplateKvStore)
421 if onuDeviceEntry.mibTemplateKVStore == nil {
422 logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service",
423 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": cBasePathMibTemplateKvStore})
424 }
425
426 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
Holger Hildebrandt60652202021-11-02 11:09:36 +0000427 baseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, dh.GetBackendPathPrefix())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000428 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, baseKvStorePath)
429 if onuDeviceEntry.onuKVStore == nil {
430 logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service",
431 log.Fields{"device-id": onuDeviceEntry.deviceID, "service": baseKvStorePath})
432 }
433
434 // Alarm Synchronization Database
435
436 //self._alarm_db = None
437 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
438 return &onuDeviceEntry
439}
440
nikesh.krishnan1249be92023-11-27 04:20:12 +0530441// Start starts (logs) the omci agent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000442func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
443 logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
444 if oo.PDevOmciCC == nil {
445 oo.PDevOmciCC = cmn.NewOmciCC(ctx, oo.deviceID, oo.baseDeviceHandler, oo, oo.baseDeviceHandler.GetOnuAlarmManager(), oo.coreClient)
446 if oo.PDevOmciCC == nil {
447 logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
448 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
449 }
450 }
451 return nil
452}
453
nikesh.krishnan1249be92023-11-27 04:20:12 +0530454// Stop stops/resets the omciCC
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000455func (oo *OnuDeviceEntry) Stop(ctx context.Context, abResetOmciCC bool) error {
456 logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
457 if abResetOmciCC && (oo.PDevOmciCC != nil) {
458 _ = oo.PDevOmciCC.Stop(ctx)
459 }
460 //to allow for all event notifications again when re-using the device and omciCC
461 oo.devState = cmn.DeviceStatusInit
462 return nil
463}
464
465// Reboot - TODO: add comment
466func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error {
467 logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
468 if oo.PDevOmciCC != nil {
469 if err := oo.PDevOmciCC.SendReboot(ctx, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.omciRebootMessageReceivedChannel); err != nil {
470 logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
471 return err
472 }
473 }
474 return nil
475}
476
477// WaitForRebootResponse - TODO: add comment
478func (oo *OnuDeviceEntry) WaitForRebootResponse(ctx context.Context, responseChannel chan cmn.Message) error {
479 select {
480 case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
481 logger.Warnw(ctx, "reboot timeout", log.Fields{"for device-id": oo.deviceID})
482 return fmt.Errorf("rebootTimeout")
483 case data := <-responseChannel:
484 switch data.Data.(cmn.OmciMessage).OmciMsg.MessageType {
485 case omci.RebootResponseType:
486 {
487 msgLayer := (*data.Data.(cmn.OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
488 if msgLayer == nil {
489 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
490 }
491 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
492 if !msgOk {
493 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
494 }
495 logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
496 if msgObj.Result != me.Success {
497 logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
498 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
499 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
500 msgObj.Result, oo.deviceID)
501 }
502 return nil
503 }
504 }
505 logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
506 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
507 }
508}
509
nikesh.krishnan1249be92023-11-27 04:20:12 +0530510// Relay the InSync message via Handler to Rw core - Status update
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000511func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000512 logger.Debugw(ctx, "relaying system-event", log.Fields{"device-id": oo.deviceID, "Event": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000513 // decouple the handler transfer from further processing here
514 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
515 if devEvent == cmn.MibDatabaseSync {
516 if oo.devState < cmn.MibDatabaseSync { //devState has not been synced yet
517 oo.devState = cmn.MibDatabaseSync
518 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
519 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
520 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000521 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored",
522 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000523 }
524 } else if devEvent == cmn.MibDownloadDone {
525 if oo.devState < cmn.MibDownloadDone { //devState has not been synced yet
526 oo.devState = cmn.MibDownloadDone
527 go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent)
528 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000529 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored",
530 log.Fields{"device-id": oo.deviceID, "state": oo.devState})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000531 }
532 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000533 logger.Warnw(ctx, "device-event not yet handled",
534 log.Fields{"device-id": oo.deviceID, "state": devEvent})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000535 }
536}
537
538// RestoreDataFromOnuKvStore - TODO: add comment
539func (oo *OnuDeviceEntry) RestoreDataFromOnuKvStore(ctx context.Context) error {
540 if oo.onuKVStore == nil {
541 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
542 return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID))
543 }
544 oo.MutexPersOnuConfig.Lock()
545 defer oo.MutexPersOnuConfig.Unlock()
546 oo.SOnuPersistentData =
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000547 onuPersistentData{0, 0, "", "", "", "", "", false, "", "", "", false, false, oo.mibAuditInterval, 0, 0,
548 make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000549 oo.mutexOnuKVStore.RLock()
550 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
551 oo.mutexOnuKVStore.RUnlock()
552 if err == nil {
553 if Value != nil {
554 logger.Debugw(ctx, "ONU-data read",
555 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
556 tmpBytes, _ := kvstore.ToByte(Value.Value)
557
558 if err = json.Unmarshal(tmpBytes, &oo.SOnuPersistentData); err != nil {
559 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
560 return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID))
561 }
562 logger.Debugw(ctx, "ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
563 "device-id": oo.deviceID})
564 } else {
565 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
566 return fmt.Errorf("no-ONU-data-found")
567 }
568 } else {
569 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
570 return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID))
571 }
572 return nil
573}
574
575// DeleteDataFromOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530576func (oo *OnuDeviceEntry) DeleteDataFromOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000577
578 if oo.onuKVStore == nil {
579 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530580 return errors.New("onu-data delete aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000581 }
Akash Soni840f8d62024-12-11 19:37:06 +0530582 err := oo.deletePersistentData(ctx)
583 if err != nil {
584 logger.Errorf(ctx, "onu-data delete aborted: during kv-access", log.Fields{"device-id": oo.deviceID, "err": err})
585 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000586 }
Akash Soni840f8d62024-12-11 19:37:06 +0530587 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000588}
589
Akash Soni840f8d62024-12-11 19:37:06 +0530590func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000591
592 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000593 oo.MutexPersOnuConfig.Lock()
594 defer oo.MutexPersOnuConfig.Unlock()
595
596 oo.SOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
597 oo.SOnuPersistentData =
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000598 onuPersistentData{0, 0, "", "", "", "", "", false, "", "", "", false, false, oo.mibAuditInterval, 0, 0,
599 make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000600 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
601 oo.mutexOnuKVStore.Lock()
602 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
603 oo.mutexOnuKVStore.Unlock()
604 if err != nil {
605 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530606 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000607 }
Akash Soni840f8d62024-12-11 19:37:06 +0530608 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000609}
610
611// UpdateOnuKvStore - TODO: add comment
Akash Soni840f8d62024-12-11 19:37:06 +0530612func (oo *OnuDeviceEntry) UpdateOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000613
614 if oo.onuKVStore == nil {
615 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530616 return errors.New("onu-data update aborted: onuKVStore not set")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000617 }
Akash Soni840f8d62024-12-11 19:37:06 +0530618 err := oo.storeDataInOnuKvStore(ctx)
619 if err != nil {
620 logger.Errorf(ctx, "onu-data update aborted: during writing process", log.Fields{"device-id": oo.deviceID, "err": err})
621 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000622 }
Akash Soni840f8d62024-12-11 19:37:06 +0530623 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000624}
625
Akash Soni840f8d62024-12-11 19:37:06 +0530626func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000627
628 oo.MutexPersOnuConfig.Lock()
629 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000630
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000631 oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
632 if _, exist := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID); !exist {
633 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000634 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
Akash Soni840f8d62024-12-11 19:37:06 +0530635 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000636 }
637 oo.baseDeviceHandler.RLockMutexDeletionInProgressFlag()
638 if oo.baseDeviceHandler.GetDeletionInProgress() {
639 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000640 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
641 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
Akash Soni840f8d62024-12-11 19:37:06 +0530642 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000643 }
644 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
645 oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag()
646
nikesh.krishnan1249be92023-11-27 04:20:12 +0530647 //assign values which are not already present when NewOnuDeviceEntry() is called
648 onuIndication := oo.baseDeviceHandler.GetOnuIndication()
649 if onuIndication != nil {
650 oo.SOnuPersistentData.PersOnuID = onuIndication.OnuId
651 oo.SOnuPersistentData.PersIntfID = onuIndication.IntfId
652 //TODO: verify usage of these values during restart UC
653 oo.SOnuPersistentData.PersAdminState = onuIndication.AdminState
654 oo.SOnuPersistentData.PersOperState = onuIndication.OperState
655 } else {
656 logger.Errorw(ctx, "onuIndication not set, unable to load ONU-data", log.Fields{"device-id": oo.deviceID})
Akash Soni840f8d62024-12-11 19:37:06 +0530657 return errors.New("onuIndication not set, unable to load ONU-data")
nikesh.krishnan1249be92023-11-27 04:20:12 +0530658 }
659
660 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "SOnuPersistentData": oo.SOnuPersistentData})
661
662 Value, err := json.Marshal(oo.SOnuPersistentData)
663 if err != nil {
664 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData,
665 "device-id": oo.deviceID, "err": err})
Akash Soni840f8d62024-12-11 19:37:06 +0530666 return err
nikesh.krishnan1249be92023-11-27 04:20:12 +0530667 }
668
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000669 oo.mutexOnuKVStore.Lock()
670 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
671 oo.mutexOnuKVStore.Unlock()
672 if err != nil {
Akash Soni840f8d62024-12-11 19:37:06 +0530673 logger.Errorf(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
674 return err
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675 }
Akash Soni840f8d62024-12-11 19:37:06 +0530676 return nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000677}
678
679// UpdateOnuUniTpPath - TODO: add comment
680func (oo *OnuDeviceEntry) UpdateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
681 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
682 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
683 no specific concurrency protection to SOnuPersistentData is required here
684 */
685 oo.MutexPersOnuConfig.Lock()
686 defer oo.MutexPersOnuConfig.Unlock()
687
688 for k, v := range oo.SOnuPersistentData.PersUniConfig {
689 if v.PersUniID == aUniID {
690 existingPath, ok := oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
691 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
692 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
693 if !ok {
694 logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString})
695 }
696 if existingPath != aPathString {
697 if aPathString == "" {
698 //existing entry to be deleted
699 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
700 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
701 } else {
702 //existing entry to be modified
703 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
704 oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
705 }
706 return true
707 }
708 //entry already exists
709 if aPathString == "" {
710 //no active TechProfile
711 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
712 "device-id": oo.deviceID, "uniID": aUniID})
713 } else {
714 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
715 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
716 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
717 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
718 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
719 //no deviceReason update (DeviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
720 // (during which the flows are removed/re-assigned but the techProf is left active)
721 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
722 // (should not be the case, but should not harm or be more robust ...)
723 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
724 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
725 if oo.pOnuTP != nil {
726 oo.pOnuTP.SetProfileToDelete(aUniID, aTpID, false)
727 }
728 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
729 }
730 return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
731 }
732 }
733 //no entry exists for uniId
734
735 if aPathString == "" {
736 //delete request in non-existing state , accept as no change
737 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
738 return false
739 }
740 //new entry to be created
741 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
742 perSubTpPathMap := make(map[uint8]string)
743 perSubTpPathMap[aTpID] = aPathString
744 oo.SOnuPersistentData.PersUniConfig =
745 append(oo.SOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]cmn.UniVlanFlowParams, 0)})
746 return true
747}
748
749// UpdateOnuUniFlowConfig - TODO: add comment
750func (oo *OnuDeviceEntry) UpdateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]cmn.UniVlanFlowParams) {
751
752 oo.MutexPersOnuConfig.Lock()
753 defer oo.MutexPersOnuConfig.Unlock()
754
755 for k, v := range oo.SOnuPersistentData.PersUniConfig {
756 if v.PersUniID == aUniID {
757 oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))
758 copy(oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
759 return
760 }
761 }
762 //flow update was faster than tp-config - create PersUniConfig-entry
763 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
764 // (e.g after flow removal from RemoveUniFlowParams()).
765 // 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
766 // 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
767 // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests
768 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))}
769 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
770 oo.SOnuPersistentData.PersUniConfig = append(oo.SOnuPersistentData.PersUniConfig, tmpConfig)
771}
772
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000773// ResetKvProcessingErrorIndication - TODO: add comment
774func (oo *OnuDeviceEntry) ResetKvProcessingErrorIndication() {
775 oo.mutexOnuKVStoreProcResult.Lock()
776 oo.onuKVStoreProcResult = nil
777 oo.mutexOnuKVStoreProcResult.Unlock()
778}
779
780// GetKvProcessingErrorIndication - TODO: add comment
781func (oo *OnuDeviceEntry) GetKvProcessingErrorIndication() error {
782 oo.mutexOnuKVStoreProcResult.RLock()
783 value := oo.onuKVStoreProcResult
784 oo.mutexOnuKVStoreProcResult.RUnlock()
785 return value
786}
787
Akash Soni840f8d62024-12-11 19:37:06 +0530788// func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
789// oo.mutexOnuKVStoreProcResult.Lock()
790// oo.onuKVStoreProcResult = value
791// oo.mutexOnuKVStoreProcResult.Unlock()
792// }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000793
794// IncrementMibDataSync - TODO: add comment
795func (oo *OnuDeviceEntry) IncrementMibDataSync(ctx context.Context) {
796 oo.MutexPersOnuConfig.Lock()
797 defer oo.MutexPersOnuConfig.Unlock()
798 if oo.SOnuPersistentData.PersMibDataSyncAdpt < 255 {
799 oo.SOnuPersistentData.PersMibDataSyncAdpt++
800 } else {
801 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
802 oo.SOnuPersistentData.PersMibDataSyncAdpt = 1
803 }
804 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.SOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
805}
806
807// ModifySwImageInactiveVersion - updates the inactive SW image version stored
808func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
809 oo.mutexOnuSwImageIndications.Lock()
810 defer oo.mutexOnuSwImageIndications.Unlock()
811 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
812 "device-id": oo.deviceID, "version": aImageVersion})
813 oo.onuSwImageIndications.InActiveEntityEntry.Version = aImageVersion
814 //inactive SW version is not part of persistency data (yet) - no need to update that
815}
816
817// ModifySwImageActiveCommit - updates the active SW commit flag stored
818func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
819 oo.mutexOnuSwImageIndications.Lock()
820 defer oo.mutexOnuSwImageIndications.Unlock()
821 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
822 "device-id": oo.deviceID, "committed": aCommitted})
823 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = aCommitted
824 //commit flag is not part of persistency data (yet) - no need to update that
825}
826
827// GetActiveImageVersion - returns the active SW image version stored
828func (oo *OnuDeviceEntry) GetActiveImageVersion(ctx context.Context) string {
829 oo.mutexOnuSwImageIndications.RLock()
830 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
831 value := oo.onuSwImageIndications.ActiveEntityEntry.Version
832 oo.mutexOnuSwImageIndications.RUnlock()
833 return value
834 }
835 oo.mutexOnuSwImageIndications.RUnlock()
836 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
837 return ""
838}
839
840// GetInactiveImageVersion - TODO: add comment
841func (oo *OnuDeviceEntry) GetInactiveImageVersion(ctx context.Context) string {
842 oo.mutexOnuSwImageIndications.RLock()
843 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
844 value := oo.onuSwImageIndications.InActiveEntityEntry.Version
845 oo.mutexOnuSwImageIndications.RUnlock()
846 return value
847 }
848 oo.mutexOnuSwImageIndications.RUnlock()
849 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
850 return ""
851}
852
853func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
854 oo.MutexPersOnuConfig.RLock()
855 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000856 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.SOnuPersistentData.PersVendorID, oo.SOnuPersistentData.PersVersion,
857 oo.SOnuPersistentData.PersActiveSwVersion)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000858}
859
860// AllocateFreeTcont - TODO: add comment
861func (oo *OnuDeviceEntry) AllocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
862 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
863 "allocated-instances": oo.SOnuPersistentData.PersTcontMap})
864
mpagenko2c3f6c52021-11-23 11:22:10 +0000865 oo.MutexPersOnuConfig.Lock()
866 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000867 if entityID, ok := oo.SOnuPersistentData.PersTcontMap[allocID]; ok {
868 //tcont already allocated before, return the used instance-id
869 return entityID, true, nil
870 }
871 //First allocation of tcont. Find a free instance
872 if tcontInstKeys := oo.pOnuDB.GetSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
873 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
874 for _, instID := range tcontInstKeys {
875 instExist := false
876 //If this instance exist in map, it means it is not empty. It is allocated before
877 for _, v := range oo.SOnuPersistentData.PersTcontMap {
878 if v == instID {
879 instExist = true
880 break
881 }
882 }
883 if !instExist {
884 oo.SOnuPersistentData.PersTcontMap[allocID] = instID
885 return instID, false, nil
886 }
887 }
888 }
889 return 0, false, fmt.Errorf(fmt.Sprintf("no-free-tcont-left-for-device-%s", oo.deviceID))
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000890}
891
892// FreeTcont - TODO: add comment
893func (oo *OnuDeviceEntry) FreeTcont(ctx context.Context, allocID uint16) {
894 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
mpagenko2c3f6c52021-11-23 11:22:10 +0000895 oo.MutexPersOnuConfig.Lock()
896 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897 delete(oo.SOnuPersistentData.PersTcontMap, allocID)
898}
899
900// GetDevOmciCC - TODO: add comment
901func (oo *OnuDeviceEntry) GetDevOmciCC() *cmn.OmciCC {
902 return oo.PDevOmciCC
903}
904
905// GetOnuDB - TODO: add comment
906func (oo *OnuDeviceEntry) GetOnuDB() *devdb.OnuDeviceDB {
907 return oo.pOnuDB
908}
909
910// GetPersSerialNumber - TODO: add comment
911func (oo *OnuDeviceEntry) GetPersSerialNumber() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000912 oo.MutexPersOnuConfig.RLock()
913 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000914 value := oo.SOnuPersistentData.PersSerialNumber
915 return value
916}
917
918// GetPersVendorID - TODO: add comment
919func (oo *OnuDeviceEntry) GetPersVendorID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000920 oo.MutexPersOnuConfig.RLock()
921 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000922 value := oo.SOnuPersistentData.PersVendorID
923 return value
924}
925
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000926// GetPersIsExtOmciSupported - TODO: add comment
927func (oo *OnuDeviceEntry) GetPersIsExtOmciSupported() bool {
928 oo.MutexPersOnuConfig.RLock()
929 defer oo.MutexPersOnuConfig.RUnlock()
930 value := oo.SOnuPersistentData.PersIsExtOmciSupported
931 return value
932}
933
Holger Hildebrandt6a001d02022-06-15 08:32:48 +0000934// GetPersVersion - TODO: add comment
935func (oo *OnuDeviceEntry) GetPersVersion() string {
936 oo.MutexPersOnuConfig.RLock()
937 defer oo.MutexPersOnuConfig.RUnlock()
938 value := oo.SOnuPersistentData.PersVersion
939 return value
940}
941
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000942// GetPersEquipmentID - TODO: add comment
943func (oo *OnuDeviceEntry) GetPersEquipmentID() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000944 oo.MutexPersOnuConfig.RLock()
945 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000946 value := oo.SOnuPersistentData.PersEquipmentID
947 return value
948}
949
950// GetMibUploadFsmCommChan - TODO: add comment
951func (oo *OnuDeviceEntry) GetMibUploadFsmCommChan() chan cmn.Message {
952 return oo.PMibUploadFsm.CommChan
953}
954
955// GetMibDownloadFsmCommChan - TODO: add comment
956func (oo *OnuDeviceEntry) GetMibDownloadFsmCommChan() chan cmn.Message {
957 return oo.PMibDownloadFsm.CommChan
958}
959
960// GetOmciRebootMsgRevChan - TODO: add comment
961func (oo *OnuDeviceEntry) GetOmciRebootMsgRevChan() chan cmn.Message {
962 return oo.omciRebootMessageReceivedChannel
963}
964
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000965// GetPersActiveSwVersion - TODO: add comment
966func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string {
mpagenko2c3f6c52021-11-23 11:22:10 +0000967 oo.MutexPersOnuConfig.RLock()
968 defer oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969 return oo.SOnuPersistentData.PersActiveSwVersion
970}
971
972// SetPersActiveSwVersion - TODO: add comment
973func (oo *OnuDeviceEntry) SetPersActiveSwVersion(value string) {
mpagenko2c3f6c52021-11-23 11:22:10 +0000974 oo.MutexPersOnuConfig.Lock()
975 defer oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000976 oo.SOnuPersistentData.PersActiveSwVersion = value
977}
978
mpagenko101ac942021-11-16 15:01:29 +0000979// setReconcilingFlows - TODO: add comment
980func (oo *OnuDeviceEntry) setReconcilingFlows(value bool) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000981 oo.mutexReconcilingFlowsFlag.Lock()
982 oo.reconcilingFlows = value
983 oo.mutexReconcilingFlowsFlag.Unlock()
984}
985
mpagenko101ac942021-11-16 15:01:29 +0000986// SendChReconcilingFlowsFinished - TODO: add comment
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000987func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) {
mpagenko101ac942021-11-16 15:01:29 +0000988 if oo != nil { //if the object still exists (might have been already deleted in background)
Sridhar Ravindra27afb582025-02-10 13:18:11 +0530989 // wait for some time before exiting, as the receiver might not have started and will lead to Mib reset if this signal is missed
990 expiry := vlanConfigSendChanExpiry * time.Second
mpagenko101ac942021-11-16 15:01:29 +0000991 select {
992 case oo.chReconcilingFlowsFinished <- value:
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530993 logger.Info(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID})
Sridhar Ravindra27afb582025-02-10 13:18:11 +0530994 case <-time.After(expiry):
995 logger.Infow(ctx, "reconciling - timer expired, flows finished not sent!", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +0000996 }
997 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000998}
999
mpagenko101ac942021-11-16 15:01:29 +00001000// isReconcilingFlows - TODO: add comment
1001func (oo *OnuDeviceEntry) isReconcilingFlows() bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001002 oo.mutexReconcilingFlowsFlag.RLock()
1003 value := oo.reconcilingFlows
1004 oo.mutexReconcilingFlowsFlag.RUnlock()
1005 return value
1006}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001007
1008// PrepareForGarbageCollection - remove references to prepare for garbage collection
1009func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1010 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1011 oo.baseDeviceHandler = nil
1012 oo.pOnuTP = nil
1013 if oo.PDevOmciCC != nil {
1014 oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID)
1015 }
1016 oo.PDevOmciCC = nil
1017}
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001018
nikesh.krishnan1249be92023-11-27 04:20:12 +05301019// SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001020func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) {
1021
1022 oo.MutexPersOnuConfig.RLock()
1023 context := make(map[string]string)
1024 context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10)
1025 context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10)
1026 context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber
1027 oo.MutexPersOnuConfig.RUnlock()
1028
1029 deviceEvent := &voltha.DeviceEvent{
1030 ResourceId: oo.deviceID,
1031 DeviceEventName: aDeviceEventName,
1032 Description: aDescription,
1033 Context: context,
1034 }
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001035 logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": oo.deviceID})
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001036 _ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix())
1037}
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301038
1039// IsMIBTemplateGenerated checks if a MIB Template is already present for this type of ONT.
1040func (oo *OnuDeviceEntry) IsMIBTemplateGenerated(ctx context.Context) bool {
1041
1042 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1043 defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
1044
1045 if _, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); !exist {
1046 logger.Infow(ctx, "MIB template not Generated , further proceed to do MIB sync upload ", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1047 return false
1048 }
1049 return true
1050}