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