blob: ad683b0325a354e5bbf3b83a083332408a0b9c77 [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"
35 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000036 "github.com/opencord/voltha-lib-go/v3/pkg/db"
Holger Hildebrandt47555e72020-09-21 11:07:24 +000037 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000038
39 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
40 "github.com/opencord/voltha-lib-go/v3/pkg/log"
41 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
42 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
43 //"github.com/opencord/voltha-protos/v3/go/voltha"
44)
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"
78 ulStInSync = "ulStInSync"
79 ulStExaminingMds = "ulStExaminingMds"
80 ulStResynchronizing = "ulStResynchronizing"
81 ulStAuditing = "ulStAuditing"
82 ulStOutOfSync = "ulStOutOfSync"
83)
84
85const (
86 // events of MibDownload FSM
87 dlEvStart = "dlEvStart"
88 dlEvCreateGal = "dlEvCreateGal"
89 dlEvRxGalResp = "dlEvRxGalResp"
90 dlEvRxOnu2gResp = "dlEvRxOnu2gResp"
91 dlEvRxBridgeResp = "dlEvRxBridgeResp"
92 dlEvTimeoutSimple = "dlEvTimeoutSimple"
93 dlEvTimeoutBridge = "dlEvTimeoutBridge"
94 dlEvReset = "dlEvReset"
95 dlEvRestart = "dlEvRestart"
96)
97const (
98 // states of MibDownload FSM
99 dlStDisabled = "dlStDisabled"
100 dlStStarting = "dlStStarting"
101 dlStCreatingGal = "dlStCreatingGal"
102 dlStSettingOnu2g = "dlStSettingOnu2g"
103 dlStBridgeInit = "dlStBridgeInit"
104 dlStDownloaded = "dlStDownloaded"
105 dlStResetting = "dlStResetting"
106)
107
108const (
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000109 cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
mpagenkoaf801632020-07-03 10:00:42 +0000110 cSuffixMibTemplateKvStore = "%s/%s/%s"
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000111 cBasePathOnuKVStore = "service/voltha/openonu"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000112)
113
Himani Chawla6d2ae152020-09-02 13:11:20 +0530114// OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115type OnuDeviceEvent int
116
117const (
118 // Events of interest to Device Adapters and OpenOMCI State Machines
Himani Chawla6d2ae152020-09-02 13:11:20 +0530119
120 // DeviceStatusInit - default start state
mpagenkofc4f56e2020-11-04 17:17:49 +0000121 DeviceStatusInit OnuDeviceEvent = iota
Himani Chawla6d2ae152020-09-02 13:11:20 +0530122 // MibDatabaseSync - MIB database sync (upload done)
mpagenkofc4f56e2020-11-04 17:17:49 +0000123 MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530124 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
mpagenkofc4f56e2020-11-04 17:17:49 +0000125 OmciCapabilitiesDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530126 // MibDownloadDone - // MIB download done
mpagenkofc4f56e2020-11-04 17:17:49 +0000127 MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530128 // UniLockStateDone - Uni ports admin set to lock
mpagenkofc4f56e2020-11-04 17:17:49 +0000129 UniLockStateDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530130 // UniUnlockStateDone - Uni ports admin set to unlock
mpagenkofc4f56e2020-11-04 17:17:49 +0000131 UniUnlockStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000132 // UniDisableStateDone - Uni ports admin set to lock based on device disable
mpagenkofc4f56e2020-11-04 17:17:49 +0000133 UniDisableStateDone
mpagenko900ee4b2020-10-12 11:56:34 +0000134 // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable
mpagenkofc4f56e2020-11-04 17:17:49 +0000135 UniEnableStateDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530136 // PortLinkUp - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000137 PortLinkUp
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138 // PortLinkDw - Port link state change
mpagenkofc4f56e2020-11-04 17:17:49 +0000139 PortLinkDw
Himani Chawla6d2ae152020-09-02 13:11:20 +0530140 // OmciAniConfigDone - AniSide config according to TechProfile done
mpagenkofc4f56e2020-11-04 17:17:49 +0000141 OmciAniConfigDone
142 // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed
143 OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone!
144 // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add
145 OmciVlanFilterAddDone
146 // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove
147 OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDone!
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000148 // Add other events here as needed (alarms separate???)
149)
150
151type activityDescr struct {
Himani Chawla4d908332020-08-31 12:30:20 +0530152 databaseClass func() error
153 //advertiseEvents bool
154 auditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155 //tasks map[string]func() error
156}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530157
158// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000159type OmciDeviceFsms map[string]activityDescr
160
Himani Chawla6d2ae152020-09-02 13:11:20 +0530161// AdapterFsm - Adapter FSM details including channel, event and device
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000162type AdapterFsm struct {
163 fsmName string
164 deviceID string
165 commChan chan Message
166 pFsm *fsm.FSM
167}
168
Himani Chawla6d2ae152020-09-02 13:11:20 +0530169//NewAdapterFsm - FSM details including event, device and channel.
170func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000171 aFsm := &AdapterFsm{
Himani Chawla6d2ae152020-09-02 13:11:20 +0530172 fsmName: aName,
173 deviceID: aDeviceID,
174 commChan: aCommChannel,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000175 }
176 return aFsm
177}
178
179//Start starts (logs) the omci agent
180func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) {
181 logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
182 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
183}
184
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000186
187const (
Himani Chawla6d2ae152020-09-02 13:11:20 +0530188 firstSwImageMeID = 0
189 secondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000190)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530191const onugMeID = 0
192const onu2gMeID = 0
193const ipHostConfigDataMeID = 1
194const onugSerialNumberLen = 8
195const omciMacAddressLen = 6
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000196
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000197const cEmptyMacAddrString = "000000000000"
198const cEmptySerialNumberString = "0000000000000000"
199
Himani Chawla6d2ae152020-09-02 13:11:20 +0530200type swImages struct {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000201 version string
202 isActive uint8
203}
204
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000205type uniPersConfig struct {
206 PersUniID uint8 `json:"uni_id"`
207 PersTpPath string `json:"tp_path"`
mpagenko01e726e2020-10-23 09:45:29 +0000208 PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000209}
210
211type onuPersistentData struct {
212 PersOnuID uint32 `json:"onu_id"`
213 PersIntfID uint32 `json:"intf_id"`
214 PersSnr string `json:"serial_number"`
215 PersAdminState string `json:"admin_state"`
216 PersOperState string `json:"oper_state"`
217 PersUniConfig []uniPersConfig `json:"uni_config"`
218}
219
Himani Chawla6d2ae152020-09-02 13:11:20 +0530220// OnuDeviceEntry - ONU device info and FSM events.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221type OnuDeviceEntry struct {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000222 deviceID string
223 baseDeviceHandler *deviceHandler
224 coreProxy adapterif.CoreProxy
225 adapterProxy adapterif.AdapterProxy
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000226 PDevOmciCC *omciCC
227 pOnuDB *onuDeviceDB
228 mibTemplateKVStore *db.Backend
229 sOnuPersistentData onuPersistentData
230 onuKVStoreMutex sync.RWMutex
231 onuKVStore *db.Backend
232 onuKVStorePath string
233 onuKVStoreprocResult error //error indication of processing
234 chOnuKvProcessingStep chan uint8
235 vendorID string
236 serialNumber string
237 equipmentID string
238 swImages [secondSwImageMeID + 1]swImages
239 activeSwVersion string
240 macAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000241 //lockDeviceEntries sync.RWMutex
242 mibDbClass func() error
243 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000244 devState OnuDeviceEvent
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000245 // for mibUpload
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000246 mibAuditDelay uint16
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000247
248 // for mibUpload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000249 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
250 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000251 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
252 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
253 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300254 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
255 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000256}
257
Himani Chawla6d2ae152020-09-02 13:11:20 +0530258//newOnuDeviceEntry returns a new instance of a OnuDeviceEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000259//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530260func newOnuDeviceEntry(ctx context.Context, deviceID string, kVStoreHost string, kVStorePort int, kvStoreType string, deviceHandler *deviceHandler,
Himani Chawla26e555c2020-08-31 12:30:20 +0530261 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
262 supportedFsmsPtr *OmciDeviceFsms) *OnuDeviceEntry {
263 logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000264 var onuDeviceEntry OnuDeviceEntry
Himani Chawla26e555c2020-08-31 12:30:20 +0530265 onuDeviceEntry.deviceID = deviceID
266 onuDeviceEntry.baseDeviceHandler = deviceHandler
267 onuDeviceEntry.coreProxy = coreProxy
268 onuDeviceEntry.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000269 onuDeviceEntry.devState = DeviceStatusInit
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000270 onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
271 onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300272 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000273 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
274 //OMCI related databases are on a per-agent basis. State machines and tasks
275 //are per ONU Vendor
276 //
277 // MIB Synchronization Database - possible overloading from arguments
Himani Chawla26e555c2020-08-31 12:30:20 +0530278 if supportedFsmsPtr != nil {
279 onuDeviceEntry.supportedFsms = *supportedFsmsPtr
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280 } else {
281 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000282 // use some internaö defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000283 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
284 "mib-synchronizer": {
285 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530286 onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530287 //true, // Advertise events on OpenOMCI event bus
288 60, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000289 // map[string]func() error{
290 // "mib-upload": onuDeviceEntry.MibUploadTask,
291 // "mib-template": onuDeviceEntry.MibTemplateTask,
292 // "get-mds": onuDeviceEntry.GetMdsTask,
293 // "mib-audit": onuDeviceEntry.GetMdsTask,
294 // "mib-resync": onuDeviceEntry.MibResyncTask,
295 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
296 // },
297 },
298 }
299 }
300 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000301 logger.Debug("access2mibDbClass")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000302 go onuDeviceEntry.mibDbClass()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000303 onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
304 logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000306 // Omci related Mib upload sync state machine
307 mibUploadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530308 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", deviceID, mibUploadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000309 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000310 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000311 fsm.Events{
312
mpagenko1cc3cb42020-07-27 15:24:38 +0000313 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000314
mpagenko1cc3cb42020-07-27 15:24:38 +0000315 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
316 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530317 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
318 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000319 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
320 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
321 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000322
mpagenko1cc3cb42020-07-27 15:24:38 +0000323 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
324 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000325
mpagenko1cc3cb42020-07-27 15:24:38 +0000326 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync},
327 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000328
mpagenko1cc3cb42020-07-27 15:24:38 +0000329 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
330 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000331
mpagenko1cc3cb42020-07-27 15:24:38 +0000332 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000333
mpagenko1cc3cb42020-07-27 15:24:38 +0000334 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
335 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000336
mpagenko1cc3cb42020-07-27 15:24:38 +0000337 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
338 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
339 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000340
mpagenko1cc3cb42020-07-27 15:24:38 +0000341 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
342 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000343
Himani Chawla4d908332020-08-31 12:30:20 +0530344 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000345 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
346 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000347
Himani Chawla4d908332020-08-31 12:30:20 +0530348 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000349 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
350 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000351 },
352
353 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000354 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) },
355 ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
356 ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) },
357 ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) },
Himani Chawla4d908332020-08-31 12:30:20 +0530358 ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) },
mpagenko1cc3cb42020-07-27 15:24:38 +0000359 ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) },
360 ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) },
361 ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) },
362 ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) },
363 ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
364 ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
365 ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
366 ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
367 ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
368 ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000369 },
370 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000371 // Omci related Mib download state machine
372 mibDownloadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530373 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", deviceID, mibDownloadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000374 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000375 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000376 fsm.Events{
377
mpagenko1cc3cb42020-07-27 15:24:38 +0000378 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000379
mpagenko1cc3cb42020-07-27 15:24:38 +0000380 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
381 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
382 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000383 // the bridge state is used for multi ME config for alle UNI related ports
384 // maybe such could be reflected in the state machine as well (port number parametrized)
385 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000386 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000387
mpagenko1cc3cb42020-07-27 15:24:38 +0000388 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
389 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000390
mpagenko1cc3cb42020-07-27 15:24:38 +0000391 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
392 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
393 // exceptional treatment for all states except dlStResetting
394 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
395 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000396 },
397
398 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000399 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
400 ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) },
401 ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) },
402 ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) },
403 ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) },
404 ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) },
405 ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000406 },
407 )
408 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200409 logger.Errorw("MibDownloadFsm could not be instantiated", log.Fields{"device-id": deviceID})
410 // TODO some specifc error treatment - or waiting for crash ?
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000411 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000412
Himani Chawla6d2ae152020-09-02 13:11:20 +0530413 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000414 if onuDeviceEntry.mibTemplateKVStore == nil {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000415 logger.Errorw("Can't access mibTemplateKVStore - no backend connection to service",
416 log.Fields{"device-id": deviceID, "service": cBasePathMibTemplateKvStore})
417 }
418
419 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
420 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathOnuKVStore)
421 if onuDeviceEntry.onuKVStore == nil {
422 logger.Errorw("Can't access onuKVStore - no backend connection to service",
423 log.Fields{"device-id": deviceID, "service": cBasePathOnuKVStore})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000424 }
425
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000426 // Alarm Synchronization Database
427 //self._alarm_db = None
428 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
429 return &onuDeviceEntry
430}
431
Himani Chawla6d2ae152020-09-02 13:11:20 +0530432//start starts (logs) the omci agent
433func (oo *OnuDeviceEntry) start(ctx context.Context) error {
mpagenko900ee4b2020-10-12 11:56:34 +0000434 logger.Infow("OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000435 if oo.PDevOmciCC == nil {
mpagenko900ee4b2020-10-12 11:56:34 +0000436 oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
437 oo.coreProxy, oo.adapterProxy)
438 if oo.PDevOmciCC == nil {
439 logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
440 return fmt.Errorf("could not create devOmciCc %s", oo.deviceID)
441 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000442 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000443 return nil
444}
445
mpagenko900ee4b2020-10-12 11:56:34 +0000446//stop stops/resets the omciCC
447func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error {
448 logger.Debugw("OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID})
449 if abResetOmciCC && (oo.PDevOmciCC != nil) {
450 _ = oo.PDevOmciCC.stop(ctx)
451 }
452 //to allow for all event notifications again when re-using the device and omciCC
453 oo.devState = DeviceStatusInit
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000454 return nil
455}
456
Himani Chawla6d2ae152020-09-02 13:11:20 +0530457func (oo *OnuDeviceEntry) reboot(ctx context.Context) error {
mpagenko900ee4b2020-10-12 11:56:34 +0000458 logger.Debugw("OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID})
459 if oo.PDevOmciCC != nil {
460 if err := oo.PDevOmciCC.sendReboot(ctx, ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
461 logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
462 return err
463 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300464 }
ozgecanetsiae11479f2020-07-06 09:44:47 +0300465 return nil
466}
467
468func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error {
469 select {
470 case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
471 logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200472 return fmt.Errorf("rebootTimeout")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300473 case data := <-responseChannel:
474 switch data.Data.(OmciMessage).OmciMsg.MessageType {
475 case omci.RebootResponseType:
476 {
477 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
478 if msgLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200479 return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300480 }
Andrea Campanellabef4e542020-10-22 11:01:28 +0200481 msgObj, msgOk := msgLayer.(*omci.RebootResponse)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300482 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200483 return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300484 }
Andrea Campanellabef4e542020-10-22 11:01:28 +0200485 logger.Debugw("RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300486 if msgObj.Result != me.Success {
mpagenko01e726e2020-10-23 09:45:29 +0000487 logger.Errorw("Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300488 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
Andrea Campanellabef4e542020-10-22 11:01:28 +0200489 return fmt.Errorf("omci RebootResponse result error indication %s for device %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200490 msgObj.Result, oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300491 }
492 return nil
493 }
494 }
mpagenko01e726e2020-10-23 09:45:29 +0000495 logger.Warnw("Reboot response message type error", log.Fields{"for device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200496 return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300497 }
498}
499
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000500//Relay the InSync message via Handler to Rw core - Status update
Himani Chawla26e555c2020-08-31 12:30:20 +0530501func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) {
502 logger.Debugw("relaying system-event", log.Fields{"Event": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000503 // decouple the handler transfer from further processing here
504 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
Himani Chawla26e555c2020-08-31 12:30:20 +0530505 if devEvent == MibDatabaseSync {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000506 if oo.devState < MibDatabaseSync { //devState has not been synced yet
507 oo.devState = MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530508 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000509 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
510 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000511 logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
512 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530513 } else if devEvent == MibDownloadDone {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000514 if oo.devState < MibDownloadDone { //devState has not been synced yet
515 oo.devState = MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530516 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000517 } else {
518 logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000519 }
520 } else {
Himani Chawla26e555c2020-08-31 12:30:20 +0530521 logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000522 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000523}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000524
525func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error {
526 if oo.onuKVStore == nil {
527 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
528 return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID))
529 }
530 oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersConfig, 0)}
531 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
532 if err == nil {
533 if Value != nil {
534 logger.Debugw("ONU-data read",
535 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
536 tmpBytes, _ := kvstore.ToByte(Value.Value)
537
538 if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil {
539 logger.Errorw("unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
540 return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID))
541 }
542 logger.Debugw("ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
543 "device-id": oo.deviceID})
544 } else {
545 logger.Errorw("no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
546 return fmt.Errorf(fmt.Sprintf("no-ONU-data-found-%s", oo.deviceID))
547 }
548 } else {
549 logger.Errorw("unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
550 return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID))
551 }
552 return nil
553}
554
555func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
556 defer wg.Done()
557
558 if oo.onuKVStore == nil {
559 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
560 oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: onuKVStore not set")
561 return
562 }
563 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
564 go oo.deletePersistentData(ctx, processingStep)
565 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
566 //timeout or error detected
567 logger.Debugw("ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID})
568 oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: during kv-access")
569 return
570 }
571}
572
573func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) {
574
575 logger.Debugw("delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
576 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
577 if err != nil {
578 logger.Errorw("unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
579 oo.chOnuKvProcessingStep <- 0 //error indication
580 return
581 }
582 oo.chOnuKvProcessingStep <- aProcessingStep //done
583}
584
585func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
586 defer wg.Done()
587
588 if oo.onuKVStore == nil {
589 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
590 oo.onuKVStoreprocResult = errors.New("onu-data update aborted: onuKVStore not set")
591 return
592 }
593 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
594 go oo.storeDataInOnuKvStore(ctx, processingStep)
595 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
596 //timeout or error detected
597 logger.Debugw("ONU-data not written - abort", log.Fields{"device-id": oo.deviceID})
598 oo.onuKVStoreprocResult = errors.New("onu-data update aborted: during writing process")
599 return
600 }
601}
602
603func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) {
604
605 //assign values which are not already present when newOnuDeviceEntry() is called
606 oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId
607 oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId
608 oo.sOnuPersistentData.PersSnr = oo.baseDeviceHandler.pOnuOmciDevice.serialNumber
609 //TODO: verify usage of these values during restart UC
610 oo.sOnuPersistentData.PersAdminState = "up"
611 oo.sOnuPersistentData.PersOperState = "active"
612
613 logger.Debugw("Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData})
614
615 Value, err := json.Marshal(oo.sOnuPersistentData)
616 if err != nil {
617 logger.Errorw("unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
618 "device-id": oo.deviceID, "err": err})
619 oo.chOnuKvProcessingStep <- 0 //error indication
620 return
621 }
622 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
623 if err != nil {
624 logger.Errorw("unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
625 oo.chOnuKvProcessingStep <- 0 //error indication
626 return
627 }
628 oo.chOnuKvProcessingStep <- aProcessingStep //done
629}
630
631func (oo *OnuDeviceEntry) updateOnuUniTpPath(aUniID uint8, aPathString string) bool {
632 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
633 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
634 no specific concurrency protection to sOnuPersistentData is required here
635 */
636 for k, v := range oo.sOnuPersistentData.PersUniConfig {
637 if v.PersUniID == aUniID {
638 logger.Debugw("PersUniConfig-entry already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
639 existingPath := oo.sOnuPersistentData.PersUniConfig[k].PersTpPath
640 if existingPath != aPathString {
641 if aPathString == "" {
642 //existing entry to be deleted
643 logger.Debugw("UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
644 oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = ""
645 } else {
646 //existing entry to be modified
647 logger.Debugw("UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
648 oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = aPathString
649 }
650 return true
651 }
652 //entry already exists
mpagenkofc4f56e2020-11-04 17:17:49 +0000653 if aPathString == "" {
654 //no active TechProfile
655 logger.Debugw("UniTp path has already been removed - no AniSide config to be removed", log.Fields{
656 "device-id": oo.deviceID, "uniID": aUniID})
657 // attention 201105: this block is at the moment entered for each of subsequent GemPortDeletes and TContDelete
658 // as the path is already cleared with the first GemPort - this will probably change with the upcoming real
659 // TechProfile removal (still TODO), but anyway the reasonUpdate initiated here should not harm overall behavior
660 go oo.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
661 // no flow config pending on 'remove' so far
662 } else {
663 //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
664 //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
665 // (as here the TechProfile has not been removed with the disable-device before the new enable-device)
666 logger.Debugw("UniTp path already exists - TechProfile supposed to be active", log.Fields{
667 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
668 //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
669 // (during which the flows are removed/re-assigned but the techProf is left active)
670 //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
671 // (should not be the case, but should not harm or be more robust ...)
672 go oo.baseDeviceHandler.VerifyVlanConfigRequest(aUniID)
673 }
674 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 +0000675 }
676 }
677 //no entry exists for uniId
678
679 if aPathString == "" {
680 //delete request in non-existing state , accept as no change
681 logger.Debugw("UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
682 return false
683 }
684 //new entry to be created
685 logger.Debugw("New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
686 oo.sOnuPersistentData.PersUniConfig =
687 append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPath: aPathString, PersFlowParams: make([]uniVlanFlowParams, 0)})
688 return true
689}
690
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000691func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) {
692
693 for k, v := range oo.sOnuPersistentData.PersUniConfig {
694 if v.PersUniID == aUniID {
695 oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams))
696 copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
697 return
698 }
699 }
700 //flow update was faster than tp-config - create PersUniConfig-entry
701 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPath: "", PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))}
702 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
703 oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig)
704}
705
706func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion(
707 ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool {
708 select {
709 case <-ctx.Done():
710 logger.Warnw("processing not completed in-time!",
711 log.Fields{"device-id": oo.deviceID, "error": ctx.Err()})
712 return false
713 case rxStep := <-aChOnuProcessingStep:
714 if rxStep == aProcessingStep {
715 return true
716 }
717 //all other values are not accepted - including 0 for error indication
718 logger.Warnw("Invalid processing step received: abort!",
719 log.Fields{"device-id": oo.deviceID,
720 "wantedStep": aProcessingStep, "haveStep": rxStep})
721 return false
722 }
723}
724
725func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() {
726 oo.onuKVStoreprocResult = nil
727}
728func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error {
729 return oo.onuKVStoreprocResult
730}
731
732func (oo *OnuDeviceEntry) lockOnuKVStoreMutex() {
733 oo.onuKVStoreMutex.Lock()
734}
735
736func (oo *OnuDeviceEntry) unlockOnuKVStoreMutex() {
737 oo.onuKVStoreMutex.Unlock()
738}