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