blob: 8c1d0971b01b41bcb9dad9b5371656f1666f23a3 [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
121 DeviceStatusInit OnuDeviceEvent = 0
122 // MibDatabaseSync - MIB database sync (upload done)
123 MibDatabaseSync OnuDeviceEvent = 1
124 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
125 OmciCapabilitiesDone OnuDeviceEvent = 2
126 // MibDownloadDone - // MIB download done
127 MibDownloadDone OnuDeviceEvent = 3
128 // UniLockStateDone - Uni ports admin set to lock
129 UniLockStateDone OnuDeviceEvent = 4
130 // UniUnlockStateDone - Uni ports admin set to unlock
131 UniUnlockStateDone OnuDeviceEvent = 5
132 // UniAdminStateDone - Uni ports admin set done - general
133 UniAdminStateDone OnuDeviceEvent = 6
134 // PortLinkUp - Port link state change
135 PortLinkUp OnuDeviceEvent = 7
136 // PortLinkDw - Port link state change
137 PortLinkDw OnuDeviceEvent = 8
138 // OmciAniConfigDone - AniSide config according to TechProfile done
139 OmciAniConfigDone OnuDeviceEvent = 9
140 // OmciVlanFilterDone - Omci Vlan config according to flowConfig done
141 OmciVlanFilterDone OnuDeviceEvent = 10
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000142 // Add other events here as needed (alarms separate???)
143)
144
145type activityDescr struct {
Himani Chawla4d908332020-08-31 12:30:20 +0530146 databaseClass func() error
147 //advertiseEvents bool
148 auditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000149 //tasks map[string]func() error
150}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530151
152// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000153type OmciDeviceFsms map[string]activityDescr
154
Himani Chawla6d2ae152020-09-02 13:11:20 +0530155// AdapterFsm - Adapter FSM details including channel, event and device
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000156type AdapterFsm struct {
157 fsmName string
158 deviceID string
159 commChan chan Message
160 pFsm *fsm.FSM
161}
162
Himani Chawla6d2ae152020-09-02 13:11:20 +0530163//NewAdapterFsm - FSM details including event, device and channel.
164func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000165 aFsm := &AdapterFsm{
Himani Chawla6d2ae152020-09-02 13:11:20 +0530166 fsmName: aName,
167 deviceID: aDeviceID,
168 commChan: aCommChannel,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000169 }
170 return aFsm
171}
172
173//Start starts (logs) the omci agent
174func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) {
175 logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
176 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
177}
178
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000179//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000180
181const (
Himani Chawla6d2ae152020-09-02 13:11:20 +0530182 firstSwImageMeID = 0
183 secondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000184)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530185const onugMeID = 0
186const onu2gMeID = 0
187const ipHostConfigDataMeID = 1
188const onugSerialNumberLen = 8
189const omciMacAddressLen = 6
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000190
Himani Chawla6d2ae152020-09-02 13:11:20 +0530191type swImages struct {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000192 version string
193 isActive uint8
194}
195
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000196type uniVlanFlowParams struct {
197 TpID uint16 `json:"tp_id"`
198 MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting
199 MatchPcp uint32 `json:"match_pcp"`
200 TagsToRemove uint32 `json:"tags_to_revome"`
201 SetVid uint32 `json:"set_vid"`
202 SetPcp uint32 `json:"set_pcp"`
203}
204
205type uniPersConfig struct {
206 PersUniID uint8 `json:"uni_id"`
207 PersTpPath string `json:"tp_path"`
208 PersFlowParams []uniVlanFlowParams `json:"flow_params"`
209}
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
226 started bool
227 PDevOmciCC *omciCC
228 pOnuDB *onuDeviceDB
229 mibTemplateKVStore *db.Backend
230 sOnuPersistentData onuPersistentData
231 onuKVStoreMutex sync.RWMutex
232 onuKVStore *db.Backend
233 onuKVStorePath string
234 onuKVStoreprocResult error //error indication of processing
235 chOnuKvProcessingStep chan uint8
236 vendorID string
237 serialNumber string
238 equipmentID string
239 swImages [secondSwImageMeID + 1]swImages
240 activeSwVersion string
241 macAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000242 //lockDeviceEntries sync.RWMutex
243 mibDbClass func() error
244 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000245 devState OnuDeviceEvent
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000246 // for mibUpload
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000247 mibAuditDelay uint16
mpagenko1cc3cb42020-07-27 15:24:38 +0000248 mibDebugLevel string
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000249
250 // for mibUpload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000251 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
252 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000253 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
254 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
255 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300256 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
257 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000258}
259
Himani Chawla6d2ae152020-09-02 13:11:20 +0530260//newOnuDeviceEntry returns a new instance of a OnuDeviceEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000261//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530262func newOnuDeviceEntry(ctx context.Context, deviceID string, kVStoreHost string, kVStorePort int, kvStoreType string, deviceHandler *deviceHandler,
Himani Chawla26e555c2020-08-31 12:30:20 +0530263 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
264 supportedFsmsPtr *OmciDeviceFsms) *OnuDeviceEntry {
265 logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000266 var onuDeviceEntry OnuDeviceEntry
267 onuDeviceEntry.started = false
Himani Chawla26e555c2020-08-31 12:30:20 +0530268 onuDeviceEntry.deviceID = deviceID
269 onuDeviceEntry.baseDeviceHandler = deviceHandler
270 onuDeviceEntry.coreProxy = coreProxy
271 onuDeviceEntry.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000272 onuDeviceEntry.devState = DeviceStatusInit
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000273 onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0)
274 onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300275 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000276 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
277 //OMCI related databases are on a per-agent basis. State machines and tasks
278 //are per ONU Vendor
279 //
280 // MIB Synchronization Database - possible overloading from arguments
Himani Chawla26e555c2020-08-31 12:30:20 +0530281 if supportedFsmsPtr != nil {
282 onuDeviceEntry.supportedFsms = *supportedFsmsPtr
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000283 } else {
284 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000285 // use some internaö defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000286 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
287 "mib-synchronizer": {
288 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530289 onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530290 //true, // Advertise events on OpenOMCI event bus
291 60, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292 // map[string]func() error{
293 // "mib-upload": onuDeviceEntry.MibUploadTask,
294 // "mib-template": onuDeviceEntry.MibTemplateTask,
295 // "get-mds": onuDeviceEntry.GetMdsTask,
296 // "mib-audit": onuDeviceEntry.GetMdsTask,
297 // "mib-resync": onuDeviceEntry.MibResyncTask,
298 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
299 // },
300 },
301 }
302 }
303 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000304 logger.Debug("access2mibDbClass")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305 go onuDeviceEntry.mibDbClass()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000306 onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
307 logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000308
mpagenko1cc3cb42020-07-27 15:24:38 +0000309 onuDeviceEntry.mibDebugLevel = "normal" //set to "verbose" if you want to have all output, possibly later also per config option!
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000310 // Omci related Mib upload sync state machine
311 mibUploadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530312 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", deviceID, mibUploadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000313 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000314 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000315 fsm.Events{
316
mpagenko1cc3cb42020-07-27 15:24:38 +0000317 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000318
mpagenko1cc3cb42020-07-27 15:24:38 +0000319 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
320 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530321 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
322 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000323 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
324 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
325 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000326
mpagenko1cc3cb42020-07-27 15:24:38 +0000327 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
328 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000329
mpagenko1cc3cb42020-07-27 15:24:38 +0000330 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync},
331 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000332
mpagenko1cc3cb42020-07-27 15:24:38 +0000333 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
334 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000335
mpagenko1cc3cb42020-07-27 15:24:38 +0000336 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000337
mpagenko1cc3cb42020-07-27 15:24:38 +0000338 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
339 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000340
mpagenko1cc3cb42020-07-27 15:24:38 +0000341 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
342 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
343 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000344
mpagenko1cc3cb42020-07-27 15:24:38 +0000345 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
346 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000347
Himani Chawla4d908332020-08-31 12:30:20 +0530348 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000349 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
350 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000351
Himani Chawla4d908332020-08-31 12:30:20 +0530352 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000353 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
354 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000355 },
356
357 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000358 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) },
359 ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
360 ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) },
361 ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) },
Himani Chawla4d908332020-08-31 12:30:20 +0530362 ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) },
mpagenko1cc3cb42020-07-27 15:24:38 +0000363 ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) },
364 ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) },
365 ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) },
366 ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) },
367 ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
368 ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
369 ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
370 ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
371 ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
372 ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000373 },
374 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000375 // Omci related Mib download state machine
376 mibDownloadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530377 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", deviceID, mibDownloadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000378 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000379 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000380 fsm.Events{
381
mpagenko1cc3cb42020-07-27 15:24:38 +0000382 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000383
mpagenko1cc3cb42020-07-27 15:24:38 +0000384 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
385 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
386 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000387 // the bridge state is used for multi ME config for alle UNI related ports
388 // maybe such could be reflected in the state machine as well (port number parametrized)
389 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000390 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000391
mpagenko1cc3cb42020-07-27 15:24:38 +0000392 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
393 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000394
mpagenko1cc3cb42020-07-27 15:24:38 +0000395 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
396 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
397 // exceptional treatment for all states except dlStResetting
398 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
399 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000400 },
401
402 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000403 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
404 ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) },
405 ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) },
406 ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) },
407 ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) },
408 ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) },
409 ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000410 },
411 )
412 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
413 logger.Error("MibDownloadFsm could not be instantiated!!")
414 // some specifc error treatment - or waiting for crash ???
415 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000416
Himani Chawla6d2ae152020-09-02 13:11:20 +0530417 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000418 if onuDeviceEntry.mibTemplateKVStore == nil {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000419 logger.Errorw("Can't access mibTemplateKVStore - no backend connection to service",
420 log.Fields{"device-id": deviceID, "service": cBasePathMibTemplateKvStore})
421 }
422
423 onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
424 onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathOnuKVStore)
425 if onuDeviceEntry.onuKVStore == nil {
426 logger.Errorw("Can't access onuKVStore - no backend connection to service",
427 log.Fields{"device-id": deviceID, "service": cBasePathOnuKVStore})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000428 }
429
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000430 // Alarm Synchronization Database
431 //self._alarm_db = None
432 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
433 return &onuDeviceEntry
434}
435
Himani Chawla6d2ae152020-09-02 13:11:20 +0530436//start starts (logs) the omci agent
437func (oo *OnuDeviceEntry) start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000438 logger.Info("starting-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000439
Himani Chawla6d2ae152020-09-02 13:11:20 +0530440 oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000441 oo.coreProxy, oo.adapterProxy)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000442 if oo.PDevOmciCC == nil {
divyadesai4d299552020-08-18 07:13:49 +0000443 logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530444 return errors.New("could not create devOmciCc")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000445 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000446
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000447 oo.started = true
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000448 logger.Info("OnuDeviceEntry-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000449 return nil
450}
451
Himani Chawla6d2ae152020-09-02 13:11:20 +0530452//stop terminates the session
453func (oo *OnuDeviceEntry) stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000454 logger.Info("stopping-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000455 oo.started = false
456 //oo.exitChannel <- 1
mpagenko3af1f032020-06-10 08:53:41 +0000457 // maybe also the omciCC should be stopped here - for now not as no real processing is expected here - maybe needs consolidation
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000458 logger.Info("OnuDeviceEntry-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000459 return nil
460}
461
Himani Chawla6d2ae152020-09-02 13:11:20 +0530462func (oo *OnuDeviceEntry) reboot(ctx context.Context) error {
ozgecanetsiae11479f2020-07-06 09:44:47 +0300463 logger.Info("reboot-OnuDeviceEntry")
464 if err := oo.PDevOmciCC.sendReboot(context.TODO(), ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
divyadesai4d299552020-08-18 07:13:49 +0000465 logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300466 return err
467 }
468 logger.Info("OnuDeviceEntry-reboot")
469 return nil
470}
471
472func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error {
473 select {
474 case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
475 logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530476 return errors.New("rebootTimeout")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300477 case data := <-responseChannel:
478 switch data.Data.(OmciMessage).OmciMsg.MessageType {
479 case omci.RebootResponseType:
480 {
481 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
482 if msgLayer == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530483 return errors.New("omci Msg layer could not be detected for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300484 }
485 msgObj, msgOk := msgLayer.(*omci.GetResponse)
486 if !msgOk {
Himani Chawla26e555c2020-08-31 12:30:20 +0530487 return errors.New("omci Msg layer could not be assigned for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300488 }
divyadesai4d299552020-08-18 07:13:49 +0000489 logger.Debugw("CreateResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300490 if msgObj.Result != me.Success {
491 logger.Errorw("Omci RebootResponseType Error ", log.Fields{"Error": msgObj.Result})
492 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
Himani Chawla26e555c2020-08-31 12:30:20 +0530493 return errors.New("omci RebootResponse Result Error indication")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300494 }
495 return nil
496 }
497 }
498 logger.Warnw("Reboot response error", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530499 return errors.New("unexpected OmciResponse type received")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300500 }
501}
502
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000503//Relay the InSync message via Handler to Rw core - Status update
Himani Chawla26e555c2020-08-31 12:30:20 +0530504func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) {
505 logger.Debugw("relaying system-event", log.Fields{"Event": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000506 // decouple the handler transfer from further processing here
507 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
Himani Chawla26e555c2020-08-31 12:30:20 +0530508 if devEvent == MibDatabaseSync {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000509 if oo.devState < MibDatabaseSync { //devState has not been synced yet
510 oo.devState = MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530511 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000512 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
513 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000514 logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
515 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530516 } else if devEvent == MibDownloadDone {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000517 if oo.devState < MibDownloadDone { //devState has not been synced yet
518 oo.devState = MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530519 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000520 } else {
521 logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000522 }
523 } else {
Himani Chawla26e555c2020-08-31 12:30:20 +0530524 logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000525 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000526}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000527
528func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error {
529 if oo.onuKVStore == nil {
530 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
531 return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID))
532 }
533 oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersConfig, 0)}
534 Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath)
535 if err == nil {
536 if Value != nil {
537 logger.Debugw("ONU-data read",
538 log.Fields{"Key": Value.Key, "device-id": oo.deviceID})
539 tmpBytes, _ := kvstore.ToByte(Value.Value)
540
541 if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil {
542 logger.Errorw("unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID})
543 return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID))
544 }
545 logger.Debugw("ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
546 "device-id": oo.deviceID})
547 } else {
548 logger.Errorw("no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID})
549 return fmt.Errorf(fmt.Sprintf("no-ONU-data-found-%s", oo.deviceID))
550 }
551 } else {
552 logger.Errorw("unable to read from KVstore", log.Fields{"device-id": oo.deviceID})
553 return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID))
554 }
555 return nil
556}
557
558func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
559 defer wg.Done()
560
561 if oo.onuKVStore == nil {
562 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
563 oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: onuKVStore not set")
564 return
565 }
566 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
567 go oo.deletePersistentData(ctx, processingStep)
568 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
569 //timeout or error detected
570 logger.Debugw("ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID})
571 oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: during kv-access")
572 return
573 }
574}
575
576func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) {
577
578 logger.Debugw("delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID})
579 err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath)
580 if err != nil {
581 logger.Errorw("unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
582 oo.chOnuKvProcessingStep <- 0 //error indication
583 return
584 }
585 oo.chOnuKvProcessingStep <- aProcessingStep //done
586}
587
588func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) {
589 defer wg.Done()
590
591 if oo.onuKVStore == nil {
592 logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID})
593 oo.onuKVStoreprocResult = errors.New("onu-data update aborted: onuKVStore not set")
594 return
595 }
596 var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep
597 go oo.storeDataInOnuKvStore(ctx, processingStep)
598 if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) {
599 //timeout or error detected
600 logger.Debugw("ONU-data not written - abort", log.Fields{"device-id": oo.deviceID})
601 oo.onuKVStoreprocResult = errors.New("onu-data update aborted: during writing process")
602 return
603 }
604}
605
606func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) {
607
608 //assign values which are not already present when newOnuDeviceEntry() is called
609 oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId
610 oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId
611 oo.sOnuPersistentData.PersSnr = oo.baseDeviceHandler.pOnuOmciDevice.serialNumber
612 //TODO: verify usage of these values during restart UC
613 oo.sOnuPersistentData.PersAdminState = "up"
614 oo.sOnuPersistentData.PersOperState = "active"
615
616 logger.Debugw("Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData})
617
618 Value, err := json.Marshal(oo.sOnuPersistentData)
619 if err != nil {
620 logger.Errorw("unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData,
621 "device-id": oo.deviceID, "err": err})
622 oo.chOnuKvProcessingStep <- 0 //error indication
623 return
624 }
625 err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value)
626 if err != nil {
627 logger.Errorw("unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err})
628 oo.chOnuKvProcessingStep <- 0 //error indication
629 return
630 }
631 oo.chOnuKvProcessingStep <- aProcessingStep //done
632}
633
634func (oo *OnuDeviceEntry) updateOnuUniTpPath(aUniID uint8, aPathString string) bool {
635 /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially,
636 as also the complete sequence is ensured to 'run to completion' before some new request is accepted
637 no specific concurrency protection to sOnuPersistentData is required here
638 */
639 for k, v := range oo.sOnuPersistentData.PersUniConfig {
640 if v.PersUniID == aUniID {
641 logger.Debugw("PersUniConfig-entry already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
642 existingPath := oo.sOnuPersistentData.PersUniConfig[k].PersTpPath
643 if existingPath != aPathString {
644 if aPathString == "" {
645 //existing entry to be deleted
646 logger.Debugw("UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
647 oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = ""
648 } else {
649 //existing entry to be modified
650 logger.Debugw("UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
651 oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = aPathString
652 }
653 return true
654 }
655 //entry already exists
656 logger.Debugw("UniTp path already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
657 return false
658 }
659 }
660 //no entry exists for uniId
661
662 if aPathString == "" {
663 //delete request in non-existing state , accept as no change
664 logger.Debugw("UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID})
665 return false
666 }
667 //new entry to be created
668 logger.Debugw("New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
669 oo.sOnuPersistentData.PersUniConfig =
670 append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPath: aPathString, PersFlowParams: make([]uniVlanFlowParams, 0)})
671 return true
672}
673
674// deleteTpResource removes Resources from the ONU's specified Uni
675func (oo *OnuDeviceEntry) deleteTpResource(ctx context.Context,
676 aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
677 wg *sync.WaitGroup) {
678 defer wg.Done()
679 logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{
680 "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
681 //TODO!!!
682 //delete the given resource from ONU OMCI config and data base - as background routine
683 /*
684 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
685 go onuTp.deleteAniResource(ctx, processingStep)
686 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
687 //timeout or error detected
688 return
689 }
690 */
691}
692
693func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) {
694
695 for k, v := range oo.sOnuPersistentData.PersUniConfig {
696 if v.PersUniID == aUniID {
697 oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams))
698 copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams)
699 return
700 }
701 }
702 //flow update was faster than tp-config - create PersUniConfig-entry
703 tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPath: "", PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))}
704 copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams)
705 oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig)
706}
707
708func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion(
709 ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool {
710 select {
711 case <-ctx.Done():
712 logger.Warnw("processing not completed in-time!",
713 log.Fields{"device-id": oo.deviceID, "error": ctx.Err()})
714 return false
715 case rxStep := <-aChOnuProcessingStep:
716 if rxStep == aProcessingStep {
717 return true
718 }
719 //all other values are not accepted - including 0 for error indication
720 logger.Warnw("Invalid processing step received: abort!",
721 log.Fields{"device-id": oo.deviceID,
722 "wantedStep": aProcessingStep, "haveStep": rxStep})
723 return false
724 }
725}
726
727func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() {
728 oo.onuKVStoreprocResult = nil
729}
730func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error {
731 return oo.onuKVStoreprocResult
732}
733
734func (oo *OnuDeviceEntry) lockOnuKVStoreMutex() {
735 oo.onuKVStoreMutex.Lock()
736}
737
738func (oo *OnuDeviceEntry) unlockOnuKVStoreMutex() {
739 oo.onuKVStoreMutex.Unlock()
740}