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