mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 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 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 17 | // Package swupg provides the utilities for onu sw upgrade |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package swupg |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 22 | "encoding/binary" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 23 | "fmt" |
| 24 | "strconv" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 25 | "sync" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 26 | "time" |
| 27 | |
| 28 | "github.com/boguslaw-wojcik/crc32a" |
| 29 | "github.com/looplab/fsm" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 30 | "github.com/opencord/omci-lib-go/v2" |
| 31 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 33 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 34 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb" |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 35 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v5/go/voltha" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | const cMaxUint32 = ^uint32(0) |
| 40 | |
| 41 | const ( |
| 42 | // internal predefined values - some off them should later be configurable (perhaps with theses as defaults) |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 43 | cOmciDownloadSectionSizeBaseLine = 31 //in bytes |
| 44 | cOmciDownloadWindowSizeLimitBaseLine = 31 //in sections for window offset (windowSize(32)-1) |
| 45 | cOmciDownloadSectionSizeExtLine = 1965 //in bytes |
| 46 | cOmciDownloadWindowSizeLimitExtLine = 7 //in sections for window offset (windowSize(8)-1) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 47 | //cOmciDownloadWindowRetryMax = 2 // max attempts for a specific window |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 48 | cOmciSectionInterleaveMilliseconds = 0 //DownloadSection interleave time in milliseconds (0 for no delay) |
| 49 | cOmciEndSwDlDelaySeconds = 1 //End Software Download delay after last section (may be also configurable?) |
| 50 | cWaitCountEndSwDl = 6 //maximum number of EndSwDl requests |
| 51 | cWaitDelayEndSwDlSeconds = 10 //duration, how long is waited before next request on EndSwDl |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 52 | //cOmciDownloadCompleteTimeout = 5400 //in s for the complete timeout (may be better scale to image size/ noOfWindows) |
| 53 | ) |
| 54 | |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 55 | // tEndSwDlResponseResult - Response result from EndSwDownload as used in channel indication |
| 56 | type tUpgradePhase uint8 |
| 57 | |
| 58 | const ( |
| 59 | // undefined phase |
| 60 | cUpgradeUndefined tUpgradePhase = iota |
| 61 | // downloading image |
| 62 | cUpgradeDownloading |
| 63 | // image downloaded |
| 64 | cUpgradeDownloaded |
| 65 | // activating image |
| 66 | cUpgradeActivating |
| 67 | // image activated |
| 68 | cUpgradeActivated |
| 69 | // committing image |
| 70 | cUpgradeCommitting |
| 71 | // image committed |
| 72 | cUpgradeCommitted |
| 73 | ) |
| 74 | |
| 75 | // tEndSwDlResponseResult - Response result from EndSwDownload as used in channel indication |
| 76 | type tEndSwDlResponseResult uint8 |
| 77 | |
| 78 | const ( |
| 79 | // response success |
| 80 | cEndSwDlResponseSuccess tEndSwDlResponseResult = iota |
| 81 | // response busy (repeat) |
| 82 | cEndSwDlResponseBusy |
| 83 | // response error or abort waiting for response |
| 84 | cEndSwDlResponseAbort |
| 85 | ) |
| 86 | |
| 87 | // upgrade FSM related events |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 88 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 89 | UpgradeEvStart = "UpgradeEvStart" |
| 90 | UpgradeEvDisable = "UpgradeEvDisable" |
| 91 | UpgradeEvAdapterDownload = "UpgradeEvAdapterDownload" |
| 92 | UpgradeEvPrepareSwDownload = "UpgradeEvPrepareSwDownload" |
| 93 | UpgradeEvRxStartSwDownload = "UpgradeEvRxStartSwDownload" |
| 94 | UpgradeEvWaitWindowAck = "UpgradeEvWaitWindowAck" |
| 95 | UpgradeEvContinueNextWindow = "UpgradeEvContinueNextWindow" |
| 96 | UpgradeEvEndSwDownload = "UpgradeEvEndSwDownload" |
| 97 | UpgradeEvWaitEndDownload = "UpgradeEvWaitEndDownload" |
| 98 | UpgradeEvContinueFinalize = "UpgradeEvContinueFinalize" |
| 99 | UpgradeEvCheckImageName = "UpgradeEvCheckImageName" |
| 100 | UpgradeEvWaitForActivate = "UpgradeEvWaitForActivate" |
| 101 | UpgradeEvRequestActivate = "UpgradeEvRequestActivate" |
| 102 | UpgradeEvActivationDone = "UpgradeEvActivationDone" |
| 103 | UpgradeEvWaitForCommit = "UpgradeEvWaitForCommit" |
| 104 | UpgradeEvCommitSw = "UpgradeEvCommitSw" |
| 105 | UpgradeEvCheckCommitted = "UpgradeEvCheckCommitted" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 106 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 107 | //UpgradeEvTimeoutSimple = "UpgradeEvTimeoutSimple" |
| 108 | //UpgradeEvTimeoutMids = "UpgradeEvTimeoutMids" |
| 109 | UpgradeEvReset = "UpgradeEvReset" |
| 110 | UpgradeEvAbort = "UpgradeEvAbort" |
| 111 | UpgradeEvRestart = "UpgradeEvRestart" |
| 112 | UpgradeEvAbortSwDownload = "UpgradeEvAbortSwDownload" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 113 | ) |
| 114 | |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 115 | // upgrade FSM related states |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 116 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 117 | UpgradeStDisabled = "UpgradeStDisabled" |
| 118 | UpgradeStStarting = "UpgradeStStarting" |
| 119 | UpgradeStWaitingAdapterDL = "UpgradeStWaitingAdapterDL" |
| 120 | UpgradeStPreparingDL = "UpgradeStPreparingDL" |
| 121 | UpgradeStDLSection = "UpgradeStDLSection" |
| 122 | UpgradeStVerifyWindow = "UpgradeStVerifyWindow" |
| 123 | UpgradeStFinalizeDL = "UpgradeStFinalizeDL" |
| 124 | UpgradeStWaitEndDL = "UpgradeStWaitEndDL" |
| 125 | UpgradeStCheckImageName = "UpgradeStCheckImageName" |
| 126 | UpgradeStWaitForActivate = "UpgradeStWaitForActivate" |
| 127 | UpgradeStRequestingActivate = "UpgradeStRequestingActivate" |
| 128 | UpgradeStActivated = "UpgradeStActivated" |
| 129 | UpgradeStWaitForCommit = "UpgradeStWaitForCommit" |
| 130 | UpgradeStCommitSw = "UpgradeStCommitSw" |
| 131 | UpgradeStCheckCommitted = "UpgradeStCheckCommitted" |
| 132 | UpgradeStResetting = "UpgradeStResetting" |
| 133 | UpgradeStRestarting = "UpgradeStRestarting" |
| 134 | UpgradeStAbortingDL = "UpgradeStAbortingDL" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 135 | ) |
| 136 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 137 | // COnuUpgradeFsmIdleState - required definition for IdleState detection for activities on OMCI |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 138 | const COnuUpgradeFsmIdleState = UpgradeStWaitForCommit |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 139 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 140 | // OnuUpgradeFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 141 | type OnuUpgradeFsm struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 142 | pDeviceHandler cmn.IdeviceHandler |
| 143 | pDownloadManager *AdapterDownloadManager |
| 144 | pFileManager *FileDownloadManager //used from R2.8 with new API version |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 145 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 146 | pDevEntry cmn.IonuDeviceEntry |
| 147 | pOmciCC *cmn.OmciCC |
| 148 | pOnuDB *devdb.OnuDeviceDB |
| 149 | requestEvent cmn.OnuDeviceEvent |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 150 | //omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 151 | PAdaptFsm *cmn.AdapterFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 152 | pImageDsc *voltha.ImageDownload |
| 153 | imageBuffer []byte |
| 154 | origImageLength uint32 //as also limited by OMCI |
| 155 | imageCRC uint32 //as per OMCI - ITU I.363.5 crc |
| 156 | imageLength uint32 //including last bytes padding |
| 157 | omciDownloadWindowSizeLimit uint8 //windowSize-1 in sections |
| 158 | omciDownloadWindowSizeLast uint8 //number of sections in last window |
| 159 | noOfSections uint32 //uint32 range for sections should be sufficient for very long images |
| 160 | nextDownloadSectionsAbsolute uint32 //number of next section to download in overall image |
| 161 | nextDownloadSectionsWindow uint8 //number of next section to download within current window |
| 162 | noOfWindows uint32 //uint32 range for windows should be sufficient for very long images |
| 163 | nextDownloadWindow uint32 //number of next window to download |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 164 | InactiveImageMeID uint16 //ME-ID of the inactive image |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 165 | downloadToOnuTimeout4MB time.Duration //timeout for downloading the image to the ONU for a 4MB image slice |
| 166 | omciSectionInterleaveDelay time.Duration //DownloadSectionInterleave delay in milliseconds |
| 167 | delayEndSwDl bool //flag to provide a delay between last section and EndSwDl |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 168 | repeatAbort bool //flag to indicate if OMCI EndSwDownload (abort) is to be repeated |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 169 | pLastTxMeInstance *me.ManagedEntity |
| 170 | waitCountEndSwDl uint8 //number, how often is waited for EndSwDl at maximum |
| 171 | waitDelayEndSwDl time.Duration //duration, how long is waited before next request on EndSwDl |
| 172 | chReceiveExpectedResponse chan bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 173 | useAPIVersion43 bool //flag for indication on which API version is used (and accordingly which specific methods) |
| 174 | mutexUpgradeParams sync.RWMutex //mutex to protect members for parallel function requests and omci response processing |
| 175 | imageVersion string //name of the image as used within OMCI (and on extrenal API interface) |
| 176 | imageIdentifier string //name of the image as used in the adapter |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 177 | mutexIsAwaitingAdapterDlResponse sync.RWMutex |
| 178 | chAdapterDlReady chan bool |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 179 | chAbortDelayEndSwDl chan struct{} |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 180 | isWaitingForAdapterDlResponse bool |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 181 | chOnuDlReady chan bool |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 182 | activateImage bool |
| 183 | commitImage bool |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 184 | mutexAbortRequest sync.RWMutex |
| 185 | abortRequested voltha.ImageState_ImageFailureReason |
| 186 | conditionalCancelRequested bool |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 187 | upgradePhase tUpgradePhase |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 188 | volthaDownloadState voltha.ImageState_ImageDownloadState |
| 189 | volthaDownloadReason voltha.ImageState_ImageFailureReason |
| 190 | volthaImageState voltha.ImageState_ImageActivationState |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 191 | isEndSwDlOpen bool |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 192 | chReceiveAbortEndSwDlResponse chan tEndSwDlResponseResult |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 193 | isExtendedOmci bool |
| 194 | omciDownloadSectionSize int64 |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 197 | // NewOnuUpgradeFsm is the 'constructor' for the state machine to config the PON ANI ports |
| 198 | // |
| 199 | // of ONU UNI ports via OMCI |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 200 | func NewOnuUpgradeFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler, |
| 201 | apDevEntry cmn.IonuDeviceEntry, apOnuDB *devdb.OnuDeviceDB, |
| 202 | aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message) *OnuUpgradeFsm { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 203 | instFsm := &OnuUpgradeFsm{ |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 204 | pDeviceHandler: apDeviceHandler, |
| 205 | deviceID: apDeviceHandler.GetDeviceID(), |
| 206 | pDevEntry: apDevEntry, |
| 207 | pOmciCC: apDevEntry.GetDevOmciCC(), |
| 208 | pOnuDB: apOnuDB, |
| 209 | requestEvent: aRequestEvent, |
| 210 | omciSectionInterleaveDelay: cOmciSectionInterleaveMilliseconds, |
| 211 | downloadToOnuTimeout4MB: apDeviceHandler.GetDlToOnuTimeout4M(), |
| 212 | waitCountEndSwDl: cWaitCountEndSwDl, |
| 213 | waitDelayEndSwDl: cWaitDelayEndSwDlSeconds, |
| 214 | upgradePhase: cUpgradeUndefined, |
| 215 | volthaDownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 216 | volthaDownloadReason: voltha.ImageState_NO_ERROR, |
| 217 | volthaImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 218 | abortRequested: voltha.ImageState_NO_ERROR, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 219 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 220 | instFsm.chReceiveExpectedResponse = make(chan bool) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 221 | instFsm.chAdapterDlReady = make(chan bool) |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 222 | instFsm.chAbortDelayEndSwDl = make(chan struct{}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 223 | instFsm.chOnuDlReady = make(chan bool) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 224 | instFsm.chReceiveAbortEndSwDlResponse = make(chan tEndSwDlResponseResult) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 225 | |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 226 | instFsm.isExtendedOmci = instFsm.pDevEntry.GetPersIsExtOmciSupported() |
| 227 | if instFsm.isExtendedOmci { |
| 228 | instFsm.omciDownloadSectionSize = cOmciDownloadSectionSizeExtLine |
| 229 | instFsm.omciDownloadWindowSizeLimit = cOmciDownloadWindowSizeLimitExtLine |
| 230 | } else { |
| 231 | instFsm.omciDownloadSectionSize = cOmciDownloadSectionSizeBaseLine |
| 232 | instFsm.omciDownloadWindowSizeLimit = cOmciDownloadWindowSizeLimitBaseLine |
| 233 | } |
| 234 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 235 | instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
| 236 | if instFsm.PAdaptFsm == nil { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 237 | logger.Errorw(ctx, "OnuUpgradeFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
| 238 | "device-id": instFsm.deviceID}) |
| 239 | return nil |
| 240 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 241 | instFsm.PAdaptFsm.PFsm = fsm.NewFSM( |
| 242 | UpgradeStDisabled, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 243 | fsm.Events{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 244 | {Name: UpgradeEvStart, Src: []string{UpgradeStDisabled}, Dst: UpgradeStStarting}, |
| 245 | {Name: UpgradeEvAdapterDownload, Src: []string{UpgradeStStarting}, Dst: UpgradeStWaitingAdapterDL}, |
| 246 | {Name: UpgradeEvPrepareSwDownload, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL}, Dst: UpgradeStPreparingDL}, |
| 247 | {Name: UpgradeEvRxStartSwDownload, Src: []string{UpgradeStPreparingDL}, Dst: UpgradeStDLSection}, |
| 248 | {Name: UpgradeEvWaitWindowAck, Src: []string{UpgradeStDLSection}, Dst: UpgradeStVerifyWindow}, |
| 249 | {Name: UpgradeEvContinueNextWindow, Src: []string{UpgradeStVerifyWindow}, Dst: UpgradeStDLSection}, |
| 250 | {Name: UpgradeEvEndSwDownload, Src: []string{UpgradeStVerifyWindow}, Dst: UpgradeStFinalizeDL}, |
| 251 | {Name: UpgradeEvWaitEndDownload, Src: []string{UpgradeStFinalizeDL}, Dst: UpgradeStWaitEndDL}, |
| 252 | {Name: UpgradeEvContinueFinalize, Src: []string{UpgradeStWaitEndDL}, Dst: UpgradeStFinalizeDL}, |
| 253 | //UpgradeStCheckImageName only used with useAPIVersion43 |
| 254 | {Name: UpgradeEvCheckImageName, Src: []string{UpgradeStWaitEndDL}, Dst: UpgradeStCheckImageName}, |
| 255 | //UpgradeEvWaitForActivate state transitions depend on useAPIVersion43 |
| 256 | {Name: UpgradeEvWaitForActivate, Src: []string{UpgradeStWaitEndDL, UpgradeStCheckImageName}, Dst: UpgradeStWaitForActivate}, |
| 257 | //UpgradeEvRequestActivate state transitions depend on useAPIVersion43 |
| 258 | {Name: UpgradeEvRequestActivate, Src: []string{UpgradeStStarting, UpgradeStWaitEndDL, UpgradeStCheckImageName, |
| 259 | UpgradeStWaitForActivate}, Dst: UpgradeStRequestingActivate}, //allows also for direct activation (without download) [TODO!!!] |
| 260 | {Name: UpgradeEvActivationDone, Src: []string{UpgradeStRequestingActivate}, Dst: UpgradeStActivated}, |
| 261 | {Name: UpgradeEvWaitForCommit, Src: []string{UpgradeStRequestingActivate}, Dst: UpgradeStWaitForCommit}, |
| 262 | {Name: UpgradeEvCommitSw, Src: []string{UpgradeStStarting, UpgradeStRequestingActivate, UpgradeStWaitForCommit, |
| 263 | UpgradeStActivated}, Dst: UpgradeStCommitSw}, //allows also for direct commitment (without download) [TODO!!!] |
| 264 | {Name: UpgradeEvCheckCommitted, Src: []string{UpgradeStCommitSw}, Dst: UpgradeStCheckCommitted}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 265 | |
| 266 | /* |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 267 | {Name: UpgradeEvTimeoutSimple, Src: []string{ |
| 268 | UpgradeStCreatingDot1PMapper, UpgradeStCreatingMBPCD, UpgradeStSettingTconts, UpgradeStSettingDot1PMapper}, Dst: UpgradeStStarting}, |
| 269 | {Name: UpgradeEvTimeoutMids, Src: []string{ |
| 270 | UpgradeStCreatingGemNCTPs, UpgradeStCreatingGemIWs, UpgradeStSettingPQs}, Dst: UpgradeStStarting}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 271 | */ |
| 272 | // exceptional treatments |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 273 | //on UpgradeEvReset: UpgradeStRequestingActivate, UpgradeStWaitForCommit and UpgradeStActivated are not reset |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 274 | // (to let the FSM survive the expected OnuDown indication) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 275 | {Name: UpgradeEvReset, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL, UpgradeStPreparingDL, UpgradeStDLSection, |
| 276 | UpgradeStVerifyWindow, UpgradeStDLSection, UpgradeStFinalizeDL, UpgradeStWaitEndDL, UpgradeStCheckImageName, |
| 277 | UpgradeStWaitForActivate, |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 278 | UpgradeStCommitSw, UpgradeStCheckCommitted, UpgradeStAbortingDL}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 279 | Dst: UpgradeStResetting}, |
| 280 | {Name: UpgradeEvAbort, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL, UpgradeStPreparingDL, UpgradeStDLSection, |
| 281 | UpgradeStVerifyWindow, UpgradeStDLSection, UpgradeStFinalizeDL, UpgradeStWaitEndDL, UpgradeStCheckImageName, |
| 282 | UpgradeStWaitForActivate, |
| 283 | UpgradeStRequestingActivate, UpgradeStActivated, UpgradeStWaitForCommit, |
| 284 | UpgradeStCommitSw, UpgradeStCheckCommitted}, |
| 285 | Dst: UpgradeStResetting}, |
| 286 | {Name: UpgradeEvAbortSwDownload, Src: []string{UpgradeStResetting}, Dst: UpgradeStAbortingDL}, |
| 287 | {Name: UpgradeEvRestart, Src: []string{UpgradeStResetting, UpgradeStAbortingDL}, Dst: UpgradeStRestarting}, |
| 288 | {Name: UpgradeEvDisable, Src: []string{UpgradeStRestarting}, Dst: UpgradeStDisabled}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 289 | }, |
| 290 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 291 | "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) }, |
| 292 | "enter_" + UpgradeStStarting: func(e *fsm.Event) { instFsm.enterStarting(ctx, e) }, |
| 293 | "enter_" + UpgradeStWaitingAdapterDL: func(e *fsm.Event) { instFsm.enterWaitingAdapterDL(ctx, e) }, |
| 294 | "enter_" + UpgradeStPreparingDL: func(e *fsm.Event) { instFsm.enterPreparingDL(ctx, e) }, |
| 295 | "enter_" + UpgradeStDLSection: func(e *fsm.Event) { instFsm.enterDownloadSection(ctx, e) }, |
| 296 | "enter_" + UpgradeStVerifyWindow: func(e *fsm.Event) { instFsm.enterVerifyWindow(ctx, e) }, |
| 297 | "enter_" + UpgradeStFinalizeDL: func(e *fsm.Event) { instFsm.enterFinalizeDL(ctx, e) }, |
| 298 | "enter_" + UpgradeStWaitEndDL: func(e *fsm.Event) { instFsm.enterWaitEndDL(ctx, e) }, |
| 299 | "enter_" + UpgradeStCheckImageName: func(e *fsm.Event) { instFsm.enterCheckImageName(ctx, e) }, |
| 300 | "enter_" + UpgradeStRequestingActivate: func(e *fsm.Event) { instFsm.enterActivateSw(ctx, e) }, |
| 301 | "enter_" + UpgradeStCommitSw: func(e *fsm.Event) { instFsm.enterCommitSw(ctx, e) }, |
| 302 | "enter_" + UpgradeStCheckCommitted: func(e *fsm.Event) { instFsm.enterCheckCommitted(ctx, e) }, |
| 303 | "enter_" + UpgradeStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) }, |
| 304 | "enter_" + UpgradeStAbortingDL: func(e *fsm.Event) { instFsm.enterAbortingDL(ctx, e) }, |
| 305 | "enter_" + UpgradeStRestarting: func(e *fsm.Event) { instFsm.enterRestarting(ctx, e) }, |
| 306 | "enter_" + UpgradeStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) }, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 307 | }, |
| 308 | ) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 309 | if instFsm.PAdaptFsm.PFsm == nil { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 310 | logger.Errorw(ctx, "OnuUpgradeFsm's Base FSM could not be instantiated!!", log.Fields{ |
| 311 | "device-id": instFsm.deviceID}) |
| 312 | return nil |
| 313 | } |
| 314 | |
| 315 | logger.Debugw(ctx, "OnuUpgradeFsm created", log.Fields{"device-id": instFsm.deviceID}) |
| 316 | return instFsm |
| 317 | } |
| 318 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 319 | // SetDownloadParams configures the needed parameters for a specific download to the ONU |
| 320 | // |
| 321 | // called from 'old' API Activate_image_update() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 322 | func (oFsm *OnuUpgradeFsm) SetDownloadParams(ctx context.Context, aInactiveImageID uint16, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 323 | apImageDsc *voltha.ImageDownload, apDownloadManager *AdapterDownloadManager) error { |
| 324 | pBaseFsm := oFsm.PAdaptFsm.PFsm |
| 325 | if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 326 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 327 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{ |
| 328 | "device-id": oFsm.deviceID, "image-description": apImageDsc}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 329 | oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 330 | oFsm.pImageDsc = apImageDsc |
| 331 | oFsm.pDownloadManager = apDownloadManager |
Holger Hildebrandt | ac1e059 | 2021-06-03 15:16:49 +0000 | [diff] [blame] | 332 | oFsm.activateImage = true |
| 333 | oFsm.commitImage = true |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 334 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 335 | |
| 336 | go func(aPBaseFsm *fsm.FSM) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 337 | // let the upgrade FSM proceed to PreparingDL |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 338 | _ = aPBaseFsm.Event(UpgradeEvPrepareSwDownload) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 339 | }(pBaseFsm) |
| 340 | return nil |
| 341 | } |
| 342 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 343 | "device-id": oFsm.deviceID}) |
| 344 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 345 | } |
| 346 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 347 | // SetDownloadParamsAfterDownload configures the needed parameters for a specific download to the ONU according to |
| 348 | // |
| 349 | // updated API interface with R2.8: start download to ONU if the image is downloaded to the adapter |
| 350 | // called from 'new' API Download_onu_image |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 351 | func (oFsm *OnuUpgradeFsm) SetDownloadParamsAfterDownload(ctx context.Context, aInactiveImageID uint16, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 352 | apImageRequest *voltha.DeviceImageDownloadRequest, apDownloadManager *FileDownloadManager, |
Holger Hildebrandt | ac01073 | 2021-06-02 13:35:39 +0000 | [diff] [blame] | 353 | aImageIdentifier string) error { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 354 | oFsm.mutexUpgradeParams.Lock() |
| 355 | var pBaseFsm *fsm.FSM = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 356 | if oFsm.PAdaptFsm != nil { |
| 357 | pBaseFsm = oFsm.PAdaptFsm.PFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 358 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 359 | if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 360 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{ |
| 361 | "device-id": oFsm.deviceID, "image-description": apImageRequest}) |
| 362 | oFsm.useAPIVersion43 = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 363 | oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 364 | oFsm.pFileManager = apDownloadManager |
| 365 | oFsm.imageIdentifier = aImageIdentifier |
| 366 | oFsm.imageVersion = apImageRequest.Image.Version |
| 367 | oFsm.activateImage = apImageRequest.ActivateOnSuccess |
| 368 | oFsm.commitImage = apImageRequest.CommitOnSuccess |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 369 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_STARTED //state change indication for download request |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 370 | oFsm.mutexUpgradeParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 371 | _ = pBaseFsm.Event(UpgradeEvAdapterDownload) //no need to call the FSM event in background here |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 372 | return nil |
| 373 | } |
| 374 | oFsm.mutexUpgradeParams.Unlock() |
| 375 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 376 | "device-id": oFsm.deviceID}) |
| 377 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 378 | } |
| 379 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 380 | // SetActivationParamsRunning sets the activate and commit flags for a running download to the ONU according to adapters rpc call |
| 381 | // |
| 382 | // called from 'new' API Activate_onu_image |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 383 | func (oFsm *OnuUpgradeFsm) SetActivationParamsRunning(ctx context.Context, |
| 384 | aImageIdentifier string, aCommit bool) error { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 385 | logger.Debugw(ctx, "OnuUpgradeFsm activate/commit parameter setting", log.Fields{ |
| 386 | "device-id": oFsm.deviceID, "image-id": aImageIdentifier, "commit": aCommit}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 387 | oFsm.mutexUpgradeParams.Lock() |
| 388 | //set activate/commit independent from state, if FSM is already beyond concerned states, then it does not matter anyway |
| 389 | // (as long as the Imageidentifier is correct) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 390 | if aImageIdentifier != oFsm.imageIdentifier { |
| 391 | logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{ |
| 392 | "device-id": oFsm.deviceID, "request-image": aImageIdentifier, "fsm-image": oFsm.imageIdentifier}) |
| 393 | oFsm.mutexUpgradeParams.Unlock() |
| 394 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s", |
| 395 | oFsm.deviceID)) |
| 396 | } |
| 397 | oFsm.activateImage = true |
| 398 | oFsm.commitImage = aCommit |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 399 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 400 | var pBaseFsm *fsm.FSM = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 401 | if oFsm.PAdaptFsm != nil { |
| 402 | pBaseFsm = oFsm.PAdaptFsm.PFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 403 | } |
| 404 | if pBaseFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 405 | if pBaseFsm.Is(UpgradeStWaitForActivate) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 406 | logger.Debugw(ctx, "OnuUpgradeFsm finish waiting for activate", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 407 | _ = pBaseFsm.Event(UpgradeEvRequestActivate) //no need to call the FSM event in background here |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 408 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 409 | logger.Debugw(ctx, "OnuUpgradeFsm not (yet?) waiting for activate", log.Fields{ |
| 410 | "device-id": oFsm.deviceID, "current FsmState": pBaseFsm.Current()}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 411 | } |
| 412 | return nil |
| 413 | } |
| 414 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{ |
| 415 | "device-id": oFsm.deviceID}) |
| 416 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID)) |
| 417 | } |
| 418 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 419 | // SetActivationParamsStart starts upgrade processing with immediate activation |
| 420 | // |
| 421 | // called from 'new' API Activate_onu_image |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 422 | func (oFsm *OnuUpgradeFsm) SetActivationParamsStart(ctx context.Context, aImageVersion string, aInactiveImageID uint16, aCommit bool) error { |
| 423 | oFsm.mutexUpgradeParams.Lock() |
| 424 | var pBaseFsm *fsm.FSM = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 425 | if oFsm.PAdaptFsm != nil { |
| 426 | pBaseFsm = oFsm.PAdaptFsm.PFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 427 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 428 | if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 429 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with activation", log.Fields{ |
| 430 | "device-id": oFsm.deviceID, "image-version": aImageVersion}) |
| 431 | oFsm.useAPIVersion43 = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 432 | oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 433 | oFsm.imageVersion = aImageVersion |
| 434 | oFsm.activateImage = true |
| 435 | oFsm.commitImage = aCommit |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 436 | // indicate start of the upgrade activity |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 437 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATING //state change indication for activate request |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 438 | oFsm.mutexUpgradeParams.Unlock() |
| 439 | //directly request the FSM to activate the image |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 440 | _ = pBaseFsm.Event(UpgradeEvRequestActivate) //no need to call the FSM event in background here |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 441 | return nil |
| 442 | } |
| 443 | oFsm.mutexUpgradeParams.Unlock() |
| 444 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 445 | "device-id": oFsm.deviceID}) |
| 446 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 447 | } |
| 448 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 449 | // SetCommitmentParamsRunning sets the commit flag for a running download to the ONU according to adapters rpc call |
| 450 | // |
| 451 | // called from 'new' API Commit_onu_image |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 452 | func (oFsm *OnuUpgradeFsm) SetCommitmentParamsRunning(ctx context.Context, |
| 453 | aImageIdentifier string, aImageVersion string) error { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 454 | oFsm.mutexUpgradeParams.Lock() |
| 455 | //set commit independent from state, if FSM is already beyond commit state (just ready), then it does not matter anyway |
| 456 | // (as long as the Imageidentifier is correct) |
| 457 | logger.Debugw(ctx, "OnuUpgradeFsm commit parameter setting", log.Fields{ |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 458 | "device-id": oFsm.deviceID, "image-id": aImageIdentifier, "image-version": aImageVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 459 | if (aImageIdentifier != oFsm.imageIdentifier) && (aImageVersion != oFsm.imageVersion) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 460 | logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{ |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 461 | "device-id": oFsm.deviceID, "request-identifier": aImageIdentifier, "fsm-identifier": oFsm.imageIdentifier, |
| 462 | "request-version": aImageVersion, "fsm-version": oFsm.imageVersion}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 463 | oFsm.mutexUpgradeParams.Unlock() |
| 464 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s", |
| 465 | oFsm.deviceID)) |
| 466 | } |
| 467 | oFsm.commitImage = true |
| 468 | oFsm.mutexUpgradeParams.Unlock() |
| 469 | var pBaseFsm *fsm.FSM = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 470 | if oFsm.PAdaptFsm != nil { |
| 471 | pBaseFsm = oFsm.PAdaptFsm.PFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 472 | } |
| 473 | if pBaseFsm != nil { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 474 | //let the FSM decide if it is ready to process the event |
| 475 | logger.Debugw(ctx, "OnuUpgradeFsm requesting commit", |
| 476 | log.Fields{"device-id": oFsm.deviceID, "current FsmState": pBaseFsm.Current()}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 477 | _ = pBaseFsm.Event(UpgradeEvCommitSw) //no need to call the FSM event in background here |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 478 | return nil |
| 479 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 480 | //should never occur |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 481 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{ |
| 482 | "device-id": oFsm.deviceID}) |
| 483 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID)) |
| 484 | } |
| 485 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 486 | // SetCommitmentParamsStart starts upgrade processing with immediate commitment |
| 487 | // |
| 488 | // called from 'new' API Commit_onu_image |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 489 | func (oFsm *OnuUpgradeFsm) SetCommitmentParamsStart(ctx context.Context, aImageVersion string, aActiveImageID uint16) error { |
| 490 | oFsm.mutexUpgradeParams.Lock() |
| 491 | var pBaseFsm *fsm.FSM = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 492 | if oFsm.PAdaptFsm != nil { |
| 493 | pBaseFsm = oFsm.PAdaptFsm.PFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 494 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 495 | if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 496 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with commitment", log.Fields{ |
| 497 | "device-id": oFsm.deviceID, "image-version": aImageVersion}) |
| 498 | oFsm.useAPIVersion43 = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 499 | oFsm.InactiveImageMeID = aActiveImageID //upgrade state machines inactive ImageId is the new active ImageId |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 500 | oFsm.imageVersion = aImageVersion |
| 501 | oFsm.commitImage = true |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 502 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTING //state change indication for activate request |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 503 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 504 | //directly request the FSM to commit the image |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 505 | _ = pBaseFsm.Event(UpgradeEvCommitSw) //no need to call the FSM event in background here |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 506 | return nil |
| 507 | } |
| 508 | oFsm.mutexUpgradeParams.Unlock() |
| 509 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 510 | "device-id": oFsm.deviceID}) |
| 511 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 512 | } |
| 513 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 514 | // GetCommitFlag delivers the commit flag that was configured here |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 515 | func (oFsm *OnuUpgradeFsm) GetCommitFlag(ctx context.Context) bool { |
| 516 | oFsm.mutexUpgradeParams.RLock() |
| 517 | defer oFsm.mutexUpgradeParams.RUnlock() |
| 518 | return oFsm.commitImage |
| 519 | } |
| 520 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 521 | // GetImageStates delivers the download/image states as per device proto buf definition |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 522 | func (oFsm *OnuUpgradeFsm) GetImageStates(ctx context.Context, |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 523 | aImageIdentifier string, aVersion string) *voltha.ImageState { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 524 | pImageState := &voltha.ImageState{} |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 525 | pImageState.Version = aVersion //version as requested |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 526 | // check if the request refers to some active image/version of the processing |
| 527 | oFsm.mutexUpgradeParams.RLock() |
| 528 | if (aImageIdentifier == oFsm.imageIdentifier) || (aVersion == oFsm.imageVersion) { |
| 529 | pImageState.DownloadState = oFsm.volthaDownloadState |
| 530 | pImageState.Reason = oFsm.volthaDownloadReason |
| 531 | pImageState.ImageState = oFsm.volthaImageState |
| 532 | } else { |
| 533 | pImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 534 | pImageState.Reason = voltha.ImageState_NO_ERROR |
| 535 | pImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 536 | } |
| 537 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 538 | return pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 541 | // SetImageStateActive sets the FSM internal volthaImageState to ImageState_IMAGE_ACTIVE |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 542 | func (oFsm *OnuUpgradeFsm) SetImageStateActive(ctx context.Context) { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 543 | oFsm.mutexUpgradeParams.Lock() |
| 544 | defer oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 545 | oFsm.upgradePhase = cUpgradeActivated |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 546 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVE |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 549 | // CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 550 | func (oFsm *OnuUpgradeFsm) CancelProcessing(ctx context.Context, abCompleteAbort bool, |
| 551 | aReason voltha.ImageState_ImageFailureReason) { |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 552 | pAdaptFsm := oFsm.PAdaptFsm |
Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 553 | logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 554 | if pAdaptFsm == nil || pAdaptFsm.PFsm == nil { |
| 555 | logger.Warnw(ctx, "OnuUpgradeFsm cancel, but FSM invalid", log.Fields{ |
| 556 | "device-id": oFsm.deviceID}) |
| 557 | return |
| 558 | } |
| 559 | logger.Debugw(ctx, "OnuUpgradeFsm start canceling", log.Fields{ |
| 560 | "device-id": oFsm.deviceID, "in fsm-state": pAdaptFsm.PFsm.Current()}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 561 | oFsm.mutexAbortRequest.Lock() |
| 562 | oFsm.abortRequested = aReason //possibly abort the sectionDownload loop |
| 563 | oFsm.mutexAbortRequest.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 564 | //mutex protection is required for possible concurrent access to FSM members |
| 565 | //attention: for an unbuffered channel the sender is blocked until the value is received (processed)! |
| 566 | // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver) |
| 567 | oFsm.mutexIsAwaitingAdapterDlResponse.RLock() |
| 568 | if oFsm.isWaitingForAdapterDlResponse { |
| 569 | oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock() |
| 570 | //use channel to indicate that the download response waiting shall be aborted for this device (channel) |
| 571 | oFsm.chAdapterDlReady <- false |
| 572 | } else { |
| 573 | oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock() |
| 574 | } |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 575 | |
| 576 | //abort a possible delaying of sending EndSwDl |
| 577 | //use asynchronous channel sending to avoid blocking here in case no receiver is waiting |
| 578 | select { |
| 579 | case oFsm.chAbortDelayEndSwDl <- struct{}{}: |
| 580 | default: |
| 581 | } |
| 582 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 583 | //chOnuDlReady is cleared as part of the FSM reset processing (from enterResetting()) |
| 584 | |
| 585 | // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 586 | // specific here: See definition of state changes: some states are excluded from reset for possible later commit |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 587 | pAdaptFsm = oFsm.PAdaptFsm |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 588 | if pAdaptFsm != nil && pAdaptFsm.PFsm != nil { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 589 | // calling FSM events in background to avoid blocking of the caller |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 590 | go func(apFsm *fsm.FSM) { |
| 591 | if apFsm.Is(UpgradeStWaitEndDL) { |
| 592 | oFsm.chReceiveExpectedResponse <- false //which aborts the FSM in WaitEndDL state |
| 593 | } else if apFsm.Is(UpgradeStAbortingDL) { |
| 594 | oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseAbort //abort waiting on EndDownloadResponse |
| 595 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 596 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 597 | var err error |
| 598 | if abCompleteAbort { |
| 599 | // in case of unconditional abort request the ImageState is set immediately |
| 600 | oFsm.mutexUpgradeParams.Lock() |
| 601 | //any previous lingering conditional cancelRequest is superseded by this abortion |
| 602 | oFsm.conditionalCancelRequested = false |
| 603 | oFsm.volthaDownloadReason = aReason |
| 604 | oFsm.mutexUpgradeParams.Unlock() |
| 605 | err = apFsm.Event(UpgradeEvAbort) //as unconditional default FSM cancellation |
| 606 | } else { |
| 607 | //at conditional abort request the image states are set when reaching the reset state |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 608 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 609 | oFsm.conditionalCancelRequested = true |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 610 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 611 | err = apFsm.Event(UpgradeEvReset) //as state-conditional default FSM cleanup |
| 612 | } |
| 613 | if err != nil { |
| 614 | //error return is expected in case of conditional request and no state transition |
| 615 | logger.Debugw(ctx, "onu upgrade fsm could not cancel with abort/reset event", log.Fields{ |
| 616 | "device-id": oFsm.deviceID, "error": err}) |
| 617 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 618 | logger.Debugw(ctx, "OnuUpgradeFsm canceling done", log.Fields{ |
| 619 | "device-id": oFsm.deviceID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 620 | }(pAdaptFsm.PFsm) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 621 | } else { //the FSM seems already to be in some released state |
| 622 | logger.Warnw(ctx, "OnuUpgradeFsm canceling without FSM event", log.Fields{ |
| 623 | "device-id": oFsm.deviceID}) |
| 624 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 625 | } |
| 626 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 627 | func (oFsm *OnuUpgradeFsm) enterStarting(ctx context.Context, e *fsm.Event) { |
| 628 | logger.Debugw(ctx, "OnuUpgradeFsm start", log.Fields{"in state": e.FSM.Current(), |
| 629 | "device-id": oFsm.deviceID}) |
| 630 | |
| 631 | // start go routine for processing of LockState messages |
| 632 | go oFsm.processOmciUpgradeMessages(ctx) |
| 633 | } |
| 634 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 635 | // enterWaitingAdapterDL state can only be reached with useAPIVersion43 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 636 | func (oFsm *OnuUpgradeFsm) enterWaitingAdapterDL(ctx context.Context, e *fsm.Event) { |
| 637 | logger.Debugw(ctx, "OnuUpgradeFsm waiting for adapter download", log.Fields{"in state": e.FSM.Current(), |
| 638 | "device-id": oFsm.deviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 639 | syncChannel := make(chan struct{}) |
| 640 | go oFsm.waitOnDownloadToAdapterReady(ctx, syncChannel, oFsm.chAdapterDlReady) |
| 641 | //block until the wait routine is really blocked on chAdapterDlReady |
| 642 | <-syncChannel |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 643 | go oFsm.pFileManager.RequestDownloadReady(ctx, oFsm.imageIdentifier, oFsm.chAdapterDlReady) |
| 644 | } |
| 645 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 646 | func (oFsm *OnuUpgradeFsm) enterPreparingDL(ctx context.Context, e *fsm.Event) { |
| 647 | logger.Debugw(ctx, "OnuUpgradeFsm prepare Download to Onu", log.Fields{"in state": e.FSM.Current(), |
| 648 | "device-id": oFsm.deviceID}) |
| 649 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 650 | var fileLen int64 |
| 651 | var err error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 652 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 653 | if oFsm.useAPIVersion43 { |
| 654 | //with the new API structure download to adapter is implicit and we have to wait until the image is available |
| 655 | fileLen, err = oFsm.pFileManager.GetImageBufferLen(ctx, oFsm.imageIdentifier) |
| 656 | } else { |
| 657 | fileLen, err = oFsm.pDownloadManager.getImageBufferLen(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir) |
| 658 | } |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 659 | if err != nil || fileLen == 0 || fileLen > int64(cMaxUint32) { |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 660 | oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 661 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 662 | logger.Errorw(ctx, "OnuUpgradeFsm abort: problems getting image buffer length", log.Fields{ |
| 663 | "device-id": oFsm.deviceID, "error": err, "length": fileLen}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 664 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 665 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 666 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 667 | _ = a_pAFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 668 | }(pBaseFsm) |
| 669 | return |
| 670 | } |
| 671 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 672 | //copy file content to buffer |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 673 | var imageBuffer []byte |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 674 | if oFsm.useAPIVersion43 { |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 675 | imageBuffer, err = oFsm.pFileManager.GetDownloadImageBuffer(ctx, oFsm.imageIdentifier) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 676 | } else { |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 677 | imageBuffer, err = oFsm.pDownloadManager.getDownloadImageBuffer(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 678 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 679 | if err != nil { |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 680 | oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 681 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 682 | logger.Errorw(ctx, "OnuUpgradeFsm abort: can't get image buffer", log.Fields{ |
| 683 | "device-id": oFsm.deviceID, "error": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 684 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 685 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 686 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 687 | _ = a_pAFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 688 | }(pBaseFsm) |
| 689 | return |
| 690 | } |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 691 | //provide slice capacity already with the reserve of one section to avoid inflation of the slice to double size at append |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 692 | oFsm.imageBuffer = make([]byte, fileLen, fileLen+oFsm.omciDownloadSectionSize) |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 693 | //better use a copy of the read image buffer in case the buffer/file is modified from outside, |
| 694 | // this also limits the slice len to the expected maximum fileLen |
| 695 | copy(oFsm.imageBuffer, imageBuffer) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 696 | |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 697 | oFsm.noOfSections = uint32(fileLen / oFsm.omciDownloadSectionSize) |
| 698 | if fileLen%oFsm.omciDownloadSectionSize > 0 { |
| 699 | // Because the extended message format allows for variable length, |
| 700 | // software image sections are only padded in baseline message format |
| 701 | if !oFsm.isExtendedOmci { |
| 702 | bufferPadding := make([]byte, oFsm.omciDownloadSectionSize-fileLen%oFsm.omciDownloadSectionSize) |
| 703 | //expand the imageBuffer to exactly fit multiples of cOmciDownloadSectionSize with padding |
| 704 | oFsm.imageBuffer = append(oFsm.imageBuffer, bufferPadding...) |
| 705 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 706 | oFsm.noOfSections++ |
| 707 | } |
| 708 | oFsm.origImageLength = uint32(fileLen) |
| 709 | oFsm.imageLength = uint32(len(oFsm.imageBuffer)) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 710 | logger.Infow(ctx, "OnuUpgradeFsm starts with StartSwDl values", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 711 | "MeId": oFsm.InactiveImageMeID, "windowSizeLimit": oFsm.omciDownloadWindowSizeLimit, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 712 | "ImageSize": oFsm.imageLength, "original file size": fileLen}) |
| 713 | //"NumberOfCircuitPacks": oFsm.numberCircuitPacks, "CircuitPacks MeId": 0}) //parallel circuit packs download not supported |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 714 | |
| 715 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 716 | |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 717 | // flush chOnuDlReady |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 718 | select { |
| 719 | case <-oFsm.chOnuDlReady: |
| 720 | logger.Debug(ctx, "flushed OnuDlReady channel") |
| 721 | default: |
| 722 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 723 | go oFsm.waitOnDownloadToOnuReady(ctx, oFsm.chOnuDlReady) // start supervision of the complete download-to-ONU procedure |
| 724 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 725 | err = oFsm.pOmciCC.SendStartSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false, |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 726 | oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, oFsm.omciDownloadWindowSizeLimit, oFsm.origImageLength, oFsm.isExtendedOmci) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 727 | if err != nil { |
| 728 | logger.Errorw(ctx, "StartSwDl abort: can't send section", log.Fields{ |
| 729 | "device-id": oFsm.deviceID, "error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 730 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 731 | return |
| 732 | } |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 733 | oFsm.isEndSwDlOpen = true |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | func (oFsm *OnuUpgradeFsm) enterDownloadSection(ctx context.Context, e *fsm.Event) { |
| 737 | logger.Debugw(ctx, "OnuUpgradeFsm start downloading sections", log.Fields{ |
| 738 | "device-id": oFsm.deviceID, "absolute window": oFsm.nextDownloadWindow}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 739 | //use a background routine to send the multiple download sections frames in a loop |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 740 | // in order to avoid blocking on synchronous event calls for the entire (long) processing time |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 741 | go oFsm.runSwDlSectionWindow(ctx) |
| 742 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 743 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 744 | // runSwDlSectionWindow runs a loop to send all DlSection frames of one window in background |
| 745 | // |
| 746 | // may be aborted by parallel change of abortRequested |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 747 | func (oFsm *OnuUpgradeFsm) runSwDlSectionWindow(ctx context.Context) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 748 | var windowAckRequest uint8 = 0 |
| 749 | var bufferStartOffset uint32 |
| 750 | var bufferEndOffset uint32 |
| 751 | var downloadSection []byte |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 752 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 753 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 754 | oFsm.upgradePhase = cUpgradeDownloading //start of downloading image to ONU |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 755 | if oFsm.nextDownloadSectionsAbsolute == 0 { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 756 | oFsm.volthaImageState = voltha.ImageState_IMAGE_DOWNLOADING |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 757 | } |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 758 | //var omuTxSecPerWindow []*common.OmciTransferStructure |
| 759 | omciMsgsPerSection := &ia.OmciMessages{} |
| 760 | //take the TID mutex |
| 761 | //To ensure the insequesnce of TIDS for all the onusw sections within a window |
| 762 | oFsm.pOmciCC.LockMutexTID() |
| 763 | defer oFsm.pOmciCC.UnLockMutexTID() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 764 | for { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 765 | oFsm.mutexAbortRequest.RLock() |
| 766 | // this way out of the section download loop on abort request |
| 767 | if oFsm.abortRequested != voltha.ImageState_NO_ERROR { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 768 | //states are updated when entering the reset state ... |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 769 | oFsm.volthaDownloadReason = oFsm.abortRequested |
| 770 | oFsm.mutexAbortRequest.RUnlock() |
| 771 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 772 | pUpgradeFsm := oFsm.PAdaptFsm |
| 773 | if pUpgradeFsm != nil { |
| 774 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvAbort) |
| 775 | logger.Debugw(ctx, "aborting runSwDlSectionWindow", log.Fields{ |
| 776 | "device-id": oFsm.deviceID, "reason": oFsm.volthaDownloadReason}) |
| 777 | return |
| 778 | } |
| 779 | logger.Warnw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 780 | return |
| 781 | } |
| 782 | oFsm.mutexAbortRequest.RUnlock() |
| 783 | |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 784 | bufferStartOffset = oFsm.nextDownloadSectionsAbsolute * uint32(oFsm.omciDownloadSectionSize) |
| 785 | bufferEndOffset = bufferStartOffset + uint32(oFsm.omciDownloadSectionSize) - 1 |
| 786 | if oFsm.isExtendedOmci { |
| 787 | if bufferEndOffset > oFsm.origImageLength-1 { |
| 788 | bufferEndOffset = oFsm.origImageLength - 1 |
| 789 | } |
| 790 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 791 | logger.Debugw(ctx, "DlSection values are", log.Fields{ |
| 792 | "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute, |
| 793 | "DlSectionWindow": oFsm.nextDownloadSectionsWindow, |
| 794 | "startOffset": bufferStartOffset, "endOffset": bufferEndOffset}) |
| 795 | if bufferStartOffset+1 > oFsm.imageLength || bufferEndOffset+1 > oFsm.imageLength { //should never occur in this state |
| 796 | logger.Errorw(ctx, "OnuUpgradeFsm buffer error: exceeded length", log.Fields{ |
| 797 | "device-id": oFsm.deviceID, "bufferStartOffset": bufferStartOffset, |
| 798 | "bufferEndOffset": bufferEndOffset, "imageLength": oFsm.imageLength}) |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 799 | oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 800 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 801 | //logical error -- reset the FSM |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 802 | pUpgradeFsm := oFsm.PAdaptFsm |
| 803 | if pUpgradeFsm != nil { |
| 804 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvAbort) |
| 805 | return |
| 806 | } |
| 807 | logger.Warnw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 808 | return |
| 809 | } |
| 810 | downloadSection = oFsm.imageBuffer[bufferStartOffset : bufferEndOffset+1] |
| 811 | if oFsm.nextDownloadSectionsWindow == oFsm.omciDownloadWindowSizeLimit { |
| 812 | windowAckRequest = 1 |
| 813 | logger.Debugw(ctx, "DlSection expect Response for complete window", log.Fields{ |
| 814 | "device-id": oFsm.deviceID, "in window": oFsm.nextDownloadWindow}) |
| 815 | } |
| 816 | if oFsm.nextDownloadSectionsAbsolute+1 >= oFsm.noOfSections { |
| 817 | windowAckRequest = 1 |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 818 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 819 | oFsm.omciDownloadWindowSizeLast = oFsm.nextDownloadSectionsWindow |
| 820 | logger.Infow(ctx, "DlSection expect Response for last window (section)", log.Fields{ |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 821 | "device-id": oFsm.deviceID, "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute}) |
| 822 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 823 | oFsm.mutexUpgradeParams.Unlock() //unlock here to give other functions some chance to process during/after the send request |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 824 | omciTxReq, err := oFsm.pOmciCC.PrepareOnuSectionsOfWindow(log.WithSpanFromContext(context.Background(), ctx), |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 825 | oFsm.InactiveImageMeID, windowAckRequest, oFsm.nextDownloadSectionsWindow, downloadSection, omciMsgsPerSection, oFsm.isExtendedOmci) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 826 | if err != nil { |
| 827 | logger.Errorw(ctx, "DlSection abort: can't send section", log.Fields{ |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 828 | "device-id": oFsm.deviceID, "section absolute": oFsm.nextDownloadSectionsAbsolute, "error": err}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 829 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 830 | return |
| 831 | } |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 832 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 833 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 834 | oFsm.nextDownloadSectionsAbsolute++ //always increase the absolute section counter after having sent one |
| 835 | if windowAckRequest == 1 { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 836 | oFsm.mutexUpgradeParams.Unlock() |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 837 | |
| 838 | if omciTxReq.OnuSwWindow == nil { |
| 839 | logger.Errorw(ctx, "fail to send sections in a window", log.Fields{ |
| 840 | "device-id": oFsm.deviceID, "section absolute": oFsm.nextDownloadSectionsAbsolute, "error": err}) |
| 841 | oFsm.abortOnOmciError(ctx, false) |
| 842 | return |
| 843 | } |
| 844 | |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 845 | pUpgradeFsm := oFsm.PAdaptFsm |
| 846 | if pUpgradeFsm != nil { |
| 847 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvWaitWindowAck) //state transition to upgradeStVerifyWindow |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 848 | oFsm.pOmciCC.SendOnuSwSectionsWindowWithRxSupervision(ctx, omciTxReq, oFsm.pDeviceHandler.GetOmciTimeout(), oFsm.PAdaptFsm.CommChan) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 849 | return |
| 850 | } |
| 851 | logger.Warnw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 852 | return |
| 853 | } |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 854 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 855 | oFsm.nextDownloadSectionsWindow++ //increase the window related section counter only if not in the last section |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 856 | if oFsm.omciSectionInterleaveDelay > 0 { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 857 | //ensure a defined intersection-time-gap to leave space for further processing, other ONU's ... |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 858 | oFsm.mutexUpgradeParams.Unlock() //unlock here to give other functions some chance to process during/after the send request |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 859 | time.Sleep(oFsm.omciSectionInterleaveDelay * time.Millisecond) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 860 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 861 | } |
| 862 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 863 | } //runSwDlSectionWindow |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 864 | |
| 865 | func (oFsm *OnuUpgradeFsm) enterVerifyWindow(ctx context.Context, e *fsm.Event) { |
| 866 | logger.Debugw(ctx, "OnuUpgradeFsm verify DL window ack", log.Fields{ |
| 867 | "for window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID}) |
| 868 | } |
| 869 | |
| 870 | func (oFsm *OnuUpgradeFsm) enterFinalizeDL(ctx context.Context, e *fsm.Event) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 871 | logger.Infow(ctx, "OnuUpgradeFsm finalize DL", log.Fields{ |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 872 | "device-id": oFsm.deviceID, "crc": strconv.FormatInt(int64(oFsm.imageCRC), 16), "delay": oFsm.delayEndSwDl}) |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 873 | //use a background routine to wait EndSwDlDelay and then send the EndSwDl request |
| 874 | // in order to avoid blocking on synchronous event calls for the complete wait time |
| 875 | // and to allow for state transition before sending the EndSwDl request |
| 876 | go oFsm.delayAndSendEndSwDl(ctx) |
| 877 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 878 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 879 | // delayAndSendEndSwDl ensures a delay before sending the EndSwDl request |
| 880 | // |
| 881 | // may also be aborted by parallel channel reception on chAbortEndSwDl |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 882 | func (oFsm *OnuUpgradeFsm) delayAndSendEndSwDl(ctx context.Context) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 883 | oFsm.mutexUpgradeParams.RLock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 884 | if oFsm.delayEndSwDl { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 885 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 886 | //give the ONU some time for image evaluation (hoping it does not only start this evaluation on first EndSwDl itself) |
| 887 | logger.Debugw(ctx, "OnuUpgradeFsm delay EndSwDl", log.Fields{"device-id": oFsm.deviceID, |
| 888 | "duration_s": cOmciEndSwDlDelaySeconds}) |
| 889 | select { |
| 890 | case <-time.After(cOmciEndSwDlDelaySeconds * time.Second): |
| 891 | logger.Warnw(ctx, "OnuUpgradeFsm start sending EndSwDl", log.Fields{ |
| 892 | "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier}) |
| 893 | case <-oFsm.chAbortDelayEndSwDl: |
| 894 | logger.Debugw(ctx, "OnuUpgradeFsm abort request to send EndSwDl", log.Fields{"device-id": oFsm.deviceID}) |
| 895 | //according further state transition is ensured by the entity that sent the abort |
| 896 | return |
| 897 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 898 | } else { |
| 899 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 902 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 903 | if pBaseFsm == nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 904 | logger.Errorw(ctx, "EndSwDl abort: BaseFsm invalid", log.Fields{"device-id": oFsm.deviceID}) |
| 905 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 906 | oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR |
| 907 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 908 | // Can't call FSM Event directly, decoupling it |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 909 | _ = pBaseFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 910 | return |
| 911 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 912 | err := oFsm.pOmciCC.SendEndSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false, |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 913 | oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, oFsm.origImageLength, oFsm.imageCRC, oFsm.isExtendedOmci) |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 914 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 915 | if err != nil { |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 916 | logger.Errorw(ctx, "EndSwDl abort: error sending EndSwDl", log.Fields{ |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 917 | "device-id": oFsm.deviceID, "error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 918 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 919 | return |
| 920 | } |
mpagenko | 609a69a | 2021-12-02 08:12:58 +0000 | [diff] [blame] | 921 | //from here on sending of EndSwDl(Abort) is not needed anymore (even though response is not yet received) |
| 922 | // this avoids sending of both EndSwDl(Success) and EndSwDl(Abort) when cancellation falls just into this window |
| 923 | // the ONU must theoretically be prepared to receive none of them (in case of OMCI transfer issues) e.g. by timeout |
| 924 | oFsm.isEndSwDlOpen = false |
| 925 | // wait for the EndSwDLResponse and check, if the ONU is ready for activation |
| 926 | _ = pBaseFsm.PFsm.Event(UpgradeEvWaitEndDownload) |
| 927 | } //delayAndSendEndSwDl |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 928 | |
| 929 | func (oFsm *OnuUpgradeFsm) enterWaitEndDL(ctx context.Context, e *fsm.Event) { |
| 930 | logger.Infow(ctx, "OnuUpgradeFsm WaitEndDl", log.Fields{ |
| 931 | "device-id": oFsm.deviceID, "wait delay": oFsm.waitDelayEndSwDl * time.Second, "wait count": oFsm.waitCountEndSwDl}) |
| 932 | if oFsm.waitCountEndSwDl == 0 { |
| 933 | logger.Errorw(ctx, "WaitEndDl abort: max limit of EndSwDL reached", log.Fields{ |
| 934 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 935 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 936 | if pBaseFsm == nil { |
| 937 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 938 | "device-id": oFsm.deviceID}) |
| 939 | return |
| 940 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 941 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 942 | oFsm.volthaDownloadReason = voltha.ImageState_IMAGE_REFUSED_BY_ONU //something like 'END_DOWNLOAD_TIMEOUT' would be better (proto) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 943 | oFsm.mutexUpgradeParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 944 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 945 | _ = a_pAFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 946 | }(pBaseFsm) |
| 947 | return |
| 948 | } |
| 949 | |
| 950 | oFsm.waitCountEndSwDl-- |
| 951 | select { |
| 952 | case <-time.After(oFsm.waitDelayEndSwDl * time.Second): |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 953 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 954 | if pBaseFsm == nil { |
| 955 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 956 | "device-id": oFsm.deviceID}) |
| 957 | //FSM may be reset already from somewhere else, nothing we can do here anymore |
| 958 | return |
| 959 | } |
| 960 | //retry End SW DL |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 961 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 962 | oFsm.delayEndSwDl = false //no more extra delay for the request |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 963 | oFsm.mutexUpgradeParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 964 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 965 | _ = a_pAFsm.PFsm.Event(UpgradeEvContinueFinalize) |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 966 | }(pBaseFsm) |
| 967 | return |
| 968 | case success := <-oFsm.chReceiveExpectedResponse: |
| 969 | logger.Debugw(ctx, "WaitEndDl stop wait timer", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 970 | oFsm.isEndSwDlOpen = false //no request to abort of download (already finished or immediate abort) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 971 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 972 | if pBaseFsm == nil { |
| 973 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 974 | "device-id": oFsm.deviceID}) |
| 975 | //FSM may be reset already from somewhere else, nothing we can do here anymore |
| 976 | return |
| 977 | } |
| 978 | if success { |
| 979 | //answer received with ready indication |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 980 | //useAPIVersion43 may not conflict in concurrency in this state function |
| 981 | if oFsm.useAPIVersion43 { // newer API usage requires verification of downloaded image version |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 983 | _ = a_pAFsm.PFsm.Event(UpgradeEvCheckImageName) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 984 | }(pBaseFsm) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 985 | } else { // elder API usage does not support image version check -immediately consider download as successful |
| 986 | if oFsm.activateImage { |
| 987 | //immediate activation requested |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 988 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 989 | _ = a_pAFsm.PFsm.Event(UpgradeEvRequestActivate) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 990 | }(pBaseFsm) |
| 991 | } else { |
| 992 | //have to wait on explicit activation request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 993 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 994 | _ = a_pAFsm.PFsm.Event(UpgradeEvWaitForActivate) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 995 | }(pBaseFsm) |
| 996 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 997 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 998 | return |
| 999 | } |
| 1000 | //timer was aborted |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1001 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1002 | return |
| 1003 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1006 | func (oFsm *OnuUpgradeFsm) enterCheckImageName(ctx context.Context, e *fsm.Event) { |
| 1007 | logger.Debugw(ctx, "OnuUpgradeFsm checking downloaded image name", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1008 | "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1009 | requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1010 | meInstance, err := oFsm.pOmciCC.SendGetMe(log.WithSpanFromContext(context.Background(), ctx), |
| 1011 | me.SoftwareImageClassID, oFsm.InactiveImageMeID, requestedAttributes, oFsm.pDeviceHandler.GetOmciTimeout(), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 1012 | false, oFsm.PAdaptFsm.CommChan, oFsm.isExtendedOmci) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1013 | if err != nil { |
| 1014 | logger.Errorw(ctx, "OnuUpgradeFsm get Software Image ME result error", |
| 1015 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1016 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1017 | return |
| 1018 | } |
| 1019 | oFsm.pLastTxMeInstance = meInstance |
| 1020 | } |
| 1021 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1022 | func (oFsm *OnuUpgradeFsm) enterActivateSw(ctx context.Context, e *fsm.Event) { |
| 1023 | logger.Infow(ctx, "OnuUpgradeFsm activate SW", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1024 | "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1025 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1026 | err := oFsm.pOmciCC.SendActivateSoftware(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false, |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 1027 | oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, oFsm.isExtendedOmci) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1028 | if err != nil { |
| 1029 | logger.Errorw(ctx, "ActivateSw abort: can't send activate frame", log.Fields{ |
| 1030 | "device-id": oFsm.deviceID, "error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1031 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1032 | return |
| 1033 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1034 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1035 | oFsm.upgradePhase = cUpgradeActivating //start of image activation for ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1036 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATING |
| 1037 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | func (oFsm *OnuUpgradeFsm) enterCommitSw(ctx context.Context, e *fsm.Event) { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1041 | logger.Debugw(ctx, "OnuUpgradeFsm start commit SW", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1042 | "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1043 | //any abort request (also conditional) is still regarded as valid as the commit indication might not be possible to verify |
| 1044 | // (which is a bit problematic as the ONU might already be in committed state, |
| 1045 | // in this case (committing failed) always 'onuimage list' should be used to verify the real state (if ONU is reachable)) |
| 1046 | if activeImageID, err := oFsm.pDevEntry.GetActiveImageMeID(ctx); err == nil { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1047 | oFsm.mutexUpgradeParams.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1048 | if activeImageID == oFsm.InactiveImageMeID { |
| 1049 | inactiveImageID := oFsm.InactiveImageMeID |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1050 | logger.Infow(ctx, "OnuUpgradeFsm commit SW", log.Fields{ |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1051 | "device-id": oFsm.deviceID, "me-id": inactiveImageID}) //more efficient activeImageID with above check |
| 1052 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTING |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1053 | oFsm.upgradePhase = cUpgradeCommitting //start of image commitment for ONU |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1054 | oFsm.mutexUpgradeParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1055 | err := oFsm.pOmciCC.SendCommitSoftware(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false, |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 1056 | oFsm.PAdaptFsm.CommChan, inactiveImageID, oFsm.isExtendedOmci) //more efficient activeImageID with above check |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1057 | if err != nil { |
| 1058 | logger.Errorw(ctx, "CommitSw abort: can't send commit sw frame", log.Fields{ |
| 1059 | "device-id": oFsm.deviceID, "error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1060 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1061 | return |
| 1062 | } |
| 1063 | return |
| 1064 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1065 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1066 | logger.Errorw(ctx, "OnuUpgradeFsm active ImageId <> IdToCommit", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1067 | "device-id": oFsm.deviceID, "active ID": activeImageID, "to commit ID": oFsm.InactiveImageMeID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1068 | } else { |
| 1069 | logger.Errorw(ctx, "OnuUpgradeFsm can't commit, no valid active image", log.Fields{ |
| 1070 | "device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1071 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1072 | oFsm.mutexUpgradeParams.Lock() |
| 1073 | oFsm.conditionalCancelRequested = false //any lingering conditional cancelRequest is superseded by this error |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1074 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1075 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1076 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1077 | pBaseFsm := oFsm.PAdaptFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1078 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1079 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1080 | _ = a_pAFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1081 | }(pBaseFsm) |
| 1082 | } |
| 1083 | |
| 1084 | func (oFsm *OnuUpgradeFsm) enterCheckCommitted(ctx context.Context, e *fsm.Event) { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1085 | logger.Debugw(ctx, "OnuUpgradeFsm checking committed SW", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1086 | "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1087 | requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1088 | meInstance, err := oFsm.pOmciCC.SendGetMe(log.WithSpanFromContext(context.Background(), ctx), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 1089 | me.SoftwareImageClassID, oFsm.InactiveImageMeID, requestedAttributes, |
| 1090 | oFsm.pDeviceHandler.GetOmciTimeout(), false, oFsm.PAdaptFsm.CommChan, oFsm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1091 | if err != nil { |
| 1092 | logger.Errorw(ctx, "OnuUpgradeFsm get Software Image ME result error", |
| 1093 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1094 | oFsm.abortOnOmciError(ctx, true) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1095 | return |
| 1096 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1097 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | func (oFsm *OnuUpgradeFsm) enterResetting(ctx context.Context, e *fsm.Event) { |
| 1101 | logger.Debugw(ctx, "OnuUpgradeFsm resetting", log.Fields{"device-id": oFsm.deviceID}) |
| 1102 | |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1103 | oFsm.stateUpdateOnReset(ctx) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1104 | |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1105 | oFsm.mutexAbortRequest.Lock() |
| 1106 | //to be sure to abort a possibly still running runSwDlSectionWindow() |
| 1107 | // in case the reset was not received from cancel() and download not finished correctly |
| 1108 | oFsm.abortRequested = oFsm.volthaDownloadReason |
| 1109 | oFsm.mutexAbortRequest.Unlock() |
| 1110 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1111 | // in case the download-to-ONU timer is still running - cancel it |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1112 | //use non-blocking channel (to be independent from receiver state) |
| 1113 | select { |
| 1114 | //use channel to indicate that the download response waiting shall be aborted for this device (channel) |
| 1115 | case oFsm.chOnuDlReady <- false: |
| 1116 | default: |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1117 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1118 | pConfigUpgradeStateAFsm := oFsm.PAdaptFsm |
| 1119 | if pConfigUpgradeStateAFsm != nil { |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1120 | var nextEvent string |
| 1121 | if oFsm.isEndSwDlOpen { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1122 | if oFsm.repeatAbort { |
| 1123 | oFsm.delayEndSwDl = true //run next abort with delay |
| 1124 | } else { //initial request |
| 1125 | oFsm.delayEndSwDl = false //run next abort with no delay |
| 1126 | oFsm.waitCountEndSwDl = cWaitCountEndSwDl //init for possible repetitions |
| 1127 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1128 | nextEvent = UpgradeEvAbortSwDownload |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1129 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1130 | nextEvent = UpgradeEvRestart |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1131 | } |
| 1132 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1133 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1134 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1135 | _ = a_pAFsm.PFsm.Event(nextEvent) |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1136 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1137 | }(pConfigUpgradeStateAFsm) |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1138 | } |
| 1139 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1140 | |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1141 | func (oFsm *OnuUpgradeFsm) enterAbortingDL(ctx context.Context, e *fsm.Event) { |
| 1142 | logger.Debugw(ctx, "OnuUpgradeFsm aborting download to ONU", log.Fields{"device-id": oFsm.deviceID}) |
| 1143 | |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1144 | oFsm.mutexUpgradeParams.RLock() |
| 1145 | if oFsm.delayEndSwDl { |
| 1146 | oFsm.mutexUpgradeParams.RUnlock() |
| 1147 | //give the ONU some time for image discard activities |
| 1148 | time.Sleep(cOmciEndSwDlDelaySeconds * time.Second) |
| 1149 | } else { |
| 1150 | oFsm.mutexUpgradeParams.RUnlock() |
| 1151 | } |
| 1152 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1153 | pBaseFsm := oFsm.PAdaptFsm |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1154 | if pBaseFsm == nil { |
| 1155 | logger.Errorw(ctx, "OnuUpgradeFsm aborting download: BaseFsm invalid", log.Fields{"device-id": oFsm.deviceID}) |
| 1156 | return |
| 1157 | } |
| 1158 | // abort the download operation by sending an end software download message with invalid CRC and image size |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1159 | err := oFsm.pOmciCC.SendEndSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false, |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 1160 | oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, 0, 0xFFFFFFFF, oFsm.isExtendedOmci) |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1161 | |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1162 | if err != nil { |
| 1163 | logger.Errorw(ctx, "OnuUpgradeFsm aborting download: can't send EndSwDl request", log.Fields{"device-id": oFsm.deviceID}) |
| 1164 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1165 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1166 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1167 | _ = a_pAFsm.PFsm.Event(UpgradeEvRestart) |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1168 | } |
| 1169 | }(pBaseFsm) |
| 1170 | return |
| 1171 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1172 | |
| 1173 | //avoid waiting in the enterXXX function here, |
| 1174 | // otherwise synchronous event calls (like from RxMessage processing) may block and block complete Rx processing then |
| 1175 | go oFsm.waitOnAbortEndSwDlResponse(ctx) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1178 | // abortingDlEvaluateResponse waits for a channel indication with decision to proceed the FSM processing |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1179 | func (oFsm *OnuUpgradeFsm) abortingDlEvaluateResponse(ctx context.Context, |
| 1180 | pBaseFsm *cmn.AdapterFsm, aResponseResult tEndSwDlResponseResult) bool { |
| 1181 | switch aResponseResult { |
| 1182 | case cEndSwDlResponseBusy: // indication for device busy, needs repetition |
| 1183 | if oFsm.waitCountEndSwDl == 0 { |
| 1184 | logger.Errorw(ctx, "aborting download: max limit of EndSwDl reached", log.Fields{ |
| 1185 | "device-id": oFsm.deviceID}) |
| 1186 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1187 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1188 | _ = a_pAFsm.PFsm.Event(UpgradeEvRestart) //give up and let FSM terminate |
| 1189 | } |
| 1190 | }(pBaseFsm) |
| 1191 | } else { |
| 1192 | logger.Debugw(ctx, "aborting download: re-trigger sending abort SwDl", log.Fields{ |
| 1193 | "device-id": oFsm.deviceID, "counter": oFsm.waitCountEndSwDl}) |
| 1194 | oFsm.waitCountEndSwDl-- |
| 1195 | oFsm.repeatAbort = true //repeated request in next round |
| 1196 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1197 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1198 | _ = a_pAFsm.PFsm.Event(UpgradeEvReset) //which then re-triggers sending AbortSwDL |
| 1199 | } |
| 1200 | }(pBaseFsm) |
| 1201 | } |
| 1202 | return true |
| 1203 | case cEndSwDlResponseSuccess: // indication for success response |
| 1204 | logger.Infow(ctx, "aborting download: success response, terminating FSM", log.Fields{ |
| 1205 | "device-id": oFsm.deviceID}) |
| 1206 | case cEndSwDlResponseAbort: // indication for request to abort waiting for response |
| 1207 | logger.Infow(ctx, "aborting download: request to abort waiting, terminating FSM", log.Fields{ |
| 1208 | "device-id": oFsm.deviceID}) |
| 1209 | default: |
| 1210 | logger.Errorw(ctx, "aborting download: unknown channel indication, terminating FSM", log.Fields{ |
| 1211 | "device-id": oFsm.deviceID}) |
| 1212 | } //switch |
| 1213 | return false |
Holger Hildebrandt | 288d947 | 2021-09-06 10:47:53 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | func (oFsm *OnuUpgradeFsm) enterRestarting(ctx context.Context, e *fsm.Event) { |
| 1217 | logger.Debugw(ctx, "OnuUpgradeFsm restarting", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1218 | pConfigUpgradeStateAFsm := oFsm.PAdaptFsm |
| 1219 | if pConfigUpgradeStateAFsm != nil { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1220 | // abort running message processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1221 | fsmAbortMsg := cmn.Message{ |
| 1222 | Type: cmn.TestMsg, |
| 1223 | Data: cmn.TestMessage{ |
| 1224 | TestMessageVal: cmn.AbortMessageProcessing, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1225 | }, |
| 1226 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1227 | pConfigUpgradeStateAFsm.CommChan <- fsmAbortMsg |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1228 | |
| 1229 | //try to restart the FSM to 'disabled' |
| 1230 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1231 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1232 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1233 | _ = a_pAFsm.PFsm.Event(UpgradeEvDisable) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1234 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1235 | }(pConfigUpgradeStateAFsm) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | func (oFsm *OnuUpgradeFsm) enterDisabled(ctx context.Context, e *fsm.Event) { |
| 1240 | logger.Debugw(ctx, "OnuUpgradeFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1241 | // no need to flush possible channels here, Upgrade FSM will be completely removed, garbage collector should find its way |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1242 | if oFsm.pDeviceHandler != nil { |
| 1243 | //request removal of 'reference' in the Handler (completely clear the FSM and its data) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1244 | pLastUpgradeImageState := &voltha.ImageState{ |
| 1245 | Version: oFsm.imageVersion, |
| 1246 | DownloadState: oFsm.volthaDownloadState, |
| 1247 | Reason: oFsm.volthaDownloadReason, |
| 1248 | ImageState: oFsm.volthaImageState, |
| 1249 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1250 | go oFsm.pDeviceHandler.RemoveOnuUpgradeFsm(ctx, pLastUpgradeImageState) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | func (oFsm *OnuUpgradeFsm) processOmciUpgradeMessages(ctx context.Context) { //ctx context.Context? |
| 1255 | logger.Debugw(ctx, "Start OnuUpgradeFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
| 1256 | loop: |
| 1257 | for { |
| 1258 | // case <-ctx.Done(): |
| 1259 | // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
| 1260 | // break loop |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1261 | message, ok := <-oFsm.PAdaptFsm.CommChan |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1262 | if !ok { |
| 1263 | logger.Info(ctx, "OnuUpgradeFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
| 1264 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1265 | oFsm.abortOnOmciError(ctx, true) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1266 | break loop |
| 1267 | } |
| 1268 | logger.Debugw(ctx, "OnuUpgradeFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
| 1269 | |
| 1270 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1271 | case cmn.TestMsg: |
| 1272 | msg, _ := message.Data.(cmn.TestMessage) |
| 1273 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1274 | logger.Infow(ctx, "OnuUpgradeFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
| 1275 | break loop |
| 1276 | } |
| 1277 | logger.Warnw(ctx, "OnuUpgradeFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1278 | case cmn.OMCI: |
| 1279 | msg, _ := message.Data.(cmn.OmciMessage) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1280 | oFsm.handleOmciOnuUpgradeMessage(ctx, msg) |
| 1281 | default: |
| 1282 | logger.Warn(ctx, "OnuUpgradeFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
| 1283 | "message.Type": message.Type}) |
| 1284 | } |
| 1285 | } |
| 1286 | logger.Infow(ctx, "End OnuUpgradeFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
| 1287 | } |
| 1288 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1289 | func (oFsm *OnuUpgradeFsm) handleOmciOnuUpgradeMessage(ctx context.Context, msg cmn.OmciMessage) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1290 | logger.Debugw(ctx, "Rx OMCI OnuUpgradeFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
| 1291 | "msgType": msg.OmciMsg.MessageType}) |
| 1292 | |
| 1293 | switch msg.OmciMsg.MessageType { |
| 1294 | case omci.StartSoftwareDownloadResponseType: |
| 1295 | { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1296 | oFsm.handleRxStartSwDownloadResponse(ctx, msg) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1297 | return |
| 1298 | } //StartSoftwareDownloadResponseType |
| 1299 | case omci.DownloadSectionResponseType: |
| 1300 | { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1301 | oFsm.handleRxSwSectionResponse(ctx, msg) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1302 | return |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1303 | } //DownloadSectionResponseType |
| 1304 | case omci.EndSoftwareDownloadResponseType: |
| 1305 | { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1306 | oFsm.handleRxEndSwDownloadResponse(ctx, msg) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1307 | return |
| 1308 | } //EndSoftwareDownloadResponseType |
| 1309 | case omci.ActivateSoftwareResponseType: |
| 1310 | { |
| 1311 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeActivateSoftwareResponse) |
| 1312 | if msgLayer == nil { |
| 1313 | logger.Errorw(ctx, "Omci Msg layer could not be detected for ActivateSw", |
| 1314 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1315 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1316 | return |
| 1317 | } |
| 1318 | msgObj, msgOk := msgLayer.(*omci.ActivateSoftwareResponse) |
| 1319 | if !msgOk { |
| 1320 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for ActivateSw", |
| 1321 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1322 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1323 | return |
| 1324 | } |
| 1325 | logger.Debugw(ctx, "OnuUpgradeFsm ActivateSwResponse data", log.Fields{ |
| 1326 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1327 | if msgObj.Result != me.Success { |
| 1328 | logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse result error - later: drive FSM to abort state ?", |
| 1329 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1330 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1331 | return |
| 1332 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1333 | oFsm.mutexUpgradeParams.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1334 | if msgObj.EntityInstance == oFsm.InactiveImageMeID { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1335 | // the image is regarded as active really only after ONU reboot and according indication (ONU down/up procedure) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1336 | oFsm.mutexUpgradeParams.Unlock() |
| 1337 | logger.Infow(ctx, "Expected ActivateSwResponse received", |
| 1338 | log.Fields{"device-id": oFsm.deviceID, "commit": oFsm.commitImage}) |
| 1339 | if oFsm.commitImage { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1340 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvWaitForCommit) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1341 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1342 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvActivationDone) // let the FSM wait for external commit request |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1343 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1344 | return |
| 1345 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1346 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1347 | logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse wrong ME instance: abort", |
| 1348 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1349 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1350 | return |
| 1351 | } //ActivateSoftwareResponseType |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1352 | case omci.CommitSoftwareResponseType: |
| 1353 | { |
| 1354 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCommitSoftwareResponse) |
| 1355 | if msgLayer == nil { |
| 1356 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CommitResponse", |
| 1357 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1358 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1359 | return |
| 1360 | } |
| 1361 | msgObj, msgOk := msgLayer.(*omci.CommitSoftwareResponse) |
| 1362 | if !msgOk { |
| 1363 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CommitResponse", |
| 1364 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1365 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1366 | return |
| 1367 | } |
mpagenko | bf67a09 | 2021-03-17 09:52:28 +0000 | [diff] [blame] | 1368 | if msgObj.Result != me.Success { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1369 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse result error - later: drive FSM to abort state ?", |
| 1370 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1371 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1372 | return |
mpagenko | bf67a09 | 2021-03-17 09:52:28 +0000 | [diff] [blame] | 1373 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1374 | oFsm.mutexUpgradeParams.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1375 | if msgObj.EntityInstance == oFsm.InactiveImageMeID { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1376 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1377 | logger.Debugw(ctx, "OnuUpgradeFsm Expected SwImage CommitResponse received", log.Fields{"device-id": oFsm.deviceID}) |
| 1378 | //verifying committed image |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1379 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvCheckCommitted) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1380 | return |
| 1381 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1382 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1383 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse wrong ME instance: abort", |
| 1384 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1385 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1386 | return |
| 1387 | } //CommitSoftwareResponseType |
| 1388 | case omci.GetResponseType: |
| 1389 | { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1390 | oFsm.handleRxSwGetResponse(ctx, msg) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1391 | return |
| 1392 | } //GetResponseType |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1393 | default: |
| 1394 | { |
| 1395 | logger.Errorw(ctx, "Rx OMCI unhandled MsgType", |
| 1396 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
| 1397 | return |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1402 | func (oFsm *OnuUpgradeFsm) handleRxStartSwDownloadResponse(ctx context.Context, msg cmn.OmciMessage) { |
| 1403 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeStartSoftwareDownloadResponse) |
| 1404 | if msgLayer == nil { |
| 1405 | logger.Errorw(ctx, "Omci Msg layer could not be detected for StartSwDlResponse", |
| 1406 | log.Fields{"device-id": oFsm.deviceID}) |
| 1407 | oFsm.abortOnOmciError(ctx, false) |
| 1408 | return |
| 1409 | } |
| 1410 | msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadResponse) |
| 1411 | if !msgOk { |
| 1412 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for StartSwDlResponse", |
| 1413 | log.Fields{"device-id": oFsm.deviceID}) |
| 1414 | oFsm.abortOnOmciError(ctx, false) |
| 1415 | return |
| 1416 | } |
| 1417 | logger.Debugw(ctx, "OnuUpgradeFsm StartSwDlResponse data", log.Fields{ |
| 1418 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1419 | if msgObj.Result != me.Success { |
| 1420 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse result error - later: drive FSM to abort state ?", |
| 1421 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1422 | oFsm.abortOnOmciError(ctx, false) |
| 1423 | return |
| 1424 | } |
| 1425 | |
| 1426 | oFsm.mutexUpgradeParams.Lock() |
| 1427 | if msgObj.EntityInstance == oFsm.InactiveImageMeID { |
| 1428 | logger.Debugw(ctx, "Expected StartSwDlResponse received", log.Fields{"device-id": oFsm.deviceID}) |
| 1429 | if msgObj.WindowSize != oFsm.omciDownloadWindowSizeLimit { |
| 1430 | // also response WindowSize = 0 is a valid number for used Window size 1 |
| 1431 | logger.Debugw(ctx, "different StartSwDlResponse window size requested by ONU", log.Fields{ |
| 1432 | "acceptedOnuWindowSizeLimit": msgObj.WindowSize, "device-id": oFsm.deviceID}) |
| 1433 | oFsm.omciDownloadWindowSizeLimit = msgObj.WindowSize |
| 1434 | } |
| 1435 | oFsm.noOfWindows = oFsm.noOfSections / uint32(oFsm.omciDownloadWindowSizeLimit+1) |
| 1436 | if oFsm.noOfSections%uint32(oFsm.omciDownloadWindowSizeLimit+1) > 0 { |
| 1437 | oFsm.noOfWindows++ |
| 1438 | } |
| 1439 | logger.Debugw(ctx, "OnuUpgradeFsm will use", log.Fields{ |
| 1440 | "windows": oFsm.noOfWindows, "sections": oFsm.noOfSections, |
| 1441 | "at WindowSizeLimit": oFsm.omciDownloadWindowSizeLimit}) |
| 1442 | oFsm.nextDownloadSectionsAbsolute = 0 |
| 1443 | oFsm.nextDownloadSectionsWindow = 0 |
| 1444 | oFsm.nextDownloadWindow = 0 |
| 1445 | |
| 1446 | oFsm.mutexUpgradeParams.Unlock() |
| 1447 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvRxStartSwDownload) |
| 1448 | return |
| 1449 | } |
| 1450 | oFsm.mutexUpgradeParams.Unlock() |
| 1451 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: try again (later)?", |
| 1452 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1453 | oFsm.abortOnOmciError(ctx, false) |
| 1454 | } //handleRxStartSwDownloadResponse |
| 1455 | |
| 1456 | func (oFsm *OnuUpgradeFsm) handleRxSwSectionResponse(ctx context.Context, msg cmn.OmciMessage) { |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1457 | if oFsm.PAdaptFsm == nil { |
| 1458 | logger.Infow(ctx, "DlSectionResponse received - but FSM not really valid anymore", log.Fields{ |
| 1459 | "device-id": oFsm.deviceID}) |
| 1460 | return |
| 1461 | } |
| 1462 | if !oFsm.PAdaptFsm.PFsm.Is(UpgradeStVerifyWindow) { |
| 1463 | //all the processing here is only relevant if the FSM is in state upgradeStVerifyWindow |
| 1464 | // otherwise this response can be ignored (may stem from a long-processing window send activity, |
| 1465 | // which is not anymore relevant based on intermediate (cancel) state transitions) |
| 1466 | logger.Infow(ctx, "DlSectionResponse received - but ignored", log.Fields{ |
| 1467 | "device-id": oFsm.deviceID, "fsm-state": oFsm.PAdaptFsm.PFsm.Current()}) |
| 1468 | return |
| 1469 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1470 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDownloadSectionResponse) |
| 1471 | if msgLayer == nil { |
| 1472 | logger.Errorw(ctx, "Omci Msg layer could not be detected for DlSectionResponse", |
| 1473 | log.Fields{"device-id": oFsm.deviceID, "omci-message": msg.OmciMsg}) |
| 1474 | oFsm.abortOnOmciError(ctx, false) |
| 1475 | return |
| 1476 | } |
| 1477 | msgObj, msgOk := msgLayer.(*omci.DownloadSectionResponse) |
| 1478 | if !msgOk { |
| 1479 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for DlSectionResponse", |
| 1480 | log.Fields{"device-id": oFsm.deviceID}) |
| 1481 | oFsm.abortOnOmciError(ctx, false) |
| 1482 | return |
| 1483 | } |
| 1484 | logger.Debugw(ctx, "OnuUpgradeFsm DlSectionResponse Data", log.Fields{ |
| 1485 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1486 | if msgObj.Result != me.Success { |
| 1487 | logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse result error - later: repeat window once?", //TODO!!! |
| 1488 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1489 | oFsm.abortOnOmciError(ctx, false) |
| 1490 | return |
| 1491 | } |
| 1492 | oFsm.mutexUpgradeParams.Lock() |
| 1493 | if msgObj.EntityInstance == oFsm.InactiveImageMeID { |
| 1494 | sectionNumber := msgObj.SectionNumber |
| 1495 | logger.Infow(ctx, "DlSectionResponse received", log.Fields{ |
| 1496 | "window section-number": sectionNumber, "window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID}) |
| 1497 | |
| 1498 | oFsm.nextDownloadWindow++ |
| 1499 | if oFsm.nextDownloadWindow >= oFsm.noOfWindows { |
| 1500 | if sectionNumber != oFsm.omciDownloadWindowSizeLast { |
| 1501 | logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse section error last window - later: repeat window once?", //TODO!!! |
| 1502 | log.Fields{"device-id": oFsm.deviceID, "actual section": sectionNumber, |
| 1503 | "expected section": oFsm.omciDownloadWindowSizeLast}) |
| 1504 | oFsm.mutexUpgradeParams.Unlock() |
| 1505 | oFsm.abortOnOmciError(ctx, false) |
| 1506 | return |
| 1507 | } |
| 1508 | oFsm.delayEndSwDl = true //ensure a delay for the EndSwDl message |
| 1509 | //CRC computation for all data bytes of the file |
| 1510 | imageCRC := crc32a.Checksum(oFsm.imageBuffer[:int(oFsm.origImageLength)]) //store internal for multiple usage |
| 1511 | //revert the retrieved CRC Byte Order (seems not to deliver NetworkByteOrder) |
| 1512 | var byteSlice []byte = make([]byte, 4) |
| 1513 | binary.LittleEndian.PutUint32(byteSlice, uint32(imageCRC)) |
| 1514 | oFsm.imageCRC = binary.BigEndian.Uint32(byteSlice) |
| 1515 | oFsm.mutexUpgradeParams.Unlock() |
| 1516 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvEndSwDownload) |
| 1517 | return |
| 1518 | } |
| 1519 | if sectionNumber != oFsm.omciDownloadWindowSizeLimit { |
| 1520 | logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse section error - later: repeat window once?", //TODO!!! |
| 1521 | log.Fields{"device-id": oFsm.deviceID, "actual-section": sectionNumber, |
| 1522 | "expected section": oFsm.omciDownloadWindowSizeLimit}) |
| 1523 | oFsm.mutexUpgradeParams.Unlock() |
| 1524 | oFsm.abortOnOmciError(ctx, false) |
| 1525 | return |
| 1526 | } |
| 1527 | oFsm.nextDownloadSectionsWindow = 0 |
| 1528 | oFsm.mutexUpgradeParams.Unlock() |
| 1529 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvContinueNextWindow) |
| 1530 | return |
| 1531 | } |
| 1532 | oFsm.mutexUpgradeParams.Unlock() |
| 1533 | logger.Errorw(ctx, "OnuUpgradeFsm Omci StartSwDlResponse wrong ME instance: try again (later)?", |
| 1534 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1535 | oFsm.abortOnOmciError(ctx, false) |
| 1536 | } //handleRxSwSectionResponse |
| 1537 | |
| 1538 | func (oFsm *OnuUpgradeFsm) handleRxEndSwDownloadResponse(ctx context.Context, msg cmn.OmciMessage) { |
| 1539 | inAbortingState := oFsm.PAdaptFsm.PFsm.Is(UpgradeStAbortingDL) |
| 1540 | |
| 1541 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeEndSoftwareDownloadResponse) |
| 1542 | if msgLayer == nil { |
| 1543 | logger.Errorw(ctx, "Omci Msg layer could not be detected for EndSwDlResponse", |
| 1544 | log.Fields{"device-id": oFsm.deviceID}) |
| 1545 | if !inAbortingState { |
| 1546 | oFsm.abortOnOmciError(ctx, false) |
| 1547 | } //else using error log and wait for another response or 'aborting' state timeout |
| 1548 | return |
| 1549 | } |
| 1550 | msgObj, msgOk := msgLayer.(*omci.EndSoftwareDownloadResponse) |
| 1551 | if !msgOk { |
| 1552 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for EndSwDlResponse", |
| 1553 | log.Fields{"device-id": oFsm.deviceID}) |
| 1554 | if !inAbortingState { |
| 1555 | oFsm.abortOnOmciError(ctx, false) |
| 1556 | } //else using error log and wait for another response or 'aborting' state timeout |
| 1557 | return |
| 1558 | } |
| 1559 | logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse data", log.Fields{ |
| 1560 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1561 | if msgObj.Result != me.Success { |
| 1562 | if msgObj.Result == me.DeviceBusy { |
| 1563 | //ONU indicates it is still processing the image - let the FSM just wait and then repeat the request |
| 1564 | logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse busy: waiting before sending new request", log.Fields{ |
| 1565 | "device-id": oFsm.deviceID}) |
| 1566 | if inAbortingState { |
| 1567 | //if the EndSwDl was requested from state AbortingDL then use channel to indicate ONU busy/repeat indication |
| 1568 | oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseBusy //repeat abort request |
| 1569 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1570 | return |
| 1571 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1572 | if inAbortingState { |
| 1573 | //if the EndSwDl was requested from state AbortingDL and response is error indication |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1574 | // that would be quite strange ONU behavior, no resolution from OnuAdapter, just let the FSM go on to disabled |
| 1575 | logger.Errorw(ctx, "OnuUpgradeFsm EndSwDlResponse result error - aborting anyway", |
| 1576 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1577 | oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseAbort //error indication to stop waiting on EndDownloadResponse(abort) |
| 1578 | return |
| 1579 | } |
| 1580 | //else: ONU rejects the previous download, complete upgrade is immediately aborted with error |
| 1581 | logger.Errorw(ctx, "OnuUpgradeFsm EndSwDlResponse result error - abort upgrade", |
| 1582 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1583 | oFsm.mutexUpgradeParams.Lock() |
| 1584 | oFsm.conditionalCancelRequested = false //any conditional cancelRequest is superseded by this abortion |
| 1585 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE |
| 1586 | oFsm.mutexUpgradeParams.Unlock() |
| 1587 | select { |
| 1588 | case oFsm.chOnuDlReady <- false: |
| 1589 | default: |
| 1590 | } |
| 1591 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1592 | return |
| 1593 | } |
| 1594 | oFsm.mutexUpgradeParams.Lock() |
| 1595 | if msgObj.EntityInstance == oFsm.InactiveImageMeID { |
| 1596 | logger.Debugw(ctx, "Expected EndSwDlResponse received", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1597 | if inAbortingState { |
| 1598 | oFsm.mutexUpgradeParams.Unlock() |
| 1599 | //if the EndSwDl was requested from state AbortingDL then use channel to indicate abort acceptance |
| 1600 | oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseSuccess //success |
| 1601 | return |
| 1602 | } |
| 1603 | if !oFsm.useAPIVersion43 { |
| 1604 | //in the older API version the image version check was not possible |
| 1605 | // - assume new loaded image as valid-inactive immediately |
| 1606 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_SUCCEEDED |
| 1607 | oFsm.volthaImageState = voltha.ImageState_IMAGE_INACTIVE |
| 1608 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1609 | //use non-blocking channel (to be independent from receiver state) to indicate that the download to ONU was successful |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1610 | select { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1611 | case oFsm.chOnuDlReady <- true: |
| 1612 | default: |
| 1613 | } |
| 1614 | } else { |
| 1615 | oFsm.mutexUpgradeParams.Unlock() |
| 1616 | } |
| 1617 | //use asynchronous channel sending to let the FSM proceed |
| 1618 | select { |
| 1619 | case oFsm.chReceiveExpectedResponse <- true: |
| 1620 | default: |
| 1621 | } |
| 1622 | return |
| 1623 | } |
| 1624 | oFsm.mutexUpgradeParams.Unlock() |
| 1625 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: ignoring", |
| 1626 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1627 | // no state abort in case of unexpected ImageId, just keep waiting for the correct one |
| 1628 | } //handleRxEndSwDownloadResponse |
| 1629 | |
| 1630 | func (oFsm *OnuUpgradeFsm) handleRxSwGetResponse(ctx context.Context, msg cmn.OmciMessage) { |
| 1631 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 1632 | if msgLayer == nil { |
| 1633 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SwImage GetResponse", |
| 1634 | log.Fields{"device-id": oFsm.deviceID}) |
| 1635 | oFsm.abortOnOmciError(ctx, false) |
| 1636 | return |
| 1637 | } |
| 1638 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 1639 | if !msgOk { |
| 1640 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SwImage GetResponse", |
| 1641 | log.Fields{"device-id": oFsm.deviceID}) |
| 1642 | oFsm.abortOnOmciError(ctx, false) |
| 1643 | return |
| 1644 | } |
Akash Soni | f80a6e6 | 2024-12-11 10:48:53 +0530 | [diff] [blame^] | 1645 | if msgObj.EntityClass != me.SoftwareImageClassID { |
| 1646 | logger.Errorw(ctx, "Class id mismatch for software image upgrade", |
| 1647 | log.Fields{"device-id": oFsm.deviceID, "received ClassId": msgObj.EntityClass, "expected ClassId": me.SoftwareImageClassID}) |
| 1648 | oFsm.abortOnOmciError(ctx, false) |
| 1649 | return |
| 1650 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1651 | logger.Debugw(ctx, "OnuUpgradeFsm SwImage GetResponse data", log.Fields{ |
| 1652 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1653 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1654 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1655 | if msgObj.Result != me.Success { |
| 1656 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse result error - later: drive FSM to abort state ?", |
| 1657 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1658 | oFsm.abortOnOmciError(ctx, false) |
| 1659 | return |
| 1660 | } |
| 1661 | } else { |
| 1662 | logger.Warnw(ctx, "OnuUpgradeFsm SwImage unexpected Entity GetResponse data - ignore", |
| 1663 | log.Fields{"device-id": oFsm.deviceID}) |
| 1664 | return |
| 1665 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1666 | meAttributes := msgObj.Attributes |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1667 | var imageVersion string |
| 1668 | var imageIsCommitted, imageIsActive uint8 |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1669 | |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1670 | if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok { |
| 1671 | if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok { |
| 1672 | if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok { |
| 1673 | imageIsCommitted = softwareImageIsCommitted.(uint8) |
| 1674 | imageIsActive = softwareImageIsActiveimage.(uint8) |
| 1675 | imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion) |
| 1676 | logger.Debugw(ctx, "OnuUpgradeFsm - GetResponse Data for SoftwareImage", |
| 1677 | log.Fields{"device-id": oFsm.deviceID, "entityID": msgObj.EntityInstance, |
| 1678 | "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted}) |
| 1679 | } else { |
| 1680 | logger.Errorw(ctx, |
| 1681 | "OnuUpgradeFsm - Not all mandatory attributes present in in SoftwareImage instance - handling stopped!", |
| 1682 | log.Fields{"device-id": oFsm.deviceID}) |
| 1683 | oFsm.abortOnOmciError(ctx, false) |
| 1684 | return |
| 1685 | } |
| 1686 | } |
| 1687 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1688 | if oFsm.PAdaptFsm.PFsm.Current() == UpgradeStCheckImageName { |
| 1689 | //image name check after EndSwDownload, this state (and block) can only be taken if APIVersion43 is used |
| 1690 | oFsm.verifyOnuSwStatusAfterDownload(ctx, msgObj.EntityInstance, imageVersion, imageIsActive, imageIsCommitted) |
| 1691 | return |
| 1692 | } |
| 1693 | |
| 1694 | //assumed only relevant state here is upgradeStCheckCommitted |
| 1695 | oFsm.mutexUpgradeParams.Lock() |
| 1696 | oFsm.conditionalCancelRequested = false //getting here any set (conditional) cancelRequest is not relevant anymore |
| 1697 | if msgObj.EntityInstance == oFsm.InactiveImageMeID && imageIsActive == cmn.SwIsActive { |
| 1698 | //a check on the delivered image version is not done, the ONU delivered version might be different from what might have been |
| 1699 | // indicated in the download image version string (version must be part of the image content itself) |
| 1700 | // so checking that might be quite unreliable |
| 1701 | //but with new API this was changed, assumption is that omci image version is known at download request and exactly that is used |
| 1702 | // in all the API references, so it can and should be checked here now |
| 1703 | if oFsm.useAPIVersion43 { |
| 1704 | if imageVersion != oFsm.imageVersion { |
| 1705 | //new active version indicated on OMCI from ONU is not the expected version |
| 1706 | logger.Errorw(ctx, "OnuUpgradeFsm image-version not matching the requested upgrade", |
| 1707 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance, |
| 1708 | "onu-version": imageVersion, "expected-version": oFsm.imageVersion}) |
| 1709 | // TODO!!!: error treatment? |
| 1710 | //TODO!!!: possibly send event information for aborted upgrade (aborted by wrong version)? |
| 1711 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE //something like 'UNEXPECTED_VERSION' would be better - proto def |
| 1712 | oFsm.mutexUpgradeParams.Unlock() |
| 1713 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
| 1714 | return |
| 1715 | } |
| 1716 | logger.Debugw(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU", |
| 1717 | log.Fields{"device-id": oFsm.deviceID}) |
| 1718 | } |
| 1719 | if imageIsCommitted == cmn.SwIsCommitted { |
| 1720 | oFsm.upgradePhase = cUpgradeCommitted |
| 1721 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTED |
| 1722 | //store the new commit flag to onuSwImageIndications (to keep them in sync) |
| 1723 | oFsm.pDevEntry.ModifySwImageActiveCommit(ctx, imageIsCommitted) |
| 1724 | logger.Infow(ctx, "requested SW image committed, releasing OnuUpgrade", log.Fields{"device-id": oFsm.deviceID}) |
| 1725 | //deviceProcStatusUpdate not used anymore, |
| 1726 | // replaced by transferring the last (more) upgrade state information within removeOnuUpgradeFsm |
| 1727 | oFsm.mutexUpgradeParams.Unlock() |
| 1728 | //releasing the upgrade FSM on success |
| 1729 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
| 1730 | return |
| 1731 | } |
| 1732 | //if not committed, abort upgrade as failed. There is no implementation here that would trigger this test again |
| 1733 | } |
| 1734 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE |
| 1735 | oFsm.mutexUpgradeParams.Unlock() |
| 1736 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade", |
| 1737 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1738 | // TODO!!!: error treatment? |
| 1739 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1740 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
| 1741 | } //handleRxSwGetResponse |
| 1742 | |
| 1743 | func (oFsm *OnuUpgradeFsm) verifyOnuSwStatusAfterDownload(ctx context.Context, aInstanceID uint16, |
| 1744 | aImageVersion string, aImageIsActive uint8, aImageIsCommitted uint8) { |
| 1745 | oFsm.mutexUpgradeParams.Lock() |
| 1746 | if aInstanceID == oFsm.InactiveImageMeID && aImageIsActive == cmn.SwIsInactive && |
| 1747 | aImageIsCommitted == cmn.SwIsUncommitted { |
| 1748 | if aImageVersion != oFsm.imageVersion { |
| 1749 | //new stored inactive version indicated on OMCI from ONU is not the expected version |
| 1750 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse version indication not matching requested upgrade", |
| 1751 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": aInstanceID, |
| 1752 | "onu-version": aImageVersion, "expected-version": oFsm.imageVersion}) |
| 1753 | //download state is set when entering the reset state |
| 1754 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE //something like 'UNEXPECTED_VERSION' would be better - proto def |
| 1755 | oFsm.mutexUpgradeParams.Unlock() |
| 1756 | //stop the running ONU download timer |
| 1757 | //use non-blocking channel (to be independent from receiver state) |
| 1758 | select { |
| 1759 | //use channel to indicate that the download response waiting shall be aborted for this device (channel) |
| 1760 | case oFsm.chOnuDlReady <- false: |
| 1761 | default: |
| 1762 | } |
| 1763 | // TODO!!!: error treatment? |
| 1764 | //TODO!!!: possibly send event information for aborted upgrade (aborted by wrong version)? |
| 1765 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
| 1766 | return |
| 1767 | } |
| 1768 | //with APIVersion43 this is the point to consider the newly loaded image as valid (and inactive) |
| 1769 | oFsm.upgradePhase = cUpgradeDownloaded |
| 1770 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_SUCCEEDED |
| 1771 | oFsm.volthaImageState = voltha.ImageState_IMAGE_INACTIVE |
| 1772 | //store the new inactive version to onuSwImageIndications (to keep them in sync) |
| 1773 | oFsm.pDevEntry.ModifySwImageInactiveVersion(ctx, oFsm.imageVersion) |
| 1774 | //proceed within upgrade FSM |
| 1775 | if oFsm.activateImage { |
| 1776 | //immediate activation requested |
| 1777 | oFsm.mutexUpgradeParams.Unlock() |
| 1778 | logger.Debugw(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU, continue with activation", |
| 1779 | log.Fields{"device-id": oFsm.deviceID}) |
| 1780 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvRequestActivate) |
| 1781 | } else { |
| 1782 | //have to wait on explicit activation request |
| 1783 | oFsm.mutexUpgradeParams.Unlock() |
| 1784 | logger.Infow(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU, wait for activate request", |
| 1785 | log.Fields{"device-id": oFsm.deviceID}) |
| 1786 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvWaitForActivate) |
| 1787 | } |
| 1788 | //use non-blocking channel (to be independent from receiver state) |
| 1789 | select { |
| 1790 | //use non-blocking channel to indicate that the download to ONU was successful |
| 1791 | case oFsm.chOnuDlReady <- true: |
| 1792 | default: |
| 1793 | } |
| 1794 | return |
| 1795 | } |
| 1796 | //not the expected image/image state |
| 1797 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE |
| 1798 | oFsm.mutexUpgradeParams.Unlock() |
| 1799 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade", |
| 1800 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": aInstanceID}) |
| 1801 | // TODO!!!: error treatment? |
| 1802 | //TODO!!!: possibly send event information for aborted upgrade (aborted by ONU state indication)? |
| 1803 | _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
| 1804 | } //verifyOnuSwStatusAfterDownload |
| 1805 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1806 | // abortOnOmciError aborts the upgrade processing with evAbort |
| 1807 | // |
| 1808 | // asynchronous/synchronous based on parameter aAsync |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1809 | func (oFsm *OnuUpgradeFsm) abortOnOmciError(ctx context.Context, aAsync bool) { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1810 | oFsm.mutexUpgradeParams.Lock() |
| 1811 | oFsm.conditionalCancelRequested = false //any conditional cancelRequest is superseded by this abortion |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1812 | oFsm.volthaDownloadReason = voltha.ImageState_OMCI_TRANSFER_ERROR |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1813 | oFsm.mutexUpgradeParams.Unlock() |
| 1814 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1815 | if oFsm.PAdaptFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1816 | var err error |
| 1817 | if aAsync { //asynchronous call requested to ensure state transition |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1818 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1819 | if a_pAFsm.PFsm != nil { |
| 1820 | err = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1821 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1822 | }(oFsm.PAdaptFsm) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1823 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1824 | if oFsm.PAdaptFsm.PFsm != nil { |
| 1825 | err = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1826 | } |
| 1827 | } |
| 1828 | if err != nil { |
| 1829 | logger.Warnw(ctx, "onu upgrade fsm could not abort on omci error", log.Fields{ |
| 1830 | "device-id": oFsm.deviceID, "error": err}) |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1835 | // waitOnDownloadToAdapterReady state can only be reached with useAPIVersion43 (usage of pFileManager) |
| 1836 | // |
| 1837 | // precondition: mutexIsAwaitingAdapterDlResponse is lockek on call |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1838 | func (oFsm *OnuUpgradeFsm) waitOnDownloadToAdapterReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1839 | aWaitChannel chan bool) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1840 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1841 | downloadToAdapterTimeout := oFsm.pFileManager.GetDownloadTimeout(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1842 | oFsm.isWaitingForAdapterDlResponse = true |
| 1843 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1844 | aSyncChannel <- struct{}{} |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1845 | select { |
| 1846 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 1847 | // case <-ctx.Done(): |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1848 | // logger.Infow("OnuUpgradeFsm-waitOnDownloadToAdapterReady canceled", log.Fields{"for device-id": oFsm.deviceID}) |
| 1849 | case <-time.After(downloadToAdapterTimeout): //10s should be enough for downloading some image to the adapter |
| 1850 | logger.Warnw(ctx, "OnuUpgradeFsm Waiting-adapter-download timeout", log.Fields{ |
| 1851 | "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToAdapterTimeout}) |
| 1852 | oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel) |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1853 | //running into timeout here may still have the download to adapter active -> abort |
| 1854 | oFsm.pFileManager.CancelDownload(ctx, oFsm.imageIdentifier) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1855 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1856 | oFsm.isWaitingForAdapterDlResponse = false |
| 1857 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1858 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1859 | oFsm.conditionalCancelRequested = false //any conditional cancelRequest is superseded by this abortion |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1860 | oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'DOWNLOAD_TO_ADAPTER_TIMEOUT' would be better (proto) |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1861 | oFsm.mutexUpgradeParams.Unlock() |
| 1862 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1863 | if oFsm.PAdaptFsm != nil && oFsm.PAdaptFsm.PFsm != nil { |
| 1864 | err := oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort) |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1865 | if err != nil { |
| 1866 | logger.Warnw(ctx, "onu upgrade fsm could not abort on omci error", log.Fields{ |
| 1867 | "device-id": oFsm.deviceID, "error": err}) |
| 1868 | } |
| 1869 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1870 | return |
| 1871 | |
| 1872 | case success := <-aWaitChannel: |
| 1873 | if success { |
| 1874 | logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded received", log.Fields{"device-id": oFsm.deviceID}) |
| 1875 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1876 | oFsm.isWaitingForAdapterDlResponse = false |
| 1877 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
| 1878 | //let the upgrade process proceed |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1879 | pUpgradeFsm := oFsm.PAdaptFsm |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1880 | if pUpgradeFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1881 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvPrepareSwDownload) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1882 | } else { |
| 1883 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1884 | } |
| 1885 | return |
| 1886 | } |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1887 | // waiting was aborted (assumed here to be caused by |
| 1888 | // error detection or cancel at download after upgrade FSM reset/abort with according image states set there) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1889 | logger.Debugw(ctx, "OnuUpgradeFsm Waiting-adapter-download aborted", log.Fields{"device-id": oFsm.deviceID}) |
| 1890 | oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel) |
| 1891 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1892 | oFsm.isWaitingForAdapterDlResponse = false |
| 1893 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1894 | return |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1895 | } |
| 1896 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1897 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1898 | // waitOnDownloadToOnuReady state can only be reached with useAPIVersion43 (usage of pFileManager) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1899 | func (oFsm *OnuUpgradeFsm) waitOnDownloadToOnuReady(ctx context.Context, aWaitChannel chan bool) { |
| 1900 | downloadToOnuTimeout := time.Duration(1+(oFsm.imageLength/0x400000)) * oFsm.downloadToOnuTimeout4MB |
| 1901 | logger.Debugw(ctx, "OnuUpgradeFsm start download-to-ONU timer", log.Fields{"device-id": oFsm.deviceID, |
| 1902 | "duration": downloadToOnuTimeout}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1903 | select { |
| 1904 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 1905 | // case <-ctx.Done(): |
| 1906 | // logger.Infow("OnuUpgradeFsm-waitOnDownloadToOnuReady canceled", log.Fields{"for device-id": oFsm.deviceID}) |
| 1907 | case <-time.After(downloadToOnuTimeout): //using an image-size depending timout (in minutes) |
| 1908 | logger.Warnw(ctx, "OnuUpgradeFsm Waiting-ONU-download timeout", log.Fields{ |
| 1909 | "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToOnuTimeout}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1910 | //the upgrade process has to be aborted |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1911 | oFsm.abortOnOmciError(ctx, false) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1912 | return |
| 1913 | |
| 1914 | case success := <-aWaitChannel: |
| 1915 | if success { |
| 1916 | logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded on ONU received", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1917 | //all fine, let the FSM proceed like defined from the sender of this event |
| 1918 | return |
| 1919 | } |
| 1920 | // waiting was aborted (assumed here to be caused by |
mpagenko | 39b703e | 2021-08-25 13:38:40 +0000 | [diff] [blame] | 1921 | // error detection or cancel at download after upgrade FSM reset/abort with according image states set there) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1922 | logger.Debugw(ctx, "OnuUpgradeFsm Waiting-ONU-download aborted", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1923 | return |
| 1924 | } |
| 1925 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1926 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1927 | // waitOnAbortEndSwDlResponse waits for either abort/success or timeout of EndSwDownload (for abortion) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1928 | func (oFsm *OnuUpgradeFsm) waitOnAbortEndSwDlResponse(ctx context.Context) { |
| 1929 | logger.Debugw(ctx, "OnuUpgradeFsm start wait for EndSwDl response (abort)", log.Fields{"device-id": oFsm.deviceID}) |
| 1930 | select { |
| 1931 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
| 1932 | logger.Warnw(ctx, "OnuUpgradeFsm aborting download: timeout - no response received", log.Fields{"device-id": oFsm.deviceID}) |
| 1933 | pUpgradeFsm := oFsm.PAdaptFsm |
| 1934 | if pUpgradeFsm != nil { |
| 1935 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvRestart) |
| 1936 | } else { |
| 1937 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1938 | } |
| 1939 | return |
| 1940 | case response := <-oFsm.chReceiveAbortEndSwDlResponse: |
| 1941 | logger.Debugw(ctx, "OnuUpgradeFsm aborting download: response received", |
| 1942 | log.Fields{"device-id": oFsm.deviceID, "response": response}) |
| 1943 | pUpgradeFsm := oFsm.PAdaptFsm |
| 1944 | if pUpgradeFsm != nil { |
| 1945 | if oFsm.abortingDlEvaluateResponse(ctx, pUpgradeFsm, response) { |
| 1946 | return //event sent from function already |
| 1947 | } |
| 1948 | _ = pUpgradeFsm.PFsm.Event(UpgradeEvRestart) |
| 1949 | } else { |
| 1950 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1951 | } |
| 1952 | return |
| 1953 | } //select |
| 1954 | } |
| 1955 | |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 1956 | // stateUpdateOnReset writes the download and/or image state on entering the reset state according to FSM internal indications |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1957 | func (oFsm *OnuUpgradeFsm) stateUpdateOnReset(ctx context.Context) { |
| 1958 | oFsm.mutexUpgradeParams.Lock() |
| 1959 | defer oFsm.mutexUpgradeParams.Unlock() |
| 1960 | if !oFsm.conditionalCancelRequested { |
| 1961 | switch oFsm.upgradePhase { |
| 1962 | case cUpgradeUndefined, cUpgradeDownloading: //coming from downloading |
| 1963 | //make sure the download state is only changed in case the device has still been downloading |
| 1964 | if oFsm.volthaDownloadReason == voltha.ImageState_CANCELLED_ON_REQUEST { |
| 1965 | // indication for termination on request |
| 1966 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_CANCELLED |
| 1967 | } else if oFsm.volthaDownloadReason != voltha.ImageState_NO_ERROR { |
| 1968 | // indication for termination on failure |
| 1969 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 1970 | } |
| 1971 | //reset the image state from Downloading in this case |
| 1972 | oFsm.volthaImageState = voltha.ImageState_IMAGE_UNKNOWN //something like 'IMAGE_DOWNLOAD_ABORTED' would be better (proto) |
| 1973 | //in all other upgrade phases the last set download state remains valid |
| 1974 | case cUpgradeActivating: |
| 1975 | //reset the image state from Activating in this case |
| 1976 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 1977 | case cUpgradeCommitting: // indication for request to abort waiting for response |
| 1978 | //reset the image state from Activating in this case |
| 1979 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 1980 | //default: in all other upgrade phases keep the last set imageState |
| 1981 | } //switch |
| 1982 | } else { |
| 1983 | //when reaching reset state with conditional cancel that can only result from ONU related problems |
| 1984 | // (mostly ONU down indication) - derived from resetFsms call |
| 1985 | // and it can only be related to the downloading-to-ONU phase (no need to check that additionally) |
| 1986 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 1987 | oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE |
| 1988 | //reset the image state from Downloading in this case |
| 1989 | oFsm.volthaImageState = voltha.ImageState_IMAGE_UNKNOWN //something like 'IMAGE_DOWNLOAD_ABORTED' would be better (proto) |
| 1990 | } |
| 1991 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 1992 | |
| 1993 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 1994 | func (oFsm *OnuUpgradeFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 1995 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 1996 | oFsm.pDeviceHandler = nil |
| 1997 | oFsm.pDownloadManager = nil |
| 1998 | oFsm.pFileManager = nil |
| 1999 | oFsm.pDevEntry = nil |
| 2000 | oFsm.pOmciCC = nil |
| 2001 | } |