Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 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 Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 22 | "errors" |
| 23 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | //"sync" |
| 25 | //"time" |
| 26 | |
| 27 | "github.com/looplab/fsm" |
| 28 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 30 | |
| 31 | //"github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 33 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 34 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 35 | //"github.com/opencord/voltha-protos/v3/go/voltha" |
| 36 | ) |
| 37 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 38 | const ( |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 39 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/templates" |
| 40 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 41 | ) |
| 42 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 43 | type OnuDeviceEvent int |
| 44 | |
| 45 | const ( |
| 46 | // Events of interest to Device Adapters and OpenOMCI State Machines |
| 47 | DeviceStatusInit OnuDeviceEvent = 0 // OnuDeviceEntry default start state |
| 48 | MibDatabaseSync OnuDeviceEvent = 1 // MIB database sync (upload done) |
| 49 | OmciCapabilitiesDone OnuDeviceEvent = 2 // OMCI ME and message type capabilities known |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 50 | MibDownloadDone OnuDeviceEvent = 3 // MIB database sync (upload done) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 51 | UniLockStateDone OnuDeviceEvent = 4 // Uni ports admin set to lock |
| 52 | UniUnlockStateDone OnuDeviceEvent = 5 // Uni ports admin set to unlock |
| 53 | UniAdminStateDone OnuDeviceEvent = 6 // Uni ports admin set done - general |
| 54 | PortLinkUp OnuDeviceEvent = 7 // Port link state change |
| 55 | PortLinkDw OnuDeviceEvent = 8 // Port link state change |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame^] | 56 | OmciAniConfigDone OnuDeviceEvent = 9 // AniSide config according to TechProfile done |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 57 | // Add other events here as needed (alarms separate???) |
| 58 | ) |
| 59 | |
| 60 | type activityDescr struct { |
| 61 | databaseClass func() error |
| 62 | advertiseEvents bool |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 63 | auditDelay uint16 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 64 | //tasks map[string]func() error |
| 65 | } |
| 66 | type OmciDeviceFsms map[string]activityDescr |
| 67 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 68 | type AdapterFsm struct { |
| 69 | fsmName string |
| 70 | deviceID string |
| 71 | commChan chan Message |
| 72 | pFsm *fsm.FSM |
| 73 | } |
| 74 | |
| 75 | func NewAdapterFsm(a_name string, a_deviceID string, a_commChannel chan Message) *AdapterFsm { |
| 76 | aFsm := &AdapterFsm{ |
| 77 | fsmName: a_name, |
| 78 | deviceID: a_deviceID, |
| 79 | commChan: a_commChannel, |
| 80 | } |
| 81 | return aFsm |
| 82 | } |
| 83 | |
| 84 | //Start starts (logs) the omci agent |
| 85 | func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) { |
| 86 | logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName, |
| 87 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 88 | } |
| 89 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 90 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 91 | |
| 92 | const ( |
| 93 | FirstSwImageMeId = 0 |
| 94 | SecondSwImageMeId = 1 |
| 95 | ) |
| 96 | const OnugMeId = 0 |
| 97 | const Onu2gMeId = 0 |
| 98 | const IpHostConfigDataMeId = 1 |
| 99 | const OnugSerialNumberLen = 8 |
| 100 | const OmciMacAddressLen = 6 |
| 101 | |
| 102 | type SwImages struct { |
| 103 | version string |
| 104 | isActive uint8 |
| 105 | } |
| 106 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 107 | type OnuDeviceEntry struct { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 108 | deviceID string |
| 109 | baseDeviceHandler *DeviceHandler |
| 110 | coreProxy adapterif.CoreProxy |
| 111 | adapterProxy adapterif.AdapterProxy |
| 112 | started bool |
| 113 | PDevOmciCC *OmciCC |
| 114 | pOnuDB *OnuDeviceDB |
| 115 | mibTemplateKVStore *db.Backend |
| 116 | vendorID string |
| 117 | serialNumber string |
| 118 | equipmentID string |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 119 | swImages [SecondSwImageMeId + 1]SwImages |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 120 | activeSwVersion string |
| 121 | macAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | //lockDeviceEntries sync.RWMutex |
| 123 | mibDbClass func() error |
| 124 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 125 | devState OnuDeviceEvent |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 126 | // for mibUpload |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 127 | mibAuditDelay uint16 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 128 | |
| 129 | // for mibUpload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 130 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 131 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 132 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 133 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 134 | // within the FSM event procedures |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 135 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | //OnuDeviceEntry returns a new instance of a OnuDeviceEntry |
| 139 | //mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 140 | func NewOnuDeviceEntry(ctx context.Context, device_id string, kVStoreHost string, kVStorePort int, kvStoreType string, device_Handler *DeviceHandler, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 141 | core_proxy adapterif.CoreProxy, adapter_proxy adapterif.AdapterProxy, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 142 | supported_Fsms_Ptr *OmciDeviceFsms) *OnuDeviceEntry { |
| 143 | logger.Infow("init-onuDeviceEntry", log.Fields{"deviceId": device_id}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | var onuDeviceEntry OnuDeviceEntry |
| 145 | onuDeviceEntry.started = false |
| 146 | onuDeviceEntry.deviceID = device_id |
| 147 | onuDeviceEntry.baseDeviceHandler = device_Handler |
| 148 | onuDeviceEntry.coreProxy = core_proxy |
| 149 | onuDeviceEntry.adapterProxy = adapter_proxy |
| 150 | onuDeviceEntry.devState = DeviceStatusInit |
| 151 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 152 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 153 | //are per ONU Vendor |
| 154 | // |
| 155 | // MIB Synchronization Database - possible overloading from arguments |
| 156 | if supported_Fsms_Ptr != nil { |
| 157 | onuDeviceEntry.supportedFsms = *supported_Fsms_Ptr |
| 158 | } else { |
| 159 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 160 | // use some internaö defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 161 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 162 | "mib-synchronizer": { |
| 163 | //mibSyncFsm, // Implements the MIB synchronization state machine |
| 164 | onuDeviceEntry.MibDbVolatileDict, // Implements volatile ME MIB database |
| 165 | true, // Advertise events on OpenOMCI event bus |
| 166 | 60, // Time to wait between MIB audits. 0 to disable audits. |
| 167 | // map[string]func() error{ |
| 168 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 169 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 170 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 171 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 172 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 173 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 174 | // }, |
| 175 | }, |
| 176 | } |
| 177 | } |
| 178 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 179 | logger.Debug("access2mibDbClass") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 180 | go onuDeviceEntry.mibDbClass() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 181 | onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay |
| 182 | logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 183 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 184 | // Omci related Mib upload sync state machine |
| 185 | mibUploadChan := make(chan Message, 2048) |
| 186 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", device_id, mibUploadChan) |
| 187 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 188 | "disabled", |
| 189 | fsm.Events{ |
| 190 | |
| 191 | {Name: "start", Src: []string{"disabled"}, Dst: "starting"}, |
| 192 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 193 | {Name: "reset_mib", Src: []string{"starting"}, Dst: "resetting_mib"}, |
| 194 | {Name: "get_vendor_and_serial", Src: []string{"resetting_mib"}, Dst: "getting_vendor_and_serial"}, |
| 195 | {Name: "get_equipment_id", Src: []string{"getting_vendor_and_serial"}, Dst: "getting_equipment_id"}, |
| 196 | {Name: "get_first_sw_version", Src: []string{"getting_equipment_id"}, Dst: "getting_first_sw_version"}, |
| 197 | {Name: "get_second_sw_version", Src: []string{"getting_first_sw_version"}, Dst: "getting_second_sw_version"}, |
| 198 | {Name: "get_mac_address", Src: []string{"getting_second_sw_version"}, Dst: "getting_mac_address"}, |
| 199 | {Name: "get_mib_template", Src: []string{"getting_mac_address"}, Dst: "getting_mib_template"}, |
| 200 | |
| 201 | {Name: "upload_mib", Src: []string{"getting_mib_template"}, Dst: "uploading"}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 202 | {Name: "examine_mds", Src: []string{"starting"}, Dst: "examining_mds"}, |
| 203 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 204 | {Name: "success", Src: []string{"getting_mib_template"}, Dst: "in_sync"}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 205 | {Name: "success", Src: []string{"uploading"}, Dst: "in_sync"}, |
| 206 | |
| 207 | {Name: "success", Src: []string{"examining_mds"}, Dst: "in_sync"}, |
| 208 | {Name: "mismatch", Src: []string{"examining_mds"}, Dst: "resynchronizing"}, |
| 209 | |
| 210 | {Name: "audit_mib", Src: []string{"in_sync"}, Dst: "auditing"}, |
| 211 | |
| 212 | {Name: "success", Src: []string{"out_of_sync"}, Dst: "in_sync"}, |
| 213 | {Name: "audit_mib", Src: []string{"out_of_sync"}, Dst: "auditing"}, |
| 214 | |
| 215 | {Name: "success", Src: []string{"auditing"}, Dst: "in_sync"}, |
| 216 | {Name: "mismatch", Src: []string{"auditing"}, Dst: "resynchronizing"}, |
| 217 | {Name: "force_resync", Src: []string{"auditing"}, Dst: "resynchronizing"}, |
| 218 | |
| 219 | {Name: "success", Src: []string{"resynchronizing"}, Dst: "in_sync"}, |
| 220 | {Name: "diffs_found", Src: []string{"resynchronizing"}, Dst: "out_of_sync"}, |
| 221 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 222 | {Name: "timeout", Src: []string{"reset_mib", "get_vendor_and_serial", "get_equipment_id", "get_first_sw_version", "get_mac_address", |
| 223 | "get_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "starting"}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 224 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 225 | {Name: "stop", Src: []string{"starting", "reset_mib", "get_vendor_and_serial", "get_equipment_id", "get_first_sw_version", "get_mac_address", |
| 226 | "get_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "disabled"}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 227 | }, |
| 228 | |
| 229 | fsm.Callbacks{ |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 230 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) }, |
| 231 | "enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) }, |
| 232 | "enter_resetting_mib": func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) }, |
| 233 | "enter_getting_vendor_and_serial": func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) }, |
| 234 | "enter_getting_equipment_id": func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIdState(e) }, |
| 235 | "enter_getting_first_sw_version": func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) }, |
| 236 | "enter_getting_second_sw_version": func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) }, |
| 237 | "enter_getting_mac_address": func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) }, |
| 238 | "enter_getting_mib_template": func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) }, |
| 239 | "enter_uploading": func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) }, |
| 240 | "enter_examining_mds": func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) }, |
| 241 | "enter_resynchronizing": func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) }, |
| 242 | "enter_auditing": func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) }, |
| 243 | "enter_out_of_sync": func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) }, |
| 244 | "enter_in_sync": func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 245 | }, |
| 246 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 247 | // Omci related Mib download state machine |
| 248 | mibDownloadChan := make(chan Message, 2048) |
| 249 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", device_id, mibDownloadChan) |
| 250 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
| 251 | "disabled", |
| 252 | fsm.Events{ |
| 253 | |
| 254 | {Name: "start", Src: []string{"disabled"}, Dst: "starting"}, |
| 255 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 256 | {Name: "create_gal", Src: []string{"starting"}, Dst: "creatingGal"}, |
| 257 | {Name: "rx_gal_resp", Src: []string{"creatingGal"}, Dst: "settingOnu2g"}, |
| 258 | {Name: "rx_onu2g_resp", Src: []string{"settingOnu2g"}, Dst: "bridgeInit"}, |
| 259 | // the bridge state is used for multi ME config for alle UNI related ports |
| 260 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 261 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
| 262 | {Name: "rx_bridge_resp", Src: []string{"bridgeInit"}, Dst: "downloaded"}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 263 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 264 | {Name: "timeout_simple", Src: []string{"creatingGal", "settingOnu2g"}, Dst: "starting"}, |
| 265 | {Name: "timeout_bridge", Src: []string{"bridgeInit"}, Dst: "starting"}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 266 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 267 | {Name: "reset", Src: []string{"starting", "creatingGal", "settingOnu2g", |
| 268 | "bridgeInit", "downloaded"}, Dst: "resetting"}, |
| 269 | // exceptional treatment for all states except "resetting" |
| 270 | {Name: "restart", Src: []string{"starting", "creatingGal", "settingOnu2g", |
| 271 | "bridgeInit", "downloaded", "resetting"}, Dst: "disabled"}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 272 | }, |
| 273 | |
| 274 | fsm.Callbacks{ |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 275 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) }, |
| 276 | "enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) }, |
| 277 | "enter_creatingGal": func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) }, |
| 278 | "enter_settingOnu2g": func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) }, |
| 279 | "enter_bridgeInit": func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) }, |
| 280 | "enter_downloaded": func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) }, |
| 281 | "enter_resetting": func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 282 | }, |
| 283 | ) |
| 284 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
| 285 | logger.Error("MibDownloadFsm could not be instantiated!!") |
| 286 | // some specifc error treatment - or waiting for crash ??? |
| 287 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 288 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 289 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 290 | if onuDeviceEntry.mibTemplateKVStore == nil { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 291 | logger.Errorw("Failed to setup mibTemplateKVStore", log.Fields{"deviceID": device_id}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 294 | // Alarm Synchronization Database |
| 295 | //self._alarm_db = None |
| 296 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 297 | return &onuDeviceEntry |
| 298 | } |
| 299 | |
| 300 | //Start starts (logs) the omci agent |
| 301 | func (oo *OnuDeviceEntry) Start(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 302 | logger.Info("starting-OnuDeviceEntry") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 303 | |
| 304 | oo.PDevOmciCC = NewOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 305 | oo.coreProxy, oo.adapterProxy) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 306 | if oo.PDevOmciCC == nil { |
| 307 | logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device": oo.deviceID}) |
| 308 | return errors.New("Could not create devOmciCc") |
| 309 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 310 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 311 | oo.started = true |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 312 | logger.Info("OnuDeviceEntry-started") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 313 | return nil |
| 314 | } |
| 315 | |
| 316 | //Stop terminates the session |
| 317 | func (oo *OnuDeviceEntry) Stop(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 318 | logger.Info("stopping-OnuDeviceEntry") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 319 | oo.started = false |
| 320 | //oo.exitChannel <- 1 |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 321 | // maybe also the omciCC should be stopped here - for now not as no real processing is expected here - maybe needs consolidation |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 322 | logger.Info("OnuDeviceEntry-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 323 | return nil |
| 324 | } |
| 325 | |
| 326 | //Relay the InSync message via Handler to Rw core - Status update |
| 327 | func (oo *OnuDeviceEntry) transferSystemEvent(dev_Event OnuDeviceEvent) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 328 | logger.Debugw("relaying system-event", log.Fields{"Event": dev_Event}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 329 | // decouple the handler transfer from further processing here |
| 330 | // TODO!!! check if really no synch is required within the system e.g. to ensure following steps .. |
| 331 | if dev_Event == MibDatabaseSync { |
| 332 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 333 | oo.devState = MibDatabaseSync |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 334 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(dev_Event) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 335 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 336 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 337 | logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState}) |
| 338 | } |
| 339 | } else if dev_Event == MibDownloadDone { |
| 340 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 341 | oo.devState = MibDownloadDone |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 342 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(dev_Event) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 343 | } else { |
| 344 | logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 345 | } |
| 346 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 347 | logger.Warnw("device-event not yet handled", log.Fields{"state": dev_Event}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 348 | } |
| 349 | return nil |
| 350 | } |