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" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 35 | "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif" |
| 36 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 37 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 38 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 39 | //"github.com/opencord/voltha-lib-go/v4/pkg/kafka" |
| 40 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 41 | //ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 42 | //"github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 43 | //"github.com/opencord/voltha-protos/v4/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 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" |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 78 | ulStUploadDone = "ulStUploadDone" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 79 | ulStInSync = "ulStInSync" |
| 80 | ulStExaminingMds = "ulStExaminingMds" |
| 81 | ulStResynchronizing = "ulStResynchronizing" |
| 82 | ulStAuditing = "ulStAuditing" |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 83 | ulStReAuditing = "ulStReAuditing" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 84 | ulStOutOfSync = "ulStOutOfSync" |
| 85 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 86 | const cMibUlFsmIdleState = ulStInSync |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 87 | |
| 88 | const ( |
| 89 | // events of MibDownload FSM |
| 90 | dlEvStart = "dlEvStart" |
| 91 | dlEvCreateGal = "dlEvCreateGal" |
| 92 | dlEvRxGalResp = "dlEvRxGalResp" |
| 93 | dlEvRxOnu2gResp = "dlEvRxOnu2gResp" |
| 94 | dlEvRxBridgeResp = "dlEvRxBridgeResp" |
| 95 | dlEvTimeoutSimple = "dlEvTimeoutSimple" |
| 96 | dlEvTimeoutBridge = "dlEvTimeoutBridge" |
| 97 | dlEvReset = "dlEvReset" |
| 98 | dlEvRestart = "dlEvRestart" |
| 99 | ) |
| 100 | const ( |
| 101 | // states of MibDownload FSM |
| 102 | dlStDisabled = "dlStDisabled" |
| 103 | dlStStarting = "dlStStarting" |
| 104 | dlStCreatingGal = "dlStCreatingGal" |
| 105 | dlStSettingOnu2g = "dlStSettingOnu2g" |
| 106 | dlStBridgeInit = "dlStBridgeInit" |
| 107 | dlStDownloaded = "dlStDownloaded" |
| 108 | dlStResetting = "dlStResetting" |
| 109 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 110 | const cMibDlFsmIdleState = dlStDisabled |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 111 | |
| 112 | const ( |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 113 | // NOTE that this hardcoded to service/voltha as the MIB template is shared across stacks |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 114 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 115 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 116 | cBasePathOnuKVStore = "%s/openonu" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 117 | ) |
| 118 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 119 | // OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | type OnuDeviceEvent int |
| 121 | |
| 122 | const ( |
| 123 | // Events of interest to Device Adapters and OpenOMCI State Machines |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 124 | |
| 125 | // DeviceStatusInit - default start state |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 126 | DeviceStatusInit OnuDeviceEvent = iota |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 127 | // MibDatabaseSync - MIB database sync (upload done) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 128 | MibDatabaseSync |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 129 | // OmciCapabilitiesDone - OMCI ME and message type capabilities known |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 130 | OmciCapabilitiesDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 131 | // MibDownloadDone - // MIB download done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 132 | MibDownloadDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 133 | // UniLockStateDone - Uni ports admin set to lock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 134 | UniLockStateDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 135 | // UniUnlockStateDone - Uni ports admin set to unlock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 136 | UniUnlockStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 137 | // UniDisableStateDone - Uni ports admin set to lock based on device disable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 138 | UniDisableStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 139 | // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 140 | UniEnableStateDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 141 | // PortLinkUp - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 142 | PortLinkUp |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 143 | // PortLinkDw - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 144 | PortLinkDw |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 145 | // OmciAniConfigDone - AniSide config according to TechProfile done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 146 | OmciAniConfigDone |
| 147 | // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed |
| 148 | OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone! |
| 149 | // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add |
| 150 | OmciVlanFilterAddDone |
| 151 | // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove |
| 152 | OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDone! |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 153 | // Add other events here as needed (alarms separate???) |
| 154 | ) |
| 155 | |
| 156 | type activityDescr struct { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 157 | databaseClass func(context.Context) error |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 158 | //advertiseEvents bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 159 | auditInterval time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 160 | //tasks map[string]func() error |
| 161 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 162 | |
| 163 | // 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] | 164 | type OmciDeviceFsms map[string]activityDescr |
| 165 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 166 | // AdapterFsm - Adapter FSM details including channel, event and device |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 167 | type AdapterFsm struct { |
| 168 | fsmName string |
| 169 | deviceID string |
| 170 | commChan chan Message |
| 171 | pFsm *fsm.FSM |
| 172 | } |
| 173 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 174 | //NewAdapterFsm - FSM details including event, device and channel. |
| 175 | func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 176 | aFsm := &AdapterFsm{ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 177 | fsmName: aName, |
| 178 | deviceID: aDeviceID, |
| 179 | commChan: aCommChannel, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 180 | } |
| 181 | return aFsm |
| 182 | } |
| 183 | |
| 184 | //Start starts (logs) the omci agent |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 185 | func (oo *AdapterFsm) logFsmStateChange(ctx context.Context, e *fsm.Event) { |
| 186 | logger.Debugw(ctx, "FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 187 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 188 | } |
| 189 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 190 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 191 | |
| 192 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 193 | firstSwImageMeID = 0 |
| 194 | secondSwImageMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 195 | ) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 196 | const onuDataMeID = 0 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 197 | const onugMeID = 0 |
| 198 | const onu2gMeID = 0 |
| 199 | const ipHostConfigDataMeID = 1 |
| 200 | const onugSerialNumberLen = 8 |
| 201 | const omciMacAddressLen = 6 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 202 | |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 203 | const cEmptyMacAddrString = "000000000000" |
| 204 | const cEmptySerialNumberString = "0000000000000000" |
| 205 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 206 | type swImages struct { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 207 | version string |
| 208 | isActive uint8 |
| 209 | } |
| 210 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 211 | type uniPersConfig struct { |
| 212 | PersUniID uint8 `json:"uni_id"` |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 213 | PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map |
| 214 | PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | type onuPersistentData struct { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 218 | PersOnuID uint32 `json:"onu_id"` |
| 219 | PersIntfID uint32 `json:"intf_id"` |
| 220 | PersSnr string `json:"serial_number"` |
| 221 | PersAdminState string `json:"admin_state"` |
| 222 | PersOperState string `json:"oper_state"` |
| 223 | PersUniUnlockDone bool `json:"uni_unlock_done"` |
| 224 | PersUniDisableDone bool `json:"uni_disable_done"` |
| 225 | PersMibAuditInterval time.Duration `json:"mib_audit_interval"` |
| 226 | PersMibLastDbSync uint32 `json:"mib_last_db_sync"` |
| 227 | PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"` |
| 228 | PersUniConfig []uniPersConfig `json:"uni_config"` |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 231 | // OnuDeviceEntry - ONU device info and FSM events. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 232 | type OnuDeviceEntry struct { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 233 | deviceID string |
| 234 | baseDeviceHandler *deviceHandler |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 235 | pOpenOnuAc *OpenONUAC |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 236 | coreProxy adapterif.CoreProxy |
| 237 | adapterProxy adapterif.AdapterProxy |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 238 | PDevOmciCC *omciCC |
| 239 | pOnuDB *onuDeviceDB |
| 240 | mibTemplateKVStore *db.Backend |
| 241 | sOnuPersistentData onuPersistentData |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 242 | mibTemplatePath string |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 243 | onuKVStoreMutex sync.RWMutex |
| 244 | onuKVStore *db.Backend |
| 245 | onuKVStorePath string |
| 246 | onuKVStoreprocResult error //error indication of processing |
| 247 | chOnuKvProcessingStep chan uint8 |
| 248 | vendorID string |
| 249 | serialNumber string |
| 250 | equipmentID string |
| 251 | swImages [secondSwImageMeID + 1]swImages |
| 252 | activeSwVersion string |
| 253 | macAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 254 | //lockDeviceEntries sync.RWMutex |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 255 | mibDbClass func(context.Context) error |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 256 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 257 | devState OnuDeviceEvent |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 258 | // Audit and MDS |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 259 | mibAuditInterval time.Duration |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 260 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 261 | //mibNextDbResync uint32 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 262 | |
| 263 | // for mibUpload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 264 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 265 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 266 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 267 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 268 | // within the FSM event procedures |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 269 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 270 | omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 273 | //newOnuDeviceEntry returns a new instance of a OnuDeviceEntry |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 274 | //mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 275 | func newOnuDeviceEntry(ctx context.Context, dh *deviceHandler) *OnuDeviceEntry { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 276 | logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 277 | var onuDeviceEntry OnuDeviceEntry |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 278 | onuDeviceEntry.deviceID = dh.deviceID |
| 279 | onuDeviceEntry.baseDeviceHandler = dh |
| 280 | onuDeviceEntry.pOpenOnuAc = dh.pOpenOnuAc |
| 281 | onuDeviceEntry.coreProxy = dh.coreProxy |
| 282 | onuDeviceEntry.adapterProxy = dh.AdapterProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 283 | onuDeviceEntry.devState = DeviceStatusInit |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 284 | onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0) |
| 285 | onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 286 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 287 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 288 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 289 | //are per ONU Vendor |
| 290 | // |
| 291 | // MIB Synchronization Database - possible overloading from arguments |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 292 | if dh.pOpenOnuAc.pSupportedFsms != nil { |
| 293 | onuDeviceEntry.supportedFsms = *dh.pOpenOnuAc.pSupportedFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 294 | } else { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 295 | // This branch is currently not used and is for potential future usage of alternative MIB Sync FSMs only! |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 296 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 297 | // use some internal defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 298 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 299 | "mib-synchronizer": { |
| 300 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 301 | onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 302 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 303 | dh.pOpenOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 304 | // map[string]func() error{ |
| 305 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 306 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 307 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 308 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 309 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 310 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 311 | // }, |
| 312 | }, |
| 313 | } |
| 314 | } |
| 315 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 316 | logger.Debug(ctx, "access2mibDbClass") |
| 317 | go onuDeviceEntry.mibDbClass(ctx) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 318 | if !dh.reconciling { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 319 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditInterval |
| 320 | onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 321 | } else { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 322 | logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": dh.deviceID}) |
| 323 | // TODO: This is a preparation for VOL-VOL-3811 to preserve config history in case of |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 324 | // vendor- or deviceID-specific configurations via voltctl-commands |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 325 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 326 | } |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 327 | logger.Debugw(ctx, "MibAudit is set to", log.Fields{"Interval": onuDeviceEntry.mibAuditInterval}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 328 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 329 | //onuDeviceEntry.mibNextDbResync = 0 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 330 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 331 | // Omci related Mib upload sync state machine |
| 332 | mibUploadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 333 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", dh.deviceID, mibUploadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 334 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 335 | ulStDisabled, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 336 | fsm.Events{ |
| 337 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 338 | {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 339 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 340 | {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib}, |
| 341 | {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial}, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 342 | {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID}, |
| 343 | {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 344 | {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion}, |
| 345 | {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress}, |
| 346 | {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate}, |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 347 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 348 | {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading}, |
| 349 | {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 350 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 351 | {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploadDone}, |
| 352 | {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStUploadDone}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 353 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 354 | {Name: ulEvSuccess, Src: []string{ulStUploadDone}, Dst: ulStInSync}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 355 | {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync}, |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 356 | // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers |
| 357 | // mib-reset and new provisioning at this point |
| 358 | //{Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing}, |
| 359 | {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResettingMib}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 360 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 361 | {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 362 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 363 | {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync}, |
| 364 | {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 365 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 366 | {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync}, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 367 | {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStReAuditing}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 368 | {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 369 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 370 | {Name: ulEvSuccess, Src: []string{ulStReAuditing}, Dst: ulStInSync}, |
| 371 | {Name: ulEvMismatch, Src: []string{ulStReAuditing}, Dst: ulStResettingMib}, |
| 372 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 373 | {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync}, |
| 374 | {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 375 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 376 | {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 377 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 378 | ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 379 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 380 | {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 381 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 382 | ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStDisabled}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 383 | }, |
| 384 | |
| 385 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 386 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(ctx, e) }, |
| 387 | "enter_" + ulStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) }, |
| 388 | "enter_" + ulStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) }, |
| 389 | "enter_" + ulStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) }, |
| 390 | "enter_" + ulStGettingEquipmentID: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(ctx, e) }, |
| 391 | "enter_" + ulStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) }, |
| 392 | "enter_" + ulStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) }, |
| 393 | "enter_" + ulStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) }, |
| 394 | "enter_" + ulStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(ctx, e) }, |
| 395 | "enter_" + ulStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) }, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 396 | "enter_" + ulStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 397 | "enter_" + ulStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) }, |
| 398 | "enter_" + ulStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) }, |
| 399 | "enter_" + ulStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) }, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 400 | "enter_" + ulStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 401 | "enter_" + ulStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) }, |
| 402 | "enter_" + ulStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 403 | }, |
| 404 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 405 | // Omci related Mib download state machine |
| 406 | mibDownloadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 407 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", dh.deviceID, mibDownloadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 408 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 409 | dlStDisabled, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 410 | fsm.Events{ |
| 411 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 412 | {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 413 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 414 | {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal}, |
| 415 | {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g}, |
| 416 | {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit}, |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 417 | // the bridge state is used for multi ME config for alle UNI related ports |
| 418 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 419 | // 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] | 420 | {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 421 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 422 | {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting}, |
| 423 | {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 424 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 425 | {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 426 | dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting}, |
| 427 | // exceptional treatment for all states except dlStResetting |
| 428 | {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 429 | dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 430 | }, |
| 431 | |
| 432 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 433 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(ctx, e) }, |
| 434 | "enter_" + dlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) }, |
| 435 | "enter_" + dlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) }, |
| 436 | "enter_" + dlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) }, |
| 437 | "enter_" + dlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) }, |
| 438 | "enter_" + dlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) }, |
| 439 | "enter_" + dlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 440 | }, |
| 441 | ) |
| 442 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 443 | logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": dh.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 444 | // TODO some specifc error treatment - or waiting for crash ? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 445 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 446 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 447 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 448 | if onuDeviceEntry.mibTemplateKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 449 | logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 450 | log.Fields{"device-id": dh.deviceID, "service": cBasePathMibTemplateKvStore}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 454 | baseKvStorePath := fmt.Sprintf(cBasePathOnuKVStore, dh.pOpenOnuAc.cm.Backend.PathPrefix) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 455 | onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, baseKvStorePath) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 456 | if onuDeviceEntry.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 457 | logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service", |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 458 | log.Fields{"device-id": dh.deviceID, "service": baseKvStorePath}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 461 | // Alarm Synchronization Database |
| 462 | //self._alarm_db = None |
| 463 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 464 | return &onuDeviceEntry |
| 465 | } |
| 466 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 467 | //start starts (logs) the omci agent |
| 468 | func (oo *OnuDeviceEntry) start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 469 | logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 470 | if oo.PDevOmciCC == nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 471 | oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 472 | oo.coreProxy, oo.adapterProxy) |
| 473 | if oo.PDevOmciCC == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 474 | logger.Errorw(ctx, "Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 475 | return fmt.Errorf("could not create devOmciCc %s", oo.deviceID) |
| 476 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 477 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 478 | return nil |
| 479 | } |
| 480 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 481 | //stop stops/resets the omciCC |
| 482 | func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 483 | logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 484 | if abResetOmciCC && (oo.PDevOmciCC != nil) { |
| 485 | _ = oo.PDevOmciCC.stop(ctx) |
| 486 | } |
| 487 | //to allow for all event notifications again when re-using the device and omciCC |
| 488 | oo.devState = DeviceStatusInit |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 489 | return nil |
| 490 | } |
| 491 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 492 | func (oo *OnuDeviceEntry) reboot(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 493 | logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 494 | if oo.PDevOmciCC != nil { |
| 495 | if err := oo.PDevOmciCC.sendReboot(ctx, ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 496 | logger.Errorw(ctx, "onu didn't reboot", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 497 | return err |
| 498 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 499 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 500 | return nil |
| 501 | } |
| 502 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 503 | func (oo *OnuDeviceEntry) waitForRebootResponse(ctx context.Context, responseChannel chan Message) error { |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 504 | select { |
| 505 | case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 506 | logger.Warnw(ctx, "Reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 507 | return fmt.Errorf("rebootTimeout") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 508 | case data := <-responseChannel: |
| 509 | switch data.Data.(OmciMessage).OmciMsg.MessageType { |
| 510 | case omci.RebootResponseType: |
| 511 | { |
| 512 | msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 513 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 514 | return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 515 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 516 | msgObj, msgOk := msgLayer.(*omci.RebootResponse) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 517 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 518 | 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] | 519 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 520 | logger.Debugw(ctx, "RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 521 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 522 | logger.Errorw(ctx, "Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 523 | // 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] | 524 | return fmt.Errorf("omci RebootResponse result error indication %s for device %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 525 | msgObj.Result, oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 526 | } |
| 527 | return nil |
| 528 | } |
| 529 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 530 | logger.Warnw(ctx, "Reboot response message type error", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 531 | return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 535 | //Relay the InSync message via Handler to Rw core - Status update |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 536 | func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent OnuDeviceEvent) { |
| 537 | logger.Debugw(ctx, "relaying system-event", log.Fields{"Event": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 538 | // decouple the handler transfer from further processing here |
| 539 | // 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] | 540 | if devEvent == MibDatabaseSync { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 541 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 542 | oo.devState = MibDatabaseSync |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 543 | go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 544 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 545 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 546 | logger.Debugw(ctx, "mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 547 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 548 | } else if devEvent == MibDownloadDone { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 549 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 550 | oo.devState = MibDownloadDone |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 551 | go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 552 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 553 | logger.Debugw(ctx, "mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 554 | } |
| 555 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 556 | logger.Warnw(ctx, "device-event not yet handled", log.Fields{"state": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 557 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 558 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 559 | |
| 560 | func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error { |
| 561 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 562 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 563 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID)) |
| 564 | } |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 565 | oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0)} |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 566 | Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath) |
| 567 | if err == nil { |
| 568 | if Value != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 569 | logger.Debugw(ctx, "ONU-data read", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 570 | log.Fields{"Key": Value.Key, "device-id": oo.deviceID}) |
| 571 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 572 | |
| 573 | if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 574 | logger.Errorw(ctx, "unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 575 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)) |
| 576 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 577 | logger.Debugw(ctx, "ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 578 | "device-id": oo.deviceID}) |
| 579 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 580 | logger.Debugw(ctx, "no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 581 | return fmt.Errorf("no-ONU-data-found") |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 582 | } |
| 583 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 584 | logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 585 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID)) |
| 586 | } |
| 587 | return nil |
| 588 | } |
| 589 | |
| 590 | func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 591 | defer wg.Done() |
| 592 | |
| 593 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 594 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 595 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: onuKVStore not set") |
| 596 | return |
| 597 | } |
| 598 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 599 | go oo.deletePersistentData(ctx, processingStep) |
| 600 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 601 | //timeout or error detected |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 602 | logger.Debugw(ctx, "ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 603 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: during kv-access") |
| 604 | return |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) { |
| 609 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 610 | logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame^] | 611 | oo.sOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector |
| 612 | oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0)} //default entry |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 613 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 614 | logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 615 | err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath) |
| 616 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 617 | logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 618 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 619 | return |
| 620 | } |
| 621 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 622 | } |
| 623 | |
| 624 | func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 625 | defer wg.Done() |
| 626 | |
| 627 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 628 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 629 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: onuKVStore not set") |
| 630 | return |
| 631 | } |
| 632 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 633 | go oo.storeDataInOnuKvStore(ctx, processingStep) |
| 634 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 635 | //timeout or error detected |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 636 | logger.Debugw(ctx, "ONU-data not written - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 637 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: during writing process") |
| 638 | return |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) { |
| 643 | |
| 644 | //assign values which are not already present when newOnuDeviceEntry() is called |
| 645 | oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId |
| 646 | oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId |
| 647 | oo.sOnuPersistentData.PersSnr = oo.baseDeviceHandler.pOnuOmciDevice.serialNumber |
| 648 | //TODO: verify usage of these values during restart UC |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 649 | oo.sOnuPersistentData.PersAdminState = oo.baseDeviceHandler.pOnuIndication.AdminState |
| 650 | oo.sOnuPersistentData.PersOperState = oo.baseDeviceHandler.pOnuIndication.OperState |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 651 | logger.Debugw(ctx, "Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 652 | |
| 653 | Value, err := json.Marshal(oo.sOnuPersistentData) |
| 654 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 655 | logger.Errorw(ctx, "unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 656 | "device-id": oo.deviceID, "err": err}) |
| 657 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 658 | return |
| 659 | } |
| 660 | err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value) |
| 661 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 662 | logger.Errorw(ctx, "unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 663 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 664 | return |
| 665 | } |
| 666 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 667 | } |
| 668 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 669 | func (oo *OnuDeviceEntry) updateOnuUniTpPath(ctx context.Context, aUniID uint8, aTpID uint8, aPathString string) bool { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 670 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 671 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 672 | no specific concurrency protection to sOnuPersistentData is required here |
| 673 | */ |
| 674 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 675 | if v.PersUniID == aUniID { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 676 | logger.Debugw(ctx, "PersUniConfig-entry already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 677 | existingPath, ok := oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] |
| 678 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 679 | logger.Debugw(ctx, "tp-does-not-exist--to-be-created-afresh", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 680 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 681 | if existingPath != aPathString { |
| 682 | if aPathString == "" { |
| 683 | //existing entry to be deleted |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 684 | logger.Debugw(ctx, "UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 685 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = "" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 686 | } else { |
| 687 | //existing entry to be modified |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 688 | logger.Debugw(ctx, "UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 689 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 690 | } |
| 691 | return true |
| 692 | } |
| 693 | //entry already exists |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 694 | if aPathString == "" { |
| 695 | //no active TechProfile |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 696 | logger.Debugw(ctx, "UniTp path has already been removed - no AniSide config to be removed", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 697 | "device-id": oo.deviceID, "uniID": aUniID}) |
| 698 | // attention 201105: this block is at the moment entered for each of subsequent GemPortDeletes and TContDelete |
| 699 | // as the path is already cleared with the first GemPort - this will probably change with the upcoming real |
| 700 | // TechProfile removal (still TODO), but anyway the reasonUpdate initiated here should not harm overall behavior |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 701 | go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 702 | // no flow config pending on 'remove' so far |
| 703 | } else { |
| 704 | //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here |
| 705 | //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU |
| 706 | // (as here the TechProfile has not been removed with the disable-device before the new enable-device) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 707 | logger.Debugw(ctx, "UniTp path already exists - TechProfile supposed to be active", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 708 | "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 709 | //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario |
| 710 | // (during which the flows are removed/re-assigned but the techProf is left active) |
| 711 | //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it |
| 712 | // (should not be the case, but should not harm or be more robust ...) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 713 | // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history |
| 714 | // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config |
| 715 | if oo.baseDeviceHandler.pOnuTP != nil { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 716 | oo.baseDeviceHandler.pOnuTP.setProfileToDelete(aUniID, aTpID, false) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 717 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 718 | go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 719 | } |
| 720 | return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | //no entry exists for uniId |
| 724 | |
| 725 | if aPathString == "" { |
| 726 | //delete request in non-existing state , accept as no change |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 727 | logger.Debugw(ctx, "UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 728 | return false |
| 729 | } |
| 730 | //new entry to be created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 731 | logger.Debugw(ctx, "New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 732 | perSubTpPathMap := make(map[uint8]string) |
| 733 | perSubTpPathMap[aTpID] = aPathString |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 734 | oo.sOnuPersistentData.PersUniConfig = |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 735 | append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPathMap: perSubTpPathMap, PersFlowParams: make([]uniVlanFlowParams, 0)}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 736 | return true |
| 737 | } |
| 738 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 739 | func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) { |
| 740 | |
| 741 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 742 | if v.PersUniID == aUniID { |
| 743 | oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams)) |
| 744 | copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams) |
| 745 | return |
| 746 | } |
| 747 | } |
| 748 | //flow update was faster than tp-config - create PersUniConfig-entry |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 749 | tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPathMap: make(map[uint8]string), PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))} |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 750 | copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams) |
| 751 | oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig) |
| 752 | } |
| 753 | |
| 754 | func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion( |
| 755 | ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
| 756 | select { |
| 757 | case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 758 | logger.Warnw(ctx, "processing not completed in-time!", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 759 | log.Fields{"device-id": oo.deviceID, "error": ctx.Err()}) |
| 760 | return false |
| 761 | case rxStep := <-aChOnuProcessingStep: |
| 762 | if rxStep == aProcessingStep { |
| 763 | return true |
| 764 | } |
| 765 | //all other values are not accepted - including 0 for error indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 766 | logger.Warnw(ctx, "Invalid processing step received: abort!", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 767 | log.Fields{"device-id": oo.deviceID, |
| 768 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 769 | return false |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() { |
| 774 | oo.onuKVStoreprocResult = nil |
| 775 | } |
| 776 | func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error { |
| 777 | return oo.onuKVStoreprocResult |
| 778 | } |
| 779 | |
| 780 | func (oo *OnuDeviceEntry) lockOnuKVStoreMutex() { |
| 781 | oo.onuKVStoreMutex.Lock() |
| 782 | } |
| 783 | |
| 784 | func (oo *OnuDeviceEntry) unlockOnuKVStoreMutex() { |
| 785 | oo.onuKVStoreMutex.Unlock() |
| 786 | } |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 787 | |
| 788 | func (oo *OnuDeviceEntry) incrementMibDataSync(ctx context.Context) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 789 | if oo.sOnuPersistentData.PersMibDataSyncAdpt < 255 { |
| 790 | oo.sOnuPersistentData.PersMibDataSyncAdpt++ |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 791 | } else { |
| 792 | // per G.984 and G.988 overflow starts over at 1 given 0 is reserved for reset |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 793 | oo.sOnuPersistentData.PersMibDataSyncAdpt = 1 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 794 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 795 | logger.Debugf(ctx, "mibDataSync updated - mds: %d - device-id: %s", oo.sOnuPersistentData.PersMibDataSyncAdpt, oo.deviceID) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 796 | } |