blob: bfb1ab5195ea227bb42fa7a70441adb178b1db4d [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
khenaidoo7d3c5582021-08-11 18:09:44 -040028 "github.com/looplab/fsm"
ozgecanetsiae11479f2020-07-06 09:44:47 +030029 "github.com/opencord/omci-lib-go"
30 me "github.com/opencord/omci-lib-go/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040031 "github.com/opencord/voltha-lib-go/v7/pkg/db"
32 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
33 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000034
khenaidoo7d3c5582021-08-11 18:09:44 -040035 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000036)
37
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000038const (
mpagenko1cc3cb42020-07-27 15:24:38 +000039 // events of MibUpload FSM
40 ulEvStart = "ulEvStart"
41 ulEvResetMib = "ulEvResetMib"
42 ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053043 ulEvGetEquipmentID = "ulEvGetEquipmentId"
mpagenko1cc3cb42020-07-27 15:24:38 +000044 ulEvGetFirstSwVersion = "ulEvGetFirstSwVersion"
45 ulEvGetSecondSwVersion = "ulEvGetSecondSwVersion"
46 ulEvGetMacAddress = "ulEvGetMacAddress"
47 ulEvGetMibTemplate = "ulEvGetMibTemplate"
48 ulEvUploadMib = "ulEvUploadMib"
49 ulEvExamineMds = "ulEvExamineMds"
50 ulEvSuccess = "ulEvSuccess"
51 ulEvMismatch = "ulEvMismatch"
52 ulEvAuditMib = "ulEvAuditMib"
53 ulEvForceResync = "ulEvForceResync"
54 ulEvDiffsFound = "ulEvDiffsFound"
55 ulEvTimeout = "ulEvTimeout"
56 ulEvStop = "ulEvStop"
57)
58const (
59 // states of MibUpload FSM
60 ulStDisabled = "ulStDisabled"
61 ulStStarting = "ulStStarting"
62 ulStResettingMib = "ulStResettingMib"
63 ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053064 ulStGettingEquipmentID = "ulStGettingEquipmentID"
mpagenko1cc3cb42020-07-27 15:24:38 +000065 ulStGettingFirstSwVersion = "ulStGettingFirstSwVersion"
66 ulStGettingSecondSwVersion = "ulStGettingSecondSwVersion"
67 ulStGettingMacAddress = "ulStGettingMacAddress"
68 ulStGettingMibTemplate = "ulStGettingMibTemplate"
69 ulStUploading = "ulStUploading"
Holger Hildebrandt10d98192021-01-27 15:29:31 +000070 ulStUploadDone = "ulStUploadDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000071 ulStInSync = "ulStInSync"
72 ulStExaminingMds = "ulStExaminingMds"
73 ulStResynchronizing = "ulStResynchronizing"
Holger Hildebrandtbe523842021-03-10 10:47:18 +000074 ulStExaminingMdsSuccess = "ulStExaminingMdsSuccess"
mpagenko1cc3cb42020-07-27 15:24:38 +000075 ulStAuditing = "ulStAuditing"
Holger Hildebrandt10d98192021-01-27 15:29:31 +000076 ulStReAuditing = "ulStReAuditing"
mpagenko1cc3cb42020-07-27 15:24:38 +000077 ulStOutOfSync = "ulStOutOfSync"
78)
Holger Hildebrandt10d98192021-01-27 15:29:31 +000079const cMibUlFsmIdleState = ulStInSync
mpagenko1cc3cb42020-07-27 15:24:38 +000080
81const (
82 // events of MibDownload FSM
83 dlEvStart = "dlEvStart"
84 dlEvCreateGal = "dlEvCreateGal"
85 dlEvRxGalResp = "dlEvRxGalResp"
86 dlEvRxOnu2gResp = "dlEvRxOnu2gResp"
87 dlEvRxBridgeResp = "dlEvRxBridgeResp"
88 dlEvTimeoutSimple = "dlEvTimeoutSimple"
89 dlEvTimeoutBridge = "dlEvTimeoutBridge"
90 dlEvReset = "dlEvReset"
91 dlEvRestart = "dlEvRestart"
92)
93const (
94 // states of MibDownload FSM
95 dlStDisabled = "dlStDisabled"
96 dlStStarting = "dlStStarting"
97 dlStCreatingGal = "dlStCreatingGal"
98 dlStSettingOnu2g = "dlStSettingOnu2g"
99 dlStBridgeInit = "dlStBridgeInit"
100 dlStDownloaded = "dlStDownloaded"
101 dlStResetting = "dlStResetting"
102)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000103const cMibDlFsmIdleState = dlStDisabled
mpagenko1cc3cb42020-07-27 15:24:38 +0000104
105const (
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800106 // NOTE that this hardcoded to service/voltha as the MIB template is shared across stacks
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000107 cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
mpagenkoaf801632020-07-03 10:00:42 +0000108 cSuffixMibTemplateKvStore = "%s/%s/%s"
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800109 cBasePathOnuKVStore = "%s/openonu"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000110)
111
Himani Chawla6d2ae152020-09-02 13:11:20 +0530112// OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113type OnuDeviceEvent int
114
115const (
116 // Events of interest to Device Adapters and OpenOMCI State Machines
Himani Chawla6d2ae152020-09-02 13:11:20 +0530117
118 // DeviceStatusInit - default start state
mpagenkofc4f56e2020-11-04 17:17:49 +0000119 DeviceStatusInit OnuDeviceEvent = iota
Himani Chawla6d2ae152020-09-02 13:11:20 +0530120 // MibDatabaseSync - MIB database sync (upload done)
mpagenkofc4f56e2020-11-04 17:17:49 +0000121 MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530122 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
mpagenkofc4f56e2020-11-04 17:17:49 +0000123 OmciCapabilitiesDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530124 // MibDownloadDone - // MIB download done
mpagenkofc4f56e2020-11-04 17:17:49 +0000125 MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530126 // UniLockStateDone - Uni ports admin set to lock
mpagenkofc4f56e2020-11-04 17:17:49 +0000127 UniLockStateDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530128 // UniUnlockStateDone - Uni ports admin set to unlock
mpagenkofc4f56e2020-11-04 17:17:49 +0000129 UniUnlockStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000130 // UniDisableStateDone - Uni ports admin set to lock based on device disable
mpagenkofc4f56e2020-11-04 17:17:49 +0000131 UniDisableStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000132 // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable
mpagenkofc4f56e2020-11-04 17:17:49 +0000133 UniEnableStateDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530134 // PortLinkUp - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000135 PortLinkUp
Himani Chawla6d2ae152020-09-02 13:11:20 +0530136 // PortLinkDw - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000137 PortLinkDw
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138 // OmciAniConfigDone - AniSide config according to TechProfile done
mpagenkofc4f56e2020-11-04 17:17:49 +0000139 OmciAniConfigDone
140 // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed
141 OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone!
mpagenkof1fc3862021-02-16 10:09:52 +0000142 // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add with request to write kvStore
mpagenkofc4f56e2020-11-04 17:17:49 +0000143 OmciVlanFilterAddDone
mpagenkof1fc3862021-02-16 10:09:52 +0000144 // OmciVlanFilterAddDoneNoKvStore - Omci Vlan config done according to flow-add without writing kvStore
145 OmciVlanFilterAddDoneNoKvStore // needs to be the successor of OmciVlanFilterAddDone!
146 // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove with request to write kvStore
147 OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDoneNoKvStore!
148 // OmciVlanFilterRemDoneNoKvStore - Omci Vlan config done according to flow-remove without writing kvStore
149 OmciVlanFilterRemDoneNoKvStore // needs to be the successor of OmciVlanFilterRemDone!
mpagenko80622a52021-02-09 16:53:23 +0000150 // OmciOnuSwUpgradeDone - SoftwareUpgrade to ONU finished
151 OmciOnuSwUpgradeDone
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 // Add other events here as needed (alarms separate???)
153)
154
mpagenko7d6bb022021-03-11 15:07:55 +0000155//AdapterFsm related error string
156//error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log
157// but not used that way so far (permit error log even for wanted cancellation)
158const cErrWaitAborted = "waitResponse aborted"
159
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000160type activityDescr struct {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 databaseClass func(context.Context) error
Himani Chawla4d908332020-08-31 12:30:20 +0530162 //advertiseEvents bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000163 auditInterval time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164 //tasks map[string]func() error
165}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530166
167// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000168type OmciDeviceFsms map[string]activityDescr
169
Himani Chawla6d2ae152020-09-02 13:11:20 +0530170// AdapterFsm - Adapter FSM details including channel, event and device
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000171type AdapterFsm struct {
172 fsmName string
173 deviceID string
174 commChan chan Message
175 pFsm *fsm.FSM
176}
177
Himani Chawla6d2ae152020-09-02 13:11:20 +0530178//NewAdapterFsm - FSM details including event, device and channel.
179func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000180 aFsm := &AdapterFsm{
Himani Chawla6d2ae152020-09-02 13:11:20 +0530181 fsmName: aName,
182 deviceID: aDeviceID,
183 commChan: aCommChannel,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000184 }
185 return aFsm
186}
187
188//Start starts (logs) the omci agent
dbainbri4d3a0dc2020-12-02 00:33:42 +0000189func (oo *AdapterFsm) logFsmStateChange(ctx context.Context, e *fsm.Event) {
190 logger.Debugw(ctx, "FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000191 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
192}
193
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000194//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000195
196const (
Himani Chawla6d2ae152020-09-02 13:11:20 +0530197 firstSwImageMeID = 0
198 secondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000199)
mpagenko15ff4a52021-03-02 10:09:20 +0000200const ( //definitions as per G.988 softwareImage::IsCommitted
201 swIsUncommitted = 0
202 swIsCommitted = 1
203)
204const ( //definitions as per G.988 softwareImage::IsActive
mpagenko38662d02021-08-11 09:45:19 +0000205 swIsInactive = 0
206 swIsActive = 1
mpagenko15ff4a52021-03-02 10:09:20 +0000207)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000208const ( //definitions as per G.988 softwareImage::IsValid
209 //swIsInvalid = 0 not yet used
210 swIsValid = 1
211)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000212const onuDataMeID = 0
Himani Chawla6d2ae152020-09-02 13:11:20 +0530213const onugMeID = 0
214const onu2gMeID = 0
215const ipHostConfigDataMeID = 1
216const onugSerialNumberLen = 8
217const omciMacAddressLen = 6
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000218
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000219const cEmptyMacAddrString = "000000000000"
220const cEmptySerialNumberString = "0000000000000000"
221
mpagenko15ff4a52021-03-02 10:09:20 +0000222type sEntrySwImageIndication struct {
223 valid bool
224 entityID uint16
225 version string
226 isCommitted uint8
227}
228type sSwImageIndications struct {
229 activeEntityEntry sEntrySwImageIndication
230 inactiveEntityEntry sEntrySwImageIndication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000231}
232
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000233type uniPersConfig struct {
234 PersUniID uint8 `json:"uni_id"`
Girish Gowdra041dcb32020-11-16 16:54:30 -0800235 PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map
236 PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000237}
238
239type onuPersistentData struct {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700240 PersOnuID uint32 `json:"onu_id"`
241 PersIntfID uint32 `json:"intf_id"`
242 PersSerialNumber string `json:"serial_number"`
243 PersMacAddress string `json:"mac_address"`
244 PersVendorID string `json:"vendor_id"`
245 PersEquipmentID string `json:"equipment_id"`
246 PersActiveSwVersion string `json:"active_sw_version"`
247 PersAdminState string `json:"admin_state"`
248 PersOperState string `json:"oper_state"`
249 PersUniUnlockDone bool `json:"uni_unlock_done"`
250 PersUniDisableDone bool `json:"uni_disable_done"`
251 PersMibAuditInterval time.Duration `json:"mib_audit_interval"`
252 PersMibLastDbSync uint32 `json:"mib_last_db_sync"`
253 PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"`
254 PersUniConfig []uniPersConfig `json:"uni_config"`
255 PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"`
256 PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000257}
258
Himani Chawla6d2ae152020-09-02 13:11:20 +0530259// OnuDeviceEntry - ONU device info and FSM events.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000260type OnuDeviceEntry struct {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000261 deviceID string
262 baseDeviceHandler *deviceHandler
263 pOpenOnuAc *OpenONUAC
khenaidoo7d3c5582021-08-11 18:09:44 -0400264 coreClient *vgrpc.Client
Holger Hildebrandt05011352021-06-15 09:40:24 +0000265 PDevOmciCC *omciCC
266 pOnuDB *onuDeviceDB
267 mibTemplateKVStore *db.Backend
268 mutexPersOnuConfig sync.RWMutex
269 sOnuPersistentData onuPersistentData
270 mibTemplatePath string
271 mutexOnuKVStore sync.RWMutex
272 onuKVStore *db.Backend
273 onuKVStorePath string
274 mutexOnuKVStoreProcResult sync.RWMutex
275 onuKVStoreProcResult error //error indication of processing
276 chOnuKvProcessingStep chan uint8
277 mutexOnuSwImageIndications sync.RWMutex
278 onuSwImageIndications sSwImageIndications
279 mutexOnuImageStatus sync.RWMutex
280 pOnuImageStatus *OnuImageStatus
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000281 //lockDeviceEntries sync.RWMutex
dbainbri4d3a0dc2020-12-02 00:33:42 +0000282 mibDbClass func(context.Context) error
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000283 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000284 devState OnuDeviceEvent
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000285 // Audit and MDS
Himani Chawla075f1642021-03-15 19:23:24 +0530286 mibAuditInterval time.Duration
287 alarmAuditInterval time.Duration
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000288 // TODO: periodical mib resync will be implemented with story VOL-3792
289 //mibNextDbResync uint32
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000290
291 // for mibUpload
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000292 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
293 mutexLastTxParamStruct sync.RWMutex
294 lastTxParamStruct sLastTxMeParameter
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000295 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000296 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
297 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
298 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300299 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
300 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700301
302 mutexTcontMap sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000303}
304
Himani Chawla6d2ae152020-09-02 13:11:20 +0530305//newOnuDeviceEntry returns a new instance of a OnuDeviceEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000306//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000307func newOnuDeviceEntry(ctx context.Context, dh *deviceHandler) *OnuDeviceEntry {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308 logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": dh.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000309 var onuDeviceEntry OnuDeviceEntry
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000310 onuDeviceEntry.deviceID = dh.deviceID
311 onuDeviceEntry.baseDeviceHandler = dh
312 onuDeviceEntry.pOpenOnuAc = dh.pOpenOnuAc
khenaidoo7d3c5582021-08-11 18:09:44 -0400313 onuDeviceEntry.coreClient = dh.coreClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000314 onuDeviceEntry.devState = DeviceStatusInit
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000315 onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700316 onuDeviceEntry.sOnuPersistentData.PersTcontMap = make(map[uint16]uint16)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000317 onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300318 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000319 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
320 //OMCI related databases are on a per-agent basis. State machines and tasks
321 //are per ONU Vendor
322 //
323 // MIB Synchronization Database - possible overloading from arguments
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000324 if dh.pOpenOnuAc.pSupportedFsms != nil {
325 onuDeviceEntry.supportedFsms = *dh.pOpenOnuAc.pSupportedFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000326 } else {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000327 // 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 +0000328 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000329 // use some internal defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000330 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
331 "mib-synchronizer": {
332 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530333 onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530334 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000335 dh.pOpenOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000336 // map[string]func() error{
337 // "mib-upload": onuDeviceEntry.MibUploadTask,
338 // "mib-template": onuDeviceEntry.MibTemplateTask,
339 // "get-mds": onuDeviceEntry.GetMdsTask,
340 // "mib-audit": onuDeviceEntry.GetMdsTask,
341 // "mib-resync": onuDeviceEntry.MibResyncTask,
342 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
343 // },
344 },
345 }
346 }
347 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 logger.Debug(ctx, "access2mibDbClass")
349 go onuDeviceEntry.mibDbClass(ctx)
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +0000350 if !dh.isReconciling() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000351 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditInterval
352 onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval
Himani Chawla075f1642021-03-15 19:23:24 +0530353 onuDeviceEntry.alarmAuditInterval = dh.pOpenOnuAc.alarmAuditInterval
354 onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000355 } else {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000356 logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": dh.deviceID})
357 // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000358 // vendor- or deviceID-specific configurations via voltctl-commands
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000359 onuDeviceEntry.mibAuditInterval = onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval
Himani Chawla075f1642021-03-15 19:23:24 +0530360 onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000361 }
Himani Chawla075f1642021-03-15 19:23:24 +0530362 logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval,
363 "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000364 // TODO: periodical mib resync will be implemented with story VOL-3792
365 //onuDeviceEntry.mibNextDbResync = 0
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000366
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000367 // Omci related Mib upload sync state machine
368 mibUploadChan := make(chan Message, 2048)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000369 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", dh.deviceID, mibUploadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000370 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000371 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000372 fsm.Events{
373
mpagenko1cc3cb42020-07-27 15:24:38 +0000374 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000375
mpagenko1cc3cb42020-07-27 15:24:38 +0000376 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
377 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530378 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
379 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000380 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
381 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
382 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000383
mpagenko1cc3cb42020-07-27 15:24:38 +0000384 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
385 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000386
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000387 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploadDone},
388 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStUploadDone},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000389
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000390 {Name: ulEvSuccess, Src: []string{ulStUploadDone}, Dst: ulStInSync},
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000391 //{Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
392 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStExaminingMdsSuccess},
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000393 // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers
394 // mib-reset and new provisioning at this point
395 //{Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
396 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResettingMib},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000397
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000398 {Name: ulEvSuccess, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStInSync},
399 {Name: ulEvMismatch, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStResettingMib},
400
mpagenko1cc3cb42020-07-27 15:24:38 +0000401 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000402
mpagenko1cc3cb42020-07-27 15:24:38 +0000403 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
404 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000405
mpagenko1cc3cb42020-07-27 15:24:38 +0000406 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000407 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStReAuditing},
mpagenko1cc3cb42020-07-27 15:24:38 +0000408 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000409
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000410 {Name: ulEvSuccess, Src: []string{ulStReAuditing}, Dst: ulStInSync},
411 {Name: ulEvMismatch, Src: []string{ulStReAuditing}, Dst: ulStResettingMib},
412
mpagenko1cc3cb42020-07-27 15:24:38 +0000413 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
414 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000415
Himani Chawla4d908332020-08-31 12:30:20 +0530416 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000417 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000418 ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000419
Himani Chawla4d908332020-08-31 12:30:20 +0530420 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000421 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000422 ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000423 },
424
425 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(ctx, e) },
427 "enter_" + ulStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) },
428 "enter_" + ulStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) },
429 "enter_" + ulStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) },
430 "enter_" + ulStGettingEquipmentID: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(ctx, e) },
431 "enter_" + ulStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) },
432 "enter_" + ulStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) },
433 "enter_" + ulStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) },
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000434 "enter_" + ulStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435 "enter_" + ulStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) },
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000436 "enter_" + ulStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000437 "enter_" + ulStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) },
438 "enter_" + ulStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) },
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000439 "enter_" + ulStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000440 "enter_" + ulStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) },
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000441 "enter_" + ulStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000442 "enter_" + ulStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) },
443 "enter_" + ulStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000444 },
445 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000446 // Omci related Mib download state machine
447 mibDownloadChan := make(chan Message, 2048)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000448 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", dh.deviceID, mibDownloadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000449 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000450 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000451 fsm.Events{
452
mpagenko1cc3cb42020-07-27 15:24:38 +0000453 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000454
mpagenko1cc3cb42020-07-27 15:24:38 +0000455 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
456 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
457 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000458 // the bridge state is used for multi ME config for alle UNI related ports
459 // maybe such could be reflected in the state machine as well (port number parametrized)
460 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000461 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000462
mpagenko1cc3cb42020-07-27 15:24:38 +0000463 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
464 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000465
mpagenko1cc3cb42020-07-27 15:24:38 +0000466 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
467 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
468 // exceptional treatment for all states except dlStResetting
469 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
470 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000471 },
472
473 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(ctx, e) },
475 "enter_" + dlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) },
476 "enter_" + dlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) },
477 "enter_" + dlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) },
478 "enter_" + dlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) },
479 "enter_" + dlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) },
480 "enter_" + dlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000481 },
482 )
483 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000484 logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": dh.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000485 // TODO some specific error treatment - or waiting for crash ?
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000486 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000487
dbainbri4d3a0dc2020-12-02 00:33:42 +0000488 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000489 if onuDeviceEntry.mibTemplateKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000490 logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000491 log.Fields{"device-id": dh.deviceID, "service": cBasePathMibTemplateKvStore})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000492 }
493
494 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800495 baseKvStorePath := fmt.Sprintf(cBasePathOnuKVStore, dh.pOpenOnuAc.cm.Backend.PathPrefix)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000496 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, baseKvStorePath)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000497 if onuDeviceEntry.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000498 logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800499 log.Fields{"device-id": dh.deviceID, "service": baseKvStorePath})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000500 }
501
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000502 // Alarm Synchronization Database
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530503
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000504 //self._alarm_db = None
505 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
506 return &onuDeviceEntry
507}
508
Himani Chawla6d2ae152020-09-02 13:11:20 +0530509//start starts (logs) the omci agent
510func (oo *OnuDeviceEntry) start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511 logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000512 if oo.PDevOmciCC == nil {
khenaidoo7d3c5582021-08-11 18:09:44 -0400513 oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, oo.coreClient)
mpagenko900ee4b2020-10-12 11:56:34 +0000514 if oo.PDevOmciCC == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515 logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000516 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
517 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000518 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000519 return nil
520}
521
mpagenko900ee4b2020-10-12 11:56:34 +0000522//stop stops/resets the omciCC
523func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000524 logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000525 if abResetOmciCC && (oo.PDevOmciCC != nil) {
526 _ = oo.PDevOmciCC.stop(ctx)
527 }
528 //to allow for all event notifications again when re-using the device and omciCC
529 oo.devState = DeviceStatusInit
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000530 return nil
531}
532
Himani Chawla6d2ae152020-09-02 13:11:20 +0530533func (oo *OnuDeviceEntry) reboot(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000534 logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000535 if oo.PDevOmciCC != nil {
Girish Gowdra0b235842021-03-09 13:06:46 -0800536 if err := oo.PDevOmciCC.sendReboot(ctx, oo.pOpenOnuAc.omciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537 logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000538 return err
539 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300540 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300541 return nil
542}
543
dbainbri4d3a0dc2020-12-02 00:33:42 +0000544func (oo *OnuDeviceEntry) waitForRebootResponse(ctx context.Context, responseChannel chan Message) error {
ozgecanetsiae11479f2020-07-06 09:44:47 +0300545 select {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000546 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 +0000547 logger.Warnw(ctx, "Reboot timeout", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200548 return fmt.Errorf("rebootTimeout")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300549 case data := <-responseChannel:
550 switch data.Data.(OmciMessage).OmciMsg.MessageType {
551 case omci.RebootResponseType:
552 {
553 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
554 if msgLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200555 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300556 }
Andrea Campanellabef4e542020-10-22 11:01:28 +0200557 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300558 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200559 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300560 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000561 logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300562 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000563 logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300564 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
Andrea Campanellabef4e542020-10-22 11:01:28 +0200565 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200566 msgObj.Result, oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300567 }
568 return nil
569 }
570 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000571 logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200572 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300573 }
574}
575
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000576//Relay the InSync message via Handler to Rw core - Status update
dbainbri4d3a0dc2020-12-02 00:33:42 +0000577func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent OnuDeviceEvent) {
578 logger.Debugw(ctx, "relaying system-event", log.Fields{"Event": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000579 // decouple the handler transfer from further processing here
580 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
Himani Chawla26e555c2020-08-31 12:30:20 +0530581 if devEvent == MibDatabaseSync {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000582 if oo.devState < MibDatabaseSync { //devState has not been synced yet
583 oo.devState = MibDatabaseSync
dbainbri4d3a0dc2020-12-02 00:33:42 +0000584 go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000585 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
586 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587 logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000588 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530589 } else if devEvent == MibDownloadDone {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000590 if oo.devState < MibDownloadDone { //devState has not been synced yet
591 oo.devState = MibDownloadDone
dbainbri4d3a0dc2020-12-02 00:33:42 +0000592 go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000593 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000594 logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000595 }
596 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Warnw(ctx, "device-event not yet handled", log.Fields{"state": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000598 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000599}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000600
601func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error {
602 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000603 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000604 return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID))
605 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000606 oo.mutexPersOnuConfig.Lock()
607 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000608 oo.sOnuPersistentData =
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700609 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 +0000610 oo.mutexOnuKVStore.RLock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000611 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000612 oo.mutexOnuKVStore.RUnlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000613 if err == nil {
614 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000615 logger.Debugw(ctx, "ONU-data read",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000616 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
617 tmpBytes, _ := kvstore.ToByte(Value.Value)
618
619 if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000620 logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000621 return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID))
622 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000623 logger.Debugw(ctx, "ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000624 "device-id": oo.deviceID})
625 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000626 logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000627 return fmt.Errorf("no-ONU-data-found")
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000628 }
629 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000630 logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000631 return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID))
632 }
633 return nil
634}
635
636func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
637 defer wg.Done()
638
639 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000640 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000641 oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: onuKVStore not set"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000642 return
643 }
644 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
645 go oo.deletePersistentData(ctx, processingStep)
646 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
647 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000648 logger.Debugw(ctx, "ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000649 oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: during kv-access"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000650 return
651 }
652}
653
654func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) {
655
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656 logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000657
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000658 oo.mutexPersOnuConfig.Lock()
659 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000660
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000661 oo.sOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry
662 oo.sOnuPersistentData =
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700663 onuPersistentData{0, 0, "", "", "", "", "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000664 logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000665 oo.mutexOnuKVStore.Lock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000666 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000667 oo.mutexOnuKVStore.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000668 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000669 logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000670 oo.chOnuKvProcessingStep <- 0 //error indication
671 return
672 }
673 oo.chOnuKvProcessingStep <- aProcessingStep //done
674}
675
676func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
677 defer wg.Done()
678
679 if oo.onuKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000680 logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000681 oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: onuKVStore not set"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000682 return
683 }
684 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
685 go oo.storeDataInOnuKvStore(ctx, processingStep)
686 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
687 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000688 logger.Debugw(ctx, "ONU-data not written - abort", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000689 oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: during writing process"))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000690 return
691 }
692}
693
694func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) {
695
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000696 oo.mutexPersOnuConfig.Lock()
697 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000698 //assign values which are not already present when newOnuDeviceEntry() is called
699 oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId
700 oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000701 //TODO: verify usage of these values during restart UC
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000702 oo.sOnuPersistentData.PersAdminState = oo.baseDeviceHandler.pOnuIndication.AdminState
703 oo.sOnuPersistentData.PersOperState = oo.baseDeviceHandler.pOnuIndication.OperState
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000704
dbainbri4d3a0dc2020-12-02 00:33:42 +0000705 logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000706
707 Value, err := json.Marshal(oo.sOnuPersistentData)
708 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000709 logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000710 "device-id": oo.deviceID, "err": err})
711 oo.chOnuKvProcessingStep <- 0 //error indication
712 return
713 }
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000714 oo.pOpenOnuAc.lockDeviceHandlersMap.RLock()
715 if _, exist := oo.pOpenOnuAc.deviceHandlers[oo.deviceID]; !exist {
716 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
717 oo.chOnuKvProcessingStep <- aProcessingStep
718 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
719 return
720 }
721 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RLock()
722 if oo.baseDeviceHandler.deletionInProgress {
723 logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID})
724 oo.chOnuKvProcessingStep <- aProcessingStep
725 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
726 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock()
727 return
728 }
729 oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock()
730 oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock()
731
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000732 oo.mutexOnuKVStore.Lock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000733 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000734 oo.mutexOnuKVStore.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000735 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000736 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 +0000737 oo.chOnuKvProcessingStep <- 0 //error indication
738 return
739 }
740 oo.chOnuKvProcessingStep <- aProcessingStep //done
741}
742
dbainbri4d3a0dc2020-12-02 00:33:42 +0000743func (oo *OnuDeviceEntry) updateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000744 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
745 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
746 no specific concurrency protection to sOnuPersistentData is required here
747 */
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000748 oo.mutexPersOnuConfig.Lock()
749 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000750
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000751 for k, v := range oo.sOnuPersistentData.PersUniConfig {
752 if v.PersUniID == aUniID {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800753 existingPath, ok := oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID]
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700754 logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID,
755 "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800756 if !ok {
mpagenko30f28442021-03-24 09:24:04 +0000757 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 -0800758 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000759 if existingPath != aPathString {
760 if aPathString == "" {
761 //existing entry to be deleted
dbainbri4d3a0dc2020-12-02 00:33:42 +0000762 logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800763 oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = ""
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000764 } else {
765 //existing entry to be modified
dbainbri4d3a0dc2020-12-02 00:33:42 +0000766 logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800767 oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000768 }
769 return true
770 }
771 //entry already exists
mpagenkofc4f56e2020-11-04 17:17:49 +0000772 if aPathString == "" {
773 //no active TechProfile
dbainbri4d3a0dc2020-12-02 00:33:42 +0000774 logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000775 "device-id": oo.deviceID, "uniID": aUniID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000776 } else {
777 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
778 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
779 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000780 logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000781 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
782 //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
783 // (during which the flows are removed/re-assigned but the techProf is left active)
784 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
785 // (should not be the case, but should not harm or be more robust ...)
mpagenko2418ab02020-11-12 12:58:06 +0000786 // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history
787 // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config
788 if oo.baseDeviceHandler.pOnuTP != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800789 oo.baseDeviceHandler.pOnuTP.setProfileToDelete(aUniID, aTpID, false)
mpagenko2418ab02020-11-12 12:58:06 +0000790 }
mpagenko551a4d42020-12-08 18:09:20 +0000791 go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000792 }
793 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 +0000794 }
795 }
796 //no entry exists for uniId
797
798 if aPathString == "" {
799 //delete request in non-existing state , accept as no change
dbainbri4d3a0dc2020-12-02 00:33:42 +0000800 logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000801 return false
802 }
803 //new entry to be created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000804 logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800805 perSubTpPathMap := make(map[uint8]string)
806 perSubTpPathMap[aTpID] = aPathString
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000807 oo.sOnuPersistentData.PersUniConfig =
Girish Gowdra041dcb32020-11-16 16:54:30 -0800808 append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]uniVlanFlowParams, 0)})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000809 return true
810}
811
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000812func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) {
813
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000814 oo.mutexPersOnuConfig.Lock()
815 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandtdaf0f722021-02-12 11:50:30 +0000816
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000817 for k, v := range oo.sOnuPersistentData.PersUniConfig {
818 if v.PersUniID == aUniID {
819 oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams))
820 copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
821 return
822 }
823 }
824 //flow update was faster than tp-config - create PersUniConfig-entry
mpagenko30f28442021-03-24 09:24:04 +0000825 //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data
826 // (e.g after flow removal from RemoveUniFlowParams()).
827 // 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
828 // 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
829 // 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 -0800830 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000831 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
832 oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig)
833}
834
835func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion(
836 ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool {
837 select {
838 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000839 logger.Warnw(ctx, "processing not completed in-time!",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000840 log.Fields{"device-id": oo.deviceID, "error": ctx.Err()})
841 return false
842 case rxStep := <-aChOnuProcessingStep:
843 if rxStep == aProcessingStep {
844 return true
845 }
846 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000847 logger.Warnw(ctx, "Invalid processing step received: abort!",
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000848 log.Fields{"device-id": oo.deviceID,
849 "wantedStep": aProcessingStep, "haveStep": rxStep})
850 return false
851 }
852}
853
854func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000855 oo.mutexOnuKVStoreProcResult.Lock()
856 oo.onuKVStoreProcResult = nil
857 oo.mutexOnuKVStoreProcResult.Unlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000858}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000859
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000860func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000861 oo.mutexOnuKVStoreProcResult.RLock()
862 value := oo.onuKVStoreProcResult
863 oo.mutexOnuKVStoreProcResult.RUnlock()
864 return value
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000865}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000866
867func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) {
868 oo.mutexOnuKVStoreProcResult.Lock()
869 oo.onuKVStoreProcResult = value
870 oo.mutexOnuKVStoreProcResult.Unlock()
871}
872
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000873func (oo *OnuDeviceEntry) incrementMibDataSync(ctx context.Context) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000874 oo.mutexPersOnuConfig.Lock()
875 defer oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000876 if oo.sOnuPersistentData.PersMibDataSyncAdpt < 255 {
877 oo.sOnuPersistentData.PersMibDataSyncAdpt++
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000878 } else {
879 // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000880 oo.sOnuPersistentData.PersMibDataSyncAdpt = 1
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000881 }
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000882 logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.sOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000883}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000884
mpagenko38662d02021-08-11 09:45:19 +0000885func (oo *OnuDeviceEntry) modifySwImageInactiveVersion(ctx context.Context, aImageVersion string) {
886 oo.mutexOnuSwImageIndications.Lock()
887 defer oo.mutexOnuSwImageIndications.Unlock()
888 logger.Debugw(ctx, "software-image set inactive version", log.Fields{
889 "device-id": oo.deviceID, "version": aImageVersion})
890 oo.onuSwImageIndications.inactiveEntityEntry.version = aImageVersion
891 //inactive SW version is not part of persistency data (yet) - no need to update that
892}
893
894func (oo *OnuDeviceEntry) modifySwImageActiveCommit(ctx context.Context, aCommitted uint8) {
895 oo.mutexOnuSwImageIndications.Lock()
896 defer oo.mutexOnuSwImageIndications.Unlock()
897 logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{
898 "device-id": oo.deviceID, "committed": aCommitted})
899 oo.onuSwImageIndications.activeEntityEntry.isCommitted = aCommitted
900 //commit flag is not part of persistency data (yet) - no need to update that
901}
902
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300903func (oo *OnuDeviceEntry) getActiveImageVersion(ctx context.Context) string {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000904 oo.mutexOnuSwImageIndications.RLock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300905 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000906 value := oo.onuSwImageIndications.activeEntityEntry.version
907 oo.mutexOnuSwImageIndications.RUnlock()
908 return value
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300909 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000910 oo.mutexOnuSwImageIndications.RUnlock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300911 logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID})
912 return ""
913}
914
915func (oo *OnuDeviceEntry) getInactiveImageVersion(ctx context.Context) string {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000916 oo.mutexOnuSwImageIndications.RLock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300917 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000918 value := oo.onuSwImageIndications.inactiveEntityEntry.version
919 oo.mutexOnuSwImageIndications.RUnlock()
920 return value
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300921 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000922 oo.mutexOnuSwImageIndications.RUnlock()
ozgecanetsiaf0a76b62021-05-31 17:42:09 +0300923 logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID})
924 return ""
925}
926
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000927func (oo *OnuDeviceEntry) buildMibTemplatePath() string {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000928 oo.mutexPersOnuConfig.RLock()
929 defer oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000930 return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.sOnuPersistentData.PersVendorID, oo.sOnuPersistentData.PersEquipmentID, oo.sOnuPersistentData.PersActiveSwVersion)
931}
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700932
933func (oo *OnuDeviceEntry) allocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) {
934 logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID,
935 "allocated-instances": oo.sOnuPersistentData.PersTcontMap})
936
937 oo.mutexTcontMap.Lock()
938 defer oo.mutexTcontMap.Unlock()
939 if entityID, ok := oo.sOnuPersistentData.PersTcontMap[allocID]; ok {
940 //tcont already allocated before, return the used instance-id
941 return entityID, true, nil
942 }
943 //First allocation of tcont. Find a free instance
944 if tcontInstKeys := oo.pOnuDB.getSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 {
945 logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys})
946 for _, instID := range tcontInstKeys {
947 instExist := false
948 //If this instance exist in map, it means it is not empty. It is allocated before
949 for _, v := range oo.sOnuPersistentData.PersTcontMap {
950 if v == instID {
951 instExist = true
952 break
953 }
954 }
955 if !instExist {
956 oo.sOnuPersistentData.PersTcontMap[allocID] = instID
957 return instID, false, nil
958 }
959 }
960 }
961 return 0, false, fmt.Errorf(fmt.Sprintf("no-free-tcont-left-for-device-%s", oo.deviceID))
962
963}
964
965func (oo *OnuDeviceEntry) freeTcont(ctx context.Context, allocID uint16) {
966 logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID})
967 oo.mutexTcontMap.Lock()
968 defer oo.mutexTcontMap.Unlock()
969 delete(oo.sOnuPersistentData.PersTcontMap, allocID)
970}