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