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