blob: 43ad62113063a1f46092b8d923d5f3d3e6b0a438 [file] [log] [blame]
mpagenko80622a52021-02-09 16:53:23 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package swupg provides the utilities for onu sw upgrade
18package swupg
mpagenko80622a52021-02-09 16:53:23 +000019
20import (
21 "context"
mpagenkoc26d4c02021-05-06 14:27:57 +000022 "encoding/binary"
mpagenko80622a52021-02-09 16:53:23 +000023 "fmt"
24 "strconv"
mpagenkoc26d4c02021-05-06 14:27:57 +000025 "sync"
mpagenko80622a52021-02-09 16:53:23 +000026 "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"
khenaidoo7d3c5582021-08-11 18:09:44 -040032 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000033 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
34 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
khenaidoo7d3c5582021-08-11 18:09:44 -040035 "github.com/opencord/voltha-protos/v5/go/voltha"
mpagenko80622a52021-02-09 16:53:23 +000036)
37
38const cMaxUint32 = ^uint32(0)
39
40const (
41 // internal predefined values - some off them should later be configurable (perhaps with theses as defaults)
42 cOmciDownloadSectionSize = 31 //in bytes
43 cOmciDownloadWindowSizeLimit = 31 //in sections for window offset (windowSize(32)-1)
44 //cOmciDownloadWindowRetryMax = 2 // max attempts for a specific window
mpagenkoc26d4c02021-05-06 14:27:57 +000045 cOmciSectionInterleaveMilliseconds = 0 //DownloadSection interleave time in milliseconds (0 for no delay)
46 cOmciEndSwDlDelaySeconds = 1 //End Software Download delay after last section (may be also configurable?)
47 cWaitCountEndSwDl = 6 //maximum number of EndSwDl requests
48 cWaitDelayEndSwDlSeconds = 10 //duration, how long is waited before next request on EndSwDl
mpagenko80622a52021-02-09 16:53:23 +000049 //cOmciDownloadCompleteTimeout = 5400 //in s for the complete timeout (may be better scale to image size/ noOfWindows)
50)
51
mpagenko45586762021-10-01 08:30:22 +000052// tEndSwDlResponseResult - Response result from EndSwDownload as used in channel indication
53type tUpgradePhase uint8
54
55const (
56 // undefined phase
57 cUpgradeUndefined tUpgradePhase = iota
58 // downloading image
59 cUpgradeDownloading
60 // image downloaded
61 cUpgradeDownloaded
62 // activating image
63 cUpgradeActivating
64 // image activated
65 cUpgradeActivated
66 // committing image
67 cUpgradeCommitting
68 // image committed
69 cUpgradeCommitted
70)
71
72// tEndSwDlResponseResult - Response result from EndSwDownload as used in channel indication
73type tEndSwDlResponseResult uint8
74
75const (
76 // response success
77 cEndSwDlResponseSuccess tEndSwDlResponseResult = iota
78 // response busy (repeat)
79 cEndSwDlResponseBusy
80 // response error or abort waiting for response
81 cEndSwDlResponseAbort
82)
83
84// upgrade FSM related events
mpagenko80622a52021-02-09 16:53:23 +000085const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000086 UpgradeEvStart = "UpgradeEvStart"
87 UpgradeEvDisable = "UpgradeEvDisable"
88 UpgradeEvAdapterDownload = "UpgradeEvAdapterDownload"
89 UpgradeEvPrepareSwDownload = "UpgradeEvPrepareSwDownload"
90 UpgradeEvRxStartSwDownload = "UpgradeEvRxStartSwDownload"
91 UpgradeEvWaitWindowAck = "UpgradeEvWaitWindowAck"
92 UpgradeEvContinueNextWindow = "UpgradeEvContinueNextWindow"
93 UpgradeEvEndSwDownload = "UpgradeEvEndSwDownload"
94 UpgradeEvWaitEndDownload = "UpgradeEvWaitEndDownload"
95 UpgradeEvContinueFinalize = "UpgradeEvContinueFinalize"
96 UpgradeEvCheckImageName = "UpgradeEvCheckImageName"
97 UpgradeEvWaitForActivate = "UpgradeEvWaitForActivate"
98 UpgradeEvRequestActivate = "UpgradeEvRequestActivate"
99 UpgradeEvActivationDone = "UpgradeEvActivationDone"
100 UpgradeEvWaitForCommit = "UpgradeEvWaitForCommit"
101 UpgradeEvCommitSw = "UpgradeEvCommitSw"
102 UpgradeEvCheckCommitted = "UpgradeEvCheckCommitted"
mpagenko80622a52021-02-09 16:53:23 +0000103
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000104 //UpgradeEvTimeoutSimple = "UpgradeEvTimeoutSimple"
105 //UpgradeEvTimeoutMids = "UpgradeEvTimeoutMids"
106 UpgradeEvReset = "UpgradeEvReset"
107 UpgradeEvAbort = "UpgradeEvAbort"
108 UpgradeEvRestart = "UpgradeEvRestart"
109 UpgradeEvAbortSwDownload = "UpgradeEvAbortSwDownload"
mpagenko80622a52021-02-09 16:53:23 +0000110)
111
mpagenko45586762021-10-01 08:30:22 +0000112// upgrade FSM related states
mpagenko80622a52021-02-09 16:53:23 +0000113const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000114 UpgradeStDisabled = "UpgradeStDisabled"
115 UpgradeStStarting = "UpgradeStStarting"
116 UpgradeStWaitingAdapterDL = "UpgradeStWaitingAdapterDL"
117 UpgradeStPreparingDL = "UpgradeStPreparingDL"
118 UpgradeStDLSection = "UpgradeStDLSection"
119 UpgradeStVerifyWindow = "UpgradeStVerifyWindow"
120 UpgradeStFinalizeDL = "UpgradeStFinalizeDL"
121 UpgradeStWaitEndDL = "UpgradeStWaitEndDL"
122 UpgradeStCheckImageName = "UpgradeStCheckImageName"
123 UpgradeStWaitForActivate = "UpgradeStWaitForActivate"
124 UpgradeStRequestingActivate = "UpgradeStRequestingActivate"
125 UpgradeStActivated = "UpgradeStActivated"
126 UpgradeStWaitForCommit = "UpgradeStWaitForCommit"
127 UpgradeStCommitSw = "UpgradeStCommitSw"
128 UpgradeStCheckCommitted = "UpgradeStCheckCommitted"
129 UpgradeStResetting = "UpgradeStResetting"
130 UpgradeStRestarting = "UpgradeStRestarting"
131 UpgradeStAbortingDL = "UpgradeStAbortingDL"
mpagenko80622a52021-02-09 16:53:23 +0000132)
133
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000134//COnuUpgradeFsmIdleState - required definition for IdleState detection for activities on OMCI
135const COnuUpgradeFsmIdleState = UpgradeStWaitForCommit
mpagenko80622a52021-02-09 16:53:23 +0000136
137//OnuUpgradeFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
138type OnuUpgradeFsm struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 pDeviceHandler cmn.IdeviceHandler
140 pDownloadManager *AdapterDownloadManager
141 pFileManager *FileDownloadManager //used from R2.8 with new API version
mpagenko80622a52021-02-09 16:53:23 +0000142 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000143 pDevEntry cmn.IonuDeviceEntry
144 pOmciCC *cmn.OmciCC
145 pOnuDB *devdb.OnuDeviceDB
146 requestEvent cmn.OnuDeviceEvent
mpagenko80622a52021-02-09 16:53:23 +0000147 //omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000148 PAdaptFsm *cmn.AdapterFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000149 pImageDsc *voltha.ImageDownload
150 imageBuffer []byte
151 origImageLength uint32 //as also limited by OMCI
152 imageCRC uint32 //as per OMCI - ITU I.363.5 crc
153 imageLength uint32 //including last bytes padding
154 omciDownloadWindowSizeLimit uint8 //windowSize-1 in sections
155 omciDownloadWindowSizeLast uint8 //number of sections in last window
156 noOfSections uint32 //uint32 range for sections should be sufficient for very long images
157 nextDownloadSectionsAbsolute uint32 //number of next section to download in overall image
158 nextDownloadSectionsWindow uint8 //number of next section to download within current window
159 noOfWindows uint32 //uint32 range for windows should be sufficient for very long images
160 nextDownloadWindow uint32 //number of next window to download
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000161 InactiveImageMeID uint16 //ME-ID of the inactive image
mpagenkoc26d4c02021-05-06 14:27:57 +0000162 downloadToOnuTimeout4MB time.Duration //timeout for downloading the image to the ONU for a 4MB image slice
163 omciSectionInterleaveDelay time.Duration //DownloadSectionInterleave delay in milliseconds
164 delayEndSwDl bool //flag to provide a delay between last section and EndSwDl
mpagenko45586762021-10-01 08:30:22 +0000165 repeatAbort bool //flag to indicate if OMCI EndSwDownload (abort) is to be repeated
mpagenkoc26d4c02021-05-06 14:27:57 +0000166 pLastTxMeInstance *me.ManagedEntity
167 waitCountEndSwDl uint8 //number, how often is waited for EndSwDl at maximum
168 waitDelayEndSwDl time.Duration //duration, how long is waited before next request on EndSwDl
169 chReceiveExpectedResponse chan bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000170 useAPIVersion43 bool //flag for indication on which API version is used (and accordingly which specific methods)
171 mutexUpgradeParams sync.RWMutex //mutex to protect members for parallel function requests and omci response processing
172 imageVersion string //name of the image as used within OMCI (and on extrenal API interface)
173 imageIdentifier string //name of the image as used in the adapter
mpagenkoc26d4c02021-05-06 14:27:57 +0000174 mutexIsAwaitingAdapterDlResponse sync.RWMutex
175 chAdapterDlReady chan bool
176 isWaitingForAdapterDlResponse bool
mpagenkoc26d4c02021-05-06 14:27:57 +0000177 chOnuDlReady chan bool
mpagenkoc26d4c02021-05-06 14:27:57 +0000178 activateImage bool
179 commitImage bool
mpagenko38662d02021-08-11 09:45:19 +0000180 mutexAbortRequest sync.RWMutex
181 abortRequested voltha.ImageState_ImageFailureReason
182 conditionalCancelRequested bool
mpagenko45586762021-10-01 08:30:22 +0000183 upgradePhase tUpgradePhase
mpagenkoaa3afe92021-05-21 16:20:58 +0000184 volthaDownloadState voltha.ImageState_ImageDownloadState
185 volthaDownloadReason voltha.ImageState_ImageFailureReason
186 volthaImageState voltha.ImageState_ImageActivationState
mpagenko45586762021-10-01 08:30:22 +0000187 downloadReasonCached voltha.ImageState_ImageFailureReason
Holger Hildebrandt288d9472021-09-06 10:47:53 +0000188 isEndSwDlOpen bool
mpagenko45586762021-10-01 08:30:22 +0000189 chReceiveAbortEndSwDlResponse chan tEndSwDlResponseResult
mpagenko80622a52021-02-09 16:53:23 +0000190}
191
192//NewOnuUpgradeFsm is the 'constructor' for the state machine to config the PON ANI ports
193// of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000194func NewOnuUpgradeFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler,
195 apDevEntry cmn.IonuDeviceEntry, apOnuDB *devdb.OnuDeviceDB,
196 aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message) *OnuUpgradeFsm {
mpagenko80622a52021-02-09 16:53:23 +0000197 instFsm := &OnuUpgradeFsm{
mpagenko59498c12021-03-18 14:15:15 +0000198 pDeviceHandler: apDeviceHandler,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000199 deviceID: apDeviceHandler.GetDeviceID(),
mpagenko38662d02021-08-11 09:45:19 +0000200 pDevEntry: apDevEntry,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000201 pOmciCC: apDevEntry.GetDevOmciCC(),
mpagenko59498c12021-03-18 14:15:15 +0000202 pOnuDB: apOnuDB,
203 requestEvent: aRequestEvent,
204 omciDownloadWindowSizeLimit: cOmciDownloadWindowSizeLimit,
205 omciSectionInterleaveDelay: cOmciSectionInterleaveMilliseconds,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000206 downloadToOnuTimeout4MB: apDeviceHandler.GetDlToOnuTimeout4M(),
mpagenko59498c12021-03-18 14:15:15 +0000207 waitCountEndSwDl: cWaitCountEndSwDl,
208 waitDelayEndSwDl: cWaitDelayEndSwDlSeconds,
mpagenko45586762021-10-01 08:30:22 +0000209 upgradePhase: cUpgradeUndefined,
210 volthaDownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
mpagenkoaa3afe92021-05-21 16:20:58 +0000211 volthaDownloadReason: voltha.ImageState_NO_ERROR,
212 volthaImageState: voltha.ImageState_IMAGE_UNKNOWN,
mpagenko38662d02021-08-11 09:45:19 +0000213 abortRequested: voltha.ImageState_NO_ERROR,
mpagenko80622a52021-02-09 16:53:23 +0000214 }
mpagenko59498c12021-03-18 14:15:15 +0000215 instFsm.chReceiveExpectedResponse = make(chan bool)
mpagenkoc26d4c02021-05-06 14:27:57 +0000216 instFsm.chAdapterDlReady = make(chan bool)
217 instFsm.chOnuDlReady = make(chan bool)
mpagenko45586762021-10-01 08:30:22 +0000218 instFsm.chReceiveAbortEndSwDlResponse = make(chan tEndSwDlResponseResult)
mpagenko80622a52021-02-09 16:53:23 +0000219
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000220 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
221 if instFsm.PAdaptFsm == nil {
mpagenko80622a52021-02-09 16:53:23 +0000222 logger.Errorw(ctx, "OnuUpgradeFsm's AdapterFsm could not be instantiated!!", log.Fields{
223 "device-id": instFsm.deviceID})
224 return nil
225 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000226 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
227 UpgradeStDisabled,
mpagenko80622a52021-02-09 16:53:23 +0000228 fsm.Events{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000229 {Name: UpgradeEvStart, Src: []string{UpgradeStDisabled}, Dst: UpgradeStStarting},
230 {Name: UpgradeEvAdapterDownload, Src: []string{UpgradeStStarting}, Dst: UpgradeStWaitingAdapterDL},
231 {Name: UpgradeEvPrepareSwDownload, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL}, Dst: UpgradeStPreparingDL},
232 {Name: UpgradeEvRxStartSwDownload, Src: []string{UpgradeStPreparingDL}, Dst: UpgradeStDLSection},
233 {Name: UpgradeEvWaitWindowAck, Src: []string{UpgradeStDLSection}, Dst: UpgradeStVerifyWindow},
234 {Name: UpgradeEvContinueNextWindow, Src: []string{UpgradeStVerifyWindow}, Dst: UpgradeStDLSection},
235 {Name: UpgradeEvEndSwDownload, Src: []string{UpgradeStVerifyWindow}, Dst: UpgradeStFinalizeDL},
236 {Name: UpgradeEvWaitEndDownload, Src: []string{UpgradeStFinalizeDL}, Dst: UpgradeStWaitEndDL},
237 {Name: UpgradeEvContinueFinalize, Src: []string{UpgradeStWaitEndDL}, Dst: UpgradeStFinalizeDL},
238 //UpgradeStCheckImageName only used with useAPIVersion43
239 {Name: UpgradeEvCheckImageName, Src: []string{UpgradeStWaitEndDL}, Dst: UpgradeStCheckImageName},
240 //UpgradeEvWaitForActivate state transitions depend on useAPIVersion43
241 {Name: UpgradeEvWaitForActivate, Src: []string{UpgradeStWaitEndDL, UpgradeStCheckImageName}, Dst: UpgradeStWaitForActivate},
242 //UpgradeEvRequestActivate state transitions depend on useAPIVersion43
243 {Name: UpgradeEvRequestActivate, Src: []string{UpgradeStStarting, UpgradeStWaitEndDL, UpgradeStCheckImageName,
244 UpgradeStWaitForActivate}, Dst: UpgradeStRequestingActivate}, //allows also for direct activation (without download) [TODO!!!]
245 {Name: UpgradeEvActivationDone, Src: []string{UpgradeStRequestingActivate}, Dst: UpgradeStActivated},
246 {Name: UpgradeEvWaitForCommit, Src: []string{UpgradeStRequestingActivate}, Dst: UpgradeStWaitForCommit},
247 {Name: UpgradeEvCommitSw, Src: []string{UpgradeStStarting, UpgradeStRequestingActivate, UpgradeStWaitForCommit,
248 UpgradeStActivated}, Dst: UpgradeStCommitSw}, //allows also for direct commitment (without download) [TODO!!!]
249 {Name: UpgradeEvCheckCommitted, Src: []string{UpgradeStCommitSw}, Dst: UpgradeStCheckCommitted},
mpagenko80622a52021-02-09 16:53:23 +0000250
251 /*
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000252 {Name: UpgradeEvTimeoutSimple, Src: []string{
253 UpgradeStCreatingDot1PMapper, UpgradeStCreatingMBPCD, UpgradeStSettingTconts, UpgradeStSettingDot1PMapper}, Dst: UpgradeStStarting},
254 {Name: UpgradeEvTimeoutMids, Src: []string{
255 UpgradeStCreatingGemNCTPs, UpgradeStCreatingGemIWs, UpgradeStSettingPQs}, Dst: UpgradeStStarting},
mpagenko80622a52021-02-09 16:53:23 +0000256 */
257 // exceptional treatments
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000258 //on UpgradeEvReset: UpgradeStRequestingActivate, UpgradeStWaitForCommit and UpgradeStActivated are not reset
mpagenko1f8e8822021-06-25 14:10:21 +0000259 // (to let the FSM survive the expected OnuDown indication)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000260 {Name: UpgradeEvReset, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL, UpgradeStPreparingDL, UpgradeStDLSection,
261 UpgradeStVerifyWindow, UpgradeStDLSection, UpgradeStFinalizeDL, UpgradeStWaitEndDL, UpgradeStCheckImageName,
262 UpgradeStWaitForActivate,
mpagenko45586762021-10-01 08:30:22 +0000263 UpgradeStCommitSw, UpgradeStCheckCommitted, UpgradeStAbortingDL},
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000264 Dst: UpgradeStResetting},
265 {Name: UpgradeEvAbort, Src: []string{UpgradeStStarting, UpgradeStWaitingAdapterDL, UpgradeStPreparingDL, UpgradeStDLSection,
266 UpgradeStVerifyWindow, UpgradeStDLSection, UpgradeStFinalizeDL, UpgradeStWaitEndDL, UpgradeStCheckImageName,
267 UpgradeStWaitForActivate,
268 UpgradeStRequestingActivate, UpgradeStActivated, UpgradeStWaitForCommit,
269 UpgradeStCommitSw, UpgradeStCheckCommitted},
270 Dst: UpgradeStResetting},
271 {Name: UpgradeEvAbortSwDownload, Src: []string{UpgradeStResetting}, Dst: UpgradeStAbortingDL},
272 {Name: UpgradeEvRestart, Src: []string{UpgradeStResetting, UpgradeStAbortingDL}, Dst: UpgradeStRestarting},
273 {Name: UpgradeEvDisable, Src: []string{UpgradeStRestarting}, Dst: UpgradeStDisabled},
mpagenko80622a52021-02-09 16:53:23 +0000274 },
275 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000276 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
277 "enter_" + UpgradeStStarting: func(e *fsm.Event) { instFsm.enterStarting(ctx, e) },
278 "enter_" + UpgradeStWaitingAdapterDL: func(e *fsm.Event) { instFsm.enterWaitingAdapterDL(ctx, e) },
279 "enter_" + UpgradeStPreparingDL: func(e *fsm.Event) { instFsm.enterPreparingDL(ctx, e) },
280 "enter_" + UpgradeStDLSection: func(e *fsm.Event) { instFsm.enterDownloadSection(ctx, e) },
281 "enter_" + UpgradeStVerifyWindow: func(e *fsm.Event) { instFsm.enterVerifyWindow(ctx, e) },
282 "enter_" + UpgradeStFinalizeDL: func(e *fsm.Event) { instFsm.enterFinalizeDL(ctx, e) },
283 "enter_" + UpgradeStWaitEndDL: func(e *fsm.Event) { instFsm.enterWaitEndDL(ctx, e) },
284 "enter_" + UpgradeStCheckImageName: func(e *fsm.Event) { instFsm.enterCheckImageName(ctx, e) },
285 "enter_" + UpgradeStRequestingActivate: func(e *fsm.Event) { instFsm.enterActivateSw(ctx, e) },
286 "enter_" + UpgradeStCommitSw: func(e *fsm.Event) { instFsm.enterCommitSw(ctx, e) },
287 "enter_" + UpgradeStCheckCommitted: func(e *fsm.Event) { instFsm.enterCheckCommitted(ctx, e) },
288 "enter_" + UpgradeStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) },
289 "enter_" + UpgradeStAbortingDL: func(e *fsm.Event) { instFsm.enterAbortingDL(ctx, e) },
290 "enter_" + UpgradeStRestarting: func(e *fsm.Event) { instFsm.enterRestarting(ctx, e) },
291 "enter_" + UpgradeStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) },
mpagenko80622a52021-02-09 16:53:23 +0000292 },
293 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000294 if instFsm.PAdaptFsm.PFsm == nil {
mpagenko80622a52021-02-09 16:53:23 +0000295 logger.Errorw(ctx, "OnuUpgradeFsm's Base FSM could not be instantiated!!", log.Fields{
296 "device-id": instFsm.deviceID})
297 return nil
298 }
299
300 logger.Debugw(ctx, "OnuUpgradeFsm created", log.Fields{"device-id": instFsm.deviceID})
301 return instFsm
302}
303
304//SetDownloadParams configures the needed parameters for a specific download to the ONU
mpagenkoc26d4c02021-05-06 14:27:57 +0000305// called from 'old' API Activate_image_update()
mpagenko15ff4a52021-03-02 10:09:20 +0000306func (oFsm *OnuUpgradeFsm) SetDownloadParams(ctx context.Context, aInactiveImageID uint16,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000307 apImageDsc *voltha.ImageDownload, apDownloadManager *AdapterDownloadManager) error {
308 pBaseFsm := oFsm.PAdaptFsm.PFsm
309 if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000310 oFsm.mutexUpgradeParams.Lock()
mpagenko80622a52021-02-09 16:53:23 +0000311 logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{
312 "device-id": oFsm.deviceID, "image-description": apImageDsc})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000313 oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId
mpagenko80622a52021-02-09 16:53:23 +0000314 oFsm.pImageDsc = apImageDsc
315 oFsm.pDownloadManager = apDownloadManager
Holger Hildebrandtac1e0592021-06-03 15:16:49 +0000316 oFsm.activateImage = true
317 oFsm.commitImage = true
mpagenkoaa3afe92021-05-21 16:20:58 +0000318 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000319
320 go func(aPBaseFsm *fsm.FSM) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000321 // let the upgrade FSM proceed to PreparingDL
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000322 _ = aPBaseFsm.Event(UpgradeEvPrepareSwDownload)
mpagenko80622a52021-02-09 16:53:23 +0000323 }(pBaseFsm)
324 return nil
325 }
326 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{
327 "device-id": oFsm.deviceID})
328 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID))
329}
330
mpagenkoc26d4c02021-05-06 14:27:57 +0000331//SetDownloadParamsAfterDownload configures the needed parameters for a specific download to the ONU according to
332// updated API interface with R2.8: start download to ONU if the image is downloaded to the adapter
333// called from 'new' API Download_onu_image
334func (oFsm *OnuUpgradeFsm) SetDownloadParamsAfterDownload(ctx context.Context, aInactiveImageID uint16,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 apImageRequest *voltha.DeviceImageDownloadRequest, apDownloadManager *FileDownloadManager,
Holger Hildebrandtac010732021-06-02 13:35:39 +0000336 aImageIdentifier string) error {
mpagenkoc26d4c02021-05-06 14:27:57 +0000337 oFsm.mutexUpgradeParams.Lock()
338 var pBaseFsm *fsm.FSM = nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 if oFsm.PAdaptFsm != nil {
340 pBaseFsm = oFsm.PAdaptFsm.PFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000341 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000342 if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000343 logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting", log.Fields{
344 "device-id": oFsm.deviceID, "image-description": apImageRequest})
345 oFsm.useAPIVersion43 = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000346 oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId
mpagenkoc26d4c02021-05-06 14:27:57 +0000347 oFsm.pFileManager = apDownloadManager
348 oFsm.imageIdentifier = aImageIdentifier
349 oFsm.imageVersion = apImageRequest.Image.Version
350 oFsm.activateImage = apImageRequest.ActivateOnSuccess
351 oFsm.commitImage = apImageRequest.CommitOnSuccess
mpagenko45586762021-10-01 08:30:22 +0000352 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_STARTED //state change indication for download request
mpagenkoc26d4c02021-05-06 14:27:57 +0000353 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000354 _ = pBaseFsm.Event(UpgradeEvAdapterDownload) //no need to call the FSM event in background here
mpagenkoc26d4c02021-05-06 14:27:57 +0000355 return nil
356 }
357 oFsm.mutexUpgradeParams.Unlock()
358 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{
359 "device-id": oFsm.deviceID})
360 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID))
361}
362
363//SetActivationParamsRunning sets the activate and commit flags for a running download to the ONU according to adapters rpc call
364// called from 'new' API Activate_onu_image
365func (oFsm *OnuUpgradeFsm) SetActivationParamsRunning(ctx context.Context,
366 aImageIdentifier string, aCommit bool) error {
mpagenko45586762021-10-01 08:30:22 +0000367 logger.Debugw(ctx, "OnuUpgradeFsm activate/commit parameter setting", log.Fields{
368 "device-id": oFsm.deviceID, "image-id": aImageIdentifier, "commit": aCommit})
mpagenkoc26d4c02021-05-06 14:27:57 +0000369 oFsm.mutexUpgradeParams.Lock()
370 //set activate/commit independent from state, if FSM is already beyond concerned states, then it does not matter anyway
371 // (as long as the Imageidentifier is correct)
mpagenkoc26d4c02021-05-06 14:27:57 +0000372 if aImageIdentifier != oFsm.imageIdentifier {
373 logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{
374 "device-id": oFsm.deviceID, "request-image": aImageIdentifier, "fsm-image": oFsm.imageIdentifier})
375 oFsm.mutexUpgradeParams.Unlock()
376 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s",
377 oFsm.deviceID))
378 }
379 oFsm.activateImage = true
380 oFsm.commitImage = aCommit
mpagenko45586762021-10-01 08:30:22 +0000381 oFsm.mutexUpgradeParams.Unlock()
mpagenkoc26d4c02021-05-06 14:27:57 +0000382 var pBaseFsm *fsm.FSM = nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000383 if oFsm.PAdaptFsm != nil {
384 pBaseFsm = oFsm.PAdaptFsm.PFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000385 }
386 if pBaseFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000387 if pBaseFsm.Is(UpgradeStWaitForActivate) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000388 logger.Debugw(ctx, "OnuUpgradeFsm finish waiting for activate", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000389 _ = pBaseFsm.Event(UpgradeEvRequestActivate) //no need to call the FSM event in background here
mpagenko38662d02021-08-11 09:45:19 +0000390 } else {
mpagenko38662d02021-08-11 09:45:19 +0000391 logger.Debugw(ctx, "OnuUpgradeFsm not (yet?) waiting for activate", log.Fields{
392 "device-id": oFsm.deviceID, "current FsmState": pBaseFsm.Current()})
mpagenkoc26d4c02021-05-06 14:27:57 +0000393 }
394 return nil
395 }
396 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{
397 "device-id": oFsm.deviceID})
398 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID))
399}
400
401//SetActivationParamsStart starts upgrade processing with immediate activation
402// called from 'new' API Activate_onu_image
403func (oFsm *OnuUpgradeFsm) SetActivationParamsStart(ctx context.Context, aImageVersion string, aInactiveImageID uint16, aCommit bool) error {
404 oFsm.mutexUpgradeParams.Lock()
405 var pBaseFsm *fsm.FSM = nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000406 if oFsm.PAdaptFsm != nil {
407 pBaseFsm = oFsm.PAdaptFsm.PFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000408 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000409 if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000410 logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with activation", log.Fields{
411 "device-id": oFsm.deviceID, "image-version": aImageVersion})
412 oFsm.useAPIVersion43 = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000413 oFsm.InactiveImageMeID = aInactiveImageID //upgrade state machines run on configured inactive ImageId
mpagenkoc26d4c02021-05-06 14:27:57 +0000414 oFsm.imageVersion = aImageVersion
415 oFsm.activateImage = true
416 oFsm.commitImage = aCommit
mpagenko38662d02021-08-11 09:45:19 +0000417 // indicate start of the upgrade activity
mpagenko45586762021-10-01 08:30:22 +0000418 oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATING //state change indication for activate request
mpagenkoc26d4c02021-05-06 14:27:57 +0000419 oFsm.mutexUpgradeParams.Unlock()
420 //directly request the FSM to activate the image
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000421 _ = pBaseFsm.Event(UpgradeEvRequestActivate) //no need to call the FSM event in background here
mpagenkoc26d4c02021-05-06 14:27:57 +0000422 return nil
423 }
424 oFsm.mutexUpgradeParams.Unlock()
425 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{
426 "device-id": oFsm.deviceID})
427 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID))
428}
429
430//SetCommitmentParamsRunning sets the commit flag for a running download to the ONU according to adapters rpc call
431// called from 'new' API Commit_onu_image
mpagenko38662d02021-08-11 09:45:19 +0000432func (oFsm *OnuUpgradeFsm) SetCommitmentParamsRunning(ctx context.Context,
433 aImageIdentifier string, aImageVersion string) error {
mpagenkoc26d4c02021-05-06 14:27:57 +0000434 oFsm.mutexUpgradeParams.Lock()
435 //set commit independent from state, if FSM is already beyond commit state (just ready), then it does not matter anyway
436 // (as long as the Imageidentifier is correct)
437 logger.Debugw(ctx, "OnuUpgradeFsm commit parameter setting", log.Fields{
438 "device-id": oFsm.deviceID, "image-id": aImageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +0000439 if (aImageIdentifier != oFsm.imageIdentifier) && (aImageVersion != oFsm.imageVersion) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000440 logger.Errorw(ctx, "OnuUpgradeFsm abort: mismatching upgrade image", log.Fields{
mpagenko38662d02021-08-11 09:45:19 +0000441 "device-id": oFsm.deviceID, "request-identifier": aImageIdentifier, "fsm-identifier": oFsm.imageIdentifier,
442 "request-version": aImageVersion, "fsm-version": oFsm.imageVersion})
mpagenkoc26d4c02021-05-06 14:27:57 +0000443 oFsm.mutexUpgradeParams.Unlock()
444 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm params ignored: requested image-name not used in current upgrade for device-id: %s",
445 oFsm.deviceID))
446 }
447 oFsm.commitImage = true
448 oFsm.mutexUpgradeParams.Unlock()
449 var pBaseFsm *fsm.FSM = nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000450 if oFsm.PAdaptFsm != nil {
451 pBaseFsm = oFsm.PAdaptFsm.PFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000452 }
453 if pBaseFsm != nil {
mpagenko183647c2021-06-08 15:25:04 +0000454 //let the FSM decide if it is ready to process the event
455 logger.Debugw(ctx, "OnuUpgradeFsm requesting commit",
456 log.Fields{"device-id": oFsm.deviceID, "current FsmState": pBaseFsm.Current()})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000457 _ = pBaseFsm.Event(UpgradeEvCommitSw) //no need to call the FSM event in background here
mpagenkoc26d4c02021-05-06 14:27:57 +0000458 return nil
459 }
mpagenko38662d02021-08-11 09:45:19 +0000460 //should never occur
mpagenkoc26d4c02021-05-06 14:27:57 +0000461 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer", log.Fields{
462 "device-id": oFsm.deviceID})
463 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer for device-id: %s", oFsm.deviceID))
464}
465
466//SetCommitmentParamsStart starts upgrade processing with immediate commitment
467// called from 'new' API Commit_onu_image
468func (oFsm *OnuUpgradeFsm) SetCommitmentParamsStart(ctx context.Context, aImageVersion string, aActiveImageID uint16) error {
469 oFsm.mutexUpgradeParams.Lock()
470 var pBaseFsm *fsm.FSM = nil
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000471 if oFsm.PAdaptFsm != nil {
472 pBaseFsm = oFsm.PAdaptFsm.PFsm
mpagenkoc26d4c02021-05-06 14:27:57 +0000473 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000474 if pBaseFsm != nil && pBaseFsm.Is(UpgradeStStarting) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000475 logger.Debugw(ctx, "OnuUpgradeFsm Parameter setting to start with commitment", log.Fields{
476 "device-id": oFsm.deviceID, "image-version": aImageVersion})
477 oFsm.useAPIVersion43 = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000478 oFsm.InactiveImageMeID = aActiveImageID //upgrade state machines inactive ImageId is the new active ImageId
mpagenkoc26d4c02021-05-06 14:27:57 +0000479 oFsm.imageVersion = aImageVersion
480 oFsm.commitImage = true
mpagenko45586762021-10-01 08:30:22 +0000481 oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTING //state change indication for activate request
mpagenkoc26d4c02021-05-06 14:27:57 +0000482 oFsm.mutexUpgradeParams.Unlock()
mpagenko38662d02021-08-11 09:45:19 +0000483 //directly request the FSM to commit the image
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000484 _ = pBaseFsm.Event(UpgradeEvCommitSw) //no need to call the FSM event in background here
mpagenkoc26d4c02021-05-06 14:27:57 +0000485 return nil
486 }
487 oFsm.mutexUpgradeParams.Unlock()
488 logger.Errorw(ctx, "OnuUpgradeFsm abort: invalid FSM base pointer or state", log.Fields{
489 "device-id": oFsm.deviceID})
490 return fmt.Errorf(fmt.Sprintf("OnuUpgradeFsm abort: invalid FSM base pointer or state for device-id: %s", oFsm.deviceID))
491}
492
mpagenko1f8e8822021-06-25 14:10:21 +0000493//GetCommitFlag delivers the commit flag that was configured here
494func (oFsm *OnuUpgradeFsm) GetCommitFlag(ctx context.Context) bool {
495 oFsm.mutexUpgradeParams.RLock()
496 defer oFsm.mutexUpgradeParams.RUnlock()
497 return oFsm.commitImage
498}
499
mpagenko38662d02021-08-11 09:45:19 +0000500//GetImageStates delivers the download/image states as per device proto buf definition
mpagenkoaa3afe92021-05-21 16:20:58 +0000501func (oFsm *OnuUpgradeFsm) GetImageStates(ctx context.Context,
mpagenko38662d02021-08-11 09:45:19 +0000502 aImageIdentifier string, aVersion string) *voltha.ImageState {
mpagenkoaa3afe92021-05-21 16:20:58 +0000503 pImageState := &voltha.ImageState{}
mpagenko38662d02021-08-11 09:45:19 +0000504 pImageState.Version = aVersion //version as requested
mpagenkoaa3afe92021-05-21 16:20:58 +0000505 // check if the request refers to some active image/version of the processing
506 oFsm.mutexUpgradeParams.RLock()
507 if (aImageIdentifier == oFsm.imageIdentifier) || (aVersion == oFsm.imageVersion) {
508 pImageState.DownloadState = oFsm.volthaDownloadState
509 pImageState.Reason = oFsm.volthaDownloadReason
510 pImageState.ImageState = oFsm.volthaImageState
511 } else {
512 pImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
513 pImageState.Reason = voltha.ImageState_NO_ERROR
514 pImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
515 }
516 oFsm.mutexUpgradeParams.RUnlock()
mpagenko38662d02021-08-11 09:45:19 +0000517 return pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +0000518}
519
mpagenko38662d02021-08-11 09:45:19 +0000520//GetSpecificImageState delivers ImageState of the download/image states as per device proto buf definition
521func (oFsm *OnuUpgradeFsm) GetSpecificImageState(ctx context.Context) voltha.ImageState_ImageActivationState {
522 oFsm.mutexUpgradeParams.RLock()
523 imageState := oFsm.volthaImageState
524 oFsm.mutexUpgradeParams.RUnlock()
525 return imageState
526}
527
528//SetImageStateActive sets the FSM internal volthaImageState to ImageState_IMAGE_ACTIVE
529func (oFsm *OnuUpgradeFsm) SetImageStateActive(ctx context.Context) {
mpagenko183647c2021-06-08 15:25:04 +0000530 oFsm.mutexUpgradeParams.Lock()
531 defer oFsm.mutexUpgradeParams.Unlock()
mpagenko45586762021-10-01 08:30:22 +0000532 oFsm.upgradePhase = cUpgradeActivated
mpagenko38662d02021-08-11 09:45:19 +0000533 oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVE
mpagenko38662d02021-08-11 09:45:19 +0000534}
535
536//GetImageVersion delivers image-version of the running upgrade
537func (oFsm *OnuUpgradeFsm) GetImageVersion(ctx context.Context) string {
538 oFsm.mutexUpgradeParams.RLock()
539 imageVersion := oFsm.imageVersion
540 oFsm.mutexUpgradeParams.RUnlock()
541 return imageVersion
mpagenko183647c2021-06-08 15:25:04 +0000542}
543
mpagenkoc26d4c02021-05-06 14:27:57 +0000544//CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
mpagenko38662d02021-08-11 09:45:19 +0000545func (oFsm *OnuUpgradeFsm) CancelProcessing(ctx context.Context, abCompleteAbort bool,
546 aReason voltha.ImageState_ImageFailureReason) {
547 oFsm.mutexAbortRequest.Lock()
548 oFsm.abortRequested = aReason //possibly abort the sectionDownload loop
549 oFsm.mutexAbortRequest.Unlock()
mpagenkoc26d4c02021-05-06 14:27:57 +0000550 //mutex protection is required for possible concurrent access to FSM members
551 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
552 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
553 oFsm.mutexIsAwaitingAdapterDlResponse.RLock()
554 if oFsm.isWaitingForAdapterDlResponse {
555 oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock()
556 //use channel to indicate that the download response waiting shall be aborted for this device (channel)
557 oFsm.chAdapterDlReady <- false
558 } else {
559 oFsm.mutexIsAwaitingAdapterDlResponse.RUnlock()
560 }
561 //chOnuDlReady is cleared as part of the FSM reset processing (from enterResetting())
562
563 // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM
mpagenko1f8e8822021-06-25 14:10:21 +0000564 // specific here: See definition of state changes: some states are excluded from reset for possible later commit
mpagenko45586762021-10-01 08:30:22 +0000565 pAdaptFsm := oFsm.PAdaptFsm
566 if pAdaptFsm != nil {
mpagenkoc26d4c02021-05-06 14:27:57 +0000567 // calling FSM events in background to avoid blocking of the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 go func(aPAFsm *cmn.AdapterFsm) {
569 if aPAFsm.PFsm != nil {
570 if aPAFsm.PFsm.Is(UpgradeStWaitEndDL) {
mpagenko38662d02021-08-11 09:45:19 +0000571 oFsm.chReceiveExpectedResponse <- false //which aborts the FSM in WaitEndDL state
mpagenko45586762021-10-01 08:30:22 +0000572 } else if aPAFsm.PFsm.Is(UpgradeStAbortingDL) {
573 oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseAbort //abort waiting on EndDownloadResponse
mpagenkoc26d4c02021-05-06 14:27:57 +0000574 }
mpagenko38662d02021-08-11 09:45:19 +0000575
576 var err error
577 if abCompleteAbort {
mpagenko45586762021-10-01 08:30:22 +0000578 // in case of unconditional abort request the ImageState is set immediately
mpagenko38662d02021-08-11 09:45:19 +0000579 oFsm.mutexUpgradeParams.Lock()
580 //any previous lingering conditional cancelRequest is superseded by this abortion
581 oFsm.conditionalCancelRequested = false
mpagenko38662d02021-08-11 09:45:19 +0000582 oFsm.volthaDownloadReason = aReason
583 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000584 err = aPAFsm.PFsm.Event(UpgradeEvAbort) //as unconditional default FSM cancellation
mpagenko38662d02021-08-11 09:45:19 +0000585 } else {
mpagenko45586762021-10-01 08:30:22 +0000586 //at conditional abort request the image states are set when reaching the reset state
mpagenko38662d02021-08-11 09:45:19 +0000587 oFsm.conditionalCancelRequested = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000588 err = aPAFsm.PFsm.Event(UpgradeEvReset) //as state-conditional default FSM cleanup
mpagenko38662d02021-08-11 09:45:19 +0000589 }
590 if err != nil {
591 //error return is expected in case of conditional request and no state transition
592 logger.Debugw(ctx, "onu upgrade fsm could not cancel with abort/reset event", log.Fields{
593 "device-id": oFsm.deviceID, "error": err})
594 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000595 } //else the FSM seems already to be in some released state
mpagenko45586762021-10-01 08:30:22 +0000596 }(pAdaptFsm)
mpagenkoc26d4c02021-05-06 14:27:57 +0000597 }
598}
599
mpagenko80622a52021-02-09 16:53:23 +0000600func (oFsm *OnuUpgradeFsm) enterStarting(ctx context.Context, e *fsm.Event) {
601 logger.Debugw(ctx, "OnuUpgradeFsm start", log.Fields{"in state": e.FSM.Current(),
602 "device-id": oFsm.deviceID})
603
604 // start go routine for processing of LockState messages
605 go oFsm.processOmciUpgradeMessages(ctx)
606}
607
mpagenkoc26d4c02021-05-06 14:27:57 +0000608//enterWaitingAdapterDL state can only be reached with useAPIVersion43
609func (oFsm *OnuUpgradeFsm) enterWaitingAdapterDL(ctx context.Context, e *fsm.Event) {
610 logger.Debugw(ctx, "OnuUpgradeFsm waiting for adapter download", log.Fields{"in state": e.FSM.Current(),
611 "device-id": oFsm.deviceID})
mpagenko38662d02021-08-11 09:45:19 +0000612 syncChannel := make(chan struct{})
613 go oFsm.waitOnDownloadToAdapterReady(ctx, syncChannel, oFsm.chAdapterDlReady)
614 //block until the wait routine is really blocked on chAdapterDlReady
615 <-syncChannel
mpagenkoc26d4c02021-05-06 14:27:57 +0000616 go oFsm.pFileManager.RequestDownloadReady(ctx, oFsm.imageIdentifier, oFsm.chAdapterDlReady)
617}
618
mpagenko80622a52021-02-09 16:53:23 +0000619func (oFsm *OnuUpgradeFsm) enterPreparingDL(ctx context.Context, e *fsm.Event) {
620 logger.Debugw(ctx, "OnuUpgradeFsm prepare Download to Onu", log.Fields{"in state": e.FSM.Current(),
621 "device-id": oFsm.deviceID})
622
mpagenkoc26d4c02021-05-06 14:27:57 +0000623 var fileLen int64
624 var err error
mpagenkoaa3afe92021-05-21 16:20:58 +0000625 oFsm.mutexUpgradeParams.Lock()
mpagenkoc26d4c02021-05-06 14:27:57 +0000626 if oFsm.useAPIVersion43 {
627 //with the new API structure download to adapter is implicit and we have to wait until the image is available
628 fileLen, err = oFsm.pFileManager.GetImageBufferLen(ctx, oFsm.imageIdentifier)
629 } else {
630 fileLen, err = oFsm.pDownloadManager.getImageBufferLen(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir)
631 }
mpagenko80622a52021-02-09 16:53:23 +0000632 if err != nil || fileLen > int64(cMaxUint32) {
mpagenko39b703e2021-08-25 13:38:40 +0000633 oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto)
mpagenkoaa3afe92021-05-21 16:20:58 +0000634 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000635 logger.Errorw(ctx, "OnuUpgradeFsm abort: problems getting image buffer length", log.Fields{
636 "device-id": oFsm.deviceID, "error": err, "length": fileLen})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000637 pBaseFsm := oFsm.PAdaptFsm
mpagenko80622a52021-02-09 16:53:23 +0000638 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 go func(a_pAFsm *cmn.AdapterFsm) {
640 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko80622a52021-02-09 16:53:23 +0000641 }(pBaseFsm)
642 return
643 }
644
mpagenkoc26d4c02021-05-06 14:27:57 +0000645 //copy file content to buffer
mpagenko80622a52021-02-09 16:53:23 +0000646 oFsm.imageBuffer = make([]byte, fileLen)
mpagenkoc26d4c02021-05-06 14:27:57 +0000647 if oFsm.useAPIVersion43 {
648 oFsm.imageBuffer, err = oFsm.pFileManager.GetDownloadImageBuffer(ctx, oFsm.imageIdentifier)
649 } else {
650 oFsm.imageBuffer, err = oFsm.pDownloadManager.getDownloadImageBuffer(ctx, oFsm.pImageDsc.Name, oFsm.pImageDsc.LocalDir)
651 }
mpagenko80622a52021-02-09 16:53:23 +0000652 if err != nil {
mpagenko39b703e2021-08-25 13:38:40 +0000653 oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto)
mpagenkoaa3afe92021-05-21 16:20:58 +0000654 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000655 logger.Errorw(ctx, "OnuUpgradeFsm abort: can't get image buffer", log.Fields{
656 "device-id": oFsm.deviceID, "error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000657 pBaseFsm := oFsm.PAdaptFsm
mpagenko80622a52021-02-09 16:53:23 +0000658 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000659 go func(a_pAFsm *cmn.AdapterFsm) {
660 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko80622a52021-02-09 16:53:23 +0000661 }(pBaseFsm)
662 return
663 }
664
665 oFsm.noOfSections = uint32(fileLen / cOmciDownloadSectionSize)
666 if fileLen%cOmciDownloadSectionSize > 0 {
mpagenkoc26d4c02021-05-06 14:27:57 +0000667 bufferPadding := make([]byte, cOmciDownloadSectionSize-uint32((fileLen)%cOmciDownloadSectionSize))
mpagenko80622a52021-02-09 16:53:23 +0000668 //expand the imageBuffer to exactly fit multiples of cOmciDownloadSectionSize with padding
mpagenkoc26d4c02021-05-06 14:27:57 +0000669 oFsm.imageBuffer = append(oFsm.imageBuffer[:(fileLen)], bufferPadding...)
mpagenko80622a52021-02-09 16:53:23 +0000670 oFsm.noOfSections++
671 }
672 oFsm.origImageLength = uint32(fileLen)
673 oFsm.imageLength = uint32(len(oFsm.imageBuffer))
mpagenko80622a52021-02-09 16:53:23 +0000674 logger.Infow(ctx, "OnuUpgradeFsm starts with StartSwDl values", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675 "MeId": oFsm.InactiveImageMeID, "windowSizeLimit": oFsm.omciDownloadWindowSizeLimit,
mpagenko80622a52021-02-09 16:53:23 +0000676 "ImageSize": oFsm.imageLength, "original file size": fileLen})
677 //"NumberOfCircuitPacks": oFsm.numberCircuitPacks, "CircuitPacks MeId": 0}) //parallel circuit packs download not supported
mpagenkoaa3afe92021-05-21 16:20:58 +0000678
679 oFsm.mutexUpgradeParams.Unlock()
mpagenko39b703e2021-08-25 13:38:40 +0000680
681 // flush commMetricsChan
682 select {
683 case <-oFsm.chOnuDlReady:
684 logger.Debug(ctx, "flushed OnuDlReady channel")
685 default:
686 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000687 go oFsm.waitOnDownloadToOnuReady(ctx, oFsm.chOnuDlReady) // start supervision of the complete download-to-ONU procedure
688
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000689 err = oFsm.pOmciCC.SendStartSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
690 oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, oFsm.omciDownloadWindowSizeLimit, oFsm.origImageLength)
mpagenko80622a52021-02-09 16:53:23 +0000691 if err != nil {
692 logger.Errorw(ctx, "StartSwDl abort: can't send section", log.Fields{
693 "device-id": oFsm.deviceID, "error": err})
mpagenko45586762021-10-01 08:30:22 +0000694 oFsm.abortOnOmciError(ctx, true)
mpagenko80622a52021-02-09 16:53:23 +0000695 return
696 }
Holger Hildebrandt288d9472021-09-06 10:47:53 +0000697 oFsm.isEndSwDlOpen = true
mpagenko80622a52021-02-09 16:53:23 +0000698}
699
700func (oFsm *OnuUpgradeFsm) enterDownloadSection(ctx context.Context, e *fsm.Event) {
701 logger.Debugw(ctx, "OnuUpgradeFsm start downloading sections", log.Fields{
702 "device-id": oFsm.deviceID, "absolute window": oFsm.nextDownloadWindow})
703
704 var windowAckRequest uint8 = 0
705 var bufferStartOffset uint32
706 var bufferEndOffset uint32
707 var downloadSection []byte
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000708 FramePrint := false //default no printing of downloadSection frames
mpagenkoaa3afe92021-05-21 16:20:58 +0000709 oFsm.mutexUpgradeParams.Lock()
mpagenko45586762021-10-01 08:30:22 +0000710 oFsm.upgradePhase = cUpgradeDownloading //start of downloading image to ONU
mpagenko80622a52021-02-09 16:53:23 +0000711 if oFsm.nextDownloadSectionsAbsolute == 0 {
712 //debug print of first section frame
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000713 FramePrint = true
mpagenkoaa3afe92021-05-21 16:20:58 +0000714 oFsm.volthaImageState = voltha.ImageState_IMAGE_DOWNLOADING
mpagenko80622a52021-02-09 16:53:23 +0000715 }
716
717 for {
mpagenko38662d02021-08-11 09:45:19 +0000718 oFsm.mutexAbortRequest.RLock()
719 // this way out of the section download loop on abort request
720 if oFsm.abortRequested != voltha.ImageState_NO_ERROR {
mpagenko45586762021-10-01 08:30:22 +0000721 //states are updated when entering the reset state ...
mpagenko38662d02021-08-11 09:45:19 +0000722 oFsm.volthaDownloadReason = oFsm.abortRequested
723 oFsm.mutexAbortRequest.RUnlock()
724 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000725 pBaseFsm := oFsm.PAdaptFsm
mpagenko38662d02021-08-11 09:45:19 +0000726 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000727 go func(a_pAFsm *cmn.AdapterFsm) {
728 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko38662d02021-08-11 09:45:19 +0000729 }(pBaseFsm)
730 return
731 }
732 oFsm.mutexAbortRequest.RUnlock()
733
mpagenko80622a52021-02-09 16:53:23 +0000734 bufferStartOffset = oFsm.nextDownloadSectionsAbsolute * cOmciDownloadSectionSize
735 bufferEndOffset = bufferStartOffset + cOmciDownloadSectionSize - 1 //for representing cOmciDownloadSectionSizeLimit values
736 logger.Debugw(ctx, "DlSection values are", log.Fields{
737 "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute,
738 "DlSectionWindow": oFsm.nextDownloadSectionsWindow,
739 "startOffset": bufferStartOffset, "endOffset": bufferEndOffset})
740 if bufferStartOffset+1 > oFsm.imageLength || bufferEndOffset+1 > oFsm.imageLength { //should never occur in this state
741 logger.Errorw(ctx, "OnuUpgradeFsm buffer error: exceeded length", log.Fields{
742 "device-id": oFsm.deviceID, "bufferStartOffset": bufferStartOffset,
743 "bufferEndOffset": bufferEndOffset, "imageLength": oFsm.imageLength})
mpagenko39b703e2021-08-25 13:38:40 +0000744 oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'LOCAL_FILE_ERROR' would be better (proto)
mpagenkoaa3afe92021-05-21 16:20:58 +0000745 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000746 //logical error -- reset the FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000747 pBaseFsm := oFsm.PAdaptFsm
mpagenko80622a52021-02-09 16:53:23 +0000748 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000749 go func(a_pAFsm *cmn.AdapterFsm) {
750 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko80622a52021-02-09 16:53:23 +0000751 }(pBaseFsm)
752 return
753 }
754 downloadSection = oFsm.imageBuffer[bufferStartOffset : bufferEndOffset+1]
755 if oFsm.nextDownloadSectionsWindow == oFsm.omciDownloadWindowSizeLimit {
756 windowAckRequest = 1
757 logger.Debugw(ctx, "DlSection expect Response for complete window", log.Fields{
758 "device-id": oFsm.deviceID, "in window": oFsm.nextDownloadWindow})
759 }
760 if oFsm.nextDownloadSectionsAbsolute+1 >= oFsm.noOfSections {
761 windowAckRequest = 1
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000762 FramePrint = true //debug print of last frame
mpagenko15ff4a52021-03-02 10:09:20 +0000763 oFsm.omciDownloadWindowSizeLast = oFsm.nextDownloadSectionsWindow
764 logger.Infow(ctx, "DlSection expect Response for last window (section)", log.Fields{
mpagenko80622a52021-02-09 16:53:23 +0000765 "device-id": oFsm.deviceID, "DlSectionNoAbsolute": oFsm.nextDownloadSectionsAbsolute})
766 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000767 oFsm.mutexUpgradeParams.Unlock() //unlock here to give other functions some chance to process during/after the send request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000768 err := oFsm.pOmciCC.SendDownloadSection(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
769 oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, windowAckRequest, oFsm.nextDownloadSectionsWindow, downloadSection, FramePrint)
mpagenko80622a52021-02-09 16:53:23 +0000770 if err != nil {
771 logger.Errorw(ctx, "DlSection abort: can't send section", log.Fields{
mpagenko15ff4a52021-03-02 10:09:20 +0000772 "device-id": oFsm.deviceID, "section absolute": oFsm.nextDownloadSectionsAbsolute, "error": err})
mpagenko45586762021-10-01 08:30:22 +0000773 oFsm.abortOnOmciError(ctx, true)
mpagenko80622a52021-02-09 16:53:23 +0000774 return
775 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000776 oFsm.mutexUpgradeParams.Lock()
mpagenko80622a52021-02-09 16:53:23 +0000777 oFsm.nextDownloadSectionsAbsolute++ //always increase the absolute section counter after having sent one
778 if windowAckRequest == 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000779 pBaseFsm := oFsm.PAdaptFsm
mpagenko80622a52021-02-09 16:53:23 +0000780 // Can't call FSM Event directly, decoupling it
mpagenkoaa3afe92021-05-21 16:20:58 +0000781 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000782 go func(a_pAFsm *cmn.AdapterFsm) {
783 _ = a_pAFsm.PFsm.Event(UpgradeEvWaitWindowAck) //state transition to UpgradeStVerifyWindow
mpagenko80622a52021-02-09 16:53:23 +0000784 }(pBaseFsm)
785 return
786 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000787 FramePrint = false //for the next Section frame (if wanted, can be enabled in logic before sendXXX())
mpagenko80622a52021-02-09 16:53:23 +0000788 oFsm.nextDownloadSectionsWindow++ //increase the window related section counter only if not in the last section
mpagenko59498c12021-03-18 14:15:15 +0000789 if oFsm.omciSectionInterleaveDelay > 0 {
mpagenko80622a52021-02-09 16:53:23 +0000790 //ensure a defined intersection-time-gap to leave space for further processing, other ONU's ...
mpagenkoaa3afe92021-05-21 16:20:58 +0000791 oFsm.mutexUpgradeParams.Unlock() //unlock here to give other functions some chance to process during/after the send request
mpagenko59498c12021-03-18 14:15:15 +0000792 time.Sleep(oFsm.omciSectionInterleaveDelay * time.Millisecond)
mpagenkoaa3afe92021-05-21 16:20:58 +0000793 oFsm.mutexUpgradeParams.Lock()
mpagenko80622a52021-02-09 16:53:23 +0000794 }
795 }
796}
797
798func (oFsm *OnuUpgradeFsm) enterVerifyWindow(ctx context.Context, e *fsm.Event) {
799 logger.Debugw(ctx, "OnuUpgradeFsm verify DL window ack", log.Fields{
800 "for window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID})
801}
802
803func (oFsm *OnuUpgradeFsm) enterFinalizeDL(ctx context.Context, e *fsm.Event) {
mpagenko80622a52021-02-09 16:53:23 +0000804 logger.Infow(ctx, "OnuUpgradeFsm finalize DL", log.Fields{
mpagenko59498c12021-03-18 14:15:15 +0000805 "device-id": oFsm.deviceID, "crc": strconv.FormatInt(int64(oFsm.imageCRC), 16), "delay": oFsm.delayEndSwDl})
mpagenko80622a52021-02-09 16:53:23 +0000806
mpagenkoaa3afe92021-05-21 16:20:58 +0000807 oFsm.mutexUpgradeParams.RLock()
mpagenko80622a52021-02-09 16:53:23 +0000808 if oFsm.delayEndSwDl {
mpagenkoaa3afe92021-05-21 16:20:58 +0000809 oFsm.mutexUpgradeParams.RUnlock()
mpagenko80622a52021-02-09 16:53:23 +0000810 //give the ONU some time for image evaluation (hoping it does not base that on first EndSwDl itself)
811 // should not be set in case this state is used for real download abort (not yet implemented)
812 time.Sleep(cOmciEndSwDlDelaySeconds * time.Second)
mpagenkoaa3afe92021-05-21 16:20:58 +0000813 } else {
814 oFsm.mutexUpgradeParams.RUnlock()
mpagenko80622a52021-02-09 16:53:23 +0000815 }
816
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000817 pBaseFsm := oFsm.PAdaptFsm
mpagenko59498c12021-03-18 14:15:15 +0000818 if pBaseFsm == nil {
mpagenko38662d02021-08-11 09:45:19 +0000819 logger.Errorw(ctx, "EndSwDl abort: BaseFsm invalid", log.Fields{"device-id": oFsm.deviceID})
820 oFsm.mutexUpgradeParams.Lock()
mpagenko38662d02021-08-11 09:45:19 +0000821 oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR
822 oFsm.mutexUpgradeParams.Unlock()
mpagenko59498c12021-03-18 14:15:15 +0000823 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000824 go func(a_pAFsm *cmn.AdapterFsm) {
825 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko59498c12021-03-18 14:15:15 +0000826 }(pBaseFsm)
827 return
828 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000829 err := oFsm.pOmciCC.SendEndSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
830 oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, oFsm.origImageLength, oFsm.imageCRC)
Holger Hildebrandt288d9472021-09-06 10:47:53 +0000831
mpagenko80622a52021-02-09 16:53:23 +0000832 if err != nil {
833 logger.Errorw(ctx, "EndSwDl abort: can't send section", log.Fields{
834 "device-id": oFsm.deviceID, "error": err})
mpagenko45586762021-10-01 08:30:22 +0000835 oFsm.abortOnOmciError(ctx, true)
mpagenko80622a52021-02-09 16:53:23 +0000836 return
837 }
mpagenko59498c12021-03-18 14:15:15 +0000838 // go waiting for the EndSwDLResponse and check, if the ONU is ready for activation
839 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000840 go func(a_pAFsm *cmn.AdapterFsm) {
841 _ = a_pAFsm.PFsm.Event(UpgradeEvWaitEndDownload)
mpagenko59498c12021-03-18 14:15:15 +0000842 }(pBaseFsm)
843}
844
845func (oFsm *OnuUpgradeFsm) enterWaitEndDL(ctx context.Context, e *fsm.Event) {
846 logger.Infow(ctx, "OnuUpgradeFsm WaitEndDl", log.Fields{
847 "device-id": oFsm.deviceID, "wait delay": oFsm.waitDelayEndSwDl * time.Second, "wait count": oFsm.waitCountEndSwDl})
848 if oFsm.waitCountEndSwDl == 0 {
849 logger.Errorw(ctx, "WaitEndDl abort: max limit of EndSwDL reached", log.Fields{
850 "device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000851 pBaseFsm := oFsm.PAdaptFsm
mpagenko59498c12021-03-18 14:15:15 +0000852 if pBaseFsm == nil {
853 logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{
854 "device-id": oFsm.deviceID})
855 return
856 }
mpagenko38662d02021-08-11 09:45:19 +0000857 oFsm.mutexUpgradeParams.Lock()
mpagenko45586762021-10-01 08:30:22 +0000858 oFsm.isEndSwDlOpen = false //no need to additionally request abort of download (already finished)
mpagenko39b703e2021-08-25 13:38:40 +0000859 oFsm.volthaDownloadReason = voltha.ImageState_IMAGE_REFUSED_BY_ONU //something like 'END_DOWNLOAD_TIMEOUT' would be better (proto)
mpagenko38662d02021-08-11 09:45:19 +0000860 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000861 go func(a_pAFsm *cmn.AdapterFsm) {
862 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko59498c12021-03-18 14:15:15 +0000863 }(pBaseFsm)
864 return
865 }
866
867 oFsm.waitCountEndSwDl--
868 select {
869 case <-time.After(oFsm.waitDelayEndSwDl * time.Second):
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000870 pBaseFsm := oFsm.PAdaptFsm
mpagenko59498c12021-03-18 14:15:15 +0000871 if pBaseFsm == nil {
872 logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{
873 "device-id": oFsm.deviceID})
874 //FSM may be reset already from somewhere else, nothing we can do here anymore
875 return
876 }
877 //retry End SW DL
mpagenkoaa3afe92021-05-21 16:20:58 +0000878 oFsm.mutexUpgradeParams.Lock()
mpagenko59498c12021-03-18 14:15:15 +0000879 oFsm.delayEndSwDl = false //no more extra delay for the request
mpagenkoaa3afe92021-05-21 16:20:58 +0000880 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000881 go func(a_pAFsm *cmn.AdapterFsm) {
882 _ = a_pAFsm.PFsm.Event(UpgradeEvContinueFinalize)
mpagenko59498c12021-03-18 14:15:15 +0000883 }(pBaseFsm)
884 return
885 case success := <-oFsm.chReceiveExpectedResponse:
886 logger.Debugw(ctx, "WaitEndDl stop wait timer", log.Fields{"device-id": oFsm.deviceID})
mpagenko45586762021-10-01 08:30:22 +0000887 oFsm.isEndSwDlOpen = false //no request to abort of download (already finished or immediate abort)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000888 pBaseFsm := oFsm.PAdaptFsm
mpagenko59498c12021-03-18 14:15:15 +0000889 if pBaseFsm == nil {
890 logger.Errorw(ctx, "WaitEndDl abort: BaseFsm invalid", log.Fields{
891 "device-id": oFsm.deviceID})
892 //FSM may be reset already from somewhere else, nothing we can do here anymore
893 return
894 }
895 if success {
896 //answer received with ready indication
mpagenko38662d02021-08-11 09:45:19 +0000897 //useAPIVersion43 may not conflict in concurrency in this state function
898 if oFsm.useAPIVersion43 { // newer API usage requires verification of downloaded image version
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000899 go func(a_pAFsm *cmn.AdapterFsm) {
900 _ = a_pAFsm.PFsm.Event(UpgradeEvCheckImageName)
mpagenkoc26d4c02021-05-06 14:27:57 +0000901 }(pBaseFsm)
mpagenko38662d02021-08-11 09:45:19 +0000902 } else { // elder API usage does not support image version check -immediately consider download as successful
903 if oFsm.activateImage {
904 //immediate activation requested
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000905 go func(a_pAFsm *cmn.AdapterFsm) {
906 _ = a_pAFsm.PFsm.Event(UpgradeEvRequestActivate)
mpagenko38662d02021-08-11 09:45:19 +0000907 }(pBaseFsm)
908 } else {
909 //have to wait on explicit activation request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000910 go func(a_pAFsm *cmn.AdapterFsm) {
911 _ = a_pAFsm.PFsm.Event(UpgradeEvWaitForActivate)
mpagenko38662d02021-08-11 09:45:19 +0000912 }(pBaseFsm)
913 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000914 }
mpagenko59498c12021-03-18 14:15:15 +0000915 return
916 }
917 //timer was aborted
mpagenko45586762021-10-01 08:30:22 +0000918 oFsm.abortOnOmciError(ctx, true)
mpagenko59498c12021-03-18 14:15:15 +0000919 return
920 }
mpagenko80622a52021-02-09 16:53:23 +0000921}
922
mpagenko38662d02021-08-11 09:45:19 +0000923func (oFsm *OnuUpgradeFsm) enterCheckImageName(ctx context.Context, e *fsm.Event) {
924 logger.Debugw(ctx, "OnuUpgradeFsm checking downloaded image name", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000925 "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID})
mpagenko38662d02021-08-11 09:45:19 +0000926 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000927 meInstance, err := oFsm.pOmciCC.SendGetMe(log.WithSpanFromContext(context.Background(), ctx),
928 me.SoftwareImageClassID, oFsm.InactiveImageMeID, requestedAttributes, oFsm.pDeviceHandler.GetOmciTimeout(),
929 false, oFsm.PAdaptFsm.CommChan)
mpagenko38662d02021-08-11 09:45:19 +0000930 if err != nil {
931 logger.Errorw(ctx, "OnuUpgradeFsm get Software Image ME result error",
932 log.Fields{"device-id": oFsm.deviceID, "Error": err})
mpagenko45586762021-10-01 08:30:22 +0000933 oFsm.abortOnOmciError(ctx, true)
mpagenko38662d02021-08-11 09:45:19 +0000934 return
935 }
936 oFsm.pLastTxMeInstance = meInstance
937}
938
mpagenko80622a52021-02-09 16:53:23 +0000939func (oFsm *OnuUpgradeFsm) enterActivateSw(ctx context.Context, e *fsm.Event) {
940 logger.Infow(ctx, "OnuUpgradeFsm activate SW", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000941 "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID})
mpagenko80622a52021-02-09 16:53:23 +0000942
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000943 err := oFsm.pOmciCC.SendActivateSoftware(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
944 oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID)
mpagenko80622a52021-02-09 16:53:23 +0000945 if err != nil {
946 logger.Errorw(ctx, "ActivateSw abort: can't send activate frame", log.Fields{
947 "device-id": oFsm.deviceID, "error": err})
mpagenko45586762021-10-01 08:30:22 +0000948 oFsm.abortOnOmciError(ctx, true)
mpagenko80622a52021-02-09 16:53:23 +0000949 return
950 }
mpagenko38662d02021-08-11 09:45:19 +0000951 oFsm.mutexUpgradeParams.Lock()
mpagenko45586762021-10-01 08:30:22 +0000952 oFsm.upgradePhase = cUpgradeActivating //start of image activation for ONU
mpagenko38662d02021-08-11 09:45:19 +0000953 oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATING
954 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000955}
956
957func (oFsm *OnuUpgradeFsm) enterCommitSw(ctx context.Context, e *fsm.Event) {
mpagenko38662d02021-08-11 09:45:19 +0000958 logger.Debugw(ctx, "OnuUpgradeFsm start commit SW", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID})
mpagenko38662d02021-08-11 09:45:19 +0000960 //any abort request (also conditional) is still regarded as valid as the commit indication might not be possible to verify
961 // (which is a bit problematic as the ONU might already be in committed state,
962 // in this case (committing failed) always 'onuimage list' should be used to verify the real state (if ONU is reachable))
963 if activeImageID, err := oFsm.pDevEntry.GetActiveImageMeID(ctx); err == nil {
mpagenkoaa3afe92021-05-21 16:20:58 +0000964 oFsm.mutexUpgradeParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000965 if activeImageID == oFsm.InactiveImageMeID {
966 inactiveImageID := oFsm.InactiveImageMeID
mpagenko15ff4a52021-03-02 10:09:20 +0000967 logger.Infow(ctx, "OnuUpgradeFsm commit SW", log.Fields{
mpagenkoaa3afe92021-05-21 16:20:58 +0000968 "device-id": oFsm.deviceID, "me-id": inactiveImageID}) //more efficient activeImageID with above check
969 oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTING
mpagenko45586762021-10-01 08:30:22 +0000970 oFsm.upgradePhase = cUpgradeCommitting //start of image commitment for ONU
mpagenkoaa3afe92021-05-21 16:20:58 +0000971 oFsm.mutexUpgradeParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000972 err := oFsm.pOmciCC.SendCommitSoftware(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
973 oFsm.PAdaptFsm.CommChan, inactiveImageID) //more efficient activeImageID with above check
mpagenko15ff4a52021-03-02 10:09:20 +0000974 if err != nil {
975 logger.Errorw(ctx, "CommitSw abort: can't send commit sw frame", log.Fields{
976 "device-id": oFsm.deviceID, "error": err})
mpagenko45586762021-10-01 08:30:22 +0000977 oFsm.abortOnOmciError(ctx, true)
mpagenko15ff4a52021-03-02 10:09:20 +0000978 return
979 }
980 return
981 }
mpagenko38662d02021-08-11 09:45:19 +0000982 oFsm.mutexUpgradeParams.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000983 logger.Errorw(ctx, "OnuUpgradeFsm active ImageId <> IdToCommit", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000984 "device-id": oFsm.deviceID, "active ID": activeImageID, "to commit ID": oFsm.InactiveImageMeID})
mpagenko38662d02021-08-11 09:45:19 +0000985 } else {
986 logger.Errorw(ctx, "OnuUpgradeFsm can't commit, no valid active image", log.Fields{
987 "device-id": oFsm.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000988 }
mpagenko38662d02021-08-11 09:45:19 +0000989 oFsm.mutexUpgradeParams.Lock()
990 oFsm.conditionalCancelRequested = false //any lingering conditional cancelRequest is superseded by this error
mpagenko38662d02021-08-11 09:45:19 +0000991 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE
mpagenko38662d02021-08-11 09:45:19 +0000992 oFsm.mutexUpgradeParams.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000993 //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)??
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000994 pBaseFsm := oFsm.PAdaptFsm
mpagenko15ff4a52021-03-02 10:09:20 +0000995 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000996 go func(a_pAFsm *cmn.AdapterFsm) {
997 _ = a_pAFsm.PFsm.Event(UpgradeEvAbort)
mpagenko15ff4a52021-03-02 10:09:20 +0000998 }(pBaseFsm)
999}
1000
1001func (oFsm *OnuUpgradeFsm) enterCheckCommitted(ctx context.Context, e *fsm.Event) {
mpagenko38662d02021-08-11 09:45:19 +00001002 logger.Debugw(ctx, "OnuUpgradeFsm checking committed SW", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001003 "device-id": oFsm.deviceID, "me-id": oFsm.InactiveImageMeID})
mpagenko15ff4a52021-03-02 10:09:20 +00001004 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001005 meInstance, err := oFsm.pOmciCC.SendGetMe(log.WithSpanFromContext(context.Background(), ctx),
1006 me.SoftwareImageClassID, oFsm.InactiveImageMeID, requestedAttributes, oFsm.pDeviceHandler.GetOmciTimeout(), false, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001007 if err != nil {
1008 logger.Errorw(ctx, "OnuUpgradeFsm get Software Image ME result error",
1009 log.Fields{"device-id": oFsm.deviceID, "Error": err})
mpagenko45586762021-10-01 08:30:22 +00001010 oFsm.abortOnOmciError(ctx, true)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001011 return
1012 }
mpagenko15ff4a52021-03-02 10:09:20 +00001013 oFsm.pLastTxMeInstance = meInstance
mpagenko80622a52021-02-09 16:53:23 +00001014}
1015
1016func (oFsm *OnuUpgradeFsm) enterResetting(ctx context.Context, e *fsm.Event) {
1017 logger.Debugw(ctx, "OnuUpgradeFsm resetting", log.Fields{"device-id": oFsm.deviceID})
1018
mpagenko45586762021-10-01 08:30:22 +00001019 oFsm.stateUpdateOnReset(ctx)
mpagenko38662d02021-08-11 09:45:19 +00001020
mpagenkoc26d4c02021-05-06 14:27:57 +00001021 // in case the download-to-ONU timer is still running - cancel it
mpagenko39b703e2021-08-25 13:38:40 +00001022 //use non-blocking channel (to be independent from receiver state)
1023 select {
1024 //use channel to indicate that the download response waiting shall be aborted for this device (channel)
1025 case oFsm.chOnuDlReady <- false:
1026 default:
mpagenkoc26d4c02021-05-06 14:27:57 +00001027 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001028 pConfigUpgradeStateAFsm := oFsm.PAdaptFsm
1029 if pConfigUpgradeStateAFsm != nil {
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001030 var nextEvent string
1031 if oFsm.isEndSwDlOpen {
mpagenko45586762021-10-01 08:30:22 +00001032 if oFsm.repeatAbort {
1033 oFsm.delayEndSwDl = true //run next abort with delay
1034 } else { //initial request
1035 oFsm.delayEndSwDl = false //run next abort with no delay
1036 oFsm.waitCountEndSwDl = cWaitCountEndSwDl //init for possible repetitions
1037 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001038 nextEvent = UpgradeEvAbortSwDownload
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001039 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001040 nextEvent = UpgradeEvRestart
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001041 }
1042 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001043 go func(a_pAFsm *cmn.AdapterFsm) {
1044 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1045 _ = a_pAFsm.PFsm.Event(nextEvent)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001046 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001047 }(pConfigUpgradeStateAFsm)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001048 }
1049}
mpagenkoc26d4c02021-05-06 14:27:57 +00001050
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001051func (oFsm *OnuUpgradeFsm) enterAbortingDL(ctx context.Context, e *fsm.Event) {
1052 logger.Debugw(ctx, "OnuUpgradeFsm aborting download to ONU", log.Fields{"device-id": oFsm.deviceID})
1053
mpagenko45586762021-10-01 08:30:22 +00001054 oFsm.mutexUpgradeParams.RLock()
1055 if oFsm.delayEndSwDl {
1056 oFsm.mutexUpgradeParams.RUnlock()
1057 //give the ONU some time for image discard activities
1058 time.Sleep(cOmciEndSwDlDelaySeconds * time.Second)
1059 } else {
1060 oFsm.mutexUpgradeParams.RUnlock()
1061 }
1062
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001063 pBaseFsm := oFsm.PAdaptFsm
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001064 if pBaseFsm == nil {
1065 logger.Errorw(ctx, "OnuUpgradeFsm aborting download: BaseFsm invalid", log.Fields{"device-id": oFsm.deviceID})
1066 return
1067 }
1068 // abort the download operation by sending an end software download message with invalid CRC and image size
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001069 err := oFsm.pOmciCC.SendEndSoftwareDownload(log.WithSpanFromContext(context.Background(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), false,
1070 oFsm.PAdaptFsm.CommChan, oFsm.InactiveImageMeID, 0, 0xFFFFFFFF)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001071
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001072 if err != nil {
1073 logger.Errorw(ctx, "OnuUpgradeFsm aborting download: can't send EndSwDl request", log.Fields{"device-id": oFsm.deviceID})
1074 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001075 go func(a_pAFsm *cmn.AdapterFsm) {
1076 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1077 _ = a_pAFsm.PFsm.Event(UpgradeEvRestart)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001078 }
1079 }(pBaseFsm)
1080 return
1081 }
1082 select {
1083 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
1084 logger.Warnw(ctx, "OnuUpgradeFsm aborting download: timeout - no response received", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001085 go func(a_pAFsm *cmn.AdapterFsm) {
1086 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1087 _ = a_pAFsm.PFsm.Event(UpgradeEvRestart)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001088 }
1089 }(pBaseFsm)
1090 return
mpagenko45586762021-10-01 08:30:22 +00001091 case response := <-oFsm.chReceiveAbortEndSwDlResponse:
1092 logger.Debugw(ctx, "OnuUpgradeFsm aborting download: response received",
1093 log.Fields{"device-id": oFsm.deviceID, "response": response})
1094 //had to shift processing to separate function due to SCA complexity
1095 if oFsm.abortingDlEvaluateResponse(ctx, pBaseFsm, response) {
1096 return //event sent from function already
1097 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001098 go func(a_pAFsm *cmn.AdapterFsm) {
1099 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1100 _ = a_pAFsm.PFsm.Event(UpgradeEvRestart)
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001101 }
1102 }(pBaseFsm)
1103 return
mpagenko45586762021-10-01 08:30:22 +00001104 } //select
1105}
1106
1107//abortingDlEvaluateResponse waits for a channel indication with decision to proceed the FSM processing
1108func (oFsm *OnuUpgradeFsm) abortingDlEvaluateResponse(ctx context.Context,
1109 pBaseFsm *cmn.AdapterFsm, aResponseResult tEndSwDlResponseResult) bool {
1110 switch aResponseResult {
1111 case cEndSwDlResponseBusy: // indication for device busy, needs repetition
1112 if oFsm.waitCountEndSwDl == 0 {
1113 logger.Errorw(ctx, "aborting download: max limit of EndSwDl reached", log.Fields{
1114 "device-id": oFsm.deviceID})
1115 go func(a_pAFsm *cmn.AdapterFsm) {
1116 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1117 _ = a_pAFsm.PFsm.Event(UpgradeEvRestart) //give up and let FSM terminate
1118 }
1119 }(pBaseFsm)
1120 } else {
1121 logger.Debugw(ctx, "aborting download: re-trigger sending abort SwDl", log.Fields{
1122 "device-id": oFsm.deviceID, "counter": oFsm.waitCountEndSwDl})
1123 oFsm.waitCountEndSwDl--
1124 oFsm.repeatAbort = true //repeated request in next round
1125 go func(a_pAFsm *cmn.AdapterFsm) {
1126 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1127 _ = a_pAFsm.PFsm.Event(UpgradeEvReset) //which then re-triggers sending AbortSwDL
1128 }
1129 }(pBaseFsm)
1130 }
1131 return true
1132 case cEndSwDlResponseSuccess: // indication for success response
1133 logger.Infow(ctx, "aborting download: success response, terminating FSM", log.Fields{
1134 "device-id": oFsm.deviceID})
1135 case cEndSwDlResponseAbort: // indication for request to abort waiting for response
1136 logger.Infow(ctx, "aborting download: request to abort waiting, terminating FSM", log.Fields{
1137 "device-id": oFsm.deviceID})
1138 default:
1139 logger.Errorw(ctx, "aborting download: unknown channel indication, terminating FSM", log.Fields{
1140 "device-id": oFsm.deviceID})
1141 } //switch
1142 return false
Holger Hildebrandt288d9472021-09-06 10:47:53 +00001143}
1144
1145func (oFsm *OnuUpgradeFsm) enterRestarting(ctx context.Context, e *fsm.Event) {
1146 logger.Debugw(ctx, "OnuUpgradeFsm restarting", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001147 pConfigUpgradeStateAFsm := oFsm.PAdaptFsm
1148 if pConfigUpgradeStateAFsm != nil {
mpagenko80622a52021-02-09 16:53:23 +00001149 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001150 fsmAbortMsg := cmn.Message{
1151 Type: cmn.TestMsg,
1152 Data: cmn.TestMessage{
1153 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko80622a52021-02-09 16:53:23 +00001154 },
1155 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001156 pConfigUpgradeStateAFsm.CommChan <- fsmAbortMsg
mpagenko80622a52021-02-09 16:53:23 +00001157
1158 //try to restart the FSM to 'disabled'
1159 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001160 go func(a_pAFsm *cmn.AdapterFsm) {
1161 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1162 _ = a_pAFsm.PFsm.Event(UpgradeEvDisable)
mpagenko80622a52021-02-09 16:53:23 +00001163 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001164 }(pConfigUpgradeStateAFsm)
mpagenko80622a52021-02-09 16:53:23 +00001165 }
1166}
1167
1168func (oFsm *OnuUpgradeFsm) enterDisabled(ctx context.Context, e *fsm.Event) {
1169 logger.Debugw(ctx, "OnuUpgradeFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID})
mpagenkoc26d4c02021-05-06 14:27:57 +00001170 // no need to flush possible channels here, Upgrade FSM will be completely removed, garbage collector should find its way
mpagenko80622a52021-02-09 16:53:23 +00001171 if oFsm.pDeviceHandler != nil {
1172 //request removal of 'reference' in the Handler (completely clear the FSM and its data)
mpagenko38662d02021-08-11 09:45:19 +00001173 pLastUpgradeImageState := &voltha.ImageState{
1174 Version: oFsm.imageVersion,
1175 DownloadState: oFsm.volthaDownloadState,
1176 Reason: oFsm.volthaDownloadReason,
1177 ImageState: oFsm.volthaImageState,
1178 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001179 go oFsm.pDeviceHandler.RemoveOnuUpgradeFsm(ctx, pLastUpgradeImageState)
mpagenko80622a52021-02-09 16:53:23 +00001180 }
1181}
1182
1183func (oFsm *OnuUpgradeFsm) processOmciUpgradeMessages(ctx context.Context) { //ctx context.Context?
1184 logger.Debugw(ctx, "Start OnuUpgradeFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
1185loop:
1186 for {
1187 // case <-ctx.Done():
1188 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
1189 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001190 message, ok := <-oFsm.PAdaptFsm.CommChan
mpagenko80622a52021-02-09 16:53:23 +00001191 if !ok {
1192 logger.Info(ctx, "OnuUpgradeFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1193 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
mpagenko45586762021-10-01 08:30:22 +00001194 oFsm.abortOnOmciError(ctx, true)
mpagenko80622a52021-02-09 16:53:23 +00001195 break loop
1196 }
1197 logger.Debugw(ctx, "OnuUpgradeFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1198
1199 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001200 case cmn.TestMsg:
1201 msg, _ := message.Data.(cmn.TestMessage)
1202 if msg.TestMessageVal == cmn.AbortMessageProcessing {
mpagenko80622a52021-02-09 16:53:23 +00001203 logger.Infow(ctx, "OnuUpgradeFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1204 break loop
1205 }
1206 logger.Warnw(ctx, "OnuUpgradeFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001207 case cmn.OMCI:
1208 msg, _ := message.Data.(cmn.OmciMessage)
mpagenko80622a52021-02-09 16:53:23 +00001209 oFsm.handleOmciOnuUpgradeMessage(ctx, msg)
1210 default:
1211 logger.Warn(ctx, "OnuUpgradeFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1212 "message.Type": message.Type})
1213 }
1214 }
1215 logger.Infow(ctx, "End OnuUpgradeFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
1216}
1217
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001218func (oFsm *OnuUpgradeFsm) handleOmciOnuUpgradeMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko80622a52021-02-09 16:53:23 +00001219 logger.Debugw(ctx, "Rx OMCI OnuUpgradeFsm Msg", log.Fields{"device-id": oFsm.deviceID,
1220 "msgType": msg.OmciMsg.MessageType})
1221
1222 switch msg.OmciMsg.MessageType {
1223 case omci.StartSoftwareDownloadResponseType:
1224 {
mpagenko45586762021-10-01 08:30:22 +00001225 oFsm.handleRxStartSwDownloadResponse(ctx, msg)
mpagenko80622a52021-02-09 16:53:23 +00001226 return
1227 } //StartSoftwareDownloadResponseType
1228 case omci.DownloadSectionResponseType:
1229 {
mpagenko45586762021-10-01 08:30:22 +00001230 oFsm.handleRxSwSectionResponse(ctx, msg)
mpagenko80622a52021-02-09 16:53:23 +00001231 return
mpagenko80622a52021-02-09 16:53:23 +00001232 } //DownloadSectionResponseType
1233 case omci.EndSoftwareDownloadResponseType:
1234 {
mpagenko45586762021-10-01 08:30:22 +00001235 oFsm.handleRxEndSwDownloadResponse(ctx, msg)
mpagenko80622a52021-02-09 16:53:23 +00001236 return
1237 } //EndSoftwareDownloadResponseType
1238 case omci.ActivateSoftwareResponseType:
1239 {
1240 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeActivateSoftwareResponse)
1241 if msgLayer == nil {
1242 logger.Errorw(ctx, "Omci Msg layer could not be detected for ActivateSw",
1243 log.Fields{"device-id": oFsm.deviceID})
mpagenko45586762021-10-01 08:30:22 +00001244 oFsm.abortOnOmciError(ctx, false)
mpagenko80622a52021-02-09 16:53:23 +00001245 return
1246 }
1247 msgObj, msgOk := msgLayer.(*omci.ActivateSoftwareResponse)
1248 if !msgOk {
1249 logger.Errorw(ctx, "Omci Msg layer could not be assigned for ActivateSw",
1250 log.Fields{"device-id": oFsm.deviceID})
mpagenko45586762021-10-01 08:30:22 +00001251 oFsm.abortOnOmciError(ctx, false)
mpagenko80622a52021-02-09 16:53:23 +00001252 return
1253 }
1254 logger.Debugw(ctx, "OnuUpgradeFsm ActivateSwResponse data", log.Fields{
1255 "device-id": oFsm.deviceID, "data-fields": msgObj})
1256 if msgObj.Result != me.Success {
1257 logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse result error - later: drive FSM to abort state ?",
1258 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenko45586762021-10-01 08:30:22 +00001259 oFsm.abortOnOmciError(ctx, false)
mpagenko80622a52021-02-09 16:53:23 +00001260 return
1261 }
mpagenko183647c2021-06-08 15:25:04 +00001262 oFsm.mutexUpgradeParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001263 if msgObj.EntityInstance == oFsm.InactiveImageMeID {
mpagenko38662d02021-08-11 09:45:19 +00001264 // the image is regarded as active really only after ONU reboot and according indication (ONU down/up procedure)
mpagenko183647c2021-06-08 15:25:04 +00001265 oFsm.mutexUpgradeParams.Unlock()
1266 logger.Infow(ctx, "Expected ActivateSwResponse received",
1267 log.Fields{"device-id": oFsm.deviceID, "commit": oFsm.commitImage})
1268 if oFsm.commitImage {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001269 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvWaitForCommit)
mpagenko183647c2021-06-08 15:25:04 +00001270 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001271 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvActivationDone) // let the FSM wait for external commit request
mpagenko183647c2021-06-08 15:25:04 +00001272 }
mpagenko80622a52021-02-09 16:53:23 +00001273 return
1274 }
mpagenko183647c2021-06-08 15:25:04 +00001275 oFsm.mutexUpgradeParams.Unlock()
mpagenko80622a52021-02-09 16:53:23 +00001276 logger.Errorw(ctx, "OnuUpgradeFsm ActivateSwResponse wrong ME instance: abort",
1277 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
mpagenko45586762021-10-01 08:30:22 +00001278 oFsm.abortOnOmciError(ctx, false)
mpagenko80622a52021-02-09 16:53:23 +00001279 return
1280 } //ActivateSoftwareResponseType
mpagenko15ff4a52021-03-02 10:09:20 +00001281 case omci.CommitSoftwareResponseType:
1282 {
1283 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCommitSoftwareResponse)
1284 if msgLayer == nil {
1285 logger.Errorw(ctx, "Omci Msg layer could not be detected for CommitResponse",
1286 log.Fields{"device-id": oFsm.deviceID})
mpagenko45586762021-10-01 08:30:22 +00001287 oFsm.abortOnOmciError(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00001288 return
1289 }
1290 msgObj, msgOk := msgLayer.(*omci.CommitSoftwareResponse)
1291 if !msgOk {
1292 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CommitResponse",
1293 log.Fields{"device-id": oFsm.deviceID})
mpagenko45586762021-10-01 08:30:22 +00001294 oFsm.abortOnOmciError(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00001295 return
1296 }
mpagenkobf67a092021-03-17 09:52:28 +00001297 if msgObj.Result != me.Success {
mpagenko15ff4a52021-03-02 10:09:20 +00001298 logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse result error - later: drive FSM to abort state ?",
1299 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenko45586762021-10-01 08:30:22 +00001300 oFsm.abortOnOmciError(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00001301 return
mpagenkobf67a092021-03-17 09:52:28 +00001302 }
mpagenkoaa3afe92021-05-21 16:20:58 +00001303 oFsm.mutexUpgradeParams.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001304 if msgObj.EntityInstance == oFsm.InactiveImageMeID {
mpagenkoaa3afe92021-05-21 16:20:58 +00001305 oFsm.mutexUpgradeParams.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001306 logger.Debugw(ctx, "OnuUpgradeFsm Expected SwImage CommitResponse received", log.Fields{"device-id": oFsm.deviceID})
1307 //verifying committed image
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001308 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvCheckCommitted)
mpagenko15ff4a52021-03-02 10:09:20 +00001309 return
1310 }
mpagenkoaa3afe92021-05-21 16:20:58 +00001311 oFsm.mutexUpgradeParams.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001312 logger.Errorw(ctx, "OnuUpgradeFsm SwImage CommitResponse wrong ME instance: abort",
1313 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
mpagenko45586762021-10-01 08:30:22 +00001314 oFsm.abortOnOmciError(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00001315 return
1316 } //CommitSoftwareResponseType
1317 case omci.GetResponseType:
1318 {
mpagenko45586762021-10-01 08:30:22 +00001319 oFsm.handleRxSwGetResponse(ctx, msg)
mpagenko15ff4a52021-03-02 10:09:20 +00001320 return
1321 } //GetResponseType
mpagenko80622a52021-02-09 16:53:23 +00001322 default:
1323 {
1324 logger.Errorw(ctx, "Rx OMCI unhandled MsgType",
1325 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
1326 return
1327 }
1328 }
1329}
1330
mpagenko45586762021-10-01 08:30:22 +00001331func (oFsm *OnuUpgradeFsm) handleRxStartSwDownloadResponse(ctx context.Context, msg cmn.OmciMessage) {
1332 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeStartSoftwareDownloadResponse)
1333 if msgLayer == nil {
1334 logger.Errorw(ctx, "Omci Msg layer could not be detected for StartSwDlResponse",
1335 log.Fields{"device-id": oFsm.deviceID})
1336 oFsm.abortOnOmciError(ctx, false)
1337 return
1338 }
1339 msgObj, msgOk := msgLayer.(*omci.StartSoftwareDownloadResponse)
1340 if !msgOk {
1341 logger.Errorw(ctx, "Omci Msg layer could not be assigned for StartSwDlResponse",
1342 log.Fields{"device-id": oFsm.deviceID})
1343 oFsm.abortOnOmciError(ctx, false)
1344 return
1345 }
1346 logger.Debugw(ctx, "OnuUpgradeFsm StartSwDlResponse data", log.Fields{
1347 "device-id": oFsm.deviceID, "data-fields": msgObj})
1348 if msgObj.Result != me.Success {
1349 logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse result error - later: drive FSM to abort state ?",
1350 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1351 oFsm.abortOnOmciError(ctx, false)
1352 return
1353 }
1354
1355 oFsm.mutexUpgradeParams.Lock()
1356 if msgObj.EntityInstance == oFsm.InactiveImageMeID {
1357 logger.Debugw(ctx, "Expected StartSwDlResponse received", log.Fields{"device-id": oFsm.deviceID})
1358 if msgObj.WindowSize != oFsm.omciDownloadWindowSizeLimit {
1359 // also response WindowSize = 0 is a valid number for used Window size 1
1360 logger.Debugw(ctx, "different StartSwDlResponse window size requested by ONU", log.Fields{
1361 "acceptedOnuWindowSizeLimit": msgObj.WindowSize, "device-id": oFsm.deviceID})
1362 oFsm.omciDownloadWindowSizeLimit = msgObj.WindowSize
1363 }
1364 oFsm.noOfWindows = oFsm.noOfSections / uint32(oFsm.omciDownloadWindowSizeLimit+1)
1365 if oFsm.noOfSections%uint32(oFsm.omciDownloadWindowSizeLimit+1) > 0 {
1366 oFsm.noOfWindows++
1367 }
1368 logger.Debugw(ctx, "OnuUpgradeFsm will use", log.Fields{
1369 "windows": oFsm.noOfWindows, "sections": oFsm.noOfSections,
1370 "at WindowSizeLimit": oFsm.omciDownloadWindowSizeLimit})
1371 oFsm.nextDownloadSectionsAbsolute = 0
1372 oFsm.nextDownloadSectionsWindow = 0
1373 oFsm.nextDownloadWindow = 0
1374
1375 oFsm.mutexUpgradeParams.Unlock()
1376 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvRxStartSwDownload)
1377 return
1378 }
1379 oFsm.mutexUpgradeParams.Unlock()
1380 logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: try again (later)?",
1381 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
1382 oFsm.abortOnOmciError(ctx, false)
1383} //handleRxStartSwDownloadResponse
1384
1385func (oFsm *OnuUpgradeFsm) handleRxSwSectionResponse(ctx context.Context, msg cmn.OmciMessage) {
1386 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDownloadSectionResponse)
1387 if msgLayer == nil {
1388 logger.Errorw(ctx, "Omci Msg layer could not be detected for DlSectionResponse",
1389 log.Fields{"device-id": oFsm.deviceID, "omci-message": msg.OmciMsg})
1390 oFsm.abortOnOmciError(ctx, false)
1391 return
1392 }
1393 msgObj, msgOk := msgLayer.(*omci.DownloadSectionResponse)
1394 if !msgOk {
1395 logger.Errorw(ctx, "Omci Msg layer could not be assigned for DlSectionResponse",
1396 log.Fields{"device-id": oFsm.deviceID})
1397 oFsm.abortOnOmciError(ctx, false)
1398 return
1399 }
1400 logger.Debugw(ctx, "OnuUpgradeFsm DlSectionResponse Data", log.Fields{
1401 "device-id": oFsm.deviceID, "data-fields": msgObj})
1402 if msgObj.Result != me.Success {
1403 logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse result error - later: repeat window once?", //TODO!!!
1404 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1405 oFsm.abortOnOmciError(ctx, false)
1406 return
1407 }
1408 oFsm.mutexUpgradeParams.Lock()
1409 if msgObj.EntityInstance == oFsm.InactiveImageMeID {
1410 sectionNumber := msgObj.SectionNumber
1411 logger.Infow(ctx, "DlSectionResponse received", log.Fields{
1412 "window section-number": sectionNumber, "window": oFsm.nextDownloadWindow, "device-id": oFsm.deviceID})
1413
1414 oFsm.nextDownloadWindow++
1415 if oFsm.nextDownloadWindow >= oFsm.noOfWindows {
1416 if sectionNumber != oFsm.omciDownloadWindowSizeLast {
1417 logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse section error last window - later: repeat window once?", //TODO!!!
1418 log.Fields{"device-id": oFsm.deviceID, "actual section": sectionNumber,
1419 "expected section": oFsm.omciDownloadWindowSizeLast})
1420 oFsm.mutexUpgradeParams.Unlock()
1421 oFsm.abortOnOmciError(ctx, false)
1422 return
1423 }
1424 oFsm.delayEndSwDl = true //ensure a delay for the EndSwDl message
1425 //CRC computation for all data bytes of the file
1426 imageCRC := crc32a.Checksum(oFsm.imageBuffer[:int(oFsm.origImageLength)]) //store internal for multiple usage
1427 //revert the retrieved CRC Byte Order (seems not to deliver NetworkByteOrder)
1428 var byteSlice []byte = make([]byte, 4)
1429 binary.LittleEndian.PutUint32(byteSlice, uint32(imageCRC))
1430 oFsm.imageCRC = binary.BigEndian.Uint32(byteSlice)
1431 oFsm.mutexUpgradeParams.Unlock()
1432 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvEndSwDownload)
1433 return
1434 }
1435 if sectionNumber != oFsm.omciDownloadWindowSizeLimit {
1436 logger.Errorw(ctx, "OnuUpgradeFsm DlSectionResponse section error - later: repeat window once?", //TODO!!!
1437 log.Fields{"device-id": oFsm.deviceID, "actual-section": sectionNumber,
1438 "expected section": oFsm.omciDownloadWindowSizeLimit})
1439 oFsm.mutexUpgradeParams.Unlock()
1440 oFsm.abortOnOmciError(ctx, false)
1441 return
1442 }
1443 oFsm.nextDownloadSectionsWindow = 0
1444 oFsm.mutexUpgradeParams.Unlock()
1445 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvContinueNextWindow)
1446 return
1447 }
1448 oFsm.mutexUpgradeParams.Unlock()
1449 logger.Errorw(ctx, "OnuUpgradeFsm Omci StartSwDlResponse wrong ME instance: try again (later)?",
1450 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
1451 oFsm.abortOnOmciError(ctx, false)
1452} //handleRxSwSectionResponse
1453
1454func (oFsm *OnuUpgradeFsm) handleRxEndSwDownloadResponse(ctx context.Context, msg cmn.OmciMessage) {
1455 inAbortingState := oFsm.PAdaptFsm.PFsm.Is(UpgradeStAbortingDL)
1456
1457 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeEndSoftwareDownloadResponse)
1458 if msgLayer == nil {
1459 logger.Errorw(ctx, "Omci Msg layer could not be detected for EndSwDlResponse",
1460 log.Fields{"device-id": oFsm.deviceID})
1461 if !inAbortingState {
1462 oFsm.abortOnOmciError(ctx, false)
1463 } //else using error log and wait for another response or 'aborting' state timeout
1464 return
1465 }
1466 msgObj, msgOk := msgLayer.(*omci.EndSoftwareDownloadResponse)
1467 if !msgOk {
1468 logger.Errorw(ctx, "Omci Msg layer could not be assigned for EndSwDlResponse",
1469 log.Fields{"device-id": oFsm.deviceID})
1470 if !inAbortingState {
1471 oFsm.abortOnOmciError(ctx, false)
1472 } //else using error log and wait for another response or 'aborting' state timeout
1473 return
1474 }
1475 logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse data", log.Fields{
1476 "device-id": oFsm.deviceID, "data-fields": msgObj})
1477 if msgObj.Result != me.Success {
1478 if msgObj.Result == me.DeviceBusy {
1479 //ONU indicates it is still processing the image - let the FSM just wait and then repeat the request
1480 logger.Debugw(ctx, "OnuUpgradeFsm EndSwDlResponse busy: waiting before sending new request", log.Fields{
1481 "device-id": oFsm.deviceID})
1482 if inAbortingState {
1483 //if the EndSwDl was requested from state AbortingDL then use channel to indicate ONU busy/repeat indication
1484 oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseBusy //repeat abort request
1485 }
1486 oFsm.mutexUpgradeParams.Lock()
1487 oFsm.downloadReasonCached = oFsm.volthaDownloadReason //copy for later reconstruction
1488 oFsm.volthaDownloadReason = voltha.ImageState_DEVICE_BUSY
1489 oFsm.mutexUpgradeParams.Unlock()
1490 return
1491 }
1492 logger.Errorw(ctx, "OnuUpgradeFsm EndSwDlResponse result error - later: drive FSM to abort state ?",
1493 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1494 if inAbortingState {
1495 //if the EndSwDl was requested from state AbortingDL and response is error indication
1496 // that would be quite strange ONU behavior, no resolution from OnuAdapter, just let the FSM go on to disabled
1497 oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseAbort //error indication to abort waiting on EndDownloadResponse
1498 } //else using error log and wait for another response or 'aborting' state timeout
1499 return
1500 }
1501 oFsm.mutexUpgradeParams.Lock()
1502 if msgObj.EntityInstance == oFsm.InactiveImageMeID {
1503 logger.Debugw(ctx, "Expected EndSwDlResponse received", log.Fields{"device-id": oFsm.deviceID})
1504 if oFsm.volthaDownloadReason == voltha.ImageState_DEVICE_BUSY { //was temporary on busy
1505 oFsm.volthaDownloadReason = oFsm.downloadReasonCached //recapture from mirror
1506 }
1507 if inAbortingState {
1508 oFsm.mutexUpgradeParams.Unlock()
1509 //if the EndSwDl was requested from state AbortingDL then use channel to indicate abort acceptance
1510 oFsm.chReceiveAbortEndSwDlResponse <- cEndSwDlResponseSuccess //success
1511 return
1512 }
1513 if !oFsm.useAPIVersion43 {
1514 //in the older API version the image version check was not possible
1515 // - assume new loaded image as valid-inactive immediately
1516 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_SUCCEEDED
1517 oFsm.volthaImageState = voltha.ImageState_IMAGE_INACTIVE
1518 oFsm.mutexUpgradeParams.Unlock()
1519 //use non-blocking channel (to be independent from receiver state)
1520 select {
1521 //use non-blocking channel to indicate that the download to ONU was successful
1522 case oFsm.chOnuDlReady <- true:
1523 default:
1524 }
1525 } else {
1526 oFsm.mutexUpgradeParams.Unlock()
1527 }
1528 //use asynchronous channel sending to let the FSM proceed
1529 select {
1530 case oFsm.chReceiveExpectedResponse <- true:
1531 default:
1532 }
1533 return
1534 }
1535 oFsm.mutexUpgradeParams.Unlock()
1536 logger.Errorw(ctx, "OnuUpgradeFsm StartSwDlResponse wrong ME instance: ignoring",
1537 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
1538 // no state abort in case of unexpected ImageId, just keep waiting for the correct one
1539} //handleRxEndSwDownloadResponse
1540
1541func (oFsm *OnuUpgradeFsm) handleRxSwGetResponse(ctx context.Context, msg cmn.OmciMessage) {
1542 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
1543 if msgLayer == nil {
1544 logger.Errorw(ctx, "Omci Msg layer could not be detected for SwImage GetResponse",
1545 log.Fields{"device-id": oFsm.deviceID})
1546 oFsm.abortOnOmciError(ctx, false)
1547 return
1548 }
1549 msgObj, msgOk := msgLayer.(*omci.GetResponse)
1550 if !msgOk {
1551 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SwImage GetResponse",
1552 log.Fields{"device-id": oFsm.deviceID})
1553 oFsm.abortOnOmciError(ctx, false)
1554 return
1555 }
1556 logger.Debugw(ctx, "OnuUpgradeFsm SwImage GetResponse data", log.Fields{
1557 "device-id": oFsm.deviceID, "data-fields": msgObj})
1558 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1559 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1560 if msgObj.Result != me.Success {
1561 logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse result error - later: drive FSM to abort state ?",
1562 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1563 oFsm.abortOnOmciError(ctx, false)
1564 return
1565 }
1566 } else {
1567 logger.Warnw(ctx, "OnuUpgradeFsm SwImage unexpected Entity GetResponse data - ignore",
1568 log.Fields{"device-id": oFsm.deviceID})
1569 return
1570 }
1571
1572 meAttributes := msgObj.Attributes
1573 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
1574 imageIsActive := meAttributes["IsActive"].(uint8)
1575 imageVersion := cmn.TrimStringFromMeOctet(meAttributes["Version"])
1576 logger.Debugw(ctx, "OnuUpgradeFsm - GetResponse Data for SoftwareImage",
1577 log.Fields{"device-id": oFsm.deviceID, "entityID": msgObj.EntityInstance,
1578 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted})
1579
1580 if oFsm.PAdaptFsm.PFsm.Current() == UpgradeStCheckImageName {
1581 //image name check after EndSwDownload, this state (and block) can only be taken if APIVersion43 is used
1582 oFsm.verifyOnuSwStatusAfterDownload(ctx, msgObj.EntityInstance, imageVersion, imageIsActive, imageIsCommitted)
1583 return
1584 }
1585
1586 //assumed only relevant state here is upgradeStCheckCommitted
1587 oFsm.mutexUpgradeParams.Lock()
1588 oFsm.conditionalCancelRequested = false //getting here any set (conditional) cancelRequest is not relevant anymore
1589 if msgObj.EntityInstance == oFsm.InactiveImageMeID && imageIsActive == cmn.SwIsActive {
1590 //a check on the delivered image version is not done, the ONU delivered version might be different from what might have been
1591 // indicated in the download image version string (version must be part of the image content itself)
1592 // so checking that might be quite unreliable
1593 //but with new API this was changed, assumption is that omci image version is known at download request and exactly that is used
1594 // in all the API references, so it can and should be checked here now
1595 if oFsm.useAPIVersion43 {
1596 if imageVersion != oFsm.imageVersion {
1597 //new active version indicated on OMCI from ONU is not the expected version
1598 logger.Errorw(ctx, "OnuUpgradeFsm image-version not matching the requested upgrade",
1599 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance,
1600 "onu-version": imageVersion, "expected-version": oFsm.imageVersion})
1601 // TODO!!!: error treatment?
1602 //TODO!!!: possibly send event information for aborted upgrade (aborted by wrong version)?
1603 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE //something like 'UNEXPECTED_VERSION' would be better - proto def
1604 oFsm.mutexUpgradeParams.Unlock()
1605 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
1606 return
1607 }
1608 logger.Debugw(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU",
1609 log.Fields{"device-id": oFsm.deviceID})
1610 }
1611 if imageIsCommitted == cmn.SwIsCommitted {
1612 oFsm.upgradePhase = cUpgradeCommitted
1613 oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMITTED
1614 //store the new commit flag to onuSwImageIndications (to keep them in sync)
1615 oFsm.pDevEntry.ModifySwImageActiveCommit(ctx, imageIsCommitted)
1616 logger.Infow(ctx, "requested SW image committed, releasing OnuUpgrade", log.Fields{"device-id": oFsm.deviceID})
1617 //deviceProcStatusUpdate not used anymore,
1618 // replaced by transferring the last (more) upgrade state information within removeOnuUpgradeFsm
1619 oFsm.mutexUpgradeParams.Unlock()
1620 //releasing the upgrade FSM on success
1621 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
1622 return
1623 }
1624 //if not committed, abort upgrade as failed. There is no implementation here that would trigger this test again
1625 }
1626 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE
1627 oFsm.mutexUpgradeParams.Unlock()
1628 logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade",
1629 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": msgObj.EntityInstance})
1630 // TODO!!!: error treatment?
1631 //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)??
1632 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
1633} //handleRxSwGetResponse
1634
1635func (oFsm *OnuUpgradeFsm) verifyOnuSwStatusAfterDownload(ctx context.Context, aInstanceID uint16,
1636 aImageVersion string, aImageIsActive uint8, aImageIsCommitted uint8) {
1637 oFsm.mutexUpgradeParams.Lock()
1638 if aInstanceID == oFsm.InactiveImageMeID && aImageIsActive == cmn.SwIsInactive &&
1639 aImageIsCommitted == cmn.SwIsUncommitted {
1640 if aImageVersion != oFsm.imageVersion {
1641 //new stored inactive version indicated on OMCI from ONU is not the expected version
1642 logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse version indication not matching requested upgrade",
1643 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": aInstanceID,
1644 "onu-version": aImageVersion, "expected-version": oFsm.imageVersion})
1645 //download state is set when entering the reset state
1646 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE //something like 'UNEXPECTED_VERSION' would be better - proto def
1647 oFsm.mutexUpgradeParams.Unlock()
1648 //stop the running ONU download timer
1649 //use non-blocking channel (to be independent from receiver state)
1650 select {
1651 //use channel to indicate that the download response waiting shall be aborted for this device (channel)
1652 case oFsm.chOnuDlReady <- false:
1653 default:
1654 }
1655 // TODO!!!: error treatment?
1656 //TODO!!!: possibly send event information for aborted upgrade (aborted by wrong version)?
1657 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
1658 return
1659 }
1660 //with APIVersion43 this is the point to consider the newly loaded image as valid (and inactive)
1661 oFsm.upgradePhase = cUpgradeDownloaded
1662 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_SUCCEEDED
1663 oFsm.volthaImageState = voltha.ImageState_IMAGE_INACTIVE
1664 //store the new inactive version to onuSwImageIndications (to keep them in sync)
1665 oFsm.pDevEntry.ModifySwImageInactiveVersion(ctx, oFsm.imageVersion)
1666 //proceed within upgrade FSM
1667 if oFsm.activateImage {
1668 //immediate activation requested
1669 oFsm.mutexUpgradeParams.Unlock()
1670 logger.Debugw(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU, continue with activation",
1671 log.Fields{"device-id": oFsm.deviceID})
1672 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvRequestActivate)
1673 } else {
1674 //have to wait on explicit activation request
1675 oFsm.mutexUpgradeParams.Unlock()
1676 logger.Infow(ctx, "OnuUpgradeFsm - expected ONU image version indicated by the ONU, wait for activate request",
1677 log.Fields{"device-id": oFsm.deviceID})
1678 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvWaitForActivate)
1679 }
1680 //use non-blocking channel (to be independent from receiver state)
1681 select {
1682 //use non-blocking channel to indicate that the download to ONU was successful
1683 case oFsm.chOnuDlReady <- true:
1684 default:
1685 }
1686 return
1687 }
1688 //not the expected image/image state
1689 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE
1690 oFsm.mutexUpgradeParams.Unlock()
1691 logger.Errorw(ctx, "OnuUpgradeFsm SwImage GetResponse indications not matching requested upgrade",
1692 log.Fields{"device-id": oFsm.deviceID, "ResponseMeId": aInstanceID})
1693 // TODO!!!: error treatment?
1694 //TODO!!!: possibly send event information for aborted upgrade (aborted by ONU state indication)?
1695 _ = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
1696} //verifyOnuSwStatusAfterDownload
1697
1698//abortOnOmciError aborts the upgrade processing with evAbort
1699// asynchronous/synchronous based on parameter aAsync
1700func (oFsm *OnuUpgradeFsm) abortOnOmciError(ctx context.Context, aAsync bool) {
mpagenko38662d02021-08-11 09:45:19 +00001701 oFsm.mutexUpgradeParams.Lock()
1702 oFsm.conditionalCancelRequested = false //any conditional cancelRequest is superseded by this abortion
mpagenko38662d02021-08-11 09:45:19 +00001703 oFsm.volthaDownloadReason = voltha.ImageState_OMCI_TRANSFER_ERROR
mpagenko38662d02021-08-11 09:45:19 +00001704 oFsm.mutexUpgradeParams.Unlock()
1705 //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)??
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001706 if oFsm.PAdaptFsm != nil {
mpagenko38662d02021-08-11 09:45:19 +00001707 var err error
1708 if aAsync { //asynchronous call requested to ensure state transition
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001709 go func(a_pAFsm *cmn.AdapterFsm) {
1710 if a_pAFsm.PFsm != nil {
1711 err = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
mpagenko38662d02021-08-11 09:45:19 +00001712 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001713 }(oFsm.PAdaptFsm)
mpagenko38662d02021-08-11 09:45:19 +00001714 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001715 if oFsm.PAdaptFsm.PFsm != nil {
1716 err = oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
mpagenko38662d02021-08-11 09:45:19 +00001717 }
1718 }
1719 if err != nil {
1720 logger.Warnw(ctx, "onu upgrade fsm could not abort on omci error", log.Fields{
1721 "device-id": oFsm.deviceID, "error": err})
1722 }
1723 }
1724}
1725
mpagenkoc26d4c02021-05-06 14:27:57 +00001726//waitOnDownloadToAdapterReady state can only be reached with useAPIVersion43 (usage of pFileManager)
mpagenko38662d02021-08-11 09:45:19 +00001727// precondition: mutexIsAwaitingAdapterDlResponse is lockek on call
1728func (oFsm *OnuUpgradeFsm) waitOnDownloadToAdapterReady(ctx context.Context, aSyncChannel chan<- struct{},
1729 aWaitChannel chan bool) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001730 oFsm.mutexIsAwaitingAdapterDlResponse.Lock()
mpagenko38662d02021-08-11 09:45:19 +00001731 downloadToAdapterTimeout := oFsm.pFileManager.GetDownloadTimeout(ctx)
mpagenkoc26d4c02021-05-06 14:27:57 +00001732 oFsm.isWaitingForAdapterDlResponse = true
1733 oFsm.mutexIsAwaitingAdapterDlResponse.Unlock()
mpagenko38662d02021-08-11 09:45:19 +00001734 aSyncChannel <- struct{}{}
mpagenko80622a52021-02-09 16:53:23 +00001735 select {
1736 // maybe be also some outside cancel (but no context modeled for the moment ...)
1737 // case <-ctx.Done():
mpagenkoc26d4c02021-05-06 14:27:57 +00001738 // logger.Infow("OnuUpgradeFsm-waitOnDownloadToAdapterReady canceled", log.Fields{"for device-id": oFsm.deviceID})
1739 case <-time.After(downloadToAdapterTimeout): //10s should be enough for downloading some image to the adapter
1740 logger.Warnw(ctx, "OnuUpgradeFsm Waiting-adapter-download timeout", log.Fields{
1741 "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToAdapterTimeout})
1742 oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel)
mpagenko39b703e2021-08-25 13:38:40 +00001743 //running into timeout here may still have the download to adapter active -> abort
1744 oFsm.pFileManager.CancelDownload(ctx, oFsm.imageIdentifier)
mpagenkoc26d4c02021-05-06 14:27:57 +00001745 oFsm.mutexIsAwaitingAdapterDlResponse.Lock()
1746 oFsm.isWaitingForAdapterDlResponse = false
1747 oFsm.mutexIsAwaitingAdapterDlResponse.Unlock()
mpagenko39b703e2021-08-25 13:38:40 +00001748 oFsm.mutexUpgradeParams.Lock()
mpagenko45586762021-10-01 08:30:22 +00001749 oFsm.conditionalCancelRequested = false //any conditional cancelRequest is superseded by this abortion
mpagenko39b703e2021-08-25 13:38:40 +00001750 oFsm.volthaDownloadReason = voltha.ImageState_UNKNOWN_ERROR //something like 'DOWNLOAD_TO_ADAPTER_TIMEOUT' would be better (proto)
mpagenko39b703e2021-08-25 13:38:40 +00001751 oFsm.mutexUpgradeParams.Unlock()
1752 //TODO!!!: possibly send event information for aborted upgrade (aborted by omci processing)??
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001753 if oFsm.PAdaptFsm != nil && oFsm.PAdaptFsm.PFsm != nil {
1754 err := oFsm.PAdaptFsm.PFsm.Event(UpgradeEvAbort)
mpagenko39b703e2021-08-25 13:38:40 +00001755 if err != nil {
1756 logger.Warnw(ctx, "onu upgrade fsm could not abort on omci error", log.Fields{
1757 "device-id": oFsm.deviceID, "error": err})
1758 }
1759 }
mpagenkoc26d4c02021-05-06 14:27:57 +00001760 return
1761
1762 case success := <-aWaitChannel:
1763 if success {
1764 logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded received", log.Fields{"device-id": oFsm.deviceID})
1765 oFsm.mutexIsAwaitingAdapterDlResponse.Lock()
1766 oFsm.isWaitingForAdapterDlResponse = false
1767 oFsm.mutexIsAwaitingAdapterDlResponse.Unlock()
1768 //let the upgrade process proceed
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001769 pUpgradeFsm := oFsm.PAdaptFsm
mpagenkoc26d4c02021-05-06 14:27:57 +00001770 if pUpgradeFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001771 _ = pUpgradeFsm.PFsm.Event(UpgradeEvPrepareSwDownload)
mpagenkoc26d4c02021-05-06 14:27:57 +00001772 } else {
1773 logger.Errorw(ctx, "pUpgradeFsm is nil", log.Fields{"device-id": oFsm.deviceID})
1774 }
1775 return
1776 }
mpagenko39b703e2021-08-25 13:38:40 +00001777 // waiting was aborted (assumed here to be caused by
1778 // error detection or cancel at download after upgrade FSM reset/abort with according image states set there)
mpagenkoc26d4c02021-05-06 14:27:57 +00001779 logger.Debugw(ctx, "OnuUpgradeFsm Waiting-adapter-download aborted", log.Fields{"device-id": oFsm.deviceID})
1780 oFsm.pFileManager.RemoveReadyRequest(ctx, oFsm.imageIdentifier, aWaitChannel)
1781 oFsm.mutexIsAwaitingAdapterDlResponse.Lock()
1782 oFsm.isWaitingForAdapterDlResponse = false
1783 oFsm.mutexIsAwaitingAdapterDlResponse.Unlock()
mpagenkoc26d4c02021-05-06 14:27:57 +00001784 return
mpagenko80622a52021-02-09 16:53:23 +00001785 }
1786}
mpagenkoc26d4c02021-05-06 14:27:57 +00001787
1788//waitOnDownloadToOnuReady state can only be reached with useAPIVersion43 (usage of pFileManager)
1789func (oFsm *OnuUpgradeFsm) waitOnDownloadToOnuReady(ctx context.Context, aWaitChannel chan bool) {
1790 downloadToOnuTimeout := time.Duration(1+(oFsm.imageLength/0x400000)) * oFsm.downloadToOnuTimeout4MB
1791 logger.Debugw(ctx, "OnuUpgradeFsm start download-to-ONU timer", log.Fields{"device-id": oFsm.deviceID,
1792 "duration": downloadToOnuTimeout})
mpagenkoc26d4c02021-05-06 14:27:57 +00001793 select {
1794 // maybe be also some outside cancel (but no context modeled for the moment ...)
1795 // case <-ctx.Done():
1796 // logger.Infow("OnuUpgradeFsm-waitOnDownloadToOnuReady canceled", log.Fields{"for device-id": oFsm.deviceID})
1797 case <-time.After(downloadToOnuTimeout): //using an image-size depending timout (in minutes)
1798 logger.Warnw(ctx, "OnuUpgradeFsm Waiting-ONU-download timeout", log.Fields{
1799 "for device-id": oFsm.deviceID, "image-id": oFsm.imageIdentifier, "timeout": downloadToOnuTimeout})
mpagenkoc26d4c02021-05-06 14:27:57 +00001800 //the upgrade process has to be aborted
mpagenko45586762021-10-01 08:30:22 +00001801 oFsm.abortOnOmciError(ctx, false)
mpagenkoc26d4c02021-05-06 14:27:57 +00001802 return
1803
1804 case success := <-aWaitChannel:
1805 if success {
1806 logger.Debugw(ctx, "OnuUpgradeFsm image-downloaded on ONU received", log.Fields{"device-id": oFsm.deviceID})
mpagenkoc26d4c02021-05-06 14:27:57 +00001807 //all fine, let the FSM proceed like defined from the sender of this event
1808 return
1809 }
1810 // waiting was aborted (assumed here to be caused by
mpagenko39b703e2021-08-25 13:38:40 +00001811 // error detection or cancel at download after upgrade FSM reset/abort with according image states set there)
mpagenkoc26d4c02021-05-06 14:27:57 +00001812 logger.Debugw(ctx, "OnuUpgradeFsm Waiting-ONU-download aborted", log.Fields{"device-id": oFsm.deviceID})
mpagenkoc26d4c02021-05-06 14:27:57 +00001813 return
1814 }
1815}
mpagenko45586762021-10-01 08:30:22 +00001816
1817//stateUpdateOnReset writes the download and/or image state on entering the reset state according to FSM internal indications
1818func (oFsm *OnuUpgradeFsm) stateUpdateOnReset(ctx context.Context) {
1819 oFsm.mutexUpgradeParams.Lock()
1820 defer oFsm.mutexUpgradeParams.Unlock()
1821 if !oFsm.conditionalCancelRequested {
1822 switch oFsm.upgradePhase {
1823 case cUpgradeUndefined, cUpgradeDownloading: //coming from downloading
1824 //make sure the download state is only changed in case the device has still been downloading
1825 if oFsm.volthaDownloadReason == voltha.ImageState_CANCELLED_ON_REQUEST {
1826 // indication for termination on request
1827 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_CANCELLED
1828 } else if oFsm.volthaDownloadReason != voltha.ImageState_NO_ERROR {
1829 // indication for termination on failure
1830 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_FAILED
1831 }
1832 //reset the image state from Downloading in this case
1833 oFsm.volthaImageState = voltha.ImageState_IMAGE_UNKNOWN //something like 'IMAGE_DOWNLOAD_ABORTED' would be better (proto)
1834 //in all other upgrade phases the last set download state remains valid
1835 case cUpgradeActivating:
1836 //reset the image state from Activating in this case
1837 oFsm.volthaImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
1838 case cUpgradeCommitting: // indication for request to abort waiting for response
1839 //reset the image state from Activating in this case
1840 oFsm.volthaImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
1841 //default: in all other upgrade phases keep the last set imageState
1842 } //switch
1843 } else {
1844 //when reaching reset state with conditional cancel that can only result from ONU related problems
1845 // (mostly ONU down indication) - derived from resetFsms call
1846 // and it can only be related to the downloading-to-ONU phase (no need to check that additionally)
1847 oFsm.volthaDownloadState = voltha.ImageState_DOWNLOAD_FAILED
1848 oFsm.volthaDownloadReason = voltha.ImageState_CANCELLED_ON_ONU_STATE
1849 //reset the image state from Downloading in this case
1850 oFsm.volthaImageState = voltha.ImageState_IMAGE_UNKNOWN //something like 'IMAGE_DOWNLOAD_ABORTED' would be better (proto)
1851 }
1852}