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