blob: 18bd1efbfa5fc409f51405523a0e6021eed9a3dd [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2 * Copyright 2020-present Open Networking Foundation
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
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
Holger Hildebrandt47555e72020-09-21 11:07:24 +000022 "encoding/json"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000023 "errors"
Holger Hildebrandt47555e72020-09-21 11:07:24 +000024 "fmt"
25 "sync"
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +000026 "time"
27
ozgecanetsiae11479f2020-07-06 09:44:47 +030028 "github.com/opencord/omci-lib-go"
29 me "github.com/opencord/omci-lib-go/generated"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000030
Holger Hildebrandtfa074992020-03-27 15:42:06 +000031 //"sync"
32 //"time"
33
34 "github.com/looplab/fsm"
Girish Gowdra50e56422021-06-01 16:46:04 -070035 "github.com/opencord/voltha-lib-go/v5/pkg/adapters/adapterif"
36 "github.com/opencord/voltha-lib-go/v5/pkg/db"
37 "github.com/opencord/voltha-lib-go/v5/pkg/db/kvstore"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000038
Girish Gowdra50e56422021-06-01 16:46:04 -070039 //"github.com/opencord/voltha-lib-go/v5/pkg/kafka"
40 "github.com/opencord/voltha-lib-go/v5/pkg/log"
dbainbri4d3a0dc2020-12-02 00:33:42 +000041 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
42 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
43 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000044)
45
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000046const (
mpagenko1cc3cb42020-07-27 15:24:38 +000047 // events of MibUpload FSM
48 ulEvStart = "ulEvStart"
49 ulEvResetMib = "ulEvResetMib"
50 ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053051 ulEvGetEquipmentID = "ulEvGetEquipmentId"
mpagenko1cc3cb42020-07-27 15:24:38 +000052 ulEvGetFirstSwVersion = "ulEvGetFirstSwVersion"
53 ulEvGetSecondSwVersion = "ulEvGetSecondSwVersion"
54 ulEvGetMacAddress = "ulEvGetMacAddress"
55 ulEvGetMibTemplate = "ulEvGetMibTemplate"
56 ulEvUploadMib = "ulEvUploadMib"
57 ulEvExamineMds = "ulEvExamineMds"
58 ulEvSuccess = "ulEvSuccess"
59 ulEvMismatch = "ulEvMismatch"
60 ulEvAuditMib = "ulEvAuditMib"
61 ulEvForceResync = "ulEvForceResync"
62 ulEvDiffsFound = "ulEvDiffsFound"
63 ulEvTimeout = "ulEvTimeout"
64 ulEvStop = "ulEvStop"
65)
66const (
67 // states of MibUpload FSM
68 ulStDisabled = "ulStDisabled"
69 ulStStarting = "ulStStarting"
70 ulStResettingMib = "ulStResettingMib"
71 ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053072 ulStGettingEquipmentID = "ulStGettingEquipmentID"
mpagenko1cc3cb42020-07-27 15:24:38 +000073 ulStGettingFirstSwVersion = "ulStGettingFirstSwVersion"
74 ulStGettingSecondSwVersion = "ulStGettingSecondSwVersion"
75 ulStGettingMacAddress = "ulStGettingMacAddress"
76 ulStGettingMibTemplate = "ulStGettingMibTemplate"
77 ulStUploading = "ulStUploading"
Holger Hildebrandt10d98192021-01-27 15:29:31 +000078 ulStUploadDone = "ulStUploadDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000079 ulStInSync = "ulStInSync"
80 ulStExaminingMds = "ulStExaminingMds"
81 ulStResynchronizing = "ulStResynchronizing"
Holger Hildebrandtbe523842021-03-10 10:47:18 +000082 ulStExaminingMdsSuccess = "ulStExaminingMdsSuccess"
mpagenko1cc3cb42020-07-27 15:24:38 +000083 ulStAuditing = "ulStAuditing"
Holger Hildebrandt10d98192021-01-27 15:29:31 +000084 ulStReAuditing = "ulStReAuditing"
mpagenko1cc3cb42020-07-27 15:24:38 +000085 ulStOutOfSync = "ulStOutOfSync"
86)
Holger Hildebrandt10d98192021-01-27 15:29:31 +000087const cMibUlFsmIdleState = ulStInSync
mpagenko1cc3cb42020-07-27 15:24:38 +000088
89const (
90 // events of MibDownload FSM
91 dlEvStart = "dlEvStart"
92 dlEvCreateGal = "dlEvCreateGal"
93 dlEvRxGalResp = "dlEvRxGalResp"
94 dlEvRxOnu2gResp = "dlEvRxOnu2gResp"
95 dlEvRxBridgeResp = "dlEvRxBridgeResp"
96 dlEvTimeoutSimple = "dlEvTimeoutSimple"
97 dlEvTimeoutBridge = "dlEvTimeoutBridge"
98 dlEvReset = "dlEvReset"
99 dlEvRestart = "dlEvRestart"
100)
101const (
102 // states of MibDownload FSM
103 dlStDisabled = "dlStDisabled"
104 dlStStarting = "dlStStarting"
105 dlStCreatingGal = "dlStCreatingGal"
106 dlStSettingOnu2g = "dlStSettingOnu2g"
107 dlStBridgeInit = "dlStBridgeInit"
108 dlStDownloaded = "dlStDownloaded"
109 dlStResetting = "dlStResetting"
110)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000111const cMibDlFsmIdleState = dlStDisabled
mpagenko1cc3cb42020-07-27 15:24:38 +0000112
113const (
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800114 // NOTE that this hardcoded to service/voltha as the MIB template is shared across stacks
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000115 cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
mpagenkoaf801632020-07-03 10:00:42 +0000116 cSuffixMibTemplateKvStore = "%s/%s/%s"
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800117 cBasePathOnuKVStore = "%s/openonu"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000118)
119
Himani Chawla6d2ae152020-09-02 13:11:20 +0530120// OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000121type OnuDeviceEvent int
122
123const (
124 // Events of interest to Device Adapters and OpenOMCI State Machines
Himani Chawla6d2ae152020-09-02 13:11:20 +0530125
126 // DeviceStatusInit - default start state
mpagenkofc4f56e2020-11-04 17:17:49 +0000127 DeviceStatusInit OnuDeviceEvent = iota
Himani Chawla6d2ae152020-09-02 13:11:20 +0530128 // MibDatabaseSync - MIB database sync (upload done)
mpagenkofc4f56e2020-11-04 17:17:49 +0000129 MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530130 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
mpagenkofc4f56e2020-11-04 17:17:49 +0000131 OmciCapabilitiesDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530132 // MibDownloadDone - // MIB download done
mpagenkofc4f56e2020-11-04 17:17:49 +0000133 MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530134 // UniLockStateDone - Uni ports admin set to lock
mpagenkofc4f56e2020-11-04 17:17:49 +0000135 UniLockStateDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530136 // UniUnlockStateDone - Uni ports admin set to unlock
mpagenkofc4f56e2020-11-04 17:17:49 +0000137 UniUnlockStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000138 // UniDisableStateDone - Uni ports admin set to lock based on device disable
mpagenkofc4f56e2020-11-04 17:17:49 +0000139 UniDisableStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000140 // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable
mpagenkofc4f56e2020-11-04 17:17:49 +0000141 UniEnableStateDone
Holger Hildebrandtda15a092022-01-07 15:30:49 +0000142 // UniEnableStateFailed - Uni ports admin set to unlock failure based on device re-enable
143 UniEnableStateFailed
Himani Chawla6d2ae152020-09-02 13:11:20 +0530144 // PortLinkUp - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000145 PortLinkUp
Himani Chawla6d2ae152020-09-02 13:11:20 +0530146 // PortLinkDw - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000147 PortLinkDw
Himani Chawla6d2ae152020-09-02 13:11:20 +0530148 // OmciAniConfigDone - AniSide config according to TechProfile done
mpagenkofc4f56e2020-11-04 17:17:49 +0000149 OmciAniConfigDone
150 // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed
151 OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone!
mpagenkof1fc3862021-02-16 10:09:52 +0000152 // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add with request to write kvStore
mpagenkofc4f56e2020-11-04 17:17:49 +0000153 OmciVlanFilterAddDone
mpagenkof1fc3862021-02-16 10:09:52 +0000154 // OmciVlanFilterAddDoneNoKvStore - Omci Vlan config done according to flow-add without writing kvStore
155 OmciVlanFilterAddDoneNoKvStore // needs to be the successor of OmciVlanFilterAddDone!
156 // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove with request to write kvStore
157 OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDoneNoKvStore!
158 // OmciVlanFilterRemDoneNoKvStore - Omci Vlan config done according to flow-remove without writing kvStore
159 OmciVlanFilterRemDoneNoKvStore // needs to be the successor of OmciVlanFilterRemDone!
mpagenko80622a52021-02-09 16:53:23 +0000160 // OmciOnuSwUpgradeDone - SoftwareUpgrade to ONU finished
161 OmciOnuSwUpgradeDone
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000162 // Add other events here as needed (alarms separate???)
163)
164
mpagenko7d6bb022021-03-11 15:07:55 +0000165//AdapterFsm related error string
166//error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log
167// but not used that way so far (permit error log even for wanted cancellation)
168const cErrWaitAborted = "waitResponse aborted"
169
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170type activityDescr struct {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000171 databaseClass func(context.Context) error
Himani Chawla4d908332020-08-31 12:30:20 +0530172 //advertiseEvents bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000173 auditInterval time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174 //tasks map[string]func() error
175}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530176
177// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000178type OmciDeviceFsms map[string]activityDescr
179
Himani Chawla6d2ae152020-09-02 13:11:20 +0530180// AdapterFsm - Adapter FSM details including channel, event and device
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000181type AdapterFsm struct {
182 fsmName string
183 deviceID string
184 commChan chan Message
185 pFsm *fsm.FSM
186}
187
Himani Chawla6d2ae152020-09-02 13:11:20 +0530188//NewAdapterFsm - FSM details including event, device and channel.
189func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000190 aFsm := &AdapterFsm{
Himani Chawla6d2ae152020-09-02 13:11:20 +0530191 fsmName: aName,
192 deviceID: aDeviceID,
193 commChan: aCommChannel,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000194 }
195 return aFsm
196}
197
198//Start starts (logs) the omci agent
dbainbri4d3a0dc2020-12-02 00:33:42 +0000199func (oo *AdapterFsm) logFsmStateChange(ctx context.Context, e *fsm.Event) {
200 logger.Debugw(ctx, "FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000201 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
202}
203
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000204//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000205
206const (
Himani Chawla6d2ae152020-09-02 13:11:20 +0530207 firstSwImageMeID = 0
208 secondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000209)
mpagenko15ff4a52021-03-02 10:09:20 +0000210const ( //definitions as per G.988 softwareImage::IsCommitted
211 swIsUncommitted = 0
212 swIsCommitted = 1
213)
214const ( //definitions as per G.988 softwareImage::IsActive
mpagenko9c225032021-10-15 14:26:49 +0000215 swIsInactive = 0
216 swIsActive = 1
mpagenko15ff4a52021-03-02 10:09:20 +0000217)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000218const ( //definitions as per G.988 softwareImage::IsValid
219 //swIsInvalid = 0 not yet used
220 swIsValid = 1
221)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000222const onuDataMeID = 0
Himani Chawla6d2ae152020-09-02 13:11:20 +0530223const onugMeID = 0
224const onu2gMeID = 0
225const ipHostConfigDataMeID = 1
226const onugSerialNumberLen = 8
227const omciMacAddressLen = 6
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000228
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000229const cEmptyMacAddrString = "000000000000"
230const cEmptySerialNumberString = "0000000000000000"
231
mpagenko15ff4a52021-03-02 10:09:20 +0000232type sEntrySwImageIndication struct {
233 valid bool
234 entityID uint16
235 version string
236 isCommitted uint8
237}
238type sSwImageIndications struct {
239 activeEntityEntry sEntrySwImageIndication
240 inactiveEntityEntry sEntrySwImageIndication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000241}
242
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000243type uniPersConfig struct {
244 PersUniID uint8 `json:"uni_id"`
Girish Gowdra041dcb32020-11-16 16:54:30 -0800245 PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map
246 PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000247}
248
249type onuPersistentData struct {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700250 PersOnuID uint32 `json:"onu_id"`
251 PersIntfID uint32 `json:"intf_id"`
252 PersSerialNumber string `json:"serial_number"`
253 PersMacAddress string `json:"mac_address"`
254 PersVendorID string `json:"vendor_id"`
255 PersEquipmentID string `json:"equipment_id"`
256 PersActiveSwVersion string `json:"active_sw_version"`
257 PersAdminState string `json:"admin_state"`
258 PersOperState string `json:"oper_state"`
259 PersUniUnlockDone bool `json:"uni_unlock_done"`
260 PersUniDisableDone bool `json:"uni_disable_done"`
261 PersMibAuditInterval time.Duration `json:"mib_audit_interval"`
262 PersMibLastDbSync uint32 `json:"mib_last_db_sync"`
263 PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"`
264 PersUniConfig []uniPersConfig `json:"uni_config"`
265 PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"`
266 PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000267}
268
Himani Chawla6d2ae152020-09-02 13:11:20 +0530269// OnuDeviceEntry - ONU device info and FSM events.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000270type OnuDeviceEntry struct {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000271 deviceID string
272 baseDeviceHandler *deviceHandler
273 pOpenOnuAc *OpenONUAC
274 coreProxy adapterif.CoreProxy
275 adapterProxy adapterif.AdapterProxy
276 PDevOmciCC *omciCC
277 pOnuDB *onuDeviceDB
278 mibTemplateKVStore *db.Backend
279 mutexPersOnuConfig sync.RWMutex
280 sOnuPersistentData onuPersistentData
281 mibTemplatePath string
282 mutexOnuKVStore sync.RWMutex
283 onuKVStore *db.Backend
284 onuKVStorePath string
285 mutexOnuKVStoreProcResult sync.RWMutex
286 onuKVStoreProcResult error //error indication of processing
287 chOnuKvProcessingStep chan uint8
288 mutexOnuSwImageIndications sync.RWMutex
289 onuSwImageIndications sSwImageIndications
290 mutexOnuImageStatus sync.RWMutex
291 pOnuImageStatus *OnuImageStatus
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292 //lockDeviceEntries sync.RWMutex
dbainbri4d3a0dc2020-12-02 00:33:42 +0000293 mibDbClass func(context.Context) error
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000294 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295 devState OnuDeviceEvent
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000296 // Audit and MDS
Himani Chawla075f1642021-03-15 19:23:24 +0530297 mibAuditInterval time.Duration
298 alarmAuditInterval time.Duration
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000299 // TODO: periodical mib resync will be implemented with story VOL-3792
300 //mibNextDbResync uint32
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000301
302 // for mibUpload
Girish Gowdraef7b4ad2022-02-09 10:43:15 -0800303 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
304 mutexLastTxParamStruct sync.RWMutex
305 lastTxParamStruct sLastTxMeParameter
306 mibSyncMsgProcessorRunning bool
307 mutexMibSyncMsgProcessorRunning sync.RWMutex
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000308 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000309 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
310 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
311 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300312 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
313 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000314}
315
Himani Chawla6d2ae152020-09-02 13:11:20 +0530316//newOnuDeviceEntry returns a new instance of a OnuDeviceEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000317//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000318func newOnuDeviceEntry(ctx context.Context, dh *deviceHandler) *OnuDeviceEntry {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000319 logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": dh.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000320 var onuDeviceEntry OnuDeviceEntry
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000321 onuDeviceEntry.deviceID = dh.deviceID
322 onuDeviceEntry.baseDeviceHandler = dh
323 onuDeviceEntry.pOpenOnuAc = dh.pOpenOnuAc
324 onuDeviceEntry.coreProxy = dh.coreProxy
325 onuDeviceEntry.adapterProxy = dh.AdapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000326 onuDeviceEntry.devState = DeviceStatusInit
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000327 onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700328 onuDeviceEntry.sOnuPersistentData.PersTcontMap = make(map[uint16]uint16)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000329 onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300330 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000331 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
332 //OMCI related databases are on a per-agent basis. State machines and tasks
333 //are per ONU Vendor
334 //
335 // MIB Synchronization Database - possible overloading from arguments
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000336 if dh.pOpenOnuAc.pSupportedFsms != nil {
337 onuDeviceEntry.supportedFsms = *dh.pOpenOnuAc.pSupportedFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000338 } else {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000339 // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only!
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000340 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000341 // use some internal defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000342 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
343 "mib-synchronizer": {
344 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530345 onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530346 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000347 dh.pOpenOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000348 // map[string]func() error{
349 // "mib-upload": onuDeviceEntry.MibUploadTask,
350 // "mib-template": onuDeviceEntry.MibTemplateTask,
351 // "get-mds": onuDeviceEntry.GetMdsTask,
352 // "mib-audit": onuDeviceEntry.GetMdsTask,
353 // "mib-resync": onuDeviceEntry.MibResyncTask,
354 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
355 // },
356 },
357 }
358 }
359 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Debug(ctx, "access2mibDbClass")
361 go onuDeviceEntry.mibDbClass(ctx)
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +0000362 if !dh.isReconciling() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000363 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditInterval
364 onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval
Himani Chawla075f1642021-03-15 19:23:24 +0530365 onuDeviceEntry.alarmAuditInterval = dh.pOpenOnuAc.alarmAuditInterval
366 onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000367 } else {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000368 logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": dh.deviceID})
369 // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000370 // vendor- or deviceID-specific configurations via voltctl-commands
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000371 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval
Himani Chawla075f1642021-03-15 19:23:24 +0530372 onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000373 }
Himani Chawla075f1642021-03-15 19:23:24 +0530374 logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval,
375 "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000376 // TODO: periodical mib resync will be implemented with story VOL-3792
377 //onuDeviceEntry.mibNextDbResync = 0
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000378
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000379 // Omci related Mib upload sync state machine
380 mibUploadChan := make(chan Message, 2048)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000381 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", dh.deviceID, mibUploadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000382 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000383 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000384 fsm.Events{
385
mpagenko1cc3cb42020-07-27 15:24:38 +0000386 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000387
mpagenko1cc3cb42020-07-27 15:24:38 +0000388 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
389 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530390 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
391 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000392 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
393 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
394 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000395
mpagenko1cc3cb42020-07-27 15:24:38 +0000396 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
397 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000398
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000399 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploadDone},
400 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStUploadDone},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000401
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000402 {Name: ulEvSuccess, Src: []string{ulStUploadDone}, Dst: ulStInSync},
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000403 //{Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
404 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStExaminingMdsSuccess},
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000405 // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers
406 // mib-reset and new provisioning at this point
407 //{Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
408 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResettingMib},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000409
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000410 {Name: ulEvSuccess, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStInSync},
411 {Name: ulEvMismatch, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStResettingMib},
412
mpagenko1cc3cb42020-07-27 15:24:38 +0000413 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000414
mpagenko1cc3cb42020-07-27 15:24:38 +0000415 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
416 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000417
mpagenko1cc3cb42020-07-27 15:24:38 +0000418 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000419 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStReAuditing},
mpagenko1cc3cb42020-07-27 15:24:38 +0000420 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000421
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000422 {Name: ulEvSuccess, Src: []string{ulStReAuditing}, Dst: ulStInSync},
423 {Name: ulEvMismatch, Src: []string{ulStReAuditing}, Dst: ulStResettingMib},
424
mpagenko1cc3cb42020-07-27 15:24:38 +0000425 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
426 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000427
Himani Chawla4d908332020-08-31 12:30:20 +0530428 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000429 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000430 ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000431
Himani Chawla4d908332020-08-31 12:30:20 +0530432 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000433 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000434 ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000435 },
436
437 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(ctx, e) },
439 "enter_" + ulStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) },
440 "enter_" + ulStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) },
441 "enter_" + ulStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) },
442 "enter_" + ulStGettingEquipmentID: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(ctx, e) },
443 "enter_" + ulStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) },
444 "enter_" + ulStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) },
445 "enter_" + ulStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) },
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000446 "enter_" + ulStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000447 "enter_" + ulStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) },
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000448 "enter_" + ulStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 "enter_" + ulStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) },
450 "enter_" + ulStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) },
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000451 "enter_" + ulStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452 "enter_" + ulStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) },
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000453 "enter_" + ulStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454 "enter_" + ulStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) },
455 "enter_" + ulStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000456 },
457 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000458 // Omci related Mib download state machine
459 mibDownloadChan := make(chan Message, 2048)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000460 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", dh.deviceID, mibDownloadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000461 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000462 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000463 fsm.Events{
464
mpagenko1cc3cb42020-07-27 15:24:38 +0000465 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000466
mpagenko1cc3cb42020-07-27 15:24:38 +0000467 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
468 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
469 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000470 // the bridge state is used for multi ME config for alle UNI related ports
471 // maybe such could be reflected in the state machine as well (port number parametrized)
472 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000473 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000474
mpagenko1cc3cb42020-07-27 15:24:38 +0000475 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
476 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000477
mpagenko1cc3cb42020-07-27 15:24:38 +0000478 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
479 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
480 // exceptional treatment for all states except dlStResetting
481 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
482 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000483 },
484
485 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000486 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(ctx, e) },
487 "enter_" + dlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) },
488 "enter_" + dlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) },
489 "enter_" + dlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) },
490 "enter_" + dlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) },
491 "enter_" + dlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) },
492 "enter_" + dlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000493 },
494 )
495 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000496 logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": dh.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000497 // TODO some specific error treatment - or waiting for crash ?
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000498 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000499
dbainbri4d3a0dc2020-12-02 00:33:42 +0000500 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000501 if onuDeviceEntry.mibTemplateKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000502 logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000503 log.Fields{"device-id": dh.deviceID, "service": cBasePathMibTemplateKvStore})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000504 }
505
506 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800507 baseKvStorePath := fmt.Sprintf(cBasePathOnuKVStore, dh.pOpenOnuAc.cm.Backend.PathPrefix)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000508 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, baseKvStorePath)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000509 if onuDeviceEntry.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000510 logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800511 log.Fields{"device-id": dh.deviceID, "service": baseKvStorePath})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000512 }
513
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000514 // Alarm Synchronization Database
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530515
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000516 //self._alarm_db = None
517 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
518 return &onuDeviceEntry
519}
520
Himani Chawla6d2ae152020-09-02 13:11:20 +0530521//start starts (logs) the omci agent
522func (oo *OnuDeviceEntry) start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000523 logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000524 if oo.PDevOmciCC == nil {
mpagenko900ee4b2020-10-12 11:56:34 +0000525 oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
526 oo.coreProxy, oo.adapterProxy)
527 if oo.PDevOmciCC == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000528 logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000529 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
530 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000531 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000532 return nil
533}
534
mpagenko900ee4b2020-10-12 11:56:34 +0000535//stop stops/resets the omciCC
536func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537 logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000538 if abResetOmciCC && (oo.PDevOmciCC != nil) {
539 _ = oo.PDevOmciCC.stop(ctx)
540 }
541 //to allow for all event notifications again when re-using the device and omciCC
542 oo.devState = DeviceStatusInit
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000543 return nil
544}
545
Himani Chawla6d2ae152020-09-02 13:11:20 +0530546func (oo *OnuDeviceEntry) reboot(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000547 logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000548 if oo.PDevOmciCC != nil {
Girish Gowdra0b235842021-03-09 13:06:46 -0800549 if err := oo.PDevOmciCC.sendReboot(ctx, oo.pOpenOnuAc.omciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550 logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000551 return err
552 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300553 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300554 return nil
555}
556
dbainbri4d3a0dc2020-12-02 00:33:42 +0000557func (oo *OnuDeviceEntry) waitForRebootResponse(ctx context.Context, responseChannel chan Message) error {
ozgecanetsiae11479f2020-07-06 09:44:47 +0300558 select {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000559 case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
dbainbri4d3a0dc2020-12-02 00:33:42 +0000560 logger.Warnw(ctx, "Reboot timeout", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200561 return fmt.Errorf("rebootTimeout")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300562 case data := <-responseChannel:
563 switch data.Data.(OmciMessage).OmciMsg.MessageType {
564 case omci.RebootResponseType:
565 {
566 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
567 if msgLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200568 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300569 }
Andrea Campanellabef4e542020-10-22 11:01:28 +0200570 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300571 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200572 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300573 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000574 logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300575 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576 logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300577 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
Andrea Campanellabef4e542020-10-22 11:01:28 +0200578 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200579 msgObj.Result, oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300580 }
581 return nil
582 }
583 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000584 logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200585 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300586 }
587}
588
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000589//Relay the InSync message via Handler to Rw core - Status update
dbainbri4d3a0dc2020-12-02 00:33:42 +0000590func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent OnuDeviceEvent) {
591 logger.Debugw(ctx, "relaying system-event", log.Fields{"Event": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000592 // decouple the handler transfer from further processing here
593 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
Himani Chawla26e555c2020-08-31 12:30:20 +0530594 if devEvent == MibDatabaseSync {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000595 if oo.devState < MibDatabaseSync { //devState has not been synced yet
596 oo.devState = MibDatabaseSync
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000598 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
599 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000600 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000601 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530602 } else if devEvent == MibDownloadDone {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000603 if oo.devState < MibDownloadDone { //devState has not been synced yet
604 oo.devState = MibDownloadDone
dbainbri4d3a0dc2020-12-02 00:33:42 +0000605 go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000606 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000608 }
609 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000610 logger.Warnw(ctx, "device-event not yet handled", log.Fields{"state": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000611 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000612}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000613
614func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error {
615 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000616 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000617 return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID))
618 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000619 oo.mutexPersOnuConfig.Lock()
620 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000621 oo.sOnuPersistentData =
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700622 onuPersistentData{0, 0, "", "", "", "", "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000623 oo.mutexOnuKVStore.RLock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000624 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000625 oo.mutexOnuKVStore.RUnlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000626 if err == nil {
627 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000628 logger.Debugw(ctx, "ONU-data read",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000629 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
630 tmpBytes, _ := kvstore.ToByte(Value.Value)
631
632 if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000633 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000634 return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID))
635 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000636 logger.Debugw(ctx, "ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000637 "device-id": oo.deviceID})
638 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000639 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000640 return fmt.Errorf("no-ONU-data-found")
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000641 }
642 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000644 return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID))
645 }
646 return nil
647}
648
649func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
650 defer wg.Done()
651
652 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000653 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000654 oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: onuKVStore not set"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000655 return
656 }
657 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
658 go oo.deletePersistentData(ctx, processingStep)
659 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
660 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000661 logger.Debugw(ctx, "ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000662 oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: during kv-access"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000663 return
664 }
665}
666
667func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) {
668
dbainbri4d3a0dc2020-12-02 00:33:42 +0000669 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000670
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000671 oo.mutexPersOnuConfig.Lock()
672 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000673
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000674 oo.sOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
675 oo.sOnuPersistentData =
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700676 onuPersistentData{0, 0, "", "", "", "", "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000677 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000678 oo.mutexOnuKVStore.Lock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000679 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000680 oo.mutexOnuKVStore.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000681 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000682 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000683 oo.chOnuKvProcessingStep <- 0 //error indication
684 return
685 }
686 oo.chOnuKvProcessingStep <- aProcessingStep //done
687}
688
689func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
690 defer wg.Done()
691
692 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000693 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000694 oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: onuKVStore not set"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000695 return
696 }
697 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
698 go oo.storeDataInOnuKvStore(ctx, processingStep)
699 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
700 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000701 logger.Debugw(ctx, "ONU-data not written - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000702 oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: during writing process"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000703 return
704 }
705}
706
707func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) {
708
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000709 oo.mutexPersOnuConfig.Lock()
710 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000711 //assign values which are not already present when newOnuDeviceEntry() is called
712 oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId
713 oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000714 //TODO: verify usage of these values during restart UC
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000715 oo.sOnuPersistentData.PersAdminState = oo.baseDeviceHandler.pOnuIndication.AdminState
716 oo.sOnuPersistentData.PersOperState = oo.baseDeviceHandler.pOnuIndication.OperState
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000717
dbainbri4d3a0dc2020-12-02 00:33:42 +0000718 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000719
720 Value, err := json.Marshal(oo.sOnuPersistentData)
721 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000722 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000723 "device-id": oo.deviceID, "err": err})
724 oo.chOnuKvProcessingStep <- 0 //error indication
725 return
726 }
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000727 oo.pOpenOnuAc.lockDeviceHandlersMap.RLock()
728 if _, exist := oo.pOpenOnuAc.deviceHandlers[oo.deviceID]; !exist {
729 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
730 oo.chOnuKvProcessingStep <- aProcessingStep
731 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
732 return
733 }
734 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RLock()
735 if oo.baseDeviceHandler.deletionInProgress {
736 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
737 oo.chOnuKvProcessingStep <- aProcessingStep
738 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
739 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock()
740 return
741 }
742 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
743 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock()
744
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000745 oo.mutexOnuKVStore.Lock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000746 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000747 oo.mutexOnuKVStore.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000748 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000749 logger.Errorw(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000750 oo.chOnuKvProcessingStep <- 0 //error indication
751 return
752 }
753 oo.chOnuKvProcessingStep <- aProcessingStep //done
754}
755
dbainbri4d3a0dc2020-12-02 00:33:42 +0000756func (oo *OnuDeviceEntry) updateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000757 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
758 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
759 no specific concurrency protection to sOnuPersistentData is required here
760 */
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000761 oo.mutexPersOnuConfig.Lock()
762 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000763
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000764 for k, v := range oo.sOnuPersistentData.PersUniConfig {
765 if v.PersUniID == aUniID {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800766 existingPath, ok := oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700767 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
768 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800769 if !ok {
mpagenko30f28442021-03-24 09:24:04 +0000770 logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800771 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000772 if existingPath != aPathString {
773 if aPathString == "" {
774 //existing entry to be deleted
dbainbri4d3a0dc2020-12-02 00:33:42 +0000775 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800776 oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000777 } else {
778 //existing entry to be modified
dbainbri4d3a0dc2020-12-02 00:33:42 +0000779 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800780 oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000781 }
782 return true
783 }
784 //entry already exists
mpagenkofc4f56e2020-11-04 17:17:49 +0000785 if aPathString == "" {
786 //no active TechProfile
dbainbri4d3a0dc2020-12-02 00:33:42 +0000787 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000788 "device-id": oo.deviceID, "uniID": aUniID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000789 } else {
790 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
791 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
792 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000793 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000794 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
795 //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
796 // (during which the flows are removed/re-assigned but the techProf is left active)
797 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
798 // (should not be the case, but should not harm or be more robust ...)
mpagenko2418ab02020-11-12 12:58:06 +0000799 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
800 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
801 if oo.baseDeviceHandler.pOnuTP != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800802 oo.baseDeviceHandler.pOnuTP.setProfileToDelete(aUniID, aTpID, false)
mpagenko2418ab02020-11-12 12:58:06 +0000803 }
mpagenko551a4d42020-12-08 18:09:20 +0000804 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000805 }
806 return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000807 }
808 }
809 //no entry exists for uniId
810
811 if aPathString == "" {
812 //delete request in non-existing state , accept as no change
dbainbri4d3a0dc2020-12-02 00:33:42 +0000813 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000814 return false
815 }
816 //new entry to be created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000817 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800818 perSubTpPathMap := make(map[uint8]string)
819 perSubTpPathMap[aTpID] = aPathString
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000820 oo.sOnuPersistentData.PersUniConfig =
Girish Gowdra041dcb32020-11-16 16:54:30 -0800821 append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]uniVlanFlowParams, 0)})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000822 return true
823}
824
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000825func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) {
826
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000827 oo.mutexPersOnuConfig.Lock()
828 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000829
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000830 for k, v := range oo.sOnuPersistentData.PersUniConfig {
831 if v.PersUniID == aUniID {
832 oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams))
833 copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
834 return
835 }
836 }
837 //flow update was faster than tp-config - create PersUniConfig-entry
mpagenko30f28442021-03-24 09:24:04 +0000838 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
839 // (e.g after flow removal from RemoveUniFlowParams()).
840 // 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
841 // 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
842 // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests
Girish Gowdra041dcb32020-11-16 16:54:30 -0800843 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000844 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
845 oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig)
846}
847
848func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion(
849 ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool {
850 select {
851 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 logger.Warnw(ctx, "processing not completed in-time!",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000853 log.Fields{"device-id": oo.deviceID, "error": ctx.Err()})
854 return false
855 case rxStep := <-aChOnuProcessingStep:
856 if rxStep == aProcessingStep {
857 return true
858 }
859 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000860 logger.Warnw(ctx, "Invalid processing step received: abort!",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000861 log.Fields{"device-id": oo.deviceID,
862 "wantedStep": aProcessingStep, "haveStep": rxStep})
863 return false
864 }
865}
866
867func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000868 oo.mutexOnuKVStoreProcResult.Lock()
869 oo.onuKVStoreProcResult = nil
870 oo.mutexOnuKVStoreProcResult.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000871}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000872
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000873func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000874 oo.mutexOnuKVStoreProcResult.RLock()
875 value := oo.onuKVStoreProcResult
876 oo.mutexOnuKVStoreProcResult.RUnlock()
877 return value
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000878}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000879
880func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
881 oo.mutexOnuKVStoreProcResult.Lock()
882 oo.onuKVStoreProcResult = value
883 oo.mutexOnuKVStoreProcResult.Unlock()
884}
885
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000886func (oo *OnuDeviceEntry) incrementMibDataSync(ctx context.Context) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000887 oo.mutexPersOnuConfig.Lock()
888 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000889 if oo.sOnuPersistentData.PersMibDataSyncAdpt < 255 {
890 oo.sOnuPersistentData.PersMibDataSyncAdpt++
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000891 } else {
892 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000893 oo.sOnuPersistentData.PersMibDataSyncAdpt = 1
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000894 }
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000895 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.sOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000896}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000897
mpagenko9c225032021-10-15 14:26:49 +0000898// ModifySwImageInactiveVersion - updates the inactive SW image version stored
899func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
900 oo.mutexOnuSwImageIndications.Lock()
901 defer oo.mutexOnuSwImageIndications.Unlock()
902 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
903 "device-id": oo.deviceID, "version": aImageVersion})
904 oo.onuSwImageIndications.inactiveEntityEntry.version = aImageVersion
905 //inactive SW version is not part of persistency data (yet) - no need to update that
906}
907
908// ModifySwImageActiveCommit - updates the active SW commit flag stored
909func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
910 oo.mutexOnuSwImageIndications.Lock()
911 defer oo.mutexOnuSwImageIndications.Unlock()
912 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
913 "device-id": oo.deviceID, "committed": aCommitted})
914 oo.onuSwImageIndications.activeEntityEntry.isCommitted = aCommitted
915 //commit flag is not part of persistency data (yet) - no need to update that
916}
917
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300918func (oo *OnuDeviceEntry) getActiveImageVersion(ctx context.Context) string {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000919 oo.mutexOnuSwImageIndications.RLock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300920 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000921 value := oo.onuSwImageIndications.activeEntityEntry.version
922 oo.mutexOnuSwImageIndications.RUnlock()
923 return value
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300924 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000925 oo.mutexOnuSwImageIndications.RUnlock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300926 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
927 return ""
928}
929
930func (oo *OnuDeviceEntry) getInactiveImageVersion(ctx context.Context) string {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000931 oo.mutexOnuSwImageIndications.RLock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300932 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000933 value := oo.onuSwImageIndications.inactiveEntityEntry.version
934 oo.mutexOnuSwImageIndications.RUnlock()
935 return value
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300936 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000937 oo.mutexOnuSwImageIndications.RUnlock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300938 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
939 return ""
940}
941
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000942func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000943 oo.mutexPersOnuConfig.RLock()
944 defer oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000945 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.sOnuPersistentData.PersVendorID, oo.sOnuPersistentData.PersEquipmentID, oo.sOnuPersistentData.PersActiveSwVersion)
946}
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700947
948func (oo *OnuDeviceEntry) allocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
949 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
950 "allocated-instances": oo.sOnuPersistentData.PersTcontMap})
951
mpagenkob59fbed2021-11-23 16:55:20 +0000952 oo.mutexPersOnuConfig.Lock()
953 defer oo.mutexPersOnuConfig.Unlock()
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700954 if entityID, ok := oo.sOnuPersistentData.PersTcontMap[allocID]; ok {
955 //tcont already allocated before, return the used instance-id
956 return entityID, true, nil
957 }
958 //First allocation of tcont. Find a free instance
959 if tcontInstKeys := oo.pOnuDB.getSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
960 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
961 for _, instID := range tcontInstKeys {
962 instExist := false
963 //If this instance exist in map, it means it is not empty. It is allocated before
964 for _, v := range oo.sOnuPersistentData.PersTcontMap {
965 if v == instID {
966 instExist = true
967 break
968 }
969 }
970 if !instExist {
971 oo.sOnuPersistentData.PersTcontMap[allocID] = instID
972 return instID, false, nil
973 }
974 }
975 }
976 return 0, false, fmt.Errorf(fmt.Sprintf("no-free-tcont-left-for-device-%s", oo.deviceID))
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700977}
978
979func (oo *OnuDeviceEntry) freeTcont(ctx context.Context, allocID uint16) {
980 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
mpagenkob59fbed2021-11-23 16:55:20 +0000981 oo.mutexPersOnuConfig.Lock()
982 defer oo.mutexPersOnuConfig.Unlock()
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700983 delete(oo.sOnuPersistentData.PersTcontMap, allocID)
984}
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +0000985
986// PrepareForGarbageCollection - remove references to prepare for garbage collection
987func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
988 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
989 oo.baseDeviceHandler = nil
990 if oo.PDevOmciCC != nil {
991 oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID)
992 }
993 oo.PDevOmciCC = nil
994}