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 | |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 48 | const cResponse = "response: " |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 49 | |
| 50 | //NewOnuImageStatus creates a new instance of OnuImageStatus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 51 | func NewOnuImageStatus(apDeviceHandler cmn.IdeviceHandler, apDevEntry cmn.IonuDeviceEntry) *OnuImageStatus { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 52 | return &OnuImageStatus{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 53 | deviceID: apDeviceHandler.GetDeviceID(), |
| 54 | pDeviceHandler: apDeviceHandler, |
| 55 | pDevEntry: apDevEntry, |
| 56 | pOmciCC: apDevEntry.GetDevOmciCC(), |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 57 | requestedAttributes: make(me.AttributeValueMap), |
| 58 | waitingForResp: false, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 59 | respChannel: make(chan cmn.Message), |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 62 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 63 | // GetOnuImageStatus - TODO: add comment |
| 64 | func (oo *OnuImageStatus) GetOnuImageStatus(ctx context.Context) (*voltha.OnuImages, error) { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 65 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 66 | if !oo.pDeviceHandler.IsReadyForOmciConfig() { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 67 | logger.Errorw(ctx, "command rejected - improper device state", log.Fields{"device-id": oo.deviceID}) |
| 68 | return nil, fmt.Errorf("command-rejected-improper-device-state") |
| 69 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 70 | if oo.pOmciCC == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 71 | logger.Errorw(ctx, "omciCC not ready to receive omci messages", log.Fields{"device-id": oo.deviceID}) |
| 72 | return nil, fmt.Errorf("omciCC-not-ready-to-receive-omci-messages") |
| 73 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 74 | var images voltha.OnuImages |
| 75 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 76 | for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ { |
| 77 | 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] | 78 | |
| 79 | var image voltha.OnuImage |
| 80 | |
| 81 | // TODO: Since the summed length of the attributes exceeds the capacity of a single response, |
| 82 | // it is distributed on several requests here. It should be discussed whether, in the course of a refactoring, |
| 83 | // a global mechanism should be implemented that automates this distribution - which would entail quite some |
| 84 | // changes on the respective receiver sides. |
| 85 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 86 | oo.requestedAttributes = me.AttributeValueMap{me.SoftwareImage_Version: "", me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_IsValid: 0} |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 87 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 88 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 89 | return nil, err |
| 90 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 91 | oo.requestedAttributes = me.AttributeValueMap{me.SoftwareImage_ProductCode: ""} |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 92 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 93 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 94 | return nil, err |
| 95 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 96 | oo.requestedAttributes = me.AttributeValueMap{me.SoftwareImage_ImageHash: 0} |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 97 | if err := oo.requestOnuImageAttributes(ctx, uint16(i), &image); err != nil { |
| 98 | logger.Errorw(ctx, err.Error(), log.Fields{"requestedAttributes": oo.requestedAttributes, "device-id": oo.deviceID}) |
| 99 | return nil, err |
| 100 | } |
| 101 | images.Items = append(images.Items, &image) |
| 102 | } |
| 103 | logger.Debugw(ctx, "images of the ONU", log.Fields{"images": images}) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 104 | oo.updateOnuSwImagePersistentData(ctx) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 105 | return &images, nil |
| 106 | } |
| 107 | |
| 108 | func (oo *OnuImageStatus) requestOnuImageAttributes(ctx context.Context, imageID uint16, image *voltha.OnuImage) error { |
| 109 | oo.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 110 | meInstance, err := oo.pOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, |
| 111 | imageID, oo.requestedAttributes, oo.pDeviceHandler.GetOmciTimeout(), true, oo.respChannel) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 112 | if err != nil { |
| 113 | oo.mutexPLastTxMeInstance.Unlock() |
| 114 | logger.Errorw(ctx, "can't send omci request to get data for image id", log.Fields{"image-id": imageID, "device-id": oo.deviceID}) |
| 115 | return fmt.Errorf("can't-send-omci-request-to-get-data-for-image-id-%d", imageID) |
| 116 | } |
| 117 | oo.pLastTxMeInstance = meInstance |
| 118 | oo.mutexPLastTxMeInstance.Unlock() |
| 119 | |
| 120 | if err = oo.waitForGetOnuImageStatus(ctx, image); err != nil { |
| 121 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oo.deviceID}) |
| 122 | return err |
| 123 | } |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | func (oo *OnuImageStatus) waitForGetOnuImageStatus(ctx context.Context, image *voltha.OnuImage) error { |
| 128 | oo.setWaitingForResp(true) |
| 129 | select { |
| 130 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 131 | case <-ctx.Done(): |
| 132 | logger.Errorw(ctx, "waitForGetOnuImageStatus context done", log.Fields{"device-id": oo.deviceID}) |
| 133 | oo.setWaitingForResp(false) |
| 134 | return fmt.Errorf("wait-for-image-status-context-done") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 135 | case <-time.After(oo.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 136 | logger.Errorw(ctx, "waitForGetOnuImageStatus timeout", log.Fields{"device-id": oo.deviceID}) |
| 137 | oo.setWaitingForResp(false) |
| 138 | return fmt.Errorf("wait-for-image-status-timeout") |
| 139 | case message, ok := <-oo.respChannel: |
| 140 | if !ok { |
| 141 | logger.Errorw(ctx, "waitForGetOnuImageStatus response error", log.Fields{"device-id": oo.deviceID}) |
| 142 | oo.setWaitingForResp(false) |
| 143 | return fmt.Errorf("wait-for-image-status-response-error") |
| 144 | } |
| 145 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 146 | case cmn.OMCI: |
| 147 | msg, _ := message.Data.(cmn.OmciMessage) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 148 | oo.setWaitingForResp(false) |
| 149 | return oo.processGetOnuImageStatusResp(ctx, msg, image) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 150 | case cmn.TestMsg: |
| 151 | msg, _ := message.Data.(cmn.TestMessage) |
| 152 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 153 | logger.Info(ctx, "waitForGetOnuImageStatus abort msg received", log.Fields{"device-id": oo.deviceID}) |
| 154 | oo.setWaitingForResp(false) |
| 155 | return fmt.Errorf("wait-for-image-status-abort-msg-received") |
| 156 | } |
| 157 | default: |
| 158 | logger.Errorw(ctx, "waitForGetOnuImageStatus wrong msg type received", log.Fields{"msgType": message.Type, "device-id": oo.deviceID}) |
| 159 | oo.setWaitingForResp(false) |
| 160 | return fmt.Errorf("wait-for-image-status-response-error") |
| 161 | } |
| 162 | } |
| 163 | logger.Errorw(ctx, "waitForGetOnuImageStatus processing error", log.Fields{"device-id": oo.deviceID}) |
| 164 | oo.setWaitingForResp(false) |
| 165 | return fmt.Errorf("wait-for-image-status-processing-error") |
| 166 | |
| 167 | } |
| 168 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 169 | 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] | 170 | if msg.OmciMsg.MessageType != omci.GetResponseType { |
| 171 | logger.Errorw(ctx, "processGetOnuImageStatusResp wrong response type received", log.Fields{"respType": msg.OmciMsg.MessageType, "device-id": oo.deviceID}) |
| 172 | return fmt.Errorf("process-image-status-response-error") |
| 173 | } |
| 174 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 175 | if msgLayer == nil { |
| 176 | logger.Errorw(ctx, "processGetOnuImageStatusResp omci Msg layer not found", log.Fields{"device-id": oo.deviceID}) |
| 177 | return fmt.Errorf("process-image-status-response-error") |
| 178 | } |
| 179 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 180 | if !msgOk { |
| 181 | logger.Errorw(ctx, "processGetOnuImageStatusResp omci msgObj layer could not be found", log.Fields{"device-id": oo.deviceID}) |
| 182 | return fmt.Errorf("process-image-status-response-error") |
| 183 | } |
| 184 | oo.mutexPLastTxMeInstance.RLock() |
| 185 | if oo.pLastTxMeInstance != nil { |
| 186 | if msgObj.EntityClass == oo.pLastTxMeInstance.GetClassID() && |
| 187 | msgObj.EntityInstance == oo.pLastTxMeInstance.GetEntityID() { |
| 188 | oo.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 189 | if err := oo.processAttributesReceived(ctx, msgObj, image); err != nil { |
| 190 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oo.deviceID}) |
| 191 | return err |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 192 | } |
| 193 | return nil |
| 194 | } |
| 195 | oo.mutexPLastTxMeInstance.RUnlock() |
| 196 | logger.Errorw(ctx, "processGetOnuImageStatusResp wrong MeInstance received", log.Fields{"device-id": oo.deviceID}) |
| 197 | return fmt.Errorf("process-image-status-response-error") |
| 198 | } |
| 199 | oo.mutexPLastTxMeInstance.RUnlock() |
| 200 | logger.Errorw(ctx, "processGetOnuImageStatusResp pLastTxMeInstance is nil", log.Fields{"device-id": oo.deviceID}) |
| 201 | return fmt.Errorf("process-image-status-response-error") |
| 202 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 203 | |
| 204 | func (oo *OnuImageStatus) processAttributesReceived(ctx context.Context, msgObj *omci.GetResponse, image *voltha.OnuImage) error { |
| 205 | meAttributes := msgObj.Attributes |
| 206 | logger.Debugw(ctx, "processAttributesReceived", log.Fields{"attributes": meAttributes, "device-id": oo.deviceID}) |
| 207 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 208 | if _, ok := oo.requestedAttributes[me.SoftwareImage_Version]; ok { |
Holger Hildebrandt | 94688c7 | 2021-12-17 12:13:02 +0000 | [diff] [blame] | 209 | if msgObj.Result != me.Success { |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 210 | logger.Errorw(ctx, "processAttributesReceived - retrieval of mandatory attributes not successful", |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 211 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 212 | return fmt.Errorf("retrieve-mandatory-attributes-not-successful") |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 213 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 214 | if !oo.pDevEntry.HandleSwImageIndications(ctx, msgObj.EntityInstance, meAttributes) { |
| 215 | logger.Errorw(ctx, "processAttributesReceived - not all mandatory attributes present in SoftwareImage instance", log.Fields{"device-id": oo.deviceID}) |
| 216 | return fmt.Errorf("not-all-mandatory-attributes-present") |
| 217 | } |
Holger Hildebrandt | 94688c7 | 2021-12-17 12:13:02 +0000 | [diff] [blame] | 218 | } |
| 219 | for k := range oo.requestedAttributes { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 220 | switch k { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 221 | // mandatory attributes |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 222 | case me.SoftwareImage_IsCommitted: |
| 223 | if meAttributes[me.SoftwareImage_IsCommitted].(uint8) == cmn.SwIsCommitted { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 224 | image.IsCommited = true |
| 225 | } else { |
| 226 | image.IsCommited = false |
| 227 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 228 | case me.SoftwareImage_IsActive: |
| 229 | if meAttributes[me.SoftwareImage_IsActive].(uint8) == cmn.SwIsActive { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 230 | image.IsActive = true |
| 231 | } else { |
| 232 | image.IsActive = false |
| 233 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 234 | case me.SoftwareImage_IsValid: |
| 235 | if meAttributes[me.SoftwareImage_IsValid].(uint8) == cmn.SwIsValid { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 236 | image.IsValid = true |
| 237 | } else { |
| 238 | image.IsValid = false |
| 239 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 240 | case me.SoftwareImage_Version: |
| 241 | image.Version = cmn.TrimStringFromMeOctet(meAttributes[me.SoftwareImage_Version]) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 242 | |
| 243 | // optional attributes |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 244 | case me.SoftwareImage_ProductCode: |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 245 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 246 | image.ProductCode = cmn.TrimStringFromMeOctet(meAttributes[me.SoftwareImage_ProductCode]) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 247 | } else { |
| 248 | sResult := msgObj.Result.String() |
| 249 | logger.Infow(ctx, "processAttributesReceived - ProductCode", |
| 250 | log.Fields{"result": sResult, "unsupported attribute mask": msgObj.UnsupportedAttributeMask, "device-id": oo.deviceID}) |
| 251 | image.ProductCode = cResponse + sResult |
| 252 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 253 | case me.SoftwareImage_ImageHash: |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 254 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 255 | bytes, _ := me.InterfaceToOctets(meAttributes[me.SoftwareImage_ImageHash]) |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 256 | image.Hash = hex.EncodeToString(bytes) |
| 257 | } else { |
| 258 | sResult := msgObj.Result.String() |
| 259 | logger.Infow(ctx, "processAttributesReceived - ImageHash", |
| 260 | log.Fields{"result": sResult, "unsupported attribute mask": msgObj.UnsupportedAttributeMask, "device-id": oo.deviceID}) |
| 261 | image.Hash = cResponse + sResult |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | return nil |
| 266 | } |
| 267 | |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 268 | func (oo *OnuImageStatus) updateOnuSwImagePersistentData(ctx context.Context) { |
| 269 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 270 | activeImageVersion := oo.pDevEntry.GetActiveImageVersion(ctx) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 271 | persActiveSwVersion := oo.pDevEntry.GetPersActiveSwVersion() |
| 272 | if persActiveSwVersion != activeImageVersion { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 273 | 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] | 274 | log.Fields{"old version": persActiveSwVersion, |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 275 | "new version": activeImageVersion, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 276 | oo.pDevEntry.SetPersActiveSwVersion(activeImageVersion) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 277 | if err := oo.pDeviceHandler.StorePersistentData(ctx); err != nil { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 278 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| 279 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 280 | } |
| 281 | return |
| 282 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 285 | func (oo *OnuImageStatus) setWaitingForResp(value bool) { |
| 286 | oo.mutexWaitingForResp.Lock() |
| 287 | oo.waitingForResp = value |
| 288 | oo.mutexWaitingForResp.Unlock() |
| 289 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 290 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 291 | func (oo *OnuImageStatus) isWaitingForResp() bool { |
| 292 | oo.mutexWaitingForResp.RLock() |
| 293 | value := oo.waitingForResp |
| 294 | oo.mutexWaitingForResp.RUnlock() |
| 295 | return value |
| 296 | } |
| 297 | |
| 298 | //CancelProcessing ensures that interrupted processing is canceled while waiting for a response |
| 299 | func (oo *OnuImageStatus) CancelProcessing(ctx context.Context) { |
| 300 | if oo.isWaitingForResp() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 301 | abortMsg := cmn.Message{ |
| 302 | Type: cmn.TestMsg, |
| 303 | Data: cmn.TestMessage{ |
| 304 | TestMessageVal: cmn.AbortMessageProcessing, |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 305 | }, |
| 306 | } |
| 307 | oo.respChannel <- abortMsg |
| 308 | } |
| 309 | } |