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