Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 17 | // Package mib provides the utilities for managing the onu mib |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package mib |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/json" |
| 23 | "errors" |
| 24 | "fmt" |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 25 | "strconv" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
| 28 | |
| 29 | "github.com/looplab/fsm" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 30 | "github.com/opencord/omci-lib-go/v2" |
| 31 | me "github.com/opencord/omci-lib-go/v2/generated" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 34 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 35 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 38 | |
| 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 |
| 47 | const ( |
| 48 | UlEvStart = "UlEvStart" |
| 49 | UlEvResetMib = "UlEvResetMib" |
| 50 | UlEvGetVendorAndSerial = "UlEvGetVendorAndSerial" |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 51 | UlEvGetVersion = "UlEvGetVersion" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 52 | UlEvGetEquipIDAndOmcc = "UlEvGetEquipIDAndOmcc" |
| 53 | UlEvTestExtOmciSupport = "UlEvTestExtOmciSupport" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 54 | UlEvGetFirstSwVersion = "UlEvGetFirstSwVersion" |
| 55 | UlEvGetSecondSwVersion = "UlEvGetSecondSwVersion" |
| 56 | UlEvGetMacAddress = "UlEvGetMacAddress" |
| 57 | UlEvGetMibTemplate = "UlEvGetMibTemplate" |
| 58 | UlEvUploadMib = "UlEvUploadMib" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 59 | UlEvVerifyAndStoreTPs = "UlEvVerifyAndStoreTPs" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 60 | 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 |
| 71 | const ( |
| 72 | UlStDisabled = "UlStDisabled" |
| 73 | UlStStarting = "UlStStarting" |
| 74 | UlStResettingMib = "UlStResettingMib" |
| 75 | UlStGettingVendorAndSerial = "UlStGettingVendorAndSerial" |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 76 | UlStGettingVersion = "UlStGettingVersion" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 77 | UlStGettingEquipIDAndOmcc = "UlStGettingEquipIDAndOmcc" |
| 78 | UlStTestingExtOmciSupport = "UlStTestingExtOmciSupport" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 79 | UlStGettingFirstSwVersion = "UlStGettingFirstSwVersion" |
| 80 | UlStGettingSecondSwVersion = "UlStGettingSecondSwVersion" |
| 81 | UlStGettingMacAddress = "UlStGettingMacAddress" |
| 82 | UlStGettingMibTemplate = "UlStGettingMibTemplate" |
| 83 | UlStUploading = "UlStUploading" |
| 84 | UlStUploadDone = "UlStUploadDone" |
| 85 | UlStInSync = "UlStInSync" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 86 | UlStVerifyingAndStoringTPs = "UlStVerifyingAndStoringTPs" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 87 | UlStExaminingMds = "UlStExaminingMds" |
| 88 | UlStResynchronizing = "UlStResynchronizing" |
| 89 | UlStExaminingMdsSuccess = "UlStExaminingMdsSuccess" |
| 90 | UlStAuditing = "UlStAuditing" |
| 91 | UlStReAuditing = "UlStReAuditing" |
| 92 | UlStOutOfSync = "UlStOutOfSync" |
| 93 | ) |
| 94 | |
| 95 | // CMibUlFsmIdleState - TODO: add comment |
| 96 | const CMibUlFsmIdleState = UlStInSync |
| 97 | |
| 98 | // events of MibDownload FSM |
| 99 | const ( |
| 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 |
| 112 | const ( |
| 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 |
| 123 | const CMibDlFsmIdleState = DlStDisabled |
| 124 | |
| 125 | const ( |
| 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 129 | ) |
| 130 | |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 131 | const cEmptyVendorIDString = "____" |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 132 | const cEmptyVersionString = "______________" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 133 | const cEmptyMacAddrString = "000000000000" |
| 134 | const cEmptySerialNumberString = "0000000000000000" |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 135 | const cEmptyEquipIDString = "EMPTY_EQUIP_ID" |
| 136 | const cNotPresentEquipIDString = "NOT_PRESENT_EQUIP_ID" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 137 | |
| 138 | type uniPersConfig struct { |
| 139 | PersUniID uint8 `json:"uni_id"` |
| 140 | PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map |
| 141 | PersFlowParams []cmn.UniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go |
| 142 | } |
| 143 | |
| 144 | type onuPersistentData struct { |
| 145 | PersOnuID uint32 `json:"onu_id"` |
| 146 | PersIntfID uint32 `json:"intf_id"` |
| 147 | PersSerialNumber string `json:"serial_number"` |
| 148 | PersMacAddress string `json:"mac_address"` |
| 149 | PersVendorID string `json:"vendor_id"` |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 150 | PersVersion string `json:"version"` |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 151 | PersEquipmentID string `json:"equipment_id"` |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 152 | PersIsExtOmciSupported bool `json:"is_ext_omci_supported"` |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 153 | PersActiveSwVersion string `json:"active_sw_version"` |
| 154 | PersAdminState string `json:"admin_state"` |
| 155 | PersOperState string `json:"oper_state"` |
| 156 | PersUniUnlockDone bool `json:"uni_unlock_done"` |
| 157 | PersUniDisableDone bool `json:"uni_disable_done"` |
| 158 | PersMibAuditInterval time.Duration `json:"mib_audit_interval"` |
| 159 | PersMibLastDbSync uint32 `json:"mib_last_db_sync"` |
| 160 | PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"` |
| 161 | PersUniConfig []uniPersConfig `json:"uni_config"` |
| 162 | PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"` |
| 163 | PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map |
| 164 | } |
| 165 | |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 166 | //type UniTpidInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage |
| 167 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 168 | // OnuDeviceEntry - ONU device info and FSM events. |
| 169 | type OnuDeviceEntry struct { |
| 170 | deviceID string |
| 171 | baseDeviceHandler cmn.IdeviceHandler |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 172 | eventProxy eventif.EventProxy |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 173 | pOpenOnuAc cmn.IopenONUAC |
| 174 | pOnuTP cmn.IonuUniTechProf |
| 175 | coreClient *vgrpc.Client |
| 176 | PDevOmciCC *cmn.OmciCC |
| 177 | pOnuDB *devdb.OnuDeviceDB |
| 178 | mibTemplateKVStore *db.Backend |
| 179 | MutexPersOnuConfig sync.RWMutex |
| 180 | SOnuPersistentData onuPersistentData |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 181 | ReconciledTpInstances map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage |
| 182 | MutexReconciledTpInstances sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 183 | reconcilingFlows bool |
| 184 | mutexReconcilingFlowsFlag sync.RWMutex |
| 185 | chReconcilingFlowsFinished chan bool //channel to indicate that reconciling of flows has been finished |
| 186 | mibTemplatePath string |
| 187 | mutexOnuKVStore sync.RWMutex |
| 188 | onuKVStore *db.Backend |
| 189 | onuKVStorePath string |
| 190 | mutexOnuKVStoreProcResult sync.RWMutex |
| 191 | onuKVStoreProcResult error //error indication of processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 192 | mutexOnuSwImageIndications sync.RWMutex |
| 193 | onuSwImageIndications cmn.SswImageIndications |
| 194 | MutexOnuImageStatus sync.RWMutex |
| 195 | POnuImageStatus *swupg.OnuImageStatus |
| 196 | //lockDeviceEntries sync.RWMutex |
| 197 | mibDbClass func(context.Context) error |
| 198 | supportedFsms cmn.OmciDeviceFsms |
| 199 | devState cmn.OnuDeviceEvent |
| 200 | // Audit and MDS |
| 201 | mibAuditInterval time.Duration |
| 202 | alarmAuditInterval time.Duration |
| 203 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 204 | //mibNextDbResync uint32 |
| 205 | |
| 206 | // for mibUpload |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 207 | PMibUploadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later |
| 208 | mutexLastTxParamStruct sync.RWMutex |
| 209 | lastTxParamStruct sLastTxMeParameter |
| 210 | mibSyncMsgProcessorRunning bool |
| 211 | mutexMibSyncMsgProcessorRunning sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 212 | // for mibDownload |
| 213 | PMibDownloadFsm *cmn.AdapterFsm //could be handled dynamically and more general as pcmn.AdapterFsm - perhaps later |
| 214 | //remark: general usage of pAdapterFsm would require generalization of CommChan usage and internal event setting |
| 215 | // within the FSM event procedures |
| 216 | mutexPLastTxMeInstance sync.RWMutex |
| 217 | pLastTxMeInstance *me.ManagedEntity |
| 218 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 219 | omciRebootMessageReceivedChannel chan cmn.Message // channel needed by reboot request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 220 | } |
| 221 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 222 | // NewOnuDeviceEntry returns a new instance of a OnuDeviceEntry |
| 223 | // mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 224 | func NewOnuDeviceEntry(ctx context.Context, cc *vgrpc.Client, dh cmn.IdeviceHandler, |
| 225 | openonu cmn.IopenONUAC) *OnuDeviceEntry { |
| 226 | var onuDeviceEntry OnuDeviceEntry |
| 227 | onuDeviceEntry.deviceID = dh.GetDeviceID() |
| 228 | logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 229 | onuDeviceEntry.baseDeviceHandler = dh |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 230 | onuDeviceEntry.eventProxy = dh.GetEventProxy() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 231 | onuDeviceEntry.pOpenOnuAc = openonu |
| 232 | onuDeviceEntry.coreClient = cc |
| 233 | onuDeviceEntry.devState = cmn.DeviceStatusInit |
| 234 | onuDeviceEntry.SOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0) |
| 235 | onuDeviceEntry.SOnuPersistentData.PersTcontMap = make(map[uint16]uint16) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 236 | onuDeviceEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 237 | onuDeviceEntry.chReconcilingFlowsFinished = make(chan bool) |
| 238 | onuDeviceEntry.reconcilingFlows = false |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 239 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan cmn.Message, 2) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 240 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 241 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 242 | //are per ONU Vendor |
| 243 | // |
| 244 | // MIB Synchronization Database - possible overloading from arguments |
| 245 | supportedFsms := onuDeviceEntry.pOpenOnuAc.GetSupportedFsms() |
| 246 | if supportedFsms != nil { |
| 247 | onuDeviceEntry.supportedFsms = *supportedFsms |
| 248 | } else { |
| 249 | // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only! |
| 250 | //var mibSyncFsm = NewMibSynchronizer() |
| 251 | // use some internal defaults, if not defined from outside |
| 252 | onuDeviceEntry.supportedFsms = cmn.OmciDeviceFsms{ |
| 253 | "mib-synchronizer": { |
| 254 | //mibSyncFsm, // Implements the MIB synchronization state machine |
| 255 | DatabaseClass: onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database |
| 256 | //true, // Advertise events on OpenOMCI event bus |
| 257 | AuditInterval: dh.GetAlarmAuditInterval(), // Time to wait between MIB audits. 0 to disable audits. |
| 258 | // map[string]func() error{ |
| 259 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 260 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 261 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 262 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 263 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 264 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 265 | // }, |
| 266 | }, |
| 267 | } |
| 268 | } |
| 269 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].DatabaseClass |
| 270 | logger.Debug(ctx, "access2mibDbClass") |
| 271 | go onuDeviceEntry.mibDbClass(ctx) |
| 272 | if !dh.IsReconciling() { |
| 273 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].AuditInterval |
| 274 | onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval |
| 275 | onuDeviceEntry.alarmAuditInterval = dh.GetAlarmAuditInterval() |
| 276 | onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval |
| 277 | } else { |
| 278 | logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 279 | // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of |
| 280 | // vendor- or deviceID-specific configurations via voltctl-commands |
| 281 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.SOnuPersistentData.PersMibAuditInterval |
| 282 | onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.SOnuPersistentData.PersAlarmAuditInterval |
| 283 | } |
| 284 | logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval, |
| 285 | "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval}) |
| 286 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 287 | //onuDeviceEntry.mibNextDbResync = 0 |
| 288 | |
| 289 | // Omci related Mib upload sync state machine |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 290 | mibUploadChan := make(chan cmn.Message, 2) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 291 | onuDeviceEntry.PMibUploadFsm = cmn.NewAdapterFsm("MibUpload", onuDeviceEntry.deviceID, mibUploadChan) |
| 292 | onuDeviceEntry.PMibUploadFsm.PFsm = fsm.NewFSM( |
| 293 | UlStDisabled, |
| 294 | fsm.Events{ |
| 295 | |
| 296 | {Name: UlEvStart, Src: []string{UlStDisabled}, Dst: UlStStarting}, |
| 297 | |
| 298 | {Name: UlEvResetMib, Src: []string{UlStStarting}, Dst: UlStResettingMib}, |
| 299 | {Name: UlEvGetVendorAndSerial, Src: []string{UlStResettingMib}, Dst: UlStGettingVendorAndSerial}, |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 300 | {Name: UlEvGetVersion, Src: []string{UlStGettingVendorAndSerial}, Dst: UlStGettingVersion}, |
| 301 | {Name: UlEvGetEquipIDAndOmcc, Src: []string{UlStGettingVersion}, Dst: UlStGettingEquipIDAndOmcc}, |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 302 | {Name: UlEvTestExtOmciSupport, Src: []string{UlStGettingEquipIDAndOmcc}, Dst: UlStTestingExtOmciSupport}, |
| 303 | {Name: UlEvGetFirstSwVersion, Src: []string{UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport}, Dst: UlStGettingFirstSwVersion}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 304 | {Name: UlEvGetSecondSwVersion, Src: []string{UlStGettingFirstSwVersion}, Dst: UlStGettingSecondSwVersion}, |
| 305 | {Name: UlEvGetMacAddress, Src: []string{UlStGettingSecondSwVersion}, Dst: UlStGettingMacAddress}, |
| 306 | {Name: UlEvGetMibTemplate, Src: []string{UlStGettingMacAddress}, Dst: UlStGettingMibTemplate}, |
| 307 | |
| 308 | {Name: UlEvUploadMib, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploading}, |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 309 | |
| 310 | {Name: UlEvVerifyAndStoreTPs, Src: []string{UlStStarting}, Dst: UlStVerifyingAndStoringTPs}, |
| 311 | {Name: UlEvSuccess, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStExaminingMds}, |
| 312 | {Name: UlEvMismatch, Src: []string{UlStVerifyingAndStoringTPs}, Dst: UlStResettingMib}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 313 | |
| 314 | {Name: UlEvSuccess, Src: []string{UlStGettingMibTemplate}, Dst: UlStUploadDone}, |
| 315 | {Name: UlEvSuccess, Src: []string{UlStUploading}, Dst: UlStUploadDone}, |
| 316 | |
| 317 | {Name: UlEvSuccess, Src: []string{UlStUploadDone}, Dst: UlStInSync}, |
| 318 | //{Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStInSync}, |
| 319 | {Name: UlEvSuccess, Src: []string{UlStExaminingMds}, Dst: UlStExaminingMdsSuccess}, |
| 320 | // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers |
| 321 | // mib-reset and new provisioning at this point |
| 322 | //{Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResynchronizing}, |
| 323 | {Name: UlEvMismatch, Src: []string{UlStExaminingMds}, Dst: UlStResettingMib}, |
| 324 | |
| 325 | {Name: UlEvSuccess, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStInSync}, |
| 326 | {Name: UlEvMismatch, Src: []string{UlStExaminingMdsSuccess}, Dst: UlStResettingMib}, |
| 327 | |
| 328 | {Name: UlEvAuditMib, Src: []string{UlStInSync}, Dst: UlStAuditing}, |
| 329 | |
| 330 | {Name: UlEvSuccess, Src: []string{UlStOutOfSync}, Dst: UlStInSync}, |
| 331 | {Name: UlEvAuditMib, Src: []string{UlStOutOfSync}, Dst: UlStAuditing}, |
| 332 | |
| 333 | {Name: UlEvSuccess, Src: []string{UlStAuditing}, Dst: UlStInSync}, |
| 334 | {Name: UlEvMismatch, Src: []string{UlStAuditing}, Dst: UlStReAuditing}, |
| 335 | {Name: UlEvForceResync, Src: []string{UlStAuditing}, Dst: UlStResynchronizing}, |
| 336 | |
| 337 | {Name: UlEvSuccess, Src: []string{UlStReAuditing}, Dst: UlStInSync}, |
| 338 | {Name: UlEvMismatch, Src: []string{UlStReAuditing}, Dst: UlStResettingMib}, |
| 339 | |
| 340 | {Name: UlEvSuccess, Src: []string{UlStResynchronizing}, Dst: UlStInSync}, |
| 341 | {Name: UlEvDiffsFound, Src: []string{UlStResynchronizing}, Dst: UlStOutOfSync}, |
| 342 | |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 343 | {Name: UlEvTimeout, Src: []string{UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport, |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 344 | UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing, |
| 345 | UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStStarting}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 346 | |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 347 | {Name: UlEvStop, Src: []string{UlStStarting, UlStResettingMib, UlStGettingVendorAndSerial, UlStGettingVersion, UlStGettingEquipIDAndOmcc, UlStTestingExtOmciSupport, |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 348 | UlStGettingFirstSwVersion, UlStGettingSecondSwVersion, UlStGettingMacAddress, UlStGettingMibTemplate, UlStUploading, UlStResynchronizing, |
| 349 | UlStVerifyingAndStoringTPs, UlStExaminingMds, UlStUploadDone, UlStInSync, UlStOutOfSync, UlStAuditing, UlStReAuditing}, Dst: UlStDisabled}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 350 | }, |
| 351 | |
| 352 | fsm.Callbacks{ |
| 353 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibUploadFsm.LogFsmStateChange(ctx, e) }, |
| 354 | "enter_" + UlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) }, |
| 355 | "enter_" + UlStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) }, |
| 356 | "enter_" + UlStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) }, |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 357 | "enter_" + UlStGettingVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingVersionState(ctx, e) }, |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 358 | "enter_" + UlStGettingEquipIDAndOmcc: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipIDAndOmccVersState(ctx, e) }, |
| 359 | "enter_" + UlStTestingExtOmciSupport: func(e *fsm.Event) { onuDeviceEntry.enterTestingExtOmciSupportState(ctx, e) }, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 360 | "enter_" + UlStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) }, |
| 361 | "enter_" + UlStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) }, |
| 362 | "enter_" + UlStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) }, |
| 363 | "enter_" + UlStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) }, |
| 364 | "enter_" + UlStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) }, |
| 365 | "enter_" + UlStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) }, |
| 366 | "enter_" + UlStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) }, |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 367 | "enter_" + UlStVerifyingAndStoringTPs: func(e *fsm.Event) { onuDeviceEntry.enterVerifyingAndStoringTPsState(ctx, e) }, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 368 | "enter_" + UlStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) }, |
| 369 | "enter_" + UlStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) }, |
| 370 | "enter_" + UlStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) }, |
| 371 | "enter_" + UlStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) }, |
| 372 | "enter_" + UlStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) }, |
| 373 | "enter_" + UlStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) }, |
| 374 | }, |
| 375 | ) |
| 376 | // Omci related Mib download state machine |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 377 | mibDownloadChan := make(chan cmn.Message, 2) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 378 | onuDeviceEntry.PMibDownloadFsm = cmn.NewAdapterFsm("MibDownload", onuDeviceEntry.deviceID, mibDownloadChan) |
| 379 | onuDeviceEntry.PMibDownloadFsm.PFsm = fsm.NewFSM( |
| 380 | DlStDisabled, |
| 381 | fsm.Events{ |
| 382 | |
| 383 | {Name: DlEvStart, Src: []string{DlStDisabled}, Dst: DlStStarting}, |
| 384 | |
| 385 | {Name: DlEvCreateGal, Src: []string{DlStStarting}, Dst: DlStCreatingGal}, |
| 386 | {Name: DlEvRxGalResp, Src: []string{DlStCreatingGal}, Dst: DlStSettingOnu2g}, |
| 387 | {Name: DlEvRxOnu2gResp, Src: []string{DlStSettingOnu2g}, Dst: DlStBridgeInit}, |
| 388 | // the bridge state is used for multi ME config for alle UNI related ports |
| 389 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 390 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
| 391 | {Name: DlEvRxBridgeResp, Src: []string{DlStBridgeInit}, Dst: DlStDownloaded}, |
| 392 | |
| 393 | {Name: DlEvTimeoutSimple, Src: []string{DlStCreatingGal, DlStSettingOnu2g}, Dst: DlStStarting}, |
| 394 | {Name: DlEvTimeoutBridge, Src: []string{DlStBridgeInit}, Dst: DlStStarting}, |
| 395 | |
| 396 | {Name: DlEvReset, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g, |
| 397 | DlStBridgeInit, DlStDownloaded}, Dst: DlStResetting}, |
| 398 | // exceptional treatment for all states except DlStResetting |
| 399 | {Name: DlEvRestart, Src: []string{DlStStarting, DlStCreatingGal, DlStSettingOnu2g, |
| 400 | DlStBridgeInit, DlStDownloaded, DlStResetting}, Dst: DlStDisabled}, |
| 401 | }, |
| 402 | |
| 403 | fsm.Callbacks{ |
| 404 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.PMibDownloadFsm.LogFsmStateChange(ctx, e) }, |
| 405 | "enter_" + DlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) }, |
| 406 | "enter_" + DlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) }, |
| 407 | "enter_" + DlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) }, |
| 408 | "enter_" + DlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) }, |
| 409 | "enter_" + DlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) }, |
| 410 | "enter_" + DlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) }, |
| 411 | }, |
| 412 | ) |
| 413 | if onuDeviceEntry.PMibDownloadFsm == nil || onuDeviceEntry.PMibDownloadFsm.PFsm == nil { |
| 414 | logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 415 | // TODO some specific error treatment - or waiting for crash ? |
| 416 | } |
| 417 | |
| 418 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, cBasePathMibTemplateKvStore) |
| 419 | if onuDeviceEntry.mibTemplateKVStore == nil { |
| 420 | logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service", |
| 421 | log.Fields{"device-id": onuDeviceEntry.deviceID, "service": cBasePathMibTemplateKvStore}) |
| 422 | } |
| 423 | |
| 424 | onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 425 | baseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, dh.GetBackendPathPrefix()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 426 | onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(ctx, baseKvStorePath) |
| 427 | if onuDeviceEntry.onuKVStore == nil { |
| 428 | logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service", |
| 429 | log.Fields{"device-id": onuDeviceEntry.deviceID, "service": baseKvStorePath}) |
| 430 | } |
| 431 | |
| 432 | // Alarm Synchronization Database |
| 433 | |
| 434 | //self._alarm_db = None |
| 435 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 436 | return &onuDeviceEntry |
| 437 | } |
| 438 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 439 | // Start starts (logs) the omci agent |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 440 | func (oo *OnuDeviceEntry) Start(ctx context.Context) error { |
| 441 | logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID}) |
| 442 | if oo.PDevOmciCC == nil { |
| 443 | oo.PDevOmciCC = cmn.NewOmciCC(ctx, oo.deviceID, oo.baseDeviceHandler, oo, oo.baseDeviceHandler.GetOnuAlarmManager(), oo.coreClient) |
| 444 | if oo.PDevOmciCC == nil { |
| 445 | logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID}) |
| 446 | return fmt.Errorf("could not create devOmciCc %s", oo.deviceID) |
| 447 | } |
| 448 | } |
| 449 | return nil |
| 450 | } |
| 451 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 452 | // Stop stops/resets the omciCC |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 453 | func (oo *OnuDeviceEntry) Stop(ctx context.Context, abResetOmciCC bool) error { |
| 454 | logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID}) |
| 455 | if abResetOmciCC && (oo.PDevOmciCC != nil) { |
| 456 | _ = oo.PDevOmciCC.Stop(ctx) |
| 457 | } |
| 458 | //to allow for all event notifications again when re-using the device and omciCC |
| 459 | oo.devState = cmn.DeviceStatusInit |
| 460 | return nil |
| 461 | } |
| 462 | |
| 463 | // Reboot - TODO: add comment |
| 464 | func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error { |
| 465 | logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID}) |
| 466 | if oo.PDevOmciCC != nil { |
| 467 | if err := oo.PDevOmciCC.SendReboot(ctx, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.omciRebootMessageReceivedChannel); err != nil { |
| 468 | logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID}) |
| 469 | return err |
| 470 | } |
| 471 | } |
| 472 | return nil |
| 473 | } |
| 474 | |
| 475 | // WaitForRebootResponse - TODO: add comment |
| 476 | func (oo *OnuDeviceEntry) WaitForRebootResponse(ctx context.Context, responseChannel chan cmn.Message) error { |
| 477 | select { |
| 478 | case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
| 479 | logger.Warnw(ctx, "reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
| 480 | return fmt.Errorf("rebootTimeout") |
| 481 | case data := <-responseChannel: |
| 482 | switch data.Data.(cmn.OmciMessage).OmciMsg.MessageType { |
| 483 | case omci.RebootResponseType: |
| 484 | { |
| 485 | msgLayer := (*data.Data.(cmn.OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 486 | if msgLayer == nil { |
| 487 | return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType") |
| 488 | } |
| 489 | msgObj, msgOk := msgLayer.(*omci.RebootResponse) |
| 490 | if !msgOk { |
| 491 | return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID) |
| 492 | } |
| 493 | logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
| 494 | if msgObj.Result != me.Success { |
| 495 | logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result}) |
| 496 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 497 | return fmt.Errorf("omci RebootResponse result error indication %s for device %s", |
| 498 | msgObj.Result, oo.deviceID) |
| 499 | } |
| 500 | return nil |
| 501 | } |
| 502 | } |
| 503 | logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID}) |
| 504 | return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID) |
| 505 | } |
| 506 | } |
| 507 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 508 | // Relay the InSync message via Handler to Rw core - Status update |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 509 | func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 510 | logger.Debugw(ctx, "relaying system-event", log.Fields{"device-id": oo.deviceID, "Event": devEvent}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 511 | // decouple the handler transfer from further processing here |
| 512 | // TODO!!! check if really no synch is required within the system e.g. to ensure following steps .. |
| 513 | if devEvent == cmn.MibDatabaseSync { |
| 514 | if oo.devState < cmn.MibDatabaseSync { //devState has not been synced yet |
| 515 | oo.devState = cmn.MibDatabaseSync |
| 516 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent) |
| 517 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 518 | } else { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 519 | logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored", |
| 520 | log.Fields{"device-id": oo.deviceID, "state": oo.devState}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 521 | } |
| 522 | } else if devEvent == cmn.MibDownloadDone { |
| 523 | if oo.devState < cmn.MibDownloadDone { //devState has not been synced yet |
| 524 | oo.devState = cmn.MibDownloadDone |
| 525 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(ctx, devEvent) |
| 526 | } else { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 527 | logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored", |
| 528 | log.Fields{"device-id": oo.deviceID, "state": oo.devState}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 529 | } |
| 530 | } else { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 531 | logger.Warnw(ctx, "device-event not yet handled", |
| 532 | log.Fields{"device-id": oo.deviceID, "state": devEvent}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | // RestoreDataFromOnuKvStore - TODO: add comment |
| 537 | func (oo *OnuDeviceEntry) RestoreDataFromOnuKvStore(ctx context.Context) error { |
| 538 | if oo.onuKVStore == nil { |
| 539 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 540 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID)) |
| 541 | } |
| 542 | oo.MutexPersOnuConfig.Lock() |
| 543 | defer oo.MutexPersOnuConfig.Unlock() |
| 544 | oo.SOnuPersistentData = |
Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 545 | onuPersistentData{0, 0, "", "", "", "", "", false, "", "", "", false, false, oo.mibAuditInterval, 0, 0, |
| 546 | make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 547 | oo.mutexOnuKVStore.RLock() |
| 548 | Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath) |
| 549 | oo.mutexOnuKVStore.RUnlock() |
| 550 | if err == nil { |
| 551 | if Value != nil { |
| 552 | logger.Debugw(ctx, "ONU-data read", |
| 553 | log.Fields{"Key": Value.Key, "device-id": oo.deviceID}) |
| 554 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 555 | |
| 556 | if err = json.Unmarshal(tmpBytes, &oo.SOnuPersistentData); err != nil { |
| 557 | logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 558 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)) |
| 559 | } |
| 560 | logger.Debugw(ctx, "ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData, |
| 561 | "device-id": oo.deviceID}) |
| 562 | } else { |
| 563 | logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID}) |
| 564 | return fmt.Errorf("no-ONU-data-found") |
| 565 | } |
| 566 | } else { |
| 567 | logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID}) |
| 568 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID)) |
| 569 | } |
| 570 | return nil |
| 571 | } |
| 572 | |
| 573 | // DeleteDataFromOnuKvStore - TODO: add comment |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 574 | func (oo *OnuDeviceEntry) DeleteDataFromOnuKvStore(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 575 | |
| 576 | if oo.onuKVStore == nil { |
| 577 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 578 | return errors.New("onu-data delete aborted: onuKVStore not set") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 579 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 580 | err := oo.deletePersistentData(ctx) |
| 581 | if err != nil { |
| 582 | logger.Errorf(ctx, "onu-data delete aborted: during kv-access", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 583 | return err |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 584 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 585 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 588 | func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 589 | |
| 590 | logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 591 | oo.MutexPersOnuConfig.Lock() |
| 592 | defer oo.MutexPersOnuConfig.Unlock() |
| 593 | |
| 594 | oo.SOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry |
| 595 | oo.SOnuPersistentData = |
Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 596 | onuPersistentData{0, 0, "", "", "", "", "", false, "", "", "", false, false, oo.mibAuditInterval, 0, 0, |
| 597 | make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID}) |
| 599 | oo.mutexOnuKVStore.Lock() |
| 600 | err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath) |
| 601 | oo.mutexOnuKVStore.Unlock() |
| 602 | if err != nil { |
| 603 | logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 604 | return err |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 605 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 606 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // UpdateOnuKvStore - TODO: add comment |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 610 | func (oo *OnuDeviceEntry) UpdateOnuKvStore(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 611 | |
| 612 | if oo.onuKVStore == nil { |
| 613 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 614 | return errors.New("onu-data update aborted: onuKVStore not set") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 615 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 616 | err := oo.storeDataInOnuKvStore(ctx) |
| 617 | if err != nil { |
| 618 | logger.Errorf(ctx, "onu-data update aborted: during writing process", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 619 | return err |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 620 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 621 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 624 | func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 625 | |
| 626 | oo.MutexPersOnuConfig.Lock() |
| 627 | defer oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 628 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 629 | oo.pOpenOnuAc.RLockMutexDeviceHandlersMap() |
| 630 | if _, exist := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID); !exist { |
| 631 | logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 632 | oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap() |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 633 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 634 | } |
| 635 | oo.baseDeviceHandler.RLockMutexDeletionInProgressFlag() |
| 636 | if oo.baseDeviceHandler.GetDeletionInProgress() { |
| 637 | logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 638 | oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap() |
| 639 | oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag() |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 640 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 641 | } |
| 642 | oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap() |
| 643 | oo.baseDeviceHandler.RUnlockMutexDeletionInProgressFlag() |
| 644 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 645 | //assign values which are not already present when NewOnuDeviceEntry() is called |
| 646 | onuIndication := oo.baseDeviceHandler.GetOnuIndication() |
| 647 | if onuIndication != nil { |
| 648 | oo.SOnuPersistentData.PersOnuID = onuIndication.OnuId |
| 649 | oo.SOnuPersistentData.PersIntfID = onuIndication.IntfId |
| 650 | //TODO: verify usage of these values during restart UC |
| 651 | oo.SOnuPersistentData.PersAdminState = onuIndication.AdminState |
| 652 | oo.SOnuPersistentData.PersOperState = onuIndication.OperState |
| 653 | } else { |
| 654 | logger.Errorw(ctx, "onuIndication not set, unable to load ONU-data", log.Fields{"device-id": oo.deviceID}) |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 655 | return errors.New("onuIndication not set, unable to load ONU-data") |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "SOnuPersistentData": oo.SOnuPersistentData}) |
| 659 | |
| 660 | Value, err := json.Marshal(oo.SOnuPersistentData) |
| 661 | if err != nil { |
| 662 | logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"SOnuPersistentData": oo.SOnuPersistentData, |
| 663 | "device-id": oo.deviceID, "err": err}) |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 664 | return err |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 665 | } |
| 666 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 667 | oo.mutexOnuKVStore.Lock() |
| 668 | err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value) |
| 669 | oo.mutexOnuKVStore.Unlock() |
| 670 | if err != nil { |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 671 | logger.Errorf(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 672 | return err |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 673 | } |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 674 | return nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // UpdateOnuUniTpPath - TODO: add comment |
| 678 | func (oo *OnuDeviceEntry) UpdateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool { |
| 679 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 680 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 681 | no specific concurrency protection to SOnuPersistentData is required here |
| 682 | */ |
| 683 | oo.MutexPersOnuConfig.Lock() |
| 684 | defer oo.MutexPersOnuConfig.Unlock() |
| 685 | |
| 686 | for k, v := range oo.SOnuPersistentData.PersUniConfig { |
| 687 | if v.PersUniID == aUniID { |
| 688 | existingPath, ok := oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] |
| 689 | logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, |
| 690 | "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok}) |
| 691 | if !ok { |
| 692 | logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString}) |
| 693 | } |
| 694 | if existingPath != aPathString { |
| 695 | if aPathString == "" { |
| 696 | //existing entry to be deleted |
| 697 | logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 698 | oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = "" |
| 699 | } else { |
| 700 | //existing entry to be modified |
| 701 | logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 702 | oo.SOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString |
| 703 | } |
| 704 | return true |
| 705 | } |
| 706 | //entry already exists |
| 707 | if aPathString == "" { |
| 708 | //no active TechProfile |
| 709 | logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{ |
| 710 | "device-id": oo.deviceID, "uniID": aUniID}) |
| 711 | } else { |
| 712 | //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here |
| 713 | //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU |
| 714 | // (as here the TechProfile has not been removed with the disable-device before the new enable-device) |
| 715 | logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{ |
| 716 | "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 717 | //no deviceReason update (DeviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario |
| 718 | // (during which the flows are removed/re-assigned but the techProf is left active) |
| 719 | //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it |
| 720 | // (should not be the case, but should not harm or be more robust ...) |
| 721 | // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history |
| 722 | // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config |
| 723 | if oo.pOnuTP != nil { |
| 724 | oo.pOnuTP.SetProfileToDelete(aUniID, aTpID, false) |
| 725 | } |
| 726 | go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID) |
| 727 | } |
| 728 | return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here |
| 729 | } |
| 730 | } |
| 731 | //no entry exists for uniId |
| 732 | |
| 733 | if aPathString == "" { |
| 734 | //delete request in non-existing state , accept as no change |
| 735 | logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
| 736 | return false |
| 737 | } |
| 738 | //new entry to be created |
| 739 | logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 740 | perSubTpPathMap := make(map[uint8]string) |
| 741 | perSubTpPathMap[aTpID] = aPathString |
| 742 | oo.SOnuPersistentData.PersUniConfig = |
| 743 | append(oo.SOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]cmn.UniVlanFlowParams, 0)}) |
| 744 | return true |
| 745 | } |
| 746 | |
| 747 | // UpdateOnuUniFlowConfig - TODO: add comment |
| 748 | func (oo *OnuDeviceEntry) UpdateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]cmn.UniVlanFlowParams) { |
| 749 | |
| 750 | oo.MutexPersOnuConfig.Lock() |
| 751 | defer oo.MutexPersOnuConfig.Unlock() |
| 752 | |
| 753 | for k, v := range oo.SOnuPersistentData.PersUniConfig { |
| 754 | if v.PersUniID == aUniID { |
| 755 | oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams)) |
| 756 | copy(oo.SOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams) |
| 757 | return |
| 758 | } |
| 759 | } |
| 760 | //flow update was faster than tp-config - create PersUniConfig-entry |
| 761 | //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data |
| 762 | // (e.g after flow removal from RemoveUniFlowParams()). |
| 763 | // 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 |
| 764 | // 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 |
| 765 | // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests |
| 766 | tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]cmn.UniVlanFlowParams, len(*aUniVlanFlowParams))} |
| 767 | copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams) |
| 768 | oo.SOnuPersistentData.PersUniConfig = append(oo.SOnuPersistentData.PersUniConfig, tmpConfig) |
| 769 | } |
| 770 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 771 | // ResetKvProcessingErrorIndication - TODO: add comment |
| 772 | func (oo *OnuDeviceEntry) ResetKvProcessingErrorIndication() { |
| 773 | oo.mutexOnuKVStoreProcResult.Lock() |
| 774 | oo.onuKVStoreProcResult = nil |
| 775 | oo.mutexOnuKVStoreProcResult.Unlock() |
| 776 | } |
| 777 | |
| 778 | // GetKvProcessingErrorIndication - TODO: add comment |
| 779 | func (oo *OnuDeviceEntry) GetKvProcessingErrorIndication() error { |
| 780 | oo.mutexOnuKVStoreProcResult.RLock() |
| 781 | value := oo.onuKVStoreProcResult |
| 782 | oo.mutexOnuKVStoreProcResult.RUnlock() |
| 783 | return value |
| 784 | } |
| 785 | |
Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame^] | 786 | // func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) { |
| 787 | // oo.mutexOnuKVStoreProcResult.Lock() |
| 788 | // oo.onuKVStoreProcResult = value |
| 789 | // oo.mutexOnuKVStoreProcResult.Unlock() |
| 790 | // } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 791 | |
| 792 | // IncrementMibDataSync - TODO: add comment |
| 793 | func (oo *OnuDeviceEntry) IncrementMibDataSync(ctx context.Context) { |
| 794 | oo.MutexPersOnuConfig.Lock() |
| 795 | defer oo.MutexPersOnuConfig.Unlock() |
| 796 | if oo.SOnuPersistentData.PersMibDataSyncAdpt < 255 { |
| 797 | oo.SOnuPersistentData.PersMibDataSyncAdpt++ |
| 798 | } else { |
| 799 | // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset |
| 800 | oo.SOnuPersistentData.PersMibDataSyncAdpt = 1 |
| 801 | } |
| 802 | logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.SOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID) |
| 803 | } |
| 804 | |
| 805 | // ModifySwImageInactiveVersion - updates the inactive SW image version stored |
| 806 | func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) { |
| 807 | oo.mutexOnuSwImageIndications.Lock() |
| 808 | defer oo.mutexOnuSwImageIndications.Unlock() |
| 809 | logger.Debugw(ctx, "software-image set inactive version", log.Fields{ |
| 810 | "device-id": oo.deviceID, "version": aImageVersion}) |
| 811 | oo.onuSwImageIndications.InActiveEntityEntry.Version = aImageVersion |
| 812 | //inactive SW version is not part of persistency data (yet) - no need to update that |
| 813 | } |
| 814 | |
| 815 | // ModifySwImageActiveCommit - updates the active SW commit flag stored |
| 816 | func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) { |
| 817 | oo.mutexOnuSwImageIndications.Lock() |
| 818 | defer oo.mutexOnuSwImageIndications.Unlock() |
| 819 | logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{ |
| 820 | "device-id": oo.deviceID, "committed": aCommitted}) |
| 821 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = aCommitted |
| 822 | //commit flag is not part of persistency data (yet) - no need to update that |
| 823 | } |
| 824 | |
| 825 | // GetActiveImageVersion - returns the active SW image version stored |
| 826 | func (oo *OnuDeviceEntry) GetActiveImageVersion(ctx context.Context) string { |
| 827 | oo.mutexOnuSwImageIndications.RLock() |
| 828 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 829 | value := oo.onuSwImageIndications.ActiveEntityEntry.Version |
| 830 | oo.mutexOnuSwImageIndications.RUnlock() |
| 831 | return value |
| 832 | } |
| 833 | oo.mutexOnuSwImageIndications.RUnlock() |
| 834 | logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID}) |
| 835 | return "" |
| 836 | } |
| 837 | |
| 838 | // GetInactiveImageVersion - TODO: add comment |
| 839 | func (oo *OnuDeviceEntry) GetInactiveImageVersion(ctx context.Context) string { |
| 840 | oo.mutexOnuSwImageIndications.RLock() |
| 841 | if oo.onuSwImageIndications.InActiveEntityEntry.Valid { |
| 842 | value := oo.onuSwImageIndications.InActiveEntityEntry.Version |
| 843 | oo.mutexOnuSwImageIndications.RUnlock() |
| 844 | return value |
| 845 | } |
| 846 | oo.mutexOnuSwImageIndications.RUnlock() |
| 847 | logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID}) |
| 848 | return "" |
| 849 | } |
| 850 | |
| 851 | func (oo *OnuDeviceEntry) buildMibTemplatePath() string { |
| 852 | oo.MutexPersOnuConfig.RLock() |
| 853 | defer oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 6a001d0 | 2022-06-15 08:32:48 +0000 | [diff] [blame] | 854 | return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.SOnuPersistentData.PersVendorID, oo.SOnuPersistentData.PersVersion, |
| 855 | oo.SOnuPersistentData.PersActiveSwVersion) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | // AllocateFreeTcont - TODO: add comment |
| 859 | func (oo *OnuDeviceEntry) AllocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) { |
| 860 | logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID, |
| 861 | "allocated-instances": oo.SOnuPersistentData.PersTcontMap}) |
| 862 | |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 863 | oo.MutexPersOnuConfig.Lock() |
| 864 | defer oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 865 | if entityID, ok := oo.SOnuPersistentData.PersTcontMap[allocID]; ok { |
| 866 | //tcont already allocated before, return the used instance-id |
| 867 | return entityID, true, nil |
| 868 | } |
| 869 | //First allocation of tcont. Find a free instance |
| 870 | if tcontInstKeys := oo.pOnuDB.GetSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 { |
| 871 | logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys}) |
| 872 | for _, instID := range tcontInstKeys { |
| 873 | instExist := false |
| 874 | //If this instance exist in map, it means it is not empty. It is allocated before |
| 875 | for _, v := range oo.SOnuPersistentData.PersTcontMap { |
| 876 | if v == instID { |
| 877 | instExist = true |
| 878 | break |
| 879 | } |
| 880 | } |
| 881 | if !instExist { |
| 882 | oo.SOnuPersistentData.PersTcontMap[allocID] = instID |
| 883 | return instID, false, nil |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | return 0, false, fmt.Errorf(fmt.Sprintf("no-free-tcont-left-for-device-%s", oo.deviceID)) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | // FreeTcont - TODO: add comment |
| 891 | func (oo *OnuDeviceEntry) FreeTcont(ctx context.Context, allocID uint16) { |
| 892 | logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID}) |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 893 | oo.MutexPersOnuConfig.Lock() |
| 894 | defer oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 895 | delete(oo.SOnuPersistentData.PersTcontMap, allocID) |
| 896 | } |
| 897 | |
| 898 | // GetDevOmciCC - TODO: add comment |
| 899 | func (oo *OnuDeviceEntry) GetDevOmciCC() *cmn.OmciCC { |
| 900 | return oo.PDevOmciCC |
| 901 | } |
| 902 | |
| 903 | // GetOnuDB - TODO: add comment |
| 904 | func (oo *OnuDeviceEntry) GetOnuDB() *devdb.OnuDeviceDB { |
| 905 | return oo.pOnuDB |
| 906 | } |
| 907 | |
| 908 | // GetPersSerialNumber - TODO: add comment |
| 909 | func (oo *OnuDeviceEntry) GetPersSerialNumber() string { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 910 | oo.MutexPersOnuConfig.RLock() |
| 911 | defer oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 912 | value := oo.SOnuPersistentData.PersSerialNumber |
| 913 | return value |
| 914 | } |
| 915 | |
| 916 | // GetPersVendorID - TODO: add comment |
| 917 | func (oo *OnuDeviceEntry) GetPersVendorID() string { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 918 | oo.MutexPersOnuConfig.RLock() |
| 919 | defer oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 920 | value := oo.SOnuPersistentData.PersVendorID |
| 921 | return value |
| 922 | } |
| 923 | |
Holger Hildebrandt | 0edf5b0 | 2022-05-04 14:19:43 +0000 | [diff] [blame] | 924 | // GetPersIsExtOmciSupported - TODO: add comment |
| 925 | func (oo *OnuDeviceEntry) GetPersIsExtOmciSupported() bool { |
| 926 | oo.MutexPersOnuConfig.RLock() |
| 927 | defer oo.MutexPersOnuConfig.RUnlock() |
| 928 | value := oo.SOnuPersistentData.PersIsExtOmciSupported |
| 929 | return value |
| 930 | } |
| 931 | |
Holger Hildebrandt | 6a001d0 | 2022-06-15 08:32:48 +0000 | [diff] [blame] | 932 | // GetPersVersion - TODO: add comment |
| 933 | func (oo *OnuDeviceEntry) GetPersVersion() string { |
| 934 | oo.MutexPersOnuConfig.RLock() |
| 935 | defer oo.MutexPersOnuConfig.RUnlock() |
| 936 | value := oo.SOnuPersistentData.PersVersion |
| 937 | return value |
| 938 | } |
| 939 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 940 | // GetPersEquipmentID - TODO: add comment |
| 941 | func (oo *OnuDeviceEntry) GetPersEquipmentID() string { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 942 | oo.MutexPersOnuConfig.RLock() |
| 943 | defer oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 944 | value := oo.SOnuPersistentData.PersEquipmentID |
| 945 | return value |
| 946 | } |
| 947 | |
| 948 | // GetMibUploadFsmCommChan - TODO: add comment |
| 949 | func (oo *OnuDeviceEntry) GetMibUploadFsmCommChan() chan cmn.Message { |
| 950 | return oo.PMibUploadFsm.CommChan |
| 951 | } |
| 952 | |
| 953 | // GetMibDownloadFsmCommChan - TODO: add comment |
| 954 | func (oo *OnuDeviceEntry) GetMibDownloadFsmCommChan() chan cmn.Message { |
| 955 | return oo.PMibDownloadFsm.CommChan |
| 956 | } |
| 957 | |
| 958 | // GetOmciRebootMsgRevChan - TODO: add comment |
| 959 | func (oo *OnuDeviceEntry) GetOmciRebootMsgRevChan() chan cmn.Message { |
| 960 | return oo.omciRebootMessageReceivedChannel |
| 961 | } |
| 962 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 963 | // GetPersActiveSwVersion - TODO: add comment |
| 964 | func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 965 | oo.MutexPersOnuConfig.RLock() |
| 966 | defer oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 967 | return oo.SOnuPersistentData.PersActiveSwVersion |
| 968 | } |
| 969 | |
| 970 | // SetPersActiveSwVersion - TODO: add comment |
| 971 | func (oo *OnuDeviceEntry) SetPersActiveSwVersion(value string) { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 972 | oo.MutexPersOnuConfig.Lock() |
| 973 | defer oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 974 | oo.SOnuPersistentData.PersActiveSwVersion = value |
| 975 | } |
| 976 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 977 | // setReconcilingFlows - TODO: add comment |
| 978 | func (oo *OnuDeviceEntry) setReconcilingFlows(value bool) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 979 | oo.mutexReconcilingFlowsFlag.Lock() |
| 980 | oo.reconcilingFlows = value |
| 981 | oo.mutexReconcilingFlowsFlag.Unlock() |
| 982 | } |
| 983 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 984 | // SendChReconcilingFlowsFinished - TODO: add comment |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 985 | func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 986 | if oo != nil { //if the object still exists (might have been already deleted in background) |
| 987 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 988 | select { |
| 989 | case oo.chReconcilingFlowsFinished <- value: |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 990 | logger.Info(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 991 | default: |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 992 | logger.Infow(ctx, "reconciling - flows finished not sent!", log.Fields{"device-id": oo.deviceID}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 993 | } |
| 994 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 995 | } |
| 996 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 997 | // isReconcilingFlows - TODO: add comment |
| 998 | func (oo *OnuDeviceEntry) isReconcilingFlows() bool { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 999 | oo.mutexReconcilingFlowsFlag.RLock() |
| 1000 | value := oo.reconcilingFlows |
| 1001 | oo.mutexReconcilingFlowsFlag.RUnlock() |
| 1002 | return value |
| 1003 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 1004 | |
| 1005 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 1006 | func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 1007 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 1008 | oo.baseDeviceHandler = nil |
| 1009 | oo.pOnuTP = nil |
| 1010 | if oo.PDevOmciCC != nil { |
| 1011 | oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID) |
| 1012 | } |
| 1013 | oo.PDevOmciCC = nil |
| 1014 | } |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 1015 | |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1016 | // SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 1017 | func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) { |
| 1018 | |
| 1019 | oo.MutexPersOnuConfig.RLock() |
| 1020 | context := make(map[string]string) |
| 1021 | context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10) |
| 1022 | context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10) |
| 1023 | context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber |
| 1024 | oo.MutexPersOnuConfig.RUnlock() |
| 1025 | |
| 1026 | deviceEvent := &voltha.DeviceEvent{ |
| 1027 | ResourceId: oo.deviceID, |
| 1028 | DeviceEventName: aDeviceEventName, |
| 1029 | Description: aDescription, |
| 1030 | Context: context, |
| 1031 | } |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 1032 | logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": oo.deviceID}) |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 1033 | _ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix()) |
| 1034 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 1035 | |
| 1036 | // IsMIBTemplateGenerated checks if a MIB Template is already present for this type of ONT. |
| 1037 | func (oo *OnuDeviceEntry) IsMIBTemplateGenerated(ctx context.Context) bool { |
| 1038 | |
| 1039 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 1040 | defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
| 1041 | |
| 1042 | if _, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); !exist { |
| 1043 | logger.Infow(ctx, "MIB template not Generated , further proceed to do MIB sync upload ", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1044 | return false |
| 1045 | } |
| 1046 | return true |
| 1047 | } |