Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package swupg provides the utilities for onu sw upgrade |
| 18 | package swupg |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/hex" |
| 23 | "fmt" |
| 24 | "sync" |
| 25 | "time" |
| 26 | |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 27 | "github.com/opencord/omci-lib-go/v2" |
| 28 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 30 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | //OnuImageStatus implements methods to get status info of onu images |
| 35 | type OnuImageStatus struct { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 36 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 37 | pDeviceHandler cmn.IdeviceHandler |
| 38 | pDevEntry cmn.IonuDeviceEntry |
| 39 | pOmciCC *cmn.OmciCC |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 40 | requestedAttributes me.AttributeValueMap |
| 41 | mutexWaitingForResp sync.RWMutex |
| 42 | waitingForResp bool |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 43 | respChannel chan cmn.Message |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 44 | mutexPLastTxMeInstance sync.RWMutex |
| 45 | pLastTxMeInstance *me.ManagedEntity |
| 46 | } |
| 47 | |
| 48 | const ( |
| 49 | cImgVersion = "Version" |
| 50 | cImgIsCommitted = "IsCommitted" |
| 51 | cImgIsActive = "IsActive" |
| 52 | cImgIsValid = "IsValid" |
| 53 | cImgProductCode = "ProductCode" |
| 54 | cImgImageHash = "ImageHash" |
| 55 | ) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 56 | const cResponse = "response: " |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 57 | |
| 58 | //NewOnuImageStatus creates a new instance of OnuImageStatus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 59 | func NewOnuImageStatus(apDeviceHandler cmn.IdeviceHandler, apDevEntry cmn.IonuDeviceEntry) *OnuImageStatus { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 60 | return &OnuImageStatus{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 61 | deviceID: apDeviceHandler.GetDeviceID(), |
| 62 | pDeviceHandler: apDeviceHandler, |
| 63 | pDevEntry: apDevEntry, |
| 64 | pOmciCC: apDevEntry.GetDevOmciCC(), |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 65 | requestedAttributes: make(me.AttributeValueMap), |
| 66 | waitingForResp: false, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 67 | respChannel: make(chan cmn.Message), |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 70 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 71 | // GetOnuImageStatus - TODO: add comment |
| 72 | func (oo *OnuImageStatus) GetOnuImageStatus(ctx context.Context) (*voltha.OnuImages, error) { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 73 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 74 | if !oo.pDeviceHandler.IsReadyForOmciConfig() { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 75 | logger.Errorw(ctx, "command rejected - improper device state", log.Fields{"device-id": oo.deviceID}) |
| 76 | return nil, fmt.Errorf("command-rejected-improper-device-state") |
| 77 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 78 | if oo.pOmciCC == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 79 | logger.Errorw(ctx, "omciCC not ready to receive omci messages", log.Fields{"device-id": oo.deviceID}) |
| 80 | return nil, fmt.Errorf("omciCC-not-ready-to-receive-omci-messages") |
| 81 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 82 | var images voltha.OnuImages |
| 83 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 84 | for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ { |
| 85 | logger.Debugw(ctx, "GetOnuImageStatus for image id", log.Fields{"image-id": i, "device-id": oo.deviceID}) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 86 | |
| 87 | var image voltha.OnuImage |
| 88 | |
| 89 | // TODO: Since the summed length of the attributes exceeds the capacity of a single response, |
| 90 | // it is distributed on several requests here. It should be discussed whether, in the course of a refactoring, |
| 91 | // a global mechanism should be implemented that automates this distribution - which would entail quite some |
| 92 | // changes on the respective receiver sides. |
| 93 | |
| 94 | oo.requestedAttributes = me.AttributeValueMap{cImgVersion: "", cImgIsCommitted: 0, cImgIsActive: 0, cImgIsValid: 0} |
| 95 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 96 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 97 | return nil, err |
| 98 | } |
| 99 | oo.requestedAttributes = me.AttributeValueMap{cImgProductCode: ""} |
| 100 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 101 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 102 | return nil, err |
| 103 | } |
| 104 | oo.requestedAttributes = me.AttributeValueMap{cImgImageHash: 0} |
| 105 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 106 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 107 | return nil, err |
| 108 | } |
| 109 | images.Items = append(images.Items, &image) |
| 110 | } |
| 111 | logger.Debugw(ctx, "images of the ONU", log.Fields{"images": images}) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 112 | oo.updateOnuSwImageIndications(ctx, &images) |
| 113 | oo.updateOnuSwImagePersistentData(ctx) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 114 | return &images, nil |
| 115 | } |
| 116 | |
| 117 | func (oo *OnuImageStatus) requestOnuImageAttributes(ctx context.Context, imageID uint16, image *voltha.OnuImage) error { |
| 118 | oo.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 119 | meInstance, err := oo.pOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, |
| 120 | imageID, oo.requestedAttributes, oo.pDeviceHandler.GetOmciTimeout(), true, oo.respChannel) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 121 | if err != nil { |
| 122 | oo.mutexPLastTxMeInstance.Unlock() |
| 123 | logger.Errorw(ctx, "can't send omci request to get data for image id", log.Fields{"image-id": imageID, "device-id": oo.deviceID}) |
| 124 | return fmt.Errorf("can't-send-omci-request-to-get-data-for-image-id-%d", imageID) |
| 125 | } |
| 126 | oo.pLastTxMeInstance = meInstance |
| 127 | oo.mutexPLastTxMeInstance.Unlock() |
| 128 | |
| 129 | if err = oo.waitForGetOnuImageStatus(ctx, image); err != nil { |
| 130 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oo.deviceID}) |
| 131 | return err |
| 132 | } |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | func (oo *OnuImageStatus) waitForGetOnuImageStatus(ctx context.Context, image *voltha.OnuImage) error { |
| 137 | oo.setWaitingForResp(true) |
| 138 | select { |
| 139 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 140 | case <-ctx.Done(): |
| 141 | logger.Errorw(ctx, "waitForGetOnuImageStatus context done", log.Fields{"device-id": oo.deviceID}) |
| 142 | oo.setWaitingForResp(false) |
| 143 | return fmt.Errorf("wait-for-image-status-context-done") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 144 | case <-time.After(oo.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 145 | logger.Errorw(ctx, "waitForGetOnuImageStatus timeout", log.Fields{"device-id": oo.deviceID}) |
| 146 | oo.setWaitingForResp(false) |
| 147 | return fmt.Errorf("wait-for-image-status-timeout") |
| 148 | case message, ok := <-oo.respChannel: |
| 149 | if !ok { |
| 150 | logger.Errorw(ctx, "waitForGetOnuImageStatus response error", log.Fields{"device-id": oo.deviceID}) |
| 151 | oo.setWaitingForResp(false) |
| 152 | return fmt.Errorf("wait-for-image-status-response-error") |
| 153 | } |
| 154 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 155 | case cmn.OMCI: |
| 156 | msg, _ := message.Data.(cmn.OmciMessage) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 157 | oo.setWaitingForResp(false) |
| 158 | return oo.processGetOnuImageStatusResp(ctx, msg, image) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 159 | case cmn.TestMsg: |
| 160 | msg, _ := message.Data.(cmn.TestMessage) |
| 161 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 162 | logger.Info(ctx, "waitForGetOnuImageStatus abort msg received", log.Fields{"device-id": oo.deviceID}) |
| 163 | oo.setWaitingForResp(false) |
| 164 | return fmt.Errorf("wait-for-image-status-abort-msg-received") |
| 165 | } |
| 166 | default: |
| 167 | logger.Errorw(ctx, "waitForGetOnuImageStatus wrong msg type received", log.Fields{"msgType": message.Type, "device-id": oo.deviceID}) |
| 168 | oo.setWaitingForResp(false) |
| 169 | return fmt.Errorf("wait-for-image-status-response-error") |
| 170 | } |
| 171 | } |
| 172 | logger.Errorw(ctx, "waitForGetOnuImageStatus processing error", log.Fields{"device-id": oo.deviceID}) |
| 173 | oo.setWaitingForResp(false) |
| 174 | return fmt.Errorf("wait-for-image-status-processing-error") |
| 175 | |
| 176 | } |
| 177 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 178 | func (oo *OnuImageStatus) processGetOnuImageStatusResp(ctx context.Context, msg cmn.OmciMessage, image *voltha.OnuImage) error { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 179 | if msg.OmciMsg.MessageType != omci.GetResponseType { |
| 180 | logger.Errorw(ctx, "processGetOnuImageStatusResp wrong response type received", log.Fields{"respType": msg.OmciMsg.MessageType, "device-id": oo.deviceID}) |
| 181 | return fmt.Errorf("process-image-status-response-error") |
| 182 | } |
| 183 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 184 | if msgLayer == nil { |
| 185 | logger.Errorw(ctx, "processGetOnuImageStatusResp omci Msg layer not found", log.Fields{"device-id": oo.deviceID}) |
| 186 | return fmt.Errorf("process-image-status-response-error") |
| 187 | } |
| 188 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 189 | if !msgOk { |
| 190 | logger.Errorw(ctx, "processGetOnuImageStatusResp omci msgObj layer could not be found", log.Fields{"device-id": oo.deviceID}) |
| 191 | return fmt.Errorf("process-image-status-response-error") |
| 192 | } |
| 193 | oo.mutexPLastTxMeInstance.RLock() |
| 194 | if oo.pLastTxMeInstance != nil { |
| 195 | if msgObj.EntityClass == oo.pLastTxMeInstance.GetClassID() && |
| 196 | msgObj.EntityInstance == oo.pLastTxMeInstance.GetEntityID() { |
| 197 | oo.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 198 | if err := oo.processAttributesReceived(ctx, msgObj, image); err != nil { |
| 199 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oo.deviceID}) |
| 200 | return err |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 201 | } |
| 202 | return nil |
| 203 | } |
| 204 | oo.mutexPLastTxMeInstance.RUnlock() |
| 205 | logger.Errorw(ctx, "processGetOnuImageStatusResp wrong MeInstance received", log.Fields{"device-id": oo.deviceID}) |
| 206 | return fmt.Errorf("process-image-status-response-error") |
| 207 | } |
| 208 | oo.mutexPLastTxMeInstance.RUnlock() |
| 209 | logger.Errorw(ctx, "processGetOnuImageStatusResp pLastTxMeInstance is nil", log.Fields{"device-id": oo.deviceID}) |
| 210 | return fmt.Errorf("process-image-status-response-error") |
| 211 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 212 | |
| 213 | func (oo *OnuImageStatus) processAttributesReceived(ctx context.Context, msgObj *omci.GetResponse, image *voltha.OnuImage) error { |
| 214 | meAttributes := msgObj.Attributes |
| 215 | logger.Debugw(ctx, "processAttributesReceived", log.Fields{"attributes": meAttributes, "device-id": oo.deviceID}) |
| 216 | |
| 217 | for k := range oo.requestedAttributes { |
| 218 | |
| 219 | if msgObj.Result != me.Success && k != cImgProductCode && k != cImgImageHash { |
| 220 | logger.Errorw(ctx, "processAttributesReceived retrieval of mandatory attributes failed", |
| 221 | log.Fields{"device-id": oo.deviceID}) |
| 222 | return fmt.Errorf("process-image-status-response-error") |
| 223 | } |
| 224 | switch k { |
| 225 | |
| 226 | // mandatory attributes |
| 227 | case cImgIsCommitted: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 228 | if meAttributes[cImgIsCommitted].(uint8) == cmn.SwIsCommitted { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 229 | image.IsCommited = true |
| 230 | } else { |
| 231 | image.IsCommited = false |
| 232 | } |
| 233 | case cImgIsActive: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 234 | if meAttributes[cImgIsActive].(uint8) == cmn.SwIsActive { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 235 | image.IsActive = true |
| 236 | } else { |
| 237 | image.IsActive = false |
| 238 | } |
| 239 | case cImgIsValid: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 240 | if meAttributes[cImgIsValid].(uint8) == cmn.SwIsValid { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 241 | image.IsValid = true |
| 242 | } else { |
| 243 | image.IsValid = false |
| 244 | } |
| 245 | case cImgVersion: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 246 | image.Version = cmn.TrimStringFromMeOctet(meAttributes[cImgVersion]) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 247 | |
| 248 | // optional attributes |
| 249 | case cImgProductCode: |
| 250 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 251 | image.ProductCode = cmn.TrimStringFromMeOctet(meAttributes[cImgProductCode]) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 252 | } else { |
| 253 | sResult := msgObj.Result.String() |
| 254 | logger.Infow(ctx, "processAttributesReceived - ProductCode", |
| 255 | log.Fields{"result": sResult, "unsupported attribute mask": msgObj.UnsupportedAttributeMask, "device-id": oo.deviceID}) |
| 256 | image.ProductCode = cResponse + sResult |
| 257 | } |
| 258 | case cImgImageHash: |
| 259 | if msgObj.Result == me.Success { |
| 260 | bytes, _ := me.InterfaceToOctets(meAttributes[cImgImageHash]) |
| 261 | image.Hash = hex.EncodeToString(bytes) |
| 262 | } else { |
| 263 | sResult := msgObj.Result.String() |
| 264 | logger.Infow(ctx, "processAttributesReceived - ImageHash", |
| 265 | log.Fields{"result": sResult, "unsupported attribute mask": msgObj.UnsupportedAttributeMask, "device-id": oo.deviceID}) |
| 266 | image.Hash = cResponse + sResult |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | return nil |
| 271 | } |
| 272 | |
| 273 | func (oo *OnuImageStatus) updateOnuSwImageIndications(ctx context.Context, images *voltha.OnuImages) { |
| 274 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 275 | oo.pDevEntry.LockMutexOnuSwImageIndications() |
| 276 | onuSwImageIndications := oo.pDevEntry.GetOnuSwImageIndications() |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 277 | validActiveImageFound := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 278 | for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 279 | if images.Items[i].IsActive && images.Items[i].IsValid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 280 | onuSwImageIndications.ActiveEntityEntry.EntityID = uint16(i) |
| 281 | onuSwImageIndications.ActiveEntityEntry.Valid = images.Items[i].IsValid |
| 282 | onuSwImageIndications.ActiveEntityEntry.Version = images.Items[i].Version |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 283 | if images.Items[i].IsCommited { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 284 | onuSwImageIndications.ActiveEntityEntry.IsCommitted = cmn.SwIsCommitted |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 285 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 286 | onuSwImageIndications.ActiveEntityEntry.IsCommitted = cmn.SwIsUncommitted |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 287 | } |
| 288 | validActiveImageFound = true |
| 289 | break |
| 290 | } |
| 291 | } |
| 292 | if !validActiveImageFound { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 293 | onuSwImageIndications.ActiveEntityEntry.Valid = false |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 294 | } |
| 295 | validInactiveImageFound := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 296 | for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 297 | if !images.Items[i].IsActive && images.Items[i].IsValid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 298 | onuSwImageIndications.InActiveEntityEntry.EntityID = uint16(i) |
| 299 | onuSwImageIndications.InActiveEntityEntry.Valid = images.Items[i].IsValid |
| 300 | onuSwImageIndications.InActiveEntityEntry.Version = images.Items[i].Version |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 301 | if images.Items[i].IsCommited { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 302 | onuSwImageIndications.InActiveEntityEntry.IsCommitted = cmn.SwIsCommitted |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 303 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 304 | onuSwImageIndications.InActiveEntityEntry.IsCommitted = cmn.SwIsUncommitted |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 305 | } |
| 306 | validInactiveImageFound = true |
| 307 | break |
| 308 | } |
| 309 | } |
| 310 | if !validInactiveImageFound { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 311 | onuSwImageIndications.InActiveEntityEntry.Valid = false |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 312 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 313 | oo.pDevEntry.SetOnuSwImageIndications(onuSwImageIndications) |
| 314 | oo.pDevEntry.UnlockMutexOnuSwImageIndications() |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | func (oo *OnuImageStatus) updateOnuSwImagePersistentData(ctx context.Context) { |
| 318 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 319 | activeImageVersion := oo.pDevEntry.GetActiveImageVersion(ctx) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 320 | persActiveSwVersion := oo.pDevEntry.GetPersActiveSwVersion() |
| 321 | if persActiveSwVersion != activeImageVersion { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 322 | logger.Infow(ctx, "Active SW version has been changed at ONU - update persistent data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 323 | log.Fields{"old version": persActiveSwVersion, |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 324 | "new version": activeImageVersion, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 325 | oo.pDevEntry.SetPersActiveSwVersion(activeImageVersion) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 326 | if err := oo.pDeviceHandler.StorePersistentData(ctx); err != nil { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 327 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| 328 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 329 | } |
| 330 | return |
| 331 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 334 | func (oo *OnuImageStatus) setWaitingForResp(value bool) { |
| 335 | oo.mutexWaitingForResp.Lock() |
| 336 | oo.waitingForResp = value |
| 337 | oo.mutexWaitingForResp.Unlock() |
| 338 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 339 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 340 | func (oo *OnuImageStatus) isWaitingForResp() bool { |
| 341 | oo.mutexWaitingForResp.RLock() |
| 342 | value := oo.waitingForResp |
| 343 | oo.mutexWaitingForResp.RUnlock() |
| 344 | return value |
| 345 | } |
| 346 | |
| 347 | //CancelProcessing ensures that interrupted processing is canceled while waiting for a response |
| 348 | func (oo *OnuImageStatus) CancelProcessing(ctx context.Context) { |
| 349 | if oo.isWaitingForResp() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 350 | abortMsg := cmn.Message{ |
| 351 | Type: cmn.TestMsg, |
| 352 | Data: cmn.TestMessage{ |
| 353 | TestMessageVal: cmn.AbortMessageProcessing, |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 354 | }, |
| 355 | } |
| 356 | oo.respChannel <- abortMsg |
| 357 | } |
| 358 | } |