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 | |
| 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
| 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" |
| 32 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 33 | "github.com/opencord/voltha-protos/v4/go/voltha" |
| 34 | ) |
| 35 | |
| 36 | const cMaxUint32 = ^uint32(0) |
| 37 | |
| 38 | const ( |
| 39 | // internal predefined values - some off them should later be configurable (perhaps with theses as defaults) |
| 40 | cOmciDownloadSectionSize = 31 //in bytes |
| 41 | cOmciDownloadWindowSizeLimit = 31 //in sections for window offset (windowSize(32)-1) |
| 42 | //cOmciDownloadWindowRetryMax = 2 // max attempts for a specific window |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 43 | cOmciSectionInterleaveMilliseconds = 0 //DownloadSection interleave time in milliseconds (0 for no delay) |
| 44 | cOmciEndSwDlDelaySeconds = 1 //End Software Download delay after last section (may be also configurable?) |
| 45 | cWaitCountEndSwDl = 6 //maximum number of EndSwDl requests |
| 46 | cWaitDelayEndSwDlSeconds = 10 //duration, how long is waited before next request on EndSwDl |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 47 | //cOmciDownloadCompleteTimeout = 5400 //in s for the complete timeout (may be better scale to image size/ noOfWindows) |
| 48 | ) |
| 49 | |
| 50 | const ( |
| 51 | // events of config PON ANI port FSM |
| 52 | upgradeEvStart = "upgradeEvStart" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 53 | upgradeEvAdapterDownload = "upgradeEvAdapterDownload" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 54 | upgradeEvPrepareSwDownload = "upgradeEvPrepareSwDownload" |
| 55 | upgradeEvRxStartSwDownload = "upgradeEvRxStartSwDownload" |
| 56 | upgradeEvWaitWindowAck = "upgradeEvWaitWindowAck" |
| 57 | upgradeEvContinueNextWindow = "upgradeEvContinueNextWindow" |
| 58 | upgradeEvEndSwDownload = "upgradeEvEndSwDownload" |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 59 | upgradeEvWaitEndDownload = "upgradeEvWaitEndDownload" |
| 60 | upgradeEvContinueFinalize = "upgradeEvContinueFinalize" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 61 | upgradeEvWaitForActivate = "upgradeEvWaitForActivate" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 62 | upgradeEvRequestActivate = "upgradeEvRequestActivate" |
| 63 | upgradeEvWaitForCommit = "upgradeEvWaitForCommit" |
| 64 | upgradeEvCommitSw = "upgradeEvCommitSw" |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 65 | upgradeEvCheckCommitted = "upgradeEvCheckCommitted" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 66 | |
| 67 | //upgradeEvTimeoutSimple = "upgradeEvTimeoutSimple" |
| 68 | //upgradeEvTimeoutMids = "upgradeEvTimeoutMids" |
| 69 | upgradeEvReset = "upgradeEvReset" |
| 70 | upgradeEvAbort = "upgradeEvAbort" |
| 71 | upgradeEvRestart = "upgradeEvRestart" |
| 72 | ) |
| 73 | |
| 74 | const ( |
| 75 | // states of config PON ANI port FSM |
| 76 | upgradeStDisabled = "upgradeStDisabled" |
| 77 | upgradeStStarting = "upgradeStStarting" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 78 | upgradeStWaitingAdapterDL = "upgradeStWaitingAdapterDL" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 79 | upgradeStPreparingDL = "upgradeStPreparingDL" |
| 80 | upgradeStDLSection = "upgradeStDLSection" |
| 81 | upgradeStVerifyWindow = "upgradeStVerifyWindow" |
| 82 | upgradeStFinalizeDL = "upgradeStFinalizeDL" |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 83 | upgradeStWaitEndDL = "upgradeStWaitEndDL" |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 84 | upgradeStWaitForActivate = "upgradeStWaitForActivate" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 85 | upgradeStRequestingActivate = "upgradeStRequestingActivate" |
| 86 | upgradeStWaitForCommit = "upgradeStWaitForCommit" |
| 87 | upgradeStCommitSw = "upgradeStCommitSw" |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 88 | upgradeStCheckCommitted = "upgradeStCheckCommitted" |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 89 | upgradeStResetting = "upgradeStResetting" |
| 90 | ) |
| 91 | |
| 92 | //required definition for IdleState detection for activities on OMCI |
| 93 | const cOnuUpgradeFsmIdleState = upgradeStWaitForCommit |
| 94 | |
| 95 | //OnuUpgradeFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 96 | type OnuUpgradeFsm struct { |
| 97 | pDeviceHandler *deviceHandler |
| 98 | pDownloadManager *adapterDownloadManager |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 99 | pFileManager *fileDownloadManager //used from R2.8 with new API version |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 100 | deviceID string |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 101 | pOnuOmciDevice *OnuDeviceEntry |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 102 | pOmciCC *omciCC |
| 103 | pOnuDB *onuDeviceDB |
| 104 | requestEvent OnuDeviceEvent |
| 105 | //omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 106 | pAdaptFsm *AdapterFsm |
| 107 | pImageDsc *voltha.ImageDownload |
| 108 | imageBuffer []byte |
| 109 | origImageLength uint32 //as also limited by OMCI |
| 110 | imageCRC uint32 //as per OMCI - ITU I.363.5 crc |
| 111 | imageLength uint32 //including last bytes padding |
| 112 | omciDownloadWindowSizeLimit uint8 //windowSize-1 in sections |
| 113 | omciDownloadWindowSizeLast uint8 //number of sections in last window |
| 114 | noOfSections uint32 //uint32 range for sections should be sufficient for very long images |
| 115 | nextDownloadSectionsAbsolute uint32 //number of next section to download in overall image |
| 116 | nextDownloadSectionsWindow uint8 //number of next section to download within current window |
| 117 | noOfWindows uint32 //uint32 range for windows should be sufficient for very long images |
| 118 | nextDownloadWindow uint32 //number of next window to download |
| 119 | inactiveImageMeID uint16 //ME-ID of the inactive image |
| 120 | downloadToOnuTimeout4MB time.Duration //timeout for downloading the image to the ONU for a 4MB image slice |
| 121 | omciSectionInterleaveDelay time.Duration //DownloadSectionInterleave delay in milliseconds |
| 122 | delayEndSwDl bool //flag to provide a delay between last section and EndSwDl |
| 123 | pLastTxMeInstance *me.ManagedEntity |
| 124 | waitCountEndSwDl uint8 //number, how often is waited for EndSwDl at maximum |
| 125 | waitDelayEndSwDl time.Duration //duration, how long is waited before next request on EndSwDl |
| 126 | chReceiveExpectedResponse chan bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 127 | useAPIVersion43 bool //flag for indication on which API version is used (and accordingly which specific methods) |
| 128 | mutexUpgradeParams sync.RWMutex //mutex to protect members for parallel function requests and omci response processing |
| 129 | imageVersion string //name of the image as used within OMCI (and on extrenal API interface) |
| 130 | imageIdentifier string //name of the image as used in the adapter |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 131 | mutexIsAwaitingAdapterDlResponse sync.RWMutex |
| 132 | chAdapterDlReady chan bool |
| 133 | isWaitingForAdapterDlResponse bool |
| 134 | mutexIsAwaitingOnuDlResponse sync.RWMutex |
| 135 | chOnuDlReady chan bool |
| 136 | isWaitingForOnuDlResponse bool |
| 137 | activateImage bool |
| 138 | commitImage bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 139 | volthaDownloadState voltha.ImageState_ImageDownloadState |
| 140 | volthaDownloadReason voltha.ImageState_ImageFailureReason |
| 141 | volthaImageState voltha.ImageState_ImageActivationState |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | //NewOnuUpgradeFsm is the 'constructor' for the state machine to config the PON ANI ports |
| 145 | // of ONU UNI ports via OMCI |
| 146 | func NewOnuUpgradeFsm(ctx context.Context, apDeviceHandler *deviceHandler, |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 147 | apDevEntry *OnuDeviceEntry, apOnuDB *onuDeviceDB, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 148 | aRequestEvent OnuDeviceEvent, aName string, aCommChannel chan Message) *OnuUpgradeFsm { |
| 149 | instFsm := &OnuUpgradeFsm{ |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 150 | pDeviceHandler: apDeviceHandler, |
| 151 | deviceID: apDeviceHandler.deviceID, |
| 152 | pOnuOmciDevice: apDevEntry, |
| 153 | pOmciCC: apDevEntry.PDevOmciCC, |
| 154 | pOnuDB: apOnuDB, |
| 155 | requestEvent: aRequestEvent, |
| 156 | omciDownloadWindowSizeLimit: cOmciDownloadWindowSizeLimit, |
| 157 | omciSectionInterleaveDelay: cOmciSectionInterleaveMilliseconds, |
Holger Hildebrandt | ac01073 | 2021-06-02 13:35:39 +0000 | [diff] [blame] | 158 | downloadToOnuTimeout4MB: apDeviceHandler.pOpenOnuAc.dlToOnuTimeout4M, |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 159 | waitCountEndSwDl: cWaitCountEndSwDl, |
| 160 | waitDelayEndSwDl: cWaitDelayEndSwDlSeconds, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 161 | volthaDownloadState: voltha.ImageState_DOWNLOAD_STARTED, //if FSM created we can assume that the download (to adapter) really started |
| 162 | volthaDownloadReason: voltha.ImageState_NO_ERROR, |
| 163 | volthaImageState: voltha.ImageState_IMAGE_UNKNOWN, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 164 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 165 | instFsm.chReceiveExpectedResponse = make(chan bool) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 166 | instFsm.chAdapterDlReady = make(chan bool) |
| 167 | instFsm.chOnuDlReady = make(chan bool) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 168 | |
| 169 | instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
| 170 | if instFsm.pAdaptFsm == nil { |
| 171 | logger.Errorw(ctx, "OnuUpgradeFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
| 172 | "device-id": instFsm.deviceID}) |
| 173 | return nil |
| 174 | } |
| 175 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
| 176 | upgradeStDisabled, |
| 177 | fsm.Events{ |
| 178 | {Name: upgradeEvStart, Src: []string{upgradeStDisabled}, Dst: upgradeStStarting}, |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 179 | {Name: upgradeEvAdapterDownload, Src: []string{upgradeStStarting}, Dst: upgradeStWaitingAdapterDL}, |
| 180 | {Name: upgradeEvPrepareSwDownload, Src: []string{upgradeStStarting, upgradeStWaitingAdapterDL}, Dst: upgradeStPreparingDL}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 181 | {Name: upgradeEvRxStartSwDownload, Src: []string{upgradeStPreparingDL}, Dst: upgradeStDLSection}, |
| 182 | {Name: upgradeEvWaitWindowAck, Src: []string{upgradeStDLSection}, Dst: upgradeStVerifyWindow}, |
| 183 | {Name: upgradeEvContinueNextWindow, Src: []string{upgradeStVerifyWindow}, Dst: upgradeStDLSection}, |
| 184 | {Name: upgradeEvEndSwDownload, Src: []string{upgradeStVerifyWindow}, Dst: upgradeStFinalizeDL}, |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 185 | {Name: upgradeEvWaitEndDownload, Src: []string{upgradeStFinalizeDL}, Dst: upgradeStWaitEndDL}, |
| 186 | {Name: upgradeEvContinueFinalize, Src: []string{upgradeStWaitEndDL}, Dst: upgradeStFinalizeDL}, |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 187 | {Name: upgradeEvWaitForActivate, Src: []string{upgradeStWaitEndDL}, Dst: upgradeStWaitForActivate}, |
| 188 | {Name: upgradeEvRequestActivate, Src: []string{upgradeStStarting, upgradeStWaitEndDL, upgradeStWaitForActivate}, |
| 189 | Dst: upgradeStRequestingActivate}, //allows also for direct activation (without download) [TODO!!!] |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 190 | {Name: upgradeEvWaitForCommit, Src: []string{upgradeStRequestingActivate}, Dst: upgradeStWaitForCommit}, |
| 191 | {Name: upgradeEvCommitSw, Src: []string{upgradeStStarting, upgradeStWaitForCommit}, |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 192 | Dst: upgradeStCommitSw}, //allows also for direct commitment (without download) [TODO!!!] |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 193 | {Name: upgradeEvCheckCommitted, Src: []string{upgradeStCommitSw}, Dst: upgradeStCheckCommitted}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | {Name: upgradeEvTimeoutSimple, Src: []string{ |
| 197 | upgradeStCreatingDot1PMapper, upgradeStCreatingMBPCD, upgradeStSettingTconts, upgradeStSettingDot1PMapper}, Dst: upgradeStStarting}, |
| 198 | {Name: upgradeEvTimeoutMids, Src: []string{ |
| 199 | upgradeStCreatingGemNCTPs, upgradeStCreatingGemIWs, upgradeStSettingPQs}, Dst: upgradeStStarting}, |
| 200 | */ |
| 201 | // exceptional treatments |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 202 | {Name: upgradeEvReset, Src: []string{upgradeStStarting, upgradeStWaitingAdapterDL, upgradeStPreparingDL, upgradeStDLSection, |
| 203 | upgradeStVerifyWindow, upgradeStDLSection, upgradeStFinalizeDL, upgradeStWaitEndDL, upgradeStWaitForActivate, |
| 204 | upgradeStRequestingActivate, upgradeStCommitSw, upgradeStCheckCommitted}, //upgradeStWaitForCommit is not reset (later perhaps also not upgradeStWaitActivate) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 205 | Dst: upgradeStResetting}, |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 206 | {Name: upgradeEvAbort, Src: []string{upgradeStStarting, upgradeStWaitingAdapterDL, upgradeStPreparingDL, upgradeStDLSection, |
| 207 | upgradeStVerifyWindow, upgradeStDLSection, upgradeStFinalizeDL, upgradeStWaitEndDL, upgradeStWaitForActivate, |
| 208 | upgradeStRequestingActivate, upgradeStWaitForCommit, upgradeStCommitSw, upgradeStCheckCommitted}, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 209 | Dst: upgradeStResetting}, |
| 210 | {Name: upgradeEvRestart, Src: []string{upgradeStResetting}, Dst: upgradeStDisabled}, |
| 211 | }, |
| 212 | fsm.Callbacks{ |
| 213 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) }, |
| 214 | "enter_" + upgradeStStarting: func(e *fsm.Event) { instFsm.enterStarting(ctx, e) }, |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 215 | "enter_" + upgradeStWaitingAdapterDL: func(e *fsm.Event) { instFsm.enterWaitingAdapterDL(ctx, e) }, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 216 | "enter_" + upgradeStPreparingDL: func(e *fsm.Event) { instFsm.enterPreparingDL(ctx, e) }, |
| 217 | "enter_" + upgradeStDLSection: func(e *fsm.Event) { instFsm.enterDownloadSection(ctx, e) }, |
| 218 | "enter_" + upgradeStVerifyWindow: func(e *fsm.Event) { instFsm.enterVerifyWindow(ctx, e) }, |
| 219 | "enter_" + upgradeStFinalizeDL: func(e *fsm.Event) { instFsm.enterFinalizeDL(ctx, e) }, |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 220 | "enter_" + upgradeStWaitEndDL: func(e *fsm.Event) { instFsm.enterWaitEndDL(ctx, e) }, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 221 | "enter_" + upgradeStRequestingActivate: func(e *fsm.Event) { instFsm.enterActivateSw(ctx, e) }, |
| 222 | "enter_" + upgradeStCommitSw: func(e *fsm.Event) { instFsm.enterCommitSw(ctx, e) }, |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 223 | "enter_" + upgradeStCheckCommitted: func(e *fsm.Event) { instFsm.enterCheckCommitted(ctx, e) }, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 224 | "enter_" + upgradeStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) }, |
| 225 | "enter_" + upgradeStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) }, |
| 226 | }, |
| 227 | ) |
| 228 | if instFsm.pAdaptFsm.pFsm == nil { |
| 229 | logger.Errorw(ctx, "OnuUpgradeFsm's Base FSM could not be instantiated!!", log.Fields{ |
| 230 | "device-id": instFsm.deviceID}) |
| 231 | return nil |
| 232 | } |
| 233 | |
| 234 | logger.Debugw(ctx, "OnuUpgradeFsm created", log.Fields{"device-id": instFsm.deviceID}) |
| 235 | return instFsm |
| 236 | } |
| 237 | |
| 238 | //SetDownloadParams configures the needed parameters for a specific download to the ONU |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 239 | // called from 'old' API Activate_image_update() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 240 | func (oFsm *OnuUpgradeFsm) SetDownloadParams(ctx context.Context, aInactiveImageID uint16, |
| 241 | apImageDsc *voltha.ImageDownload, apDownloadManager *adapterDownloadManager) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 242 | pBaseFsm := oFsm.pAdaptFsm.pFsm |
| 243 | if pBaseFsm != nil && pBaseFsm.Is(upgradeStStarting) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 244 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 245 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{ |
| 246 | "device-id": oFsm.deviceID, "image-description": apImageDsc}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 247 | oFsm.inactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 248 | oFsm.pImageDsc = apImageDsc |
| 249 | oFsm.pDownloadManager = apDownloadManager |
Holger Hildebrandt | ac1e059 | 2021-06-03 15:16:49 +0000 | [diff] [blame^] | 250 | oFsm.activateImage = true |
| 251 | oFsm.commitImage = true |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 252 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 253 | |
| 254 | go func(aPBaseFsm *fsm.FSM) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 255 | // let the upgrade FSM proceed to PreparingDL |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 256 | _ = aPBaseFsm.Event(upgradeEvPrepareSwDownload) |
| 257 | }(pBaseFsm) |
| 258 | return nil |
| 259 | } |
| 260 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 261 | "device-id": oFsm.deviceID}) |
| 262 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 263 | } |
| 264 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 265 | //SetDownloadParamsAfterDownload configures the needed parameters for a specific download to the ONU according to |
| 266 | // updated API interface with R2.8: start download to ONU if the image is downloaded to the adapter |
| 267 | // called from 'new' API Download_onu_image |
| 268 | func (oFsm *OnuUpgradeFsm) SetDownloadParamsAfterDownload(ctx context.Context, aInactiveImageID uint16, |
| 269 | apImageRequest *voltha.DeviceImageDownloadRequest, apDownloadManager *fileDownloadManager, |
Holger Hildebrandt | ac01073 | 2021-06-02 13:35:39 +0000 | [diff] [blame] | 270 | aImageIdentifier string) error { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 271 | oFsm.mutexUpgradeParams.Lock() |
| 272 | var pBaseFsm *fsm.FSM = nil |
| 273 | if oFsm.pAdaptFsm != nil { |
| 274 | pBaseFsm = oFsm.pAdaptFsm.pFsm |
| 275 | } |
| 276 | if pBaseFsm != nil && pBaseFsm.Is(upgradeStStarting) { |
| 277 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{ |
| 278 | "device-id": oFsm.deviceID, "image-description": apImageRequest}) |
| 279 | oFsm.useAPIVersion43 = true |
| 280 | oFsm.inactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
| 281 | oFsm.pFileManager = apDownloadManager |
| 282 | oFsm.imageIdentifier = aImageIdentifier |
| 283 | oFsm.imageVersion = apImageRequest.Image.Version |
| 284 | oFsm.activateImage = apImageRequest.ActivateOnSuccess |
| 285 | oFsm.commitImage = apImageRequest.CommitOnSuccess |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 286 | //TODO: currently straightforward options activate and commit are expected to be set and (unconditionally) done |
| 287 | // for separate handling of these options the FSM must accordingly branch from the concerned states - later |
| 288 | oFsm.mutexUpgradeParams.Unlock() |
| 289 | _ = pBaseFsm.Event(upgradeEvAdapterDownload) //no need to call the FSM event in background here |
| 290 | return nil |
| 291 | } |
| 292 | oFsm.mutexUpgradeParams.Unlock() |
| 293 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 294 | "device-id": oFsm.deviceID}) |
| 295 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 296 | } |
| 297 | |
| 298 | //SetActivationParamsRunning sets the activate and commit flags for a running download to the ONU according to adapters rpc call |
| 299 | // called from 'new' API Activate_onu_image |
| 300 | func (oFsm *OnuUpgradeFsm) SetActivationParamsRunning(ctx context.Context, |
| 301 | aImageIdentifier string, aCommit bool) error { |
| 302 | oFsm.mutexUpgradeParams.Lock() |
| 303 | //set activate/commit independent from state, if FSM is already beyond concerned states, then it does not matter anyway |
| 304 | // (as long as the Imageidentifier is correct) |
| 305 | logger.Debugw(ctx, "OnuUpgradeFsm activate/commit parameter setting", log.Fields{ |
| 306 | "device-id": oFsm.deviceID, "image-id": aImageIdentifier, "commit": aCommit}) |
| 307 | if aImageIdentifier != oFsm.imageIdentifier { |
| 308 | logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{ |
| 309 | "device-id": oFsm.deviceID, "request-image": aImageIdentifier, "fsm-image": oFsm.imageIdentifier}) |
| 310 | oFsm.mutexUpgradeParams.Unlock() |
| 311 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s", |
| 312 | oFsm.deviceID)) |
| 313 | } |
| 314 | oFsm.activateImage = true |
| 315 | oFsm.commitImage = aCommit |
| 316 | oFsm.mutexUpgradeParams.Unlock() |
| 317 | var pBaseFsm *fsm.FSM = nil |
| 318 | if oFsm.pAdaptFsm != nil { |
| 319 | pBaseFsm = oFsm.pAdaptFsm.pFsm |
| 320 | } |
| 321 | if pBaseFsm != nil { |
| 322 | if pBaseFsm.Is(upgradeStWaitForActivate) { |
| 323 | logger.Debugw(ctx, "OnuUpgradeFsm finish waiting for activate", log.Fields{"device-id": oFsm.deviceID}) |
| 324 | _ = pBaseFsm.Event(upgradeEvRequestActivate) //no need to call the FSM event in background here |
| 325 | } |
| 326 | return nil |
| 327 | } |
| 328 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{ |
| 329 | "device-id": oFsm.deviceID}) |
| 330 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID)) |
| 331 | } |
| 332 | |
| 333 | //SetActivationParamsStart starts upgrade processing with immediate activation |
| 334 | // called from 'new' API Activate_onu_image |
| 335 | func (oFsm *OnuUpgradeFsm) SetActivationParamsStart(ctx context.Context, aImageVersion string, aInactiveImageID uint16, aCommit bool) error { |
| 336 | oFsm.mutexUpgradeParams.Lock() |
| 337 | var pBaseFsm *fsm.FSM = nil |
| 338 | if oFsm.pAdaptFsm != nil { |
| 339 | pBaseFsm = oFsm.pAdaptFsm.pFsm |
| 340 | } |
| 341 | if pBaseFsm != nil && pBaseFsm.Is(upgradeStStarting) { |
| 342 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with activation", log.Fields{ |
| 343 | "device-id": oFsm.deviceID, "image-version": aImageVersion}) |
| 344 | oFsm.useAPIVersion43 = true |
| 345 | oFsm.inactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId |
| 346 | oFsm.imageVersion = aImageVersion |
| 347 | oFsm.activateImage = true |
| 348 | oFsm.commitImage = aCommit |
| 349 | oFsm.mutexUpgradeParams.Unlock() |
| 350 | //directly request the FSM to activate the image |
| 351 | _ = pBaseFsm.Event(upgradeEvRequestActivate) //no need to call the FSM event in background here |
| 352 | return nil |
| 353 | } |
| 354 | oFsm.mutexUpgradeParams.Unlock() |
| 355 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 356 | "device-id": oFsm.deviceID}) |
| 357 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 358 | } |
| 359 | |
| 360 | //SetCommitmentParamsRunning sets the commit flag for a running download to the ONU according to adapters rpc call |
| 361 | // called from 'new' API Commit_onu_image |
| 362 | func (oFsm *OnuUpgradeFsm) SetCommitmentParamsRunning(ctx context.Context, aImageIdentifier string) error { |
| 363 | oFsm.mutexUpgradeParams.Lock() |
| 364 | //set commit independent from state, if FSM is already beyond commit state (just ready), then it does not matter anyway |
| 365 | // (as long as the Imageidentifier is correct) |
| 366 | logger.Debugw(ctx, "OnuUpgradeFsm commit parameter setting", log.Fields{ |
| 367 | "device-id": oFsm.deviceID, "image-id": aImageIdentifier}) |
| 368 | if aImageIdentifier != oFsm.imageIdentifier { |
| 369 | logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{ |
| 370 | "device-id": oFsm.deviceID, "request-image": aImageIdentifier, "fsm-image": oFsm.imageIdentifier}) |
| 371 | oFsm.mutexUpgradeParams.Unlock() |
| 372 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s", |
| 373 | oFsm.deviceID)) |
| 374 | } |
| 375 | oFsm.commitImage = true |
| 376 | oFsm.mutexUpgradeParams.Unlock() |
| 377 | var pBaseFsm *fsm.FSM = nil |
| 378 | if oFsm.pAdaptFsm != nil { |
| 379 | pBaseFsm = oFsm.pAdaptFsm.pFsm |
| 380 | } |
| 381 | if pBaseFsm != nil { |
| 382 | if pBaseFsm.Is(upgradeStWaitForCommit) { |
| 383 | logger.Debugw(ctx, "OnuUpgradeFsm finish waiting for commit", log.Fields{"device-id": oFsm.deviceID}) |
| 384 | _ = pBaseFsm.Event(upgradeEvCommitSw) //no need to call the FSM event in background here |
| 385 | } |
| 386 | return nil |
| 387 | } |
| 388 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{ |
| 389 | "device-id": oFsm.deviceID}) |
| 390 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID)) |
| 391 | } |
| 392 | |
| 393 | //SetCommitmentParamsStart starts upgrade processing with immediate commitment |
| 394 | // called from 'new' API Commit_onu_image |
| 395 | func (oFsm *OnuUpgradeFsm) SetCommitmentParamsStart(ctx context.Context, aImageVersion string, aActiveImageID uint16) error { |
| 396 | oFsm.mutexUpgradeParams.Lock() |
| 397 | var pBaseFsm *fsm.FSM = nil |
| 398 | if oFsm.pAdaptFsm != nil { |
| 399 | pBaseFsm = oFsm.pAdaptFsm.pFsm |
| 400 | } |
| 401 | if pBaseFsm != nil && pBaseFsm.Is(upgradeStStarting) { |
| 402 | logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with commitment", log.Fields{ |
| 403 | "device-id": oFsm.deviceID, "image-version": aImageVersion}) |
| 404 | oFsm.useAPIVersion43 = true |
| 405 | oFsm.inactiveImageMeID = aActiveImageID //upgrade state machines inactive ImageId is the new active ImageId |
| 406 | oFsm.imageVersion = aImageVersion |
| 407 | oFsm.commitImage = true |
| 408 | oFsm.mutexUpgradeParams.Unlock() |
| 409 | //directly request the FSM to activate the image |
| 410 | _ = pBaseFsm.Event(upgradeEvCommitSw) //no need to call the FSM event in background here |
| 411 | return nil |
| 412 | } |
| 413 | oFsm.mutexUpgradeParams.Unlock() |
| 414 | logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{ |
| 415 | "device-id": oFsm.deviceID}) |
| 416 | return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID)) |
| 417 | } |
| 418 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 419 | //GetImageStates delivers the download states as per device proto buf or error indication |
| 420 | func (oFsm *OnuUpgradeFsm) GetImageStates(ctx context.Context, |
| 421 | aImageIdentifier string, aVersion string) (*voltha.ImageState, error) { |
| 422 | pImageState := &voltha.ImageState{} |
| 423 | // check if the request refers to some active image/version of the processing |
| 424 | oFsm.mutexUpgradeParams.RLock() |
| 425 | if (aImageIdentifier == oFsm.imageIdentifier) || (aVersion == oFsm.imageVersion) { |
| 426 | pImageState.DownloadState = oFsm.volthaDownloadState |
| 427 | pImageState.Reason = oFsm.volthaDownloadReason |
| 428 | pImageState.ImageState = oFsm.volthaImageState |
| 429 | } else { |
| 430 | pImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 431 | pImageState.Reason = voltha.ImageState_NO_ERROR |
| 432 | pImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 433 | } |
| 434 | oFsm.mutexUpgradeParams.RUnlock() |
| 435 | return pImageState, nil |
| 436 | } |
| 437 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 438 | //CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM |
| 439 | func (oFsm *OnuUpgradeFsm) CancelProcessing(ctx context.Context) { |
| 440 | //mutex protection is required for possible concurrent access to FSM members |
| 441 | //attention: for an unbuffered channel the sender is blocked until the value is received (processed)! |
| 442 | // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver) |
| 443 | oFsm.mutexIsAwaitingAdapterDlResponse.RLock() |
| 444 | if oFsm.isWaitingForAdapterDlResponse { |
| 445 | oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock() |
| 446 | //use channel to indicate that the download response waiting shall be aborted for this device (channel) |
| 447 | oFsm.chAdapterDlReady <- false |
| 448 | } else { |
| 449 | oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock() |
| 450 | } |
| 451 | //chOnuDlReady is cleared as part of the FSM reset processing (from enterResetting()) |
| 452 | |
| 453 | // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM |
| 454 | // specific here: If the FSM is in upgradeStWaitForCommit, it is left there for possibly later commit |
| 455 | // this possibly also refers later to (not yet existing) upgradeStWaitForActivate (with ctl API changes) |
| 456 | pAdaptFsm := oFsm.pAdaptFsm |
| 457 | if pAdaptFsm != nil { |
| 458 | // calling FSM events in background to avoid blocking of the caller |
| 459 | go func(aPAFsm *AdapterFsm) { |
| 460 | if aPAFsm.pFsm != nil { |
| 461 | if aPAFsm.pFsm.Is(upgradeStWaitEndDL) { |
| 462 | oFsm.chReceiveExpectedResponse <- false //which aborts the FSM (activate was not yet sent) |
| 463 | } |
| 464 | _ = aPAFsm.pFsm.Event(upgradeEvReset) //anyway and for all other states |
| 465 | } //else the FSM seems already to be in some released state |
| 466 | }(pAdaptFsm) |
| 467 | } |
| 468 | } |
| 469 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 470 | func (oFsm *OnuUpgradeFsm) enterStarting(ctx context.Context, e *fsm.Event) { |
| 471 | logger.Debugw(ctx, "OnuUpgradeFsm start", log.Fields{"in state": e.FSM.Current(), |
| 472 | "device-id": oFsm.deviceID}) |
| 473 | |
| 474 | // start go routine for processing of LockState messages |
| 475 | go oFsm.processOmciUpgradeMessages(ctx) |
| 476 | } |
| 477 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 478 | //enterWaitingAdapterDL state can only be reached with useAPIVersion43 |
| 479 | func (oFsm *OnuUpgradeFsm) enterWaitingAdapterDL(ctx context.Context, e *fsm.Event) { |
| 480 | logger.Debugw(ctx, "OnuUpgradeFsm waiting for adapter download", log.Fields{"in state": e.FSM.Current(), |
| 481 | "device-id": oFsm.deviceID}) |
| 482 | go oFsm.waitOnDownloadToAdapterReady(ctx, oFsm.chAdapterDlReady) |
| 483 | go oFsm.pFileManager.RequestDownloadReady(ctx, oFsm.imageIdentifier, oFsm.chAdapterDlReady) |
| 484 | } |
| 485 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 486 | func (oFsm *OnuUpgradeFsm) enterPreparingDL(ctx context.Context, e *fsm.Event) { |
| 487 | logger.Debugw(ctx, "OnuUpgradeFsm prepare Download to Onu", log.Fields{"in state": e.FSM.Current(), |
| 488 | "device-id": oFsm.deviceID}) |
| 489 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 490 | var fileLen int64 |
| 491 | var err error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 492 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 493 | if oFsm.useAPIVersion43 { |
| 494 | //with the new API structure download to adapter is implicit and we have to wait until the image is available |
| 495 | fileLen, err = oFsm.pFileManager.GetImageBufferLen(ctx, oFsm.imageIdentifier) |
| 496 | } else { |
| 497 | fileLen, err = oFsm.pDownloadManager.getImageBufferLen(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir) |
| 498 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 499 | if err != nil || fileLen > int64(cMaxUint32) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 500 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 501 | logger.Errorw(ctx, "OnuUpgradeFsm abort: problems getting image buffer length", log.Fields{ |
| 502 | "device-id": oFsm.deviceID, "error": err, "length": fileLen}) |
| 503 | pBaseFsm := oFsm.pAdaptFsm |
| 504 | // Can't call FSM Event directly, decoupling it |
| 505 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 506 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 507 | }(pBaseFsm) |
| 508 | return |
| 509 | } |
| 510 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 511 | //copy file content to buffer |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 512 | oFsm.imageBuffer = make([]byte, fileLen) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 513 | if oFsm.useAPIVersion43 { |
| 514 | oFsm.imageBuffer, err = oFsm.pFileManager.GetDownloadImageBuffer(ctx, oFsm.imageIdentifier) |
| 515 | } else { |
| 516 | oFsm.imageBuffer, err = oFsm.pDownloadManager.getDownloadImageBuffer(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir) |
| 517 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 518 | if err != nil { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 519 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 520 | logger.Errorw(ctx, "OnuUpgradeFsm abort: can't get image buffer", log.Fields{ |
| 521 | "device-id": oFsm.deviceID, "error": err}) |
| 522 | pBaseFsm := oFsm.pAdaptFsm |
| 523 | // Can't call FSM Event directly, decoupling it |
| 524 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 525 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 526 | }(pBaseFsm) |
| 527 | return |
| 528 | } |
| 529 | |
| 530 | oFsm.noOfSections = uint32(fileLen / cOmciDownloadSectionSize) |
| 531 | if fileLen%cOmciDownloadSectionSize > 0 { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 532 | bufferPadding := make([]byte, cOmciDownloadSectionSize-uint32((fileLen)%cOmciDownloadSectionSize)) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 533 | //expand the imageBuffer to exactly fit multiples of cOmciDownloadSectionSize with padding |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 534 | oFsm.imageBuffer = append(oFsm.imageBuffer[:(fileLen)], bufferPadding...) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 535 | oFsm.noOfSections++ |
| 536 | } |
| 537 | oFsm.origImageLength = uint32(fileLen) |
| 538 | oFsm.imageLength = uint32(len(oFsm.imageBuffer)) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 539 | logger.Infow(ctx, "OnuUpgradeFsm starts with StartSwDl values", log.Fields{ |
| 540 | "MeId": oFsm.inactiveImageMeID, "windowSizeLimit": oFsm.omciDownloadWindowSizeLimit, |
| 541 | "ImageSize": oFsm.imageLength, "original file size": fileLen}) |
| 542 | //"NumberOfCircuitPacks": oFsm.numberCircuitPacks, "CircuitPacks MeId": 0}) //parallel circuit packs download not supported |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 543 | |
| 544 | oFsm.mutexUpgradeParams.Unlock() |
| 545 | go oFsm.waitOnDownloadToOnuReady(ctx, oFsm.chOnuDlReady) // start supervision of the complete download-to-ONU procedure |
| 546 | |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 547 | err = oFsm.pOmciCC.sendStartSoftwareDownload(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 548 | oFsm.pAdaptFsm.commChan, oFsm.inactiveImageMeID, oFsm.omciDownloadWindowSizeLimit, oFsm.origImageLength) |
| 549 | if err != nil { |
| 550 | logger.Errorw(ctx, "StartSwDl abort: can't send section", log.Fields{ |
| 551 | "device-id": oFsm.deviceID, "error": err}) |
| 552 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
| 553 | pBaseFsm := oFsm.pAdaptFsm |
| 554 | // Can't call FSM Event directly, decoupling it |
| 555 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 556 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 557 | }(pBaseFsm) |
| 558 | return |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | func (oFsm *OnuUpgradeFsm) enterDownloadSection(ctx context.Context, e *fsm.Event) { |
| 563 | logger.Debugw(ctx, "OnuUpgradeFsm start downloading sections", log.Fields{ |
| 564 | "device-id": oFsm.deviceID, "absolute window": oFsm.nextDownloadWindow}) |
| 565 | |
| 566 | var windowAckRequest uint8 = 0 |
| 567 | var bufferStartOffset uint32 |
| 568 | var bufferEndOffset uint32 |
| 569 | var downloadSection []byte |
| 570 | framePrint := false //default no printing of downloadSection frames |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 571 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 572 | if oFsm.nextDownloadSectionsAbsolute == 0 { |
| 573 | //debug print of first section frame |
| 574 | framePrint = true |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 575 | oFsm.volthaImageState = voltha.ImageState_IMAGE_DOWNLOADING |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | for { |
| 579 | bufferStartOffset = oFsm.nextDownloadSectionsAbsolute * cOmciDownloadSectionSize |
| 580 | bufferEndOffset = bufferStartOffset + cOmciDownloadSectionSize - 1 //for representing cOmciDownloadSectionSizeLimit values |
| 581 | logger.Debugw(ctx, "DlSection values are", log.Fields{ |
| 582 | "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute, |
| 583 | "DlSectionWindow": oFsm.nextDownloadSectionsWindow, |
| 584 | "startOffset": bufferStartOffset, "endOffset": bufferEndOffset}) |
| 585 | if bufferStartOffset+1 > oFsm.imageLength || bufferEndOffset+1 > oFsm.imageLength { //should never occur in this state |
| 586 | logger.Errorw(ctx, "OnuUpgradeFsm buffer error: exceeded length", log.Fields{ |
| 587 | "device-id": oFsm.deviceID, "bufferStartOffset": bufferStartOffset, |
| 588 | "bufferEndOffset": bufferEndOffset, "imageLength": oFsm.imageLength}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 589 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 590 | //logical error -- reset the FSM |
| 591 | pBaseFsm := oFsm.pAdaptFsm |
| 592 | // Can't call FSM Event directly, decoupling it |
| 593 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 594 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 595 | }(pBaseFsm) |
| 596 | return |
| 597 | } |
| 598 | downloadSection = oFsm.imageBuffer[bufferStartOffset : bufferEndOffset+1] |
| 599 | if oFsm.nextDownloadSectionsWindow == oFsm.omciDownloadWindowSizeLimit { |
| 600 | windowAckRequest = 1 |
| 601 | logger.Debugw(ctx, "DlSection expect Response for complete window", log.Fields{ |
| 602 | "device-id": oFsm.deviceID, "in window": oFsm.nextDownloadWindow}) |
| 603 | } |
| 604 | if oFsm.nextDownloadSectionsAbsolute+1 >= oFsm.noOfSections { |
| 605 | windowAckRequest = 1 |
| 606 | framePrint = true //debug print of last frame |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 607 | oFsm.omciDownloadWindowSizeLast = oFsm.nextDownloadSectionsWindow |
| 608 | logger.Infow(ctx, "DlSection expect Response for last window (section)", log.Fields{ |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 609 | "device-id": oFsm.deviceID, "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute}) |
| 610 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 611 | oFsm.mutexUpgradeParams.Unlock() //unlock here to give other functions some chance to process during/after the send request |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 612 | err := oFsm.pOmciCC.sendDownloadSection(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 613 | oFsm.pAdaptFsm.commChan, oFsm.inactiveImageMeID, windowAckRequest, oFsm.nextDownloadSectionsWindow, downloadSection, framePrint) |
| 614 | if err != nil { |
| 615 | logger.Errorw(ctx, "DlSection abort: can't send section", log.Fields{ |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 616 | "device-id": oFsm.deviceID, "section absolute": oFsm.nextDownloadSectionsAbsolute, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 617 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
| 618 | pBaseFsm := oFsm.pAdaptFsm |
| 619 | // Can't call FSM Event directly, decoupling it |
| 620 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 621 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 622 | }(pBaseFsm) |
| 623 | return |
| 624 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 625 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 626 | oFsm.nextDownloadSectionsAbsolute++ //always increase the absolute section counter after having sent one |
| 627 | if windowAckRequest == 1 { |
| 628 | pBaseFsm := oFsm.pAdaptFsm |
| 629 | // Can't call FSM Event directly, decoupling it |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 630 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 631 | go func(a_pAFsm *AdapterFsm) { |
| 632 | _ = a_pAFsm.pFsm.Event(upgradeEvWaitWindowAck) //state transition to upgradeStVerifyWindow |
| 633 | }(pBaseFsm) |
| 634 | return |
| 635 | } |
| 636 | framePrint = false //for the next Section frame (if wanted, can be enabled in logic before sendXXX()) |
| 637 | 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] | 638 | if oFsm.omciSectionInterleaveDelay > 0 { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 639 | //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] | 640 | 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] | 641 | time.Sleep(oFsm.omciSectionInterleaveDelay * time.Millisecond) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 642 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | func (oFsm *OnuUpgradeFsm) enterVerifyWindow(ctx context.Context, e *fsm.Event) { |
| 648 | logger.Debugw(ctx, "OnuUpgradeFsm verify DL window ack", log.Fields{ |
| 649 | "for window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID}) |
| 650 | } |
| 651 | |
| 652 | func (oFsm *OnuUpgradeFsm) enterFinalizeDL(ctx context.Context, e *fsm.Event) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 653 | logger.Infow(ctx, "OnuUpgradeFsm finalize DL", log.Fields{ |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 654 | "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] | 655 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 656 | oFsm.mutexUpgradeParams.RLock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 657 | if oFsm.delayEndSwDl { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 658 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 659 | //give the ONU some time for image evaluation (hoping it does not base that on first EndSwDl itself) |
| 660 | // should not be set in case this state is used for real download abort (not yet implemented) |
| 661 | time.Sleep(cOmciEndSwDlDelaySeconds * time.Second) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 662 | } else { |
| 663 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 664 | } |
| 665 | |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 666 | pBaseFsm := oFsm.pAdaptFsm |
| 667 | if pBaseFsm == nil { |
| 668 | logger.Errorw(ctx, "EndSwDl abort: BaseFsm invalid", log.Fields{ |
| 669 | "device-id": oFsm.deviceID}) |
| 670 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
| 671 | // Can't call FSM Event directly, decoupling it |
| 672 | go func(a_pAFsm *AdapterFsm) { |
| 673 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 674 | }(pBaseFsm) |
| 675 | return |
| 676 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 677 | err := oFsm.pOmciCC.sendEndSoftwareDownload(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 678 | oFsm.pAdaptFsm.commChan, oFsm.inactiveImageMeID, oFsm.origImageLength, oFsm.imageCRC) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 679 | if err != nil { |
| 680 | logger.Errorw(ctx, "EndSwDl abort: can't send section", log.Fields{ |
| 681 | "device-id": oFsm.deviceID, "error": err}) |
| 682 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 683 | // Can't call FSM Event directly, decoupling it |
| 684 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 685 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 686 | }(pBaseFsm) |
| 687 | return |
| 688 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 689 | // go waiting for the EndSwDLResponse and check, if the ONU is ready for activation |
| 690 | // Can't call FSM Event directly, decoupling it |
| 691 | go func(a_pAFsm *AdapterFsm) { |
| 692 | _ = a_pAFsm.pFsm.Event(upgradeEvWaitEndDownload) |
| 693 | }(pBaseFsm) |
| 694 | } |
| 695 | |
| 696 | func (oFsm *OnuUpgradeFsm) enterWaitEndDL(ctx context.Context, e *fsm.Event) { |
| 697 | logger.Infow(ctx, "OnuUpgradeFsm WaitEndDl", log.Fields{ |
| 698 | "device-id": oFsm.deviceID, "wait delay": oFsm.waitDelayEndSwDl * time.Second, "wait count": oFsm.waitCountEndSwDl}) |
| 699 | if oFsm.waitCountEndSwDl == 0 { |
| 700 | logger.Errorw(ctx, "WaitEndDl abort: max limit of EndSwDL reached", log.Fields{ |
| 701 | "device-id": oFsm.deviceID}) |
| 702 | pBaseFsm := oFsm.pAdaptFsm |
| 703 | if pBaseFsm == nil { |
| 704 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 705 | "device-id": oFsm.deviceID}) |
| 706 | return |
| 707 | } |
| 708 | go func(a_pAFsm *AdapterFsm) { |
| 709 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 710 | }(pBaseFsm) |
| 711 | return |
| 712 | } |
| 713 | |
| 714 | oFsm.waitCountEndSwDl-- |
| 715 | select { |
| 716 | case <-time.After(oFsm.waitDelayEndSwDl * time.Second): |
| 717 | pBaseFsm := oFsm.pAdaptFsm |
| 718 | if pBaseFsm == nil { |
| 719 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 720 | "device-id": oFsm.deviceID}) |
| 721 | //FSM may be reset already from somewhere else, nothing we can do here anymore |
| 722 | return |
| 723 | } |
| 724 | //retry End SW DL |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 725 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 726 | oFsm.delayEndSwDl = false //no more extra delay for the request |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 727 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 728 | go func(a_pAFsm *AdapterFsm) { |
| 729 | _ = a_pAFsm.pFsm.Event(upgradeEvContinueFinalize) |
| 730 | }(pBaseFsm) |
| 731 | return |
| 732 | case success := <-oFsm.chReceiveExpectedResponse: |
| 733 | logger.Debugw(ctx, "WaitEndDl stop wait timer", log.Fields{"device-id": oFsm.deviceID}) |
| 734 | pBaseFsm := oFsm.pAdaptFsm |
| 735 | if pBaseFsm == nil { |
| 736 | logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{ |
| 737 | "device-id": oFsm.deviceID}) |
| 738 | //FSM may be reset already from somewhere else, nothing we can do here anymore |
| 739 | return |
| 740 | } |
| 741 | if success { |
| 742 | //answer received with ready indication |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 743 | if oFsm.activateImage { |
| 744 | //immediate activation requested |
| 745 | go func(a_pAFsm *AdapterFsm) { |
| 746 | _ = a_pAFsm.pFsm.Event(upgradeEvRequestActivate) |
| 747 | }(pBaseFsm) |
| 748 | } else { |
| 749 | //have to wait on explicit activation request |
| 750 | go func(a_pAFsm *AdapterFsm) { |
| 751 | _ = a_pAFsm.pFsm.Event(upgradeEvWaitForActivate) |
| 752 | }(pBaseFsm) |
| 753 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 754 | return |
| 755 | } |
| 756 | //timer was aborted |
| 757 | go func(a_pAFsm *AdapterFsm) { |
| 758 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 759 | }(pBaseFsm) |
| 760 | return |
| 761 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | func (oFsm *OnuUpgradeFsm) enterActivateSw(ctx context.Context, e *fsm.Event) { |
| 765 | logger.Infow(ctx, "OnuUpgradeFsm activate SW", log.Fields{ |
| 766 | "device-id": oFsm.deviceID, "me-id": oFsm.inactiveImageMeID}) |
| 767 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 768 | oFsm.mutexUpgradeParams.Lock() |
| 769 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATING |
| 770 | oFsm.mutexUpgradeParams.Unlock() |
| 771 | |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 772 | err := oFsm.pOmciCC.sendActivateSoftware(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 773 | oFsm.pAdaptFsm.commChan, oFsm.inactiveImageMeID) |
| 774 | if err != nil { |
| 775 | logger.Errorw(ctx, "ActivateSw abort: can't send activate frame", log.Fields{ |
| 776 | "device-id": oFsm.deviceID, "error": err}) |
| 777 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
| 778 | pBaseFsm := oFsm.pAdaptFsm |
| 779 | // Can't call FSM Event directly, decoupling it |
| 780 | go func(a_pAFsm *AdapterFsm) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 781 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 782 | }(pBaseFsm) |
| 783 | return |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | func (oFsm *OnuUpgradeFsm) enterCommitSw(ctx context.Context, e *fsm.Event) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 788 | if activeImageID, err := oFsm.pOnuOmciDevice.GetActiveImageMeID(ctx); err == nil { |
| 789 | //TODO!!: as long as testing with BBSIM and BBSIM not support upgrade tests following check needs to be deactivated |
| 790 | imageFit := true //TODO!!: test workaround as long as BBSIM does not fully support upgrade |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 791 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 792 | if imageFit || activeImageID == oFsm.inactiveImageMeID { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 793 | inactiveImageID := oFsm.inactiveImageMeID |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 794 | logger.Infow(ctx, "OnuUpgradeFsm commit SW", log.Fields{ |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 795 | "device-id": oFsm.deviceID, "me-id": inactiveImageID}) //more efficient activeImageID with above check |
| 796 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTING |
| 797 | oFsm.mutexUpgradeParams.Unlock() |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 798 | err := oFsm.pOmciCC.sendCommitSoftware(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 799 | oFsm.pAdaptFsm.commChan, inactiveImageID) //more efficient activeImageID with above check |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 800 | if err != nil { |
| 801 | logger.Errorw(ctx, "CommitSw abort: can't send commit sw frame", log.Fields{ |
| 802 | "device-id": oFsm.deviceID, "error": err}) |
| 803 | //TODO!!!: define some more sophisticated error treatment with some repetition, for now just reset the FSM |
| 804 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 805 | pBaseFsm := oFsm.pAdaptFsm |
| 806 | // Can't call FSM Event directly, decoupling it |
| 807 | go func(a_pAFsm *AdapterFsm) { |
| 808 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 809 | }(pBaseFsm) |
| 810 | return |
| 811 | } |
| 812 | return |
| 813 | } |
| 814 | logger.Errorw(ctx, "OnuUpgradeFsm active ImageId <> IdToCommit", log.Fields{ |
| 815 | "device-id": oFsm.deviceID, "active ID": activeImageID, "to commit ID": oFsm.inactiveImageMeID}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 816 | oFsm.mutexUpgradeParams.Unlock() |
| 817 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 818 | //TODO!!!: possibly send event information for aborted upgrade (not activated)?? |
| 819 | pBaseFsm := oFsm.pAdaptFsm |
| 820 | // Can't call FSM Event directly, decoupling it |
| 821 | go func(a_pAFsm *AdapterFsm) { |
| 822 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 823 | }(pBaseFsm) |
| 824 | return |
| 825 | } |
| 826 | logger.Errorw(ctx, "OnuUpgradeFsm can't commit, no valid active image", log.Fields{ |
| 827 | "device-id": oFsm.deviceID}) |
| 828 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 829 | pBaseFsm := oFsm.pAdaptFsm |
| 830 | // Can't call FSM Event directly, decoupling it |
| 831 | go func(a_pAFsm *AdapterFsm) { |
| 832 | _ = a_pAFsm.pFsm.Event(upgradeEvAbort) |
| 833 | }(pBaseFsm) |
| 834 | } |
| 835 | |
| 836 | func (oFsm *OnuUpgradeFsm) enterCheckCommitted(ctx context.Context, e *fsm.Event) { |
| 837 | logger.Infow(ctx, "OnuUpgradeFsm checking committed SW", log.Fields{ |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 838 | "device-id": oFsm.deviceID, "me-id": oFsm.inactiveImageMeID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 839 | requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""} |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 840 | meInstance, err := oFsm.pOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 841 | me.SoftwareImageClassID, oFsm.inactiveImageMeID, requestedAttributes, oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, false, oFsm.pAdaptFsm.commChan) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 842 | //accept also nil as (error) return value for writing to LastTx |
| 843 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 844 | if err != nil { |
| 845 | logger.Errorw(ctx, "OnuUpgradeFsm get Software Image ME result error", |
| 846 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
| 847 | pOnuUpgradeFsm := oFsm.pAdaptFsm |
| 848 | if pOnuUpgradeFsm != nil { |
| 849 | go func(a_pAFsm *AdapterFsm) { |
| 850 | _ = a_pAFsm.pFsm.Event(upgradeEvReset) |
| 851 | }(pOnuUpgradeFsm) |
| 852 | } |
| 853 | return |
| 854 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 855 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | func (oFsm *OnuUpgradeFsm) enterResetting(ctx context.Context, e *fsm.Event) { |
| 859 | logger.Debugw(ctx, "OnuUpgradeFsm resetting", log.Fields{"device-id": oFsm.deviceID}) |
| 860 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 861 | // in case the download-to-ONU timer is still running - cancel it |
| 862 | oFsm.mutexIsAwaitingOnuDlResponse.RLock() |
| 863 | if oFsm.isWaitingForOnuDlResponse { |
| 864 | oFsm.mutexIsAwaitingOnuDlResponse.RUnlock() |
| 865 | //use channel to indicate that the download response waiting shall be aborted for this device (channel) |
| 866 | oFsm.chOnuDlReady <- false |
| 867 | } else { |
| 868 | oFsm.mutexIsAwaitingOnuDlResponse.RUnlock() |
| 869 | } |
| 870 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 871 | pConfigupgradeStateAFsm := oFsm.pAdaptFsm |
| 872 | if pConfigupgradeStateAFsm != nil { |
| 873 | // abort running message processing |
| 874 | fsmAbortMsg := Message{ |
| 875 | Type: TestMsg, |
| 876 | Data: TestMessage{ |
| 877 | TestMessageVal: AbortMessageProcessing, |
| 878 | }, |
| 879 | } |
| 880 | pConfigupgradeStateAFsm.commChan <- fsmAbortMsg |
| 881 | |
| 882 | //try to restart the FSM to 'disabled' |
| 883 | // Can't call FSM Event directly, decoupling it |
| 884 | go func(a_pAFsm *AdapterFsm) { |
| 885 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 886 | _ = a_pAFsm.pFsm.Event(upgradeEvRestart) |
| 887 | } |
| 888 | }(pConfigupgradeStateAFsm) |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | func (oFsm *OnuUpgradeFsm) enterDisabled(ctx context.Context, e *fsm.Event) { |
| 893 | logger.Debugw(ctx, "OnuUpgradeFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 894 | // 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] | 895 | if oFsm.pDeviceHandler != nil { |
| 896 | //request removal of 'reference' in the Handler (completely clear the FSM and its data) |
| 897 | go oFsm.pDeviceHandler.removeOnuUpgradeFsm(ctx) |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | func (oFsm *OnuUpgradeFsm) processOmciUpgradeMessages(ctx context.Context) { //ctx context.Context? |
| 902 | logger.Debugw(ctx, "Start OnuUpgradeFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
| 903 | loop: |
| 904 | for { |
| 905 | // case <-ctx.Done(): |
| 906 | // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
| 907 | // break loop |
| 908 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 909 | if !ok { |
| 910 | logger.Info(ctx, "OnuUpgradeFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
| 911 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 912 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 913 | break loop |
| 914 | } |
| 915 | logger.Debugw(ctx, "OnuUpgradeFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
| 916 | |
| 917 | switch message.Type { |
| 918 | case TestMsg: |
| 919 | msg, _ := message.Data.(TestMessage) |
| 920 | if msg.TestMessageVal == AbortMessageProcessing { |
| 921 | logger.Infow(ctx, "OnuUpgradeFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
| 922 | break loop |
| 923 | } |
| 924 | logger.Warnw(ctx, "OnuUpgradeFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 925 | case OMCI: |
| 926 | msg, _ := message.Data.(OmciMessage) |
| 927 | oFsm.handleOmciOnuUpgradeMessage(ctx, msg) |
| 928 | default: |
| 929 | logger.Warn(ctx, "OnuUpgradeFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
| 930 | "message.Type": message.Type}) |
| 931 | } |
| 932 | } |
| 933 | logger.Infow(ctx, "End OnuUpgradeFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
| 934 | } |
| 935 | |
| 936 | //nolint: gocyclo |
| 937 | func (oFsm *OnuUpgradeFsm) handleOmciOnuUpgradeMessage(ctx context.Context, msg OmciMessage) { |
| 938 | logger.Debugw(ctx, "Rx OMCI OnuUpgradeFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
| 939 | "msgType": msg.OmciMsg.MessageType}) |
| 940 | |
| 941 | switch msg.OmciMsg.MessageType { |
| 942 | case omci.StartSoftwareDownloadResponseType: |
| 943 | { |
| 944 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeStartSoftwareDownloadResponse) |
| 945 | if msgLayer == nil { |
| 946 | logger.Errorw(ctx, "Omci Msg layer could not be detected for StartSwDlResponse", |
| 947 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 948 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 949 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 950 | return |
| 951 | } |
| 952 | msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadResponse) |
| 953 | if !msgOk { |
| 954 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for StartSwDlResponse", |
| 955 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 956 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 957 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 958 | return |
| 959 | } |
| 960 | logger.Debugw(ctx, "OnuUpgradeFsm StartSwDlResponse data", log.Fields{ |
| 961 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 962 | if msgObj.Result != me.Success { |
| 963 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse result error - later: drive FSM to abort state ?", |
| 964 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 965 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 966 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 967 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 968 | return |
| 969 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 970 | |
| 971 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 972 | if msgObj.EntityInstance == oFsm.inactiveImageMeID { |
| 973 | logger.Debugw(ctx, "Expected StartSwDlResponse received", log.Fields{"device-id": oFsm.deviceID}) |
| 974 | if msgObj.WindowSize != oFsm.omciDownloadWindowSizeLimit { |
| 975 | // also response WindowSize = 0 is a valid number for used Window size 1 |
| 976 | logger.Debugw(ctx, "different StartSwDlResponse window size requested by ONU", log.Fields{ |
| 977 | "acceptedOnuWindowSizeLimit": msgObj.WindowSize, "device-id": oFsm.deviceID}) |
| 978 | oFsm.omciDownloadWindowSizeLimit = msgObj.WindowSize |
| 979 | } |
| 980 | oFsm.noOfWindows = oFsm.noOfSections / uint32(oFsm.omciDownloadWindowSizeLimit+1) |
| 981 | if oFsm.noOfSections%uint32(oFsm.omciDownloadWindowSizeLimit+1) > 0 { |
| 982 | oFsm.noOfWindows++ |
| 983 | } |
| 984 | logger.Debugw(ctx, "OnuUpgradeFsm will use", log.Fields{ |
| 985 | "windows": oFsm.noOfWindows, "sections": oFsm.noOfSections, |
| 986 | "at WindowSizeLimit": oFsm.omciDownloadWindowSizeLimit}) |
| 987 | oFsm.nextDownloadSectionsAbsolute = 0 |
| 988 | oFsm.nextDownloadSectionsWindow = 0 |
| 989 | oFsm.nextDownloadWindow = 0 |
| 990 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 991 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 992 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvRxStartSwDownload) |
| 993 | return |
| 994 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 995 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 996 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: try again (later)?", |
| 997 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 998 | // TODO!!!: possibly repeat the start request (once)? |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 999 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1000 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1001 | return |
| 1002 | } //StartSoftwareDownloadResponseType |
| 1003 | case omci.DownloadSectionResponseType: |
| 1004 | { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1005 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDownloadSectionResponse) |
| 1006 | if msgLayer == nil { |
| 1007 | logger.Errorw(ctx, "Omci Msg layer could not be detected for DlSectionResponse", |
| 1008 | log.Fields{"device-id": oFsm.deviceID, "omci-message": msg.OmciMsg}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1009 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1010 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1011 | return |
| 1012 | } |
| 1013 | msgObj, msgOk := msgLayer.(*omci.DownloadSectionResponse) |
| 1014 | if !msgOk { |
| 1015 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for DlSectionResponse", |
| 1016 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1017 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1018 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1019 | return |
| 1020 | } |
| 1021 | logger.Debugw(ctx, "OnuUpgradeFsm DlSectionResponse Data", log.Fields{ |
| 1022 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1023 | if msgObj.Result != me.Success { |
| 1024 | logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse result error - later: repeat window once?", //TODO!!! |
| 1025 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1026 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1027 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1028 | return |
| 1029 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1030 | oFsm.mutexUpgradeParams.Lock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1031 | if msgObj.EntityInstance == oFsm.inactiveImageMeID { |
| 1032 | sectionNumber := msgObj.SectionNumber |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1033 | logger.Infow(ctx, "DlSectionResponse received", log.Fields{ |
| 1034 | "window section-number": sectionNumber, "window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1035 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1036 | oFsm.nextDownloadWindow++ |
| 1037 | if oFsm.nextDownloadWindow >= oFsm.noOfWindows { |
| 1038 | if sectionNumber != oFsm.omciDownloadWindowSizeLast { |
mpagenko | 02cf1b2 | 2021-03-12 17:30:30 +0000 | [diff] [blame] | 1039 | 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] | 1040 | log.Fields{"device-id": oFsm.deviceID, "actual section": sectionNumber, |
| 1041 | "expected section": oFsm.omciDownloadWindowSizeLast}) |
| 1042 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1043 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1044 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1045 | return |
| 1046 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1047 | oFsm.delayEndSwDl = true //ensure a delay for the EndSwDl message |
| 1048 | //CRC computation for all data bytes of the file |
| 1049 | imageCRC := crc32a.Checksum(oFsm.imageBuffer[:int(oFsm.origImageLength)]) //store internal for multiple usage |
| 1050 | //revert the retrieved CRC Byte Order (seems not to deliver NetworkByteOrder) |
| 1051 | var byteSlice []byte = make([]byte, 4) |
| 1052 | binary.LittleEndian.PutUint32(byteSlice, uint32(imageCRC)) |
| 1053 | oFsm.imageCRC = binary.BigEndian.Uint32(byteSlice) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1054 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1055 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvEndSwDownload) |
| 1056 | return |
| 1057 | } |
| 1058 | if sectionNumber != oFsm.omciDownloadWindowSizeLimit { |
| 1059 | logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse section error - later: repeat window once?", //TODO!!! |
mpagenko | 02cf1b2 | 2021-03-12 17:30:30 +0000 | [diff] [blame] | 1060 | log.Fields{"device-id": oFsm.deviceID, "actual-section": sectionNumber, |
| 1061 | "expected section": oFsm.omciDownloadWindowSizeLimit}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1062 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1063 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1064 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1065 | return |
| 1066 | } |
| 1067 | oFsm.nextDownloadSectionsWindow = 0 |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1068 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1069 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvContinueNextWindow) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1070 | return |
| 1071 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1072 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1073 | logger.Errorw(ctx, "OnuUpgradeFsm Omci StartSwDlResponse wrong ME instance: try again (later)?", |
| 1074 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1075 | // TODO!!!: possibly repeat the download (section) (once)? |
| 1076 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1077 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1078 | return |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1079 | } //DownloadSectionResponseType |
| 1080 | case omci.EndSoftwareDownloadResponseType: |
| 1081 | { |
| 1082 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeEndSoftwareDownloadResponse) |
| 1083 | if msgLayer == nil { |
| 1084 | logger.Errorw(ctx, "Omci Msg layer could not be detected for EndSwDlResponse", |
| 1085 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1086 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1087 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1088 | return |
| 1089 | } |
| 1090 | msgObj, msgOk := msgLayer.(*omci.EndSoftwareDownloadResponse) |
| 1091 | if !msgOk { |
| 1092 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for EndSwDlResponse", |
| 1093 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1094 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1095 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1096 | return |
| 1097 | } |
| 1098 | logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse data", log.Fields{ |
| 1099 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1100 | if msgObj.Result != me.Success { |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1101 | if msgObj.Result == me.DeviceBusy { |
| 1102 | //ONU indicates it is still processing the image - let the FSM just wait and then repeat the request |
| 1103 | logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse busy: waiting before sending new request", log.Fields{ |
| 1104 | "device-id": oFsm.deviceID}) |
| 1105 | return |
| 1106 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1107 | logger.Errorw(ctx, "OnuUpgradeFsm EndSwDlResponse result error - later: drive FSM to abort state ?", |
| 1108 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1109 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1110 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1111 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1112 | return |
| 1113 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1114 | oFsm.mutexUpgradeParams.RLock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1115 | if msgObj.EntityInstance == oFsm.inactiveImageMeID { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1116 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1117 | logger.Debugw(ctx, "Expected EndSwDlResponse received", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1118 | oFsm.mutexIsAwaitingOnuDlResponse.RLock() |
| 1119 | if oFsm.isWaitingForOnuDlResponse { |
| 1120 | oFsm.mutexIsAwaitingOnuDlResponse.RUnlock() |
| 1121 | //use channel to indicate that the download to ONU was successful |
| 1122 | oFsm.chOnuDlReady <- true |
| 1123 | } else { |
| 1124 | oFsm.mutexIsAwaitingOnuDlResponse.RUnlock() |
| 1125 | } |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1126 | oFsm.chReceiveExpectedResponse <- true //let the FSM proceed from the waitState |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1127 | return |
| 1128 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1129 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1130 | logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: try again (later)?", |
| 1131 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1132 | // TODO!!!: possibly repeat the end request (once)? or verify ONU upgrade state? |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1133 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1134 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1135 | return |
| 1136 | } //EndSoftwareDownloadResponseType |
| 1137 | case omci.ActivateSoftwareResponseType: |
| 1138 | { |
| 1139 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeActivateSoftwareResponse) |
| 1140 | if msgLayer == nil { |
| 1141 | logger.Errorw(ctx, "Omci Msg layer could not be detected for ActivateSw", |
| 1142 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1143 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1144 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1145 | return |
| 1146 | } |
| 1147 | msgObj, msgOk := msgLayer.(*omci.ActivateSoftwareResponse) |
| 1148 | if !msgOk { |
| 1149 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for ActivateSw", |
| 1150 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1151 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1152 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1153 | return |
| 1154 | } |
| 1155 | logger.Debugw(ctx, "OnuUpgradeFsm ActivateSwResponse data", log.Fields{ |
| 1156 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1157 | if msgObj.Result != me.Success { |
| 1158 | logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse result error - later: drive FSM to abort state ?", |
| 1159 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1160 | // TODO!!!: error treatment?, perhaps in the end reset the FSM |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1161 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1162 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1163 | return |
| 1164 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1165 | oFsm.mutexUpgradeParams.RLock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1166 | if msgObj.EntityInstance == oFsm.inactiveImageMeID { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1167 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 02cf1b2 | 2021-03-12 17:30:30 +0000 | [diff] [blame] | 1168 | logger.Infow(ctx, "Expected ActivateSwResponse received", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1169 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvWaitForCommit) |
| 1170 | return |
| 1171 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1172 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1173 | logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse wrong ME instance: abort", |
| 1174 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1175 | // TODO!!!: error treatment? |
| 1176 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1177 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1178 | return |
| 1179 | } //ActivateSoftwareResponseType |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1180 | case omci.CommitSoftwareResponseType: |
| 1181 | { |
| 1182 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCommitSoftwareResponse) |
| 1183 | if msgLayer == nil { |
| 1184 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CommitResponse", |
| 1185 | log.Fields{"device-id": oFsm.deviceID}) |
| 1186 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1187 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1188 | return |
| 1189 | } |
| 1190 | msgObj, msgOk := msgLayer.(*omci.CommitSoftwareResponse) |
| 1191 | if !msgOk { |
| 1192 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CommitResponse", |
| 1193 | log.Fields{"device-id": oFsm.deviceID}) |
| 1194 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1195 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1196 | return |
| 1197 | } |
mpagenko | bf67a09 | 2021-03-17 09:52:28 +0000 | [diff] [blame] | 1198 | if msgObj.Result != me.Success { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1199 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse result error - later: drive FSM to abort state ?", |
| 1200 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1201 | // TODO!!!: error treatment?, perhaps in the end reset the FSM |
| 1202 | return |
mpagenko | bf67a09 | 2021-03-17 09:52:28 +0000 | [diff] [blame] | 1203 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1204 | oFsm.mutexUpgradeParams.RLock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1205 | if msgObj.EntityInstance == oFsm.inactiveImageMeID { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1206 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1207 | logger.Debugw(ctx, "OnuUpgradeFsm Expected SwImage CommitResponse received", log.Fields{"device-id": oFsm.deviceID}) |
| 1208 | //verifying committed image |
| 1209 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvCheckCommitted) |
| 1210 | return |
| 1211 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1212 | oFsm.mutexUpgradeParams.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1213 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse wrong ME instance: abort", |
| 1214 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1215 | // TODO!!!: error treatment? |
| 1216 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1217 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1218 | return |
| 1219 | } //CommitSoftwareResponseType |
| 1220 | case omci.GetResponseType: |
| 1221 | { |
| 1222 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 1223 | if msgLayer == nil { |
| 1224 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SwImage GetResponse", |
| 1225 | log.Fields{"device-id": oFsm.deviceID}) |
| 1226 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1227 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1228 | return |
| 1229 | } |
| 1230 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 1231 | if !msgOk { |
| 1232 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SwImage GetResponse", |
| 1233 | log.Fields{"device-id": oFsm.deviceID}) |
| 1234 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1235 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1236 | return |
| 1237 | } |
| 1238 | logger.Debugw(ctx, "OnuUpgradeFsm SwImage GetResponse data", log.Fields{ |
| 1239 | "device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1240 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1241 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1242 | if msgObj.Result != me.Success { |
| 1243 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse result error - later: drive FSM to abort state ?", |
| 1244 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1245 | // TODO!!!: error treatment?, perhaps in the end reset the FSM |
| 1246 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1247 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1248 | return |
| 1249 | } |
| 1250 | } else { |
| 1251 | logger.Warnw(ctx, "OnuUpgradeFsm SwImage unexpected Entity GetResponse data - ignore", |
| 1252 | log.Fields{"device-id": oFsm.deviceID}) |
| 1253 | return |
| 1254 | } |
| 1255 | |
| 1256 | meAttributes := msgObj.Attributes |
| 1257 | imageIsCommitted := meAttributes["IsCommitted"].(uint8) |
| 1258 | imageIsActive := meAttributes["IsActive"].(uint8) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1259 | imageVersion := TrimStringFromMeOctet(meAttributes["Version"]) |
mpagenko | 02cf1b2 | 2021-03-12 17:30:30 +0000 | [diff] [blame] | 1260 | logger.Debugw(ctx, "OnuUpgradeFsm - GetResponse Data for SoftwareImage", |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1261 | log.Fields{"device-id": oFsm.deviceID, "entityID": msgObj.EntityInstance, |
| 1262 | "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1263 | |
| 1264 | oFsm.mutexUpgradeParams.Lock() |
| 1265 | if msgObj.EntityInstance == oFsm.inactiveImageMeID && imageIsActive == swIsActive { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1266 | //a check on the delivered image version is not done, the ONU delivered version might be different from what might have been |
| 1267 | // indicated in the download image version string (version must be part of the image content itself) |
| 1268 | // so checking that might be quite unreliable |
| 1269 | //but with new API this was changed, assumption is that omci image version is known at download request and exactly that is used |
| 1270 | // in all the API references, so it can and should be checked here now |
| 1271 | if oFsm.useAPIVersion43 { |
| 1272 | if imageVersion != oFsm.imageVersion { |
| 1273 | //new active version indicated on OMCI from ONU is not the expected version |
| 1274 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade", |
| 1275 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance, |
| 1276 | "onu-version": imageVersion, "expected-version": oFsm.imageVersion}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1277 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1278 | // TODO!!!: error treatment? |
| 1279 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1280 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1281 | return |
| 1282 | } |
| 1283 | logger.Debugw(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU", |
| 1284 | log.Fields{"device-id": oFsm.deviceID}) |
| 1285 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1286 | oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVE |
| 1287 | if imageIsCommitted == swIsCommitted { |
| 1288 | oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_SUCCEEDED |
| 1289 | oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTED |
| 1290 | logger.Infow(ctx, "requested SW image committed, releasing OnuUpgrade", log.Fields{"device-id": oFsm.deviceID}) |
| 1291 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent)) //to let the handler now about success |
| 1292 | oFsm.mutexUpgradeParams.Unlock() |
| 1293 | //releasing the upgrade FSM |
| 1294 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvReset) |
| 1295 | return |
| 1296 | } |
| 1297 | oFsm.mutexUpgradeParams.Unlock() |
| 1298 | return //if the imageId is active but not committed let upgrade persist, maybe ONU reboot or manual commit may resolve the situation |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1299 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1300 | oFsm.mutexUpgradeParams.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1301 | logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade", |
| 1302 | log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance}) |
| 1303 | // TODO!!!: error treatment? |
| 1304 | //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)?? |
| 1305 | _ = oFsm.pAdaptFsm.pFsm.Event(upgradeEvAbort) |
| 1306 | return |
| 1307 | } //GetResponseType |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1308 | default: |
| 1309 | { |
| 1310 | logger.Errorw(ctx, "Rx OMCI unhandled MsgType", |
| 1311 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
| 1312 | return |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1317 | //waitOnDownloadToAdapterReady state can only be reached with useAPIVersion43 (usage of pFileManager) |
| 1318 | func (oFsm *OnuUpgradeFsm) waitOnDownloadToAdapterReady(ctx context.Context, aWaitChannel chan bool) { |
| 1319 | downloadToAdapterTimeout := oFsm.pFileManager.GetDownloadTimeout(ctx) |
| 1320 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1321 | oFsm.isWaitingForAdapterDlResponse = true |
| 1322 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1323 | select { |
| 1324 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 1325 | // case <-ctx.Done(): |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1326 | // logger.Infow("OnuUpgradeFsm-waitOnDownloadToAdapterReady canceled", log.Fields{"for device-id": oFsm.deviceID}) |
| 1327 | case <-time.After(downloadToAdapterTimeout): //10s should be enough for downloading some image to the adapter |
| 1328 | logger.Warnw(ctx, "OnuUpgradeFsm Waiting-adapter-download timeout", log.Fields{ |
| 1329 | "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToAdapterTimeout}) |
| 1330 | oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel) |
| 1331 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1332 | oFsm.isWaitingForAdapterDlResponse = false |
| 1333 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
| 1334 | //the upgrade process has to be aborted |
| 1335 | pUpgradeFsm := oFsm.pAdaptFsm |
| 1336 | if pUpgradeFsm != nil { |
| 1337 | _ = pUpgradeFsm.pFsm.Event(upgradeEvReset) |
| 1338 | } else { |
| 1339 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1340 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1341 | return |
| 1342 | |
| 1343 | case success := <-aWaitChannel: |
| 1344 | if success { |
| 1345 | logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded received", log.Fields{"device-id": oFsm.deviceID}) |
| 1346 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1347 | oFsm.isWaitingForAdapterDlResponse = false |
| 1348 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
| 1349 | //let the upgrade process proceed |
| 1350 | pUpgradeFsm := oFsm.pAdaptFsm |
| 1351 | if pUpgradeFsm != nil { |
| 1352 | _ = pUpgradeFsm.pFsm.Event(upgradeEvPrepareSwDownload) |
| 1353 | } else { |
| 1354 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1355 | } |
| 1356 | return |
| 1357 | } |
| 1358 | // waiting was aborted (probably on external request) |
| 1359 | logger.Debugw(ctx, "OnuUpgradeFsm Waiting-adapter-download aborted", log.Fields{"device-id": oFsm.deviceID}) |
| 1360 | oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel) |
| 1361 | oFsm.mutexIsAwaitingAdapterDlResponse.Lock() |
| 1362 | oFsm.isWaitingForAdapterDlResponse = false |
| 1363 | oFsm.mutexIsAwaitingAdapterDlResponse.Unlock() |
| 1364 | //the upgrade process has to be aborted |
| 1365 | pUpgradeFsm := oFsm.pAdaptFsm |
| 1366 | if pUpgradeFsm != nil { |
| 1367 | _ = pUpgradeFsm.pFsm.Event(upgradeEvAbort) |
| 1368 | } else { |
| 1369 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1370 | } |
| 1371 | return |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1372 | } |
| 1373 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1374 | |
| 1375 | //waitOnDownloadToOnuReady state can only be reached with useAPIVersion43 (usage of pFileManager) |
| 1376 | func (oFsm *OnuUpgradeFsm) waitOnDownloadToOnuReady(ctx context.Context, aWaitChannel chan bool) { |
| 1377 | downloadToOnuTimeout := time.Duration(1+(oFsm.imageLength/0x400000)) * oFsm.downloadToOnuTimeout4MB |
| 1378 | logger.Debugw(ctx, "OnuUpgradeFsm start download-to-ONU timer", log.Fields{"device-id": oFsm.deviceID, |
| 1379 | "duration": downloadToOnuTimeout}) |
| 1380 | oFsm.mutexIsAwaitingOnuDlResponse.Lock() |
| 1381 | oFsm.isWaitingForOnuDlResponse = true |
| 1382 | oFsm.mutexIsAwaitingOnuDlResponse.Unlock() |
| 1383 | select { |
| 1384 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 1385 | // case <-ctx.Done(): |
| 1386 | // logger.Infow("OnuUpgradeFsm-waitOnDownloadToOnuReady canceled", log.Fields{"for device-id": oFsm.deviceID}) |
| 1387 | case <-time.After(downloadToOnuTimeout): //using an image-size depending timout (in minutes) |
| 1388 | logger.Warnw(ctx, "OnuUpgradeFsm Waiting-ONU-download timeout", log.Fields{ |
| 1389 | "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToOnuTimeout}) |
| 1390 | oFsm.mutexIsAwaitingOnuDlResponse.Lock() |
| 1391 | oFsm.isWaitingForOnuDlResponse = false |
| 1392 | oFsm.mutexIsAwaitingOnuDlResponse.Unlock() |
| 1393 | //the upgrade process has to be aborted |
| 1394 | pUpgradeFsm := oFsm.pAdaptFsm |
| 1395 | if pUpgradeFsm != nil { |
| 1396 | _ = pUpgradeFsm.pFsm.Event(upgradeEvAbort) |
| 1397 | } else { |
| 1398 | logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID}) |
| 1399 | } |
| 1400 | return |
| 1401 | |
| 1402 | case success := <-aWaitChannel: |
| 1403 | if success { |
| 1404 | logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded on ONU received", log.Fields{"device-id": oFsm.deviceID}) |
| 1405 | oFsm.mutexIsAwaitingOnuDlResponse.Lock() |
| 1406 | oFsm.isWaitingForOnuDlResponse = false |
| 1407 | oFsm.mutexIsAwaitingOnuDlResponse.Unlock() |
| 1408 | //all fine, let the FSM proceed like defined from the sender of this event |
| 1409 | return |
| 1410 | } |
| 1411 | // waiting was aborted (assumed here to be caused by |
| 1412 | // error detection or cancel at download after upgrade FSM reset/abort) |
| 1413 | logger.Debugw(ctx, "OnuUpgradeFsm Waiting-ONU-download aborted", log.Fields{"device-id": oFsm.deviceID}) |
| 1414 | oFsm.mutexIsAwaitingOnuDlResponse.Lock() |
| 1415 | oFsm.isWaitingForOnuDlResponse = false |
| 1416 | oFsm.mutexIsAwaitingOnuDlResponse.Unlock() |
| 1417 | return |
| 1418 | } |
| 1419 | } |