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" |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 35 | "github.com/opencord/voltha-lib-go/v5/pkg/adapters/adapterif" |
| 36 | "github.com/opencord/voltha-lib-go/v5/pkg/db" |
| 37 | "github.com/opencord/voltha-lib-go/v5/pkg/db/kvstore" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 38 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 39 | //"github.com/opencord/voltha-lib-go/v5/pkg/kafka" |
| 40 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 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" |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 82 | ulStExaminingMdsSuccess = "ulStExaminingMdsSuccess" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 83 | ulStAuditing = "ulStAuditing" |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 84 | ulStReAuditing = "ulStReAuditing" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 85 | ulStOutOfSync = "ulStOutOfSync" |
| 86 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 87 | const cMibUlFsmIdleState = ulStInSync |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 88 | |
| 89 | const ( |
| 90 | // events of MibDownload FSM |
| 91 | dlEvStart = "dlEvStart" |
| 92 | dlEvCreateGal = "dlEvCreateGal" |
| 93 | dlEvRxGalResp = "dlEvRxGalResp" |
| 94 | dlEvRxOnu2gResp = "dlEvRxOnu2gResp" |
| 95 | dlEvRxBridgeResp = "dlEvRxBridgeResp" |
| 96 | dlEvTimeoutSimple = "dlEvTimeoutSimple" |
| 97 | dlEvTimeoutBridge = "dlEvTimeoutBridge" |
| 98 | dlEvReset = "dlEvReset" |
| 99 | dlEvRestart = "dlEvRestart" |
| 100 | ) |
| 101 | const ( |
| 102 | // states of MibDownload FSM |
| 103 | dlStDisabled = "dlStDisabled" |
| 104 | dlStStarting = "dlStStarting" |
| 105 | dlStCreatingGal = "dlStCreatingGal" |
| 106 | dlStSettingOnu2g = "dlStSettingOnu2g" |
| 107 | dlStBridgeInit = "dlStBridgeInit" |
| 108 | dlStDownloaded = "dlStDownloaded" |
| 109 | dlStResetting = "dlStResetting" |
| 110 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 111 | const cMibDlFsmIdleState = dlStDisabled |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 112 | |
| 113 | const ( |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 114 | // 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] | 115 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 116 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 117 | cBasePathOnuKVStore = "%s/openonu" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 118 | ) |
| 119 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 120 | // OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 121 | type OnuDeviceEvent int |
| 122 | |
| 123 | const ( |
| 124 | // Events of interest to Device Adapters and OpenOMCI State Machines |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 125 | |
| 126 | // DeviceStatusInit - default start state |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 127 | DeviceStatusInit OnuDeviceEvent = iota |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 128 | // MibDatabaseSync - MIB database sync (upload done) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 129 | MibDatabaseSync |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 130 | // OmciCapabilitiesDone - OMCI ME and message type capabilities known |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 131 | OmciCapabilitiesDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 132 | // MibDownloadDone - // MIB download done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 133 | MibDownloadDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 134 | // UniLockStateDone - Uni ports admin set to lock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 135 | UniLockStateDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 136 | // UniUnlockStateDone - Uni ports admin set to unlock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 137 | UniUnlockStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 138 | // UniDisableStateDone - Uni ports admin set to lock based on device disable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 139 | UniDisableStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 140 | // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 141 | UniEnableStateDone |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 142 | // UniEnableStateFailed - Uni ports admin set to unlock failure based on device re-enable |
| 143 | UniEnableStateFailed |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 144 | // PortLinkUp - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 145 | PortLinkUp |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 146 | // PortLinkDw - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 147 | PortLinkDw |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 148 | // OmciAniConfigDone - AniSide config according to TechProfile done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 149 | OmciAniConfigDone |
| 150 | // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed |
| 151 | OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone! |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 152 | // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add with request to write kvStore |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 153 | OmciVlanFilterAddDone |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 154 | // OmciVlanFilterAddDoneNoKvStore - Omci Vlan config done according to flow-add without writing kvStore |
| 155 | OmciVlanFilterAddDoneNoKvStore // needs to be the successor of OmciVlanFilterAddDone! |
| 156 | // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove with request to write kvStore |
| 157 | OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDoneNoKvStore! |
| 158 | // OmciVlanFilterRemDoneNoKvStore - Omci Vlan config done according to flow-remove without writing kvStore |
| 159 | OmciVlanFilterRemDoneNoKvStore // needs to be the successor of OmciVlanFilterRemDone! |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 160 | // OmciOnuSwUpgradeDone - SoftwareUpgrade to ONU finished |
| 161 | OmciOnuSwUpgradeDone |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 162 | // Add other events here as needed (alarms separate???) |
| 163 | ) |
| 164 | |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 165 | //AdapterFsm related error string |
| 166 | //error string could be checked on waitforOmciResponse() e.g. to avoid misleading error log |
| 167 | // but not used that way so far (permit error log even for wanted cancellation) |
| 168 | const cErrWaitAborted = "waitResponse aborted" |
| 169 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 170 | type activityDescr struct { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 171 | databaseClass func(context.Context) error |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 172 | //advertiseEvents bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 173 | auditInterval time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 174 | //tasks map[string]func() error |
| 175 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 176 | |
| 177 | // 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] | 178 | type OmciDeviceFsms map[string]activityDescr |
| 179 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 180 | // AdapterFsm - Adapter FSM details including channel, event and device |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 181 | type AdapterFsm struct { |
| 182 | fsmName string |
| 183 | deviceID string |
| 184 | commChan chan Message |
| 185 | pFsm *fsm.FSM |
| 186 | } |
| 187 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 188 | //NewAdapterFsm - FSM details including event, device and channel. |
| 189 | func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 190 | aFsm := &AdapterFsm{ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 191 | fsmName: aName, |
| 192 | deviceID: aDeviceID, |
| 193 | commChan: aCommChannel, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 194 | } |
| 195 | return aFsm |
| 196 | } |
| 197 | |
| 198 | //Start starts (logs) the omci agent |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 199 | func (oo *AdapterFsm) logFsmStateChange(ctx context.Context, e *fsm.Event) { |
| 200 | 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] | 201 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 202 | } |
| 203 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 204 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 205 | |
| 206 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 207 | firstSwImageMeID = 0 |
| 208 | secondSwImageMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 209 | ) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 210 | const ( //definitions as per G.988 softwareImage::IsCommitted |
| 211 | swIsUncommitted = 0 |
| 212 | swIsCommitted = 1 |
| 213 | ) |
| 214 | const ( //definitions as per G.988 softwareImage::IsActive |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 215 | swIsInactive = 0 |
| 216 | swIsActive = 1 |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 217 | ) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 218 | const ( //definitions as per G.988 softwareImage::IsValid |
| 219 | //swIsInvalid = 0 not yet used |
| 220 | swIsValid = 1 |
| 221 | ) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 222 | const onuDataMeID = 0 |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 223 | const onugMeID = 0 |
| 224 | const onu2gMeID = 0 |
| 225 | const ipHostConfigDataMeID = 1 |
| 226 | const onugSerialNumberLen = 8 |
| 227 | const omciMacAddressLen = 6 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 228 | |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 229 | const cEmptyMacAddrString = "000000000000" |
| 230 | const cEmptySerialNumberString = "0000000000000000" |
| 231 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 232 | type sEntrySwImageIndication struct { |
| 233 | valid bool |
| 234 | entityID uint16 |
| 235 | version string |
| 236 | isCommitted uint8 |
| 237 | } |
| 238 | type sSwImageIndications struct { |
| 239 | activeEntityEntry sEntrySwImageIndication |
| 240 | inactiveEntityEntry sEntrySwImageIndication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 243 | type uniPersConfig struct { |
| 244 | PersUniID uint8 `json:"uni_id"` |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 245 | PersTpPathMap map[uint8]string `json:"PersTpPathMap"` // tp-id to tp-path map |
| 246 | PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | type onuPersistentData struct { |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 250 | PersOnuID uint32 `json:"onu_id"` |
| 251 | PersIntfID uint32 `json:"intf_id"` |
| 252 | PersSerialNumber string `json:"serial_number"` |
| 253 | PersMacAddress string `json:"mac_address"` |
| 254 | PersVendorID string `json:"vendor_id"` |
| 255 | PersEquipmentID string `json:"equipment_id"` |
| 256 | PersActiveSwVersion string `json:"active_sw_version"` |
| 257 | PersAdminState string `json:"admin_state"` |
| 258 | PersOperState string `json:"oper_state"` |
| 259 | PersUniUnlockDone bool `json:"uni_unlock_done"` |
| 260 | PersUniDisableDone bool `json:"uni_disable_done"` |
| 261 | PersMibAuditInterval time.Duration `json:"mib_audit_interval"` |
| 262 | PersMibLastDbSync uint32 `json:"mib_last_db_sync"` |
| 263 | PersMibDataSyncAdpt uint8 `json:"mib_data_sync_adpt"` |
| 264 | PersUniConfig []uniPersConfig `json:"uni_config"` |
| 265 | PersAlarmAuditInterval time.Duration `json:"alarm_audit_interval"` |
| 266 | PersTcontMap map[uint16]uint16 `json:"tcont_map"` //alloc-id to me-instance-id map |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 269 | // OnuDeviceEntry - ONU device info and FSM events. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 270 | type OnuDeviceEntry struct { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 271 | deviceID string |
| 272 | baseDeviceHandler *deviceHandler |
| 273 | pOpenOnuAc *OpenONUAC |
| 274 | coreProxy adapterif.CoreProxy |
| 275 | adapterProxy adapterif.AdapterProxy |
| 276 | PDevOmciCC *omciCC |
| 277 | pOnuDB *onuDeviceDB |
| 278 | mibTemplateKVStore *db.Backend |
| 279 | mutexPersOnuConfig sync.RWMutex |
| 280 | sOnuPersistentData onuPersistentData |
| 281 | mibTemplatePath string |
| 282 | mutexOnuKVStore sync.RWMutex |
| 283 | onuKVStore *db.Backend |
| 284 | onuKVStorePath string |
| 285 | mutexOnuKVStoreProcResult sync.RWMutex |
| 286 | onuKVStoreProcResult error //error indication of processing |
| 287 | chOnuKvProcessingStep chan uint8 |
| 288 | mutexOnuSwImageIndications sync.RWMutex |
| 289 | onuSwImageIndications sSwImageIndications |
| 290 | mutexOnuImageStatus sync.RWMutex |
| 291 | pOnuImageStatus *OnuImageStatus |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 292 | //lockDeviceEntries sync.RWMutex |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 293 | mibDbClass func(context.Context) error |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 294 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 295 | devState OnuDeviceEvent |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 296 | // Audit and MDS |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 297 | mibAuditInterval time.Duration |
| 298 | alarmAuditInterval time.Duration |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 299 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 300 | //mibNextDbResync uint32 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 301 | |
| 302 | // for mibUpload |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 303 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 304 | mutexLastTxParamStruct sync.RWMutex |
| 305 | lastTxParamStruct sLastTxMeParameter |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 306 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 307 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 308 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 309 | // within the FSM event procedures |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 310 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 311 | omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 314 | //newOnuDeviceEntry returns a new instance of a OnuDeviceEntry |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 315 | //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] | 316 | func newOnuDeviceEntry(ctx context.Context, dh *deviceHandler) *OnuDeviceEntry { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 317 | logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 318 | var onuDeviceEntry OnuDeviceEntry |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 319 | onuDeviceEntry.deviceID = dh.deviceID |
| 320 | onuDeviceEntry.baseDeviceHandler = dh |
| 321 | onuDeviceEntry.pOpenOnuAc = dh.pOpenOnuAc |
| 322 | onuDeviceEntry.coreProxy = dh.coreProxy |
| 323 | onuDeviceEntry.adapterProxy = dh.AdapterProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 324 | onuDeviceEntry.devState = DeviceStatusInit |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 325 | onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 326 | onuDeviceEntry.sOnuPersistentData.PersTcontMap = make(map[uint16]uint16) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 327 | onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 328 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 329 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 330 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 331 | //are per ONU Vendor |
| 332 | // |
| 333 | // MIB Synchronization Database - possible overloading from arguments |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 334 | if dh.pOpenOnuAc.pSupportedFsms != nil { |
| 335 | onuDeviceEntry.supportedFsms = *dh.pOpenOnuAc.pSupportedFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 336 | } else { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 337 | // 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] | 338 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 339 | // use some internal defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 340 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 341 | "mib-synchronizer": { |
| 342 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 343 | onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 344 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 345 | 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] | 346 | // map[string]func() error{ |
| 347 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 348 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 349 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 350 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 351 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 352 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 353 | // }, |
| 354 | }, |
| 355 | } |
| 356 | } |
| 357 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 358 | logger.Debug(ctx, "access2mibDbClass") |
| 359 | go onuDeviceEntry.mibDbClass(ctx) |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 360 | if !dh.isReconciling() { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 361 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditInterval |
| 362 | onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval = onuDeviceEntry.mibAuditInterval |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 363 | onuDeviceEntry.alarmAuditInterval = dh.pOpenOnuAc.alarmAuditInterval |
| 364 | onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval = onuDeviceEntry.alarmAuditInterval |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 365 | } else { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 366 | logger.Debugw(ctx, "reconciling - take audit interval from persistent data", log.Fields{"device-id": dh.deviceID}) |
| 367 | // 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] | 368 | // vendor- or deviceID-specific configurations via voltctl-commands |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 369 | onuDeviceEntry.mibAuditInterval = onuDeviceEntry.sOnuPersistentData.PersMibAuditInterval |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 370 | onuDeviceEntry.alarmAuditInterval = onuDeviceEntry.sOnuPersistentData.PersAlarmAuditInterval |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 371 | } |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 372 | logger.Debugw(ctx, "MibAuditInterval and AlarmAuditInterval is set to", log.Fields{"mib-audit-interval": onuDeviceEntry.mibAuditInterval, |
| 373 | "alarm-audit-interval": onuDeviceEntry.alarmAuditInterval}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 374 | // TODO: periodical mib resync will be implemented with story VOL-3792 |
| 375 | //onuDeviceEntry.mibNextDbResync = 0 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 376 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 377 | // Omci related Mib upload sync state machine |
| 378 | mibUploadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 379 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", dh.deviceID, mibUploadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 380 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 381 | ulStDisabled, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 382 | fsm.Events{ |
| 383 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 384 | {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 385 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 386 | {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib}, |
| 387 | {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial}, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 388 | {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID}, |
| 389 | {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 390 | {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion}, |
| 391 | {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress}, |
| 392 | {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate}, |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 393 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 394 | {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading}, |
| 395 | {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 396 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 397 | {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploadDone}, |
| 398 | {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStUploadDone}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 399 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 400 | {Name: ulEvSuccess, Src: []string{ulStUploadDone}, Dst: ulStInSync}, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 401 | //{Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync}, |
| 402 | {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStExaminingMdsSuccess}, |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 403 | // TODO: As long as mib-resynchronizing is not implemented, failed MDS-examination triggers |
| 404 | // mib-reset and new provisioning at this point |
| 405 | //{Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing}, |
| 406 | {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResettingMib}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 407 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 408 | {Name: ulEvSuccess, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStInSync}, |
| 409 | {Name: ulEvMismatch, Src: []string{ulStExaminingMdsSuccess}, Dst: ulStResettingMib}, |
| 410 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 411 | {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 412 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 413 | {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync}, |
| 414 | {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 415 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 416 | {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync}, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 417 | {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStReAuditing}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 418 | {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 419 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 420 | {Name: ulEvSuccess, Src: []string{ulStReAuditing}, Dst: ulStInSync}, |
| 421 | {Name: ulEvMismatch, Src: []string{ulStReAuditing}, Dst: ulStResettingMib}, |
| 422 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 423 | {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync}, |
| 424 | {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 425 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 426 | {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 427 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 428 | ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 429 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 430 | {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 431 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 432 | ulStUploadDone, ulStInSync, ulStOutOfSync, ulStAuditing, ulStReAuditing}, Dst: ulStDisabled}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 433 | }, |
| 434 | |
| 435 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 436 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(ctx, e) }, |
| 437 | "enter_" + ulStStarting: func(e *fsm.Event) { onuDeviceEntry.enterStartingState(ctx, e) }, |
| 438 | "enter_" + ulStResettingMib: func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(ctx, e) }, |
| 439 | "enter_" + ulStGettingVendorAndSerial: func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(ctx, e) }, |
| 440 | "enter_" + ulStGettingEquipmentID: func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(ctx, e) }, |
| 441 | "enter_" + ulStGettingFirstSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(ctx, e) }, |
| 442 | "enter_" + ulStGettingSecondSwVersion: func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(ctx, e) }, |
| 443 | "enter_" + ulStGettingMacAddress: func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(ctx, e) }, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 444 | "enter_" + ulStGettingMibTemplate: func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplateState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 445 | "enter_" + ulStUploading: func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(ctx, e) }, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 446 | "enter_" + ulStUploadDone: func(e *fsm.Event) { onuDeviceEntry.enterUploadDoneState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 447 | "enter_" + ulStExaminingMds: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(ctx, e) }, |
| 448 | "enter_" + ulStResynchronizing: func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(ctx, e) }, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 449 | "enter_" + ulStExaminingMdsSuccess: func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsSuccessState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 450 | "enter_" + ulStAuditing: func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(ctx, e) }, |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 451 | "enter_" + ulStReAuditing: func(e *fsm.Event) { onuDeviceEntry.enterReAuditingState(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 452 | "enter_" + ulStOutOfSync: func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(ctx, e) }, |
| 453 | "enter_" + ulStInSync: func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(ctx, e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 454 | }, |
| 455 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 456 | // Omci related Mib download state machine |
| 457 | mibDownloadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 458 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", dh.deviceID, mibDownloadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 459 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 460 | dlStDisabled, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 461 | fsm.Events{ |
| 462 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 463 | {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 464 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 465 | {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal}, |
| 466 | {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g}, |
| 467 | {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit}, |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 468 | // the bridge state is used for multi ME config for alle UNI related ports |
| 469 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 470 | // 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] | 471 | {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 472 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 473 | {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting}, |
| 474 | {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 475 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 476 | {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 477 | dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting}, |
| 478 | // exceptional treatment for all states except dlStResetting |
| 479 | {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 480 | dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 481 | }, |
| 482 | |
| 483 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 484 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(ctx, e) }, |
| 485 | "enter_" + dlStStarting: func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(ctx, e) }, |
| 486 | "enter_" + dlStCreatingGal: func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(ctx, e) }, |
| 487 | "enter_" + dlStSettingOnu2g: func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(ctx, e) }, |
| 488 | "enter_" + dlStBridgeInit: func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(ctx, e) }, |
| 489 | "enter_" + dlStDownloaded: func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(ctx, e) }, |
| 490 | "enter_" + dlStResetting: func(e *fsm.Event) { onuDeviceEntry.enterResettingState(ctx, e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 491 | }, |
| 492 | ) |
| 493 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 494 | logger.Errorw(ctx, "MibDownloadFsm could not be instantiated", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 495 | // TODO some specific error treatment - or waiting for crash ? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 496 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 497 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 498 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 499 | if onuDeviceEntry.mibTemplateKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 500 | logger.Errorw(ctx, "Can't access mibTemplateKVStore - no backend connection to service", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 501 | log.Fields{"device-id": dh.deviceID, "service": cBasePathMibTemplateKvStore}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 505 | baseKvStorePath := fmt.Sprintf(cBasePathOnuKVStore, dh.pOpenOnuAc.cm.Backend.PathPrefix) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 506 | onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(ctx, baseKvStorePath) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 507 | if onuDeviceEntry.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 508 | logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service", |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 509 | log.Fields{"device-id": dh.deviceID, "service": baseKvStorePath}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 512 | // Alarm Synchronization Database |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 513 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 514 | //self._alarm_db = None |
| 515 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 516 | return &onuDeviceEntry |
| 517 | } |
| 518 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 519 | //start starts (logs) the omci agent |
| 520 | func (oo *OnuDeviceEntry) start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 521 | logger.Debugw(ctx, "OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 522 | if oo.PDevOmciCC == nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 523 | oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 524 | oo.coreProxy, oo.adapterProxy) |
| 525 | if oo.PDevOmciCC == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 526 | 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] | 527 | return fmt.Errorf("could not create devOmciCc %s", oo.deviceID) |
| 528 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 529 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 530 | return nil |
| 531 | } |
| 532 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 533 | //stop stops/resets the omciCC |
| 534 | func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 535 | logger.Debugw(ctx, "OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 536 | if abResetOmciCC && (oo.PDevOmciCC != nil) { |
| 537 | _ = oo.PDevOmciCC.stop(ctx) |
| 538 | } |
| 539 | //to allow for all event notifications again when re-using the device and omciCC |
| 540 | oo.devState = DeviceStatusInit |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 541 | return nil |
| 542 | } |
| 543 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 544 | func (oo *OnuDeviceEntry) reboot(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 545 | logger.Debugw(ctx, "OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 546 | if oo.PDevOmciCC != nil { |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 547 | if err := oo.PDevOmciCC.sendReboot(ctx, oo.pOpenOnuAc.omciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 548 | 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] | 549 | return err |
| 550 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 551 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 552 | return nil |
| 553 | } |
| 554 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 555 | func (oo *OnuDeviceEntry) waitForRebootResponse(ctx context.Context, responseChannel chan Message) error { |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 556 | select { |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 557 | case <-time.After(oo.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * 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] | 558 | logger.Warnw(ctx, "Reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 559 | return fmt.Errorf("rebootTimeout") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 560 | case data := <-responseChannel: |
| 561 | switch data.Data.(OmciMessage).OmciMsg.MessageType { |
| 562 | case omci.RebootResponseType: |
| 563 | { |
| 564 | msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 565 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 566 | return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 567 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 568 | msgObj, msgOk := msgLayer.(*omci.RebootResponse) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 569 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 570 | 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] | 571 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 572 | 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] | 573 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 574 | 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] | 575 | // 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] | 576 | return fmt.Errorf("omci RebootResponse result error indication %s for device %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 577 | msgObj.Result, oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 578 | } |
| 579 | return nil |
| 580 | } |
| 581 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 582 | 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] | 583 | return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 587 | //Relay the InSync message via Handler to Rw core - Status update |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 588 | func (oo *OnuDeviceEntry) transferSystemEvent(ctx context.Context, devEvent OnuDeviceEvent) { |
| 589 | logger.Debugw(ctx, "relaying system-event", log.Fields{"Event": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 590 | // decouple the handler transfer from further processing here |
| 591 | // 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] | 592 | if devEvent == MibDatabaseSync { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 593 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 594 | oo.devState = MibDatabaseSync |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 595 | go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 596 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 597 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 598 | 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] | 599 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 600 | } else if devEvent == MibDownloadDone { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 601 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 602 | oo.devState = MibDownloadDone |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 603 | go oo.baseDeviceHandler.deviceProcStatusUpdate(ctx, devEvent) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 604 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 605 | 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] | 606 | } |
| 607 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 608 | logger.Warnw(ctx, "device-event not yet handled", log.Fields{"state": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 609 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 610 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 611 | |
| 612 | func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error { |
| 613 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 614 | 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] | 615 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID)) |
| 616 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 617 | oo.mutexPersOnuConfig.Lock() |
| 618 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 619 | oo.sOnuPersistentData = |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 620 | onuPersistentData{0, 0, "", "", "", "", "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 621 | oo.mutexOnuKVStore.RLock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 622 | Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 623 | oo.mutexOnuKVStore.RUnlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 624 | if err == nil { |
| 625 | if Value != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 626 | logger.Debugw(ctx, "ONU-data read", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 627 | log.Fields{"Key": Value.Key, "device-id": oo.deviceID}) |
| 628 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 629 | |
| 630 | if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 631 | 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] | 632 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)) |
| 633 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 634 | logger.Debugw(ctx, "ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 635 | "device-id": oo.deviceID}) |
| 636 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 637 | 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] | 638 | return fmt.Errorf("no-ONU-data-found") |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 639 | } |
| 640 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 641 | 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] | 642 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID)) |
| 643 | } |
| 644 | return nil |
| 645 | } |
| 646 | |
| 647 | func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 648 | defer wg.Done() |
| 649 | |
| 650 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 651 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 652 | oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: onuKVStore not set")) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 653 | return |
| 654 | } |
| 655 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 656 | go oo.deletePersistentData(ctx, processingStep) |
| 657 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 658 | //timeout or error detected |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 659 | logger.Debugw(ctx, "ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 660 | oo.setKvProcessingErrorIndication(errors.New("onu-data delete aborted: during kv-access")) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 661 | return |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) { |
| 666 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 667 | logger.Debugw(ctx, "delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | daf0f72 | 2021-02-12 11:50:30 +0000 | [diff] [blame] | 668 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 669 | oo.mutexPersOnuConfig.Lock() |
| 670 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | daf0f72 | 2021-02-12 11:50:30 +0000 | [diff] [blame] | 671 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 672 | oo.sOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector default entry |
| 673 | oo.sOnuPersistentData = |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 674 | onuPersistentData{0, 0, "", "", "", "", "", "", "", false, false, oo.mibAuditInterval, 0, 0, make([]uniPersConfig, 0), oo.alarmAuditInterval, make(map[uint16]uint16)} |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 675 | logger.Debugw(ctx, "delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 676 | oo.mutexOnuKVStore.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 677 | err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 678 | oo.mutexOnuKVStore.Unlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 679 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 680 | 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] | 681 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 682 | return |
| 683 | } |
| 684 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 685 | } |
| 686 | |
| 687 | func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 688 | defer wg.Done() |
| 689 | |
| 690 | if oo.onuKVStore == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 691 | logger.Debugw(ctx, "onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 692 | oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: onuKVStore not set")) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 693 | return |
| 694 | } |
| 695 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 696 | go oo.storeDataInOnuKvStore(ctx, processingStep) |
| 697 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 698 | //timeout or error detected |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 699 | logger.Debugw(ctx, "ONU-data not written - abort", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 700 | oo.setKvProcessingErrorIndication(errors.New("onu-data update aborted: during writing process")) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 701 | return |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) { |
| 706 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 707 | oo.mutexPersOnuConfig.Lock() |
| 708 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 709 | //assign values which are not already present when newOnuDeviceEntry() is called |
| 710 | oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId |
| 711 | oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 712 | //TODO: verify usage of these values during restart UC |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 713 | oo.sOnuPersistentData.PersAdminState = oo.baseDeviceHandler.pOnuIndication.AdminState |
| 714 | oo.sOnuPersistentData.PersOperState = oo.baseDeviceHandler.pOnuIndication.OperState |
Holger Hildebrandt | daf0f72 | 2021-02-12 11:50:30 +0000 | [diff] [blame] | 715 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 716 | 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] | 717 | |
| 718 | Value, err := json.Marshal(oo.sOnuPersistentData) |
| 719 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 720 | 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] | 721 | "device-id": oo.deviceID, "err": err}) |
| 722 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 723 | return |
| 724 | } |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 725 | oo.pOpenOnuAc.lockDeviceHandlersMap.RLock() |
| 726 | if _, exist := oo.pOpenOnuAc.deviceHandlers[oo.deviceID]; !exist { |
| 727 | logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID}) |
| 728 | oo.chOnuKvProcessingStep <- aProcessingStep |
| 729 | oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock() |
| 730 | return |
| 731 | } |
| 732 | oo.baseDeviceHandler.mutexDeletionInProgressFlag.RLock() |
| 733 | if oo.baseDeviceHandler.deletionInProgress { |
| 734 | logger.Debugw(ctx, "delete_device in progress - skip write request", log.Fields{"device-id": oo.deviceID}) |
| 735 | oo.chOnuKvProcessingStep <- aProcessingStep |
| 736 | oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock() |
| 737 | oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock() |
| 738 | return |
| 739 | } |
| 740 | oo.pOpenOnuAc.lockDeviceHandlersMap.RUnlock() |
| 741 | oo.baseDeviceHandler.mutexDeletionInProgressFlag.RUnlock() |
| 742 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 743 | oo.mutexOnuKVStore.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 744 | err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 745 | oo.mutexOnuKVStore.Unlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 746 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 747 | 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] | 748 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 749 | return |
| 750 | } |
| 751 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 752 | } |
| 753 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 754 | 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] | 755 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 756 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 757 | no specific concurrency protection to sOnuPersistentData is required here |
| 758 | */ |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 759 | oo.mutexPersOnuConfig.Lock() |
| 760 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | daf0f72 | 2021-02-12 11:50:30 +0000 | [diff] [blame] | 761 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 762 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 763 | if v.PersUniID == aUniID { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 764 | existingPath, ok := oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 765 | logger.Debugw(ctx, "PersUniConfig-entry exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, |
| 766 | "tpID": aTpID, "path": aPathString, "existingPath": existingPath, "ok": ok}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 767 | if !ok { |
mpagenko | 30f2844 | 2021-03-24 09:24:04 +0000 | [diff] [blame] | 768 | logger.Debugw(ctx, "tp-does-not-exist", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "tpID": aTpID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 769 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 770 | if existingPath != aPathString { |
| 771 | if aPathString == "" { |
| 772 | //existing entry to be deleted |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 773 | 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] | 774 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = "" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 775 | } else { |
| 776 | //existing entry to be modified |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 777 | 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] | 778 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPathMap[aTpID] = aPathString |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 779 | } |
| 780 | return true |
| 781 | } |
| 782 | //entry already exists |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 783 | if aPathString == "" { |
| 784 | //no active TechProfile |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 785 | 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] | 786 | "device-id": oo.deviceID, "uniID": aUniID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 787 | } else { |
| 788 | //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here |
| 789 | //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU |
| 790 | // (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] | 791 | 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] | 792 | "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 793 | //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario |
| 794 | // (during which the flows are removed/re-assigned but the techProf is left active) |
| 795 | //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it |
| 796 | // (should not be the case, but should not harm or be more robust ...) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 797 | // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history |
| 798 | // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config |
| 799 | if oo.baseDeviceHandler.pOnuTP != nil { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 800 | oo.baseDeviceHandler.pOnuTP.setProfileToDelete(aUniID, aTpID, false) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 801 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 802 | go oo.baseDeviceHandler.VerifyVlanConfigRequest(ctx, aUniID, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 803 | } |
| 804 | 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] | 805 | } |
| 806 | } |
| 807 | //no entry exists for uniId |
| 808 | |
| 809 | if aPathString == "" { |
| 810 | //delete request in non-existing state , accept as no change |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 811 | 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] | 812 | return false |
| 813 | } |
| 814 | //new entry to be created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 815 | 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] | 816 | perSubTpPathMap := make(map[uint8]string) |
| 817 | perSubTpPathMap[aTpID] = aPathString |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 818 | oo.sOnuPersistentData.PersUniConfig = |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 819 | 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] | 820 | return true |
| 821 | } |
| 822 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 823 | func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) { |
| 824 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 825 | oo.mutexPersOnuConfig.Lock() |
| 826 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | daf0f72 | 2021-02-12 11:50:30 +0000 | [diff] [blame] | 827 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 828 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 829 | if v.PersUniID == aUniID { |
| 830 | oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams)) |
| 831 | copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams) |
| 832 | return |
| 833 | } |
| 834 | } |
| 835 | //flow update was faster than tp-config - create PersUniConfig-entry |
mpagenko | 30f2844 | 2021-03-24 09:24:04 +0000 | [diff] [blame] | 836 | //TODO!!: following activity to 'add' some new uni entry might not be quite correct if this function is called to clear the data |
| 837 | // (e.g after flow removal from RemoveUniFlowParams()). |
| 838 | // This has the effect of misleading indication that there is still some active UNI entry, even though there might be only some nil flow entry |
| 839 | // The effect of this flaw is that at TechProfile removal there is an additional attempt to remove the entry even though no techProfile exists anymore |
| 840 | // The code is not changed here because of the current release lane, changes might have unexpected secondary effects, perhaps later with more elaborate tests |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 841 | 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] | 842 | copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams) |
| 843 | oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig) |
| 844 | } |
| 845 | |
| 846 | func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion( |
| 847 | ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
| 848 | select { |
| 849 | case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 850 | logger.Warnw(ctx, "processing not completed in-time!", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 851 | log.Fields{"device-id": oo.deviceID, "error": ctx.Err()}) |
| 852 | return false |
| 853 | case rxStep := <-aChOnuProcessingStep: |
| 854 | if rxStep == aProcessingStep { |
| 855 | return true |
| 856 | } |
| 857 | //all other values are not accepted - including 0 for error indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 858 | logger.Warnw(ctx, "Invalid processing step received: abort!", |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 859 | log.Fields{"device-id": oo.deviceID, |
| 860 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 861 | return false |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 866 | oo.mutexOnuKVStoreProcResult.Lock() |
| 867 | oo.onuKVStoreProcResult = nil |
| 868 | oo.mutexOnuKVStoreProcResult.Unlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 869 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 870 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 871 | func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 872 | oo.mutexOnuKVStoreProcResult.RLock() |
| 873 | value := oo.onuKVStoreProcResult |
| 874 | oo.mutexOnuKVStoreProcResult.RUnlock() |
| 875 | return value |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 876 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 877 | |
| 878 | func (oo *OnuDeviceEntry) setKvProcessingErrorIndication(value error) { |
| 879 | oo.mutexOnuKVStoreProcResult.Lock() |
| 880 | oo.onuKVStoreProcResult = value |
| 881 | oo.mutexOnuKVStoreProcResult.Unlock() |
| 882 | } |
| 883 | |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 884 | func (oo *OnuDeviceEntry) incrementMibDataSync(ctx context.Context) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 885 | oo.mutexPersOnuConfig.Lock() |
| 886 | defer oo.mutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 887 | if oo.sOnuPersistentData.PersMibDataSyncAdpt < 255 { |
| 888 | oo.sOnuPersistentData.PersMibDataSyncAdpt++ |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 889 | } else { |
| 890 | // 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] | 891 | oo.sOnuPersistentData.PersMibDataSyncAdpt = 1 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 892 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 893 | 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] | 894 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 895 | |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 896 | // ModifySwImageInactiveVersion - updates the inactive SW image version stored |
| 897 | func (oo *OnuDeviceEntry) ModifySwImageInactiveVersion(ctx context.Context, aImageVersion string) { |
| 898 | oo.mutexOnuSwImageIndications.Lock() |
| 899 | defer oo.mutexOnuSwImageIndications.Unlock() |
| 900 | logger.Debugw(ctx, "software-image set inactive version", log.Fields{ |
| 901 | "device-id": oo.deviceID, "version": aImageVersion}) |
| 902 | oo.onuSwImageIndications.inactiveEntityEntry.version = aImageVersion |
| 903 | //inactive SW version is not part of persistency data (yet) - no need to update that |
| 904 | } |
| 905 | |
| 906 | // ModifySwImageActiveCommit - updates the active SW commit flag stored |
| 907 | func (oo *OnuDeviceEntry) ModifySwImageActiveCommit(ctx context.Context, aCommitted uint8) { |
| 908 | oo.mutexOnuSwImageIndications.Lock() |
| 909 | defer oo.mutexOnuSwImageIndications.Unlock() |
| 910 | logger.Debugw(ctx, "software-image set active entity commit flag", log.Fields{ |
| 911 | "device-id": oo.deviceID, "committed": aCommitted}) |
| 912 | oo.onuSwImageIndications.activeEntityEntry.isCommitted = aCommitted |
| 913 | //commit flag is not part of persistency data (yet) - no need to update that |
| 914 | } |
| 915 | |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 916 | func (oo *OnuDeviceEntry) getActiveImageVersion(ctx context.Context) string { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 917 | oo.mutexOnuSwImageIndications.RLock() |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 918 | if oo.onuSwImageIndications.activeEntityEntry.valid { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 919 | value := oo.onuSwImageIndications.activeEntityEntry.version |
| 920 | oo.mutexOnuSwImageIndications.RUnlock() |
| 921 | return value |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 922 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 923 | oo.mutexOnuSwImageIndications.RUnlock() |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 924 | logger.Debugw(ctx, "Active Image is not valid", log.Fields{"device-id": oo.deviceID}) |
| 925 | return "" |
| 926 | } |
| 927 | |
| 928 | func (oo *OnuDeviceEntry) getInactiveImageVersion(ctx context.Context) string { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 929 | oo.mutexOnuSwImageIndications.RLock() |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 930 | if oo.onuSwImageIndications.inactiveEntityEntry.valid { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 931 | value := oo.onuSwImageIndications.inactiveEntityEntry.version |
| 932 | oo.mutexOnuSwImageIndications.RUnlock() |
| 933 | return value |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 934 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 935 | oo.mutexOnuSwImageIndications.RUnlock() |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 936 | logger.Debugw(ctx, "Inactive Image is not valid", log.Fields{"device-id": oo.deviceID}) |
| 937 | return "" |
| 938 | } |
| 939 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 940 | func (oo *OnuDeviceEntry) buildMibTemplatePath() string { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 941 | oo.mutexPersOnuConfig.RLock() |
| 942 | defer oo.mutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 943 | return fmt.Sprintf(cSuffixMibTemplateKvStore, oo.sOnuPersistentData.PersVendorID, oo.sOnuPersistentData.PersEquipmentID, oo.sOnuPersistentData.PersActiveSwVersion) |
| 944 | } |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 945 | |
| 946 | func (oo *OnuDeviceEntry) allocateFreeTcont(ctx context.Context, allocID uint16) (uint16, bool, error) { |
| 947 | logger.Debugw(ctx, "allocate-free-tcont", log.Fields{"device-id": oo.deviceID, "allocID": allocID, |
| 948 | "allocated-instances": oo.sOnuPersistentData.PersTcontMap}) |
| 949 | |
mpagenko | b59fbed | 2021-11-23 16:55:20 +0000 | [diff] [blame] | 950 | oo.mutexPersOnuConfig.Lock() |
| 951 | defer oo.mutexPersOnuConfig.Unlock() |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 952 | if entityID, ok := oo.sOnuPersistentData.PersTcontMap[allocID]; ok { |
| 953 | //tcont already allocated before, return the used instance-id |
| 954 | return entityID, true, nil |
| 955 | } |
| 956 | //First allocation of tcont. Find a free instance |
| 957 | if tcontInstKeys := oo.pOnuDB.getSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 { |
| 958 | logger.Debugw(ctx, "allocate-free-tcont-db-keys", log.Fields{"device-id": oo.deviceID, "keys": tcontInstKeys}) |
| 959 | for _, instID := range tcontInstKeys { |
| 960 | instExist := false |
| 961 | //If this instance exist in map, it means it is not empty. It is allocated before |
| 962 | for _, v := range oo.sOnuPersistentData.PersTcontMap { |
| 963 | if v == instID { |
| 964 | instExist = true |
| 965 | break |
| 966 | } |
| 967 | } |
| 968 | if !instExist { |
| 969 | oo.sOnuPersistentData.PersTcontMap[allocID] = instID |
| 970 | return instID, false, nil |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | return 0, false, fmt.Errorf(fmt.Sprintf("no-free-tcont-left-for-device-%s", oo.deviceID)) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | func (oo *OnuDeviceEntry) freeTcont(ctx context.Context, allocID uint16) { |
| 978 | logger.Debugw(ctx, "free-tcont", log.Fields{"device-id": oo.deviceID, "alloc": allocID}) |
mpagenko | b59fbed | 2021-11-23 16:55:20 +0000 | [diff] [blame] | 979 | oo.mutexPersOnuConfig.Lock() |
| 980 | defer oo.mutexPersOnuConfig.Unlock() |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 981 | delete(oo.sOnuPersistentData.PersTcontMap, allocID) |
| 982 | } |
Holger Hildebrandt | ddc4fbd | 2022-02-04 14:10:36 +0000 | [diff] [blame^] | 983 | |
| 984 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 985 | func (oo *OnuDeviceEntry) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 986 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 987 | oo.baseDeviceHandler = nil |
| 988 | if oo.PDevOmciCC != nil { |
| 989 | oo.PDevOmciCC.PrepareForGarbageCollection(ctx, aDeviceID) |
| 990 | } |
| 991 | oo.PDevOmciCC = nil |
| 992 | } |