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 | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 22 | "encoding/json" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 23 | "errors" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 24 | "fmt" |
| 25 | "sync" |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 26 | "time" |
| 27 | |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 28 | "github.com/opencord/omci-lib-go" |
| 29 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 30 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 31 | //"sync" |
| 32 | //"time" |
| 33 | |
| 34 | "github.com/looplab/fsm" |
| 35 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 37 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 38 | |
| 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 46 | const ( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 47 | // events of MibUpload FSM |
| 48 | ulEvStart = "ulEvStart" |
| 49 | ulEvResetMib = "ulEvResetMib" |
| 50 | ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 51 | ulEvGetEquipmentID = "ulEvGetEquipmentId" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 52 | 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 | ) |
| 66 | const ( |
| 67 | // states of MibUpload FSM |
| 68 | ulStDisabled = "ulStDisabled" |
| 69 | ulStStarting = "ulStStarting" |
| 70 | ulStResettingMib = "ulStResettingMib" |
| 71 | ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 72 | ulStGettingEquipmentID = "ulStGettingEquipmentID" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 73 | 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 | |
| 85 | const ( |
| 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 | ) |
| 97 | const ( |
| 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 | |
| 108 | const ( |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 109 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 110 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 111 | cBasePathOnuKVStore = "service/voltha/openonu" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 112 | ) |
| 113 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 114 | // OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 115 | type OnuDeviceEvent int |
| 116 | |
| 117 | const ( |
| 118 | // Events of interest to Device Adapters and OpenOMCI State Machines |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 119 | |
| 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 |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 132 | // UniDisableStateDone - Uni ports admin set to lock based on device disable |
| 133 | UniDisableStateDone OnuDeviceEvent = 6 |
| 134 | // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable |
| 135 | UniEnableStateDone OnuDeviceEvent = 7 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 136 | // PortLinkUp - Port link state change |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 137 | PortLinkUp OnuDeviceEvent = 8 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 138 | // PortLinkDw - Port link state change |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 139 | PortLinkDw OnuDeviceEvent = 9 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 140 | // OmciAniConfigDone - AniSide config according to TechProfile done |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 141 | OmciAniConfigDone OnuDeviceEvent = 10 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 142 | // OmciVlanFilterDone - Omci Vlan config according to flowConfig done |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 143 | OmciVlanFilterDone OnuDeviceEvent = 11 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | // Add other events here as needed (alarms separate???) |
| 145 | ) |
| 146 | |
| 147 | type activityDescr struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 148 | databaseClass func() error |
| 149 | //advertiseEvents bool |
| 150 | auditDelay uint16 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 151 | //tasks map[string]func() error |
| 152 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 153 | |
| 154 | // OmciDeviceFsms - FSM event mapping to database class and time to wait between audits |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | type OmciDeviceFsms map[string]activityDescr |
| 156 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 157 | // AdapterFsm - Adapter FSM details including channel, event and device |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 158 | type AdapterFsm struct { |
| 159 | fsmName string |
| 160 | deviceID string |
| 161 | commChan chan Message |
| 162 | pFsm *fsm.FSM |
| 163 | } |
| 164 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 165 | //NewAdapterFsm - FSM details including event, device and channel. |
| 166 | func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 167 | aFsm := &AdapterFsm{ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 168 | fsmName: aName, |
| 169 | deviceID: aDeviceID, |
| 170 | commChan: aCommChannel, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 171 | } |
| 172 | return aFsm |
| 173 | } |
| 174 | |
| 175 | //Start starts (logs) the omci agent |
| 176 | func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) { |
| 177 | logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName, |
| 178 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 179 | } |
| 180 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 181 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 182 | |
| 183 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 184 | firstSwImageMeID = 0 |
| 185 | secondSwImageMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 186 | ) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 187 | const onugMeID = 0 |
| 188 | const onu2gMeID = 0 |
| 189 | const ipHostConfigDataMeID = 1 |
| 190 | const onugSerialNumberLen = 8 |
| 191 | const omciMacAddressLen = 6 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 192 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 193 | type swImages struct { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 194 | version string |
| 195 | isActive uint8 |
| 196 | } |
| 197 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 198 | type uniPersConfig struct { |
| 199 | PersUniID uint8 `json:"uni_id"` |
| 200 | PersTpPath string `json:"tp_path"` |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 201 | PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | type onuPersistentData struct { |
| 205 | PersOnuID uint32 `json:"onu_id"` |
| 206 | PersIntfID uint32 `json:"intf_id"` |
| 207 | PersSnr string `json:"serial_number"` |
| 208 | PersAdminState string `json:"admin_state"` |
| 209 | PersOperState string `json:"oper_state"` |
| 210 | PersUniConfig []uniPersConfig `json:"uni_config"` |
| 211 | } |
| 212 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 213 | // OnuDeviceEntry - ONU device info and FSM events. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 214 | type OnuDeviceEntry struct { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 215 | deviceID string |
| 216 | baseDeviceHandler *deviceHandler |
| 217 | coreProxy adapterif.CoreProxy |
| 218 | adapterProxy adapterif.AdapterProxy |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 219 | PDevOmciCC *omciCC |
| 220 | pOnuDB *onuDeviceDB |
| 221 | mibTemplateKVStore *db.Backend |
| 222 | sOnuPersistentData onuPersistentData |
| 223 | onuKVStoreMutex sync.RWMutex |
| 224 | onuKVStore *db.Backend |
| 225 | onuKVStorePath string |
| 226 | onuKVStoreprocResult error //error indication of processing |
| 227 | chOnuKvProcessingStep chan uint8 |
| 228 | vendorID string |
| 229 | serialNumber string |
| 230 | equipmentID string |
| 231 | swImages [secondSwImageMeID + 1]swImages |
| 232 | activeSwVersion string |
| 233 | macAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 234 | //lockDeviceEntries sync.RWMutex |
| 235 | mibDbClass func() error |
| 236 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 237 | devState OnuDeviceEvent |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 238 | // for mibUpload |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 239 | mibAuditDelay uint16 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 240 | |
| 241 | // for mibUpload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 242 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 243 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 244 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 245 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 246 | // within the FSM event procedures |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 247 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 248 | omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 251 | //newOnuDeviceEntry returns a new instance of a OnuDeviceEntry |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 252 | //mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 253 | func newOnuDeviceEntry(ctx context.Context, deviceID string, kVStoreHost string, kVStorePort int, kvStoreType string, deviceHandler *deviceHandler, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 254 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
| 255 | supportedFsmsPtr *OmciDeviceFsms) *OnuDeviceEntry { |
| 256 | logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 257 | var onuDeviceEntry OnuDeviceEntry |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 258 | onuDeviceEntry.deviceID = deviceID |
| 259 | onuDeviceEntry.baseDeviceHandler = deviceHandler |
| 260 | onuDeviceEntry.coreProxy = coreProxy |
| 261 | onuDeviceEntry.adapterProxy = adapterProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 262 | onuDeviceEntry.devState = DeviceStatusInit |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 263 | onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0) |
| 264 | onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 265 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 266 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 267 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 268 | //are per ONU Vendor |
| 269 | // |
| 270 | // MIB Synchronization Database - possible overloading from arguments |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 271 | if supportedFsmsPtr != nil { |
| 272 | onuDeviceEntry.supportedFsms = *supportedFsmsPtr |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 273 | } else { |
| 274 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 275 | // use some internaö defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 276 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 277 | "mib-synchronizer": { |
| 278 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 279 | onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 280 | //true, // Advertise events on OpenOMCI event bus |
| 281 | 60, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | // map[string]func() error{ |
| 283 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 284 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 285 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 286 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 287 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 288 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 289 | // }, |
| 290 | }, |
| 291 | } |
| 292 | } |
| 293 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 294 | logger.Debug("access2mibDbClass") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 295 | go onuDeviceEntry.mibDbClass() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 296 | onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay |
| 297 | logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 298 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 299 | // Omci related Mib upload sync state machine |
| 300 | mibUploadChan := make(chan Message, 2048) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 301 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", deviceID, mibUploadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 302 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 303 | ulStDisabled, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 304 | fsm.Events{ |
| 305 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 306 | {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 307 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 308 | {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib}, |
| 309 | {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial}, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 310 | {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID}, |
| 311 | {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 312 | {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion}, |
| 313 | {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress}, |
| 314 | {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate}, |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 315 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 316 | {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading}, |
| 317 | {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 318 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 319 | {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync}, |
| 320 | {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 321 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 322 | {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync}, |
| 323 | {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 324 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 325 | {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 326 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 327 | {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync}, |
| 328 | {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 329 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 330 | {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync}, |
| 331 | {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
| 332 | {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 333 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 334 | {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync}, |
| 335 | {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 336 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 337 | {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 338 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 339 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 340 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 341 | {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 342 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 343 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 344 | }, |
| 345 | |
| 346 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 347 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) }, |
| 348 | ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) }, |
| 349 | ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) }, |
| 350 | ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) }, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 351 | ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) }, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 352 | ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) }, |
| 353 | ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) }, |
| 354 | ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) }, |
| 355 | ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) }, |
| 356 | ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) }, |
| 357 | ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) }, |
| 358 | ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) }, |
| 359 | ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) }, |
| 360 | ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) }, |
| 361 | ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 362 | }, |
| 363 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 364 | // Omci related Mib download state machine |
| 365 | mibDownloadChan := make(chan Message, 2048) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 366 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", deviceID, mibDownloadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 367 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 368 | dlStDisabled, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 369 | fsm.Events{ |
| 370 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 371 | {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 372 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 373 | {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal}, |
| 374 | {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g}, |
| 375 | {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit}, |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 376 | // the bridge state is used for multi ME config for alle UNI related ports |
| 377 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 378 | // 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] | 379 | {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 380 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 381 | {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting}, |
| 382 | {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 383 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 384 | {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 385 | dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting}, |
| 386 | // exceptional treatment for all states except dlStResetting |
| 387 | {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 388 | dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 389 | }, |
| 390 | |
| 391 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 392 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) }, |
| 393 | ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) }, |
| 394 | ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) }, |
| 395 | ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) }, |
| 396 | ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) }, |
| 397 | ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) }, |
| 398 | ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 399 | }, |
| 400 | ) |
| 401 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 402 | logger.Errorw("MibDownloadFsm could not be instantiated", log.Fields{"device-id": deviceID}) |
| 403 | // TODO some specifc error treatment - or waiting for crash ? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 404 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 405 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 406 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 407 | if onuDeviceEntry.mibTemplateKVStore == nil { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 408 | logger.Errorw("Can't access mibTemplateKVStore - no backend connection to service", |
| 409 | log.Fields{"device-id": deviceID, "service": cBasePathMibTemplateKvStore}) |
| 410 | } |
| 411 | |
| 412 | onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID |
| 413 | onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathOnuKVStore) |
| 414 | if onuDeviceEntry.onuKVStore == nil { |
| 415 | logger.Errorw("Can't access onuKVStore - no backend connection to service", |
| 416 | log.Fields{"device-id": deviceID, "service": cBasePathOnuKVStore}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 419 | // Alarm Synchronization Database |
| 420 | //self._alarm_db = None |
| 421 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 422 | return &onuDeviceEntry |
| 423 | } |
| 424 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 425 | //start starts (logs) the omci agent |
| 426 | func (oo *OnuDeviceEntry) start(ctx context.Context) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 427 | logger.Infow("OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 428 | if oo.PDevOmciCC == nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 429 | oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 430 | oo.coreProxy, oo.adapterProxy) |
| 431 | if oo.PDevOmciCC == nil { |
| 432 | logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID}) |
| 433 | return fmt.Errorf("could not create devOmciCc %s", oo.deviceID) |
| 434 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 435 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 436 | return nil |
| 437 | } |
| 438 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 439 | //stop stops/resets the omciCC |
| 440 | func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error { |
| 441 | logger.Debugw("OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID}) |
| 442 | if abResetOmciCC && (oo.PDevOmciCC != nil) { |
| 443 | _ = oo.PDevOmciCC.stop(ctx) |
| 444 | } |
| 445 | //to allow for all event notifications again when re-using the device and omciCC |
| 446 | oo.devState = DeviceStatusInit |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 447 | return nil |
| 448 | } |
| 449 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 450 | func (oo *OnuDeviceEntry) reboot(ctx context.Context) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 451 | logger.Debugw("OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID}) |
| 452 | if oo.PDevOmciCC != nil { |
| 453 | if err := oo.PDevOmciCC.sendReboot(ctx, ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil { |
| 454 | logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID}) |
| 455 | return err |
| 456 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 457 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 458 | return nil |
| 459 | } |
| 460 | |
| 461 | func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error { |
| 462 | select { |
| 463 | case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
| 464 | logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 465 | return fmt.Errorf("rebootTimeout") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 466 | case data := <-responseChannel: |
| 467 | switch data.Data.(OmciMessage).OmciMsg.MessageType { |
| 468 | case omci.RebootResponseType: |
| 469 | { |
| 470 | msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 471 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 472 | return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 473 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 474 | msgObj, msgOk := msgLayer.(*omci.RebootResponse) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 475 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 476 | return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 477 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 478 | logger.Debugw("RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 479 | if msgObj.Result != me.Success { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 480 | logger.Errorw("Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 481 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 482 | return fmt.Errorf("omci RebootResponse result error indication %s for device %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 483 | msgObj.Result, oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 484 | } |
| 485 | return nil |
| 486 | } |
| 487 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 488 | logger.Warnw("Reboot response message type error", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 489 | return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 493 | //Relay the InSync message via Handler to Rw core - Status update |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 494 | func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) { |
| 495 | logger.Debugw("relaying system-event", log.Fields{"Event": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 496 | // decouple the handler transfer from further processing here |
| 497 | // 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] | 498 | if devEvent == MibDatabaseSync { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 499 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 500 | oo.devState = MibDatabaseSync |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 501 | go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 502 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 503 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 504 | logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState}) |
| 505 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 506 | } else if devEvent == MibDownloadDone { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 507 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 508 | oo.devState = MibDownloadDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 509 | go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 510 | } else { |
| 511 | 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] | 512 | } |
| 513 | } else { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 514 | logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 515 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 516 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 517 | |
| 518 | func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error { |
| 519 | if oo.onuKVStore == nil { |
| 520 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 521 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID)) |
| 522 | } |
| 523 | oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersConfig, 0)} |
| 524 | Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath) |
| 525 | if err == nil { |
| 526 | if Value != nil { |
| 527 | logger.Debugw("ONU-data read", |
| 528 | log.Fields{"Key": Value.Key, "device-id": oo.deviceID}) |
| 529 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 530 | |
| 531 | if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil { |
| 532 | logger.Errorw("unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 533 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)) |
| 534 | } |
| 535 | logger.Debugw("ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
| 536 | "device-id": oo.deviceID}) |
| 537 | } else { |
| 538 | logger.Errorw("no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID}) |
| 539 | return fmt.Errorf(fmt.Sprintf("no-ONU-data-found-%s", oo.deviceID)) |
| 540 | } |
| 541 | } else { |
| 542 | logger.Errorw("unable to read from KVstore", log.Fields{"device-id": oo.deviceID}) |
| 543 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID)) |
| 544 | } |
| 545 | return nil |
| 546 | } |
| 547 | |
| 548 | func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 549 | defer wg.Done() |
| 550 | |
| 551 | if oo.onuKVStore == nil { |
| 552 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 553 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: onuKVStore not set") |
| 554 | return |
| 555 | } |
| 556 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 557 | go oo.deletePersistentData(ctx, processingStep) |
| 558 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 559 | //timeout or error detected |
| 560 | logger.Debugw("ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID}) |
| 561 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: during kv-access") |
| 562 | return |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) { |
| 567 | |
| 568 | logger.Debugw("delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID}) |
| 569 | err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath) |
| 570 | if err != nil { |
| 571 | logger.Errorw("unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 572 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 573 | return |
| 574 | } |
| 575 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 576 | } |
| 577 | |
| 578 | func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 579 | defer wg.Done() |
| 580 | |
| 581 | if oo.onuKVStore == nil { |
| 582 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 583 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: onuKVStore not set") |
| 584 | return |
| 585 | } |
| 586 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 587 | go oo.storeDataInOnuKvStore(ctx, processingStep) |
| 588 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 589 | //timeout or error detected |
| 590 | logger.Debugw("ONU-data not written - abort", log.Fields{"device-id": oo.deviceID}) |
| 591 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: during writing process") |
| 592 | return |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) { |
| 597 | |
| 598 | //assign values which are not already present when newOnuDeviceEntry() is called |
| 599 | oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId |
| 600 | oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId |
| 601 | oo.sOnuPersistentData.PersSnr = oo.baseDeviceHandler.pOnuOmciDevice.serialNumber |
| 602 | //TODO: verify usage of these values during restart UC |
| 603 | oo.sOnuPersistentData.PersAdminState = "up" |
| 604 | oo.sOnuPersistentData.PersOperState = "active" |
| 605 | |
| 606 | logger.Debugw("Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData}) |
| 607 | |
| 608 | Value, err := json.Marshal(oo.sOnuPersistentData) |
| 609 | if err != nil { |
| 610 | logger.Errorw("unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
| 611 | "device-id": oo.deviceID, "err": err}) |
| 612 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 613 | return |
| 614 | } |
| 615 | err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value) |
| 616 | if err != nil { |
| 617 | logger.Errorw("unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 618 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 619 | return |
| 620 | } |
| 621 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 622 | } |
| 623 | |
| 624 | func (oo *OnuDeviceEntry) updateOnuUniTpPath(aUniID uint8, aPathString string) bool { |
| 625 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 626 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 627 | no specific concurrency protection to sOnuPersistentData is required here |
| 628 | */ |
| 629 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 630 | if v.PersUniID == aUniID { |
| 631 | logger.Debugw("PersUniConfig-entry already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
| 632 | existingPath := oo.sOnuPersistentData.PersUniConfig[k].PersTpPath |
| 633 | if existingPath != aPathString { |
| 634 | if aPathString == "" { |
| 635 | //existing entry to be deleted |
| 636 | logger.Debugw("UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 637 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = "" |
| 638 | } else { |
| 639 | //existing entry to be modified |
| 640 | logger.Debugw("UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 641 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = aPathString |
| 642 | } |
| 643 | return true |
| 644 | } |
| 645 | //entry already exists |
| 646 | logger.Debugw("UniTp path already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 647 | return false |
| 648 | } |
| 649 | } |
| 650 | //no entry exists for uniId |
| 651 | |
| 652 | if aPathString == "" { |
| 653 | //delete request in non-existing state , accept as no change |
| 654 | logger.Debugw("UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
| 655 | return false |
| 656 | } |
| 657 | //new entry to be created |
| 658 | logger.Debugw("New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 659 | oo.sOnuPersistentData.PersUniConfig = |
| 660 | append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPath: aPathString, PersFlowParams: make([]uniVlanFlowParams, 0)}) |
| 661 | return true |
| 662 | } |
| 663 | |
| 664 | // deleteTpResource removes Resources from the ONU's specified Uni |
| 665 | func (oo *OnuDeviceEntry) deleteTpResource(ctx context.Context, |
| 666 | aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32, |
| 667 | wg *sync.WaitGroup) { |
| 668 | defer wg.Done() |
| 669 | logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{ |
| 670 | "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource}) |
| 671 | //TODO!!! |
| 672 | //delete the given resource from ONU OMCI config and data base - as background routine |
| 673 | /* |
| 674 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 675 | go onuTp.deleteAniResource(ctx, processingStep) |
| 676 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
| 677 | //timeout or error detected |
| 678 | return |
| 679 | } |
| 680 | */ |
| 681 | } |
| 682 | |
| 683 | func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) { |
| 684 | |
| 685 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 686 | if v.PersUniID == aUniID { |
| 687 | oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams)) |
| 688 | copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams) |
| 689 | return |
| 690 | } |
| 691 | } |
| 692 | //flow update was faster than tp-config - create PersUniConfig-entry |
| 693 | tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPath: "", PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))} |
| 694 | copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams) |
| 695 | oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig) |
| 696 | } |
| 697 | |
| 698 | func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion( |
| 699 | ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
| 700 | select { |
| 701 | case <-ctx.Done(): |
| 702 | logger.Warnw("processing not completed in-time!", |
| 703 | log.Fields{"device-id": oo.deviceID, "error": ctx.Err()}) |
| 704 | return false |
| 705 | case rxStep := <-aChOnuProcessingStep: |
| 706 | if rxStep == aProcessingStep { |
| 707 | return true |
| 708 | } |
| 709 | //all other values are not accepted - including 0 for error indication |
| 710 | logger.Warnw("Invalid processing step received: abort!", |
| 711 | log.Fields{"device-id": oo.deviceID, |
| 712 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 713 | return false |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() { |
| 718 | oo.onuKVStoreprocResult = nil |
| 719 | } |
| 720 | func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error { |
| 721 | return oo.onuKVStoreprocResult |
| 722 | } |
| 723 | |
| 724 | func (oo *OnuDeviceEntry) lockOnuKVStoreMutex() { |
| 725 | oo.onuKVStoreMutex.Lock() |
| 726 | } |
| 727 | |
| 728 | func (oo *OnuDeviceEntry) unlockOnuKVStoreMutex() { |
| 729 | oo.onuKVStoreMutex.Unlock() |
| 730 | } |