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" |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 23 | "time" |
| 24 | |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 25 | "github.com/opencord/omci-lib-go" |
| 26 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 27 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 28 | //"sync" |
| 29 | //"time" |
| 30 | |
| 31 | "github.com/looplab/fsm" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 34 | |
| 35 | //"github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 36 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 37 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 38 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 39 | //"github.com/opencord/voltha-protos/v3/go/voltha" |
| 40 | ) |
| 41 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 42 | const ( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 43 | // events of MibUpload FSM |
| 44 | ulEvStart = "ulEvStart" |
| 45 | ulEvResetMib = "ulEvResetMib" |
| 46 | ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 47 | ulEvGetEquipmentID = "ulEvGetEquipmentId" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 48 | ulEvGetFirstSwVersion = "ulEvGetFirstSwVersion" |
| 49 | ulEvGetSecondSwVersion = "ulEvGetSecondSwVersion" |
| 50 | ulEvGetMacAddress = "ulEvGetMacAddress" |
| 51 | ulEvGetMibTemplate = "ulEvGetMibTemplate" |
| 52 | ulEvUploadMib = "ulEvUploadMib" |
| 53 | ulEvExamineMds = "ulEvExamineMds" |
| 54 | ulEvSuccess = "ulEvSuccess" |
| 55 | ulEvMismatch = "ulEvMismatch" |
| 56 | ulEvAuditMib = "ulEvAuditMib" |
| 57 | ulEvForceResync = "ulEvForceResync" |
| 58 | ulEvDiffsFound = "ulEvDiffsFound" |
| 59 | ulEvTimeout = "ulEvTimeout" |
| 60 | ulEvStop = "ulEvStop" |
| 61 | ) |
| 62 | const ( |
| 63 | // states of MibUpload FSM |
| 64 | ulStDisabled = "ulStDisabled" |
| 65 | ulStStarting = "ulStStarting" |
| 66 | ulStResettingMib = "ulStResettingMib" |
| 67 | ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 68 | ulStGettingEquipmentID = "ulStGettingEquipmentID" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 69 | ulStGettingFirstSwVersion = "ulStGettingFirstSwVersion" |
| 70 | ulStGettingSecondSwVersion = "ulStGettingSecondSwVersion" |
| 71 | ulStGettingMacAddress = "ulStGettingMacAddress" |
| 72 | ulStGettingMibTemplate = "ulStGettingMibTemplate" |
| 73 | ulStUploading = "ulStUploading" |
| 74 | ulStInSync = "ulStInSync" |
| 75 | ulStExaminingMds = "ulStExaminingMds" |
| 76 | ulStResynchronizing = "ulStResynchronizing" |
| 77 | ulStAuditing = "ulStAuditing" |
| 78 | ulStOutOfSync = "ulStOutOfSync" |
| 79 | ) |
| 80 | |
| 81 | const ( |
| 82 | // events of MibDownload FSM |
| 83 | dlEvStart = "dlEvStart" |
| 84 | dlEvCreateGal = "dlEvCreateGal" |
| 85 | dlEvRxGalResp = "dlEvRxGalResp" |
| 86 | dlEvRxOnu2gResp = "dlEvRxOnu2gResp" |
| 87 | dlEvRxBridgeResp = "dlEvRxBridgeResp" |
| 88 | dlEvTimeoutSimple = "dlEvTimeoutSimple" |
| 89 | dlEvTimeoutBridge = "dlEvTimeoutBridge" |
| 90 | dlEvReset = "dlEvReset" |
| 91 | dlEvRestart = "dlEvRestart" |
| 92 | ) |
| 93 | const ( |
| 94 | // states of MibDownload FSM |
| 95 | dlStDisabled = "dlStDisabled" |
| 96 | dlStStarting = "dlStStarting" |
| 97 | dlStCreatingGal = "dlStCreatingGal" |
| 98 | dlStSettingOnu2g = "dlStSettingOnu2g" |
| 99 | dlStBridgeInit = "dlStBridgeInit" |
| 100 | dlStDownloaded = "dlStDownloaded" |
| 101 | dlStResetting = "dlStResetting" |
| 102 | ) |
| 103 | |
| 104 | const ( |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 105 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 106 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 107 | ) |
| 108 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 109 | type OnuDeviceEvent int |
| 110 | |
| 111 | const ( |
| 112 | // Events of interest to Device Adapters and OpenOMCI State Machines |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 113 | DeviceStatusInit OnuDeviceEvent = 0 // OnuDeviceEntry default start state |
| 114 | MibDatabaseSync OnuDeviceEvent = 1 // MIB database sync (upload done) |
| 115 | OmciCapabilitiesDone OnuDeviceEvent = 2 // OMCI ME and message type capabilities known |
| 116 | MibDownloadDone OnuDeviceEvent = 3 // MIB database sync (upload done) |
| 117 | UniLockStateDone OnuDeviceEvent = 4 // Uni ports admin set to lock |
| 118 | UniUnlockStateDone OnuDeviceEvent = 5 // Uni ports admin set to unlock |
| 119 | UniAdminStateDone OnuDeviceEvent = 6 // Uni ports admin set done - general |
| 120 | PortLinkUp OnuDeviceEvent = 7 // Port link state change |
| 121 | PortLinkDw OnuDeviceEvent = 8 // Port link state change |
| 122 | OmciAniConfigDone OnuDeviceEvent = 9 // AniSide config according to TechProfile done |
| 123 | OmciVlanFilterDone OnuDeviceEvent = 10 // Omci Vlan config according to flowConfig done |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 124 | // Add other events here as needed (alarms separate???) |
| 125 | ) |
| 126 | |
| 127 | type activityDescr struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 128 | databaseClass func() error |
| 129 | //advertiseEvents bool |
| 130 | auditDelay uint16 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 131 | //tasks map[string]func() error |
| 132 | } |
| 133 | type OmciDeviceFsms map[string]activityDescr |
| 134 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 135 | type AdapterFsm struct { |
| 136 | fsmName string |
| 137 | deviceID string |
| 138 | commChan chan Message |
| 139 | pFsm *fsm.FSM |
| 140 | } |
| 141 | |
| 142 | func NewAdapterFsm(a_name string, a_deviceID string, a_commChannel chan Message) *AdapterFsm { |
| 143 | aFsm := &AdapterFsm{ |
| 144 | fsmName: a_name, |
| 145 | deviceID: a_deviceID, |
| 146 | commChan: a_commChannel, |
| 147 | } |
| 148 | return aFsm |
| 149 | } |
| 150 | |
| 151 | //Start starts (logs) the omci agent |
| 152 | func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) { |
| 153 | logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName, |
| 154 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 155 | } |
| 156 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 157 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 158 | |
| 159 | const ( |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 160 | FirstSwImageMeID = 0 |
| 161 | SecondSwImageMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 162 | ) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 163 | const OnugMeID = 0 |
| 164 | const Onu2gMeID = 0 |
| 165 | const IPHostConfigDataMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 166 | const OnugSerialNumberLen = 8 |
| 167 | const OmciMacAddressLen = 6 |
| 168 | |
| 169 | type SwImages struct { |
| 170 | version string |
| 171 | isActive uint8 |
| 172 | } |
| 173 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 174 | type OnuDeviceEntry struct { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 175 | deviceID string |
| 176 | baseDeviceHandler *DeviceHandler |
| 177 | coreProxy adapterif.CoreProxy |
| 178 | adapterProxy adapterif.AdapterProxy |
| 179 | started bool |
| 180 | PDevOmciCC *OmciCC |
| 181 | pOnuDB *OnuDeviceDB |
| 182 | mibTemplateKVStore *db.Backend |
| 183 | vendorID string |
| 184 | serialNumber string |
| 185 | equipmentID string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 186 | swImages [SecondSwImageMeID + 1]SwImages |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 187 | activeSwVersion string |
| 188 | macAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 189 | //lockDeviceEntries sync.RWMutex |
| 190 | mibDbClass func() error |
| 191 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 192 | devState OnuDeviceEvent |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 193 | // for mibUpload |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 194 | mibAuditDelay uint16 |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 195 | mibDebugLevel string |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 196 | |
| 197 | // for mibUpload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 198 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 199 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 200 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 201 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 202 | // within the FSM event procedures |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 203 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 204 | omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | //OnuDeviceEntry returns a new instance of a OnuDeviceEntry |
| 208 | //mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 209 | func NewOnuDeviceEntry(ctx context.Context, deviceID string, kVStoreHost string, kVStorePort int, kvStoreType string, deviceHandler *DeviceHandler, |
| 210 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
| 211 | supportedFsmsPtr *OmciDeviceFsms) *OnuDeviceEntry { |
| 212 | logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 213 | var onuDeviceEntry OnuDeviceEntry |
| 214 | onuDeviceEntry.started = false |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 215 | onuDeviceEntry.deviceID = deviceID |
| 216 | onuDeviceEntry.baseDeviceHandler = deviceHandler |
| 217 | onuDeviceEntry.coreProxy = coreProxy |
| 218 | onuDeviceEntry.adapterProxy = adapterProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 219 | onuDeviceEntry.devState = DeviceStatusInit |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 220 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 221 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 222 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 223 | //are per ONU Vendor |
| 224 | // |
| 225 | // MIB Synchronization Database - possible overloading from arguments |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 226 | if supportedFsmsPtr != nil { |
| 227 | onuDeviceEntry.supportedFsms = *supportedFsmsPtr |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 228 | } else { |
| 229 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 230 | // use some internaö defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 231 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 232 | "mib-synchronizer": { |
| 233 | //mibSyncFsm, // Implements the MIB synchronization state machine |
| 234 | onuDeviceEntry.MibDbVolatileDict, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 235 | //true, // Advertise events on OpenOMCI event bus |
| 236 | 60, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 237 | // map[string]func() error{ |
| 238 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 239 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 240 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 241 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 242 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 243 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 244 | // }, |
| 245 | }, |
| 246 | } |
| 247 | } |
| 248 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 249 | logger.Debug("access2mibDbClass") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 250 | go onuDeviceEntry.mibDbClass() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 251 | onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay |
| 252 | logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 253 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 254 | onuDeviceEntry.mibDebugLevel = "normal" //set to "verbose" if you want to have all output, possibly later also per config option! |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 255 | // Omci related Mib upload sync state machine |
| 256 | mibUploadChan := make(chan Message, 2048) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 257 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", deviceID, mibUploadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 258 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 259 | ulStDisabled, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 260 | fsm.Events{ |
| 261 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 262 | {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 263 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 264 | {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib}, |
| 265 | {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial}, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 266 | {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID}, |
| 267 | {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 268 | {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion}, |
| 269 | {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress}, |
| 270 | {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate}, |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 271 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 272 | {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading}, |
| 273 | {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 274 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 275 | {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync}, |
| 276 | {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 277 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 278 | {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync}, |
| 279 | {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 280 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 281 | {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 283 | {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync}, |
| 284 | {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 285 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 286 | {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync}, |
| 287 | {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
| 288 | {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 289 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 290 | {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync}, |
| 291 | {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 292 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 293 | {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 294 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 295 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 296 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 297 | {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 298 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 299 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 300 | }, |
| 301 | |
| 302 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 303 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) }, |
| 304 | ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) }, |
| 305 | ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) }, |
| 306 | ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) }, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 307 | ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) }, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 308 | ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) }, |
| 309 | ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) }, |
| 310 | ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) }, |
| 311 | ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) }, |
| 312 | ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) }, |
| 313 | ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) }, |
| 314 | ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) }, |
| 315 | ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) }, |
| 316 | ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) }, |
| 317 | ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 318 | }, |
| 319 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 320 | // Omci related Mib download state machine |
| 321 | mibDownloadChan := make(chan Message, 2048) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 322 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", deviceID, mibDownloadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 323 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 324 | dlStDisabled, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 325 | fsm.Events{ |
| 326 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 327 | {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 328 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 329 | {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal}, |
| 330 | {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g}, |
| 331 | {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit}, |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 332 | // the bridge state is used for multi ME config for alle UNI related ports |
| 333 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 334 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 335 | {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 336 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 337 | {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting}, |
| 338 | {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 339 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 340 | {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 341 | dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting}, |
| 342 | // exceptional treatment for all states except dlStResetting |
| 343 | {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 344 | dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 345 | }, |
| 346 | |
| 347 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 348 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) }, |
| 349 | ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) }, |
| 350 | ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) }, |
| 351 | ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) }, |
| 352 | ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) }, |
| 353 | ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) }, |
| 354 | ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 355 | }, |
| 356 | ) |
| 357 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
| 358 | logger.Error("MibDownloadFsm could not be instantiated!!") |
| 359 | // some specifc error treatment - or waiting for crash ??? |
| 360 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 361 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 362 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 363 | if onuDeviceEntry.mibTemplateKVStore == nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 364 | logger.Errorw("Failed to setup mibTemplateKVStore", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 367 | // Alarm Synchronization Database |
| 368 | //self._alarm_db = None |
| 369 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 370 | return &onuDeviceEntry |
| 371 | } |
| 372 | |
| 373 | //Start starts (logs) the omci agent |
| 374 | func (oo *OnuDeviceEntry) Start(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 375 | logger.Info("starting-OnuDeviceEntry") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 376 | |
| 377 | oo.PDevOmciCC = NewOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 378 | oo.coreProxy, oo.adapterProxy) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 379 | if oo.PDevOmciCC == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 380 | logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 381 | return errors.New("could not create devOmciCc") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 382 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 383 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 384 | oo.started = true |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 385 | logger.Info("OnuDeviceEntry-started") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 386 | return nil |
| 387 | } |
| 388 | |
| 389 | //Stop terminates the session |
| 390 | func (oo *OnuDeviceEntry) Stop(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 391 | logger.Info("stopping-OnuDeviceEntry") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 392 | oo.started = false |
| 393 | //oo.exitChannel <- 1 |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 394 | // 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] | 395 | logger.Info("OnuDeviceEntry-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 396 | return nil |
| 397 | } |
| 398 | |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 399 | func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error { |
| 400 | logger.Info("reboot-OnuDeviceEntry") |
| 401 | if err := oo.PDevOmciCC.sendReboot(context.TODO(), ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 402 | logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 403 | return err |
| 404 | } |
| 405 | logger.Info("OnuDeviceEntry-reboot") |
| 406 | return nil |
| 407 | } |
| 408 | |
| 409 | func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error { |
| 410 | select { |
| 411 | case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
| 412 | logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 413 | return errors.New("rebootTimeout") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 414 | case data := <-responseChannel: |
| 415 | switch data.Data.(OmciMessage).OmciMsg.MessageType { |
| 416 | case omci.RebootResponseType: |
| 417 | { |
| 418 | msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 419 | if msgLayer == nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 420 | return errors.New("omci Msg layer could not be detected for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 421 | } |
| 422 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 423 | if !msgOk { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 424 | return errors.New("omci Msg layer could not be assigned for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 425 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 426 | logger.Debugw("CreateResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 427 | if msgObj.Result != me.Success { |
| 428 | logger.Errorw("Omci RebootResponseType Error ", log.Fields{"Error": msgObj.Result}) |
| 429 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 430 | return errors.New("omci RebootResponse Result Error indication") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 431 | } |
| 432 | return nil |
| 433 | } |
| 434 | } |
| 435 | logger.Warnw("Reboot response error", log.Fields{"for device-id": oo.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 436 | return errors.New("unexpected OmciResponse type received") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 440 | //Relay the InSync message via Handler to Rw core - Status update |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 441 | func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) { |
| 442 | logger.Debugw("relaying system-event", log.Fields{"Event": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 443 | // decouple the handler transfer from further processing here |
| 444 | // TODO!!! check if really no synch is required within the system e.g. to ensure following steps .. |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 445 | if devEvent == MibDatabaseSync { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 446 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 447 | oo.devState = MibDatabaseSync |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 448 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 449 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 450 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 451 | logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState}) |
| 452 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 453 | } else if devEvent == MibDownloadDone { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 454 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 455 | oo.devState = MibDownloadDone |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 456 | go oo.baseDeviceHandler.DeviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 457 | } else { |
| 458 | 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] | 459 | } |
| 460 | } else { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 461 | logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 462 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 463 | } |